agcMsgUpd.php 11.3 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
<?php
require_once("../inc/confNetisse.php");

session_start();
if (!isset($_SESSION['auth'])) {
    header("location:index.php");
}

if (!in_array("edit_all_orientations", $_SESSION['permissions']) && !in_array("edit_own_orientations", $_SESSION['permissions'])) {
    header("location:dashboard.php");
}

$s2 = "";
$multilang = (isset($GLOBALS["BORNE_CONF"]["LANGUAGES"]) && count($GLOBALS["BORNE_CONF"]["LANGUAGES"]) > 1) ? true : false;

$AID = $EID = 0;
if (!isset($_GET["aid"])) {
    header("location:agcList.php");
} else {
    $AID = intval($_GET["aid"]);
    $EID = intval($_GET["eid"]);
}

$M = intval($_GET["m"]);
$N = $_GET["n"];
$L = isset($_REQUEST['lang']) ? strtolower($_REQUEST['lang']) : 'fr';
$o_supp = 0;

if ($EID > 0) {
    $q = "SELECT e.id_entite, e.libelle, a.nom_agence FROM ca_entites e LEFT JOIN ca_agences a ON a.id_agence = e.id_agence WHERE e.id_entite=:id_entite";
    $values = array(':id_entite' => $EID);
	$result = excuteQuery($q, $values);
	$r = $result['stmt'];
    $o = $r->fetchObject();
    $NOMENTITE = "l'entité " . $o->libelle;
    $NOMAGENCE = "l'agence " . $o->nom_agence;
    if ($r->rowCount() == 0) {
        header("location:entList.php?aid=" . $AID);
    }
} else {
    $q = "SELECT nom_agence FROM ca_agences WHERE id_agence=:id_agence";
    $values = array(':id_agence' => $AID);
    $result = excuteQuery($q, $values);
	$r = $result['stmt'];
    $o = $r->fetchObject();
    $NOMENTITE = "l'agence " . $o->nom_agence;
    if ($r->rowCount() == 0) {
        header("location:agcList");
    }
}
$multilangCol = ", o.texte";
$valuesBind = array();
$typesBind = "";
if ($multilang) {
    $multilangCol = ", ol.texte";
    $multilangJoin = "LEFT JOIN ca_orientations_lang ol ON ol.id_orientation = o.id_orientation AND ol.id_lang=:id_lang";
    $valuesBind[':id_lang'] = $L;
}

$q2 = "SELECT o.id_orientation, o.orientation" . $multilangCol . ", o.label, o.salle, o.default_msg FROM ca_orientations o " . $multilangJoin . " WHERE o.id_agence=:id_agence AND o.supp=:supp AND o.id_orientation=:id_orientation";


$valuesBind [':id_agence'] = $AID;
$valuesBind [':supp'] = $o_supp;
$valuesBind [':id_orientation'] = $M;
$stmt = excuteQuery($q2, $valuesBind);
$j = count($values);
if ($stmt['status']) {
	$result = $stmt['stmt'];
	$nb = $result->rowCount();
	if ($nb > 0){
		while ($o2 = $result->fetchObject()) {
			$TYPE = $o2->label;
			$ORIENTATION = $o2->orientation;
			$TEXTE = strip_tags($o2->texte, '<br>');
			$LABEL = $o2->label;
			$SALLE = $o2->salle;
		}
	}
} else {
	wts_die($stmt->error);
}

$langs = "";
if ($multilang) {
    foreach ($GLOBALS["BORNE_CONF"]["LANGUAGES"] as $lang) {
        $langs .= "<option value='" . strtolower($lang) . "'";
        $langs .= (strtolower($lang) == $L) ? " selected" : "";
        $langs .= ">" . $lang . "</option>";
    }
}

$q3 = "SELECT count(1) nb FROM ca_conseillers WHERE supp = :supp AND orientation = :orientation";
$v3 = array(':supp' => 0, ':orientation' => $M);
$result = excuteQuery($q3, $v3);
$r3 = $result['stmt'];
$o3 = $r3->fetchObject();
$NB = $o3->nb;

