=\"" . $curtime_in . "\" ORDER BY resvtimeend ASC, idx ASC"; //echo "
\n"; //print_r($query_string); //echo "\n"; } else { //User who is a flight instructor. $query_string = "SELECT idx,type,useridx,alias," . "finstid,finsttimestart,finsttimeend," . "acftsimid,acftsimtimestart,acftsimtimeend," . "resvtimestart,resvtimeend " . "FROM resv WHERE (useridx=\"" . $useridx_in . "\" OR finstid=\"" . $rscs_corresponding . "\") AND type!=\"" . RESV_TYPE_BANNER . "\" AND resvtimeend>=\"" . $curtime_in . "\" ORDER BY resvtimeend ASC, idx ASC"; //echo "
\n"; //print_r($query_string); //echo "\n"; } //Run the query, get the result. $result = mysql_query($query_string, $GLOBAL_dbhandle); //If the query did not go through successfully, return FALSE to the caller. // if ($result === FALSE) { $rv = FALSE; } // //If the number of rows in the result set is 0, also give the caller FALSE. else if (mysql_num_rows($result) <= 0) { //Technically, we got a result set, so free it. mysql_free_result($result); //The caller gets FALSE signaling no data. $rv = FALSE; } else { //If we're here, we have a valid result set. Each row of the returned array is //the expected fields from the resv table. //Copy out the results to the array we'll return. while ($row = mysql_fetch_assoc($result)) { $rv[] = $row; } //Free memory. mysql_free_result($result); } //Unlock the database (if it was locked) using the recursive critical section //method. if (! $db_was_locked) { DB_db_unlock(); $GLOBAL_dblocked = FALSE; } //Return the agreed-on result to the caller. return($rv); } // //-------------------------------------------------------------------------------------------------------------- //Retrieves the reservations for an individual user that: // a)Are owned by the user OR // b)Are instructional appointments with the user as the flight instructor. // c)End before the current time (i.e. have fully finished). // d)Are not banner reservations. // //Results returned are information about the reservation except description, as an associative //array in order from now to the future. // //If no such reservations exist, FALSE is returned. // function RESV_usrs_past_resv_a($useridx_in, $curtime_in) { global $GLOBAL_dblocked; global $GLOBAL_dbhandle; //Lock the database using the recursive protocol. This is done to be sure that nobody //deletes the user or the resource during this operation. $db_was_locked = $GLOBAL_dblocked; if (! $GLOBAL_dblocked) { DB_db_lock(); $GLOBAL_dblocked = TRUE; } //See if the user record exists. If not, can't go further, and return FALSE. // $userinfo = USRS_retrieve_by_idx($useridx_in); if ($userinfo === FALSE) { if (! $db_was_locked) { DB_db_unlock(); $GLOBAL_dblocked = FALSE; } return(FALSE); } //Figure out if the user is a flight instructor or not. This is done by //looking at the resources to see if there is a resource that points back to the //user. // //Form the query string. $query_string = "SELECT idx FROM rscs WHERE usercorres=\"" . mysql_real_escape_string((string)$useridx_in, $GLOBAL_dbhandle) . "\""; //Execute the query. $result = mysql_query($query_string, $GLOBAL_dbhandle); if ($result === FALSE) { //Unknown query failure. Return FALSE to the caller. No need to free, //as this is not a result. $rscs_corresponding = FALSE; } else { //Figure out how many rows in the result. $nrows = mysql_num_rows($result); if ($nrows == 0) { //No rows in the result. The query failed to give us a record, but still //we need to free the result set. //Free the result. mysql_free_result($result); //The caller gets FALSE. No record with that SID. $rscs_corresponding = FALSE; } else { //We have at least one record. Assume just one, because the IDX is supposed //to be unique. $resource_record = mysql_fetch_assoc($result); //Get the associative record. $rscs_corresponding = $resource_record["idx"]; //Free the result. mysql_free_result($result); } } //Form and execute the query to get the relevant reservations. The query is slightly //more complex if the user is also a flight instructor. if ($rscs_corresponding === FALSE) { //User who is not a flight instructor. $query_string = "SELECT idx,type,useridx,alias," . "finstid,finsttimestart,finsttimeend," . "acftsimid,acftsimtimestart,acftsimtimeend," . "resvtimestart,resvtimeend " . "FROM resv WHERE useridx=\"" . $useridx_in . "\" AND type!=\"" . RESV_TYPE_BANNER . "\" AND resvtimeend<\"" . $curtime_in . "\" ORDER BY resvtimeend DESC, idx ASC"; //echo "
\n"; //print_r($query_string); //echo "\n"; } else { //User who is a flight instructor. $query_string = "SELECT idx,type,useridx,alias," . "finstid,finsttimestart,finsttimeend," . "acftsimid,acftsimtimestart,acftsimtimeend," . "resvtimestart,resvtimeend " . "FROM resv WHERE (useridx=\"" . $useridx_in . "\" OR finstid=\"" . $rscs_corresponding . "\") AND type!=\"" . RESV_TYPE_BANNER . "\" AND resvtimeend<\"" . $curtime_in . "\" ORDER BY resvtimeend DESC, idx ASC"; //echo "
\n"; //print_r($query_string); //echo "\n"; } //Run the query, get the result. $result = mysql_query($query_string, $GLOBAL_dbhandle); //If the query did not go through successfully, return FALSE to the caller. // if ($result === FALSE) { $rv = FALSE; } // //If the number of rows in the result set is 0, also give the caller FALSE. else if (mysql_num_rows($result) <= 0) { //Technically, we got a result set, so free it. mysql_free_result($result); //The caller gets FALSE signaling no data. $rv = FALSE; } else { //If we're here, we have a valid result set. Each row of the returned array is //the expected fields from the resv table. //Copy out the results to the array we'll return. while ($row = mysql_fetch_assoc($result)) { $rv[] = $row; } //Free memory. mysql_free_result($result); } //Unlock the database (if it was locked) using the recursive critical section //method. if (! $db_was_locked) { DB_db_unlock(); $GLOBAL_dblocked = FALSE; } //Return the agreed-on result to the caller. return($rv); } // //-------------------------------------------------------------------------------------------------------------- //Returns the time for a reservation display time. // function RESV_time_string_a($st_in) { //Split apart the hour and minute as integers. sscanf(SubStr($st_in, 10, 4), "%02d%02d", $hour, $minute); if (CONFIG_TIME_FORMAT_24HR) { $rv = sprintf("%02d:%02d", $hour, $minute); } else { if ($hour == 0) { $rv = sprintf("12:%02d a.m.", $minute); } else if ($hour == 12) { $rv = sprintf("12:%02d p.m.", $minute); } else if ($hour > 12) { $rv = sprintf("%d:%02d p.m.", $hour-12, $minute); } else { $rv = sprintf("%d:%02d a.m.", $hour, $minute); } } return($rv); } // //-------------------------------------------------------------------------------------------------------------- //Returns the date for a reservation display date. // function RESV_date_string_a($st_in) { if (CONFIG_DATE_FORMAT_EUROPEAN) { $rv = SubStr($st_in, 2, 4) . "/" . SubStr($st_in, 6, 2) . "/" . SubStr($st_in, 8, 2); } else { $rv = SubStr($st_in, 6, 2) . "/" . SubStr($st_in, 8, 2) . "/" . SubStr($st_in, 2, 4); } return($rv); } // //-------------------------------------------------------------------------------------------------------------- //Returns the text corresponding to the date range for printout of reservations. If the two //STIMEs correspond to the same date, the date is compressed into one. // function RESV_date_range_string_a($st_start_in, $st_end_in) { if (SubStr($st_start_in, 0, 10) == SubStr($st_end_in, 0, 10)) { //Dates are the same, so can just do the date once. $rv = RESV_date_string_a($st_start_in) . " (" . STIME_dow_string_a($st_start_in) . ") " . RESV_time_string_a($st_start_in) . " - " . RESV_time_string_a($st_end_in); } else { //Dates are different so must do it twice. $rv = RESV_date_string_a($st_start_in) . " (" . STIME_dow_string_a($st_start_in) . ") " . RESV_time_string_a($st_start_in) . " - " . RESV_date_string_a($st_end_in) . " (" . STIME_dow_string_a($st_end_in) . ") " . RESV_time_string_a($st_end_in); } //Tack on the duration. $rv = $rv . " (" . STIME_diff_string_a($st_start_in, $st_end_in) . ")"; return($rv); } // //-------------------------------------------------------------------------------------------------------------- //Returns the text corresponding to a given reservation, flight instructor first. If the date //and time for the aircraft/simulator and flight instructor are the same, only one string is returned. // function RESV_resv_date_string_a($resv_in, $personstring, $acftsimstring) { if (($resv_in["finstid"] != 0) && ($resv_in["acftsimid"] != 0)) { //Both a flight instructor and an aircraft. if (($resv_in["finsttimestart"] == $resv_in["acftsimtimestart"]) && ($resv_in["finsttimeend"] == $resv_in["acftsimtimeend"])) { //Start and end time of the instructor and aircraft are the same. Can combine them. // $rv = RESV_date_range_string_a($resv_in["finsttimestart"], $resv_in["finsttimeend"]); } else { //Start and end time of instructor and aircraft are different. Cannot combine them. $rv = $personstring . " " . RESV_date_range_string_a($resv_in["finsttimestart"], $resv_in["finsttimeend"]) . ", " . $acftsimstring . " " . RESV_date_range_string_a($resv_in["acftsimtimestart"], $resv_in["acftsimtimeend"]) ; } } else if (($resv_in["finstid"] == 0) && ($resv_in["acftsimid"] != 0)) { //Aircraft but no flight instructor. $rv = RESV_date_range_string_a($resv_in["acftsimtimestart"], $resv_in["acftsimtimeend"]); } else if (($resv_in["finstid"] != 0) && ($resv_in["acftsimid"] == 0)) { //Flight instructor but no aircraft. $rv = RESV_date_range_string_a($resv_in["finsttimestart"], $resv_in["finsttimeend"]); } else { //Should never be here. Return the empty string to be safe. $rv = ""; } return($rv); } // //-------------------------------------------------------------------------------------------------------------- //End of $RCSfile: resvx.inc,v $. //-------------------------------------------------------------------------------------------------------------- ?>