24require_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',
127 'type' =>
'varchar(128)',
133 'css' =>
'minwidth200',
134 'help' =>
'Hook module'
137 'type' =>
'varchar(128)',
143 'css' =>
'minwidth200',
144 'help' =>
'Hook action trigger'
147 'type' =>
'varchar(255)',
153 'css' =>
'minwidth200',
155 'showoncombobox' => 1,
157 'date_creation' => array(
158 'type' =>
'datetime',
159 'label' =>
'DateCreation',
165 'import_key' => array(
166 'type' =>
'varchar(14)',
167 'label' =>
'ImportId',
183 'arrayofkeyval' => array(
229 public $date_creation;
239 public $fk_user_creat;
244 public $fk_user_modif;
259 global $conf, $langs, $user;
264 $this->fields[
'rowid'][
'visible'] = 0;
266 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
267 $this->fields[
'entity'][
'enabled'] = 0;
271 foreach ($this->fields as $key => $val) {
272 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
273 unset($this->fields[$key]);
278 foreach ($this->fields as $key => $val) {
279 if (is_array($this->fields[
'status'][
'arrayofkeyval'])) {
280 foreach ($this->fields[
'status'][
'arrayofkeyval'] as $key2 => $val2) {
281 $this->fields[
'status'][
'arrayofkeyval'][$key2] = $langs->trans($val2);
308 global $langs, $hookmanager, $extrafields;
313 $object =
new self($this->db);
318 $object->fetchCommon($fromid);
321 unset($object->fk_user_creat);
322 unset($object->import_key);
325 $object->ref =
"copy_of_".$object->ref;
326 $object->title = $langs->trans(
"CopyOf").
" ".$object->title;
329 if (is_array($object->array_options) && count($object->array_options) > 0) {
330 $extrafields->fetch_name_optionals_label($this->table_element);
331 foreach ($object->array_options as $key => $option) {
332 $shortkey = preg_replace(
'/options_/',
'', $key);
333 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
337 unset($object->array_options[$key]);
343 $object->context[
'createfromclone'] =
'createfromclone';
344 $result = $object->createCommon($user);
347 $this->error = $object->error;
348 $this->errors = $object->errors;
351 unset($object->context[
'createfromclone']);
358 $this->db->rollback();
370 public function fetch($id, $ref =
null)
373 if ($result > 0 && !empty($this->table_element_line)) {
404 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
415 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
416 $sql .=
' WHERE t.entity = '.((int) $conf->entity);
419 if (count($filter) > 0) {
420 foreach ($filter as $key => $value) {
421 if ($key ==
't.rowid') {
422 $sqlwhere[] = $key.
" = ".((int) $value);
423 } elseif (strpos($key,
'date') !==
false) {
424 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
425 } elseif ($key ==
'customsql') {
426 $sqlwhere[] = $value;
428 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
432 if (count($sqlwhere) > 0) {
433 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
436 if (!empty($sortfield)) {
437 $sql .= $this->db->order($sortfield, $sortorder);
439 if (!empty($limit)) {
440 $sql .= $this->db->plimit($limit, $offset);
443 $resql = $this->db->query($sql);
445 $num = $this->db->num_rows($resql);
447 while ($obj = $this->db->fetch_object($resql)) {
448 $record =
new self($this->db);
450 $record->id = $obj->rowid;
454 $records[$record->id] = $record;
456 $this->db->free($resql);
460 $this->errors[] =
'Error '.$this->db->lasterror();
461 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
486 public function delete(
User $user, $notrigger =
false)
502 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
504 global $db, $conf, $langs, $hookmanager, $action;
505 global $dolibarr_main_authentication, $dolibarr_main_demo;
508 if (!empty($conf->dol_no_mouse_hover)) {
515 $label =
'<u>'.$langs->trans(
"Hook").
'</u>';
517 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
519 $url = DOL_URL_ROOT.
'/zapier/hook_card.php?id='.$this->id;
521 if ($option !=
'nolink') {
523 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
524 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
525 $add_save_lastsearch_values = 1;
527 if ($add_save_lastsearch_values) {
528 $url .=
'&save_lastsearch_values=1';
533 if (empty($notooltip)) {
535 $label = $langs->trans(
"ShowMyObject");
536 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
538 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
539 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
541 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
544 $linkstart =
'<a href="'.$url.
'"';
545 $linkstart .= $linkclose.
'>';
548 $result .= $linkstart;
550 $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);
552 if ($withpicto != 2) {
553 $result .= $this->ref;
558 $hookmanager->initHooks(array(
'hookdao'));
561 'getnomurl' => &$result,
564 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
566 $result = $hookmanager->resPrint;
568 $result .= $hookmanager->resPrint;
604 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
607 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Disabled');
608 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
609 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Disabled');
610 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
613 $statusType =
'status5';
614 if ($status == self::STATUS_VALIDATED) {
615 $statusType =
'status4';
618 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
629 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
630 $sql .=
' fk_user_creat, fk_user_modif';
631 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
632 $sql .=
' WHERE t.rowid = '.((int) $id);
633 $result = $this->db->query($sql);
635 if ($this->db->num_rows($result)) {
636 $obj = $this->db->fetch_object($result);
638 $this->
id = $obj->rowid;
640 $this->user_creation_id = $obj->fk_user_creat;
641 $this->user_modification_id = $obj->fk_user_modif;
642 $this->date_creation = $this->db->jdate($obj->datec);
643 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
646 $this->db->free($result);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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.
info($id)
Load the info information in the object.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
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.
fetch($id, $ref=null)
Load object in memory from the database.
create(User $user, $notrigger=false)
Create object into database.
getLibStatut($mode=0)
Return label of the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object lines in memory from the database.
createFromClone(User $user, $fromid)
Clone an object into another one.
LibStatut($status, $mode=0)
Return the status.
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)
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.