dolibarr  21.0.0-alpha
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) 2024 Frédéric France <frederic.france@free.fr>
7  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 // Put here all includes required by your class file
30 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31 
32 
37 {
41  public $element = 'emailsenderprofile';
42 
46  public $table_element = 'c_email_senderprofile';
47 
51  public $picto = 'emailsenderprofile';
52 
53  public $fk_user_creat;
54 
55 
56  const STATUS_DISABLED = 0;
57  const STATUS_ENABLED = 1;
58 
59 
60 
85  // BEGIN MODULEBUILDER PROPERTIES
89  public $fields = array(
90  'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',),
91  'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => -1, 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'index' => 1,),
92  'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'notnull' => 1),
93  'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'visible' => 1, 'enabled' => 1, 'position' => 40, 'notnull' => -1),
94  'private' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'User', 'visible' => 1, 'enabled' => 1, 'position' => 50, 'default' => '0', 'notnull' => 1),
95  'signature' => array('type' => 'html', 'label' => 'Signature', 'visible' => 3, 'enabled' => 1, 'position' => 400, 'notnull' => -1, 'index' => 1,),
96  'position' => array('type' => 'integer', 'label' => 'Position', 'visible' => 1, 'enabled' => 1, 'position' => 405, 'notnull' => -1, 'index' => 1,),
97  'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'visible' => -1, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
98  'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'visible' => -1, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
99  'active' => array('type' => 'integer', 'label' => 'Status', 'visible' => 1, 'enabled' => 1, 'default' => 1, 'position' => 1000, 'notnull' => 1, 'index' => 1, 'arrayofkeyval' => array(0 => 'Disabled', 1 => 'Enabled')),
100  );
101 
105  public $rowid;
106 
110  public $entity;
111 
115  public $label;
116 
117  public $email;
118 
119  public $private;
120  public $signature;
121  public $position;
122  public $active;
123  // END MODULEBUILDER PROPERTIES
124 
125 
131  public function __construct(DoliDB $db)
132  {
133  global $conf;
134 
135  $this->db = $db;
136 
137  $this->ismultientitymanaged = 1;
138 
139  if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
140  $this->fields['rowid']['visible'] = 0;
141  }
142  if (!isModEnabled('multicompany')) {
143  $this->fields['entity']['enabled'] = 0;
144  }
145  }
146 
154  public function create(User $user, $notrigger = 0)
155  {
156  return $this->createCommon($user, $notrigger);
157  }
158 
166  public function createFromClone(User $user, $fromid)
167  {
168  global $hookmanager, $langs;
169  $error = 0;
170 
171  dol_syslog(__METHOD__, LOG_DEBUG);
172 
173  $object = new self($this->db);
174 
175  $this->db->begin();
176 
177  // Load source object
178  $object->fetchCommon($fromid);
179  // Reset some properties
180  unset($object->id);
181  unset($object->fk_user_creat);
182  unset($object->import_key);
183 
184  // Clear fields
185  $object->ref = "copy_of_".$object->ref;
186  $object->title = $langs->trans("CopyOf")." ".$object->title;
187  // ...
188 
189  // Create clone
190  $object->context['createfromclone'] = 'createfromclone';
191  $result = $object->createCommon($user);
192  if ($result < 0) {
193  $error++;
194  $this->error = $object->error;
195  $this->errors = $object->errors;
196  }
197 
198  unset($object->context['createfromclone']);
199 
200  // End
201  if (!$error) {
202  $this->db->commit();
203  return $object;
204  } else {
205  $this->db->rollback();
206  return -1;
207  }
208  }
209 
217  public function fetch($id, $ref = null)
218  {
219  $result = $this->fetchCommon($id, $ref);
220  if ($result > 0 && !empty($this->table_element_line)) {
221  $this->fetchLines();
222  }
223  return $result;
224  }
225 
231  public function fetchLines()
232  {
233  $this->lines = array();
234 
235  // Load lines with object EmailSenderProfileLine
236 
237  return count($this->lines) ? 1 : 0;
238  }
239 
247  public function update(User $user, $notrigger = 0)
248  {
249  return $this->updateCommon($user, $notrigger);
250  }
251 
259  public function delete(User $user, $notrigger = 0)
260  {
261  return $this->deleteCommon($user, $notrigger);
262  }
263 
270  public function getNomUrl($withpicto = 0)
271  {
272  global $db, $conf, $langs;
273  global $dolibarr_main_authentication, $dolibarr_main_demo;
274  global $menumanager;
275 
276  $result = '';
277  $companylink = '';
278 
279  $label = $this->label;
280 
281  $url = '';
282  //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
283 
284  $linkstart = '';
285  $linkend = '';
286 
287  if ($withpicto) {
288  $result .= ($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
289  if ($withpicto != 2) {
290  $result .= ' ';
291  }
292  }
293  $result .= $linkstart.$this->label.$linkend;
294  return $result;
295  }
296 
303  public function getLibStatut($mode = 0)
304  {
305  return $this->LibStatut($this->active, $mode);
306  }
307 
308  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
316  public static function LibStatut($status, $mode = 0)
317  {
318  global $langs;
319 
320  if ($status == 1) {
321  $label = $labelshort = $langs->transnoentitiesnoconv('Enabled');
322  } else {
323  $label = $labelshort = $langs->transnoentitiesnoconv('Disabled');
324  }
325 
326  $statusType = 'status'.$status;
327  if ($status == self::STATUS_ENABLED) {
328  $statusType = 'status4';
329  }
330 
331  return dolGetStatus($label, $labelshort, '', $statusType, $mode);
332  }
333 
340  public function info($id)
341  {
342  $sql = "SELECT rowid, date_creation as datec, tms as datem";
343  $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
344  $sql .= " WHERE t.rowid = ".((int) $id);
345  $result = $this->db->query($sql);
346  if ($result) {
347  if ($this->db->num_rows($result)) {
348  $obj = $this->db->fetch_object($result);
349  $this->id = $obj->rowid;
350 
351  $this->date_creation = $this->db->jdate($obj->datec);
352  $this->date_modification = $this->db->jdate($obj->datem);
353  }
354 
355  $this->db->free($result);
356  } else {
357  dol_print_error($this->db);
358  }
359  }
360 
367  public function initAsSpecimen()
368  {
369  return $this->initAsSpecimenCommon();
370  }
371 }
372 
376 /*
377 class EmailSenderProfileLine
378 {
379  // @var int ID
380  public $id;
381  // @var mixed Sample line property 1
382  public $prop1;
383  // @var mixed Sample line property 2
384  public $prop2;
385 }
386 */
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class for EmailSenderProfile.
fetchLines()
Load object lines in memory from the database.
getLibStatut($mode=0)
Return the label of a given status.
update(User $user, $notrigger=0)
Update object into database.
getNomUrl($withpicto=0)
Return a link to the object card (with optionally the picto)
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id, $ref=null)
Load object in memory from the database.
info($id)
Charge les information d'ordre info dans l'objet commande.
static LibStatut($status, $mode=0)
Return the label of a given status.
createFromClone(User $user, $fromid)
Clone and object into another one.
create(User $user, $notrigger=0)
Create object into database.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr users.
Definition: user.class.php:50
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.