forked from zsion/serverchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.automsg.php
220 lines (174 loc) · 7.37 KB
/
admin.automsg.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
<?php
// +---------------------------------------------+
// | Copyright 2010 - 2028 WeLive |
// | http://www.weentech.com |
// | This file may not be redistributed. |
// +---------------------------------------------+
define('AUTH', true);
include('includes/welive.Core.php');
include(BASEPATH . 'includes/welive.Admin.php');
if($userinfo['usergroupid'] != 1) exit();
$action = ForceIncomingString('action', 'default');
if(IsPost('updatemsgs')) $action= 'updatemsgs';
if(IsPost('deletemsgs')) $action= 'deletemsgs';
PrintHeader($userinfo['username'], 'automsg');
//########### UPDATE MESSAGES ###########
if($action == 'updatemsgs'){
$msgids = $_POST['msgids'];
$ordernums = $_POST['ordernums'];
$activateds = $_POST['activateds'];
$msgs = $_POST['msgs'];
$page = ForceIncomingInt('p');
for($i = 0; $i < count($msgids); $i++){
$DB->exe("UPDATE " . TABLE_PREFIX . "automsg SET ordernum = '".ForceInt($ordernums[$i])."',
activated = '".ForceInt($activateds[$i])."',
msg = '".ForceString($msgs[$i])."'
WHERE msgid = '".ForceInt($msgids[$i])."'");
}
GotoPage('admin.automsg.php'.Iif($page, '?p='.$page), 1);
}
//########### DELETE MESSAGES ###########
if($action == 'deletemsgs'){
$deletemsgids = $_POST['deletemsgids'];
$page = ForceIncomingInt('p');
for($i = 0; $i < count($deletemsgids); $i++){
$DB->exe("DELETE FROM " . TABLE_PREFIX . "automsg WHERE msgid = '".ForceInt($deletemsgids[$i])."'");
}
GotoPage('admin.automsg.php'.Iif($page, '?p='.$page), 1);
}
//########### UPDATE OR ADD MSG ###########
if($action == 'insertmsg' OR $action == 'updatemsg'){
$msgid = ForceIncomingInt('msgid');
$activated = ForceIncomingInt('activated');
$ordernum = ForceIncomingInt('ordernum');
$msg = ForceIncomingString('msg');
$deletemsg = ForceIncomingInt('deletemsg');
if($deletemsg){
$DB->exe("DELETE FROM " . TABLE_PREFIX . "automsg WHERE msgid = '$msgid'");
GotoPage('admin.automsg.php', 1);
}
if(strlen($msg) == 0){
$errors = '请输入短语内容!';
}
if(isset($errors)){
$errortitle = Iif($msgid, '编辑短语错误', '添加短语错误');
$action = Iif($msgid, 'editmsg', 'addmsg');
}else{
if($action == 'updatemsg'){
$DB->exe("UPDATE " . TABLE_PREFIX . "automsg SET ordernum = '$ordernum',
activated = '$activated',
msg = '$msg'
WHERE msgid = '$msgid'");
}else{
$DB->exe("INSERT INTO " . TABLE_PREFIX . "automsg (ordernum, activated, msg) VALUES (0, 1, '$msg')");
$newmsgid = $DB->insert_id();
$DB->exe("UPDATE " . TABLE_PREFIX . "automsg SET ordernum = '$newmsgid' WHERE msgid = '$newmsgid'");
}
GotoPage('admin.automsg.php', 1);
}
}
//########### ADD OR EDIT MESSAGE ###########
if($action == 'editmsg' OR $action == 'addmsg'){
$msgid = ForceIncomingInt('msgid');
if(isset($errors)){
PrintErrors($errors, $errortitle);
$msg = array('msgid' => $msgid,
'activated' => $activated,
'ordernum' => $ordernum,
'msg' => $_POST['msg']);
} else if($msgid) {
$msg = $DB->getOne("SELECT * FROM " . TABLE_PREFIX . "automsg WHERE msgid = '$msgid'");
}else{
$msg = array('msgid' => 0, 'activated' => 1);
}
echo '<form method="post" action="admin.automsg.php">
<input type="hidden" name="action" value="' . Iif($msgid, 'updatemsg', 'insertmsg') . '">
<input type="hidden" name="msgid" value="' . $msg['msgid'] . '">
<table id="welive_list" border="0" cellpadding="0" cellspacing="0" class="maintable">
<thead>
<tr>
<th colspan="2">添加短语</th>
</tr>
</thead>
<tbody>
<tr>
<td>短语内容:<br><br><span class=note>说明:</span> <br>1. 允许使用HTML代码, 如换行可输入<br><br>2. 插入链接, 必须在新窗口打开, 否则在当前窗口打开链接将导致离线<br>如: <a href="链接地址" target="_blank">链接文字</a></td>
<td><textarea name="msg" rows="6" style="width:460px;">'.$msg['msg'].'</textarea> <font class=red>* 必填项</font></td>
</tr> ';
if($msgid){
echo '<tr>
<td>是否显示?</td>
<td><input type="checkbox" name="activated" value="1" ' . Iif($msg['activated'] == 1, 'checked="checked"') .'></td>
</tr>
<tr>
<td>是否删除?:</td>
<td><input type="checkbox" name="deletemsg" value="1"></td>
</tr> ';
}
echo '</tbody></table>';
PrintSubmit(Iif($msgid, '保存更新', '添加短语'));
}
//########### PRINT DEFAULT ###########
if($action == 'default'){
$NumPerPage =10;
$page = ForceIncomingInt('p', 1);
$start = $NumPerPage * ($page-1);
$search = ForceIncomingString('s');
if(IsGet('s')){
$search = urldecode($search);
}
$searchsql = Iif($search, "WHERE msg like '%".$search."%'", "");
$getmessages = $DB->query("SELECT * FROM " . TABLE_PREFIX . "automsg ".$searchsql." ORDER BY ordernum ASC LIMIT $start,$NumPerPage");
$maxrows = $DB->getOne("SELECT COUNT(msgid) AS value FROM " . TABLE_PREFIX . "automsg ".$searchsql);
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td> 共有: <span class=note>'.$maxrows['value'].'</span> 条短语 <a href="admin.automsg.php?action=addmsg">添加短语</a></td>
<td>
<form method="post" action="admin.automsg.php" name="searchform">
关键字: <input type="text" name="s" size="22"> <input type="submit" name="search" value=" 搜索短语 " />
</form>
</td>
</tr>
</table>
<BR>
<form method="post" action="admin.automsg.php" name="messagesform">
<input type="hidden" name="action" value="deletemessages">
<input type="hidden" name="p" value="'.$page.'">
<table id="welive_list" border="0" cellpadding="0" cellspacing="0" class="moreinfo">
<thead>
<tr>
<th>排序编号</th>
<th>状态</th>
<th>短语内容</th>
<th>编辑</th>
<th><input type="checkbox" checkall="group" onclick="select_deselectAll (\'messagesform\', this, \'group\');"> 删除</th>
</tr>
</thead>
<tbody>';
if($maxrows['value'] < 1){
echo '<tr><td colspan="5"><center><span class=red>暂无任何短语!</span></center></td></tr></tbody></table></form>';
}else{
while($message = $DB->fetch($getmessages)){
echo '<tr>
<td><input type="hidden" name="msgids[]" value="'.$message['msgid'].'" /><input type="text" name="ordernums[]" value="' . $message['ordernum'] . '" size="4" /></td>
<td><select name="activateds[]"><option value="1">显示</option><option style="color:red;" value="0" ' . Iif(!$message['activated'], 'SELECTED', '') . '>隐藏</option></select></td>
<td><textarea name="msgs[]" style="height:32px;width:360px;">'.$message['msg'].'</textarea></td>
<td><a href="admin.automsg.php?action=editmsg&msgid='.$message['msgid'].'">'.Iif($message['activated'], '编辑', '<span class=red>编辑</span>').'</a></td>
<td><input type="checkbox" name="deletemsgids[]" value="' . $message['msgid'] . '" checkme="group"></td>
</tr>';
}
$totalpages = ceil($maxrows['value'] / $NumPerPage);
if($totalpages > 1){
echo '<tr><th colspan="5" class="last">'.GetPageList('admin.automsg.php', $totalpages, $page, 10, 's', urlencode($search)).'</th></tr>';
}
echo '</tbody>
</table>
<div style="margin-top:20px;text-align:center;">
<input type="submit" name="updatemsgs" value=" 保存更新 " />
<input type="submit" name="deletemsgs" onclick="return confirm(\'确定删除所选短语吗?\');" value=" 删除短语 " />
</div>
</form>';
}
}
PrintFooter();
?>