Cheetah
email_templates.php
Go to the documentation of this file.
1 <?php
2 
8 require_once('../inc/header.inc.php');
9 
10 $GLOBALS['iAdminPage'] = 1;
11 
12 require_once(CH_DIRECTORY_PATH_INC . 'profiles.inc.php');
13 require_once(CH_DIRECTORY_PATH_INC . 'design.inc.php');
14 require_once(CH_DIRECTORY_PATH_INC . 'admin_design.inc.php');
15 require_once(CH_DIRECTORY_PATH_INC . 'utils.inc.php');
16 
17 ch_import('ChWsbAdminSettings');
18 ch_import('ChTemplSearchResult');
19 
20 $logged['admin'] = member_auth(1, true, true);
21 
23 
24 //--- Process submit ---//
25 $aResults = array();
26 
27 if (isset($_POST['save']) && isset($_POST['cat'])) {
28  $aResults['settings'] = $oSettings->saveChanges($_POST);
29 } elseif (isset($_POST['action']) && $_POST['action'] == 'get_translations') {
30  $aTranslation = $GLOBALS['MySQL']->getRow("SELECT `Subject` AS `subject`, `Body` AS `body` FROM `sys_email_templates` WHERE `Name`= ? AND `LangID`= ? LIMIT ?",
31  [$_POST['templ_name'], $_POST['lang_id'], 1]);
32  if (empty($aTranslation)) {
33  $aTranslation = $GLOBALS['MySQL']->getRow("SELECT `Subject` AS `subject`, `Body` AS `body` FROM `sys_email_templates` WHERE `Name`= ? AND `LangID`= ? LIMIT ?",
34  [$_POST['templ_name'], 0, 1]);
35  }
36 
37  echo json_encode(array('subject' => $aTranslation['subject'], 'body' => $aTranslation['body']));
38  exit;
39 }
40 
42 $_page = array(
43  'name_index' => $iNameIndex,
44  'css_name' => array('forms_adv.css', 'settings.css'),
45  'js_name' => array('email_templates.js'),
46  'header' => _t('_adm_page_cpt_email_templates'),
47 );
49  'page_main_code' => PageCodeMain($aResults)
50 );
51 
53 
55 {
56  $aTopItems = array(
57  'adm-etempl-btn-list' => array(
58  'href' => 'javascript:void(0)',
59  'onclick' => 'javascript:onChangeType(this)',
60  'title' => _t('_adm_txt_email_list'),
61  'active' => empty($aResults) ? 1 : 0
62  ),
63  'adm-etempl-btn-settings' => array(
64  'href' => 'javascript:void(0)',
65  'onclick' => 'javascript:onChangeType(this)',
66  'title' => _t('_adm_txt_email_settings'),
67  'active' => isset($aResults['settings']) ? 1 : 0
68  )
69  );
70 
71  $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('email_templates.html', array(
72  'content_list' => _getList(isset($aResults['list']) ? $aResults['list'] : true, empty($aResults)),
73  'content_settings' => _getSettings(isset($aResults['settings']) ? $aResults['settings'] : true),
74  ));
75 
76  return DesignBoxAdmin(_t('_adm_box_cpt_email_templates'), $sResult, $aTopItems);
77 }
78 
79 function _getSettings($mixedResult, $bActive = false)
80 {
81  $sResult = $GLOBALS['oSettings']->getForm();
82  if ($mixedResult !== true && !empty($mixedResult)) {
83  $bActive = true;
84  $sResult = $mixedResult . $sResult;
85  }
86 
87  return $GLOBALS['oAdmTemplate']->parseHtmlByName('email_templates_settings.html', array(
88  'display' => $bActive ? 'block' : 'none',
89  'form' => $sResult
90  ));
91 }
92 
93 function _getList($mixedResult, $bActive = false)
94 {
95  $aForm = array(
96  'form_attrs' => array(
97  'id' => 'adm-email-templates',
98  'action' => $GLOBALS['site']['url_admin'] . 'email_templates.php',
99  'method' => 'post',
100  'enctype' => 'multipart/form-data',
101  ),
102  'params' => array(
103  'db' => array(
104  'table' => 'sys_email_templates',
105  'key' => 'ID',
106  'uri' => '',
107  'uri_title' => '',
108  'submit_name' => 'adm-emial-templates-save'
109  ),
110  ),
111  'inputs' => array()
112  );
113 
114  $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
115 
116  $aLanguageChooser = array(array('key' => 0, 'value' => 'default'));
117  foreach ($aLanguages as $aLanguage) {
118  $aLanguageChooser[] = array('key' => $aLanguage['id'], 'value' => $aLanguage['title']);
119  }
120 
121  $sLanguageCpt = _t('_adm_txt_email_language');
122  $sSubjectCpt = _t('_adm_txt_email_subject');
123  $sBodyCpt = _t('_adm_txt_email_body');
124 
125  $aEmails = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `name`, `Subject` AS `subject`, `Body` AS `body`, `Desc` AS `description` FROM `sys_email_templates` WHERE `LangID`='0' ORDER BY `ID`");
126  foreach ($aEmails as $aEmail) {
127  $aForm['inputs'] = array_merge($aForm['inputs'], array(
128  $aEmail['name'] . '_Beg' => array(
129  'type' => 'block_header',
130  'caption' => $aEmail['description'],
131  'collapsable' => true,
132  'collapsed' => true
133  ),
134  $aEmail['name'] . '_Language' => array(
135  'type' => 'select',
136  'name' => $aEmail['name'] . '_Language',
137  'caption' => $sLanguageCpt,
138  'value' => 0,
139  'values' => $aLanguageChooser,
140  'db' => array(
141  'pass' => 'Int',
142  ),
143  'attrs' => array(
144  'onchange' => "javascript:getTranslations(this)"
145  )
146  ),
147  $aEmail['name'] . '_Subject' => array(
148  'type' => 'text',
149  'name' => $aEmail['name'] . '_Subject',
150  'caption' => $sSubjectCpt,
151  'value' => $aEmail['subject'],
152  'db' => array(
153  'pass' => 'Xss',
154  ),
155  ),
156  $aEmail['name'] . '_Body' => array(
157  'type' => 'textarea',
158  'name' => $aEmail['name'] . '_Body',
159  'caption' => $sBodyCpt,
160  'value' => $aEmail['body'],
161  'db' => array(
162  'pass' => 'XssHtml',
163  ),
164  ),
165  $aEmail['name'] . '_End' => array(
166  'type' => 'block_end'
167  )
168  ));
169  }
170 
171  $aForm['inputs']['adm-emial-templates-save'] = array(
172  'type' => 'submit',
173  'name' => 'adm-emial-templates-save',
174  'value' => _t('_adm_btn_email_save'),
175  );
176 
178  $oForm->initChecker();
179 
180  $sResult = "";
181  if ($oForm->isSubmittedAndValid()) {
182  $iResult = 0;
183  foreach ($aEmails as $aEmail) {
184  $iEmailId = (int)$GLOBALS['MySQL']->getOne("SELECT `ID` FROM `sys_email_templates` WHERE `Name`='" . process_db_input($aEmail['name']) . "' AND `LangID`='" . (int)$_POST[$aEmail['name'] . '_Language'] . "' LIMIT 1");
185  if ($iEmailId != 0) {
186  $iResult += (int)$GLOBALS['MySQL']->query("UPDATE `sys_email_templates` SET `Subject`='" . process_db_input($_POST[$aEmail['name'] . '_Subject']) . "', `Body`='" . process_db_input($_POST[$aEmail['name'] . '_Body']) . "' WHERE `ID`='" . $iEmailId . "'");
187  } else {
188  $iResult += (int)$GLOBALS['MySQL']->query("INSERT INTO `sys_email_templates` SET `Name`='" . process_db_input($aEmail['name']) . "', `Subject`='" . process_db_input($_POST[$aEmail['name'] . '_Subject']) . "', `Body`='" . process_db_input($_POST[$aEmail['name'] . '_Body']) . "', `LangID`='" . (int)$_POST[$aEmail['name'] . '_Language'] . "'");
189  }
190  }
191 
192  $bActive = true;
193  $sResult .= MsgBox(_t($iResult > 0 ? "_adm_txt_email_success_save" : "_adm_txt_email_nothing_changed"), 3);
194  }
195  $sResult .= $oForm->getCode();
196 
197  return $GLOBALS['oAdmTemplate']->parseHtmlByName('email_templates_list.html', array(
198  'display' => $bActive ? 'block' : 'none',
199  'content' => stripslashes($sResult),
200  'loading' => LoadingBox('adm-email-loading')
201  ));
202 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
ChTemplFormView
Definition: ChTemplFormView.php:11
$_page
$_page
Definition: email_templates.php:42
LoadingBox
LoadingBox($sName)
Definition: design.inc.php:185
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
$sResult
$sResult
Definition: advanced_settings.php:26
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
php
$oForm
$oForm
Definition: host_tools.php:42
DesignBoxAdmin
DesignBoxAdmin($sTitle, $sContent, $mixedTopItems='', $sBottomItems='', $iIndex=1)
Definition: admin_design.inc.php:50
exit
exit
Definition: cart.php:21
$aTopItems
$aTopItems
Definition: antispam.php:366
$aResults
$aResults
Definition: email_templates.php:25
$oSettings
$oSettings
Definition: email_templates.php:22
$logged
$logged['admin']
Definition: email_templates.php:20
_getList
_getList($mixedResult, $bActive=false)
Definition: email_templates.php:93
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
ChWsbAdminSettings
Definition: ChWsbAdminSettings.php:35
$_page_cont
$_page_cont[$iNameIndex]
Definition: email_templates.php:48
_getSettings
_getSettings($mixedResult, $bActive=false)
Definition: email_templates.php:79
$GLOBALS
$GLOBALS['iAdminPage']
Definition: email_templates.php:10
$aForm
$aForm
Definition: forgot.php:43
$iNameIndex
if(isset($_POST['save']) &&isset($_POST['cat'])) elseif(isset($_POST['action']) && $_POST['action']=='get_translations') $iNameIndex
Definition: email_templates.php:41
PageCodeMain
PageCodeMain($aResults)
Definition: email_templates.php:54
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10