dolibarr 21.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) 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
30require_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
56 public $fk_user_creat;
57
58
59 const STATUS_DISABLED = 0;
60 const STATUS_ENABLED = 1;
61
62
63
88 // BEGIN MODULEBUILDER PROPERTIES
92 public $fields = array(
93 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',),
94 'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => -1, 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'index' => 1,),
95 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'notnull' => 1),
96 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'visible' => 1, 'enabled' => 1, 'position' => 40, 'notnull' => -1),
97 'private' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'User', 'visible' => 1, 'enabled' => 1, 'position' => 50, 'default' => '0', 'notnull' => 1),
98 'signature' => array('type' => 'html', 'label' => 'Signature', 'visible' => 3, 'enabled' => 1, 'position' => 400, 'notnull' => -1, 'index' => 1,),
99 'position' => array('type' => 'integer', 'label' => 'Position', 'visible' => 1, 'enabled' => 1, 'position' => 405, 'notnull' => -1, 'index' => 1,),
100 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'visible' => -1, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
101 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'visible' => -1, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
102 'active' => array('type' => 'integer', 'label' => 'Status', 'visible' => 1, 'enabled' => 1, 'default' => 1, 'position' => 1000, 'notnull' => 1, 'index' => 1, 'arrayofkeyval' => array(0 => 'Disabled', 1 => 'Enabled')),
103 );
104
108 public $rowid;
109
113 public $entity;
114
118 public $label;
119
123 public $email;
124
128 public $private;
132 public $signature;
136 public $position;
140 public $active;
141 // END MODULEBUILDER PROPERTIES
142
143
149 public function __construct(DoliDB $db)
150 {
151 global $conf;
152
153 $this->db = $db;
154
155 $this->ismultientitymanaged = 1;
156
157 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
158 $this->fields['rowid']['visible'] = 0;
159 }
160 if (!isModEnabled('multicompany')) {
161 $this->fields['entity']['enabled'] = 0;
162 }
163 }
164
172 public function create(User $user, $notrigger = 0)
173 {
174 return $this->createCommon($user, $notrigger);
175 }
176
184 public function createFromClone(User $user, $fromid)
185 {
186 global $hookmanager, $langs;
187 $error = 0;
188
189 dol_syslog(__METHOD__, LOG_DEBUG);
190
191 $object = new self($this->db);
192
193 $this->db->begin();
194
195 // Load source object
196 $object->fetchCommon($fromid);
197 // Reset some properties
198 unset($object->id);
199 unset($object->fk_user_creat);
200 unset($object->import_key);
201
202 // Clear fields
203 $object->ref = "copy_of_".$object->ref;
204 $object->title = $langs->trans("CopyOf")." ".$object->title;
205 // ...
206
207 // Create clone
208 $object->context['createfromclone'] = 'createfromclone';
209 $result = $object->createCommon($user);
210 if ($result < 0) {
211 $error++;
212 $this->error = $object->error;
213 $this->errors = $object->errors;
214 }
215
216 unset($object->context['createfromclone']);
217
218 // End
219 if (!$error) {
220 $this->db->commit();
221 return $object;
222 } else {
223 $this->db->rollback();
224 return -1;
225 }
226 }
227
235 public function fetch($id, $ref = null)
236 {
237 $result = $this->fetchCommon($id, $ref);
238 if ($result > 0 && !empty($this->table_element_line)) {
239 $this->fetchLines();
240 }
241 return $result;
242 }
243
249 public function fetchLines()
250 {
251 $this->lines = array();
252
253 // Load lines with object EmailSenderProfileLine
254
255 return count($this->lines) ? 1 : 0;
256 }
257
265 public function update(User $user, $notrigger = 0)
266 {
267 return $this->updateCommon($user, $notrigger);
268 }
269
277 public function delete(User $user, $notrigger = 0)
278 {
279 return $this->deleteCommon($user, $notrigger);
280 }
281
288 public function getNomUrl($withpicto = 0)
289 {
290 global $db, $conf, $langs;
291 global $dolibarr_main_authentication, $dolibarr_main_demo;
292 global $menumanager;
293
294 $result = '';
295 $companylink = '';
296
297 $label = $this->label;
298
299 $url = '';
300 //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
301
302 $linkstart = '';
303 $linkend = '';
304
305 if ($withpicto) {
306 $result .= ($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
307 if ($withpicto != 2) {
308 $result .= ' ';
309 }
310 }
311 $result .= $linkstart.$this->label.$linkend;
312 return $result;
313 }
314
321 public function getLibStatut($mode = 0)
322 {
323 return $this->LibStatut($this->active, $mode);
324 }
325
326 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
334 public static function LibStatut($status, $mode = 0)
335 {
336 global $langs;
337
338 if ($status == 1) {
339 $label = $labelshort = $langs->transnoentitiesnoconv('Enabled');
340 } else {
341 $label = $labelshort = $langs->transnoentitiesnoconv('Disabled');
342 }
343
344 $statusType = 'status'.$status;
345 if ($status == self::STATUS_ENABLED) {
346 $statusType = 'status4';
347 }
348
349 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
350 }
351
358 public function info($id)
359 {
360 $sql = "SELECT rowid, date_creation as datec, tms as datem";
361 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
362 $sql .= " WHERE t.rowid = ".((int) $id);
363 $result = $this->db->query($sql);
364 if ($result) {
365 if ($this->db->num_rows($result)) {
366 $obj = $this->db->fetch_object($result);
367 $this->id = $obj->rowid;
368
369 $this->date_creation = $this->db->jdate($obj->datec);
370 $this->date_modification = $this->db->jdate($obj->datem);
371 }
372
373 $this->db->free($result);
374 } else {
375 dol_print_error($this->db);
376 }
377 }
378
385 public function initAsSpecimen()
386 {
387 return $this->initAsSpecimenCommon();
388 }
389}
390
394/*
395class EmailSenderProfileLine
396{
397 // @var int ID
398 public $id;
399 // @var mixed Sample line property 1
400 public $prop1;
401 // @var mixed Sample line property 2
402 public $prop2;
403}
404*/
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79