HomeHelpTrac

source: trunk/administration/email_templates.php @ 15211

Revision 15211, 7.9 KB checked in by Alexander Trofimov, 12 months ago (diff)

Code cleaning:

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