PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/mrbs/tags/mrbs-1-0-pre2/web/edit_entry.php

https://github.com/jessfishenden/mrbs-mcr
PHP | 320 lines | 244 code | 53 blank | 23 comment | 48 complexity | 2d2e3a3f4315ae1f7bff34bd44ba0689 MD5 | raw file
  1. <?php
  2. # $Id$
  3. include "config.inc";
  4. include "functions.inc";
  5. include "$dbsys.inc";
  6. include "mrbs_auth.inc";
  7. #If we dont know the right date then make it up
  8. if(!isset($day) or !isset($month) or !isset($year))
  9. {
  10. $day = date("d");
  11. $month = date("m");
  12. $year = date("Y");
  13. }
  14. if(empty($area))
  15. $area = get_default_area();
  16. if(!isset($edit_type))
  17. $edit_type = "";
  18. if(!getAuthorised(getUserName(), getUserPassword(), 1))
  19. {
  20. showAccessDenied($day, $month, $year, $area);
  21. exit;
  22. }
  23. # This page will either add or modify a booking
  24. # We need to know:
  25. # Name of booker
  26. # Description of meeting
  27. # Date (option select box for day, month, year)
  28. # Time
  29. # Duration
  30. # Internal/External
  31. # Firstly we need to know if this is a new booking or modifying an old one
  32. # and if it's a modification we need to get all the old data from the db.
  33. # If we had $id passed in then it's a modification.
  34. if (isset($id))
  35. {
  36. $sql = "select name, create_by, description, start_time, end_time - start_time,
  37. type, room_id, entry_type, repeat_id from mrbs_entry where id=$id";
  38. $res = sql_query($sql);
  39. if (! $res) fatal_error(1, sql_error());
  40. if (sql_count($res) != 1) fatal_error(1, "Entry ID $id not found");
  41. $row = sql_row($res, 0);
  42. sql_free($res);
  43. # Note: Removed stripslashes() calls from name and description. Previous
  44. # versions of MRBS mistakenly had the backslash-escapes in the actual database
  45. # records because of an extra addslashes going on. Fix your database and
  46. # leave this code alone, please.
  47. $name = $row[0];
  48. $create_by = $row[1];
  49. $description = $row[2];
  50. $start_day = strftime('%d', $row[3]);
  51. $start_month = strftime('%m', $row[3]);
  52. $start_year = strftime('%Y', $row[3]);
  53. $start_hour = strftime('%H', $row[3]);
  54. $start_min = strftime('%M', $row[3]);
  55. $duration = $row[4];
  56. $type = $row[5];
  57. $room_id = $row[6];
  58. $entry_type = $row[7];
  59. $rep_id = $row[8];
  60. if($entry_type >= 1)
  61. {
  62. $sql = "SELECT rep_type, start_time, end_date, rep_opt
  63. FROM mrbs_repeat WHERE id=$rep_id";
  64. $res = sql_query($sql);
  65. if (! $res) fatal_error(1, sql_error());
  66. if (sql_count($res) != 1) fatal_error(1, "Repeat ID $rep_id not found");
  67. $row = sql_row($res, 0);
  68. sql_free($res);
  69. $rep_type = $row[0];
  70. if($edit_type == "series")
  71. {
  72. $start_day = (int)strftime('%d', $row[1]);
  73. $start_month = (int)strftime('%m', $row[1]);
  74. $start_year = (int)strftime('%Y', $row[1]);
  75. $rep_end_day = (int)strftime('%d', $row[2]);
  76. $rep_end_month = (int)strftime('%m', $row[2]);
  77. $rep_end_year = (int)strftime('%Y', $row[2]);
  78. switch($rep_type)
  79. {
  80. case 2:
  81. $rep_day[0] = $row[3][0] != "0";
  82. $rep_day[1] = $row[3][1] != "0";
  83. $rep_day[2] = $row[3][2] != "0";
  84. $rep_day[3] = $row[3][3] != "0";
  85. $rep_day[4] = $row[3][4] != "0";
  86. $rep_day[5] = $row[3][5] != "0";
  87. $rep_day[6] = $row[3][6] != "0";
  88. break;
  89. default:
  90. $rep_day = array(0, 0, 0, 0, 0, 0, 0);
  91. }
  92. }
  93. else
  94. {
  95. $rep_type = $row[0];
  96. $rep_end_date = strftime('%A %d %B %Y',$row[2]);
  97. $rep_opt = $row[3];
  98. }
  99. }
  100. }
  101. else
  102. {
  103. # It is a new booking. The data comes from whichever button the user clicked
  104. $edit_type = "series";
  105. $name = "";
  106. $create_by = getUserName();
  107. $description = "";
  108. $start_day = $day;
  109. $start_month = $month;
  110. $start_year = $year;
  111. $start_hour = $hour;
  112. $start_min = $minute;
  113. $duration = 60 * 60;
  114. $type = "I";
  115. $room_id = $room;
  116. $rep_id = 0;
  117. $rep_type = 0;
  118. $rep_end_day = $day;
  119. $rep_end_month = $month;
  120. $rep_end_year = $year;
  121. $rep_day = array(0, 0, 0, 0, 0, 0, 0);
  122. }
  123. toTimeString($duration, $dur_units);
  124. #now that we know all the data to fill the form with we start drawing it
  125. if(!getWritable($create_by, getUserName()))
  126. {
  127. showAccessDenied($day, $month, $year, $area);
  128. exit;
  129. }
  130. print_header($day, $month, $year, $area);
  131. ?>
  132. <SCRIPT LANGUAGE="JavaScript">
  133. // do a little form verifying
  134. function validate_and_submit ()
  135. {
  136. if(document.forms["main"].name.value == "")
  137. {
  138. alert ( "You have not entered a\nBrief Description." );
  139. return false;
  140. }
  141. h = parseInt(document.forms["main"].hour.value);
  142. m = parseInt(document.forms["main"].minute.value);
  143. if(h > 23 || m > 59)
  144. {
  145. alert("You have not entered a\nvalid time of day.");
  146. return false;
  147. }
  148. // would be nice to also check date to not allow Feb 31, etc...
  149. document.forms["main"].submit();
  150. return true;
  151. }
  152. </SCRIPT>
  153. <h2><? echo isset($id) ? $lang["editentry"] : $lang["addentry"]; ?></H2>
  154. <FORM NAME="main" ACTION="edit_entry_handler.php" METHOD="GET">
  155. <TABLE BORDER=0>
  156. <TR><TD CLASS=CR><B><? echo $lang["namebooker"]?></B></TD>
  157. <TD CLASS=CL><INPUT NAME="name" SIZE=40 VALUE="<? echo htmlentities($name) ?>"></TD></TR>
  158. <TR><TD CLASS=TR><B><?echo $lang["fulldescription"]?></B></TD>
  159. <TD CLASS=TL><TEXTAREA NAME="description" ROWS=8 COLS=40 WRAP="virtual"><? echo htmlentities ( $description ); ?></TEXTAREA></TD></TR>
  160. <TR><TD CLASS=CR><B><? echo $lang["date"]?></B></TD>
  161. <TD CLASS=CL>
  162. <? genDateSelector("", $start_day, $start_month, $start_year) ?>
  163. </TD>
  164. </TR>
  165. <TR><TD CLASS=CR><B><?echo $lang["time"]?></B></TD>
  166. <TD CLASS=CL><INPUT NAME="hour" SIZE=2 VALUE="<? echo $start_hour;?>" MAXLENGTH=2>:<INPUT NAME="minute" SIZE=2 VALUE="<? echo $start_min;?>" MAXLENGTH=2>
  167. </TD></TR>
  168. <TR><TD CLASS=CR><B><? echo $lang["duration"];?></B></TD>
  169. <TD CLASS=CL><INPUT NAME="duration" SIZE=7 VALUE="<? echo $duration;?>">
  170. <SELECT NAME="dur_units">
  171. <?
  172. $units = array("minutes", "hours", "days", "weeks");
  173. while (list(,$unit) = each($units))
  174. {
  175. echo "<OPTION VALUE=$unit";
  176. if ($dur_units == $lang[$unit]) echo " SELECTED";
  177. echo ">$lang[$unit]";
  178. }
  179. ?>
  180. </SELECT>
  181. <INPUT NAME="all_day" TYPE="checkbox" VALUE="yes"> <? echo $lang["all_day"]; ?>
  182. </TD></TR>
  183. <TR><TD CLASS=CR><B><?echo $lang["type"]?></B></TD>
  184. <TD CLASS=CL><SELECT NAME="type">
  185. <?
  186. for ($c = "A"; $c <= "J"; $c++)
  187. {
  188. if (!empty($typel[$c]))
  189. echo "<OPTION VALUE=$c" . ($type == $c ? " SELECTED" : "") . ">$typel[$c]\n";
  190. }
  191. ?></SELECT></TD></TR>
  192. <? if($edit_type == "series") { ?>
  193. <TR>
  194. <TD CLASS=CR><B><?echo $lang["rep_type"]?></B></TD>
  195. <TD CLASS=CL>
  196. <?
  197. for($i = 0; isset($lang["rep_type_$i"]); $i++)
  198. {
  199. echo "<INPUT NAME=\"rep_type\" TYPE=\"RADIO\" VALUE=\"" . $i . "\"";
  200. if($i == $rep_type)
  201. echo " CHECKED";
  202. echo ">" . $lang["rep_type_$i"] . "\n";
  203. }
  204. ?>
  205. </TD>
  206. </TR>
  207. <TR>
  208. <TD CLASS=CR><B><?echo $lang["rep_end_date"]?></B></TD>
  209. <TD CLASS=CL><? genDateSelector("rep_end_", $rep_end_day, $rep_end_month, $rep_end_year) ?></TD>
  210. </TR>
  211. <TR>
  212. <TD CLASS=CR><B><? echo $lang["rep_rep_day"]?></B> <? echo $lang["rep_for_weekly"]?></TD>
  213. <TD CLASS=CL>
  214. <?php
  215. # Display day name checkboxes according to language and preferred weekday start.
  216. for ($i = 0; $i < 7; $i++)
  217. {
  218. $wday = ($i + $weekstarts) % 7;
  219. echo "<INPUT NAME=\"rep_day[$wday]\" TYPE=CHECKBOX";
  220. if ($rep_day[$wday]) echo " CHECKED";
  221. echo ">" . day_name($wday) . "\n";
  222. }
  223. ?>
  224. </TD>
  225. </TR>
  226. <?
  227. }
  228. else
  229. {
  230. $key = "rep_type_" . (isset($rep_type) ? $rep_type : "0");
  231. echo "<tr><td class=CR><b>$lang[rep_type]</b></td><td class=CL>$lang[$key]</td></tr>\n";
  232. if(isset($rep_type) && ($rep_type != 0))
  233. {
  234. $opt = "";
  235. if ($rep_type == 2)
  236. {
  237. # Display day names according to language and preferred weekday start.
  238. for ($i = 0; $i < 7; $i++)
  239. {
  240. $wday = ($i + $weekstarts) % 7;
  241. if ($rep_opt[$wday]) $opt .= day_name($wday) . " ";
  242. }
  243. }
  244. if($opt)
  245. echo "<tr><td class=CR><b>$lang[rep_rep_day]</b></td><td class=CL>$opt</td></tr>\n";
  246. echo "<tr><td class=CR><b>$lang[rep_end_date]</b></td><td class=CL>$rep_end_date</td></tr>\n";
  247. }
  248. }
  249. ?>
  250. <TR>
  251. <TD colspan=2 align=center>
  252. <SCRIPT LANGUAGE="JavaScript">
  253. document.writeln ( '<INPUT TYPE="button" VALUE="<?echo $lang["save"]?>" ONCLICK="validate_and_submit()">' );
  254. </SCRIPT>
  255. <NOSCRIPT>
  256. <INPUT TYPE="submit" VALUE="<? echo $lang["save"]?>">
  257. </NOSCRIPT>
  258. </TD></TR>
  259. </TABLE>
  260. <INPUT TYPE=HIDDEN NAME="returl" VALUE="<? echo $HTTP_REFERER?>">
  261. <INPUT TYPE=HIDDEN NAME="room_id" VALUE="<? echo $room_id?>">
  262. <INPUT TYPE=HIDDEN NAME="create_by" VALUE="<? echo $create_by?>">
  263. <INPUT TYPE=HIDDEN NAME="rep_id" VALUE="<? echo $rep_id?>">
  264. <INPUT TYPE=HIDDEN NAME="edit_type" VALUE="<? echo $edit_type?>">
  265. <? if(isset($id)) echo "<INPUT TYPE=HIDDEN NAME=\"id\" VALUE=\"$id\">\n"; ?>
  266. </FORM>
  267. <? include "trailer.inc" ?>