#!/usr/bin/php -q BTL because of my toothache.", "Trip to Coldwater to use the cleaner restrooms.", "Woman-chasing at the beach.", "Man-chasing at the beach.", "I'm going to get my underarms shaved.", "Teaching my cat to fly.", "Teaching my hamster to fly.", "Teaching my dog to fly.", "Circles about a point.", "Squares about a pretty girl.", "My cat will teach me to appreciate mice.", "Ovals about a circle, while programming the GPS." ); return($lut[rand(0, count($lut)-1)]); } //-------------------------------------------------------------------------------- function test_populate_resv_table() { global $GLOBAL_dbhandle; global $GLOBAL_stime_year; global $GLOBAL_stime_month; global $GLOBAL_stime_day; global $GLOBAL_stime_string; $make_output = TRUE; echo "Adding test reservations.\n"; //Get the indices corresponding to the complete set of flight instructor resources, //or FALSE if non exist. $fi_indices = RSCS_get_fi_online_idxs(); //print_r($fi_indices); //Get the indices corresponding to the complete set of aircraft / simulator resources, //or FALSE if non exist. $acftsim_indices = RSCS_get_acftsim_online_idxs(); //print_r($acftsim_indices); //Get the indices corresponding all active users. $usrs_indices = USRS_get_user_online_idxs(); //Get the current Unix time. $unix_time_secs = time(); //Get the lower limit of what we should pick for a date. $lower_limit_secs = $unix_time_secs - (31 * 24 * 3600 * (CONFIG_SCHED_SCHEDACC_PREV_MO+1)); //Figure out how many seconds should be in the range. This should be kept to a manageable number because //I don't have too much confidence in the rand() function. // $range_secs = (CONFIG_SCHED_SCHEDACC_PREV_MO + CONFIG_SCHED_SCHEDACC_FUTU_MO + 2) * 31 * 24 * 3600; for ($test_res_cntr = 0; $test_res_cntr < (7 * 30 * 100); $test_res_cntr++) { echo "Adding test reservation #" . (string)($test_res_cntr+1) . ".\n"; //Pick a random starting point. $start_secs = $lower_limit_secs + rand(0, $range_secs); //Pick a random duration. The distribution should be mostly 1-3 hour reservations with //a small number that can be as long as 1 week. if (rand(0,100) == 0) $duration_secs = rand(1,7*3600*24); else $duration_secs = rand(1,3*3600); //Compute the endpoint. $end_secs = $start_secs + $duration_secs; //Compute the aircraft start year, month, day, hour, and minute. $acft_start_year = (int) date("Y", $start_secs); $acft_start_month = (int) date("n", $start_secs); $acft_start_day = (int) date("j", $start_secs); $acft_start_hour = (int) date("G", $start_secs); $acft_start_minute = date("i", $start_secs); if ((strlen($acft_start_minute) == 2) && (SubStr($acft_start_minute, 0, 1) == "0")) $acft_start_minute = SubStr($acft_start_minute, 1, 1); $acft_start_minute = (int) $acft_start_minute; if ($acft_start_minute < 30) $acft_start_minute = 0; else $acft_start_minute = 30; //Compute the aircraft end year, month, day, hour, and minute. $acft_end_year = (int) date("Y", $end_secs); $acft_end_month = (int) date("n", $end_secs); $acft_end_day = (int) date("j", $end_secs); $acft_end_hour = (int) date("G", $end_secs); $acft_end_minute = date("i", $end_secs); if ((strlen($acft_end_minute) == 2) && (SubStr($acft_end_minute, 0, 1) == "0")) $acft_end_minute = SubStr($acft_end_minute, 1, 1); $acft_end_minute = (int) $acft_end_minute; if ($acft_end_minute < 30) $acft_end_minute = 0; else $acft_end_minute = 30; //Write the results echo " " . "Acft " . sprintf("%02d/%02d/%04d %02d:%02d:00", $acft_start_month, $acft_start_day, $acft_start_year, $acft_start_hour, $acft_start_minute) . " - " . sprintf("%02d/%02d/%04d %02d:%02d:00", $acft_end_month, $acft_end_day, $acft_end_year, $acft_end_hour, $acft_end_minute) . "\n"; //Need to discard any reservations that are of zero duration. if ( ($acft_start_year == $acft_end_year) && ($acft_start_month == $acft_end_month) && ($acft_start_day == $acft_end_day) && ($acft_start_hour == $acft_end_hour) && ($acft_start_minute == $acft_end_minute) ) { //The items are identical, need to discard. echo " Start and end times identical--test reservation discarded.\n"; } else { //Offset the flight instructor start time and end time by a random amount //and get new times for that. $start_secs = $start_secs - rand(0, 3600 * 2); $end_secs = $end_secs + rand(0, 3600 * 2); //Compute the flight instructor start year, month, day, hour, and minute. $finst_start_year = (int) date("Y", $start_secs); $finst_start_month = (int) date("n", $start_secs); $finst_start_day = (int) date("j", $start_secs); $finst_start_hour = (int) date("G", $start_secs); $finst_start_minute = date("i", $start_secs); if ((strlen($finst_start_minute) == 2) && (SubStr($finst_start_minute, 0, 1) == "0")) $finst_start_minute = SubStr($finst_start_minute, 1, 1); $finst_start_minute = (int) $finst_start_minute; if ($finst_start_minute < 30) $finst_start_minute = 0; else $finst_start_minute = 30; //Compute the aircraft end year, month, day, hour, and minute. $finst_end_year = (int) date("Y", $end_secs); $finst_end_month = (int) date("n", $end_secs); $finst_end_day = (int) date("j", $end_secs); $finst_end_hour = (int) date("G", $end_secs); $finst_end_minute = date("i", $end_secs); if ((strlen($finst_end_minute) == 2) && (SubStr($finst_end_minute, 0, 1) == "0")) $finst_end_minute = SubStr($finst_end_minute, 1, 1); $finst_end_minute = (int) $finst_end_minute; if ($finst_end_minute < 30) $finst_end_minute = 0; else $finst_end_minute = 30; //Write the results echo " " . "Finst " . sprintf("%02d/%02d/%04d %02d:%02d:00", $finst_start_month, $finst_start_day, $finst_start_year, $finst_start_hour, $finst_start_minute) . " - " . sprintf("%02d/%02d/%04d %02d:%02d:00", $finst_end_month, $finst_end_day, $finst_end_year, $finst_end_hour, $finst_end_minute) . "\n"; //Set up for the database commit. // $type = rand(0,2); $crsguid = SGUID_sguid(); $createtimest = $GLOBAL_stime_string; $useridx = $usrs_indices[rand(0, count($usrs_indices) - 1)]; $alias = 0; if ($fi_indices !== FALSE) { $finstid = $fi_indices[rand(0, count($fi_indices) - 1)]; $finsttimestart = "ST" . sprintf("%04d%02d%02d%02d%02d", $finst_start_year, $finst_start_month, $finst_start_day, $finst_start_hour, $finst_start_minute) . "00000000"; $finsttimeend = "ST" . sprintf("%04d%02d%02d%02d%02d", $finst_end_year, $finst_end_month, $finst_end_day, $finst_end_hour, $finst_end_minute) . "00000000"; } else { $finstid = 0; $finsttimestart = ""; $finsttimeend = ""; } if ($acftsim_indices !== FALSE) { $acftsimid = $acftsim_indices[rand(0, count($acftsim_indices) - 1)]; $acftsimtimestart = "ST" . sprintf("%04d%02d%02d%02d%02d", $acft_start_year, $acft_start_month, $acft_start_day, $acft_start_hour, $acft_start_minute) . "00000000"; $acftsimtimeend = "ST" . sprintf("%04d%02d%02d%02d%02d", $acft_end_year, $acft_end_month, $acft_end_day, $acft_end_hour, $acft_end_minute) . "00000000"; } else { $acftsimid = 0; $acftsimtimestart = ""; $acftsimtimeend = ""; } $usrprivdesc = ""; $fboprivdesc = ""; $comprivdesc = random_reservation_description($test_res_cntr + 1); $publicdesc = ""; $crmodsguid = $crsguid; //Randomly blank out reservation components to represent aircraft-only or flight-instructor-only //reservations. if (rand(0,5)==0) { //Kill the flight instructor info. Aircraft-only reservation. $finstid = 0; $finsttimestart = ""; $finsttimeend = ""; } else if (rand(0,5)==0) { //Kill the aircraft info. Flight-instructor-only reservation. $acftsimid = 0; $acftsimtimestart = ""; $acftsimtimeend = ""; } //Calculate the reservation minimum and maximum. $resvtimestart = ""; $resvtimeend = ""; if (($acftsimid != 0) && ($finstid != 0)) { //Both a/c and flight instructor exist. Gotta do some fancy stuff to figure out how to assign. if (strcmp($finsttimestart, $acftsimtimestart) < 0) { $resvtimestart = $finsttimestart; } else { $resvtimestart = $acftsimtimestart; } if (strcmp($finsttimeend, $acftsimtimeend) > 0) { $resvtimeend = $finsttimeend; } else { $resvtimeend = $acftsimtimeend; } } else if ($acftsimid != 0) { //Aircraft/simulator, but no flight instructor. $resvtimestart = $acftsimtimestart; $resvtimeend = $acftsimtimeend; } else if ($finstid != 0) { //Flight instructor, but no aircraft/simulator. $resvtimestart = $finsttimestart; $resvtimeend = $finsttimeend; } //Form the query string. $query_string = "INSERT INTO resv SET " . "type=\"" . mysql_real_escape_string((string)$type, $GLOBAL_dbhandle) . "\", " . "crsguid=\"" . mysql_real_escape_string($crsguid, $GLOBAL_dbhandle) . "\", " . "createtimest=\"" . mysql_real_escape_string($createtimest, $GLOBAL_dbhandle) . "\", " . "useridx=\"" . mysql_real_escape_string((string)$useridx, $GLOBAL_dbhandle) . "\", " . "alias=\"" . mysql_real_escape_string((string)$alias, $GLOBAL_dbhandle) . "\", " . "finstid=\"" . mysql_real_escape_string((string)$finstid, $GLOBAL_dbhandle) . "\", " . "finsttimestart=\"" . mysql_real_escape_string($finsttimestart, $GLOBAL_dbhandle) . "\", " . "finsttimeend=\"" . mysql_real_escape_string($finsttimeend, $GLOBAL_dbhandle) . "\", " . "acftsimid=\"" . mysql_real_escape_string((string)$acftsimid, $GLOBAL_dbhandle) . "\", " . "acftsimtimestart=\"" . mysql_real_escape_string($acftsimtimestart, $GLOBAL_dbhandle) . "\", " . "acftsimtimeend=\"" . mysql_real_escape_string($acftsimtimeend, $GLOBAL_dbhandle) . "\", " . "resvtimestart=\"" . mysql_real_escape_string($resvtimestart, $GLOBAL_dbhandle) . "\", " . "resvtimeend=\"" . mysql_real_escape_string($resvtimeend, $GLOBAL_dbhandle) . "\", " . "usrprivdesc=\"" . mysql_real_escape_string($usrprivdesc, $GLOBAL_dbhandle) . "\", " . "fboprivdesc=\"" . mysql_real_escape_string($fboprivdesc, $GLOBAL_dbhandle) . "\", " . "comprivdesc=\"" . mysql_real_escape_string($comprivdesc, $GLOBAL_dbhandle) . "\", " . "publicdesc=\"" . mysql_real_escape_string($publicdesc, $GLOBAL_dbhandle) . "\", " . "crmodsguid=\"" . mysql_real_escape_string($crmodsguid, $GLOBAL_dbhandle) . "\"" ; //echo "\n\n" . $query_string . "\n\n"; //sleep(10); $result = mysql_query($query_string, $GLOBAL_dbhandle); } } } // //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- //------ M A I N S C R I P T ------------------------------------------------ //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- // // //This is the list of the database tables. For each one, this script will try to //trash it if it exists. // if ($argc == 1) { //The no-parameters case, as expected. //Set up the global variables. GLOBAL_init(); $GLOBAL_dbhandle = mysql_connect(CONFIG_MYSQL_SERVER, CONFIG_MYSQL_USERNAME, CONFIG_MYSQL_PASSWORD); if ($GLOBAL_dbhandle === FALSE) { echo "ERROR: Unable to connect and/or authenticate to MySQL database.\n"; exit(1); } $result = mysql_select_db(CONFIG_MYSQL_DATABASE, $GLOBAL_dbhandle); if ($result === FALSE) { echo "ERROR: Unable to select MySQL database \"" . CONFIG_MYSQL_DATABASE . "\".\n"; exit(1); } hline(); //Populate the usrs table. populate_usrs_table(); hline(); //Populate the rscs table. populate_rscs_table(); hline(); //Populate reservations. test_populate_resv_table(); hline(); //Try to close the database. $result = mysql_close($GLOBAL_dbhandle); if ($result === FALSE) { echo "ERROR: Unable to close MySQL connection.\n"; exit(1); } exit(0); } else { echo "ERROR: This command accepts no command-line parameters.\n"; exit(1); } //If we're here, success. Per the standard Unix way of thinking //say nothing. Silence means OK. exit(0); // //-------------------------------------------------------------------------------- //End of $RCSfile: dbtestpop.php,v $. //-------------------------------------------------------------------------------- ?>