dolibarr  16.0.5
conferenceorboothattendee.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 
34 {
38  public $module = 'eventorganization';
39 
43  public $element = 'conferenceorboothattendee';
44 
48  public $table_element = 'eventorganization_conferenceorboothattendee';
49 
54  public $ismultientitymanaged = 0;
55 
59  public $isextrafieldmanaged = 1;
60 
64  public $picto = 'contact';
65 
66  public $paid = 0;
67 
68  const STATUS_DRAFT = 0;
69  const STATUS_VALIDATED = 1;
70  const STATUS_CANCELED = 9;
71 
72 
99  // BEGIN MODULEBUILDER PROPERTIES
103  public $fields = array(
104  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
105  'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>2, 'index'=>1, 'comment'=>"Reference of object"),
106  'fk_actioncomm' => array('type'=>'integer:ActionComm:comm/action/class/actioncomm.class.php:1', 'label'=>'ConferenceOrBooth', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>0, 'index'=>1, 'picto'=>'agenda'),
107  'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'$conf->project->enabled', 'position'=>20, 'notnull'=>1, 'visible'=>0, 'index'=>1, 'picto'=>'project', 'css'=>'tdoverflowmax150 maxwidth500'),
108  'email' => array('type'=>'mail', 'label'=>'EmailAttendee', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'autofocusoncreate'=>1, 'searchall'=>1),
109  'firstname' => array('type'=>'varchar(100)', 'label'=>'Firstname', 'enabled'=>'1', 'position'=>31, 'notnull'=>0, 'visible'=>1, 'index'=>1, 'searchall'=>1),
110  'lastname' => array('type'=>'varchar(100)', 'label'=>'Lastname', 'enabled'=>'1', 'position'=>32, 'notnull'=>0, 'visible'=>1, 'index'=>1, 'searchall'=>1),
111  'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status = 1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'$conf->societe->enabled', 'position'=>40, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'help'=>"OrganizationEventLinkToThirdParty", 'picto'=>'company', 'css'=>'tdoverflowmax150 maxwidth500'),
112  'date_subscription' => array('type'=>'datetime', 'label'=>'DateOfRegistration', 'enabled'=>'1', 'position'=>56, 'notnull'=>1, 'visible'=>1, 'showoncombobox'=>'1',),
113  'fk_invoice' => array('type'=>'integer:Facture:compta/facture/class/facture.class.php', 'label'=>'Invoice', 'enabled'=>'$conf->facture->enabled', 'position'=>57, 'notnull'=>0, 'visible'=>-1, 'index'=>0, 'picto'=>'bill', 'css'=>'tdoverflowmax150 maxwidth500'),
114  'amount' => array('type'=>'price', 'label'=>'AmountPaid', 'enabled'=>'1', 'position'=>57, 'notnull'=>0, 'visible'=>1, 'default'=>'null', 'isameasure'=>'1', 'help'=>"AmountOfSubscriptionPaid",),
115  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>3,),
116  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>3,),
117  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
118  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
119  'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>-1, 'visible'=>-2),
120  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
121  'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,),
122  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
123  'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
124  'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'default'=>0, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '9'=>'Canceled'),),
125  );
126  public $rowid;
127  public $ref;
128  public $fk_soc;
129  public $fk_actioncomm;
130  public $email;
131  public $firstname;
132  public $lastname;
133  public $date_subscription;
134  public $fk_invoice;
135  public $amount;
136  public $note_public;
137  public $note_private;
138  public $date_creation;
139  public $tms;
140  public $fk_user_creat;
141  public $fk_user_modif;
142  public $last_main_doc;
143  public $import_key;
144  public $model_pdf;
145  public $status;
146  // END MODULEBUILDER PROPERTIES
147 
148 
149  // If this object has a subtable with lines
150 
151  // /**
152  // * @var string Name of subtable line
153  // */
154  // public $table_element_line = 'eventorganization_conferenceorboothattendeeline';
155 
156  // /**
157  // * @var string Field with ID of parent key if this object has a parent
158  // */
159  // public $fk_element = 'fk_conferenceorboothattendee';
160 
161  // /**
162  // * @var string Name of subtable class that manage subtable lines
163  // */
164  // public $class_element_line = 'ConferenceOrBoothAttendeeline';
165 
166  // /**
167  // * @var array List of child tables. To test if we can delete object.
168  // */
169  // protected $childtables = array();
170 
171  // /**
172  // * @var array List of child tables. To know object to delete on cascade.
173  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
174  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
175  // */
176  // protected $childtablesoncascade = array('eventorganization_conferenceorboothattendeedet');
177 
178  // /**
179  // * @var ConferenceOrBoothAttendeeLine[] Array of subtable lines
180  // */
181  // public $lines = array();
182 
183 
184 
190  public function __construct(DoliDB $db)
191  {
192  global $conf, $langs;
193 
194  $this->db = $db;
195 
196  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
197  $this->fields['rowid']['visible'] = 0;
198  }
199  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
200  $this->fields['entity']['enabled'] = 0;
201  }
202 
203  if (!empty($conf->global->EVENTORGANIZATION_FILTERATTENDEES_CAT)) {
204  $this->fields['fk_soc']['type'] .= ' AND rowid IN (SELECT DISTINCT c.fk_soc FROM '.MAIN_DB_PREFIX.'categorie_societe as c WHERE c.fk_categorie='.(int) $conf->global->EVENTORGANIZATION_FILTERATTENDEES_CAT.')';
205  }
206  if (isset($conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE)
207  && $conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE !== ''
208  && $conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE !== '-1') {
209  $this->fields['fk_soc']['type'] .= ' AND client = '.(int) $conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE;
210  }
211 
212  // Example to show how to set values of fields definition dynamically
213  /*if ($user->rights->eventorganization->conferenceorboothattendee->read) {
214  $this->fields['myfield']['visible'] = 1;
215  $this->fields['myfield']['noteditable'] = 0;
216  }*/
217 
218  // Unset fields that are disabled
219  foreach ($this->fields as $key => $val) {
220  if (isset($val['enabled']) && empty($val['enabled'])) {
221  unset($this->fields[$key]);
222  }
223  }
224 
225  // Translate some data of arrayofkeyval
226  if (is_object($langs)) {
227  foreach ($this->fields as $key => $val) {
228  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
229  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
230  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
231  }
232  }
233  }
234  }
235  }
236 
244  public function create(User $user, $notrigger = false)
245  {
246  global $langs;
247 
248  if (!isValidEMail($this->email)) {
249  $langs->load("errors");
250  $this->errors[] = $langs->trans("ErrorBadEMail", $this->email);
251  return -1;
252  }
253 
254  $result = $this->createCommon($user, $notrigger);
255  if ($result > 0) {
256  $result = $this->fetch($result);
257  if ($result > 0) {
258  $this->ref = $this->id;
259  $result = $this->update($user);
260  }
261  }
262  return $result;
263  }
264 
272  public function createFromClone(User $user, $fromid)
273  {
274  global $langs, $extrafields;
275  $error = 0;
276 
277  dol_syslog(__METHOD__, LOG_DEBUG);
278 
279  $object = new self($this->db);
280 
281  $this->db->begin();
282 
283  // Load source object
284  $result = $object->fetchCommon($fromid);
285  if ($result > 0 && !empty($object->table_element_line)) {
286  $object->fetchLines();
287  }
288 
289  // get lines so they will be clone
290  //foreach($this->lines as $line)
291  // $line->fetch_optionals();
292 
293  // Reset some properties
294  unset($object->id);
295  unset($object->fk_user_creat);
296  unset($object->import_key);
297 
298  // Clear fields
299  if (property_exists($object, 'ref')) {
300  $object->ref = empty($this->fields['ref']['default']) ? "(PROV)" : $this->fields['ref']['default'];
301  }
302  if (property_exists($object, 'label')) {
303  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
304  }
305  if (property_exists($object, 'status')) {
306  $object->status = self::STATUS_DRAFT;
307  }
308  if (property_exists($object, 'date_creation')) {
309  $object->date_creation = dol_now();
310  }
311  if (property_exists($object, 'date_modification')) {
312  $object->date_modification = null;
313  }
314  // ...
315  // Clear extrafields that are unique
316  if (is_array($object->array_options) && count($object->array_options) > 0) {
317  $extrafields->fetch_name_optionals_label($this->table_element);
318  foreach ($object->array_options as $key => $option) {
319  $shortkey = preg_replace('/options_/', '', $key);
320  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
321  //var_dump($key);
322  //var_dump($clonedObj->array_options[$key]); exit;
323  unset($object->array_options[$key]);
324  }
325  }
326  }
327 
328  // Create clone
329  $object->context['createfromclone'] = 'createfromclone';
330  $result = $object->createCommon($user);
331  if ($result < 0) {
332  $error++;
333  $this->error = $object->error;
334  $this->errors = $object->errors;
335  } else {
336  $object->ref = $object->id;
337  $result = $object->update($user);
338  }
339 
340  if (!$error) {
341  // copy internal contacts
342  if ($this->copy_linked_contact($object, 'internal') < 0) {
343  $error++;
344  }
345  }
346 
347  if (!$error) {
348  // copy external contacts if same company
349  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
350  if ($this->copy_linked_contact($object, 'external') < 0) {
351  $error++;
352  }
353  }
354  }
355 
356  unset($object->context['createfromclone']);
357 
358  // End
359  if (!$error) {
360  $this->db->commit();
361  return $object;
362  } else {
363  $this->db->rollback();
364  return -1;
365  }
366  }
367 
375  public function fetch($id, $ref = null)
376  {
377  $result = $this->fetchCommon($id, $ref);
378  if ($result > 0 && !empty($this->table_element_line)) {
379  $this->fetchLines();
380  }
381  return $result;
382  }
383 
389  public function fetchLines()
390  {
391  $this->lines = array();
392 
393  $result = $this->fetchLinesCommon();
394  return $result;
395  }
396 
397 
409  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
410  {
411  global $conf;
412 
413  dol_syslog(__METHOD__, LOG_DEBUG);
414 
415  $records = array();
416 
417  $sql = 'SELECT ';
418  $sql .= $this->getFieldList('t');
419  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
420  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm as a on a.id = t.fk_actioncomm";
421  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
422  $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
423  } else {
424  $sql .= ' WHERE 1 = 1';
425  }
426  // Manage filter
427  $sqlwhere = array();
428  if (count($filter) > 0) {
429  foreach ($filter as $key => $value) {
430  if ($key == 't.rowid' || $key == 't.fk_soc' || $key == 't.fk_project' || $key == 't.fk_actioncomm') {
431  $sqlwhere[] = $key.'='.((int) $value);
432  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
433  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
434  } elseif ($key == 'customsql') {
435  $sqlwhere[] = $value;
436  } elseif (strpos($value, '%') === false) {
437  $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
438  } else {
439  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
440  }
441  }
442  }
443  if (count($sqlwhere) > 0) {
444  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
445  }
446 
447  if (!empty($sortfield)) {
448  $sql .= $this->db->order($sortfield, $sortorder);
449  }
450  if (!empty($limit)) {
451  $sql .= $this->db->plimit($limit, $offset);
452  }
453 
454  $resql = $this->db->query($sql);
455  if ($resql) {
456  $num = $this->db->num_rows($resql);
457  $i = 0;
458  while ($i < ($limit ? min($limit, $num) : $num)) {
459  $obj = $this->db->fetch_object($resql);
460 
461  $record = new self($this->db);
462  $record->setVarsFromFetchObj($obj);
463 
464  $records[$record->id] = $record;
465 
466  $i++;
467  }
468  $this->db->free($resql);
469 
470  return $records;
471  } else {
472  $this->errors[] = 'Error '.$this->db->lasterror();
473  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
474 
475  return -1;
476  }
477  }
478 
486  public function update(User $user, $notrigger = false)
487  {
488  return $this->updateCommon($user, $notrigger);
489  }
490 
498  public function delete(User $user, $notrigger = false)
499  {
500  return $this->deleteCommon($user, $notrigger);
501  //return $this->deleteCommon($user, $notrigger, 1);
502  }
503 
512  public function deleteLine(User $user, $idline, $notrigger = false)
513  {
514  if ($this->status < 0) {
515  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
516  return -2;
517  }
518 
519  return $this->deleteLineCommon($user, $idline, $notrigger);
520  }
521 
522 
530  public function validate($user, $notrigger = 0)
531  {
532  global $conf, $langs;
533 
534  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
535 
536  $error = 0;
537 
538  // Protection
539  if ($this->status == self::STATUS_VALIDATED) {
540  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
541  return 0;
542  }
543 
544  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->conferenceorboothattendee->write))
545  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->conferenceorboothattendee->conferenceorboothattendee_advance->validate))))
546  {
547  $this->error='NotEnoughPermissions';
548  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
549  return -1;
550  }*/
551 
552  $now = dol_now();
553 
554  $this->db->begin();
555 
556  // Define new ref
557  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
558  $num = $this->getNextNumRef();
559  } else {
560  $num = $this->ref;
561  }
562  $this->newref = $num;
563 
564  if (!empty($num)) {
565  // Validate
566  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
567  $sql .= " SET ref = '".$this->db->escape($num)."',";
568  $sql .= " status = ".self::STATUS_VALIDATED;
569  if (!empty($this->fields['date_validation'])) {
570  $sql .= ", date_validation = '".$this->db->idate($now)."'";
571  }
572  if (!empty($this->fields['fk_user_valid'])) {
573  $sql .= ", fk_user_valid = ".$user->id;
574  }
575  $sql .= " WHERE rowid = ".((int) $this->id);
576 
577  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
578  $resql = $this->db->query($sql);
579  if (!$resql) {
580  dol_print_error($this->db);
581  $this->error = $this->db->lasterror();
582  $error++;
583  }
584 
585  if (!$error && !$notrigger) {
586  // Call trigger
587  $result = $this->call_trigger('CONFERENCEORBOOTHATTENDEE_VALIDATE', $user);
588  if ($result < 0) {
589  $error++;
590  }
591  // End call triggers
592  }
593  }
594 
595  if (!$error) {
596  $this->oldref = $this->ref;
597 
598  // Rename directory if dir was a temporary ref
599  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
600  // Now we rename also files into index
601  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'conferenceorboothattendee/".$this->db->escape($this->newref)."'";
602  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
603  $resql = $this->db->query($sql);
604  if (!$resql) {
605  $error++; $this->error = $this->db->lasterror();
606  }
607 
608  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
609  $oldref = dol_sanitizeFileName($this->ref);
610  $newref = dol_sanitizeFileName($num);
611  $dirsource = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$oldref;
612  $dirdest = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref;
613  if (!$error && file_exists($dirsource)) {
614  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
615 
616  if (@rename($dirsource, $dirdest)) {
617  dol_syslog("Rename ok");
618  // Rename docs starting with $oldref with $newref
619  $listoffiles = dol_dir_list($conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
620  foreach ($listoffiles as $fileentry) {
621  $dirsource = $fileentry['name'];
622  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
623  $dirsource = $fileentry['path'].'/'.$dirsource;
624  $dirdest = $fileentry['path'].'/'.$dirdest;
625  @rename($dirsource, $dirdest);
626  }
627  }
628  }
629  }
630  }
631 
632  // Set new ref and current status
633  if (!$error) {
634  $this->ref = $num;
635  $this->status = self::STATUS_VALIDATED;
636  }
637 
638  if (!$error) {
639  $this->db->commit();
640  return 1;
641  } else {
642  $this->db->rollback();
643  return -1;
644  }
645  }
646 
647  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
653  public function fetch_projet()
654  {
655  // phpcs:enable
656  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
657 
658  if (empty($this->fk_project) && !empty($this->fk_projet)) {
659  $this->fk_project = $this->fk_projet; // For backward compatibility
660  }
661  if (empty($this->fk_project)) {
662  return 0;
663  }
664 
665  $project = new Project($this->db);
666  $result = $project->fetch($this->fk_project);
667 
668  $this->projet = $project; // deprecated
669  $this->project = $project;
670  return $result;
671  }
672 
680  public function setDraft($user, $notrigger = 0)
681  {
682  // Protection
683  if ($this->status <= self::STATUS_DRAFT) {
684  return 0;
685  }
686 
687  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
688  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
689  {
690  $this->error='Permission denied';
691  return -1;
692  }*/
693 
694  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTHATTENDEE_UNVALIDATE');
695  }
696 
704  public function cancel($user, $notrigger = 0)
705  {
706  // Protection
707  if ($this->status != self::STATUS_VALIDATED) {
708  return 0;
709  }
710 
711  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
712  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
713  {
714  $this->error='Permission denied';
715  return -1;
716  }*/
717 
718  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_CANCEL');
719  }
720 
728  public function reopen($user, $notrigger = 0)
729  {
730  // Protection
731  if ($this->status != self::STATUS_CANCELED) {
732  return 0;
733  }
734 
735  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
736  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
737  {
738  $this->error='Permission denied';
739  return -1;
740  }*/
741 
742  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_REOPEN');
743  }
744 
755  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
756  {
757  global $conf, $langs, $hookmanager;
758 
759  if (!empty($conf->dol_no_mouse_hover)) {
760  $notooltip = 1; // Force disable tooltips
761  }
762 
763  $result = '';
764 
765  $label = img_picto('', $this->picto).' <u>'.$langs->trans("ConferenceOrBoothAttendee").'</u>';
766  if (isset($this->status)) {
767  $label .= ' '.$this->getLibStatut(5);
768  }
769  $label .= '<br>';
770  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
771  $label .= '<br><b>'.$langs->trans('DateOfRegistration').':</b> '.dol_print_date($this->date_subscription, 'dayhour');
772  $label .= '<br><b>'.$langs->trans('AmountPaid').':</b> '.$this->amount;
773 
774  $url = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.$this->id;
775 
776  if ($option != 'nolink') {
777  // Add param to save lastsearch_values or not
778  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
779  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
780  $add_save_lastsearch_values = 1;
781  }
782  if ($add_save_lastsearch_values) {
783  $url .= '&save_lastsearch_values=1';
784  }
785 
786  if ($option == 'conforboothid') {
787  $url .= '&conforboothid='.((int) $this->fk_actioncomm);
788  }
789 
790  if ($option == 'projectid') {
791  $url .= '&fk_project='.((int) $this->fk_project).'&withproject=1';
792  }
793 
794  if ($option == 'conforboothidproject') {
795  $url .= '&conforboothid='.((int) $this->fk_actioncomm).'&withproject=1';
796  }
797  }
798 
799  $linkclose = '';
800  if (empty($notooltip)) {
801  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
802  $label = $langs->trans("ShowConferenceOrBoothAttendee");
803  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
804  }
805  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
806  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
807  } else {
808  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
809  }
810 
811  if ($option == 'nolink') {
812  $linkstart = '<span';
813  } else {
814  $linkstart = '<a href="'.$url.'"';
815  }
816  $linkstart .= $linkclose.'>';
817  if ($option == 'nolink') {
818  $linkend = '</span>';
819  } else {
820  $linkend = '</a>';
821  }
822 
823  $result .= $linkstart;
824 
825  if (empty($this->showphoto_on_popup)) {
826  if ($withpicto) {
827  $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);
828  }
829  } else {
830  if ($withpicto) {
831  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
832 
833  list($class, $module) = explode('@', $this->picto);
834  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
835  $filearray = dol_dir_list($upload_dir, "files");
836  $filename = $filearray[0]['name'];
837  if (!empty($filename)) {
838  $pospoint = strpos($filearray[0]['name'], '.');
839 
840  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
841  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
842  $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>';
843  } else {
844  $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>';
845  }
846 
847  $result .= '</div>';
848  } else {
849  $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);
850  }
851  }
852  }
853 
854  if ($withpicto != 2) {
855  $result .= $this->ref;
856  }
857 
858  $result .= $linkend;
859  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
860 
861  global $action, $hookmanager;
862  $hookmanager->initHooks(array('conferenceorboothattendeedao'));
863  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
864  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
865  if ($reshook > 0) {
866  $result = $hookmanager->resPrint;
867  } else {
868  $result .= $hookmanager->resPrint;
869  }
870 
871  return $result;
872  }
873 
880  public function getLabelStatus($mode = 0)
881  {
882  return $this->LibStatut($this->status, $mode);
883  }
884 
891  public function getLibStatut($mode = 0)
892  {
893  return $this->LibStatut($this->status, $mode);
894  }
895 
896  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
904  public function LibStatut($status, $mode = 0)
905  {
906  // phpcs:enable
907  global $langs;
908 
909  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
910  //$langs->load("eventorganization@eventorganization");
911  $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
912  $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
913  $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
914  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
915  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
916  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
917  }
918 
919  $statusType = 'status'.$status;
920  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
921  if ($status == self::STATUS_CANCELED) {
922  $statusType = 'status6';
923  }
924 
925  if ($status == self::STATUS_VALIDATED && $this->date_subscription && $this->amount) {
926  $statusType = 'status4';
927  $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated').' - '.$langs->trans("Paid");
928  }
929 
930  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
931  }
932 
939  public function info($id)
940  {
941  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
942  $sql .= ' fk_user_creat, fk_user_modif';
943  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
944  $sql .= ' WHERE t.rowid = '.((int) $id);
945  $result = $this->db->query($sql);
946  if ($result) {
947  if ($this->db->num_rows($result)) {
948  $obj = $this->db->fetch_object($result);
949  $this->id = $obj->rowid;
950 
951  $this->user_creation_id = $obj->fk_user_creat;
952  $this->user_modification_id = $obj->fk_user_modif;
953  $this->date_creation = $this->db->jdate($obj->datec);
954  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
955  }
956 
957  $this->db->free($result);
958  } else {
959  dol_print_error($this->db);
960  }
961  }
962 
969  public function initAsSpecimen()
970  {
971  $this->initAsSpecimenCommon();
972  }
973 
979  public function getNextNumRef()
980  {
981  global $langs, $conf;
982  $langs->load("eventorganization@eventorganization");
983 
984  if (empty($conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON)) {
985  $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON = 'mod_conferenceorboothattendee_standard';
986  }
987 
988  if (!empty($conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON)) {
989  $mybool = false;
990 
991  $file = $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON.".php";
992  $classname = $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON;
993 
994  // Include file with class
995  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
996  foreach ($dirmodels as $reldir) {
997  $dir = dol_buildpath($reldir."core/modules/eventorganization/");
998 
999  // Load file with numbering class (if found)
1000  $mybool |= @include_once $dir.$file;
1001  }
1002 
1003  if ($mybool === false) {
1004  dol_print_error('', "Failed to include file ".$file);
1005  return '';
1006  }
1007 
1008  if (class_exists($classname)) {
1009  $obj = new $classname();
1010  $numref = $obj->getNextValue($this);
1011 
1012  if ($numref != '' && $numref != '-1') {
1013  return $numref;
1014  } else {
1015  $this->error = $obj->error;
1016  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1017  return "";
1018  }
1019  } else {
1020  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1021  return "";
1022  }
1023  } else {
1024  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1025  return "";
1026  }
1027  }
1028 
1040  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1041  {
1042  global $conf, $langs;
1043 
1044  $result = 0;
1045  $includedocgeneration = 0;
1046 
1047  $langs->load("eventorganization@eventorganization");
1048 
1049  if (!dol_strlen($modele)) {
1050  $modele = 'standard_conferenceorboothattendee';
1051 
1052  if (!empty($this->model_pdf)) {
1053  $modele = $this->model_pdf;
1054  } elseif (!empty($conf->global->CONFERENCEORBOOTHATTENDEE_ADDON_PDF)) {
1055  $modele = $conf->global->CONFERENCEORBOOTHATTENDEE_ADDON_PDF;
1056  }
1057  }
1058 
1059  $modelpath = "core/modules/eventorganization/doc/";
1060 
1061  if ($includedocgeneration && !empty($modele)) {
1062  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1063  }
1064 
1065  return $result;
1066  }
1067 
1075  public function doScheduledJob()
1076  {
1077  global $conf, $langs;
1078 
1079  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1080 
1081  $error = 0;
1082  $this->output = '';
1083  $this->error = '';
1084 
1085  dol_syslog(__METHOD__, LOG_DEBUG);
1086 
1087  $now = dol_now();
1088 
1089  $this->db->begin();
1090 
1091  // ...
1092 
1093  $this->db->commit();
1094 
1095  return $error;
1096  }
1097 
1106  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1107  {
1108  $tables = array(
1109  'eventorganization_conferenceorboothattendee'
1110  );
1111 
1112  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1113  }
1114 }
1115 
1116 
1117 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1118 
1123 {
1124  // To complete with content of an object ConferenceOrBoothAttendeeLine
1125  // We should have a field rowid, fk_conferenceorboothattendee and position
1126 
1130  public $isextrafieldmanaged = 0;
1131 
1137  public function __construct(DoliDB $db)
1138  {
1139  $this->db = $db;
1140  }
1141 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9683
ConferenceOrBoothAttendee\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: conferenceorboothattendee.class.php:512
ConferenceOrBoothAttendee\update
update(User $user, $notrigger=false)
Update object into database.
Definition: conferenceorboothattendee.class.php:486
db
$conf db
API class for accounts.
Definition: inc.php:41
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
ConferenceOrBoothAttendee\info
info($id)
Load the info information in the object.
Definition: conferenceorboothattendee.class.php:939
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1217
Project
Class to manage projects.
Definition: project.class.php:35
ConferenceOrBoothAttendee\getLabelStatus
getLabelStatus($mode=0)
Return the label of the status.
Definition: conferenceorboothattendee.class.php:880
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
ConferenceOrBoothAttendeeLine
Class ConferenceOrBoothAttendeeLine.
Definition: conferenceorboothattendee.class.php:1122
ConferenceOrBoothAttendee\validate
validate($user, $notrigger=0)
Validate object.
Definition: conferenceorboothattendee.class.php:530
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:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9258
ConferenceOrBoothAttendee\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: conferenceorboothattendee.class.php:272
ref
$object ref
Definition: info.php:77
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)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
ConferenceOrBoothAttendee\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: conferenceorboothattendee.class.php:904
ConferenceOrBoothAttendee\replaceThirdparty
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Definition: conferenceorboothattendee.class.php:1106
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:44
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
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:3880
ConferenceOrBoothAttendee\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: conferenceorboothattendee.class.php:755
ConferenceOrBoothAttendee\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: conferenceorboothattendee.class.php:1040
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
CommonObject\commonReplaceThirdparty
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Definition: commonobject.class.php:8347
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
ConferenceOrBoothAttendee\create
create(User $user, $notrigger=false)
Create object into database.
Definition: conferenceorboothattendee.class.php:244
ConferenceOrBoothAttendeeLine\__construct
__construct(DoliDB $db)
Constructor.
Definition: conferenceorboothattendee.class.php:1137
ConferenceOrBoothAttendee\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: conferenceorboothattendee.class.php:1075
ConferenceOrBoothAttendee\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: conferenceorboothattendee.class.php:969
ConferenceOrBoothAttendee\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: conferenceorboothattendee.class.php:704
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
ConferenceOrBoothAttendee\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: conferenceorboothattendee.class.php:389
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
ConferenceOrBoothAttendee\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: conferenceorboothattendee.class.php:979
User
Class to manage Dolibarr users.
Definition: user.class.php:44
ConferenceOrBoothAttendee\fetch_projet
fetch_projet()
Load the project with id $this->fk_project into this->project.
Definition: conferenceorboothattendee.class.php:653
ConferenceOrBoothAttendee\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: conferenceorboothattendee.class.php:728
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
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:4211
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9622
ConferenceOrBoothAttendee\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: conferenceorboothattendee.class.php:891
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
ConferenceOrBoothAttendee\__construct
__construct(DoliDB $db)
Constructor.
Definition: conferenceorboothattendee.class.php:190
ConferenceOrBoothAttendee
Class for ConferenceOrBoothAttendee.
Definition: conferenceorboothattendee.class.php:33
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:8987
ConferenceOrBoothAttendee\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: conferenceorboothattendee.class.php:375
CommonObject\$fk_projet
$fk_projet
Definition: commonobject.class.php:193
ConferenceOrBoothAttendee\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: conferenceorboothattendee.class.php:680
ConferenceOrBoothAttendee\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: conferenceorboothattendee.class.php:409