098aeb6cd85969e7f6b0bb4a38f845a91763577b
[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 // update event info
31 function show_event_form() {
32 global $color, $editor_size, $year, $day, $month, $hour, $minute, $calendardata;
33
34 $tmparray = $calendardata["$month$day$year"]["$hour$minute"];
35 echo "\n<FORM name=eventupdate action=\"event_edit.php\" METHOD=POST >\n".
36 " <INPUT TYPE=hidden NAME=\"year\" VALUE=\"$year\">\n".
37 " <INPUT TYPE=hidden NAME=\"month\" VALUE=\"$month\">\n".
38 " <INPUT TYPE=hidden NAME=\"day\" VALUE=\"$day\">\n".
39 " <INPUT TYPE=hidden NAME=\"hour\" VALUE=\"$hour\">\n".
40 " <INPUT TYPE=hidden NAME=\"minute\" VALUE=\"$minute\">\n".
41 " <INPUT TYPE=hidden NAME=\"updated\" VALUE=\"yes\">\n".
42 html_tag( 'tr' ) .
43 html_tag( 'td', _("Date:"), 'right', $color[4] ) . "\n" .
44 html_tag( 'td', '', 'left', $color[4] ) .
45 " <SELECT NAME=\"event_year\">\n";
46 select_option_year($year);
47 echo " </SELECT>\n" .
48 " &nbsp;&nbsp;\n" .
49 " <SELECT NAME=\"event_month\">\n";
50 select_option_month($month);
51 echo " </SELECT>\n".
52 " &nbsp;&nbsp;\n".
53 " <SELECT NAME=\"event_day\">\n";
54 select_option_day($day);
55 echo " </SELECT>\n".
56 " </td></tr>\n".
57 html_tag( 'tr' ) .
58 html_tag( 'td', _("Time:"), 'right', $color[4] ) . "\n" .
59 html_tag( 'td', '', 'left', $color[4] ) .
60 " <SELECT NAME=\"event_hour\">\n";
61 select_option_hour($hour);
62 echo " </SELECT>\n".
63 " &nbsp;:&nbsp;\n".
64 " <SELECT NAME=\"event_minute\">\n";
65 select_option_minute($minute);
66 echo " </SELECT>\n".
67 " </td></tr>\n".
68 html_tag( 'tr' ) .
69 html_tag( 'td', _("Length:"), 'right', $color[4] ) . "\n" .
70 html_tag( 'td', '', 'left', $color[4] ) .
71 " <SELECT NAME=\"event_length\">\n";
72 select_option_length($tmparray[length]);
73 echo " </SELECT>\n".
74 " </td></tr>\n".
75 html_tag( 'tr' ) .
76 html_tag( 'td', _("Priority:"), 'right', $color[4] ) . "\n" .
77 html_tag( 'td', '', 'left', $color[4] ) .
78 " <SELECT NAME=\"event_priority\">\n";
79 select_option_priority($tmparray[priority]);
80 echo " </SELECT>\n".
81 " </td></tr>\n".
82 html_tag( 'tr' ) .
83 html_tag( 'td', _("Title:"), 'right', $color[4] ) . "\n" .
84 html_tag( 'td', '', 'left', $color[4] ) .
85 " <INPUT TYPE=text NAME=\"event_title\" VALUE=\"$tmparray[title]\" SIZE=30 MAXLENGTH=50><BR>\n".
86 " </td></tr>\n".
87 html_tag( 'td',
88 " <TEXTAREA NAME=\"event_text\" ROWS=5 COLS=\"$editor_size\" WRAP=HARD>$tmparray[message]</TEXTAREA>\n" ,
89 'left', $color[4], 'colspan="2"' ) .
90 '</tr>' . html_tag( 'tr' ) .
91 html_tag( 'td',
92 "<INPUT TYPE=SUBMIT NAME=send VALUE=\"" .
93 _("Update Event") . "\">\n" ,
94 'left', $color[4], 'colspan="2"' ) .
95 "</tr></FORM>\n";
96 }
97
98 // self explenatory
99 function confirm_update() {
100 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;
101
102 $tmparray = $calendardata["$month$day$year"]["$hour$minute"];
103
104 echo html_tag( 'table',
105 html_tag( 'tr',
106 html_tag( 'th', _("Do you really want to change this event from:") . "<br>\n", '', $color[4], 'colspan="2"' ) ."\n"
107 ) .
108 html_tag( 'tr',
109 html_tag( 'td', _("Date:") , 'right', $color[4] ) ."\n" .
110 html_tag( 'td', $month.'/'.$day.'/'.$year , 'left', $color[4] ) ."\n"
111 ) .
112 html_tag( 'tr',
113 html_tag( 'td', _("Time:") , 'right', $color[4] ) ."\n" .
114 html_tag( 'td', $hour.':'.$minute , 'left', $color[4] ) ."\n"
115 ) .
116 html_tag( 'tr',
117 html_tag( 'td', _("Priority:") , 'right', $color[4] ) ."\n" .
118 html_tag( 'td', $tmparray[priority] , 'left', $color[4] ) ."\n"
119 ) .
120 html_tag( 'tr',
121 html_tag( 'td', _("Title:") , 'right', $color[4] ) ."\n" .
122 html_tag( 'td', $tmparray[title] , 'left', $color[4] ) ."\n"
123 ) .
124 html_tag( 'tr',
125 html_tag( 'td', _("Message:") , 'right', $color[4] ) ."\n" .
126 html_tag( 'td', $tmparray[message] , 'left', $color[4] ) ."\n"
127 ) .
128 html_tag( 'tr',
129 html_tag( 'th', _("to:") . "<br>\n", '', $color[4], 'colspan="2"' ) ."\n"
130 ) .
131
132 html_tag( 'tr',
133 html_tag( 'td', _("Date:") , 'right', $color[4] ) ."\n" .
134 html_tag( 'td', $event_month.'/'.$event_day.'/'.$event_year , 'left', $color[4] ) ."\n"
135 ) .
136 html_tag( 'tr',
137 html_tag( 'td', _("Time:") , 'right', $color[4] ) ."\n" .
138 html_tag( 'td', $event_hour.':'.$event_minute , 'left', $color[4] ) ."\n"
139 ) .
140 html_tag( 'tr',
141 html_tag( 'td', _("Priority:") , 'right', $color[4] ) ."\n" .
142 html_tag( 'td', $event_priority , 'left', $color[4] ) ."\n"
143 ) .
144 html_tag( 'tr',
145 html_tag( 'td', _("Title:") , 'right', $color[4] ) ."\n" .
146 html_tag( 'td', $event_title , 'left', $color[4] ) ."\n"
147 ) .
148 html_tag( 'tr',
149 html_tag( 'td', _("Message:") , 'right', $color[4] ) ."\n" .
150 html_tag( 'td', $event_text , 'left', $color[4] ) ."\n"
151 ) .
152 html_tag( 'tr',
153 html_tag( 'td',
154 " <FORM NAME=\"updateevent\" METHOD=POST ACTION=\"$calself\">\n".
155 " <INPUT TYPE=HIDDEN NAME=\"year\" VALUE=\"$year\">\n".
156 " <INPUT TYPE=HIDDEN NAME=\"month\" VALUE=\"$month\">\n".
157 " <INPUT TYPE=HIDDEN NAME=\"day\" VALUE=\"$day\">\n".
158 " <INPUT TYPE=HIDDEN NAME=\"hour\" VALUE=\"$hour\">\n".
159 " <INPUT TYPE=HIDDEN NAME=\"minute\" VALUE=\"$minute\">\n".
160 " <INPUT TYPE=HIDDEN NAME=\"event_year\" VALUE=\"$event_year\">\n".
161 " <INPUT TYPE=HIDDEN NAME=\"event_month\" VALUE=\"$event_month\">\n".
162 " <INPUT TYPE=HIDDEN NAME=\"event_day\" VALUE=\"$event_day\">\n".
163 " <INPUT TYPE=HIDDEN NAME=\"event_hour\" VALUE=\"$event_hour\">\n".
164 " <INPUT TYPE=HIDDEN NAME=\"event_minute\" VALUE=\"$event_minute\">\n".
165 " <INPUT TYPE=HIDDEN NAME=\"event_priority\" VALUE=\"$event_priority\">\n".
166 " <INPUT TYPE=HIDDEN NAME=\"event_length\" VALUE=\"$event_length\">\n".
167 " <INPUT TYPE=HIDDEN NAME=\"event_title\" VALUE=\"$event_title\">\n".
168 " <INPUT TYPE=HIDDEN NAME=\"event_text\" VALUE=\"$event_text\">\n".
169 " <INPUT TYPE=hidden NAME=\"updated\" VALUE=\"yes\">\n".
170 " <INPUT TYPE=HIDDEN NAME=\"confirmed\" VALUE=\"yes\">\n".
171 ' <INPUT TYPE=SUBMIT VALUE="' . _("Yes") . "\">\n".
172 " </FORM>\n" ,
173 'right', $color[4] ) ."\n" .
174 html_tag( 'td',
175 " <FORM NAME=\"nodelevent\" METHOD=POST ACTION=\"day.php\">\n".
176 " <INPUT TYPE=HIDDEN NAME=\"year\" VALUE=\"$year\">\n".
177 " <INPUT TYPE=HIDDEN NAME=\"month\" VALUE=\"$month\">\n".
178 " <INPUT TYPE=HIDDEN NAME=\"day\" VALUE=\"$day\">\n".
179 ' <INPUT TYPE=SUBMIT VALUE="' . _("No") . "\">\n".
180 " </FORM>\n" ,
181 'left', $color[4] ) ."\n"
182 ) ,
183 '', $color[0], 'border="0" cellpadding="2" cellspacing="1"' );
184 }
185
186 if ($month <= 0){
187 $month = date( 'm' );
188 }
189 if ($year <= 0){
190 $year = date( 'Y' );
191 }
192 if ($day <= 0){
193 $day = date( 'd' );
194 }
195 if ($hour <= 0){
196 $hour = '08';
197 }
198
199 $calself=basename($PHP_SELF);
200
201 displayPageHeader($color, 'None');
202 //load calendar menu
203 calendar_header();
204
205 echo html_tag( 'tr', '', '', $color[0] ) .
206 html_tag( 'td', '', 'left' ) .
207 html_tag( 'table', '', '', $color[0], 'width="100%" border="0" cellpadding="2" cellspacing="1"' ) .
208 html_tag( 'tr' ) .
209 html_tag( 'td',
210 date_intl( _("l, F j Y"), mktime(0, 0, 0, $month, $day, $year)) ,
211 'left', '', 'colspan="2"' );
212 if (!isset($updated)){
213 //get changes to event
214 readcalendardata();
215 show_event_form();
216 } else {
217 if (!isset($confirmed)){
218 //confirm changes
219 readcalendardata();
220 // strip event text so it fits in one line
221 $event_text=nl2br($event_text);
222 $event_text=ereg_replace ("\n", '', $event_text);
223 $event_text=ereg_replace ("\r", '', $event_text);
224 confirm_update();
225 } else {
226 update_event("$month$day$year", "$hour$minute");
227 echo html_tag( 'tr',
228 html_tag( 'td', _("Event updated!"), 'left' )
229 ) . "\n";
230 echo html_tag( 'tr',
231 html_tag( 'td',
232 "<a href=\"day.php?year=$year&month=$month&day=$day\">" .
233 _("Day View") ."</a>",
234 'left' )
235 ) . "\n";
236
237 $fixdate = date( 'mdY', mktime(0, 0, 0, $event_month, $event_day, $event_year));
238 //if event has been moved to different year then act accordingly
239 if ($year==$event_year){
240 $calendardata["$fixdate"]["$event_hour$event_minute"] = array("length"=>"$event_length","priority"=>"$event_priority","title"=>"$event_title","message"=>"$event_text");
241 writecalendardata();
242 } else {
243 writecalendardata();
244 $year=$event_year;
245 $calendardata = array();
246 readcalendardata();
247 $calendardata["$fixdate"]["$event_hour$event_minute"] = array("length"=>"$event_length","priority"=>"$event_priority","title"=>"$event_title","message"=>"$event_text");
248 writecalendardata();
249 }
250 }
251 }
252
253 ?>
254 </table></td></tr></table>
255 </body></html>