dolibarr 19.0.3
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
26require_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 = 'fk_project@projet';
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'=>15, 'notnull'=>0, 'visible'=>0, 'index'=>1, 'picto'=>'agenda'),
107 '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'),
108 'email' => array('type'=>'mail', 'label'=>'EmailAttendee', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'autofocusoncreate'=>1, 'searchall'=>1, 'csslist'=>'tdoverflowmax150'),
109 'firstname' => array('type'=>'varchar(100)', 'label'=>'Firstname', 'enabled'=>'1', 'position'=>31, 'notnull'=>0, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'csslist'=>'tdoverflowmax125'),
110 'lastname' => array('type'=>'varchar(100)', 'label'=>'Lastname', 'enabled'=>'1', 'position'=>32, 'notnull'=>0, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'csslist'=>'tdoverflowmax125'),
111 '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'),
112 'email_company' => array('type'=>'mail', 'label'=>'EmailCompany', 'enabled'=>'1', 'position'=>41, 'notnull'=>0, 'visible'=>-2, 'searchall'=>1),
113 'date_subscription' => array('type'=>'datetime', 'label'=>'DateOfRegistration', 'enabled'=>'1', 'position'=>56, 'notnull'=>1, 'visible'=>1, 'showoncombobox'=>'1',),
114 'fk_invoice' => array('type'=>'integer:Facture:compta/facture/class/facture.class.php', 'label'=>'Invoice', 'enabled'=>'isModEnabled("facture")', 'position'=>57, 'notnull'=>0, 'visible'=>1, 'index'=>0, 'picto'=>'bill', 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150'),
115 'amount' => array('type'=>'price', 'label'=>'AmountPaid', 'enabled'=>'1', 'position'=>57, 'notnull'=>0, 'visible'=>1, 'default'=>'null', 'isameasure'=>'1', 'help'=>"AmountOfRegistrationPaid",),
116 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>3,),
117 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>3,),
118 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2, 'css'=>'nowraponall'),
119 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
120 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>-1, 'visible'=>-2),
121 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
122 'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,),
123 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
124 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
125 'ip' => array('type'=>'varchar(250)', 'label'=>'IPAddress', 'enabled'=>'1', 'position'=>900, 'notnull'=>-1, 'visible'=>-2,),
126 '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'),),
127 );
128 public $rowid;
129 public $ref;
130 public $fk_actioncomm;
131 public $fk_project;
132 public $email;
133 public $firstname;
134 public $lastname;
135 public $fk_soc;
136 public $email_company;
137 public $date_subscription;
138 public $fk_invoice;
139 public $amount;
140 public $note_public;
141 public $note_private;
142 public $date_creation;
143 public $tms;
144 public $fk_user_creat;
145 public $fk_user_modif;
146 public $last_main_doc;
147 public $import_key;
148 public $model_pdf;
149 public $status;
150 // END MODULEBUILDER PROPERTIES
151
152
153 // If this object has a subtable with lines
154
155 // /**
156 // * @var string Name of subtable line
157 // */
158 // public $table_element_line = 'eventorganization_conferenceorboothattendeeline';
159
160 // /**
161 // * @var string Field with ID of parent key if this object has a parent
162 // */
163 // public $fk_element = 'fk_conferenceorboothattendee';
164
165 // /**
166 // * @var string Name of subtable class that manage subtable lines
167 // */
168 // public $class_element_line = 'ConferenceOrBoothAttendeeline';
169
170 // /**
171 // * @var array List of child tables. To test if we can delete object.
172 // */
173 // protected $childtables = array();
174
175 // /**
176 // * @var array List of child tables. To know object to delete on cascade.
177 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
178 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
179 // */
180 // protected $childtablesoncascade = array('eventorganization_conferenceorboothattendeedet');
181
182 // /**
183 // * @var ConferenceOrBoothAttendeeLine[] Array of subtable lines
184 // */
185 // public $lines = array();
186
187
188
194 public function __construct(DoliDB $db)
195 {
196 global $conf, $langs;
197
198 $this->db = $db;
199
200 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
201 $this->fields['rowid']['visible'] = 0;
202 }
203 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
204 $this->fields['entity']['enabled'] = 0;
205 }
206
207 if (getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_CAT')) {
208 $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.')';
209 }
210 if (isset($conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE)
211 && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== ''
212 && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== '-1') {
213 $this->fields['fk_soc']['type'] .= ' AND client = '.(int) $conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE;
214 }
215
216 // Example to show how to set values of fields definition dynamically
217 /*if ($user->rights->eventorganization->conferenceorboothattendee->read) {
218 $this->fields['myfield']['visible'] = 1;
219 $this->fields['myfield']['noteditable'] = 0;
220 }*/
221
222 // Unset fields that are disabled
223 foreach ($this->fields as $key => $val) {
224 if (isset($val['enabled']) && empty($val['enabled'])) {
225 unset($this->fields[$key]);
226 }
227 }
228
229 // Translate some data of arrayofkeyval
230 if (is_object($langs)) {
231 foreach ($this->fields as $key => $val) {
232 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
233 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
234 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
235 }
236 }
237 }
238 }
239 }
240
248 public function create(User $user, $notrigger = false)
249 {
250 global $langs;
251
252 if (!isValidEMail($this->email)) {
253 $langs->load("errors");
254 $this->errors[] = $langs->trans("ErrorBadEMail", $this->email);
255 return -1;
256 }
257
258 $result = $this->createCommon($user, $notrigger);
259 if ($result > 0) {
260 $result = $this->fetch($result);
261 if ($result > 0) {
262 $this->ref = $this->id;
263 $result = $this->update($user);
264 }
265 }
266 return $result;
267 }
268
276 public function createFromClone(User $user, $fromid)
277 {
278 global $langs, $extrafields;
279 $error = 0;
280
281 dol_syslog(__METHOD__, LOG_DEBUG);
282
283 $object = new self($this->db);
284
285 $this->db->begin();
286
287 // Load source object
288 $result = $object->fetchCommon($fromid);
289 if ($result > 0 && !empty($object->table_element_line)) {
290 $object->fetchLines();
291 }
292
293 // get lines so they will be clone
294 //foreach($this->lines as $line)
295 // $line->fetch_optionals();
296
297 // Reset some properties
298 unset($object->id);
299 unset($object->fk_user_creat);
300 unset($object->import_key);
301
302 // Clear fields
303 if (property_exists($object, 'ref')) {
304 $object->ref = empty($this->fields['ref']['default']) ? "(PROV)" : $this->fields['ref']['default'];
305 }
306 if (property_exists($object, 'label')) {
307 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
308 }
309 if (property_exists($object, 'status')) {
310 $object->status = self::STATUS_DRAFT;
311 }
312 if (property_exists($object, 'date_creation')) {
313 $object->date_creation = dol_now();
314 }
315 if (property_exists($object, 'date_modification')) {
316 $object->date_modification = null;
317 }
318 // ...
319 // Clear extrafields that are unique
320 if (is_array($object->array_options) && count($object->array_options) > 0) {
321 $extrafields->fetch_name_optionals_label($this->table_element);
322 foreach ($object->array_options as $key => $option) {
323 $shortkey = preg_replace('/options_/', '', $key);
324 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
325 //var_dump($key);
326 //var_dump($clonedObj->array_options[$key]); exit;
327 unset($object->array_options[$key]);
328 }
329 }
330 }
331
332 // Create clone
333 $object->context['createfromclone'] = 'createfromclone';
334 $result = $object->createCommon($user);
335 if ($result < 0) {
336 $error++;
337 $this->error = $object->error;
338 $this->errors = $object->errors;
339 } else {
340 $object->ref = $object->id;
341 $result = $object->update($user);
342 }
343
344 if (!$error) {
345 // copy internal contacts
346 if ($this->copy_linked_contact($object, 'internal') < 0) {
347 $error++;
348 }
349 }
350
351 if (!$error) {
352 // copy external contacts if same company
353 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
354 if ($this->copy_linked_contact($object, 'external') < 0) {
355 $error++;
356 }
357 }
358 }
359
360 unset($object->context['createfromclone']);
361
362 // End
363 if (!$error) {
364 $this->db->commit();
365 return $object;
366 } else {
367 $this->db->rollback();
368 return -1;
369 }
370 }
371
379 public function fetch($id, $ref = null)
380 {
381 $result = $this->fetchCommon($id, $ref);
382 if ($result > 0 && !empty($this->table_element_line)) {
383 $this->fetchLines();
384 }
385 return $result;
386 }
387
393 public function fetchLines()
394 {
395 $this->lines = array();
396
397 $result = $this->fetchLinesCommon();
398 return $result;
399 }
400
401
413 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
414 {
415 global $conf;
416
417 dol_syslog(__METHOD__, LOG_DEBUG);
418
419 $records = array();
420
421 $sql = 'SELECT ';
422 $sql .= $this->getFieldList('t');
423 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
424 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm as a on a.id = t.fk_actioncomm";
425 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
426 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
427 } else {
428 $sql .= ' WHERE 1 = 1';
429 }
430 // Manage filter
431 $sqlwhere = array();
432 if (count($filter) > 0) {
433 foreach ($filter as $key => $value) {
434 if ($key == 't.rowid' || $key == 't.fk_soc' || $key == 't.fk_project' || $key == 't.fk_actioncomm') {
435 $sqlwhere[] = $key.'='.((int) $value);
436 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
437 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
438 } elseif ($key == 'customsql') {
439 $sqlwhere[] = $value;
440 } elseif (strpos($value, '%') === false) {
441 $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
442 } else {
443 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
444 }
445 }
446 }
447 if (count($sqlwhere) > 0) {
448 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
449 }
450
451 if (!empty($sortfield)) {
452 $sql .= $this->db->order($sortfield, $sortorder);
453 }
454 if (!empty($limit)) {
455 $sql .= $this->db->plimit($limit, $offset);
456 }
457
458 $resql = $this->db->query($sql);
459 if ($resql) {
460 $num = $this->db->num_rows($resql);
461 $i = 0;
462 while ($i < ($limit ? min($limit, $num) : $num)) {
463 $obj = $this->db->fetch_object($resql);
464
465 $record = new self($this->db);
466 $record->setVarsFromFetchObj($obj);
467
468 $records[$record->id] = $record;
469
470 $i++;
471 }
472 $this->db->free($resql);
473
474 return $records;
475 } else {
476 $this->errors[] = 'Error '.$this->db->lasterror();
477 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
478
479 return -1;
480 }
481 }
482
490 public function update(User $user, $notrigger = false)
491 {
492 return $this->updateCommon($user, $notrigger);
493 }
494
502 public function delete(User $user, $notrigger = false)
503 {
504 return $this->deleteCommon($user, $notrigger);
505 //return $this->deleteCommon($user, $notrigger, 1);
506 }
507
516 public function deleteLine(User $user, $idline, $notrigger = false)
517 {
518 if ($this->status < 0) {
519 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
520 return -2;
521 }
522
523 return $this->deleteLineCommon($user, $idline, $notrigger);
524 }
525
526
534 public function validate($user, $notrigger = 0)
535 {
536 global $conf, $langs;
537
538 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
539
540 $error = 0;
541
542 // Protection
543 if ($this->status == self::STATUS_VALIDATED) {
544 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
545 return 0;
546 }
547
548 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->conferenceorboothattendee->write))
549 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->conferenceorboothattendee->conferenceorboothattendee_advance->validate))))
550 {
551 $this->error='NotEnoughPermissions';
552 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
553 return -1;
554 }*/
555
556 $now = dol_now();
557
558 $this->db->begin();
559
560 // Define new ref
561 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
562 $num = $this->getNextNumRef();
563 } else {
564 $num = $this->ref;
565 }
566 $this->newref = $num;
567
568 if (!empty($num)) {
569 // Validate
570 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
571 $sql .= " SET ref = '".$this->db->escape($num)."',";
572 $sql .= " status = ".self::STATUS_VALIDATED;
573 if (!empty($this->fields['date_validation'])) {
574 $sql .= ", date_validation = '".$this->db->idate($now)."'";
575 }
576 if (!empty($this->fields['fk_user_valid'])) {
577 $sql .= ", fk_user_valid = ".$user->id;
578 }
579 $sql .= " WHERE rowid = ".((int) $this->id);
580
581 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
582 $resql = $this->db->query($sql);
583 if (!$resql) {
584 dol_print_error($this->db);
585 $this->error = $this->db->lasterror();
586 $error++;
587 }
588
589 if (!$error && !$notrigger) {
590 // Call trigger
591 $result = $this->call_trigger('CONFERENCEORBOOTHATTENDEE_VALIDATE', $user);
592 if ($result < 0) {
593 $error++;
594 }
595 // End call triggers
596 }
597 }
598
599 if (!$error) {
600 $this->oldref = $this->ref;
601
602 // Rename directory if dir was a temporary ref
603 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
604 // Now we rename also files into index
605 $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)."'";
606 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
607 $resql = $this->db->query($sql);
608 if (!$resql) {
609 $error++;
610 $this->error = $this->db->lasterror();
611 }
612 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'conferenceorboothattendee/".$this->db->escape($this->newref)."'";
613 $sql .= " WHERE filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
614 $resql = $this->db->query($sql);
615 if (!$resql) {
616 $error++;
617 $this->error = $this->db->lasterror();
618 }
619
620 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
621 $oldref = dol_sanitizeFileName($this->ref);
622 $newref = dol_sanitizeFileName($num);
623 $dirsource = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$oldref;
624 $dirdest = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref;
625 if (!$error && file_exists($dirsource)) {
626 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
627
628 if (@rename($dirsource, $dirdest)) {
629 dol_syslog("Rename ok");
630 // Rename docs starting with $oldref with $newref
631 $listoffiles = dol_dir_list($conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
632 foreach ($listoffiles as $fileentry) {
633 $dirsource = $fileentry['name'];
634 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
635 $dirsource = $fileentry['path'].'/'.$dirsource;
636 $dirdest = $fileentry['path'].'/'.$dirdest;
637 @rename($dirsource, $dirdest);
638 }
639 }
640 }
641 }
642 }
643
644 // Set new ref and current status
645 if (!$error) {
646 $this->ref = $num;
647 $this->status = self::STATUS_VALIDATED;
648 }
649
650 if (!$error) {
651 $this->db->commit();
652 return 1;
653 } else {
654 $this->db->rollback();
655 return -1;
656 }
657 }
658
659 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
665 public function fetch_projet()
666 {
667 // phpcs:enable
668 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
669
670 if (empty($this->fk_project) && !empty($this->fk_projet)) {
671 $this->fk_project = $this->fk_projet; // For backward compatibility
672 }
673 if (empty($this->fk_project)) {
674 return 0;
675 }
676
677 $project = new Project($this->db);
678 $result = $project->fetch($this->fk_project);
679
680 $this->projet = $project; // deprecated
681 $this->project = $project;
682 return $result;
683 }
684
692 public function setDraft($user, $notrigger = 0)
693 {
694 // Protection
695 if ($this->status <= self::STATUS_DRAFT) {
696 return 0;
697 }
698
699 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->write))
700 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->eventorganization_advance->validate))))
701 {
702 $this->error='Permission denied';
703 return -1;
704 }*/
705
706 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTHATTENDEE_UNVALIDATE');
707 }
708
716 public function cancel($user, $notrigger = 0)
717 {
718 // Protection
719 if ($this->status != self::STATUS_VALIDATED) {
720 return 0;
721 }
722
723 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->write))
724 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->eventorganization_advance->validate))))
725 {
726 $this->error='Permission denied';
727 return -1;
728 }*/
729
730 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_CANCEL');
731 }
732
740 public function reopen($user, $notrigger = 0)
741 {
742 // Protection
743 if ($this->status != self::STATUS_CANCELED) {
744 return 0;
745 }
746
747 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->write))
748 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->eventorganization_advance->validate))))
749 {
750 $this->error='Permission denied';
751 return -1;
752 }*/
753
754 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_REOPEN');
755 }
756
767 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
768 {
769 global $conf, $langs, $hookmanager;
770
771 if (!empty($conf->dol_no_mouse_hover)) {
772 $notooltip = 1; // Force disable tooltips
773 }
774
775 $result = '';
776
777 $label = img_picto('', $this->picto).' <u>'.$langs->trans("ConferenceOrBoothAttendee").'</u>';
778 if (isset($this->status)) {
779 $label .= ' '.$this->getLibStatut(5);
780 }
781 $label .= '<br>';
782 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
783 $label .= '<br><b>'.$langs->trans('DateOfRegistration').':</b> '.dol_print_date($this->date_subscription, 'dayhour');
784 $label .= '<br><b>'.$langs->trans('AmountPaid').':</b> '.$this->amount;
785
786 $url = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.$this->id;
787
788 if ($option != 'nolink') {
789 // Add param to save lastsearch_values or not
790 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
791 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
792 $add_save_lastsearch_values = 1;
793 }
794 if ($add_save_lastsearch_values) {
795 $url .= '&save_lastsearch_values=1';
796 }
797
798 if ($option == 'conforboothid') {
799 $url .= '&conforboothid='.((int) $this->fk_actioncomm);
800 }
801
802 if ($option == 'projectid') {
803 $url .= '&fk_project='.((int) $this->fk_project).'&withproject=1';
804 }
805
806 if ($option == 'conforboothidproject') {
807 $url .= '&conforboothid='.((int) $this->fk_actioncomm).'&withproject=1';
808 }
809 }
810
811 $linkclose = '';
812 if (empty($notooltip)) {
813 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
814 $label = $langs->trans("ShowConferenceOrBoothAttendee");
815 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
816 }
817 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
818 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
819 } else {
820 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
821 }
822
823 if ($option == 'nolink') {
824 $linkstart = '<span';
825 } else {
826 $linkstart = '<a href="'.$url.'"';
827 }
828 $linkstart .= $linkclose.'>';
829 if ($option == 'nolink') {
830 $linkend = '</span>';
831 } else {
832 $linkend = '</a>';
833 }
834
835 $result .= $linkstart;
836
837 if (empty($this->showphoto_on_popup)) {
838 if ($withpicto) {
839 $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);
840 }
841 } else {
842 if ($withpicto) {
843 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
844
845 list($class, $module) = explode('@', $this->picto);
846 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
847 $filearray = dol_dir_list($upload_dir, "files");
848 $filename = $filearray[0]['name'];
849 if (!empty($filename)) {
850 $pospoint = strpos($filearray[0]['name'], '.');
851
852 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
853 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
854 $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>';
855 } else {
856 $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>';
857 }
858
859 $result .= '</div>';
860 } else {
861 $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);
862 }
863 }
864 }
865
866 if ($withpicto != 2) {
867 $result .= $this->ref;
868 }
869
870 $result .= $linkend;
871 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
872
873 global $action, $hookmanager;
874 $hookmanager->initHooks(array('conferenceorboothattendeedao'));
875 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
876 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
877 if ($reshook > 0) {
878 $result = $hookmanager->resPrint;
879 } else {
880 $result .= $hookmanager->resPrint;
881 }
882
883 return $result;
884 }
885
892 public function getLabelStatus($mode = 0)
893 {
894 return $this->LibStatut($this->status, $mode);
895 }
896
903 public function getLibStatut($mode = 0)
904 {
905 return $this->LibStatut($this->status, $mode);
906 }
907
908 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
916 public function LibStatut($status, $mode = 0)
917 {
918 // phpcs:enable
919 global $langs;
920
921 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
922 //$langs->load("eventorganization@eventorganization");
923 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
924 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
925 $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
926 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
927 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
928 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
929 }
930
931 $statusType = 'status'.$status;
932 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
933 if ($status == self::STATUS_CANCELED) {
934 $statusType = 'status6';
935 }
936
937 if ($status == self::STATUS_VALIDATED && $this->date_subscription && $this->amount) {
938 $statusType = 'status4';
939 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated').' - '.$langs->trans("Paid");
940 }
941
942 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
943 }
944
951 public function info($id)
952 {
953 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
954 $sql .= ' fk_user_creat, fk_user_modif';
955 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
956 $sql .= ' WHERE t.rowid = '.((int) $id);
957 $result = $this->db->query($sql);
958 if ($result) {
959 if ($this->db->num_rows($result)) {
960 $obj = $this->db->fetch_object($result);
961
962 $this->id = $obj->rowid;
963
964 $this->user_creation_id = $obj->fk_user_creat;
965 $this->user_modification_id = $obj->fk_user_modif;
966 $this->date_creation = $this->db->jdate($obj->datec);
967 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
968 }
969
970 $this->db->free($result);
971 } else {
972 dol_print_error($this->db);
973 }
974 }
975
982 public function initAsSpecimen()
983 {
984 $this->initAsSpecimenCommon();
985 }
986
992 public function getNextNumRef()
993 {
994 global $langs, $conf;
995 $langs->load("eventorganization@eventorganization");
996
997 if (!getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
998 $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON = 'mod_conferenceorboothattendee_standard';
999 }
1000
1001 if (getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
1002 $mybool = false;
1003
1004 $file = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON') . ".php";
1005 $classname = $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON;
1006
1007 // Include file with class
1008 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1009 foreach ($dirmodels as $reldir) {
1010 $dir = dol_buildpath($reldir."core/modules/eventorganization/");
1011
1012 // Load file with numbering class (if found)
1013 $mybool |= @include_once $dir.$file;
1014 }
1015
1016 if ($mybool === false) {
1017 dol_print_error('', "Failed to include file ".$file);
1018 return '';
1019 }
1020
1021 if (class_exists($classname)) {
1022 $obj = new $classname();
1023 $numref = $obj->getNextValue($this);
1024
1025 if ($numref != '' && $numref != '-1') {
1026 return $numref;
1027 } else {
1028 $this->error = $obj->error;
1029 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1030 return "";
1031 }
1032 } else {
1033 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1034 return "";
1035 }
1036 } else {
1037 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1038 return "";
1039 }
1040 }
1041
1053 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1054 {
1055 global $conf, $langs;
1056
1057 $result = 0;
1058 $includedocgeneration = 0;
1059
1060 $langs->load("eventorganization@eventorganization");
1061
1062 if (!dol_strlen($modele)) {
1063 $modele = 'standard_conferenceorboothattendee';
1064
1065 if (!empty($this->model_pdf)) {
1066 $modele = $this->model_pdf;
1067 } elseif (getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF')) {
1068 $modele = $conf->global->CONFERENCEORBOOTHATTENDEE_ADDON_PDF;
1069 }
1070 }
1071
1072 $modelpath = "core/modules/eventorganization/doc/";
1073
1074 if ($includedocgeneration && !empty($modele)) {
1075 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1076 }
1077
1078 return $result;
1079 }
1080
1088 public function doScheduledJob()
1089 {
1090 global $conf, $langs;
1091
1092 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1093
1094 $error = 0;
1095 $this->output = '';
1096 $this->error = '';
1097
1098 dol_syslog(__METHOD__, LOG_DEBUG);
1099
1100 $now = dol_now();
1101
1102 $this->db->begin();
1103
1104 // ...
1105
1106 $this->db->commit();
1107
1108 return $error;
1109 }
1110
1119 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1120 {
1121 $tables = array(
1122 'eventorganization_conferenceorboothattendee'
1123 );
1124
1125 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1126 }
1127
1137 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
1138 {
1139 $lastname = $this->lastname;
1140 $firstname = $this->firstname;
1141 if (empty($lastname)) {
1142 $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 : '')))));
1143 }
1144
1145 $ret = '';
1146
1147 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
1148
1149 return dol_trunc($ret, $maxlen);
1150 }
1151}
1152
1153
1154require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1155
1160{
1161 // To complete with content of an object ConferenceOrBoothAttendeeLine
1162 // We should have a field rowid, fk_conferenceorboothattendee and position
1163
1167 public $isextrafieldmanaged = 0;
1168
1174 public function __construct(DoliDB $db)
1175 {
1176 $this->db = $db;
1177 }
1178}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in 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.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
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.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
cancel($user, $notrigger=0)
Set cancel status.
createFromClone(User $user, $fromid)
Clone an object into another one.
update(User $user, $notrigger=false)
Update object into database.
getLibStatut($mode=0)
Return the label of the status.
info($id)
Load the info information in the object.
create(User $user, $notrigger=false)
Create object into database.
fetch($id, $ref=null)
Load object in memory from the database.
getLabelStatus($mode=0)
Return the label of the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the 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 optionaly 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.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
reopen($user, $notrigger=0)
Set back to validated status.
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.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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_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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124