Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.52 KB | None | 0 0
  1. <?php
  2. function responsive_cell_html($cell, $query_strings, $s, $is_invalid = FALSE)
  3. {
  4. // draws a single cell in the main table of the day and week views
  5. //
  6. // $cell is a two dimensional array that is part of the map of the whole
  7. // display and looks like this:
  8. //
  9. // $cell[n][id]
  10. // [is_repeat]
  11. // [is_multiday_start]
  12. // [is_multiday_end]
  13. // [color]
  14. // [data]
  15. // [long_descr]
  16. // [create_by]
  17. // [room_id]
  18. // [start_time]
  19. // [slots]
  20. // [status]
  21. //
  22. // where n is the number of the booking in the cell. There can be none, one or many
  23. // bookings in a cell. If there are no bookings then a blank cell is drawn with a link
  24. // to the edit entry form. If there is one booking, then the booking is shown in that
  25. // cell. If there is more than one booking then all the bookings are shown, but they can
  26. // be shown in two different ways: minimised and maximised. By default they are shown
  27. // minimised, so that the standard row height is preserved. By clicking a control
  28. // the cell can be maximised. (Multiple bookings can arise in a cell if the resolution
  29. // of an existing database in increased or the booking day is shifted).
  30.  
  31. // $query_strings is an array containg the query strings (or partial query strings) to be
  32. // appended to the link used for the cell. It is indexed as follows:
  33. // ['new_periods'] the string to be used for an empty cell if using periods
  34. // ['new_times'] the string to be used for an empty cell if using times
  35. // ['booking'] the string to be used for a full cell
  36. //
  37. // $is_invalid specifies whether the slot actually exists or is one of the non-existent
  38. // slots in the transition to DST
  39.  
  40. global $main_cell_height, $main_table_cell_border_width;
  41. global $area, $year, $month, $timetohighlight;
  42. global $enable_periods, $times_along_top, $show_plus_link;
  43. global $approval_enabled, $confirmation_enabled;
  44.  
  45. $html = '';
  46. $user = getUserName();
  47.  
  48. // if the time slot has got multiple bookings, then draw a mini-table
  49. if(isset($cell[1]["id"]))
  50. {
  51. // Find out how many bookings there are (needed to calculate heights)
  52. $n_bookings = 0;
  53. while (isset($cell[$n_bookings]["id"]))
  54. {
  55. $n_bookings++;
  56. }
  57.  
  58. // Make the class maximized by default so that if you don't have JavaScript then
  59. // you can still see all the bookings. If you have JavaScript it will overwrite
  60. // the class and make it minimized.
  61. $html .= "<td class=\"multiple_booking maximized\">\n";
  62.  
  63. // First draw the mini table
  64. $html .= "<div class=\"celldiv slots1 mini\">\n";
  65. $html .= "<div class=\"multiple_control\">+</div>\n";
  66. $html .= "<table>\n";
  67. $html .= "<tbody>\n";
  68.  
  69. $row_height = $main_cell_height - (($n_bookings-1) * $main_table_cell_border_width); // subtract the borders (first row has no top border)
  70. $row_height = $row_height/$n_bookings; // split what's left between the bookings
  71. $row_height = (int) ceil($row_height); // round up, so that (a) there's no empty space at the bottom
  72. // and (b) each stripe is at least 1 unit high
  73. for ($n=0; $n<$n_bookings; $n++)
  74. {
  75. $id = $cell[$n]["id"];
  76. $is_repeat = $cell[$n]["is_repeat"];
  77. $is_multiday_start = $cell[$n]["is_multiday_start"];
  78. $is_multiday_end = $cell[$n]["is_multiday_end"];
  79. $status = $cell[$n]["status"];
  80. $color = $cell[$n]["color"];
  81. $descr = htmlspecialchars($cell[$n]["data"]);
  82. $long_descr = htmlspecialchars($cell[$n]["long_descr"]);
  83. $class = $color;
  84. if ($status & STATUS_PRIVATE)
  85. {
  86. $class .= " private";
  87. }
  88. if ($approval_enabled && ($status & STATUS_AWAITING_APPROVAL))
  89. {
  90. $class .= " awaiting_approval";
  91. }
  92. if ($confirmation_enabled && ($status & STATUS_TENTATIVE))
  93. {
  94. $class .= " tentative";
  95. }
  96. if ($is_multiday_start)
  97. {
  98. $class .= " multiday_start";
  99. }
  100. if ($is_multiday_end)
  101. {
  102. $class .= " multiday_end";
  103. }
  104.  
  105. $html .= "<tr>\n";
  106. $html .= "<td class=\"$class\"" .
  107. (($n==0) ? " style=\"border-top-width: 0\"" : "") . // no border for first row
  108. ">\n";
  109. $html .= "<div style=\"overflow: hidden; " .
  110. "height: " . $row_height . "px; " .
  111. "max-height: " . $row_height . "px; " .
  112. "min-height: " . $row_height . "px\">\n";
  113. $html .= "&nbsp;\n";
  114. $html .= "</div>\n";
  115. $html .= "</td>\n";
  116. $html .= "</tr>\n";
  117. }
  118. $html .= "</tbody>\n";
  119. $html .= "</table>\n";
  120. $html .= "</div>\n";
  121.  
  122. // Now draw the maxi table
  123. $html .= "<div class=\"maxi\">\n";
  124. $total_height = $n_bookings * $main_cell_height;
  125. $total_height += ($n_bookings - 1) * $main_table_cell_border_width; // (first row has no top border)
  126. $html .= "<div class=\"multiple_control\" " .
  127. "style =\"height: " . $total_height . "px; " .
  128. "min-height: " . $total_height . "px; " .
  129. "max-height: " . $total_height . "px; " .
  130. "\">-</div>\n";
  131. $html .= "<table>\n";
  132. $html .= "<tbody>\n";
  133. for ($n=0; $n<$n_bookings; $n++)
  134. {
  135. $id = $cell[$n]["id"];
  136. $is_repeat = $cell[$n]["is_repeat"];
  137. $is_multiday_start = $cell[$n]["is_multiday_start"];
  138. $is_multiday_end = $cell[$n]["is_multiday_end"];
  139. $status = $cell[$n]["status"];
  140. $color = $cell[$n]["color"];
  141. $descr = htmlspecialchars($cell[$n]["start_time"] . " " . $cell[$n]["data"]);
  142. $long_descr = htmlspecialchars($cell[$n]["long_descr"]);
  143. $class = $color;
  144. if ($status & STATUS_PRIVATE)
  145. {
  146. $class .= " private";
  147. }
  148. if ($approval_enabled && ($status & STATUS_AWAITING_APPROVAL))
  149. {
  150. $class .= " awaiting_approval";
  151. }
  152. if ($confirmation_enabled && ($status & STATUS_TENTATIVE))
  153. {
  154. $class .= " tentative";
  155. }
  156. if ($is_multiday_start)
  157. {
  158. $class .= " multiday_start";
  159. }
  160. if ($is_multiday_end)
  161. {
  162. $class .= " multiday_end";
  163. }
  164. $html .= "<tr>\n";
  165. $html .= "<td class=\"$class\"" .
  166. (($n==0) ? " style=\"border-top-width: 0\"" : "") . // no border for first row
  167. ">\n";
  168. $html .= "<div class=\"celldiv slots1\">\n"; // we want clipping of overflow
  169. $html .= "<a href=\"r_view_entry.php?id=$id&". $query_strings['booking'] . "\" title=\"$long_descr\">";
  170. $html .= ($is_repeat) ? "<img class=\"repeat_symbol\" src=\"images/repeat.png\" alt=\"" . get_vocab("series") . "\" title=\"" . get_vocab("series") . "\" width=\"10\" height=\"10\">" : '';
  171. $html .= "$descr</a>\n";
  172. $html .= "</div>\n";
  173.  
  174. $html .= "</td>\n";
  175. $html .= "</tr>\n";
  176. }
  177. $html .= "</tbody>\n";
  178. $html .= "</table>\n";
  179. $html .= "</div>\n";
  180.  
  181. $html .= "</td>\n";
  182. } // end of if isset ( ...[1]..)
  183.  
  184. // otherwise draw a cell, showing either the booking or a blank cell
  185. else
  186. {
  187. if(isset($cell[0]["id"]))
  188. {
  189. $id = $cell[0]["id"];
  190. $is_repeat = $cell[0]["is_repeat"];
  191. $is_multiday_start = $cell[0]["is_multiday_start"];
  192. $is_multiday_end = $cell[0]["is_multiday_end"];
  193. $status = $cell[0]["status"];
  194. $color = $cell[0]["color"];
  195. $descr = htmlspecialchars($cell[0]["data"]);
  196. $long_descr = htmlspecialchars($cell[0]["long_descr"]);
  197. $slots = $cell[0]["slots"];
  198. }
  199. else // id not set
  200. {
  201. unset($id);
  202. $slots = 1;
  203. }
  204.  
  205. // $c is the colour of the cell that the browser sees. Zebra stripes normally,
  206. // row_highlight if we're highlighting that line and the appropriate colour if
  207. // it is booked (determined by the type).
  208. // We tell if its booked by $id having something in it
  209. if (isset($id))
  210. {
  211. $c = $color;
  212. if ($status & STATUS_PRIVATE)
  213. {
  214. $c .= " private";
  215. }
  216. if ($approval_enabled && ($status & STATUS_AWAITING_APPROVAL))
  217. {
  218. $c .= " awaiting_approval";
  219. }
  220. if ($confirmation_enabled && ($status & STATUS_TENTATIVE))
  221. {
  222. $c .= " tentative";
  223. }
  224. if ($is_multiday_start)
  225. {
  226. $c .= " multiday_start";
  227. }
  228. if ($is_multiday_end)
  229. {
  230. $c .= " multiday_end";
  231. }
  232. // Add a class to bookings that this user is allowed to edit so that the
  233. // JavaScript can turn them into resizable bookings
  234. if (getWritable($cell[0]['create_by'], $user, $cell[0]['room_id']))
  235. {
  236. $c .= " writable";
  237. if ($is_repeat)
  238. {
  239. $c .= " series";
  240. }
  241. }
  242. }
  243. else
  244. {
  245. $c = ($is_invalid) ? "invalid" : "new";
  246. }
  247.  
  248. // Don't put in a <td> cell if the slot is booked and there's no description.
  249. // This would mean that it's the second or subsequent slot of a booking and so the
  250. // <td> for the first slot would have had a rowspan that extended the cell down for
  251. // the number of slots of the booking.
  252.  
  253. if (!(isset($id) && ($descr == "")))
  254. {
  255. $html .= tdcell($c, $slots);
  256.  
  257. // If the room isn't booked then allow it to be booked
  258. if (!isset($id))
  259. {
  260. // Don't provide a link if the slot doesn't really exist
  261. if (!$is_invalid)
  262. {
  263. $html .= "<div class=\"celldiv slots1\">\n"; // a bookable slot is only one unit high
  264. $html .= "<a href=\"r_edit_entry.php?" .
  265. (($enable_periods) ? $query_strings['new_periods'] : $query_strings['new_times']) .
  266. "\">\n";
  267. if ($show_plus_link)
  268. {
  269. $html .= "<img src=\"images/new.gif\" alt=\"New\" width=\"10\" height=\"10\">\n";
  270. }
  271. $html .= gmdate("g:i A", $s);
  272. $html .= " </a>\n";
  273. $html .= "</div>\n";
  274. }
  275. }
  276. else // if it is booked then show the booking
  277. {
  278. $html .= "<div data-id=\"$id\" class=\"celldiv slots" .
  279. (($times_along_top) ? "1" : $slots) .
  280. "\">\n";
  281. $html .= "<a href=\"r_view_entry.php?id=$id&". $query_strings['booking'] . "\" title=\"$long_descr\">";
  282. $html .= ($is_repeat) ? "<img class=\"repeat_symbol $c\" src=\"images/repeat.png\" alt=\"" . get_vocab("series") . "\" title=\"" . get_vocab("series") . "\" width=\"10\" height=\"10\">" : '';
  283. $html .= "$descr</a>\n";
  284. $html .= "</div>\n";
  285. }
  286. $html .= "</td>\n";
  287. }
  288. }
  289.  
  290. return $html;
  291. } // end function responsive_cell_html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement