dolibarr  7.0.0-beta
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';
45  public $table_element = 'c_email_senderprofile';
49  public $ismultientitymanaged = 1;
53  public $picto = 'emailsenderprofile@monmodule';
54 
55 
71  // BEGIN MODULEBUILDER PROPERTIES
75  public $fields=array(
76  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
77  'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>-1, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
78  'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>-1),
79  'email' => array('type'=>'varchar(255)', 'label'=>'Email', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1),
80  //'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
81  //'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,),
82  'signature' => array('type'=>'text', 'label'=>'Signature', 'visible'=>-1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
83  'position' => array('type'=>'integer', 'label'=>'Position', 'visible'=>-1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
84  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
85  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
86  'active' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1),
87  );
88  public $rowid;
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 
101 
102 
103  // If this object has a subtable with lines
104 
108  //public $table_element_line = 'emailsenderprofiledet';
112  //public $fk_element = 'fk_emailsenderprofile';
116  //public $class_element_line = 'EmailSenderProfileline';
120  //protected $childtables=array('emailsenderprofiledet');
124  //public $lines = array();
125 
126 
127 
133  public function __construct(DoliDB $db)
134  {
135  global $conf;
136 
137  $this->db = $db;
138 
139  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
140  if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0;
141  }
142 
150  public function create(User $user, $notrigger = false)
151  {
152  return $this->createCommon($user, $notrigger);
153  }
154 
162  public function createFromClone(User $user, $fromid)
163  {
164  global $hookmanager, $langs;
165  $error = 0;
166 
167  dol_syslog(__METHOD__, LOG_DEBUG);
168 
169  $object = new self($this->db);
170 
171  $this->db->begin();
172 
173  // Load source object
174  $object->fetchCommon($fromid);
175  // Reset some properties
176  unset($object->id);
177  unset($object->fk_user_creat);
178  unset($object->import_key);
179 
180  // Clear fields
181  $object->ref = "copy_of_".$object->ref;
182  $object->title = $langs->trans("CopyOf")." ".$object->title;
183  // ...
184 
185  // Create clone
186  $object->context['createfromclone'] = 'createfromclone';
187  $result = $object->createCommon($user);
188  if ($result < 0) {
189  $error++;
190  $this->error = $object->error;
191  $this->errors = $object->errors;
192  }
193 
194  // End
195  if (!$error) {
196  $this->db->commit();
197  return $object;
198  } else {
199  $this->db->rollback();
200  return -1;
201  }
202  }
203 
211  public function fetch($id, $ref = null)
212  {
213  $result = $this->fetchCommon($id, $ref);
214  if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
215  return $result;
216  }
217 
223  public function fetchLines()
224  {
225  $this->lines=array();
226 
227  // Load lines with object EmailSenderProfileLine
228 
229  return count($this->lines)?1:0;
230  }
231 
239  public function update(User $user, $notrigger = false)
240  {
241  return $this->updateCommon($user, $notrigger);
242  }
243 
251  public function delete(User $user, $notrigger = false)
252  {
253  return $this->deleteCommon($user, $notrigger);
254  }
255 
262  function getNomUrl($withpicto=0)
263  {
264  global $db, $conf, $langs;
265  global $dolibarr_main_authentication, $dolibarr_main_demo;
266  global $menumanager;
267 
268  $result = '';
269  $companylink = '';
270 
271  $label=$this->label;
272 
273  $url='';
274  //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
275 
276  $linkstart = '';
277  $linkend='';
278 
279  if ($withpicto)
280  {
281  $result.=($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
282  if ($withpicto != 2) $result.=' ';
283  }
284  $result.= $linkstart . $this->label . $linkend;
285  return $result;
286  }
287 
294  function getDirectExternalLink($withpicto=0)
295  {
296  return 'todo';
297  }
298 
305  function getLibStatut($mode=0)
306  {
307  return $this->LibStatut($this->status,$mode);
308  }
309 
317  static function LibStatut($status,$mode=0)
318  {
319  global $langs;
320 
321  if ($mode == 0)
322  {
323  $prefix='';
324  if ($status == 1) return $langs->trans('Enabled');
325  if ($status == 0) return $langs->trans('Disabled');
326  }
327  if ($mode == 1)
328  {
329  if ($status == 1) return $langs->trans('Enabled');
330  if ($status == 0) return $langs->trans('Disabled');
331  }
332  if ($mode == 2)
333  {
334  if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
335  if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
336  }
337  if ($mode == 3)
338  {
339  if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
340  if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
341  }
342  if ($mode == 4)
343  {
344  if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
345  if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
346  }
347  if ($mode == 5)
348  {
349  if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
350  if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
351  }
352  if ($mode == 6)
353  {
354  if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
355  if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
356  }
357  }
358 
365  function info($id)
366  {
367  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
368  $sql.= ' fk_user_creat, fk_user_modif';
369  $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
370  $sql.= ' WHERE t.rowid = '.$id;
371  $result=$this->db->query($sql);
372  if ($result)
373  {
374  if ($this->db->num_rows($result))
375  {
376  $obj = $this->db->fetch_object($result);
377  $this->id = $obj->rowid;
378  if ($obj->fk_user_author)
379  {
380  $cuser = new User($this->db);
381  $cuser->fetch($obj->fk_user_author);
382  $this->user_creation = $cuser;
383  }
384 
385  if ($obj->fk_user_valid)
386  {
387  $vuser = new User($this->db);
388  $vuser->fetch($obj->fk_user_valid);
389  $this->user_validation = $vuser;
390  }
391 
392  if ($obj->fk_user_cloture)
393  {
394  $cluser = new User($this->db);
395  $cluser->fetch($obj->fk_user_cloture);
396  $this->user_cloture = $cluser;
397  }
398 
399  $this->date_creation = $this->db->jdate($obj->datec);
400  $this->date_modification = $this->db->jdate($obj->datem);
401  $this->date_validation = $this->db->jdate($obj->datev);
402  }
403 
404  $this->db->free($result);
405 
406  }
407  else
408  {
409  dol_print_error($this->db);
410  }
411  }
412 
419  public function initAsSpecimen()
420  {
421  $this->initAsSpecimenCommon();
422  }
423 
424 }
425 
429 /*
430 class EmailSenderProfileLine
431 {
432  // @var int ID
433  public $id;
434  // @var mixed Sample line property 1
435  public $prop1;
436  // @var mixed Sample line property 2
437  public $prop2;
438 }
439 */
getDirectExternalLink($withpicto=0)
Return link to download file from a direct external access.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
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:39
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...
fetchCommon($id, $ref=null)
Load object in memory from the database.
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'un user (actif, inactif)
info($id)
Charge les informations d'ordre info dans l'objet commande.
updateCommon(User $user, $notrigger=false)
Update object into database.
createFromClone(User $user, $fromid)
Clone and object into another one.
deleteCommon(User $user, $notrigger=false)
Delete object in database.
Class for EmailSenderProfile.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)