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' => 'AutomaticTrigger', '2' => 'ManualTrigger'), 'validate' => 1,),
110 "trigger_stack" => array("type" => "text", "label" => "TriggerStack", "enabled" => "1", 'position' => 59, 'notnull' => 0, "visible" => "0",),
111 );
115 public $rowid;
119 public $ref;
123 public $label;
127 public $description;
131 public $note_public;
135 public $note_private;
139 public $fk_user_creat;
143 public $fk_user_modif;
147 public $import_key;
151 public $status;
155 public $url;
159 public $trigger_codes;
160
164 public $trigger_stack;
165 // END MODULEBUILDER PROPERTIES
166
167
168 // If this object has a subtable with lines
169
170 // /**
171 // * @var string Name of subtable line
172 // */
173 // public $table_element_line = 'webhook_targetline';
174
175 // /**
176 // * @var string Field with ID of parent key if this object has a parent
177 // */
178 // public $fk_element = 'fk_target';
179
180 // /**
181 // * @var string Name of subtable class that manage subtable lines
182 // */
183 // public $class_element_line = 'Targetline';
184
185 // /**
186 // * @var array List of child tables. To test if we can delete object.
187 // */
188 // protected $childtables = array();
189
190 // /**
191 // * @var array List of child tables. To know object to delete on cascade.
192 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
193 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
194 // */
195 // protected $childtablesoncascade = array('webhook_targetdet');
196
197 // /**
198 // * @var TargetLine[] Array of subtable lines
199 // */
200 // public $lines = array();
201
202
203
209 public function __construct(DoliDB $db)
210 {
211 global $langs;
212
213 $this->db = $db;
214
215 $this->ismultientitymanaged = 0;
216 $this->isextrafieldmanaged = 0;
217
218 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
219 $this->fields['rowid']['visible'] = 0;
220 }
221 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
222 $this->fields['entity']['enabled'] = 0;
223 }
224
225 // Unset fields that are disabled
226 foreach ($this->fields as $key => $val) {
227 if (isset($val['enabled']) && empty($val['enabled'])) {
228 unset($this->fields[$key]);
229 }
230 }
231
232 // Translate some data of arrayofkeyval
233 if (is_object($langs)) {
234 foreach ($this->fields as $key => $val) {
235 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
236 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
237 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
238 }
239 }
240 }
241 }
242 }
243
249 public function initListOfTriggers()
250 {
251 $entitytoicon = array(
252 'societe' => 'company',
253 'facture' => 'bill',
254 'commande' => 'order',
255 'order_supplier' => 'supplier_order',
256 'proposal_supplier' => 'supplier_proposal',
257 'invoice_supplier' => 'supplier_invoice',
258 'facturerec' => 'bill',
259 'ficheinter' => 'intervention',
260 'shipping' => 'shipment',
261 'contrat' => 'contract',
262 'recruitment' => 'recruitmentjobposition',
263 );
264 // Define the array $arrayofkeyval for $this->fields["trigger_codes"]
265 // @phan-suppress-next-line PhanTypeMismatchProperty
266 if (!empty($this->fields["trigger_codes"]['arrayofkeyval']) && is_array($this->fields["trigger_codes"]['arrayofkeyval']) && !empty($this->fields["trigger_codes"]["multiinput"])) {
267 $sql = "SELECT c.code, c.label, c.elementtype FROM ".MAIN_DB_PREFIX."c_action_trigger as c ORDER BY c.rang ASC";
268 $resql = $this->db->query($sql);
269 if ($resql) {
270 $num = $this->db->num_rows($resql);
271 $i = 0;
272 $arraytrigger = array();
273 while ($i < $num) {
274 $obj = $this->db->fetch_object($resql);
275 $elementtype = (!empty($entitytoicon[$obj->elementtype]) ? $entitytoicon[$obj->elementtype] : $obj->elementtype);
276 $arraytrigger[$obj->code] = img_object("", $elementtype).' '.$obj->label.' ('.$obj->code.')';
277 $i++;
278 }
279 $this->fields["trigger_codes"]['arrayofkeyval'] = $arraytrigger;
280 } else {
281 $this->errors[] = 'Error '.$this->db->lasterror();
282 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
283 }
284 }
285
286 return 1;
287 }
288
296 public function create(User $user, $notrigger = 0)
297 {
298 $resultcreate = $this->createCommon($user, $notrigger);
299 $this->ref = (string) $this->id;
300
301 if ($resultcreate <= 0) {
302 return $resultcreate;
303 }
304
305 return $this->id;
306 }
307
315 public function createFromClone(User $user, $fromid)
316 {
317 global $langs, $extrafields;
318 $error = 0;
319
320 dol_syslog(__METHOD__, LOG_DEBUG);
321
322 $object = new self($this->db);
323
324 $this->db->begin();
325
326 // Load source object
327 $result = $object->fetchCommon($fromid);
328 if ($result > 0 && !empty($object->table_element_line)) {
329 $object->fetchLines();
330 }
331
332 // get lines so they will be clone
333 //foreach($this->lines as $line)
334 // $line->fetch_optionals();
335
336 // Reset some properties
337 unset($object->id);
338 unset($object->fk_user_creat);
339 unset($object->import_key);
340
341 // Clear fields
342 if (property_exists($object, 'ref')) {
343 // @phan-suppress-next-line PhanTypeInvalidDimOffset
344 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
345 }
346 if (property_exists($object, 'label')) {
347 // @phan-suppress-next-line PhanTypeInvalidDimOffset
348 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
349 }
350 if (property_exists($object, 'status')) {
351 $object->status = self::STATUS_DRAFT;
352 }
353 if (property_exists($object, 'date_creation')) {
354 $object->date_creation = dol_now();
355 }
356 if (property_exists($object, 'date_modification')) {
357 $object->date_modification = null;
358 }
359 // ...
360 // Clear extrafields that are unique
361 if (is_array($object->array_options) && count($object->array_options) > 0) {
362 $extrafields->fetch_name_optionals_label($this->table_element);
363 foreach ($object->array_options as $key => $option) {
364 $shortkey = preg_replace('/options_/', '', $key);
365 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
366 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
367 unset($object->array_options[$key]);
368 }
369 }
370 }
371
372 // Create clone
373 $object->context['createfromclone'] = 'createfromclone';
374 $result = $object->createCommon($user);
375 if ($result < 0) {
376 $error++;
378 }
379
380 // if (!$error) {
381 // // copy internal contacts
382 // if ($this->copy_linked_contact($object, 'internal') < 0) {
383 // $error++;
384 // }
385 // }
386
387 // if (!$error) {
388 // // copy external contacts if same company
389 // if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
390 // if ($this->copy_linked_contact($object, 'external') < 0) {
391 // $error++;
392 // }
393 // }
394 // }
395
396 unset($object->context['createfromclone']);
397
398 // End
399 if (!$error) {
400 $this->db->commit();
401 return $object;
402 } else {
403 $this->db->rollback();
404 return -1;
405 }
406 }
407
415 public function fetch($id, $ref = null)
416 {
417 $result = $this->fetchCommon($id, $ref);
418 if (empty($this->ref)) {
419 $this->ref = (string) $this->id;
420 }
421
422 return $result;
423 }
424
430 public function fetchLines()
431 {
432 $this->lines = array();
433
434 $result = $this->fetchLinesCommon();
435 return $result;
436 }
437
438
451 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
452 {
453 dol_syslog(__METHOD__, LOG_DEBUG);
454
455 $records = array();
456
457 $sql = "SELECT ";
458 $sql .= $this->getFieldList('t');
459 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
460 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
461 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
462 } else {
463 $sql .= " WHERE 1 = 1";
464 }
465
466 $errormessage = '';
467 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
468 if ($errormessage) {
469 $this->errors[] = $errormessage;
470 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
471 return -1;
472 }
473
474 if (!empty($sortfield)) {
475 $sql .= $this->db->order($sortfield, $sortorder);
476 }
477 if (!empty($limit)) {
478 $sql .= $this->db->plimit($limit, $offset);
479 }
480
481 $resql = $this->db->query($sql);
482 if ($resql) {
483 $num = $this->db->num_rows($resql);
484 $i = 0;
485 while ($i < ($limit ? min($limit, $num) : $num)) {
486 $obj = $this->db->fetch_object($resql);
487
488 $record = new self($this->db);
489 $record->setVarsFromFetchObj($obj);
490
491 $records[$record->id] = $record;
492
493 $i++;
494 }
495 $this->db->free($resql);
496
497 return $records;
498 } else {
499 $this->errors[] = 'Error '.$this->db->lasterror();
500 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
501
502 return -1;
503 }
504 }
505
513 public function update(User $user, $notrigger = 0)
514 {
515 return $this->updateCommon($user, $notrigger);
516 }
517
525 public function delete(User $user, $notrigger = 0)
526 {
527 return $this->deleteCommon($user, $notrigger);
528 //return $this->deleteCommon($user, $notrigger, 1);
529 }
530
539 public function deleteLine(User $user, $idline, $notrigger = 0)
540 {
541 if ($this->status < 0) {
542 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
543 return -2;
544 }
545
546 return $this->deleteLineCommon($user, $idline, $notrigger);
547 }
548
549
557 public function validate($user, $notrigger = 0)
558 {
559 global $conf;
560
561 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
562
563 $error = 0;
564
565 // Protection
566 if ($this->status == self::STATUS_VALIDATED) {
567 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
568 return 0;
569 }
570
571 $now = dol_now();
572
573 $this->db->begin();
574
575 // Define new ref
576 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
577 $num = $this->getNextNumRef();
578 } else {
579 $num = $this->ref;
580 }
581 $this->newref = $num;
582
583 if (!empty($num)) {
584 // Validate
585 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
586 $sql .= " SET ref = '".$this->db->escape($num)."',";
587 $sql .= " status = ".self::STATUS_VALIDATED;
588 if (!empty($this->fields['date_validation'])) {
589 $sql .= ", date_validation = '".$this->db->idate($now)."'";
590 }
591 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
592 $sql .= ", fk_user_valid = ".((int) $user->id);
593 }
594 $sql .= " WHERE rowid = ".((int) $this->id);
595
596 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
597 $resql = $this->db->query($sql);
598 if (!$resql) {
599 dol_print_error($this->db);
600 $this->error = $this->db->lasterror();
601 $error++;
602 }
603
604 if (!$error && !$notrigger) {
605 // Call trigger
606 $result = $this->call_trigger('TARGET_VALIDATE', $user);
607 if ($result < 0) {
608 $error++;
609 }
610 // End call triggers
611 }
612 }
613
614 if (!$error) {
615 $this->oldref = $this->ref;
616
617 // Rename directory if dir was a temporary ref
618 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
619 // Now we rename also files into index
620 $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)."'";
621 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
622 $resql = $this->db->query($sql);
623 if (!$resql) {
624 $error++;
625 $this->error = $this->db->lasterror();
626 }
627 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'target/".$this->db->escape($this->newref)."'";
628 $sql .= " WHERE filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
629 $resql = $this->db->query($sql);
630 if (!$resql) {
631 $error++;
632 $this->error = $this->db->lasterror();
633 }
634
635 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
636 $oldref = dol_sanitizeFileName($this->ref);
637 $newref = dol_sanitizeFileName($num);
638 $dirsource = $conf->webhook->dir_output.'/target/'.$oldref;
639 $dirdest = $conf->webhook->dir_output.'/target/'.$newref;
640 if (!$error && file_exists($dirsource)) {
641 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
642
643 if (@rename($dirsource, $dirdest)) {
644 dol_syslog("Rename ok");
645 // Rename docs starting with $oldref with $newref
646 $listoffiles = dol_dir_list($conf->webhook->dir_output.'/target/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
647 foreach ($listoffiles as $fileentry) {
648 $dirsource = $fileentry['name'];
649 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
650 $dirsource = $fileentry['path'].'/'.$dirsource;
651 $dirdest = $fileentry['path'].'/'.$dirdest;
652 @rename($dirsource, $dirdest);
653 }
654 }
655 }
656 }
657 }
658
659 // Set new ref and current status
660 if (!$error) {
661 $this->ref = $num;
662 $this->status = self::STATUS_VALIDATED;
663 }
664
665 if (!$error) {
666 $this->db->commit();
667 return 1;
668 } else {
669 $this->db->rollback();
670 return -1;
671 }
672 }
673
674
682 public function setDraft($user, $notrigger = 0)
683 {
684 // Protection
685 if ($this->status <= self::STATUS_DRAFT) {
686 return 0;
687 }
688
689 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'TARGET_UNVALIDATE');
690 }
691
699 public function cancel($user, $notrigger = 0)
700 {
701 // Protection
702 if ($this->status != self::STATUS_VALIDATED) {
703 return 0;
704 }
705
706 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'TARGET_CANCEL');
707 }
708
716 public function reopen($user, $notrigger = 0)
717 {
718 // Protection
719 if ($this->status != self::STATUS_CANCELED) {
720 return 0;
721 }
722
723 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'TARGET_REOPEN');
724 }
725
736 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
737 {
738 global $conf, $langs, $hookmanager;
739
740 if (!empty($conf->dol_no_mouse_hover)) {
741 $notooltip = 1; // Force disable tooltips
742 }
743
744 $result = '';
745
746 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Target").'</u>';
747 if (isset($this->status)) {
748 $label .= ' '.$this->getLibStatut(5);
749 }
750 $label .= '<br>';
751 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
752
753 $url = dol_buildpath('/webhook/target_card.php', 1).'?id='.$this->id;
754
755 if ($option != 'nolink') {
756 // Add param to save lastsearch_values or not
757 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
758 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
759 $add_save_lastsearch_values = 1;
760 }
761 if ($url && $add_save_lastsearch_values) {
762 $url .= '&save_lastsearch_values=1';
763 }
764 }
765
766 $linkclose = '';
767 if (empty($notooltip)) {
768 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
769 $label = $langs->trans("ShowTarget");
770 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
771 }
772 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
773 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
774 } else {
775 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
776 }
777
778 if ($option == 'nolink' || empty($url)) {
779 $linkstart = '<span';
780 } else {
781 $linkstart = '<a href="'.$url.'"';
782 }
783 $linkstart .= $linkclose.'>';
784 if ($option == 'nolink' || empty($url)) {
785 $linkend = '</span>';
786 } else {
787 $linkend = '</a>';
788 }
789
790 $result .= $linkstart;
791
792 if (empty($this->showphoto_on_popup)) {
793 if ($withpicto) {
794 $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);
795 }
796 } else {
797 if ($withpicto) {
798 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
799
800 list($class, $module) = explode('@', $this->picto);
801 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
802 $filearray = dol_dir_list($upload_dir, "files");
803 $filename = $filearray[0]['name'];
804 if (!empty($filename)) {
805 $pospoint = strpos($filearray[0]['name'], '.');
806
807 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
808 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
809 $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>';
810 } else {
811 $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>';
812 }
813
814 $result .= '</div>';
815 } else {
816 $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);
817 }
818 }
819 }
820
821 if ($withpicto != 2) {
822 $result .= $this->ref;
823 }
824
825 $result .= $linkend;
826 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
827
828 global $action, $hookmanager;
829 $hookmanager->initHooks(array('targetdao'));
830 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
831 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
832 if ($reshook > 0) {
833 $result = $hookmanager->resPrint;
834 } else {
835 $result .= $hookmanager->resPrint;
836 }
837
838 return $result;
839 }
840
847 public function getLabelStatus($mode = 0)
848 {
849 return $this->LibStatut($this->status, $mode);
850 }
851
858 public function getLibStatut($mode = 0)
859 {
860 return $this->LibStatut($this->status, $mode);
861 }
862
863 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
871 public function LibStatut($status, $mode = 0)
872 {
873 // phpcs:enable
874 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
875 global $langs;
876
877 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
878 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
879 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
880 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
881 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
882 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
883 }
884
885 $statusType = 'status'.$status;
886 if ($status == self::STATUS_VALIDATED) {
887 $statusType = 'status4';
888 }
889 if ($status == self::STATUS_CANCELED) {
890 $statusType = 'status6';
891 }
892
893 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
894 }
895
902 public function info($id)
903 {
904 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
905 $sql .= " fk_user_creat, fk_user_modif";
906 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
907 $sql .= " WHERE t.rowid = ".((int) $id);
908
909 $result = $this->db->query($sql);
910 if ($result) {
911 if ($this->db->num_rows($result)) {
912 $obj = $this->db->fetch_object($result);
913
914 $this->id = $obj->rowid;
915
916 $this->user_creation_id = $obj->fk_user_creat;
917 $this->user_modification_id = $obj->fk_user_modif;
918 $this->date_creation = $this->db->jdate($obj->datec);
919 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
920 }
921
922 $this->db->free($result);
923 } else {
924 dol_print_error($this->db);
925 }
926 }
927
934 public function initAsSpecimen()
935 {
936 $this->url = "https://thisisunurl";
937 $this->trigger_codes = "ThisIsATestCode";
938
939 return $this->initAsSpecimenCommon();
940 }
941
947 public function getNextNumRef()
948 {
949 global $langs, $conf;
950
951 $mybool = false;
952
953 $classname = getDolGlobalString('WEBHOOK_TARGET_ADDON', 'mod_target_standard');
954 $file = $classname.".php";
955
956 // Include file with class
957 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
958 foreach ($dirmodels as $reldir) {
959 $dir = dol_buildpath($reldir."core/modules/webhook/");
960
961 // Load file with numbering class (if found)
962 $mybool = ((bool) @include_once $dir.$file) || $mybool;
963 }
964
965 if (!$mybool) {
966 dol_print_error(null, "Failed to include file ".$file);
967 return '';
968 }
969
970 if (class_exists($classname)) {
971 $obj = new $classname();
972 '@phan-var-force CommonNumRefGenerator $obj';
973 $numref = $obj->getNextValue($this);
974
975 if ($numref != '' && $numref != '-1') {
976 return $numref;
977 } else {
978 $this->error = $obj->error;
979 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
980 return "";
981 }
982 } else {
983 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
984 return "";
985 }
986 }
987
999 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1000 {
1001 $result = 0;
1002 $includedocgeneration = 0;
1003
1004 if (!dol_strlen($modele)) {
1005 $modele = 'standard_target';
1006
1007 if (!empty($this->model_pdf)) {
1008 $modele = $this->model_pdf;
1009 } elseif (getDolGlobalString('TARGET_ADDON_PDF')) {
1010 $modele = getDolGlobalString('TARGET_ADDON_PDF');
1011 }
1012 }
1013
1014 $modelpath = "core/modules/webhook/doc/";
1015
1016 if ($includedocgeneration && !empty($modele)) {
1017 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1018 }
1019
1020 return $result;
1021 }
1022
1030 public function doScheduledJob()
1031 {
1032 //global $conf, $langs;
1033
1034 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1035
1036 $error = 0;
1037 $this->output = '';
1038 $this->error = '';
1039
1040 dol_syslog(__METHOD__, LOG_DEBUG);
1041
1042 //$now = dol_now();
1043
1044 $this->db->begin();
1045
1046 // ...
1047
1048 $this->db->commit();
1049
1050 return $error;
1051 }
1052}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
$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.
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...
Definition index.php:162
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.