24 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
34 public $element =
'hook';
39 public $table_element =
'zapier_hook';
44 public $ismultientitymanaged = 0;
49 public $isextrafieldmanaged = 1;
54 public $picto =
'hook@zapier';
57 const STATUS_DRAFT = 0;
58 const STATUS_VALIDATED = 1;
59 const STATUS_DISABLED = -1;
85 public $fields = array(
88 'label' =>
'TechnicalID',
109 'label' =>
'UserOwner',
114 'foreignkey' =>
'llx_user.rowid',
117 'type' =>
'varchar(255)',
123 'css' =>
'minwidth200',
124 'help' =>
'Hook url',
125 'showoncombobox' => 1,
128 'type' =>
'varchar(128)',
134 'css' =>
'minwidth200',
135 'help' =>
'Hook module',
136 'showoncombobox' => 1,
139 'type' =>
'varchar(128)',
145 'css' =>
'minwidth200',
146 'help' =>
'Hook action trigger',
147 'showoncombobox' => 1,
150 'type' =>
'varchar(255)',
156 'css' =>
'minwidth200',
158 'showoncombobox' => 1,
160 'date_creation' => array(
161 'type' =>
'datetime',
162 'label' =>
'DateCreation',
168 'import_key' => array(
169 'type' =>
'varchar(14)',
170 'label' =>
'ImportId',
186 'arrayofkeyval' => array(
232 public $date_creation;
242 public $fk_user_creat;
247 public $fk_user_modif;
262 global $conf, $langs, $user;
266 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->
fields[
'rowid'])) {
267 $this->
fields[
'rowid'][
'visible'] = 0;
269 if (empty($conf->multicompany->enabled) && isset($this->
fields[
'entity'])) {
270 $this->
fields[
'entity'][
'enabled'] = 0;
274 foreach ($this->
fields as $key => $val) {
275 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
276 unset($this->
fields[$key]);
281 foreach ($this->
fields as $key => $val) {
282 if (is_array($this->
fields[
'status'][
'arrayofkeyval'])) {
283 foreach ($this->
fields[
'status'][
'arrayofkeyval'] as $key2 => $val2) {
284 $this->
fields[
'status'][
'arrayofkeyval'][$key2] = $langs->trans($val2);
311 global $langs, $hookmanager, $extrafields;
316 $object =
new self($this->db);
321 $object->fetchCommon($fromid);
324 unset($object->fk_user_creat);
325 unset($object->import_key);
328 $object->ref =
"copy_of_".$object->ref;
329 $object->title = $langs->trans(
"CopyOf").
" ".$object->title;
332 if (is_array($object->array_options) && count($object->array_options) > 0) {
333 $extrafields->fetch_name_optionals_label($this->table_element);
334 foreach ($object->array_options as $key => $option) {
335 $shortkey = preg_replace(
'/options_/',
'', $key);
336 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
340 unset($object->array_options[$key]);
346 $object->context[
'createfromclone'] =
'createfromclone';
347 $result = $object->createCommon($user);
350 $this->error = $object->error;
351 $this->errors = $object->errors;
354 unset($object->context[
'createfromclone']);
361 $this->
db->rollback();
373 public function fetch($id, $ref = null)
376 if ($result > 0 && !empty($this->table_element_line)) {
407 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
418 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
419 $sql .=
' WHERE t.entity = '.$conf->entity;
422 if (count($filter) > 0) {
423 foreach ($filter as $key => $value) {
424 if ($key ==
't.rowid') {
425 $sqlwhere[] = $key.
'='.$value;
426 } elseif (strpos($key,
'date') !==
false) {
427 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
428 } elseif ($key ==
'customsql') {
429 $sqlwhere[] = $value;
431 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
435 if (count($sqlwhere) > 0) {
436 $sql .=
' AND ('.implode(
' '.$filtermode.
' ', $sqlwhere).
')';
439 if (!empty($sortfield)) {
440 $sql .= $this->
db->order($sortfield, $sortorder);
442 if (!empty($limit)) {
443 $sql .=
' '.$this->db->plimit($limit, $offset);
450 while ($obj = $this->
db->fetch_object(
$resql)) {
451 $record =
new self($this->db);
453 $record->id = $obj->rowid;
457 $records[$record->id] = $record;
463 $this->errors[] =
'Error '.$this->db->lasterror();
464 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
489 public function delete(
User $user, $notrigger =
false)
505 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
507 global $db, $conf, $langs, $hookmanager, $action;
508 global $dolibarr_main_authentication, $dolibarr_main_demo;
511 if (!empty($conf->dol_no_mouse_hover)) {
518 $label =
'<u>'.$langs->trans(
"Hook").
'</u>';
520 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
522 $url =
dol_buildpath(
'/zapier/hook_card.php', 1).
'?id='.$this->id;
524 if ($option !=
'nolink') {
526 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
527 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) {
528 $add_save_lastsearch_values = 1;
530 if ($add_save_lastsearch_values) {
531 $url .=
'&save_lastsearch_values=1';
536 if (empty($notooltip)) {
537 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
538 $label = $langs->trans(
"ShowMyObject");
539 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
541 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
542 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
551 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
554 $linkstart =
'<a href="'.$url.
'"';
555 $linkstart .= $linkclose.
'>';
558 $result .= $linkstart;
560 $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);
562 if ($withpicto != 2) {
563 $result .= $this->ref;
568 $hookmanager->initHooks(array(
'hookdao'));
571 'getnomurl' => $result,
574 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
576 $result = $hookmanager->resPrint;
578 $result .= $hookmanager->resPrint;
597 return $this->
LibStatut($this->status, $mode);
614 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
617 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans(
'Disabled');
618 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
619 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans(
'Disabled');
620 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
623 $statusType =
'status5';
624 if ($status == self::STATUS_VALIDATED) $statusType =
'status4';
626 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
637 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
638 $sql .=
' fk_user_creat, fk_user_modif';
639 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
640 $sql .=
' WHERE t.rowid = '.$id;
641 $result = $this->
db->query($sql);
643 if ($this->
db->num_rows($result)) {
644 $obj = $this->
db->fetch_object($result);
645 $this->
id = $obj->rowid;
646 if ($obj->fk_user_author) {
647 $cuser =
new User($this->
db);
648 $cuser->fetch($obj->fk_user_author);
649 $this->user_creation = $cuser;
652 if ($obj->fk_user_valid) {
653 $vuser =
new User($this->
db);
654 $vuser->fetch($obj->fk_user_valid);
655 $this->user_validation = $vuser;
658 if ($obj->fk_user_cloture) {
659 $cluser =
new User($this->
db);
660 $cluser->fetch($obj->fk_user_cloture);
661 $this->user_cloture = $cluser;
664 $this->date_creation = $this->
db->jdate($obj->datec);
665 $this->date_modification = $this->
db->jdate($obj->datem);
666 $this->date_validation = $this->
db->jdate($obj->datev);
669 $this->
db->free($result);
695 global $conf, $langs;
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
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
info($id)
Load the info information in the object.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
LibStatut($status, $mode=0)
Return the status.
Class to manage Dolibarr database access.
getLibStatut($mode=0)
Return label of the status.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
update(User $user, $notrigger=false)
Update object into database.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load object lines in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
create(User $user, $notrigger=false)
Create object into database.
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.
print $_SERVER["PHP_SELF"]
Edit parameters.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
createFromClone(User $user, $fromid)
Clone an object into another one.
fetch($id, $ref=null)
Load object in memory from the database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.