0byt3m1n1
Path:
/
home
/
k
/
a
/
s
/
kassiope
/
www
/
administrer
/
[
Home
]
File: profils.php
<? include("../configuration.inc.php"); necessite_identification(); necessite_priv("admin"); $DOC_TITLE = "Gestion des profils"; include("modeles/haut.php"); $start = vn($_REQUEST['start']);// Détermine la variable start (début de page) switch (vb($_REQUEST['mode'])) { case "ajout" : affiche_formulaire_ajout_profil(); break; case "positionner" : if (isset($_POST['id'])) { for($i=0;$i<count($_POST['id']);$i++) { mysql_query_override("UPDATE gaia_profils SET position = '".$i."' WHERE id = '".intval($_POST['id'][$i])."'"); } } echo '<div class="alert alert-success">Le positionnement des profils a été effectué.</div>'; affiche_liste_profil($start); break; case "modif" : affiche_formulaire_modif_profil($_GET['id']); break; case "suppr" : supprime_profil($_GET['id']); affiche_liste_profil($start); break; case "insere" : insere_profil($_POST['id'], $_POST); affiche_liste_profil($start); break; case "maj" : maj_profil($_POST['id'], $_POST); affiche_liste_profil($start); break; default : affiche_liste_profil($start); break; } include("modeles/bas.php"); /****************************************************************************** * FONCTIONS *****************************************************************************/ function affiche_formulaire_ajout_profil() { /* Affiche un formulaire vierge pour ajouter un profil */ global $frm; /* Valeurs par défaut */ $frm['nouveau_mode'] = "insere"; $frm['id'] = ""; foreach ($_SESSION['lng'] as $lng) { $frm['nom_'.$lng.''] = ""; } $frm['prix'] = ""; $frm['signe'] = ""; $frm['prix_revendeur'] = ""; $frm['titre_bouton'] = "Ajouter un profil"; affiche_formulaire_profil(); } function affiche_formulaire_modif_profil($id) { /* Affiche le formulaire de modification pour le profil sélectionné */ global $frm; /* Charge les informations du produit */ $qid = mysql_query_override("SELECT * FROM gaia_profils WHERE id = $id"); $frm = mysql_fetch_array_override($qid); $frm['id'] = $id; $frm["nouveau_mode"] = "maj"; $frm["titre_bouton"] = "Sauvegarder changements"; affiche_formulaire_profil(); } function affiche_formulaire_profil() { GLOBAL $frm,$wwwroot; ?> <form name="entryform" method="post" action="<?=$_SERVER['PHP_SELF']?>?start=0"> <input type="hidden" name="mode" value="<?=$frm["nouveau_mode"]?>"> <input type="hidden" name="id" value="<?=$frm['id']?>"> <input type="hidden" name="prix" value="0"> <input type="hidden" name="prix_revendeur" value="0"> <input type="hidden" name="signe" value="0"> <table class="tablespace" border="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <th class="entete" colspan="2">Ajouter ou modifier un profil</th> </tr> <?php $nblng = count($_SESSION['lng']); foreach ($_SESSION['lng'] as $lng) { ?> <? echo (($nblng>1)?'<tr><td colspan="2" class="menu">BLOC DE LANGUE '.strtoupper($lng).'</td></tr>':'')?> <tr> <td>Nom <?echo $lng ?>:</td> <td><input type="text" name="nom_<?echo $lng ?>" value="<?=$frm['nom_'.$lng.''] ?>"></td> </tr> <? } ?> <!-- <tr> <td>Prix : <br /><i>(non obligatoire, prix affiché pour une gestion multiprix de vos produits)</i></td> <td> <div class="input-group"> <input type="text" name="prix" class="input-small" value="<?=str_replace("-","",$frm["prix"])?>"><span class="add-on">€ TTC</span> </div> </td> </tr> <tr> <td>Prix revendeur : <br /><i>(non obligatoire, prix affiché pour une gestion multiprix de vos produits)</i></td> <td> <div class="input-group"> <input type="text" name="prix_revendeur" class="input-small" value="<?=str_replace("-","",$frm["prix_revendeur"])?>"><span class="add-on">€ TTC</span> </div> </td> </tr> <tr> <td>Signe</td> <td><select name="signe" class="form-control"><option value="+" <? if ($frm['signe'] == "+") {echo " selected";}?>>+</option><option value="-" <? if ($frm['signe'] == "-") {echo " selected";}?>>-</option></select></td> </tr> --> <tr> <td colspan="2" class="bouton" align="center"><input type="button" onclick="history.go(-1)" value="Annuler"><input type="submit" value="<?=$frm["titre_bouton"] ?>"></td> </tr> </table> </form> <? } function supprime_profil($id) { /* Supprime le profil spécificié par $id. Il faut supprimer le profil * puis les entrées correspondantes de la table profil_categories. */ $qid = mysql_query_override("SELECT nom_".$_SESSION['langue']." FROM gaia_profils WHERE id = $id"); $col = mysql_fetch_array_override($qid); /* Efface le profil */ $qid = mysql_query_override("DELETE FROM gaia_profils WHERE id = $id"); /* Efface ce profil de la table produits_profil */ $qid = mysql_query_override("DELETE FROM gaia_produits_profils WHERE profil_id = $id"); echo '<div class="alert alert-error">Le profil a été effacé <button type="button" class="close" data-dismiss="alert">×</button></div>'; } function insere_profil($id, $frm) { $prix = $frm['signe'].$frm['prix']; $prix_revendeur = $frm['signe'].$frm['prix_revendeur']; /*ajoute le profil dans la table profil */ $sql ="INSERT INTO gaia_profils (prix"; foreach ($_SESSION['lng'] as $lng) { $sql .= ", nom_".$lng.""; } $sql .= ", prix_revendeur, signe) VALUES ('".$prix."'"; foreach ($_SESSION['lng'] as $lng) { $sql .= ", '".htmlspecialchars($frm['nom_'.$lng.''], ENT_QUOTES)."'"; } $sql .= ", '".$prix_revendeur."','".$frm['signe']."')"; mysql_query_override($sql) or DIE('Une erreur de connexion à la base s est produite ' . __LINE__ . '.<p>' . MYSQL_ERROR()); echo '<div class="alert alert-success">Le profil a été ajouté <button type="button" class="close" data-dismiss="alert">×</button></div>'; } function maj_profil($id, $frm) { /* Met à jour le profil $id avec de nouvelles valeurs. Les champs sont dans $frm */ $prix = $frm['signe'].$frm['prix']; $prix_revendeur = $frm['signe'].$frm['prix_revendeur']; /* Met à jour la table profil */ $sql = "UPDATE gaia_profils SET prix = '".$prix."'"; foreach ($_SESSION['lng'] as $lng) { $sql .= ", nom_".$lng." = '".htmlspecialchars($frm['nom_'.$lng.''], ENT_QUOTES)."'"; } $sql .= ", prix_revendeur = '".$prix_revendeur."',signe ='".$frm['signe']."' WHERE id = '$id'"; mysql_query_override($sql) or DIE('Une erreur de connexion à la base s est produite ' . __LINE__ . '.<p>' . MYSQL_ERROR()); echo '<div class="alert alert-success">Le profil a été modifié <button type="button" class="close" data-dismiss="alert">×</button></div>'; } function affiche_liste_profil($start) { ?> <form name="entryform" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <input type="hidden" name="mode" value="positionner"> <table class="tablespace" width="100%" cellpadding="0" cellspacing="0"> <tr> <th class="entete" colspan="5">Gérer les profils</th> </tr> <tr> <td colspan="5" class="action"><a href="<?=$_SERVER['PHP_SELF']?>?mode=ajout"> Ajouter un profil</a></td> </tr> <? $result=mysql_query_override("SELECT id, position, nom_".$_SESSION['langue'].", prix, prix_revendeur FROM gaia_profils ORDER BY prix, position"); if (mysql_num_rows_override($result) == 0) {echo "<tr><td class=normal><b>Aucun profil enregistré dans la base.</b></td></tr>"; } else { ?> <tr> <td class="menu">Action</td> <td class="menu">Système</td> <!-- <td class="menu" align="center">Prix</td> <td class="menu" align="center">Revendeur</td> --> </tr> <tbody id="sortable"> <? $i = 0; while ($ligne = mysql_fetch_array_override($result)) { ?> <tr> <td style="width:250px"> <input type="hidden" name="id[]" value="<?=$ligne['id']?>"> <i style="cursor:pointer; margin-right:10px" title="Tirer pour déplacer" rel="tooltip" class="icon-reorder"></i> <a href="#myModal<?=$ligne['id']?>" role="button" data-toggle="modal" title="Supprimer" rel="tooltip" ><i class="ti-close"></i></a> <a title="Modifier" rel="tooltip" href="<?=$_SERVER['PHP_SELF']?>?mode=modif&id=<?=$ligne['id'] ?>"><i class="ti-pencil"></i></a> </td> <td style="width:250px"><a title="Modifier ce profil" href="<?=$_SERVER['PHP_SELF']?>?mode=modif&id=<?=$ligne['id'] ?>"><?=$ligne['nom_'.$_SESSION['langue'].''] ?></a></td> <!-- <td style="width:300px" align="center"><? if ($ligne['prix'] != 0) { echo fprix($ligne['prix'])." €"; } else {echo "n.a";} ?></td> <td align="center"><? if ($ligne['prix_revendeur'] != 0) { echo fprix($ligne['prix_revendeur'])." €"; } else {echo "n.a";} ?></td> --> </tr> <div id="myModal<?=$ligne['id']?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Supprimer</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <p>Êtes-vous sur de vouloir supprimer cet enregistrement ?</p> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">Annuler</button> <a class="btn btn-primary" href="<?=$_SERVER['PHP_SELF']?>?mode=suppr&id=<?=$ligne['id'] ?>">Supprimer</a> </div> </div> </div> </div> <? $i++; } echo '</tbody>'; } echo '<tr><td colspan="4" align="center" class="bouton" style="background:#fff"><input type="submit" value="Positionner les profils"></td></tr>'; echo "</table></form>"; } ?>