\n" ); } function printem( $email ) // Duh { print( "$email" ); } function swap( &$v1, &$v2 ) // Duh { $tmp = $v1; $v1 = $v2; $v2 = $tmp; } function listbox( $name, $options, $selected, $method="straight", $onchange="", $pmethod="print", $multiple=FALSE, $size="" ) // prints out a listbox form element using $name as the name // and hash array $options for they value and associated labels // and selects the hash value indicated by $selected // $method is either "hash" or "straight" hash indicates $options // is a hash array and straight uses the $value for both listbox values // $pmethod determines whether the function prints the box or returns the html for it { if( $multiple ) $multiple = "multiple"; else $multiple = ""; $p = ($pmethod == "print"); if($p) println(""; switch( $method ) { case "hash": foreach( $options as $key=>$value ) { if( $key == $selected || $value == $selected ) { if($p) println(" "); $retval .= " "; } else { if($p) println(" "); $retval .= " "; } } break; case "straight": foreach( $options as $key=>$value ) { if( $key == $selected || $value == $selected ) { if($p) println(" "); $retval .= " "; } else { if($p) println(" "); $retval .= " "; } } break; case "index": foreach( $options as $key=>$value ) { if( $key == $selected || $value == $selected ) { if($p) println(" "); $retval .= " "; } else { if($p) println(" "); $retval .= " "; } } break; } if($p) println("" ); $retval .= ""; if( !$p ) return( $retval ); } function redirect( $url, $delay=0 ) // Redirects a page { print( "" ); } function getFileByLine( $file ) // Opens the specified file and returns an array containing // each line of the file in consecutive order { if( file_exists( $file ) ) { return file( $file ); } else { print( "Error: file not found
\n" ); } } function alert( $msg ) { $msg = addslashes( $msg ); $msg = str_replace( "^", "\\n", $msg ); print("\n"); } function isIn( $item, $list ) { if( $list ) { return( in_array( $item, $list ) ); } return FALSE; } function whereIs( $item, $list ) { if( $list ) { return( array_search( $item, $list ) ); } return FALSE; } function leapyear( $yr ) // Receives year // Returns TRUE or FALSE if $yr is or is not a leapyear { if( ($yr % 4) == 0 && ($yr % 100) != 0 ) { return 1; } else { return 0; } } function prevDay( $date, $reps=1 ) // Receives calendar day in YYYY-mm-dd format // Returns previous calendar day in YYYY-mm-dd format { list( $yr, $mn, $dy ) = split( "-", $date ); $yr *= 1; $mn *= 1; $dy *= 1; for( $i = $reps; $i; $i-- ) { if( $dy > 1 ) { $dy--; } else { if( $mn == 1 ) { $mn = 12; $yr--; $dy = 31; } else { $mn--; switch( $mn ) { case 2: if( leapyear( $yr ) ) { $dy = 29; } else { $dy = 28; } break; case 4: case 6: case 9: case 11: $dy = 30; break; default: $dy = 31; break; } } } } if( $dy < 10 && $mn < 10 ) { return $yr."-0".$mn."-0".$dy; } elseif( $mn < 10 ) { return $yr."-0".$mn."-".$dy; } elseif( $dy < 10 ) { return $yr."-".$mn."-0".$dy; } else { return $yr."-".$mn."-".$dy; } } function nextDay( $date, $reps=1 ) // Receives calendar day in YYYY-mm-dd format // Returns next calendar day in YYYY-mm-dd format { list( $yr, $mn, $dy ) = split( "-", $date ); $yr *= 1; $mn *= 1; $dy *= 1; for( $i = $reps; $i; $i-- ) { if( $mn == 12 && $dy == 31 ) { $yr++; $mn = 1; $dy = 1; } else { switch( $mn ) { case 2: if( ($dy == 28 && !leapyear( $yr )) || $dy == 29 ) { $dy = 1; $mn++; } else { $dy++; } break; case 4: case 6: case 9: case 11: if( $dy == 30 ) { $dy = 1; $mn++; } else { $dy++; } break; default: if( $dy == 31 ) { $dy = 1; $mn++; } else { $dy++; } break; } } } if( $dy < 10 && $mn < 10 ) { return $yr."-0".$mn."-0".$dy; } elseif( $mn < 10 ) { return $yr."-0".$mn."-".$dy; } elseif( $dy < 10 ) { return $yr."-".$mn."-0".$dy; } else { return $yr."-".$mn."-".$dy; } } function prevMonth( $date, $reps=1 ) // Receives calendar day in YYYY-mm-dd format // Returns previous calendar day in YYYY-mm-dd format { list( $yr, $mn, $dy ) = split( "-", $date ); $yr *= 1; $mn *= 1; $dy *= 1; for( $i = $reps; $i; $i-- ) { if( $mn == 1 ) { $mn = 12; $yr--; } else { $mn--; } } if( $dy < 10 && $mn < 10 ) { return $yr."-0".$mn."-0".$dy; } elseif( $mn < 10 ) { return $yr."-0".$mn."-".$dy; } elseif( $dy < 10 ) { return $yr."-".$mn."-0".$dy; } else { return $yr."-".$mn."-".$dy; } } function nextMonth( $date, $reps=1 ) // Receives calendar day in YYYY-mm-dd format // Returns next calendar day in YYYY-mm-dd format { list( $yr, $mn, $dy ) = split( "-", $date ); $yr *= 1; $mn *= 1; $dy *= 1; for( $i = $reps; $i; $i-- ) { if( $mn == 12 ) { $yr++; $mn = 1; } else { $mn++; } } if( $dy < 10 && $mn < 10 ) { return $yr."-0".$mn."-0".$dy; } elseif( $mn < 10 ) { return $yr."-0".$mn."-".$dy; } elseif( $dy < 10 ) { return $yr."-".$mn."-0".$dy; } else { return $yr."-".$mn."-".$dy; } } function fDate( $FMT_DATE, $mysqldate, $print=FALSE ) { list( $yr, $mn, $dy ) = split( "-", $mysqldate ); $mysqldate = date( $FMT_DATE, mktime( 0, 0, 0, $mn, $dy, $yr ) ); if( $print ) print( $mysqldate ); else return( $mysqldate ); } function num_suffix( $num ) { if( $num == 0 || $num == "" ) return( "" ); elseif( $num == 11 || $num == 12 || $num == 13 ) return( "th" ); $digit = substr( $num, strlen($num)-1, 1 ); switch( $digit ) { case 0: case 4: case 5: case 6: case 7: case 8: case 9: return( "th" ); case 1: return( "st" ); case 2: return( "nd" ); case 3: return( "rd" ); default: return( "" ); } } function floodprotect( $floodtime ) // Receives a minimum time to compare with the last time function was called // Returns FALSE if the function was previously called within that time, // TRUE if it has been longer than the specified time. { $fhand = fopen( "floodprotect.txt", "r" ); if( $fhand ) { $ftime = fgets( $fhand ); fclose( $fhand ); } $tnow = time(); if( $tnow - $ftime < $floodtime ) { return FALSE; } else { $fhand = fopen( "floodprotect.txt", "w" ); fputs( $tnow ); fclose( $fhand ); return TRUE; } } function parseEmails( $str ) // Receives a string containing one or more email addresses // Returns an array with one email address in each element { $str = strtolower( $str ); $str = str_replace( ";", "|", $str ); $str = str_replace( ",", "|", $str ); $str = str_replace( "&", "|", $str ); $str = str_replace( "<", "", $str ); $str = str_replace( ">", "", $str ); $str = str_replace( " ", "", $str ); $str = ereg_replace( "\n", "", $str ); $str = ereg_replace( "\r", "", $str ); $str = ereg_replace( "\t", "", $str ); $emails = split( "\|", $str ); for( $i = 0; $i < count( $emails ); $i++ ) { if( strstr($emails[$i], "@") == "" ) { $emails[$i] = ""; } } $exist = FALSE; for( $i = 0; $i < count( $emails ); $i++ ) { if( $emails[$i] != "" ) { $exist = TRUE; } } if( !$exist ) { unset( $emails ); } return $emails; } function encodeEmail( $string, $link = FALSE ) { $ret = ""; for( $i = 0; $i < strlen( $string ); ++$i ) { $n = rand( -1, 1 ); if( !$n || $string{$i} == "@" ) $ret .= '&#x' . sprintf( "%X", ord( $string{$i} ) ) . ';'; elseif( $n > 0 ) $ret .= '&#' . ord( $string{$i} ) . ';'; else $ret .= $string{$i}; } if( $link ) { $string = "mailto:"; for( $i = 0; $i < strlen( $string ); ++$i ) { $n = rand( -1, 1 ); if( !$n || $string{$i} == "@" ) $mailto .= '&#x' . sprintf( "%X", ord( $string{$i} ) ) . ';'; elseif( $n > 0 ) $mailto .= '&#' . ord( $string{$i} ) . ';'; else $mailto .= $string{$i}; } return "$ret"; } else return $ret; } function stateToAbr( $state ) { $abr = ""; $state = formatName( $state ); switch( $state ) { case "Alabama": $abr = "AL"; break; case "Alaska": $abr = "AK"; break; case "Arizona": $abr = "AZ"; break; case "Arkansas": $abr = "AK"; break; case "California": $abr = "CA"; break; case "Colorado": $abr = "CO"; break; case "Connecticut": $abr = "CT"; break; case "Delaware": $abr = "DE"; break; case "Florida": $abr = "FL"; break; case "Georgia": $abr = "GA"; break; case "Hawaii": $abr = "HI"; break; case "Idaho": $abr = "ID"; break; case "Illinois": $abr = "IL"; break; case "Indiana": $abr = "IN"; break; case "Iowa": $abr = "IA"; break; case "Kansas": $abr = "KS"; break; case "Kentucky": $abr = "KY"; break; case "Louisiana": $abr = "LA"; break; case "Maine": $abr = "ME"; break; case "Maryland": $abr = "MD"; break; case "Massachusetts": $abr = "MA"; break; case "Michigan": $abr = "MI"; break; case "Minnesota": $abr = "MN"; break; case "Mississippi": $abr = "MS"; break; case "Missouri": $abr = "MO"; break; case "Montana": $abr = "MT"; break; case "Nebraska": $abr = "NE"; break; case "Nevada": $abr = "NV"; break; case "New Hampshire": $abr = "NH"; break; case "New Jersey": $abr = "NJ"; break; case "New Mexico": $abr = "NM"; break; case "New York": $abr = "NY"; break; case "North Carolina": $abr = "NC"; break; case "North Dakota": $abr = "ND"; break; case "Ohio": $abr = "OH"; break; case "Oklahoma": $abr = "OK"; break; case "Oregon": $abr = "OR"; break; case "Pennsylvania": $abr = "PA"; break; case "Rhode Island": $abr = "RI"; break; case "South Carolina": $abr = "SC"; break; case "South Dakota": $abr = "SD"; break; case "Tennesee": $abr = "TN"; break; case "Texas": $abr = "TX"; break; case "Utah": $abr = "UT"; break; case "Vermont": $abr = "VT"; break; case "Virginia": $abr = "VA"; break; case "Washington": $abr = "WA"; break; case "West Virginia": $abr = "WV"; break; case "Wisconsin": $abr = "WI"; break; case "Wyoming": $abr = "WY"; break; default: $abr = "ERROR"; break; } return $abr; } function abrToState( $abr ) { $state = ""; $abr = strtoupper( $abr ); switch( $abr ) { case "AL": $state = "Alabama"; break; case "AK": $state = "Alaska"; break; case "AZ": $state = "Arizona"; break; case "AK": $state = "Arkansas"; break; case "CA": $state = "California"; break; case "CO": $state = "Colorado"; break; case "CT": $state = "Connecticut"; break; case "DE": $state = "Delaware"; break; case "FL": $state = "Florida"; break; case "GA": $state = "Georgia"; break; case "HI": $state = "Hawaii"; break; case "ID": $state = "Idaho"; break; case "IL": $state = "Illinois"; break; case "IN": $state = "Indiana"; break; case "IA": $state = "Iowa"; break; case "KS": $state = "Kansas"; break; case "KY": $state = "Kentucky"; break; case "LA": $state = "Louisiana"; break; case "ME": $state = "Maine"; break; case "MD": $state = "Maryland"; break; case "MA": $state = "Massachusetts"; break; case "MI": $state = "Michigan"; break; case "MN": $state = "Minnesota"; break; case "MS": $state = "Mississippi"; break; case "MO": $state = "Missouri"; break; case "MT": $state = "Montana"; break; case "NE": $state = "Nebraska"; break; case "NV": $state = "Nevada"; break; case "NH": $state = "New Hampshire"; break; case "NJ": $state = "New Jersey"; break; case "NM": $state = "New Mexico"; break; case "NY": $state = "New York"; break; case "NC": $state = "North Carolina"; break; case "ND": $state = "North Dakota"; break; case "OH": $state = "Ohio"; break; case "OK": $state = "Oklahoma"; break; case "OR": $state = "Oregon"; break; case "PA": $state = "Pennsylvania"; break; case "RI": $state = "Rhode Island"; break; case "SC": $state = "South Carolina"; break; case "SD": $state = "South Dakota"; break; case "TN": $state = "Tennesee"; break; case "TX": $state = "Texas"; break; case "UT": $state = "Utah"; break; case "VA": $state = "Virginia"; break; case "VT": $state = "Vermont"; break; case "WA": $state = "Washington"; break; case "WV": $state = "West Virginia"; break; case "WI": $state = "Wisconsin"; break; case "WY": $state = "Wyoming"; break; default: $state = "ERROR"; break; } return $state; } function formatCurrency( $amt ) // This function formats a number to the proper format for US currency { return "\$".number_format( $amt, 2 ); } function str_max( $string, $max=255 ) { return( substr( $string, 0, $max ) ); } function verifyEmail($address, &$error) // This function connects to a mail server and attempts to verify the validity of the given email address { $eold = error_reporting( 0 ); global $SERVER_NAME; list( $user, $domain ) = split( "@", $address, 2 ); //make sure the domain has a mail exchanger if( checkdnsrr( $domain, "MX" ) ) { //get mail exchanger records if( !getmxrr( $domain, $mxhost, $mxweight ) ) { $error = "Could not retrieve mail exchangers!
\n"; return( FALSE ); } } else { //if no mail exchanger, maybe the host itself will accept mail $mxhost[] = $domain; $mxweight[] = 1; } //create sorted array of hosts for($i = 0; $i < count($mxhost); $i++) { $weighted_host[( $mxweight[$i] )] = $mxhost[$i]; } ksort( $weighted_host ); //loop over each host foreach( $weighted_host as $host ) { //connect to host on SMTP port if( !( $fp = fsockopen( $host, 25 ) ) ) { //couldn't connect to this host, but //the next might work continue; } // ** skip over 220 messages; give up if no response for 10 seconds set_socket_blocking( $fp, FALSE ); $stopTime = time() + 10; $gotResponse = FALSE; while( TRUE ) { //try to get a line from mail server $line = fgets( $fp, 1024 ); if( substr( $line, 0, 3 ) == "220" ) { //reset timer $stopTime = time() + 10; $gotResponse = TRUE; } elseif( ( $line == "" ) AND ( $gotResponse ) ) { break; } elseif( time() > $stopTime ) { break; } } if( !$gotResponse ) { //this host was unresponsive, but //maybe the next will be better continue; } set_socket_blocking( $fp, TRUE ); //sign in fputs( $fp, "HELO $SERVER_NAME\r\n" ); fgets( $fp, 1024 ); //set from fputs( $fp, "MAIL FROM: \r\n" ); fgets( $fp, 1024 ); //try address fputs( $fp, "RCPT TO: <$address>\r\n" ); $line = fgets($fp, 1024 ); //close connection fputs( $fp, "QUIT\r\n" ); fclose( $fp ); if( substr( $line, 0, 3 ) != "250" ) { //mail server doesn't recognize //this address, so it must be bad $error = $line; return( FALSE ); } else { //address recognized return( TRUE ); } } error_reporting( $eold ); $error = "Unable to reach a mail exchanger!"; return( FALSE ); } function sum() // This function sums up all numbers passed to it. Arrays are accepted as well. { $args = func_get_args(); $sum = 0.0; for( $i = 0; $i < count( $args ); $i++ ) { if( is_array( $args[$i] ) ) { $temp = $args[$i]; for( $i = 0; $i < count( $temp ); $i++ ) { if( is_array( $temp[$i] ) ) { $sum += sum( $temp[$i] ); } else { $sum += $temp[$i]; } } } else { $sum += $args[$i]; } } return $sum; } function avg() // This function averages all numbers passed to it. Arrays are accepted as well. { $args = func_get_args(); $sum = 0.0; $tot = 0; for( $i = 0; $i < count( $args ); $i++ ) { if( is_array( $args[$i] ) ) { $temp = $args[$i]; for( $i = 0; $i < count( $temp ); $i++ ) { if( is_array( $temp[$i] ) ) { $sum += sum( $temp[$i] ); $tot += count( $temp[$i] ); } else { $sum += $temp[$i]; $tot++; } } } else { $sum += $args[$i]; $tot++; } } return $sum / $tot; } function rands( $max ) // This function returns the sequence of numbers from 0 to $max in a random order { for( $i = 0; $i < $max; $i++ ) { $newnums[$i] = $i; } $i = 0; while( count( $newnums ) >= 1 ) { unset( $nums ); $nums = array(); $nums = $newnums; $temp = rand( 0, count( $nums ) - 1 ); $sequence[$i] = $nums[$temp]; $nums[$temp] = NULL; unset( $newnums ); $newnums = array(); for( $j = 0; $j < count( $nums ); $j++ ) { if( $j != $temp ) { array_push( $newnums, $nums[$j] ); } } $i++; } return $sequence; } function http_post($server, $url, $vars) // This function makes a post to the given server at the given path submitting the given variables // The resulting web page is returned as a string { $user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"; $port = 80; $urlencoded = ""; while (list($key,$value) = each($vars)) { if( is_array( $value ) ) { for( $i = 0; $i < count( $vars ); $i++ ) { $urlencoded.= urlencode($key.$i) . "=" . urlencode($value[$i]) . "&"; } } else { $urlencoded.= urlencode($key) . "=" . urlencode($value) . "&"; } } $urlencoded = substr($urlencoded,0,-1); $content_length = strlen($urlencoded); $headers = "POST $url HTTP/1.1 Accept: */* Content-Type: application/x-www-form-urlencoded User-Agent: $user_agent Referer: http://$server Host: $server Content-Length: $content_length "; $fp = fsockopen($server, $port, $errno, $errstr); if (!$fp) { return FALSE; } fputs($fp, $headers); fputs($fp, $urlencoded); $ret = ""; while (!feof($fp)) $ret.= fgets($fp, 2048); fclose($fp); return $ret; } function formatName( $name ) { if( strstr( ",", $name ) != "" ) { $arr = split( ",", $name ); swap( $arr[0], $arr[1] ); } else { $arr = split( " ", $name ); $name = ""; } for( $i = 0; $i < count( $arr ) - 1; $i++ ) { $name .= strtoupper( substr( $arr[$i], 0, 1 ) ).substr( $arr[$i], 1, 30 )." "; } $name .= strtoupper( substr( $arr[$i], 0, 1 ) ).substr( $arr[$i], 1, 30 ); return $name; } function formatURL( $url ) // This function is design to take a badly formatted url and make it syntactically correct, // returning the URL in a standard format. { // Correct typo's $url = str_replace( "\\", "/", $url ); $url = ereg_replace( "^htp", "http", $url ); $url = ereg_replace( "^http/", "http:/", $url ); $url = ereg_replace( "^http;", "http:", $url ); $url = str_replace( "http://", "", $url ); $url = ereg_replace( "\/+", "/", $url ); $url = ereg_replace( "\.+", ".", $url ); // Check for filename if( strstr( $url, "/" ) == "" && ( stristr( $url, ".jpg" ) != "" || stristr( $url, ".gif" ) != "" || stristr( $url, ".png" ) != "" || stristr( $url, ".htm" ) != "" || stristr( $url, ".php" ) != "" || stristr( $url, ".asp" ) != "" || stristr( $url, ".cgi" ) != "" || stristr( $url, ".pl" ) != "" || stristr( $url, ".doc" ) != "" || stristr( $url, ".pdf" ) != "" ) ) { return( $url ); } if( $url == "" ) { return( "" ); } $url = "http://".$url; $arr = parse_url( $url ); $ret = $arr["scheme"]."://"; if( $arr["user"] != "" ) $ret .= $arr["user"].":".$arr["pass"]."@"; $ret .= $arr["host"].$arr["path"]; if( $arr["query"] != "" ) $ret .= "?".$arr["query"]; return $ret; } function convertTags( $string, $convto="html" ) // This function is designed to convert a string from user formatted text to formatted html // and vice versa. It will catch email addresses and URLs and transform them into links // Prerequisite function: formatURL( $url ) { switch( $convto ) { case "html": $links = array(); $string = str_replace( "<", "[", $string ); $string = str_replace( ">", "]", $string ); // Allow tags other than bold or italics? Uncomment to DISallow $string = ereg_replace( "\<[^\>]+\>", "", $string ); $string = str_replace( " ", " ", $string ); $string = preg_replace( "/\[bold\](.*?)\[bold\]/", "\\1", $string ); $string = preg_replace( "/\[italics\](.*?)\[italics\]/", "\\1", $string ); $string = preg_replace( "/\[underline\](.*?)\[underline\]/", "\\1", $string ); $string = preg_replace( "/\[center\](.*?)\[center\]/", "
\\1
", $string ); // Link bullshit $i = 0; while( preg_match( "/\[link\]([^\|]*?)\|([^\[]*?)\[link\]/", $string, $matches ) ) { $links[$i] = $matches[1]."|".$matches[2]; $string = str_replace( $matches[0], "%%%".$i."%%%", $string ); $i++; } $string = preg_replace( "/\[b\](.*?)\[b\]/", "\\1", $string ); $string = preg_replace( "/\[i\](.*?)\[i\]/", "\\1", $string ); $string = preg_replace( "/\[u\](.*?)\[u\]/", "\\1", $string ); $string = preg_replace( "/\[c\](.*?)\[c\]/", "
\\1
", $string ); $string = ereg_replace( "\[[^\]]+\]", "", $string ); $string = ereg_replace( "[ ]*\r", "", $string ); $string = ereg_replace( "[ ]*\n", "
", $string ); $string = ereg_replace( "\t", " ", $string ); $string = ereg_replace( "\\\"", """, $string ); $string = ereg_replace( "\"", """, $string ); $string = str_replace( "\\'", "'", $string ); $string = ereg_replace( "\\\"", """, $string ); $string = ereg_replace( " ", " ", $string ); $string = ereg_replace( "([A-Z]|[a-z]|\.|\?|\!)\ \;([A-Z]|[a-z])", "\\1 \\2", $string ); preg_match_all( "/(\w+\@[^\.]+\.[^ \.\)\>\:\&\[\]\<]+)/", $string, $matches ); for( $i = 0; $i < count( $matches[1] ); $i++ ) { $string = str_replace( $matches[1][$i], "".$matches[1][$i]."", $string ); } unset( $matches ); preg_match_all( "/[^'\"\]](ht{1,2}p:[^ \[\&\)\]\>\&\<\(\[]+)/", $string, $matches ); for( $i = 0; $i < count( $matches[1] ); $i++ ) { $temp = formatURL( $matches[1][$i] ); $string = str_replace( $matches[1][$i], "".$temp."", $string ); } unset( $matches ); preg_match_all( "/[^\/'\"\]](www\.[^ \.]+\.[^ \[\&\)\]\>\<\[]+)/", $string, $matches ); for( $i = 0; $i < count( $matches[1] ); $i++ ) { $temp = formatURL( $matches[1][$i] ); $string = str_replace( $matches[1][$i], "".$temp."", $string ); } for( $i = 0; $i < count( $links ); $i++ ) { list( $url, $txt ) = split( "\|", $links[$i] ); $string = str_replace( "%%%".$i."%%%", "".$txt."", $string ); } break; case "code": $string = ereg_replace( "\n", " ", $string ); $string = ereg_replace( "\r", " ", $string ); $string = ereg_replace( "
", "\n", $string ); $string = ereg_replace( "\t", "", $string ); // Codes $string = preg_replace( "|([^\<]*?)|", "[link]\\1|\\2", $string ); $string = preg_replace( "||", "", $string ); $string = preg_replace( "||", "", $string ); $string = ereg_replace( "<\/a>", "", $string ); $string = ereg_replace( "<\/a link>", "[link]", $string ); $string = ereg_replace( "", "[bold]", $string ); $string = ereg_replace( "<\/b>", "[bold]", $string ); $string = ereg_replace( "", "[italics]", $string ); $string = ereg_replace( "<\/i>", "[italics]", $string ); $string = ereg_replace( "", "[underline]", $string ); $string = ereg_replace( "<\/u>", "[underline]", $string ); $string = ereg_replace( "
", "[center]", $string ); $string = ereg_replace( "<\/center>", "[center]", $string ); $string = ereg_replace( "\<[^\>]+\>", "", $string ); $string = ereg_replace( "\\\"", """, $string ); $string = ereg_replace( "\\\"", """, $string ); $string = ereg_replace( "\"", """, $string ); $string = str_replace( "\\'", "'", $string ); break; } return $string; } function secure( $page = "" ) // This function redirects the page to its secure version or the secure version of the optional link passed to it. { global $_SERVER; if( $_SERVER["HTTPS"] != "on" ) { if( $page == "" ) { redirect( "https://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"] ); } else { redirect( str_replace( "http://", "https://", $page ) ); } } } function encrypt( $string, $KEY ) // This function uses the mcrypt library to encrypt a string and returns it { $td = mcrypt_module_open( 'tripledes', '', 'ecb', '' ); $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_RAND ); mcrypt_generic_init( $td, $KEY, $iv ); return mcrypt_generic( $td, $string ); } function decrypt( $string, $KEY ) // This function uses the mcrypt library te decrypt a string and returns it { $td = mcrypt_module_open( 'tripledes', '', 'ecb', '' ); $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_RAND ); mcrypt_generic_init( $td, $KEY, $iv ); while( strlen( $string ) % 8 ) { $string .= "\0"; } return( chop( mdecrypt_generic( $td, $string ) ) ); } function incHeader( $floc="" ) { global $HEADER; if( file_exists( $floc ) ) require( $floc ); elseif( file_exists( $HEADER ) ) require( $HEADER ); elseif( file_exists( "header.inc" ) ) require( "header.inc" ); elseif( file_exists( "../header.inc" ) ) require( "../header.inc" ); elseif( file_exists( "../../header.inc" ) ) require( "../../header.inc" ); } function incJava( $floc="" ) { global $JAVA; if( file_exists( $floc ) ) require( $floc ); elseif( file_exists( $JAVA ) ) require( $JAVA ); elseif( file_exists( "java.inc" ) ) require( "java.inc" ); elseif( file_exists( "../java.inc" ) ) require( "../java.inc" ); elseif( file_exists( "../../java.inc" ) ) require( "../../java.inc" ); } function incFooter( $floc="" ) { global $FOOTER; if( file_exists( $floc ) ) require( $floc ); elseif( file_exists( $FOOTER ) ) require( $FOOTER ); elseif( file_exists( "footer.inc" ) ) require( "footer.inc" ); elseif( file_exists( "../footer.inc" ) ) require( "../footer.inc" ); elseif( file_exists( "../../footer.inc" ) ) require( "../../footer.inc" ); } function requireJS() { println( " Please note: You MUST have JavaScript Enabled on your browser to make use of this page.

