dolibarr  13.0.2
emailcollectoraction.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 = 'emailcollectoraction';
39 
43  public $table_element = 'emailcollector_emailcollectoraction';
44 
48  public $ismultientitymanaged = 0;
49 
53  public $isextrafieldmanaged = 0;
54 
58  public $picto = 'emailcollectoraction@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, 'index'=>1),
88  'actionparam' => array('type'=>'varchar(255)', 'label'=>'ParamForAction', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'notnull'=>-1),
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  'position' => array('type'=>'integer', 'label'=>'Position', 'enabled'=>1, 'visible'=>1, 'position'=>600, 'default'=>'0',),
94  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,),
95  'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>1000, 'notnull'=>1, 'default'=>1, 'arrayofkeyval'=>array('0'=>'Disabled', '1'=>'Enabled')),
96  );
97  public $rowid;
98  public $fk_emailcollector;
99  public $type;
100  public $actionparam;
101 
105  public $date_creation;
106 
107 
108  public $tms;
109  public $fk_user_creat;
110  public $fk_user_modif;
111  public $position;
112  public $import_key;
113  public $status;
114  // END MODULEBUILDER PROPERTIES
115 
116 
117 
118  // If this object has a subtable with lines
119 
120  // /**
121  // * @var string Name of subtable line
122  // */
123  //public $table_element_line = 'emailcollectoractiondet';
124 
125  // /**
126  // * @var string Field with ID of parent key if this field has a parent
127  // */
128  //public $fk_element = 'fk_emailcollectoraction';
129 
130  // /**
131  // * @var string Name of subtable class that manage subtable lines
132  // */
133  //public $class_element_line = 'EmailcollectorActionline';
134 
135  // /**
136  // * @var array List of child tables. To test if we can delete object.
137  // */
138  //protected $childtables=array();
139 
140  // /**
141  // * @var EmailcollectorActionLine[] Array of subtable lines
142  // */
143  //public $lines = array();
144 
145 
146 
152  public function __construct(DoliDB $db)
153  {
154  global $conf, $langs;
155 
156  $this->db = $db;
157 
158  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
159  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
160 
161  // Unset fields that are disabled
162  foreach ($this->fields as $key => $val)
163  {
164  if (isset($val['enabled']) && empty($val['enabled']))
165  {
166  unset($this->fields[$key]);
167  }
168  }
169 
170  // Translate some data of arrayofkeyval
171  foreach ($this->fields as $key => $val)
172  {
173  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval']))
174  {
175  foreach ($val['arrayofkeyval'] as $key2 => $val2)
176  {
177  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
178  }
179  }
180  }
181  }
182 
190  public function create(User $user, $notrigger = false)
191  {
192  global $langs;
193  if (empty($this->type))
194  {
195  $langs->load("errors");
196  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
197  return -1;
198  }
199 
200  return $this->createCommon($user, $notrigger);
201  }
202 
210  public function createFromClone(User $user, $fromid)
211  {
212  global $langs, $hookmanager, $extrafields;
213  $error = 0;
214 
215  dol_syslog(__METHOD__, LOG_DEBUG);
216 
217  $object = new self($this->db);
218 
219  $this->db->begin();
220 
221  // Load source object
222  $object->fetchCommon($fromid);
223  // Reset some properties
224  unset($object->id);
225  unset($object->fk_user_creat);
226  unset($object->import_key);
227 
228  // Clear fields
229  $object->ref = "copy_of_".$object->ref;
230  $object->title = $langs->trans("CopyOf")." ".$object->title;
231  // ...
232  // Clear extrafields that are unique
233  if (is_array($object->array_options) && count($object->array_options) > 0)
234  {
235  $extrafields->fetch_name_optionals_label($this->table_element);
236  foreach ($object->array_options as $key => $option)
237  {
238  $shortkey = preg_replace('/options_/', '', $key);
239  if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
240  {
241  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
242  unset($object->array_options[$key]);
243  }
244  }
245  }
246 
247  // Create clone
248  $object->context['createfromclone'] = 'createfromclone';
249  $result = $object->createCommon($user);
250  if ($result < 0) {
251  $error++;
252  $this->error = $object->error;
253  $this->errors = $object->errors;
254  }
255 
256  unset($object->context['createfromclone']);
257 
258  // End
259  if (!$error) {
260  $this->db->commit();
261  return $object;
262  } else {
263  $this->db->rollback();
264  return -1;
265  }
266  }
267 
275  public function fetch($id, $ref = null)
276  {
277  $result = $this->fetchCommon($id, $ref);
278  if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
279  return $result;
280  }
281 
287  /*public function fetchLines()
288  {
289  $this->lines=array();
290 
291  // Load lines with object EmailcollectorActionLine
292 
293  return count($this->lines)?1:0;
294  }*/
295 
303  public function update(User $user, $notrigger = false)
304  {
305  return $this->updateCommon($user, $notrigger);
306  }
307 
315  public function delete(User $user, $notrigger = false)
316  {
317  return $this->deleteCommon($user, $notrigger);
318  }
319 
330  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
331  {
332  global $db, $conf, $langs, $hookmanager;
333  global $dolibarr_main_authentication, $dolibarr_main_demo;
334  global $menumanager;
335 
336  if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
337 
338  $result = '';
339  $companylink = '';
340 
341  $label = '<u>'.$langs->trans("EmailcollectorAction").'</u>';
342  $label .= '<br>';
343  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
344 
345  $url = dol_buildpath('/emailcollector/emailcollectoraction_card.php', 1).'?id='.$this->id;
346 
347  if ($option != 'nolink')
348  {
349  // Add param to save lastsearch_values or not
350  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
351  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
352  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
353  }
354 
355  $linkclose = '';
356  if (empty($notooltip))
357  {
358  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
359  {
360  $label = $langs->trans("ShowEmailcollectorAction");
361  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
362  }
363  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
364  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
365 
366  /*
367  $hookmanager->initHooks(array('emailcollectoractiondao'));
368  $parameters=array('id'=>$this->id);
369  $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
370  if ($reshook > 0) $linkclose = $hookmanager->resPrint;
371  */
372  } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
373 
374  $linkstart = '<a href="'.$url.'"';
375  $linkstart .= $linkclose.'>';
376  $linkend = '</a>';
377 
378  $result .= $linkstart;
379  if ($withpicto) $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);
380  if ($withpicto != 2) $result .= $this->ref;
381  $result .= $linkend;
382  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
383 
384  global $action, $hookmanager;
385  $hookmanager->initHooks(array('emailcollectoractiondao'));
386  $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
387  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
388  if ($reshook > 0) $result = $hookmanager->resPrint;
389  else $result .= $hookmanager->resPrint;
390 
391  return $result;
392  }
393 
400  public function getLibStatut($mode = 0)
401  {
402  return $this->LibStatut($this->status, $mode);
403  }
404 
405  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
413  public function LibStatut($status, $mode = 0)
414  {
415  // phpcs:enable
416  if (empty($this->labelStatus))
417  {
418  global $langs;
419  //$langs->load("emailcollector");
420  $this->labelStatus[1] = $langs->trans('Enabled');
421  $this->labelStatus[0] = $langs->trans('Disabled');
422  }
423 
424  if ($mode == 0)
425  {
426  return $this->labelStatus[$status];
427  } elseif ($mode == 1)
428  {
429  return $this->labelStatus[$status];
430  } elseif ($mode == 2)
431  {
432  if ($status == 1) return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
433  elseif ($status == 0) return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
434  } elseif ($mode == 3)
435  {
436  if ($status == 1) return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
437  elseif ($status == 0) return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
438  } elseif ($mode == 4)
439  {
440  if ($status == 1) return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
441  elseif ($status == 0) return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
442  } elseif ($mode == 5)
443  {
444  if ($status == 1) return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
445  elseif ($status == 0) return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
446  } elseif ($mode == 6)
447  {
448  if ($status == 1) return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
449  elseif ($status == 0) return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
450  }
451  }
452 
459  public function info($id)
460  {
461  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
462  $sql .= ' fk_user_creat, fk_user_modif';
463  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
464  $sql .= ' WHERE t.rowid = '.$id;
465  $result = $this->db->query($sql);
466  if ($result)
467  {
468  if ($this->db->num_rows($result))
469  {
470  $obj = $this->db->fetch_object($result);
471  $this->id = $obj->rowid;
472  if ($obj->fk_user_author)
473  {
474  $cuser = new User($this->db);
475  $cuser->fetch($obj->fk_user_author);
476  $this->user_creation = $cuser;
477  }
478 
479  if ($obj->fk_user_valid)
480  {
481  $vuser = new User($this->db);
482  $vuser->fetch($obj->fk_user_valid);
483  $this->user_validation = $vuser;
484  }
485 
486  if ($obj->fk_user_cloture)
487  {
488  $cluser = new User($this->db);
489  $cluser->fetch($obj->fk_user_cloture);
490  $this->user_cloture = $cluser;
491  }
492 
493  $this->date_creation = $this->db->jdate($obj->datec);
494  $this->date_modification = $this->db->jdate($obj->datem);
495  $this->date_validation = $this->db->jdate($obj->datev);
496  }
497 
498  $this->db->free($result);
499  } else {
500  dol_print_error($this->db);
501  }
502  }
503 
510  public function initAsSpecimen()
511  {
512  $this->initAsSpecimenCommon();
513  }
514 }
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
update(User $user, $notrigger=false)
Load object lines in memory from the database.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage Dolibarr database access.
Class for EmailCollectorAction.
LibStatut($status, $mode=0)
Return the status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
createCommon(User $user, $notrigger=false)
Create object into database.
createFromClone(User $user, $fromid)
Clone and object into another one.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
__construct(DoliDB $db)
Constructor.
getLibStatut($mode=0)
Return label of the status.
$conf db
API class for accounts.
Definition: inc.php:54
fetch($id, $ref=null)
Load object in memory from the database.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
updateCommon(User $user, $notrigger=false)
Update object into database.
print $_SERVER["PHP_SELF"]
Edit parameters.
info($id)
Charge les informations d&#39;ordre info dans l&#39;objet commande.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
create(User $user, $notrigger=false)
Create object into database.
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.