emailsenderprofile.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. /**
  91. * @var string Email Sender Profile label
  92. */
  93. public $label;
  94. public $email;
  95. public $date_creation;
  96. public $tms;
  97. //public $fk_user_creat;
  98. //public $fk_user_modif;
  99. public $signature;
  100. public $position;
  101. public $active;
  102. // END MODULEBUILDER PROPERTIES
  103. // If this object has a subtable with lines
  104. /**
  105. * @var int Name of subtable line
  106. */
  107. //public $table_element_line = 'emailsenderprofiledet';
  108. /**
  109. * @var int Field with ID of parent key if this field has a parent
  110. */
  111. //public $fk_element = 'fk_emailsenderprofile';
  112. /**
  113. * @var int Name of subtable class that manage subtable lines
  114. */
  115. //public $class_element_line = 'EmailSenderProfileline';
  116. /**
  117. * @var array Array of child tables (child tables to delete before deleting a record)
  118. */
  119. //protected $childtables=array('emailsenderprofiledet');
  120. /**
  121. * @var EmailSenderProfileLine[] Array of subtable lines
  122. */
  123. //public $lines = array();
  124. /**
  125. * Constructor
  126. *
  127. * @param DoliDb $db Database handler
  128. */
  129. public function __construct(DoliDB $db)
  130. {
  131. global $conf;
  132. $this->db = $db;
  133. if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
  134. if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0;
  135. }
  136. /**
  137. * Create object into database
  138. *
  139. * @param User $user User that creates
  140. * @param bool $notrigger false=launch triggers after, true=disable triggers
  141. * @return int <0 if KO, Id of created object if OK
  142. */
  143. public function create(User $user, $notrigger = false)
  144. {
  145. return $this->createCommon($user, $notrigger);
  146. }
  147. /**
  148. * Clone and object into another one
  149. *
  150. * @param User $user User that creates
  151. * @param int $fromid Id of object to clone
  152. * @return mixed New object created, <0 if KO
  153. */
  154. public function createFromClone(User $user, $fromid)
  155. {
  156. global $hookmanager, $langs;
  157. $error = 0;
  158. dol_syslog(__METHOD__, LOG_DEBUG);
  159. $object = new self($this->db);
  160. $this->db->begin();
  161. // Load source object
  162. $object->fetchCommon($fromid);
  163. // Reset some properties
  164. unset($object->id);
  165. unset($object->fk_user_creat);
  166. unset($object->import_key);
  167. // Clear fields
  168. $object->ref = "copy_of_".$object->ref;
  169. $object->title = $langs->trans("CopyOf")." ".$object->title;
  170. // ...
  171. // Create clone
  172. $object->context['createfromclone'] = 'createfromclone';
  173. $result = $object->createCommon($user);
  174. if ($result < 0) {
  175. $error++;
  176. $this->error = $object->error;
  177. $this->errors = $object->errors;
  178. }
  179. unset($object->context['createfromclone']);
  180. // End
  181. if (!$error) {
  182. $this->db->commit();
  183. return $object;
  184. } else {
  185. $this->db->rollback();
  186. return -1;
  187. }
  188. }
  189. /**
  190. * Load object in memory from the database
  191. *
  192. * @param int $id Id object
  193. * @param string $ref Ref
  194. * @return int <0 if KO, 0 if not found, >0 if OK
  195. */
  196. public function fetch($id, $ref = null)
  197. {
  198. $result = $this->fetchCommon($id, $ref);
  199. if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
  200. return $result;
  201. }
  202. /**
  203. * Load object lines in memory from the database
  204. *
  205. * @return int <0 if KO, 0 if not found, >0 if OK
  206. */
  207. public function fetchLines()
  208. {
  209. $this->lines=array();
  210. // Load lines with object EmailSenderProfileLine
  211. return count($this->lines)?1:0;
  212. }
  213. /**
  214. * Update object into database
  215. *
  216. * @param User $user User that modifies
  217. * @param bool $notrigger false=launch triggers after, true=disable triggers
  218. * @return int <0 if KO, >0 if OK
  219. */
  220. public function update(User $user, $notrigger = false)
  221. {
  222. return $this->updateCommon($user, $notrigger);
  223. }
  224. /**
  225. * Delete object in database
  226. *
  227. * @param User $user User that deletes
  228. * @param bool $notrigger false=launch triggers after, true=disable triggers
  229. * @return int <0 if KO, >0 if OK
  230. */
  231. public function delete(User $user, $notrigger = false)
  232. {
  233. return $this->deleteCommon($user, $notrigger);
  234. }
  235. /**
  236. * Return a link to the object card (with optionaly the picto)
  237. *
  238. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  239. * @return string String with URL
  240. */
  241. function getNomUrl($withpicto=0)
  242. {
  243. global $db, $conf, $langs;
  244. global $dolibarr_main_authentication, $dolibarr_main_demo;
  245. global $menumanager;
  246. $result = '';
  247. $companylink = '';
  248. $label=$this->label;
  249. $url='';
  250. //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
  251. $linkstart = '';
  252. $linkend='';
  253. if ($withpicto)
  254. {
  255. $result.=($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
  256. if ($withpicto != 2) $result.=' ';
  257. }
  258. $result.= $linkstart . $this->label . $linkend;
  259. return $result;
  260. }
  261. /**
  262. * Return link to download file from a direct external access
  263. *
  264. * @param int $withpicto Add download picto into link
  265. * @return string HTML link to file
  266. */
  267. function getDirectExternalLink($withpicto=0)
  268. {
  269. return 'todo';
  270. }
  271. /**
  272. * Retourne le libelle du status d'un user (actif, inactif)
  273. *
  274. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  275. * @return string Label of status
  276. */
  277. function getLibStatut($mode=0)
  278. {
  279. return $this->LibStatut($this->status,$mode);
  280. }
  281. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  282. /**
  283. * Return the status
  284. *
  285. * @param int $status Id status
  286. * @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
  287. * @return string Label of status
  288. */
  289. static function LibStatut($status,$mode=0)
  290. {
  291. global $langs;
  292. if ($mode == 0 || $mode == 1)
  293. {
  294. if ($status == 1) return $langs->trans('Enabled');
  295. if ($status == 0) return $langs->trans('Disabled');
  296. }
  297. elseif ($mode == 2)
  298. {
  299. if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
  300. if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
  301. }
  302. elseif ($mode == 3)
  303. {
  304. if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
  305. if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
  306. }
  307. elseif ($mode == 4)
  308. {
  309. if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
  310. if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
  311. }
  312. elseif ($mode == 5)
  313. {
  314. if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
  315. if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
  316. }
  317. elseif ($mode == 6)
  318. {
  319. if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
  320. if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
  321. }
  322. }
  323. /**
  324. * Charge les informations d'ordre info dans l'objet commande
  325. *
  326. * @param int $id Id of order
  327. * @return void
  328. */
  329. function info($id)
  330. {
  331. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  332. $sql.= ' fk_user_creat, fk_user_modif';
  333. $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  334. $sql.= ' WHERE t.rowid = '.$id;
  335. $result=$this->db->query($sql);
  336. if ($result)
  337. {
  338. if ($this->db->num_rows($result))
  339. {
  340. $obj = $this->db->fetch_object($result);
  341. $this->id = $obj->rowid;
  342. if ($obj->fk_user_author)
  343. {
  344. $cuser = new User($this->db);
  345. $cuser->fetch($obj->fk_user_author);
  346. $this->user_creation = $cuser;
  347. }
  348. if ($obj->fk_user_valid)
  349. {
  350. $vuser = new User($this->db);
  351. $vuser->fetch($obj->fk_user_valid);
  352. $this->user_validation = $vuser;
  353. }
  354. if ($obj->fk_user_cloture)
  355. {
  356. $cluser = new User($this->db);
  357. $cluser->fetch($obj->fk_user_cloture);
  358. $this->user_cloture = $cluser;
  359. }
  360. $this->date_creation = $this->db->jdate($obj->datec);
  361. $this->date_modification = $this->db->jdate($obj->datem);
  362. $this->date_validation = $this->db->jdate($obj->datev);
  363. }
  364. $this->db->free($result);
  365. }
  366. else
  367. {
  368. dol_print_error($this->db);
  369. }
  370. }
  371. /**
  372. * Initialise object with example values
  373. * Id must be 0 if object instance is a specimen
  374. *
  375. * @return void
  376. */
  377. public function initAsSpecimen()
  378. {
  379. $this->initAsSpecimenCommon();
  380. }
  381. }
  382. /**
  383. * Class EmailSenderProfileLine. You can also remove this and generate a CRUD class for lines objects.
  384. */
  385. /*
  386. class EmailSenderProfileLine
  387. {
  388. // @var int ID
  389. public $id;
  390. // @var mixed Sample line property 1
  391. public $prop1;
  392. // @var mixed Sample line property 2
  393. public $prop2;
  394. }
  395. */