categorie.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  7. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  9. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  10. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/categories/categorie.php
  27. * \ingroup category
  28. * \brief Page to show category tab
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  32. $langs->load("categories");
  33. $langs->load("products");
  34. $socid = GETPOST('socid','int');
  35. $id = GETPOST('id','int');
  36. $ref = GETPOST('ref');
  37. $type = GETPOST('type');
  38. $removecat = GETPOST('removecat','int');
  39. $parent=GETPOST('parent','int');
  40. $dbtablename = '';
  41. // For categories on third parties
  42. if (! empty($socid)) $id = $socid;
  43. if (! isset($type)) $type = Categorie::TYPE_PRODUCT;
  44. if ($type == Categorie::TYPE_SUPPLIER || $type == Categorie::TYPE_CUSTOMER) $socid = $id;
  45. if ($id || $ref)
  46. {
  47. if ($type == Categorie::TYPE_PRODUCT) {
  48. $elementtype = 'product';
  49. $objecttype = 'produit|service&categorie';
  50. $objectid = isset($id)?$id:(isset($ref)?$ref:'');
  51. $dbtablename = 'product';
  52. $fieldid = isset($ref)?'ref':'rowid';
  53. }
  54. elseif ($type == Categorie::TYPE_SUPPLIER) {
  55. $elementtype = 'fournisseur';
  56. $objecttype = 'societe&categorie';
  57. $objectid = isset($id)?$id:(isset($socid)?$socid:'');
  58. $dbtablename = '&societe';
  59. $fieldid = 'rowid';
  60. }
  61. elseif ($type == Categorie::TYPE_CUSTOMER) {
  62. $elementtype = 'societe';
  63. $objecttype = 'societe&categorie';
  64. $objectid = isset($id)?$id:(isset($socid)?$socid:'');
  65. $dbtablename = '&societe';
  66. $fieldid = 'rowid';
  67. }
  68. elseif ($type == Categorie::TYPE_MEMBER) {
  69. $elementtype = 'member';
  70. $objecttype = 'adherent&categorie';
  71. $objectid = isset($id)?$id:(isset($ref)?$ref:'');
  72. $dbtablename = 'adherent';
  73. $fieldid = ! empty($ref)?'ref':'rowid';
  74. }
  75. elseif ($type == Categorie::TYPE_CONTACT) {
  76. $elementtype = 'societe';
  77. $objecttype = 'contact';
  78. $objectid = isset($id)?$id:(isset($ref)?$ref:'');
  79. $dbtablename = 'socpeople&societe';
  80. $fieldid = ! empty($ref)?'ref':'rowid';
  81. }
  82. }
  83. // Security check
  84. if ($user->societe_id) $socid=$user->societe_id;
  85. $result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid);
  86. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  87. $hookmanager->initHooks(array('categorycard','globalcard'));
  88. /*
  89. * Actions
  90. */
  91. $parameters=array('id'=>$socid);
  92. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  93. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  94. if (empty($reshook))
  95. {
  96. // Remove element from category
  97. if ($removecat > 0)
  98. {
  99. if ($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer))
  100. {
  101. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  102. $object = new Product($db);
  103. $result = $object->fetch($id, $ref);
  104. $elementtype = 'product';
  105. }
  106. if ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer)
  107. {
  108. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  109. $object = new Fournisseur($db);
  110. $result = $object->fetch($objectid);
  111. $elementtype = 'fournisseur';
  112. }
  113. if ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer)
  114. {
  115. $object = new Societe($db);
  116. $result = $object->fetch($objectid);
  117. $elementtype = 'societe';
  118. }
  119. if ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer)
  120. {
  121. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  122. $object = new Adherent($db);
  123. $result = $object->fetch($objectid);
  124. $elementtype = 'member';
  125. }
  126. if ($type == Categorie::TYPE_CONTACT && $user->rights->societe->creer)
  127. {
  128. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  129. $object = new Contact($db);
  130. $result = $object->fetch($objectid);
  131. $elementtype = 'contact';
  132. }
  133. $cat = new Categorie($db);
  134. $result=$cat->fetch($removecat);
  135. $result=$cat->del_type($object,$elementtype);
  136. if ($result < 0)
  137. {
  138. setEventMessages($cat->error, $cat->errors, 'errors');
  139. }
  140. }
  141. // Add object into a category
  142. if ($parent > 0)
  143. {
  144. if ($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer))
  145. {
  146. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  147. $object = new Product($db);
  148. $result = $object->fetch($id, $ref);
  149. $elementtype = 'product';
  150. }
  151. if ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer)
  152. {
  153. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  154. $object = new Fournisseur($db);
  155. $result = $object->fetch($objectid);
  156. $elementtype = 'fournisseur';
  157. }
  158. if ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer)
  159. {
  160. $object = new Societe($db);
  161. $result = $object->fetch($objectid);
  162. $elementtype = 'societe';
  163. }
  164. if ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer)
  165. {
  166. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  167. $object = new Adherent($db);
  168. $result = $object->fetch($objectid);
  169. $elementtype = 'member';
  170. }
  171. if ($type == Categorie::TYPE_CONTACT && $user->rights->societe->creer)
  172. {
  173. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  174. $object = new Contact($db);
  175. $result = $object->fetch($objectid);
  176. $elementtype = 'contact';
  177. }
  178. $cat = new Categorie($db);
  179. $result=$cat->fetch($parent);
  180. $result=$cat->add_type($object,$elementtype);
  181. if ($result >= 0)
  182. {
  183. setEventMessages($langs->trans("WasAddedSuccessfully",$cat->label), null, 'mesgs');
  184. }
  185. else
  186. {
  187. if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  188. {
  189. setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), null, 'warnings');
  190. }
  191. else
  192. {
  193. setEventMessages($cat->error, $cat->errors, 'errors');
  194. }
  195. }
  196. }
  197. }
  198. /*
  199. * View
  200. */
  201. $form = new Form($db);
  202. /*
  203. * Fiche categorie de client et/ou fournisseur
  204. */
  205. if ($socid)
  206. {
  207. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  208. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  209. $langs->load("companies");
  210. if (! empty($conf->notification->enabled)) $langs->load("mails");
  211. $soc = new Societe($db);
  212. $result = $soc->fetch($socid);
  213. $title=$langs->trans("Category");
  214. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$soc->name." - ".$title;
  215. llxHeader("",$title);
  216. // Show tabs
  217. $head = societe_prepare_head($soc);
  218. dol_fiche_head($head, 'category', $langs->trans("ThirdParty"),0,'company');
  219. print '<table class="border" width="100%">';
  220. print '<tr><td width="25%">'.$langs->trans("ThirdPartyName").'</td><td colspan="3">';
  221. print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom','','&type='.$type);
  222. print '</td></tr>';
  223. // Alias names (commercial, trademark or alias names)
  224. print '<tr><td valign="top">'.$langs->trans('AliasNames').'</td><td colspan="3">';
  225. print $soc->name_alias;
  226. print "</td></tr>";
  227. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  228. {
  229. print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$soc->prefix_comm.'</td></tr>';
  230. }
  231. if ($soc->client)
  232. {
  233. print '<tr><td>';
  234. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  235. print $soc->code_client;
  236. if ($soc->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
  237. print '</td></tr>';
  238. }
  239. if ($soc->fournisseur)
  240. {
  241. print '<tr><td>';
  242. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  243. print $soc->code_fournisseur;
  244. if ($soc->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
  245. print '</td></tr>';
  246. }
  247. if (! empty($conf->barcode->enabled))
  248. {
  249. print '<tr><td>'.$langs->trans('Gencod').'</td><td colspan="3">'.$soc->barcode.'</td></tr>';
  250. }
  251. // Address
  252. print '<tr><td valign="top">'.$langs->trans('Address').'</td><td colspan="3">';
  253. dol_print_address($soc->address,'gmap','thirdparty',$soc->id);
  254. print '</td></tr>';
  255. // Zip / Town
  256. print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$soc->zip."</td>";
  257. print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$soc->town."</td></tr>";
  258. // Country
  259. if ($soc->country)
  260. {
  261. print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
  262. //$img=picto_from_langcode($soc->country_code);
  263. $img='';
  264. print ($img?$img.' ':'');
  265. print $soc->country;
  266. print '</td></tr>';
  267. }
  268. // EMail
  269. print '<tr><td>'.$langs->trans('EMail').'</td><td colspan="3">';
  270. print dol_print_email($soc->email,0,$soc->id,'AC_EMAIL');
  271. print '</td></tr>';
  272. // Web
  273. print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3">';
  274. print dol_print_url($soc->url);
  275. print '</td></tr>';
  276. // Phone
  277. print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->phone,$soc->country_code,0,$soc->id,'AC_TEL').'</td>';
  278. print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'</td></tr>';
  279. print '</table>';
  280. dol_fiche_end();
  281. if ($soc->client) formCategory($db,$soc,2,$socid,$user->rights->societe->creer);
  282. if ($soc->client && $soc->fournisseur) print '<br><br>';
  283. if ($soc->fournisseur) formCategory($db,$soc,1,$socid,$user->rights->societe->creer);
  284. }
  285. else if ($id || $ref)
  286. {
  287. if ($type == Categorie::TYPE_PRODUCT)
  288. {
  289. $langs->load("products");
  290. /*
  291. * Category card for product
  292. */
  293. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  294. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  295. // Product
  296. $product = new Product($db);
  297. $result = $product->fetch($id, $ref);
  298. llxHeader("","",$langs->trans("CardProduct".$product->type));
  299. $head=product_prepare_head($product);
  300. $titre=$langs->trans("CardProduct".$product->type);
  301. $picto=($product->type== Product::TYPE_SERVICE?'service':'product');
  302. dol_fiche_head($head, 'category', $titre,0,$picto);
  303. print '<table class="border" width="100%">';
  304. // Ref
  305. print "<tr>";
  306. print '<td width="15%">'.$langs->trans("Ref").'</td><td>';
  307. print $form->showrefnav($product,'ref','',1,'ref');
  308. print '</td>';
  309. print '</tr>';
  310. // Label
  311. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->label.'</td>';
  312. print '</tr>';
  313. // Status (to sell)
  314. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
  315. print $product->getLibStatut(2,0);
  316. print '</td></tr>';
  317. // Status (to buy)
  318. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
  319. print $product->getLibStatut(2,1);
  320. print '</td></tr>';
  321. print '</table>';
  322. dol_fiche_end();
  323. formCategory($db,$product,0,$socid,($user->rights->produit->creer || $user->rights->service->creer));
  324. }
  325. if ($type == Categorie::TYPE_MEMBER)
  326. {
  327. $langs->load("members");
  328. /*
  329. * Category card for member
  330. */
  331. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  332. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  333. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  334. // Produit
  335. $member = new Adherent($db);
  336. $result = $member->fetch($id, $ref);
  337. $membert = new AdherentType($db);
  338. $membert->fetch($member->typeid);
  339. llxHeader("","",$langs->trans("Member"));
  340. $head=member_prepare_head($member);
  341. $titre=$langs->trans("Member");
  342. $picto='user';
  343. dol_fiche_head($head, 'category', $titre,0,$picto);
  344. $rowspan=5;
  345. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan+=1;
  346. if (! empty($conf->societe->enabled)) $rowspan++;
  347. print '<table class="border" width="100%">';
  348. // Ref
  349. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  350. print '<td class="valeur">';
  351. print $form->showrefnav($member,'id','','1','rowid','ref','','&type='.$type);
  352. print '</td></tr>';
  353. // Login
  354. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  355. {
  356. print '<tr><td>'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$member->login.'&nbsp;</td></tr>';
  357. }
  358. // Morphy
  359. print '<tr><td>'.$langs->trans("Nature").'</td><td class="valeur" >'.$member->getmorphylib().'</td>';
  360. /*print '<td rowspan="'.$rowspan.'" align="center" valign="middle" width="25%">';
  361. print $form->showphoto('memberphoto',$member);
  362. print '</td>';*/
  363. print '</tr>';
  364. // Type
  365. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$membert->getNomUrl(1)."</td></tr>\n";
  366. // Company
  367. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$member->societe.'</td></tr>';
  368. // Civility
  369. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$member->getCivilityLabel().'&nbsp;</td>';
  370. print '</tr>';
  371. // Lastname
  372. print '<tr><td>'.$langs->trans("Lastname").'</td><td class="valeur">'.$member->lastname.'&nbsp;</td>';
  373. print '</tr>';
  374. // Firstname
  375. print '<tr><td>'.$langs->trans("Firstname").'</td><td class="valeur">'.$member->firstname.'&nbsp;</td>';
  376. print '</tr>';
  377. // Status
  378. print '<tr><td>'.$langs->trans("Status").'</td><td class="valeur">'.$member->getLibStatut(4).'</td></tr>';
  379. print '</table>';
  380. dol_fiche_end();
  381. formCategory($db,$member,3,0,$user->rights->adherent->creer);
  382. }
  383. if ($type == Categorie::TYPE_CONTACT)
  384. {
  385. $langs->load("contact");
  386. /*
  387. * Category card for contact
  388. */
  389. require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
  390. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  391. // Produit
  392. $object = new Contact($db);
  393. $result = $object->fetch($id, $ref);
  394. $object->fetch_thirdparty();
  395. llxHeader("","",$langs->trans("Contact"));
  396. $head=contact_prepare_head($object);
  397. $titre=$langs->trans("ContactsAddresses");
  398. $picto='contact';
  399. dol_fiche_head($head, 'category', $titre,0,$picto);
  400. $rowspan=5;
  401. if (! empty($conf->societe->enabled)) $rowspan++;
  402. print '<table class="border" width="100%">';
  403. // Ref
  404. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  405. print '<td class="valeur">';
  406. print $form->showrefnav($object,'rowid');
  407. print '</td></tr>';
  408. // Name
  409. print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
  410. print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
  411. // Company
  412. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  413. {
  414. print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
  415. if (!empty($object->thirdparty->id))
  416. {
  417. print $object->thirdparty->getNomUrl(1);
  418. }
  419. else
  420. {
  421. print $langs->trans("ContactNotLinkedToCompany");
  422. }
  423. print '</td></tr>';
  424. }
  425. // Civility
  426. print '<tr><td width="15%">'.$langs->trans("UserTitle").'</td><td colspan="3">';
  427. print $object->getCivilityLabel();
  428. print '</td></tr>';
  429. // Role
  430. print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td colspan="3">'.$object->poste.'</td>';
  431. // Address
  432. print '<tr><td>'.$langs->trans("Address").'</td><td colspan="3">';
  433. dol_print_address($object->address,'gmap','contact',$object->id);
  434. print '</td></tr>';
  435. // Zip/Town
  436. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">';
  437. print $object->zip;
  438. if ($object->zip) print '&nbsp;';
  439. print $object->town.'</td></tr>';
  440. // Country
  441. print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
  442. $img=picto_from_langcode($object->country_code);
  443. if ($img) print $img.' ';
  444. print $object->country;
  445. print '</td></tr>';
  446. // State
  447. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  448. {
  449. print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">'.$object->state.'</td>';
  450. }
  451. // Phone
  452. print '<tr><td>'.$langs->trans("PhonePro").'</td><td>'.dol_print_phone($object->phone_pro,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td>';
  453. print '<td>'.$langs->trans("PhonePerso").'</td><td>'.dol_print_phone($object->phone_perso,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td></tr>';
  454. print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td>'.dol_print_phone($object->phone_mobile,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td>';
  455. print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($object->fax,$object->country_code,$object->id,$object->socid,'AC_FAX').'</td></tr>';
  456. // Email
  457. print '<tr><td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($object->email,$object->id,$object->socid,'AC_EMAIL').'</td>';
  458. if (! empty($conf->mailing->enabled))
  459. {
  460. $langs->load("mails");
  461. print '<td class="nowrap">'.$langs->trans("NbOfEMailingsReceived").'</td>';
  462. print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td>';
  463. }
  464. else
  465. {
  466. print '<td colspan="2">&nbsp;</td>';
  467. }
  468. print '</tr>';
  469. // Instant message and no email
  470. print '<tr><td>'.$langs->trans("IM").'</td><td>'.$object->jabberid.'</td>';
  471. if (!empty($conf->mailing->enabled))
  472. {
  473. print '<td>'.$langs->trans("No_Email").'</td><td>'.yn($object->no_email).'</td>';
  474. }
  475. else
  476. {
  477. print '<td colspan="2">&nbsp;</td>';
  478. }
  479. print '</tr>';
  480. print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td colspan="3">';
  481. print $object->LibPubPriv($object->priv);
  482. print '</td></tr>';
  483. // Note Public
  484. print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td><td colspan="3">';
  485. print nl2br($object->note_public);
  486. print '</td></tr>';
  487. // Note Private
  488. print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td><td colspan="3">';
  489. print nl2br($object->note_private);
  490. print '</td></tr>';
  491. // Other attributes
  492. $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"');
  493. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  494. if (empty($reshook) && ! empty($extrafields->attribute_label))
  495. {
  496. print $object->showOptionals($extrafields);
  497. }
  498. print '</table>';
  499. dol_fiche_end();
  500. formCategory($db,$object,4,$socid, $user->rights->societe->creer);
  501. }
  502. }
  503. /**
  504. * Function to output a form to add object into a category
  505. *
  506. * @param DoliDb $db Database handler
  507. * @param Object $object Object we want to see categories it can be classified into
  508. * @param int $typeid Type of category (0, 1, 2, 3)
  509. * @param int $socid Id thirdparty
  510. * @param int $showclassifyform 1=Add form to 'Classify', 0=Do not show form to 'Classify'
  511. * @return int 0
  512. */
  513. function formCategory($db,$object,$typeid,$socid=0,$showclassifyform=1)
  514. {
  515. global $user,$langs,$form,$bc;
  516. $title='NotDefined';
  517. if ($typeid == Categorie::TYPE_PRODUCT) $title = $langs->trans("ProductsCategoriesShort");
  518. if ($typeid == Categorie::TYPE_SUPPLIER) $title = $langs->trans("SuppliersCategoriesShort");
  519. if ($typeid == Categorie::TYPE_CUSTOMER) $title = $langs->trans("CustomersProspectsCategoriesShort");
  520. if ($typeid == Categorie::TYPE_MEMBER) $title = $langs->trans("MembersCategoriesShort");
  521. if ($typeid == Categorie::TYPE_CONTACT) $title = $langs->trans("ContactCategoriesShort");
  522. $linktocreate='';
  523. if ($showclassifyform && $user->rights->categorie->creer)
  524. {
  525. $linktocreate='<a href="'.DOL_URL_ROOT.'/categories/card.php?action=create&amp;origin='.$object->id.'&type='.$typeid.'&urlfrom='.urlencode($_SERVER["PHP_SELF"].'?'.(($typeid==Categorie::TYPE_SUPPLIER||$typeid==Categorie::TYPE_CUSTOMER)?'socid':'id').'='.$object->id.'&type='.$typeid).'">';
  526. $linktocreate.=$langs->trans("CreateCat").' ';
  527. $linktocreate.=img_picto($langs->trans("Create"),'filenew');
  528. $linktocreate.="</a>";
  529. }
  530. print '<br>';
  531. print load_fiche_titre($title,$linktocreate,'');
  532. // Form to add record into a category
  533. if ($showclassifyform)
  534. {
  535. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  536. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  537. print '<input type="hidden" name="typeid" value="'.$typeid.'">';
  538. print '<input type="hidden" name="type" value="'.$typeid.'">';
  539. print '<input type="hidden" name="id" value="'.$object->id.'">';
  540. print '<table class="noborder" width="100%">';
  541. print '<tr class="liste_titre"><td width="40%">';
  542. print '<span class="hideonsmartphone">'.$langs->trans("ClassifyInCategory").' &nbsp;</span>';
  543. print $form->select_all_categories($typeid,'auto');
  544. print '</td>';
  545. print '<td><input type="submit" class="button" value="'.$langs->trans("Classify").'"></td>';
  546. print '</tr>';
  547. print '</table>';
  548. print '</form>';
  549. print '<br>';
  550. }
  551. $c = new Categorie($db);
  552. $cats = $c->containing($object->id,$typeid);
  553. if (count($cats) > 0)
  554. {
  555. if ($typeid == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductIsInCategories");
  556. if ($typeid == Categorie::TYPE_SUPPLIER) $title=$langs->trans("CompanyIsInSuppliersCategories");
  557. if ($typeid == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CompanyIsInCustomersCategories");
  558. if ($typeid == Categorie::TYPE_MEMBER) $title=$langs->trans("MemberIsInCategories");
  559. if ($typeid == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactIsInCategories");
  560. print "\n";
  561. print '<table class="noborder" width="100%">';
  562. print '<tr class="liste_titre"><td colspan="2">'.$title.':</td></tr>';
  563. $var = true;
  564. foreach ($cats as $cat)
  565. {
  566. $ways = $cat->print_all_ways();
  567. foreach ($ways as $way)
  568. {
  569. $var = ! $var;
  570. print "<tr ".$bc[$var].">";
  571. // Categorie
  572. print "<td>".img_object('','category').' '.$way."</td>";
  573. // Link to delete from category
  574. print '<td align="right">';
  575. $permission=0;
  576. if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer);
  577. if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer;
  578. if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
  579. if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
  580. if ($typeid == Categorie::TYPE_CONTACT) $permission=$user->rights->societe->creer;
  581. if ($permission)
  582. {
  583. print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removecat=".$cat->id."'>";
  584. print img_delete($langs->trans("DeleteFromCat")).' ';
  585. print $langs->trans("DeleteFromCat")."</a>";
  586. }
  587. else
  588. {
  589. print '&nbsp;';
  590. }
  591. print "</td>";
  592. print "</tr>\n";
  593. }
  594. }
  595. print "</table>\n";
  596. }
  597. else if ($cats < 0)
  598. {
  599. print $langs->trans("ErrorUnknown");
  600. }
  601. else
  602. {
  603. if ($typeid == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductHasNoCategory");
  604. if ($typeid == Categorie::TYPE_SUPPLIER) $title=$langs->trans("CompanyHasNoCategory");
  605. if ($typeid == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CompanyHasNoCategory");
  606. if ($typeid == Categorie::TYPE_MEMBER) $title=$langs->trans("MemberHasNoCategory");
  607. if ($typeid == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactHasNoCategory");
  608. print $title;
  609. print "<br/>";
  610. }
  611. return 0;
  612. }
  613. llxFooter();
  614. $db->close();