index.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
  3. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/categories/index.php
  24. * \ingroup category
  25. * \brief Home page of category area
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. // Load translation files required by the page
  32. $langs->load("categories");
  33. if (!$user->rights->categorie->lire) accessforbidden();
  34. $id = GETPOST('id', 'int');
  35. $type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
  36. $catname = GETPOST('catname', 'alpha');
  37. $nosearch = GETPOST('nosearch', 'int');
  38. $categstatic = new Categorie($db);
  39. if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  40. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  41. $hookmanager->initHooks(array('categoryindex'));
  42. /*
  43. * View
  44. */
  45. $form = new Form($db);
  46. $moreparam = ($nosearch ? '&nosearch=1' : '');
  47. $typetext = $type;
  48. if ($type == Categorie::TYPE_ACCOUNT) $title = $langs->trans('AccountsCategoriesArea');
  49. elseif ($type == Categorie::TYPE_WAREHOUSE) $title = $langs->trans('StocksCategoriesArea');
  50. elseif ($type == Categorie::TYPE_ACTIONCOMM) $title = $langs->trans('ActionCommCategoriesArea');
  51. elseif ($type == Categorie::TYPE_WEBSITE_PAGE) $title = $langs->trans('WebsitePagesCategoriesArea');
  52. else {
  53. $title = $langs->trans(ucfirst($type).'sCategoriesArea');
  54. }
  55. $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
  56. $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
  57. llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss);
  58. $newcardbutton = '';
  59. if (!empty($user->rights->categorie->creer)) {
  60. $newcardbutton .= dolGetButtonTitle($langs->trans('NewCategory'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/categories/card.php?action=create&type='.$type.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam).$moreparam);
  61. }
  62. print load_fiche_titre($title, $newcardbutton, 'object_category');
  63. // Search categories
  64. if (empty($nosearch)) {
  65. print '<div class="fichecenter"><div class="fichehalfleft">';
  66. print '<form method="post" action="index.php?type='.$type.'">';
  67. print '<input type="hidden" name="token" value="'.newToken().'">';
  68. print '<input type="hidden" name="type" value="'.$type.'">';
  69. print '<input type="hidden" name="nosearch" value="'.$nosearch.'">';
  70. print '<table class="noborder nohover centpercent">';
  71. print '<tr class="liste_titre">';
  72. print '<td colspan="3">'.$langs->trans("Search").'</td>';
  73. print '</tr>';
  74. print '<tr class="oddeven nohover"><td>';
  75. print $langs->trans("Name").':</td><td><input class="flat inputsearch" type="text" name="catname" value="'.$catname.'"/></td><td><input type="submit" class="button" value="'.$langs->trans("Search").'"></td></tr>';
  76. print '</table></form>';
  77. print '</div><div class="fichehalfright">';
  78. /*
  79. * Categories found
  80. */
  81. if ($catname || $id > 0)
  82. {
  83. $cats = $categstatic->rechercher($id, $catname, $typetext);
  84. print '<table class="noborder centpercent">';
  85. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
  86. foreach ($cats as $cat)
  87. {
  88. $color = $categstatic->color ? ' style="background: #'.$categstatic->color.';"' : ' style="background: #bbb"';
  89. print "\t".'<tr class="oddeven">'."\n";
  90. print "\t\t<td>";
  91. $categstatic->id = $cat->id;
  92. $categstatic->ref = $cat->label;
  93. $categstatic->label = $cat->label;
  94. $categstatic->type = $cat->type;
  95. $categstatic->color = $cat->color;
  96. print '<span class="noborderoncategories"'.$color.'>';
  97. print $categstatic->getNomUrl(1, '');
  98. print '</span>';
  99. print "</td>\n";
  100. print "\t\t<td>";
  101. print dolGetFirstLineOfText($cat->description);
  102. print "</td>\n";
  103. print "\t</tr>\n";
  104. }
  105. print "</table>";
  106. } else print '&nbsp;';
  107. print '</div></div>';
  108. }
  109. print '<div class="fichecenter"><br>';
  110. // Charge tableau des categories
  111. $cate_arbo = $categstatic->get_full_arbo($typetext);
  112. // Define fulltree array
  113. $fulltree = $cate_arbo;
  114. // Load possible missing includes
  115. if ($conf->global->CATEGORY_SHOW_COUNTS)
  116. {
  117. if ($type == Categorie::TYPE_MEMBER) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  118. if ($type == Categorie::TYPE_ACCOUNT) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  119. if ($type == Categorie::TYPE_PROJECT) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  120. if ($type == Categorie::TYPE_USER) require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  121. }
  122. // Define data (format for treeview)
  123. $data = array();
  124. $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
  125. foreach ($fulltree as $key => $val)
  126. {
  127. $categstatic->id = $val['id'];
  128. $categstatic->ref = $val['label'];
  129. $categstatic->color = $val['color'];
  130. $categstatic->type = $type;
  131. $li = $categstatic->getNomUrl(1, '', 60, $moreparam.'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam));
  132. $desc = dol_htmlcleanlastbr($val['description']);
  133. $counter = '';
  134. if ($conf->global->CATEGORY_SHOW_COUNTS)
  135. {
  136. // we need only a count of the elements, so it is enough to consume only the id's from the database
  137. $elements = $categstatic->getObjectsInCateg($type, 1);
  138. $counter = "<td class='left' width='40px;'>".(is_countable($elements) ? count($elements) : '0')."</td>";
  139. }
  140. $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
  141. $data[] = array(
  142. 'rowid'=>$val['rowid'],
  143. 'fk_menu'=>$val['fk_parent'],
  144. 'entry'=>'<table class="nobordernopadding centpercent"><tr><td><span class="noborderoncategories"'.$color.'>'.$li.'</span></td>'.$counter.
  145. '<td class="right" width="20px;"><a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.$moreparam.'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam).'">'.img_view().'</a></td></tr></table>'
  146. );
  147. }
  148. //print_barre_liste('', 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, 0, '', 0, $newcardbutton, '', 0, 1, 1);
  149. print '<table class="liste nohover" width="100%">';
  150. print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">';
  151. if (!empty($conf->use_javascript_ajax))
  152. {
  153. print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a> | <a class="notasortlink" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div>';
  154. }
  155. print '</td></tr>';
  156. $nbofentries = (count($data) - 1);
  157. if ($nbofentries > 0)
  158. {
  159. print '<tr class="pair"><td colspan="3">';
  160. tree_recur($data, $data[0], 0);
  161. print '</td></tr>';
  162. } else {
  163. print '<tr class="pair">';
  164. print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
  165. print '<td valign="middle">';
  166. print $langs->trans("NoCategoryYet");
  167. print '</td>';
  168. print '<td>&nbsp;</td>';
  169. print '</table></td>';
  170. print '</tr>';
  171. }
  172. print "</table>";
  173. print '</div>';
  174. // End of page
  175. llxFooter();
  176. $db->close();