forked from pdxlibrary/LibRooms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_usage.php
445 lines (367 loc) · 12.9 KB
/
report_usage.php
1
<?phpsession_start();require_once("config/config.inc.php");require_once("config/strings.inc.php");require_once("includes/Database.php");require_once("load.php");require_once("includes/verify_access.php");restrict_access($db,array("staff","admin"));$search = $_GET['search'];$user_id = $_GET['user_id'];$format = $_GET['format'];if(isset($_GET['start_date'])) $start_date = $_GET['start_date'];else $start_date = date('m/1/Y',strtotime('now'));if(isset($_GET['end_date'])) $end_date = $_GET['end_date'];else $end_date = date('m/d/Y');if(isset($_GET['selected_rooms'])) $selected_rooms = $_GET['selected_rooms'];else $selected_rooms = array();if(isset($_GET['selected_amenities'])) $selected_amenities = $_GET['selected_amenities'];else $selected_amenities = array();if(isset($_GET['selected_capacities'])) $selected_capacities = $_GET['selected_capacities'];else $selected_capacities = array();if(isset($_GET['selected_status_options'])) $selected_status_options = $_GET['selected_status_options'];else $selected_status_options = array();if(strcmp($format,'excel')){ require_once("includes/header.php"); ?><script type="text/javascript" language="javascript" src="js/jquery.ui.core.js"></script><script type="text/javascript" language="javascript" src="js/jquery.ui.datepicker.js"></script><script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script><script type="text/javascript" charset="utf-8"> jQuery(document).ready(function($) { // turn off caching for ajax calls, fixes IE caching issue jQuery.ajaxSetup({ cache: false }); $("#start_date").datepicker(); $("#end_date").datepicker(); <?php if(!isset($_GET['submitted'])) { print("select_all('room_number_field');\n"); print("select_all('room_amenity_field');\n"); print("select_all('room_capacity_field');\n"); print("select_all('reservation_status_field');\n"); } ?> var usage_report_table = $('#usage_report_table').dataTable({ "bJQueryUI": true, "sPaginationType": "full_numbers", "iDisplayLength": 50, "aaSorting": [[ 0, "desc" ]], "aoColumns": [ { }, { }, { "bSortable": false}, { "bSortable": false}, { "bSortable": false}, { "bSortable": false}, { "bSortable": false}, { "sWidth": "100px"} <?php if(in_array("Cancelled",$selected_status_options)) print(",{ \"bSortable\": false, \"sWidth\": \"150px\"}\n"); ?> ] }); <?php if(isset($_GET['submitted'])) { print("$(\"#usage_report_form\").toggle(false);\n"); print("$(\"#show_usage_report_form\").toggle(true);\n"); } ?> }); function show_usage_report_form() { $("#usage_report_form").toggle(true); $("#show_usage_report_form").toggle(false); } function select_all(class_name) { $("."+class_name).attr('checked', true); } function select_none(class_name) { $("."+class_name).attr('checked', false); } </script><link rel="stylesheet" href="css/jquery-ui.css" type="text/css" media="all" /><link rel="stylesheet" href="css/results_table.css" type="text/css" media="all" /><?php print("<div id='PageTitle'>Usage Report</div>\n"); print("<div class='breadcrumb'><a href='http://library.pdx.edu'>Home</a> » <a href='index.php'>Reserve a Study Room</a> » <a href='reports.php'>Reports</a> » Usage Reports</div>\n"); print("<br>\n"); print("<div id='show_usage_report_form' style='display:none'><input type='button' onClick='show_usage_report_form()' value='Show Usage Report Selection Form'><br><br></div>\n"); print("<div id='usage_report_form'>\n"); print("<form>\n"); print("<h2>Date Range</h2>\n"); print("<blockquote>\n"); print("<input id='start_date' name='start_date' size='8' value='$start_date'> through <input id='end_date' name='end_date' size='8' value='$end_date'>\n"); print("</blockquote>\n"); print("<hr>\n"); print("<h2>Rooms</h2>\n"); print("<blockquote>\n"); // table of room numbers $per_row = 12; $in_row = 0; $width = floor(100/$per_row); print("<b>Room Numbers</b><br>\n"); print("<table>\n"); $all_rooms = load_rooms(null,array('active'=>"1",'sort asc'=>'room_number')); foreach($all_rooms as $room_id => $room) { if($in_row == 0) { print("<tr valign='top'>"); } if(in_array($room->id,$selected_rooms)) $checked = "checked"; else $checked = ""; print("<td width='$width%'><input class='room_number_field' type='checkbox' name='selected_rooms[]' value='$room->id' $checked>$room->room_number</td>"); $in_row++; if($in_row >= $per_row) { print("</tr>\n"); $in_row = 0; } } if($in_row > 0) { while($in_row < $per_row) { print("<td> </td>\n"); $in_row++; } } print("</table><input type='button' onClick='javascript:select_all(\"room_number_field\");' value='Select All'> <input type='button' onClick='javascript:select_none(\"room_number_field\");' value='Select None'> \n"); /* print("<hr>\n"); // table of room amenities $per_row = 3; $in_row = 0; $width = floor(100/$per_row); print("<b>Room Amenities</b><br>\n"); print("<table width='100%'>\n"); $all_amenities = load_amenities(); //$all_rooms = load_rooms(null,array('active'=>"1",'sort asc'=>'room_number')); foreach($all_amenities as $amenity_id => $amenity) { if($in_row == 0) { print("<tr valign='top'>"); } if(in_array($amenity->id,$selected_amenities)) $checked = "checked"; else $checked = ""; print("<td width='$width%'><input class='room_amenity_field' type='checkbox' name='selected_amenities[]' value='$amenity->id' $checked>$amenity->name"); //if(strcmp($amenity->description,'')) // print(" - $amenity->description"); print("</td>"); $in_row++; if($in_row >= $per_row) { print("</tr>\n"); $in_row = 0; } } if($in_row > 0) { while($in_row < $per_row) { print("<td> </td>\n"); $in_row++; } } print("</table><input type='button' onClick='javascript:select_all(\"room_amenity_field\");' value='Select All'> <input type='button' onClick='javascript:select_none(\"room_amenity_field\");' value='Select None'> \n"); */ print("<hr>\n"); // table of room capacities $per_row = 5; $in_row = 0; $width = floor(100/$per_row); print("<b>Room Capacities</b><br>\n"); print("<table width='100%'>\n"); //$all_rooms = load_rooms(null,array('active'=>"1",'sort asc'=>'room_number')); foreach($capacity_options as $capacity => $label) { if($in_row == 0) { print("<tr valign='top'>"); } if(in_array($capacity,$selected_capacities)) $checked = "checked"; else $checked = ""; print("<td width='$width%'><input class='room_capacity_field' type='checkbox' name='selected_capacities[]' value='$capacity' $checked>$label</td>"); $in_row++; if($in_row >= $per_row) { print("</tr>\n"); $in_row = 0; } } if($in_row > 0) { while($in_row < $per_row) { print("<td> </td>\n"); $in_row++; } } print("</table><input type='button' onClick='javascript:select_all(\"room_capacity_field\");' value='Select All'> <input type='button' onClick='javascript:select_none(\"room_capacity_field\");' value='Select None'> \n"); print("</blockquote>\n"); print("<hr>\n"); print("<h2>Status</h2>\n"); print("<blockquote>\n"); // table of reservation statues $per_row = 5; $in_row = 0; $width = floor(100/$per_row); print("<b>Reservation Status Options</b><br>\n"); print("<table width='100%'>\n"); //$all_rooms = load_rooms(null,array('active'=>"1",'sort asc'=>'room_number')); foreach($status_options as $status) { if($in_row == 0) { print("<tr valign='top'>"); } if(in_array($status,$selected_status_options)) $checked = "checked"; else $checked = ""; print("<td width='$width%'><input class='reservation_status_field' type='checkbox' name='selected_status_options[]' value='$status' $checked>$status</td>"); $in_row++; if($in_row >= $per_row) { print("</tr>\n"); $in_row = 0; } } if($in_row > 0) { while($in_row < $per_row) { print("<td> </td>\n"); $in_row++; } } print("</table><input type='button' onClick='javascript:select_all(\"reservation_status_field\");' value='Select All'> <input type='button' onClick='javascript:select_none(\"reservation_status_field\");' value='Select None'> \n"); print("</blockquote>\n"); print("<hr>\n"); print("<input type='submit' name='submitted' value='Create Report'> <input type='button' onClick='document.location.href=\"?\";' value='Reset Form'>\n"); print("<hr>\n"); print("</form>\n"); print("</div>\n"); if(isset($_GET['submitted'])) { print("<div style='float:right; margin-right:10px'><a href='?".$_SERVER['QUERY_STRING']."&format=excel'>Export to Excel</a></div>\n"); print("<table id='usage_report_table' width='100%' border><thead><tr><th>Date</th><th>Room</th><th>Sched Start</th><th>Sched End</th><th>Checkout Time</th><th>Check-in Time</th><th>Patron ID</th><th>Status</th>"); if(in_array("Cancelled",$selected_status_options)) print("<th>Cancellation Reason</th>"); print("</tr></thead>\n"); print("<tbody>\n"); $options = array(); $options['active'] = 1; if(strcmp($start_date,'')) $options['sched_start_time'] = date('Y-m-d',strtotime($start_date)); if(strcmp($end_date,'')) $options['sched_end_time'] = date('Y-m-d',strtotime("+1 day",strtotime($end_date))); $options['status'] = $selected_status_options; // pr($options); $reservations = load_reservations($options); // amenities to ignore //$amenities_diff = array_diff($selected_resolution_options,$room_amenity_options); foreach($reservations as $reservation) { if(!in_array($reservation->room->id,$selected_rooms)) continue; if(!in_array($reservation->room->capacity,$selected_capacities)) continue; print("<tr><td align='center'>".date('m/d/Y',strtotime($reservation->date))."</td>"); print("<td align='center'>".$reservation->room->room_number."</td>"); print("<td align='center'>".date('g:ia',strtotime($reservation->sched_start_time))."</td>"); print("<td align='center'>".date('g:ia',strtotime($reservation->sched_end_time))."</td>"); if(strcmp($reservation->key_checkout_time,'')) print("<td align='center'>".date('g:ia',strtotime($reservation->key_checkout_time))."</td>"); else print("<td></td>"); if(strcmp($reservation->key_checkin_time,'')) print("<td align='center'>".date('g:ia',strtotime($reservation->key_checkin_time))."</td>"); else print("<td></td>"); $user = get_user_by_id($reservation->user_id); print("<td align='center'><a href='search.php?search=$user->patron_id'>$user->patron_id</a></td>"); print("<td align='center'>$reservation->status</td>"); if(in_array("Cancelled",$selected_status_options)) print("<td>$reservation->cancellation_reason</td>"); print("</tr>\n"); } print("</tbody>\n"); print("</table>\n"); } require_once("includes/footer.php");}else{ header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=study_rooms_usage_report.xls"); print("<table id='usage_report_table' width='100%' border><thead><tr><th>Date</th><th>Room</th><th>Sched Start</th><th>Sched End</th><th>Checkout Time</th><th>Check-in Time</th><th>Patron ID</th><th>Status</th>"); if(in_array("Cancelled",$selected_status_options)) print("<th>Cancellation Reason</th>"); print("</tr></thead>\n"); print("<tbody>\n"); $options = array(); $options['active'] = 1; if(strcmp($start_date,'')) $options['sched_start_time'] = date('Y-m-d',strtotime($start_date)); if(strcmp($end_date,'')) $options['sched_end_time'] = date('Y-m-d',strtotime("+1 day",strtotime($end_date))); $options['status'] = $selected_status_options; $reservations = load_reservations($options); // amenities to ignore //$amenities_diff = array_diff($selected_resolution_options,$room_amenity_options); foreach($reservations as $reservation) { if(!in_array($reservation->room->id,$selected_rooms)) continue; if(!in_array($reservation->room->capacity,$selected_capacities)) continue; print("<tr><td align='center'>".date('m/d/Y',strtotime($reservation->date))."</td>"); print("<td align='center'>".$reservation->room->room_number."</td>"); print("<td align='center'>".date('g:ia',strtotime($reservation->sched_start_time))."</td>"); print("<td align='center'>".date('g:ia',strtotime($reservation->sched_end_time))."</td>"); if(strcmp($reservation->key_checkout_time,'')) print("<td align='center'>".date('g:ia',strtotime($reservation->key_checkout_time))."</td>"); else print("<td></td>"); if(strcmp($reservation->key_checkin_time,'')) print("<td align='center'>".date('g:ia',strtotime($reservation->key_checkin_time))."</td>"); else print("<td></td>"); $user = get_user_by_id($reservation->user_id); print("<td align='center'>".$user->patron_id."</td>"); print("<td align='center'>$reservation->status</td>"); if(in_array("Cancelled",$selected_status_options)) print("<td>$reservation->cancellation_reason</td>"); print("</tr>\n"); } print("</tbody>\n"); print("</table>\n");}?>