dolibarr  19.0.0-dev
societecontact.php
Go to the documentation of this file.
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 
30 // Load Dolibarr environment
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('companies', 'orders'));
39 
40 // Get parameters
41 $id = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('socid', 'int');
42 $ref = GETPOST('ref', 'alpha');
43 $action = GETPOST('action', 'aZ09');
44 $massaction = GETPOST('massaction', 'alpha');
45 
46 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
47 $sortfield = GETPOST('sortfield', 'aZ09comma');
48 $sortorder = GETPOST('sortorder', 'aZ09comma');
49 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
50 if (!$sortorder) {
51  $sortorder = "ASC";
52 }
53 if (!$sortfield) {
54  $sortfield = "s.nom";
55 }
56 if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
57  $page = 0;
58 }
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 
63 // Security check
64 if ($user->socid) {
65  $socid = $user->socid;
66 }
67 $result = restrictedArea($user, 'societe', $id, '');
68 
69 
70 // Initialize objects
71 $object = new Societe($db);
72 
73 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
74 $hookmanager->initHooks(array('contactthirdparty', 'globalcard'));
75 
76 
77 /*
78  * Actions
79  */
80 
81 if ($action == 'addcontact' && $user->hasRight('societe', 'creer')) {
82  $result = $object->fetch($id);
83 
84  if ($result > 0 && $id > 0) {
85  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
86  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
87  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
88  }
89 
90  if ($result >= 0) {
91  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
92  exit;
93  } else {
94  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
95  $langs->load("errors");
96  $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
97  } else {
98  $mesg = '<div class="error">'.$object->error.'</div>';
99  }
100  }
101 } elseif ($action == 'swapstatut' && $user->hasRight('societe', 'creer')) {
102  // bascule du statut d'un contact
103  if ($object->fetch($id)) {
104  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
105  } else {
106  dol_print_error($db);
107  }
108 } elseif ($action == 'deletecontact' && $user->hasRight('societe', 'creer')) {
109  // Efface un contact
110  $object->fetch($id);
111  $result = $object->delete_contact(GETPOST("lineid", 'int'));
112 
113  if ($result >= 0) {
114  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
115  exit;
116  } else {
117  dol_print_error($db);
118  }
119 }
120 
121 
122 /*
123  * View
124  */
125 
126 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
127 llxHeader('', $langs->trans("ThirdParty"), $help_url);
128 
129 
130 $form = new Form($db);
131 $formcompany = new FormCompany($db);
132 $formother = new FormOther($db);
133 $contactstatic = new Contact($db);
134 $userstatic = new User($db);
135 
136 
137 // View and edit
138 
139 if ($id > 0 || !empty($ref)) {
140  if ($object->fetch($id, $ref) > 0) {
141  $head = societe_prepare_head($object);
142  print dol_get_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company');
143 
144  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
145  print '<input type="hidden" name="token" value="'.newToken().'">';
146 
147  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
148 
149  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
150 
151  print '<div class="fichecenter">';
152 
153  print '<div class="underbanner clearboth"></div>';
154  print '<table class="border centpercent">';
155 
156  // Prospect/Customer
157  /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
158  print $object->getLibCustProspStatut();
159  print '</td></tr>';
160 
161  // Supplier
162  print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
163  print yn($object->fournisseur);
164  print '</td></tr>';*/
165 
166  if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
167  print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
168  }
169 
170  if ($object->client) {
171  print '<tr><td class="titlefield">';
172  print $langs->trans('CustomerCode').'</td><td colspan="3">';
173  print $object->code_client;
174  $tmpcheck = $object->check_codeclient();
175  if ($tmpcheck != 0 && $tmpcheck != -5) {
176  print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
177  }
178  print '</td></tr>';
179  }
180 
181  if ($object->fournisseur) {
182  print '<tr><td class="titlefield">';
183  print $langs->trans('SupplierCode').'</td><td colspan="3">';
184  print $object->code_fournisseur;
185  $tmpcheck = $object->check_codefournisseur();
186  if ($tmpcheck != 0 && $tmpcheck != -5) {
187  print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
188  }
189  print '</td></tr>';
190  }
191  print '</table>';
192 
193  print '</div>';
194 
195  print '</form>';
196  print '<br>';
197 
198  // Contacts lines (modules that overwrite templates must declare this into descriptor)
199  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
200  foreach ($dirtpls as $reldir) {
201  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
202  if ($res) {
203  break;
204  }
205  }
206 
207  // additionnal list with adherents of company
208  if (isModEnabled('adherent') && $user->rights->adherent->lire) {
209  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
210  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
211 
212  $membertypestatic = new AdherentType($db);
213  $memberstatic = new Adherent($db);
214 
215  $langs->load("members");
216  $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
217  $sql .= " d.datefin,";
218  $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
219  $sql .= " t.libelle as type, t.subscription";
220  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
221  $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
222  $sql .= " WHERE d.fk_soc = ".((int) $id);
223  $sql .= " AND d.fk_adherent_type = t.rowid";
224 
225  dol_syslog("get list sql=".$sql);
226  $resql = $db->query($sql);
227  if ($resql) {
228  $num = $db->num_rows($resql);
229 
230  if ($num > 0) {
231  $param = '';
232 
233  $titre = $langs->trans("MembersListOfTiers");
234  print '<br>';
235 
236  print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, '');
237 
238  print "<table class=\"noborder\" width=\"100%\">";
239  print '<tr class="liste_titre">';
240  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", $param, "", "", $sortfield, $sortorder);
241  print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder);
242  print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder);
243  print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", $param, "", "", $sortfield, $sortorder);
244  print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder);
245  print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder);
246  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder);
247  print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", '', $sortfield, $sortorder, 'center ');
248  print "</tr>\n";
249 
250  $i = 0;
251  while ($i < $num && $i < $conf->liste_limit) {
252  $objp = $db->fetch_object($resql);
253 
254  $datefin = $db->jdate($objp->datefin);
255  $memberstatic->id = $objp->rowid;
256  $memberstatic->ref = $objp->rowid;
257  $memberstatic->lastname = $objp->lastname;
258  $memberstatic->firstname = $objp->firstname;
259  $memberstatic->statut = $objp->statut;
260  $memberstatic->datefin = $db->jdate($objp->datefin);
261 
262  $companyname = $objp->company;
263 
264  print '<tr class="oddeven">';
265 
266  // Ref
267  print "<td>";
268  print $memberstatic->getNomUrl(1);
269  print "</td>\n";
270 
271  // Lastname
272  print "<td><a href=\"card.php?rowid=$objp->rowid\">";
273  print ((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
274  print (((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : '');
275  print (!empty($companyname) ? dol_trunc($companyname, 32) : '');
276  print "</a></td>\n";
277 
278  // Login
279  print "<td>".$objp->login."</td>\n";
280 
281  // Type
282  $membertypestatic->id = $objp->type_id;
283  $membertypestatic->libelle = $objp->type;
284  $membertypestatic->label = $objp->type;
285 
286  print '<td class="nowrap">';
287  print $membertypestatic->getNomUrl(1, 32);
288  print '</td>';
289 
290  // Moral/Physique
291  print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
292 
293  // EMail
294  print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
295 
296  // Statut
297  print '<td class="nowrap">';
298  print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2);
299  print "</td>";
300 
301  // End of subscription date
302  if ($datefin) {
303  print '<td class="center nowrap">';
304  print dol_print_date($datefin, 'day');
305  if ($memberstatic->hasDelay()) {
306  print " ".img_warning($langs->trans("SubscriptionLate"));
307  }
308  print '</td>';
309  } else {
310  print '<td class="left nowrap">';
311  if (!empty($objp->subscription)) {
312  print $langs->trans("SubscriptionNotReceived");
313  if ($objp->statut > 0) {
314  print " ".img_warning();
315  }
316  } else {
317  print '&nbsp;';
318  }
319  print '</td>';
320  }
321 
322  print "</tr>\n";
323  $i++;
324  }
325  print "</table>\n";
326  }
327  }
328  }
329  } else {
330  // Contrat non trouve
331  print "ErrorRecordNotFound";
332  }
333 }
334 
335 // End of page
336 llxFooter();
337 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage members of a foundation.
Class to manage members type.
Class to manage contact/addresses.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:48
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.