dolibarr 21.0.0-alpha
emailcollectorfilter.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//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31
36{
40 public $element = 'emailcollectorfilter';
41
45 public $table_element = 'emailcollector_emailcollectorfilter';
46
50 public $picto = 'emailcollectorfilter@emailcollector';
51
52
72 // BEGIN MODULEBUILDER PROPERTIES
76 public $fields = array(
77 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => "Id",),
78 'fk_emailcollector' => array('type' => 'integer', 'label' => 'Id of emailcollector', 'foreignkey' => 'emailcollector.rowid'),
79 'type' => array('type' => 'varchar(128)', 'label' => 'Type', 'enabled' => 1, 'visible' => 1, 'position' => 10, 'notnull' => 1,),
80 'rulevalue' => array('type' => 'varchar(255)', 'label' => 'ValueOfRule', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'notnull' => -1, 'help' => "Value of Rule",),
81 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 500, 'notnull' => 1,),
82 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'position' => 501, 'notnull' => 1,),
83 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'position' => 510, 'notnull' => 1, 'foreignkey' => 'llx_user.rowid',),
84 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'position' => 511, 'notnull' => -1,),
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 );
88 public $rowid;
89 public $fk_emailcollector;
90 public $type;
91 public $rulevalue;
92
93 public $fk_user_creat;
94 public $fk_user_modif;
95 public $import_key;
96 public $status;
97 // END MODULEBUILDER PROPERTIES
98
99
100
106 public function __construct(DoliDB $db)
107 {
108 global $conf, $langs;
109
110 $this->db = $db;
111
112 $this->ismultientitymanaged = 0;
113 $this->isextrafieldmanaged = 0;
114
115 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
116 $this->fields['rowid']['visible'] = 0;
117 }
118 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
119 $this->fields['entity']['enabled'] = 0;
120 }
121
122 // Unset fields that are disabled
123 foreach ($this->fields as $key => $val) {
124 if (isset($val['enabled']) && empty($val['enabled'])) {
125 unset($this->fields[$key]);
126 }
127 }
128
129 // Translate some data of arrayofkeyval
130 foreach ($this->fields as $key => $val) {
131 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
132 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
133 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
134 }
135 }
136 }
137 }
138
146 public function create(User $user, $notrigger = 0)
147 {
148 global $langs;
149
150 if (empty($this->type)) {
151 $langs->load("errors");
152 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
153 return -1;
154 }
155 if (!in_array($this->type, array('seen', 'unseen', 'unanswered', 'answered', 'withtrackingidinmsgid', 'withouttrackingidinmsgid', 'withtrackingid', 'withouttrackingid', 'isanswer', 'isnotanswer')) && empty($this->rulevalue)) {
156 $langs->load("errors");
157 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("SearchString"));
158 return -2;
159 }
160
161 if (in_array($this->type, array('to')) && strpos($this->rulevalue, '+') != false) {
162 $langs->load("errors");
163 $this->errors[] = $langs->trans("ErrorCharPlusNotSupportedByImapForSearch");
164 return -3;
165 }
166
167 return $this->createCommon($user, $notrigger);
168 }
169
177 public function createFromClone(User $user, $fromid)
178 {
179 global $langs, $hookmanager, $extrafields;
180 $error = 0;
181
182 dol_syslog(__METHOD__, LOG_DEBUG);
183
184 $object = new self($this->db);
185
186 $this->db->begin();
187
188 // Load source object
189 $object->fetchCommon($fromid);
190 // Reset some properties
191 unset($object->id);
192 unset($object->fk_user_creat);
193 unset($object->import_key);
194
195 // Clear fields
196 $object->ref = "copy_of_".$object->ref;
197 // $object->title = $langs->trans("CopyOf")." ".$object->title;
198
199 // Clear extrafields that are unique
200 if (is_array($object->array_options) && count($object->array_options) > 0) {
201 $extrafields->fetch_name_optionals_label($this->table_element);
202 foreach ($object->array_options as $key => $option) {
203 $shortkey = preg_replace('/options_/', '', $key);
204 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
205 unset($object->array_options[$key]);
206 }
207 }
208 }
209
210 // Create clone
211 $object->context['createfromclone'] = 'createfromclone';
212 $result = $object->createCommon($user);
213 if ($result < 0) {
214 $error++;
215 $this->error = $object->error;
216 $this->errors = $object->errors;
217 }
218
219 unset($object->context['createfromclone']);
220
221 // End
222 if (!$error) {
223 $this->db->commit();
224 return $object;
225 } else {
226 $this->db->rollback();
227 return -1;
228 }
229 }
230
238 public function fetch($id, $ref = null)
239 {
240 $result = $this->fetchCommon($id, $ref);
241
242 return $result;
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
279 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
280 {
281 global $db, $conf, $langs, $hookmanager;
282 global $dolibarr_main_authentication, $dolibarr_main_demo;
283 global $menumanager;
284
285 if (!empty($conf->dol_no_mouse_hover)) {
286 $notooltip = 1; // Force disable tooltips
287 }
288
289 $result = '';
290
291 $label = '<u>'.$langs->trans("EmailcollectorFilter").'</u>';
292 $label .= '<br>';
293 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
294
295 $url = dol_buildpath('/emailcollector/emailcollectorfilter_card.php', 1).'?id='.$this->id;
296
297 if ($option != 'nolink') {
298 // Add param to save lastsearch_values or not
299 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
300 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
301 $add_save_lastsearch_values = 1;
302 }
303 if ($add_save_lastsearch_values) {
304 $url .= '&save_lastsearch_values=1';
305 }
306 }
307
308 $linkclose = '';
309 if (empty($notooltip)) {
310 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
311 $label = $langs->trans("ShowEmailcollectorFilter");
312 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
313 }
314 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
315 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
316
317 /*
318 $hookmanager->initHooks(array('emailcollectorfilterdao'));
319 $parameters=array('id'=>$this->id);
320 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
321 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
322 */
323 } else {
324 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
325 }
326
327 $linkstart = '<a href="'.$url.'"';
328 $linkstart .= $linkclose.'>';
329 $linkend = '</a>';
330
331 $result .= $linkstart;
332 if ($withpicto) {
333 $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);
334 }
335 if ($withpicto != 2) {
336 $result .= $this->ref;
337 }
338 $result .= $linkend;
339 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
340
341 global $action, $hookmanager;
342 $hookmanager->initHooks(array('emailcollectorfilterdao'));
343 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
344 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
345 if ($reshook > 0) {
346 $result = $hookmanager->resPrint;
347 } else {
348 $result .= $hookmanager->resPrint;
349 }
350
351 return $result;
352 }
353
360 public function getLibStatut($mode = 0)
361 {
362 return $this->LibStatut($this->status, $mode);
363 }
364
365 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
373 public function LibStatut($status, $mode = 0)
374 {
375 // phpcs:enable
376 if (empty($this->labelStatus)) {
377 global $langs;
378 //$langs->load("emailcollector");
379 $this->labelStatus[1] = $langs->trans('Enabled');
380 $this->labelStatus[0] = $langs->trans('Disabled');
381 }
382
383 if ($mode == 0) {
384 return $this->labelStatus[$status];
385 } elseif ($mode == 1) {
386 return $this->labelStatus[$status];
387 } elseif ($mode == 2) {
388 if ($status == 1) {
389 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
390 } elseif ($status == 0) {
391 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
392 }
393 } elseif ($mode == 3) {
394 if ($status == 1) {
395 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
396 } elseif ($status == 0) {
397 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
398 }
399 } elseif ($mode == 4) {
400 if ($status == 1) {
401 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
402 } elseif ($status == 0) {
403 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
404 }
405 } elseif ($mode == 5) {
406 if ($status == 1) {
407 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
408 } elseif ($status == 0) {
409 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
410 }
411 } elseif ($mode == 6) {
412 if ($status == 1) {
413 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
414 } elseif ($status == 0) {
415 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
416 }
417 }
418 return "";
419 }
420
427 public function info($id)
428 {
429 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
430 $sql .= ' fk_user_creat, fk_user_modif';
431 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
432 $sql .= ' WHERE t.rowid = '.((int) $id);
433 $result = $this->db->query($sql);
434 if ($result) {
435 if ($this->db->num_rows($result)) {
436 $obj = $this->db->fetch_object($result);
437
438 $this->id = $obj->rowid;
439
440 $this->user_creation_id = $obj->fk_user_creat;
441 $this->user_modification_id = $obj->fk_user_modif;
442 $this->date_creation = $this->db->jdate($obj->datec);
443 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
444 }
445
446 $this->db->free($result);
447 } else {
448 dol_print_error($this->db);
449 }
450 }
451
458 public function initAsSpecimen()
459 {
460 return $this->initAsSpecimenCommon();
461 }
462}
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:626
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 EmailCollectorFilter.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
create(User $user, $notrigger=0)
Create object into database.
info($id)
Charge les information d'ordre info dans l'objet commande.
update(User $user, $notrigger=0)
Update object into database.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null)
Load object in memory from the 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)
getLibStatut($mode=0)
Return label of the status.
createFromClone(User $user, $fromid)
Clone and object into another one.
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