dolibarr 19.0.3
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Put here all includes required by your class file
26require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27
32{
36 public $element = 'emailcollectoraction';
37
41 public $table_element = 'emailcollector_emailcollectoraction';
42
46 public $ismultientitymanaged = 0;
47
51 public $isextrafieldmanaged = 0;
52
56 public $picto = 'emailcollectoraction@emailcollector';
57
58
78 // BEGIN MODULEBUILDER PROPERTIES
82 public $fields = array(
83 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
84 'fk_emailcollector' => array('type'=>'integer', 'label'=>'Id of emailcollector', 'foreignkey'=>'emailcollector.rowid'),
85 'type' => array('type'=>'varchar(128)', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1),
86 'actionparam' => array('type'=>'text', 'label'=>'ParamForAction', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'notnull'=>-1),
87 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>500, 'notnull'=>1,),
88 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>501, 'notnull'=>1,),
89 'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>510, 'notnull'=>1, 'foreignkey'=>'llx_user.rowid',),
90 'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'position'=>511, 'notnull'=>-1,),
91 'position' => array('type'=>'integer', 'label'=>'Position', 'enabled'=>1, 'visible'=>1, 'position'=>600, 'default'=>'0',),
92 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,),
93 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>1000, 'notnull'=>1, 'default'=>1, 'arrayofkeyval'=>array('0'=>'Disabled', '1'=>'Enabled')),
94 );
95 public $rowid;
96 public $fk_emailcollector;
97 public $type;
98 public $actionparam;
99
103 public $date_creation;
104
105
106 public $tms;
107 public $fk_user_creat;
108 public $fk_user_modif;
109 public $position;
110 public $import_key;
111 public $status;
112 // END MODULEBUILDER PROPERTIES
113
119 public function __construct(DoliDB $db)
120 {
121 global $conf, $langs;
122
123 $this->db = $db;
124
125 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
126 $this->fields['rowid']['visible'] = 0;
127 }
128 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
129 $this->fields['entity']['enabled'] = 0;
130 }
131
132 // Unset fields that are disabled
133 foreach ($this->fields as $key => $val) {
134 if (isset($val['enabled']) && empty($val['enabled'])) {
135 unset($this->fields[$key]);
136 }
137 }
138
139 // Translate some data of arrayofkeyval
140 foreach ($this->fields as $key => $val) {
141 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
142 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
143 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
144 }
145 }
146 }
147 }
148
156 public function create(User $user, $notrigger = false)
157 {
158 global $langs;
159 if (empty($this->type)) {
160 $langs->load("errors");
161 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
162 return -1;
163 }
164
165 return $this->createCommon($user, $notrigger);
166 }
167
175 public function createFromClone(User $user, $fromid)
176 {
177 global $langs, $hookmanager, $extrafields;
178 $error = 0;
179
180 dol_syslog(__METHOD__, LOG_DEBUG);
181
182 $object = new self($this->db);
183
184 $this->db->begin();
185
186 // Load source object
187 $object->fetchCommon($fromid);
188 // Reset some properties
189 unset($object->id);
190 unset($object->fk_user_creat);
191 unset($object->import_key);
192
193 // Clear fields
194 $object->ref = "copy_of_".$object->ref;
195 // $object->title = $langs->trans("CopyOf")." ".$object->title;
196
197 // Clear extrafields that are unique
198 if (is_array($object->array_options) && count($object->array_options) > 0) {
199 $extrafields->fetch_name_optionals_label($this->table_element);
200 foreach ($object->array_options as $key => $option) {
201 $shortkey = preg_replace('/options_/', '', $key);
202 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
203 unset($object->array_options[$key]);
204 }
205 }
206 }
207
208 // Create clone
209 $object->context['createfromclone'] = 'createfromclone';
210 $result = $object->createCommon($user);
211 if ($result < 0) {
212 $error++;
213 $this->error = $object->error;
214 $this->errors = $object->errors;
215 }
216
217 unset($object->context['createfromclone']);
218
219 // End
220 if (!$error) {
221 $this->db->commit();
222 return $object;
223 } else {
224 $this->db->rollback();
225 return -1;
226 }
227 }
228
236 public function fetch($id, $ref = null)
237 {
238 $result = $this->fetchCommon($id, $ref);
239
240 return $result;
241 }
242
250 public function update(User $user, $notrigger = false)
251 {
252 return $this->updateCommon($user, $notrigger);
253 }
254
262 public function delete(User $user, $notrigger = false)
263 {
264 return $this->deleteCommon($user, $notrigger);
265 }
266
277 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
278 {
279 global $db, $conf, $langs, $hookmanager;
280 global $dolibarr_main_authentication, $dolibarr_main_demo;
281 global $menumanager;
282
283 if (!empty($conf->dol_no_mouse_hover)) {
284 $notooltip = 1; // Force disable tooltips
285 }
286
287 $result = '';
288
289 $label = '<u>'.$langs->trans("EmailcollectorAction").'</u>';
290 $label .= '<br>';
291 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
292
293 $url = dol_buildpath('/emailcollector/emailcollectoraction_card.php', 1).'?id='.$this->id;
294
295 if ($option != 'nolink') {
296 // Add param to save lastsearch_values or not
297 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
298 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
299 $add_save_lastsearch_values = 1;
300 }
301 if ($add_save_lastsearch_values) {
302 $url .= '&save_lastsearch_values=1';
303 }
304 }
305
306 $linkclose = '';
307 if (empty($notooltip)) {
308 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
309 $label = $langs->trans("ShowEmailcollectorAction");
310 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
311 }
312 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
313 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
314
315 /*
316 $hookmanager->initHooks(array('emailcollectoractiondao'));
317 $parameters=array('id'=>$this->id);
318 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
319 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
320 */
321 } else {
322 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
323 }
324
325 $linkstart = '<a href="'.$url.'"';
326 $linkstart .= $linkclose.'>';
327 $linkend = '</a>';
328
329 $result .= $linkstart;
330 if ($withpicto) {
331 $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);
332 }
333 if ($withpicto != 2) {
334 $result .= $this->ref;
335 }
336 $result .= $linkend;
337 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
338
339 global $action, $hookmanager;
340 $hookmanager->initHooks(array('emailcollectoractiondao'));
341 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
342 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
343 if ($reshook > 0) {
344 $result = $hookmanager->resPrint;
345 } else {
346 $result .= $hookmanager->resPrint;
347 }
348
349 return $result;
350 }
351
358 public function getLibStatut($mode = 0)
359 {
360 return $this->LibStatut($this->status, $mode);
361 }
362
363 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
371 public function LibStatut($status, $mode = 0)
372 {
373 // phpcs:enable
374 if (empty($this->labelStatus)) {
375 global $langs;
376 //$langs->load("emailcollector");
377 $this->labelStatus[1] = $langs->trans('Enabled');
378 $this->labelStatus[0] = $langs->trans('Disabled');
379 }
380
381 if ($mode == 0) {
382 return $this->labelStatus[$status];
383 } elseif ($mode == 1) {
384 return $this->labelStatus[$status];
385 } elseif ($mode == 2) {
386 if ($status == 1) {
387 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
388 } elseif ($status == 0) {
389 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
390 }
391 } elseif ($mode == 3) {
392 if ($status == 1) {
393 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
394 } elseif ($status == 0) {
395 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
396 }
397 } elseif ($mode == 4) {
398 if ($status == 1) {
399 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
400 } elseif ($status == 0) {
401 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
402 }
403 } elseif ($mode == 5) {
404 if ($status == 1) {
405 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
406 } elseif ($status == 0) {
407 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
408 }
409 } elseif ($mode == 6) {
410 if ($status == 1) {
411 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
412 } elseif ($status == 0) {
413 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
414 }
415 }
416 return "";
417 }
418
425 public function info($id)
426 {
427 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
428 $sql .= ' fk_user_creat, fk_user_modif';
429 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
430 $sql .= ' WHERE t.rowid = '.((int) $id);
431 $result = $this->db->query($sql);
432 if ($result) {
433 if ($this->db->num_rows($result)) {
434 $obj = $this->db->fetch_object($result);
435
436 $this->id = $obj->rowid;
437
438 $this->user_creation_id = $obj->fk_user_creat;
439 $this->user_modification_id = $obj->fk_user_modif;
440 $this->date_creation = $this->db->jdate($obj->datec);
441 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
442 }
443
444 $this->db->free($result);
445 } else {
446 dol_print_error($this->db);
447 }
448 }
449
456 public function initAsSpecimen()
457 {
458 $this->initAsSpecimenCommon();
459 }
460}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
Class to manage Dolibarr database access.
Class for EmailCollectorAction.
fetch($id, $ref=null)
Load object in memory from the database.
update(User $user, $notrigger=false)
Update object into database.
LibStatut($status, $mode=0)
Return the status.
create(User $user, $notrigger=false)
Create object into database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
__construct(DoliDB $db)
Constructor.
createFromClone(User $user, $fromid)
Clone and object into another one.
info($id)
Charge les informations 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.
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $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.
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:121