calendar.class.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
  4. * Copyright (C) 2023 Alice Adminson <aadminson@example.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file class/calendar.class.php
  21. * \ingroup bookcal
  22. * \brief This file is a CRUD class file for Calendar (Create/Read/Update/Delete)
  23. */
  24. // Put here all includes required by your class file
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  26. //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  27. //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  28. /**
  29. * Class for Calendar
  30. */
  31. class Calendar extends CommonObject
  32. {
  33. /**
  34. * @var string ID of module.
  35. */
  36. public $module = 'bookcal';
  37. /**
  38. * @var string ID to identify managed object.
  39. */
  40. public $element = 'calendar';
  41. /**
  42. * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
  43. */
  44. public $table_element = 'bookcal_calendar';
  45. /**
  46. * @var int Does this object support multicompany module ?
  47. * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
  48. */
  49. public $ismultientitymanaged = 0;
  50. /**
  51. * @var int Does object support extrafields ? 0=No, 1=Yes
  52. */
  53. public $isextrafieldmanaged = 1;
  54. /**
  55. * @var string String with name of icon for calendar. Must be a 'fa-xxx' fontawesome code (or 'fa-xxx_fa_color_size') or 'calendar@bookcal' if picto is file 'img/object_calendar.png'.
  56. */
  57. public $picto = 'fa-file';
  58. const STATUS_DRAFT = 0;
  59. const STATUS_VALIDATED = 1;
  60. const STATUS_CANCELED = 9;
  61. /**
  62. * 'type' field format:
  63. * 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',
  64. * 'select' (list of values are in 'options'),
  65. * 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]',
  66. * 'chkbxlst:...',
  67. * 'varchar(x)',
  68. * 'text', 'text:none', 'html',
  69. * 'double(24,8)', 'real', 'price',
  70. * 'date', 'datetime', 'timestamp', 'duration',
  71. * 'boolean', 'checkbox', 'radio', 'array',
  72. * 'mail', 'phone', 'url', 'password', 'ip'
  73. * Note: Filter must be a Dolibarr Universal Filter syntax string. Example: "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.status:!=:0) or (t.nature:is:NULL)"
  74. * 'label' the translation key.
  75. * 'picto' is code of a picto to show before value in forms
  76. * 'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalInt('MY_SETUP_PARAM') or 'isModEnabled("multicurrency")' ...)
  77. * 'position' is the sort order of field.
  78. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  79. * '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)
  80. * 'noteditable' says if field is not editable (1 or 0)
  81. * 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
  82. * '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.
  83. * 'index' if we want an index in database.
  84. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  85. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  86. * 'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage)
  87. * '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: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
  88. * 'help' and 'helplist' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
  89. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  90. * '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.
  91. * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
  92. * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
  93. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  94. * 'validate' is 1 if need to validate with $this->validateField()
  95. * 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value)
  96. *
  97. * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
  98. */
  99. // BEGIN MODULEBUILDER PROPERTIES
  100. /**
  101. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  102. */
  103. public $fields=array(
  104. 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'right', 'comment'=>"Id"),
  105. 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'validate'=>'1', 'comment'=>"Reference of object", 'css'=>'width100'),
  106. 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'alwayseditable'=>'1', 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'help'=>"Help text", 'showoncombobox'=>'2', 'validate'=>'1',),
  107. 'visibility' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Owner', 'enabled'=>'1', 'position'=>40, 'notnull'=>1, 'visible'=>1, 'picto'=>'user', 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150',),
  108. 'type' => array('type'=>'integer', 'label'=>'Type', 'enabled'=>'1', 'position'=>42, 'notnull'=>1, 'visible'=>1, 'arrayofkeyval'=>array('0'=>'Customer', '1'=>'Supplier', '3'=>'Other'),),
  109. 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label'=>'ThirdParty', 'picto'=>'company', 'enabled'=>'isModEnabled("societe")', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150', 'help'=>"ThirdPartyBookCalHelp", 'validate'=>'1',),
  110. 'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'picto'=>'project', 'enabled'=>'isModEnabled("project")', 'position'=>52, 'notnull'=>-1, 'visible'=>-1, 'index'=>1, 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150', 'validate'=>'1',),
  111. 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3, 'validate'=>'1',),
  112. 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0, 'cssview'=>'wordbreak', 'validate'=>'1',),
  113. 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0, 'cssview'=>'wordbreak', 'validate'=>'1',),
  114. 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
  115. 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
  116. 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'picto'=>'user', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid', 'csslist'=>'tdoverflowmax150',),
  117. 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'picto'=>'user', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2, 'csslist'=>'tdoverflowmax150',),
  118. 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
  119. 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>2000, 'notnull'=>1, 'default'=>0, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '9'=>'Closed'), 'validate'=>'1',),
  120. );
  121. public $rowid;
  122. public $ref;
  123. public $label;
  124. public $type;
  125. public $visibility;
  126. public $fk_soc;
  127. public $fk_project;
  128. public $description;
  129. public $note_public;
  130. public $note_private;
  131. public $date_creation;
  132. public $tms;
  133. public $fk_user_creat;
  134. public $fk_user_modif;
  135. public $import_key;
  136. public $status;
  137. // END MODULEBUILDER PROPERTIES
  138. /**
  139. * Constructor
  140. *
  141. * @param DoliDb $db Database handler
  142. */
  143. public function __construct(DoliDB $db)
  144. {
  145. global $langs, $user;
  146. $this->db = $db;
  147. if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
  148. $this->fields['rowid']['visible'] = 0;
  149. }
  150. if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
  151. $this->fields['entity']['enabled'] = 0;
  152. }
  153. // Example to show how to set values of fields definition dynamically
  154. /*if ($user->hasRight('bookcal', 'calendar', 'read')) {
  155. $this->fields['myfield']['visible'] = 1;
  156. $this->fields['myfield']['noteditable'] = 0;
  157. }*/
  158. $this->fields['visibility']['default'] = $user->id;
  159. // Unset fields that are disabled
  160. foreach ($this->fields as $key => $val) {
  161. if (isset($val['enabled']) && empty($val['enabled'])) {
  162. unset($this->fields[$key]);
  163. }
  164. }
  165. // Translate some data of arrayofkeyval
  166. if (is_object($langs)) {
  167. foreach ($this->fields as $key => $val) {
  168. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  169. foreach ($val['arrayofkeyval'] as $key2 => $val2) {
  170. $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
  171. }
  172. }
  173. }
  174. }
  175. }
  176. /**
  177. * Create object into database
  178. *
  179. * @param User $user User that creates
  180. * @param bool $notrigger false=launch triggers after, true=disable triggers
  181. * @return int <0 if KO, Id of created object if OK
  182. */
  183. public function create(User $user, $notrigger = false)
  184. {
  185. $resultcreate = $this->createCommon($user, $notrigger);
  186. //$resultvalidate = $this->validate($user, $notrigger);
  187. return $resultcreate;
  188. }
  189. /**
  190. * Clone an object into another one
  191. *
  192. * @param User $user User that creates
  193. * @param int $fromid Id of object to clone
  194. * @return mixed New object created, <0 if KO
  195. */
  196. public function createFromClone(User $user, $fromid)
  197. {
  198. global $langs, $extrafields;
  199. $error = 0;
  200. dol_syslog(__METHOD__, LOG_DEBUG);
  201. $object = new self($this->db);
  202. $this->db->begin();
  203. // Load source object
  204. $result = $object->fetchCommon($fromid);
  205. if ($result > 0 && !empty($object->table_element_line)) {
  206. $object->fetchLines();
  207. }
  208. // get lines so they will be clone
  209. //foreach($this->lines as $line)
  210. // $line->fetch_optionals();
  211. // Reset some properties
  212. unset($object->id);
  213. unset($object->fk_user_creat);
  214. unset($object->import_key);
  215. // Clear fields
  216. if (property_exists($object, 'ref')) {
  217. $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
  218. }
  219. if (property_exists($object, 'label')) {
  220. $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
  221. }
  222. if (property_exists($object, 'status')) {
  223. $object->status = self::STATUS_DRAFT;
  224. }
  225. if (property_exists($object, 'date_creation')) {
  226. $object->date_creation = dol_now();
  227. }
  228. if (property_exists($object, 'date_modification')) {
  229. $object->date_modification = null;
  230. }
  231. // ...
  232. // Clear extrafields that are unique
  233. if (is_array($object->array_options) && count($object->array_options) > 0) {
  234. $extrafields->fetch_name_optionals_label($this->table_element);
  235. foreach ($object->array_options as $key => $option) {
  236. $shortkey = preg_replace('/options_/', '', $key);
  237. if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
  238. //var_dump($key);
  239. //var_dump($clonedObj->array_options[$key]); exit;
  240. unset($object->array_options[$key]);
  241. }
  242. }
  243. }
  244. // Create clone
  245. $object->context['createfromclone'] = 'createfromclone';
  246. $result = $object->createCommon($user);
  247. if ($result < 0) {
  248. $error++;
  249. $this->setErrorsFromObject($object);
  250. }
  251. if (!$error) {
  252. // copy internal contacts
  253. if ($this->copy_linked_contact($object, 'internal') < 0) {
  254. $error++;
  255. }
  256. }
  257. if (!$error) {
  258. // copy external contacts if same company
  259. if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
  260. if ($this->copy_linked_contact($object, 'external') < 0) {
  261. $error++;
  262. }
  263. }
  264. }
  265. unset($object->context['createfromclone']);
  266. // End
  267. if (!$error) {
  268. $this->db->commit();
  269. return $object;
  270. } else {
  271. $this->db->rollback();
  272. return -1;
  273. }
  274. }
  275. /**
  276. * Load object in memory from the database
  277. *
  278. * @param int $id Id object
  279. * @param string $ref Ref
  280. * @return int <0 if KO, 0 if not found, >0 if OK
  281. */
  282. public function fetch($id, $ref = null)
  283. {
  284. $result = $this->fetchCommon($id, $ref);
  285. if ($result > 0 && !empty($this->table_element_line)) {
  286. $this->fetchLines();
  287. }
  288. return $result;
  289. }
  290. /**
  291. * Load object lines in memory from the database
  292. *
  293. * @return int <0 if KO, 0 if not found, >0 if OK
  294. */
  295. public function fetchLines()
  296. {
  297. $this->lines = array();
  298. $result = $this->fetchLinesCommon();
  299. return $result;
  300. }
  301. /**
  302. * Load list of objects in memory from the database.
  303. *
  304. * @param string $sortorder Sort Order
  305. * @param string $sortfield Sort field
  306. * @param int $limit limit
  307. * @param int $offset Offset
  308. * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
  309. * @param string $filtermode Filter mode (AND or OR)
  310. * @return array|int int <0 if KO, array of pages if OK
  311. */
  312. public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
  313. {
  314. dol_syslog(__METHOD__, LOG_DEBUG);
  315. $records = array();
  316. $sql = "SELECT ";
  317. $sql .= $this->getFieldList('t');
  318. $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
  319. if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
  320. $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
  321. } else {
  322. $sql .= " WHERE 1 = 1";
  323. }
  324. // Manage filter
  325. $sqlwhere = array();
  326. if (count($filter) > 0) {
  327. foreach ($filter as $key => $value) {
  328. if ($key == 't.rowid') {
  329. $sqlwhere[] = $key." = ".((int) $value);
  330. } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
  331. $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
  332. } elseif ($key == 'customsql') {
  333. $sqlwhere[] = $value;
  334. } elseif (strpos($value, '%') === false) {
  335. $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
  336. } else {
  337. $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
  338. }
  339. }
  340. }
  341. if (count($sqlwhere) > 0) {
  342. $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
  343. }
  344. if (!empty($sortfield)) {
  345. $sql .= $this->db->order($sortfield, $sortorder);
  346. }
  347. if (!empty($limit)) {
  348. $sql .= $this->db->plimit($limit, $offset);
  349. }
  350. $resql = $this->db->query($sql);
  351. if ($resql) {
  352. $num = $this->db->num_rows($resql);
  353. $i = 0;
  354. while ($i < ($limit ? min($limit, $num) : $num)) {
  355. $obj = $this->db->fetch_object($resql);
  356. $record = new self($this->db);
  357. $record->setVarsFromFetchObj($obj);
  358. $records[$record->id] = $record;
  359. $i++;
  360. }
  361. $this->db->free($resql);
  362. return $records;
  363. } else {
  364. $this->errors[] = 'Error '.$this->db->lasterror();
  365. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  366. return -1;
  367. }
  368. }
  369. /**
  370. * Update object into database
  371. *
  372. * @param User $user User that modifies
  373. * @param bool $notrigger false=launch triggers after, true=disable triggers
  374. * @return int <0 if KO, >0 if OK
  375. */
  376. public function update(User $user, $notrigger = false)
  377. {
  378. return $this->updateCommon($user, $notrigger);
  379. }
  380. /**
  381. * Delete object in database
  382. *
  383. * @param User $user User that deletes
  384. * @param bool $notrigger false=launch triggers, true=disable triggers
  385. * @return int <0 if KO, >0 if OK
  386. */
  387. public function delete(User $user, $notrigger = false)
  388. {
  389. return $this->deleteCommon($user, $notrigger);
  390. //return $this->deleteCommon($user, $notrigger, 1);
  391. }
  392. /**
  393. * Delete a line of object in database
  394. *
  395. * @param User $user User that delete
  396. * @param int $idline Id of line to delete
  397. * @param bool $notrigger false=launch triggers after, true=disable triggers
  398. * @return int >0 if OK, <0 if KO
  399. */
  400. public function deleteLine(User $user, $idline, $notrigger = false)
  401. {
  402. if ($this->status < 0) {
  403. $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
  404. return -2;
  405. }
  406. return $this->deleteLineCommon($user, $idline, $notrigger);
  407. }
  408. /**
  409. * Validate object
  410. *
  411. * @param User $user User making status change
  412. * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
  413. * @return int <=0 if OK, 0=Nothing done, >0 if KO
  414. */
  415. public function validate($user, $notrigger = 0)
  416. {
  417. global $conf;
  418. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  419. $error = 0;
  420. // Protection
  421. if ($this->status == self::STATUS_VALIDATED) {
  422. dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
  423. return 0;
  424. }
  425. /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->calendar->write))
  426. || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->calendar->calendar_advance->validate))))
  427. {
  428. $this->error='NotEnoughPermissions';
  429. dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
  430. return -1;
  431. }*/
  432. $now = dol_now();
  433. $this->db->begin();
  434. // Define new ref
  435. if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
  436. $num = $this->getNextNumRef();
  437. } else {
  438. $num = $this->ref;
  439. }
  440. $this->newref = $num;
  441. if (!empty($num)) {
  442. // Validate
  443. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  444. $sql .= " SET ref = '".$this->db->escape($num)."',";
  445. $sql .= " status = ".self::STATUS_VALIDATED;
  446. if (!empty($this->fields['date_validation'])) {
  447. $sql .= ", date_validation = '".$this->db->idate($now)."'";
  448. }
  449. if (!empty($this->fields['fk_user_valid'])) {
  450. $sql .= ", fk_user_valid = ".((int) $user->id);
  451. }
  452. $sql .= " WHERE rowid = ".((int) $this->id);
  453. dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
  454. $resql = $this->db->query($sql);
  455. if (!$resql) {
  456. dol_print_error($this->db);
  457. $this->error = $this->db->lasterror();
  458. $error++;
  459. }
  460. if (!$error && !$notrigger) {
  461. // Call trigger
  462. $result = $this->call_trigger('MYOBJECT_VALIDATE', $user);
  463. if ($result < 0) {
  464. $error++;
  465. }
  466. // End call triggers
  467. }
  468. }
  469. if (!$error) {
  470. $this->oldref = $this->ref;
  471. // Rename directory if dir was a temporary ref
  472. if (preg_match('/^[\(]?PROV/i', $this->ref)) {
  473. // Now we rename also files into index
  474. $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'calendar/".$this->db->escape($this->newref)."'";
  475. $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'calendar/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
  476. $resql = $this->db->query($sql);
  477. if (!$resql) {
  478. $error++; $this->error = $this->db->lasterror();
  479. }
  480. $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'calendar/".$this->db->escape($this->newref)."'";
  481. $sql .= " WHERE filepath = 'calendar/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
  482. $resql = $this->db->query($sql);
  483. if (!$resql) {
  484. $error++; $this->error = $this->db->lasterror();
  485. }
  486. // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
  487. $oldref = dol_sanitizeFileName($this->ref);
  488. $newref = dol_sanitizeFileName($num);
  489. $dirsource = $conf->bookcal->dir_output.'/calendar/'.$oldref;
  490. $dirdest = $conf->bookcal->dir_output.'/calendar/'.$newref;
  491. if (!$error && file_exists($dirsource)) {
  492. dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
  493. if (@rename($dirsource, $dirdest)) {
  494. dol_syslog("Rename ok");
  495. // Rename docs starting with $oldref with $newref
  496. $listoffiles = dol_dir_list($conf->bookcal->dir_output.'/calendar/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
  497. foreach ($listoffiles as $fileentry) {
  498. $dirsource = $fileentry['name'];
  499. $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
  500. $dirsource = $fileentry['path'].'/'.$dirsource;
  501. $dirdest = $fileentry['path'].'/'.$dirdest;
  502. @rename($dirsource, $dirdest);
  503. }
  504. }
  505. }
  506. }
  507. }
  508. // Set new ref and current status
  509. if (!$error) {
  510. $this->ref = $num;
  511. $this->status = self::STATUS_VALIDATED;
  512. }
  513. if (!$error) {
  514. $this->db->commit();
  515. return 1;
  516. } else {
  517. $this->db->rollback();
  518. return -1;
  519. }
  520. }
  521. /**
  522. * Set draft status
  523. *
  524. * @param User $user Object user that modify
  525. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  526. * @return int <0 if KO, >0 if OK
  527. */
  528. public function setDraft($user, $notrigger = 0)
  529. {
  530. // Protection
  531. if ($this->status <= self::STATUS_DRAFT) {
  532. return 0;
  533. }
  534. /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->write))
  535. || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->bookcal_advance->validate))))
  536. {
  537. $this->error='Permission denied';
  538. return -1;
  539. }*/
  540. return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MYOBJECT_UNVALIDATE');
  541. }
  542. /**
  543. * Set cancel status
  544. *
  545. * @param User $user Object user that modify
  546. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  547. * @return int <0 if KO, 0=Nothing done, >0 if OK
  548. */
  549. public function cancel($user, $notrigger = 0)
  550. {
  551. // Protection
  552. if ($this->status != self::STATUS_VALIDATED) {
  553. return 0;
  554. }
  555. /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->write))
  556. || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->bookcal_advance->validate))))
  557. {
  558. $this->error='Permission denied';
  559. return -1;
  560. }*/
  561. return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MYOBJECT_CANCEL');
  562. }
  563. /**
  564. * Set back to validated status
  565. *
  566. * @param User $user Object user that modify
  567. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  568. * @return int <0 if KO, 0=Nothing done, >0 if OK
  569. */
  570. public function reopen($user, $notrigger = 0)
  571. {
  572. // Protection
  573. if ($this->status == self::STATUS_VALIDATED) {
  574. return 0;
  575. }
  576. /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->write))
  577. || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->bookcal_advance->validate))))
  578. {
  579. $this->error='Permission denied';
  580. return -1;
  581. }*/
  582. return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MYOBJECT_REOPEN');
  583. }
  584. /**
  585. * getTooltipContentArray
  586. *
  587. * @param array $params Params to construct tooltip data
  588. * @since v18
  589. * @return array
  590. */
  591. public function getTooltipContentArray($params)
  592. {
  593. global $langs;
  594. $datas = [];
  595. if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
  596. return ['optimize' => $langs->trans("ShowCalendar")];
  597. }
  598. $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Calendar").'</u>';
  599. if (isset($this->status)) {
  600. $datas['picto'] .= ' '.$this->getLibStatut(5);
  601. }
  602. $datas['ref'] .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
  603. return $datas;
  604. }
  605. /**
  606. * Return a link to the object card (with optionaly the picto)
  607. *
  608. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  609. * @param string $option On what the link point to ('nolink', ...)
  610. * @param int $notooltip 1=Disable tooltip
  611. * @param string $morecss Add more css on link
  612. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  613. * @return string String with URL
  614. */
  615. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  616. {
  617. global $conf, $langs, $hookmanager;
  618. if (!empty($conf->dol_no_mouse_hover)) {
  619. $notooltip = 1; // Force disable tooltips
  620. }
  621. $result = '';
  622. $params = [
  623. 'id' => $this->id,
  624. 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
  625. 'option' => $option,
  626. ];
  627. $classfortooltip = 'classfortooltip';
  628. $dataparams = '';
  629. if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
  630. $classfortooltip = 'classforajaxtooltip';
  631. $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
  632. $label = '';
  633. } else {
  634. $label = implode($this->getTooltipContentArray($params));
  635. }
  636. $url = dol_buildpath('/bookcal/calendar_card.php', 1).'?id='.$this->id;
  637. if ($option !== 'nolink') {
  638. // Add param to save lastsearch_values or not
  639. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  640. if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  641. $add_save_lastsearch_values = 1;
  642. }
  643. if ($url && $add_save_lastsearch_values) {
  644. $url .= '&save_lastsearch_values=1';
  645. }
  646. }
  647. $linkclose = '';
  648. if (empty($notooltip)) {
  649. if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
  650. $label = $langs->trans("ShowCalendar");
  651. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  652. }
  653. $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
  654. $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
  655. } else {
  656. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  657. }
  658. if ($option == 'nolink' || empty($url)) {
  659. $linkstart = '<span';
  660. } else {
  661. $linkstart = '<a href="'.$url.'"';
  662. }
  663. $linkstart .= $linkclose.'>';
  664. if ($option == 'nolink' || empty($url)) {
  665. $linkend = '</span>';
  666. } else {
  667. $linkend = '</a>';
  668. }
  669. $result .= $linkstart;
  670. if (empty($this->showphoto_on_popup)) {
  671. if ($withpicto) {
  672. $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
  673. }
  674. } else {
  675. if ($withpicto) {
  676. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  677. list($class, $module) = explode('@', $this->picto);
  678. $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
  679. $filearray = dol_dir_list($upload_dir, "files");
  680. $filename = $filearray[0]['name'];
  681. if (!empty($filename)) {
  682. $pospoint = strpos($filearray[0]['name'], '.');
  683. $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
  684. if (!getDolGlobalInt(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
  685. $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>';
  686. } else {
  687. $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>';
  688. }
  689. $result .= '</div>';
  690. } else {
  691. $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
  692. }
  693. }
  694. }
  695. if ($withpicto != 2) {
  696. $result .= $this->ref;
  697. }
  698. $result .= $linkend;
  699. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  700. global $action, $hookmanager;
  701. $hookmanager->initHooks(array($this->element.'dao'));
  702. $parameters = array('id' => $this->id, 'getnomurl' => &$result);
  703. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  704. if ($reshook > 0) {
  705. $result = $hookmanager->resPrint;
  706. } else {
  707. $result .= $hookmanager->resPrint;
  708. }
  709. return $result;
  710. }
  711. /**
  712. * Return a thumb for kanban views
  713. *
  714. * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
  715. * @param array $arraydata Array of data
  716. * @return string HTML Code for Kanban thumb.
  717. */
  718. public function getKanbanView($option = '', $arraydata = null)
  719. {
  720. global $conf, $langs;
  721. $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
  722. $return = '<div class="box-flex-item box-flex-grow-zero">';
  723. $return .= '<div class="info-box info-box-sm">';
  724. $return .= '<span class="info-box-icon bg-infobox-action">';
  725. $return .= img_picto('', $this->picto);
  726. $return .= '</span>';
  727. $return .= '<div class="info-box-content">';
  728. $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
  729. if ($selected >= 0) {
  730. $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
  731. }
  732. if (property_exists($this, 'label')) {
  733. $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
  734. }
  735. if (property_exists($this, 'amount')) {
  736. $return .= '<br>';
  737. $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
  738. }
  739. if (method_exists($this, 'getLibStatut')) {
  740. $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
  741. }
  742. $return .= '</div>';
  743. $return .= '</div>';
  744. $return .= '</div>';
  745. return $return;
  746. }
  747. /**
  748. * Return the label of the status
  749. *
  750. * @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
  751. * @return string Label of status
  752. */
  753. public function getLabelStatus($mode = 0)
  754. {
  755. return $this->LibStatut($this->status, $mode);
  756. }
  757. /**
  758. * Return the label of the status
  759. *
  760. * @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
  761. * @return string Label of status
  762. */
  763. public function getLibStatut($mode = 0)
  764. {
  765. return $this->LibStatut($this->status, $mode);
  766. }
  767. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  768. /**
  769. * Return the label of a given status
  770. *
  771. * @param int $status Id status
  772. * @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
  773. * @return string Label of status
  774. */
  775. public function LibStatut($status, $mode = 0)
  776. {
  777. // phpcs:enable
  778. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  779. global $langs;
  780. $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  781. $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
  782. $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
  783. $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  784. $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
  785. $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
  786. }
  787. $statusType = 'status'.$status;
  788. if ($status == self::STATUS_VALIDATED) {
  789. $statusType = 'status4';
  790. }
  791. if ($status == self::STATUS_CANCELED) {
  792. $statusType = 'status6';
  793. }
  794. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  795. }
  796. /**
  797. * Load the info information in the object
  798. *
  799. * @param int $id Id of object
  800. * @return void
  801. */
  802. public function info($id)
  803. {
  804. $sql = "SELECT rowid,";
  805. $sql .= " date_creation as datec, tms as datem,";
  806. $sql .= " fk_user_creat, fk_user_modif";
  807. $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
  808. $sql .= " WHERE t.rowid = ".((int) $id);
  809. $result = $this->db->query($sql);
  810. if ($result) {
  811. if ($this->db->num_rows($result)) {
  812. $obj = $this->db->fetch_object($result);
  813. $this->id = $obj->rowid;
  814. $this->user_creation_id = $obj->fk_user_creat;
  815. $this->user_modification_id = $obj->fk_user_modif;
  816. $this->date_creation = $this->db->jdate($obj->datec);
  817. $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
  818. }
  819. $this->db->free($result);
  820. } else {
  821. dol_print_error($this->db);
  822. }
  823. }
  824. /**
  825. * Initialise object with example values
  826. * Id must be 0 if object instance is a specimen
  827. *
  828. * @return void
  829. */
  830. public function initAsSpecimen()
  831. {
  832. // Set here init that are not commonf fields
  833. // $this->property1 = ...
  834. // $this->property2 = ...
  835. $this->initAsSpecimenCommon();
  836. }
  837. /**
  838. * Create an array of lines
  839. *
  840. * @return array|int array of lines if OK, <0 if KO
  841. */
  842. public function getLinesArray()
  843. {
  844. $this->lines = array();
  845. $objectline = new CalendarLine($this->db);
  846. $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_calendar = '.((int) $this->id)));
  847. if (is_numeric($result)) {
  848. $this->setErrorsFromObject($objectline);
  849. return $result;
  850. } else {
  851. $this->lines = $result;
  852. return $this->lines;
  853. }
  854. }
  855. /**
  856. * Returns the reference to the following non used object depending on the active numbering module.
  857. *
  858. * @return string Object free reference
  859. */
  860. public function getNextNumRef()
  861. {
  862. global $langs, $conf;
  863. $langs->load("agenda");
  864. if (getDolGlobalString('BOOKCAL_MYOBJECT_ADDON')) {
  865. $conf->global->BOOKCAL_MYOBJECT_ADDON = 'mod_calendar_standard';
  866. }
  867. if (getDolGlobalString('BOOKCAL_MYOBJECT_ADDON')) {
  868. $mybool = false;
  869. $file = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON').".php";
  870. $classname = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON');
  871. // Include file with class
  872. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  873. foreach ($dirmodels as $reldir) {
  874. $dir = dol_buildpath($reldir."core/modules/bookcal/");
  875. // Load file with numbering class (if found)
  876. $mybool |= @include_once $dir.$file;
  877. }
  878. if ($mybool === false) {
  879. dol_print_error('', "Failed to include file ".$file);
  880. return '';
  881. }
  882. if (class_exists($classname)) {
  883. $obj = new $classname();
  884. $numref = $obj->getNextValue($this);
  885. if ($numref != '' && $numref != '-1') {
  886. return $numref;
  887. } else {
  888. $this->error = $obj->error;
  889. //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
  890. return "";
  891. }
  892. } else {
  893. print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
  894. return "";
  895. }
  896. } else {
  897. print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
  898. return "";
  899. }
  900. }
  901. /**
  902. * Create a document onto disk according to template module.
  903. *
  904. * @param string $modele Force template to use ('' to not force)
  905. * @param Translate $outputlangs objet lang a utiliser pour traduction
  906. * @param int $hidedetails Hide details of lines
  907. * @param int $hidedesc Hide description
  908. * @param int $hideref Hide ref
  909. * @param null|array $moreparams Array to provide more information
  910. * @return int 0 if KO, 1 if OK
  911. */
  912. public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
  913. {
  914. global $conf, $langs;
  915. $result = 0;
  916. $includedocgeneration = 0;
  917. $langs->load("agenda");
  918. if (!dol_strlen($modele)) {
  919. $modele = 'standard_calendar';
  920. if (!empty($this->model_pdf)) {
  921. $modele = $this->model_pdf;
  922. } elseif (getDolGlobalString('MYOBJECT_ADDON_PDF')) {
  923. $modele = getDolGlobalString('MYOBJECT_ADDON_PDF');
  924. }
  925. }
  926. $modelpath = "core/modules/bookcal/doc/";
  927. if ($includedocgeneration && !empty($modele)) {
  928. $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
  929. }
  930. return $result;
  931. }
  932. /**
  933. * Action executed by scheduler
  934. * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
  935. * Use public function doScheduledJob($param1, $param2, ...) to get parameters
  936. *
  937. * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
  938. */
  939. public function doScheduledJob()
  940. {
  941. //global $conf, $langs;
  942. //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
  943. $error = 0;
  944. $this->output = '';
  945. $this->error = '';
  946. dol_syslog(__METHOD__, LOG_DEBUG);
  947. $now = dol_now();
  948. $this->db->begin();
  949. // ...
  950. $this->db->commit();
  951. return $error;
  952. }
  953. }
  954. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
  955. /**
  956. * Class CalendarLine. You can also remove this and generate a CRUD class for lines objects.
  957. */
  958. class CalendarLine extends CommonObjectLine
  959. {
  960. // To complete with content of an object CalendarLine
  961. // We should have a field rowid, fk_calendar and position
  962. /**
  963. * @var int Does object support extrafields ? 0=No, 1=Yes
  964. */
  965. public $isextrafieldmanaged = 0;
  966. /**
  967. * Constructor
  968. *
  969. * @param DoliDb $db Database handler
  970. */
  971. public function __construct(DoliDB $db)
  972. {
  973. $this->db = $db;
  974. }
  975. }