dolibarr  20.0.0-beta
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  * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 // Put here all includes required by your class file
28 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31 
36 {
40  public $module = 'eventorganization';
41 
45  public $element = 'conferenceorboothattendee';
46 
50  public $table_element = 'eventorganization_conferenceorboothattendee';
51 
55  public $picto = 'contact';
56 
57  public $paid = 0;
58 
59  const STATUS_DRAFT = 0;
60  const STATUS_VALIDATED = 1;
61  const STATUS_CANCELED = 9;
62 
63 
90  // BEGIN MODULEBUILDER PROPERTIES
94  public $fields = array(
95  'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
96  'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 2, 'index' => 1, 'comment' => "Reference of object"),
97  //'fk_actioncomm' => array('type'=>'integer:ActionComm:comm/action/class/actioncomm.class.php:1', 'label'=>'ConferenceOrBooth', 'enabled'=>'1', 'position'=>15, 'notnull'=>0, 'visible'=>0, 'index'=>1, 'picto'=>'agenda'),
98  'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'position' => 20, 'notnull' => 1, 'visible' => 0, 'index' => 1, 'picto' => 'project', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
99  'email' => array('type' => 'mail', 'label' => 'EmailAttendee', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'index' => 1, 'autofocusoncreate' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax150'),
100  'firstname' => array('type' => 'varchar(100)', 'label' => 'Firstname', 'enabled' => 1, 'position' => 31, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax125'),
101  'lastname' => array('type' => 'varchar(100)', 'label' => 'Lastname', 'enabled' => 1, 'position' => 32, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax125'),
102  'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'enabled' => 'isModEnabled("societe")', 'position' => 40, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'help' => "OrganizationEventLinkToThirdParty", 'picto' => 'company', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
103  'email_company' => array('type' => 'mail', 'label' => 'EmailCompany', 'enabled' => 1, 'position' => 41, 'notnull' => 0, 'visible' => -2, 'searchall' => 1),
104  'date_subscription' => array('type' => 'datetime', 'label' => 'DateOfRegistration', 'enabled' => 1, 'position' => 56, 'notnull' => 1, 'visible' => 1, 'showoncombobox' => 1,),
105  'fk_invoice' => array('type' => 'integer:Facture:compta/facture/class/facture.class.php', 'label' => 'Invoice', 'enabled' => 'isModEnabled("invoice")', 'position' => 57, 'notnull' => 0, 'visible' => 1, 'index' => 0, 'picto' => 'bill', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
106  'amount' => array('type' => 'price', 'label' => 'AmountPaid', 'enabled' => 1, 'position' => 57, 'notnull' => 0, 'visible' => 1, 'default' => 'null', 'isameasure' => 1, 'help' => "AmountOfRegistrationPaid",),
107  'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 3,),
108  'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 3,),
109  'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'css' => 'nowraponall'),
110  'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
111  'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => -1, 'visible' => -2),
112  'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
113  'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => 0,),
114  'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
115  'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
116  'ip' => array('type' => 'varchar(250)', 'label' => 'IPAddress', 'enabled' => 1, 'position' => 900, 'notnull' => -1, 'visible' => -2,),
117  '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'),),
118  );
119  public $rowid;
120  public $ref;
121  public $fk_actioncomm;
122  public $fk_project;
123  public $email;
124  public $firstname;
125  public $lastname;
126  public $fk_soc;
127  public $email_company;
128  public $date_subscription;
129  public $fk_invoice;
130  public $amount;
131  public $note_public;
132  public $note_private;
133  public $date_creation;
134  public $fk_user_creat;
135  public $fk_user_modif;
136  public $last_main_doc;
137  public $import_key;
138  public $model_pdf;
139  public $status;
140  // END MODULEBUILDER PROPERTIES
141 
142 
143  // If this object has a subtable with lines
144 
145  // /**
146  // * @var string Name of subtable line
147  // */
148  // public $table_element_line = 'eventorganization_conferenceorboothattendeeline';
149 
150  // /**
151  // * @var string Field with ID of parent key if this object has a parent
152  // */
153  // public $fk_element = 'fk_conferenceorboothattendee';
154 
155  // /**
156  // * @var string Name of subtable class that manage subtable lines
157  // */
158  // public $class_element_line = 'ConferenceOrBoothAttendeeline';
159 
160  // /**
161  // * @var array List of child tables. To test if we can delete object.
162  // */
163  // protected $childtables = array();
164 
165  // /**
166  // * @var array List of child tables. To know object to delete on cascade.
167  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
168  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
169  // */
170  // protected $childtablesoncascade = array('eventorganization_conferenceorboothattendeedet');
171 
172  // /**
173  // * @var ConferenceOrBoothAttendeeLine[] Array of subtable lines
174  // */
175  // public $lines = array();
176 
177 
178 
184  public function __construct(DoliDB $db)
185  {
186  global $conf, $langs;
187 
188  $this->db = $db;
189 
190  $this->ismultientitymanaged = 'fk_project@projet';
191  $this->isextrafieldmanaged = 1;
192 
193  if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
194  $this->fields['rowid']['visible'] = 0;
195  }
196  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
197  $this->fields['entity']['enabled'] = 0;
198  }
199 
200  if (getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_CAT')) {
201  $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.')';
202  }
203  if (isset($conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE)
204  && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== ''
205  && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== '-1') {
206  $this->fields['fk_soc']['type'] .= ' AND client = '.((int) getDolGlobalInt('EVENTORGANIZATION_FILTERATTENDEES_TYPE', 0));
207  }
208 
209  // Example to show how to set values of fields definition dynamically
210  /*if ($user->rights->eventorganization->conferenceorboothattendee->read) {
211  $this->fields['myfield']['visible'] = 1;
212  $this->fields['myfield']['noteditable'] = 0;
213  }*/
214 
215  // Unset fields that are disabled
216  foreach ($this->fields as $key => $val) {
217  if (isset($val['enabled']) && empty($val['enabled'])) {
218  unset($this->fields[$key]);
219  }
220  }
221 
222  // Translate some data of arrayofkeyval
223  if (is_object($langs)) {
224  foreach ($this->fields as $key => $val) {
225  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
226  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
227  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
228  }
229  }
230  }
231  }
232  }
233 
241  public function create(User $user, $notrigger = 0)
242  {
243  global $langs;
244 
245  if (!isValidEmail($this->email)) {
246  $langs->load("errors");
247  $this->errors[] = $langs->trans("ErrorBadEMail", $this->email);
248  return -1;
249  }
250 
251  $result = $this->createCommon($user, $notrigger);
252  if ($result > 0) {
253  $result = $this->fetch($result);
254  if ($result > 0) {
255  $this->ref = (string) $this->id;
256  $result = $this->update($user);
257  }
258  }
259  return $result;
260  }
261 
269  public function createFromClone(User $user, $fromid)
270  {
271  global $langs, $extrafields;
272  $error = 0;
273 
274  dol_syslog(__METHOD__, LOG_DEBUG);
275 
276  $object = new self($this->db);
277 
278  $this->db->begin();
279 
280  // Load source object
281  $result = $object->fetchCommon($fromid);
282  if ($result > 0 && !empty($object->table_element_line)) {
283  $object->fetchLines();
284  }
285 
286  // get lines so they will be clone
287  //foreach($this->lines as $line)
288  // $line->fetch_optionals();
289 
290  // Reset some properties
291  unset($object->id);
292  unset($object->fk_user_creat);
293  unset($object->import_key);
294 
295  // Clear fields
296  if (property_exists($object, 'ref')) {
297  $object->ref = empty($this->fields['ref']['default']) ? "(PROV)" : $this->fields['ref']['default'];
298  }
299  if (property_exists($object, 'label')) {
300  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
301  }
302  if (property_exists($object, 'status')) {
303  $object->status = self::STATUS_DRAFT;
304  }
305  if (property_exists($object, 'date_creation')) {
306  $object->date_creation = dol_now();
307  }
308  if (property_exists($object, 'date_modification')) {
309  $object->date_modification = null;
310  }
311  // ...
312  // Clear extrafields that are unique
313  if (is_array($object->array_options) && count($object->array_options) > 0) {
314  $extrafields->fetch_name_optionals_label($this->table_element);
315  foreach ($object->array_options as $key => $option) {
316  $shortkey = preg_replace('/options_/', '', $key);
317  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
318  //var_dump($key);
319  //var_dump($clonedObj->array_options[$key]); exit;
320  unset($object->array_options[$key]);
321  }
322  }
323  }
324 
325  // Create clone
326  $object->context['createfromclone'] = 'createfromclone';
327  $result = $object->createCommon($user);
328  if ($result < 0) {
329  $error++;
331  } else {
332  $object->ref = (string) $object->id;
333  $result = $object->update($user);
334  }
335 
336  if (!$error) {
337  // copy internal contacts
338  if ($this->copy_linked_contact($object, 'internal') < 0) {
339  $error++;
340  }
341  }
342 
343  if (!$error) {
344  // copy external contacts if same company
345  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
346  if ($this->copy_linked_contact($object, 'external') < 0) {
347  $error++;
348  }
349  }
350  }
351 
352  unset($object->context['createfromclone']);
353 
354  // End
355  if (!$error) {
356  $this->db->commit();
357  return $object;
358  } else {
359  $this->db->rollback();
360  return -1;
361  }
362  }
363 
371  public function fetch($id, $ref = null)
372  {
373  $result = $this->fetchCommon($id, $ref);
374  if ($result > 0 && !empty($this->table_element_line)) {
375  $this->fetchLines();
376  }
377  return $result;
378  }
379 
385  public function fetchLines()
386  {
387  $this->lines = array();
388 
389  $result = $this->fetchLinesCommon();
390  return $result;
391  }
392 
393 
406  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
407  {
408  dol_syslog(__METHOD__, LOG_DEBUG);
409 
410  $records = array();
411 
412  $sql = 'SELECT ';
413  $sql .= $this->getFieldList('t');
414  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
415  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm as a on a.id = t.fk_actioncomm";
416  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
417  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
418  } else {
419  $sql .= ' WHERE 1 = 1';
420  }
421 
422  // Manage filter
423  $errormessage = '';
424  $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
425  if ($errormessage) {
426  $this->errors[] = $errormessage;
427  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
428  return -1;
429  }
430 
431  if (!empty($sortfield)) {
432  $sql .= $this->db->order($sortfield, $sortorder);
433  }
434  if (!empty($limit)) {
435  $sql .= $this->db->plimit($limit, $offset);
436  }
437 
438  $resql = $this->db->query($sql);
439  if ($resql) {
440  $num = $this->db->num_rows($resql);
441  $i = 0;
442  while ($i < ($limit ? min($limit, $num) : $num)) {
443  $obj = $this->db->fetch_object($resql);
444 
445  $record = new self($this->db);
446  $record->setVarsFromFetchObj($obj);
447 
448  $records[$record->id] = $record;
449 
450  $i++;
451  }
452  $this->db->free($resql);
453 
454  return $records;
455  } else {
456  $this->errors[] = 'Error '.$this->db->lasterror();
457  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
458 
459  return -1;
460  }
461  }
462 
470  public function update(User $user, $notrigger = 0)
471  {
472  return $this->updateCommon($user, $notrigger);
473  }
474 
482  public function delete(User $user, $notrigger = 0)
483  {
484  return $this->deleteCommon($user, $notrigger);
485  //return $this->deleteCommon($user, $notrigger, 1);
486  }
487 
496  public function deleteLine(User $user, $idline, $notrigger = 0)
497  {
498  if ($this->status < 0) {
499  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
500  return -2;
501  }
502 
503  return $this->deleteLineCommon($user, $idline, $notrigger);
504  }
505 
506 
514  public function validate($user, $notrigger = 0)
515  {
516  global $conf;
517 
518  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
519 
520  $error = 0;
521 
522  // Protection
523  if ($this->status == self::STATUS_VALIDATED) {
524  dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
525  return 0;
526  }
527 
528  $now = dol_now();
529 
530  $this->db->begin();
531 
532  // Define new ref
533  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
534  $num = $this->getNextNumRef();
535  } else {
536  $num = $this->ref;
537  }
538  $this->newref = $num;
539 
540  if (!empty($num)) {
541  // Validate
542  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
543  $sql .= " SET ref = '".$this->db->escape($num)."',";
544  $sql .= " status = ".self::STATUS_VALIDATED;
545  if (!empty($this->fields['date_validation'])) {
546  $sql .= ", date_validation = '".$this->db->idate($now)."'";
547  }
548  if (!empty($this->fields['fk_user_valid'])) {
549  $sql .= ", fk_user_valid = ".$user->id;
550  }
551  $sql .= " WHERE rowid = ".((int) $this->id);
552 
553  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
554  $resql = $this->db->query($sql);
555  if (!$resql) {
556  dol_print_error($this->db);
557  $this->error = $this->db->lasterror();
558  $error++;
559  }
560 
561  if (!$error && !$notrigger) {
562  // Call trigger
563  $result = $this->call_trigger('CONFERENCEORBOOTHATTENDEE_VALIDATE', $user);
564  if ($result < 0) {
565  $error++;
566  }
567  // End call triggers
568  }
569  }
570 
571  if (!$error) {
572  $this->oldref = $this->ref;
573 
574  // Rename directory if dir was a temporary ref
575  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
576  // Now we rename also files into index
577  $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)."'";
578  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
579  $resql = $this->db->query($sql);
580  if (!$resql) {
581  $error++;
582  $this->error = $this->db->lasterror();
583  }
584  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'conferenceorboothattendee/".$this->db->escape($this->newref)."'";
585  $sql .= " WHERE filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
586  $resql = $this->db->query($sql);
587  if (!$resql) {
588  $error++;
589  $this->error = $this->db->lasterror();
590  }
591 
592  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
593  $oldref = dol_sanitizeFileName($this->ref);
594  $newref = dol_sanitizeFileName($num);
595  $dirsource = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$oldref;
596  $dirdest = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref;
597  if (!$error && file_exists($dirsource)) {
598  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
599 
600  if (@rename($dirsource, $dirdest)) {
601  dol_syslog("Rename ok");
602  // Rename docs starting with $oldref with $newref
603  $listoffiles = dol_dir_list($conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
604  foreach ($listoffiles as $fileentry) {
605  $dirsource = $fileentry['name'];
606  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
607  $dirsource = $fileentry['path'].'/'.$dirsource;
608  $dirdest = $fileentry['path'].'/'.$dirdest;
609  @rename($dirsource, $dirdest);
610  }
611  }
612  }
613  }
614  }
615 
616  // Set new ref and current status
617  if (!$error) {
618  $this->ref = $num;
619  $this->status = self::STATUS_VALIDATED;
620  }
621 
622  if (!$error) {
623  $this->db->commit();
624  return 1;
625  } else {
626  $this->db->rollback();
627  return -1;
628  }
629  }
630 
631  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
637  public function fetch_projet()
638  {
639  // phpcs:enable
640  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
641 
642  if (empty($this->fk_project) && !empty($this->fk_projet)) {
643  $this->fk_project = $this->fk_projet; // For backward compatibility
644  }
645  if (empty($this->fk_project)) {
646  return 0;
647  }
648 
649  $project = new Project($this->db);
650  $result = $project->fetch($this->fk_project);
651 
652  $this->projet = $project; // deprecated
653  $this->project = $project;
654  return $result;
655  }
656 
664  public function setDraft($user, $notrigger = 0)
665  {
666  // Protection
667  if ($this->status <= self::STATUS_DRAFT) {
668  return 0;
669  }
670 
671  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTHATTENDEE_UNVALIDATE');
672  }
673 
681  public function cancel($user, $notrigger = 0)
682  {
683  // Protection
684  if ($this->status != self::STATUS_VALIDATED) {
685  return 0;
686  }
687 
688  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_CANCEL');
689  }
690 
698  public function reopen($user, $notrigger = 0)
699  {
700  // Protection
701  if ($this->status != self::STATUS_CANCELED) {
702  return 0;
703  }
704 
705  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_REOPEN');
706  }
707 
718  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
719  {
720  global $conf, $langs, $hookmanager;
721 
722  if (!empty($conf->dol_no_mouse_hover)) {
723  $notooltip = 1; // Force disable tooltips
724  }
725 
726  $result = '';
727 
728  $label = img_picto('', $this->picto).' <u>'.$langs->trans("ConferenceOrBoothAttendee").'</u>';
729  if (isset($this->status)) {
730  $label .= ' '.$this->getLibStatut(5);
731  }
732  $label .= '<br>';
733  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
734  $label .= '<br><b>'.$langs->trans('DateOfRegistration').':</b> '.dol_print_date($this->date_subscription, 'dayhour');
735  $label .= '<br><b>'.$langs->trans('AmountPaid').':</b> '.$this->amount;
736 
737  $url = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.$this->id;
738 
739  if ($option != 'nolink') {
740  // Add param to save lastsearch_values or not
741  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
742  if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
743  $add_save_lastsearch_values = 1;
744  }
745  if ($add_save_lastsearch_values) {
746  $url .= '&save_lastsearch_values=1';
747  }
748 
749  if ($option == 'conforboothid') {
750  $url .= '&conforboothid='.((int) $this->fk_actioncomm);
751  }
752 
753  if ($option == 'projectid') {
754  $url .= '&fk_project='.((int) $this->fk_project).'&withproject=1';
755  }
756 
757  if ($option == 'conforboothidproject') {
758  $url .= '&conforboothid='.((int) $this->fk_actioncomm).'&withproject=1';
759  }
760  }
761 
762  $linkclose = '';
763  if (empty($notooltip)) {
764  if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
765  $label = $langs->trans("ShowConferenceOrBoothAttendee");
766  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
767  }
768  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
769  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
770  } else {
771  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
772  }
773 
774  if ($option == 'nolink') {
775  $linkstart = '<span';
776  } else {
777  $linkstart = '<a href="'.$url.'"';
778  }
779  $linkstart .= $linkclose.'>';
780  if ($option == 'nolink') {
781  $linkend = '</span>';
782  } else {
783  $linkend = '</a>';
784  }
785 
786  $result .= $linkstart;
787 
788  if (empty($this->showphoto_on_popup)) {
789  if ($withpicto) {
790  $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);
791  }
792  } else {
793  if ($withpicto) {
794  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
795 
796  list($class, $module) = explode('@', $this->picto);
797  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
798  $filearray = dol_dir_list($upload_dir, "files");
799  $filename = $filearray[0]['name'];
800  if (!empty($filename)) {
801  $pospoint = strpos($filearray[0]['name'], '.');
802 
803  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
804  if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
805  $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>';
806  } else {
807  $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>';
808  }
809 
810  $result .= '</div>';
811  } else {
812  $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);
813  }
814  }
815  }
816 
817  if ($withpicto != 2) {
818  $result .= $this->ref;
819  }
820 
821  $result .= $linkend;
822  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
823 
824  global $action, $hookmanager;
825  $hookmanager->initHooks(array('conferenceorboothattendeedao'));
826  $parameters = array('id' => $this->id, 'getnomurl' => &$result);
827  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
828  if ($reshook > 0) {
829  $result = $hookmanager->resPrint;
830  } else {
831  $result .= $hookmanager->resPrint;
832  }
833 
834  return $result;
835  }
836 
843  public function getLabelStatus($mode = 0)
844  {
845  return $this->LibStatut($this->status, $mode);
846  }
847 
854  public function getLibStatut($mode = 0)
855  {
856  return $this->LibStatut($this->status, $mode);
857  }
858 
859  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
867  public function LibStatut($status, $mode = 0)
868  {
869  // phpcs:enable
870  global $langs;
871 
872  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
873  //$langs->load("eventorganization@eventorganization");
874  $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
875  $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
876  $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
877  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
878  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
879  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
880  }
881 
882  $statusType = 'status'.$status;
883  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
884  if ($status == self::STATUS_CANCELED) {
885  $statusType = 'status6';
886  }
887 
888  if ($status == self::STATUS_VALIDATED && $this->date_subscription && $this->amount) {
889  $statusType = 'status4';
890  $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated').' - '.$langs->trans("Paid");
891  }
892 
893  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
894  }
895 
902  public function info($id)
903  {
904  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
905  $sql .= ' fk_user_creat, fk_user_modif';
906  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
907  $sql .= ' WHERE t.rowid = '.((int) $id);
908  $result = $this->db->query($sql);
909  if ($result) {
910  if ($this->db->num_rows($result)) {
911  $obj = $this->db->fetch_object($result);
912 
913  $this->id = $obj->rowid;
914 
915  $this->user_creation_id = $obj->fk_user_creat;
916  $this->user_modification_id = $obj->fk_user_modif;
917  $this->date_creation = $this->db->jdate($obj->datec);
918  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
919  }
920 
921  $this->db->free($result);
922  } else {
923  dol_print_error($this->db);
924  }
925  }
926 
933  public function initAsSpecimen()
934  {
935  return $this->initAsSpecimenCommon();
936  }
937 
943  public function getNextNumRef()
944  {
945  global $langs, $conf;
946  $langs->load("eventorganization@eventorganization");
947 
948  if (!getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
949  $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON = 'mod_conferenceorboothattendee_standard';
950  }
951 
952  if (getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
953  $mybool = false;
954 
955  $file = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON') . ".php";
956  $classname = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON');
957 
958  // Include file with class
959  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
960  foreach ($dirmodels as $reldir) {
961  $dir = dol_buildpath($reldir."core/modules/eventorganization/");
962 
963  // Load file with numbering class (if found)
964  $mybool = ((bool) @include_once $dir.$file) || $mybool;
965  }
966 
967  if ($mybool === false) {
968  dol_print_error(null, "Failed to include file ".$file);
969  return '';
970  }
971 
972  if (class_exists($classname)) {
973  $obj = new $classname();
974  $numref = $obj->getNextValue($this);
975 
976  if ($numref != '' && $numref != '-1') {
977  return $numref;
978  } else {
979  $this->error = $obj->error;
980  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
981  return "";
982  }
983  } else {
984  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
985  return "";
986  }
987  } else {
988  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
989  return "";
990  }
991  }
992 
1004  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1005  {
1006  global $conf, $langs;
1007 
1008  $result = 0;
1009  $includedocgeneration = 0;
1010 
1011  $langs->load("eventorganization@eventorganization");
1012 
1013  if (!dol_strlen($modele)) {
1014  $modele = 'standard_conferenceorboothattendee';
1015 
1016  if (!empty($this->model_pdf)) {
1017  $modele = $this->model_pdf;
1018  } elseif (getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF')) {
1019  $modele = getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF');
1020  }
1021  }
1022 
1023  $modelpath = "core/modules/eventorganization/doc/";
1024 
1025  if ($includedocgeneration && !empty($modele)) {
1026  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1027  }
1028 
1029  return $result;
1030  }
1031 
1039  public function doScheduledJob()
1040  {
1041  global $conf, $langs;
1042 
1043  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1044 
1045  $error = 0;
1046  $this->output = '';
1047  $this->error = '';
1048 
1049  dol_syslog(__METHOD__, LOG_DEBUG);
1050 
1051  $now = dol_now();
1052 
1053  $this->db->begin();
1054 
1055  // ...
1056 
1057  $this->db->commit();
1058 
1059  return $error;
1060  }
1061 
1070  public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1071  {
1072  $tables = array(
1073  'eventorganization_conferenceorboothattendee'
1074  );
1075 
1076  return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1077  }
1078 
1088  public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
1089  {
1090  $lastname = $this->lastname;
1091  $firstname = $this->firstname;
1092  if (empty($lastname)) {
1093  $lastname = (isset($this->lastname) ? $this->lastname : (isset($this->name) ? $this->name : (isset($this->nom) ? $this->nom : (isset($this->societe) ? $this->societe : (isset($this->company) ? $this->company : '')))));
1094  }
1095 
1096  $ret = '';
1097 
1098  $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
1099 
1100  return dol_trunc($ret, $maxlen);
1101  }
1102 }
1103 
1104 
1105 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1106 
1111 {
1112  // To complete with content of an object ConferenceOrBoothAttendeeLine
1113  // We should have a field rowid, fk_conferenceorboothattendee and position
1114 
1120  public function __construct(DoliDB $db)
1121  {
1122  $this->db = $db;
1123 
1124  $this->isextrafieldmanaged = 0;
1125  }
1126 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition: security.php:607
$object ref
Definition: info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in 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 for ConferenceOrBoothAttendee.
cancel($user, $notrigger=0)
Set cancel status.
createFromClone(User $user, $fromid)
Clone an object into another one.
getLibStatut($mode=0)
Return the label of the status.
info($id)
Load the info information in the object.
fetch($id, $ref=null)
Load object in memory from the database.
getLabelStatus($mode=0)
Return the label of the status.
create(User $user, $notrigger=0)
Create object into database.
fetchLines()
Load object lines in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
LibStatut($status, $mode=0)
Return the status.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
fetch_projet()
Load the project with id $this->fk_project into this->project.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name ('name+' '+lastname)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
update(User $user, $notrigger=0)
Update object into database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
reopen($user, $notrigger=0)
Set back to validated status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
setDraft($user, $notrigger=0)
Set draft status.
validate($user, $notrigger=0)
Validate object.
Class ConferenceOrBoothAttendeeLine.
Class to manage Dolibarr database access.
Class to manage projects.
Class to manage Dolibarr users.
Definition: user.class.php:50
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('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') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_dir_list($utf8_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:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
td amount
Definition: global.inc.php:554
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:126