dolibarr  18.0.6
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  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->error = $object->error;
303  $this->errors = $object->errors;
304  }
305 
306  if (!$error) {
307  // copy internal contacts
308  if ($this->copy_linked_contact($object, 'internal') < 0) {
309  $error++;
310  }
311  }
312 
313  if (!$error) {
314  // copy external contacts if same company
315  if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
316  if ($this->copy_linked_contact($object, 'external') < 0) {
317  $error++;
318  }
319  }
320  }
321 
322  unset($object->context['createfromclone']);
323 
324  // End
325  if (!$error) {
326  $this->db->commit();
327  return $object;
328  } else {
329  $this->db->rollback();
330  return -1;
331  }
332  }
333 
341  public function fetch($id, $ref = null)
342  {
343  $result = $this->fetchCommon($id, $ref);
344  if (empty($this->ref)) {
345  $this->ref = $this->id;
346  }
347 
348  return $result;
349  }
350 
356  public function fetchLines()
357  {
358  $this->lines = array();
359 
360  $result = $this->fetchLinesCommon();
361  return $result;
362  }
363 
364 
376  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
377  {
378  global $conf;
379 
380  dol_syslog(__METHOD__, LOG_DEBUG);
381 
382  $records = array();
383 
384  $sql = "SELECT ";
385  $sql .= $this->getFieldList('t');
386  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
387  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
388  $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
389  } else {
390  $sql .= " WHERE 1 = 1";
391  }
392  // Manage filter
393  $sqlwhere = array();
394  if (count($filter) > 0) {
395  foreach ($filter as $key => $value) {
396  if ($key == 't.rowid') {
397  $sqlwhere[] = $key." = ".((int) $value);
398  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
399  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
400  } elseif ($key == 'customsql') {
401  $sqlwhere[] = $value;
402  } elseif (strpos($value, '%') === false) {
403  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
404  } else {
405  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
406  }
407  }
408  }
409  if (count($sqlwhere) > 0) {
410  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
411  }
412 
413  if (!empty($sortfield)) {
414  $sql .= $this->db->order($sortfield, $sortorder);
415  }
416  if (!empty($limit)) {
417  $sql .= $this->db->plimit($limit, $offset);
418  }
419 
420  $resql = $this->db->query($sql);
421  if ($resql) {
422  $num = $this->db->num_rows($resql);
423  $i = 0;
424  while ($i < ($limit ? min($limit, $num) : $num)) {
425  $obj = $this->db->fetch_object($resql);
426 
427  $record = new self($this->db);
428  $record->setVarsFromFetchObj($obj);
429 
430  $records[$record->id] = $record;
431 
432  $i++;
433  }
434  $this->db->free($resql);
435 
436  return $records;
437  } else {
438  $this->errors[] = 'Error '.$this->db->lasterror();
439  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
440 
441  return -1;
442  }
443  }
444 
452  public function update(User $user, $notrigger = false)
453  {
454  return $this->updateCommon($user, $notrigger);
455  }
456 
464  public function delete(User $user, $notrigger = false)
465  {
466  return $this->deleteCommon($user, $notrigger);
467  //return $this->deleteCommon($user, $notrigger, 1);
468  }
469 
478  public function deleteLine(User $user, $idline, $notrigger = false)
479  {
480  if ($this->status < 0) {
481  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
482  return -2;
483  }
484 
485  return $this->deleteLineCommon($user, $idline, $notrigger);
486  }
487 
488 
496  public function validate($user, $notrigger = 0)
497  {
498  global $conf, $langs;
499 
500  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
501 
502  $error = 0;
503 
504  // Protection
505  if ($this->status == self::STATUS_VALIDATED) {
506  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
507  return 0;
508  }
509 
510  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->target->write))
511  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->target->target_advance->validate))))
512  {
513  $this->error='NotEnoughPermissions';
514  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
515  return -1;
516  }*/
517 
518  $now = dol_now();
519 
520  $this->db->begin();
521 
522  // Define new ref
523  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
524  $num = $this->getNextNumRef();
525  } else {
526  $num = $this->ref;
527  }
528  $this->newref = $num;
529 
530  if (!empty($num)) {
531  // Validate
532  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
533  $sql .= " SET ref = '".$this->db->escape($num)."',";
534  $sql .= " status = ".self::STATUS_VALIDATED;
535  if (!empty($this->fields['date_validation'])) {
536  $sql .= ", date_validation = '".$this->db->idate($now)."'";
537  }
538  if (!empty($this->fields['fk_user_valid'])) {
539  $sql .= ", fk_user_valid = ".((int) $user->id);
540  }
541  $sql .= " WHERE rowid = ".((int) $this->id);
542 
543  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
544  $resql = $this->db->query($sql);
545  if (!$resql) {
546  dol_print_error($this->db);
547  $this->error = $this->db->lasterror();
548  $error++;
549  }
550 
551  if (!$error && !$notrigger) {
552  // Call trigger
553  $result = $this->call_trigger('TARGET_VALIDATE', $user);
554  if ($result < 0) {
555  $error++;
556  }
557  // End call triggers
558  }
559  }
560 
561  if (!$error) {
562  $this->oldref = $this->ref;
563 
564  // Rename directory if dir was a temporary ref
565  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
566  // Now we rename also files into index
567  $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)."'";
568  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
569  $resql = $this->db->query($sql);
570  if (!$resql) {
571  $error++; $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++; $this->error = $this->db->lasterror();
578  }
579 
580  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
581  $oldref = dol_sanitizeFileName($this->ref);
582  $newref = dol_sanitizeFileName($num);
583  $dirsource = $conf->webhook->dir_output.'/target/'.$oldref;
584  $dirdest = $conf->webhook->dir_output.'/target/'.$newref;
585  if (!$error && file_exists($dirsource)) {
586  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
587 
588  if (@rename($dirsource, $dirdest)) {
589  dol_syslog("Rename ok");
590  // Rename docs starting with $oldref with $newref
591  $listoffiles = dol_dir_list($conf->webhook->dir_output.'/target/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
592  foreach ($listoffiles as $fileentry) {
593  $dirsource = $fileentry['name'];
594  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
595  $dirsource = $fileentry['path'].'/'.$dirsource;
596  $dirdest = $fileentry['path'].'/'.$dirdest;
597  @rename($dirsource, $dirdest);
598  }
599  }
600  }
601  }
602  }
603 
604  // Set new ref and current status
605  if (!$error) {
606  $this->ref = $num;
607  $this->status = self::STATUS_VALIDATED;
608  }
609 
610  if (!$error) {
611  $this->db->commit();
612  return 1;
613  } else {
614  $this->db->rollback();
615  return -1;
616  }
617  }
618 
619 
627  public function setDraft($user, $notrigger = 0)
628  {
629  // Protection
630  if ($this->status <= self::STATUS_DRAFT) {
631  return 0;
632  }
633 
634  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
635  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
636  {
637  $this->error='Permission denied';
638  return -1;
639  }*/
640 
641  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'TARGET_UNVALIDATE');
642  }
643 
651  public function cancel($user, $notrigger = 0)
652  {
653  // Protection
654  if ($this->status != self::STATUS_VALIDATED) {
655  return 0;
656  }
657 
658  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
659  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
660  {
661  $this->error='Permission denied';
662  return -1;
663  }*/
664 
665  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'TARGET_CANCEL');
666  }
667 
675  public function reopen($user, $notrigger = 0)
676  {
677  // Protection
678  if ($this->status != self::STATUS_CANCELED) {
679  return 0;
680  }
681 
682  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->write))
683  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->webhook->webhook_advance->validate))))
684  {
685  $this->error='Permission denied';
686  return -1;
687  }*/
688 
689  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'TARGET_REOPEN');
690  }
691 
702  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
703  {
704  global $conf, $langs, $hookmanager;
705 
706  if (!empty($conf->dol_no_mouse_hover)) {
707  $notooltip = 1; // Force disable tooltips
708  }
709 
710  $result = '';
711 
712  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Target").'</u>';
713  if (isset($this->status)) {
714  $label .= ' '.$this->getLibStatut(5);
715  }
716  $label .= '<br>';
717  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
718 
719  $url = dol_buildpath('/webhook/target_card.php', 1).'?id='.$this->id;
720 
721  if ($option != 'nolink') {
722  // Add param to save lastsearch_values or not
723  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
724  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
725  $add_save_lastsearch_values = 1;
726  }
727  if ($url && $add_save_lastsearch_values) {
728  $url .= '&save_lastsearch_values=1';
729  }
730  }
731 
732  $linkclose = '';
733  if (empty($notooltip)) {
734  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
735  $label = $langs->trans("ShowTarget");
736  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
737  }
738  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
739  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
740  } else {
741  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
742  }
743 
744  if ($option == 'nolink' || empty($url)) {
745  $linkstart = '<span';
746  } else {
747  $linkstart = '<a href="'.$url.'"';
748  }
749  $linkstart .= $linkclose.'>';
750  if ($option == 'nolink' || empty($url)) {
751  $linkend = '</span>';
752  } else {
753  $linkend = '</a>';
754  }
755 
756  $result .= $linkstart;
757 
758  if (empty($this->showphoto_on_popup)) {
759  if ($withpicto) {
760  $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);
761  }
762  } else {
763  if ($withpicto) {
764  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
765 
766  list($class, $module) = explode('@', $this->picto);
767  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
768  $filearray = dol_dir_list($upload_dir, "files");
769  $filename = $filearray[0]['name'];
770  if (!empty($filename)) {
771  $pospoint = strpos($filearray[0]['name'], '.');
772 
773  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
774  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
775  $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>';
776  } else {
777  $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>';
778  }
779 
780  $result .= '</div>';
781  } else {
782  $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);
783  }
784  }
785  }
786 
787  if ($withpicto != 2) {
788  $result .= $this->ref;
789  }
790 
791  $result .= $linkend;
792  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
793 
794  global $action, $hookmanager;
795  $hookmanager->initHooks(array('targetdao'));
796  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
797  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
798  if ($reshook > 0) {
799  $result = $hookmanager->resPrint;
800  } else {
801  $result .= $hookmanager->resPrint;
802  }
803 
804  return $result;
805  }
806 
813  public function getLabelStatus($mode = 0)
814  {
815  return $this->LibStatut($this->status, $mode);
816  }
817 
824  public function getLibStatut($mode = 0)
825  {
826  return $this->LibStatut($this->status, $mode);
827  }
828 
829  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
837  public function LibStatut($status, $mode = 0)
838  {
839  // phpcs:enable
840  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
841  global $langs;
842 
843  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
844  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
845  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
846  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
847  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
848  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
849  }
850 
851  $statusType = 'status'.$status;
852  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
853  if ($status == self::STATUS_CANCELED) {
854  $statusType = 'status6';
855  }
856 
857  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
858  }
859 
866  public function info($id)
867  {
868  $sql = "SELECT rowid, date_creation as datec, tms as datem,";
869  $sql .= " fk_user_creat, fk_user_modif";
870  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
871  $sql .= " WHERE t.rowid = ".((int) $id);
872 
873  $result = $this->db->query($sql);
874  if ($result) {
875  if ($this->db->num_rows($result)) {
876  $obj = $this->db->fetch_object($result);
877  $this->id = $obj->rowid;
878 
879 
880  $this->user_creation_id = $obj->fk_user_creat;
881  $this->user_modification_id = $obj->fk_user_modif;
882  $this->date_creation = $this->db->jdate($obj->datec);
883  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
884  }
885 
886  $this->db->free($result);
887  } else {
888  dol_print_error($this->db);
889  }
890  }
891 
898  public function initAsSpecimen()
899  {
900  $this->url = "https://thisisunurl";
901  $this->trigger_codes = "ThisIsATestCode";
902  $this->initAsSpecimenCommon();
903  }
904 
910  public function getLinesArray()
911  {
912  $this->lines = array();
913 
914  $objectline = new TargetLine($this->db);
915  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_target = '.((int) $this->id)));
916 
917  if (is_numeric($result)) {
918  $this->error = $objectline->error;
919  $this->errors = $objectline->errors;
920  return $result;
921  } else {
922  $this->lines = $result;
923  return $this->lines;
924  }
925  }
926 
932  public function getNextNumRef()
933  {
934  global $langs, $conf;
935 
936  if (empty($conf->global->WEBHOOK_TARGET_ADDON)) {
937  $conf->global->WEBHOOK_TARGET_ADDON = 'mod_target_standard';
938  }
939 
940  if (!empty($conf->global->WEBHOOK_TARGET_ADDON)) {
941  $mybool = false;
942 
943  $file = $conf->global->WEBHOOK_TARGET_ADDON.".php";
944  $classname = $conf->global->WEBHOOK_TARGET_ADDON;
945 
946  // Include file with class
947  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
948  foreach ($dirmodels as $reldir) {
949  $dir = dol_buildpath($reldir."core/modules/webhook/");
950 
951  // Load file with numbering class (if found)
952  $mybool |= @include_once $dir.$file;
953  }
954 
955  if ($mybool === false) {
956  dol_print_error('', "Failed to include file ".$file);
957  return '';
958  }
959 
960  if (class_exists($classname)) {
961  $obj = new $classname();
962  $numref = $obj->getNextValue($this);
963 
964  if ($numref != '' && $numref != '-1') {
965  return $numref;
966  } else {
967  $this->error = $obj->error;
968  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
969  return "";
970  }
971  } else {
972  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
973  return "";
974  }
975  } else {
976  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
977  return "";
978  }
979  }
980 
992  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
993  {
994  global $conf, $langs;
995 
996  $result = 0;
997  $includedocgeneration = 0;
998 
999  if (!dol_strlen($modele)) {
1000  $modele = 'standard_target';
1001 
1002  if (!empty($this->model_pdf)) {
1003  $modele = $this->model_pdf;
1004  } elseif (!empty($conf->global->TARGET_ADDON_PDF)) {
1005  $modele = $conf->global->TARGET_ADDON_PDF;
1006  }
1007  }
1008 
1009  $modelpath = "core/modules/webhook/doc/";
1010 
1011  if ($includedocgeneration && !empty($modele)) {
1012  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1013  }
1014 
1015  return $result;
1016  }
1017 
1025  public function doScheduledJob()
1026  {
1027  global $conf, $langs;
1028 
1029  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1030 
1031  $error = 0;
1032  $this->output = '';
1033  $this->error = '';
1034 
1035  dol_syslog(__METHOD__, LOG_DEBUG);
1036 
1037  $now = dol_now();
1038 
1039  $this->db->begin();
1040 
1041  // ...
1042 
1043  $this->db->commit();
1044 
1045  return $error;
1046  }
1047 }
1048 
1049 
1050 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1051 
1056 {
1057  // To complete with content of an object TargetLine
1058  // We should have a field rowid, fk_target and position
1059 
1063  public $isextrafieldmanaged = 0;
1064 
1070  public function __construct(DoliDB $db)
1071  {
1072  $this->db = $db;
1073  }
1074 }
$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.
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.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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:48
if(isModEnabled('facture') && $user->hasRight('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
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)
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.