"; //print_r($query_string); //echo "
"; //Execute the query to insert the record. $result = mysql_query($query_string, $GLOBAL_dbhandle); // //If the update failed, set the query failure flag. if ($result == FALSE) { $query_failure_error_out = TRUE; } //Unlock the database (if it was locked) using the recursive critical section //method. if (! $db_was_locked) { DB_db_unlock(); $GLOBAL_dblocked = FALSE; } } // //-------------------------------------------------------------------------------------------------------------- //Retrieves an associative array containing full information about the resource whose index is //passed, or FALSE if it can't be located. // function RSCS_retrieve_by_idx($idx) { global $GLOBAL_dbhandle; //Form the query string. $query_string = "SELECT * FROM rscs WHERE idx=\"" . mysql_real_escape_string($idx, $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. $rv = 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. $rv = FALSE; } else { //We have at least one record. Assume just one, because the IDX is supposed //to be unique. $rv = mysql_fetch_assoc($result); //Get the associative record. //Free the result. mysql_free_result($result); } //Return the value to the caller. return($rv); } } // //-------------------------------------------------------------------------------------------------------------- //Retrieves an array containing the indices of all flight instructors in the resources //table that are online, or FALSE if none exist. // function RSCS_get_fi_online_idxs() { global $GLOBAL_dbhandle; //Form the query string. $query_string = "SELECT idx FROM rscs WHERE type=\"" . mysql_real_escape_string((string)RSCS_TYPE_FLIGHTINSTRUCTOR, $GLOBAL_dbhandle) . "\" AND status=\"" . mysql_real_escape_string((string)RSCS_STATUS_ONLINE, $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. $rv = 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 records. $rv = FALSE; } else { //We have at least one record. Grab the indices. // for ($i=0; $i<$nrows; $i++) { $temp = mysql_fetch_assoc($result); $rv[$i] = $temp["idx"]; } //Free the result. mysql_free_result($result); } //Return the value to the caller. return($rv); } } // //-------------------------------------------------------------------------------------------------------------- //Retrieves an array containing the indices of all aircraft/simulators in the resources //table that are online, or FALSE if none exist. // function RSCS_get_acftsim_online_idxs() { global $GLOBAL_dbhandle; //Form the query string. $query_string = "SELECT idx FROM rscs WHERE ( type=\"" . mysql_real_escape_string((string)RSCS_TYPE_AIRCRAFT, $GLOBAL_dbhandle) . "\" OR type=\"" . mysql_real_escape_string((string)RSCS_TYPE_SIMULATOR, $GLOBAL_dbhandle) . "\" ) AND status=\"" . mysql_real_escape_string((string)RSCS_STATUS_ONLINE, $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. $rv = 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 records. $rv = FALSE; } else { //We have at least one record. Grab the indices. // for ($i=0; $i<$nrows; $i++) { $temp = mysql_fetch_assoc($result); $rv[$i] = $temp["idx"]; } //Free the result. mysql_free_result($result); } //Return the value to the caller. return($rv); } } // //-------------------------------------------------------------------------------------------------------------- //Retrieves an array containing the indices of _all_ resources, ordered by status, sort index, then index //for display on the resource list page. // function RSCS_get_idxs_all_rscslist_a() { global $GLOBAL_dbhandle; //Form the query string. $query_string = "SELECT idx FROM rscs ORDER BY status DESC, disporder ASC, idx ASC"; //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. $rv = 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 records. $rv = FALSE; } else { //We have at least one record. Grab the indices. // for ($i=0; $i<$nrows; $i++) { $temp = mysql_fetch_assoc($result); $rv[$i] = $temp["idx"]; } //Free the result. mysql_free_result($result); } //Return the value to the caller. return($rv); } } // //-------------------------------------------------------------------------------------------------------------- //Retrieves an array containing the short description, medium description, database index, status, and //corresponding user for each entry in the resources table. The array returned is indexed by the database index //(not sequentially), meaning that some gaps in the indexing may occur. // //Returns FALSE if no records. // function RSCS_get_key_info_rscslist_a() { global $GLOBAL_dbhandle; //Form the query string. $query_string = "SELECT idx,type,status,initials,shortdesc,usercorres FROM rscs"; //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. $rv = 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 records. $rv = FALSE; } else { //We have at least one record. Grab the data. // for ($i=0; $i<$nrows; $i++) { $temp = mysql_fetch_assoc($result); $rv[$temp["idx"]] = $temp; } //Free the result. mysql_free_result($result); } //Return the value to the caller. return($rv); } } // //-------------------------------------------------------------------------------------------------------------- //Renumbers the disporder fields of the resource table at a fixed interval. // function RSCS_renumber_disporder_autointerval() { global $GLOBAL_dblocked; global $GLOBAL_dbhandle; $renumber_interval = 100; //Interval to use. 100 should be large enough for any practical //number of resources. //Lock the database using the recursive locking protocol to ensure that there won't be //any changes while we are going through tampering with each resource. // $db_was_locked = $GLOBAL_dblocked; if (! $GLOBAL_dblocked) { DB_db_lock(); $GLOBAL_dblocked = TRUE; } //----------------------------------------------- //Get the complete set of indices from the resource table. We want to preserve the old //order, so primary sort key is the display order, but then we have a couple (somewhat //arbitrary) tiebreakers. We calculate the value FALSE (in place of an array) //if something goes wrong. // //Form the query string. $query_string = "SELECT idx FROM rscs ORDER BY disporder ASC, status DESC, idx ASC"; //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. $indices = 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 records. $indices = FALSE; } else { //We have at least one record. Grab the indices. // for ($i=0; $i<$nrows; $i++) { $temp = mysql_fetch_assoc($result); $indices[$i] = $temp["idx"]; } //Free the result. mysql_free_result($result); } } //----------------------------------------------- //If we had success in getting the list of indices (in the order we want), //loop through them all and give them the right values. We loop backwards to avoid //changing resource order in the event that the httpd process dies in the middle of this. //We also need to change the modification sguid to make sure any editing collisions //will be detected. // if ($indices !== FALSE) { $n = count($indices); $number_to_assign = $n * $renumber_interval; for ($i=0; $i<$n; $i++) { $sguid = SGUID_sguid(); $target = $indices[$n-1-$i]; mysql_query("UPDATE rscs SET disporder=\"" . (string)(($n - $i) * $renumber_interval) . "\", crmodsguid=\"" . $sguid . "\" WHERE idx=\"" . $target . "\"", $GLOBAL_dbhandle); } } //----------------------------------------------- //Unlock the database using the recursive locking protocol. // if (! $db_was_locked) { DB_db_unlock(); $GLOBAL_dblocked = FALSE; } } // //-------------------------------------------------------------------------------------------------------------- //Maps from the resource status to a short description for the resource views. // function RSCS_status_map_long($status_in) { switch($status_in) { default: { $rv = "Unknown"; break; } case RSCS_STATUS_OFFLINE : { $rv = "Offline"; break; } case RSCS_STATUS_ONLINE : { $rv = "Online"; break; } } return($rv); } //-------------------------------------------------------------------------------------------------------------- //Maps from the resource status to a short description for the resource views. // function RSCS_type_map_long($status_in) { switch($status_in) { default: { $rv = "Unknown"; break; } case RSCS_TYPE_AIRCRAFT : { $rv = "Aircraft"; break; } case RSCS_TYPE_SIMULATOR : { $rv = "Simulator"; break; } case RSCS_TYPE_FLIGHTINSTRUCTOR : { $rv = "Flight Instructor"; break; } } return($rv); } //-------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------- //Returns the HTML that should be used to identify the resource index on the EDIT and ADD pages. HTML may //be marked up with and and includes the trailing colon. // function RSCS_idx_id_html_01() { return("idx:"); } //-------------------------------------------------------------------------------------------------------------- //Returns the HTML that should be used to display the resource index on the EDIT and ADD pages. // function RSCS_idx_disp_html_01($idx_in) { $rv = number_format($idx_in); return($rv); } //-------------------------------------------------------------------------------------------------------------- //Returns the HTML that should be used to identify the resource index description on the EDIT and ADD pages. //HTML may be marked up with , , and . // function RSCS_idx_desc_html_01() { $rv = "The idx field is assigned automatically by the database " . "when a resource is created and may not be modified."; return($rv); } //-------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------- //Returns the HTML that should be used to identify the resource type on the EDIT and ADD pages. HTML may //be marked up with and and includes the trailing colon. // function RSCS_type_id_html_01() { return("type:"); } //-------------------------------------------------------------------------------------------------------------- //Returns the HTML that should be used to display the resource type select control on the EDIT and ADD pages. // function RSCS_type_disp_html_01($type_in) { //Turn the input into a numeric value. If it can't be turned into a numeric value, //make it an aircraft. if (is_numeric($type_in)) { $type_in = (int)$type_in; if ( ($type_in != RSCS_TYPE_AIRCRAFT) && ($type_in != RSCS_TYPE_SIMULATOR) && ($type_in != RSCS_TYPE_FLIGHTINSTRUCTOR) ) { //This is nothing we recognize. Assume aircraft. $type_in = (int)RSCS_TYPE_AIRCRAFT; } } else { //This is nothing we recognize. Assume aircraft. $type_in = (int)RSCS_TYPE_AIRCRAFT; } //Do the control. $rv = ""; //-------- $rv .= "