dolibarr  18.0.0-beta
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
26 require_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 
33 class 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 (empty($conf->global->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  $resultvalidate = $this->validate($user, $notrigger);
233  if ($resultvalidate <= 0) {
234  return $resultvalidate;
235  }
236 
237  return $this->id;
238  }
239 
247  public function createFromClone(User $user, $fromid)
248  {
249  global $langs, $extrafields;
250  $error = 0;
251 
252  dol_syslog(__METHOD__, LOG_DEBUG);
253 
254  $object = new self($this->db);
255 
256  $this->db->begin();
257 
258  // Load source object
259  $result = $object->fetchCommon($fromid);
260  if ($result > 0 && !empty($object->table_element_line)) {
261  $object->fetchLines();
262  }
263 
264  // get lines so they will be clone
265  //foreach($this->lines as $line)
266  // $line->fetch_optionals();
267 
268  // Reset some properties
269  unset($object->id);
270  unset($object->fk_user_creat);
271  unset($object->import_key);
272 
273  // Clear fields
274  if (property_exists($object, 'ref')) {
275  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
276  }
277  if (property_exists($object, 'label')) {
278  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
279  }
280  if (property_exists($object, 'status')) {
281  $object->status = self::STATUS_DRAFT;
282  }
283  if (property_exists($object, 'date_creation')) {
284  $object->date_creation = dol_now();
285  }
286  if (property_exists($object, 'date_modification')) {
287  $object->date_modification = null;
288  }
289  // ...
290  // Clear extrafields that are unique
291  if (is_array($object->array_options) && count($object->array_options) > 0) {
292  $extrafields->fetch_name_optionals_label($this->table_element);
293  foreach ($object->array_options as $key => $option) {
294  $shortkey = preg_replace('/options_/', '', $key);
295  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
296  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
297  unset($object->array_options[$key]);
298  }
299  }
300  }
301 
302  // Create clone
303  $object->context['createfromclone'] = 'createfromclone';
304  $result = $object->createCommon($user);
305  if ($result < 0) {
306  $error++;
307  $this->error = $object->error;
308  $this->errors = $object->errors;
309  }
310 
311  if (!$error) {
312  // copy internal contacts
313  if ($this->copy_linked_contact($object, 'internal') < 0) {
314  $error++;
315  }
316  }
317 
318  if (!$error) {
319  // copy external contacts if same company
320  if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
321  if ($this->copy_linked_contact($object, 'external') < 0) {
322  $error++;
323  }
324  }
325  }
326 
327  unset($object->context['createfromclone']);
328 
329  // End
330  if (!$error) {
331  $this->db->commit();
332  return $object;
333  } else {
334  $this->db->rollback();
335  return -1;
336  }
337  }
338 
346  public function fetch($id, $ref = null)
347  {
348  $result = $this->fetchCommon($id, $ref);
349  if (empty($this->ref)) {
350  $this->ref = $this->id;
351  }
352 
353  return $result;
354  }
355 
361  public function fetchLines()
362  {
363  $this->lines = array();
364 
365  $result = $this->fetchLinesCommon();
366  return $result;
367  }
368 
369 
381  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
382  {
383  global $conf;
384 
385  dol_syslog(__METHOD__, LOG_DEBUG);
386 
387  $records = array();
388 
389  $sql = "SELECT ";
390  $sql .= $this->getFieldList('t');
391  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
392  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
393  $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
394  } else {
395  $sql .= " WHERE 1 = 1";
396  }
397  // Manage filter
398  $sqlwhere = array();
399  if (count($filter) > 0) {
400  foreach ($filter as $key => $value) {
401  if ($key == 't.rowid') {
402  $sqlwhere[] = $key." = ".((int) $value);
403  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
404  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
405  } elseif ($key == 'customsql') {
406  $sqlwhere[] = $value;
407  } elseif (strpos($value, '%') === false) {
408  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
409  } else {
410  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
411  }
412  }
413  }
414  if (count($sqlwhere) > 0) {
415  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
416  }
417 
418  if (!empty($sortfield)) {
419  $sql .= $this->db->order($sortfield, $sortorder);
420  }
421  if (!empty($limit)) {
422  $sql .= $this->db->plimit($limit, $offset);
423  }
424 
425  $resql = $this->db->query($sql);
426  if ($resql) {
427  $num = $this->db->num_rows($resql);
428  $i = 0;
429  while ($i < ($limit ? min($limit, $num) : $num)) {
430  $obj = $this->db->fetch_object($resql);
431 
432  $record = new self($this->db);
433  $record->setVarsFromFetchObj($obj);
434 
435  $records[$record->id] = $record;
436 
437  $i++;
438  }
439  $this->db->free($resql);
440 
441  return $records;
442  } else {
443  $this->errors[] = 'Error '.$this->db->lasterror();
444  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
445 
446  return -1;
447  }
448  }
449 
457  public function update(User $user, $notrigger = false)
458  {
459  return $this->updateCommon($user, $notrigger);
460  }
461 
469  public function delete(User $user, $notrigger = false)
470  {
471  return $this->deleteCommon($user, $notrigger);
472  //return $this->deleteCommon($user, $notrigger, 1);
473  }
474 
483  public function deleteLine(User $user, $idline, $notrigger = false)
484  {
485  if ($this->status < 0) {
486  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
487  return -2;
488  }
489 
490  return $this->deleteLineCommon($user, $idline, $notrigger);
491  }
492 
493 
501  public function validate($user, $notrigger = 0)
502  {
503  global $conf, $langs;
504 
505  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
506 
507  $error = 0;
508 
509  // Protection
510  if ($this->status == self::STATUS_VALIDATED) {
511  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
512  return 0;
513  }
514 
515  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->target->write))
516  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->target->target_advance->validate))))
517  {
518  $this->error='NotEnoughPermissions';
519  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
520  return -1;
521  }*/
522 
523  $now = dol_now();
524 
525  $this->db->begin();
526 
527  // Define new ref
528  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
529  $num = $this->getNextNumRef();
530  } else {
531  $num = $this->ref;
532  }
533  $this->newref = $num;
534 
535  if (!empty($num)) {
536  // Validate
537  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
538  $sql .= " SET ref = '".$this->db->escape($num)."',";
539  $sql .= " status = ".self::STATUS_VALIDATED;
540  if (!empty($this->fields['date_validation'])) {
541  $sql .= ", date_validation = '".$this->db->idate($now)."'";
542  }
543  if (!empty($this->fields['fk_user_valid'])) {
544  $sql .= ", fk_user_valid = ".((int) $user->id);
545  }
546  $sql .= " WHERE rowid = ".((int) $this->id);
547 
548  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
549  $resql = $this->db->query($sql);
550  if (!$resql) {
551  dol_print_error($this->db);
552  $this->error = $this->db->lasterror();
553  $error++;
554  }
555 
556  if (!$error && !$notrigger) {
557  // Call trigger
558  $result = $this->call_trigger('TARGET_VALIDATE', $user);
559  if ($result < 0) {
560  $error++;
561  }
562  // End call triggers
563  }
564  }
565 
566  if (!$error) {
567  $this->oldref = $this->ref;
568 
569  // Rename directory if dir was a temporary ref
570  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
571  // Now we rename also files into index
572  $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)."'";
573  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
574  $resql = $this->db->query($sql);
575  if (!$resql) {
576  $error++; $this->error = $this->db->lasterror();
577  }
578 
579  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
580  $oldref = dol_sanitizeFileName($this->ref);
581  $newref = dol_sanitizeFileName($num);
582  $dirsource = $conf->webhook->dir_output.'/target/'.$oldref;
583  $dirdest = $conf->webhook->dir_output.'/target/'.$newref;
584  if (!$error && file_exists($dirsource)) {
585  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
586 
587  if (@rename($dirsource, $dirdest)) {
588  dol_syslog("Rename ok");
589  // Rename docs starting with $oldref with $newref
590  $listoffiles = dol_dir_list($conf->webhook->dir_output.'/target/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
591  foreach ($listoffiles as $fileentry) {
592  $dirsource = $fileentry['name'];
593  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
594  $dirsource = $fileentry['path'].'/'.$dirsource;
595  $dirdest = $fileentry['path'].'/'.$dirdest;
596  @rename($dirsource, $dirdest);
597  }
598  }
599  }
600  }
601  }
602 
603  // Set new ref and current status
604  if (!$error) {
605  $this->ref = $num;
606  $this->status = self::STATUS_VALIDATED;
607  }
608 
609  if (!$error) {
610  $this->db->commit();
611  return 1;
612  } else {
613  $this->db->rollback();
614  return -1;
615  }
616  }
617 
618 
626  public function setDraft($user, $notrigger = 0)
627  {
628  // Protection
629  if ($this->status <= self::STATUS_DRAFT) {
630  return 0;
631  }
632 
633  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
634  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
635  {
636  $this->error='Permission denied';
637  return -1;
638  }*/
639 
640  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'TARGET_UNVALIDATE');
641  }
642 
650  public function cancel($user, $notrigger = 0)
651  {
652  // Protection
653  if ($this->status != self::STATUS_VALIDATED) {
654  return 0;
655  }
656 
657  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
658  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
659  {
660  $this->error='Permission denied';
661  return -1;
662  }*/
663 
664  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'TARGET_CANCEL');
665  }
666 
674  public function reopen($user, $notrigger = 0)
675  {
676  // Protection
677  if ($this->status != self::STATUS_CANCELED) {
678  return 0;
679  }
680 
681  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
682  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
683  {
684  $this->error='Permission denied';
685  return -1;
686  }*/
687 
688  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'TARGET_REOPEN');
689  }
690 
701  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
702  {
703  global $conf, $langs, $hookmanager;
704 
705  if (!empty($conf->dol_no_mouse_hover)) {
706  $notooltip = 1; // Force disable tooltips
707  }
708 
709  $result = '';
710 
711  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Target").'</u>';
712  if (isset($this->status)) {
713  $label .= ' '.$this->getLibStatut(5);
714  }
715  $label .= '<br>';
716  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
717 
718  $url = dol_buildpath('/webhook/target_card.php', 1).'?id='.$this->id;
719 
720  if ($option != 'nolink') {
721  // Add param to save lastsearch_values or not
722  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
723  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
724  $add_save_lastsearch_values = 1;
725  }
726  if ($url && $add_save_lastsearch_values) {
727  $url .= '&save_lastsearch_values=1';
728  }
729  }
730 
731  $linkclose = '';
732  if (empty($notooltip)) {
733  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
734  $label = $langs->trans("ShowTarget");
735  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
736  }
737  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
738  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
739  } else {
740  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
741  }
742 
743  if ($option == 'nolink' || empty($url)) {
744  $linkstart = '<span';
745  } else {
746  $linkstart = '<a href="'.$url.'"';
747  }
748  $linkstart .= $linkclose.'>';
749  if ($option == 'nolink' || empty($url)) {
750  $linkend = '</span>';
751  } else {
752  $linkend = '</a>';
753  }
754 
755  $result .= $linkstart;
756 
757  if (empty($this->showphoto_on_popup)) {
758  if ($withpicto) {
759  $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);
760  }
761  } else {
762  if ($withpicto) {
763  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
764 
765  list($class, $module) = explode('@', $this->picto);
766  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
767  $filearray = dol_dir_list($upload_dir, "files");
768  $filename = $filearray[0]['name'];
769  if (!empty($filename)) {
770  $pospoint = strpos($filearray[0]['name'], '.');
771 
772  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
773  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
774  $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>';
775  } else {
776  $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>';
777  }
778 
779  $result .= '</div>';
780  } else {
781  $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);
782  }
783  }
784  }
785 
786  if ($withpicto != 2) {
787  $result .= $this->ref;
788  }
789 
790  $result .= $linkend;
791  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
792 
793  global $action, $hookmanager;
794  $hookmanager->initHooks(array('targetdao'));
795  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
796  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
797  if ($reshook > 0) {
798  $result = $hookmanager->resPrint;
799  } else {
800  $result .= $hookmanager->resPrint;
801  }
802 
803  return $result;
804  }
805 
812  public function getLabelStatus($mode = 0)
813  {
814  return $this->LibStatut($this->status, $mode);
815  }
816 
823  public function getLibStatut($mode = 0)
824  {
825  return $this->LibStatut($this->status, $mode);
826  }
827 
828  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
836  public function LibStatut($status, $mode = 0)
837  {
838  // phpcs:enable
839  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
840  global $langs;
841 
842  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
843  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
844  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
845  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
846  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
847  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
848  }
849 
850  $statusType = 'status'.$status;
851  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
852  if ($status == self::STATUS_CANCELED) {
853  $statusType = 'status6';
854  }
855 
856  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
857  }
858 
865  public function info($id)
866  {
867  $sql = "SELECT rowid, date_creation as datec, tms as datem,";
868  $sql .= " fk_user_creat, fk_user_modif";
869  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
870  $sql .= " WHERE t.rowid = ".((int) $id);
871 
872  $result = $this->db->query($sql);
873  if ($result) {
874  if ($this->db->num_rows($result)) {
875  $obj = $this->db->fetch_object($result);
876  $this->id = $obj->rowid;
877 
878 
879  $this->user_creation_id = $obj->fk_user_creat;
880  $this->user_modification_id = $obj->fk_user_modif;
881  $this->date_creation = $this->db->jdate($obj->datec);
882  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
883  }
884 
885  $this->db->free($result);
886  } else {
887  dol_print_error($this->db);
888  }
889  }
890 
897  public function initAsSpecimen()
898  {
899  $this->url = "https://thisisunurl";
900  $this->trigger_codes = "ThisIsATestCode";
901  $this->initAsSpecimenCommon();
902  }
903 
909  public function getLinesArray()
910  {
911  $this->lines = array();
912 
913  $objectline = new TargetLine($this->db);
914  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_target = '.((int) $this->id)));
915 
916  if (is_numeric($result)) {
917  $this->error = $objectline->error;
918  $this->errors = $objectline->errors;
919  return $result;
920  } else {
921  $this->lines = $result;
922  return $this->lines;
923  }
924  }
925 
931  public function getNextNumRef()
932  {
933  global $langs, $conf;
934 
935  if (empty($conf->global->WEBHOOK_TARGET_ADDON)) {
936  $conf->global->WEBHOOK_TARGET_ADDON = 'mod_target_standard';
937  }
938 
939  if (!empty($conf->global->WEBHOOK_TARGET_ADDON)) {
940  $mybool = false;
941 
942  $file = $conf->global->WEBHOOK_TARGET_ADDON.".php";
943  $classname = $conf->global->WEBHOOK_TARGET_ADDON;
944 
945  // Include file with class
946  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
947  foreach ($dirmodels as $reldir) {
948  $dir = dol_buildpath($reldir."core/modules/webhook/");
949 
950  // Load file with numbering class (if found)
951  $mybool |= @include_once $dir.$file;
952  }
953 
954  if ($mybool === false) {
955  dol_print_error('', "Failed to include file ".$file);
956  return '';
957  }
958 
959  if (class_exists($classname)) {
960  $obj = new $classname();
961  $numref = $obj->getNextValue($this);
962 
963  if ($numref != '' && $numref != '-1') {
964  return $numref;
965  } else {
966  $this->error = $obj->error;
967  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
968  return "";
969  }
970  } else {
971  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
972  return "";
973  }
974  } else {
975  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
976  return "";
977  }
978  }
979 
991  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
992  {
993  global $conf, $langs;
994 
995  $result = 0;
996  $includedocgeneration = 0;
997 
998  if (!dol_strlen($modele)) {
999  $modele = 'standard_target';
1000 
1001  if (!empty($this->model_pdf)) {
1002  $modele = $this->model_pdf;
1003  } elseif (!empty($conf->global->TARGET_ADDON_PDF)) {
1004  $modele = $conf->global->TARGET_ADDON_PDF;
1005  }
1006  }
1007 
1008  $modelpath = "core/modules/webhook/doc/";
1009 
1010  if ($includedocgeneration && !empty($modele)) {
1011  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1012  }
1013 
1014  return $result;
1015  }
1016 
1024  public function doScheduledJob()
1025  {
1026  global $conf, $langs;
1027 
1028  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1029 
1030  $error = 0;
1031  $this->output = '';
1032  $this->error = '';
1033 
1034  dol_syslog(__METHOD__, LOG_DEBUG);
1035 
1036  $now = dol_now();
1037 
1038  $this->db->begin();
1039 
1040  // ...
1041 
1042  $this->db->commit();
1043 
1044  return $error;
1045  }
1046 }
1047 
1048 
1049 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1050 
1055 {
1056  // To complete with content of an object TargetLine
1057  // We should have a field rowid, fk_target and position
1058 
1062  public $isextrafieldmanaged = 0;
1063 
1069  public function __construct(DoliDB $db)
1070  {
1071  $this->db = $db;
1072  }
1073 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9539
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9817
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9329
Target\create
create(User $user, $notrigger=false)
Create object into database.
Definition: target.class.php:223
Target\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: target.class.php:346
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1322
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1099
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
Target\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: target.class.php:897
Target\update
update(User $user, $notrigger=false)
Update object into database.
Definition: target.class.php:457
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5096
Target\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: target.class.php:823
Target\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: target.class.php:931
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1157
dol_dir_list
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
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9385
Target\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: target.class.php:626
CommonObjectLine
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Definition: commonobjectline.class.php:32
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
Target\info
info($id)
Load the info information in the object.
Definition: target.class.php:865
Target\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: target.class.php:674
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4125
Target\getLinesArray
getLinesArray()
Create an array of lines.
Definition: target.class.php:909
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9162
Target\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: target.class.php:836
Target\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: target.class.php:381
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
Target\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: target.class.php:247
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1732
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9435
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3987
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
ref
$object ref
Definition: info.php:78
Target\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: target.class.php:1024
Target\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: target.class.php:650
User
Class to manage Dolibarr users.
Definition: user.class.php:47
Target\getLabelStatus
getLabelStatus($mode=0)
Return the label of the status.
Definition: target.class.php:812
Target
Class for Target.
Definition: target.class.php:33
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10932
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4462
Target\__construct
__construct(DoliDB $db)
Constructor.
Definition: target.class.php:178
Target\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: target.class.php:483
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3046
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9755
TargetLine
Class TargetLine.
Definition: target.class.php:1054
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5743
TargetLine\__construct
__construct(DoliDB $db)
Constructor.
Definition: target.class.php:1069
Target\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: target.class.php:991
Target\validate
validate($user, $notrigger=0)
Validate object.
Definition: target.class.php:501
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9114
Target\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: target.class.php:701
Target\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: target.class.php:361