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

Contents of /to_be_filed/webprojs/php_libraries/php_library/fboprime/rscs.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (7 years, 11 months ago) by dashley
File size: 8198 byte(s)
Initial commit.
1 <?php
2 //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/phplib/rscs.inc,v 1.7 2006/07/27 01:24:28 dashley Exp $
3 //--------------------------------------------------------------------------------------------------------------
4 //rscs.inc--FboPrime Database rscs 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 rscs table of the database.
22 //--------------------------------------------------------------------------------------------------------------
23 //
24 require_once("db.inc");
25 require_once("global.inc");
26 require_once("sguid.inc");
27 //
28 //--------------------------------------------------------------------------------------------------------------
29 //Constants for rscs table fields.
30 //
31 //Constants for the type field of the rscs table.
32 define("RSCS_TYPE_AIRCRAFT", 0 );
33 define("RSCS_TYPE_SIMULATOR", 1 );
34 define("RSCS_TYPE_FLIGHTINSTRUCTOR", 2 );
35 //
36 //Constants for the status field of the rscs table.
37 define("RSCS_STATUS_OFFLINE", 0 );
38 define("RSCS_STATUS_ONLINE", 1 );
39 //
40 //--------------------------------------------------------------------------------------------------------------
41 //Inserts a new record into the RSCS database, using the passed associative array to assign the fields.
42 //Each element of the associative array is indexed by a field name.
43 //
44 //The function returns the integer index of the record added.
45 //
46 //This operation cannot fail. The autoincrement index is the primary key, so no duplicates or other
47 //error conditions are meaningful.
48 //
49 function RSCS_insert($arg)
50 {
51 global $GLOBAL_dbhandle;
52 global $GLOBAL_dblocked;
53
54 //Build the query string with each successive parameter.
55 //
56 //type
57 //------
58 if (! isset($arg["type"]))
59 $pushval = RSCS_TYPE_AIRCRAFT;
60 else
61 $pushval = $arg["type"];
62 $query_string = "INSERT INTO rscs SET type=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"";
63 //
64 //status
65 //------
66 if (! isset($arg["status"]))
67 $pushval = RSCS_STATUS_ONLINE;
68 else
69 $pushval = $arg["status"];
70 $query_string .= (", status=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
71 //
72 //disporder
73 //---------
74 if (! isset($arg["disporder"]))
75 $pushval = 0;
76 else
77 $pushval = $arg["disporder"];
78 $query_string .= (", disporder=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
79 //
80 //longdesc
81 //--------
82 if (! isset($arg["longdesc"]))
83 $pushval = "";
84 else
85 $pushval = $arg["longdesc"];
86 $query_string .= (", longdesc=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
87 //
88 //shortdesc
89 //---------
90 if (! isset($arg["shortdesc"]))
91 $pushval = "";
92 else
93 $pushval = $arg["shortdesc"];
94 $query_string .= (", shortdesc=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
95 //
96 //initials
97 //--------
98 if (! isset($arg["initials"]))
99 $pushval = "";
100 else
101 $pushval = $arg["initials"];
102 $query_string .= (", initials=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
103 //
104 //rstdtime
105 //--------
106 if (! isset($arg["rstdtime"]))
107 $pushval = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU";
108 else
109 $pushval = $arg["rstdtime"];
110 $query_string .= (", rstdtime=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
111 //
112 //schedaheadhrs
113 //-------------
114 if (! isset($arg["schedaheadhrs"]))
115 $pushval = (int) 0;
116 else
117 $pushval = $arg["schedaheadhrs"];
118 $query_string .= (", schedaheadhrs=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
119 //
120 //usercorres
121 //----------
122 if (! isset($arg["usercorres"]))
123 $pushval = (int) 0;
124 else
125 $pushval = $arg["usercorres"];
126 $query_string .= (", usercorres=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
127 //
128 //crmodsguid
129 //----------
130 if (! isset($arg["crmodsguid"]))
131 $pushval = SGUID_sguid();
132 else
133 $pushval = $arg["crmodsguid"];
134 $query_string .= (", crmodsguid=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
135 //
136 //echo " " . $query_string . " ";
137
138 //Execute the query to insert the record.
139 $result = mysql_query($query_string, $GLOBAL_dbhandle);
140 //
141 //If the insert failed, our caller gets FALSE.
142 if ($result == FALSE)
143 {
144 $rv = FALSE;
145 }
146 else
147 {
148 //The insert was successful. Figure out the index that was assigned.
149 $result = mysql_query("SELECT LAST_INSERT_ID()");
150
151 //If we have a failure, the caller gets FALSE, otherwise the caller gets the
152 //index.
153 if ($result === FALSE)
154 {
155 $rv = FALSE;
156 }
157 else
158 {
159 //Pick apart the result.
160 $row = mysql_fetch_array($result, MYSQL_NUM);
161
162 //Extract the integer.
163 $rv = $row[0];
164
165 //Free the result memory.
166 mysql_free_result($result);
167 }
168 }
169
170 //Return the result.
171 return($rv);
172 }
173 //
174 //--------------------------------------------------------------------------------------------------------------
175 //Retrieves a two-dimensional array of elements containing full information about each resource that is
176 //online for the purpose of displaying the dayview scheduling page. Resources are sorted by the
177 //specified display order, then by type, then (as the ultimate tie-breaker), by index.
178 //
179 //If no resources are online, FALSE is returned.
180 //
181 function RSCS_rscs_list_dayview_online()
182 {
183 global $GLOBAL_dbhandle;
184
185 $query_string = "SELECT * FROM rscs WHERE status="
186 .
187 RSCS_STATUS_ONLINE
188 .
189 " ORDER BY disporder, type, idx ASC";
190
191 $result = mysql_query($query_string, $GLOBAL_dbhandle);
192
193 //If the query did not go through successfully, return FALSE to the caller.
194 //
195 if ($result === FALSE)
196 {
197 return(FALSE);
198 }
199
200 //If the number of rows in the result set is 0, also give the caller FALSE.
201 if (mysql_num_rows($result) <= 0)
202 {
203 //Technically, we got a result set, so free it.
204 mysql_free_result($result);
205
206 //The caller gets FALSE.
207 return(FALSE);
208 }
209
210 //If we're here, we have a valid result set. Each row of the returned array is
211 //the expected fields from the rscs table.
212
213 //Copy out the results to the array we'll return.
214 while ($row = mysql_fetch_assoc($result))
215 {
216 $rv[] = $row;
217 }
218
219 //Free memory.
220 mysql_free_result($result);
221
222 //Give the caller the array.
223 return($rv);
224 }
225 //
226 //--------------------------------------------------------------------------------------------------------------
227 //End of $RCSfile: rscs.inc,v $.
228 //--------------------------------------------------------------------------------------------------------------
229 ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25