dolibarr 19.0.4
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Put here all includes required by your class file
26require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29
33class Target extends CommonObject
34{
38 public $module = 'webhook';
39
43 public $element = 'target';
44
48 public $table_element = 'webhook_target';
49
54 public $ismultientitymanaged = 0;
55
59 public $isextrafieldmanaged = 0;
60
64 public $picto = 'webhook';
65
66
67 const STATUS_DRAFT = 0;
68 const STATUS_VALIDATED = 1;
69 const STATUS_CANCELED = 9;
70
71
100 // BEGIN MODULEBUILDER PROPERTIES
104 public $fields=array(
105 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
106 '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"),
107 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'help'=>"Help text", 'showoncombobox'=>'2', 'validate'=>'1',),
108 'url' => array('type'=>'varchar(255)', 'label'=>'Url', 'enabled'=>'1', 'position'=>50, 'notnull'=>1, 'visible'=>1,),
109 'trigger_codes' => array('type'=>'text', 'label'=>'TriggerCodes', 'enabled'=>'1', 'position'=>55, 'notnull'=>1, 'visible'=>1, 'help'=>"TriggerCodeInfo",),
110 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3, 'validate'=>'1',),
111 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0, 'cssview'=>'wordbreak', 'validate'=>'1',),
112 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0, 'cssview'=>'wordbreak', 'validate'=>'1',),
113 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
114 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
115 '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',),
116 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
117 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
118 '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',),
119 );
120 public $rowid;
121 public $ref;
122 public $label;
123 public $description;
124 public $note_public;
125 public $note_private;
126 public $date_creation;
127 public $tms;
128 public $fk_user_creat;
129 public $fk_user_modif;
130 public $import_key;
131 public $status;
132 public $url;
133 public $trigger_codes;
134 // END MODULEBUILDER PROPERTIES
135
136
137 // If this object has a subtable with lines
138
139 // /**
140 // * @var string Name of subtable line
141 // */
142 // public $table_element_line = 'webhook_targetline';
143
144 // /**
145 // * @var string Field with ID of parent key if this object has a parent
146 // */
147 // public $fk_element = 'fk_target';
148
149 // /**
150 // * @var string Name of subtable class that manage subtable lines
151 // */
152 // public $class_element_line = 'Targetline';
153
154 // /**
155 // * @var array List of child tables. To test if we can delete object.
156 // */
157 // protected $childtables = array();
158
159 // /**
160 // * @var array List of child tables. To know object to delete on cascade.
161 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
162 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
163 // */
164 // protected $childtablesoncascade = array('webhook_targetdet');
165
166 // /**
167 // * @var TargetLine[] Array of subtable lines
168 // */
169 // public $lines = array();
170
171
172
178 public function __construct(DoliDB $db)
179 {
180 global $conf, $langs;
181
182 $this->db = $db;
183
184 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
185 $this->fields['rowid']['visible'] = 0;
186 }
187 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
188 $this->fields['entity']['enabled'] = 0;
189 }
190
191 // Example to show how to set values of fields definition dynamically
192 /*if ($user->rights->webhook->target->read) {
193 $this->fields['myfield']['visible'] = 1;
194 $this->fields['myfield']['noteditable'] = 0;
195 }*/
196
197 // Unset fields that are disabled
198 foreach ($this->fields as $key => $val) {
199 if (isset($val['enabled']) && empty($val['enabled'])) {
200 unset($this->fields[$key]);
201 }
202 }
203
204 // Translate some data of arrayofkeyval
205 if (is_object($langs)) {
206 foreach ($this->fields as $key => $val) {
207 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
208 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
209 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
210 }
211 }
212 }
213 }
214 }
215
223 public function create(User $user, $notrigger = false)
224 {
225 $resultcreate = $this->createCommon($user, $notrigger);
226 $this->ref = $this->id;
227
228 if ($resultcreate <= 0) {
229 return $resultcreate;
230 }
231
232 return $this->id;
233 }
234
242 public function createFromClone(User $user, $fromid)
243 {
244 global $langs, $extrafields;
245 $error = 0;
246
247 dol_syslog(__METHOD__, LOG_DEBUG);
248
249 $object = new self($this->db);
250
251 $this->db->begin();
252
253 // Load source object
254 $result = $object->fetchCommon($fromid);
255 if ($result > 0 && !empty($object->table_element_line)) {
256 $object->fetchLines();
257 }
258
259 // get lines so they will be clone
260 //foreach($this->lines as $line)
261 // $line->fetch_optionals();
262
263 // Reset some properties
264 unset($object->id);
265 unset($object->fk_user_creat);
266 unset($object->import_key);
267
268 // Clear fields
269 if (property_exists($object, 'ref')) {
270 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
271 }
272 if (property_exists($object, 'label')) {
273 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
274 }
275 if (property_exists($object, 'status')) {
276 $object->status = self::STATUS_DRAFT;
277 }
278 if (property_exists($object, 'date_creation')) {
279 $object->date_creation = dol_now();
280 }
281 if (property_exists($object, 'date_modification')) {
282 $object->date_modification = null;
283 }
284 // ...
285 // Clear extrafields that are unique
286 if (is_array($object->array_options) && count($object->array_options) > 0) {
287 $extrafields->fetch_name_optionals_label($this->table_element);
288 foreach ($object->array_options as $key => $option) {
289 $shortkey = preg_replace('/options_/', '', $key);
290 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
291 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
292 unset($object->array_options[$key]);
293 }
294 }
295 }
296
297 // Create clone
298 $object->context['createfromclone'] = 'createfromclone';
299 $result = $object->createCommon($user);
300 if ($result < 0) {
301 $error++;
302 $this->setErrorsFromObject($object);
303 }
304
305 // if (!$error) {
306 // // copy internal contacts
307 // if ($this->copy_linked_contact($object, 'internal') < 0) {
308 // $error++;
309 // }
310 // }
311
312 // if (!$error) {
313 // // copy external contacts if same company
314 // if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
315 // if ($this->copy_linked_contact($object, 'external') < 0) {
316 // $error++;
317 // }
318 // }
319 // }
320
321 unset($object->context['createfromclone']);
322
323 // End
324 if (!$error) {
325 $this->db->commit();
326 return $object;
327 } else {
328 $this->db->rollback();
329 return -1;
330 }
331 }
332
340 public function fetch($id, $ref = null)
341 {
342 $result = $this->fetchCommon($id, $ref);
343 if (empty($this->ref)) {
344 $this->ref = $this->id;
345 }
346
347 return $result;
348 }
349
355 public function fetchLines()
356 {
357 $this->lines = array();
358
359 $result = $this->fetchLinesCommon();
360 return $result;
361 }
362
363
375 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
376 {
377 global $conf;
378
379 dol_syslog(__METHOD__, LOG_DEBUG);
380
381 $records = array();
382
383 $sql = "SELECT ";
384 $sql .= $this->getFieldList('t');
385 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
386 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
387 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
388 } else {
389 $sql .= " WHERE 1 = 1";
390 }
391 // Manage filter
392 $sqlwhere = array();
393 if (count($filter) > 0) {
394 foreach ($filter as $key => $value) {
395 if ($key == 't.rowid') {
396 $sqlwhere[] = $key." = ".((int) $value);
397 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
398 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
399 } elseif ($key == 'customsql') {
400 $sqlwhere[] = $value;
401 } elseif (strpos($value, '%') === false) {
402 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
403 } else {
404 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
405 }
406 }
407 }
408 if (count($sqlwhere) > 0) {
409 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
410 }
411
412 if (!empty($sortfield)) {
413 $sql .= $this->db->order($sortfield, $sortorder);
414 }
415 if (!empty($limit)) {
416 $sql .= $this->db->plimit($limit, $offset);
417 }
418
419 $resql = $this->db->query($sql);
420 if ($resql) {
421 $num = $this->db->num_rows($resql);
422 $i = 0;
423 while ($i < ($limit ? min($limit, $num) : $num)) {
424 $obj = $this->db->fetch_object($resql);
425
426 $record = new self($this->db);
427 $record->setVarsFromFetchObj($obj);
428
429 $records[$record->id] = $record;
430
431 $i++;
432 }
433 $this->db->free($resql);
434
435 return $records;
436 } else {
437 $this->errors[] = 'Error '.$this->db->lasterror();
438 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
439
440 return -1;
441 }
442 }
443
451 public function update(User $user, $notrigger = false)
452 {
453 return $this->updateCommon($user, $notrigger);
454 }
455
463 public function delete(User $user, $notrigger = false)
464 {
465 return $this->deleteCommon($user, $notrigger);
466 //return $this->deleteCommon($user, $notrigger, 1);
467 }
468
477 public function deleteLine(User $user, $idline, $notrigger = false)
478 {
479 if ($this->status < 0) {
480 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
481 return -2;
482 }
483
484 return $this->deleteLineCommon($user, $idline, $notrigger);
485 }
486
487
495 public function validate($user, $notrigger = 0)
496 {
497 global $conf, $langs;
498
499 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
500
501 $error = 0;
502
503 // Protection
504 if ($this->status == self::STATUS_VALIDATED) {
505 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
506 return 0;
507 }
508
509 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->target->write))
510 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->target->target_advance->validate))))
511 {
512 $this->error='NotEnoughPermissions';
513 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
514 return -1;
515 }*/
516
517 $now = dol_now();
518
519 $this->db->begin();
520
521 // Define new ref
522 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
523 $num = $this->getNextNumRef();
524 } else {
525 $num = $this->ref;
526 }
527 $this->newref = $num;
528
529 if (!empty($num)) {
530 // Validate
531 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
532 $sql .= " SET ref = '".$this->db->escape($num)."',";
533 $sql .= " status = ".self::STATUS_VALIDATED;
534 if (!empty($this->fields['date_validation'])) {
535 $sql .= ", date_validation = '".$this->db->idate($now)."'";
536 }
537 if (!empty($this->fields['fk_user_valid'])) {
538 $sql .= ", fk_user_valid = ".((int) $user->id);
539 }
540 $sql .= " WHERE rowid = ".((int) $this->id);
541
542 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
543 $resql = $this->db->query($sql);
544 if (!$resql) {
545 dol_print_error($this->db);
546 $this->error = $this->db->lasterror();
547 $error++;
548 }
549
550 if (!$error && !$notrigger) {
551 // Call trigger
552 $result = $this->call_trigger('TARGET_VALIDATE', $user);
553 if ($result < 0) {
554 $error++;
555 }
556 // End call triggers
557 }
558 }
559
560 if (!$error) {
561 $this->oldref = $this->ref;
562
563 // Rename directory if dir was a temporary ref
564 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
565 // Now we rename also files into index
566 $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)."'";
567 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
568 $resql = $this->db->query($sql);
569 if (!$resql) {
570 $error++;
571 $this->error = $this->db->lasterror();
572 }
573 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'target/".$this->db->escape($this->newref)."'";
574 $sql .= " WHERE filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
575 $resql = $this->db->query($sql);
576 if (!$resql) {
577 $error++;
578 $this->error = $this->db->lasterror();
579 }
580
581 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
582 $oldref = dol_sanitizeFileName($this->ref);
583 $newref = dol_sanitizeFileName($num);
584 $dirsource = $conf->webhook->dir_output.'/target/'.$oldref;
585 $dirdest = $conf->webhook->dir_output.'/target/'.$newref;
586 if (!$error && file_exists($dirsource)) {
587 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
588
589 if (@rename($dirsource, $dirdest)) {
590 dol_syslog("Rename ok");
591 // Rename docs starting with $oldref with $newref
592 $listoffiles = dol_dir_list($conf->webhook->dir_output.'/target/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
593 foreach ($listoffiles as $fileentry) {
594 $dirsource = $fileentry['name'];
595 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
596 $dirsource = $fileentry['path'].'/'.$dirsource;
597 $dirdest = $fileentry['path'].'/'.$dirdest;
598 @rename($dirsource, $dirdest);
599 }
600 }
601 }
602 }
603 }
604
605 // Set new ref and current status
606 if (!$error) {
607 $this->ref = $num;
608 $this->status = self::STATUS_VALIDATED;
609 }
610
611 if (!$error) {
612 $this->db->commit();
613 return 1;
614 } else {
615 $this->db->rollback();
616 return -1;
617 }
618 }
619
620
628 public function setDraft($user, $notrigger = 0)
629 {
630 // Protection
631 if ($this->status <= self::STATUS_DRAFT) {
632 return 0;
633 }
634
635 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
636 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
637 {
638 $this->error='Permission denied';
639 return -1;
640 }*/
641
642 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'TARGET_UNVALIDATE');
643 }
644
652 public function cancel($user, $notrigger = 0)
653 {
654 // Protection
655 if ($this->status != self::STATUS_VALIDATED) {
656 return 0;
657 }
658
659 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
660 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
661 {
662 $this->error='Permission denied';
663 return -1;
664 }*/
665
666 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'TARGET_CANCEL');
667 }
668
676 public function reopen($user, $notrigger = 0)
677 {
678 // Protection
679 if ($this->status != self::STATUS_CANCELED) {
680 return 0;
681 }
682
683 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
684 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
685 {
686 $this->error='Permission denied';
687 return -1;
688 }*/
689
690 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'TARGET_REOPEN');
691 }
692
703 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
704 {
705 global $conf, $langs, $hookmanager;
706
707 if (!empty($conf->dol_no_mouse_hover)) {
708 $notooltip = 1; // Force disable tooltips
709 }
710
711 $result = '';
712
713 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Target").'</u>';
714 if (isset($this->status)) {
715 $label .= ' '.$this->getLibStatut(5);
716 }
717 $label .= '<br>';
718 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
719
720 $url = dol_buildpath('/webhook/target_card.php', 1).'?id='.$this->id;
721
722 if ($option != 'nolink') {
723 // Add param to save lastsearch_values or not
724 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
725 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
726 $add_save_lastsearch_values = 1;
727 }
728 if ($url && $add_save_lastsearch_values) {
729 $url .= '&save_lastsearch_values=1';
730 }
731 }
732
733 $linkclose = '';
734 if (empty($notooltip)) {
735 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
736 $label = $langs->trans("ShowTarget");
737 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
738 }
739 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
740 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
741 } else {
742 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
743 }
744
745 if ($option == 'nolink' || empty($url)) {
746 $linkstart = '<span';
747 } else {
748 $linkstart = '<a href="'.$url.'"';
749 }
750 $linkstart .= $linkclose.'>';
751 if ($option == 'nolink' || empty($url)) {
752 $linkend = '</span>';
753 } else {
754 $linkend = '</a>';
755 }
756
757 $result .= $linkstart;
758
759 if (empty($this->showphoto_on_popup)) {
760 if ($withpicto) {
761 $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);
762 }
763 } else {
764 if ($withpicto) {
765 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
766
767 list($class, $module) = explode('@', $this->picto);
768 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
769 $filearray = dol_dir_list($upload_dir, "files");
770 $filename = $filearray[0]['name'];
771 if (!empty($filename)) {
772 $pospoint = strpos($filearray[0]['name'], '.');
773
774 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
775 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
776 $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>';
777 } else {
778 $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>';
779 }
780
781 $result .= '</div>';
782 } else {
783 $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);
784 }
785 }
786 }
787
788 if ($withpicto != 2) {
789 $result .= $this->ref;
790 }
791
792 $result .= $linkend;
793 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
794
795 global $action, $hookmanager;
796 $hookmanager->initHooks(array('targetdao'));
797 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
798 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
799 if ($reshook > 0) {
800 $result = $hookmanager->resPrint;
801 } else {
802 $result .= $hookmanager->resPrint;
803 }
804
805 return $result;
806 }
807
814 public function getLabelStatus($mode = 0)
815 {
816 return $this->LibStatut($this->status, $mode);
817 }
818
825 public function getLibStatut($mode = 0)
826 {
827 return $this->LibStatut($this->status, $mode);
828 }
829
830 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
838 public function LibStatut($status, $mode = 0)
839 {
840 // phpcs:enable
841 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
842 global $langs;
843
844 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
845 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
846 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
847 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
848 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
849 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
850 }
851
852 $statusType = 'status'.$status;
853 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
854 if ($status == self::STATUS_CANCELED) {
855 $statusType = 'status6';
856 }
857
858 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
859 }
860
867 public function info($id)
868 {
869 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
870 $sql .= " fk_user_creat, fk_user_modif";
871 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
872 $sql .= " WHERE t.rowid = ".((int) $id);
873
874 $result = $this->db->query($sql);
875 if ($result) {
876 if ($this->db->num_rows($result)) {
877 $obj = $this->db->fetch_object($result);
878
879 $this->id = $obj->rowid;
880
881 $this->user_creation_id = $obj->fk_user_creat;
882 $this->user_modification_id = $obj->fk_user_modif;
883 $this->date_creation = $this->db->jdate($obj->datec);
884 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
885 }
886
887 $this->db->free($result);
888 } else {
889 dol_print_error($this->db);
890 }
891 }
892
899 public function initAsSpecimen()
900 {
901 $this->url = "https://thisisunurl";
902 $this->trigger_codes = "ThisIsATestCode";
903 $this->initAsSpecimenCommon();
904 }
905
911 public function getLinesArray()
912 {
913 $this->lines = array();
914
915 $objectline = new TargetLine($this->db);
916 $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_target = '.((int) $this->id)));
917
918 if (is_numeric($result)) {
919 $this->error = $objectline->error;
920 $this->errors = $objectline->errors;
921 return $result;
922 } else {
923 $this->lines = $result;
924 return $this->lines;
925 }
926 }
927
933 public function getNextNumRef()
934 {
935 global $langs, $conf;
936
937 $mybool = false;
938
939 $classname = getDolGlobalString('WEBHOOK_TARGET_ADDON', 'mod_target_standard');
940 $file = $classname.".php";
941
942 // Include file with class
943 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
944 foreach ($dirmodels as $reldir) {
945 $dir = dol_buildpath($reldir."core/modules/webhook/");
946
947 // Load file with numbering class (if found)
948 $mybool |= @include_once $dir.$file;
949 }
950
951 if ($mybool === false) {
952 dol_print_error('', "Failed to include file ".$file);
953 return '';
954 }
955
956 if (class_exists($classname)) {
957 $obj = new $classname();
958 $numref = $obj->getNextValue($this);
959
960 if ($numref != '' && $numref != '-1') {
961 return $numref;
962 } else {
963 $this->error = $obj->error;
964 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
965 return "";
966 }
967 } else {
968 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
969 return "";
970 }
971 }
972
984 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
985 {
986 global $conf, $langs;
987
988 $result = 0;
989 $includedocgeneration = 0;
990
991 if (!dol_strlen($modele)) {
992 $modele = 'standard_target';
993
994 if (!empty($this->model_pdf)) {
995 $modele = $this->model_pdf;
996 } elseif (getDolGlobalString('TARGET_ADDON_PDF')) {
997 $modele = $conf->global->TARGET_ADDON_PDF;
998 }
999 }
1000
1001 $modelpath = "core/modules/webhook/doc/";
1002
1003 if ($includedocgeneration && !empty($modele)) {
1004 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1005 }
1006
1007 return $result;
1008 }
1009
1017 public function doScheduledJob()
1018 {
1019 global $conf, $langs;
1020
1021 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1022
1023 $error = 0;
1024 $this->output = '';
1025 $this->error = '';
1026
1027 dol_syslog(__METHOD__, LOG_DEBUG);
1028
1029 $now = dol_now();
1030
1031 $this->db->begin();
1032
1033 // ...
1034
1035 $this->db->commit();
1036
1037 return $error;
1038 }
1039}
1040
1041
1042require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1043
1048{
1049 // To complete with content of an object TargetLine
1050 // We should have a field rowid, fk_target and position
1051
1055 public $isextrafieldmanaged = 0;
1056
1062 public function __construct(DoliDB $db)
1063 {
1064 $this->db = $db;
1065 }
1066}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for Target.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
update(User $user, $notrigger=false)
Update object into database.
deleteLine(User $user, $idline, $notrigger=false)
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.
getLinesArray()
Create an array of lines.
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 optionaly 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.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
cancel($user, $notrigger=0)
Set cancel status.
create(User $user, $notrigger=false)
Create object into database.
validate($user, $notrigger=0)
Validate object.
setDraft($user, $notrigger=0)
Set draft status.
Class TargetLine.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr users.
dol_dir_list($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:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.