dolibarr 20.0.2
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
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
122 public $date_creation;
123
124 public $private;
125 public $signature;
126 public $position;
127 public $active;
128 // END MODULEBUILDER PROPERTIES
129
130
136 public function __construct(DoliDB $db)
137 {
138 global $conf;
139
140 $this->db = $db;
141
142 $this->ismultientitymanaged = 1;
143
144 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
145 $this->fields['rowid']['visible'] = 0;
146 }
147 if (!isModEnabled('multicompany')) {
148 $this->fields['entity']['enabled'] = 0;
149 }
150 }
151
159 public function create(User $user, $notrigger = 0)
160 {
161 return $this->createCommon($user, $notrigger);
162 }
163
171 public function createFromClone(User $user, $fromid)
172 {
173 global $hookmanager, $langs;
174 $error = 0;
175
176 dol_syslog(__METHOD__, LOG_DEBUG);
177
178 $object = new self($this->db);
179
180 $this->db->begin();
181
182 // Load source object
183 $object->fetchCommon($fromid);
184 // Reset some properties
185 unset($object->id);
186 unset($object->fk_user_creat);
187 unset($object->import_key);
188
189 // Clear fields
190 $object->ref = "copy_of_".$object->ref;
191 $object->title = $langs->trans("CopyOf")." ".$object->title;
192 // ...
193
194 // Create clone
195 $object->context['createfromclone'] = 'createfromclone';
196 $result = $object->createCommon($user);
197 if ($result < 0) {
198 $error++;
199 $this->error = $object->error;
200 $this->errors = $object->errors;
201 }
202
203 unset($object->context['createfromclone']);
204
205 // End
206 if (!$error) {
207 $this->db->commit();
208 return $object;
209 } else {
210 $this->db->rollback();
211 return -1;
212 }
213 }
214
222 public function fetch($id, $ref = null)
223 {
224 $result = $this->fetchCommon($id, $ref);
225 if ($result > 0 && !empty($this->table_element_line)) {
226 $this->fetchLines();
227 }
228 return $result;
229 }
230
236 public function fetchLines()
237 {
238 $this->lines = array();
239
240 // Load lines with object EmailSenderProfileLine
241
242 return count($this->lines) ? 1 : 0;
243 }
244
252 public function update(User $user, $notrigger = 0)
253 {
254 return $this->updateCommon($user, $notrigger);
255 }
256
264 public function delete(User $user, $notrigger = 0)
265 {
266 return $this->deleteCommon($user, $notrigger);
267 }
268
275 public function getNomUrl($withpicto = 0)
276 {
277 global $db, $conf, $langs;
278 global $dolibarr_main_authentication, $dolibarr_main_demo;
279 global $menumanager;
280
281 $result = '';
282 $companylink = '';
283
284 $label = $this->label;
285
286 $url = '';
287 //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
288
289 $linkstart = '';
290 $linkend = '';
291
292 if ($withpicto) {
293 $result .= ($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
294 if ($withpicto != 2) {
295 $result .= ' ';
296 }
297 }
298 $result .= $linkstart.$this->label.$linkend;
299 return $result;
300 }
301
308 public function getLibStatut($mode = 0)
309 {
310 return $this->LibStatut($this->active, $mode);
311 }
312
313 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
321 public static function LibStatut($status, $mode = 0)
322 {
323 global $langs;
324
325 if ($status == 1) {
326 $label = $labelshort = $langs->transnoentitiesnoconv('Enabled');
327 } else {
328 $label = $labelshort = $langs->transnoentitiesnoconv('Disabled');
329 }
330
331 $statusType = 'status'.$status;
332 if ($status == self::STATUS_ENABLED) {
333 $statusType = 'status4';
334 }
335
336 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
337 }
338
345 public function info($id)
346 {
347 $sql = "SELECT rowid, date_creation as datec, tms as datem";
348 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
349 $sql .= " WHERE t.rowid = ".((int) $id);
350 $result = $this->db->query($sql);
351 if ($result) {
352 if ($this->db->num_rows($result)) {
353 $obj = $this->db->fetch_object($result);
354 $this->id = $obj->rowid;
355
356 $this->date_creation = $this->db->jdate($obj->datec);
357 $this->date_modification = $this->db->jdate($obj->datem);
358 }
359
360 $this->db->free($result);
361 } else {
362 dol_print_error($this->db);
363 }
364 }
365
372 public function initAsSpecimen()
373 {
374 return $this->initAsSpecimenCommon();
375 }
376}
377
381/*
382class EmailSenderProfileLine
383{
384 // @var int ID
385 public $id;
386 // @var mixed Sample line property 1
387 public $prop1;
388 // @var mixed Sample line property 2
389 public $prop2;
390}
391*/
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.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.