Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function responsive_cell_html($cell, $query_strings, $s, $is_invalid = FALSE)
- {
- // draws a single cell in the main table of the day and week views
- //
- // $cell is a two dimensional array that is part of the map of the whole
- // display and looks like this:
- //
- // $cell[n][id]
- // [is_repeat]
- // [is_multiday_start]
- // [is_multiday_end]
- // [color]
- // [data]
- // [long_descr]
- // [create_by]
- // [room_id]
- // [start_time]
- // [slots]
- // [status]
- //
- // where n is the number of the booking in the cell. There can be none, one or many
- // bookings in a cell. If there are no bookings then a blank cell is drawn with a link
- // to the edit entry form. If there is one booking, then the booking is shown in that
- // cell. If there is more than one booking then all the bookings are shown, but they can
- // be shown in two different ways: minimised and maximised. By default they are shown
- // minimised, so that the standard row height is preserved. By clicking a control
- // the cell can be maximised. (Multiple bookings can arise in a cell if the resolution
- // of an existing database in increased or the booking day is shifted).
- // $query_strings is an array containg the query strings (or partial query strings) to be
- // appended to the link used for the cell. It is indexed as follows:
- // ['new_periods'] the string to be used for an empty cell if using periods
- // ['new_times'] the string to be used for an empty cell if using times
- // ['booking'] the string to be used for a full cell
- //
- // $is_invalid specifies whether the slot actually exists or is one of the non-existent
- // slots in the transition to DST
- global $main_cell_height, $main_table_cell_border_width;
- global $area, $year, $month, $timetohighlight;
- global $enable_periods, $times_along_top, $show_plus_link;
- global $approval_enabled, $confirmation_enabled;
- $html = '';
- $user = getUserName();
- // if the time slot has got multiple bookings, then draw a mini-table
- if(isset($cell[1]["id"]))
- {
- // Find out how many bookings there are (needed to calculate heights)
- $n_bookings = 0;
- while (isset($cell[$n_bookings]["id"]))
- {
- $n_bookings++;
- }
- // Make the class maximized by default so that if you don't have JavaScript then
- // you can still see all the bookings. If you have JavaScript it will overwrite
- // the class and make it minimized.
- $html .= "<td class=\"multiple_booking maximized\">\n";
- // First draw the mini table
- $html .= "<div class=\"celldiv slots1 mini\">\n";
- $html .= "<div class=\"multiple_control\">+</div>\n";
- $html .= "<table>\n";
- $html .= "<tbody>\n";
- $row_height = $main_cell_height - (($n_bookings-1) * $main_table_cell_border_width); // subtract the borders (first row has no top border)
- $row_height = $row_height/$n_bookings; // split what's left between the bookings
- $row_height = (int) ceil($row_height); // round up, so that (a) there's no empty space at the bottom
- // and (b) each stripe is at least 1 unit high
- for ($n=0; $n<$n_bookings; $n++)
- {
- $id = $cell[$n]["id"];
- $is_repeat = $cell[$n]["is_repeat"];
- $is_multiday_start = $cell[$n]["is_multiday_start"];
- $is_multiday_end = $cell[$n]["is_multiday_end"];
- $status = $cell[$n]["status"];
- $color = $cell[$n]["color"];
- $descr = htmlspecialchars($cell[$n]["data"]);
- $long_descr = htmlspecialchars($cell[$n]["long_descr"]);
- $class = $color;
- if ($status & STATUS_PRIVATE)
- {
- $class .= " private";
- }
- if ($approval_enabled && ($status & STATUS_AWAITING_APPROVAL))
- {
- $class .= " awaiting_approval";
- }
- if ($confirmation_enabled && ($status & STATUS_TENTATIVE))
- {
- $class .= " tentative";
- }
- if ($is_multiday_start)
- {
- $class .= " multiday_start";
- }
- if ($is_multiday_end)
- {
- $class .= " multiday_end";
- }
- $html .= "<tr>\n";
- $html .= "<td class=\"$class\"" .
- (($n==0) ? " style=\"border-top-width: 0\"" : "") . // no border for first row
- ">\n";
- $html .= "<div style=\"overflow: hidden; " .
- "height: " . $row_height . "px; " .
- "max-height: " . $row_height . "px; " .
- "min-height: " . $row_height . "px\">\n";
- $html .= " \n";
- $html .= "</div>\n";
- $html .= "</td>\n";
- $html .= "</tr>\n";
- }
- $html .= "</tbody>\n";
- $html .= "</table>\n";
- $html .= "</div>\n";
- // Now draw the maxi table
- $html .= "<div class=\"maxi\">\n";
- $total_height = $n_bookings * $main_cell_height;
- $total_height += ($n_bookings - 1) * $main_table_cell_border_width; // (first row has no top border)
- $html .= "<div class=\"multiple_control\" " .
- "style =\"height: " . $total_height . "px; " .
- "min-height: " . $total_height . "px; " .
- "max-height: " . $total_height . "px; " .
- "\">-</div>\n";
- $html .= "<table>\n";
- $html .= "<tbody>\n";
- for ($n=0; $n<$n_bookings; $n++)
- {
- $id = $cell[$n]["id"];
- $is_repeat = $cell[$n]["is_repeat"];
- $is_multiday_start = $cell[$n]["is_multiday_start"];
- $is_multiday_end = $cell[$n]["is_multiday_end"];
- $status = $cell[$n]["status"];
- $color = $cell[$n]["color"];
- $descr = htmlspecialchars($cell[$n]["start_time"] . " " . $cell[$n]["data"]);
- $long_descr = htmlspecialchars($cell[$n]["long_descr"]);
- $class = $color;
- if ($status & STATUS_PRIVATE)
- {
- $class .= " private";
- }
- if ($approval_enabled && ($status & STATUS_AWAITING_APPROVAL))
- {
- $class .= " awaiting_approval";
- }
- if ($confirmation_enabled && ($status & STATUS_TENTATIVE))
- {
- $class .= " tentative";
- }
- if ($is_multiday_start)
- {
- $class .= " multiday_start";
- }
- if ($is_multiday_end)
- {
- $class .= " multiday_end";
- }
- $html .= "<tr>\n";
- $html .= "<td class=\"$class\"" .
- (($n==0) ? " style=\"border-top-width: 0\"" : "") . // no border for first row
- ">\n";
- $html .= "<div class=\"celldiv slots1\">\n"; // we want clipping of overflow
- $html .= "<a href=\"r_view_entry.php?id=$id&". $query_strings['booking'] . "\" title=\"$long_descr\">";
- $html .= ($is_repeat) ? "<img class=\"repeat_symbol\" src=\"images/repeat.png\" alt=\"" . get_vocab("series") . "\" title=\"" . get_vocab("series") . "\" width=\"10\" height=\"10\">" : '';
- $html .= "$descr</a>\n";
- $html .= "</div>\n";
- $html .= "</td>\n";
- $html .= "</tr>\n";
- }
- $html .= "</tbody>\n";
- $html .= "</table>\n";
- $html .= "</div>\n";
- $html .= "</td>\n";
- } // end of if isset ( ...[1]..)
- // otherwise draw a cell, showing either the booking or a blank cell
- else
- {
- if(isset($cell[0]["id"]))
- {
- $id = $cell[0]["id"];
- $is_repeat = $cell[0]["is_repeat"];
- $is_multiday_start = $cell[0]["is_multiday_start"];
- $is_multiday_end = $cell[0]["is_multiday_end"];
- $status = $cell[0]["status"];
- $color = $cell[0]["color"];
- $descr = htmlspecialchars($cell[0]["data"]);
- $long_descr = htmlspecialchars($cell[0]["long_descr"]);
- $slots = $cell[0]["slots"];
- }
- else // id not set
- {
- unset($id);
- $slots = 1;
- }
- // $c is the colour of the cell that the browser sees. Zebra stripes normally,
- // row_highlight if we're highlighting that line and the appropriate colour if
- // it is booked (determined by the type).
- // We tell if its booked by $id having something in it
- if (isset($id))
- {
- $c = $color;
- if ($status & STATUS_PRIVATE)
- {
- $c .= " private";
- }
- if ($approval_enabled && ($status & STATUS_AWAITING_APPROVAL))
- {
- $c .= " awaiting_approval";
- }
- if ($confirmation_enabled && ($status & STATUS_TENTATIVE))
- {
- $c .= " tentative";
- }
- if ($is_multiday_start)
- {
- $c .= " multiday_start";
- }
- if ($is_multiday_end)
- {
- $c .= " multiday_end";
- }
- // Add a class to bookings that this user is allowed to edit so that the
- // JavaScript can turn them into resizable bookings
- if (getWritable($cell[0]['create_by'], $user, $cell[0]['room_id']))
- {
- $c .= " writable";
- if ($is_repeat)
- {
- $c .= " series";
- }
- }
- }
- else
- {
- $c = ($is_invalid) ? "invalid" : "new";
- }
- // Don't put in a <td> cell if the slot is booked and there's no description.
- // This would mean that it's the second or subsequent slot of a booking and so the
- // <td> for the first slot would have had a rowspan that extended the cell down for
- // the number of slots of the booking.
- if (!(isset($id) && ($descr == "")))
- {
- $html .= tdcell($c, $slots);
- // If the room isn't booked then allow it to be booked
- if (!isset($id))
- {
- // Don't provide a link if the slot doesn't really exist
- if (!$is_invalid)
- {
- $html .= "<div class=\"celldiv slots1\">\n"; // a bookable slot is only one unit high
- $html .= "<a href=\"r_edit_entry.php?" .
- (($enable_periods) ? $query_strings['new_periods'] : $query_strings['new_times']) .
- "\">\n";
- if ($show_plus_link)
- {
- $html .= "<img src=\"images/new.gif\" alt=\"New\" width=\"10\" height=\"10\">\n";
- }
- $html .= gmdate("g:i A", $s);
- $html .= " </a>\n";
- $html .= "</div>\n";
- }
- }
- else // if it is booked then show the booking
- {
- $html .= "<div data-id=\"$id\" class=\"celldiv slots" .
- (($times_along_top) ? "1" : $slots) .
- "\">\n";
- $html .= "<a href=\"r_view_entry.php?id=$id&". $query_strings['booking'] . "\" title=\"$long_descr\">";
- $html .= ($is_repeat) ? "<img class=\"repeat_symbol $c\" src=\"images/repeat.png\" alt=\"" . get_vocab("series") . "\" title=\"" . get_vocab("series") . "\" width=\"10\" height=\"10\">" : '';
- $html .= "$descr</a>\n";
- $html .= "</div>\n";
- }
- $html .= "</td>\n";
- }
- }
- return $html;
- } // end function responsive_cell_html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement