viewcat.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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@capnetworks.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. $langs->load("categories");
  32. $id=GETPOST('id','int');
  33. $ref=GETPOST('ref');
  34. $type=GETPOST('type');
  35. $action=GETPOST('action');
  36. $confirm=GETPOST('confirm');
  37. $removeelem = GETPOST('removeelem','int');
  38. $elemid=GETPOST('elemid');
  39. if ($id == "")
  40. {
  41. dol_print_error('','Missing parameter id');
  42. exit();
  43. }
  44. // Security check
  45. $result = restrictedArea($user, 'categorie', $id, '&category');
  46. $object = new Categorie($db);
  47. $result=$object->fetch($id);
  48. $object->fetch_optionals($id,$extralabels);
  49. if ($result <= 0)
  50. {
  51. dol_print_error($db,$object->error);
  52. exit;
  53. }
  54. $type=$object->type;
  55. $extrafields = new ExtraFields($db);
  56. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  57. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  58. $hookmanager->initHooks(array('categorycard'));
  59. /*
  60. * Actions
  61. */
  62. // Remove element from category
  63. if ($id > 0 && $removeelem > 0)
  64. {
  65. if ($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer))
  66. {
  67. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  68. $tmpobject = new Product($db);
  69. $result = $tmpobject->fetch($removeelem);
  70. $elementtype = 'product';
  71. }
  72. else if ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer)
  73. {
  74. $tmpobject = new Societe($db);
  75. $result = $tmpobject->fetch($removeelem);
  76. $elementtype = 'fournisseur';
  77. }
  78. else if ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer)
  79. {
  80. $tmpobject = new Societe($db);
  81. $result = $tmpobject->fetch($removeelem);
  82. $elementtype = 'societe';
  83. }
  84. else if ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer)
  85. {
  86. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  87. $tmpobject = new Adherent($db);
  88. $result = $tmpobject->fetch($removeelem);
  89. $elementtype = 'member';
  90. }
  91. else if ($type == Categorie::TYPE_CONTACT && $user->rights->societe->creer) {
  92. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  93. $tmpobject = new Contact($db);
  94. $result = $tmpobject->fetch($removeelem);
  95. $elementtype = 'contact';
  96. }
  97. else if ($type == Categorie::TYPE_ACCOUNT && $user->rights->banque->configurer)
  98. {
  99. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  100. $tmpobject = new Account($db);
  101. $result = $tmpobject->fetch($removeelem);
  102. $elementtype = 'account';
  103. }
  104. $result=$object->del_type($tmpobject,$elementtype);
  105. if ($result < 0) dol_print_error('',$object->error);
  106. }
  107. if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confirm == 'yes')
  108. {
  109. if ($object->delete($user) >= 0)
  110. {
  111. header("Location: ".DOL_URL_ROOT.'/categories/index.php?type='.$type);
  112. exit;
  113. }
  114. else
  115. {
  116. setEventMessages($object->error, $object->errors, 'errors');
  117. }
  118. }
  119. if ($type == Categorie::TYPE_PRODUCT && $elemid && $action == 'addintocategory' && ($user->rights->produit->creer || $user->rights->service->creer))
  120. {
  121. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  122. $newobject = new Product($db);
  123. $result = $newobject->fetch($elemid);
  124. $elementtype = 'product';
  125. // TODO Add into categ
  126. $result=$object->add_type($newobject,$elementtype);
  127. if ($result >= 0)
  128. {
  129. setEventMessages($langs->trans("WasAddedSuccessfully",$newobject->ref), null, 'mesgs');
  130. }
  131. else
  132. {
  133. if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  134. {
  135. setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), null, 'warnings');
  136. }
  137. else
  138. {
  139. setEventMessages($object->error,$object->errors,'errors');
  140. }
  141. }
  142. }
  143. /*
  144. * View
  145. */
  146. $form = new Form($db);
  147. $formother = new FormOther($db);
  148. llxHeader("","",$langs->trans("Categories"));
  149. if ($type == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductsCategoryShort");
  150. elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCategoryShort");
  151. elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort");
  152. elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort");
  153. elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort");
  154. elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort");
  155. else $title=$langs->trans("Category");
  156. $head = categories_prepare_head($object,$type);
  157. dol_fiche_head($head, 'card', $title, 0, 'category');
  158. /*
  159. * Confirmation suppression
  160. */
  161. if ($action == 'delete')
  162. {
  163. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;type='.$type,$langs->trans('DeleteCategory'),$langs->trans('ConfirmDeleteCategory'),'confirm_delete');
  164. }
  165. print '<table width="100%" class="border">';
  166. // Path of category
  167. print '<tr><td class="titlefield notopnoleft">';
  168. $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
  169. print $langs->trans("Ref").'</td><td>';
  170. print '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
  171. foreach ($ways as $way)
  172. {
  173. print $way."<br>\n";
  174. }
  175. print '</td></tr>';
  176. // Description
  177. print '<tr><td class="notopnoleft">';
  178. print $langs->trans("Description").'</td><td>';
  179. print dol_htmlentitiesbr($object->description);
  180. print '</td></tr>';
  181. // Color
  182. print '<tr><td class="notopnoleft">';
  183. print $langs->trans("Color").'</td><td>';
  184. print $formother->showColor($object->color);
  185. print '</td></tr>';
  186. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  187. if (empty($reshook) && ! empty($extrafields->attribute_label))
  188. {
  189. print $object->showOptionals($extrafields);
  190. }
  191. print '</table>';
  192. dol_fiche_end();
  193. /*
  194. * Boutons actions
  195. */
  196. print "<div class='tabsAction'>\n";
  197. if ($user->rights->categorie->creer)
  198. {
  199. $socid = ($object->socid ? "&amp;socid=".$object->socid : "");
  200. print "<a class='butAction' href='edit.php?id=".$object->id.$socid."&amp;type=".$type."'>".$langs->trans("Modify")."</a>";
  201. }
  202. if ($user->rights->categorie->supprimer)
  203. {
  204. print "<a class='butActionDelete' href='".DOL_URL_ROOT."/categories/viewcat.php?action=delete&amp;id=".$object->id."&amp;type=".$type."'>".$langs->trans("Delete")."</a>";
  205. }
  206. print "</div>";
  207. $cats = $object->get_filles();
  208. if ($cats < 0)
  209. {
  210. dol_print_error($db, $cats->error, $cats->errors);
  211. }
  212. else
  213. {
  214. print "<br>";
  215. print "<table class='noborder' width='100%'>\n";
  216. print "<tr class='liste_titre'><td colspan='2'>".$langs->trans("SubCats").'</td><td align="right">';
  217. if ($user->rights->categorie->creer)
  218. {
  219. 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)."'>";
  220. print img_picto($langs->trans("Create"),'filenew');
  221. print "</a>";
  222. }
  223. print "</td>";
  224. print "</tr>\n";
  225. if (count($cats) > 0)
  226. {
  227. $var=true;
  228. foreach ($cats as $cat)
  229. {
  230. $var=!$var;
  231. print "\t<tr ".$bc[$var].">\n";
  232. print "\t\t".'<td class="nowrap">';
  233. print "<a href='viewcat.php?id=".$cat->id."&amp;type=".$type."'>".$cat->label."</a>";
  234. print "</td>\n";
  235. print "\t\t".'<td colspan="2">'.$cat->description."</td>\n";
  236. /*
  237. if ($cat->visible == 1)
  238. {
  239. print "\t\t<td>".$langs->trans("ContentsVisibleByAllShort")."</td>\n";
  240. }
  241. else
  242. {
  243. print "\t\t<td>".$langs->trans("ContentsNotVisibleByAllShort")."</td>\n";
  244. }
  245. */
  246. print "\t</tr>\n";
  247. }
  248. }
  249. else
  250. {
  251. print "<tr ".$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("NoSubCat")."</td></tr>";
  252. }
  253. print "</table>\n";
  254. }
  255. // List of products or services (type is type of category)
  256. if ($object->type == Categorie::TYPE_PRODUCT)
  257. {
  258. $prods = $object->getObjectsInCateg("product");
  259. if ($prods < 0)
  260. {
  261. dol_print_error($db, $prods->error, $prods->errors);
  262. }
  263. else
  264. {
  265. $showclassifyform=1; $typeid=Categorie::TYPE_PRODUCT;
  266. // Form to add record into a category
  267. if ($showclassifyform)
  268. {
  269. print '<br>';
  270. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  271. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  272. print '<input type="hidden" name="typeid" value="'.$typeid.'">';
  273. print '<input type="hidden" name="type" value="'.$typeid.'">';
  274. print '<input type="hidden" name="id" value="'.$object->id.'">';
  275. print '<input type="hidden" name="action" value="addintocategory">';
  276. print '<table class="noborder" width="100%">';
  277. print '<tr class="liste_titre"><td width="40%">';
  278. print $langs->trans("AddProductServiceIntoCategory").' &nbsp;';
  279. print $form->select_produits('','elemid','',0,0,-1,2,'',1);
  280. print '</td><td>';
  281. print '<input type="submit" class="button" value="'.$langs->trans("ClassifyInCategory").'"></td>';
  282. print '</tr>';
  283. print '</table>';
  284. print '</form>';
  285. }
  286. print "<br>";
  287. print "<table class='noborder' width='100%'>\n";
  288. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("ProductsAndServices")."</td></tr>\n";
  289. if (count($prods) > 0)
  290. {
  291. $var=true;
  292. foreach ($prods as $prod)
  293. {
  294. $var=!$var;
  295. print "\t<tr ".$bc[$var].">\n";
  296. print '<td class="nowrap" valign="top">';
  297. print $prod->getNomUrl(1);
  298. print "</td>\n";
  299. print '<td valign="top">'.$prod->label."</td>\n";
  300. // Link to delete from category
  301. print '<td align="right">';
  302. $typeid=$object->type;
  303. $permission=0;
  304. if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  305. if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  306. if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  307. if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  308. if ($permission)
  309. {
  310. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$prod->id."'>";
  311. print img_delete($langs->trans("DeleteFromCat")).' ';
  312. print $langs->trans("DeleteFromCat")."</a>";
  313. }
  314. print '</td>';
  315. print "</tr>\n";
  316. }
  317. }
  318. else
  319. {
  320. print "<tr ".$bc[false].'><td colspan="2" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoProduct")."</td></tr>";
  321. }
  322. print "</table>\n";
  323. }
  324. }
  325. if ($object->type == Categorie::TYPE_SUPPLIER)
  326. {
  327. $socs = $object->getObjectsInCateg("supplier");
  328. if ($socs < 0)
  329. {
  330. dol_print_error($db, $socs->error, $socs->errors);
  331. }
  332. else
  333. {
  334. print "<br>";
  335. print '<table class="noborder" width="100%">'."\n";
  336. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Suppliers")."</td></tr>\n";
  337. if (count($socs) > 0)
  338. {
  339. $var=true;
  340. foreach ($socs as $soc)
  341. {
  342. $var=!$var;
  343. print "\t<tr ".$bc[$var].">\n";
  344. print '<td class="nowrap" valign="top">';
  345. print $soc->getNomUrl(1);
  346. print "</td>\n";
  347. // Link to delete from category
  348. print '<td align="right">';
  349. $typeid=$object->type;
  350. $permission=0;
  351. if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  352. if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  353. if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  354. if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  355. if ($permission)
  356. {
  357. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$soc->id."'>";
  358. print img_delete($langs->trans("DeleteFromCat")).' ';
  359. print $langs->trans("DeleteFromCat")."</a>";
  360. }
  361. print '</td>';
  362. print "</tr>\n";
  363. }
  364. }
  365. else
  366. {
  367. print '<tr '.$bc[false].'><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoSupplier").'</td></tr>';
  368. }
  369. print "</table>\n";
  370. }
  371. }
  372. if($object->type == Categorie::TYPE_CUSTOMER)
  373. {
  374. $socs = $object->getObjectsInCateg("customer");
  375. if ($socs < 0)
  376. {
  377. dol_print_error($db, $socs->error, $socs->errors);
  378. }
  379. else
  380. {
  381. print "<br>";
  382. print '<table class="noborder" width="100%">'."\n";
  383. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Customers")."</td></tr>\n";
  384. if (count($socs) > 0)
  385. {
  386. $i = 0;
  387. $var=true;
  388. foreach ($socs as $key => $soc)
  389. {
  390. if ($user->societe_id > 0 && $soc->id != $user->societe_id) continue; // External user always see only themself
  391. $i++;
  392. $var=!$var;
  393. print "\t<tr ".$bc[$var].">\n";
  394. print '<td class="nowrap" valign="top">';
  395. print $soc->getNomUrl(1);
  396. print "</td>\n";
  397. // Link to delete from category
  398. print '<td align="right">';
  399. $typeid=$object->type;
  400. $permission=0;
  401. if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  402. if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  403. if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  404. if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  405. if ($permission)
  406. {
  407. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$soc->id."'>";
  408. print img_delete($langs->trans("DeleteFromCat")).' ';
  409. print $langs->trans("DeleteFromCat")."</a>";
  410. }
  411. print '</td>';
  412. print "</tr>\n";
  413. }
  414. }
  415. else
  416. {
  417. print '<tr '.$bc[false].'><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoCustomer").'</td></tr>';
  418. }
  419. print "</table>\n";
  420. }
  421. }
  422. // List of members
  423. if ($object->type == Categorie::TYPE_MEMBER)
  424. {
  425. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  426. $prods = $object->getObjectsInCateg("member");
  427. if ($prods < 0)
  428. {
  429. dol_print_error($db, $prods->error, $prods->errors);
  430. }
  431. else
  432. {
  433. print "<br>";
  434. print "<table class='noborder' width='100%'>\n";
  435. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Member")."</td></tr>\n";
  436. if (count($prods) > 0)
  437. {
  438. $var=true;
  439. foreach ($prods as $key => $member)
  440. {
  441. $var=!$var;
  442. print "\t<tr ".$bc[$var].">\n";
  443. print '<td class="nowrap" valign="top">';
  444. $member->ref=$member->login;
  445. print $member->getNomUrl(1,0);
  446. print "</td>\n";
  447. print '<td valign="top">'.$member->lastname."</td>\n";
  448. print '<td valign="top">'.$member->firstname."</td>\n";
  449. // Link to delete from category
  450. print '<td align="right">';
  451. $typeid=$object->type;
  452. $permission=0;
  453. if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  454. if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  455. if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  456. if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  457. if ($permission)
  458. {
  459. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$member->id."'>";
  460. print img_delete($langs->trans("DeleteFromCat")).' ';
  461. print $langs->trans("DeleteFromCat")."</a>";
  462. }
  463. print "</tr>\n";
  464. }
  465. }
  466. else
  467. {
  468. print '<tr '.$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoMember").'</td></tr>';
  469. }
  470. print "</table>\n";
  471. }
  472. }
  473. // Categorie contact
  474. if($object->type == Categorie::TYPE_CONTACT)
  475. {
  476. $contacts = $object->getObjectsInCateg("contact");
  477. if ($contacts < 0)
  478. {
  479. dol_print_error($db, $contacts->error, $contacts->errors);
  480. }
  481. else
  482. {
  483. print "<br>";
  484. print '<table class="noborder" width="100%">'."\n";
  485. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Contact")."</td></tr>\n";
  486. if (count($contacts) > 0)
  487. {
  488. $i = 0;
  489. $var=true;
  490. foreach ($contacts as $key => $contact)
  491. {
  492. $i++;
  493. $var=!$var;
  494. print "\t<tr ".$bc[$var].">\n";
  495. print '<td class="nowrap" valign="top">';
  496. print $contact->getNomUrl(1,'category');
  497. print "</td>\n";
  498. // Link to delete from category
  499. print '<td align="right">';
  500. $typeid=$object->type;
  501. $permission=0;
  502. if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  503. if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  504. if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  505. if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  506. if ($typeid == Categorie::TYPE_CONTACT) $permission=$user->rights->societe->creer;
  507. if ($permission)
  508. {
  509. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$contact->id."'>";
  510. print img_delete($langs->trans("DeleteFromCat")).' ';
  511. print $langs->trans("DeleteFromCat")."</a>";
  512. }
  513. print '</td>';
  514. print "</tr>\n";
  515. }
  516. }
  517. else
  518. {
  519. print '<tr '.$bc[false].'><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoContact").'</td></tr>';
  520. }
  521. print "</table>\n";
  522. }
  523. }
  524. // List of accounts
  525. if ($object->type == Categorie::TYPE_ACCOUNT)
  526. {
  527. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  528. $accounts = $object->getObjectsInCateg("account");
  529. if ($accounts < 0)
  530. {
  531. dol_print_error($db, $accounts->error, $accounts->errors);
  532. }
  533. else
  534. {
  535. print "<br>";
  536. print "<table class='noborder' width='100%'>\n";
  537. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Account")."</td></tr>\n";
  538. if (count($accounts) > 0)
  539. {
  540. $var=true;
  541. foreach ($accounts as $key => $account)
  542. {
  543. $var=!$var;
  544. print "\t<tr ".$bc[$var].">\n";
  545. print '<td class="nowrap" valign="top">';
  546. print $account->getNomUrl(1,0);
  547. print "</td>\n";
  548. print '<td valign="top">'.$account->bank."</td>\n";
  549. print '<td valign="top">'.$account->number."</td>\n";
  550. // Link to delete from category
  551. print '<td align="right">';
  552. $typeid=$object->type;
  553. $permission=0;
  554. if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  555. if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  556. if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  557. if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  558. if ($typeid == Categorie::TYPE_ACCOUNT) $permission=$user->rights->banque->configurer;
  559. if ($permission)
  560. {
  561. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$account->id."'>";
  562. print img_delete($langs->trans("DeleteFromCat")).' ';
  563. print $langs->trans("DeleteFromCat")."</a>";
  564. }
  565. print "</tr>\n";
  566. }
  567. }
  568. else
  569. {
  570. print '<tr '.$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoAccount").'</td></tr>';
  571. }
  572. print "</table>\n";
  573. }
  574. }
  575. llxFooter();
  576. $db->close();