viewcat.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. <?php
  2. /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
  3. * Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/categories/viewcat.php
  23. * \ingroup category
  24. * \brief Page to show a category card
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. // Load translation files required by the page
  32. $langs->load("categories");
  33. $id = GETPOST('id','int');
  34. $label= GETPOST('label','alpha');
  35. $type = GETPOST('type','az09');
  36. $action=GETPOST('action','aZ09');
  37. $confirm = GETPOST('confirm','alpha');
  38. $removeelem = GETPOST('removeelem','int');
  39. $elemid = GETPOST('elemid','alpha');
  40. if ($id == "" && $label == "")
  41. {
  42. dol_print_error('','Missing parameter id');
  43. exit();
  44. }
  45. // Security check
  46. $result = restrictedArea($user, 'categorie', $id, '&category');
  47. $object = new Categorie($db);
  48. $result=$object->fetch($id, $label);
  49. if ($result <= 0) {
  50. dol_print_error($db,$object->error); exit;
  51. }
  52. $object->fetch_optionals();
  53. if ($result <= 0) {
  54. dol_print_error($db,$object->error); exit;
  55. }
  56. $type=$object->type;
  57. if (is_numeric($type)) $type=Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  58. $extrafields = new ExtraFields($db);
  59. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  60. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  61. $hookmanager->initHooks(array('categorycard','globalcard'));
  62. /*
  63. * Actions
  64. */
  65. $parameters=array();
  66. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  67. // Remove element from category
  68. if ($id > 0 && $removeelem > 0)
  69. {
  70. if ($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer))
  71. {
  72. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  73. $tmpobject = new Product($db);
  74. $result = $tmpobject->fetch($removeelem);
  75. $elementtype = 'product';
  76. }
  77. else if ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer)
  78. {
  79. $tmpobject = new Societe($db);
  80. $result = $tmpobject->fetch($removeelem);
  81. $elementtype = 'supplier';
  82. }
  83. else if ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer)
  84. {
  85. $tmpobject = new Societe($db);
  86. $result = $tmpobject->fetch($removeelem);
  87. $elementtype = 'customer';
  88. }
  89. else if ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer)
  90. {
  91. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  92. $tmpobject = new Adherent($db);
  93. $result = $tmpobject->fetch($removeelem);
  94. $elementtype = 'member';
  95. }
  96. else if ($type == Categorie::TYPE_CONTACT && $user->rights->societe->creer) {
  97. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  98. $tmpobject = new Contact($db);
  99. $result = $tmpobject->fetch($removeelem);
  100. $elementtype = 'contact';
  101. }
  102. else if ($type == Categorie::TYPE_ACCOUNT && $user->rights->banque->configurer)
  103. {
  104. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  105. $tmpobject = new Account($db);
  106. $result = $tmpobject->fetch($removeelem);
  107. $elementtype = 'account';
  108. }
  109. else if ($type == Categorie::TYPE_PROJECT && $user->rights->projet->creer)
  110. {
  111. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  112. $tmpobject = new Project($db);
  113. $result = $tmpobject->fetch($removeelem);
  114. $elementtype = 'project';
  115. }
  116. $result=$object->del_type($tmpobject,$elementtype);
  117. if ($result < 0) dol_print_error('',$object->error);
  118. }
  119. if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confirm == 'yes')
  120. {
  121. if ($object->delete($user) >= 0)
  122. {
  123. header("Location: ".DOL_URL_ROOT.'/categories/index.php?type='.$type);
  124. exit;
  125. }
  126. else
  127. {
  128. setEventMessages($object->error, $object->errors, 'errors');
  129. }
  130. }
  131. if ($type == Categorie::TYPE_PRODUCT && $elemid && $action == 'addintocategory' && ($user->rights->produit->creer || $user->rights->service->creer))
  132. {
  133. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  134. $newobject = new Product($db);
  135. $result = $newobject->fetch($elemid);
  136. $elementtype = 'product';
  137. // TODO Add into categ
  138. $result=$object->add_type($newobject,$elementtype);
  139. if ($result >= 0)
  140. {
  141. setEventMessages($langs->trans("WasAddedSuccessfully",$newobject->ref), null, 'mesgs');
  142. }
  143. else
  144. {
  145. if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  146. {
  147. setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), null, 'warnings');
  148. }
  149. else
  150. {
  151. setEventMessages($object->error,$object->errors,'errors');
  152. }
  153. }
  154. }
  155. /*
  156. * View
  157. */
  158. $form = new Form($db);
  159. $formother = new FormOther($db);
  160. $helpurl='';
  161. llxHeader("",$langs->trans("Categories"),$helpurl);
  162. if ($type == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductsCategoryShort");
  163. elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCategoryShort");
  164. elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort");
  165. elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort");
  166. elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort");
  167. elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort");
  168. elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesShort");
  169. elseif ($type == Categorie::TYPE_USER) $title=$langs->trans("ProjectsCategoriesShort");
  170. else $title=$langs->trans("Category");
  171. $head = categories_prepare_head($object,$type);
  172. dol_fiche_head($head, 'card', $title, -1, 'category');
  173. $linkback = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
  174. $object->next_prev_filter=" type = ".$object->type;
  175. $object->ref = $object->label;
  176. $morehtmlref='<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
  177. $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
  178. foreach ($ways as $way)
  179. {
  180. $morehtmlref.=$way."<br>\n";
  181. }
  182. $morehtmlref.='</div>';
  183. dol_banner_tab($object, 'label', $linkback, ($user->societe_id?0:1), 'label', 'label', $morehtmlref, '', 0, '', '', 1);
  184. /*
  185. * Confirmation suppression
  186. */
  187. if ($action == 'delete')
  188. {
  189. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;type='.$type, $langs->trans('DeleteCategory'), $langs->trans('ConfirmDeleteCategory'), 'confirm_delete', '', '', 1);
  190. }
  191. print '<br>';
  192. print '<div class="fichecenter">';
  193. print '<div class="underbanner clearboth"></div>';
  194. print '<table width="100%" class="border">';
  195. // Description
  196. print '<tr><td class="titlefield notopnoleft tdtop">';
  197. print $langs->trans("Description").'</td><td>';
  198. print dol_htmlentitiesbr($object->description);
  199. print '</td></tr>';
  200. // Color
  201. print '<tr><td class="notopnoleft">';
  202. print $langs->trans("Color").'</td><td>';
  203. print $formother->showColor($object->color);
  204. print '</td></tr>';
  205. // Other attributes
  206. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  207. print '</table>';
  208. print '</div>';
  209. dol_fiche_end();
  210. /*
  211. * Boutons actions
  212. */
  213. print "<div class='tabsAction'>\n";
  214. if ($user->rights->categorie->creer)
  215. {
  216. $socid = ($object->socid ? "&amp;socid=".$object->socid : "");
  217. print "<a class='butAction' href='edit.php?id=".$object->id.$socid."&amp;type=".$type."'>".$langs->trans("Modify")."</a>";
  218. }
  219. if ($user->rights->categorie->supprimer)
  220. {
  221. print "<a class='butActionDelete' href='".DOL_URL_ROOT."/categories/viewcat.php?action=delete&amp;id=".$object->id."&amp;type=".$type."'>".$langs->trans("Delete")."</a>";
  222. }
  223. print "</div>";
  224. $cats = $object->get_filles();
  225. if ($cats < 0)
  226. {
  227. dol_print_error($db, $cats->error, $cats->errors);
  228. }
  229. else
  230. {
  231. print "<br>";
  232. print "<table class='noborder' width='100%'>\n";
  233. print "<tr class='liste_titre'><td colspan='2'>".$langs->trans("SubCats").'</td><td align="right">';
  234. if ($user->rights->categorie->creer)
  235. {
  236. print "<a href='".DOL_URL_ROOT."/categories/card.php?action=create&amp;catorigin=".$object->id."&amp;socid=".$object->socid."&amp;type=".$type."&amp;urlfrom=".urlencode($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type)."'>";
  237. print img_picto($langs->trans("Create"),'filenew');
  238. print "</a>";
  239. }
  240. print "</td>";
  241. print "</tr>\n";
  242. if (count($cats) > 0)
  243. {
  244. foreach ($cats as $cat)
  245. {
  246. print "\t".'<tr class="oddeven">'."\n";
  247. print "\t\t".'<td class="nowrap">';
  248. print "<a href='viewcat.php?id=".$cat->id."&amp;type=".$type."'>".$cat->label."</a>";
  249. print "</td>\n";
  250. print "\t\t".'<td colspan="2">'.$cat->description."</td>\n";
  251. /*
  252. if ($cat->visible == 1)
  253. {
  254. print "\t\t<td>".$langs->trans("ContentsVisibleByAllShort")."</td>\n";
  255. }
  256. else
  257. {
  258. print "\t\t<td>".$langs->trans("ContentsNotVisibleByAllShort")."</td>\n";
  259. }
  260. */
  261. print "\t</tr>\n";
  262. }
  263. }
  264. else
  265. {
  266. print "<tr ".$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("NoSubCat")."</td></tr>";
  267. }
  268. print "</table>\n";
  269. }
  270. // List of products or services (type is type of category)
  271. if ($type == Categorie::TYPE_PRODUCT)
  272. {
  273. $prods = $object->getObjectsInCateg("product");
  274. if ($prods < 0)
  275. {
  276. dol_print_error($db, $prods->error, $prods->errors);
  277. }
  278. else
  279. {
  280. $showclassifyform=1; $typeid=Categorie::TYPE_PRODUCT;
  281. // Form to add record into a category
  282. if ($showclassifyform)
  283. {
  284. print '<br>';
  285. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  286. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  287. print '<input type="hidden" name="typeid" value="'.$typeid.'">';
  288. print '<input type="hidden" name="type" value="'.$typeid.'">';
  289. print '<input type="hidden" name="id" value="'.$object->id.'">';
  290. print '<input type="hidden" name="action" value="addintocategory">';
  291. print '<table class="noborder" width="100%">';
  292. print '<tr class="liste_titre"><td width="40%">';
  293. print $langs->trans("AddProductServiceIntoCategory").' &nbsp;';
  294. print $form->select_produits('','elemid','',0,0,-1,2,'',1);
  295. print '</td><td>';
  296. print '<input type="submit" class="button" value="'.$langs->trans("ClassifyInCategory").'"></td>';
  297. print '</tr>';
  298. print '</table>';
  299. print '</form>';
  300. }
  301. print "<br>";
  302. print "<table class='noborder' width='100%'>\n";
  303. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("ProductsAndServices")." (".count($prods).")</td></tr>\n";
  304. if (count($prods) > 0)
  305. {
  306. foreach ($prods as $prod)
  307. {
  308. print "\t".'<tr class="oddeven">'."\n";
  309. print '<td class="nowrap" valign="top">';
  310. print $prod->getNomUrl(1);
  311. print "</td>\n";
  312. print '<td class="tdtop">'.$prod->label."</td>\n";
  313. // Link to delete from category
  314. print '<td align="right">';
  315. $permission=0;
  316. if ($type == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  317. if ($type == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  318. if ($type == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  319. if ($type == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  320. if ($type == Categorie::TYPE_PROJECT) $permission=$user->rights->projet->creer;
  321. if ($permission)
  322. {
  323. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$prod->id."'>";
  324. print img_delete($langs->trans("DeleteFromCat")).' ';
  325. print $langs->trans("DeleteFromCat")."</a>";
  326. }
  327. print '</td>';
  328. print "</tr>\n";
  329. }
  330. }
  331. else
  332. {
  333. print "<tr ".$bc[false].'><td colspan="2" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoProduct")."</td></tr>";
  334. }
  335. print "</table>\n";
  336. }
  337. }
  338. if ($type == Categorie::TYPE_SUPPLIER)
  339. {
  340. $socs = $object->getObjectsInCateg("supplier");
  341. if ($socs < 0)
  342. {
  343. dol_print_error($db, $socs->error, $socs->errors);
  344. }
  345. else
  346. {
  347. print "<br>";
  348. print '<table class="noborder" width="100%">'."\n";
  349. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Suppliers")." (".count($socs).")</td></tr>\n";
  350. if (count($socs) > 0)
  351. {
  352. foreach ($socs as $soc)
  353. {
  354. print "\t".'<tr class="oddeven">'."\n";
  355. print '<td class="nowrap" valign="top">';
  356. print $soc->getNomUrl(1);
  357. print "</td>\n";
  358. // Link to delete from category
  359. print '<td align="right">';
  360. $permission=0;
  361. if ($type == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  362. if ($type == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  363. if ($type == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  364. if ($type == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  365. if ($type == Categorie::TYPE_PROJECT) $permission=$user->rights->projet->creer;
  366. if ($permission)
  367. {
  368. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$soc->id."'>";
  369. print img_delete($langs->trans("DeleteFromCat")).' ';
  370. print $langs->trans("DeleteFromCat")."</a>";
  371. }
  372. print '</td>';
  373. print "</tr>\n";
  374. }
  375. }
  376. else
  377. {
  378. print '<tr '.$bc[false].'><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoSupplier").'</td></tr>';
  379. }
  380. print "</table>\n";
  381. }
  382. }
  383. if($type == Categorie::TYPE_CUSTOMER)
  384. {
  385. $socs = $object->getObjectsInCateg("customer");
  386. if ($socs < 0)
  387. {
  388. dol_print_error($db, $socs->error, $socs->errors);
  389. }
  390. else
  391. {
  392. print "<br>";
  393. print '<table class="noborder" width="100%">'."\n";
  394. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Customers")." (".count($socs).")</td></tr>\n";
  395. if (count($socs) > 0)
  396. {
  397. $i = 0;
  398. foreach ($socs as $key => $soc)
  399. {
  400. if ($user->societe_id > 0 && $soc->id != $user->societe_id) continue; // External user always see only themself
  401. $i++;
  402. print "\t".'<tr class="oddeven">'."\n";
  403. print '<td class="nowrap" valign="top">';
  404. print $soc->getNomUrl(1);
  405. print "</td>\n";
  406. // Link to delete from category
  407. print '<td align="right">';
  408. $permission=0;
  409. if ($type == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  410. if ($type == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  411. if ($type == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  412. if ($type == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  413. if ($type == Categorie::TYPE_PROJECT) $permission=$user->rights->projet->creer;
  414. if ($permission)
  415. {
  416. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$soc->id."'>";
  417. print img_delete($langs->trans("DeleteFromCat")).' ';
  418. print $langs->trans("DeleteFromCat")."</a>";
  419. }
  420. print '</td>';
  421. print "</tr>\n";
  422. }
  423. }
  424. else
  425. {
  426. print '<tr '.$bc[false].'><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoCustomer").'</td></tr>';
  427. }
  428. print "</table>\n";
  429. }
  430. }
  431. // List of members
  432. if ($type == Categorie::TYPE_MEMBER)
  433. {
  434. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  435. $prods = $object->getObjectsInCateg("member");
  436. if ($prods < 0)
  437. {
  438. dol_print_error($db, $prods->error, $prods->errors);
  439. }
  440. else
  441. {
  442. print "<br>";
  443. print "<table class='noborder' width='100%'>\n";
  444. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Member")." (".count($prods).")</td></tr>\n";
  445. if (count($prods) > 0)
  446. {
  447. foreach ($prods as $key => $member)
  448. {
  449. print "\t".'<tr class="oddeven">'."\n";
  450. print '<td class="nowrap" valign="top">';
  451. $member->ref=$member->login;
  452. print $member->getNomUrl(1,0);
  453. print "</td>\n";
  454. print '<td class="tdtop">'.$member->lastname."</td>\n";
  455. print '<td class="tdtop">'.$member->firstname."</td>\n";
  456. // Link to delete from category
  457. print '<td align="right">';
  458. $permission=0;
  459. if ($type == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  460. if ($type == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  461. if ($type == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  462. if ($type == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  463. if ($type == Categorie::TYPE_PROJECT) $permission=$user->rights->projet->creer;
  464. if ($permission)
  465. {
  466. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$member->id."'>";
  467. print img_delete($langs->trans("DeleteFromCat")).' ';
  468. print $langs->trans("DeleteFromCat")."</a>";
  469. }
  470. print "</tr>\n";
  471. }
  472. }
  473. else
  474. {
  475. print '<tr '.$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoMember").'</td></tr>';
  476. }
  477. print "</table>\n";
  478. }
  479. }
  480. // Categorie contact
  481. if ($type == Categorie::TYPE_CONTACT)
  482. {
  483. $contacts = $object->getObjectsInCateg("contact");
  484. if ($contacts < 0)
  485. {
  486. dol_print_error($db, $contacts->error, $contacts->errors);
  487. }
  488. else
  489. {
  490. print "<br>";
  491. print '<table class="noborder" width="100%">'."\n";
  492. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Contact")." (".count($contacts).")</td></tr>\n";
  493. if (count($contacts) > 0)
  494. {
  495. $i = 0;
  496. foreach ($contacts as $key => $contact)
  497. {
  498. $i++;
  499. print "\t".'<tr class="oddeven">'."\n";
  500. print '<td class="nowrap" valign="top">';
  501. print $contact->getNomUrl(1,'category');
  502. print "</td>\n";
  503. // Link to delete from category
  504. print '<td align="right">';
  505. $permission=0;
  506. if ($type == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  507. if ($type == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  508. if ($type == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  509. if ($type == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  510. if ($type == Categorie::TYPE_PROJECT) $permission=$user->rights->projet->creer;
  511. if ($permission)
  512. {
  513. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$contact->id."'>";
  514. print img_delete($langs->trans("DeleteFromCat")).' ';
  515. print $langs->trans("DeleteFromCat")."</a>";
  516. }
  517. print '</td>';
  518. print "</tr>\n";
  519. }
  520. }
  521. else
  522. {
  523. print '<tr '.$bc[false].'><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoContact").'</td></tr>';
  524. }
  525. print "</table>\n";
  526. }
  527. }
  528. // List of accounts
  529. if ($type == Categorie::TYPE_ACCOUNT)
  530. {
  531. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  532. $accounts = $object->getObjectsInCateg("account");
  533. if ($accounts < 0)
  534. {
  535. dol_print_error($db, $accounts->error, $accounts->errors);
  536. }
  537. else
  538. {
  539. print "<br>";
  540. print "<table class='noborder' width='100%'>\n";
  541. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Account")." (".count($accounts).")</td></tr>\n";
  542. if (count($accounts) > 0)
  543. {
  544. foreach ($accounts as $key => $account)
  545. {
  546. print "\t".'<tr class="oddeven">'."\n";
  547. print '<td class="nowrap" valign="top">';
  548. print $account->getNomUrl(1,0);
  549. print "</td>\n";
  550. print '<td class="tdtop">'.$account->bank."</td>\n";
  551. print '<td class="tdtop">'.$account->number."</td>\n";
  552. // Link to delete from category
  553. print '<td align="right">';
  554. $permission=0;
  555. if ($type == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  556. if ($type == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  557. if ($type == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  558. if ($type == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  559. if ($type == Categorie::TYPE_PROJECT) $permission=$user->rights->projet->creer;
  560. if ($permission)
  561. {
  562. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$account->id."'>";
  563. print img_delete($langs->trans("DeleteFromCat")).' ';
  564. print $langs->trans("DeleteFromCat")."</a>";
  565. }
  566. print "</tr>\n";
  567. }
  568. }
  569. else
  570. {
  571. print '<tr '.$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoAccount").'</td></tr>';
  572. }
  573. print "</table>\n";
  574. }
  575. }
  576. // List of Project
  577. if ($type == Categorie::TYPE_PROJECT)
  578. {
  579. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  580. $projects = $object->getObjectsInCateg("project");
  581. if ($projects < 0)
  582. {
  583. dol_print_error($db, $object->error, $object->errors);
  584. }
  585. else
  586. {
  587. print "<br>";
  588. print "<table class='noborder' width='100%'>\n";
  589. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Project")." (".count($projects).")</td></tr>\n";
  590. if (count($projects) > 0)
  591. {
  592. foreach ($projects as $key => $project)
  593. {
  594. print "\t".'<tr class="oddeven">'."\n";
  595. print '<td class="nowrap" valign="top">';
  596. print $project->getNomUrl(1);
  597. print "</td>\n";
  598. print '<td class="tdtop">'.$project->ref."</td>\n";
  599. print '<td class="tdtop">'.$project->title."</td>\n";
  600. // Link to delete from category
  601. print '<td align="right">';
  602. $permission=0;
  603. if ($type == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  604. if ($type == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  605. if ($type == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  606. if ($type == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  607. if ($type == Categorie::TYPE_PROJECT) $permission=$user->rights->projet->creer;
  608. if ($permission)
  609. {
  610. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$project->id."'>";
  611. print img_delete($langs->trans("DeleteFromCat")).' ';
  612. print $langs->trans("DeleteFromCat")."</a>";
  613. }
  614. print "</tr>\n";
  615. }
  616. }
  617. else
  618. {
  619. print '<tr '.$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoProject").'</td></tr>';
  620. }
  621. print "</table>\n";
  622. }
  623. }
  624. // End of page
  625. llxFooter();
  626. $db->close();