Your browser does not have Active Scripting (JavaScript) enabled. " ); } function submitJS( $value="Submit", $name="" ) { $pnt = ""; println( $pnt ); } function newWindowLink( $str, $link="Click", $height=250, $width=200 ) { $num = floor( rand() ); println( "
".$link."" ); } function newWindow( $str, $height=250, $width=200 ) { println( "" ); } function Ox( $hexstr ) { return( hexdec( "0x".$hexstr ) ); } function removeDupes( $arr ) { $newarr = array(); for( $i = 0; $i < count( $arr ); $i++ ) { if( !isIn( $arr[$i], $newarr ) ) { array_push( $newarr, $arr[$i] ); } } return( $newarr ); } function getPerms( $file ) { if( !file_exists( $file ) ) return( FALSE ); $perms = base_convert( fileperms( $file ), 10, 8 ); return( substr( $perms, (strlen( $perms ) - 3) ) ); } function getFiles( $dir ) { $fp = opendir( $dir ); $filelist = array(); while( $temp = readdir( $fp ) ) { if( $temp != "." && $temp != ".." && strlen( $temp ) > 1 ) { $filelist[] = $temp; } } closedir( $fp ); return $filelist; } function shadowbox( $txt, $shadcolor="#444444", $bgcolor="#FFFFFF" ) { global $_SERVER; if( stristr( $_SERVER["HTTP_USER_AGENT"], "MSIE" ) ) { $box = '
'.$txt.'   
 
 
                                 
