-
Notifications
You must be signed in to change notification settings - Fork 82
/
magazine_list.php
553 lines (253 loc) · 12.7 KB
/
magazine_list.php
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/**
* ECSHOP 程序说明
* ===========================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ==========================================================
* $Author: liubo $
* $Id: magazine_list.php 17217 2011-01-19 06:29:08Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
admin_priv('magazine_list');
if ($_REQUEST['act'] == 'list')
{
$smarty->assign('ur_here', $_LANG['magazine_list']);
$smarty->assign('action_link', array('text' => $_LANG['add_new'], 'href' => 'magazine_list.php?act=add'));
$smarty->assign('full_page', 1);
$magazinedb = get_magazine();
$smarty->assign('magazinedb', $magazinedb['magazinedb']);
$smarty->assign('filter', $magazinedb['filter']);
$smarty->assign('record_count', $magazinedb['record_count']);
$smarty->assign('page_count', $magazinedb['page_count']);
$special_ranks = get_rank_list();
$send_rank[SEND_LIST . '_0'] = $_LANG['email_user'];
$send_rank[SEND_USER . '_0'] = $_LANG['user_list'];
foreach($special_ranks as $rank_key => $rank_value)
{
$send_rank[SEND_RANK . '_' . $rank_key] = $rank_value;
}
$smarty->assign('send_rank', $send_rank);
assign_query_info();
$smarty->display('magazine_list.htm');
}
elseif ($_REQUEST['act'] == 'query')
{
$magazinedb = get_magazine();
$smarty->assign('magazinedb', $magazinedb['magazinedb']);
$smarty->assign('filter', $magazinedb['filter']);
$smarty->assign('record_count', $magazinedb['record_count']);
$smarty->assign('page_count', $magazinedb['page_count']);
$sort_flag = sort_flag($magazinedb['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
make_json_result($smarty->fetch('magazine_list.htm'), '', array('filter' => $magazinedb['filter'], 'page_count' => $magazinedb['page_count']));
}
elseif ($_REQUEST['act'] == 'add')
{
if (empty($_POST['step']))
{
include_once(ROOT_PATH.'includes/fckeditor/fckeditor.php'); // 包含 html editor 类文件
$smarty->assign('action_link', array('text' => $_LANG['go_list'], 'href' => 'magazine_list.php?act=list'));
$smarty->assign(array('ur_here'=>$_LANG['magazine_list'],'act'=>'add'));
create_html_editor('magazine_content');
assign_query_info();
$smarty->display('magazine_list_add.htm');
}
elseif ($_POST['step'] == 2)
{
$magazine_name = trim($_POST['magazine_name']);
$magazine_content = trim($_POST['magazine_content']);
$magazine_content = str_replace('src=\"','src=\"http://'.$_SERVER['HTTP_HOST'],$magazine_content);
$time = gmtime();
$sql = "INSERT INTO " . $ecs->table('mail_templates') . " (template_code, is_html,template_subject, template_content, last_modify, type) VALUES('" . md5($magazine_name.$time) . "',1, '$magazine_name', '$magazine_content', '$time', 'magazine')";
$db->query($sql);
$links[] = array('text' => $_LANG['magazine_list'], 'href' => 'magazine_list.php?act=list');
$links[] = array('text' => $_LANG['add_new'], 'href' => 'magazine_list.php?act=add');
sys_msg($_LANG['edit_ok'], 0, $links);
}
}
elseif ($_REQUEST['act'] == 'edit')
{
include_once(ROOT_PATH.'includes/fckeditor/fckeditor.php'); // 包含 html editor 类文件
$id = intval($_REQUEST['id']);
if (empty($_POST['step']))
{
$rt = $db->getRow("SELECT * FROM " . $ecs->table('mail_templates') . " WHERE type = 'magazine' AND template_id = '$id'");
$smarty->assign(array('id'=>$id,'act'=>'edit','magazine_name'=>$rt['template_subject'],'magazine_content'=>$rt['template_content']));
$smarty->assign(array('ur_here'=>$_LANG['magazine_list'],'act'=>'edit'));
$smarty->assign('action_link', array('text' => $_LANG['go_list'], 'href' => 'magazine_list.php?act=list'));
create_html_editor('magazine_content', $rt['template_content']);
assign_query_info();
$smarty->display('magazine_list_add.htm');
}
elseif ($_POST['step'] == 2)
{
$magazine_name = trim($_POST['magazine_name']);
$magazine_content = trim($_POST['magazine_content']);
$magazine_content = str_replace('src=\"','src=\"http://'.$_SERVER['HTTP_HOST'],$magazine_content);
$time = gmtime();
$db->query("UPDATE " . $ecs->table('mail_templates') . " SET is_html = 1, template_subject = '$magazine_name', template_content = '$magazine_content', last_modify = '$time' WHERE type = 'magazine' AND template_id = '$id'");
$links[] = array('text' => $_LANG['magazine_list'], 'href' => 'magazine_list.php?act=list');
sys_msg($_LANG['edit_ok'], 0, $links);
}
}
elseif ($_REQUEST['act'] == 'del')
{
$id = intval($_REQUEST['id']);
$db->query("DELETE FROM " . $ecs->table('mail_templates') . " WHERE type = 'magazine' AND template_id = '$id' LIMIT 1");
$links[] = array('text' => $_LANG['magazine_list'], 'href' => 'magazine_list.php?act=list');
sys_msg($_LANG['edit_ok'], 0, $links);
}
elseif ($_REQUEST['act'] == 'addtolist')
{
$id = intval($_REQUEST['id']);
$pri = !empty($_REQUEST['pri']) ? 1 : 0;
$start = empty($_GET['start']) ? 0 : (int)$_GET['start'];
$send_rank = $_REQUEST['send_rank'];
$rank_array = explode('_', $send_rank);
$template_id = $db->getOne("SELECT template_id FROM " . $ecs->table('mail_templates') . " WHERE type = 'magazine' AND template_id = '$id'");
if (!empty($template_id))
{
if (SEND_LIST == $rank_array['0'])
{
$count = $db->getOne("SELECT COUNT(*) FROM " . $ecs->table('email_list') . "WHERE stat = 1");
if ($count > $start)
{
$sql = "SELECT email FROM " . $ecs->table('email_list') . "WHERE stat = 1 LIMIT $start,100";
$query = $db->query($sql);
$add = '';
$i = 0;
while ($rt = $db->fetch_array($query))
{
$time = time();
$add .= $add ? ",('$rt[email]','$id','$pri','$time')" : "('$rt[email]','$id','$pri','$time')";
$i ++ ;
}
if ($add)
{
$sql = "INSERT INTO " . $ecs->table('email_sendlist') . " (email,template_id,pri,last_send) VALUES " . $add;
$db->query($sql);
}
if($i == 100)
{
$start = $start + 100;
}
else
{
$start = $start + $i;
}
$links[] = array('text' => sprintf($_LANG['finish_list'],$start), 'href' => "magazine_list.php?act=addtolist&id=$id&pri=$pri&start=$start&send_rank=$send_rank");
sys_msg($_LANG['finishing'], 0, $links);
}
else
{
$db->query("UPDATE " . $ecs->table('mail_templates') . " SET last_send = " . time() . " WHERE type = 'magazine' AND template_id = '$id'");
$links[] = array('text' => $_LANG['magazine_list'], 'href' => 'magazine_list.php?act=list');
sys_msg($_LANG['edit_ok'], 0, $links);
}
}
else
{
$sql = "SELECT special_rank FROM " . $ecs->table('user_rank') . " WHERE rank_id = '" . $rank_array['1'] . "'";
$row = $db->getRow($sql);
if (SEND_USER == $rank_array['0'])
{
$count_sql = 'SELECT COUNT(*) FROM ' . $ecs->table('users') . 'WHERE is_validated = 1';
$email_sql = 'SELECT email FROM ' . $ecs->table('users') . "WHERE is_validated = 1 LIMIT $start,100";
}
elseif ($row['special_rank'])
{
$count_sql = 'SELECT COUNT(*) FROM ' . $ecs->table('users') . 'WHERE is_validated = 1 AND user_rank = ' . $rank_array['1'];
$email_sql = 'SELECT email FROM ' . $ecs->table('users') . 'WHERE is_validated = 1 AND user_rank = ' . $rank_array['1'] . " LIMIT $start,100";
}
else
{
$count_sql = 'SELECT COUNT(*) ' .
'FROM ' . $ecs->table('users') . ' AS u LEFT JOIN ' . $ecs->table('user_rank') . ' AS ur ' .
" ON ur.special_rank = '0' AND ur.min_points <= u.rank_points AND ur.max_points > u.rank_points" .
" WHERE ur.rank_id = '" . $rank_array['1'] . "' AND u.is_validated = 1";
$email_sql = 'SELECT u.email ' .
'FROM ' . $ecs->table('users') . ' AS u LEFT JOIN ' . $ecs->table('user_rank') . ' AS ur ' .
" ON ur.special_rank = '0' AND ur.min_points <= u.rank_points AND ur.max_points > u.rank_points" .
" WHERE ur.rank_id = '" . $rank_array['1'] . "' AND u.is_validated = 1 LIMIT $start,100";
}
$count = $db->getOne($count_sql);
if ($count > $start)
{
$query = $db->query($email_sql);
$add = '';
$i = 0;
while ($rt = $db->fetch_array($query))
{
$time = time();
$add .= $add ? ",('$rt[email]','$id','$pri','$time')" : "('$rt[email]','$id','$pri','$time')";
$i ++ ;
}
if ($add)
{
$sql = "INSERT INTO " . $ecs->table('email_sendlist') . " (email,template_id,pri,last_send) VALUES " . $add;
$db->query($sql);
}
if($i == 100)
{
$start = $start + 100;
}
else
{
$start = $start + $i;
}
$links[] = array('text' => sprintf($_LANG['finish_list'],$start), 'href' => "magazine_list.php?act=addtolist&id=$id&pri=$pri&start=$start&send_rank=$send_rank");
sys_msg($_LANG['finishing'], 0, $links);
}
else
{
$db->query("UPDATE " . $ecs->table('mail_templates') . " SET last_send = " . time() . " WHERE type = 'magazine' AND template_id = '$id'");
$links[] = array('text' => $_LANG['magazine_list'], 'href' => 'magazine_list.php?act=list');
sys_msg($_LANG['edit_ok'], 0, $links);
}
}
}
else
{
$links[] = array('text' => $_LANG['magazine_list'], 'href' => 'magazine_list.php?act=list');
sys_msg($_LANG['edit_ok'], 0, $links);
}
}
function get_magazine()
{
$result = get_filter();
if ($result === false)
{
$filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'template_id' : trim($_REQUEST['sort_by']);
$filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
$sql = "SELECT count(*) FROM " .$GLOBALS['ecs']->table('mail_templates') . " WHERE type = 'magazine'";
$filter['record_count'] = $GLOBALS['db']->getOne($sql);
/* 分页大小 */
$filter = page_and_size($filter);
/* 查询 */
$sql = "SELECT * ".
" FROM ".$GLOBALS['ecs']->table('mail_templates') .
" WHERE type = 'magazine'" .
" ORDER by " . $filter['sort_by'] . ' ' . $filter['sort_order'] .
" LIMIT " . $filter['start'] . ',' . $filter['page_size'];
set_filter($filter, $sql);
}
else
{
$sql = $result['sql'];
$filter = $result['filter'];
}
$magazinedb = $GLOBALS['db']->getAll($sql);
foreach($magazinedb as $k => $v)
{
$magazinedb[$k]['last_modify'] = local_date('Y-m-d', $v['last_modify']);
$magazinedb[$k]['last_send'] = local_date('Y-m-d', $v['last_send']);
}
$arr = array('magazinedb' => $magazinedb, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
return $arr;
}
?>