dolibarr 20.0.0
emailcollectoraction.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) ---Put here your own copyright and developer email---
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29
34{
38 public $element = 'emailcollectoraction';
39
43 public $table_element = 'emailcollector_emailcollectoraction';
44
48 public $picto = 'emailcollectoraction@emailcollector';
49
50
70 // BEGIN MODULEBUILDER PROPERTIES
74 public $fields = array(
75 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => "Id",),
76 'fk_emailcollector' => array('type' => 'integer', 'label' => 'Id of emailcollector', 'foreignkey' => 'emailcollector.rowid'),
77 'type' => array('type' => 'varchar(128)', 'label' => 'Type', 'enabled' => 1, 'visible' => 1, 'position' => 10, 'notnull' => 1, 'index' => 1),
78 'actionparam' => array('type' => 'text', 'label' => 'ParamForAction', 'enabled' => 1, 'visible' => 1, 'position' => 40, 'notnull' => -1),
79 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 500, 'notnull' => 1,),
80 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'position' => 501, 'notnull' => 1,),
81 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'position' => 510, 'notnull' => 1, 'foreignkey' => 'llx_user.rowid',),
82 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'position' => 511, 'notnull' => -1,),
83 'position' => array('type' => 'integer', 'label' => 'Position', 'enabled' => 1, 'visible' => 1, 'position' => 600, 'default' => '0',),
84 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 1000, 'notnull' => -1,),
85 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 1000, 'notnull' => 1, 'default' => 1, 'arrayofkeyval' => array('0' => 'Disabled', '1' => 'Enabled')),
86 );
87 public $rowid;
88 public $fk_emailcollector;
89 public $type;
90 public $actionparam;
91
95 public $date_creation;
96
97 public $fk_user_creat;
98 public $fk_user_modif;
99 public $position;
100 public $import_key;
101 public $status;
102 // END MODULEBUILDER PROPERTIES
103
109 public function __construct(DoliDB $db)
110 {
111 global $conf, $langs;
112
113 $this->db = $db;
114
115 $this->ismultientitymanaged = 0;
116 $this->isextrafieldmanaged = 0;
117
118 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
119 $this->fields['rowid']['visible'] = 0;
120 }
121 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
122 $this->fields['entity']['enabled'] = 0;
123 }
124
125 // Unset fields that are disabled
126 foreach ($this->fields as $key => $val) {
127 if (isset($val['enabled']) && empty($val['enabled'])) {
128 unset($this->fields[$key]);
129 }
130 }
131
132 // Translate some data of arrayofkeyval
133 foreach ($this->fields as $key => $val) {
134 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
135 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
136 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
137 }
138 }
139 }
140 }
141
149 public function create(User $user, $notrigger = 0)
150 {
151 global $langs;
152 if (empty($this->type)) {
153 $langs->load("errors");
154 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
155 return -1;
156 }
157
158 return $this->createCommon($user, $notrigger);
159 }
160
168 public function createFromClone(User $user, $fromid)
169 {
170 global $langs, $hookmanager, $extrafields;
171 $error = 0;
172
173 dol_syslog(__METHOD__, LOG_DEBUG);
174
175 $object = new self($this->db);
176
177 $this->db->begin();
178
179 // Load source object
180 $object->fetchCommon($fromid);
181 // Reset some properties
182 unset($object->id);
183 unset($object->fk_user_creat);
184 unset($object->import_key);
185
186 // Clear fields
187 $object->ref = "copy_of_".$object->ref;
188 // $object->title = $langs->trans("CopyOf")." ".$object->title;
189
190 // Clear extrafields that are unique
191 if (is_array($object->array_options) && count($object->array_options) > 0) {
192 $extrafields->fetch_name_optionals_label($this->table_element);
193 foreach ($object->array_options as $key => $option) {
194 $shortkey = preg_replace('/options_/', '', $key);
195 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
196 unset($object->array_options[$key]);
197 }
198 }
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
233 return $result;
234 }
235
243 public function update(User $user, $notrigger = 0)
244 {
245 return $this->updateCommon($user, $notrigger);
246 }
247
255 public function delete(User $user, $notrigger = 0)
256 {
257 return $this->deleteCommon($user, $notrigger);
258 }
259
270 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
271 {
272 global $db, $conf, $langs, $hookmanager;
273 global $dolibarr_main_authentication, $dolibarr_main_demo;
274 global $menumanager;
275
276 if (!empty($conf->dol_no_mouse_hover)) {
277 $notooltip = 1; // Force disable tooltips
278 }
279
280 $result = '';
281
282 $label = '<u>'.$langs->trans("EmailcollectorAction").'</u>';
283 $label .= '<br>';
284 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
285
286 $url = dol_buildpath('/emailcollector/emailcollectoraction_card.php', 1).'?id='.$this->id;
287
288 if ($option != 'nolink') {
289 // Add param to save lastsearch_values or not
290 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
291 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
292 $add_save_lastsearch_values = 1;
293 }
294 if ($add_save_lastsearch_values) {
295 $url .= '&save_lastsearch_values=1';
296 }
297 }
298
299 $linkclose = '';
300 if (empty($notooltip)) {
301 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
302 $label = $langs->trans("ShowEmailcollectorAction");
303 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
304 }
305 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
306 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
307
308 /*
309 $hookmanager->initHooks(array('emailcollectoractiondao'));
310 $parameters=array('id'=>$this->id);
311 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
312 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
313 */
314 } else {
315 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
316 }
317
318 $linkstart = '<a href="'.$url.'"';
319 $linkstart .= $linkclose.'>';
320 $linkend = '</a>';
321
322 $result .= $linkstart;
323 if ($withpicto) {
324 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
325 }
326 if ($withpicto != 2) {
327 $result .= $this->ref;
328 }
329 $result .= $linkend;
330 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
331
332 global $action, $hookmanager;
333 $hookmanager->initHooks(array('emailcollectoractiondao'));
334 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
335 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
336 if ($reshook > 0) {
337 $result = $hookmanager->resPrint;
338 } else {
339 $result .= $hookmanager->resPrint;
340 }
341
342 return $result;
343 }
344
351 public function getLibStatut($mode = 0)
352 {
353 return $this->LibStatut($this->status, $mode);
354 }
355
356 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
364 public function LibStatut($status, $mode = 0)
365 {
366 // phpcs:enable
367 if (empty($this->labelStatus)) {
368 global $langs;
369 //$langs->load("emailcollector");
370 $this->labelStatus[1] = $langs->trans('Enabled');
371 $this->labelStatus[0] = $langs->trans('Disabled');
372 }
373
374 if ($mode == 0) {
375 return $this->labelStatus[$status];
376 } elseif ($mode == 1) {
377 return $this->labelStatus[$status];
378 } elseif ($mode == 2) {
379 if ($status == 1) {
380 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
381 } elseif ($status == 0) {
382 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
383 }
384 } elseif ($mode == 3) {
385 if ($status == 1) {
386 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
387 } elseif ($status == 0) {
388 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
389 }
390 } elseif ($mode == 4) {
391 if ($status == 1) {
392 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
393 } elseif ($status == 0) {
394 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
395 }
396 } elseif ($mode == 5) {
397 if ($status == 1) {
398 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
399 } elseif ($status == 0) {
400 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
401 }
402 } elseif ($mode == 6) {
403 if ($status == 1) {
404 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
405 } elseif ($status == 0) {
406 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
407 }
408 }
409 return "";
410 }
411
418 public function info($id)
419 {
420 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
421 $sql .= ' fk_user_creat, fk_user_modif';
422 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
423 $sql .= ' WHERE t.rowid = '.((int) $id);
424 $result = $this->db->query($sql);
425 if ($result) {
426 if ($this->db->num_rows($result)) {
427 $obj = $this->db->fetch_object($result);
428
429 $this->id = $obj->rowid;
430
431 $this->user_creation_id = $obj->fk_user_creat;
432 $this->user_modification_id = $obj->fk_user_modif;
433 $this->date_creation = $this->db->jdate($obj->datec);
434 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
435 }
436
437 $this->db->free($result);
438 } else {
439 dol_print_error($this->db);
440 }
441 }
442
449 public function initAsSpecimen()
450 {
451 return $this->initAsSpecimenCommon();
452 }
453}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:636
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 EmailCollectorAction.
fetch($id, $ref=null)
Load object in memory from the database.
create(User $user, $notrigger=0)
Create object into database.
LibStatut($status, $mode=0)
Return the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
__construct(DoliDB $db)
Constructor.
createFromClone(User $user, $fromid)
Clone and object into another one.
info($id)
Charge les information d'ordre info dans l'objet commande.
getLibStatut($mode=0)
Return label of the status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
update(User $user, $notrigger=0)
Update object into database.
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:139