dolibarr 22.0.5
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
32// Load Dolibarr environment
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
38
47// Load translation files required by the page
48$langs->loadLangs(array('companies', 'orders'));
49
50// Get parameters
51$id = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
52$ref = GETPOST('ref', 'alpha');
53$action = GETPOST('action', 'aZ09');
54$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
55$massaction = GETPOST('massaction', 'alpha');
56$optioncss = GETPOST('optioncss', 'alpha');
57
58$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
59$sortfield = GETPOST('sortfield', 'aZ09comma');
60$sortorder = GETPOST('sortorder', 'aZ09comma');
61$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
62if (!$sortorder) {
63 $sortorder = "ASC";
64}
65if (!$sortfield) {
66 $sortfield = "s.nom";
67}
68if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
69 $page = 0;
70}
71$offset = $limit * $page;
72$pageprev = $page - 1;
73$pagenext = $page + 1;
74
75// Security check
76if ($user->socid) {
77 $socid = $user->socid;
78}
79
80// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
81$hookmanager->initHooks(array('thirdpartycontact', 'thirdpartycontactcard', 'globalcard'));
82
83$result = restrictedArea($user, 'societe', $id, '');
84
85
86// Initialize objects
87$object = new Societe($db);
88
89/*
90 * Actions
91 */
92
93$parameters = array('id' => $id);
94$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
95if ($reshook < 0) {
96 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
97}
98if (empty($reshook)) {
99 if ($action == 'addcontact' && $user->hasRight('societe', 'creer')) {
100 $result = $object->fetch($id);
101
102 if ($result > 0 && $id > 0) {
103 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
104 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
105 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
106 }
107
108 if ($result >= 0) {
109 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
110 exit;
111 } else {
112 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
113 $langs->load("errors");
114 $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
115 } else {
116 $mesg = '<div class="error">'.$object->error.'</div>';
117 }
118 }
119 } elseif ($action == 'swapstatut' && $user->hasRight('societe', 'creer')) {
120 // bascule du statut d'un contact
121 if ($object->fetch($id)) {
122 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
123 } else {
124 dol_print_error($db);
125 }
126 } elseif ($action == 'deletecontact' && $user->hasRight('societe', 'creer')) {
127 // Efface un contact
128 $object->fetch($id);
129 $result = $object->delete_contact(GETPOSTINT("lineid"));
130
131 if ($result >= 0) {
132 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
133 exit;
134 } else {
135 dol_print_error($db);
136 }
137 }
138}
139
140
141/*
142 * View
143 */
144
145$form = new Form($db);
146$formcompany = new FormCompany($db);
147$formother = new FormOther($db);
148$contactstatic = new Contact($db);
149$userstatic = new User($db);
150
151$title = $langs->trans("ContactAddress", $object->name);
152if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
153 $title = $object->name." - ".$title;
154}
155$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
156llxHeader('', $title, $help_url);
157
158
159// View and edit
160
161if ($id > 0 || !empty($ref)) {
162 if ($object->fetch($id, $ref) > 0) {
163 $head = societe_prepare_head($object);
164 print dol_get_fiche_head($head, 'contactext', $langs->trans("ThirdParty"), -1, 'company');
165
166 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
167 print '<input type="hidden" name="token" value="'.newToken().'">';
168
169 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
170
171 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
172
173 print '<div class="fichecenter">';
174
175 print '<div class="underbanner clearboth"></div>';
176 print '<table class="border centpercent">';
177
178 // Prospect/Customer
179 /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
180 print $object->getLibCustProspStatut();
181 print '</td></tr>';
182
183 // Supplier
184 print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
185 print yn($object->fournisseur);
186 print '</td></tr>';*/
187
188 if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
189 print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
190 }
191
192 if ($object->client) {
193 print '<tr><td class="titlefield">';
194 print $langs->trans('CustomerCode').'</td><td colspan="3">';
195 print $object->code_client;
196 $tmpcheck = $object->check_codeclient();
197 if ($tmpcheck != 0 && $tmpcheck != -5) {
198 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
199 }
200 print '</td></tr>';
201 }
202
203 if ($object->fournisseur) {
204 print '<tr><td class="titlefield">';
205 print $langs->trans('SupplierCode').'</td><td colspan="3">';
206 print $object->code_fournisseur;
207 $tmpcheck = $object->check_codefournisseur();
208 if ($tmpcheck != 0 && $tmpcheck != -5) {
209 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
210 }
211 print '</td></tr>';
212 }
213 print '</table>';
214
215 print '</div>';
216
217 print '</form>';
218 print '<br>';
219
220 // Contacts lines (modules that overwrite templates must declare this into descriptor)
221 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
222 foreach ($dirtpls as $reldir) {
223 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
224 if ($res) {
225 break;
226 }
227 }
228
229 // additional list with adherents of company
230 if (isModEnabled('member') && $user->hasRight('adherent', 'lire')) {
231 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
232 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
233
234 $membertypestatic = new AdherentType($db);
235 $memberstatic = new Adherent($db);
236
237 $langs->load("members");
238 $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
239 $sql .= " d.datefin,";
240 $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
241 $sql .= " t.libelle as type_label, t.subscription";
242 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
243 $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
244 $sql .= " WHERE d.entity IN (".getEntity('member').")";
245 $sql .= " AND d.fk_soc = ".((int) $id);
246 $sql .= " AND d.fk_adherent_type = t.rowid";
247
248 dol_syslog("get list sql=".$sql);
249 $resql = $db->query($sql);
250 if ($resql) {
251 $num = $db->num_rows($resql);
252
253 if ($num > 0) {
254 $param = '';
255
256 $titre = $langs->trans("MembersListOfTiers");
257 print '<br>';
258
259 print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, '');
260
261 print "<table class=\"noborder\" width=\"100%\">";
262 print '<tr class="liste_titre">';
263 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
264 print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
265 print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", "", $param, "", $sortfield, $sortorder);
266 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", "", $param, "", $sortfield, $sortorder);
267 print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", "", $param, "", $sortfield, $sortorder);
268 print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", "", $param, "", $sortfield, $sortorder);
269 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", "", $param, "", $sortfield, $sortorder);
270 print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", "", $param, '', $sortfield, $sortorder, 'center ');
271 print "</tr>\n";
272
273 $i = 0;
274 while ($i < $num && $i < $conf->liste_limit) {
275 $objp = $db->fetch_object($resql);
276
277 $datefin = $db->jdate($objp->datefin);
278 $memberstatic->id = $objp->rowid;
279 $memberstatic->ref = $objp->rowid;
280 $memberstatic->lastname = $objp->lastname;
281 $memberstatic->firstname = $objp->firstname;
282 $memberstatic->statut = $objp->statut; // deprecated
283 $memberstatic->status = $objp->statut;
284 $memberstatic->datefin = $db->jdate($objp->datefin);
285
286 $companyname = $objp->company;
287
288 print '<tr class="oddeven">';
289
290 // Ref
291 print "<td>";
292 print $memberstatic->getNomUrl(1);
293 print "</td>\n";
294
295 // Lastname
296 print "<td><a href=\"card.php?rowid=$objp->rowid\">";
297 print((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
298 print(((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : '');
299 print(!empty($companyname) ? dol_trunc($companyname, 32) : '');
300 print "</a></td>\n";
301
302 // Login
303 print "<td>".$objp->login."</td>\n";
304
305 // Type
306 $membertypestatic->id = $objp->type_id;
307 $membertypestatic->libelle = $objp->type_label; // deprecated
308 $membertypestatic->label = $objp->type_label;
309
310 print '<td class="nowrap">';
311 print $membertypestatic->getNomUrl(1, 32);
312 print '</td>';
313
314 // Moral/Physique
315 print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
316
317 // EMail
318 print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
319
320 // Statut
321 print '<td class="nowrap">';
322 print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2);
323 print "</td>";
324
325 // End of subscription date
326 if ($datefin) {
327 print '<td class="center nowrap">';
328 print dol_print_date($datefin, 'day');
329 if ($memberstatic->hasDelay()) {
330 print " ".img_warning($langs->trans("SubscriptionLate"));
331 }
332 print '</td>';
333 } else {
334 print '<td class="left nowrap">';
335 if (!empty($objp->subscription)) {
336 print $langs->trans("SubscriptionNotReceived");
337 if ($objp->statut > 0) {
338 print " ".img_warning();
339 }
340 } else {
341 print '&nbsp;';
342 }
343 print '</td>';
344 }
345
346 print "</tr>\n";
347 $i++;
348 }
349 print "</table>\n";
350 }
351 }
352 }
353 } else {
354 // Contrat non trouve
355 print "ErrorRecordNotFound";
356 }
357}
358
359// End of page
360llxFooter();
361$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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.
Class 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.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $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 '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.