26require_once DOL_DOCUMENT_ROOT.
'/core/class/doldeprecationhandler.class.php';
34 const TRIGGER_PREFIX =
'EMAILTEMPLATE';
38 public $element =
'email_template';
43 public $table_element =
'c_email_templates';
50 public $fields = array(
51 "rowid" => array(
"type" =>
"integer",
"label" =>
"TechnicalID",
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => -1,),
52 "module" => array(
"type" =>
"varchar(32)",
"label" =>
"Module",
'enabled' => 1,
'position' => 20,
'notnull' => 0,
'visible' => -1,),
53 "type_template" => array(
"type" =>
"varchar(32)",
"label" =>
"Typetemplate",
'enabled' => 1,
'position' => 25,
'notnull' => 0,
'visible' => -1,),
54 "lang" => array(
"type" =>
"varchar(6)",
"label" =>
"Lang",
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => -1,),
55 "private" => array(
"type" =>
"smallint(6)",
"label" =>
"Private",
'enabled' => 1,
'position' => 35,
'notnull' => 1,
'visible' => -1,),
56 "fk_user" => array(
"type" =>
"integer:User:user/class/user.class.php",
"label" =>
"Fkuser",
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => -1,
"css" =>
"maxwidth500 widthcentpercentminusxx",
"csslist" =>
"tdoverflowmax150",),
57 "datec" => array(
"type" =>
"datetime",
"label" =>
"DateCreation",
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => -1,),
58 "tms" => array(
"type" =>
"timestamp",
"label" =>
"DateModification",
'enabled' => 1,
'position' => 50,
'notnull' => 1,
'visible' => -1,),
59 "label" => array(
"type" =>
"varchar(255)",
"label" =>
"Label",
'enabled' => 1,
'position' => 55,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,
"css" =>
"minwidth300",
"cssview" =>
"wordbreak",
"csslist" =>
"tdoverflowmax150",),
60 "position" => array(
"type" =>
"smallint(6)",
"label" =>
"Position",
'enabled' => 1,
'position' => 60,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
61 "active" => array(
"type" =>
"integer",
"label" =>
"Active",
'enabled' => 1,
'position' => 65,
'notnull' => 1,
'visible' => -1,
'alwayseditable' => 1,),
62 "topic" => array(
"type" =>
"text",
"label" =>
"Topic",
'enabled' => 1,
'position' => 70,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
63 "content" => array(
"type" =>
"mediumtext",
"label" =>
"Content",
'enabled' => 1,
'position' => 75,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
64 "content_lines" => array(
"type" =>
"text",
"label" =>
"Contentlines",
"enabled" =>
"getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')",
'position' => 80,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
65 "enabled" => array(
"type" =>
"varchar(255)",
"label" =>
"Enabled",
'enabled' => 1,
'position' => 85,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
66 "joinfiles" => array(
"type" =>
"varchar(255)",
"label" =>
"Joinfiles",
'enabled' => 1,
'position' => 90,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
67 "email_from" => array(
"type" =>
"varchar(255)",
"label" =>
"Emailfrom",
'enabled' => 1,
'position' => 95,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
68 "email_to" => array(
"type" =>
"varchar(255)",
"label" =>
"Emailto",
'enabled' => 1,
'position' => 100,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
69 "email_tocc" => array(
"type" =>
"varchar(255)",
"label" =>
"Emailtocc",
'enabled' => 1,
'position' => 105,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
70 "email_tobcc" => array(
"type" =>
"varchar(255)",
"label" =>
"Emailtobcc",
'enabled' => 1,
'position' => 110,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
71 "defaultfortype" => array(
"type" =>
"smallint(6)",
"label" =>
"Defaultfortype",
'enabled' => 1,
'position' => 115,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
80 public $type_template;
100 public $defaultfortype;
134 public $content_lines;
188 $this->ismultientitymanaged = 1;
189 $this->isextrafieldmanaged = 1;
192 if (!
getDolGlobalInt(
'MAIN_SHOW_TECHNICAL_ID') && isset($this->fields[
'rowid']) && !empty($this->fields[
'ref'])) {
193 $this->fields[
'rowid'][
'visible'] = 0;
195 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
196 $this->fields[
'entity'][
'enabled'] = 0;
206 foreach ($this->fields as $key => $val) {
207 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
208 unset($this->fields[$key]);
213 if (is_object($langs)) {
214 foreach ($this->fields as $key => $val) {
215 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
216 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
217 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
232 public function create($user, $notrigger = 0)
237 dol_syslog(get_class($this).
"::create user=".$user->id);
240 if (!empty($this->label)) {
243 $this->error =
'ErrorLabelAlreadyExists';
244 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
245 $this->db->rollback();
254 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (entity,";
255 $sql .=
" module, type_template, lang, private, fk_user, datec, label,";
256 $sql .=
" position, defaultfortype, enabled, active, email_from, email_to,";
257 $sql .=
" email_tocc, email_tobcc, topic, joinfiles, content, content_lines)";
259 $sql .=
" ".((int)
$conf->entity).
",";
260 if (is_null($this->module)) {
263 $sql .=
" '".$this->db->escape($this->module).
"',";
265 $sql .=
" '".$this->db->escape($this->type_template).
"',";
266 if (is_null($this->lang)) {
269 $sql .=
" '".$this->db->escape($this->lang).
"',";
271 $sql .=
" ".((int) $this->
private).
",";
272 if (is_null($this->fk_user)) {
275 $sql .=
" '".((int) $this->fk_user).
"',";
277 if (is_null($this->datec)) {
278 $sql .=
" '".$this->db->idate($now).
"',";
280 $sql .=
" '".$this->db->idate($this->datec).
"',";
282 $sql .=
" '".$this->db->escape($this->label).
"',";
283 $sql .=
" ".((int) $this->
position).
", ".((int) $this->defaultfortype).
",";
284 if (is_null($this->enabled)) {
287 $sql .=
" '".((int) $this->enabled).
"',";
289 if (is_null($this->
active)) {
292 $sql .=
" '".((int) $this->
active).
"',";
294 if (is_null($this->email_from)) {
297 $sql .=
" '".$this->db->escape($this->email_from).
"',";
299 if (is_null($this->email_to)) {
302 $sql .=
" '".$this->db->escape($this->email_to).
"',";
304 if (is_null($this->email_tocc)) {
307 $sql .=
" '".$this->db->escape($this->email_tocc).
"',";
309 if (is_null($this->email_tobcc)) {
312 $sql .=
" '".$this->db->escape($this->email_tobcc).
"',";
314 $sql .=
" '".$this->db->escape($this->topic).
"',";
315 $sql .=
" ".((int) $this->joinfiles).
",";
316 if (is_null($this->content)) {
319 $sql .=
" '".((string) $this->db->escape($this->content)).
"',";
321 if (is_null($this->content_lines)) {
324 $sql .=
" '".((string) $this->db->escape($this->content_lines)).
"'";
329 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
330 $resql = $this->db->query($sql);
332 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
336 $result = $this->call_trigger(self::TRIGGER_PREFIX.
'_CREATE', $user);
347 $this->db->rollback();
351 $this->error = $this->db->lasterror();
352 $this->db->rollback();
369 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
370 $sql .=
" module=".($this->module ?
"'".$this->db->escape($this->module).
"', " :
'NULL, ');
371 $sql .=
" type_template=".($this->type_template ?
"'".$this->db->escape($this->type_template).
"', " :
'NULL, ');
372 $sql .=
" lang=".($this->lang ?
"'".$this->db->escape($this->lang).
"', " :
'NULL, ');
373 $sql .=
" private=".((int) $this->
private).
",";
374 $sql .=
" fk_user=".((int) $this->fk_user).
",";
375 $sql .=
" label=".($this->label ?
"'".$this->db->escape($this->label).
"', " :
'NULL, ');
376 $sql .=
" position=".((int) $this->
position).
",";
377 $sql .=
" defaultfortype=".((int) $this->defaultfortype).
",";
378 $sql .=
" enabled=".($this->enabled ?
"'".$this->db->escape($this->enabled).
"', " :
'NULL, ');
379 $sql .=
" active=".((int) $this->
active).
",";
380 $sql .=
" email_from=".($this->email_from ?
"'".$this->db->escape($this->email_from).
"', " :
'NULL, ');
381 $sql .=
" email_to=".($this->email_to ?
"'".$this->db->escape($this->email_to).
"', " :
'NULL, ');
382 $sql .=
" email_tocc=".($this->email_tocc ?
"'".$this->db->escape($this->email_tocc).
"', " :
'NULL, ');
383 $sql .=
" email_tobcc=".($this->email_tobcc ?
"'".$this->db->escape($this->email_tobcc).
"', " :
'NULL, ');
384 $sql .=
" topic=".($this->topic ?
"'".$this->db->escape($this->topic).
"', " :
'NULL, ');
385 $sql .=
" joinfiles=".((int) $this->joinfiles).
",";
386 $sql .=
" content=".($this->content ?
"'".$this->db->escape($this->content).
"', " :
'NULL, ');
387 $sql .=
" content_lines=".($this->content_lines ?
"'".$this->db->escape($this->content_lines).
"'" :
'NULL');
388 $sql .=
" WHERE rowid=".((int) $this->
id);
392 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
393 $resql = $this->db->query($sql);
396 $this->errors[] =
"Error ".$this->db->lasterror();
399 if (!$error && !$notrigger) {
401 $result = $this->call_trigger(self::TRIGGER_PREFIX.
'_MODIFY', $user);
410 foreach ($this->errors as $errmsg) {
411 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
412 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
414 $this->db->rollback();
429 public function delete($user, $notrigger = 0)
433 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
439 $result = $this->call_trigger(self::TRIGGER_PREFIX.
'_DELETE', $user);
448 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
449 $res = $this->db->query($sql);
452 $this->error = $this->db->lasterror();
453 $this->errors[] = $this->error;
454 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
459 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
463 $this->db->rollback();
477 public function fetch($id, $label =
null, $noextrafields = 0, $nolines = 0)
480 $result = $this->
fetchCommon($id,
'', ((!$id || $label) ?
" AND t.label = '".$this->db->escape($label).
"'" :
''), $noextrafields);
482 if ($result > 0 && !empty($this->table_element_line) && empty($nolines)) {
483 $this->fetchLines($noextrafields);
498 if (($id == 0 || empty($id)) && empty($label)) {
499 dol_syslog(get_class($this).
"::apifetch id and label are empty", LOG_DEBUG);
500 $this->error =
'id='.$id.
' and label are empty';
504 $sql =
"SELECT e.rowid, e.entity, e.module, e.type_template, e.lang,";
505 $sql .=
" e.private, e.fk_user, e.datec, e.tms, e.label, e.position,";
506 $sql .=
" e.defaultfortype, e.enabled, e.active, e.email_from, e.email_to,";
507 $sql .=
" e.email_tocc, e.email_tobcc, e.topic, e.joinfiles, e.content,";
508 $sql .=
" e.content_lines FROM ".$this->db->prefix().$this->table_element.
" as e";
510 $sql .=
" WHERE e.rowid = ".((int) $id);
512 $sql .=
" WHERE e.entity IN (".getEntity($this->table_element).
")";
514 $sql .=
" AND e.label = '".$this->db->escape($label).
"'";
518 dol_syslog(get_class($this).
"::apifetch", LOG_DEBUG);
519 $result = $this->db->query($sql);
521 $obj = $this->db->fetch_object($result);
523 $this->
id = (int) $obj->rowid;
524 $this->entity = (int) $obj->entity;
526 $this->
active = (int) $obj->active;
527 $this->content = (
string) $obj->content;
528 $this->content_lines = (
string) $obj->content_lines;
529 $this->datec = $this->db->jdate($obj->datec);
530 $this->defaultfortype = (int) $obj->defaultfortype;
531 $this->email_from = (
string) $obj->email_from;
532 $this->email_to = (
string) $obj->email_to;
533 $this->email_tobcc = (
string) $obj->email_tobcc;
534 $this->email_tocc = (
string) $obj->email_tocc;
535 $this->enabled = (
string) $obj->enabled;
536 $this->fk_user = (int) $obj->fk_user;
537 $this->joinfiles = (int) $obj->joinfiles;
538 $this->label = (
string) $obj->label;
539 $this->lang = (
string) $obj->lang;
540 $this->module = (
string) $obj->module;
541 $this->
position = (int) $obj->position;
542 $this->
private = (int) $obj->private;
543 $this->tms = $this->db->jdate($obj->tms);
544 $this->topic = (
string) $obj->topic;
545 $this->type_template = (
string) $obj->type_template;
548 $this->date_creation = $this->db->jdate($obj->datec);
553 $this->error =
'Email template with id '.((string) $id).
' not found sql='.$sql;
555 $this->error =
'Email template with label '.$label.
' not found sql='.$sql;
560 $this->error = $this->db->error();
Object of table llx_c_email_templates.
__construct(DoliDB $db)
Constructor.
create($user, $notrigger=0)
Create email template Required fields: label, type_template, topic.
apifetch($id, $label='')
Get email template from database.
fetch($id, $label=null, $noextrafields=0, $nolines=0)
Load object in memory from the database.
update(User $user, $notrigger=0)
Update database with changed email template.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
Class to manage Dolibarr database access.
Old class name for Object of table llx_c_email_templates I prefer the CEmailTemplate name as it bette...
Class to manage Dolibarr users.
dol_now($mode='gmt')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php