PageRenderTime 28ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/modules/annonces/admin_Categories.php

http://malleo-cms.googlecode.com/
PHP | 193 lines | 149 code | 16 blank | 28 comment | 25 complexity | bc0cff57c5ee23d08cadf35c92498d25 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. |------------------------------------------------------------------------------------------------------------
  4. | Software: Malleo ( CMS )
  5. | Contact: alain91 - http://www.malleo-cms.com
  6. | Support: http://www.malleo-cms.com?module=forum
  7. | Documentation : Support :
  8. |------------------------------------------------------------------------------------------------------------
  9. | Author: Alain GANDON
  10. | Copyright (c) 2011, Alain GANDON All Rights Reserved
  11. |------------------------------------------------------------------------------------------------------------
  12. | License: Distributed under the CECILL V2 License
  13. | This program is distributed in the hope that it will be useful - WITHOUT
  14. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. | FITNESS FOR A PARTICULAR PURPOSE.
  16. |
  17. | Please read Licence_CeCILL_V2-en.txt
  18. | SVP lisez Licence_CeCILL_V2-fr.txt
  19. |------------------------------------------------------------------------------------------------------------
  20. */
  21. defined('PROTECT_ADMIN') OR die("Tentative de Hacking");
  22. defined('ANNONCES_PATH') OR define('ANNONCES_PATH', dirname(__FILE__));
  23. require_once(ANNONCES_PATH.'/class/class_core.php');
  24. Core::setup();
  25. //
  26. // initialisation de certaines variables
  27. $chemin_icones = 'data/icones_annonces/';
  28. $module_select = '';
  29. $ext_ok = array('gif','png','jpg','jpeg');
  30. $image = $liste_images = $image_par_defaut = '';
  31. $tpl->assign_vars(array(
  32. 'HIDDEN_ACTION' => 'ajouter'
  33. ));
  34. require(ANNONCES_PATH.'/prerequis.php');
  35. $tpl->set_filenames(array('body_admin' => ANNONCES_PATH.'/html/admin_categories.html'));
  36. Helper::cleanGPC();
  37. // TRAITEMENT
  38. if (isset($_POST['action']) || isset($_GET['action']))
  39. {
  40. $action = (isset($_POST['action']))? $_POST['action']:$_GET['action'];
  41. // controles
  42. if (($action == 'ajouter' || $action == 'editer') &&
  43. (empty($_POST['titre']))) {
  44. erreur_saisie('erreur_saisie',$lang['L_TOUT_REMPLIR'],array(
  45. 'TITRE'=>isset($_POST['titre'])?$_POST['titre']:''));
  46. if ($action == 'ajouter') $action = '';
  47. if ($action == 'editer') $action = 'edit';
  48. $_GET = $_POST;
  49. }
  50. switch ($action)
  51. {
  52. case 'move':
  53. $sens = ($_GET['sens']=='up')? '+':'-';
  54. require_once($root.'fonctions/fct_formulaires.php');
  55. deplacer_id_tableau(TABLE_ANNONCES_CATS, 'id_cat', 'ordre', 'ASC', intval($_GET['id_cat']), $sens);
  56. $cache->appel_cache('listing_blog_cat',true);
  57. header('location: '.$base_formate_url);
  58. break;
  59. case 'ajouter':
  60. $titre = $_POST['titre'];
  61. $image = empty($_POST['image']) ? '' : $_POST['image'];
  62. $id_module = $_POST['id_module'];
  63. $sql = 'INSERT INTO '.TABLE_ANNONCES_CATS.' (title_cat, picture_cat) VALUES (
  64. \''.Helper::sql_escape($titre).'\',
  65. \''.Helper::sql_escape($image).'\')';
  66. $resultat = $c->sql_query($sql) OR message_die(E_ERROR,510,__FILE__,__LINE__,$sql);
  67. $cache->appel_cache('listing_blog_cat',true);
  68. header('location: '.$base_formate_url);
  69. break;
  70. case 'editer':
  71. $titre = $_POST['titre'];
  72. $image = empty($_POST['image']) ? '' : $_POST['image'];
  73. $id_cat = intval($_POST['id_cat']);
  74. $sql = 'UPDATE '.TABLE_ANNONCES_CATS.' SET
  75. title_cat=\''.Helper::sql_escape($titre).'\',
  76. picture_cat=\''.Helper::sql_escape($image).'\'
  77. WHERE id_cat='.$id_cat;
  78. $resultat = $c->sql_query($sql) OR message_die(E_ERROR,513,__FILE__,__LINE__,$sql);
  79. $cache->appel_cache('listing_blog_cat',true);
  80. header('location: '.$base_formate_url);
  81. break;
  82. case 'supprimer':
  83. $id_cat = intval($_GET['id_cat']);
  84. $sql = 'DELETE FROM '.TABLE_ANNONCES_CATS.' WHERE id_cat='.$id_cat;
  85. $resultat = $c->sql_query($sql) OR message_die(E_ERROR,511,__FILE__,__LINE__,$sql);
  86. $cache->appel_cache('listing_blog_cat',true);
  87. header('location: '.$base_formate_url);
  88. break;
  89. case 'edit':
  90. $id_cat = intval($_GET['id_cat']);
  91. $sql = 'SELECT title_cat, picture_cat FROM '.TABLE_ANNONCES_CATS.' WHERE id_cat = '.$id_cat;
  92. $resultat = $c->sql_query($sql) OR message_die(E_ERROR,512,__FILE__,__LINE__,$sql);
  93. $row = $c->sql_fetchrow($resultat);
  94. $tpl->assign_vars(array(
  95. 'HIDDEN_ACTION' => 'editer',
  96. 'HIDDEN' => '<input type="hidden" name="id_cat" value="'.$id_cat.'" />',
  97. 'TITRE' => $row['title_cat']
  98. ));
  99. $titre = $row['title_cat'];
  100. $image = $row['picture_cat'];
  101. }
  102. }
  103. $module_select = 'annonces';
  104. //
  105. // AFFICHAGE des Categories
  106. $sql = 'SELECT id_cat, title_cat, picture_cat, `order`
  107. FROM '.TABLE_ANNONCES_CATS.'
  108. ORDER BY `order` ASC, title_cat ASC';
  109. $resultat = $c->sql_query($sql) OR message_die(E_ERROR,509,__FILE__,__LINE__,$sql);
  110. $liste_cats = array();
  111. while($row = $c->sql_fetchrow($resultat))
  112. {
  113. $liste_cats[$module_select][] = $row;
  114. }
  115. $sql = 'SELECT module FROM '.TABLE_MODULES.'
  116. WHERE module="'.$module_select.'" OR virtuel="'.$module_select.'"
  117. ORDER BY module ASC';
  118. $resultat = $c->sql_query($sql) OR message_die(E_ERROR,509,__FILE__,__LINE__,$sql);
  119. $select_list = '';
  120. while($row = $c->sql_fetchrow($resultat))
  121. {
  122. $tpl->assign_block_vars('liste_modules', array(
  123. 'MODULE' => ucfirst($module_select)
  124. ));
  125. if (array_key_exists($row['module'],$liste_cats))
  126. {
  127. $tpl->assign_block_vars('liste_modules.ok', array());
  128. $t=1;
  129. foreach ($liste_cats[$row['module']] as $k=>$v)
  130. {
  131. $tpl->assign_block_vars('liste_modules.ok.cat', array(
  132. 'TITRE' => $v['title_cat'],
  133. 'IMAGE' => $v['picture_cat'],
  134. 'S_UP' => formate_url('action=move&sens=up&id_cat='.$v['id_cat'],true),
  135. 'S_DOWN' => formate_url('action=move&sens=down&id_cat='.$v['id_cat'],true),
  136. 'S_EDIT' => formate_url('action=edit&id_cat='.$v['id_cat'],true),
  137. 'S_SUPP' => formate_url('action=supprimer&id_cat='.$v['id_cat'],true),
  138. ));
  139. // Monter / descendre
  140. $nbre_cats = sizeof($liste_cats[$row['module']]);
  141. if ($nbre_cats>1 && $t>1) $tpl->assign_block_vars('liste_modules.ok.cat.monter',array());
  142. if ($nbre_cats>1 && $t<$nbre_cats) $tpl->assign_block_vars('liste_modules.ok.cat.descendre',array());
  143. $t++;
  144. }
  145. }else{
  146. $tpl->assign_block_vars('liste_modules.nok', array());
  147. }
  148. $selected = ($module_select==$row['module'])?' selected="selected"':'';
  149. $select_list .= '<option'.$selected.'>'.$row['module'].'</option>';
  150. }
  151. //
  152. // Listing des icones de catégories
  153. if (file_exists($chemin_icones))
  154. {
  155. $ch = @opendir($chemin_icones);
  156. while ($icone = @readdir($ch))
  157. {
  158. $ext = pathinfo($icone);
  159. if ($icone[0] != '.' && in_array(strtolower($ext['extension']),$ext_ok)) {
  160. if ($image_par_defaut == '') $image_par_defaut = $icone;
  161. $selected = ($image == $icone)?' selected="selected"':'';
  162. $liste_images .= "\n ".'<option value="'.$icone.'"'.$selected.'>'.basename($icone,'.'.$ext['extension']).'</option>';
  163. }
  164. }
  165. @closedir($ch);
  166. }
  167. $tpl->assign_vars(array(
  168. 'IMAGE' => $liste_images,
  169. 'MODULE' => $select_list,
  170. 'ICONE_PAR_DEFAUT' => ($image!='')?$image:$image_par_defaut,
  171. 'CHEMIN_ICONES' => $chemin_icones,
  172. 'I_DOWN' => $img['down'],
  173. 'I_UP' => $img['up'],
  174. 'I_EDITER' => $img['editer'],
  175. 'I_EFFACER' => $img['effacer'],
  176. ));
  177. ?>