cat_list.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. require dirname(__FILE__).'/inc/prepend.php';
  23. $auth->check(5);
  24. include dirname(__FILE__).'/inc/connexion.php';
  25. $err = '';
  26. # Reord
  27. if (!empty($_GET['reord']))
  28. {
  29. if ($blog->reordCats(false,true) === false) {
  30. $err = $blog->error(1);
  31. } else {
  32. header('Location: cat_list.php');
  33. exit;
  34. }
  35. }
  36. # Classic ord
  37. if (isset($_POST['catOrd']) && is_array($_POST['catOrd']))
  38. {
  39. if ($blog->ordCats($_POST['catOrd']) === false) {
  40. $err = $blog->error(1);
  41. } else {
  42. header('Location: cat_list.php');
  43. exit;
  44. }
  45. }
  46. # DragNdrop
  47. if (!empty($_POST['dndSort']))
  48. {
  49. $catOrd = array();
  50. foreach (explode(';',$_POST['dndSort']) as $k => $v) {
  51. $catOrd[substr($v,3)] = $k;
  52. }
  53. if ($blog->ordCats($catOrd) === false) {
  54. $err = $blog->error(1);
  55. } else {
  56. header('Location: cat_list.php');
  57. exit;
  58. }
  59. }
  60. $mySubMenu->addItem('<strong>'.__('New category').'</strong>','categorie.php','images/ico_new.png',false);
  61. openPage(__('Categories list'),
  62. ' <script type="text/javascript" src="js/drag.js"></script>'.
  63. ' <script type="text/javascript" src="js/dragsort.js"></script>'.
  64. ' <script type="text/javascript">'."\n".
  65. ' if (document.getElementById) { '."\n".
  66. ' window.onload = function() { '."\n".
  67. ' dragSort.dest = document.getElementById(\'dndSort\');'."\n".
  68. ' dragSort.makeElementSortable(document.getElementById(\'sortcat\'));'."\n".
  69. ' };'."\n".
  70. ' }'."\n".
  71. '</script>');
  72. ?>
  73. <h2><?php echo __('Categories list'); ?></h2>
  74. <?php
  75. if ($err != '')
  76. {
  77. echo '<div class="erreur"><p><strong>'.__('Error(s)').' :</strong></p>'.
  78. $err.'</div>';
  79. }
  80. $rsCat = $blog->getCat('','cat_ord');
  81. if ($rsCat->isEmpty())
  82. {
  83. echo '<p>'.__('No category yet').'</p>';
  84. }
  85. else
  86. {
  87. echo '<p>'.__('Drag items to change their positions.').'</p>';
  88. echo '<form action="cat_list.php" method="post">';
  89. echo '<div id="sortcat">';
  90. while(!$rsCat->EOF())
  91. {
  92. $cat_id = $rsCat->field('cat_id');
  93. $cat_ord = $rsCat->field('cat_ord');
  94. $cat_libelle = $rsCat->field('cat_libelle');
  95. $cat_nb_post = (integer) $rsCat->field('nb_post');
  96. echo
  97. '<div class="sort" id="dnd'.$cat_id.'">'.
  98. '<p><strong><a href="categorie.php?cat_id='.$cat_id.'">'.
  99. $cat_libelle.'</a></strong> - ';
  100. if ($cat_nb_post > 0)
  101. {
  102. echo '<a href="index.php?cat_id='.$cat_id.'">'.
  103. (($cat_nb_post>1) ? sprintf(__('%d entries'),$cat_nb_post) : sprintf(__('%d entry'),$cat_nb_post)).
  104. '</a>';
  105. }
  106. else
  107. {
  108. echo '<a href="categorie.php?cat_id='.$cat_id.'&amp;del=1" '.
  109. ' onclick="return window.confirm(\''.__('Are you sure you want to delete this category?').'\')">'.
  110. __('delete').'</a>';
  111. }
  112. echo
  113. '</p>'.
  114. '<p class="nojsfield"><label for="catOrd'.$cat_id.'" class="inline">'.__('Position').' : </label>'.
  115. form::field(array('catOrd['.$cat_id.']','catOrd'.$cat_id),3,3,$cat_ord).'</p>'.
  116. '</div>';
  117. $rsCat->moveNext();
  118. }
  119. echo
  120. '</div>'.
  121. '<p><input type="hidden" id="dndSort" name="dndSort" value="" />'.
  122. '<input type="submit" class="submit" value="'.__('save order').'" /></p>'.
  123. '</form>';
  124. echo '<p><a href="cat_list.php?reord=1">'.__('Reorder categories').'</a></p>';
  125. }
  126. ?>
  127. <?php closePage(); ?>