dolibarr  16.0.5
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 (empty($conf->multicompany->enabled) && 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  if (empty($this->type)) {
162  $langs->load("errors");
163  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
164  return -1;
165  }
166  if (!in_array($this->type, array('seen', 'unseen', 'unanswered', 'answered', 'withtrackingidinmsgid', 'withouttrackingidinmsgid', 'withtrackingid', 'withouttrackingid', 'isanswer', 'isnotanswer')) && empty($this->rulevalue)) {
167  $langs->load("errors");
168  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("SearchString"));
169  return -2;
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  //var_dump($key);
211  //var_dump($clonedObj->array_options[$key]); exit;
212  unset($object->array_options[$key]);
213  }
214  }
215  }
216 
217  // Create clone
218  $object->context['createfromclone'] = 'createfromclone';
219  $result = $object->createCommon($user);
220  if ($result < 0) {
221  $error++;
222  $this->error = $object->error;
223  $this->errors = $object->errors;
224  }
225 
226  unset($object->context['createfromclone']);
227 
228  // End
229  if (!$error) {
230  $this->db->commit();
231  return $object;
232  } else {
233  $this->db->rollback();
234  return -1;
235  }
236  }
237 
245  public function fetch($id, $ref = null)
246  {
247  $result = $this->fetchCommon($id, $ref);
248  if ($result > 0 && !empty($this->table_element_line)) {
249  $this->fetchLines();
250  }
251  return $result;
252  }
253 
259  /*public function fetchLines()
260  {
261  $this->lines=array();
262 
263  // Load lines with object EmailcollectorFilterLine
264 
265  return count($this->lines)?1:0;
266  }*/
267 
275  public function update(User $user, $notrigger = false)
276  {
277  return $this->updateCommon($user, $notrigger);
278  }
279 
287  public function delete(User $user, $notrigger = false)
288  {
289  return $this->deleteCommon($user, $notrigger);
290  }
291 
302  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
303  {
304  global $db, $conf, $langs, $hookmanager;
305  global $dolibarr_main_authentication, $dolibarr_main_demo;
306  global $menumanager;
307 
308  if (!empty($conf->dol_no_mouse_hover)) {
309  $notooltip = 1; // Force disable tooltips
310  }
311 
312  $result = '';
313  $companylink = '';
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 && 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 (!empty($conf->global->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', '', 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 == 3) {
418  if ($status == 1) {
419  return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
420  } elseif ($status == 0) {
421  return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
422  }
423  } elseif ($mode == 4) {
424  if ($status == 1) {
425  return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
426  } elseif ($status == 0) {
427  return img_picto($this->labelStatus[$status], 'statut5', '', false, 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', '', false, 0, 0, '', 'valignmiddle');
432  } elseif ($status == 0) {
433  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
434  }
435  } elseif ($mode == 6) {
436  if ($status == 1) {
437  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
438  } elseif ($status == 0) {
439  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
440  }
441  }
442  }
443 
450  public function info($id)
451  {
452  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
453  $sql .= ' fk_user_creat, fk_user_modif';
454  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
455  $sql .= ' WHERE t.rowid = '.((int) $id);
456  $result = $this->db->query($sql);
457  if ($result) {
458  if ($this->db->num_rows($result)) {
459  $obj = $this->db->fetch_object($result);
460  $this->id = $obj->rowid;
461 
462  $this->user_creation_id = $obj->fk_user_creat;
463  $this->user_modification_id = $obj->fk_user_modif;
464  $this->date_creation = $this->db->jdate($obj->datec);
465  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
466  }
467 
468  $this->db->free($result);
469  } else {
470  dol_print_error($this->db);
471  }
472  }
473 
480  public function initAsSpecimen()
481  {
482  $this->initAsSpecimenCommon();
483  }
484 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
EmailCollectorFilter\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: emailcollectorfilter.class.php:480
db
$conf db
API class for accounts.
Definition: inc.php:41
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
EmailCollectorFilter\update
update(User $user, $notrigger=false)
Load object lines in memory from the database.
Definition: emailcollectorfilter.class.php:275
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
EmailCollectorFilter\getLibStatut
getLibStatut($mode=0)
Return label of the status.
Definition: emailcollectorfilter.class.php:384
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
EmailCollectorFilter\info
info($id)
Charge les informations d'ordre info dans l'objet commande.
Definition: emailcollectorfilter.class.php:450
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
EmailCollectorFilter
Class for EmailCollectorFilter.
Definition: emailcollectorfilter.class.php:33
CommonObject\initAsSpecimenCommon
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: commonobject.class.php:9733
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
EmailCollectorFilter\createFromClone
createFromClone(User $user, $fromid)
Clone and object into another one.
Definition: emailcollectorfilter.class.php:182
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
EmailCollectorFilter\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: emailcollectorfilter.class.php:302
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
EmailCollectorFilter\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: emailcollectorfilter.class.php:397
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
EmailCollectorFilter\create
create(User $user, $notrigger=false)
Create object into database.
Definition: emailcollectorfilter.class.php:158
EmailCollectorFilter\__construct
__construct(DoliDB $db)
Constructor.
Definition: emailcollectorfilter.class.php:121
User
Class to manage Dolibarr users.
Definition: user.class.php:44
EmailCollectorFilter\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: emailcollectorfilter.class.php:245
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119