dolibarr  9.0.0
emailsenderprofile.class.php
Go to the documentation of this file.
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 
28 // Put here all includes required by your class file
29 require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
30 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32 
37 {
41  public $element = 'emailsenderprofile';
42 
46  public $table_element = 'c_email_senderprofile';
47 
51  public $ismultientitymanaged = 1;
52 
56  public $picto = 'emailsenderprofile@monmodule';
57 
58 
74  // BEGIN MODULEBUILDER PROPERTIES
78  public $fields=array(
79  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
80  'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>-1, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
81  'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>-1),
82  'email' => array('type'=>'varchar(255)', 'label'=>'Email', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1),
83  //'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
84  //'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,),
85  'signature' => array('type'=>'text', 'label'=>'Signature', 'visible'=>-1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
86  'position' => array('type'=>'integer', 'label'=>'Position', 'visible'=>-1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
87  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
88  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
89  'active' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1),
90  );
91 
95  public $rowid;
96 
100  public $entity;
101 
105  public $label;
106 
107  public $email;
108  public $date_creation;
109  public $tms;
110  //public $fk_user_creat;
111  //public $fk_user_modif;
112  public $signature;
113  public $position;
114  public $active;
115  // END MODULEBUILDER PROPERTIES
116 
117 
118 
119  // If this object has a subtable with lines
120 
124  //public $table_element_line = 'emailsenderprofiledet';
128  //public $fk_element = 'fk_emailsenderprofile';
132  //public $class_element_line = 'EmailSenderProfileline';
136  //protected $childtables=array('emailsenderprofiledet');
140  //public $lines = array();
141 
142 
143 
149  public function __construct(DoliDB $db)
150  {
151  global $conf;
152 
153  $this->db = $db;
154 
155  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
156  if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0;
157  }
158 
166  public function create(User $user, $notrigger = false)
167  {
168  return $this->createCommon($user, $notrigger);
169  }
170 
178  public function createFromClone(User $user, $fromid)
179  {
180  global $hookmanager, $langs;
181  $error = 0;
182 
183  dol_syslog(__METHOD__, LOG_DEBUG);
184 
185  $object = new self($this->db);
186 
187  $this->db->begin();
188 
189  // Load source object
190  $object->fetchCommon($fromid);
191  // Reset some properties
192  unset($object->id);
193  unset($object->fk_user_creat);
194  unset($object->import_key);
195 
196  // Clear fields
197  $object->ref = "copy_of_".$object->ref;
198  $object->title = $langs->trans("CopyOf")." ".$object->title;
199  // ...
200 
201  // Create clone
202  $object->context['createfromclone'] = 'createfromclone';
203  $result = $object->createCommon($user);
204  if ($result < 0) {
205  $error++;
206  $this->error = $object->error;
207  $this->errors = $object->errors;
208  }
209 
210  unset($object->context['createfromclone']);
211 
212  // End
213  if (!$error) {
214  $this->db->commit();
215  return $object;
216  } else {
217  $this->db->rollback();
218  return -1;
219  }
220  }
221 
229  public function fetch($id, $ref = null)
230  {
231  $result = $this->fetchCommon($id, $ref);
232  if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
233  return $result;
234  }
235 
241  public function fetchLines()
242  {
243  $this->lines=array();
244 
245  // Load lines with object EmailSenderProfileLine
246 
247  return count($this->lines)?1:0;
248  }
249 
257  public function update(User $user, $notrigger = false)
258  {
259  return $this->updateCommon($user, $notrigger);
260  }
261 
269  public function delete(User $user, $notrigger = false)
270  {
271  return $this->deleteCommon($user, $notrigger);
272  }
273 
280  function getNomUrl($withpicto=0)
281  {
282  global $db, $conf, $langs;
283  global $dolibarr_main_authentication, $dolibarr_main_demo;
284  global $menumanager;
285 
286  $result = '';
287  $companylink = '';
288 
289  $label=$this->label;
290 
291  $url='';
292  //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
293 
294  $linkstart = '';
295  $linkend='';
296 
297  if ($withpicto)
298  {
299  $result.=($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
300  if ($withpicto != 2) $result.=' ';
301  }
302  $result.= $linkstart . $this->label . $linkend;
303  return $result;
304  }
305 
312  function getDirectExternalLink($withpicto=0)
313  {
314  return 'todo';
315  }
316 
323  function getLibStatut($mode=0)
324  {
325  return $this->LibStatut($this->status,$mode);
326  }
327 
328  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
336  static function LibStatut($status,$mode=0)
337  {
338  global $langs;
339 
340  if ($mode == 0 || $mode == 1)
341  {
342  if ($status == 1) return $langs->trans('Enabled');
343  if ($status == 0) return $langs->trans('Disabled');
344  }
345  elseif ($mode == 2)
346  {
347  if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
348  if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
349  }
350  elseif ($mode == 3)
351  {
352  if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
353  if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
354  }
355  elseif ($mode == 4)
356  {
357  if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
358  if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
359  }
360  elseif ($mode == 5)
361  {
362  if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
363  if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
364  }
365  elseif ($mode == 6)
366  {
367  if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
368  if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
369  }
370  }
371 
378  function info($id)
379  {
380  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
381  $sql.= ' fk_user_creat, fk_user_modif';
382  $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
383  $sql.= ' WHERE t.rowid = '.$id;
384  $result=$this->db->query($sql);
385  if ($result)
386  {
387  if ($this->db->num_rows($result))
388  {
389  $obj = $this->db->fetch_object($result);
390  $this->id = $obj->rowid;
391  if ($obj->fk_user_author)
392  {
393  $cuser = new User($this->db);
394  $cuser->fetch($obj->fk_user_author);
395  $this->user_creation = $cuser;
396  }
397 
398  if ($obj->fk_user_valid)
399  {
400  $vuser = new User($this->db);
401  $vuser->fetch($obj->fk_user_valid);
402  $this->user_validation = $vuser;
403  }
404 
405  if ($obj->fk_user_cloture)
406  {
407  $cluser = new User($this->db);
408  $cluser->fetch($obj->fk_user_cloture);
409  $this->user_cloture = $cluser;
410  }
411 
412  $this->date_creation = $this->db->jdate($obj->datec);
413  $this->date_modification = $this->db->jdate($obj->datem);
414  $this->date_validation = $this->db->jdate($obj->datev);
415  }
416 
417  $this->db->free($result);
418  }
419  else
420  {
421  dol_print_error($this->db);
422  }
423  }
424 
431  public function initAsSpecimen()
432  {
433  $this->initAsSpecimenCommon();
434  }
435 }
436 
440 /*
441 class EmailSenderProfileLine
442 {
443  // @var int ID
444  public $id;
445  // @var mixed Sample line property 1
446  public $prop1;
447  // @var mixed Sample line property 2
448  public $prop2;
449 }
450 */
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
getDirectExternalLink($withpicto=0)
Return link to download file from a direct external access.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
fetch($id, $ref=null)
Load object in memory from the database.
getNomUrl($withpicto=0)
Return a link to the object card (with optionaly the picto)
create(User $user, $notrigger=false)
Create object into database.
Class to manage Dolibarr users.
Definition: user.class.php:41
Class to manage Dolibarr database access.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
createCommon(User $user, $notrigger=false)
Create object into database.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchLines()
Load object lines in memory from the database.
__construct(DoliDB $db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
update(User $user, $notrigger=false)
Update object into database.
static LibStatut($status, $mode=0)
Return the status.
getLibStatut($mode=0)
Retourne le libelle du status d&#39;un user (actif, inactif)
info($id)
Charge les informations d&#39;ordre info dans l&#39;objet commande.
updateCommon(User $user, $notrigger=false)
Update object into database.
createFromClone(User $user, $fromid)
Clone and object into another one.
Class for EmailSenderProfile.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)