$MAXWIDTHSALLE = isset($GLOBALS["BO_CONF"]["IMAGES"]["salle"]["width"]) ? $GLOBALS["BO_CONF"]["IMAGES"]["salle"]["width"] : 830;
$MAXHEIGHTSALLE = isset($GLOBALS["BO_CONF"]["IMAGES"]["salle"]["height"]) ? $GLOBALS["BO_CONF"]["IMAGES"]["salle"]["height"] : 600;
//salle dimensions for siege agency
if($GLOBALS["BO_CONF"]["AGENCE"]["SIEGE"] && $GLOBALS["BO_CONF"]["AGENCE"]["SIEGE"]["CHOICES"]){
	$q_agency_siege = "SELECT siege FROM ca_agences WHERE id_agence = ".$AID." LIMIT 1";
	$stmt_agency_siege = excuteQuery($q_agency_siege);
	$res_agency_siege = $stmt_agency_siege["stmt"];
	$o_agency_siege = $res_agency_siege->fetchObject();
	if($o_agency_siege->siege == 1){
		$MAXWIDTHSALLE = isset($GLOBALS["BO_CONF"]["AGENCE"]["SIEGE"]["IMAGES"]["salle"]["width"]) ? $GLOBALS["BO_CONF"]["AGENCE"]["SIEGE"]["IMAGES"]["salle"]["width"] : 830;
		$MAXHEIGHTSALLE = isset($GLOBALS["BO_CONF"]["AGENCE"]["SIEGE"]["IMAGES"]["salle"]["height"]) ? $GLOBALS["BO_CONF"]["AGENCE"]["SIEGE"]["IMAGES"]["salle"]["height"] : 600;
	}
}
?>

<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><?php echo $PROJECT_TITLE;?> : Edition des messages d'une agence</title>
	<link rel="stylesheet" type="text/css" href="css/cans/jquery-ui-1.8.17.custom.css" />
	<link rel="stylesheet" href="css/font-awesome.min.css" />
	<link rel="stylesheet" type="text/css" href="css/cadif.css" />
	<link rel="stylesheet" type="text/css" href="css/dashboard.css" />
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="js/jquery-ui-1.8.22.custom.min.js"></script>
	<script type="text/javascript">
		<?php echo 'var nbUsed = $NB;';?>
		function delMsg() {
			if(nbUsed){
				if (confirm("Le message que vous allez supprimer est affecté à des conseillers. \nLe message qui sera affiché après la suppression sera le RDV1.\nConfirmez-vous cette suppression ?")) {
					document.getElementById("supp").value = 1;
					document.formAgencyMsgUpd.submit();
				} else {
					document.getElementById("supp").value = 0;
				}
			}
			else{
				document.getElementById("supp").value = 1;
				document.formAgencyMsgUpd.submit();
			}

		}

		function checkMax(obj,maxlength){
		  if (obj.value.length > maxlength) {
		    obj.value = obj.value.substring(0, maxlength);
		    var POP = $('<div></div>').html("<center>Votre message est trop long. Merci de le raccourcir.</center>").dialog({autoOpen: false,title: 'Erreur'});
			POP.dialog({autoOpen:false, modal:true, draggable: false, width:360,close:function(ev, ui){document.getElementById(obj).focus();} });
			POP.dialog("open");
		   }
		}

		function checkForm() {
			if (document.getElementById("label").value == "") {
				var POP = $('<div></div>').html("<center>Vous devez renseigner le champ 'Label'.</center>").dialog({autoOpen: false,title: 'Erreur'});
				POP.dialog({autoOpen:false, modal:true, draggable: false, width:360,close:function(ev, ui){document.getElementById("label").focus();} });
				POP.dialog("open");
			} else if (document.getElementById("texte").value == "") {
				var POP = $('<div></div>').html("<center>Vous devez renseigner le champ 'Texte'.</center>").dialog({autoOpen: false,title: 'Erreur'});
				POP.dialog({autoOpen:false, modal:true, draggable: false, width:360,close:function(ev, ui){document.getElementById("texte").focus();} });
				POP.dialog("open");
			} else {
				document.formAgencyMsgUpd.submit();
			}
		}

		function addBloc() {
			document.getElementById('bloc').innerHTML = document.getElementById('bloc').innerHTML + "<tr><td></td><td class='agencyRub'><br/>Message <select name='newtype[]' size='1'><option>Type de message</option><option value='0'>Sans rendez-vous</option><option value='1'>Avec Rendez-vous</option></select></td></tr><tr><td>Titre</td><td><textarea name='newtitre[]' id='titre' onkeyup='javascript:checkMax(this, 48);'></textarea></td></tr><tr><td>Texte</td><td><textarea name='newtexte[]' id='texte' onkeyup='javascript:checkMax(this, 75);'></textarea></td></tr>";
		}

		function toggleUpload(){
			$("#cnsUpload").show();
			$("#uploadLink").hide();
		}
	</script>
</head>


<body>

