dolibarr  17.0.4
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
26 require_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 (empty($conf->global->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  //var_dump($key);
218  //var_dump($clonedObj->array_options[$key]); exit;
219  unset($object->array_options[$key]);
220  }
221  }
222  }
223 
224  // Create clone
225  $object->context['createfromclone'] = 'createfromclone';
226  $result = $object->createCommon($user);
227  if ($result < 0) {
228  $error++;
229  $this->error = $object->error;
230  $this->errors = $object->errors;
231  }
232 
233  unset($object->context['createfromclone']);
234 
235  // End
236  if (!$error) {
237  $this->db->commit();
238  return $object;
239  } else {
240  $this->db->rollback();
241  return -1;
242  }
243  }
244 
252  public function fetch($id, $ref = null)
253  {
254  $result = $this->fetchCommon($id, $ref);
255  if ($result > 0 && !empty($this->table_element_line)) {
256  $this->fetchLines();
257  }
258  return $result;
259  }
260 
266  /*public function fetchLines()
267  {
268  $this->lines=array();
269 
270  // Load lines with object EmailcollectorFilterLine
271 
272  return count($this->lines)?1:0;
273  }*/
274 
282  public function update(User $user, $notrigger = false)
283  {
284  return $this->updateCommon($user, $notrigger);
285  }
286 
294  public function delete(User $user, $notrigger = false)
295  {
296  return $this->deleteCommon($user, $notrigger);
297  }
298 
309  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
310  {
311  global $db, $conf, $langs, $hookmanager;
312  global $dolibarr_main_authentication, $dolibarr_main_demo;
313  global $menumanager;
314 
315  if (!empty($conf->dol_no_mouse_hover)) {
316  $notooltip = 1; // Force disable tooltips
317  }
318 
319  $result = '';
320  $companylink = '';
321 
322  $label = '<u>'.$langs->trans("EmailcollectorFilter").'</u>';
323  $label .= '<br>';
324  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
325 
326  $url = dol_buildpath('/emailcollector/emailcollectorfilter_card.php', 1).'?id='.$this->id;
327 
328  if ($option != 'nolink') {
329  // Add param to save lastsearch_values or not
330  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
331  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
332  $add_save_lastsearch_values = 1;
333  }
334  if ($add_save_lastsearch_values) {
335  $url .= '&save_lastsearch_values=1';
336  }
337  }
338 
339  $linkclose = '';
340  if (empty($notooltip)) {
341  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
342  $label = $langs->trans("ShowEmailcollectorFilter");
343  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
344  }
345  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
346  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
347 
348  /*
349  $hookmanager->initHooks(array('emailcollectorfilterdao'));
350  $parameters=array('id'=>$this->id);
351  $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
352  if ($reshook > 0) $linkclose = $hookmanager->resPrint;
353  */
354  } else {
355  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
356  }
357 
358  $linkstart = '<a href="'.$url.'"';
359  $linkstart .= $linkclose.'>';
360  $linkend = '</a>';
361 
362  $result .= $linkstart;
363  if ($withpicto) {
364  $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);
365  }
366  if ($withpicto != 2) {
367  $result .= $this->ref;
368  }
369  $result .= $linkend;
370  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
371 
372  global $action, $hookmanager;
373  $hookmanager->initHooks(array('emailcollectorfilterdao'));
374  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
375  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
376  if ($reshook > 0) {
377  $result = $hookmanager->resPrint;
378  } else {
379  $result .= $hookmanager->resPrint;
380  }
381 
382  return $result;
383  }
384 
391  public function getLibStatut($mode = 0)
392  {
393  return $this->LibStatut($this->status, $mode);
394  }
395 
396  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
404  public function LibStatut($status, $mode = 0)
405  {
406  // phpcs:enable
407  if (empty($this->labelStatus)) {
408  global $langs;
409  //$langs->load("emailcollector");
410  $this->labelStatus[1] = $langs->trans('Enabled');
411  $this->labelStatus[0] = $langs->trans('Disabled');
412  }
413 
414  if ($mode == 0) {
415  return $this->labelStatus[$status];
416  } elseif ($mode == 1) {
417  return $this->labelStatus[$status];
418  } elseif ($mode == 2) {
419  if ($status == 1) {
420  return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
421  } elseif ($status == 0) {
422  return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
423  }
424  } elseif ($mode == 3) {
425  if ($status == 1) {
426  return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
427  } elseif ($status == 0) {
428  return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
429  }
430  } elseif ($mode == 4) {
431  if ($status == 1) {
432  return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
433  } elseif ($status == 0) {
434  return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
435  }
436  } elseif ($mode == 5) {
437  if ($status == 1) {
438  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
439  } elseif ($status == 0) {
440  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
441  }
442  } elseif ($mode == 6) {
443  if ($status == 1) {
444  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
445  } elseif ($status == 0) {
446  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
447  }
448  }
449  }
450 
457  public function info($id)
458  {
459  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
460  $sql .= ' fk_user_creat, fk_user_modif';
461  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
462  $sql .= ' WHERE t.rowid = '.((int) $id);
463  $result = $this->db->query($sql);
464  if ($result) {
465  if ($this->db->num_rows($result)) {
466  $obj = $this->db->fetch_object($result);
467  $this->id = $obj->rowid;
468 
469  $this->user_creation_id = $obj->fk_user_creat;
470  $this->user_modification_id = $obj->fk_user_modif;
471  $this->date_creation = $this->db->jdate($obj->datec);
472  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
473  }
474 
475  $this->db->free($result);
476  } else {
477  dol_print_error($this->db);
478  }
479  }
480 
487  public function initAsSpecimen()
488  {
489  $this->initAsSpecimenCommon();
490  }
491 }
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
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.
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)
Load object lines in memory from the database.
Class to manage Dolibarr users.
Definition: user.class.php:47
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.
isModEnabled($module)
Is Dolibarr module enabled.
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:119
$conf db
API class for accounts.
Definition: inc.php:41