//variables
// $serverName="localhost";
$serverName="localhost";
$userName="theffron_pace";
$password="pacesd";
$initpswd="sdisfun";
$articlesDirectory = "pacearticles";
// end variables
/**
* Checks for a valid date
*
* @param string Date in the format given by the format parameter.
* @param integer Disallow years more than $yearepsilon from now (in future as well as in past)
* @param string Formatting string. Has to be one of 'dmy', 'dym', 'mdy', 'myd', 'ydm' or 'ymd'. (Default is 'ymd' for ISO 8601 compability)
* @return array [ year, month, day ]
* @since 1.0
*/
function datecheck($date, $yearepsilon=5, $format='ymd') {
$date=str_replace("/", "-", $date);
$format = strtolower($format);
if (count($datebits=explode('-',$date))!=3) return false;
$year = intval($datebits[strpos($format, 'y')]) + 2000;
$month = intval($datebits[strpos($format, 'm')]);
$day = intval($datebits[strpos($format, 'd')]);
if (!checkdate($month, $day, $year)) {
// return array(
// 'year' => "b" . $year,
// 'month' => $month,
// 'day' => $day) ;
return "the date is" . date('m-d-y',mktime(0,0,0,$month,$day,$year));
} else {
return array(
'year' => $year,
'month' => $month,
'day' => $day); // date out of range
} // end if
} // end datecheck
function escape_data($data) { // Create a function to escape the data
global $dbConn; //Need the connection
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbConn);
} //end escape_data function
function connectPace() {
// conncet to Pace db
global $serverName, $userName, $password;
//$dbConn = mysql_connect($serverName, $userName, $password);
$dbConn = mysql_connect($serverName, $userName, $password);
if (!$dbConn) {
print "
Problem connecting to database!
\n";
} // end if
$select = mysql_select_db("theffron_PACE");
if (!$select) {
print mysql_error() . " \n";
} // end if
return $dbConn;
} // end connectPace
function buildFieldList($tablename, $selectname, $keyname, $keyVal, $fieldname, $addNone) {
// with a given table and field generate list values for an HTML select
global $dbConn;
$output = "";
$sqlquery = "select $keyname, $fieldname from $tablename order by $fieldname asc";
$result = mysql_query($sqlquery, $dbConn);
$output .= "\n";
return $output;
} // end listMonths
function listLevels($keyname, $keyval) {
// build a dropdown with dance levels
$i = 1;
$levels = array(1 => "A2", "C1", "C2", "C3A", "C3", "C4");
$output = "\n";
return $output;
} // end listLevels
function clean_phone($phone)
{
$p = strtolower($phone);
for ($i=0;$i= 48) && ($a <= 57)) $r .= substr($p, $i, 1);
}
return $r;
}
function format_phone($phone)
{
$phone = clean_phone($phone);
$ret = "";
switch(strlen($phone))
{
case 7:
$ret = substr($phone, 0, 3)."-".substr($phone, 3);
break;
case 8:
$ret = substr($phone, 0, 4)."-".substr($phone, 4);
break;
case 10:
$ret = "(".substr($phone, 0, 3).") ".substr($phone, 3, 3)."-".substr($phone, 6, 4);
break;
case 11 || 12 || 13 || 14:
$ret = "(".substr($phone, 0, 3).") ".substr($phone, 3, 3)."-".substr($phone, 6, 4) . " ext." . substr($phone,10, strlen($phone) - 10);
break;
default:
$ret = $phone;
}
// return $ret.$ext;
return $ret;
}
function check_email($email)
{
// define a regular expression for "normal" addresses
$normal = "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$";
// define a regular expression for "strange looking" but syntactically valid addresses
$validButRare = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$";
$msg = "";
if (eregi($normal, $email)) {
// $msg = "The email address $email is valid and looks normal.";
} else if (eregi($validButRare, $email)) {
$msg = "The email address $email looks a bit strange but it is syntactically valid. You might want to check it for typos.";
}
else {
$msg = "The email address $email is not valid.";
}
return $msg;
}
// A function to generate random alphanumeric passwords in PHP
// It expects to be passed a desired password length, but it
// none is passed the default is set to 10 (you can change this)
function generate_password($length = 10) {
// This variable contains the list of allowable characters
// for the password. Note that the number 0 and the letter
// 'O' have been removed to avoid confusion between the two.
// The same is true of 'I' and 1
$allowable_characters = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
// We see how many characters are in the allowable list
$ps_len = strlen($allowable_characters);
// Seed the random number generator with the microtime stamp
// (current UNIX timestamp, but in microseconds)
mt_srand((double)microtime()*1000000);
// Declare the password as a blank string.
$pass = "";
// Loop the number of times specified by $length
for($i = 0; $i < $length; $i++) {
// Each iteration, pick a random character from the
// allowable string and append it to the password.
$pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
} // End for
// Retun the password we've selected
return $pass;
}
?>