societecontact.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2014 Charles-Fr Benke <charles.fr@benke.fr>
  7. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/societe/societecontact.php
  24. * \ingroup societe
  25. * \brief Tab to manage differently contact. Used when unstable feature MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES is on.
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('companies', 'orders'));
  35. // Get parameters
  36. $id = GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('socid', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. $massaction = GETPOST('massaction', 'alpha');
  40. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  41. $sortfield = GETPOST('sortfield', 'aZ09comma');
  42. $sortorder = GETPOST('sortorder', 'aZ09comma');
  43. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  44. if (!$sortorder) {
  45. $sortorder = "ASC";
  46. }
  47. if (!$sortfield) {
  48. $sortfield = "s.nom";
  49. }
  50. if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
  51. $page = 0;
  52. }
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. // Security check
  57. if ($user->socid) {
  58. $socid = $user->socid;
  59. }
  60. $result = restrictedArea($user, 'societe', $id, '');
  61. // Initialize objects
  62. $object = new Societe($db);
  63. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  64. $hookmanager->initHooks(array('contactthirdparty', 'globalcard'));
  65. /*
  66. * Actions
  67. */
  68. if ($action == 'addcontact' && $user->hasRight('societe', 'creer')) {
  69. $result = $object->fetch($id);
  70. if ($result > 0 && $id > 0) {
  71. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  72. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  73. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  74. }
  75. if ($result >= 0) {
  76. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  77. exit;
  78. } else {
  79. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  80. $langs->load("errors");
  81. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  82. } else {
  83. $mesg = '<div class="error">'.$object->error.'</div>';
  84. }
  85. }
  86. } elseif ($action == 'swapstatut' && $user->hasRight('societe', 'creer')) {
  87. // bascule du statut d'un contact
  88. if ($object->fetch($id)) {
  89. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  90. } else {
  91. dol_print_error($db);
  92. }
  93. } elseif ($action == 'deletecontact' && $user->hasRight('societe', 'creer')) {
  94. // Efface un contact
  95. $object->fetch($id);
  96. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  97. if ($result >= 0) {
  98. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  99. exit;
  100. } else {
  101. dol_print_error($db);
  102. }
  103. }
  104. /*
  105. * View
  106. */
  107. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  108. llxHeader('', $langs->trans("ThirdParty"), $help_url);
  109. $form = new Form($db);
  110. $formcompany = new FormCompany($db);
  111. $formother = new FormOther($db);
  112. $contactstatic = new Contact($db);
  113. $userstatic = new User($db);
  114. // View and edit
  115. if ($id > 0 || !empty($ref)) {
  116. if ($object->fetch($id, $ref) > 0) {
  117. $head = societe_prepare_head($object);
  118. print dol_get_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company');
  119. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  120. print '<input type="hidden" name="token" value="'.newToken().'">';
  121. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  122. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  123. print '<div class="fichecenter">';
  124. print '<div class="underbanner clearboth"></div>';
  125. print '<table class="border centpercent">';
  126. // Prospect/Customer
  127. /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
  128. print $object->getLibCustProspStatut();
  129. print '</td></tr>';
  130. // Supplier
  131. print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
  132. print yn($object->fournisseur);
  133. print '</td></tr>';*/
  134. if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
  135. print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  136. }
  137. if ($object->client) {
  138. print '<tr><td class="titlefield">';
  139. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  140. print $object->code_client;
  141. $tmpcheck = $object->check_codeclient();
  142. if ($tmpcheck != 0 && $tmpcheck != -5) {
  143. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  144. }
  145. print '</td></tr>';
  146. }
  147. if ($object->fournisseur) {
  148. print '<tr><td class="titlefield">';
  149. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  150. print $object->code_fournisseur;
  151. $tmpcheck = $object->check_codefournisseur();
  152. if ($tmpcheck != 0 && $tmpcheck != -5) {
  153. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  154. }
  155. print '</td></tr>';
  156. }
  157. print '</table>';
  158. print '</div>';
  159. print '</form>';
  160. print '<br>';
  161. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  162. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  163. foreach ($dirtpls as $reldir) {
  164. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  165. if ($res) {
  166. break;
  167. }
  168. }
  169. // additionnal list with adherents of company
  170. if (isModEnabled('adherent') && $user->hasRight('adherent', 'lire')) {
  171. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  172. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  173. $membertypestatic = new AdherentType($db);
  174. $memberstatic = new Adherent($db);
  175. $langs->load("members");
  176. $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
  177. $sql .= " d.datefin,";
  178. $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
  179. $sql .= " t.libelle as type_label, t.subscription";
  180. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
  181. $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
  182. $sql .= " WHERE d.fk_soc = ".((int) $id);
  183. $sql .= " AND d.fk_adherent_type = t.rowid";
  184. dol_syslog("get list sql=".$sql);
  185. $resql = $db->query($sql);
  186. if ($resql) {
  187. $num = $db->num_rows($resql);
  188. if ($num > 0) {
  189. $param = '';
  190. $titre = $langs->trans("MembersListOfTiers");
  191. print '<br>';
  192. print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, '');
  193. print "<table class=\"noborder\" width=\"100%\">";
  194. print '<tr class="liste_titre">';
  195. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", $param, "", "", $sortfield, $sortorder);
  196. print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder);
  197. print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder);
  198. print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", $param, "", "", $sortfield, $sortorder);
  199. print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder);
  200. print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder);
  201. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder);
  202. print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", '', $sortfield, $sortorder, 'center ');
  203. print "</tr>\n";
  204. $i = 0;
  205. while ($i < $num && $i < $conf->liste_limit) {
  206. $objp = $db->fetch_object($resql);
  207. $datefin = $db->jdate($objp->datefin);
  208. $memberstatic->id = $objp->rowid;
  209. $memberstatic->ref = $objp->rowid;
  210. $memberstatic->lastname = $objp->lastname;
  211. $memberstatic->firstname = $objp->firstname;
  212. $memberstatic->statut = $objp->statut;
  213. $memberstatic->datefin = $db->jdate($objp->datefin);
  214. $companyname = $objp->company;
  215. print '<tr class="oddeven">';
  216. // Ref
  217. print "<td>";
  218. print $memberstatic->getNomUrl(1);
  219. print "</td>\n";
  220. // Lastname
  221. print "<td><a href=\"card.php?rowid=$objp->rowid\">";
  222. print((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
  223. print(((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : '');
  224. print(!empty($companyname) ? dol_trunc($companyname, 32) : '');
  225. print "</a></td>\n";
  226. // Login
  227. print "<td>".$objp->login."</td>\n";
  228. // Type
  229. $membertypestatic->id = $objp->type_id;
  230. $membertypestatic->libelle = $objp->type_label; // deprecated
  231. $membertypestatic->label = $objp->type_label;
  232. print '<td class="nowrap">';
  233. print $membertypestatic->getNomUrl(1, 32);
  234. print '</td>';
  235. // Moral/Physique
  236. print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
  237. // EMail
  238. print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
  239. // Statut
  240. print '<td class="nowrap">';
  241. print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2);
  242. print "</td>";
  243. // End of subscription date
  244. if ($datefin) {
  245. print '<td class="center nowrap">';
  246. print dol_print_date($datefin, 'day');
  247. if ($memberstatic->hasDelay()) {
  248. print " ".img_warning($langs->trans("SubscriptionLate"));
  249. }
  250. print '</td>';
  251. } else {
  252. print '<td class="left nowrap">';
  253. if (!empty($objp->subscription)) {
  254. print $langs->trans("SubscriptionNotReceived");
  255. if ($objp->statut > 0) {
  256. print " ".img_warning();
  257. }
  258. } else {
  259. print '&nbsp;';
  260. }
  261. print '</td>';
  262. }
  263. print "</tr>\n";
  264. $i++;
  265. }
  266. print "</table>\n";
  267. }
  268. }
  269. }
  270. } else {
  271. // Contrat non trouve
  272. print "ErrorRecordNotFound";
  273. }
  274. }
  275. // End of page
  276. llxFooter();
  277. $db->close();