/[dtapublic]/to_be_filed/webprojs/php_libraries/php_library/fboprime/dbtestpop.php
ViewVC logotype

Contents of /to_be_filed/webprojs/php_libraries/php_library/fboprime/dbtestpop.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (6 years, 3 months ago) by dashley
File size: 49547 byte(s)
Initial commit.
1 #!/usr/bin/php -q
2 <?php
3 //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/standalone/dbtestpop.php,v 1.31 2006/11/05 01:07:30 dashley Exp $
4 //--------------------------------------------------------------------------------
5 //dbtestpop.php--Populates the FBO-Prime Database for Testing
6 //Copyright (C) 2006 David T. Ashley
7 //
8 //This program is free software; you can redistribute it and/or
9 //modify it under the terms of the GNU General Public License
10 //as published by the Free Software Foundation; either version 2
11 //of the License, or (at your option) any later version.
12 //
13 //This program is distributed in the hope that it will be useful,
14 //but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 //GNU General Public License for more details.
17 //
18 //You should have received a copy of the GNU General Public License
19 //along with this program; if not, write to the Free Software
20 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 //--------------------------------------------------------------------------------
22 //This script populates an FBO-Prime database for testing. This program was
23 //used to populate the database after dropping and recreating the database to
24 //avoid the trouble of manually re-entering data using web forms.
25 //--------------------------------------------------------------------------------
26 //Set the include file path. This is necessary to get to the configuration
27 //information, including how to try to connect to the database.
28 set_include_path("/var/www/php_library/fboprime");
29 //
30 require_once("config.inc");
31 require_once("passwd.inc");
32 require_once("rscsx.inc");
33 require_once("resvx.inc");
34 require_once("sguid.inc");
35 require_once("usrsx.inc");
36 //
37 //--------------------------------------------------------------------------------
38 //Writes a horizontal line.
39 //
40 function hline()
41 {
42 for ($i=0; $i<80; $i++)
43 {
44 echo "-";
45 }
46 echo "\n";
47 }
48 //
49 //--------------------------------------------------------------------------------
50 //Errors out.
51 //
52 function error_out()
53 {
54 echo "FATAL ERROR\n";
55 exit(1);
56 }
57 //--------------------------------------------------------------------------------
58 //Returns a version control string. Used for randomness.
59 //
60 function vc_info()
61 {
62 return("\$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/standalone/dbtestpop.php,v 1.31 2006/11/05 01:07:30 dashley Exp $");
63 }
64 //
65 //--------------------------------------------------------------------------------
66 function random_alpha_character()
67 {
68 $s = "abcdefghijklmnopqrstuvwxyz";
69
70 $l = strlen($s);
71
72 $p = rand(0, $l-1);
73
74 return(SubStr($s, $p, 1));
75 }
76 //
77 //--------------------------------------------------------------------------------
78 function random_alphanum_character()
79 {
80 $s = "abcdefghijklmnopqrstuvwxyz0123456789";
81
82 $l = strlen($s);
83
84 $p = rand(0, $l-1);
85
86 return(SubStr($s, $p, 1));
87 }
88 //
89 //--------------------------------------------------------------------------------
90 function random_nameish_string($maxlen)
91 {
92 if ($maxlen == 0)
93 {
94 return("");
95 }
96 else
97 {
98 $tgt = rand(1,$maxlen);
99 $rv = StrToUpper(random_alpha_character());
100 while(strlen($rv) < $tgt)
101 {
102 $rv .= random_alpha_character();
103 }
104
105 return($rv);
106 }
107 }
108 //
109 //--------------------------------------------------------------------------------
110 function random_useridish_string($maxlen)
111 {
112 if ($maxlen == 0)
113 {
114 return("");
115 }
116 else
117 {
118 $tgt = rand(1,$maxlen);
119 $rv = random_alpha_character();
120 while(strlen($rv) < $tgt)
121 {
122 $rv .= random_alphanum_character();
123 }
124
125 return($rv);
126 }
127 }
128 //
129 //--------------------------------------------------------------------------------
130 function add_random_user()
131 {
132 //Get a userid.
133 $v["userid"] = random_useridish_string(20);
134
135 //Get a password hash.
136 $v["pwhash"] = PASSWD_stored_hash_gen($v["userid"]);
137
138 //Get a sex.
139 $v["sex"] = rand(0,2);
140
141 //Get a first name.
142 $v["fname"] = random_nameish_string(10);
143
144 //Get a last name.
145 $v["lname"] = random_nameish_string(12);
146
147 $trash = rand(0,2);
148 if ($trash == 0)
149 $v["schedalonerscs"] = ",1,5,";
150 else if ($trash == 1)
151 $v["schedalonerscs"] = ",3,2,4,7,12,";
152 else
153 $v["schedalonerscs"] = ",9,";
154
155 //Add the user.
156 USRS_record_add_modify("A", $v, $result_code_out, $errors_out, $warnings_out);
157 }
158 //
159 //--------------------------------------------------------------------------------
160 function add_random_users()
161 {
162 //Decide how many users.
163 $nusers = rand(0,50);
164
165 for ($i=0; $i<$nusers; $i++)
166 add_random_user();
167 }
168 //
169 //--------------------------------------------------------------------------------
170 function populate_usrs_table()
171 {
172 global $GLOBAL_dbhandle;
173
174 $lut = array(
175 //-------------------------------------------------------------
176 //Theresa Whiting
177 //
178 "twhiting",
179 "twhiting",
180 USRS_SEX_FEMALE,
181 "Theresa",
182 "Whiting",
183 USRS_STATUS_ACTIVE,
184 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
185 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
186 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
187 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
188 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
189 "limeshoes@yahoo.com",
190 "theresa@metzgersaircraft.com",
191 //-------------------------------------------------------------
192 //Daniel Wynja
193 //
194 "dwynja",
195 "dwynja",
196 USRS_SEX_MALE,
197 "Daniel",
198 "Wynja",
199 USRS_STATUS_ACTIVE,
200 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
201 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
202 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
203 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
204 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
205 "danielwynja@hotmail.com",
206 "",
207 //-------------------------------------------------------------
208 //Sun Hee Metzger
209 //
210 "smetzger",
211 "smetzger",
212 USRS_SEX_FEMALE,
213 "Sun Hee",
214 "Metzger",
215 USRS_STATUS_ACTIVE,
216 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
217 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
218 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
219 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
220 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
221 "eric@metzgersaircraft.com",
222 "",
223 //-------------------------------------------------------------
224 //Eric Metzger
225 //
226 "emetzger",
227 "emetzger",
228 USRS_SEX_MALE,
229 "Eric",
230 "Metzger",
231 USRS_STATUS_ACTIVE,
232 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
233 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
234 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
235 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
236 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
237 "eric@metzgersaircraft.com",
238 "",
239 //-------------------------------------------------------------
240 //Nicki MacDonald
241 //
242 "nmacdona",
243 "nmacdona",
244 USRS_SEX_FEMALE,
245 "Nicki",
246 "MacDonald",
247 USRS_STATUS_ACTIVE,
248 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
249 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
250 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
251 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
252 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
253 "nicki@metzgersaircraft.com",
254 "",
255 //-------------------------------------------------------------
256 //Josh Hodge
257 //
258 "jhodge",
259 "jhodge",
260 USRS_SEX_MALE,
261 "Josh",
262 "Hodge",
263 USRS_STATUS_ACTIVE,
264 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
265 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
266 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
267 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
268 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
269 "bcbruin26@aol.com",
270 "10jrhodge@alma.edu",
271 //-------------------------------------------------------------
272 //Peter Ferencz
273 //
274 "pferencz",
275 "pferencz",
276 USRS_SEX_MALE,
277 "Peter",
278 "Ferencz",
279 USRS_STATUS_ACTIVE,
280 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
281 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
282 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
283 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
284 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
285 "",
286 "",
287 //-------------------------------------------------------------
288 //Michael Butson
289 //
290 "mbutson",
291 "mbutson",
292 USRS_SEX_MALE,
293 "Michael",
294 "Butson",
295 USRS_STATUS_ACTIVE,
296 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
297 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
298 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
299 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
300 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
301 "",
302 "",
303 //-------------------------------------------------------------
304 //Bob Buttrick
305 //
306 "bbuttrick",
307 "bbuttrick",
308 USRS_SEX_MALE,
309 "Bob",
310 "Buttrick",
311 USRS_STATUS_ACTIVE,
312 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
313 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
314 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
315 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
316 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
317 "pyro_2232@hotmail.com",
318 "",
319 //-------------------------------------------------------------
320 //Sean Ferencz
321 //
322 "sferencz",
323 "sferencz",
324 USRS_SEX_MALE,
325 "Sean",
326 "Ferencz",
327 USRS_STATUS_ACTIVE,
328 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
329 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
330 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
331 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
332 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
333 "",
334 "",
335 //-------------------------------------------------------------
336 //David Ashley
337 //
338 "dashley",
339 "dashley",
340 USRS_SEX_MALE,
341 "David",
342 "Ashley",
343 USRS_STATUS_ACTIVE,
344 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
345 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
346 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
347 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
348 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
349 "dtashley@aol.com",
350 "dta@e3ft.com",
351 //-------------------------------------------------------------
352 //Barry Bruns
353 //
354 "bbruns",
355 "bbruns",
356 USRS_SEX_MALE,
357 "Barry",
358 "Bruns",
359 USRS_STATUS_ACTIVE,
360 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
361 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
362 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
363 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
364 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
365 "bbruns6831@aol.com",
366 "",
367 //-------------------------------------------------------------
368 //Noah Belcher
369 //
370 "nbelcher",
371 "nbelcher",
372 USRS_SEX_MALE,
373 "Noah",
374 "Belcher",
375 USRS_STATUS_ACTIVE,
376 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
377 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
378 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
379 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
380 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
381 "",
382 "",
383 //-------------------------------------------------------------
384 //Erv Brinker
385 //
386 "ebrinker",
387 "ebrinker",
388 USRS_SEX_MALE,
389 "Erv",
390 "Brinker",
391 USRS_STATUS_ACTIVE,
392 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
393 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
394 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
395 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
396 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
397 "erv@summitpointe.org",
398 "",
399 //-------------------------------------------------------------
400 //Doug Motts
401 //
402 "dmotts",
403 "dmotts",
404 USRS_SEX_MALE,
405 "Doug",
406 "Motts",
407 USRS_STATUS_ACTIVE,
408 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
409 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
410 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
411 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
412 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
413 "drmotts@comcast.net",
414 "dmotts@cequentgroup.com",
415 //-------------------------------------------------------------
416 //Candice Young
417 //
418 "cyoung",
419 "cyoung",
420 USRS_SEX_FEMALE,
421 "Candice",
422 "Young",
423 USRS_STATUS_ACTIVE,
424 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
425 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
426 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
427 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
428 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
429 "young.candice@gmail.com",
430 "",
431 //-------------------------------------------------------------
432 //Jason Duca
433 //
434 "jduca",
435 "jduca",
436 USRS_SEX_MALE,
437 "Jason",
438 "Duca",
439 USRS_STATUS_ACTIVE,
440 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
441 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
442 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
443 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
444 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
445 "jason.duca@wmich.edu",
446 "duca47@hotmail.com",
447 //-------------------------------------------------------------
448 //Keith Rhoades
449 //
450 "krhoades",
451 "krhoades",
452 USRS_SEX_MALE,
453 "Keith",
454 "Rhoades",
455 USRS_STATUS_ACTIVE,
456 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
457 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
458 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
459 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
460 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
461 "keith.rhoades@comcast.net",
462 "",
463 //-------------------------------------------------------------
464 //Marilyn Ashley
465 //
466 "mashley2",
467 "mashley2",
468 USRS_SEX_FEMALE,
469 "Marilyn",
470 "Ashley",
471 USRS_STATUS_ACTIVE,
472 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
473 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
474 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
475 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
476 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
477 "mashley2@aol.com",
478 "",
479 //-------------------------------------------------------------
480 //Ed Shumway
481 //
482 "eshumway",
483 "eshumway",
484 USRS_SEX_MALE,
485 "Ed",
486 "Shumway",
487 USRS_STATUS_ACTIVE,
488 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
489 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
490 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
491 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
492 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
493 "shumwaypopcorn@aol.com",
494 "",
495 //-------------------------------------------------------------
496 //Pat Traster
497 //
498 "ptraster",
499 "ptraster",
500 USRS_SEX_MALE,
501 "Pat",
502 "Traster",
503 USRS_STATUS_ACTIVE,
504 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
505 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
506 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
507 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
508 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
509 "trasterp@calhounisd.org",
510 "",
511 //-------------------------------------------------------------
512 //Rob Williams
513 //
514 "rwilliams",
515 "rwilliams",
516 USRS_SEX_MALE,
517 "Rob",
518 "Williams",
519 USRS_STATUS_ACTIVE,
520 "\\canviewuserslist=\"\"\\canviewuserinfo=\"\"\\canedituserinfo=\"\"\\canresetuserpasswords=\"\"" .
521 "\\candeleteusers=\"\"\\canaddusers=\"\"\\canviewforeignresvexistence=\"\"" .
522 "\\canviewforeignresvdetails=\"\"\\canmodifyforeignresvlesspriv=\"\"" .
523 "\\canmodifyforeignresvpeerpriv=\"\"\\canmodifyforeignresvmorepriv=\"\"\\canviewdbstats=\"\"" .
524 "\\canviewlogentries=\"\"\\canvieweditresources=\"\"",
525 "",
526 "",
527 //-------------------------------------------------------------
528 //Unprivileged User
529 //
530 "uprivuser",
531 "uprivuser",
532 USRS_SEX_MALE,
533 "Unprivileged",
534 "User",
535 USRS_STATUS_ACTIVE,
536 "",
537 "",
538 "",
539 );
540
541 $n = count($lut);
542 for ($i=0; $i<$n; $i+=9)
543 {
544 //Add a random number of users to the database.
545 add_random_users();
546
547 $v["userid"] = $lut[$i];
548 $v["pwhash"] = PASSWD_stored_hash_gen($lut[$i+1]);
549 $v["sex"] = $lut[$i+2];
550 $v["fname"] = $lut[$i+3];
551 $v["lname"] = $lut[$i+4];
552 $v["status"] = $lut[$i+5];
553 $v["perm"] = $lut[$i+6];
554 $v["em1"] = $lut[$i+7];
555 $v["em2"] = $lut[$i+8];
556
557 $trash = rand(0,2);
558 if ($trash == 0)
559 $v["schedalonerscs"] = ",1,2,5,9,";
560 else if ($trash == 1)
561 $v["schedalonerscs"] = ",3,2,4,";
562 else
563 $v["schedalonerscs"] = "";
564
565
566 $v["crmodsguid"] = SGUID_sguid();
567
568 echo "Making call to add user \"" . $v["userid"] . "\".\n";
569
570 USRS_record_add_modify("A", $v, $result_code_out, $errors_out, $warnings_out);
571
572 if ($result_code_out == 0)
573 echo "Return value was 0, indicating an error.\n";
574 else
575 echo "Return value was " . $result_code_out . ".\n";
576 unset($v);
577 }
578 }
579 //
580 //--------------------------------------------------------------------------------
581 //
582 function populate_rscs_table()
583 {
584 global $GLOBAL_dbhandle;
585
586 $lut = array(
587 //-------------------------------------------------------------
588 //N30348 J4 Cub Coupe
589 //
590 RSCS_TYPE_AIRCRAFT,
591 RSCS_STATUS_ONLINE,
592 5,
593 "NC30348 J4 Cub Coupe",
594 "NC30348",
595 "NC30348",
596 "",
597 //-------------------------------------------------------------
598 //N52341 Cessna 172P
599 //
600 RSCS_TYPE_AIRCRAFT,
601 RSCS_STATUS_ONLINE,
602 10,
603 "N52341 Cessna 172P",
604 "N52341",
605 "N52341",
606 "",
607 //-------------------------------------------------------------
608 //N6258K Cessna 172P
609 //
610 RSCS_TYPE_AIRCRAFT,
611 RSCS_STATUS_ONLINE,
612 15,
613 "N6258K Cessna 172P",
614 "N6258K",
615 "N6258K",
616 "",
617 //-------------------------------------------------------------
618 //N3024S Piper Warrior
619 //
620 RSCS_TYPE_AIRCRAFT,
621 RSCS_STATUS_ONLINE,
622 20,
623 "N3024S Piper Warrior",
624 "N3024S",
625 "N3024S",
626 "",
627 //-------------------------------------------------------------
628 //N2009Y Beechcraft Duchess
629 //
630 RSCS_TYPE_AIRCRAFT,
631 RSCS_STATUS_ONLINE,
632 25,
633 "N2009Y Beechcraft Duchess",
634 "N2009Y",
635 "N2009Y",
636 "",
637 //-------------------------------------------------------------
638 //Barry Bruns
639 //
640 RSCS_TYPE_FLIGHTINSTRUCTOR,
641 RSCS_STATUS_ONLINE,
642 100,
643 "Bruns, Barry",
644 "B. Bruns",
645 "B.B.",
646 "bbruns",
647 //-------------------------------------------------------------
648 //Ed Shumway
649 //
650 RSCS_TYPE_FLIGHTINSTRUCTOR,
651 RSCS_STATUS_ONLINE,
652 110,
653 "Shumway, Ed",
654 "E. Shumway",
655 "E.S.",
656 "eshumway",
657 //-------------------------------------------------------------
658 //Pat Traster
659 //
660 RSCS_TYPE_FLIGHTINSTRUCTOR,
661 RSCS_STATUS_ONLINE,
662 112,
663 "Traster, Pat",
664 "P. Traster",
665 "P.T.",
666 "ptraster",
667 //-------------------------------------------------------------
668 //Theresa Whiting
669 //
670 RSCS_TYPE_FLIGHTINSTRUCTOR,
671 RSCS_STATUS_ONLINE,
672 115,
673 "Whiting, Theresa",
674 "T. Whiting",
675 "T.W.",
676 "twhiting",
677 //-------------------------------------------------------------
678 //Rob Williams
679 //
680 RSCS_TYPE_FLIGHTINSTRUCTOR,
681 RSCS_STATUS_ONLINE,
682 117,
683 "Williams, Rob",
684 "R. Williams",
685 "R.W.",
686 "rwilliams",
687 //-------------------------------------------------------------
688 //Daniel Wynja
689 //
690 RSCS_TYPE_FLIGHTINSTRUCTOR,
691 RSCS_STATUS_ONLINE,
692 120,
693 "Wynja, Daniel",
694 "D. Wynja",
695 "D.W.",
696 "dwynja",
697 //-------------------------------------------------------------
698 //Candice Young
699 //
700 RSCS_TYPE_FLIGHTINSTRUCTOR,
701 RSCS_STATUS_ONLINE,
702 130,
703 "Young, Candice",
704 "C. Young",
705 "C.Y.",
706 "cyoung",
707 //-------------------------------------------------------------
708 );
709
710 $n = count($lut);
711 for ($i=0; $i<$n; $i+=7)
712 {
713 $v["type"] = $lut[$i];
714 $v["status"] = $lut[$i+1];
715 $v["disporder"] = $lut[$i+2];
716 $v["longdesc"] = $lut[$i+3];
717 $v["shortdesc"] = $lut[$i+4];
718 $v["initials"] = $lut[$i+5];
719 $v["usercorres"] = USRS_userid_idx_map($lut[$i+6]);
720 if ($v["usercorres"] === FALSE)
721 $v["usercorres"] = 0;
722 $v["crmodsguid"] = SGUID_sguid();
723
724 echo "Making call to add resource \"" . $v["longdesc"] . "\".\n";
725 $rv = RSCS_insert($v);
726 if ($rv === FALSE)
727 echo "Return value was FALSE.\n";
728 else
729 echo "Return value was " . $rv . ".\n";
730 unset($v);
731 }
732 }
733 //
734 //--------------------------------------------------------------------------------
735 function random_reservation_description($res_no_in)
736 {
737 $lut = array(
738 "RMY->BTL because of my toothache.",
739 "Trip to Coldwater to use the cleaner restrooms.",
740 "Woman-chasing at the beach.",
741 "Man-chasing at the beach.",
742 "I'm going to get my underarms shaved.",
743 "Teaching my cat to fly.",
744 "Teaching my hamster to fly.",
745 "Teaching my dog to fly.",
746 "Circles about a point.",
747 "Squares about a pretty girl.",
748 "My cat will teach me to appreciate mice.",
749 "Ovals about a circle, while programming the GPS."
750 );
751
752 return($lut[rand(0, count($lut)-1)]);
753 }
754 //--------------------------------------------------------------------------------
755 function test_populate_resv_table()
756 {
757 global $GLOBAL_dbhandle;
758 global $GLOBAL_stime_year;
759 global $GLOBAL_stime_month;
760 global $GLOBAL_stime_day;
761 global $GLOBAL_stime_string;
762
763 $make_output = TRUE;
764
765 echo "Adding test reservations.\n";
766
767 //Get the indices corresponding to the complete set of flight instructor resources,
768 //or FALSE if non exist.
769 $fi_indices = RSCS_get_fi_online_idxs();
770 //print_r($fi_indices);
771
772 //Get the indices corresponding to the complete set of aircraft / simulator resources,
773 //or FALSE if non exist.
774 $acftsim_indices = RSCS_get_acftsim_online_idxs();
775 //print_r($acftsim_indices);
776
777 //Get the indices corresponding all active users.
778 $usrs_indices = USRS_get_user_online_idxs();
779
780 //Get the current Unix time.
781 $unix_time_secs = time();
782
783 //Get the lower limit of what we should pick for a date.
784 $lower_limit_secs = $unix_time_secs - (31 * 24 * 3600 * (CONFIG_SCHED_SCHEDACC_PREV_MO+1));
785
786 //Figure out how many seconds should be in the range. This should be kept to a manageable number because
787 //I don't have too much confidence in the rand() function.
788 //
789 $range_secs = (CONFIG_SCHED_SCHEDACC_PREV_MO + CONFIG_SCHED_SCHEDACC_FUTU_MO + 2) * 31 * 24 * 3600;
790
791 for ($test_res_cntr = 0; $test_res_cntr < (7 * 30 * 100); $test_res_cntr++)
792 {
793 echo "Adding test reservation #" . (string)($test_res_cntr+1) . ".\n";
794
795 //Pick a random starting point.
796 $start_secs = $lower_limit_secs + rand(0, $range_secs);
797
798 //Pick a random duration. The distribution should be mostly 1-3 hour reservations with
799 //a small number that can be as long as 1 week.
800 if (rand(0,100) == 0)
801 $duration_secs = rand(1,7*3600*24);
802 else
803 $duration_secs = rand(1,3*3600);
804
805 //Compute the endpoint.
806 $end_secs = $start_secs + $duration_secs;
807
808 //Compute the aircraft start year, month, day, hour, and minute.
809 $acft_start_year = (int) date("Y", $start_secs);
810 $acft_start_month = (int) date("n", $start_secs);
811 $acft_start_day = (int) date("j", $start_secs);
812 $acft_start_hour = (int) date("G", $start_secs);
813 $acft_start_minute = date("i", $start_secs);
814 if ((strlen($acft_start_minute) == 2) && (SubStr($acft_start_minute, 0, 1) == "0"))
815 $acft_start_minute = SubStr($acft_start_minute, 1, 1);
816 $acft_start_minute = (int) $acft_start_minute;
817 if ($acft_start_minute < 30)
818 $acft_start_minute = 0;
819 else
820 $acft_start_minute = 30;
821
822 //Compute the aircraft end year, month, day, hour, and minute.
823 $acft_end_year = (int) date("Y", $end_secs);
824 $acft_end_month = (int) date("n", $end_secs);
825 $acft_end_day = (int) date("j", $end_secs);
826 $acft_end_hour = (int) date("G", $end_secs);
827 $acft_end_minute = date("i", $end_secs);
828 if ((strlen($acft_end_minute) == 2) && (SubStr($acft_end_minute, 0, 1) == "0"))
829 $acft_end_minute = SubStr($acft_end_minute, 1, 1);
830 $acft_end_minute = (int) $acft_end_minute;
831 if ($acft_end_minute < 30)
832 $acft_end_minute = 0;
833 else
834 $acft_end_minute = 30;
835
836 //Write the results
837 echo " "
838 . "Acft "
839 . sprintf("%02d/%02d/%04d %02d:%02d:00", $acft_start_month, $acft_start_day, $acft_start_year, $acft_start_hour, $acft_start_minute)
840 . " - "
841 . sprintf("%02d/%02d/%04d %02d:%02d:00", $acft_end_month, $acft_end_day, $acft_end_year, $acft_end_hour, $acft_end_minute)
842 . "\n";
843
844 //Need to discard any reservations that are of zero duration.
845 if (
846 ($acft_start_year == $acft_end_year)
847 &&
848 ($acft_start_month == $acft_end_month)
849 &&
850 ($acft_start_day == $acft_end_day)
851 &&
852 ($acft_start_hour == $acft_end_hour)
853 &&
854 ($acft_start_minute == $acft_end_minute)
855 )
856 {
857 //The items are identical, need to discard.
858 echo " Start and end times identical--test reservation discarded.\n";
859 }
860 else
861 {
862 //Offset the flight instructor start time and end time by a random amount
863 //and get new times for that.
864 $start_secs = $start_secs - rand(0, 3600 * 2);
865 $end_secs = $end_secs + rand(0, 3600 * 2);
866
867 //Compute the flight instructor start year, month, day, hour, and minute.
868 $finst_start_year = (int) date("Y", $start_secs);
869 $finst_start_month = (int) date("n", $start_secs);
870 $finst_start_day = (int) date("j", $start_secs);
871 $finst_start_hour = (int) date("G", $start_secs);
872 $finst_start_minute = date("i", $start_secs);
873 if ((strlen($finst_start_minute) == 2) && (SubStr($finst_start_minute, 0, 1) == "0"))
874 $finst_start_minute = SubStr($finst_start_minute, 1, 1);
875 $finst_start_minute = (int) $finst_start_minute;
876 if ($finst_start_minute < 30)
877 $finst_start_minute = 0;
878 else
879 $finst_start_minute = 30;
880
881 //Compute the aircraft end year, month, day, hour, and minute.
882 $finst_end_year = (int) date("Y", $end_secs);
883 $finst_end_month = (int) date("n", $end_secs);
884 $finst_end_day = (int) date("j", $end_secs);
885 $finst_end_hour = (int) date("G", $end_secs);
886 $finst_end_minute = date("i", $end_secs);
887 if ((strlen($finst_end_minute) == 2) && (SubStr($finst_end_minute, 0, 1) == "0"))
888 $finst_end_minute = SubStr($finst_end_minute, 1, 1);
889 $finst_end_minute = (int) $finst_end_minute;
890 if ($finst_end_minute < 30)
891 $finst_end_minute = 0;
892 else
893 $finst_end_minute = 30;
894
895 //Write the results
896 echo " "
897 . "Finst "
898 . sprintf("%02d/%02d/%04d %02d:%02d:00", $finst_start_month, $finst_start_day, $finst_start_year, $finst_start_hour, $finst_start_minute)
899 . " - "
900 . sprintf("%02d/%02d/%04d %02d:%02d:00", $finst_end_month, $finst_end_day, $finst_end_year, $finst_end_hour, $finst_end_minute)
901 . "\n";
902
903
904 //Set up for the database commit.
905 //
906 $type = rand(0,2);
907 $crsguid = SGUID_sguid();
908 $createtimest = $GLOBAL_stime_string;
909 $useridx = $usrs_indices[rand(0, count($usrs_indices) - 1)];
910 $alias = 0;
911 if ($fi_indices !== FALSE)
912 {
913 $finstid = $fi_indices[rand(0, count($fi_indices) - 1)];
914 $finsttimestart = "ST"
915 .
916 sprintf("%04d%02d%02d%02d%02d",
917 $finst_start_year,
918 $finst_start_month,
919 $finst_start_day,
920 $finst_start_hour,
921 $finst_start_minute)
922 .
923 "00000000";
924 $finsttimeend = "ST"
925 .
926 sprintf("%04d%02d%02d%02d%02d",
927 $finst_end_year,
928 $finst_end_month,
929 $finst_end_day,
930 $finst_end_hour,
931 $finst_end_minute)
932 .
933 "00000000";
934 }
935 else
936 {
937 $finstid = 0;
938 $finsttimestart = "";
939 $finsttimeend = "";
940 }
941
942 if ($acftsim_indices !== FALSE)
943 {
944 $acftsimid = $acftsim_indices[rand(0, count($acftsim_indices) - 1)];
945 $acftsimtimestart = "ST"
946 .
947 sprintf("%04d%02d%02d%02d%02d",
948 $acft_start_year,
949 $acft_start_month,
950 $acft_start_day,
951 $acft_start_hour,
952 $acft_start_minute)
953 .
954 "00000000";
955 $acftsimtimeend = "ST"
956 .
957 sprintf("%04d%02d%02d%02d%02d",
958 $acft_end_year,
959 $acft_end_month,
960 $acft_end_day,
961 $acft_end_hour,
962 $acft_end_minute)
963 .
964 "00000000";
965 }
966 else
967 {
968 $acftsimid = 0;
969 $acftsimtimestart = "";
970 $acftsimtimeend = "";
971 }
972
973 $usrprivdesc = "";
974 $fboprivdesc = "";
975 $comprivdesc = random_reservation_description($test_res_cntr + 1);
976 $publicdesc = "";
977 $crmodsguid = $crsguid;
978
979 //Randomly blank out reservation components to represent aircraft-only or flight-instructor-only
980 //reservations.
981 if (rand(0,5)==0)
982 {
983 //Kill the flight instructor info. Aircraft-only reservation.
984 $finstid = 0;
985 $finsttimestart = "";
986 $finsttimeend = "";
987 }
988 else if (rand(0,5)==0)
989 {
990 //Kill the aircraft info. Flight-instructor-only reservation.
991 $acftsimid = 0;
992 $acftsimtimestart = "";
993 $acftsimtimeend = "";
994 }
995
996 //Calculate the reservation minimum and maximum.
997 $resvtimestart = "";
998 $resvtimeend = "";
999 if (($acftsimid != 0) && ($finstid != 0))
1000 {
1001 //Both a/c and flight instructor exist. Gotta do some fancy stuff to figure out how to assign.
1002 if (strcmp($finsttimestart, $acftsimtimestart) < 0)
1003 {
1004 $resvtimestart = $finsttimestart;
1005 }
1006 else
1007 {
1008 $resvtimestart = $acftsimtimestart;
1009 }
1010
1011 if (strcmp($finsttimeend, $acftsimtimeend) > 0)
1012 {
1013 $resvtimeend = $finsttimeend;
1014 }
1015 else
1016 {
1017 $resvtimeend = $acftsimtimeend;
1018 }
1019 }
1020 else if ($acftsimid != 0)
1021 {
1022 //Aircraft/simulator, but no flight instructor.
1023 $resvtimestart = $acftsimtimestart;
1024 $resvtimeend = $acftsimtimeend;
1025 }
1026 else if ($finstid != 0)
1027 {
1028 //Flight instructor, but no aircraft/simulator.
1029 $resvtimestart = $finsttimestart;
1030 $resvtimeend = $finsttimeend;
1031 }
1032
1033 //Form the query string.
1034 $query_string = "INSERT INTO resv SET "
1035 .
1036 "type=\"" . mysql_real_escape_string((string)$type, $GLOBAL_dbhandle) . "\", "
1037 .
1038 "crsguid=\"" . mysql_real_escape_string($crsguid, $GLOBAL_dbhandle) . "\", "
1039 .
1040 "createtimest=\"" . mysql_real_escape_string($createtimest, $GLOBAL_dbhandle) . "\", "
1041 .
1042 "useridx=\"" . mysql_real_escape_string((string)$useridx, $GLOBAL_dbhandle) . "\", "
1043 .
1044 "alias=\"" . mysql_real_escape_string((string)$alias, $GLOBAL_dbhandle) . "\", "
1045 .
1046 "finstid=\"" . mysql_real_escape_string((string)$finstid, $GLOBAL_dbhandle) . "\", "
1047 .
1048 "finsttimestart=\"" . mysql_real_escape_string($finsttimestart, $GLOBAL_dbhandle) . "\", "
1049 .
1050 "finsttimeend=\"" . mysql_real_escape_string($finsttimeend, $GLOBAL_dbhandle) . "\", "
1051 .
1052 "acftsimid=\"" . mysql_real_escape_string((string)$acftsimid, $GLOBAL_dbhandle) . "\", "
1053 .
1054 "acftsimtimestart=\"" . mysql_real_escape_string($acftsimtimestart, $GLOBAL_dbhandle) . "\", "
1055 .
1056 "acftsimtimeend=\"" . mysql_real_escape_string($acftsimtimeend, $GLOBAL_dbhandle) . "\", "
1057 .
1058 "resvtimestart=\"" . mysql_real_escape_string($resvtimestart, $GLOBAL_dbhandle) . "\", "
1059 .
1060 "resvtimeend=\"" . mysql_real_escape_string($resvtimeend, $GLOBAL_dbhandle) . "\", "
1061 .
1062 "usrprivdesc=\"" . mysql_real_escape_string($usrprivdesc, $GLOBAL_dbhandle) . "\", "
1063 .
1064 "fboprivdesc=\"" . mysql_real_escape_string($fboprivdesc, $GLOBAL_dbhandle) . "\", "
1065 .
1066 "comprivdesc=\"" . mysql_real_escape_string($comprivdesc, $GLOBAL_dbhandle) . "\", "
1067 .
1068 "publicdesc=\"" . mysql_real_escape_string($publicdesc, $GLOBAL_dbhandle) . "\", "
1069 .
1070 "crmodsguid=\"" . mysql_real_escape_string($crmodsguid, $GLOBAL_dbhandle) . "\""
1071 ;
1072
1073 //echo "\n\n" . $query_string . "\n\n";
1074 //sleep(10);
1075
1076 $result = mysql_query($query_string, $GLOBAL_dbhandle);
1077 }
1078 }
1079 }
1080 //
1081 //--------------------------------------------------------------------------------
1082 //--------------------------------------------------------------------------------
1083 //--------------------------------------------------------------------------------
1084 //------ M A I N S C R I P T ------------------------------------------------
1085 //--------------------------------------------------------------------------------
1086 //--------------------------------------------------------------------------------
1087 //--------------------------------------------------------------------------------
1088 //
1089 //
1090 //This is the list of the database tables. For each one, this script will try to
1091 //trash it if it exists.
1092 //
1093 if ($argc == 1)
1094 {
1095 //The no-parameters case, as expected.
1096 //Set up the global variables.
1097 GLOBAL_init();
1098
1099 $GLOBAL_dbhandle = mysql_connect(CONFIG_MYSQL_SERVER, CONFIG_MYSQL_USERNAME, CONFIG_MYSQL_PASSWORD);
1100 if ($GLOBAL_dbhandle === FALSE)
1101 {
1102 echo "ERROR: Unable to connect and/or authenticate to MySQL database.\n";
1103 exit(1);
1104 }
1105
1106 $result = mysql_select_db(CONFIG_MYSQL_DATABASE, $GLOBAL_dbhandle);
1107 if ($result === FALSE)
1108 {
1109 echo "ERROR: Unable to select MySQL database \"" . CONFIG_MYSQL_DATABASE . "\".\n";
1110 exit(1);
1111 }
1112
1113 hline();
1114
1115 //Populate the usrs table.
1116 populate_usrs_table();
1117 hline();
1118
1119 //Populate the rscs table.
1120 populate_rscs_table();
1121 hline();
1122
1123 //Populate reservations.
1124 test_populate_resv_table();
1125 hline();
1126
1127 //Try to close the database.
1128 $result = mysql_close($GLOBAL_dbhandle);
1129 if ($result === FALSE)
1130 {
1131 echo "ERROR: Unable to close MySQL connection.\n";
1132 exit(1);
1133 }
1134
1135 exit(0);
1136 }
1137 else
1138 {
1139 echo "ERROR: This command accepts no command-line parameters.\n";
1140 exit(1);
1141 }
1142
1143 //If we're here, success. Per the standard Unix way of thinking
1144 //say nothing. Silence means OK.
1145 exit(0);
1146 //
1147 //--------------------------------------------------------------------------------
1148 //End of $RCSfile: dbtestpop.php,v $.
1149 //--------------------------------------------------------------------------------
1150 ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25