dolibarr 19.0.3
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 *
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//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29
34{
38 public $element = 'emailcollectorfilter';
39
43 public $table_element = 'emailcollector_emailcollectorfilter';
44
48 public $ismultientitymanaged = 0;
49
53 public $isextrafieldmanaged = 0;
54
58 public $picto = 'emailcollectorfilter@emailcollector';
59
60
80 // BEGIN MODULEBUILDER PROPERTIES
84 public $fields = array(
85 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
86 'fk_emailcollector' => array('type'=>'integer', 'label'=>'Id of emailcollector', 'foreignkey'=>'emailcollector.rowid'),
87 'type' => array('type'=>'varchar(128)', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'position'=>10, 'notnull'=>1,),
88 'rulevalue' => array('type'=>'varchar(255)', 'label'=>'ValueOfRule', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'notnull'=>-1, 'help'=>"Value of Rule",),
89 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>500, 'notnull'=>1,),
90 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>501, 'notnull'=>1,),
91 'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>510, 'notnull'=>1, 'foreignkey'=>'llx_user.rowid',),
92 'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'position'=>511, 'notnull'=>-1,),
93 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,),
94 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>1000, 'notnull'=>1, 'default'=>1, 'arrayofkeyval'=>array('0'=>'Disabled', '1'=>'Enabled')),
95 );
96 public $rowid;
97 public $fk_emailcollector;
98 public $type;
99 public $rulevalue;
100
104 public $date_creation;
105
106
107 public $tms;
108 public $fk_user_creat;
109 public $fk_user_modif;
110 public $import_key;
111 public $status;
112 // END MODULEBUILDER PROPERTIES
113
114
115
121 public function __construct(DoliDB $db)
122 {
123 global $conf, $langs;
124
125 $this->db = $db;
126
127 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
128 $this->fields['rowid']['visible'] = 0;
129 }
130 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
131 $this->fields['entity']['enabled'] = 0;
132 }
133
134 // Unset fields that are disabled
135 foreach ($this->fields as $key => $val) {
136 if (isset($val['enabled']) && empty($val['enabled'])) {
137 unset($this->fields[$key]);
138 }
139 }
140
141 // Translate some data of arrayofkeyval
142 foreach ($this->fields as $key => $val) {
143 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
144 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
145 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
146 }
147 }
148 }
149 }
150
158 public function create(User $user, $notrigger = false)
159 {
160 global $langs;
161
162 if (empty($this->type)) {
163 $langs->load("errors");
164 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
165 return -1;
166 }
167 if (!in_array($this->type, array('seen', 'unseen', 'unanswered', 'answered', 'withtrackingidinmsgid', 'withouttrackingidinmsgid', 'withtrackingid', 'withouttrackingid', 'isanswer', 'isnotanswer')) && empty($this->rulevalue)) {
168 $langs->load("errors");
169 $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("SearchString"));
170 return -2;
171 }
172
173 if (in_array($this->type, array('to')) && strpos($this->rulevalue, '+') != false) {
174 $langs->load("errors");
175 $this->errors[] = $langs->trans("ErrorCharPlusNotSupportedByImapForSearch");
176 return -3;
177 }
178
179 return $this->createCommon($user, $notrigger);
180 }
181
189 public function createFromClone(User $user, $fromid)
190 {
191 global $langs, $hookmanager, $extrafields;
192 $error = 0;
193
194 dol_syslog(__METHOD__, LOG_DEBUG);
195
196 $object = new self($this->db);
197
198 $this->db->begin();
199
200 // Load source object
201 $object->fetchCommon($fromid);
202 // Reset some properties
203 unset($object->id);
204 unset($object->fk_user_creat);
205 unset($object->import_key);
206
207 // Clear fields
208 $object->ref = "copy_of_".$object->ref;
209 // $object->title = $langs->trans("CopyOf")." ".$object->title;
210
211 // Clear extrafields that are unique
212 if (is_array($object->array_options) && count($object->array_options) > 0) {
213 $extrafields->fetch_name_optionals_label($this->table_element);
214 foreach ($object->array_options as $key => $option) {
215 $shortkey = preg_replace('/options_/', '', $key);
216 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
217 unset($object->array_options[$key]);
218 }
219 }
220 }
221
222 // Create clone
223 $object->context['createfromclone'] = 'createfromclone';
224 $result = $object->createCommon($user);
225 if ($result < 0) {
226 $error++;
227 $this->error = $object->error;
228 $this->errors = $object->errors;
229 }
230
231 unset($object->context['createfromclone']);
232
233 // End
234 if (!$error) {
235 $this->db->commit();
236 return $object;
237 } else {
238 $this->db->rollback();
239 return -1;
240 }
241 }
242
250 public function fetch($id, $ref = null)
251 {
252 $result = $this->fetchCommon($id, $ref);
253
254 return $result;
255 }
256
264 public function update(User $user, $notrigger = false)
265 {
266 return $this->updateCommon($user, $notrigger);
267 }
268
276 public function delete(User $user, $notrigger = false)
277 {
278 return $this->deleteCommon($user, $notrigger);
279 }
280
291 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
292 {
293 global $db, $conf, $langs, $hookmanager;
294 global $dolibarr_main_authentication, $dolibarr_main_demo;
295 global $menumanager;
296
297 if (!empty($conf->dol_no_mouse_hover)) {
298 $notooltip = 1; // Force disable tooltips
299 }
300
301 $result = '';
302
303 $label = '<u>'.$langs->trans("EmailcollectorFilter").'</u>';
304 $label .= '<br>';
305 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
306
307 $url = dol_buildpath('/emailcollector/emailcollectorfilter_card.php', 1).'?id='.$this->id;
308
309 if ($option != 'nolink') {
310 // Add param to save lastsearch_values or not
311 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
312 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
313 $add_save_lastsearch_values = 1;
314 }
315 if ($add_save_lastsearch_values) {
316 $url .= '&save_lastsearch_values=1';
317 }
318 }
319
320 $linkclose = '';
321 if (empty($notooltip)) {
322 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
323 $label = $langs->trans("ShowEmailcollectorFilter");
324 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
325 }
326 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
327 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
328
329 /*
330 $hookmanager->initHooks(array('emailcollectorfilterdao'));
331 $parameters=array('id'=>$this->id);
332 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
333 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
334 */
335 } else {
336 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
337 }
338
339 $linkstart = '<a href="'.$url.'"';
340 $linkstart .= $linkclose.'>';
341 $linkend = '</a>';
342
343 $result .= $linkstart;
344 if ($withpicto) {
345 $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);
346 }
347 if ($withpicto != 2) {
348 $result .= $this->ref;
349 }
350 $result .= $linkend;
351 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
352
353 global $action, $hookmanager;
354 $hookmanager->initHooks(array('emailcollectorfilterdao'));
355 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
356 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
357 if ($reshook > 0) {
358 $result = $hookmanager->resPrint;
359 } else {
360 $result .= $hookmanager->resPrint;
361 }
362
363 return $result;
364 }
365
372 public function getLibStatut($mode = 0)
373 {
374 return $this->LibStatut($this->status, $mode);
375 }
376
377 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
385 public function LibStatut($status, $mode = 0)
386 {
387 // phpcs:enable
388 if (empty($this->labelStatus)) {
389 global $langs;
390 //$langs->load("emailcollector");
391 $this->labelStatus[1] = $langs->trans('Enabled');
392 $this->labelStatus[0] = $langs->trans('Disabled');
393 }
394
395 if ($mode == 0) {
396 return $this->labelStatus[$status];
397 } elseif ($mode == 1) {
398 return $this->labelStatus[$status];
399 } elseif ($mode == 2) {
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 == 3) {
406 if ($status == 1) {
407 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
408 } elseif ($status == 0) {
409 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
410 }
411 } elseif ($mode == 4) {
412 if ($status == 1) {
413 return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
414 } elseif ($status == 0) {
415 return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
416 }
417 } elseif ($mode == 5) {
418 if ($status == 1) {
419 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
420 } elseif ($status == 0) {
421 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
422 }
423 } elseif ($mode == 6) {
424 if ($status == 1) {
425 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
426 } elseif ($status == 0) {
427 return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
428 }
429 }
430 return "";
431 }
432
439 public function info($id)
440 {
441 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
442 $sql .= ' fk_user_creat, fk_user_modif';
443 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
444 $sql .= ' WHERE t.rowid = '.((int) $id);
445 $result = $this->db->query($sql);
446 if ($result) {
447 if ($this->db->num_rows($result)) {
448 $obj = $this->db->fetch_object($result);
449
450 $this->id = $obj->rowid;
451
452 $this->user_creation_id = $obj->fk_user_creat;
453 $this->user_modification_id = $obj->fk_user_modif;
454 $this->date_creation = $this->db->jdate($obj->datec);
455 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
456 }
457
458 $this->db->free($result);
459 } else {
460 dol_print_error($this->db);
461 }
462 }
463
470 public function initAsSpecimen()
471 {
472 $this->initAsSpecimenCommon();
473 }
474}
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 EmailCollectorFilter.
create(User $user, $notrigger=false)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
info($id)
Charge les informations d'ordre info dans l'objet commande.
__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 optionaly the picto)
getLibStatut($mode=0)
Return label of the status.
createFromClone(User $user, $fromid)
Clone and object into another one.
update(User $user, $notrigger=false)
Update object into database.
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