admin_mail.php
5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* @author: Bunzia Alexander <nifus@mail.ru> <http://www.weblancer.net/users/nifus/>
* @copyright: Copyright (c) 2010, Bunzia Alexander
* @version: 1.0
* @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @package: HiLo CMS
*/
/**
* Класс управления почтовыми шаблонами
*
*/
class admin_mail{
private $error = false;
private $act = 'index';
private $JsHttpRequest = false;
public function __construct(){
global $MAIN_PAGE;
define('M_PATH',MAIN_SOURCE_PATH.'/modules/'.$MAIN_PAGE -> dirname() );
define('M_URL',MAIN_SOURCE_URL.'/modules/'.$MAIN_PAGE -> dirname() );
define('A_CHARSET', $MAIN_PAGE -> charset() );
include_once(M_PATH.'/inc/url.php');
include_once(M_PATH.'/inc/class.mailTmpl.php');
include_once(MAIN_SOURCE_PATH.'/inc/class.html.php');
include(MAIN_SOURCE_PATH.'/ext/ajax/JsHttpRequest.php');
$this -> JsHttpRequest = new JsHttpRequest( A_CHARSET );
$this -> act = !empty($_REQUEST['act']) ? $_REQUEST['act'] : $this -> act;
$GLOBALS['_RESULT']['id_request'] = $_REQUEST['id_request'];
}
public function get(){
//sleep(2);
$func = $this -> act;
if ( !method_exists($this ,$func) ){
sys_error(ERROR_404);
}
return $this -> $func();
}
/**
* формирует таблицу шаблонов
*
*/
private function index(){
$t = new PHPTAL();//
$t -> setSnippet('admin','admin_mail_index');// M_PATH.'/tmpl/control_mail/main.html' );
$t -> index = true; // для шаблона
$p = new mailTmplQuery('m');
$p -> where_main_rows(); // у админки всегда один язык
$p -> orderby_id('DESC');
$p -> get('*, m.m_from_name AS `from`,m_id as lang_links',false);
$t -> rows = $p -> rows();
return $t -> execute();
}
/**
* AJAX функции
*
*
*/
/**
* перезагружаем таблицу со списком шаблонов
*
*/
private function ajax_reload(){
sys_block_disable();
$t = new PHPTAL();//
$t -> setSnippet('admin','admin_mail_index');// M_PATH.'/tmpl/control_mail/main.html' );
$t -> execute = true;
$p = new mailTmplQuery('m');
$p -> where_main_rows(); // у админки всегда один язык
$p -> orderby_id('DESC');
$p -> get('*, m.m_from_name AS `from`,m_id as lang_links',false);
$t -> rows = $p -> rows();
$GLOBALS['_RESULT']['content'] = $t -> execute();
exit();
}
private function ajax_delete(){
sys_block_disable();
$m = mailTmpl::load_id($_REQUEST['id']);
if ( false===$m ){
die( A_EMPTY_ID );
}
$m -> delete();
exit();
}
private function ajax_save(){
sys_block_disable();
$p = mailTmpl::load_id($_POST['id']);
if ( false===$p ){
$p = mailTmpl::create();
$create=true;
}
//$p -> set_debug(1);
try{
foreach( $_POST['form'] as $k => $v ){
$p -> set($k,$v);
}
$id= ($create===true) ? $p -> insert() : $p -> update();
if ( $create===true && empty($_POST['form']['link_id']) ){
$p -> set('link_id',$id);
$p -> update();
}
}catch(Exception $e){
echo $e -> getMessage();
exit();
}
$GLOBALS['_RESULT']['msg'] = M_ADMIN_TMPL_SAVE;
exit();
}
/**
* Форма добавления/редактирования шаблона
*
*/
private function ajax_edit(){
global $MAIN_PAGE ;
sys_block_disable();
// получаем из базы страницу $_REQUEST['id']
$p = new mailTmplQuery('f');
//$p -> set_debug(1);
if ( false!==$p -> where_link($_GET['id']) ){
$p -> where_main_rows();
$p -> get('*, lang as lang_list,m_content_type as type_list ');
$row = $p -> row();
}else{
$row = array( 'lang_list'=>filedsGetMailTmpl::lang_list(),'type_list'=>filedsGetMailTmpl::type_list() );
}
$row['site_name'] = $MAIN_PAGE -> config('sys_site_name');
$row['site_email'] = $MAIN_PAGE -> config('sys_mail');
// формируем страницу
$t = new PHPTAL( );//M_PATH.'/tmpl/control_mail/form.html' );
$t -> setSnippet('admin','admin_mail_edit');
$t -> lang_edit = false; // редактируем ключевую запись
$t -> lang = !empty($_GET['lang']) ? $_GET['lang'] : MAIN_LANG;
$t -> row = ($row );
$GLOBALS['_RESULT']['content'] = $t -> execute();
$GLOBALS['_RESULT']['title'] = M_ADMIN_M_TMPL;
exit();
}
/**
* Редактируем языки
*
*/
private function ajax_lang_edit(){
sys_block_disable();
$t = new PHPTAL( false );
$t -> setSnippet( 'admin','admin_mail_edit'); //$this -> path_tmpl.'/edit.html' );
$t -> lang_edit = true; // редактируем ключевую запись
$p = new mailTmplQuery('p');
//$p -> set_debug(1);
$p -> where_link($_GET['id']);
$p -> where_lang($_GET['lang']);
$p -> get('*,m_content_type as type_list');
if ( $p-> get_count_rows()!=0 ){
$row = $p -> row();
}else{
$row = array('link_id'=>$_GET['id'],'type_list'=>filedsGetMailTmpl::type_list() );
}
$t -> row = $row;
$t -> lang = !empty($_GET['lang']) ? $_GET['lang'] : MAIN_LANG;
$GLOBALS['_RESULT']['content'] = $t -> execute();
$GLOBALS['_RESULT']['title'] = M_ADMIN_SP_ADD_EDIT_PAGE;
exit();
}
}
?>