index.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 <http://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. if (is_numeric($type)) $type=Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  38. /*
  39. * View
  40. */
  41. $categstatic = new Categorie($db);
  42. $form = new Form($db);
  43. if ($type == Categorie::TYPE_PRODUCT) { $title=$langs->trans("ProductsCategoriesArea"); $typetext='product'; }
  44. elseif ($type == Categorie::TYPE_SUPPLIER) { $title=$langs->trans("SuppliersCategoriesArea"); $typetext='supplier'; }
  45. elseif ($type == Categorie::TYPE_CUSTOMER) { $title=$langs->trans("CustomersCategoriesArea"); $typetext='customer'; }
  46. elseif ($type == Categorie::TYPE_MEMBER) { $title=$langs->trans("MembersCategoriesArea"); $typetext='member'; }
  47. elseif ($type == Categorie::TYPE_CONTACT) { $title=$langs->trans("ContactsCategoriesArea"); $typetext='contact'; }
  48. elseif ($type == Categorie::TYPE_ACCOUNT) { $title=$langs->trans("AccountsCategoriesArea"); $typetext='bank_account'; }
  49. elseif ($type == Categorie::TYPE_PROJECT) { $title=$langs->trans("ProjectsCategoriesArea"); $typetext='project'; }
  50. elseif ($type == Categorie::TYPE_USER) { $title=$langs->trans("UsersCategoriesArea"); $typetext='user'; }
  51. else { $title=$langs->trans("CategoriesArea"); $typetext='unknown'; }
  52. $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
  53. $arrayofcss=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
  54. llxHeader('',$title,'','',0,0,$arrayofjs,$arrayofcss);
  55. $newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/categories/card.php?action=create&type='.$type.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type='.$type).'"><span class="valignmiddle">'.$langs->trans("NewCategory").'</span>';
  56. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  57. $newcardbutton.= '</a>';
  58. print load_fiche_titre($title, $newcardbutton);
  59. //print '<table border="0" width="100%" class="notopnoleftnoright">';
  60. //print '<tr><td valign="top" width="30%" class="notopnoleft">';
  61. print '<div class="fichecenter"><div class="fichethirdleft">';
  62. /*
  63. * Zone recherche produit/service
  64. */
  65. print '<form method="post" action="index.php?type='.$type.'">';
  66. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  67. print '<input type="hidden" name="type" value="'.$type.'">';
  68. print '<table class="noborder nohover" width="100%">';
  69. print '<tr class="liste_titre">';
  70. print '<td colspan="3">'.$langs->trans("Search").'</td>';
  71. print '</tr>';
  72. print '<tr class="oddeven"><td>';
  73. 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>';
  74. /*
  75. // faire une rech dans une sous categorie uniquement
  76. print '<tr '.$bc[0].'><td>';
  77. print $langs->trans("SubCatOf").':</td><td>';
  78. print $form->select_all_categories('','subcatof');
  79. print '</td>';
  80. print '<td><input type="submit" class="button" value="'.$langs->trans ("Search").'"></td></tr>';
  81. */
  82. print '</table></form>';
  83. //print '</td><td valign="top" width="70%">';
  84. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  85. /*
  86. * Categories found
  87. */
  88. if ($catname || $id > 0)
  89. {
  90. $cats = $categstatic->rechercher($id, $catname, $typetext);
  91. print '<table class="noborder" width="100%">';
  92. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
  93. foreach ($cats as $cat)
  94. {
  95. print "\t".'<tr class="oddeven">'."\n";
  96. print "\t\t<td>";
  97. $categstatic->id=$cat->id;
  98. $categstatic->ref=$cat->label;
  99. $categstatic->label=$cat->label;
  100. $categstatic->type=$cat->type;
  101. $categstatic->color=$cat->color;
  102. print '<span class="noborderoncategories" '.($categstatic->color?' style="background: #'.$categstatic->color.';"':' style="background: #aaa"').'>';
  103. print $categstatic->getNomUrl(1,'');
  104. print '</span>';
  105. print "</td>\n";
  106. print "\t\t<td>";
  107. print dolGetFirstLineOfText($cat->description);
  108. print "</td>\n";
  109. print "\t</tr>\n";
  110. }
  111. print "</table>";
  112. }
  113. else print '&nbsp;';
  114. //print '</td></tr></table>';
  115. print '</div></div></div>';
  116. print '<div class="fichecenter"><br>';
  117. // Charge tableau des categories
  118. $cate_arbo = $categstatic->get_full_arbo($typetext);
  119. // Define fulltree array
  120. $fulltree=$cate_arbo;
  121. // Define data (format for treeview)
  122. $data=array();
  123. $data[] = array('rowid'=>0,'fk_menu'=>-1,'title'=>"racine",'mainmenu'=>'','leftmenu'=>'','fk_mainmenu'=>'','fk_leftmenu'=>'');
  124. foreach($fulltree as $key => $val)
  125. {
  126. $categstatic->id=$val['id'];
  127. $categstatic->ref=$val['label'];
  128. $categstatic->color=$val['color'];
  129. $categstatic->type=$type;
  130. $li=$categstatic->getNomUrl(1,'',60);
  131. $desc=dol_htmlcleanlastbr($val['description']);
  132. $data[] = array(
  133. 'rowid'=>$val['rowid'],
  134. 'fk_menu'=>$val['fk_parent'],
  135. 'entry'=>'<table class="nobordernopadding centpercent"><tr><td><span class="noborderoncategories" '.($categstatic->color?' style="background: #'.$categstatic->color.';"':' style="background: #aaa"').'>'.$li.'</span></td>'.
  136. //'<td width="50%">'.dolGetFirstLineOfText($desc).'</td>'.
  137. '<td align="right" width="20px;"><a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.'">'.img_view().'</a></td>'.
  138. '</tr></table>'
  139. );
  140. }
  141. //print_barre_liste('', 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, 0, '', 0, $newcardbutton, '', 0, 1, 1);
  142. print '<table class="liste nohover" width="100%">';
  143. print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td align="right">';
  144. if (! empty($conf->use_javascript_ajax))
  145. {
  146. print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">'.img_picto('','object_category').' '.$langs->trans("UndoExpandAll").'</a> | <a class="notasortlink" href="#">'.img_picto('','object_category-expanded').' '.$langs->trans("ExpandAll").'</a></div>';
  147. }
  148. print '</td></tr>';
  149. $nbofentries=(count($data) - 1);
  150. if ($nbofentries > 0)
  151. {
  152. print '<tr class="pair"><td colspan="3">';
  153. tree_recur($data,$data[0],0);
  154. print '</td></tr>';
  155. }
  156. else
  157. {
  158. print '<tr class="pair">';
  159. print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('','treemenu/branchbottom.gif').'</td>';
  160. print '<td valign="middle">';
  161. print $langs->trans("NoCategoryYet");
  162. print '</td>';
  163. print '<td>&nbsp;</td>';
  164. print '</table></td>';
  165. print '</tr>';
  166. }
  167. print "</table>";
  168. print '</div>';
  169. // End of page
  170. llxFooter();
  171. $db->close();