4 |
andreas |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
Copyright (C) 2003-2004 MJG/04-Inconceivable.org
|
|
|
4 |
See file LICENSE for licensing details.
|
|
|
5 |
See file VERSION for versioning/author/source details
|
|
|
6 |
See file CHANGELOG for changes from version to version
|
|
|
7 |
*/
|
|
|
8 |
// Include configuration data
|
|
|
9 |
include("../dbaccess.inc");
|
|
|
10 |
include("../global_config.inc.php");
|
|
|
11 |
|
|
|
12 |
// connect to the database
|
|
|
13 |
$CONF['dbConn']= OpenDB();
|
|
|
14 |
|
|
|
15 |
// Authenticate via the set cookie from index.php
|
|
|
16 |
if ( md5($CONF['adm_user'] . $CONF['adm_pass']) != $_COOKIE['mcal_adm_auth'] )
|
|
|
17 |
{
|
|
|
18 |
header("Location: index.php?year=" . $FORM['year'] . "&month=" . $FORM['month'] . "&today=" . $FORM['today'] . "\n\n");
|
|
|
19 |
exit(1);
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
// Clean up event input
|
|
|
23 |
if ( isset($FORM['day_title']))
|
|
|
24 |
$day_title = $FORM['day_title'];
|
|
|
25 |
else
|
|
|
26 |
$day_title = "";
|
|
|
27 |
|
|
|
28 |
if ( isset($FORM['day_event']))
|
|
|
29 |
$day_event = $FORM['day_event'];
|
|
|
30 |
else
|
|
|
31 |
$day_event = "";
|
|
|
32 |
|
|
|
33 |
if (isset($FORM['html']) )
|
|
|
34 |
$show_html = intval($FORM['html']);
|
|
|
35 |
|
|
|
36 |
// Setup an sql-style date
|
|
|
37 |
$sql_date = mktime(0, 0, 0, $month, $today, $year);
|
|
|
38 |
|
|
|
39 |
if ( (isset($_GET['del'])) && ($_GET['del'] == 1) )
|
|
|
40 |
{
|
|
|
41 |
$eventQuery = "DELETE FROM calendar WHERE ca_date = '$sql_date';";
|
|
|
42 |
$eventExec = TQueryDB($CONF['dbConn'], $eventQuery);
|
|
|
43 |
header("Location: admin.php?year=" . $FORM['year'] . "&month=" . $FORM['month'] . "&today=" . $FORM['today']);
|
|
|
44 |
exit();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
//no title, no comply
|
|
|
50 |
if ( strlen($day_title) < 1 )
|
|
|
51 |
{
|
|
|
52 |
header("Location: admin.php?year=" . $FORM['year'] . "&month=" . $FORM['month'] . "&today=" . $FORM['today']);
|
|
|
53 |
exit();
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
// Check to see if we're inserting new or updating entry
|
|
|
57 |
$Q = "SELECT ca_num FROM calendar WHERE ca_date = $sql_date";
|
|
|
58 |
$STH = QueryDB($CONF['dbConn'], $Q);
|
|
|
59 |
|
|
|
60 |
if ( $STH )
|
|
|
61 |
{
|
|
|
62 |
$update=0;
|
|
|
63 |
|
|
|
64 |
if ( pg_num_rows($STH) > 0 )
|
|
|
65 |
{
|
|
|
66 |
$update = 1;
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
else { }
|
|
|
70 |
|
|
|
71 |
$day_title_safe = addslashes($day_title);
|
|
|
72 |
$day_event_safe = addslashes($day_event);
|
|
|
73 |
if ( $show_html ) { $show_html = 1; } else { $show_html = 0; }
|
|
|
74 |
|
|
|
75 |
if ( $update == 1 )
|
|
|
76 |
{
|
|
|
77 |
// UPDATE
|
|
|
78 |
// $postQuery = "UPDATE " . $CONF['tbl_cal'] . " SET title = '$day_title_safe', event = '$day_event_safe', html = '$show_html' WHERE date = '$sql_date';";
|
|
|
79 |
$postQuery = "UPDATE calendar SET ca_title = '$day_title_safe', ca_text = '$day_event_safe' WHERE ca_date = $sql_date";
|
|
|
80 |
// $postExec = mysql_query($postQuery) or die("Could not Post UPDATE Cal Event to database!");
|
|
|
81 |
TQueryDB($CONF['dbConn'], $postQuery);
|
|
|
82 |
header("Location: admin.php?year=" . $FORM['year'] . "&month=" . $FORM['month'] . "&today=" . $FORM['today']);
|
|
|
83 |
}
|
|
|
84 |
else
|
|
|
85 |
{
|
|
|
86 |
// INSERT
|
|
|
87 |
// $postQuery = "INSERT INTO " . $CONF['tbl_cal'] . " (date,title,event,html) VALUES ('$sql_date','$day_title_safe','$day_event_safe','$show_html');";
|
|
|
88 |
$postQuery = "SELECT co_calendar FROM COUNTER";
|
|
|
89 |
$result = QueryDB($CONF['dbConn'], $postQuery);
|
|
|
90 |
|
|
|
91 |
if ( $result) {
|
|
|
92 |
$data = pg_fetch_row($result, 0);
|
|
|
93 |
$co_calendar = $data[0] + 1;
|
|
|
94 |
} else {
|
|
|
95 |
$co_calendar = 0;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
if ($co_calendar > 0) {
|
|
|
99 |
$postQuery = "INSERT INTO calendar (ca_num, ca_date, ";
|
|
|
100 |
$postQuery .= "ca_title, ca_text, ca_status) VALUES ";
|
|
|
101 |
$postQuery .= "($co_calendar, $sql_date, ";
|
|
|
102 |
$postQuery .= "'$day_title_safe', '$day_event_safe', 1)";
|
|
|
103 |
|
|
|
104 |
QueryDB($CONF['dbConn'], "begin");
|
|
|
105 |
|
|
|
106 |
if (!QueryDB($CONF['dbConn'], $postQuery)) {
|
|
|
107 |
QueryDB($CONF['dbConn'], "rollback");
|
|
|
108 |
pg_close($CONF['dbConn']);
|
|
|
109 |
return;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
$postQuery = "UPDATE counter SET co_calendar = $co_calendar";
|
|
|
113 |
|
|
|
114 |
if (!QueryDB($CONF['dbConn'], $postQuery)) {
|
|
|
115 |
QueryDB($CONF['dbConn'], "rollback");
|
|
|
116 |
pg_close($CONF['dbConn']);
|
|
|
117 |
return;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
QueryDB($CONF['dbConn'], "commit");
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
header("Location: admin.php?year=" . $FORM['year'] . "&month=" . $FORM['month'] . "&today=" . $FORM['today']);
|
|
|
124 |
}
|
|
|
125 |
?>
|