$val) { $arr[$key] = self::clean_string($val); } return($arr); } static public function reverse_clean_string($s) { // replaces " with "" and ’ with "'" - mainly for use w/ meta tags $s = str_replace('"', '', $s); $s = str_replace("’", "'", $s); return($s); } */ static public function quotes_to_html($s, $convert_double_quotes=TRUE) { // cleans ', " from db to not screw up php or js - should only be used during output $s = str_replace("'", "’", $s); if($convert_double_quotes) { $s = str_replace('"', '"', $s); } return($s); } static public function get_months() { return(array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")); } static public function in_array_case_insensitive($search, $arr) { //echo '
'.$search; foreach($arr as $value) { //echo ':'.$value.'
'; if(strtolower($search) == strtolower($value)) { return(TRUE); } } return(FALSE); } static public function strip_index_file($filename, $strip) { if(substr($filename, strlen($filename)-strlen($strip), strlen($strip)) == $strip) { $filename = substr($filename, 0, strlen($filename)-strlen($strip)); } return($filename); } static public function make_www() { // REDIRECT TO www $domain = $_SERVER['HTTP_HOST']; $http = ($_SERVER['HTTPS'] != "on") ? 'http' : 'https'; $qs = ($_SERVER['QUERY_STRING'] != '') ? '?'.$_SERVER['QUERY_STRING'] : ''; $redirect = "$http://www.$domain".$_SERVER['SCRIPT_NAME'].$qs; header("Location: $redirect"); exit(); } static public function make_https() { if(!isset($_SERVER['HTTPS'])) { // REDIRECT TO SECURE PAGE $domain = $_SERVER['HTTP_HOST']; $qs = ($_SERVER['QUERY_STRING'] != '') ? '?'.$_SERVER['QUERY_STRING'] : ''; $redirect = "https://$domain".$_SERVER['SCRIPT_NAME'].$qs; header("Location: $redirect"); exit(); } } static public function make_http() { if(isset($_SERVER['HTTPS'])) { // REDIRECT TO NON-SECURE PAGE $domain = $_SERVER['HTTP_HOST']; $qs = ($_SERVER['QUERY_STRING'] != '') ? '?'.$_SERVER['QUERY_STRING'] : ''; $redirect = "http://$domain".$_SERVER['SCRIPT_NAME'].$qs; header("Location: $redirect"); exit(); } } static public function array_key_exists_case_insensitive($search, $arr) { foreach($arr as $key=>$value) { if(strtolower($search) == strtolower($key)) { return(TRUE); } } return(FALSE); } static public function convert_dt_from_military($dt, $linebreak = TRUE) { $year = substr($dt, 0, 4); $month = (int) substr($dt, 5, 2); $day = (int) substr($dt, 8, 2); $hour = (int) substr($dt, 11, 2); $minute = substr($dt, 14, 2); $ampm = ($hour >= 12) ? 'PM' : 'AM'; if($hour > 12) { $hour = $hour - 12; } if($hour == 0) { $hour = 12; } $ret = $month.'/'.$day.'/'.$year; if($linebreak){$ret .= '
';}else{$ret .= ' ';} $ret .= $hour.':'.$minute.' '.$ampm; return($ret); } static public function get_encoded_base64_qs_var($var) { $qsparts = explode('&', base64_decode($_SERVER['QUERY_STRING'])); //print_r($qsparts); foreach($qsparts as $qspart) // foreach var1=val1 { $pairparts = explode('=', $qspart); //print_r($pairparts); if($pairparts[0] == $var) { //echo $pairparts[1]; return($pairparts[1]); } } return(FALSE); // match not found for $var } static public function delete_file($file) { $cmd = "rm $file"; //echo $cmd; exec($cmd); } static public function is_valid_email($email) { if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $email)) { return(TRUE); } else { return(FALSE); } } static public function notify($to, $subject, $message, $cc='', $from='', $from_name = '', $block_local=TRUE) { if(Config::$location == 'local' && $block_local) { return(TRUE); } // use this fn for all internal email // $to can come in as a string or an array $to_arr = array(); // must pass array to phpmailer if(is_array($to)) { $to_arr = $to; } else { if(trim($to) == '') { return(FALSE); } $to_arr[] = $to; } $headers = ""; $subject = $subject; // make it noticeable $cc_arr = array(); if($cc != '') { $cc_arr[] = $cc; } $bcc_arr = array(); self::phpmailer_email($to_arr, $subject, $message, '', '', $cc_arr, $bcc_arr, '', '', FALSE, '', ''); } static public function select_month($arg_array) // $Forms, $months, $name, $format='default', $top_option_text='', $preselected='', $onchange='', $css='' { // hokey - had to set args to an array because of the way the args are passed to zz_form from join_confirm - see http://www.thescripts.com/forum/thread525082.html foreach($arg_array as $arg=>$val) { $$arg = $val; } $options = array(); // default format is Jan Feb ... $count = 0; foreach($months as $month) { ++$count; $options[$count] = ucwords(substr($month, 0, 3)); } return($Forms->generate_select_formfield($name, $options, $top_option, $preselected, $onchange, $css)); } static public function select_day($arg_array) // $Forms, $name, $format='default', $top_option_text='', $preselected='', $onchange='', $css='' { // hokey - had to set args to an array because of the way the args are passed to zz_form from join_confirm - see http://www.thescripts.com/forum/thread525082.html foreach($arg_array as $arg=>$val) { $$arg = $val; } // unsophisticated - just go from 1 to 31 $options = array(); for($i=1;$i<=31;++$i) { $options[$i] = $i; } return($Forms->generate_select_formfield($name, $options, $top_option, $preselected, $onchange, $css)); } static public function cc_exp_mo_select($arg_array) //($Forms, $name, $onchange='', $top_option, $selected='', $css) { foreach($arg_array as $arg=>$val) { $$arg = $val; } if($selected == '') { $selected = date("m"); // defaults to current month } $options = array(); for($i=1;$i<13;++$i) { $mo = ($i<10) ? "0".$i : $i; $options[$mo] = $mo; } return($Forms->generate_select_formfield($name, $options, $top_option, $selected, $onchange, $css)); } static public function cc_exp_yr_select($arg_array) //($Forms, $name, $onchange='', $top_option, $selected='', $css) { foreach($arg_array as $arg=>$val) { $$arg = $val; } if($selected == '') { $selected = substr(date("Y"), 2, 2); // defaults to current year } $options = array(); for($j=date("Y");$jgenerate_select_formfield($name, $options, $top_option, $selected, $onchange, $css)); } static public function cc_exp_in_future($mm, $yy) { //echo "mo in: $mm vs mo: ".date("m").", yr in: $yy vs yr: ".date("y"); if((int)$yy < (int)date("y")) { return(FALSE); } if((int)$yy == (int)date("y") && (int)$mm < (int)date("m")) { return(FALSE); } return(TRUE); } static public function is_digit($check) { if(strlen($check) != 1) { return(false); } $regex = "/^[0-9]$/"; return(preg_match($regex, $check) > 0); } static public function is_positive_int($check) { if(strlen($check) == 0) { return(false); } $regex = "/^[0-9]+$/"; return(preg_match($regex, $check) > 0); } static public function is_cvv2($test) { // either a 3 or 4 digit number $regex = "/[0-9]{3,4}$/"; return(preg_match($regex, $test) > 0); } static public function remove_non_int($str) { $arr = str_split($str); $newStr = ''; foreach($arr as $char) { if(self::is_digit($char)) { $newStr .= $char; } } return($newStr); } static public function is_cc($cardnum) { if(!is_numeric($cardnum)) // this will allow '.' - should fix { return(FALSE); } $checksum = 0; $checkdigit=substr($cardnum,-1); $remainingcardnum=substr($cardnum,0,strlen($cardnum)-1); $i=0; while($i < strlen($remainingcardnum)) { if($i%2==0) $remaing_array[$i]=substr($remainingcardnum,($i+1)*-1,1) * 2; else $remaing_array[$i]=substr($remainingcardnum,($i+1)*-1,1); if($remaing_array[$i]>=10) $checksum=$checksum+1; $checksum=$checksum+($remaing_array[$i]%10); $i++; } $calculatedcheckdigit=(10-($checksum%10))%10; if( $calculatedcheckdigit==$checkdigit) { return true; } else { return false; } } static public function get_cc_type($cc) { switch(substr($cc, 0, 1)) { case '3': return('A'); case '4': return('V'); case '5': return('M'); case '6': return('D'); default: return(FALSE); } } static public function phpmailer_email($to_arr, $subject, $body, $from='', $from_name='', $cc_arr='', $bcc_arr='', $reply_to='', $reply_to_name='', $is_html=TRUE, $image_arr='', $attachment_arr='', $AltBody='', $wordWrap=0) { // use this fn for all client email // turn off for local //if(Config::$location != 'local') { /* debug echo '

params:
to: '; var_dump($to_arr); echo '
subj: '.$subject.'
body: '.$body.'
from: '.$from.'
from_name: '.$from_name.'
cc_arr: '; var_dump($cc_arr); echo '
bcc_arr: '; var_dump($bcc_arr); echo '
reply_to:'.$reply_to.'
reply_to_name:'.$reply_to_name.'
is_html:'.$is_html.'
image_arr: '; var_dump($image_arr);echo '
attachment_arr: '; var_dump($attachment_arr); */ require_once(Config::$path_to_phpmailer); $mail = new PHPMailer(); // set up mail if(Config::$location == 'remote') { $mail->IsSendmail(); } else { $mail->IsSMTP(); $mail->Host = 'smtp.snet.net'; // default: smtp_port = 25 } $mail->From = ($from == '') ? 'info@'.Config::$domain : $from; $mail->FromName = ($from_name == '') ? Config::$domain : $from_name; foreach($to_arr as $to) { $mail->AddAddress($to); } if($cc_arr != '') { foreach($cc_arr as $cc) { $mail->AddCC($cc); } } //if($bcc_arr == '' && !in_array(Config::$tech_email, $to_arr)) { //$bcc_arr[] = Config::$tech_email; } if($bcc_arr != '') { foreach($bcc_arr as $bcc) { $mail->AddBCC($bcc); } } if($reply_to != '') { $mail->AddReplyTo($reply_to, $reply_to_name); } if($AltBody != '') { $mail->AltBody = $AltBody; } if($wordWrap > 0) { $mail->WordWrap = $wordWrap; } $mail->Subject = $subject; $mail->IsHTML($is_html); // images if($is_html && $image_arr != '') { $i = 0; foreach($image_arr as $image_name=>$image_src) { ++$i; // note image_src should be full path if(!$mail->AddEmbeddedImage($image_src, 'image'.$i, $image_name)) { self::notify(Config::$tech_email, "phpmailer inline image failed", "email subject: $subject\nemail body: $body"); } $body = str_replace('image'.$i, '', $body); } } $mail->Body = $body; // attachments if($attachment_arr != '') { $i = 0; foreach($attachment_arr as $attachment_name=>$attachment_src) { ++$i; if(!$mail->AddAttachment($attachment_src, $attachment_name)) { self::notify(Config::$tech_email, "phpmailer attachment failed", "email subject: $subject\nemail body: $body"); } } } $res = $mail->Send(); if($mail->ErrorInfo != '') { //echo $subject.'
'.$body; //self::notify(Config::$tech_email, "PHPMailer Email Failed", "$res\n\n".$mail->ErrorInfo); } } } static public function date_compare($d1, $d2) { // inputs 2 mysql dates and returns d1 - d2 in seconds if(!self::is_mysql_date($d1) || !self::is_mysql_date($d2)) { return(FALSE); } return(self::convert_mysql_date_to_mktime($d1) - self::convert_mysql_date_to_mktime($d2)); } static public function convert_mysql_date_to_mktime($date) { if(!self::is_mysql_date($date)) { return(FALSE); } $yr = substr($date, 0, 4); $mo = substr($date, 5, 2); $dy = substr($date, 8, 2); return(mktime(0,0,0,$mo,$dy,$yr)); } static public function is_mysql_dt($dt) { // Y-m-d H:i:s (yyyy-mm-dd hh:mm:ss military) // should use a reg ex if(strlen($dt) != 19) { return(FALSE); } if(!self::is_mysql_date(substr($dt, 0, 10))) { return(FALSE); } $hr = substr($dt, 11, 2); $mi = substr($dt, 14, 2); $se = substr($dt, 17, 2); if(!is_numeric($hr) || $hr > 23) { return(FALSE); } if(!is_numeric($mi) || $mi > 59) { return(FALSE); } if(!is_numeric($se) || $se > 59) { return(FALSE); } return(TRUE); } static public function convert_time_to_sec($min=0,$hr=0,$day=0) { return($min*60+$hr*60*60+$day*24*60*60); } static public function is_mysql_date($date) { // yyyy-mm-dd // should use a reg ex if(strlen($date) != 10) { return(FALSE); } $yr = substr($date, 0, 4); $mo = substr($date, 5, 2); $dy = substr($date, 8, 2); if(substr($yr, 0, 2) != '20') { return(FALSE); } if($mo > 12 || !is_numeric($mo) || (substr($mo, 0, 1) != '0' && substr($mo, 0, 1) != '1') ) { return(FALSE); } if($dy > 31 || !is_numeric($dy) || (substr($mo, 0, 1) != '0' && substr($mo, 0, 1) != '1') ) { return(FALSE); } if(substr($date, 4, 1) != "-" || substr($date, 7, 1) != "-" ) { return(FALSE); } return(TRUE); } static public function formal_date($mysql_date, $show_year=TRUE) { if(!self::is_mysql_date($mysql_date)) { //echo 'invalid date format'; return(FALSE); } $d = ($show_year) ? date("F jS, Y", mktime(date("H"), date("i"), date("s"), (int) substr($mysql_date, 5, 2), (int) substr($mysql_date, 8, 2), (int) substr($mysql_date, 0, 4))) : date("F jS", mktime(date("H"), date("i"), date("s"), (int) substr($mysql_date, 5, 2), (int) substr($mysql_date, 8, 2), (int) substr($mysql_date, 0, 4))); return($d); } static public function informal_date($mysql_date) { if(!self::is_mysql_date($mysql_date)) { //echo 'invalid date format'; return(FALSE); } $d = date("m/d/y", mktime(date("H"), date("i"), date("s"), (int) substr($mysql_date, 5, 2), (int) substr($mysql_date, 8, 2), (int) substr($mysql_date, 0, 4))); return($d); } static public function enum_get_options($field="",$table="") { $result=mysql_query("SHOW COLUMNS FROM `$table` LIKE '$field'"); if(mysql_num_rows($result)>0){ $row=mysql_fetch_row($result); $options=explode("','", preg_replace("/(enum|set)\('(.+?)'\)/","\\2", $row[1])); } else { $options=array(); } return $options; } static public function date_in_range($date, $sdate, $edate) { // only for date, not dt //echo '
checking '.$date.' in range ('.$sdate.', '.$edate.')'; // sdate or edate can be blank if( !self::is_mysql_date($date) || ($sdate != '' && !self::is_mysql_date($sdate)) || ($edate != '' && !self::is_mysql_date($edate)) ) { //self::notify(Config::$tech_email, 'invalid date format sent to Utilities::date_in_range', $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']); echo 'fail one: '.$date.' in range ('.$sdate.', '.$edate.')'; return(FALSE); } if($sdate == '' && $edate == '') { //self::notify(Config::$tech_email, 'invalid date format sent to Utilities::date_in_range', $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']); echo 'fail two: '.$date.' in range ('.$sdate.', '.$edate.')'; return(FALSE); } if($sdate == '') { return (self::date_compare($edate, $date) >= 0) ? TRUE : FALSE; } if($edate == '') { return (self::date_compare($date, $sdate) >= 0) ? TRUE : FALSE; } return (self::date_compare($date, $sdate) >= 0 && self::date_compare($edate, $date) >= 0) ? TRUE : FALSE; } static public function date_adjust($mysql_date_dt, $hr_adj, $min_adj=0, $sec_adj=0, $yr_adj=0, $mo_adj=0, $day_adj=0) { $mysql_date_dt = trim($mysql_date_dt); // input can either be date or dt if(strlen($mysql_date_dt) == 10 && !self::is_mysql_date($mysql_date_dt)) { //echo 'invalid date format'; return(FALSE); } if(strlen($mysql_date_dt) == 19 && !self::is_mysql_dt($mysql_date_dt)) { //echo 'invalid date format'; return(FALSE); } elseif(strlen($mysql_date_dt) != 10 && strlen($mysql_date_dt) != 19) { //echo 'invalid date format'; return(FALSE); } // 2007-12-17 12:22:44 // 0123456789012345678 $yr = substr($mysql_date_dt, 0, 4) + $yr_adj; $mo = substr($mysql_date_dt, 5, 2) + $mo_adj; $day = substr($mysql_date_dt, 8, 2) + $day_adj; if(strlen($mysql_date_dt) == 19) { $hr = substr($mysql_date_dt, 11, 2) + $hr_adj; $min = substr($mysql_date_dt, 14, 2) + $min_adj; $sec = substr($mysql_date_dt, 17, 2) + $sec_adj; $newdate_dt = date("Y-m-d H:i:s", mktime ($hr, $min, $sec, $mo, $day, $yr) ); } else { $newdate_dt = date("Y-m-d", mktime (0, 0, 0, $mo, $day, $yr) ); } return($newdate_dt); } static public function date_in_past($mysql_date) { if(!self::is_mysql_date($mysql_date)) { //echo 'invalid date format'; return(FALSE); } $today = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $comp = mktime(0, 0, 0, date(substr($mysql_date, 5, 2)), date(substr($mysql_date, 8, 2)), date(substr($mysql_date, 0, 4))); return($comp < $today); } static public function date_convert_to_mysql($date) { // input can be mm/dd/yy or m/d/y $dp = explode("/", $date); $yyyy = (strlen($dp[2]) == 4) ? $dp[2] : '20'.$dp[2]; $dd = (strlen($dp[1]) == 2) ? $dp[1] : '0'.$dp[1]; $mm = (strlen($dp[0]) == 2) ? $dp[0] : '0'.$dp[0]; return("$yyyy-$mm-$dd"); } static public function get_current_script() { // returns page name and query string $qs = ($_SERVER['QUERY_STRING'] != '') ? '?'.$_SERVER['QUERY_STRING'] : ''; return($_SERVER['SCRIPT_NAME'].$qs); } } ?>