* @author Loic Vinet * @author Laurent Giovannoni */ class domain extends dbquery { /** * * @access private * @var integer */ private $the_start; /** * Redefinition of the LetterBox object constructor */ function __construct() { // configure the sql argument order by if(isset($_GET['start'])) { $this->the_start = strip_tags($_GET['start']); } else { $this->the_start = 0; } } /** * Alphabetical list of the domains * * @param string $page page name */ public function domainslistletters($page = "domains") { // List all the alphabet letter to view the doc types who are starting with the letter if(isset($_GET['show'])) { if($_GET['show'] == "false") { $show = "&show=false"; } else { $show = ""; } } else { $show = ""; } ?>

: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z -

connect(); $this->query("select count(*) as total from ".$table_name." ".$where); $nb_total_1 = $this->fetch_object(); $nb_total = $nb_total_1->total; // define the defaults values $nb_pages = ceil($nb_total/$nb_show); $link = "index.php?page=".$page_name."&start=".$this->the_start."&order=".$this->orderby.$what; if($nb_pages > 1) { $next_start = 0; $page_list1 = '

'; $lastpage = 0; for($i = 0;$i <> $nb_pages; $i++) { $page_name = $i + 1; $the_line = $i + 1; if($this->the_start == $next_start) { $page_list1 .= ""; $page_list2 .= ""; } else { $page_list1 .= ""; $page_list2 .= ""; } $next_start = $next_start + $nb_show; $lastpage = $next_start; } $lastpage = $lastpage - $nb_show; $previous = ""; $next = ""; if($this->the_start > 0) { $start_prev = $this->the_start - $nb_show; $previous = ''; } if($this->the_start <> $lastpage) { $start_next = $this->the_start + $nb_show; $next = ''; } $page_list1 = $page_list1.""; $page_list2 = $page_list2.""; if($previous <> '' || $next <> '') { if(empty($previous)) { $previous = " "; } if(empty($next)) { $next = " "; } $page_list1 .= $previous." ".$next.'

'; $page_list2 .= $previous." ".$next.'

'; } } $this->query("select distinct ID from ".$table_name." ".$where." order by label asc limit ".$this->the_start.",".$nb_show); echo '

'.$title.'

'; $this->domainslistletters(); echo $page_list1; ?> connect(); $color = "line1"; while($line = $this->fetch_object()) { if($color == ' class="col"') { $color = ''; } else { $color = ' class="col"'; } $db->query("select ID, LABEL from ".$table_name." where ID ='".$line->ID."'"); $desc = ""; $line2 = $db->fetch_object(); $desc = $line2->LABEL; ?> >
ID; ?> '));" >
cleardomaininfos(); $_SESSION['services'] = array(); $this->query("select ID, SERVICE from ".$_SESSION['tablename']['services']." where ENABLED = 'Y'"); while($line = $this->fetch_object()) { array_push($_SESSION['services'], array("ID"=>$line->ID, "LABEL" => $line->SERVICE)); } $_SESSION['chosen_services'] = array(); } /** * Clear the session variables of the domain administration * */ private function cleardomaininfos() { // clear the session variable for the domains $_SESSION['m_admin']['domain'] = array(); $_SESSION['m_admin']['domain']['ID'] = ""; $_SESSION['m_admin']['domain']['LABEL'] = ""; $_SESSION['m_admin']['domain']['SERVICES'] = array(); } /** * Form to add or modify a domain * * @param string $mode up or add * @param string $id identifier of the domain to modify */ public function formdomain($mode,$id = "") { $func = new functions(); $state = true; if(!isset($_SESSION['m_admin']['domain'])) { $this->cleardomaininfos(); } if($mode <> "add" && empty($_SESSION['error'])) { $this->connect(); $this->query("select * from ".$_SESSION['tablename']['domains']." where ID = '".$id."'"); if($this->nb_result() == 0) { $_SESSION['error'] = _DOMAIN.' '._UNKNOWN; $state = false; } else { $_SESSION['m_admin']['domain'] = array(); $line = $this->fetch_object(); $_SESSION['m_admin']['domain']['ID'] = $line->ID; $_SESSION['m_admin']['domain']['LABEL'] = trim($line->LABEL); $_SESSION['m_admin']['domain']['SERVICES'] = array(); $this->query("select s.ID, s.SERVICE from ".$_SESSION['tablename']['domain_service']." ms, ".$_SESSION['tablename']['services']." s where ms.ID_DOMAIN = ".$_SESSION['m_admin']['domain']['ID']." and s.ID = ms.ID_SERVICE"); //$this->show(); while($res = $this->fetch_object()) { array_push($_SESSION['m_admin']['domain']['SERVICES'] , array('ID' =>$res->ID, 'LABEL' => $res->SERVICE)); } } } ?>

*

"; } $_SESSION['m_admin']['domain']['LABEL'] = $func->wash($_REQUEST['domain_name'], "no", _THE_WORDING); $_SESSION['m_admin']['domain']['LABEL'] = trim(stripslashes($_SESSION['m_admin']['domain']['LABEL'])); if($_REQUEST['mode'] == "up") { $_SESSION['m_admin']['domain']['ID'] = $func->wash($_REQUEST['domain_id'], "no", _ID); } } /** * Update the database with the domain data * */ public function updomain() { $this->domaininfo(); if(!empty($_SESSION['error'])) { if($_REQUEST['mode'] == "up") { if(!empty($_SESSION['m_admin']['domain']['ID'])) { header("location: index.php?page=domain_up&id=".$_SESSION['m_admin']['label']['ID']); exit; } else { header("location: index.php?page=domains"); exit; } } elseif($_REQUEST['mode'] == "add" ) { header("location: index.php?page=domain_add"); exit; } } else { $this->connect(); if( $_REQUEST['mode'] <> "add") { $this->query("update `".$_SESSION['tablename']['domains']."` set LABEL = '".addslashes($_SESSION['m_admin']['domain']['LABEL'])."' where ID = '".$_SESSION['m_admin']['domain']['ID']."'"); $this->query("delete from ".$_SESSION['tablename']['domain_service']." where ID_DOMAIN = '".$_SESSION['m_admin']['domain']['ID']."'"); for($i=0; $i < count($_SESSION['m_admin']['domain']['SERVICES']);$i++) { $this->query("insert into ".$_SESSION['tablename']['domain_service']." ( ID_SERVICE, ID_DOMAIN ) VALUES ( '".$_SESSION['m_admin']['domain']['SERVICES'][$i]['ID']."', ".$_SESSION['m_admin']['domain']['ID'].")"); } if($_REQUEST['mode'] == "up") { $_SESSION['error'] = _DOMAIN_MODIFICATION; if($_SESSION['history']['domainsup'] == "true") { require_once("class_history.php"); $users = new history(); $users->add($_SESSION['tablename']['domains'], $_SESSION['m_admin']['domain']['ID'],"UP",_DOMAIN_MODIFICATION." : ".$_SESSION['m_admin']['domain']['LABEL']); } } $this->cleardomaininfos(); header("location: index.php?page=domains"); exit; } else { $this->query("select LABEL from ".$_SESSION['tablename']['domains']." where LABEL = '".addslashes($_SESSION['m_admin']['domain']['LABEL'])."'"); if($this->nb_result() > 0) { $_SESSION['error'] = _THE_DOMAIN.' '.$_SESSION['m_admin']['domain']['LABEL'].' '._ALREADY_EXISTS; header("location: index.php?page=domain_add"); exit; } else { require_once("class_history.php"); $users = new history(); if( $_REQUEST['mode'] == "add") { $this->query("INSERT INTO ".$_SESSION['tablename']['domains']." (LABEL) VALUES('".addslashes($_SESSION['m_admin']['domain']['LABEL'])."')"); $this->query("select ID from ".$_SESSION['tablename']['domains']." where LABEL = '".addslashes($_SESSION['m_admin']['domain']['LABEL'])."'"); $res = $this->fetch_object(); $_SESSION['m_admin']['domain']['ID'] = $res->ID; if($_SESSION['history']['domainsadd'] == "true") { $users->add($_SESSION['tablename']['domains'], $_SESSION['m_admin']['domain']['ID'],"ADD", _DOMAIN_ADDED." : ".$_SESSION['m_admin']['domain']['LABEL']); } } for($i=0; $i < count($_SESSION['m_admin']['domain']['SERVICES']);$i++) { $this->query("insert into ".$_SESSION['tablename']['domain_service']." (ID_DOMAIN, ID_SERVICE) VALUES (".$_SESSION['m_admin']['domain']['ID'].", '".$_SESSION['m_admin']['domain']['SERVICES'][$i]['ID']."' )"); } $_SESSION['error'] = _DOMAIN_ADDED; } $_SESSION['error'] = ""; } if ($_REQUEST['mode'] == "add") { $url = "index.php?page=domains"; } $this->cleardomaininfos(); header("location: ".$url); exit; } } /** * delete a domain in the database * * @param string $id domain identifier */ public function deldomain($id) { if(!empty($_SESSION['error'])) { header("location: index.php?page=domains"); exit; } else { $this->connect(); $this->query("select ID, LABEL from ".$_SESSION['tablename']['domains']." where ID = ".$id); if($this->nb_result() == 0) { $_SESSION['error'] = _DOMAIN.' '._UNKNOWN; header("location: index.php?page=domains"); exit; } else { $res = $this->fetch_object(); $label = $res->LABEL; $this->query("delete from ".$_SESSION['tablename']['domains']." where ID = ".$id); $this->query("delete from ".$_SESSION['tablename']['domain_service']." where ID_DOMAIN = ".$id); if($_SESSION['history']['domainsdel']) { require_once("class_history.php"); $users = new history(); $users->add($_SESSION['tablename']['domains'], $id,"DEL",_DOMAIN_DELETION." : ".$label); } $_SESSION['error'] = _DELETED_DOMAIN; header("location: index.php?page=domains"); exit; } } } /** * get domain for one service (if filled) * * @param string $service_id service identifier */ public function get_domains($service_id='') { if (!empty ($service_id)) { if (is_array($service_id)) { $my_services = array(); foreach($service_id as $theService) { $my_services[] = "'".$theService."'"; } $where = "where ID_SERVICE in (".join(",", $my_services).")"; $grouby = "group by ID_DOMAIN"; } else { $where = "where ID_SERVICE = '".$service_id."'"; } } $domains = array(); $db = new dbquery(); $db->connect(); $db2 = new dbquery(); $db2->connect(); $db->query("select ID_SERVICE, ID_DOMAIN from ".$_SESSION['tablename']['domain_service']." ".$where." ".$grouby." order by ID_SERVICE asc "); //$db->show(); $actual_service = $save_service = ''; while($res = $db->fetch_object()) { $db2->query("select ID, LABEL from ".$_SESSION['tablename']['domains']." where ID = ".$res->ID_DOMAIN); $res2 = $db2->fetch_object(); $domains[$res->ID_SERVICE][] = array('ID' =>$res2->ID, 'LABEL' => $res2->LABEL); } return $domains; } public function get_domain_label($domain_id) { $label = ''; if (!empty ($domain_id)) { $this->connect(); $this->query("select LABEL from ".$_SESSION['tablename']['domains']." where ID = ".$domain_id); $res = $this->fetch_object(); $label = $res->LABEL; } return $label; } } ?>