0byt3m1n1
Path:
/
home
/
k
/
a
/
s
/
kassiope
/
www
/
administrer
/
[
Home
]
File: codes_promos - Copie.php
<? include("../configuration.inc.php"); necessite_identification(); necessite_priv("admin"); $DOC_TITLE = "Gestion des codes promotionnels"; include("modeles/haut.php"); $start = intval(vn($_REQUEST['start'])); $mode = htmlspecialchars(vb($_REQUEST['mode'])); switch ($mode) { case "ajout" : affiche_formulaire_ajout_code_promo(); break; case "modif" : affiche_formulaire_modif_code_promo(intval($_GET['id'])); break; case "suppr" : supprime_code_promo(intval($_REQUEST['id'])); affiche_liste_code_promo($start); break; case "insere" : insere_code_promo($_POST); affiche_liste_code_promo($start); break; case "maj" : maj_code_promo(intval($_REQUEST['id']), $_POST); affiche_liste_code_promo($start); break; default : affiche_liste_code_promo($start); break; } include("modeles/bas.php"); /****************************************************************************** * FONCTIONS *****************************************************************************/ function affiche_formulaire_ajout_code_promo() { global $frm; /* Valeurs par défaut */ $frm["nouveau_mode"] = "insere"; $frm["nom"] = ""; $frm["date_debut"] = ""; $frm["date_fin"] = ""; $frm["remise"] = ""; $frm["titre_bouton"] = "Ajouter un code promotionnel"; affiche_formulaire_code_promo(); } function affiche_formulaire_modif_code_promo($id) { global $frm; /* Charge les informations du produit */ $qid = mysql_query_override(" SELECT * FROM gaia_codes_promos WHERE id = '".$id."' "); $frm = mysql_fetch_array_override($qid); $frm["nouveau_mode"] = "maj"; $frm["titre_bouton"] = "Sauvegarder changements"; affiche_formulaire_code_promo(); } function affiche_formulaire_code_promo() { global $frm; global $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="<?=vn($frm['id'])?>"> <table border="0" width="100%" cellspacing="0" cellpadding="0" class="tablespace"> <tr> <th class="entete" colspan="2">Ajouter un code promotionnel</th> </tr> <tr> <td>Code :</td> <td><input class="input-medium" type="text" name="nom" value="<?=vb($frm["nom"])?>"></td> </tr> <tr> <td>Date début : <br /> <i>(JJ/MM/AAAA)</i></td> <td> <? $frm['date_debut'] = date('d/m/Y', strtotime($frm['date_debut'])); ?> <div class="input-group date" rel="datepicker" data-date="12-02-2012" data-date-format="dd/mm/yyyy"> <input class="form-control" name="date_debut" size="16" readonly="readonly" type="text" value="<?=vb($frm["date_debut"])?>"> <span class="add-on"><i class="icon-calendar icon-large"></i></span> </div> </td> </tr> <tr> <td>Date fin : <br /> <i>(JJ/MM/AAAA)</i></td> <td> <? $frm['date_fin'] = date('d/m/Y', strtotime($frm['date_fin'])); ?> <div class="input-group date" rel="datepicker" data-date="12-02-2012" data-date-format="dd/mm/yyyy"> <input class="form-control" name="date_fin" size="16" readonly="readonly" type="text" value="<?=vb($frm["date_fin"])?>"> <span class="add-on"><i class="icon-calendar icon-large"></i></span> </div> </td> </tr> <tr> <td>Remise :</td> <td> <div class="input-group"> <input type="text" name="remise" class="form-control" value="<?=vb($frm['remise']) ?>"><span class="add-on">%</span> </div> </td> </tr> <tr> <td colspan="2"><b>OU</b></td> </tr> <tr> <td>Frais de port offert :</td> <td> <label class="toggle-switch"> <input type="checkbox" name="port" <?=($frm['port']==1?'checked':'') ?> value="1"> <span data-unchecked="Off" data-checked="On"></span> </label> </td> </tr> <td colspan="2" class="bouton" align="center"><input type="button" onclick="history.go(-1)" value="Annuler"><input class="bouton" type="submit" value="<?=$frm["titre_bouton"] ?>"></td> </tr> </table> </form> <? } function supprime_code_promo($id) { /* Supprime le styles spécificié par $id. Il faut supprimer le styles * puis les entrées correspondantes de la table styles_categories. */ /* Efface le styles */ $qid = mysql_query_override("DELETE FROM gaia_codes_promos WHERE id = $id"); echo '<div class="alert alert-error">Le code promo a été effacé <button type="button" class="close" data-dismiss="alert">×</button></div>'; } function insere_code_promo($frm) { $date_debut = preg_replace('<^([0-9]{2})/([0-9]{2})/([0-9]{4})$>', '$3-$2-$1', $frm["date_debut"]); $date_fin = preg_replace('<^([0-9]{2})/([0-9]{2})/([0-9]{4})$>', '$3-$2-$1', $frm["date_fin"]); $qid = mysql_query_override(" INSERT INTO gaia_codes_promos ( nom , date_debut , date_fin , remise , port ) VALUES ( '".addslashes(strtoupper($frm['nom']))."' , '".$date_debut."' , '".$date_fin."' , '".$frm['remise']."' , '".$frm['port']."' ) "); echo '<div class="alert alert-success">Le code promo a été ajouté <button type="button" class="close" data-dismiss="alert">×</button></div>'; } function maj_code_promo($id, $frm) { $date_debut = preg_replace('<^([0-9]{2})/([0-9]{2})/([0-9]{4})$>', '$3-$2-$1', $frm["date_debut"]); $date_fin = preg_replace('<^([0-9]{2})/([0-9]{2})/([0-9]{4})$>', '$3-$2-$1', $frm["date_fin"]); $qid = mysql_query_override(" UPDATE gaia_codes_promos SET nom = '".addslashes(strtoupper($frm['nom']))."' ,date_debut = '".$date_debut."' ,date_fin = '".$date_fin."' ,remise = '".$frm['remise']."' ,port = '".$frm['port']."' WHERE id = $id "); echo '<div class="alert alert-success">Le code promo a été modifié <button type="button" class="close" data-dismiss="alert">×</button></div>'; } function affiche_liste_code_promo($start) { ?> <table border="0" class="tablespace" width="100%" cellpadding="0" cellspacing="0"> <tr> <th class="entete" colspan="6">Liste des codes promotionnels</th> </tr> <tr><td colspan="5" class="action"><a href="codes_promos.php?mode=ajout"> Ajouter un code promotionnel</a> </td></tr> <? $Links = new MultiPage(); $Links-> ResultPerPage = 50; $Links-> LinkPerPage = 10; $Links-> Template = "tpl1.htm"; $Links-> SqlRequest = "SELECT * FROM gaia_codes_promos ORDER BY date_debut ASC"; $Links-> Initialize(); $result = mysql_query_override($Links-> LimitSQL); if (mysql_num_rows_override($result) == 0) { echo "<tr><td colspan=\"5\" class=\"\">Aucun code promotionnel ne figure dans la base dans la base.</td></tr>"; } else { ?> <tr> <td class="menu">Action</td> <td class="menu">Code</td> <td class="menu" align="center">Date de début</td> <td class="menu" align="center">Date de fin</td> <td class="menu" align="center">Remise</td> </tr> <?php while ($ligne = mysql_fetch_array_override($result)) { ?> <tr> <td> <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><a title="modifier" href="<?=$_SERVER['PHP_SELF']?>?mode=modif&id=<?=$ligne['id'] ?>"><?=$ligne['nom'] ?></a></td> <td align="center"><?=date("d/m/Y", strtotime($ligne['date_debut'])) ?></td> <td align="center"><?=date("d/m/Y", strtotime($ligne['date_fin'])) ?></td> <td align="center"><?=(($ligne['port']==1)?'Frais de port':$ligne['remise'].' %') ?></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> <? } echo "<tr><td align=\"center\" class=\"normal\" colspan=\"5\">"; $Links-> pMultipage(); echo "</td></tr>"; } echo "</table>"; } ?>