event_edit.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. /**
  3. * Functions to edit an event.
  4. *
  5. * @copyright &copy; 2002-2007 The SquirrelMail Project Team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package plugins
  9. * @subpackage calendar
  10. */
  11. /**
  12. * Include the SquirrelMail initialization file.
  13. */
  14. require('../../include/init.php');
  15. /* SquirrelMail required files. */
  16. /* date_intl() */
  17. include_once(SM_PATH . 'functions/date.php');
  18. /* form functions */
  19. include_once(SM_PATH . 'functions/forms.php');
  20. /* Calendar plugin required files. */
  21. include_once(SM_PATH . 'plugins/calendar/calendar_data.php');
  22. include_once(SM_PATH . 'plugins/calendar/functions.php');
  23. /* get globals */
  24. sqGetGlobalVar('updated',$updated,SQ_POST);
  25. /* get date values and make sure that they are numeric */
  26. if (! sqGetGlobalVar('event_year',$event_year,SQ_POST) || ! is_numeric($event_year)) {
  27. unset($event_year);
  28. }
  29. if (! sqGetGlobalVar('event_month',$event_month,SQ_POST) || ! is_numeric($event_month)) {
  30. unset($event_month);
  31. }
  32. if (! sqGetGlobalVar('event_day',$event_day,SQ_POST) || ! is_numeric($event_day)) {
  33. unset($event_day);
  34. }
  35. if (! sqGetGlobalVar('event_hour',$event_hour,SQ_POST) || ! is_numeric($event_hour)) {
  36. unset($event_hour);
  37. }
  38. if (! sqGetGlobalVar('event_minute',$event_minute,SQ_POST) || ! is_numeric($event_minute)) {
  39. unset($event_minute);
  40. }
  41. if (! sqGetGlobalVar('event_length',$event_length,SQ_POST) || ! is_numeric($event_length)) {
  42. unset($event_length);
  43. }
  44. sqGetGlobalVar('event_title',$event_title,SQ_POST);
  45. sqGetGlobalVar('event_text',$event_text,SQ_POST);
  46. sqGetGlobalVar('send',$send,SQ_POST);
  47. if (! sqGetGlobalVar('event_priority',$event_priority,SQ_POST) || ! is_numeric($event_priority)) {
  48. unset($event_priority);
  49. }
  50. sqGetGlobalVar('confirmed',$confirmed,SQ_POST);
  51. if (! sqGetGlobalVar('year',$year,SQ_FORM) || ! is_numeric($year)) {
  52. unset($year);
  53. }
  54. if (! sqGetGlobalVar('month',$month,SQ_FORM) || ! is_numeric($month)) {
  55. unset($month);
  56. }
  57. if (! sqGetGlobalVar('day',$day,SQ_FORM) || ! is_numeric($day)) {
  58. unset($day);
  59. }
  60. if (! sqGetGlobalVar('hour',$hour,SQ_FORM) || ! is_numeric($hour)) {
  61. unset($hour);
  62. }
  63. if (! sqGetGlobalVar('minute',$minute,SQ_FORM) || ! is_numeric($minute)) {
  64. unset($minute);
  65. }
  66. /* got 'em */
  67. /**
  68. * update event info
  69. * @return void
  70. * @access private
  71. */
  72. function update_event_form() {
  73. global $color, $editor_size, $year, $day, $month, $hour, $minute, $calendardata;
  74. $tmparray = $calendardata["$month$day$year"]["$hour$minute"];
  75. $tab = ' ';
  76. echo "\n<form name=\"eventupdate\" action=\"event_edit.php\" method=\"post\">\n".
  77. $tab . addHidden('year',$year).
  78. $tab . addHidden('month',$month).
  79. $tab . addHidden('day',$day).
  80. $tab . addHidden('hour',$hour).
  81. $tab . addHidden('minute',$minute).
  82. $tab . addHidden('updated','yes').
  83. html_tag( 'tr' ) .
  84. html_tag( 'td', _("Date:"), 'right', $color[4] ) . "\n" .
  85. html_tag( 'td', '', 'left', $color[4] ) .
  86. " <select name=\"event_year\">\n";
  87. select_option_year($year);
  88. echo " </select>\n" .
  89. " &nbsp;&nbsp;\n" .
  90. " <select name=\"event_month\">\n";
  91. select_option_month($month);
  92. echo " </select>\n".
  93. " &nbsp;&nbsp;\n".
  94. " <select name=\"event_day\">\n";
  95. select_option_day($day);
  96. echo " </select>\n".
  97. " </td></tr>\n".
  98. html_tag( 'tr' ) .
  99. html_tag( 'td', _("Time:"), 'right', $color[4] ) . "\n" .
  100. html_tag( 'td', '', 'left', $color[4] ) .
  101. " <select name=\"event_hour\">\n";
  102. select_option_hour($hour);
  103. echo " </select>\n".
  104. " &nbsp;:&nbsp;\n".
  105. " <select name=\"event_minute\">\n";
  106. select_option_minute($minute);
  107. echo " </select>\n".
  108. " </td></tr>\n".
  109. html_tag( 'tr' ) .
  110. html_tag( 'td', _("Length:"), 'right', $color[4] ) . "\n" .
  111. html_tag( 'td', '', 'left', $color[4] ) .
  112. " <select name=\"event_length\">\n";
  113. select_option_length($tmparray['length']);
  114. echo " </select>\n".
  115. " </td></tr>\n".
  116. html_tag( 'tr' ) .
  117. html_tag( 'td', _("Priority:"), 'right', $color[4] ) . "\n" .
  118. html_tag( 'td', '', 'left', $color[4] ) .
  119. " <select name=\"event_priority\">\n";
  120. select_option_priority($tmparray['priority']);
  121. echo " </select>\n".
  122. " </td></tr>\n".
  123. html_tag( 'tr' ) .
  124. html_tag( 'td', _("Title:"), 'right', $color[4] ) . "\n" .
  125. html_tag( 'td', addInput('event_title',$tmparray['title'],30,50), 'left', $color[4]) .
  126. "\n</tr>\n".
  127. html_tag( 'tr' ) .
  128. html_tag( 'td', addTextArea('event_text',$tmparray['message'],$editor_size,5),
  129. 'left', $color[4], 'colspan="2"' ) .
  130. '</tr>' . html_tag( 'tr' ) .
  131. html_tag( 'td', addSubmit(_("Update Event"),'send'), 'left', $color[4], 'colspan="2"' ) .
  132. "</tr></form>\n";
  133. }
  134. /**
  135. * Confirms event update
  136. * @return void
  137. * @access private
  138. */
  139. function confirm_update() {
  140. global $calself, $year, $month, $day, $hour, $minute, $calendardata,
  141. $color, $event_year, $event_month, $event_day, $event_hour,
  142. $event_minute, $event_length, $event_priority, $event_title, $event_text;
  143. $tmparray = $calendardata["$month$day$year"]["$hour$minute"];
  144. $tab = ' ';
  145. echo html_tag( 'table',
  146. html_tag( 'tr',
  147. html_tag( 'th', _("Do you really want to change this event from:") . "<br />\n", '', $color[4], 'colspan="2"' ) ."\n"
  148. ) .
  149. html_tag( 'tr',
  150. html_tag( 'td', _("Date:") , 'right', $color[4] ) ."\n" .
  151. html_tag( 'td', date_intl(_("m/d/Y"),mktime(0,0,0,$month,$day,$year)), 'left', $color[4] ) ."\n"
  152. ) .
  153. html_tag( 'tr',
  154. html_tag( 'td', _("Time:") , 'right', $color[4] ) ."\n" .
  155. html_tag( 'td', date_intl(_("H:i"),mktime($hour,$minute,0,$month,$day,$year)) , 'left', $color[4] ) ."\n"
  156. ) .
  157. html_tag( 'tr',
  158. html_tag( 'td', _("Priority:") , 'right', $color[4] ) ."\n" .
  159. html_tag( 'td', $tmparray['priority'] , 'left', $color[4] ) ."\n"
  160. ) .
  161. html_tag( 'tr',
  162. html_tag( 'td', _("Title:") , 'right', $color[4] ) ."\n" .
  163. html_tag( 'td', htmlspecialchars($tmparray['title']) , 'left', $color[4] ) ."\n"
  164. ) .
  165. html_tag( 'tr',
  166. html_tag( 'td', _("Message:") , 'right', $color[4] ) ."\n" .
  167. html_tag( 'td', nl2br(htmlspecialchars($tmparray['message'])) , 'left', $color[4] ) ."\n"
  168. ) .
  169. html_tag( 'tr',
  170. html_tag( 'th', _("to:") . "<br />\n", '', $color[4], 'colspan="2"' ) ."\n"
  171. ) .
  172. html_tag( 'tr',
  173. html_tag( 'td', _("Date:") , 'right', $color[4] ) ."\n" .
  174. html_tag( 'td', date_intl(_("m/d/Y"),mktime(0,0,0,$event_month,$event_day,$event_year)), 'left', $color[4] ) ."\n"
  175. ) .
  176. html_tag( 'tr',
  177. html_tag( 'td', _("Time:") , 'right', $color[4] ) ."\n" .
  178. html_tag( 'td', date_intl(_("H:i"),mktime($event_hour,$event_minute,0,$event_month,$event_day,$event_year)), 'left', $color[4] ) ."\n"
  179. ) .
  180. html_tag( 'tr',
  181. html_tag( 'td', _("Priority:") , 'right', $color[4] ) ."\n" .
  182. html_tag( 'td', $event_priority , 'left', $color[4] ) ."\n"
  183. ) .
  184. html_tag( 'tr',
  185. html_tag( 'td', _("Title:") , 'right', $color[4] ) ."\n" .
  186. html_tag( 'td', htmlspecialchars($event_title) , 'left', $color[4] ) ."\n"
  187. ) .
  188. html_tag( 'tr',
  189. html_tag( 'td', _("Message:") , 'right', $color[4] ) ."\n" .
  190. html_tag( 'td', nl2br(htmlspecialchars($event_text)) , 'left', $color[4] ) ."\n"
  191. ) .
  192. html_tag( 'tr',
  193. html_tag( 'td',
  194. "<form name=\"updateevent\" method=\"post\" action=\"$calself\">\n".
  195. $tab . addHidden('year',$year).
  196. $tab . addHidden('month',$month).
  197. $tab . addHidden('day',$day).
  198. $tab . addHidden('hour',$hour).
  199. $tab . addHidden('minute',$minute).
  200. $tab . addHidden('event_year',$event_year).
  201. $tab . addHidden('event_month',$event_month).
  202. $tab . addHidden('event_day',$event_day).
  203. $tab . addHidden('event_hour',$event_hour).
  204. $tab . addHidden('event_minute',$event_minute).
  205. $tab . addHidden('event_priority',$event_priority).
  206. $tab . addHidden('event_length',$event_length).
  207. $tab . addHidden('event_title',$event_title).
  208. $tab . addHidden('event_text',$event_text).
  209. $tab . addHidden('updated','yes').
  210. $tab . addHidden('confirmed','yes').
  211. $tab . addSubmit(_("Yes")).
  212. "</form>\n" ,
  213. 'right', $color[4] ) ."\n" .
  214. html_tag( 'td',
  215. "<form name=\"nodelevent\" method=\"post\" action=\"day.php\">\n".
  216. $tab . addHidden('year',$year).
  217. $tab . addHidden('month',$month).
  218. $tab . addHidden('day',$day).
  219. $tab . addSubmit(_("No")).
  220. "</form>\n" ,
  221. 'left', $color[4] ) ."\n"
  222. ) ,
  223. '', $color[0], 'border="0" cellpadding="2" cellspacing="1"' );
  224. }
  225. if ($month <= 0){
  226. $month = date( 'm' );
  227. }
  228. if ($year <= 0){
  229. $year = date( 'Y' );
  230. }
  231. if ($day <= 0){
  232. $day = date( 'd' );
  233. }
  234. if ($hour <= 0){
  235. $hour = '08';
  236. }
  237. $calself=basename($PHP_SELF);
  238. displayPageHeader($color, 'None');
  239. //load calendar menu
  240. calendar_header();
  241. echo html_tag( 'tr', '', '', $color[0] ) .
  242. html_tag( 'td', '', 'left' ) .
  243. html_tag( 'table', '', '', $color[0], 'width="100%" border="0" cellpadding="2" cellspacing="1"' ) .
  244. html_tag( 'tr' ) .
  245. html_tag( 'td',
  246. date_intl( _("l, F j Y"), mktime(0, 0, 0, $month, $day, $year)) ,
  247. 'left', '', 'colspan="2"' );
  248. if (!isset($updated)){
  249. //get changes to event
  250. readcalendardata();
  251. update_event_form();
  252. } else {
  253. if (!isset($confirmed)){
  254. //confirm changes
  255. readcalendardata();
  256. confirm_update();
  257. } else {
  258. update_event("$month$day$year", "$hour$minute");
  259. echo html_tag( 'tr',
  260. html_tag( 'td', _("Event updated!"), 'left' )
  261. ) . "\n";
  262. echo html_tag( 'tr',
  263. html_tag( 'td',
  264. "<a href=\"day.php?year=$year&amp;month=$month&amp;day=$day\">" .
  265. _("Day View") ."</a>",
  266. 'left' )
  267. ) . "\n";
  268. $fixdate = date( 'mdY', mktime(0, 0, 0, $event_month, $event_day, $event_year));
  269. //if event has been moved to different year then act accordingly
  270. if ($year==$event_year){
  271. $calendardata["$fixdate"]["$event_hour$event_minute"] = array('length' => $event_length,
  272. 'priority' => $event_priority,
  273. 'title' => $event_title,
  274. 'message' => $event_text);
  275. writecalendardata();
  276. } else {
  277. writecalendardata();
  278. $year=$event_year;
  279. $calendardata = array();
  280. readcalendardata();
  281. $calendardata["$fixdate"]["$event_hour$event_minute"] = array('length' => $event_length,
  282. 'priority' => $event_priority,
  283. 'title' => $event_title,
  284. 'message' => $event_text);
  285. writecalendardata();
  286. }
  287. }
  288. }
  289. ?>
  290. </table></td></tr></table>
  291. </body></html>