PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/mrbs/trunk/web/view_entry.php

https://github.com/jessfishenden/mrbs-mcr
PHP | 415 lines | 348 code | 45 blank | 22 comment | 48 complexity | 90487630b4103ff9c74592ee9423c1eb MD5 | raw file
  1. <?php
  2. // $Id$
  3. require_once "defaultincludes.inc";
  4. $user = getUserName();
  5. // Get form variables
  6. $day = get_form_var('day', 'int');
  7. $month = get_form_var('month', 'int');
  8. $year = get_form_var('year', 'int');
  9. $area = get_form_var('area', 'int');
  10. $room = get_form_var('room', 'int');
  11. $id = get_form_var('id', 'int');
  12. $series = get_form_var('series', 'int');
  13. // If we dont know the right date then make it up
  14. if (!isset($day) or !isset($month) or !isset($year))
  15. {
  16. $day = date("d");
  17. $month = date("m");
  18. $year = date("Y");
  19. }
  20. if (empty($area))
  21. {
  22. $area = get_default_area();
  23. }
  24. print_header($day, $month, $year, $area, isset($room) ? $room : "");
  25. if (empty($series))
  26. {
  27. $series = 0;
  28. }
  29. else
  30. {
  31. $series = 1;
  32. }
  33. if ($series)
  34. {
  35. $sql = "
  36. SELECT $tbl_repeat.name,
  37. $tbl_repeat.description,
  38. $tbl_repeat.create_by,
  39. $tbl_room.room_name,
  40. $tbl_area.area_name,
  41. $tbl_repeat.type,
  42. $tbl_repeat.private,
  43. $tbl_repeat.room_id,
  44. " . sql_syntax_timestamp_to_unix("$tbl_repeat.timestamp") . " AS last_updated,
  45. ($tbl_repeat.end_time - $tbl_repeat.start_time) AS duration,
  46. $tbl_repeat.start_time,
  47. $tbl_repeat.end_time,
  48. $tbl_repeat.rep_type,
  49. $tbl_repeat.end_date,
  50. $tbl_repeat.rep_opt,
  51. $tbl_repeat.rep_num_weeks
  52. FROM $tbl_repeat, $tbl_room, $tbl_area
  53. WHERE $tbl_repeat.room_id = $tbl_room.id
  54. AND $tbl_room.area_id = $tbl_area.id
  55. AND $tbl_repeat.id=$id
  56. ";
  57. }
  58. else
  59. {
  60. $sql = "
  61. SELECT $tbl_entry.name,
  62. $tbl_entry.description,
  63. $tbl_entry.create_by,
  64. $tbl_room.room_name,
  65. $tbl_area.area_name,
  66. $tbl_entry.type,
  67. $tbl_entry.private,
  68. $tbl_entry.room_id,
  69. " . sql_syntax_timestamp_to_unix("$tbl_entry.timestamp") . " AS last_updated,
  70. ($tbl_entry.end_time - $tbl_entry.start_time) AS duration,
  71. $tbl_entry.start_time,
  72. $tbl_entry.end_time,
  73. $tbl_entry.repeat_id
  74. FROM $tbl_entry, $tbl_room, $tbl_area
  75. WHERE $tbl_entry.room_id = $tbl_room.id
  76. AND $tbl_room.area_id = $tbl_area.id
  77. AND $tbl_entry.id=$id
  78. ";
  79. }
  80. $res = sql_query($sql);
  81. if (! $res)
  82. {
  83. fatal_error(0, sql_error());
  84. }
  85. if (sql_count($res) < 1)
  86. {
  87. fatal_error(0,
  88. ($series ? get_vocab("invalid_series_id") : get_vocab("invalid_entry_id"))
  89. );
  90. }
  91. $row = sql_row_keyed($res, 0);
  92. sql_free($res);
  93. $name = htmlspecialchars($row['name']);
  94. $description = htmlspecialchars($row['description']);
  95. $create_by = htmlspecialchars($row['create_by']);
  96. $room_name = htmlspecialchars($row['room_name']);
  97. $area_name = htmlspecialchars($row['area_name']);
  98. $type = $row['type'];
  99. $private = $row['private'];
  100. $room_id = $row['room_id'];
  101. $updated = time_date_string($row['last_updated']);
  102. // need to make DST correct in opposite direction to entry creation
  103. // so that user see what he expects to see
  104. $duration = $row['duration'] - cross_dst($row['start_time'],
  105. $row['end_time']);
  106. $writeable = getWritable($create_by,$user);
  107. if (is_private_event($private) && !$writeable)
  108. {
  109. $name = "[".get_vocab('private')."]";
  110. $description = $name;
  111. $create_by = $name;
  112. $keep_private = TRUE;
  113. }
  114. else
  115. {
  116. $keep_private = FALSE;
  117. }
  118. if ($enable_periods)
  119. {
  120. list($start_period, $start_date) = period_date_string($row['start_time']);
  121. }
  122. else
  123. {
  124. $start_date = time_date_string($row['start_time']);
  125. }
  126. if ($enable_periods)
  127. {
  128. list( , $end_date) = period_date_string($row['end_time'], -1);
  129. }
  130. else
  131. {
  132. $end_date = time_date_string($row['end_time']);
  133. }
  134. $rep_type = 0;
  135. if ($series == 1)
  136. {
  137. $rep_type = $row['rep_type'];
  138. $rep_end_date = utf8_strftime('%A %d %B %Y',$row['end_date']);
  139. $rep_opt = $row['rep_opt'];
  140. $rep_num_weeks = $row['rep_num_weeks'];
  141. // I also need to set $id to the value of a single entry as it is a
  142. // single entry from a series that is used by del_entry.php and
  143. // edit_entry.php
  144. // So I will look for the first entry in the series where the entry is
  145. // as per the original series settings
  146. $sql = "SELECT id
  147. FROM $tbl_entry
  148. WHERE repeat_id=\"$id\" AND entry_type=\"1\"
  149. ORDER BY start_time
  150. LIMIT 1";
  151. $res = sql_query($sql);
  152. if (! $res)
  153. {
  154. fatal_error(0, sql_error());
  155. }
  156. if (sql_count($res) < 1)
  157. {
  158. // if all entries in series have been modified then
  159. // as a fallback position just select the first entry
  160. // in the series
  161. // hopefully this code will never be reached as
  162. // this page will display the start time of the series
  163. // but edit_entry.php will display the start time of the entry
  164. sql_free($res);
  165. $sql = "SELECT id
  166. FROM $tbl_entry
  167. WHERE repeat_id=\"$id\"
  168. ORDER BY start_time
  169. LIMIT 1";
  170. $res = sql_query($sql);
  171. if (! $res)
  172. {
  173. fatal_error(0, sql_error());
  174. }
  175. }
  176. $row = sql_row_keyed($res, 0);
  177. $id = $row['id'];
  178. sql_free($res);
  179. }
  180. else
  181. {
  182. $repeat_id = $row['repeat_id'];
  183. if ($repeat_id != 0)
  184. {
  185. $res = sql_query("SELECT rep_type, end_date, rep_opt, rep_num_weeks
  186. FROM $tbl_repeat WHERE id=$repeat_id");
  187. if (! $res)
  188. {
  189. fatal_error(0, sql_error());
  190. }
  191. if (sql_count($res) == 1)
  192. {
  193. $row = sql_row_keyed($res, 0);
  194. $rep_type = $row['rep_type'];
  195. $rep_end_date = utf8_strftime('%A %d %B %Y',$row['end_date']);
  196. $rep_opt = $row['rep_opt'];
  197. $rep_num_weeks = $row['rep_num_weeks'];
  198. }
  199. sql_free($res);
  200. }
  201. }
  202. $enable_periods ? toPeriodString($start_period, $duration, $dur_units) : toTimeString($duration, $dur_units);
  203. $repeat_key = "rep_type_" . $rep_type;
  204. // Now that we know all the data we start drawing it
  205. echo "<h3" . (($keep_private) ? " class=\"private\"" : "") . ">\n";
  206. echo $name;
  207. if (is_private_event($private) && $writeable)
  208. {
  209. echo ' ('.get_vocab('private').')';
  210. }
  211. echo "</h3>\n";
  212. ?>
  213. <table id="entry">
  214. <tr>
  215. <td><?php echo get_vocab("description") ?>:</td>
  216. <?php
  217. echo "<td" . (($keep_private) ? " class=\"private\"" : "") . ">" . mrbs_nl2br($description) . "</td>\n";
  218. ?>
  219. </tr>
  220. <tr>
  221. <td><?php echo get_vocab("room") ?>:</td>
  222. <td><?php echo mrbs_nl2br($area_name . " - " . $room_name) ?></td>
  223. </tr>
  224. <tr>
  225. <td><?php echo get_vocab("start_date") ?>:</td>
  226. <td><?php echo $start_date ?></td>
  227. </tr>
  228. <tr>
  229. <td><?php echo get_vocab("duration") ?>:</td>
  230. <td><?php echo $duration . " " . $dur_units ?></td>
  231. </tr>
  232. <tr>
  233. <td><?php echo get_vocab("end_date") ?>:</td>
  234. <td><?php echo $end_date ?></td>
  235. </tr>
  236. <tr>
  237. <td><?php echo get_vocab("type") ?>:</td>
  238. <td><?php echo empty($typel[$type]) ? "?$type?" : $typel[$type] ?></td>
  239. </tr>
  240. <tr>
  241. <td><?php echo get_vocab("createdby") ?>:</td>
  242. <?php
  243. echo "<td" . (($keep_private) ? " class=\"private\"" : "") . ">" . $create_by . "</td>\n";
  244. ?>
  245. </tr>
  246. <tr>
  247. <td><?php echo get_vocab("lastupdate") ?>:</td>
  248. <td><?php echo $updated ?></td>
  249. </tr>
  250. <tr>
  251. <td><?php echo get_vocab("rep_type") ?>:</td>
  252. <td><?php echo get_vocab($repeat_key) ?></td>
  253. </tr>
  254. <?php
  255. if($rep_type != 0)
  256. {
  257. $opt = "";
  258. if (($rep_type == 2) || ($rep_type == 6))
  259. {
  260. // Display day names according to language and preferred weekday start.
  261. for ($i = 0; $i < 7; $i++)
  262. {
  263. $daynum = ($i + $weekstarts) % 7;
  264. if ($rep_opt[$daynum])
  265. {
  266. $opt .= day_name($daynum) . " ";
  267. }
  268. }
  269. }
  270. if ($rep_type == 6)
  271. {
  272. echo "<tr><td>".get_vocab("rep_num_weeks")." ".get_vocab("rep_for_nweekly").":</td><td>$rep_num_weeks</td></tr>\n";
  273. }
  274. if ($opt)
  275. {
  276. echo "<tr><td>".get_vocab("rep_rep_day").":</td><td>$opt</td></tr>\n";
  277. }
  278. echo "<tr><td>".get_vocab("rep_end_date").":</td><td>$rep_end_date</td></tr>\n";
  279. }
  280. ?>
  281. </table>
  282. <?php
  283. // Need to tell all the links where to go back to after an edit or delete
  284. if (isset($HTTP_REFERER))
  285. {
  286. $returl = $HTTP_REFERER;
  287. }
  288. // If we haven't got a referer (eg we've come here from an email) then construct
  289. // a sensible place to go to afterwards
  290. else
  291. {
  292. switch ($default_view)
  293. {
  294. case "month":
  295. $returl = "month.php";
  296. break;
  297. case "week":
  298. $returl = "week.php";
  299. break;
  300. default:
  301. $returl = "day.php";
  302. }
  303. $returl .= "?year=$year&month=$month&day=$day&area=$area";
  304. }
  305. $returl = urlencode($returl);
  306. ?>
  307. <div id="view_entry_nav">
  308. <div>
  309. <?php
  310. if (! $series)
  311. {
  312. echo "<a href=\"edit_entry.php?id=$id&amp;returl=$returl\">". get_vocab("editentry") ."</a>";
  313. }
  314. if ($repeat_id)
  315. {
  316. echo " - ";
  317. }
  318. if ($repeat_id || $series )
  319. {
  320. echo "<a href=\"edit_entry.php?id=$id&amp;edit_type=series&amp;day=$day&amp;month=$month&amp;year=$year&amp;returl=$returl\">".get_vocab("editseries")."</a>";
  321. }
  322. ?>
  323. </div>
  324. <div>
  325. <?php
  326. // Copy and Copy series
  327. if ( ! $series )
  328. {
  329. echo "<a href=\"edit_entry.php?id=$id&amp;copy=1&amp;returl=$returl\">". get_vocab("copyentry") ."</a>";
  330. }
  331. if ($repeat_id)
  332. {
  333. echo " - ";
  334. }
  335. if ($repeat_id || $series )
  336. {
  337. echo "<a href=\"edit_entry.php?id=$id&amp;edit_type=series&amp;day=$day&amp;month=$month&amp;year=$year&amp;copy=1&amp;returl=$returl\">".get_vocab("copyseries")."</a>";
  338. }
  339. ?>
  340. </div>
  341. <div>
  342. <?php
  343. if ( ! $series )
  344. {
  345. echo "<a href=\"del_entry.php?id=$id&amp;series=0&amp;returl=$returl\" onclick=\"return confirm('".get_vocab("confirmdel")."');\">".get_vocab("deleteentry")."</a>";
  346. }
  347. if ($repeat_id)
  348. {
  349. echo " - ";
  350. }
  351. if ($repeat_id || $series )
  352. {
  353. echo "<a href=\"del_entry.php?id=$id&amp;series=1&amp;day=$day&amp;month=$month&amp;year=$year&amp;returl=$returl\" onClick=\"return confirm('".get_vocab("confirmdel")."');\">".get_vocab("deleteseries")."</a>";
  354. }
  355. ?>
  356. </div>
  357. <div>
  358. <?php
  359. if (isset($HTTP_REFERER)) //remove the link if displayed from an email
  360. {
  361. ?>
  362. <a href="<?php echo htmlspecialchars($HTTP_REFERER) ?>"><?php echo get_vocab("returnprev") ?></a>
  363. <?php
  364. }
  365. ?>
  366. </div>
  367. </div>
  368. <?php
  369. require_once "trailer.inc";
  370. ?>