Source of trunk/cp_edit.php at revision 369 (05/10/2008 11:05:59, 8225 bytes, 226 lines, language: php) [download]:

1
<?php
2
3
/*
4
** Control Panel :: Edit Post
5
** for CodewiseBlog Multi-User
6
**
7
** by William R. Fraser <wrf@codewise.org>
8
** Copyright (c) 2005-2008 Codewise.org
9
*/
10
11
/*
12
** This file is part of CodewiseBlog
13
**
14
** CodewiseBlog is free software; you can redistribute it and/or modify
15
** it under the terms of the GNU General Public License as published by
16
** the Free Software Foundation; either version 2 of the License, or
17
** (at your option) any later version.
18
**
19
** CodewiseBlog is distributed in the hope that it will be useful,
20
** but WITHOUT ANY WARRANTY; without even the implied warranty of
21
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
** GNU General Public License for more details.
23
**
24
** You should have received a copy of the GNU General Public License
25
** along with CodewiseBlog; if not, write to the Free Software
26
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27
*/
28
29
$current "edit";
30
31
// hack to allow direct link to editing a topic
32
if(isset($_GET['tid']))
33
{
34
    $_POST['tid'] = $_GET['tid'];
35
}
36
37
if(empty($_POST))
38
{
39
    $q $db->issue_query("SELECT tid,title,timestamp FROM topics WHERE blogid = '" BLOGID "' ORDER BY tid DESC");
40
    $data $db->fetch_all($q);
41
42
    $html "";
43
    foreach($data as $row)
44
    {
45
        $html .= "<option value=\"{$row['tid']}\">\"{$row['title']}\" - " date(DATE_FORMAT$row['timestamp']) . "</option>\n";
46
    }
47
48
    $body skinvoodoo(
49
        "controlpanel_edit""showselect",
50
        array(
51
            "posturl" => INDEX_URL "?controlpanel:edit",
52
            "options"  => $html,
53
        )
54
    );
55
} elseif(isset($_POST['delete']) && !isset($_POST['REALLY_FREAKING_SURE'])) {
56
    $body skinvoodoo("controlpanel_edit""delete_ask", array("posturl" => INDEX_URL "?controlpanel:edit""tid" => $_POST['tid']));
57
} elseif(isset($_POST['delete']) && isset($_POST['REALLY_FREAKING_SURE'])) {
58
    $q1 $db->issue_query("DELETE FROM topics WHERE tid = " $db->prepare_value($_POST['tid']) . " AND blogid = '" BLOGID "' LIMIT 1");
59
    $q2 $db->issue_query("DELETE FROM replies WHERE tid = " $db->prepare_value($_POST['tid']) . " AND blogid = '" BLOGID "'");
60
61
    $body skinvoodoo("controlpanel_edit""delete_successful", array("num_comments" => $db->num_rows[$q2]));
62
} elseif(!isset($_POST['do_edit'])) {
63
64
    if(isset($_POST['preview']))
65
    {
66
        $month $_POST['month'];
67
        $date $_POST['date'];
68
        $year $_POST['year'];
69
        $hour $_POST['hour'];
70
        $minute $_POST['minute'];
71
        $second $_POST['second'];
72
        $ampm $_POST['ampm'];
73
74
        $topic = array(
75
            "title" => $_POST['title'],
76
            "text" => $_POST['text'],
77
        );
78
    } else {
79
        $q $db->issue_query("SELECT title,timestamp,text,extra FROM topics WHERE tid = " $db->prepare_value($_POST['tid']) . " AND blogid = '" BLOGID "'");
80
        $topic $db->fetch_row($q);
81
        $month date("n"$topic['timestamp']);
82
        $date date("j"$topic['timestamp']);
83
        $year date("Y"$topic['timestamp']);
84
        $hour date("g"$topic['timestamp']);
85
        $minute date("i"$topic['timestamp']);
86
        $second date("s"$topic['timestamp']);
87
        $ampm date("a"$topic['timestamp']);
88
    }
89
90
    $months = array("null""January""February""March""April""May""June""July""August""September""October""November""December");
91
92
    $month_sel "<select name=\"month\">";
93
    for($i 1$i <= 12$i++)
94
    {
95
        if($i == $month)
96
            $month_sel .= "<option value=\"$i\" selected=\"selected\">{$months[$i]}</option>";
97
        else
98
            $month_sel .= "<option value=\"$i\">{$months[$i]}</option>";
99
    }
100
    $month_sel .= "</select>";
101
102
    $date_sel "<select name=\"date\">";
103
    for($i 1$i <= 31$i++)
104
    {
105
        if($i == $date)
106
            $date_sel .= "<option value=\"$i\" selected=\"selected\">" ordinal($i) . "</option>";
107
        else
108
            $date_sel .= "<option value=\"$i\">" ordinal($i) . "</option>";
109
    }
110
    $date_sel .= "</select>";
111
112
    $year_sel "<input type=\"text\" size=\"4\" value=\"" $year "\" name=\"year\" />";
113
114
    $hour_sel "<select name=\"hour\">";
115
    for($i 1$i <= 12$i++)
116
    {
117
        if($i == $hour)
118
            $hour_sel .= "<option value=\"$i\" selected=\"selected\">$i</option>";
119
        else
120
            $hour_sel .= "<option value=\"$i\">$i</option>";
121
    }
122
    $hour_sel .= "</select>";
123
124
    $minute_sel "<select name=\"minute\">";
125
    for($i 0$i <= 59$i++)
126
    {
127
        if($i == $minute)
128
            $minute_sel .= "<option value=\"$i\" selected=\"selected\">" str_pad($i2"0"STR_PAD_LEFT) . "</option>";
129
        else
130
            $minute_sel .= "<option value=\"$i\">" str_pad($i2"0"STR_PAD_LEFT) . "</option>";
131
    }
132
    $minute_sel .= "</select>";
133
134
    $second_sel "<select name=\"second\">";
135
    for($i 0$i <= 59$i++)
136
    {
137
        if($i == $second)
138
            $second_sel .= "<option value=\"$i\" selected=\"selected\">" str_pad($i2"0"STR_PAD_LEFT) . "</option>";
139
        else
140
            $second_sel .= "<option value=\"$i\">" str_pad($i2"0"STR_PAD_LEFT) . "</option>";
141
    }
142
    $second_sel .= "</select>";
143
144
    $ampm_sel "<select name=\"ampm\">";
145
    if($ampm == "am")
146
    {
147
        $ampm_sel .= "<option value=\"am\" selected=\"selected\">AM</option>";
148
        $ampm_sel .= "<option value=\"pm\">PM</option>";
149
    } else {
150
        $ampm_sel .= "<option value=\"am\">AM</option>";
151
        $ampm_sel .= "<option value=\"pm\" selected=\"selected\">PM</option>";
152
    }
153
    $ampm_sel .= "</select>";
154
155
    $preview skinvoodoo("controlpanel_write""preview_topic", array("text" => output_topic_text($topic['text'])));
156
157
    $body skinvoodoo(
158
        "controlpanel_edit""editform",
159
        array(
160
            "posturl" => INDEX_URL "?controlpanel:edit",
161
            "title"   => $topic['title'],
162
            "date"    => date(DATE_FORMAT$topic['timestamp']),
163
            "text"    => $topic['text'],
164
            "extra"   => $topic['extra'],
165
            "tid"     => $_POST['tid'],
166
            "month_sel"  => $month_sel,
167
            "date_sel"   => $date_sel,
168
            "year_sel"   => $year_sel,
169
            "hour_sel"   => $hour_sel,
170
            "minute_sel" => $minute_sel,
171
            "second_sel" => $second_sel,
172
            "ampm_sel"   => $ampm_sel,
173
            "preview" => $preview,
174
            "quicktags" => HTTP BASE_DOMAIN INSTALLED_PATH "/cwb/quicktags.js",
175
            "autoresize" => HTTP BASE_DOMAIN INSTALLED_PATH "/cwb/autoresize.js",
176
            "rows" => $_POST['rows'] ? $_POST['rows'] : 25,
177
            "cols" => $_POST['cols'] ? $_POST['cols'] : 80,
178
        )
179
    );
180
181
} else {
182
183
    if(!checkdate($_POST['month'], $_POST['date'], $_POST['year']))
184
    {
185
        $body skinvoodoo("error""error", array("message" => "Invalid date specified."));
186
    } elseif(
187
        $_POST['hour'] > 12   ||
188
        $_POST['hour'] < 1    ||
189
        $_POST['minute'] > 59 ||
190
        $_POST['minute'] < 0  ||
191
        $_POST['second'] > 59 ||
192
        $_POST['second'] < 0  ||
193
        ( $_POST['ampm'] != "am" && $_POST['ampm'] != "pm")
194
    ) {
195
        $body skinvoodoo("error""error", array("message" => "Invalid time specified."));
196
    } else {
197
198
        // int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
199
        $time mktime(
200
            // lol 12 hour time makes no sense :P
201
            $_POST['hour'] + ($_POST['ampm'] == "pm" ? (($_POST['hour'] == 12) ? 12) : (($_POST['hour'] == 12) ? -12 0)),
202
            $_POST['minute'],
203
            $_POST['second'],
204
            $_POST['month'],
205
            $_POST['date'],
206
            $_POST['year']
207
        );
208
209
        $data = array
210
        (
211
            "blogid" => BLOGID,
212
            "title" => $_POST['title'], // ToDo: check for uniqueness
213
            "timestamp" => $time,
214
            "text" => $_POST['text'],
215
        );
216
217
        $db->update("topics"$data, array("tid" => $_POST['tid']));
218
219
        $body skinvoodoo("controlpanel_edit""success_redirect", array("topic_url" => INDEX_URL "?tid={$_POST['tid']}"));
220
221
    }
222
223
}
224
225
?>
226

powered by Codewise Manager v0.1-DEV :: 61.57ms, 6 ops, 3 queries