27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $module =
'webhook';
44 public $element =
'webhook_triggerhistory';
49 public $table_element =
'webhook_history';
59 public $picto =
'fa-calendar-alt';
62 const STATUS_SUCCESS = 1;
63 const STATUS_ERROR = -1;
114 "rowid" => array(
"type" =>
"integer",
"label" =>
"TechnicalID",
"enabled" => 1,
'position' => 1,
'notnull' => 1,
"visible" => 1,
"noteditable" => 1,
"index" => 1,
"css" =>
"left",
"comment" =>
"Id"),
115 "fk_target" => array(
"type" =>
"integer:target:webhook/class/target.class.php:0:(status:=:1)",
"label" =>
"Target",
"enabled" => 1,
'position' => 5,
'notnull' => 1,
"visible" => 1),
116 "trigger_code" => array(
"type" =>
"varchar(128)",
"label" =>
"TriggerCode",
"enabled" => 1,
'position' => 8,
'notnull' => 1,
"visible" => 1),
117 "url" => array(
"type" =>
"varchar(255)",
"label" =>
"Url",
"enabled" => 1,
'position' => 15,
'notnull' => 1,
"visible" => 1,
'csslist' =>
"small tdoverflowmax150"),
118 "trigger_data" => array(
"type" =>
"text",
"label" =>
"TriggerData",
"enabled" => 1,
'position' => 20,
'notnull' => 1,
"visible" => 1,
"csslist" =>
"small tdoverflowmax300"),
119 "note_private" => array(
"type" =>
"text",
"label" =>
"NotePrivate",
"enabled" => 1,
'position' => 62,
'notnull' => 0,
"visible" => 0,
"cssview" =>
"wordbreak",
"validate" => 1),
120 "date_creation" => array(
"type" =>
"datetime",
"label" =>
"DateCreation",
"enabled" => 1,
'position' => 500,
'notnull' => 1,
"visible" => -2),
121 "tms" => array(
"type" =>
"timestamp",
"label" =>
"DateModification",
"enabled" => 1,
'position' => 501,
'notnull' => 0,
"visible" => -2),
122 "fk_user_creat" => array(
"type" =>
"integer:User:user/class/user.class.php",
"label" =>
"UserAuthor",
"picto" =>
"user",
"enabled" => 1,
'position' => 510,
'notnull' => 1,
"visible" => -2,
"csslist" =>
"tdoverflowmax150"),
123 "import_key" => array(
"type" =>
"varchar(14)",
"label" =>
"ImportId",
"enabled" => 1,
'position' => 1000,
'notnull' => -1,
"visible" => -2,),
124 "status" => array(
"type" =>
"integer",
"label" =>
"Status",
"enabled" => 1,
"position" => 2000,
"notnull" => 1,
'default' =>
'1',
"visible" => 1,
"index" => 1,
"arrayofkeyval" => array(
"1" =>
"Success",
"-1" =>
"Error"),
"validate" => 1),
125 "error_message" => array(
"type" =>
"text",
"label" =>
"ErrorMessage",
"enabled" => 1,
'position' => 50,
'notnull' => 0,
"visible" => 1,
"csslist" =>
"small tdoverflowmax150"),
138 public $note_private;
142 public $date_creation;
150 public $fk_user_creat;
162 public $trigger_data;
174 public $trigger_code;
178 public $error_messsage;
229 $this->ismultientitymanaged = 0;
230 $this->isextrafieldmanaged = 1;
232 if (!
getDolGlobalInt(
'MAIN_SHOW_TECHNICAL_ID') && isset($this->fields[
'rowid']) && !empty($this->fields[
'ref'])) {
233 $this->fields[
'rowid'][
'visible'] = 0;
235 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
236 $this->fields[
'entity'][
'enabled'] = 0;
246 foreach ($this->fields as $key => $val) {
247 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
248 unset($this->fields[$key]);
253 if (is_object($langs)) {
254 foreach ($this->fields as $key => $val) {
255 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
256 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
257 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
294 public function fetch($id, $ref =
null, $noextrafields = 0, $nolines = 0)
296 $result = $this->
fetchCommon($id, $ref,
'', $noextrafields);
297 if ($result > 0 && !empty($this->table_element_line) && empty($nolines)) {
311 $this->lines = array();
332 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 1000, $offset = 0,
string $filter =
'', $filtermode =
'AND')
340 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
341 if ($this->isextrafieldmanaged == 1) {
342 $sql .=
" LEFT JOIN ".$this->db->prefix().$this->table_element.
"_extrafields as te ON te.fk_object = t.rowid";
344 if ($this->ismultientitymanaged == 1) {
345 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
347 $sql .=
" WHERE 1 = 1";
354 $this->errors[] = $errormessage;
355 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
359 if (!empty($sortfield)) {
360 $sql .= $this->db->order($sortfield, $sortorder);
362 if (!empty($limit)) {
363 $sql .= $this->db->plimit($limit, $offset);
366 $resql = $this->db->query($sql);
368 $num = $this->db->num_rows($resql);
370 while ($i < ($limit ? min($limit, $num) : $num)) {
371 $obj = $this->db->fetch_object($resql);
373 $record =
new self($this->db);
374 $record->setVarsFromFetchObj($obj);
376 if (!empty($record->isextrafieldmanaged)) {
377 $record->fetch_optionals();
380 $records[$record->id] = $record;
384 $this->db->free($resql);
388 $this->errors[] =
'Error '.$this->db->lasterror();
389 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
414 public function delete(
User $user, $notrigger = 0)
431 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
448 if ($this->
status <= self::STATUS_SUCCESS) {
459 return $this->
setStatusCommon($user, self::STATUS_ERROR, $notrigger,
'WEBHOOK_MYOBJECT_UNVALIDATE');
469 public function cancel($user, $notrigger = 0)
472 if ($this->
status != self::STATUS_SUCCESS) {
483 return $this->
setStatusCommon($user, self::STATUS_ERROR, $notrigger,
'WEBHOOK_MYOBJECT_CANCEL');
493 public function reopen($user, $notrigger = 0)
496 if ($this->
status == self::STATUS_SUCCESS) {
507 return $this->
setStatusCommon($user, self::STATUS_SUCCESS, $notrigger,
'WEBHOOK_MYOBJECT_REOPEN');
524 return [
'optimize' => $langs->trans(
"ShowTriggerHistory")];
526 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"").
'</u>';
527 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
541 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
543 global $conf, $langs, $hookmanager;
545 if (!empty($conf->dol_no_mouse_hover)) {
551 'id' => (string) $this->
id,
552 'objecttype' => $this->element.($this->module ?
'@'.$this->module :
''),
555 $classfortooltip =
'classfortooltip';
557 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"TriggerHistory").
'</u>';
558 $label .=
' '.$this->getLibStatut(5);
560 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
561 $url =
dol_buildpath(
'/webhook/triggerhistory_card.php', 1).
'?id='.$this->id;
563 if ($option !==
'nolink') {
565 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
566 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
567 $add_save_lastsearch_values = 1;
569 if ($add_save_lastsearch_values) {
570 $url .=
'&save_lastsearch_values=1';
575 if (empty($notooltip)) {
577 $label = $langs->trans(
"ShowTriggerHistory");
578 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
580 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
581 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
583 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
586 if ($option ==
'nolink') {
587 $linkstart =
'<span';
589 $linkstart =
'<a href="'.$url.
'"';
591 $linkstart .= $linkclose.
'>';
592 if ($option ==
'nolink') {
593 $linkend =
'</span>';
598 $result .= $linkstart;
600 if (empty($this->showphoto_on_popup)) {
602 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
606 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
608 list($class, $module) = explode(
'@', $this->picto);
611 $filename = $filearray[0][
'name'];
612 if (!empty($filename)) {
613 $pospoint = strpos($filearray[0][
'name'],
'.');
615 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
617 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.
'" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div></div>';
619 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div>';
624 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
629 if ($withpicto != 2) {
630 $result .= $this->ref;
636 global $action, $hookmanager;
637 $hookmanager->initHooks(array($this->element.
'dao'));
638 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
639 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
641 $result = $hookmanager->resPrint;
643 $result .= $hookmanager->resPrint;
658 global $conf, $langs;
660 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
662 $return =
'<div class="box-flex-item box-flex-grow-zero">';
663 $return .=
'<div class="info-box info-box-sm">';
664 $return .=
'<span class="info-box-icon bg-infobox-action">';
666 $return .=
'</span>';
667 $return .=
'<div class="info-box-content">';
668 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().
'</span>';
669 if ($selected >= 0) {
670 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
672 if (is_object($this->thirdparty)) {
673 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
679 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
720 if (is_null($status)) {
724 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
727 $this->labelStatus[self::STATUS_SUCCESS] = $langs->transnoentitiesnoconv(
'Success');
728 $this->labelStatus[self::STATUS_ERROR] = $langs->transnoentitiesnoconv(
'Error');
729 $this->labelStatusShort[self::STATUS_SUCCESS] = $langs->transnoentitiesnoconv(
'Success');
730 $this->labelStatusShort[self::STATUS_ERROR] = $langs->transnoentitiesnoconv(
'Error');
733 $statusType =
'status'.$status;
734 if ($status == self::STATUS_SUCCESS) {
735 $statusType =
'status4';
737 if ($status == self::STATUS_ERROR) {
738 $statusType =
'status8';
741 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
752 $sql =
"SELECT rowid,";
753 $sql .=
" date_creation as datec, tms as datem";
754 if (!empty($this->fields[
'date_validation'])) {
755 $sql .=
", date_validation as datev";
757 if (!empty($this->fields[
'fk_user_creat'])) {
758 $sql .=
", fk_user_creat";
760 if (!empty($this->fields[
'fk_user_modif'])) {
761 $sql .=
", fk_user_modif";
763 if (!empty($this->fields[
'fk_user_valid'])) {
764 $sql .=
", fk_user_valid";
766 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
767 $sql .=
" WHERE t.rowid = ".((int) $id);
769 $result = $this->db->query($sql);
771 if ($this->db->num_rows($result)) {
772 $obj = $this->db->fetch_object($result);
774 $this->
id = $obj->rowid;
776 if (!empty($this->fields[
'fk_user_creat'])) {
777 $this->user_creation_id = $obj->fk_user_creat;
779 if (!empty($this->fields[
'fk_user_modif'])) {
780 $this->user_modification_id = $obj->fk_user_modif;
782 if (!empty($this->fields[
'fk_user_valid'])) {
783 $this->user_validation_id = $obj->fk_user_valid;
785 $this->date_creation = $this->db->jdate($obj->datec);
786 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
787 if (!empty($obj->datev)) {
788 $this->date_validation = empty($obj->datev) ?
'' : $this->db->jdate($obj->datev);
792 $this->db->free($result);
820 $this->lines = array();
823 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0,
'(fk_history:=:'.((
int) $this->
id).
')');
825 if (is_numeric($result)) {
829 $this->lines = $result;
848 return parent::validateField(
$fields, $fieldKey, $fieldValue);
885require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
916 $this->isextrafieldmanaged = 0;
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
$parent_element
To overload.
$fk_parent_attribute
To overload.
__construct(DoliDB $db)
Constructor.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
initAsSpecimen()
Initialize object with example values Id must be 0 if object instance is a specimen.
cancel($user, $notrigger=0)
Set cancel status.
$fields
'type' field format: 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortf...
getLinesArray()
Create an array of lines.
getTooltipContentArray($params)
getTooltipContentArray
LibStatut($status, $mode=0)
Return the label of a given status.
getLabelStatus($mode=0)
Return the label of the status.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null, $noextrafields=0, $nolines=0)
Load object in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
update(User $user, $notrigger=0)
Update object into database.
reopen($user, $notrigger=0)
Set back to validated status.
fetchAll($sortorder='', $sortfield='', $limit=1000, $offset=0, string $filter='', $filtermode='AND')
Load list of objects in memory from the database.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
getLibStatut($mode=0)
Return the label of the status.
setDraft($user, $notrigger=0)
Set draft status.
create(User $user, $notrigger=0)
Create object into database.
validateField($fields, $fieldKey, $fieldValue)
Return validation test result for a field.
fetchLines($noextrafields=0)
Load object lines in memory from the database.
info($id)
Load the info information in the object.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.