dolibarr 21.0.0-alpha
target.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) ---Put here your own copyright and developer email---
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31
35class Target extends CommonObject
36{
40 public $module = 'webhook';
41
45 public $element = 'target';
46
50 public $table_element = 'webhook_target';
51
55 public $picto = 'webhook';
56
57
58 const STATUS_DRAFT = 0;
59 const STATUS_VALIDATED = 1;
60 const STATUS_CANCELED = 9;
61
62
91 // BEGIN MODULEBUILDER PROPERTIES
95 public $fields = array(
96 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
97 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'index' => 1, 'searchall' => 1, 'validate' => 1, 'comment' => "Reference of object"),
98 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'csslist' => 'tdoverflowmax150', 'showoncombobox' => 2, 'validate' => 1, 'autofocusoncreate' => 1),
99 'trigger_codes' => array('type' => 'text', 'label' => 'TriggerCodes', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 1, 'help' => "TriggerCodeInfo", 'tdcss' => 'titlefieldmiddle', 'csslist' => 'tdoverflowmax200', 'css' => 'minwidth400', 'arrayofkeyval' => array('defined_in_constructor' => 'defined_from_c_action_trigger'), 'multiinput' => 1,),
100 'url' => array('type' => 'url', 'label' => 'Url', 'enabled' => 1, 'position' => 55, 'notnull' => 1, 'visible' => 1,),
101 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 3, 'validate' => 1,),
102 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,),
103 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,),
104 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
105 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
106 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
107 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
108 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
109 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'position' => 2000, 'notnull' => 1, 'default' => '1', 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Disabled', '1' => 'Enabled'), 'validate' => 1,),
110 );
111 public $rowid;
112 public $ref;
113 public $label;
114 public $description;
115 public $note_public;
116 public $note_private;
117 public $fk_user_creat;
118 public $fk_user_modif;
119 public $import_key;
120 public $status;
121 public $url;
125 public $trigger_codes;
126 // END MODULEBUILDER PROPERTIES
127
128
129 // If this object has a subtable with lines
130
131 // /**
132 // * @var string Name of subtable line
133 // */
134 // public $table_element_line = 'webhook_targetline';
135
136 // /**
137 // * @var string Field with ID of parent key if this object has a parent
138 // */
139 // public $fk_element = 'fk_target';
140
141 // /**
142 // * @var string Name of subtable class that manage subtable lines
143 // */
144 // public $class_element_line = 'Targetline';
145
146 // /**
147 // * @var array List of child tables. To test if we can delete object.
148 // */
149 // protected $childtables = array();
150
151 // /**
152 // * @var array List of child tables. To know object to delete on cascade.
153 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
154 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
155 // */
156 // protected $childtablesoncascade = array('webhook_targetdet');
157
158 // /**
159 // * @var TargetLine[] Array of subtable lines
160 // */
161 // public $lines = array();
162
163
164
170 public function __construct(DoliDB $db)
171 {
172 global $langs;
173
174 $this->db = $db;
175
176 $this->ismultientitymanaged = 0;
177 $this->isextrafieldmanaged = 0;
178
179 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
180 $this->fields['rowid']['visible'] = 0;
181 }
182 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
183 $this->fields['entity']['enabled'] = 0;
184 }
185
186 // Unset fields that are disabled
187 foreach ($this->fields as $key => $val) {
188 if (isset($val['enabled']) && empty($val['enabled'])) {
189 unset($this->fields[$key]);
190 }
191 }
192
193 // Translate some data of arrayofkeyval
194 if (is_object($langs)) {
195 foreach ($this->fields as $key => $val) {
196 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
197 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
198 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
199 }
200 }
201 }
202 }
203 }
204
210 public function initListOfTriggers()
211 {
212 $entitytoicon = array(
213 'societe' => 'company',
214 'facture' => 'bill',
215 'commande' => 'order',
216 'order_supplier' => 'supplier_order',
217 'proposal_supplier' => 'supplier_proposal',
218 'invoice_supplier' => 'supplier_invoice',
219 'facturerec' => 'bill',
220 'ficheinter' => 'intervention',
221 'shipping' => 'shipment',
222 'contrat' => 'contract',
223 'recruitment' => 'recruitmentjobposition',
224 );
225 // Define the array $arrayofkeyval for $this->fields["trigger_codes"]
226 // @phan-suppress-next-line PhanTypeMismatchProperty
227 if (!empty($this->fields["trigger_codes"]['arrayofkeyval']) && is_array($this->fields["trigger_codes"]['arrayofkeyval']) && !empty($this->fields["trigger_codes"]["multiinput"])) {
228 $sql = "SELECT c.code, c.label, c.elementtype FROM ".MAIN_DB_PREFIX."c_action_trigger as c ORDER BY c.rang ASC";
229 $resql = $this->db->query($sql);
230 if ($resql) {
231 $num = $this->db->num_rows($resql);
232 $i = 0;
233 $arraytrigger = array();
234 while ($i < $num) {
235 $obj = $this->db->fetch_object($resql);
236 $elementtype = (!empty($entitytoicon[$obj->elementtype]) ? $entitytoicon[$obj->elementtype] : $obj->elementtype);
237 $arraytrigger[$obj->code] = img_object("", $elementtype).' '.$obj->label.' ('.$obj->code.')';
238 $i++;
239 }
240 $this->fields["trigger_codes"]['arrayofkeyval'] = $arraytrigger;
241 } else {
242 $this->errors[] = 'Error '.$this->db->lasterror();
243 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
244 }
245 }
246
247 return 1;
248 }
249
257 public function create(User $user, $notrigger = 0)
258 {
259 $resultcreate = $this->createCommon($user, $notrigger);
260 $this->ref = (string) $this->id;
261
262 if ($resultcreate <= 0) {
263 return $resultcreate;
264 }
265
266 return $this->id;
267 }
268
276 public function createFromClone(User $user, $fromid)
277 {
278 global $langs, $extrafields;
279 $error = 0;
280
281 dol_syslog(__METHOD__, LOG_DEBUG);
282
283 $object = new self($this->db);
284
285 $this->db->begin();
286
287 // Load source object
288 $result = $object->fetchCommon($fromid);
289 if ($result > 0 && !empty($object->table_element_line)) {
290 $object->fetchLines();
291 }
292
293 // get lines so they will be clone
294 //foreach($this->lines as $line)
295 // $line->fetch_optionals();
296
297 // Reset some properties
298 unset($object->id);
299 unset($object->fk_user_creat);
300 unset($object->import_key);
301
302 // Clear fields
303 if (property_exists($object, 'ref')) {
304 // @phan-suppress-next-line PhanTypeInvalidDimOffset
305 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
306 }
307 if (property_exists($object, 'label')) {
308 // @phan-suppress-next-line PhanTypeInvalidDimOffset
309 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
310 }
311 if (property_exists($object, 'status')) {
312 $object->status = self::STATUS_DRAFT;
313 }
314 if (property_exists($object, 'date_creation')) {
315 $object->date_creation = dol_now();
316 }
317 if (property_exists($object, 'date_modification')) {
318 $object->date_modification = null;
319 }
320 // ...
321 // Clear extrafields that are unique
322 if (is_array($object->array_options) && count($object->array_options) > 0) {
323 $extrafields->fetch_name_optionals_label($this->table_element);
324 foreach ($object->array_options as $key => $option) {
325 $shortkey = preg_replace('/options_/', '', $key);
326 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
327 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
328 unset($object->array_options[$key]);
329 }
330 }
331 }
332
333 // Create clone
334 $object->context['createfromclone'] = 'createfromclone';
335 $result = $object->createCommon($user);
336 if ($result < 0) {
337 $error++;
339 }
340
341 // if (!$error) {
342 // // copy internal contacts
343 // if ($this->copy_linked_contact($object, 'internal') < 0) {
344 // $error++;
345 // }
346 // }
347
348 // if (!$error) {
349 // // copy external contacts if same company
350 // if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
351 // if ($this->copy_linked_contact($object, 'external') < 0) {
352 // $error++;
353 // }
354 // }
355 // }
356
357 unset($object->context['createfromclone']);
358
359 // End
360 if (!$error) {
361 $this->db->commit();
362 return $object;
363 } else {
364 $this->db->rollback();
365 return -1;
366 }
367 }
368
376 public function fetch($id, $ref = null)
377 {
378 $result = $this->fetchCommon($id, $ref);
379 if (empty($this->ref)) {
380 $this->ref = (string) $this->id;
381 }
382
383 return $result;
384 }
385
391 public function fetchLines()
392 {
393 $this->lines = array();
394
395 $result = $this->fetchLinesCommon();
396 return $result;
397 }
398
399
412 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
413 {
414 dol_syslog(__METHOD__, LOG_DEBUG);
415
416 $records = array();
417
418 $sql = "SELECT ";
419 $sql .= $this->getFieldList('t');
420 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
421 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
422 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
423 } else {
424 $sql .= " WHERE 1 = 1";
425 }
426
427 $errormessage = '';
428 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
429 if ($errormessage) {
430 $this->errors[] = $errormessage;
431 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
432 return -1;
433 }
434
435 if (!empty($sortfield)) {
436 $sql .= $this->db->order($sortfield, $sortorder);
437 }
438 if (!empty($limit)) {
439 $sql .= $this->db->plimit($limit, $offset);
440 }
441
442 $resql = $this->db->query($sql);
443 if ($resql) {
444 $num = $this->db->num_rows($resql);
445 $i = 0;
446 while ($i < ($limit ? min($limit, $num) : $num)) {
447 $obj = $this->db->fetch_object($resql);
448
449 $record = new self($this->db);
450 $record->setVarsFromFetchObj($obj);
451
452 $records[$record->id] = $record;
453
454 $i++;
455 }
456 $this->db->free($resql);
457
458 return $records;
459 } else {
460 $this->errors[] = 'Error '.$this->db->lasterror();
461 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
462
463 return -1;
464 }
465 }
466
474 public function update(User $user, $notrigger = 0)
475 {
476 return $this->updateCommon($user, $notrigger);
477 }
478
486 public function delete(User $user, $notrigger = 0)
487 {
488 return $this->deleteCommon($user, $notrigger);
489 //return $this->deleteCommon($user, $notrigger, 1);
490 }
491
500 public function deleteLine(User $user, $idline, $notrigger = 0)
501 {
502 if ($this->status < 0) {
503 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
504 return -2;
505 }
506
507 return $this->deleteLineCommon($user, $idline, $notrigger);
508 }
509
510
518 public function validate($user, $notrigger = 0)
519 {
520 global $conf;
521
522 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
523
524 $error = 0;
525
526 // Protection
527 if ($this->status == self::STATUS_VALIDATED) {
528 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
529 return 0;
530 }
531
532 $now = dol_now();
533
534 $this->db->begin();
535
536 // Define new ref
537 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
538 $num = $this->getNextNumRef();
539 } else {
540 $num = $this->ref;
541 }
542 $this->newref = $num;
543
544 if (!empty($num)) {
545 // Validate
546 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
547 $sql .= " SET ref = '".$this->db->escape($num)."',";
548 $sql .= " status = ".self::STATUS_VALIDATED;
549 if (!empty($this->fields['date_validation'])) {
550 $sql .= ", date_validation = '".$this->db->idate($now)."'";
551 }
552 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
553 $sql .= ", fk_user_valid = ".((int) $user->id);
554 }
555 $sql .= " WHERE rowid = ".((int) $this->id);
556
557 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
558 $resql = $this->db->query($sql);
559 if (!$resql) {
560 dol_print_error($this->db);
561 $this->error = $this->db->lasterror();
562 $error++;
563 }
564
565 if (!$error && !$notrigger) {
566 // Call trigger
567 $result = $this->call_trigger('TARGET_VALIDATE', $user);
568 if ($result < 0) {
569 $error++;
570 }
571 // End call triggers
572 }
573 }
574
575 if (!$error) {
576 $this->oldref = $this->ref;
577
578 // Rename directory if dir was a temporary ref
579 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
580 // Now we rename also files into index
581 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'target/".$this->db->escape($this->newref)."'";
582 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
583 $resql = $this->db->query($sql);
584 if (!$resql) {
585 $error++;
586 $this->error = $this->db->lasterror();
587 }
588 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'target/".$this->db->escape($this->newref)."'";
589 $sql .= " WHERE filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
590 $resql = $this->db->query($sql);
591 if (!$resql) {
592 $error++;
593 $this->error = $this->db->lasterror();
594 }
595
596 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
597 $oldref = dol_sanitizeFileName($this->ref);
598 $newref = dol_sanitizeFileName($num);
599 $dirsource = $conf->webhook->dir_output.'/target/'.$oldref;
600 $dirdest = $conf->webhook->dir_output.'/target/'.$newref;
601 if (!$error && file_exists($dirsource)) {
602 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
603
604 if (@rename($dirsource, $dirdest)) {
605 dol_syslog("Rename ok");
606 // Rename docs starting with $oldref with $newref
607 $listoffiles = dol_dir_list($conf->webhook->dir_output.'/target/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
608 foreach ($listoffiles as $fileentry) {
609 $dirsource = $fileentry['name'];
610 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
611 $dirsource = $fileentry['path'].'/'.$dirsource;
612 $dirdest = $fileentry['path'].'/'.$dirdest;
613 @rename($dirsource, $dirdest);
614 }
615 }
616 }
617 }
618 }
619
620 // Set new ref and current status
621 if (!$error) {
622 $this->ref = $num;
623 $this->status = self::STATUS_VALIDATED;
624 }
625
626 if (!$error) {
627 $this->db->commit();
628 return 1;
629 } else {
630 $this->db->rollback();
631 return -1;
632 }
633 }
634
635
643 public function setDraft($user, $notrigger = 0)
644 {
645 // Protection
646 if ($this->status <= self::STATUS_DRAFT) {
647 return 0;
648 }
649
650 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'TARGET_UNVALIDATE');
651 }
652
660 public function cancel($user, $notrigger = 0)
661 {
662 // Protection
663 if ($this->status != self::STATUS_VALIDATED) {
664 return 0;
665 }
666
667 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'TARGET_CANCEL');
668 }
669
677 public function reopen($user, $notrigger = 0)
678 {
679 // Protection
680 if ($this->status != self::STATUS_CANCELED) {
681 return 0;
682 }
683
684 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'TARGET_REOPEN');
685 }
686
697 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
698 {
699 global $conf, $langs, $hookmanager;
700
701 if (!empty($conf->dol_no_mouse_hover)) {
702 $notooltip = 1; // Force disable tooltips
703 }
704
705 $result = '';
706
707 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Target").'</u>';
708 if (isset($this->status)) {
709 $label .= ' '.$this->getLibStatut(5);
710 }
711 $label .= '<br>';
712 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
713
714 $url = dol_buildpath('/webhook/target_card.php', 1).'?id='.$this->id;
715
716 if ($option != 'nolink') {
717 // Add param to save lastsearch_values or not
718 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
719 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
720 $add_save_lastsearch_values = 1;
721 }
722 if ($url && $add_save_lastsearch_values) {
723 $url .= '&save_lastsearch_values=1';
724 }
725 }
726
727 $linkclose = '';
728 if (empty($notooltip)) {
729 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
730 $label = $langs->trans("ShowTarget");
731 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
732 }
733 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
734 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
735 } else {
736 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
737 }
738
739 if ($option == 'nolink' || empty($url)) {
740 $linkstart = '<span';
741 } else {
742 $linkstart = '<a href="'.$url.'"';
743 }
744 $linkstart .= $linkclose.'>';
745 if ($option == 'nolink' || empty($url)) {
746 $linkend = '</span>';
747 } else {
748 $linkend = '</a>';
749 }
750
751 $result .= $linkstart;
752
753 if (empty($this->showphoto_on_popup)) {
754 if ($withpicto) {
755 $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);
756 }
757 } else {
758 if ($withpicto) {
759 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
760
761 list($class, $module) = explode('@', $this->picto);
762 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
763 $filearray = dol_dir_list($upload_dir, "files");
764 $filename = $filearray[0]['name'];
765 if (!empty($filename)) {
766 $pospoint = strpos($filearray[0]['name'], '.');
767
768 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
769 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
770 $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>';
771 } else {
772 $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>';
773 }
774
775 $result .= '</div>';
776 } else {
777 $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);
778 }
779 }
780 }
781
782 if ($withpicto != 2) {
783 $result .= $this->ref;
784 }
785
786 $result .= $linkend;
787 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
788
789 global $action, $hookmanager;
790 $hookmanager->initHooks(array('targetdao'));
791 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
792 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
793 if ($reshook > 0) {
794 $result = $hookmanager->resPrint;
795 } else {
796 $result .= $hookmanager->resPrint;
797 }
798
799 return $result;
800 }
801
808 public function getLabelStatus($mode = 0)
809 {
810 return $this->LibStatut($this->status, $mode);
811 }
812
819 public function getLibStatut($mode = 0)
820 {
821 return $this->LibStatut($this->status, $mode);
822 }
823
824 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
832 public function LibStatut($status, $mode = 0)
833 {
834 // phpcs:enable
835 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
836 global $langs;
837
838 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
839 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
840 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
841 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
842 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
843 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
844 }
845
846 $statusType = 'status'.$status;
847 if ($status == self::STATUS_VALIDATED) {
848 $statusType = 'status4';
849 }
850 if ($status == self::STATUS_CANCELED) {
851 $statusType = 'status6';
852 }
853
854 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
855 }
856
863 public function info($id)
864 {
865 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
866 $sql .= " fk_user_creat, fk_user_modif";
867 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
868 $sql .= " WHERE t.rowid = ".((int) $id);
869
870 $result = $this->db->query($sql);
871 if ($result) {
872 if ($this->db->num_rows($result)) {
873 $obj = $this->db->fetch_object($result);
874
875 $this->id = $obj->rowid;
876
877 $this->user_creation_id = $obj->fk_user_creat;
878 $this->user_modification_id = $obj->fk_user_modif;
879 $this->date_creation = $this->db->jdate($obj->datec);
880 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
881 }
882
883 $this->db->free($result);
884 } else {
885 dol_print_error($this->db);
886 }
887 }
888
895 public function initAsSpecimen()
896 {
897 $this->url = "https://thisisunurl";
898 $this->trigger_codes = "ThisIsATestCode";
899
900 return $this->initAsSpecimenCommon();
901 }
902
908 public function getNextNumRef()
909 {
910 global $langs, $conf;
911
912 $mybool = false;
913
914 $classname = getDolGlobalString('WEBHOOK_TARGET_ADDON', 'mod_target_standard');
915 $file = $classname.".php";
916
917 // Include file with class
918 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
919 foreach ($dirmodels as $reldir) {
920 $dir = dol_buildpath($reldir."core/modules/webhook/");
921
922 // Load file with numbering class (if found)
923 $mybool = ((bool) @include_once $dir.$file) || $mybool;
924 }
925
926 if (!$mybool) {
927 dol_print_error(null, "Failed to include file ".$file);
928 return '';
929 }
930
931 if (class_exists($classname)) {
932 $obj = new $classname();
933 $numref = $obj->getNextValue($this);
934
935 if ($numref != '' && $numref != '-1') {
936 return $numref;
937 } else {
938 $this->error = $obj->error;
939 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
940 return "";
941 }
942 } else {
943 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
944 return "";
945 }
946 }
947
959 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
960 {
961 $result = 0;
962 $includedocgeneration = 0;
963
964 if (!dol_strlen($modele)) {
965 $modele = 'standard_target';
966
967 if (!empty($this->model_pdf)) {
968 $modele = $this->model_pdf;
969 } elseif (getDolGlobalString('TARGET_ADDON_PDF')) {
970 $modele = getDolGlobalString('TARGET_ADDON_PDF');
971 }
972 }
973
974 $modelpath = "core/modules/webhook/doc/";
975
976 if ($includedocgeneration && !empty($modele)) {
977 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
978 }
979
980 return $result;
981 }
982
990 public function doScheduledJob()
991 {
992 //global $conf, $langs;
993
994 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
995
996 $error = 0;
997 $this->output = '';
998 $this->error = '';
999
1000 dol_syslog(__METHOD__, LOG_DEBUG);
1001
1002 //$now = dol_now();
1003
1004 $this->db->begin();
1005
1006 // ...
1007
1008 $this->db->commit();
1009
1010 return $error;
1011 }
1012}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:640
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for Target.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
initListOfTriggers()
Init the list of available triggers;.
getLabelStatus($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetchLines()
Load object lines in memory from the database.
info($id)
Load the info information in the object.
fetch($id, $ref=null)
Load object in memory from the database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
__construct(DoliDB $db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
reopen($user, $notrigger=0)
Set back to validated status.
createFromClone(User $user, $fromid)
Clone an object into another one.
LibStatut($status, $mode=0)
Return the status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
create(User $user, $notrigger=0)
Create object into database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
cancel($user, $notrigger=0)
Set cancel status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
validate($user, $notrigger=0)
Validate object.
setDraft($user, $notrigger=0)
Set draft status.
update(User $user, $notrigger=0)
Update object into database.
Class to manage Dolibarr users.
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.
Definition files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.