grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* NotificationTemplateTranslation Class
**/
class NotificationTemplateTranslation extends CommonDBChild {
// From CommonDBChild
static public $itemtype = 'NotificationTemplate';
static public $items_id = 'notificationtemplates_id';
public $dohistory = true;
static function getTypeName($nb=0) {
return _n('Template translation', 'Template translations', $nb);
}
/**
* @since version 0.84
**/
function getForbiddenStandardMassiveAction() {
$forbidden = parent::getForbiddenStandardMassiveAction();
$forbidden[] = 'update';
return $forbidden;
}
/**
* @see CommonDBTM::getRawName()
**/
function getRawName() {
global $CFG_GLPI;
if ($this->getField('language') != '') {
return $CFG_GLPI['languages'][$this->getField('language')][0];
} else {
return self::getTypeName(1);
}
return '';
}
function defineTabs($options=array()) {
$ong = array();
$this->addDefaultFormTab($ong);
$this->addStandardTab('Log', $ong, $options);
return $ong;
}
function showForm($ID, $options) {
global $DB, $CFG_GLPI;
if (!Config::canUpdate()) {
return false;
}
$notificationtemplates_id = -1;
if (isset($options['notificationtemplates_id'])) {
$notificationtemplates_id = $options['notificationtemplates_id'];
}
if ($this->getFromDB($ID)) {
$notificationtemplates_id = $this->getField('notificationtemplates_id');
}
$this->initForm($ID, $options);
$template = new NotificationTemplate();
$template->getFromDB($notificationtemplates_id);
Html::initEditorSystem('content_html');
$this->showFormHeader($options);
echo "
";
echo "".NotificationTemplate::getTypeName()." ";
echo "".$template->getField('name')." ";
echo "";
$rand = mt_rand();
Ajax::createIframeModalWindow("tags".$rand,
$CFG_GLPI['root_doc']."/front/notification.tags.php?sub_type=".
$template->getField('itemtype'));
echo "".__('Show list of available tags')." ";
echo " ";
echo "";
echo "" . __('Language') . " ";
//Get all used languages
$used = self::getAllUsedLanguages($notificationtemplates_id);
if ($ID > 0) {
if (isset($used[$this->getField('language')])) {
unset($used[$this->getField('language')]);
}
}
Dropdown::showLanguages("language", array('display_emptychoice' => true,
'value' => $this->fields['language'],
'used' => $used));
echo " ";
echo "" . __('Subject') . " ";
echo "";
Html::autocompletionTextField($this,'subject', array('size' => 100));
echo " ";
echo "";
_e('Email text body');
echo " ".__('(leave the field empty for a generation from HTML)');
echo " ";
echo " ";
echo "";
echo "" ;
_e('Email HTML body');
echo " ";
echo "";
echo " ";
echo " ";
$this->showFormButtons($options);
return true;
}
/**
* @param $template NotificationTemplate object
* @param $options array
**/
function showSummary(NotificationTemplate $template, $options=array()) {
global $DB, $CFG_GLPI;
$nID = $template->getField('id');
$canedit = Config::canUpdate();
if ($canedit) {
echo " ";
}
echo "";
Session::initNavigateListItems('NotificationTemplateTranslation',
//TRANS : %1$s is the itemtype name, %2$s is the name of the item (used for headings of a list)
sprintf(__('%1$s = %2$s'),
NotificationTemplate::getTypeName(1),
$template->getName()));
if ($canedit) {
$rand = mt_rand();
Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
$massiveactionparams = array('container' => 'mass'.__CLASS__.$rand);
Html::showMassiveActions($massiveactionparams);
}
echo "
";
if ($canedit) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
}
echo "
";
}
/**
* @param $input array
*/
static function cleanContentHtml(array $input) {
$txt = Html::clean(Toolbox::unclean_cross_side_scripting_deep($input['content_html']));
$txt = trim(html_entity_decode($txt, 0, 'UTF-8'));
if (!$txt) {
// No HTML (nothing to display)
$input['content_html'] = '';
} else if (!$input['content_text']) {
// Use cleaned HTML
$input['content_text'] = $txt;
}
return $input;
}
function prepareInputForAdd($input) {
return parent::prepareInputForAdd(self::cleanContentHtml($input));
}
function prepareInputForUpdate($input) {
return parent::prepareInputForUpdate(self::cleanContentHtml($input));
}
function getSearchOptions() {
$tab = array();
$tab['common'] = __('Characteristics');
$tab[1]['table'] = $this->getTable();
$tab[1]['field'] = 'language';
$tab[1]['name'] = __('Language');
$tab[1]['datatype'] = 'language';
$tab[1]['massiveaction'] = false;
$tab[2]['table'] = $this->getTable();
$tab[2]['field'] = 'subject';
$tab[2]['name'] = __('Subject');
$tab[2]['massiveaction'] = false;
$tab[2]['datatype'] = 'string';
$tab[3]['table'] = $this->getTable();
$tab[3]['field'] = 'content_html';
$tab[3]['name'] = __('Email HTML body');
$tab[3]['datatype'] = 'text';
$tab[3]['htmltext'] = 'true';
$tab[3]['massiveaction'] = false;
$tab[4]['table'] = $this->getTable();
$tab[4]['field'] = 'content_text';
$tab[4]['name'] = __('Email text body');
$tab[4]['datatype'] = 'text';
$tab[4]['massiveaction'] = false;
return $tab;
}
/**
* @param $language_id
**/
static function getAllUsedLanguages($language_id) {
$used_languages = getAllDatasFromTable('glpi_notificationtemplatetranslations',
'notificationtemplates_id='.$language_id);
$used = array();
foreach ($used_languages as $used_language) {
$used[$used_language['language']] = $used_language['language'];
}
return $used;
}
/**
* @param $itemtype
**/
static function showAvailableTags($itemtype) {
$target = NotificationTarget::getInstanceByType($itemtype);
$target->getTags();
echo "";
echo "
";
echo "".__('Tag')."
".__('Label')."
"._n('Event', 'Events', 1)."
".__('Type')."
".__('Possible values')."
";
$tags = array();
foreach ($target->tag_descriptions as $tag_type => $infos) {
foreach ($infos as $key => $val) {
$infos[$key]['type'] = $tag_type;
}
$tags = array_merge($tags,$infos);
}
ksort($tags);
foreach ($tags as $tag => $values) {
if ($values['events'] == NotificationTarget::TAG_FOR_ALL_EVENTS) {
$event = __('All');
} else {
$event = implode(', ',$values['events']);
}
$action = '';
if ($values['foreach']) {
$action = __('List of values');
} else {
$action = __('Single value');
}
if (!empty($values['allowed_values'])) {
$allowed_values = implode(',',$values['allowed_values']);
} else {
$allowed_values = '';
}
echo "".$tag." ".
"";
if ($values['type'] == NotificationTarget::TAG_LANGUAGE) {
printf(__('%1$s: %2$s'), __('Label'), $values['label']);
} else {
echo $values['label'];
}
echo " ".$event." ".
"".$action." ".
"".$allowed_values." ".
" ";
}
echo "
";
}
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
if (!$withtemplate) {
$nb = 0;
switch ($item->getType()) {
case 'NotificationTemplate' :
if ($_SESSION['glpishow_count_on_tabs']) {
$nb = countElementsInTable($this->getTable(),
"notificationtemplates_id = '".$item->getID()."'");
}
return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb);
}
}
return '';
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
if ($item->getType() == 'NotificationTemplate') {
$temp = new self();
$temp->showSummary($item);
}
return true;
}
/**
* Display debug information for current object
* NotificationTemplateTranslation => translation preview
*
* @since version 0.84
**/
function showDebug() {
$template = new NotificationTemplate();
if (!$template->getFromDB($this->fields['notificationtemplates_id'])) {
return;
}
$itemtype = $template->getField('itemtype');
if (!($item = getItemForItemtype($itemtype))) {
return;
}
echo "";
echo "
";
echo "".__('Preview')." ";
$oktypes = array('CartridgeItem', 'Change', 'ConsumableItem', 'Contract', 'Crontask',
'Problem', 'Project', 'Ticket', 'User');
if (!in_array($itemtype, $oktypes)) {
// this itemtype doesn't work, need to be fixed
echo "".NOT_AVAILABLE." ";
echo "
";
return;
}
// Criteria Form
$key = getForeignKeyFieldForItemType($item->getType());
$id = Session::getSavedOption(__CLASS__, $key, 0);
$event = Session::getSavedOption(__CLASS__, $key.'_event', '');
echo "".$item->getTypeName(1)." ";
$item->dropdown(array('value' => $id,
'on_change' => 'reloadTab("'.$key.'="+this.value)'));
echo " ".NotificationEvent::getTypeName(1)." ";
NotificationEvent::dropdownEvents($item->getType(),
array('value' => $event,
'on_change' => 'reloadTab("'.$key.'_event="+this.value)'));
echo " ";
// Preview
if ($event
&& $item->getFromDB($id)) {
$options = array('_debug' => true);
// TODO Awfull Hack waiting for https://forge.indepnet.net/issues/3439
$multi = array('alert', 'alertnotclosed', 'end', 'notice',
'periodicity', 'periodicitynotice');
if (in_array($event, $multi)) {
// Won't work for Cardridge and Consumable
$options['entities_id'] = $item->getEntityID();
$options['items'] = array($item->getID() => $item->fields);
}
$target = NotificationTarget::getInstance($item, $event, $options);
$infos = array('language'=> $_SESSION['glpilanguage'],
'additionnaloption' => array('usertype' => NotificationTarget::GLPI_USER));
$template->resetComputedTemplates();
$template->setSignature(Notification::getMailingSignature($_SESSION['glpiactive_entity']));
if ($tid = $template->getTemplateByLanguage($target, $infos, $event, $options)) {
$data = $template->templates_by_languages[$tid];
echo "".__('Subject')." ";
echo "".$data['subject']." ";
echo "".__('Email text body')." ";
echo "".__('Email HTML body')." ";
echo "".nl2br($data['content_text'])." ";
echo "".$data['content_html']." ";
}
}
echo "";
}
}
?>