-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforumedit.php
169 lines (146 loc) · 6.13 KB
/
forumedit.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
<?php
/*
<Secret Center, open source member management system>
Copyright (C) 2012-2017 Secret Center開發團隊 <http://center.gdsecret.net/#team>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.
*/
require_once('Connections/SQL.php');
require_once('config.php');
require_once('include/view.php');
if(!isset($_SESSION['Center_Username'])){
header("Location: index.php?login");
exit;
}
if((!isset($_GET['id']))or($_GET['id']=='')){
header("Location: forum.php");
exit;
}
if(isset($_GET['post'])){
if(isset($_GET['reply'])){
header("Location: forum.php");
exit;
}
$_post = sc_get_result("SELECT * FROM `forum` WHERE `id` = '%d' AND `author` = '%d'",array($_GET['id'],$_SESSION['Center_Id']));
$_block = sc_get_result("SELECT * FROM `forum_block` ORDER BY `position` ASC");
if($_post['num_rows']<=0){
header("Location: forum.php");
exit;
}
if(isset($_POST['title']) && isset($_POST['content']) && trim(htmlspecialchars($_POST['title'])) != '' && trim(strip_tags($_POST['content'])," ") != '' && isset($_GET[$_SESSION['Center_Auth']])) {
$_block_auth = $SQL->query("SELECT * FROM `forum_block` WHERE `id` = '%d'",array(abs($_POST['block'])))->num_rows;
if($_block_auth<=0){
die;
}
$SQL->query("UPDATE `forum` SET `title` = '%s', `content` = '%s',`block`='%d',`level`='%d' WHERE `id` = '%d' AND `author` = '%d'",array(
htmlspecialchars($_POST['title']),
sc_xss_filter($_POST['content']),
abs($_POST['block']),
abs($_POST['level']),
$_GET['id'],
$_SESSION['Center_Id']
));
header("Location: forumview.php?editok&id=".$_post['row']['id']);
}
}elseif(isset($_GET['reply'])) {
if(isset($_GET['post'])){
header("Location: forum.php");
exit;
}
$_reply = sc_get_result("SELECT * FROM `forum_reply` WHERE `id` = '%d' AND `author` = '%d'",array($_GET['id'],$_SESSION['Center_Id']));
if($_reply['num_rows']<=0){
header("Location: forum.php");
exit;
}
if(isset($_POST['content']) && trim(strip_tags($_POST['content'])," ") != '' && isset($_GET[$_SESSION['Center_Auth']])) {
$SQL->query("UPDATE `forum_reply` SET `content` = '%s' WHERE `id` = '%d' AND `author` = '%d'",array(
sc_xss_filter($_POST['content']),
$_GET['id'],
$_SESSION['Center_Id']
));
header("Location: forumview.php?editok&id=".$_reply['row']['post_id']);
}
}else{
header("Location: forum.php");
exit;
}
$view = new View('include/theme/default.html','include/nav.php',NULL,$center['site_name'],'論壇編輯');
$view->addScript("include/js/notice.js");
$view->addCSS("include/js/summernote/summernote.css");
$view->addScript("include/js/summernote/summernote.min.js");
$view->addScript("include/js/summernote/lang/summernote-zh-TW.min.js");
?>
<script>
$(function(){
$("#summernote").summernote({width:'99%', height:300, focus: true, lang: 'zh-TW'});
});
</script>
<?php if(isset($_GET['reply'])){ ?>
<h2>編輯回覆</h2>
<form action="forumedit.php?reply&id=<?php echo $_reply['row']['id'].'&'.$_SESSION['Center_Auth']; ?>" method="POST">
<div class="form-group">
<label for="content">回覆內容:</label>
<textarea id="summernote" class="form-control" name="content" cols="65" rows="10" required="required"><?php echo sc_removal_escape_string($_reply['row']['content']); ?></textarea>
</div>
<p><input name="button" class="btn btn-primary" type="submit" value="儲存"></p>
</form>
<?php } elseif(isset($_GET['post'])){ ?>
<h2>編輯文章</h2>
<form action="forumedit.php?post&id=<?php echo $_post['row']['id'].'&'.$_SESSION['Center_Auth']; ?>" method="POST">
<div class="form-group">
<input class="form-control" name="title" type="text" placeholder="標題" required="required" value="<?php echo $_post['row']['title']; ?>">
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="block">區塊:</label>
<select class="form-control" name="block" required="required">
<?php do{ ?>
<option value="<?php echo $_block['row']['id']; ?>" <?php if($_block['row']['id']==$_post['row']['block']){ ?>selected="selected"<?php } ?>>
<?php echo $_block['row']['blockname']; ?>
</option>
<?php }while ($_block['row'] = $_block['query']->fetch_assoc()); ?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="level">權限:</label>
<select class="form-control" name="level" required="required">
<?php foreach(sc_member_level_array() as $key=>$value){if($key>0){ ?>
<option value="<?php echo $key; ?>" <?php if($key==$_post['row']['level']){ ?>selected="selected"<?php } ?>><?php echo $value; ?></option>
<?php }} ?>
</select>
</div>
</div>
</div>
<div class="form-group">
<textarea id="summernote" name="content" rows="10" required="required">
<?php echo $_post['row']['content']; ?>
</textarea>
</div>
<br><input name="button" class="btn btn-primary" type="submit" value="儲存">
</form>
<?php } ?>
<?php
$view->render();
?>