<div id="global">

	<div id="home">
		<div id="logo"><a href="dashboard.php"><img src="<?php echo $SERVER; ?>assets/img/logo.png" height="110" border="0"/></a></div>
		<div id="username">
			<b><?php echo isset($_SESSION["nom"]) ? $_SESSION["nom"] : $_SESSION["matricule"];?></b> &nbsp; | &nbsp; <a href="close.php" class="link" title="Fermer et clore votre session">D&#233;connexion</a>
			<br/>
		</div>
	</div>
	<div id="panels">
	  <?php include "menu.php";?>
	  <div class="main-content">
		<div id="title">
			Nouveau message pour <?php echo $GLOBALS["BO_CONF"]["ENTITIES"]?$NOMENTITE:$NOMAGENCE;?>
		</div>
		<?php if($nb === 0){ echo "Pas de données";	} else{	?>
		<div id="panelsedit">
			<div id="formCns">
			<form name="formAgencyMsgUpd" id="formAgencyMsgUpd" action="do.php" method="post" enctype="multipart/form-data">
				<input type="hidden" name="act" value="agencyMsgUpd"/>
				<input type="hidden" name="aid" value="<?php echo $AID; ?>"/>
				<input type="hidden" name="eid" value="<?php echo $EID; ?>"/>
				<input type="hidden" name="m" id="m" value="<?php echo $M;?>"/>
				<input type="hidden" name="supp" id="supp" value="0"/>
				<input type="hidden" name="type" id="type" value="<?php echo $ORIENTATION; ?>"/>
				<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
				<input type="hidden" name="lang" value="<?php echo $L;?>" />

				<table align="center" class="form">
				<tr>
				<td></td>
				<td class='agencyRub'><br/><?php echo $TYPE;?><br/><br/></td>
				</tr>
				<?php if($multilang){ ?>
				<tr>
				<td>Langue</td>
				<td><select disabled><?php echo $langs;?></select></td>
				</tr>
				<?php } ?>
				<tr>
				<td>Label</td>
				<td><input name="label" id="label" type="text" value="<?php echo $LABEL;?>" style="width: 200px;margin:10px 0"  tabindex="1"/></td>
				</tr>
				<tr>
				<td>Texte</td>
				<td><textarea tabindex="2" name="texte" id="texte" onkeyup="javascript:checkMax(this, 280);" style="height:100px;"><?php echo $TEXTE;?></textarea></td>
				</tr>
				<tr>
				<td>Salon d'attente</td>
				<td>
					<?php if($SALLE != ""){?>
					<center><img src="<?php echo $SERVER.$SALLE;?>" width="300" height="auto" border="0"/></center>
					<br/>
					<a href="javascript:toggleUpload();" id="uploadLink">Modifier l'image de salon d'attente</a>
					<?php }else{ ?>
					<a href="javascript:toggleUpload();" id="uploadLink">Ajouter une image de salon d'attente</a>
					<?php } ?>
					<div id="cnsUpload" style="display:none">
						<span class="cnsPhotoText">
							<b><u>Caract&#233;ristiques du fichier</u> :</b>
							<br/>
							Poids maximum : 1 Mo.
							<br/>
							Type de fichier : JPG.
							<br/>
							Dimensions attendues :<br/>Largeur: <?php echo $MAXWIDTHSALLE;?> pixels. | Hauteur : <?php echo $MAXHEIGHTSALLE;?> pixels.
						</span>
						<br/><br/>
						<input type="file" name="salle" id="salle" size="30" style="width: 200px;" tabindex="3" accept="image/*"/>
					</div>
				</td>
				</tr>
				<tr>
				<td></td>
				<td>
					<br/><br/>
					<?php if($o2->default_msg == 0 && (in_array("delete_all_orientations",$_SESSION['permissions']) || (in_array("delete_own_orientations",$_SESSION['permissions']) && in_array($AID,$_SESSION['agences'])))) {?>
					<input type="button" class="formAct" name="supprimer" id="supprimer" value="Supprimer le message" onclick="delMsg();" tabindex="9"/>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<?php } ?>
					<input type="button" class="formAct" name="valider" id="valider" value="Valider" onclick="checkForm();" tabindex="4"/></td>
				</tr>
				</table>
			</form>
			</div>
		</div>
		<div id="nav">
			<?php if(in_array("edit_all_agences",$_SESSION['permissions']) || in_array("edit_own_agence",$_SESSION['permissions'])){
				if($GLOBALS["BO_CONF"]["ENTITIES"]){
					$link = "orientationList.php?aid=".$AID."&eid=".$EID;
				?>
			<a href="<?php echo $link; ?>" class='formNav'>Retour</a><!--href='agcUpd.php?aid=<?php echo $AID;?>' -->
			<?php }else{
				$link = "orientationList.php?aid=".$AID;
			?>
			<a href="<?php echo $link; ?>" class='formNav'>Retour</a>
			<?php
			}
			} ?>
		</div>
		<?php } ?>
	  </div>
	</div>

</div>

<?php include 'footer.php';?>

<script>
document.getElementById('type').focus();
</script>

</body>

</html>