getList.php 11.7 KB
Newer Older
Hamza Arfaoui's avatar
Hamza Arfaoui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
<?php

require_once("../../inc/confNetisse.php");
require_once("../functions.php");

if(!$_SESSION)
    session_start();

$TYPE = $_REQUEST["type"];
$JSON = isset($_REQUEST["json"]);
$filtre = isset($_REQUEST["filtre"]) ? $_REQUEST["filtre"] : "";
$values_filter = isset($_REQUEST["values"]) ? $_REQUEST["values"] : "";
$list = isset($_REQUEST["list"]) ? $_REQUEST["list"] : "";
$DATA = "";
switch($TYPE){
	case 'getMotif':
		$MID = intval($_REQUEST["mid"]);
		$q ="SELECT id_motif, titre FROM ca_motifs WHERE id_motif = :id_motif";
		$values = array(':id_motif' => $MID);
		$result = excuteQuery($q, $values);
		$r = $result['stmt'];
		$o = $r->fetchObject();
		$DATA = json_encode(array("id_motif"=>$o->id_motif, "titre"=>$o->titre));
	break;
	case 'getGuichet':
		$GID = intval($_REQUEST["gid"]);
		$AID = $_REQUEST["aid"];
		$q ="SELECT id_guichet, libelle FROM ca_guichets WHERE id_guichet = :id_guichet";
		$values = array(':id_guichet' => $GID);
		$result = excuteQuery($q, $values);
		$r = $result['stmt'];
		$o = $r->fetchObject();
		$DATA.= '<button type="button" id="btn-guichet'.$o->id_guichet.'" class="tablinks" onclick="openTab(event,\'guichett'.$o->id_guichet.'\', \'motifsGuichet'.$o->id_guichet.'\', '.$o->id_guichet.', '.$AID.')">'.$o->libelle.'</button>';
	break;
	case 'motifsByGuichet':
		$AID = intval($_REQUEST["aid"]);
		$GID = intval($_REQUEST["gid"]);
		$motifs = load_motifs($AID);
		$qgm ="
		SELECT id_motif, id_guichet
		FROM ca_guichet_motifs gm
		WHERE id_agence = :id_agence AND id_guichet=:id_guichet";
		$values = array(':id_agence' => $AID, ':id_guichet' => $GID);
		$mg = array();
		$result = excuteQuery($qgm, $values);
		$r = $result['stmt'];
		while ($o = $r->fetchObject()) {
			$mg[] = $o->id_motif;
		}
		foreach ($motifs as $motif)
		{
			if(in_array($motif->id_motif, $mg)){
				$DATA .= "<input type='checkbox' id='mo".$motif->id_motif."' name='motifsg".$GID."[]' class='guichets_checkbox' value='".$motif->id_motif."' checked /><span id='mo".$motif->id_motif."'>&nbsp;".$motif->titre."<br/></span>";
			}else{
				$DATA .= "<input type='checkbox' id='mo".$motif->id_motif."' name='motifsg".$GID."[]' class='guichdet_checkbox' value='".$motif->id_motif."' /><span id='mo".$motif->id_motif."'>&nbsp;".$motif->titre."<br/></span>";
			}
		}
	break;
	case 'getEntityOrientations':
		$values = array(':supp' => 0);
		if(isset($_REQUEST["aid"])){
			$agenceQ = isset($_REQUEST["aid"]) ? " AND id_agence=:id_agence" : "";
			$values[':id_agence'] = intval($_REQUEST["aid"]);
		}
		if(isset($_REQUEST["eid"])){
			$entiteQ = isset($_REQUEST["eid"]) ? " AND id_entite=:id_entite" : "";
			$values[':id_entite'] = intval($_REQUEST["eid"]);
		}
		$selected = isset($_REQUEST["selected"]) ? $_REQUEST["selected"] : null;
		$q2 = "SELECT id_orientation, orientation, texte, label FROM ca_orientations WHERE supp=:supp".$entiteQ.$agenceQ." ORDER BY id_orientation ASC";
		// echo $q2;
		$result = excuteQuery($q2, $values);
		$r2 = $result['stmt'];
		$n2 = $r2->rowCount();
		if ($n2 > 0)
		{
			$NBRDV = 0;
			$j=0;
			$firstRDV = true;
			while($o2 = $r2->fetchObject())
			{
				$OTYPE = $o2->label;
				$selected = ($o2->orientation == 2 && $firstRDV) ? ' selected' : '';
				$DATA .= "<option value='".$o2->id_orientation."' ".$selected.">".$OTYPE."</option>";
				if($o2->orientation == 2){
					$firstRDV = false;
				}
			}
		}
	break;
	case 'entity':
		$values = array(':supp' => 0);
		if(isset($_REQUEST["aid"])){
			$agenceQ = isset($_REQUEST["aid"]) ? " AND id_agence=:id_agence" : "";
			$values[':id_agence'] = intval($_REQUEST["aid"]);
		}
		
		
		$q2 = "SELECT id_entite, libelle FROM ca_entites WHERE supp=:supp".$agenceQ." ORDER BY id_entite ASC";
		// echo $q2;
		$result = excuteQuery($q2, $values);
		$r2 = $result['stmt'];
		$n2 = $r2->rowCount();
		if ($n2 > 0)
		{
			$NBRDV = 0;
			$j=0;
			$DATA .= "<option value=''>Sélectionner une entité</option>"; 
			while($o2 = $r2->fetchObject())
			{
				$OTYPE = $o2->label;
				$DATA .= "<option value='".$o2->id_entite."' ";
				$DATA .=">".$o2->libelle."</option>";
			}
		}
	break;
	case 'agents':
		$AID = $_REQUEST["aid"];
		$values = array(':supp1' => 0, ':supp2' => 0);
		if($filtre && $AID && ($filtre!='-1')){
			$values[':id_agence1'] = $AID;
			$values[':id_agence2'] = $AID;
		}
		if($filtre && !$AID && ($filtre!='-1')){
			// $values[':id_agence'] = $AID;
		}
	
		$GS3 = $GLOBALS["BO_CONF"]["GS3"] ? ", gs3" : "";
		$created_fromQ = $GLOBALS["PILE_CONF"]["AGENT_FORM"] ? ', created_from' : '';
		$query = "SELECT cns.id_conseiller, cns.id_agence, cns.nom, prenom, email".$created_fromQ.", photo, part, pro, cns.inactif, f.libelle as fonction, p.nom as profil, id_agent, ca.temporaire, IF(cns.id_agence = $AID, 1, 0) agence_origine, '0' as mobile, e.libelle, a.nom_agence, e.borne_color,
		TIMESTAMPDIFF(SECOND,ca.last_active,now()) last_active_sec
		".$GS3."
		FROM ca_conseiller_agence ca
		LEFT JOIN ca_conseillers cns ON cns.id_conseiller = ca.id_conseiller
		LEFT JOIN ca_agences a ON cns.id_agence = a.id_agence ";
		if(!empty($_REQUEST["aid"])){
			//$query .= "LEFT JOIN ca_entites e ON ca.id_entite = e.id_entite ";
			$query .= "LEFT JOIN ca_entites e ON CASE WHEN ca.id_agence = $AID
														THEN e.id_entite = ca.id_entite
													  WHEN ca.id_agence != $AID
													  THEN ca.id_entite = cns.groupe END ";
		}else{
			$query .= "LEFT JOIN ca_entites e ON e.id_entite = cns.groupe ";
		}
		
		$query .= "LEFT JOIN ca_fonctions f ON ca.id_fonction = f.id_fonction
		LEFT JOIN ca_profils p ON ca.id_profile = p.id_profil
		WHERE cns.supp=:supp1 AND a.supp=:supp2".$filtre."
		GROUP BY id_conseiller";
		
		if($AID && !$GLOBALS["BO_CONF"]["SHOW_AFFECTION_COLUMN"]){
			$query .= " HAVING agence_origine = 1";
		}
		$DATA = array();
		$result = excuteQuery($query, $values);
		if (!$result['status']) 
        wts_die (var_dump($result['stmt']->errorInfo()));
		$res = $result['stmt'];
		$DATA["sEcho"] = 3;
		$DATA["iTotalRecords"] = $DATA["iTotalDisplayRecords"] = $res->rowCount();
		$DATA["aaData"] = array();
		while($agent = $res->fetchObject()) {
			
			if($GLOBALS["BO_CONF"]["SHOW_AFFECTION_COLUMN"] && !empty($_REQUEST["aid"])){
				if($agent->agence_origine != 0){
					$affectation = '<span style="background-color: green;color: #FFF;padding: 5px;display: block;width: 55%;margin-left: 20%;">Principale</span>';
				}elseif(($agent->agence_origine == 0)&&($agent->temporaire == 0)){
					$affectation = '<span style="background-color: #1ea1f3;color: #FFF;padding: 5px;display: block;width: 55%;margin-left: 20%;">Rattaché</span>';
				}elseif(($agent->agence_origine == 0)&&($agent->temporaire == 1)){
					$affectation = '<span style="background-color: #757575;color: #FFF;padding: 5px;display: block;width: 55%;margin-left: 20%;">Temporaire</span>';
				}
				
			}
			$INACTIF = "";
			if ($agent->inactif == 0) {
				$INACTIF .= "<span>Actif</span><div class='status-preview green' data-id='".$agent->id_conseiller."' data-tostatus='1'></div>";
			} else {
				$INACTIF .= "<span>Inactif</span><div class='status-preview red' data-id='".$agent->id_conseiller."' data-tostatus='0'></div>";
			}
			$src_img = $agent->photo;
			$row = array();
			if($GLOBALS["BO_CONF"]["SHOW_AFFECTION_COLUMN"] && !empty($_REQUEST["aid"])){
				$row[] = $affectation;
				// array_unshift($row, $affectation);
				// $i = 6;
			}
			$has_star_icon = '';
			if($created_fromQ != ""){
			$has_star_icon =  $agent->created_from == 1 ? ' <span style="color: red;font-size: 12px;position: absolute;font-weight: bold;">*</span>': '';
			}
			$row[] = $agent->nom.$has_star_icon;
			$row[] = $agent->prenom;
			$row[] = $agent->id_agent;
		    
		    
			if($GLOBALS["BO_CONF"]["GS3"] == TRUE){
				$gs3 = $agent->gs3 ? $agent->gs3 : "";
				//array_splice($row, 3, 0, $gs3);
				$row[] = $gs3;
			}	
			$row[] = ($agent->profil ? $agent->profil : 'Conseiller');
			if(empty($_REQUEST["aid"])){
		    	$row[] = $agent->nom_agence;
		    }
			if($GLOBALS["BO_CONF"]["ENTITIES"] == TRUE){
				$entite = $agent->libelle ? $agent->libelle : "&nbsp;";
				$row[] = $entite;
				// if(!empty($filtre)){
				// 	array_splice($row, $i-1, 0, $entite);
				// }else{
				// 	array_splice($row, $i, 0, $entite);
				// }
				
			}
			$row[] = "<img style='background-color:".$agent->borne_color."' src='".$SERVER.$src_img."' width='auto' height='48'/>";
		    $row[] = $INACTIF;
			$i = 5;
			
			if(in_array("edit_agence_agents",$_SESSION['permissions'])) {
				$disable = "";
			}else{
				$disable = "style='pointer-events: none;cursor: default;color:#ccc;'";
			}
					
			if((in_array("edit_agence_agents",$_SESSION['permissions']) && $_SESSION['agence'] == $agent->id_agence || in_array($agent->id_agence, $_SESSION['agences'])) || in_array("edit_all_agents",$_SESSION['permissions'])) {
				if(in_array("edit_all_agents",$_SESSION['permissions']) || (in_array("edit_agence_agents",$_SESSION['permissions']) && in_array($agent->id_agence, $_SESSION['agences']))) {
					$disable = "";
				}else{
					$disable = "style='pointer-events: none;cursor: default;color:#ccc;'";
				}
				$actions = "<a ".$disable." ".$disable." href='cnsUpd.php?aid=".$agent->id_agence."&cid=".$agent->id_conseiller."'>Editer</a>";
				if(in_array("AR",$GLOBALS["BORNE_CONF"]["LANGUAGES"])){
					$actions .= "&nbsp;<a href='cnsTranslate.php?cid=".$agent->id_conseiller."&lang=ar'>Traduire</a>";
				}
				$row[] = $actions;
			}
			else{
				$disable = "";
				if(in_array("edit_all_agents",$_SESSION['permissions']) || (in_array("edit_agence_agents",$_SESSION['permissions']) && in_array($agent->id_agence, $_SESSION['agences']))) {
					$disable = "";
				}else{
					$disable = "style='pointer-events: none;cursor: default;color:#ccc;'";
				}
				$row[] = "<a ".$disable." href='cnsUpd.php?aid=".$agent->id_agence."&cid=".$agent->id_conseiller."'>Editer</a>";
			}
			if(!empty($_REQUEST["aid"])){
			      if($agent->agence_origine == 1){
			              $DATA["aaData"][] = $row;
			      }else{
			      	if($agent->temporaire == 1){
			      		if(intval($agent->last_active_sec) < 15){
							$DATA["aaData"][] = $row;
				      	}else{
				      	}
			      	}else{
			      		$DATA["aaData"][] = $row;
			      	}
			      	
			      }
			      
			      
			}
			else{ // AID
			     if(!$GLOBALS["BO_CONF"]["SHOW_AFFECTION_COLUMN"] && ($agent->temporaire = 0 || $agent->agence_origine=0)){
			       } 
			      else{

			           $DATA["aaData"][] = $row;
			     }
			     
			}
		}
	break;
	case 'agenciesInPopup':
		$status = $_REQUEST['status'];
		$qagcByProfil =$_SESSION['profil'] != 100 ? " AND id_agence IN (SELECT id_agence FROM ca_links WHERE id_admin = ". intval($_SESSION["id"]) .")" :"" ;
		$query = "SELECT nom_agence, eds FROM ca_agences WHERE supp = 0 AND is_active = ".$status.$qagcByProfil;
		$result = excuteQuery($query);
		$DATA .= "<div style='margin-left: 7%;margin-top: 16px;margin-bottom: 16px;overflow-y: auto;height: 200px;'>
		<table style='width: 97%;border-collapse: collapse;font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif;'><tbody style='height:50px;overflow:scroll;'>";
		$DATA .= "<tr><th style='border: 1px solid #ddd;padding: 8px;background-color: #757575;color: white;'>EDS</th><th style='border: 1px solid #ddd;padding: 8px;background-color: #757575;color: white;'>Nom</th></tr>";
		while ($o = $result['stmt']->fetchObject()) {
			$DATA .= '<tr><td style="border: 1px solid #ddd;padding: 8px;">'.$o->eds.'</td><td style="border: 1px solid #ddd;padding: 8px;">'.$o->nom_agence.'<td></tr>'; 
		}
		$DATA .= "</tbody></table></div>";
	break;
	case 'getOrientationMessage':
		$OID = $_REQUEST['oid'];
		$q = "SELECT texte FROM ca_orientations WHERE id_orientation=:id_orientation";
		$v = array(':id_orientation' => $OID);
		$result = excuteQuery($q,$v);
		$DATA = $result['stmt']->fetchObject()->texte;
	break;
}
if($JSON){
	echo json_encode($DATA);
}
else{
	echo $DATA;
}
?>