dolibarr 21.0.0-beta
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', 'enabled' => 0, 'visible' => 0, 'foreignkey' => 'emailcollector.rowid', 'position' => 0),
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 );
91 public $rowid;
95 public $fk_emailcollector;
99 public $type;
103 public $rulevalue;
104
108 public $fk_user_creat;
112 public $fk_user_modif;
116 public $import_key;
120 public $status;
121 // END MODULEBUILDER PROPERTIES
122
123
124
130 public function __construct(DoliDB $db)
131 {
132 global $conf, $langs;
133
134 $this->db = $db;
135
136 $this->ismultientitymanaged = 0;
137 $this->isextrafieldmanaged = 0;
138
139 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
140 $this->fields['rowid']['visible'] = 0;
141 }
142 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
143 $this->fields['entity']['enabled'] = 0;
144 }
145
146 // Unset fields that are disabled
147 foreach ($this->fields as $key => $val) {
148 if (isset($val['enabled']) && empty($val['enabled'])) {
149 unset($this->fields[$key]);
150 }
151 }
152
153 // Translate some data of arrayofkeyval
154 foreach ($this->fields as $key => $val) {
155 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
156 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
157 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
158 }
159 }
160 }
161 }
162
170 public function create(User $user, $notrigger = 0)
171 {
172 global $langs;
173
174 if (empty($this->type)) {
175 $langs->load("errors");
176 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
177 return -1;
178 }
179 if (!in_array($this->type, array('seen', 'unseen', 'unanswered', 'answered', 'withtrackingidinmsgid', 'withouttrackingidinmsgid', 'withtrackingid', 'withouttrackingid', 'isanswer', 'isnotanswer')) && empty($this->rulevalue)) {
180 $langs->load("errors");
181 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("SearchString"));
182 return -2;
183 }
184
185 if (in_array($this->type, array('to')) && strpos($this->rulevalue, '+') != false) {
186 $langs->load("errors");
187 $this->errors[] = $langs->trans("ErrorCharPlusNotSupportedByImapForSearch");
188 return -3;
189 }
190
191 return $this->createCommon($user, $notrigger);
192 }
193
201 public function createFromClone(User $user, $fromid)
202 {
203 global $langs, $hookmanager, $extrafields;
204 $error = 0;
205
206 dol_syslog(__METHOD__, LOG_DEBUG);
207
208 $object = new self($this->db);
209
210 $this->db->begin();
211
212 // Load source object
213 $object->fetchCommon($fromid);
214 // Reset some properties
215 unset($object->id);
216 unset($object->fk_user_creat);
217 unset($object->import_key);
218
219 // Clear fields
220 $object->ref = "copy_of_".$object->ref;
221 // $object->title = $langs->trans("CopyOf")." ".$object->title;
222
223 // Clear extrafields that are unique
224 if (is_array($object->array_options) && count($object->array_options) > 0) {
225 $extrafields->fetch_name_optionals_label($this->table_element);
226 foreach ($object->array_options as $key => $option) {
227 $shortkey = preg_replace('/options_/', '', $key);
228 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
229 unset($object->array_options[$key]);
230 }
231 }
232 }
233
234 // Create clone
235 $object->context['createfromclone'] = 'createfromclone';
236 $result = $object->createCommon($user);
237 if ($result < 0) {
238 $error++;
239 $this->error = $object->error;
240 $this->errors = $object->errors;
241 }
242
243 unset($object->context['createfromclone']);
244
245 // End
246 if (!$error) {
247 $this->db->commit();
248 return $object;
249 } else {
250 $this->db->rollback();
251 return -1;
252 }
253 }
254
262 public function fetch($id, $ref = null)
263 {
264 $result = $this->fetchCommon($id, $ref);
265
266 return $result;
267 }
268
276 public function update(User $user, $notrigger = 0)
277 {
278 return $this->updateCommon($user, $notrigger);
279 }
280
288 public function delete(User $user, $notrigger = 0)
289 {
290 return $this->deleteCommon($user, $notrigger);
291 }
292
303 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
304 {
305 global $db, $conf, $langs, $hookmanager;
306 global $dolibarr_main_authentication, $dolibarr_main_demo;
307 global $menumanager;
308
309 if (!empty($conf->dol_no_mouse_hover)) {
310 $notooltip = 1; // Force disable tooltips
311 }
312
313 $result = '';
314
315 $label = '<u>'.$langs->trans("EmailcollectorFilter").'</u>';
316 $label .= '<br>';
317 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
318
319 $url = dol_buildpath('/emailcollector/emailcollectorfilter_card.php', 1).'?id='.$this->id;
320
321 if ($option != 'nolink') {
322 // Add param to save lastsearch_values or not
323 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
324 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
325 $add_save_lastsearch_values = 1;
326 }
327 if ($add_save_lastsearch_values) {
328 $url .= '&save_lastsearch_values=1';
329 }
330 }
331
332 $linkclose = '';
333 if (empty($notooltip)) {
334 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
335 $label = $langs->trans("ShowEmailcollectorFilter");
336 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
337 }
338 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
339 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
340
341 /*
342 $hookmanager->initHooks(array('emailcollectorfilterdao'));
343 $parameters=array('id'=>$this->id);
344 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
345 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
346 */
347 } else {
348 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
349 }
350
351 $linkstart = '<a href="'.$url.'"';
352 $linkstart .= $linkclose.'>';
353 $linkend = '</a>';
354
355 $result .= $linkstart;
356 if ($withpicto) {
357 $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);
358 }
359 if ($withpicto != 2) {
360 $result .= $this->ref;
361 }
362 $result .= $linkend;
363 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
364
365 global $action, $hookmanager;
366 $hookmanager->initHooks(array('emailcollectorfilterdao'));
367 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
368 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
369 if ($reshook > 0) {
370 $result = $hookmanager->resPrint;
371 } else {
372 $result .= $hookmanager->resPrint;
373 }
374
375 return $result;
376 }
377
384 public function getLibStatut($mode = 0)
385 {
386 return $this->LibStatut($this->status, $mode);
387 }
388
389 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
397 public function LibStatut($status, $mode = 0)
398 {
399 // phpcs:enable
400 if (empty($this->labelStatus)) {
401 global $langs;
402 //$langs->load("emailcollector");
403 $this->labelStatus[1] = $langs->trans('Enabled');
404 $this->labelStatus[0] = $langs->trans('Disabled');
405 }
406
407 if ($mode == 0) {
408 return $this->labelStatus[$status];
409 } elseif ($mode == 1) {
410 return $this->labelStatus[$status];
411 } elseif ($mode == 2) {
412 if ($status == 1) {
413 return img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
414 } elseif ($status == 0) {
415 return img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
416 }
417 } elseif ($mode == 3) {
418 if ($status == 1) {
419 return img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle');
420 } elseif ($status == 0) {
421 return img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle');
422 }
423 } elseif ($mode == 4) {
424 if ($status == 1) {
425 return img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
426 } elseif ($status == 0) {
427 return img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
428 }
429 } elseif ($mode == 5) {
430 if ($status == 1) {
431 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle');
432 } elseif ($status == 0) {
433 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle');
434 }
435 } elseif ($mode == 6) {
436 if ($status == 1) {
437 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', 0, 0, 0, '', 'valignmiddle');
438 } elseif ($status == 0) {
439 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', 0, 0, 0, '', 'valignmiddle');
440 }
441 }
442 return "";
443 }
444
451 public function info($id)
452 {
453 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
454 $sql .= ' fk_user_creat, fk_user_modif';
455 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
456 $sql .= ' WHERE t.rowid = '.((int) $id);
457 $result = $this->db->query($sql);
458 if ($result) {
459 if ($this->db->num_rows($result)) {
460 $obj = $this->db->fetch_object($result);
461
462 $this->id = $obj->rowid;
463
464 $this->user_creation_id = $obj->fk_user_creat;
465 $this->user_modification_id = $obj->fk_user_modif;
466 $this->date_creation = $this->db->jdate($obj->datec);
467 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
468 }
469
470 $this->db->free($result);
471 } else {
472 dol_print_error($this->db);
473 }
474 }
475
482 public function initAsSpecimen()
483 {
484 return $this->initAsSpecimenCommon();
485 }
486}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
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_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 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
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149