dolibarr  16.0.5
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'])) {
159  $this->fields['rowid']['visible'] = 0;
160  }
161  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
162  $this->fields['entity']['enabled'] = 0;
163  }
164 
165  // Unset fields that are disabled
166  foreach ($this->fields as $key => $val) {
167  if (isset($val['enabled']) && empty($val['enabled'])) {
168  unset($this->fields[$key]);
169  }
170  }
171 
172  // Translate some data of arrayofkeyval
173  foreach ($this->fields as $key => $val) {
174  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
175  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
176  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
177  }
178  }
179  }
180  }
181 
189  public function create(User $user, $notrigger = false)
190  {
191  global $langs;
192  if (empty($this->type)) {
193  $langs->load("errors");
194  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
195  return -1;
196  }
197 
198  return $this->createCommon($user, $notrigger);
199  }
200 
208  public function createFromClone(User $user, $fromid)
209  {
210  global $langs, $hookmanager, $extrafields;
211  $error = 0;
212 
213  dol_syslog(__METHOD__, LOG_DEBUG);
214 
215  $object = new self($this->db);
216 
217  $this->db->begin();
218 
219  // Load source object
220  $object->fetchCommon($fromid);
221  // Reset some properties
222  unset($object->id);
223  unset($object->fk_user_creat);
224  unset($object->import_key);
225 
226  // Clear fields
227  $object->ref = "copy_of_".$object->ref;
228  $object->title = $langs->trans("CopyOf")." ".$object->title;
229  // ...
230  // Clear extrafields that are unique
231  if (is_array($object->array_options) && count($object->array_options) > 0) {
232  $extrafields->fetch_name_optionals_label($this->table_element);
233  foreach ($object->array_options as $key => $option) {
234  $shortkey = preg_replace('/options_/', '', $key);
235  if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
236  //var_dump($key);
237  //var_dump($clonedObj->array_options[$key]); exit;
238  unset($object->array_options[$key]);
239  }
240  }
241  }
242 
243  // Create clone
244  $object->context['createfromclone'] = 'createfromclone';
245  $result = $object->createCommon($user);
246  if ($result < 0) {
247  $error++;
248  $this->error = $object->error;
249  $this->errors = $object->errors;
250  }
251 
252  unset($object->context['createfromclone']);
253 
254  // End
255  if (!$error) {
256  $this->db->commit();
257  return $object;
258  } else {
259  $this->db->rollback();
260  return -1;
261  }
262  }
263 
271  public function fetch($id, $ref = null)
272  {
273  $result = $this->fetchCommon($id, $ref);
274  // if ($result > 0 && !empty($this->table_element_line)) {
275  // $this->fetchLinesCommon();
276  // }
277  return $result;
278  }
279 
285  /*public function fetchLines()
286  {
287  $this->lines=array();
288 
289  // Load lines with object EmailcollectorActionLine
290 
291  return count($this->lines)?1:0;
292  }*/
293 
301  public function update(User $user, $notrigger = false)
302  {
303  return $this->updateCommon($user, $notrigger);
304  }
305 
313  public function delete(User $user, $notrigger = false)
314  {
315  return $this->deleteCommon($user, $notrigger);
316  }
317 
328  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
329  {
330  global $db, $conf, $langs, $hookmanager;
331  global $dolibarr_main_authentication, $dolibarr_main_demo;
332  global $menumanager;
333 
334  if (!empty($conf->dol_no_mouse_hover)) {
335  $notooltip = 1; // Force disable tooltips
336  }
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  // Add param to save lastsearch_values or not
349  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
350  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
351  $add_save_lastsearch_values = 1;
352  }
353  if ($add_save_lastsearch_values) {
354  $url .= '&save_lastsearch_values=1';
355  }
356  }
357 
358  $linkclose = '';
359  if (empty($notooltip)) {
360  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
361  $label = $langs->trans("ShowEmailcollectorAction");
362  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
363  }
364  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
365  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
366 
367  /*
368  $hookmanager->initHooks(array('emailcollectoractiondao'));
369  $parameters=array('id'=>$this->id);
370  $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
371  if ($reshook > 0) $linkclose = $hookmanager->resPrint;
372  */
373  } else {
374  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
375  }
376 
377  $linkstart = '<a href="'.$url.'"';
378  $linkstart .= $linkclose.'>';
379  $linkend = '</a>';
380 
381  $result .= $linkstart;
382  if ($withpicto) {
383  $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);
384  }
385  if ($withpicto != 2) {
386  $result .= $this->ref;
387  }
388  $result .= $linkend;
389  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
390 
391  global $action, $hookmanager;
392  $hookmanager->initHooks(array('emailcollectoractiondao'));
393  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
394  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
395  if ($reshook > 0) {
396  $result = $hookmanager->resPrint;
397  } else {
398  $result .= $hookmanager->resPrint;
399  }
400 
401  return $result;
402  }
403 
410  public function getLibStatut($mode = 0)
411  {
412  return $this->LibStatut($this->status, $mode);
413  }
414 
415  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
423  public function LibStatut($status, $mode = 0)
424  {
425  // phpcs:enable
426  if (empty($this->labelStatus)) {
427  global $langs;
428  //$langs->load("emailcollector");
429  $this->labelStatus[1] = $langs->trans('Enabled');
430  $this->labelStatus[0] = $langs->trans('Disabled');
431  }
432 
433  if ($mode == 0) {
434  return $this->labelStatus[$status];
435  } elseif ($mode == 1) {
436  return $this->labelStatus[$status];
437  } elseif ($mode == 2) {
438  if ($status == 1) {
439  return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
440  } elseif ($status == 0) {
441  return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
442  }
443  } elseif ($mode == 3) {
444  if ($status == 1) {
445  return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
446  } elseif ($status == 0) {
447  return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
448  }
449  } elseif ($mode == 4) {
450  if ($status == 1) {
451  return img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
452  } elseif ($status == 0) {
453  return img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelStatus[$status];
454  }
455  } elseif ($mode == 5) {
456  if ($status == 1) {
457  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
458  } elseif ($status == 0) {
459  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
460  }
461  } elseif ($mode == 6) {
462  if ($status == 1) {
463  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut4', '', false, 0, 0, '', 'valignmiddle');
464  } elseif ($status == 0) {
465  return $this->labelStatus[$status].' '.img_picto($this->labelStatus[$status], 'statut5', '', false, 0, 0, '', 'valignmiddle');
466  }
467  }
468  }
469 
476  public function info($id)
477  {
478  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
479  $sql .= ' fk_user_creat, fk_user_modif';
480  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
481  $sql .= ' WHERE t.rowid = '.((int) $id);
482  $result = $this->db->query($sql);
483  if ($result) {
484  if ($this->db->num_rows($result)) {
485  $obj = $this->db->fetch_object($result);
486  $this->id = $obj->rowid;
487 
488  $this->user_creation_id = $obj->fk_user_creat;
489  $this->user_modification_id = $obj->fk_user_modif;
490  $this->date_creation = $this->db->jdate($obj->datec);
491  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
492  }
493 
494  $this->db->free($result);
495  } else {
496  dol_print_error($this->db);
497  }
498  }
499 
506  public function initAsSpecimen()
507  {
508  $this->initAsSpecimenCommon();
509  }
510 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
EmailCollectorAction\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: emailcollectoraction.class.php:506
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
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
EmailCollectorAction
Class for EmailCollectorAction.
Definition: emailcollectoraction.class.php:33
EmailCollectorAction\createFromClone
createFromClone(User $user, $fromid)
Clone and object into another one.
Definition: emailcollectoraction.class.php:208
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
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
EmailCollectorAction\__construct
__construct(DoliDB $db)
Constructor.
Definition: emailcollectoraction.class.php:152
EmailCollectorAction\update
update(User $user, $notrigger=false)
Load object lines in memory from the database.
Definition: emailcollectoraction.class.php:301
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
EmailCollectorAction\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: emailcollectoraction.class.php:423
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
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
EmailCollectorAction\getLibStatut
getLibStatut($mode=0)
Return label of the status.
Definition: emailcollectoraction.class.php:410
EmailCollectorAction\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: emailcollectoraction.class.php:271
EmailCollectorAction\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: emailcollectoraction.class.php:328
EmailCollectorAction\info
info($id)
Charge les informations d'ordre info dans l'objet commande.
Definition: emailcollectoraction.class.php:476
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
User
Class to manage Dolibarr users.
Definition: user.class.php:44
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
EmailCollectorAction\create
create(User $user, $notrigger=false)
Create object into database.
Definition: emailcollectoraction.class.php:189
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119