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