dolibarr 22.0.5
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 * Copyright (C) 2025 Vincent de Grandpré <vincent@de-grandpre.quebec>
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 <https://www.gnu.org/licenses/>.
20 */
21
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
35{
39 public $element = 'emailcollectoraction';
40
44 public $table_element = 'emailcollector_emailcollectoraction';
45
49 public $picto = 'emailcollectoraction@emailcollector';
50
51
71 // BEGIN MODULEBUILDER PROPERTIES
75 public $fields = array(
76 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => "Id",),
77 'fk_emailcollector' => array('type' => 'integer', 'label' => 'Id of emailcollector', 'enabled' => 1, 'visible' => 0, 'foreignkey' => 'emailcollector.rowid', 'position' => 0,),
78 'type' => array('type' => 'varchar(128)', 'label' => 'Type', 'enabled' => 1, 'visible' => 1, 'position' => 10, 'notnull' => 1, 'index' => 1),
79 'actionparam' => array('type' => 'text', 'label' => 'ParamForAction', 'enabled' => 1, 'visible' => 1, 'position' => 40, 'notnull' => -1),
80 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 500, 'notnull' => 1,),
81 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'position' => 501, 'notnull' => 1,),
82 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'position' => 510, 'notnull' => 1, 'foreignkey' => 'llx_user.rowid',),
83 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'position' => 511, 'notnull' => -1,),
84 'position' => array('type' => 'integer', 'label' => 'Position', 'enabled' => 1, 'visible' => 1, 'position' => 600, 'default' => '0',),
85 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 1000, 'notnull' => -1,),
86 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 1000, 'notnull' => 1, 'default' => '1', 'arrayofkeyval' => array(0 => 'Disabled', 1 => 'Enabled')),
87 );
91 public $rowid;
95 public $fk_emailcollector;
99 public $type;
103 public $actionparam;
104
108 public $fk_user_creat;
112 public $fk_user_modif;
116 public $position;
120 public $import_key;
124 public $status;
125 // END MODULEBUILDER PROPERTIES
126
132 public function __construct(DoliDB $db)
133 {
134 global $conf, $langs;
135
136 $this->db = $db;
137
138 $this->ismultientitymanaged = 0;
139 $this->isextrafieldmanaged = 0;
140
141 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
142 $this->fields['rowid']['visible'] = 0;
143 }
144 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
145 $this->fields['entity']['enabled'] = 0;
146 }
147
148 // Unset fields that are disabled
149 foreach ($this->fields as $key => $val) {
150 if (isset($val['enabled']) && empty($val['enabled'])) {
151 unset($this->fields[$key]);
152 }
153 }
154
155 // Translate some data of arrayofkeyval
156 foreach ($this->fields as $key => $val) {
157 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
158 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
159 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
160 }
161 }
162 }
163 }
164
172 public function create(User $user, $notrigger = 0)
173 {
174 global $langs;
175 if (empty($this->type)) {
176 $langs->load("errors");
177 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
178 return -1;
179 }
180
181 return $this->createCommon($user, $notrigger);
182 }
183
191 public function createFromClone(User $user, $fromid)
192 {
193 global $langs, $hookmanager, $extrafields;
194 $error = 0;
195
196 dol_syslog(__METHOD__, LOG_DEBUG);
197
198 $object = new self($this->db);
199
200 $this->db->begin();
201
202 // Load source object
203 $object->fetchCommon($fromid);
204 // Reset some properties
205 unset($object->id);
206 unset($object->fk_user_creat);
207 unset($object->import_key);
208
209 // Clear fields
210 $object->ref = "copy_of_".$object->ref;
211 // $object->title = $langs->trans("CopyOf")." ".$object->title;
212
213 // Clear extrafields that are unique
214 if (is_array($object->array_options) && count($object->array_options) > 0) {
215 $extrafields->fetch_name_optionals_label($this->table_element);
216 foreach ($object->array_options as $key => $option) {
217 $shortkey = preg_replace('/options_/', '', $key);
218 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
219 unset($object->array_options[$key]);
220 }
221 }
222 }
223
224 // Create clone
225 $object->context['createfromclone'] = 'createfromclone';
226 $result = $object->createCommon($user);
227 if ($result < 0) {
228 $error++;
229 $this->error = $object->error;
230 $this->errors = $object->errors;
231 }
232
233 unset($object->context['createfromclone']);
234
235 // End
236 if (!$error) {
237 $this->db->commit();
238 return $object;
239 } else {
240 $this->db->rollback();
241 return -1;
242 }
243 }
244
252 public function fetch($id, $ref = null)
253 {
254 $result = $this->fetchCommon($id, $ref);
255
256 return $result;
257 }
258
266 public function update(User $user, $notrigger = 0)
267 {
268 return $this->updateCommon($user, $notrigger);
269 }
270
278 public function delete(User $user, $notrigger = 0)
279 {
280 return $this->deleteCommon($user, $notrigger);
281 }
282
293 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
294 {
295 global $db, $conf, $langs, $hookmanager;
296 global $dolibarr_main_authentication, $dolibarr_main_demo;
297 global $menumanager;
298
299 if (!empty($conf->dol_no_mouse_hover)) {
300 $notooltip = 1; // Force disable tooltips
301 }
302
303 $result = '';
304
305 $label = '<u>'.$langs->trans("EmailcollectorAction").'</u>';
306 $label .= '<br>';
307 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
308
309 $url = dol_buildpath('/emailcollector/emailcollectoraction_card.php', 1).'?id='.$this->id;
310
311 if ($option != 'nolink') {
312 // Add param to save lastsearch_values or not
313 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
314 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
315 $add_save_lastsearch_values = 1;
316 }
317 if ($add_save_lastsearch_values) {
318 $url .= '&save_lastsearch_values=1';
319 }
320 }
321
322 $linkclose = '';
323 if (empty($notooltip)) {
324 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
325 $label = $langs->trans("ShowEmailcollectorAction");
326 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
327 }
328 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
329 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
330
331 /*
332 $hookmanager->initHooks(array('emailcollectoractiondao'));
333 $parameters=array('id'=>$this->id);
334 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
335 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
336 */
337 } else {
338 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
339 }
340
341 $linkstart = '<a href="'.$url.'"';
342 $linkstart .= $linkclose.'>';
343 $linkend = '</a>';
344
345 $result .= $linkstart;
346 if ($withpicto) {
347 $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);
348 }
349 if ($withpicto != 2) {
350 $result .= $this->ref;
351 }
352 $result .= $linkend;
353 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
354
355 global $action, $hookmanager;
356 $hookmanager->initHooks(array('emailcollectoractiondao'));
357 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
358 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
359 if ($reshook > 0) {
360 $result = $hookmanager->resPrint;
361 } else {
362 $result .= $hookmanager->resPrint;
363 }
364
365 return $result;
366 }
367
374 public function getLibStatut($mode = 0)
375 {
376 return $this->LibStatut($this->status, $mode);
377 }
378
379 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
387 public function LibStatut($status, $mode = 0)
388 {
389 // phpcs:enable
390 if (empty($this->labelStatus)) {
391 global $langs;
392 //$langs->load("emailcollector");
393 $this->labelStatus[1] = $langs->trans('Enabled');
394 $this->labelStatus[0] = $langs->trans('Disabled');
395 }
396
397 if ($mode == 0) {
398 return $this->labelStatus[$status];
399 } elseif ($mode == 1) {
400 return $this->labelStatus[$status];
401 } elseif ($mode == 2) {
402 if ($status == 1) {
403 return img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
404 } elseif ($status == 0) {
405 return img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
406 }
407 } elseif ($mode == 3) {
408 if ($status == 1) {
409 return img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle');
410 } elseif ($status == 0) {
411 return img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle');
412 }
413 } elseif ($mode == 4) {
414 if ($status == 1) {
415 return img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
416 } elseif ($status == 0) {
417 return img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
418 }
419 } elseif ($mode == 5) {
420 if ($status == 1) {
421 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle');
422 } elseif ($status == 0) {
423 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle');
424 }
425 } elseif ($mode == 6) {
426 if ($status == 1) {
427 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle');
428 } elseif ($status == 0) {
429 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle');
430 }
431 }
432 return "";
433 }
434
441 public function info($id)
442 {
443 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
444 $sql .= ' fk_user_creat, fk_user_modif';
445 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
446 $sql .= ' WHERE t.rowid = '.((int) $id);
447 $result = $this->db->query($sql);
448 if ($result) {
449 if ($this->db->num_rows($result)) {
450 $obj = $this->db->fetch_object($result);
451
452 $this->id = $obj->rowid;
453
454 $this->user_creation_id = $obj->fk_user_creat;
455 $this->user_modification_id = $obj->fk_user_modif;
456 $this->date_creation = $this->db->jdate($obj->datec);
457 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
458 }
459
460 $this->db->free($result);
461 } else {
462 dol_print_error($this->db);
463 }
464 }
465
472 public function initAsSpecimen()
473 {
474 return $this->initAsSpecimenCommon();
475 }
476}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (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 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
global $dolibarr_main_demo
Definition index.php:57
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158