28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $module =
'webhook';
45 public $element =
'webhook_triggerhistory';
50 public $table_element =
'webhook_history';
60 public $picto =
'fa-calendar-alt';
63 const STATUS_SUCCESS = 1;
64 const STATUS_ERROR = -1;
115 "rowid" => array(
"type" =>
"integer",
"label" =>
"TechnicalID",
"enabled" => 1,
'position' => 1,
'notnull' => 1,
"visible" => 1,
"noteditable" => 1,
"index" => 1,
"css" =>
"left",
"comment" =>
"Id"),
116 "fk_target" => array(
"type" =>
"integer:target:webhook/class/target.class.php:0:(status:=:1)",
"label" =>
"Target",
"enabled" => 1,
'position' => 5,
'notnull' => 1,
"visible" => 1),
117 "trigger_code" => array(
"type" =>
"varchar(128)",
"label" =>
"TriggerCode",
"enabled" => 1,
'position' => 8,
'notnull' => 1,
"visible" => 1),
118 "url" => array(
"type" =>
"varchar(255)",
"label" =>
"Url",
"enabled" => 1,
'position' => 15,
'notnull' => 1,
"visible" => 1,
'csslist' =>
"small tdoverflowmax150"),
119 "trigger_data" => array(
"type" =>
"text",
"label" =>
"TriggerData",
"enabled" => 1,
'position' => 20,
'notnull' => 1,
"visible" => 1,
"csslist" =>
"small tdoverflowmax300"),
120 "note_private" => array(
"type" =>
"text",
"label" =>
"NotePrivate",
"enabled" => 1,
'position' => 62,
'notnull' => 0,
"visible" => 0,
"cssview" =>
"wordbreak",
"validate" => 1),
121 "date_creation" => array(
"type" =>
"datetime",
"label" =>
"DateCreation",
"enabled" => 1,
'position' => 500,
'notnull' => 1,
"visible" => -2),
122 "tms" => array(
"type" =>
"timestamp",
"label" =>
"DateModification",
"enabled" => 1,
'position' => 501,
'notnull' => 0,
"visible" => -2),
123 "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"),
124 "import_key" => array(
"type" =>
"varchar(14)",
"label" =>
"ImportId",
"enabled" => 1,
'position' => 1000,
'notnull' => -1,
"visible" => -2,),
125 "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),
126 "error_message" => array(
"type" =>
"text",
"label" =>
"ErrorMessage",
"enabled" => 1,
'position' => 50,
'notnull' => 0,
"visible" => 1,
"csslist" =>
"small tdoverflowmax150"),
139 public $note_private;
143 public $date_creation;
151 public $fk_user_creat;
163 public $trigger_data;
175 public $trigger_code;
179 public $error_messsage;
230 $this->ismultientitymanaged = 0;
231 $this->isextrafieldmanaged = 1;
233 if (!
getDolGlobalInt(
'MAIN_SHOW_TECHNICAL_ID') && isset($this->fields[
'rowid']) && !empty($this->fields[
'ref'])) {
234 $this->fields[
'rowid'][
'visible'] = 0;
236 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
237 $this->fields[
'entity'][
'enabled'] = 0;
247 foreach ($this->fields as $key => $val) {
248 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
249 unset($this->fields[$key]);
254 if (is_object($langs)) {
255 foreach ($this->fields as $key => $val) {
256 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
257 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
258 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
295 public function fetch($id, $ref =
null, $noextrafields = 0, $nolines = 0)
297 $result = $this->
fetchCommon($id, $ref,
'', $noextrafields);
298 if ($result > 0 && !empty($this->table_element_line) && empty($nolines)) {
312 $this->lines = array();
333 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 1000, $offset = 0,
string $filter =
'', $filtermode =
'AND')
341 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
342 if ($this->isextrafieldmanaged == 1) {
343 $sql .=
" LEFT JOIN ".$this->db->prefix().$this->table_element.
"_extrafields as te ON te.fk_object = t.rowid";
345 if ($this->ismultientitymanaged == 1) {
346 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
348 $sql .=
" WHERE 1 = 1";
355 $this->errors[] = $errormessage;
356 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
360 if (!empty($sortfield)) {
361 $sql .= $this->db->order($sortfield, $sortorder);
363 if (!empty($limit)) {
364 $sql .= $this->db->plimit($limit, $offset);
367 $resql = $this->db->query($sql);
369 $num = $this->db->num_rows($resql);
371 while ($i < ($limit ? min($limit, $num) : $num)) {
372 $obj = $this->db->fetch_object($resql);
374 $record =
new self($this->db);
375 $record->setVarsFromFetchObj($obj);
377 if (!empty($record->isextrafieldmanaged)) {
378 $record->fetch_optionals();
381 $records[$record->id] = $record;
385 $this->db->free($resql);
389 $this->errors[] =
'Error '.$this->db->lasterror();
390 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
415 public function delete(
User $user, $notrigger = 0)
432 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
449 if ($this->
status <= self::STATUS_SUCCESS) {
460 return $this->
setStatusCommon($user, self::STATUS_ERROR, $notrigger,
'WEBHOOK_MYOBJECT_UNVALIDATE');
470 public function cancel($user, $notrigger = 0)
473 if ($this->
status != self::STATUS_SUCCESS) {
484 return $this->
setStatusCommon($user, self::STATUS_ERROR, $notrigger,
'WEBHOOK_MYOBJECT_CANCEL');
494 public function reopen($user, $notrigger = 0)
497 if ($this->
status == self::STATUS_SUCCESS) {
508 return $this->
setStatusCommon($user, self::STATUS_SUCCESS, $notrigger,
'WEBHOOK_MYOBJECT_REOPEN');
525 return [
'optimize' => $langs->trans(
"ShowTriggerHistory")];
527 $datas[
'picto'] = img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"").
'</u>';
528 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
542 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
544 global
$conf, $langs, $hookmanager;
546 if (!empty(
$conf->dol_no_mouse_hover)) {
552 'id' => (string) $this->
id,
553 'objecttype' => $this->element.($this->module ?
'@'.$this->module :
''),
556 $classfortooltip =
'classfortooltip';
558 $label = img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"TriggerHistory").
'</u>';
559 $label .=
' '.$this->getLibStatut(5);
561 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
563 $baseurl = DOL_URL_ROOT.
'/webhook/triggerhistory_card.php';
564 $query = [
'id' => $this->id];
565 if ($option !==
'nolink') {
567 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
568 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
569 $add_save_lastsearch_values = 1;
571 if ($add_save_lastsearch_values) {
572 $query += [
'save_lastsearch_values' => 1];
578 if (empty($notooltip)) {
580 $label = $langs->trans(
"ShowTriggerHistory");
581 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
583 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
584 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
586 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
589 if ($option ==
'nolink') {
590 $linkstart =
'<span';
592 $linkstart =
'<a href="'.$url.
'"';
594 $linkstart .= $linkclose.
'>';
595 if ($option ==
'nolink') {
596 $linkend =
'</span>';
601 $result .= $linkstart;
603 if (empty($this->showphoto_on_popup)) {
605 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
609 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
611 list($class, $module) = explode(
'@', $this->picto);
614 $filename = $filearray[0][
'name'];
615 if (!empty($filename)) {
616 $pospoint = strpos($filearray[0][
'name'],
'.');
618 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.
dol_substr($filename, 0, $pospoint).
'_mini'.
dol_substr($filename, $pospoint);
620 $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>';
622 $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>';
627 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
632 if ($withpicto != 2) {
633 $result .= $this->ref;
639 global $action, $hookmanager;
640 $hookmanager->initHooks(array($this->element.
'dao'));
641 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
642 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
644 $result = $hookmanager->resPrint;
646 $result .= $hookmanager->resPrint;
661 global
$conf, $langs;
663 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
665 $return =
'<div class="box-flex-item box-flex-grow-zero">';
666 $return .=
'<div class="info-box info-box-sm">';
667 $return .=
'<span class="info-box-icon bg-infobox-action">';
668 $return .= img_picto(
'', $this->picto);
669 $return .=
'</span>';
670 $return .=
'<div class="info-box-content">';
671 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().
'</span>';
672 if ($selected >= 0) {
673 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
675 if (is_object($this->thirdparty)) {
676 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
682 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
723 if (is_null($status)) {
727 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
730 $this->labelStatus[self::STATUS_SUCCESS] = $langs->transnoentitiesnoconv(
'Success');
731 $this->labelStatus[self::STATUS_ERROR] = $langs->transnoentitiesnoconv(
'Error');
732 $this->labelStatusShort[self::STATUS_SUCCESS] = $langs->transnoentitiesnoconv(
'Success');
733 $this->labelStatusShort[self::STATUS_ERROR] = $langs->transnoentitiesnoconv(
'Error');
736 $statusType =
'status'.$status;
737 if ($status == self::STATUS_SUCCESS) {
738 $statusType =
'status4';
740 if ($status == self::STATUS_ERROR) {
741 $statusType =
'status8';
744 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
755 $sql =
"SELECT rowid,";
756 $sql .=
" date_creation as datec, tms as datem";
757 if (!empty($this->fields[
'date_validation'])) {
758 $sql .=
", date_validation as datev";
760 if (!empty($this->fields[
'fk_user_creat'])) {
761 $sql .=
", fk_user_creat";
763 if (!empty($this->fields[
'fk_user_modif'])) {
764 $sql .=
", fk_user_modif";
766 if (!empty($this->fields[
'fk_user_valid'])) {
767 $sql .=
", fk_user_valid";
769 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
770 $sql .=
" WHERE t.rowid = ".((int) $id);
772 $result = $this->db->query($sql);
774 if ($this->db->num_rows($result)) {
775 $obj = $this->db->fetch_object($result);
777 $this->
id = $obj->rowid;
779 if (!empty($this->fields[
'fk_user_creat'])) {
780 $this->user_creation_id = $obj->fk_user_creat;
782 if (!empty($this->fields[
'fk_user_modif'])) {
783 $this->user_modification_id = $obj->fk_user_modif;
785 if (!empty($this->fields[
'fk_user_valid'])) {
786 $this->user_validation_id = $obj->fk_user_valid;
788 $this->date_creation = $this->db->jdate($obj->datec);
789 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
790 if (!empty($obj->datev)) {
791 $this->date_validation = empty($obj->datev) ?
'' : $this->db->jdate($obj->datev);
795 $this->db->free($result);
797 dol_print_error($this->db);
823 $this->lines = array();
826 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0,
'(fk_history:=:'.((
int) $this->
id).
')');
828 if (is_numeric($result)) {
832 $this->lines = $result;
851 return parent::validateField(
$fields, $fieldKey, $fieldValue);
888require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
919 $this->isextrafieldmanaged = 0;
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.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
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.