public function search($request)
 {
     define('ONE_DAY', 60 * 60 * 24);
     //defining what one day is
     $week = date('w');
     //define the current week
     switch ($request->action) {
         case "nextweek":
             $start_date = date('Y-m-d', time() - ($week - 7) * ONE_DAY);
             $end_date = date('Y-m-d', time() - ($week - 13) * ONE_DAY);
             $fixed_start_date = self::fix_date($start_date);
             $fixed_end_date = self::fix_date($end_date);
             $title = "Reservations from {$fixed_start_date} to {$fixed_end_date}";
             //add the dates to the date array, four dates are needed for testing the date ranges
             //and for proper use with adodb binding
             $dates = array('start_date' => $start_date, 'end_date' => $end_date, 'start_date2' => $start_date, 'end_date2' => $end_date);
             $reservation = self::by_date_range($dates);
             break;
         case "thisweek":
             //this shows the information for this week
             $start_date = date('Y-m-d', time() - $week * ONE_DAY);
             $end_date = date('Y-m-d', time() - ($week - 6) * ONE_DAY);
             //add the dates to the date array, four dates are needed for testing the date ranges
             //and for proper use with adodb binding
             $dates = array('start_date' => $start_date, 'end_date' => $end_date, 'start_date2' => $start_date, 'end_date2' => $end_date);
             $fixed_start_date = self::fix_date($start_date);
             $fixed_end_date = self::fix_date($end_date);
             $title = "Reservations from {$fixed_start_date} to {$fixed_end_date}";
             $reservation = self::by_date_range($dates);
             break;
         case "daterange":
             $start_date = $request->param('from_date');
             $start_date = date('Y-m-d', strtotime($start_date));
             $end_date = $request->param('to_date');
             $end_date = date('Y-m-d', strtotime($end_date));
             $fixed_start_date = ReserveDatabaseAPI::fix_date($start_date);
             $fixed_end_date = ReserveDatabaseAPI::fix_date($end_date);
             //add the dates to the date array, four dates are needed for testing the date ranges
             //and for proper use with adodb binding
             $dates = array('start_date' => $start_date, 'end_date' => $end_date, 'start_date2' => $start_date, 'end_date2' => $end_date);
             $title = "Reservations from {$fixed_start_date} to {$fixed_end_date}";
             $reservation = self::by_date_range($dates);
             break;
         case "lastweek":
             //this shows the information from last week
             $start_date = date('Y-m-d', time() - ($week + 7) * ONE_DAY);
             $end_date = date('Y-m-d', time() - ($week + 1) * ONE_DAY);
             $fixed_start_date = self::fix_date($start_date);
             $fixed_end_date = self::fix_date($end_date);
             //add the dates to the date array, four dates are needed for testing the date ranges
             //and for proper use with adodb binding
             $dates = array('start_date' => $start_date, 'end_date' => $end_date, 'start_date2' => $start_date, 'end_date2' => $end_date);
             $title = "Reservations from {$fixed_start_date} to {$fixed_end_date}";
             $reservation = self::by_date_range($dates);
             break;
         case "today":
             //this shows the information from today, which is default
             $start_date = date('Y-m-d');
             $fixed_start_date = self::fix_date($start_date);
             $title = "Reservations for today -  {$fixed_start_date}";
             $reservation = self::by_date($start_date);
             break;
         case "yesterday":
             //this shows the information from yesterday
             $start_date = date('Y-m-d', strtotime("-1 day"));
             $fixed_start_date = self::fix_date($start_date);
             $title = "Reservations for yesterday - {$fixed_start_date}";
             $reservation = self::by_date($start_date);
             break;
         case "tommorrow":
             //this shows the information from tomorrow
             $start_date = date('Y-m-d', strtotime("+1 day"));
             $fixed_start_date = self::fix_date($start_date);
             $title = "Reservations for tomorrow - {$fixed_start_date}";
             $reservation = self::by_date($start_date);
             break;
         case "pending":
             //this shows any loans that are pending
             $query = "pending";
             $title = "Pending Reservations";
             $reservation = self::by_status($query);
             break;
         case "loaned":
             //this shows any loans that are pending
             $query = "loaned out";
             $title = "Loaned Reservations";
             $reservation = self::by_status($query);
             break;
         case "outstanding":
             //this shows any loans that are pending
             $end_date = date('Y-m-d');
             $title = "Outstanding Reservations";
             $reservation = self::by_outstanding($end_date);
             break;
         case "missing":
             //this shows any loans that are pending
             $query = "missing-equipment";
             $title = "Missing Reservations";
             $reservation = self::by_status($query);
             break;
         case "detailed":
             //this searches between two dates
             if ($start_date = $request->param('from_date')) {
                 $start_date = date('Y-m-d', strtotime($start_date));
                 $args['start_date'] = $start_date;
                 $fixed_start_date = self::fix_date($start_date);
             }
             if ($end_date = $request->param('to_date')) {
                 $end_date = date('Y-m-d', strtotime($end_date));
                 $args['end_date'] = $end_date;
                 $fixed_end_date = self::fix_date($end_date);
             }
             if ($first_name = $request->param('first_name')) {
                 $args['first_name'] = $first_name;
             }
             if ($last_name = $request->param('last_name')) {
                 $args['last_name'] = $last_name;
             }
             if ($location = $request->param('location')) {
                 $args['location'] = $location;
             }
             if ($reservation_id = $request->param('reservation_id')) {
                 $args['reservation_id'] = $reservation_id;
             }
             if (count($args) < 1) {
                 $_SESSION['errors'][] = 'You need to specify at least one criteria.';
                 $redirect_url = $GLOBALS['BASE_URL'] . '/admin/reservation';
             } else {
                 $reservation = self::search_reservation($args);
             }
             if ($start_date && $end_date) {
                 //only change the title if there is a start and end date
                 $title = "Reservations from {$fixed_start_date} to {$fixed_end_date}";
             }
             break;
         case "thisreservation":
             $dates = ReserveDatabaseAPI::get_dates($request->id);
             $fixed_start_date = ReserveDatabaseAPI::fix_date($dates['start_date']);
             $fixed_end_date = ReserveDatabaseAPI::fix_date($dates['end_date']);
             $title = "Reservations from {$fixed_start_date} to {$fixed_end_date}";
             break;
         default:
             //if there was no parameter, return the dates and reservations for today
             if ($request->id) {
                 //if there is a request id, load the dates from the reservation
                 $dates = ReserveDatabaseAPI::get_dates($request->id);
                 $fixed_start_date = ReserveDatabaseAPI::fix_date($dates['start_date']);
                 $fixed_end_date = ReserveDatabaseAPI::fix_date($dates['end_date']);
                 $title = "Reservations from {$fixed_start_date} to {$fixed_end_date}";
             } else {
                 //if there is not a request id, load today as the default date
                 $start_date = date('Y-m-d');
                 $end_date = date('Y-m-d');
                 $dates = array('start_date' => $start_date, 'end_date' => $end_date);
                 $fixed_start_date = self::fix_date($start_date);
                 $title = "Reservations for today - {$fixed_start_date}";
                 $reservation = self::by_date($start_date);
             }
             break;
     }
     //end switch
     $data = array('title' => $title, 'dates' => $dates, 'redirect_url' => $redirect_url, 'reservations' => $reservation);
     return $data;
 }