source: trunk/administration/email_templates.php

Last change on this file was 2, checked in by george, 14 years ago
  • Přidáno: Trunk revize 13719.
File size: 7.7 KB
Line 
1<?php
2
3/***************************************************************************
4* Dolphin Smart Community Builder
5* -----------------
6* begin : Mon Mar 23 2006
7* copyright : (C) 2006 BoonEx Group
8* website : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21require_once( '../inc/header.inc.php' );
22
23$GLOBALS['iAdminPage'] = 1;
24
25require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
26require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
27require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
28require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
29require_once( BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php' );
30
31bx_import('BxDolAdminSettings');
32bx_import('BxTemplSearchResult');
33
34$logged['admin'] = member_auth( 1, true, true );
35
36$oSettings = new BxDolAdminSettings(4);
37
38//--- Process submit ---//
39$mixedResultSettings = '';
40$mixedResultTemplates = '';
41if(isset($_POST['save']) && isset($_POST['cat'])) {
42 $mixedResultSettings = $oSettings->saveChanges($_POST);
43} elseif(isset($_POST['action']) && $_POST['action'] == 'get_translations') {
44 $aTranslation = $GLOBALS['MySQL']->getRow("SELECT `Subject` AS `subject`, `Body` AS `body` FROM `sys_email_templates` WHERE `Name`='" . process_db_input($_POST['templ_name']) . "' AND `LangID`='" . (int)$_POST['lang_id'] . "' LIMIT 1");
45 if(empty($aTranslation))
46 $aTranslation = $GLOBALS['MySQL']->getRow("SELECT `Subject` AS `subject`, `Body` AS `body` FROM `sys_email_templates` WHERE `Name`='" . process_db_input($_POST['templ_name']) . "' AND `LangID`='0' LIMIT 1");
47
48 $oJson = new Services_JSON();
49 echo $oJson->encode(array('subject' => $aTranslation['subject'], 'body' => $aTranslation['body']));
50 exit;
51}
52
53$iNameIndex = 8;
54$_page = array(
55 'name_index' => $iNameIndex,
56 'css_name' => array('forms_adv.css', 'settings.css'),
57 'js_name' => array('email_templates.js'),
58 'header' => _t('_adm_page_cpt_email_templates'),
59);
60$_page_cont[$iNameIndex] = array(
61 'page_code_settings' => PageCodeSettings($mixedResultSettings),
62 'page_code_templates' => PageCodeTemplates($mixedResultTemplates),
63);
64
65PageCodeAdmin();
66
67function PageCodeSettings($mixedResult) {
68
69 $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $GLOBALS['oSettings']->getForm()));
70 if($mixedResult !== true && !empty($mixedResult))
71 $sResult = $mixedResult . $sResult;
72
73 return DesignBoxAdmin(_t('_adm_box_cpt_email_settings'), $sResult);
74}
75function PageCodeTemplates($mixedResult) {
76
77 $aForm = array(
78 'form_attrs' => array(
79 'id' => 'adm-email-templates',
80 'action' => $_SERVER['PHP_SELF'],
81 'method' => 'post',
82 'enctype' => 'multipart/form-data',
83 ),
84 'params' => array (
85 'db' => array(
86 'table' => 'sys_email_templates',
87 'key' => 'ID',
88 'uri' => '',
89 'uri_title' => '',
90 'submit_name' => 'adm-emial-templates-save'
91 ),
92 ),
93 'inputs' => array ()
94 );
95
96 $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
97
98 $aLanguageChooser = array(array('key' => 0, 'value' => 'default'));
99 foreach($aLanguages as $aLanguage)
100 $aLanguageChooser[] = array('key' => $aLanguage['id'], 'value' => $aLanguage['title']);
101
102 $sLanguageCpt = _t('_adm_txt_email_language');
103 $sSubjectCpt = _t('_adm_txt_email_subject');
104 $sBodyCpt = _t('_adm_txt_email_body');
105
106 $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`");
107 foreach($aEmails as $aEmail) {
108 $aForm['inputs'] = array_merge($aForm['inputs'], array(
109 $aEmail['name'] . '_Beg' => array(
110 'type' => 'block_header',
111 'caption' => $aEmail['description'],
112 'collapsable' => true,
113 'collapsed' => true
114 ),
115 $aEmail['name'] . '_Language' => array(
116 'type' => 'select',
117 'name' => $aEmail['name'] . '_Language',
118 'caption' => $sLanguageCpt,
119 'value' => 0,
120 'values' => $aLanguageChooser,
121 'db' => array (
122 'pass' => 'Int',
123 ),
124 'attrs' => array(
125 'onchange' => "javascript:getTranslations(this)"
126 )
127 ),
128 $aEmail['name'] . '_Subject' => array(
129 'type' => 'text',
130 'name' => $aEmail['name'] . '_Subject',
131 'caption' => $sSubjectCpt,
132 'value' => $aEmail['subject'],
133 'db' => array (
134 'pass' => 'Xss',
135 ),
136 ),
137 $aEmail['name'] . '_Body' => array(
138 'type' => 'textarea',
139 'name' => $aEmail['name'] . '_Body',
140 'caption' => $sBodyCpt,
141 'value' => $aEmail['body'],
142 'db' => array (
143 'pass' => 'XssHtml',
144 ),
145 ),
146 $aEmail['name'] . '_End' => array(
147 'type' => 'block_end'
148 )
149 ));
150 }
151
152 $aForm['inputs']['adm-emial-templates-save'] = array(
153 'type' => 'submit',
154 'name' => 'adm-emial-templates-save',
155 'value' => _t('_adm_btn_email_save'),
156 );
157
158 $oForm = new BxTemplFormView($aForm);
159 $oForm->initChecker();
160
161 $sResult = "";
162 if($oForm->isSubmittedAndValid()) {
163 $iResult = 0;
164 foreach($aEmails as $aEmail) {
165 $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");
166 if($iEmailId != 0)
167 $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 . "'");
168 else
169 $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'] . "'");
170 }
171
172 $sResult .= MsgBox(_t($iResult > 0 ? "_adm_txt_email_success_save" : "_adm_txt_email_nothing_changed"), 3);
173 }
174 $sResult .= $oForm->getCode();
175
176 return DesignBoxAdmin(_t('_adm_box_cpt_email_templates'), $GLOBALS['oAdmTemplate']->parseHtmlByName('email_templates.html', array(
177 'content' => stripslashes($sResult),
178 'loading' => LoadingBox('adm-email-loading')
179 )));
180}
181
182?>
Note: See TracBrowser for help on using the repository browser.