contacts.tpl.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2015-2016 Charlie BENKE <charlie@patas-monkey.com>
  5. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * This template needs:
  21. * $object
  22. * $withproject (if we are on task contact)
  23. *
  24. * $preselectedtypeofcontact may be defined or not
  25. */
  26. // Protection to avoid direct call of template
  27. if (empty($object) || !is_object($object)) {
  28. print "Error, template page can't be called as URL";
  29. exit;
  30. }
  31. if (empty($preselectedtypeofcontact)) {
  32. $preselectedtypeofcontact = 0;
  33. }
  34. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  36. $module = $object->element;
  37. // Special cases
  38. if ($module == 'propal') {
  39. $permission = $user->rights->propale->creer;
  40. } elseif ($module == 'fichinter') {
  41. $permission = $user->rights->ficheinter->creer;
  42. } elseif ($module == 'order_supplier') {
  43. if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
  44. $permission = $user->rights->fournisseur->commande->creer;
  45. } else {
  46. $permission = $user->rights->supplier_order->creer;
  47. }
  48. } elseif ($module == 'invoice_supplier' && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
  49. if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
  50. $permission = $user->rights->fournisseur->facture->creer;
  51. } else {
  52. $permission = $user->rights->supplier_invoice->creer;
  53. }
  54. } elseif ($module == 'project') {
  55. $permission = $user->rights->projet->creer;
  56. } elseif ($module == 'action') {
  57. $permission = $user->rights->agenda->myactions->create;
  58. } elseif ($module == 'shipping') {
  59. $permission = $user->rights->expedition->creer;
  60. } elseif ($module == 'reception') {
  61. $permission = $user->rights->reception->creer;
  62. } elseif ($module == 'project_task') {
  63. $permission = $user->rights->projet->creer;
  64. } elseif (!isset($permission) && isset($user->rights->$module->creer)) {
  65. $permission = $user->rights->$module->creer;
  66. } elseif (!isset($permission) && isset($user->rights->$module->write)) {
  67. $permission = $user->rights->$module->write;
  68. }
  69. $formcompany = new FormCompany($db);
  70. $companystatic = new Societe($db);
  71. $contactstatic = new Contact($db);
  72. $userstatic = new User($db);
  73. ?>
  74. <!-- BEGIN PHP TEMPLATE CONTACTS -->
  75. <?php
  76. if ($permission) {
  77. print '<div class="underbanner clearboth"></div>'."\n";
  78. print '<div class="div-table-responsive-no-min">'."\n";
  79. print '<div class="tagtable tableforcontact centpercent noborder nobordertop allwidth">'."\n";
  80. ?>
  81. <form class="tagtr liste_titre">
  82. <div class="tagtd liste_titre"><?php echo img_object('', 'company', 'class="optiongrey paddingright"').$langs->trans("ThirdParty"); ?></div>
  83. <div class="tagtd liste_titre"><?php echo img_picto($langs->trans("Users"), 'user', 'class="optiongrey paddingright"').$langs->trans("Users").' | '.img_picto($langs->trans("Contacts"), 'contact', 'class="optiongrey paddingright"').$langs->trans("Contacts"); ?></div>
  84. <div class="tagtd liste_titre"><?php echo $langs->trans("ContactType"); ?></div>
  85. <div class="tagtd liste_titre">&nbsp;</div>
  86. <div class="tagtd liste_titre">&nbsp;</div>
  87. </form>
  88. <?php
  89. if (empty($hideaddcontactforuser)) {
  90. ?>
  91. <form class="tagtr impair nohover" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id; ?>" method="POST">
  92. <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
  93. <input type="hidden" name="id" value="<?php echo $object->id; ?>" />
  94. <input type="hidden" name="action" value="addcontact" />
  95. <input type="hidden" name="source" value="internal" />
  96. <?php if (!empty($withproject)) {
  97. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  98. } ?>
  99. <div class="tagtd"><?php echo $conf->global->MAIN_INFO_SOCIETE_NOM; ?></div>
  100. <!-- <div class="nowrap tagtd"><?php echo img_object('', 'user').' '.$langs->trans("Users"); ?></div> -->
  101. <div class="tagtd maxwidthonsmartphone"><?php echo img_object('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($user->id, 'userid', 0, (!empty($userAlreadySelected) ? $userAlreadySelected : null), 0, null, null, 0, 56, 0, '', 0, '', 'minwidth100imp widthcentpercentminusxx maxwidth400'); ?></div>
  102. <div class="tagtd maxwidthonsmartphone">
  103. <?php
  104. $tmpobject = $object;
  105. if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) {
  106. $tmpobject = $objectsrc;
  107. }
  108. $formcompany->selectTypeContact($tmpobject, '', 'type', 'internal', 'position', 0, 'minwidth125imp widthcentpercentminusx maxwidth400');
  109. ?></div>
  110. <div class="tagtd">&nbsp;</div>
  111. <div class="tagtd center"><input type="submit" class="button small" value="<?php echo $langs->trans("Add"); ?>"></div>
  112. </form>
  113. <?php
  114. }
  115. if (empty($hideaddcontactforthirdparty)) {
  116. ?>
  117. <form class="tagtr pair nohover" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id; ?>" method="POST">
  118. <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
  119. <input type="hidden" name="id" value="<?php echo $object->id; ?>" />
  120. <input type="hidden" name="action" value="addcontact" />
  121. <input type="hidden" name="source" value="external" />
  122. <input type="hidden" name="page_y" value="" />
  123. <?php if (!empty($withproject)) {
  124. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  125. } ?>
  126. <div class="tagtd nowrap noborderbottom">
  127. <?php
  128. $selectedCompany = GETPOSTISSET("newcompany") ? GETPOST("newcompany", 'int') : (empty($object->socid) ? 0 : $object->socid);
  129. $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', '', 0, '', 'minwidth300imp'); ?>
  130. </div>
  131. <div class="tagtd noborderbottom minwidth500imp">
  132. <?php
  133. print img_object('', 'contact', 'class="pictofixedwidth"').$form->selectcontacts(($selectedCompany > 0 ? $selectedCompany : -1), '', 'contactid', 3, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400');
  134. $nbofcontacts = $form->num;
  135. $newcardbutton = '';
  136. if (!empty($object->socid) && $object->socid > 1 && $user->rights->societe->creer) {
  137. $newcardbutton .= '<a href="'.DOL_URL_ROOT.'/contact/card.php?socid='.$selectedCompany.'&action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'" title="'.$langs->trans('NewContact').'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
  138. }
  139. print $newcardbutton;
  140. ?>
  141. </div>
  142. <div class="tagtd noborderbottom">
  143. <?php
  144. $tmpobject = $object;
  145. if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) {
  146. $tmpobject = $objectsrc;
  147. }
  148. $formcompany->selectTypeContact($tmpobject, $preselectedtypeofcontact, 'typecontact', 'external', 'position', 0, 'minwidth125imp widthcentpercentminusx maxwidth400');
  149. ?>
  150. </div>
  151. <div class="tagtd noborderbottom">&nbsp;</div>
  152. <div class="tagtd center noborderbottom">
  153. <input type="submit" id="add-customer-contact" class="button small" value="<?php echo $langs->trans("Add"); ?>"<?php if (!$nbofcontacts) {
  154. echo ' disabled';
  155. } ?>>
  156. </div>
  157. </form>
  158. <?php
  159. }
  160. print "</div>";
  161. print "</div>";
  162. print '<br>';
  163. }
  164. // Prepare list
  165. // TODO: replace this with direct SQL string to use $db->sort($sortfield, $sortorder)
  166. $list = array();
  167. foreach (array('internal', 'external') as $source) {
  168. if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) {
  169. $contactlist = $objectsrc->liste_contact(-1, $source);
  170. } else {
  171. $contactlist = $object->liste_contact(-1, $source);
  172. }
  173. foreach ($contactlist as $contact) {
  174. $entry = new stdClass();
  175. $entry->id = $contact['rowid'];
  176. $entry->type = $contact['libelle'];
  177. $entry->nature = "";
  178. $entry->thirdparty_html = "";
  179. $entry->thirdparty_name = "";
  180. $entry->contact_html = "";
  181. $entry->contact_name = "";
  182. $entry->status = "";
  183. if ($contact['source'] == 'internal') {
  184. $entry->nature = $langs->trans("User");
  185. } elseif ($contact['source'] == 'external') {
  186. $entry->nature = $langs->trans("ThirdPartyContact");
  187. }
  188. if ($contact['socid'] > 0) {
  189. $companystatic->fetch($contact['socid']);
  190. $entry->thirdparty_html = $companystatic->getNomUrl(1);
  191. $entry->thirdparty_name = strtolower($companystatic->getFullName($langs));
  192. } elseif ($contact['socid'] < 0) {
  193. $entry->thirdparty_html = $conf->global->MAIN_INFO_SOCIETE_NOM;
  194. $entry->thirdparty_name = strtolower($conf->global->MAIN_INFO_SOCIETE_NOM);
  195. }
  196. if ($contact['source'] == 'internal') {
  197. $userstatic->fetch($contact['id']);
  198. $entry->contact_html = $userstatic->getNomUrl(-1, '', 0, 0, 0, 0, '', 'valignmiddle');
  199. $entry->contact_name = strtolower($userstatic->getFullName($langs));
  200. } elseif ($contact['source'] == 'external') {
  201. $contactstatic->fetch($contact['id']);
  202. $entry->contact_html = $contactstatic->getNomUrl(1, '', 0, '', 0, 0);
  203. $entry->contact_name = strtolower($contactstatic->getFullName($langs));
  204. }
  205. if ($contact['source'] == 'internal') {
  206. $entry->status = $userstatic->LibStatut($contact['statuscontact'], 3);
  207. } elseif ($contact['source'] == 'external') {
  208. $entry->status = $contactstatic->LibStatut($contact['statuscontact'], 3);
  209. }
  210. $list[] = $entry;
  211. }
  212. }
  213. $sortfield = GETPOST("sortfield", "aZ09comma");
  214. $sortorder = GETPOST("sortorder", 'aZ09comma');
  215. if (!$sortfield) {
  216. $sortfield = "nature";
  217. }
  218. if (!$sortorder) {
  219. $sortorder = "asc";
  220. }
  221. // Re-sort list
  222. $list = dol_sort_array($list, $sortfield, $sortorder, 1, 0, 1);
  223. $arrayfields = array(
  224. 'rowid' => array('label'=>$langs->trans("Id"), 'checked'=>1),
  225. 'nature' => array('label'=>$langs->trans("NatureOfContact"), 'checked'=>1),
  226. 'thirdparty' => array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  227. 'contact' => array('label'=>$langs->trans("Users").' | '.$langs->trans("Contacts"), 'checked'=>1),
  228. 'type' => array('label'=>$langs->trans("ContactType"), 'checked'=>1),
  229. 'status' => array('label'=>$langs->trans("Status"), 'checked'=>1),
  230. 'link' => array('label'=>$langs->trans("Link"), 'checked'=>1),
  231. );
  232. $param = 'id='.$object->id.'&mainmenu=home';
  233. /**
  234. * Show list
  235. */
  236. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  237. print '<input type="hidden" name="token" value="'.newToken().'">';
  238. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  239. print '<input type="hidden" name="action" value="list">';
  240. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  241. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  242. print '<div class="div-table-responsive-no-min">'."\n";
  243. print '<table class="tagtable nobottomiftotal liste">';
  244. //print '<tr class="liste_titre_filter">';
  245. //print '</tr>';
  246. print '<tr class="liste_titre">';
  247. print_liste_field_titre($arrayfields['thirdparty']['label'], $_SERVER["PHP_SELF"], "thirdparty_name", "", $param, "", $sortfield, $sortorder);
  248. print_liste_field_titre($arrayfields['contact']['label'], $_SERVER["PHP_SELF"], "contact_name", "", $param, "", $sortfield, $sortorder);
  249. print_liste_field_titre($arrayfields['nature']['label'], $_SERVER["PHP_SELF"], "nature", "", $param, "", $sortfield, $sortorder);
  250. print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "type", "", $param, "", $sortfield, $sortorder);
  251. print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "statut", "", $param, "", $sortfield, $sortorder, 'center ');
  252. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder, 'center maxwidthsearch ');
  253. print "</tr>";
  254. foreach ($list as $entry) {
  255. print '<tr class="oddeven">';
  256. print '<td class="tdoverflowmax200">'.$entry->thirdparty_html.'</td>';
  257. print '<td class="tdoverflowmax200">'.$entry->contact_html.'</td>';
  258. print '<td class="nowrap"><span class="opacitymedium">'.$entry->nature.'</span></td>';
  259. print '<td class="tdoverflowmax200">'.$entry->type.'</td>';
  260. print '<td class="tdoverflowmax200 center">'.$entry->status.'</td>';
  261. if ($permission) {
  262. $href = $_SERVER["PHP_SELF"];
  263. $href .= '?id='.((int) $object->id);
  264. $href .= '&action=deletecontact&token='.newToken();
  265. $href .= '&lineid='.((int) $entry->id);
  266. print '<td class="center">';
  267. print '<a href="'.$href.'">';
  268. print img_picto($langs->trans("Unlink"), "unlink");
  269. print "</a>";
  270. print "</td>";
  271. }
  272. print "</tr>";
  273. }
  274. print "</table>";
  275. print '</div>';
  276. print "</form>";
  277. print "<!-- TEMPLATE CONTACTS HOOK BEGIN HERE -->\n";
  278. if (is_object($hookmanager)) {
  279. $hookmanager->initHooks(array('contacttpl'));
  280. $parameters = array();
  281. $reshook = $hookmanager->executeHooks('formContactTpl', $parameters, $object, $action);
  282. }
  283. print "<!-- END PHP TEMPLATE CONTACTS -->\n";