emailsenderprofile.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
  4. * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  6. * Copyright (C) ---Put here your own copyright and developer email---
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file class/emailsenderprofile.class.php
  23. * \ingroup monmodule
  24. * \brief This file is a CRUD class file for EmailSenderProfile (Create/Read/Update/Delete)
  25. */
  26. // Put here all includes required by your class file
  27. require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
  28. //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  29. //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  30. /**
  31. * Class for EmailSenderProfile
  32. */
  33. class EmailSenderProfile extends CommonObject
  34. {
  35. /**
  36. * @var string ID to identify managed object
  37. */
  38. public $element = 'emailsenderprofile';
  39. /**
  40. * @var string Name of table without prefix where object is stored
  41. */
  42. public $table_element = 'c_email_senderprofile';
  43. /**
  44. * @var array Does emailsenderprofile support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
  45. */
  46. public $ismultientitymanaged = 1;
  47. /**
  48. * @var string String with name of icon for emailsenderprofile
  49. */
  50. public $picto = 'emailsenderprofile@monmodule';
  51. /**
  52. * 'type' if the field format.
  53. * 'label' the translation key.
  54. * 'enabled' is a condition when the filed must be managed.
  55. * 'visible' says if field is visible in list (-1 means not shown by default but can be added into list to be viewed).
  56. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  57. * 'index' if we want an index in database.
  58. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  59. * 'position' is the sort order of field.
  60. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  61. * '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).
  62. * 'help' is a string visible as a tooltip on field
  63. * 'comment' is not used. You can store here any text of your choice.
  64. */
  65. // BEGIN MODULEBUILDER PROPERTIES
  66. /**
  67. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  68. */
  69. public $fields=array(
  70. 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
  71. 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>-1, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
  72. 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>-1),
  73. 'email' => array('type'=>'varchar(255)', 'label'=>'Email', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1),
  74. //'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
  75. //'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,),
  76. 'signature' => array('type'=>'text', 'label'=>'Signature', 'visible'=>-1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
  77. 'position' => array('type'=>'integer', 'label'=>'Position', 'visible'=>-1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
  78. 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
  79. 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
  80. 'active' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1),
  81. );
  82. /**
  83. * @var int ID
  84. */
  85. public $rowid;
  86. /**
  87. * @var int Entity
  88. */
  89. public $entity;
  90. public $label;
  91. public $email;
  92. public $date_creation;
  93. public $tms;
  94. //public $fk_user_creat;
  95. //public $fk_user_modif;
  96. public $signature;
  97. public $position;
  98. public $active;
  99. // END MODULEBUILDER PROPERTIES
  100. // If this object has a subtable with lines
  101. /**
  102. * @var int Name of subtable line
  103. */
  104. //public $table_element_line = 'emailsenderprofiledet';
  105. /**
  106. * @var int Field with ID of parent key if this field has a parent
  107. */
  108. //public $fk_element = 'fk_emailsenderprofile';
  109. /**
  110. * @var int Name of subtable class that manage subtable lines
  111. */
  112. //public $class_element_line = 'EmailSenderProfileline';
  113. /**
  114. * @var array Array of child tables (child tables to delete before deleting a record)
  115. */
  116. //protected $childtables=array('emailsenderprofiledet');
  117. /**
  118. * @var EmailSenderProfileLine[] Array of subtable lines
  119. */
  120. //public $lines = array();
  121. /**
  122. * Constructor
  123. *
  124. * @param DoliDb $db Database handler
  125. */
  126. public function __construct(DoliDB $db)
  127. {
  128. global $conf;
  129. $this->db = $db;
  130. if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
  131. if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0;
  132. }
  133. /**
  134. * Create object into database
  135. *
  136. * @param User $user User that creates
  137. * @param bool $notrigger false=launch triggers after, true=disable triggers
  138. * @return int <0 if KO, Id of created object if OK
  139. */
  140. public function create(User $user, $notrigger = false)
  141. {
  142. return $this->createCommon($user, $notrigger);
  143. }
  144. /**
  145. * Clone and object into another one
  146. *
  147. * @param User $user User that creates
  148. * @param int $fromid Id of object to clone
  149. * @return mixed New object created, <0 if KO
  150. */
  151. public function createFromClone(User $user, $fromid)
  152. {
  153. global $hookmanager, $langs;
  154. $error = 0;
  155. dol_syslog(__METHOD__, LOG_DEBUG);
  156. $object = new self($this->db);
  157. $this->db->begin();
  158. // Load source object
  159. $object->fetchCommon($fromid);
  160. // Reset some properties
  161. unset($object->id);
  162. unset($object->fk_user_creat);
  163. unset($object->import_key);
  164. // Clear fields
  165. $object->ref = "copy_of_".$object->ref;
  166. $object->title = $langs->trans("CopyOf")." ".$object->title;
  167. // ...
  168. // Create clone
  169. $object->context['createfromclone'] = 'createfromclone';
  170. $result = $object->createCommon($user);
  171. if ($result < 0) {
  172. $error++;
  173. $this->error = $object->error;
  174. $this->errors = $object->errors;
  175. }
  176. // End
  177. if (!$error) {
  178. $this->db->commit();
  179. return $object;
  180. } else {
  181. $this->db->rollback();
  182. return -1;
  183. }
  184. }
  185. /**
  186. * Load object in memory from the database
  187. *
  188. * @param int $id Id object
  189. * @param string $ref Ref
  190. * @return int <0 if KO, 0 if not found, >0 if OK
  191. */
  192. public function fetch($id, $ref = null)
  193. {
  194. $result = $this->fetchCommon($id, $ref);
  195. if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
  196. return $result;
  197. }
  198. /**
  199. * Load object lines in memory from the database
  200. *
  201. * @return int <0 if KO, 0 if not found, >0 if OK
  202. */
  203. public function fetchLines()
  204. {
  205. $this->lines=array();
  206. // Load lines with object EmailSenderProfileLine
  207. return count($this->lines)?1:0;
  208. }
  209. /**
  210. * Update object into database
  211. *
  212. * @param User $user User that modifies
  213. * @param bool $notrigger false=launch triggers after, true=disable triggers
  214. * @return int <0 if KO, >0 if OK
  215. */
  216. public function update(User $user, $notrigger = false)
  217. {
  218. return $this->updateCommon($user, $notrigger);
  219. }
  220. /**
  221. * Delete object in database
  222. *
  223. * @param User $user User that deletes
  224. * @param bool $notrigger false=launch triggers after, true=disable triggers
  225. * @return int <0 if KO, >0 if OK
  226. */
  227. public function delete(User $user, $notrigger = false)
  228. {
  229. return $this->deleteCommon($user, $notrigger);
  230. }
  231. /**
  232. * Return a link to the object card (with optionaly the picto)
  233. *
  234. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  235. * @return string String with URL
  236. */
  237. function getNomUrl($withpicto=0)
  238. {
  239. global $db, $conf, $langs;
  240. global $dolibarr_main_authentication, $dolibarr_main_demo;
  241. global $menumanager;
  242. $result = '';
  243. $companylink = '';
  244. $label=$this->label;
  245. $url='';
  246. //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
  247. $linkstart = '';
  248. $linkend='';
  249. if ($withpicto)
  250. {
  251. $result.=($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
  252. if ($withpicto != 2) $result.=' ';
  253. }
  254. $result.= $linkstart . $this->label . $linkend;
  255. return $result;
  256. }
  257. /**
  258. * Return link to download file from a direct external access
  259. *
  260. * @param int $withpicto Add download picto into link
  261. * @return string HTML link to file
  262. */
  263. function getDirectExternalLink($withpicto=0)
  264. {
  265. return 'todo';
  266. }
  267. /**
  268. * Retourne le libelle du status d'un user (actif, inactif)
  269. *
  270. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  271. * @return string Label of status
  272. */
  273. function getLibStatut($mode=0)
  274. {
  275. return $this->LibStatut($this->status,$mode);
  276. }
  277. /**
  278. * Return the status
  279. *
  280. * @param int $status Id status
  281. * @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
  282. * @return string Label of status
  283. */
  284. // phpcs:ignore PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  285. static function LibStatut($status,$mode=0)
  286. {
  287. global $langs;
  288. if ($mode == 0)
  289. {
  290. $prefix='';
  291. if ($status == 1) return $langs->trans('Enabled');
  292. if ($status == 0) return $langs->trans('Disabled');
  293. }
  294. if ($mode == 1)
  295. {
  296. if ($status == 1) return $langs->trans('Enabled');
  297. if ($status == 0) return $langs->trans('Disabled');
  298. }
  299. if ($mode == 2)
  300. {
  301. if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
  302. if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
  303. }
  304. if ($mode == 3)
  305. {
  306. if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
  307. if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
  308. }
  309. if ($mode == 4)
  310. {
  311. if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
  312. if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
  313. }
  314. if ($mode == 5)
  315. {
  316. if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
  317. if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
  318. }
  319. if ($mode == 6)
  320. {
  321. if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
  322. if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
  323. }
  324. }
  325. /**
  326. * Charge les informations d'ordre info dans l'objet commande
  327. *
  328. * @param int $id Id of order
  329. * @return void
  330. */
  331. function info($id)
  332. {
  333. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  334. $sql.= ' fk_user_creat, fk_user_modif';
  335. $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  336. $sql.= ' WHERE t.rowid = '.$id;
  337. $result=$this->db->query($sql);
  338. if ($result)
  339. {
  340. if ($this->db->num_rows($result))
  341. {
  342. $obj = $this->db->fetch_object($result);
  343. $this->id = $obj->rowid;
  344. if ($obj->fk_user_author)
  345. {
  346. $cuser = new User($this->db);
  347. $cuser->fetch($obj->fk_user_author);
  348. $this->user_creation = $cuser;
  349. }
  350. if ($obj->fk_user_valid)
  351. {
  352. $vuser = new User($this->db);
  353. $vuser->fetch($obj->fk_user_valid);
  354. $this->user_validation = $vuser;
  355. }
  356. if ($obj->fk_user_cloture)
  357. {
  358. $cluser = new User($this->db);
  359. $cluser->fetch($obj->fk_user_cloture);
  360. $this->user_cloture = $cluser;
  361. }
  362. $this->date_creation = $this->db->jdate($obj->datec);
  363. $this->date_modification = $this->db->jdate($obj->datem);
  364. $this->date_validation = $this->db->jdate($obj->datev);
  365. }
  366. $this->db->free($result);
  367. }
  368. else
  369. {
  370. dol_print_error($this->db);
  371. }
  372. }
  373. /**
  374. * Initialise object with example values
  375. * Id must be 0 if object instance is a specimen
  376. *
  377. * @return void
  378. */
  379. public function initAsSpecimen()
  380. {
  381. $this->initAsSpecimenCommon();
  382. }
  383. }
  384. /**
  385. * Class EmailSenderProfileLine. You can also remove this and generate a CRUD class for lines objects.
  386. */
  387. /*
  388. class EmailSenderProfileLine
  389. {
  390. // @var int ID
  391. public $id;
  392. // @var mixed Sample line property 1
  393. public $prop1;
  394. // @var mixed Sample line property 2
  395. public $prop2;
  396. }
  397. */