forked from Znote/ZnoteAAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_news.php
152 lines (146 loc) · 4.86 KB
/
admin_news.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
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
protect_page();
admin_only($user_data);
// Recieving POST
if (empty($_POST) === false) {
list($action, $id) = explode('!', sanitize($_POST['option']));
// Delete
if ($action === 'd') {
echo '<font color="green"><b>News deleted!</b></font>';
mysql_delete("DELETE FROM `znote_news` WHERE `id`='$id';");
$cache = new Cache('engine/cache/news');
$news = fetchAllNews();
$cache->setContent($news);
$cache->save();
}
// Add news
if ($action === 'a') {
// fetch data
$char_array = user_character_list($user_data['id']);
?>
<script src="engine/js/nicedit.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
<form action="" method="post">
<input type="hidden" name="option" value="i!0">
Select character:<select name="selected_char">
<?php
$count = 0;
if ($char_array !== false) {
foreach ($char_array as $name) {
$name = $name['name'];
$charD = user_character_data(user_character_id($name), 'group_id', 'id');
if ($charD['group_id'] > 1) {
echo '<option value="'. user_character_id($name) .'">'. $name .'</option>';
$count++;
}
}
}
?>
</select>
<input type="text" name="title" value="" placeholder="Title"> [youtube]wK0w0x62PjA[/youtube] <br />
<textarea name="text" id="area1" cols="75" rows="10" placeholder="Contents..." style="width: 100%"></textarea><br />
<input type="submit" value="Create News">
</form>
<?php
if ($count === 0) echo "<font size='6' color='red'>ERROR: NO GMs or Tutors on this account!</font>";
}
// Insert news
if ($action === 'i') {
echo '<font color="green"><b>News created successfully!</b></font>';
list($charid, $title, $text) = array((int)$_POST['selected_char'], mysql_znote_escape_string($_POST['title']), mysql_znote_escape_string($_POST['text']));
$date = time();
mysql_insert("INSERT INTO `znote_news` (`title`, `text`, `date`, `pid`) VALUES ('$title', '$text', '$date', '$charid');");
// Reload the cache.
$cache = new Cache('engine/cache/news');
$news = fetchAllNews();
$cache->setContent($news);
$cache->save();
}
// Save
if ($action === 's') {
echo '<font color="green"><b>News successfully updated!</b></font>';
list($title, $text) = array(mysql_znote_escape_string($_POST['title']), mysql_znote_escape_string($_POST['text']));
mysql_update("UPDATE `znote_news` SET `title`='$title',`text`='$text' WHERE `id`='$id';");
$cache = new Cache('engine/cache/news');
$news = fetchAllNews();
$cache->setContent($news);
$cache->save();
}
// Edit
if ($action === 'e') {
$news = fetchAllNews();
$edit = array();
foreach ($news as $n) if ($n['id'] == $id) $edit = $n;
?>
<script src="engine/js/nicedit.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
<form action="" method="post">
<input type="hidden" name="option" value="s!<?php echo $id; ?>">
<input type="text" name="title" value="<?php echo $edit['title']; ?>"><br />
<textarea name="text" cols="75" rows="10" style="width: 100%"><?php echo $edit['text']; ?></textarea><br />
<input type="submit" value="Save Changes">
</form>
<br>
<p>
[b]<b>Bold Text</b>[/b]<br>
[size=5]Size 5 text[/size]<br>
[img]<a href="http://www.imgland.net/" target="_BLANK">Direct Image Link</a>[/img]<br>
[center]Cented Text[/center]<br>
[link]<a href="http://youtube.com/" target="_BLANK">http://youtube.com/</a>[/link]<br>
[link=http://youtube.com/]<a href="http://youtube.com/" target="_BLANK">Click to View youtube</a>[/link]<br>
[color=<font color="green">GREEN</font>]<font color="green">Green Text!</font>[/color]<br>
[*]* Noted text [/*]
</p>
<?php
}
}
?>
<h1>News admin panel</h1>
<form action="" method="post">
<input type="hidden" name="option" value="a!0">
<input type="submit" value="Create new article">
</form>
<?php
// pre stuff
$news = fetchAllNews();
if ($news !== false) {
?>
<table id="news">
<tr class="yellow">
<td>Date</td>
<td>By</td>
<td>Title</td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php
foreach ($news as $n) {
echo '<tr>';
echo '<td>'. getClock($n['date'], true) .'</td>';
echo '<td><a href="characterprofile.php?name='. $n['name'] .'">'. $n['name'] .'</a></td>';
echo '<td>'. $n['title'] .'</td>';
echo '<td>';
// edit
?>
<form action="" method="post">
<input type="hidden" name="option" value="e!<?php echo $n['id']; ?>">
<input type="submit" value="Edit">
</form>
<?php
echo '</td>';
echo '<td>';
// delete
?>
<form action="" method="post">
<input type="hidden" name="option" value="d!<?php echo $n['id']; ?>">
<input type="submit" value="Delete">
</form>
<?php
echo '</td>';
echo '</tr>';
}
?>
</table>
<?php
}
include 'layout/overall/footer.php'; ?>