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