conferenceorbooth.class.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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. /**
  19. * \file class/conferenceorbooth.class.php
  20. * \ingroup eventorganization
  21. * \brief This file is a CRUD class file for ConferenceOrBooth (Create/Read/Update/Delete)
  22. */
  23. // Put here all includes required by your class file
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  25. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
  26. //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  27. /**
  28. * Class for ConferenceOrBooth
  29. */
  30. class ConferenceOrBooth extends ActionComm
  31. {
  32. /**
  33. * @var string ID of module.
  34. */
  35. public $module = 'eventorganization';
  36. /**
  37. * @var string ID to identify managed object.
  38. */
  39. public $element = 'conferenceorbooth';
  40. /**
  41. * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
  42. */
  43. public $table_element = 'actioncomm';
  44. /**
  45. * @var int Does this object support multicompany module ?
  46. * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
  47. */
  48. public $ismultientitymanaged = 1;
  49. /**
  50. * @var int Does object support extrafields ? 0=No, 1=Yes
  51. */
  52. public $isextrafieldmanaged = 1;
  53. /**
  54. * @var string String with name of icon for conferenceorbooth. Must be the part after the 'object_' into object_conferenceorbooth.png
  55. */
  56. public $picto = 'conferenceorbooth';
  57. const STATUS_DRAFT = 0;
  58. const STATUS_SUGGESTED = 1;
  59. const STATUS_CONFIRMED = 2;
  60. const STATUS_NOT_QUALIFIED = 3;
  61. const STATUS_DONE = 4;
  62. const STATUS_CANCELED = 9;
  63. /**
  64. * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
  65. * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
  66. * 'label' the translation key.
  67. * 'picto' is code of a picto to show before value in forms
  68. * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
  69. * 'position' is the sort order of field.
  70. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  71. * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
  72. * 'noteditable' says if field is not editable (1 or 0)
  73. * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
  74. * 'index' if we want an index in database.
  75. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  76. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  77. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
  78. * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'maxwidth200', 'wordbreak', 'tdoverflowmax200'
  79. * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
  80. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  81. * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
  82. * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
  83. * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
  84. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  85. *
  86. * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
  87. */
  88. // BEGIN MODULEBUILDER PROPERTIES
  89. /**
  90. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  91. */
  92. public $fields=array(
  93. 'id' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
  94. 'ref' => array('type'=>'integer', 'label'=>'Ref', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>2, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
  95. 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'help'=>"Help text", 'showoncombobox'=>'1',),
  96. 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'help'=>"LinkToThirparty",),
  97. 'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1::eventorganization', 'label'=>'Project', 'enabled'=>'1', 'position'=>52, 'notnull'=>-1, 'visible'=>-1, 'index'=>1,),
  98. 'note' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>1),
  99. 'fk_action' => array('type'=>'sellist:c_actioncomm:libelle:id::module LIKE (\'%@eventorganization\')', 'label'=>'Format', 'enabled'=>'1', 'position'=>60, 'notnull'=>1, 'visible'=>1,),
  100. 'datep' => array('type'=>'datetime', 'label'=>'DateStart', 'enabled'=>'1', 'position'=>70, 'notnull'=>0, 'visible'=>1, 'showoncombobox'=>'2',),
  101. 'datep2' => array('type'=>'datetime', 'label'=>'DateEnd', 'enabled'=>'1', 'position'=>71, 'notnull'=>0, 'visible'=>1, 'showoncombobox'=>'3',),
  102. 'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
  103. 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
  104. 'fk_user_author' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
  105. 'fk_user_mod' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
  106. 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
  107. 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'index'=>1, 'arrayofkeyval'=>array('0'=>'EvntOrgDraft', '1'=>'EvntOrgSuggested', '2'=> 'EvntOrgConfirmed', '3' =>'EvntOrgNotQualified', '4' =>'EvntOrgDone', '9'=>'EvntOrgCancelled'),),
  108. 'num_vote' => array('type'=>'smallint', 'label'=>'NbVotes', 'enabled'=>'1', 'position'=>1001, 'notnull'=>-1, 'visible'=>5, 'default'=>'0', 'index'=>0),
  109. );
  110. public $rowid;
  111. public $id;
  112. public $label;
  113. public $fk_soc;
  114. public $fk_project;
  115. public $note;
  116. public $fk_action;
  117. public $datec;
  118. public $tms;
  119. public $fk_user_author;
  120. public $fk_user_mod;
  121. public $import_key;
  122. public $status;
  123. // END MODULEBUILDER PROPERTIES
  124. public $pubregister;
  125. /**
  126. * Constructor
  127. *
  128. * @param DoliDb $db Database handler
  129. */
  130. public function __construct(DoliDB $db)
  131. {
  132. global $conf, $langs;
  133. $this->db = $db;
  134. if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
  135. $this->fields['id']['visible'] = 0;
  136. }
  137. if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
  138. $this->fields['entity']['enabled'] = 0;
  139. }
  140. // Unset fields that are disabled
  141. foreach ($this->fields as $key => $val) {
  142. if (isset($val['enabled']) && empty($val['enabled'])) {
  143. unset($this->fields[$key]);
  144. }
  145. }
  146. // Translate some data of arrayofkeyval
  147. if (is_object($langs)) {
  148. foreach ($this->fields as $key => $val) {
  149. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  150. foreach ($val['arrayofkeyval'] as $key2 => $val2) {
  151. $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
  152. }
  153. }
  154. }
  155. }
  156. }
  157. /**
  158. * Create object into database
  159. *
  160. * @param User $user User that creates
  161. * @param bool $notrigger false=launch triggers after, true=disable triggers
  162. * @return int <0 if KO, Id of created object if OK
  163. */
  164. public function create(User $user, $notrigger = false)
  165. {
  166. $this->setPercentageFromStatus();
  167. $this->setActionCommFields($user);
  168. return parent::create($user, $notrigger);
  169. }
  170. /**
  171. * Set Percentage from status
  172. *
  173. * @return void
  174. */
  175. protected function setPercentageFromStatus()
  176. {
  177. if ($this->status==self::STATUS_DONE) {
  178. $this->percentage=100;
  179. }
  180. if ($this->status==self::STATUS_DRAFT) {
  181. $this->percentage=0;
  182. }
  183. }
  184. /**
  185. * Set action comm fields
  186. *
  187. * @param User $user User
  188. * @return void
  189. */
  190. protected function setActionCommFields(User $user)
  191. {
  192. $this->userownerid=$user->id;
  193. $this->type_id=$this->fk_action;
  194. $this->socid=$this->fk_soc;
  195. $this->datef=$this->datep2;
  196. $this->note_private=$this->note;
  197. $this->fk_user_author=$this->fk_user_author;
  198. }
  199. /**
  200. * Get action comm fields
  201. *
  202. * @return void
  203. */
  204. protected function getActionCommFields()
  205. {
  206. $this->fk_action=$this->type_id;
  207. $this->fk_soc=$this->socid;
  208. $this->datep2=$this->datef;
  209. }
  210. /**
  211. * Load object in memory from the database
  212. *
  213. * @param int $id Id object
  214. * @param string $ref Ref
  215. * @param string $ref_ext Ref ext to get
  216. * @param string $email_msgid Email msgid
  217. * @return int <0 if KO, 0 if not found, >0 if OK
  218. */
  219. public function fetch($id, $ref = null, $ref_ext = '', $email_msgid = '')
  220. {
  221. global $dolibarr_main_url_root, $dolibarr_main_instance_unique_id, $conf, $langs;
  222. $result = parent::fetch($id, $ref, $ref_ext, $email_msgid);
  223. $link_subscription = $dolibarr_main_url_root.'/public/eventorganization/attendee_subscription.php?id='.$id;
  224. $encodedsecurekey = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$id, 2);
  225. $link_subscription .= '&securekey='.urlencode($encodedsecurekey);
  226. $this->fields['pubregister'] = array('type'=>'url', 'label'=>$langs->trans("PublicAttendeeSubscriptionPage"), 'enabled'=>'1', 'position'=>72, 'notnull'=>0, 'visible'=>1);
  227. $this->pubregister = $link_subscription;
  228. $this->getActionCommFields();
  229. return $result;
  230. }
  231. /**
  232. * Load list of objects in memory from the database.
  233. *
  234. * @param string $sortorder Sort Order
  235. * @param string $sortfield Sort field
  236. * @param int $limit limit
  237. * @param int $offset Offset
  238. * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
  239. * @param string $filtermode Filter mode (AND or OR)
  240. * @return array|int int <0 if KO, array of pages if OK
  241. */
  242. public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
  243. {
  244. //TODO set percent according status
  245. global $conf;
  246. dol_syslog(__METHOD__, LOG_DEBUG);
  247. $records = array();
  248. $sql = 'SELECT ';
  249. $sql .= $this->getFieldList('t');
  250. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  251. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_actioncomm as cact ON cact.id=t.fk_action AND cact.module LIKE '%@eventorganization'";
  252. if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
  253. $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
  254. } else {
  255. $sql .= ' WHERE 1 = 1';
  256. }
  257. // Manage filter
  258. $sqlwhere = array();
  259. if (count($filter) > 0) {
  260. foreach ($filter as $key => $value) {
  261. if ($key == 't.id' || $key == 't.fk_project' || $key == 't.fk_soc' || $key == 't.fk_action') {
  262. $sqlwhere[] = $key." = ".((int) $value);
  263. } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
  264. $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
  265. } elseif ($key == 'customsql') {
  266. $sqlwhere[] = $value;
  267. } elseif (strpos($value, '%') === false) {
  268. $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
  269. } else {
  270. $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
  271. }
  272. }
  273. }
  274. if (count($sqlwhere) > 0) {
  275. $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
  276. }
  277. if (!empty($sortfield)) {
  278. $sql .= $this->db->order($sortfield, $sortorder);
  279. }
  280. if (!empty($limit)) {
  281. $sql .= $this->db->plimit($limit, $offset);
  282. }
  283. $resql = $this->db->query($sql);
  284. if ($resql) {
  285. $num = $this->db->num_rows($resql);
  286. $i = 0;
  287. while ($i < ($limit ? min($limit, $num) : $num)) {
  288. $obj = $this->db->fetch_object($resql);
  289. $record = new self($this->db);
  290. $record->setVarsFromFetchObj($obj);
  291. $records[$record->id] = $record;
  292. $i++;
  293. }
  294. $this->db->free($resql);
  295. return $records;
  296. } else {
  297. $this->errors[] = 'Error '.$this->db->lasterror();
  298. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  299. return -1;
  300. }
  301. }
  302. /**
  303. * Update object into database
  304. *
  305. * @param User $user User that modifies
  306. * @param bool $notrigger false=launch triggers after, true=disable triggers
  307. * @return int <0 if KO, >0 if OK
  308. */
  309. public function update(User $user, $notrigger = false)
  310. {
  311. $this->setPercentageFromStatus();
  312. $this->setActionCommFields($user);
  313. return parent::update($user, $notrigger);
  314. }
  315. /**
  316. * Delete object in database
  317. *
  318. * @param bool $notrigger false=launch triggers after, true=disable triggers
  319. * @return int <0 if KO, >0 if OK
  320. */
  321. public function delete($notrigger = false)
  322. {
  323. //TODO delete attendees and subscription
  324. return parent::delete($notrigger);
  325. }
  326. /**
  327. * Validate object
  328. *
  329. * @param User $user User making status change
  330. * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
  331. * @return int <=0 if OK, 0=Nothing done, >0 if KO
  332. */
  333. public function validate($user, $notrigger = 0)
  334. {
  335. global $conf, $langs;
  336. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  337. $error = 0;
  338. // Protection
  339. if ($this->status == self::STATUS_VALIDATED) {
  340. dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
  341. return 0;
  342. }
  343. $now = dol_now();
  344. $this->db->begin();
  345. // Validate
  346. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  347. $sql .= " status = ".self::STATUS_CONFIRMED;
  348. $sql .= " WHERE id = ".$this->id;
  349. dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
  350. $resql = $this->db->query($sql);
  351. if (!$resql) {
  352. dol_print_error($this->db);
  353. $this->error = $this->db->lasterror();
  354. $error++;
  355. }
  356. if (!$error && !$notrigger) {
  357. // Call trigger
  358. $result = $this->call_trigger('CONFERENCEORBOOTH_VALIDATE', $user);
  359. if ($result < 0) $error++;
  360. // End call triggers
  361. }
  362. if (!$error) {
  363. $this->oldref = $this->ref;
  364. // Rename directory if dir was a temporary ref
  365. if (preg_match('/^[\(]?PROV/i', $this->ref)) {
  366. // Now we rename also files into index
  367. $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'conferenceorbooth/".$this->db->escape($this->newref)."'";
  368. $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'conferenceorbooth/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
  369. $resql = $this->db->query($sql);
  370. if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
  371. // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
  372. $oldref = dol_sanitizeFileName($this->ref);
  373. $newref = dol_sanitizeFileName($num);
  374. $dirsource = $conf->eventorganization->dir_output.'/conferenceorbooth/'.$oldref;
  375. $dirdest = $conf->eventorganization->dir_output.'/conferenceorbooth/'.$newref;
  376. if (!$error && file_exists($dirsource)) {
  377. dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
  378. if (@rename($dirsource, $dirdest)) {
  379. dol_syslog("Rename ok");
  380. // Rename docs starting with $oldref with $newref
  381. $listoffiles = dol_dir_list($conf->eventorganization->dir_output.'/conferenceorbooth/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
  382. foreach ($listoffiles as $fileentry) {
  383. $dirsource = $fileentry['name'];
  384. $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
  385. $dirsource = $fileentry['path'].'/'.$dirsource;
  386. $dirdest = $fileentry['path'].'/'.$dirdest;
  387. @rename($dirsource, $dirdest);
  388. }
  389. }
  390. }
  391. }
  392. }
  393. // Set new ref and current status
  394. if (!$error) {
  395. $this->ref = $num;
  396. $this->status = self::STATUS_CONFIRMED;
  397. }
  398. if (!$error) {
  399. $this->db->commit();
  400. return 1;
  401. } else {
  402. $this->db->rollback();
  403. return -1;
  404. }
  405. }
  406. /**
  407. * Set draft status
  408. *
  409. * @param User $user Object user that modify
  410. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  411. * @return int <0 if KO, >0 if OK
  412. */
  413. public function setDraft($user, $notrigger = 0)
  414. {
  415. // Protection
  416. if ($this->status <= self::STATUS_DRAFT) {
  417. return 0;
  418. }
  419. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
  420. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
  421. {
  422. $this->error='Permission denied';
  423. return -1;
  424. }*/
  425. return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTH_UNVALIDATE');
  426. }
  427. /**
  428. * Set cancel status
  429. *
  430. * @param User $user Object user that modify
  431. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  432. * @return int <0 if KO, 0=Nothing done, >0 if OK
  433. */
  434. public function cancel($user, $notrigger = 0)
  435. {
  436. // Protection
  437. if ($this->status != self::STATUS_CONFIRMED) {
  438. return 0;
  439. }
  440. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
  441. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
  442. {
  443. $this->error='Permission denied';
  444. return -1;
  445. }*/
  446. return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTH_CANCEL');
  447. }
  448. /**
  449. * Set back to validated status
  450. *
  451. * @param User $user Object user that modify
  452. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  453. * @return int <0 if KO, 0=Nothing done, >0 if OK
  454. */
  455. public function reopen($user, $notrigger = 0)
  456. {
  457. // Protection
  458. if ($this->status != self::STATUS_CANCELED) {
  459. return 0;
  460. }
  461. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
  462. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
  463. {
  464. $this->error='Permission denied';
  465. return -1;
  466. }*/
  467. return $this->setStatusCommon($user, self::STATUS_CONFIRMED, $notrigger, 'CONFERENCEORBOOTH_REOPEN');
  468. }
  469. /**
  470. * Return a link to the object card (with optionaly the picto)
  471. *
  472. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  473. * @param int $maxlength Not use here just for declaration method compatibility with parent classes
  474. * @param string $classname Not use here just for declaration method compatibility with parent classes
  475. * @param string $option On what the link point to ('nolink', ...)
  476. * @param int $overwritepicto Not use here just for declaration method compatibility with parent classes
  477. * @param int $notooltip 1=Disable tooltip
  478. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  479. * @param string $morecss Add more css on link
  480. * @return string String with URL
  481. */
  482. public function getNomUrl($withpicto = 0, $maxlength = 0, $classname = '', $option = '', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1, $morecss = '')
  483. {
  484. global $conf, $langs, $hookmanager;
  485. if (!empty($conf->dol_no_mouse_hover)) {
  486. $notooltip = 1; // Force disable tooltips
  487. }
  488. $result = '';
  489. $label = img_picto('', $this->picto).' <u>'.$langs->trans("ConferenceOrBooth").'</u>';
  490. if (isset($this->status)) {
  491. $label .= ' '.$this->getLibStatut(5);
  492. }
  493. $label .= '<br>';
  494. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->id;
  495. $url = dol_buildpath('/eventorganization/conferenceorbooth_card.php', 1).'?id='.$this->id;
  496. if ($option != 'nolink') {
  497. // Add param to save lastsearch_values or not
  498. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  499. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  500. $add_save_lastsearch_values = 1;
  501. }
  502. if ($add_save_lastsearch_values) {
  503. $url .= '&save_lastsearch_values=1';
  504. }
  505. if ($option=='withproject') {
  506. $url .= '&withproject=1';
  507. }
  508. }
  509. $linkclose = '';
  510. if (empty($notooltip)) {
  511. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  512. $label = $langs->trans("ShowConferenceOrBooth");
  513. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  514. }
  515. //$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  516. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  517. } else {
  518. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  519. }
  520. $linkstart = '<a href="'.$url.'"';
  521. $linkstart .= $linkclose.'>';
  522. $linkend = '</a>';
  523. $result .= $linkstart;
  524. if (empty($this->showphoto_on_popup)) {
  525. if ($withpicto) {
  526. $picto = img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
  527. // var_dump($picto);
  528. $result .= $picto;
  529. }
  530. } else {
  531. if ($withpicto) {
  532. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  533. //list($class, $module) = explode('@', $this->picto);
  534. $upload_dir = $conf->eventorganisation->multidir_output[$conf->entity]."/".dol_sanitizeFileName($this->ref);
  535. $filearray = dol_dir_list($upload_dir, "files");
  536. $filename = $filearray[0]['name'];
  537. if (!empty($filename)) {
  538. $pospoint = strpos($filearray[0]['name'], '.');
  539. $pathtophoto = '/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
  540. $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=eventorganisation&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
  541. $result .= '</div>';
  542. } else {
  543. $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);
  544. }
  545. }
  546. }
  547. if ($withpicto != 2) {
  548. $result .= $this->ref;
  549. }
  550. $result .= $linkend;
  551. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  552. global $action, $hookmanager;
  553. $hookmanager->initHooks(array('conferenceorboothdao'));
  554. $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
  555. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  556. if ($reshook > 0) {
  557. $result = $hookmanager->resPrint;
  558. } else {
  559. $result .= $hookmanager->resPrint;
  560. }
  561. return $result;
  562. }
  563. /**
  564. * Return the label of the status
  565. *
  566. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  567. * @param int $hidenastatus Not use here just for declaration method compatibility with parent classes
  568. * @return string Label of status
  569. */
  570. public function getLibStatut($mode = 0, $hidenastatus = 0)
  571. {
  572. return $this->LibStatutEvent($this->status, $mode);
  573. }
  574. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  575. /**
  576. * Return the status
  577. *
  578. * @param int $status Id status
  579. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  580. * @return string Label of status
  581. */
  582. public function LibStatutEvent($status, $mode = 0)
  583. {
  584. // phpcs:enable
  585. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  586. global $langs;
  587. //$langs->load("eventorganization@eventorganization");
  588. $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
  589. $this->labelStatus[self::STATUS_SUGGESTED] = $langs->trans('Suggested');
  590. $this->labelStatus[self::STATUS_CONFIRMED] = $langs->trans('Confirmed');
  591. $this->labelStatus[self::STATUS_NOT_QUALIFIED] = $langs->trans('NotSelected');
  592. $this->labelStatus[self::STATUS_DONE] = $langs->trans('Done');
  593. $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Canceled');
  594. $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
  595. $this->labelStatusShort[self::STATUS_SUGGESTED] = $langs->trans('Suggested');
  596. $this->labelStatusShort[self::STATUS_CONFIRMED] = $langs->trans('Confirmed');
  597. $this->labelStatusShort[self::STATUS_NOT_QUALIFIED] = $langs->trans('NotSelected');
  598. $this->labelStatusShort[self::STATUS_DONE] = $langs->trans('Done');
  599. $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Canceled');
  600. }
  601. $statusType = 'status'.$status;
  602. //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
  603. if ($status == self::STATUS_CANCELED) {
  604. $statusType = 'status6';
  605. }
  606. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  607. }
  608. /**
  609. * Load the info information in the object
  610. *
  611. * @param int $id Id of object
  612. * @return void
  613. */
  614. public function info($id)
  615. {
  616. $sql = 'SELECT rowid, datec as datec, tms as datem,';
  617. $sql .= ' fk_user_author, fk_user_mod';
  618. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  619. $sql .= ' WHERE t.id = '.((int) $id);
  620. $result = $this->db->query($sql);
  621. if ($result) {
  622. if ($this->db->num_rows($result)) {
  623. $obj = $this->db->fetch_object($result);
  624. $this->id = $obj->rowid;
  625. if ($obj->fk_user_author) {
  626. $cuser = new User($this->db);
  627. $cuser->fetch($obj->fk_user_author);
  628. $this->user_creation = $cuser;
  629. }
  630. $this->date_creation = $this->db->jdate($obj->datec);
  631. $this->date_modification = $this->db->jdate($obj->datem);
  632. }
  633. $this->db->free($result);
  634. } else {
  635. dol_print_error($this->db);
  636. }
  637. }
  638. /**
  639. * Initialise object with example values
  640. * Id must be 0 if object instance is a specimen
  641. *
  642. * @return void
  643. */
  644. public function initAsSpecimen()
  645. {
  646. $this->initAsSpecimenCommon();
  647. }
  648. /**
  649. * Create an array of lines
  650. *
  651. * @return array|int array of lines if OK, <0 if KO
  652. */
  653. /*public function getLinesArray()
  654. {
  655. $this->lines = array();
  656. $objectline = new ConferenceOrBoothLine($this->db);
  657. $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_conferenceorbooth = '.$this->id));
  658. if (is_numeric($result)) {
  659. $this->error = $this->error;
  660. $this->errors = $this->errors;
  661. return $result;
  662. } else {
  663. $this->lines = $result;
  664. return $this->lines;
  665. }
  666. }*/
  667. /**
  668. * Create a document onto disk according to template module.
  669. *
  670. * @param string $modele Force template to use ('' to not force)
  671. * @param Translate $outputlangs objet lang a utiliser pour traduction
  672. * @param int $hidedetails Hide details of lines
  673. * @param int $hidedesc Hide description
  674. * @param int $hideref Hide ref
  675. * @param null|array $moreparams Array to provide more information
  676. * @return int 0 if KO, 1 if OK
  677. */
  678. public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
  679. {
  680. global $conf, $langs;
  681. $result = 0;
  682. $includedocgeneration = 0;
  683. $langs->load("eventorganization@eventorganization");
  684. if (!dol_strlen($modele)) {
  685. $modele = 'standard_conferenceorbooth';
  686. if (!empty($this->model_pdf)) {
  687. $modele = $this->model_pdf;
  688. } elseif (!empty($conf->global->CONFERENCEORBOOTH_ADDON_PDF)) {
  689. $modele = $conf->global->CONFERENCEORBOOTH_ADDON_PDF;
  690. }
  691. }
  692. $modelpath = "core/modules/eventorganization/doc/";
  693. if ($includedocgeneration && !empty($modele)) {
  694. $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
  695. }
  696. return $result;
  697. }
  698. /**
  699. * Action executed by scheduler
  700. * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
  701. * Use public function doScheduledJob($param1, $param2, ...) to get parameters
  702. *
  703. * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
  704. */
  705. public function doScheduledJob()
  706. {
  707. global $conf, $langs;
  708. //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
  709. $error = 0;
  710. $this->output = '';
  711. $this->error = '';
  712. dol_syslog(__METHOD__, LOG_DEBUG);
  713. $now = dol_now();
  714. $this->db->begin();
  715. // ...
  716. $this->db->commit();
  717. return $error;
  718. }
  719. }