0byt3m1n1
Path:
/
home
/
kassiope
/
www
/
administrer
/
[
Home
]
File: codes_promos.php
<?php $menu=4; 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["produit"] = ""; $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'] = preg_replace("/([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})/","\\3/\\2/\\1", vb($frm['date_debut'])); if(!empty($frm['date_debut'])) : $d = explode('-', $frm['date_debut']); $frm['date_debut'] = $d[2].'/'.$d[1].'/'.$d[0]; else : $frm['date_debut'] = date('d/m/Y'); endif; ?> <div class="input-group date"> <input class="datepicker 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'] = preg_replace("/([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})/","\\3/\\2/\\1", vb($frm['date_fin'])); if(!empty($frm['date_fin'])) : $d = explode('-', $frm['date_fin']); $frm['date_fin'] = $d[2].'/'.$d[1].'/'.$d[0]; else : $frm['date_fin'] = date('d/m/Y'); endif; ?> <div class="input-group date"> <input class="datepicker 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="input-mini- form-control" value="<?=vb($frm['remise']) ?>"><span class="add-on">% / €</span> </div> </td> </tr> <tr> <td>Type de remise :</td> <td> <input type="radio" name="type" <?=($frm['type']==0?'checked':'') ?> value="0" /> % <input type="radio" name="type" <?=($frm['type']==1?'checked':'') ?> value="1" /> € </td> </tr> <tr> <td>A partir de :</td> <td> <div class="input-group"> <input type="text" name="seuil_remise" class="input-mini- form-control" value="<?=vb($frm['seuil_remise']) ?>"><span class="add-on">€</span> </div> </td> </tr> <tr> <td><b>OU</b> Frais de port offert :</td> <td> <input type="checkbox" name="port" <?=($frm['port']==1?'checked':'') ?> value="1" /> </td> </tr> <!-- <tr> <td><b>OU</b> cadeau offert :</td> <td> <select name="produit_cadeau" class="input-medium" style="width:500px;"> <option value="">--</option> <? $rec = mysql_query_override("select * from gaia_produits where etat = 1 order by nom_fr"); while($data = mysql_fetch_array_override($rec)) { echo '<option value="'.$data['id'].'" '.(($data['id']==$frm['produit_cadeau'])?'selected':'').'>'.stripslashes($data['nom_fr']).'</option>'; } ?> </select> </td> </tr> --> <tr> <td>Inclure / exclure les produits :</td> <td> <select name="in_or_not" class="input-medium"> <option value="">--</option> <option value="in" <?=(($frm['in_or_not']=='in')?'selected':'')?>>Inclure</option> <option value="not in" <?=(($frm['in_or_not']=='not in')?'selected':'')?>>Exclure</option> </select> </td> </tr> <tr> <td>Produits :</td> <td> <select name="produits[]" class="input-medium" multiple style="width:500px; height:300px"> <option value="">--</option> <? $prods = explode(',',$frm['produits']); $rec = mysql_query_override("select * from gaia_produits where etat = 1 order by nom_fr"); while($data = mysql_fetch_array_override($rec)) { echo '<option value="'.$data['id'].'" '.((in_array($data['id'],$prods))?'selected':'').'>'.stripslashes($data['nom_fr']).'</option>'; } ?> </select> </td> </tr> <!-- <tr> <td>Produit :</td> <td> <select name="produit"> <option value="0">--</option> <? $recp = mysql_query_override("select * from gaia_produits where etat = 1 order by nom_fr"); while($datap = mysql_fetch_array_override($recp)) { echo '<option value="'.$datap['id'].'" '.(($frm['produit']==$datap['id'])?'selected':'').'>'.stripslashes($datap['nom_fr']).'</option>'; } ?> </select> </td> </tr> --> <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 = ereg_replace('^([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})$','\\3-\\2-\\1', $frm["date_debut"]); $date_fin = ereg_replace('^([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})$','\\3-\\2-\\1', $frm["date_fin"]); */ $d = explode('/', $frm['date_debut']); $date_debut = $d[2].'-'.$d[1].'-'.$d[0]; $d = explode('/', $frm['date_fin']); $date_fin = $d[2].'-'.$d[1].'-'.$d[0]; $prods = $frm['produits']; if(is_array($frm['produits'])) $prods = implode(',',$frm['produits']); $qid = mysql_query_override(" INSERT INTO gaia_codes_promos ( nom , date_debut , date_fin , remise , seuil_remise , produit , type , port , produit_cadeau , produits , in_or_not ) VALUES ( '".addslashes(strtoupper($frm['nom']))."' , '".$date_debut."' , '".$date_fin."' , '".$frm['remise']."' , '".$frm['seuil_remise']."' , '".$frm['produit']."' , '".$frm['type']."' , '".$frm['port']."' , '".$frm['produit_cadeau']."' , '".$prods."' , '".$frm['in_or_not']."' ) "); 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 = ereg_replace('^([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})$','\\3-\\2-\\1', $frm["date_debut"]); $date_fin = ereg_replace('^([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})$','\\3-\\2-\\1', $frm["date_fin"]); */ $d = explode('/', $frm['date_debut']); $date_debut = $d[2].'-'.$d[1].'-'.$d[0]; $d = explode('/', $frm['date_fin']); $date_fin = $d[2].'-'.$d[1].'-'.$d[0]; $prods = $frm['produits']; if(is_array($frm['produits'])) $prods = implode(',',$frm['produits']); $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']."' ,seuil_remise = '".$frm['seuil_remise']."' ,produit = '".$frm['produit']."' ,type = '".$frm['type']."' ,port = '".$frm['port']."' ,produit_cadeau = '".$frm['produit_cadeau']."' ,produits = '".$prods."' ,in_or_not = '".$frm['in_or_not']."' 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="10">Liste des codes promotionnels</th> </tr> <tr><td colspan="10" 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 desc"; $Links-> Initialize(); $result = mysql_query_override($Links-> LimitSQL); if (mysql_num_rows_override($result) == 0) { echo "<tr><td colspan=\"22\" class=\"label\">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> <td class="menu" align="center">Seuil remise</td> <td class="menu" align="center">Frais de port</td> <!--<td class="menu" align="center">Produit cadeau</td>--> <td class="menu" align="center">Produit(s)</td> </tr> <?php while ($ligne = mysql_fetch_array_override($result)) { $produit_cadeau = '-'; if($ligne['produit_cadeau']>0) { $recp = mysql_query_override("select * from gaia_produits where id = '".$ligne['produit_cadeau']."'"); $produit_cadeau = stripslashes(mysql_result_override($recp,0,'nom_fr')); } $produits = ''; if(!empty($ligne['produits'])) { $prods = explode(',',$ligne['produits']); foreach($prods as $k =>$v) { $recp = mysql_query_override("select * from gaia_produits where id = '".$v."'"); $produits .= stripslashes(mysql_result_override($recp,0,'nom_fr')).' / '; } } if(empty($produits)) $produits = 'Tous'; ?> <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['remise'] ?> <?=(($ligne['type']==0)?'%':'€') ?></td> <td align="center"><?=$ligne['seuil_remise'] ?> €</td> <td align="center"><?=(($ligne['port']==1)?'Offert':'') ?></td> <!--<td align="center"><?=$produit_cadeau ?></td>--> <td align="center" style="width:300px"><?=$produits ?></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> <?php } echo "<tr><td align=\"center\" class=\"normal\" colspan=\"22\">"; $Links-> pMultipage(); echo "</td></tr>"; } echo "</table>"; } ?>