6211c3cb7cd07cd5e0c7067530235a77f3828049
[squirrelmail.git] / plugins / calendar / event_edit.php
1 <?php
2
3 /**
4 * event_edit.php
5 *
6 * Copyright (c) 2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Originally contrubuted by Michal Szczotka <michal@tuxy.org>
10 *
11 * Functions to edit an event.
12 *
13 * $Id$
14 */
15 define('SM_PATH','../../');
16
17 /* Calender plugin required files. */
18 require_once(SM_PATH . 'plugins/calendar/calendar_data.php');
19 require_once(SM_PATH . 'plugins/calendar/functions.php');
20
21 /* SquirrelMail required files. */
22 require_once(SM_PATH . 'include/validate.php');
23 require_once(SM_PATH . 'functions/strings.php');
24 require_once(SM_PATH . 'functions/date.php');
25 require_once(SM_PATH . 'config/config.php');
26 require_once(SM_PATH . 'functions/page_header.php');
27 require_once(SM_PATH . 'include/load_prefs.php');
28 require_once(SM_PATH . 'functions/html.php');
29
30
31 /* get globals */
32
33 if (isset($_POST['updated'])) {
34 $updated = $_POST['updated'];
35 }
36 if (isset($_POST['event_year'])) {
37 $event_year = $_POST['event_year'];
38 }
39 if (isset($_POST['event_month'])) {
40 $event_month = $_POST['event_month'];
41 }
42 if (isset($_POST['event_day'])) {
43 $event_day = $_POST['event_day'];
44 }
45 if (isset($_POST['event_hour'])) {
46 $event_hour = $_POST['event_hour'];
47 }
48 if (isset($_POST['event_minute'])) {
49 $event_minute = $_POST['event_minute'];
50 }
51 if (isset($_POST['event_length'])) {
52 $event_length = $_POST['event_length'];
53 }
54 if (isset($_POST['event_title'])) {
55 $event_title = $_POST['event_title'];
56 }
57 if (isset($_POST['event_text'])) {
58 $event_text = $_POST['event_text'];
59 }
60 if (isset($_POST['send'])) {
61 $send = $_POST['send'];
62 }
63 if (isset($_POST['event_priority'])) {
64 $event_priority = $_POST['event_priority'];
65 }
66 if (isset($_POST['confirmed'])) {
67 $confirmed = $_POST['confirmed'];
68 }
69 if (isset($_POST['year'])) {
70 $year = $_POST['year'];
71 }
72 elseif (isset($_GET['year'])) {
73 $year = $_GET['year'];
74 }
75 if (isset($_POST['month'])) {
76 $month = $_POST['month'];
77 }
78 elseif (isset($_GET['month'])) {
79 $month = $_GET['month'];
80 }
81 if (isset($_POST['day'])) {
82 $day = $_POST['day'];
83 }
84 elseif (isset($_GET['day'])) {
85 $day = $_GET['day'];
86 }
87 if (isset($_POST['hour'])) {
88 $hour = $_POST['hour'];
89 }
90 elseif (isset($_GET['hour'])) {
91 $hour = $_GET['hour'];
92 }
93 if (isset($_POST['minute'])) {
94 $minute = $_POST['minute'];
95 }
96 elseif (isset($_GET['minute'])) {
97 $minute = $_GET['minute'];
98 }
99 /* got 'em */
100
101 // update event info
102 function show_event_form() {
103 global $color, $editor_size, $year, $day, $month, $hour, $minute, $calendardata;
104
105 $tmparray = $calendardata["$month$day$year"]["$hour$minute"];
106 echo "\n<FORM name=eventupdate action=\"event_edit.php\" METHOD=POST >\n".
107 " <INPUT TYPE=hidden NAME=\"year\" VALUE=\"$year\">\n".
108 " <INPUT TYPE=hidden NAME=\"month\" VALUE=\"$month\">\n".
109 " <INPUT TYPE=hidden NAME=\"day\" VALUE=\"$day\">\n".
110 " <INPUT TYPE=hidden NAME=\"hour\" VALUE=\"$hour\">\n".
111 " <INPUT TYPE=hidden NAME=\"minute\" VALUE=\"$minute\">\n".
112 " <INPUT TYPE=hidden NAME=\"updated\" VALUE=\"yes\">\n".
113 html_tag( 'tr' ) .
114 html_tag( 'td', _("Date:"), 'right', $color[4] ) . "\n" .
115 html_tag( 'td', '', 'left', $color[4] ) .
116 " <SELECT NAME=\"event_year\">\n";
117 select_option_year($year);
118 echo " </SELECT>\n" .
119 " &nbsp;&nbsp;\n" .
120 " <SELECT NAME=\"event_month\">\n";
121 select_option_month($month);
122 echo " </SELECT>\n".
123 " &nbsp;&nbsp;\n".
124 " <SELECT NAME=\"event_day\">\n";
125 select_option_day($day);
126 echo " </SELECT>\n".
127 " </td></tr>\n".
128 html_tag( 'tr' ) .
129 html_tag( 'td', _("Time:"), 'right', $color[4] ) . "\n" .
130 html_tag( 'td', '', 'left', $color[4] ) .
131 " <SELECT NAME=\"event_hour\">\n";
132 select_option_hour($hour);
133 echo " </SELECT>\n".
134 " &nbsp;:&nbsp;\n".
135 " <SELECT NAME=\"event_minute\">\n";
136 select_option_minute($minute);
137 echo " </SELECT>\n".
138 " </td></tr>\n".
139 html_tag( 'tr' ) .
140 html_tag( 'td', _("Length:"), 'right', $color[4] ) . "\n" .
141 html_tag( 'td', '', 'left', $color[4] ) .
142 " <SELECT NAME=\"event_length\">\n";
143 select_option_length($tmparray[length]);
144 echo " </SELECT>\n".
145 " </td></tr>\n".
146 html_tag( 'tr' ) .
147 html_tag( 'td', _("Priority:"), 'right', $color[4] ) . "\n" .
148 html_tag( 'td', '', 'left', $color[4] ) .
149 " <SELECT NAME=\"event_priority\">\n";
150 select_option_priority($tmparray[priority]);
151 echo " </SELECT>\n".
152 " </td></tr>\n".
153 html_tag( 'tr' ) .
154 html_tag( 'td', _("Title:"), 'right', $color[4] ) . "\n" .
155 html_tag( 'td', '', 'left', $color[4] ) .
156 " <INPUT TYPE=text NAME=\"event_title\" VALUE=\"$tmparray[title]\" SIZE=30 MAXLENGTH=50><BR>\n".
157 " </td></tr>\n".
158 html_tag( 'td',
159 " <TEXTAREA NAME=\"event_text\" ROWS=5 COLS=\"$editor_size\" WRAP=HARD>$tmparray[message]</TEXTAREA>\n" ,
160 'left', $color[4], 'colspan="2"' ) .
161 '</tr>' . html_tag( 'tr' ) .
162 html_tag( 'td',
163 "<INPUT TYPE=SUBMIT NAME=send VALUE=\"" .
164 _("Update Event") . "\">\n" ,
165 'left', $color[4], 'colspan="2"' ) .
166 "</tr></FORM>\n";
167 }
168
169 // self explenatory
170 function confirm_update() {
171 global $calself, $year, $month, $day, $hour, $minute, $calendardata, $color, $event_year, $event_month, $event_day, $event_hour, $event_minute, $event_length, $event_priority, $event_title, $event_text;
172
173 $tmparray = $calendardata["$month$day$year"]["$hour$minute"];
174
175 echo html_tag( 'table',
176 html_tag( 'tr',
177 html_tag( 'th', _("Do you really want to change this event from:") . "<br>\n", '', $color[4], 'colspan="2"' ) ."\n"
178 ) .
179 html_tag( 'tr',
180 html_tag( 'td', _("Date:") , 'right', $color[4] ) ."\n" .
181 html_tag( 'td', $month.'/'.$day.'/'.$year , 'left', $color[4] ) ."\n"
182 ) .
183 html_tag( 'tr',
184 html_tag( 'td', _("Time:") , 'right', $color[4] ) ."\n" .
185 html_tag( 'td', $hour.':'.$minute , 'left', $color[4] ) ."\n"
186 ) .
187 html_tag( 'tr',
188 html_tag( 'td', _("Priority:") , 'right', $color[4] ) ."\n" .
189 html_tag( 'td', $tmparray[priority] , 'left', $color[4] ) ."\n"
190 ) .
191 html_tag( 'tr',
192 html_tag( 'td', _("Title:") , 'right', $color[4] ) ."\n" .
193 html_tag( 'td', $tmparray[title] , 'left', $color[4] ) ."\n"
194 ) .
195 html_tag( 'tr',
196 html_tag( 'td', _("Message:") , 'right', $color[4] ) ."\n" .
197 html_tag( 'td', $tmparray[message] , 'left', $color[4] ) ."\n"
198 ) .
199 html_tag( 'tr',
200 html_tag( 'th', _("to:") . "<br>\n", '', $color[4], 'colspan="2"' ) ."\n"
201 ) .
202
203 html_tag( 'tr',
204 html_tag( 'td', _("Date:") , 'right', $color[4] ) ."\n" .
205 html_tag( 'td', $event_month.'/'.$event_day.'/'.$event_year , 'left', $color[4] ) ."\n"
206 ) .
207 html_tag( 'tr',
208 html_tag( 'td', _("Time:") , 'right', $color[4] ) ."\n" .
209 html_tag( 'td', $event_hour.':'.$event_minute , 'left', $color[4] ) ."\n"
210 ) .
211 html_tag( 'tr',
212 html_tag( 'td', _("Priority:") , 'right', $color[4] ) ."\n" .
213 html_tag( 'td', $event_priority , 'left', $color[4] ) ."\n"
214 ) .
215 html_tag( 'tr',
216 html_tag( 'td', _("Title:") , 'right', $color[4] ) ."\n" .
217 html_tag( 'td', $event_title , 'left', $color[4] ) ."\n"
218 ) .
219 html_tag( 'tr',
220 html_tag( 'td', _("Message:") , 'right', $color[4] ) ."\n" .
221 html_tag( 'td', $event_text , 'left', $color[4] ) ."\n"
222 ) .
223 html_tag( 'tr',
224 html_tag( 'td',
225 " <FORM NAME=\"updateevent\" METHOD=POST ACTION=\"$calself\">\n".
226 " <INPUT TYPE=HIDDEN NAME=\"year\" VALUE=\"$year\">\n".
227 " <INPUT TYPE=HIDDEN NAME=\"month\" VALUE=\"$month\">\n".
228 " <INPUT TYPE=HIDDEN NAME=\"day\" VALUE=\"$day\">\n".
229 " <INPUT TYPE=HIDDEN NAME=\"hour\" VALUE=\"$hour\">\n".
230 " <INPUT TYPE=HIDDEN NAME=\"minute\" VALUE=\"$minute\">\n".
231 " <INPUT TYPE=HIDDEN NAME=\"event_year\" VALUE=\"$event_year\">\n".
232 " <INPUT TYPE=HIDDEN NAME=\"event_month\" VALUE=\"$event_month\">\n".
233 " <INPUT TYPE=HIDDEN NAME=\"event_day\" VALUE=\"$event_day\">\n".
234 " <INPUT TYPE=HIDDEN NAME=\"event_hour\" VALUE=\"$event_hour\">\n".
235 " <INPUT TYPE=HIDDEN NAME=\"event_minute\" VALUE=\"$event_minute\">\n".
236 " <INPUT TYPE=HIDDEN NAME=\"event_priority\" VALUE=\"$event_priority\">\n".
237 " <INPUT TYPE=HIDDEN NAME=\"event_length\" VALUE=\"$event_length\">\n".
238 " <INPUT TYPE=HIDDEN NAME=\"event_title\" VALUE=\"$event_title\">\n".
239 " <INPUT TYPE=HIDDEN NAME=\"event_text\" VALUE=\"$event_text\">\n".
240 " <INPUT TYPE=hidden NAME=\"updated\" VALUE=\"yes\">\n".
241 " <INPUT TYPE=HIDDEN NAME=\"confirmed\" VALUE=\"yes\">\n".
242 ' <INPUT TYPE=SUBMIT VALUE="' . _("Yes") . "\">\n".
243 " </FORM>\n" ,
244 'right', $color[4] ) ."\n" .
245 html_tag( 'td',
246 " <FORM NAME=\"nodelevent\" METHOD=POST ACTION=\"day.php\">\n".
247 " <INPUT TYPE=HIDDEN NAME=\"year\" VALUE=\"$year\">\n".
248 " <INPUT TYPE=HIDDEN NAME=\"month\" VALUE=\"$month\">\n".
249 " <INPUT TYPE=HIDDEN NAME=\"day\" VALUE=\"$day\">\n".
250 ' <INPUT TYPE=SUBMIT VALUE="' . _("No") . "\">\n".
251 " </FORM>\n" ,
252 'left', $color[4] ) ."\n"
253 ) ,
254 '', $color[0], 'border="0" cellpadding="2" cellspacing="1"' );
255 }
256
257 if ($month <= 0){
258 $month = date( 'm' );
259 }
260 if ($year <= 0){
261 $year = date( 'Y' );
262 }
263 if ($day <= 0){
264 $day = date( 'd' );
265 }
266 if ($hour <= 0){
267 $hour = '08';
268 }
269
270 $calself=basename($PHP_SELF);
271
272 displayPageHeader($color, 'None');
273 //load calendar menu
274 calendar_header();
275
276 echo html_tag( 'tr', '', '', $color[0] ) .
277 html_tag( 'td', '', 'left' ) .
278 html_tag( 'table', '', '', $color[0], 'width="100%" border="0" cellpadding="2" cellspacing="1"' ) .
279 html_tag( 'tr' ) .
280 html_tag( 'td',
281 date_intl( _("l, F j Y"), mktime(0, 0, 0, $month, $day, $year)) ,
282 'left', '', 'colspan="2"' );
283 if (!isset($updated)){
284 //get changes to event
285 readcalendardata();
286 show_event_form();
287 } else {
288 if (!isset($confirmed)){
289 //confirm changes
290 readcalendardata();
291 // strip event text so it fits in one line
292 $event_text=nl2br($event_text);
293 $event_text=ereg_replace ("\n", '', $event_text);
294 $event_text=ereg_replace ("\r", '', $event_text);
295 confirm_update();
296 } else {
297 update_event("$month$day$year", "$hour$minute");
298 echo html_tag( 'tr',
299 html_tag( 'td', _("Event updated!"), 'left' )
300 ) . "\n";
301 echo html_tag( 'tr',
302 html_tag( 'td',
303 "<a href=\"day.php?year=$year&amp;month=$month&amp;day=$day\">" .
304 _("Day View") ."</a>",
305 'left' )
306 ) . "\n";
307
308 $fixdate = date( 'mdY', mktime(0, 0, 0, $event_month, $event_day, $event_year));
309 //if event has been moved to different year then act accordingly
310 if ($year==$event_year){
311 $calendardata["$fixdate"]["$event_hour$event_minute"] = array("length"=>"$event_length","priority"=>"$event_priority","title"=>"$event_title","message"=>"$event_text");
312 writecalendardata();
313 } else {
314 writecalendardata();
315 $year=$event_year;
316 $calendardata = array();
317 readcalendardata();
318 $calendardata["$fixdate"]["$event_hour$event_minute"] = array("length"=>"$event_length","priority"=>"$event_priority","title"=>"$event_title","message"=>"$event_text");
319 writecalendardata();
320 }
321 }
322 }
323
324 ?>
325 </table></td></tr></table>
326 </body></html>