/[dtapublic]/to_be_filed/webprojs/php_libraries/php_library/fboprime/resv.inc
ViewVC logotype

Annotation of /to_be_filed/webprojs/php_libraries/php_library/fboprime/resv.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (7 years, 5 months ago) by dashley
File size: 12532 byte(s)
Initial commit.
1 dashley 35 <?php
2     //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/phplib/resv.inc,v 1.5 2006/07/29 23:04:50 dashley Exp $
3     //--------------------------------------------------------------------------------------------------------------
4     //resv.inc--FboPrime Database resv Table Manipulation Functions
5     //Copyright (C) 2006 David T. Ashley
6     //
7     //This program is free software; you can redistribute it and/or
8     //modify it under the terms of the GNU General Public License
9     //as published by the Free Software Foundation; either version 2
10     //of the License, or (at your option) any later version.
11     //
12     //This program is distributed in the hope that it will be useful,
13     //but WITHOUT ANY WARRANTY; without even the implied warranty of
14     //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     //GNU General Public License for more details.
16     //
17     //You should have received a copy of the GNU General Public License
18     //along with this program; if not, write to the Free Software
19     //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20     //********************************************************************************
21     //Contains functions related to [operations on] the usrs table of the database.
22     //--------------------------------------------------------------------------------------------------------------
23     //
24     require_once("db.inc");
25     require_once("global.inc");
26     //
27     //--------------------------------------------------------------------------------------------------------------
28     //Constants for usrs table fields.
29     //
30     //Constants for different types of reservations.
31     define("RESV_TYPE_BANNER", 0 );
32     define("RESV_TYPE_ACTIVE", 1 );
33     define("RESV_TYPE_STANDBY", 2 );
34     //
35     //--------------------------------------------------------------------------------------------------------------
36     //Retrieves a two dimensional associative array corresponding to the RESV record
37     //with the passed IDX, or FALSE if the record does not exist.
38     //
39     function RESV_retrieve_by_idx($idx)
40     {
41     global $GLOBAL_dbhandle;
42    
43     //Form the query string.
44     $query_string = "SELECT * FROM resv WHERE idx=\""
45     .
46     mysql_real_escape_string($idx, $GLOBAL_dbhandle)
47     .
48     "\"";
49    
50     //Execute the query.
51     $result = mysql_query($query_string, $GLOBAL_dbhandle);
52    
53     if ($result === FALSE)
54     {
55     //Unknown query failure. Return FALSE to the caller. No need to free,
56     //as this is not a result.
57     $rv = FALSE;
58     }
59     else
60     {
61     //Figure out how many rows in the result.
62     $nrows = mysql_num_rows($result);
63    
64     if ($nrows == 0)
65     {
66     //No rows in the result. The query failed to give us a record, but still
67     //we need to free the result set.
68    
69     //Free the result.
70     mysql_free_result($result);
71    
72     //The caller gets FALSE. No record with that SID.
73     $rv = FALSE;
74     }
75     else
76     {
77     //We have at least one record. Assume just one, because the IDX is supposed
78     //to be unique.
79     $rv = mysql_fetch_assoc($result); //Get the associative record.
80    
81     //Free the result.
82     mysql_free_result($result);
83     }
84    
85     //Return the value to the caller.
86     return($rv);
87     }
88     }
89     //
90     //--------------------------------------------------------------------------------------------------------------
91     //Retrieves two two-dimensional arrays of elements containing full information about each reservation that
92     //overlaps into the passed time window. Two arrays are necessary because we have the need to sort both by
93     //flight instructor and by aircraft/simulator.
94     //
95     //Reservations are sorted first by index of the flight instructor/resource, then by reservation, then by the
96     //start time, then by the tie-breaker SGUID.
97     //
98     //The start-time ordering is necessary to be sure that within a displayed row, one doesn't have to sort
99     //before trying to display.
100     //
101     //For each of the two arrays, a parallel search array is also returned. The indices of the parallel search
102     //array are the same as the corresponding indices of the data array, and the values are the flight
103     //instructor/resource index. The purpose of the parallel search array are to assist in locating the data
104     //for a given flight instructor/resource by index in the data array as rapidly as possible.
105     //
106     //If no reservations apply for either of the two queries, FALSE is returned in both the data array and
107     //the search array.
108     //
109     function RESV_resvns_in_time_window( $stime_startwindow_in,
110     $stime_endwindow_in,
111     &$flight_inst_data_array,
112     &$flight_inst_search_array,
113     &$resource_data_array,
114     &$resource_search_array )
115     {
116     global $GLOBAL_dbhandle;
117    
118     //------------------------------------------------------------------------------------------------------------
119     //Start with a clean slate for the output variables.
120     //
121     if (isset($flight_inst_data_array))
122     unset($flight_inst_data_array);
123     if (isset($flight_inst_search_array))
124     unset($flight_inst_search_array);
125     if (isset($resource_data_array))
126     unset($resource_data_array);
127     if (isset($resource_search_array))
128     unset($resource_search_array);
129     //
130     //------------------------------------------------------------------------------------------------------------
131     //Flight instructor half.
132     //
133     $query_string = "SELECT * FROM resv WHERE finstid!=\"0\" AND finsttimestart<\""
134     .
135     $stime_endwindow_in
136     .
137     "\" AND finsttimeend>\""
138     .
139     $stime_startwindow_in
140     .
141     "\" ORDER BY finstid, type, finsttimestart, crsguid ASC";
142    
143     $result = mysql_query($query_string, $GLOBAL_dbhandle);
144    
145     //If the query did not go through successfully, return FALSE to the caller.
146     //
147     if ($result === FALSE)
148     {
149     //The caller gets FALSE signaling no data.
150     $flight_inst_data_array = FALSE;
151     $flight_inst_search_array = FALSE;
152     }
153     //
154     //If the number of rows in the result set is 0, also give the caller FALSE.
155     else if (mysql_num_rows($result) <= 0)
156     {
157     //Technically, we got a result set, so free it.
158     mysql_free_result($result);
159    
160     //The caller gets FALSE signaling no data.
161     $flight_inst_data_array = FALSE;
162     $flight_inst_search_array = FALSE;
163     }
164     else
165     {
166     //If we're here, we have a valid result set. Each row of the returned array is
167     //the expected fields from the resv table.
168    
169     //Copy out the results to the array we'll return.
170     while ($row = mysql_fetch_assoc($result))
171     {
172     $flight_inst_data_array[] = $row; //Assign the data.
173     $flight_inst_search_array[] = $row["finstid"]; //Set the search index.
174     }
175    
176     //Free memory.
177     mysql_free_result($result);
178     }
179    
180     //------------------------------------------------------------------------------------------------------------
181     //Resource half.
182     //
183     $query_string = "SELECT * FROM resv WHERE acftsimid!=\"0\" AND acftsimtimestart<\""
184     .
185     $stime_endwindow_in
186     .
187     "\" AND acftsimtimeend>\""
188     .
189     $stime_startwindow_in
190     .
191     "\" ORDER BY acftsimid, type, acftsimtimestart, crsguid ASC";
192    
193     $result = mysql_query($query_string, $GLOBAL_dbhandle);
194    
195     //If the query did not go through successfully, return FALSE to the caller.
196     //
197     if ($result === FALSE)
198     {
199     //The caller gets FALSE signaling no data.
200     $resource_data_array = FALSE;
201     $resource_search_array = FALSE;
202     }
203     //
204     //If the number of rows in the result set is 0, also give the caller FALSE.
205     else if (mysql_num_rows($result) <= 0)
206     {
207     //Technically, we got a result set, so free it.
208     mysql_free_result($result);
209    
210     //The caller gets FALSE signaling no data.
211     $resource_data_array = FALSE;
212     $resource_search_array = FALSE;
213     }
214     else
215     {
216     //If we're here, we have a valid result set. Each row of the returned array is
217     //the expected fields from the resv table.
218    
219     //Copy out the results to the array we'll return.
220     while ($row = mysql_fetch_assoc($result))
221     {
222     $resource_data_array[] = $row; //Assign the data.
223     $resource_search_array[] = $row["acftsimid"]; //Set the search index.
224     }
225    
226     //Free memory.
227     mysql_free_result($result);
228     }
229     }
230     //
231     //--------------------------------------------------------------------------------------------------------------
232     //Extracts the records pertaining to a certain flight instructor from an array returned from
233     //the RESV_resvns_in_time_window() function, using the search array as a search aid. Returns FALSE
234     //if no match.
235     //
236     //Records must not have been rearranged (they must still be sorted by the flight instructor ID).
237     //
238     function RESV_extract_finst_records($data_array_in, $search_array_in, $idx_to_find_in)
239     {
240     //If the data array or search array are FALSE, then the result is FALSE, i.e. subset of the
241     //empty set is also the empty set.
242     if (($data_array_in === FALSE) || ($search_array_in === FALSE))
243     {
244     return(FALSE);
245     }
246    
247     //Find the first record with the passed index, if any. This is enough, as the others will be contiguous.
248     $index = array_search($idx_to_find_in, $search_array_in);
249    
250     //If there is no match, return FALSE.
251     if (($index === FALSE) || ($index === NULL))
252     {
253     return(FALSE);
254     }
255    
256     //If we're here, we have success. Find out how many elements in the array, for reference.
257     $n = count($data_array_in);
258    
259     //Tack the original search success onto the return value.
260     $rv[] = $data_array_in[$index];
261    
262     //Find any others.
263     $index++;
264     while (($index < $n) && ($search_array_in[$index] == $idx_to_find_in))
265     {
266     $rv[] = $data_array_in[$index];
267     $index++;
268     }
269    
270     //Return the results.
271     return($rv);
272     }
273     //
274     //--------------------------------------------------------------------------------------------------------------
275     //Extracts the records pertaining to a certain resource (aircraft/simulator) from an array returned from
276     //the RESV_resvns_in_time_window() function, using the search array as a search aid. Returns FALSE
277     //if no match.
278     //
279     //Records must not have been rearranged (they must still be sorted by the resource ID).
280     //
281     function RESV_extract_resource_records($data_array_in, $search_array_in, $idx_to_find_in)
282     {
283     //If the data array or search array are FALSE, then the result is FALSE, i.e. subset of the
284     //empty set is also the empty set.
285     if (($data_array_in === FALSE) || ($search_array_in === FALSE))
286     {
287     return(FALSE);
288     }
289    
290     //Find the first record with the passed index, if any. This is enough, as the others will be contiguous.
291     $index = array_search($idx_to_find_in, $search_array_in);
292    
293     //If there is no match, return FALSE.
294     if (($index === FALSE) || ($index === NULL))
295     {
296     return(FALSE);
297     }
298    
299     //If we're here, we have success. Find out how many elements in the array, for reference.
300     $n = count($data_array_in);
301    
302     //Tack the original search success onto the return value.
303     $rv[] = $data_array_in[$index];
304    
305     //Find any others.
306     $index++;
307     while (($index < $n) && ($search_array_in[$index] == $idx_to_find_in))
308     {
309     $rv[] = $data_array_in[$index];
310     $index++;
311     }
312    
313     //Return the results.
314     return($rv);
315     }
316     //
317     //--------------------------------------------------------------------------------------------------------------
318     //End of $RCSfile: resv.inc,v $.
319     //--------------------------------------------------------------------------------------------------------------
320     ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25