// // Note that all db functions assume that the most recent query was // against the correct mysql connect link // get_pattern($pid) -- query the database for all known about the given pattern. // Returns an array of the composite results of various queries // function get_pattern($pid) { // validate input if ($pid <= 0) { die("get_pattern: $pid is " . $pid); } // do the query for the pattern $pres = mysql_query("SELECT * FROM pattern WHERE patternid = '$pid' AND deleted=0"); if (!$pres) { die("SELECT pattern: " . mysql_error()); } // do the query for the aliases $ares = mysql_query("SELECT alias FROM patternalias WHERE patternid = '$pid'"); if (!$ares) { die("SELECT aliases: " . mysql_error()); } // do the query(s) for the related patterns $rres = mysql_query("SELECT pattern.patternid,pattern.name,howrelated FROM relatedpattern,pattern WHERE relatedpattern.patternid = '$pid' AND pattern.patternid = relatedpattern.relation"); if (!$rres) { die("SELECT related patterns: " . mysql_error()); } return array($pres,$ares,$rres); } // get_patternid - uses $pname to find the pattern. Searches // patternalias as well as pattern tables. Returns patternid (or -1). // function get_patternid($pname) { //try the alias table first reset_juggle_db(); $gp_aresult = mysql_query("SELECT patternid FROM patternalias WHERE alias='" . mysql_escape_string($pname) . "'"); if (! $gp_aresult) { die("SELECT 1 in get_patternid(): " . mysql_error()); } if (mysql_num_rows($gp_aresult) >= 1) { // someday, 0 or 1 for sure list($patternid) = mysql_fetch_array($gp_aresult); } else { // no joy in aliases, try the pattern table $qs = "SELECT patternid FROM pattern WHERE name='" . mysql_escape_string($pname) . "' AND deleted=0"; $gp_presult = mysql_query($qs); if (! $gp_presult) { die("SELECT 2 in get_patternid(): " . mysql_error() . "
\n" . $qs); } if (mysql_num_rows($gp_presult) >= 1) { list($patternid) = mysql_fetch_array($gp_presult); } else $patternid = -1; // not found } return $patternid; } // $pattern_names = get_pattern_names() // // This function will return an array with each pattern name/alias // function get_pattern_names() { $gpn_resnames = mysql_query("SELECT name, patternid FROM pattern WHERE deleted=0 ORDER BY passers, clubs, name") or die("SELECT FROM pattern failed: " . mysql_error()); // insert the retrieved pattern names into $tmp[] array while ($gpn_prow = mysql_fetch_array($gpn_resnames)) { $tmp[] = $gpn_prow["name"]; // add this pattern // now look for aliases of it $gpn_pid = $gpn_prow["patternid"]; $gpn_alinames = mysql_query("SELECT alias FROM patternalias WHERE patternid = $gpn_pid"); // insert any aliases which were found while (list($gpn_alias) = mysql_fetch_row($gpn_alinames)) { $tmp[] = " ".$gpn_alias; // add this alias } } // sort($tmp, SORT_STRING); $patternnames = $tmp; // make a clean copy for returning return $patternnames; } // gen_pattern_select($selectedName, $showaliases) // // This routine will output the \n", $lbl, $lbl); $oldclubs = $gpn_prow["clubs"]; $oldpassers = $gpn_prow["passers"]; } printf(" \n", $gpn_prow["patternid"], $gpn_prow["name"]); if ($showaliases) { // now look for aliases of it $gpn_pid = $gpn_prow["patternid"]; $gpn_alinames = mysql_query("SELECT alias FROM patternalias WHERE patternid = $gpn_pid"); // insert any aliases which were found while (list($gpn_alias) = mysql_fetch_row($gpn_alinames)) { printf(" \n", $gpn_prow["patternid"],$gpn_alias); // add this alias } } } printf("\n\n\n"); } // // This routine will return the aliases associated with a pattern // // $patternID is the pattern to examine // // Returns array containing alias names // function get_aliases($patternID) { $ga_aliasnames = mysql_query("SELECT alias FROM patternalias WHERE patternid = $patternID") or die("SELECT FROM alias $patternID failed: " . mysql_error()); $acount = 0; $aliases = array(); while (list($ga_alias) = mysql_fetch_row($ga_aliasnames)) { $aliases[$acount++] = $ga_alias; } return $aliases; } // $name = get_pattern_name($pid); // // This function will return the primary name for the give pattern // function get_pattern_name($pid) { $qres = mysql_query("SELECT name FROM pattern WHERE patternid=$pid AND deleted = 0") or die("SELECT of pattern $pid failed: " . mysql_error()); if (mysql_num_rows($qres) != 1) { return NULL; } list($name) = mysql_fetch_array($qres); return $name; } // placeholder for when we decide what to do about access function authenticate_juggle_user($type) { return; // short-circuit // if user isn't authenticated yet, then challenge him if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="Gnerds Juggling"'); header('HTTP/1.0 401 Unauthorized'); echo 'Please contact management by email to update/add juggling patterns'; exit; } else { // authenticate user -- verify password, unset PHP_AUTH_USER if failed, etc. } } // genheader($title_string); // takes title string and generates the html/head/title/body tags // for the beginning of a page's output // Note that 'lightYellow' is darker than the yellow used in the gif function genheader($title) { echo ' HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <?echo $title;?>

Aerial Mirage Jugglers

%s", $title); ?>
} // $str = cvt_size($number) // // Take a number and stick in commas every three places. This is an // anglicism, if not just a USism. Is there a locale specification for // this?? And a conversion?? // function cvt_size($number) { $str = "" . $number; // make sure we are working on a string $len = strlen($str); // how many commas needed to divide up this $commacount = ($len-1)/3; // how many chars before first comma? 0 case means exactly 3 $commaextra = $len%3; if ($commaextra == 0) $commaextra = 3; // need any commas? if ($commacount < 1) { return $str; // No, OK as is } // initialize the return string with any pre-comma necessities $returnstring = substr($str, 0, $commaextra); $strindex = $commaextra; while ($commacount-- >= 1) { $returnstring .= "," . substr($str, $strindex, 3); $strindex += 3; } return $returnstring; } // Leave this stuff to fester. For now, the app will only be // running where magic_quotes_gpc is turned off. /* From us.php.net: ian at NO_SPAM dot verteron dot net 01-Jan-2003 12:21 A nice solution is to use a reference if gpc_magic_quotes are off, so the code will be nice and fast when they are (no array copy will be performed) - and since this is now the default, only legacy code will be slow - and removes the problem commented on above concerning how other scripts will behave if you modify $_GET, $_POST and so on. I'll leave the reader to sort out deep traversal to handle PHP arrays and so on: */ function & gpc_quotes(&$array) { if(get_magic_quotes_gpc()) { $result = array(); foreach($array as $key => $val) { $result[$key] = stripslashes($array); } return $result; } else { return $array; } } /* Usage: $get = & gpc_quotes($_GET); $post = & gpc_quotes($_POST); I now use $get to actually access vars, which will just be a reference if magic quotes are off, but a whole new array if they're on. I won't be writing to this array, because results would be unpredictable - but a tidy script shouldn't be writing to $_GET, $_POST anyway. */ /* davidbaker84 at hotmail dot com 27-Aug-2003 07:31 Here's yet another way of making code that will work regardless of whether gpc_magic_quotes is on or off: */ if (get_magic_quotes_gpc()) { function maybeaddslashes(&$inthing) { // return $inthing; } function maybestripslashes(&$inthing) { if (is_array($inthing)){ foreach ($inthing as $element) { $element = stripslashes($element); } } else { $inthing = stripslashes($inthing); } // return $inthing; } } else { function maybeaddslashes(&$inthing) { if (is_array($inthing)) { foreach ($inthing as $element) { $element = addslashes($element); } } else { $inthing = addslashes($inthing); } // return $inthing; } function maybestripslashes(&$inthing) { // return $inthing; } } ?>