dolibarr 20.0.0
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
96 public $date_creation;
97
98 public $fk_user_creat;
99 public $fk_user_modif;
100 public $import_key;
101 public $status;
102 // END MODULEBUILDER PROPERTIES
103
104
105
111 public function __construct(DoliDB $db)
112 {
113 global $conf, $langs;
114
115 $this->db = $db;
116
117 $this->ismultientitymanaged = 0;
118 $this->isextrafieldmanaged = 0;
119
120 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
121 $this->fields['rowid']['visible'] = 0;
122 }
123 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
124 $this->fields['entity']['enabled'] = 0;
125 }
126
127 // Unset fields that are disabled
128 foreach ($this->fields as $key => $val) {
129 if (isset($val['enabled']) && empty($val['enabled'])) {
130 unset($this->fields[$key]);
131 }
132 }
133
134 // Translate some data of arrayofkeyval
135 foreach ($this->fields as $key => $val) {
136 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
137 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
138 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
139 }
140 }
141 }
142 }
143
151 public function create(User $user, $notrigger = 0)
152 {
153 global $langs;
154
155 if (empty($this->type)) {
156 $langs->load("errors");
157 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
158 return -1;
159 }
160 if (!in_array($this->type, array('seen', 'unseen', 'unanswered', 'answered', 'withtrackingidinmsgid', 'withouttrackingidinmsgid', 'withtrackingid', 'withouttrackingid', 'isanswer', 'isnotanswer')) && empty($this->rulevalue)) {
161 $langs->load("errors");
162 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("SearchString"));
163 return -2;
164 }
165
166 if (in_array($this->type, array('to')) && strpos($this->rulevalue, '+') != false) {
167 $langs->load("errors");
168 $this->errors[] = $langs->trans("ErrorCharPlusNotSupportedByImapForSearch");
169 return -3;
170 }
171
172 return $this->createCommon($user, $notrigger);
173 }
174
182 public function createFromClone(User $user, $fromid)
183 {
184 global $langs, $hookmanager, $extrafields;
185 $error = 0;
186
187 dol_syslog(__METHOD__, LOG_DEBUG);
188
189 $object = new self($this->db);
190
191 $this->db->begin();
192
193 // Load source object
194 $object->fetchCommon($fromid);
195 // Reset some properties
196 unset($object->id);
197 unset($object->fk_user_creat);
198 unset($object->import_key);
199
200 // Clear fields
201 $object->ref = "copy_of_".$object->ref;
202 // $object->title = $langs->trans("CopyOf")." ".$object->title;
203
204 // Clear extrafields that are unique
205 if (is_array($object->array_options) && count($object->array_options) > 0) {
206 $extrafields->fetch_name_optionals_label($this->table_element);
207 foreach ($object->array_options as $key => $option) {
208 $shortkey = preg_replace('/options_/', '', $key);
209 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
210 unset($object->array_options[$key]);
211 }
212 }
213 }
214
215 // Create clone
216 $object->context['createfromclone'] = 'createfromclone';
217 $result = $object->createCommon($user);
218 if ($result < 0) {
219 $error++;
220 $this->error = $object->error;
221 $this->errors = $object->errors;
222 }
223
224 unset($object->context['createfromclone']);
225
226 // End
227 if (!$error) {
228 $this->db->commit();
229 return $object;
230 } else {
231 $this->db->rollback();
232 return -1;
233 }
234 }
235
243 public function fetch($id, $ref = null)
244 {
245 $result = $this->fetchCommon($id, $ref);
246
247 return $result;
248 }
249
257 public function update(User $user, $notrigger = 0)
258 {
259 return $this->updateCommon($user, $notrigger);
260 }
261
269 public function delete(User $user, $notrigger = 0)
270 {
271 return $this->deleteCommon($user, $notrigger);
272 }
273
284 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
285 {
286 global $db, $conf, $langs, $hookmanager;
287 global $dolibarr_main_authentication, $dolibarr_main_demo;
288 global $menumanager;
289
290 if (!empty($conf->dol_no_mouse_hover)) {
291 $notooltip = 1; // Force disable tooltips
292 }
293
294 $result = '';
295
296 $label = '<u>'.$langs->trans("EmailcollectorFilter").'</u>';
297 $label .= '<br>';
298 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
299
300 $url = dol_buildpath('/emailcollector/emailcollectorfilter_card.php', 1).'?id='.$this->id;
301
302 if ($option != 'nolink') {
303 // Add param to save lastsearch_values or not
304 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
305 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
306 $add_save_lastsearch_values = 1;
307 }
308 if ($add_save_lastsearch_values) {
309 $url .= '&save_lastsearch_values=1';
310 }
311 }
312
313 $linkclose = '';
314 if (empty($notooltip)) {
315 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
316 $label = $langs->trans("ShowEmailcollectorFilter");
317 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
318 }
319 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
320 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
321
322 /*
323 $hookmanager->initHooks(array('emailcollectorfilterdao'));
324 $parameters=array('id'=>$this->id);
325 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
326 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
327 */
328 } else {
329 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
330 }
331
332 $linkstart = '<a href="'.$url.'"';
333 $linkstart .= $linkclose.'>';
334 $linkend = '</a>';
335
336 $result .= $linkstart;
337 if ($withpicto) {
338 $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);
339 }
340 if ($withpicto != 2) {
341 $result .= $this->ref;
342 }
343 $result .= $linkend;
344 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
345
346 global $action, $hookmanager;
347 $hookmanager->initHooks(array('emailcollectorfilterdao'));
348 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
349 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
350 if ($reshook > 0) {
351 $result = $hookmanager->resPrint;
352 } else {
353 $result .= $hookmanager->resPrint;
354 }
355
356 return $result;
357 }
358
365 public function getLibStatut($mode = 0)
366 {
367 return $this->LibStatut($this->status, $mode);
368 }
369
370 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
378 public function LibStatut($status, $mode = 0)
379 {
380 // phpcs:enable
381 if (empty($this->labelStatus)) {
382 global $langs;
383 //$langs->load("emailcollector");
384 $this->labelStatus[1] = $langs->trans('Enabled');
385 $this->labelStatus[0] = $langs->trans('Disabled');
386 }
387
388 if ($mode == 0) {
389 return $this->labelStatus[$status];
390 } elseif ($mode == 1) {
391 return $this->labelStatus[$status];
392 } elseif ($mode == 2) {
393 if ($status == 1) {
394 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
395 } elseif ($status == 0) {
396 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
397 }
398 } elseif ($mode == 3) {
399 if ($status == 1) {
400 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
401 } elseif ($status == 0) {
402 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
403 }
404 } elseif ($mode == 4) {
405 if ($status == 1) {
406 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
407 } elseif ($status == 0) {
408 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
409 }
410 } elseif ($mode == 5) {
411 if ($status == 1) {
412 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
413 } elseif ($status == 0) {
414 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
415 }
416 } elseif ($mode == 6) {
417 if ($status == 1) {
418 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
419 } elseif ($status == 0) {
420 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
421 }
422 }
423 return "";
424 }
425
432 public function info($id)
433 {
434 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
435 $sql .= ' fk_user_creat, fk_user_modif';
436 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
437 $sql .= ' WHERE t.rowid = '.((int) $id);
438 $result = $this->db->query($sql);
439 if ($result) {
440 if ($this->db->num_rows($result)) {
441 $obj = $this->db->fetch_object($result);
442
443 $this->id = $obj->rowid;
444
445 $this->user_creation_id = $obj->fk_user_creat;
446 $this->user_modification_id = $obj->fk_user_modif;
447 $this->date_creation = $this->db->jdate($obj->datec);
448 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
449 }
450
451 $this->db->free($result);
452 } else {
453 dol_print_error($this->db);
454 }
455 }
456
463 public function initAsSpecimen()
464 {
465 return $this->initAsSpecimenCommon();
466 }
467}
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 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