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