dolibarr 19.0.3
societeaccount.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2015 Raphaƫl Doursenaud <rdoursenaud@gpcsolutions.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31
36{
40 public $element = 'societeaccount';
41
45 public $table_element = 'societe_account';
46
50 public $ismultientitymanaged = 0;
51
55 public $picto = 'lock';
56
57
75 // BEGIN MODULEBUILDER PROPERTIES
79 public $fields = array(
80 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
81 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1),
82 'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'notnull'=>1, 'position'=>10, 'showoncombobox'=>1),
83 'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30),
84 'pass_crypted' => array('type'=>'password', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1),
85 'pass_temp' => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,),
86 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1, 'picto'=>'company', 'css'=>'maxwidth300 widthcentpercentminusxx'),
87 'site' => array('type'=>'varchar(128)', 'label'=>'WebsiteTypeLabel', 'visible'=>0, 'enabled'=>0, 'position'=>41, 'notnull'=>1, 'default' => '', 'help'=>'Name of the website or service if this is account on an external website or service'),
88 'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>0, 'enabled'=>0, 'position'=>42, 'notnull'=>-1, 'index'=>1, 'picto'=>'website', 'css'=>'maxwidth300 widthcentpercentminusxx'),
89 'site_account' => array('type'=>'varchar(128)', 'label'=>'ExternalSiteAccount', 'visible'=>0, 'enabled'=>1, 'position'=>44, 'help'=>'A key to identify the account on external web site if this is an account on an external website'),
90 'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>0, 'enabled'=>1, 'position'=>48, 'notnull'=>0, 'index'=>1, 'searchall'=>1, 'comment'=>'The id of third party in the external web site (for site_account if site_account defined)',),
91 'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,),
92 'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,),
93 //'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
94 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'visible'=>-1, 'enabled'=>1, 'position'=>46, 'notnull'=>-1,),
95 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
96 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
97 'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
98 'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,),
99 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'visible'=>-2, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
100 'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active', '0'=>'Disabled')),
101 );
102
106 public $rowid;
107
111 public $entity;
112
113 public $key_account;
114 public $login;
115 public $pass_encoding;
116 public $pass_crypted;
117 public $pass_temp;
118
122 public $fk_soc;
123
124 public $site;
125 public $site_account;
126
130 public $date_last_login;
131
132
133 public $date_previous_login;
134 public $note_private;
135
139 public $date_creation;
140
141
142 public $tms;
143
147 public $fk_user_creat;
148
152 public $fk_user_modif;
153
154 public $import_key;
155
159 public $status;
160
161 // END MODULEBUILDER PROPERTIES
162
163
164 const STATUS_ENABLED = 1;
165 const STATUS_DISABLED = 0;
166
167
173 public function __construct(DoliDB $db)
174 {
175 global $conf, $langs;
176
177 $this->db = $db;
178
179 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
180 $this->fields['rowid']['visible'] = 0;
181 }
182
183 // add site type list and set visible
184 $site_type_list = array();
185 if (isModEnabled('website')) {
186 $this->fields['fk_website']['visible'] = 1;
187 $this->fields['fk_website']['enabled'] = 1;
188 $this->fields['site']['visible'] = 1;
189 $this->fields['site']['enabled'] = 1;
190 $site_type_list['dolibarr_website'] = $langs->trans('WebsiteTypeDolibarrWebsite');
191 }
192 if (isModEnabled('webportal')) {
193 $this->fields['site']['visible'] = 1;
194 $this->fields['site']['enabled'] = 1;
195 $site_type_list['dolibarr_portal'] = $langs->trans('WebsiteTypeDolibarrPortal');
196 }
197 $this->fields['site']['arrayofkeyval'] = $site_type_list;
198 }
199
207 public function create(User $user, $notrigger = false)
208 {
209 return $this->createCommon($user, $notrigger);
210 }
211
219 public function createFromClone(User $user, $fromid)
220 {
221 global $hookmanager, $langs;
222 $error = 0;
223
224 dol_syslog(__METHOD__, LOG_DEBUG);
225
226 $object = new self($this->db);
227
228 $this->db->begin();
229
230 // Load source object
231 $object->fetchCommon($fromid);
232 // Reset some properties
233 unset($object->id);
234 unset($object->fk_user_creat);
235 unset($object->import_key);
236
237 // Clear fields
238 $object->ref = "copy_of_".$object->ref;
239 // $object->title = $langs->trans("CopyOf")." ".$object->title;
240
241 // Create clone
242 $object->context['createfromclone'] = 'createfromclone';
243 $result = $object->createCommon($user);
244 if ($result < 0) {
245 $error++;
246 $this->error = $object->error;
247 $this->errors = $object->errors;
248 }
249
250 unset($object->context['createfromclone']);
251
252 // End
253 if (!$error) {
254 $this->db->commit();
255 return $object;
256 } else {
257 $this->db->rollback();
258 return -1;
259 }
260 }
261
269 public function fetch($id, $ref = null)
270 {
271 $result = $this->fetchCommon($id, $ref);
272 if ($result > 0 && !empty($this->table_element_line)) {
273 $this->fetchLines();
274 }
275 return $result;
276 }
277
283 public function fetchLines()
284 {
285 $this->lines = array();
286
287 // Load lines with object societeAccountLine
288
289 return count($this->lines) ? 1 : 0;
290 }
291
302 public function getCustomerAccount($id, $site, $status = 0, $site_account = '')
303 {
304 $sql = "SELECT sa.key_account as key_account, sa.entity";
305 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
306 $sql .= " WHERE sa.fk_soc = ".((int) $id);
307 $sql .= " AND sa.entity IN (".getEntity('societe').")";
308 $sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
309 $sql .= " AND sa.key_account IS NOT NULL AND sa.key_account <> ''";
310 $sql .= " AND (sa.site_account = '' OR sa.site_account IS NULL OR sa.site_account = '".$this->db->escape($site_account)."')";
311 $sql .= " ORDER BY sa.site_account DESC"; // To get the entry with a site_account defined in priority
312
313 dol_syslog(get_class($this)."::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG);
314 $result = $this->db->query($sql);
315 if ($result) {
316 if ($this->db->num_rows($result)) {
317 $obj = $this->db->fetch_object($result);
318 $key = $obj->key_account;
319 } else {
320 $key = '';
321 }
322 } else {
323 $key = '';
324 }
325
326 return $key;
327 }
328
338 public function getThirdPartyID($id, $site, $status = 0)
339 {
340 $socid = 0;
341
342 $sql = "SELECT sa.fk_soc as fk_soc, sa.key_account, sa.entity";
343 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
344 $sql .= " WHERE sa.key_account = '".$this->db->escape($id)."'";
345 $sql .= " AND sa.entity IN (".getEntity('societe').")";
346 $sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
347 $sql .= " AND sa.fk_soc > 0";
348
349 dol_syslog(get_class($this)."::getCustomerAccount Try to find the first thirdparty id for ".$site." for external id=".$id, LOG_DEBUG);
350 $result = $this->db->query($sql);
351 if ($result) {
352 if ($this->db->num_rows($result)) {
353 $obj = $this->db->fetch_object($result);
354 $socid = $obj->fk_soc;
355 }
356 }
357
358 return $socid;
359 }
360
368 public function update(User $user, $notrigger = false)
369 {
370 return $this->updateCommon($user, $notrigger);
371 }
372
380 public function delete(User $user, $notrigger = false)
381 {
382 return $this->deleteCommon($user, $notrigger);
383 }
384
391 public function getTooltipContentArray($params)
392 {
393 global $conf, $langs, $user;
394
395 $langs->loadLangs(['companies, commercial']);
396
397 $datas = [];
398 $option = $params['option'] ?? '';
399
400 $datas['picto'] = '<u>'.$langs->trans("WebsiteAccount").'</u>';
401 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
402
403 return $datas;
404 }
405
416 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
417 {
418 global $db, $conf, $langs;
419 global $dolibarr_main_authentication, $dolibarr_main_demo;
420 global $menumanager;
421
422 if (!empty($conf->dol_no_mouse_hover)) {
423 $notooltip = 1; // Force disable tooltips
424 }
425
426 $result = '';
427
428 $this->ref = $this->login;
429
430 $label = '<u>'.$langs->trans("WebsiteAccount").'</u>';
431 $label .= '<br>';
432 $label .= '<b>'.$langs->trans('Login').':</b> '.$this->ref;
433 //$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref;
434
435 $url = DOL_URL_ROOT.'/website/websiteaccount_card.php?id='.$this->id;
436
437 if ($option != 'nolink') {
438 // Add param to save lastsearch_values or not
439 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
440 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
441 $add_save_lastsearch_values = 1;
442 }
443 if ($add_save_lastsearch_values) {
444 $url .= '&save_lastsearch_values=1';
445 }
446 }
447
448 $linkclose = '';
449 $classfortooltip = 'classfortooltip';
450 $dataparams = '';
451 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
452 $params = [
453 'id' => $this->id,
454 'objecttype' => $this->element,
455 'option' => $option,
456 ];
457 $classfortooltip = 'classforajaxtooltip';
458 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
459 $label = '';
460 }
461
462 if (empty($notooltip)) {
463 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
464 $label = $langs->trans("WebsiteAccount");
465 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
466 }
467 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
468 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
469 } else {
470 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
471 }
472
473 $linkstart = '<a href="'.$url.'"';
474 $linkstart .= $linkclose.'>';
475 $linkend = '</a>';
476
477 $result .= $linkstart;
478 if ($withpicto) {
479 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
480 }
481 if ($withpicto != 2) {
482 $result .= $this->ref;
483 }
484 $result .= $linkend;
485
486 return $result;
487 }
488
495 public function getLibStatut($mode = 0)
496 {
497 return $this->LibStatut($this->status, $mode);
498 }
499
500 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
508 public function LibStatut($status, $mode = 0)
509 {
510 // phpcs:enable
511 if (is_null($status)) {
512 return '';
513 }
514
515 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
516 global $langs;
517 //$langs->load("mymodule@mymodule");
518 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
519 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
520 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
521 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
522 }
523
524 $statusType = 'status4';
525 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
526 if ($status == self::STATUS_DISABLED) {
527 $statusType = 'status6';
528 }
529
530 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
531 }
532
539 public function info($id)
540 {
541 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
542 $sql .= ' fk_user_creat, fk_user_modif';
543 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
544 $sql .= ' WHERE t.rowid = '.((int) $id);
545 $result = $this->db->query($sql);
546 if ($result) {
547 if ($this->db->num_rows($result)) {
548 $obj = $this->db->fetch_object($result);
549 $this->id = $obj->rowid;
550
551 $this->user_creation_id = $obj->fk_user_creat;
552 $this->user_modification_id = $obj->fk_user_modif;
553 $this->date_creation = $this->db->jdate($obj->datec);
554 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
555 }
556
557 $this->db->free($result);
558 } else {
559 dol_print_error($this->db);
560 }
561 }
562
569 public function initAsSpecimen()
570 {
571 $this->initAsSpecimenCommon();
572 }
573}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
Class to manage Dolibarr database access.
Class for SocieteAccount.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
create(User $user, $notrigger=false)
Create object into database.
fetch($id, $ref=null)
Load object in memory from the database.
info($id)
Charge les informations d'ordre info dans l'objet commande.
getLibStatut($mode=0)
Return the label of a given status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
getTooltipContentArray($params)
getTooltipContentArray
fetchLines()
Load object lines in memory from the database.
createFromClone(User $user, $fromid)
Clone and object into another one.
__construct(DoliDB $db)
Constructor.
getCustomerAccount($id, $site, $status=0, $site_account='')
Try to find the external customer id of a thirdparty for another site/system.
LibStatut($status, $mode=0)
Return the status.
getThirdPartyID($id, $site, $status=0)
Try to find the thirdparty id from an another site/system external id.
update(User $user, $notrigger=false)
Update object into database.
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.