dolibarr 24.0.0-beta
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';
41require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
45
46// Load translation files required by the page
47$langs->loadLangs(array('companies', 'orders'));
48
49// Get parameters
50$id = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
51$ref = GETPOST('ref', 'alpha');
52$action = GETPOST('action', 'aZ09');
53$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
54$massaction = GETPOST('massaction', 'alpha');
55$optioncss = GETPOST('optioncss', 'alpha');
56
57$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
58$sortfield = GETPOST('sortfield', 'aZ09comma');
59$sortorder = GETPOST('sortorder', 'aZ09comma');
60$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
61if (!$sortorder) {
62 $sortorder = "ASC";
63}
64if (!$sortfield) {
65 $sortfield = "s.nom";
66}
67if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
68 // If $page is not defined, or '' or -1 or if we click on clear filters
69 $page = 0;
70}
71$offset = $limit * $page;
72$pageprev = $page - 1;
73$pagenext = $page + 1;
74
75// Security check
76$socid = 0;
77if ($user->socid) {
78 $socid = $user->socid;
79}
80
81// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
82$hookmanager->initHooks(array('thirdpartycontact', 'thirdpartycontactcard', 'globalcard'));
83
84$result = restrictedArea($user, 'societe', $id, '');
85
86
87// Initialize objects
88$object = new Societe($db);
89
90/*
91 * Actions
92 */
93
94$parameters = array('id' => $id);
95$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
96if ($reshook < 0) {
97 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
98}
99if (empty($reshook)) {
100 if ($action == 'addcontact' && $user->hasRight('societe', 'creer')) {
101 $result = $object->fetch($id);
102
103 if ($result > 0 && $id > 0) {
104 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
105 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
106 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
107 }
108
109 if ($result >= 0) {
110 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
111 exit;
112 } else {
113 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
114 $langs->load("errors");
115 $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
116 } else {
117 $mesg = '<div class="error">'.$object->error.'</div>';
118 }
119 }
120 } elseif ($action == 'swapstatut' && $user->hasRight('societe', 'creer')) {
121 // bascule du statut d'un contact
122 if ($object->fetch($id)) {
123 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
124 } else {
126 }
127 } elseif ($action == 'deletecontact' && $user->hasRight('societe', 'creer')) {
128 // Efface un contact
129 $object->fetch($id);
130 $result = $object->delete_contact(GETPOSTINT("lineid"));
131
132 if ($result >= 0) {
133 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
134 exit;
135 } else {
137 }
138 }
139}
140
141
142/*
143 * View
144 */
145
146$form = new Form($db);
147$formcompany = new FormCompany($db);
148$formother = new FormOther($db);
149$contactstatic = new Contact($db);
150$userstatic = new User($db);
151
152$title = $langs->trans("ContactAddress", $object->name);
153if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
154 $title = $object->name." - ".$title;
155}
156$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
157llxHeader('', $title, $help_url);
158
159
160// View and edit
161
162if ($id > 0 || !empty($ref)) {
163 if ($object->fetch($id, $ref) > 0) {
164 $head = societe_prepare_head($object);
165 print dol_get_fiche_head($head, 'contactext', $langs->trans("ThirdParty"), -1, 'company');
166
167 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
168 print '<input type="hidden" name="token" value="'.newToken().'">';
169
170 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
171
172 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
173
174 print '<div class="fichecenter">';
175
176 print '<div class="underbanner clearboth"></div>';
177 print '<table class="border centpercent">';
178
179 // Prospect/Customer
180 /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
181 print $object->getLibCustProspStatut();
182 print '</td></tr>';
183
184 // Supplier
185 print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
186 print yn($object->fournisseur);
187 print '</td></tr>';*/
188
189 if ($object->client) {
190 print '<tr><td class="titlefield">';
191 print $langs->trans('CustomerCode').'</td><td colspan="3">';
192 print $object->code_client;
193 $tmpcheck = $object->check_codeclient();
194 if ($tmpcheck != 0 && $tmpcheck != -5) {
195 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
196 }
197 print '</td></tr>';
198 }
199
200 if ($object->fournisseur) {
201 print '<tr><td class="titlefield">';
202 print $langs->trans('SupplierCode').'</td><td colspan="3">';
203 print $object->code_fournisseur;
204 $tmpcheck = $object->check_codefournisseur();
205 if ($tmpcheck != 0 && $tmpcheck != -5) {
206 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
207 }
208 print '</td></tr>';
209 }
210 print '</table>';
211
212 print '</div>';
213
214 print '</form>';
215
216 print '<br><br>';
217
218 // Contacts lines (modules that overwrite templates must declare this into descriptor)
219 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
220 foreach ($dirtpls as $reldir) {
221 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
222 if ($res) {
223 break;
224 }
225 }
226
227 // additional list with adherents of company
228 if (isModEnabled('member') && $user->hasRight('adherent', 'lire')) {
229 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
230 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
231
232 $membertypestatic = new AdherentType($db);
233 $memberstatic = new Adherent($db);
234
235 $langs->load("members");
236 $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
237 $sql .= " d.datefin,";
238 $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
239 $sql .= " t.libelle as type_label, t.subscription";
240 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
241 $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
242 $sql .= " WHERE d.entity IN (".getEntity('member').")";
243 $sql .= " AND d.fk_soc = ".((int) $id);
244 $sql .= " AND d.fk_adherent_type = t.rowid";
245
246 dol_syslog("get list sql=".$sql);
247 $resql = $db->query($sql);
248 if ($resql) {
249 $num = $db->num_rows($resql);
250
251 if ($num > 0) {
252 $param = '';
253
254 $titre = $langs->trans("MembersListOfTiers");
255 print '<br>';
256
257 print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, '');
258
259 print "<table class=\"noborder\" width=\"100%\">";
260 print '<tr class="liste_titre">';
261 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
262 print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
263 print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", "", $param, "", $sortfield, $sortorder);
264 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", "", $param, "", $sortfield, $sortorder);
265 print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", "", $param, "", $sortfield, $sortorder);
266 print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", "", $param, "", $sortfield, $sortorder);
267 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", "", $param, "", $sortfield, $sortorder);
268 print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", "", $param, '', $sortfield, $sortorder, 'center ');
269 print "</tr>\n";
270
271 $i = 0;
272 while ($i < $num && $i < $conf->liste_limit) {
273 $objp = $db->fetch_object($resql);
274
275 $datefin = $db->jdate($objp->datefin);
276 $memberstatic->id = $objp->rowid;
277 $memberstatic->ref = $objp->rowid;
278 $memberstatic->lastname = $objp->lastname;
279 $memberstatic->firstname = $objp->firstname;
280 $memberstatic->statut = $objp->statut; // deprecated
281 $memberstatic->status = $objp->statut;
282 $memberstatic->datefin = $db->jdate($objp->datefin);
283
284 $companyname = $objp->company;
285
286 print '<tr class="oddeven">';
287
288 // Ref
289 print "<td>";
290 print $memberstatic->getNomUrl(1);
291 print "</td>\n";
292
293 // Lastname
294 print "<td><a href=\"card.php?rowid=$objp->rowid\">";
295 print((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
296 print(((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : '');
297 print(!empty($companyname) ? dol_trunc($companyname, 32) : '');
298 print "</a></td>\n";
299
300 // Login
301 print "<td>".$objp->login."</td>\n";
302
303 // Type
304 $membertypestatic->id = $objp->type_id;
305 $membertypestatic->libelle = $objp->type_label; // deprecated
306 $membertypestatic->label = $objp->type_label;
307
308 print '<td class="nowrap">';
309 print $membertypestatic->getNomUrl(1, 32);
310 print '</td>';
311
312 // Moral/Physique
313 print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
314
315 // EMail
316 print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
317
318 // Statut
319 print '<td class="nowrap">';
320 print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2);
321 print "</td>";
322
323 // End of subscription date
324 if ($datefin) {
325 print '<td class="center nowrap">';
326 print dol_print_date($datefin, 'day');
327 if ($memberstatic->hasDelay()) {
328 print " ".img_warning($langs->trans("SubscriptionLate"));
329 }
330 print '</td>';
331 } else {
332 print '<td class="left nowrap">';
333 if (!empty($objp->subscription)) {
334 print $langs->trans("SubscriptionNotReceived");
335 if ($objp->statut > 0) {
336 print " ".img_warning();
337 }
338 } else {
339 print '&nbsp;';
340 }
341 print '</td>';
342 }
343
344 print "</tr>\n";
345 $i++;
346 }
347 print "</table>\n";
348 }
349 }
350 }
351 } else {
352 // Contrat non trouve
353 print "ErrorRecordNotFound";
354 }
355}
356
357// End of page
358llxFooter();
359$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 to help generate other html components Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
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.