28 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'societeaccount';
45 public $table_element =
'societe_account';
50 public $ismultientitymanaged = 0;
55 public $picto =
'lock';
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'=>
'varchar(128)',
'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),
87 'fk_website' => array(
'type'=>
'integer:Website:website/class/website.class.php',
'label'=>
'WebSite',
'visible'=>1,
'enabled'=>1,
'position'=>42,
'notnull'=>-1,
'index'=>1),
88 'site' => array(
'type'=>
'varchar(128)',
'label'=>
'ExternalSite',
'visible'=>0,
'enabled'=>1,
'position'=>43,
'help'=>
'Name of the website or service if this is account on an external website or service'),
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,),
94 'note_private' => array(
'type'=>
'text',
'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')),
115 public $pass_encoding;
116 public $pass_crypted;
125 public $site_account;
130 public $date_last_login;
133 public $date_previous_login;
134 public $note_private;
139 public $date_creation;
147 public $fk_user_creat;
152 public $fk_user_modif;
175 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->
fields[
'rowid'][
'visible'] = 0;
199 global $hookmanager, $langs;
204 $object =
new self($this->db);
209 $object->fetchCommon($fromid);
212 unset($object->fk_user_creat);
213 unset($object->import_key);
216 $object->ref =
"copy_of_".$object->ref;
217 $object->title = $langs->trans(
"CopyOf").
" ".$object->title;
221 $object->context[
'createfromclone'] =
'createfromclone';
222 $result = $object->createCommon($user);
225 $this->error = $object->error;
226 $this->errors = $object->errors;
229 unset($object->context[
'createfromclone']);
236 $this->
db->rollback();
248 public function fetch($id, $ref = null)
251 if ($result > 0 && !empty($this->table_element_line)) $this->
fetchLines();
262 $this->lines = array();
266 return count($this->lines) ? 1 : 0;
281 $sql =
"SELECT sa.key_account as key_account, sa.entity";
282 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_account as sa";
283 $sql .=
" WHERE sa.fk_soc = ".$id;
284 $sql .=
" AND sa.entity IN (".getEntity(
'societe').
")";
285 $sql .=
" AND sa.site = '".$this->db->escape($site).
"' AND sa.status = ".((int) $status);
286 $sql .=
" AND sa.key_account IS NOT NULL AND sa.key_account <> ''";
287 $sql .=
" AND (sa.site_account = '' OR sa.site_account IS NULL OR sa.site_account = '".$this->db->escape($site_account).
"')";
288 $sql .=
" ORDER BY sa.site_account DESC";
290 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);
291 $result = $this->
db->query($sql);
293 if ($this->
db->num_rows($result)) {
294 $obj = $this->
db->fetch_object($result);
295 $key = $obj->key_account;
319 $sql =
"SELECT sa.fk_soc as fk_soc, sa.key_account, sa.entity";
320 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_account as sa";
321 $sql .=
" WHERE sa.key_account = '".$this->db->escape($id).
"'";
322 $sql .=
" AND sa.entity IN (".getEntity(
'societe').
")";
323 $sql .=
" AND sa.site = '".$this->db->escape($site).
"' AND sa.status = ".((int) $status);
324 $sql .=
" AND sa.fk_soc > 0";
326 dol_syslog(get_class($this).
"::getCustomerAccount Try to find the first thirdparty id for ".$site.
" for external id=".$id, LOG_DEBUG);
327 $result = $this->
db->query($sql);
329 if ($this->
db->num_rows($result)) {
330 $obj = $this->
db->fetch_object($result);
331 $socid = $obj->fk_soc;
357 public function delete(
User $user, $notrigger =
false)
372 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
374 global $db, $conf, $langs;
375 global $dolibarr_main_authentication, $dolibarr_main_demo;
378 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
382 $this->ref = $this->login;
384 $label =
'<u>'.$langs->trans(
"WebsiteAccount").
'</u>';
386 $label .=
'<b>'.$langs->trans(
'Login').
':</b> '.$this->ref;
389 $url =
dol_buildpath(
'/website/websiteaccount_card.php', 1).
'?id='.$this->id;
391 if ($option !=
'nolink')
394 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
395 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
396 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
400 if (empty($notooltip))
402 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
404 $label = $langs->trans(
"WebsiteAccount");
405 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
407 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
408 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
409 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
411 $linkstart =
'<a href="'.$url.
'"';
412 $linkstart .= $linkclose.
'>';
415 $result .= $linkstart;
416 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
417 if ($withpicto != 2) $result .= $this->ref;
431 return $this->
LibStatut($this->status, $mode);
450 if ($status == 1)
return $langs->trans(
'Enabled');
451 elseif ($status == 0)
return $langs->trans(
'Disabled');
452 } elseif ($mode == 1)
454 if ($status == 1)
return $langs->trans(
'Enabled');
455 elseif ($status == 0)
return $langs->trans(
'Disabled');
456 } elseif ($mode == 2)
458 if ($status == 1)
return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
459 elseif ($status == 0)
return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
460 } elseif ($mode == 3)
462 if ($status == 1)
return img_picto($langs->trans(
'Enabled'),
'statut4');
463 elseif ($status == 0)
return img_picto($langs->trans(
'Disabled'),
'statut5');
464 } elseif ($mode == 4)
466 if ($status == 1)
return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
467 elseif ($status == 0)
return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
468 } elseif ($mode == 5)
470 if ($status == 1)
return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
471 elseif ($status == 0)
return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
472 } elseif ($mode == 6)
474 if ($status == 1)
return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
475 elseif ($status == 0)
return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
487 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
488 $sql .=
' fk_user_creat, fk_user_modif';
489 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
490 $sql .=
' WHERE t.rowid = '.$id;
491 $result = $this->
db->query($sql);
494 if ($this->
db->num_rows($result))
496 $obj = $this->
db->fetch_object($result);
497 $this->
id = $obj->rowid;
498 if ($obj->fk_user_author)
500 $cuser =
new User($this->
db);
501 $cuser->fetch($obj->fk_user_author);
502 $this->user_creation = $cuser;
505 if ($obj->fk_user_valid)
507 $vuser =
new User($this->
db);
508 $vuser->fetch($obj->fk_user_valid);
509 $this->user_validation = $vuser;
512 if ($obj->fk_user_cloture)
514 $cluser =
new User($this->
db);
515 $cluser->fetch($obj->fk_user_cloture);
516 $this->user_cloture = $cluser;
519 $this->date_creation = $this->
db->jdate($obj->datec);
520 $this->date_modification = $this->
db->jdate($obj->datem);
521 $this->date_validation = $this->
db->jdate($obj->datev);
524 $this->
db->free($result);
__construct(DoliDB $db)
Constructor.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
fetch($id, $ref=null)
Load object in memory from the database.
static LibStatut($status, $mode=0)
Return the status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
createCommon(User $user, $notrigger=false)
Create object into database.
Class for SocieteAccount.
create(User $user, $notrigger=false)
Create object into database.
getThirdPartyID($id, $site, $status=0)
Try to find the thirdparty id from an another site/system external id.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
update(User $user, $notrigger=false)
Update object into database.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
updateCommon(User $user, $notrigger=false)
Update object into database.
createFromClone(User $user, $fromid)
Clone and object into another one.
print $_SERVER["PHP_SELF"]
Edit parameters.
getCustomerAccount($id, $site, $status=0, $site_account= '')
Try to find the external customer id of a thirdparty for another site/system.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
fetchLines()
Load object lines in memory from the database.
getLibStatut($mode=0)
Retourne le libelle du status d'un user (actif, inactif)
info($id)
Charge les informations d'ordre info dans l'objet commande.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.