'; } else { $box = '
'.$txt.'   
 
   
'; } print( $box ); } ?> db ) // createTable( $queryArray ) // createTableStr( $list ) // deleteColumn( $name ) // deleteDB( $db=$this->db ) // deleteRow( $key, $value ) // deleteTable( $tb=$this->table ) // exportDB( $filepath ) // fetch( $result ) // getFields() // getColumn( $columns ) // getDBs() // getNewId() // getRow( $col, $val ) // getTable() // getTables() // getValue( $query ) // idExists( $id ) // importDB( $data, $imode ) // insert( $queryArray ) // makeArray( $dbResult ) // modifyRow( $col, $oldval, $newvals ) // modifyTable( $modArray ) // numFields() // printResult( $inpResult ) // printTable() // query( $query ) // tableDump( $tb=$this->table ) // tableExists( $tb=$this->table ) // tableInfo() function Database() { $DEBUG = TRUE; } function init( $p1, $p2, $p3, $p4="", $p5="" ) { $this->host = $p1; $this->username = $p2; $this->password = $p3; $this->db = $p4; $this->table = $p5; $this->slink = mysql_connect( $this->host, $this->username, $this->password ); $DEBUG = FALSE; return( $this->slink ); } function open() { $this->slink = mysql_connect( $this->host, $this->username, $this->password ); return( $this->slink ); } function close() { mysql_close( $this->slink ); } function addColumn( $name, $spec, $pos ) { $query = "ALTER TABLE ".$this->table." ADD ".$name." ".$spec." ".$pos; if( $this->DEBUG ) { print( "
\n
\n".$query."
\n
\n" ); } else return( mysql_db_query( $this->db, $query, $this->slink ) ); } function columnExists( $column ) { $dbResult = mysql_list_fields( $this->db, $this->table, $this->slink ); for( $i = 0; $i < mysql_num_fields( $dbResult ); $i++ ) { if( $column == mysql_field_name( $dbResult, $i ) ) return TRUE; } return FALSE; } function createDB( $db="" ) { if( $db == "" ) { $db = $this->db; } if( $this->DEBUG ) { print( "
\n
\nCreate DB: ".$this->db."
\n
\n" ); } else return( $this->query( "CREATE DATABASE ".$db ) ); } function createTable( $newtb, $queryArray ) { $this->table = $newtb; $myquery = "CREATE TABLE ".$newtb." ("; foreach( $queryArray as $key=>$value ) { $myquery .= $key." ".$value; } $myquery .= ")"; if( $this->DEBUG ) { print( "
\n
\n".$myquery."
\n
\n" ); } else return( mysql_db_query( $this->db, $myquery, $this->slink ) ); } function createTableStr( $list ) { $query = "CREATE TABLE ".$this->table." ".$list; if( $this->DEBUG ) { print( "
\n
\n".$query."
\n
\n" ); } else return( mysql_db_query( $this->db, $query, $this->slink ) ); } function deleteColumn( $name ) { $query = "ALTER TABLE ".$this->table." DROP ".$name; if( $this->DEBUG ) { print( "
\n
\n".$query."
\n
\n" ); } else return( mysql_db_query( $this->db, $query, $this->slink ) ); } function deleteDB( $db="" ) { if( $db == "" ) { $db = $this->db; } if( $this->DEBUG ) { print( "
\n
\nDrop DB: ".$this->db."
\n
\n" ); } else return( mysql_query( "DROP DATABASE ".$this->db, $this->slink ) ); } function deleteTable( $tb="" ) { if( $tb == "" ) { $tb = $this->table; } if( $this->DEBUG ) { print( "
\n
\nDelete Table: ".$this->table."
\n
\n" ); } else return( mysql_db_query( $this->db, "DROP TABLE ".$tb, $this->slink ) ); } function deleteRow( $key, $value ) { $query = "DELETE FROM ".$this->table." WHERE ".$key."='".$value."' LIMIT 1"; if( $this->DEBUG ) { print( "
\n
\n".$query."
\n
\n" ); } else return( mysql_db_query( $this->db, $query, $this->slink ) ); } function exportDB( $filepath ) { $dbResult = mysql_db_query( $this->db, "SELECT * FROM ".$this->table, $this->slink ); if( !$dbResult ) { return( FALSE ); } $i = 0; while( $row = mysql_fetch_array( $dbResult, MYSQL_NUM ) ) { for( $j = 0; $j < count( $row ) - 1; $j++ ) { $myTable[$i] .= $row[$j]." "; } $myTable[$i] .= $row[$j]; $i++; } $file = fopen( $filepath."/dbexport.txt", "w" ); if( $file ) { for( $i = 0; $i < count( $myTable ); $i++ ) { fputs( $file, $myTable[$i]."\n" ); } fclose( $file ); return( TRUE ); } else { return( FALSE ); } } function fetch( $result ) { return( mysql_fetch_array( $result, MYSQL_NUM ) ); } function getColumn( $columns ) { $dbResult = mysql_db_query( $this->db, "SELECT ".$columns." FROM ".$this->table, $this->slink ); if( !$dbResult ) { return( FALSE ); } $i = 0; while( $row = mysql_fetch_array( $dbResult, MYSQL_NUM ) ) { if( count( $row ) > 1 ) { for( $j = 0; $j < count($row); $j++ ) { $myTable[$i][$j] = $row[$j]; } } else { $myTable[$i] = $row[0]; } $i++; } return( $myTable ); } function getDBs() { $dbResult = mysql_list_dbs( $this->slink ); if( !$dbResult ) { return( FALSE ); } $i = 0; while( $row = mysql_fetch_row( $dbResult ) ) { $list[$i] = $row[0]; $i++; } return( $list ); } function getFields() { $dbResult = mysql_list_fields( $this->db, $this->table, $this->slink ); $fields = mysql_num_fields( $dbResult ); for( $i = 0; $i < $fields; $i++ ) { $headings[$i] = mysql_field_name( $dbResult, $i ); } return( $headings ); } function getNewId() // Defunct... use auto-number fields // Included for backward-compatibility { $ids = mysql_db_query( $this->db, "SELECT id FROM ".$this->table, $this->slink ); if( $ids ) { $newid = mysql_num_rows( $ids ) + 1; while( $this->idExists( $newid ) ) { $newid++; } } else { $newid = 1; } return( $newid ); } function getRow( $col, $val ) { $dbResult = mysql_db_query( $this->db, "SELECT * FROM ".$this->table." WHERE $col='$val' LIMIT 1", $this->slink ); if( !$dbResult ) { return( FALSE ); } return( mysql_fetch_array( $dbResult, MYSQL_NUM ) ); } function getTable() { $dbResult = mysql_db_query( $this->db, "SELECT * FROM ".$this->table, $this->slink ); if( !$dbResult ) { return( FALSE ); } $i = 0; while( $row = mysql_fetch_array( $dbResult, MYSQL_NUM ) ) { for( $j = 0; $j < count($row); $j++ ) { $myTable[$i][$j] = $row[$j]; } $i++; } return( $myTable ); } function getTables() { $dbResult = mysql_list_tables( $this->db, $this->slink ); if( !$dbResult ) { return( FALSE ); } $i = 0; while( $row = mysql_fetch_row( $dbResult ) ) { $list[$i] = $row[0]; $i++; } return( $list ); } function getValue( $query, $col=1 ) { if( stristr( $query, "select" ) || stristr( $query, "show" ) || stristr( $query, "describe" ) ) { $dbResult = $this->query( $query ); } else { $dbResult = $query; } $arr = $this->fetch( $dbResult ); if( !is_array( $arr ) ) return( FALSE ); for( $i = 0; $i < $col; $i++ ) $ret = array_shift( $arr ); return( $ret ); } function idExists( $id ) { $query = "SELECT id FROM ".$this->table." WHERE id='".$id."' LIMIT 1"; $dbResult = mysql_db_query( $this->db, $query, $this->slink ); $arr = mysql_fetch_array( $dbResult, MYSQL_NUM ); return( $arr[0] ); } function importDB( $data, $imode="replace" ) { switch( $imode ) { case "replace": $query = "DELETE FROM ".$this->table; mysql_db_query( $this->db, $query, $this->slink ); for( $i = 0; $i < count( $data ); $i++ ) { $data[$i] = str_replace( "\"", "", $data[$i] ); $data[$i] = ereg_replace( "\n", "", $data[$i] ); $data[$i] = ereg_replace( "\r", "", $data[$i] ); $line = split( "\t", $data[$i] ); if( $line[0] != "" ) { $this->insert( $line ); } } break; case "merge": for( $i = 0; $i < count( $data ); $i++ ) { $data[$i] = str_replace( "\"", "", $data[$i] ); $data[$i] = ereg_replace( "\r", "", $data[$i] ); $data[$i] = ereg_replace( "\n", "", $data[$i] ); $line = split( "\t", $data[$i] ); $fields = $this->getFields(); for( $i = 0; $i < count( $fields ); $i++ ) { if( $fields[$i] == "id" ) { $idfieldnum = $i; break; } } if( $line[0] != "" ) { if( $this->isIn( $line[$idfieldnum] ) ) { $this->modifyRow( "id", $line[$idfieldnum], $line ); } else { $this->insert( $line ); } } } break; } } function insert( $queryArray ) { $myquery = "INSERT INTO ".$this->table." VALUES("; for( $i = 0; $i < $this->numFields() - 1; $i++ ) { $queryArray[$i] = stripslashes( $queryArray[$i] ); $myquery .= "'".addslashes($queryArray[$i])."', "; } $queryArray[$i] = stripslashes( $queryArray[$i] ); $myquery .= "'".addslashes($queryArray[$i])."')"; if( $this->DEBUG ) { print( "
\n
\n".$myquery."
\n
\n" ); } else return( mysql_db_query( $this->db, $myquery, $this->slink ) ); } function isIn( $id ) { $dbResult = mysql_db_query( $this->db, "SELECT id FROM ".$this->table." WHERE id='".$id."' LIMIT 1", $this->slink ); list( $arr ) = mysql_fetch_array( $dbResult, MYSQL_NUM ); return( $arr ); } function makeArray( $dbResult ) { if( !$dbResult ) { return( FALSE ); } $i = 0; while( $row = mysql_fetch_array( $dbResult, MYSQL_NUM ) ) { if( count( $row ) > 1 ) { for( $j = 0; $j < count($row); $j++ ) { $myTable[$i][$j] = $row[$j]; } } else { $myTable[$i] = $row[0]; $i++; } } return( $myTable ); } function modifyTable( $modArray ) { $myquery = "ALTER TABLE ".$this->table." CHANGE COLUMN ".$modArray[0]." ".$modArray[1]." ".$modArray[2]; if( $this->DEBUG ) { print( "
\n
\n".$myquery."
\n
\n" ); } else return( mysql_db_query( $this->db, $myquery, $this->slink ) ); } function modifyRow( $col, $oldval, $newvals ) { $headings = $this->getFields(); if( count( $headings ) < 2 ) { $myquery = "UPDATE ".$this->table." SET ".$headings." = '".$newvals."' WHERE ".$col." = '".$oldval."'"; } else { $myquery = "UPDATE ".$this->table." SET "; for( $i = 0; $i < count( $headings ) - 1; $i++ ) { $myquery .= $headings[$i]." = '".$newvals[$i]."', "; } $myquery .= $headings[$i]." = '".$newvals[$i]."' WHERE ".$col." = '".$oldval."'"; } $myquery .= " LIMIT 1"; if( $this->DEBUG ) { print( "
\n
\n".$myquery."
\n
\n" ); } else return( mysql_db_query( $this->db, $myquery, $this->slink ) ); } function numFields() { $dbresult = mysql_list_fields( $this->db, $this->table, $this->slink ); return( mysql_num_fields( $dbresult ) ); } function printResult( $inpResult ) { $fields = mysql_num_fields( $inpResult ); print( "Results from query on table '".$this->table."':
\n" ); print( "\n\n" ); for( $i = 0; $i < $fields; $i++ ) { print( "\n" ); } print( "\n" ); while( $line = mysql_fetch_array( $inpResult, MYSQL_NUM ) ) { print( "\n" ); for( $i = 0; $i < count( $line ); $i++ ) { print( "\n" ); } print( "\n" ); } print( "
".mysql_field_name( $inpResult, $i )."
".$line[$i]."

\n" ); } function printTable() { $dbResult = mysql_list_fields( $this->db, $this->table, $this->slink ); $records = $this->getTable(); $fields = mysql_num_fields( $dbResult ); print( "Contents of table ".$this->table.":
\n" ); print( "\n\n" ); for( $i = 0; $i < $fields; $i++ ) { print( "\n" ); } print( "\n" ); for( $i = 0; $i < count( $records ); $i++ ) { print( "\n" ); for( $j = 0; $j < $fields; $j++ ) { print( "\n" ); } print( "\n" ); } print( "
".mysql_field_name( $dbResult, $i )."
".$records[$i][$j]."

\n" ); } function query( $query ) { if( $this->DEBUG ) { print( "
\n
\n".$query."
\n
\n" ); if( !( stristr( $query, "DROP" ) || stristr( $query, "DELETE" ) || stristr( $query, "ALTER" ) || stristr( $query, "UPDATE" ) ) ) return( mysql_db_query( $this->db, $query, $this->slink ) ); } else return( mysql_db_query( $this->db, $query, $this->slink ) ); } function tableExists( $tb="" ) { if( $tb == "" ) { $tb = $this->table; } return( mysql_db_query( $this->db, "SELECT * FROM ".$tb, $this->slink ) ); } function tableInfo() { $dbResult = $this->query( "DESCRIBE ".$this->table ); $this->printResult( $dbResult ); } function tableDump( $tb="" ) { if( $tb == "" ) { $tb = $this->table; } $ret[] = array(); if( $tb == "*" || strtolower($tb) == "all" ) { $tables = $this->getTables(); foreach( $tables as $table ) { if( $table != "" ) { $dbResult = $this->query( "SHOW CREATE TABLE ".$table ); $ret[] = $this->fetch( $dbResult ); } } } else { $dbResult = $this->query( "SHOW CREATE TABLE $tb" ); $ret[] = $this->fetch( $dbResult ); } return( $ret ); } // Nonstandard Functions: // ---------------------- } ?>