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