"; } function checkAdmin() { if (!verifyAdmin()) { $host = $_SERVER['HTTP_HOST']; $page = 'vineyards/'; $thisPage = $_SERVER['PHP_SELF']; $thisPage .= ($_SERVER['QUERY_STRING'] == "" ? "" : "?".$_SERVER['QUERY_STRING']); setMessage("error", "Unauthorized Access"); header("Location: http://$host/$page?redirect=".urlencode($thisPage)); die(); } } # # This function checks if email is valid # function checkEmail($email) { # # Simplified checking # $email_regular_expression = "^([-\d\w][-.\d\w]*)?[-\d\w]@([-!#\$%&*+\\/=?\w\d^_`{|}~]+\.)+[a-zA-Z]{2,6}$"; # # Full checking according to RFC 822 # Uncomment the line below to use it # $email_regular_expression = "^[^.]{1}([-!#\$%&'*+.\\/0-9=?A-Z^_`a-z{|}~])+[^.]{1}@([-!#\$%&'*+\\/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}$"; return preg_match("/".$email_regular_expression."/iS", safe_email(stripslashes($email))); } function checkRequiredFields($reqFields) { // usage: $errMsg = checkRequiredFields($arrRequiredFields) $retVal = array(); foreach($reqFields as $fldName=>$fldText) { if (trim($_POST[$fldName]) == "") { $retVal[] = $fldText ." is required."; } } return $retVal; } function debug($text) { if (!isset($_SESSION["messages"]["notify"])) { $_SESSION["messages"]["notify"] = ""; } $text = is_array($text) ? print_r($text, true) : wordwrap(print_r($text, true), 110, "
"); $_SESSION["messages"]["notify"] .= "
".$text."
"; } function error_die($message = "unspecified error") { //only redirect if headers are not already sent. Otherwise show crude error message if (headers_sent()) { echo '
An error occurred:
'; echo '***********************************'; echo '
'.$message.'
'; echo '***********************************'; echo '
Please contact the site admin
'; } else { header("location: http://".$_SERVER['HTTP_HOST']."/error.php?msg=".urlencode($message)); } die(); } function formatBlockRowNumber($s) { return str_pad(strval($s), 3, '0', STR_PAD_LEFT); } function formatGender($g, $abbrev=true) { switch ($g) { case 1: return $abbrev ? "M" : "Male"; break; case 2: return $abbrev ? "F" : "Female"; break; default: return ""; } } function sql_str($str, $bUseNull=true, $bAllowHTML=false) { //$ALLOWED_HTML_TAGS is set in config.php global $ALLOWED_HTML_TAGS; if (trim($str)=="") { if ($bUseNull) $sTemp = "NULL"; else $sTemp = "''"; } else { if ($bAllowHTML) { $sTemp = "'".str_replace("'", "''",trim(stripslashes($str)))."'"; } else { $sTemp = "'".str_replace("'", "''",trim(strip_tags(stripslashes($str),$ALLOWED_HTML_TAGS)))."'"; } } return $sTemp; } function sql_num($num, $bUseNull=true) { if (trim($num) == "" || !is_numeric($num)) { if ($bUseNull) $sTemp = "NULL"; else $sTemp = "0"; } else $sTemp = $num; return $sTemp; } function getCurrentUser() { if (isset($_SESSION["user"]) && $_SESSION["user"]["id"]) { return $_SESSION["user"]["id"]; } return ""; } function getFirstParagraphs($string, $length = 999999, $count = 1, $ellipsis = "...") { //$length: the maximum length of text to return //$count: the number of paragraphs to retrieve. $paragraph = explode("\n", $string); if($count < count($paragraph)) { for($i = 0; $i < $count; $i++) { if($i < $count - 1) { $output .= $paragraph[$i] . "\n"; } else { $output .= $paragraph[$i]; } } if (strlen($output) > $length) { $output = substr($output,0,$length) . $ellipsis; } return trim($output); } if (strlen($string) > $length) { $string = substr($string,0,$length); //trim end characters in case it's a word fragment. $words = explode(" ",$string); $words[count($words)-1] = ""; $string = implode(" ",$words); return $string.$ellipsis; } else { return $string; } } # function getLanguage() { //1 = english, 2 = spanish global $LANGUAGES, $_GET; $lang = (isset($_GET["lang"]) && $_GET["lang"] != "") ? $_GET["lang"] : 1; if (!array_key_exists($lang,$LANGUAGES)) { $lang = 1; } return $lang; } function getMonthString($mNum) { $timestamp = mktime(0, 0, 0, $mNum, 1, 2000); return date("M", $timestamp); } function getPagingNav($recCount, $perPage, $curPage, $qs=array(), $ajax=false) { # $recCount: count of all records in resultset # $perPage: number of records to display per page # $curPage: the current page number # $qs: an array of querystring values to append to the link # $ajax: if true then use getPage() function. Must define getPage() on each page to handle the click $numPages = ceil($recCount / $perPage); if ($numPages == 1) return ""; if ($curPage > $numPages) $curPage = $numPages; $nav = ""; $strQS = ""; if (!empty($qs)) { foreach ($qs as $key=>$val) { $strQS .= "&".$key."=".urlencode($val); } } if($curPage > 1) { if ($ajax) { $nav .= '<< Prev |'; } else { $nav .= '<< Prev |'; } } for($i = 1; $i < $numPages+1; $i++) { if($curPage == $i) { // Bold the page and dont make it a link $nav .= ' '.$i.' |'; } else { // Link the page if ($ajax) { $nav .= ' '.$i.' |'; } else { $nav .= ' '.$i.' |'; } } } // Can we have a link to the next page? if($curPage < $numPages) { if ($ajax) { $nav .= ' Next >> |'; } else { $nav .= " Next >>"; } } $nav = ereg_replace("\|$", "", $nav); //remove final vertical separator $finalOutput = ''; return $finalOutput; } function getImageOptions($active_only=true) { $active_sql = $active_only ? ' WHERE opt_active = 1 ' : ''; $sql = "SELECT * FROM image_options ".$active_sql." ORDER BY opt_sortorder;"; return func_query($sql); } function genRandomString($length = 8) { $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $len = strlen($salt); $makepass = ''; $stat = @stat(__FILE__); if(empty($stat) || !is_array($stat)) $stat = array(php_uname()); mt_srand(crc32(microtime() . implode('|', $stat))); for ($i = 0; $i < $length; $i ++) { $makepass .= $salt[mt_rand(0, $len -1)]; } return $makepass; } function getSettingValue($settingname, $link="") { global $RR_SETTINGS; if (isset($RR_SETTINGS[$settingname])) { return $RR_SETTINGS[$settingname]; } else { $sql = "select setting_value from settings where setting_name=".sql_str($settingname); $res = ($link=="") ? mysql_query($sql) : mysql_query($sql, $link); if ($row=mysql_fetch_array($res)) { return $row["setting_value"]; } else return false; } } function getCustomerInfo($id) { $sql = "SELECT * FROM customers WHERE id = " . sql_num($id); return func_query_first($sql); } function getVal(&$val,$default='') { return (isset($val))?$val:$default; } function left($sString, $numPos) { if (!is_string($sString)) return ''; return substr($sString, 0, $numPos); } function right($sString, $numPos) { if (!is_string($sString)) return ''; $strLen = strlen($sString); return substr($sString, $strLen - $numPos, $strLen); } function hashPassword($username, $password) { $passhash = sha1(strtolower($username).$password); return $passhash; } function html_checkbox_array($data, $name, $id, $selected = "", $extra_html = "") { $list = ""; if (!empty($data)) { foreach ($data as $val => $txt) { $list .= ''.$txt.''; } } return $list; } function html_drop_down ($name, $id, $tablename, $value_field, $display_field, $other_value = "", $other_display = "", $selected_value = "", $where_clause = "", $orderBy = "") { // build the SQL string $sql = "SELECT " . $value_field . " col_val," . $display_field . " col_disp" . " FROM " . $tablename; if ($where_clause) { $sql .= " " . $where_clause; } if ($orderBy) { $sql .= " order by ".$orderBy; } else { $sql .= " order by col_disp"; } // queries the database, be sure to name your database. $res = mysql_query($sql); // build the select list. if ($res) { $return_value = ""; } else { $return_value .= "No data."; } mysql_free_result($res); return $return_value; } function html_drop_down_array($data, $name, $id, $selected_value = "", $extra_html = "") { $list = '"; return $list; } function imgUpload($file, $real_path, $max_size, $options=array()) { # Options: # allow_text: let users upload text files (possible scripts/viruses, etc # record_id: a unique record id to append to the file name # file_types: a generic type of files to check against (currently only supports image type) $temp_name = $file['tmp_name']; $actual_file_name = trim($file['name']); $file_type = $file['type']; $file_size = $file['size']; $result = $file['error']; $nokb = $max_size / 1024; $nokb = $nokb."kb"; $actual_file_name = preg_replace('/[^a-z0-9_\-\.]/i', '_', $actual_file_name); $arrFile = explode(".", $actual_file_name); $fileNameExt = $arrFile[count($arrFile)-1]; srand(make_seed()); $randval = uniqid(rand().'-'); $filewithnewname = $randval . (isset($options["record_id"]) ? ("_".$options["record_id"]) : "") . "." . $fileNameExt; $uploadfile = $real_path . "/". $filewithnewname; //File Name Check if ($actual_file_name =="") { $message = "Invalid File Name Specified"; return $message; } //File Size Check else if ($file_size > $max_size) { $message = "The file size is over the maximum limit of $nokb."; return $message; } //File Type Check else if ($file_type == "text/plain" && (!isset($options["allow_text"]) || $options["allow_text"] !== true)) { $message = "Sorry, the file type is invalid" ; return $message; } else if (isset($options["file_types"]) && $options["file_types"] == "image" && !validateImgType($temp_name)) { $message = "Please upload a picture of type JPG, GIF, or PNG" ; return $message; } $result = move_uploaded_file($temp_name, $uploadfile); list($fileWidth, $fileHeight, $file_type) = @getimagesize($uploadfile); $succmesg = "success||".$fileWidth."||".$fileHeight."||".$file_size."||".$filewithnewname; // echo $succmesg; $errmessage = "Something is wrong with uploading a file."; if($result) { return $succmesg; } else { return $errmessage ; } } function isDevSite() { return (eregi("ndic\.com$", $_SERVER['HTTP_HOST'])); } function isImage($img) { return getimagesize($img) === false ? false : true; } function is_wp_admin() { if ( !is_user_logged_in() ) { return false; } $role = get_current_user_role(); if( strtolower($role) == 'administrator' || strtolower($role) == 'editor' ) { return true; } else { return false; } //return (get_current_user_role() == 'administrator' || 'editor' ? true : false); //Use WordPress function to check for admin } function get_current_user_role() { global $wp_roles; $current_user = wp_get_current_user(); $roles = $current_user->roles; $role = array_shift($roles); return isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : false; } function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } function myFormatDate($timestamp) { if ($timestamp > 0 && is_numeric($timestamp)) return date("m/d/Y",$timestamp); else return ""; } function myFormatDateTime($timestamp) { if ($timestamp > 0 && is_numeric($timestamp)) return date("m/d/Y H:i:s T",$timestamp); else return ""; } function myFormatTime($timestamp) { if ($timestamp > 0 && is_numeric($timestamp)) return date("h:i a",$timestamp); else return ""; } function mysql_timestamp() { // Convert a UNIX Timestamp into a string, safe for MySql return date("Y-m-d H:i:s", time()); } function mysql_to_US_date($val,$set1900=false) { //Expects $val to be formatted yyyy-mm-dd. Converts to mm/dd/yyyy. if ($val == "" || $val == null) return ($set1900 ? "01/01/1900" : ""); else { if (strpos($val," ")) { //get the date portion only if field is date/time $tmp = explode(" ",$val); $val = $tmp[0]; } $dateparts = explode("-",$val); //print_r($dateparts); if (count($dateparts) == 3) { $dp = array(); $dp[] = $dateparts[1]; $dp[] = $dateparts[2]; $dp[] = $dateparts[0]; #return (string)$dateparts[1] + "/" + (string)$dateparts[2] + "/" + (string)$dateparts[0]; return implode("/",$dp); } else { return ($set1900 ? "01/01/1900" : ""); } } } function out($str, $trim=true) { if ($trim == true) $s = trim($str); return htmlspecialchars(stripslashes($s)); } function redirect($location = '') { if ($location == '') { $location = $_SERVER['PHP_SELF']; } if (!headers_sent()) { header("Location: $location"); } else { echo ''; } die(); } function safe_email($string) { return preg_replace( '((?:\n|\r|\t|%0A|%0D|%08|%09)+)i' , '', $string ); } function setMessage($type, $msg, $overwrite=true) { if (in_array($type, array('notify','warn','error'))) { if ($overwrite || empty($_SESSION['messages'][$type])) { $_SESSION['messages'][$type] = $msg; } } } function truncate($text,$numb,$mid,$wid) { $text = html_entity_decode($text, ENT_QUOTES); if (strlen($text) > $numb) { $text = substr($text, 0, $numb); $text = substr($text,0,strrpos($text," ")); //This strips the full stop: if ((substr($text, -1)) == ".") { $text = substr($text,0,(strrpos($text,"."))); } $text = htmlentities($text, ENT_QUOTES); } return $text; } function txt2html($txt) { //$ALLOWED_HTML_TAGS is defined in config.php global $ALLOWED_HTML_TAGS; return nl2br(strip_tags(htmlspecialchars($txt),$ALLOWED_HTML_TAGS)); } function txt2xml($txt) { //$ALLOWED_HTML_TAGS is defined in config.php global $ALLOWED_HTML_TAGS; return htmlspecialchars(nl2br(strip_tags($txt,$ALLOWED_HTML_TAGS))); } function US_to_mysql_date($val,$set1900=false) { //Expects $val to be formatted mm/dd/yyyy. Converts to yyyy-mm-dd. if ($val == "" || $val == null) return ($set1900 ? "1900-01-01" : ""); else { $dateparts = explode("/",$val); if (count($dateparts) == 3) { $dp = array(); $dp[] = $dateparts[2]; $dp[] = $dateparts[0]; $dp[] = $dateparts[1]; if (strlen($dp[0]) == 2) { $dp[0] = ($dp[0] >= 78 ? "19" : "20") . $dp[0]; } return implode("-",$dp); } else { return ($set1900 ? "1900-01-01" : ""); } } } # a very crude to validate file type, but it helps a little. function validateFileExt($fileNameExt) { $file_types_array=array("JPG","GIF","PNG"); $ext = strtoupper($fileNameExt); return in_array($ext, $file_types_array); } function validateImgType($file) { $file_types_array=array(IMAGETYPE_GIF,IMAGETYPE_JPEG,IMAGETYPE_PNG); return in_array(exif_imagetype($file), $file_types_array); } function validateFileUpload($file, $uploadpath, $arrFileType = array()) { global $MAX_FILE_SIZE; $arrReturn = array(); $arrReturn["result"] = false; if ($file['imageFile']['name'] != "") { if ($file['imageFile']['size'] > $MAX_FILE_SIZE || $file['imageFile']['size'] == 0) { $arrReturn["errMsg"] = "The file size is invalid."; } else { $filename = trim($file['imageFile']['name']); $filename = preg_replace('/[^a-z0-9_\-\.]/i', '_', $filename); $arrFile = explode(".", $filename); $fileNameExt = $arrFile[count($arrFile)-1]; $validFileType = false; foreach($arrFileType as $k => $v) { if (strtolower($fileNameExt)==strtolower($v)) $validFileType = true; } if (!$validFileType) { $arrReturn["errMsg"] = "The file extension is invalid."; } else { $uploadfile = $uploadpath . "/" . $filename; if (!@move_uploaded_file($_FILES['imageFile']['tmp_name'], $uploadfile)) { $arrReturn["errMsg"] = "File could not be uploaded."; } else { list($fileWidth, $fileHeight, $fileType) = @getimagesize($uploadfile); $arrReturn["uploadfile"] = $uploadfile; $arrReturn["filename"] = $filename; $arrReturn["filesize"] = @filesize($uploadfile); $arrReturn["result"] = true; } } //file extension check } //maxfilesize check } else { $arrReturn["result"] = true; } return $arrReturn; } function verifySession() { if (!verifyAdmin()) { $host = $_SERVER['HTTP_HOST']; $page = 'vineyards/index.php'; $thisPage = $_SERVER['PHP_SELF']; $thisPage .= ($_SERVER['QUERY_STRING'] == "" ? "" : "?".$_SERVER['QUERY_STRING']); header("Location: http://$host/$page?redirect=".urlencode($thisPage)); die(); } } function verify_wp_admin() { if (!is_wp_admin()) { $host = $_SERVER['HTTP_HOST']; $page = 'wp-login.php'; $thisPage = $_SERVER['PHP_SELF']; $thisPage .= ($_SERVER['QUERY_STRING'] == "" ? "" : "?".$_SERVER['QUERY_STRING']); header("Location: http://$host/$page?redirect_to=".urlencode($thisPage)."&reauth=1"); die(); } } function verifyAdmin() { $validUser = false; if (isset($_SESSION["user"])) { $user_id = $_SESSION["user"]["id"]; $hashpass = $_SESSION["user"]["hashpass"]; if (is_numeric($user_id)) { $sql = "select active from admin where id = ".sql_num($user_id)." and password = ".sql_str($hashpass).";"; $res = mysql_query($sql); if (mysql_num_rows($res) > 0) { $user = mysql_fetch_assoc($res); if ($user['active'] == 1) { $validUser = true; } } } } return $validUser; } ?> $maxWidth || $imageHeight > $maxHeight) { if ($imageWidth > $maxWidth) { $resizedWidth = $maxWidth; $resizedHeight = $resizedWidth*$ratio; } else { $resizedWidth = $imageWidth; $resizedHeight = $imageHeight; } if ($resizedHeight > $maxHeight) { $resizedHeight = $maxHeight; $resizedWidth = $resizedHeight/$ratio; } $resizedImage = imagecreatetruecolor($resizedWidth,$resizedHeight); imagecopyresampled($resizedImage,$imageSource,0,0,0,0,$resizedWidth,$resizedHeight,$imageWidth,$imageHeight); } else { //$resizedWidth = $imageWidth; //$resizedHeight = $imageHeight; $resizedImage = $imageSource; } $outputFunction($resizedImage,$newDir."/".$newImage,$quality); return true; } else return false; } function getImage($imageid) { $arrRes = array(); $sql = "SELECT * FROM member_images WHERE image_id = ".formatSQL_Str($imageid); $sql .= " LIMIT 1;"; $res = mysql_query($sql); if ($res && mysql_num_rows($res) > 0) { while ($row = mysql_fetch_assoc($res)) { foreach ($row as $key=>$val) { $arrRes[$key] = $val; } } } else { return array("image_id"=>0,"filename"=>"noimage.gif", "title"=>"", "description"=>"", "image_type"=>"", "height"=>"", "width"=>""); } return $arrRes; } function getScaledSize($origW, $origH, $maxW, $maxH) { # Returns an array of the scaled height and width values of an # image, with theaspect ration maintained. Pass zero values # to $maxW or $maxH to disable resizing of the dimension. $maxW = $maxW == 0 ? 99999 : $maxW; $maxH = $maxH == 0 ? 99999 : $maxH; if ($origW == 0) { $ratio = 0; } else { $ratio = ($origH/$origW); } if ($origW > $maxW || $origH > $maxH) { if ($origW > $maxW) { $resizedWidth = $maxW; $resizedHeight = $resizedWidth*$ratio; } else { $resizedWidth = $origW; $resizedHeight = $origH; } if ($resizedHeight > $maxH) { $resizedHeight = $maxH; if ($ratio == 0) { $resizedWidth = 0; } else { $resizedWidth = $resizedHeight/$ratio; } } } else { $resizedHeight = $origH; $resizedWidth = $origW; } return array("width" => $resizedWidth, "height" => $resizedHeight); } ?>" . $row["password"] . "
"); if ($row["password"]!=$hashpass) { return false; } elseif ($row["active"] != 1) { setMessage("notify", "Your account is not activated. Please contact us for support."); header("location: http://".$_SERVER['HTTP_HOST']."/admin"); die(); } else { $_SESSION["user"] = array( "id" => $row["id"], "email" => $row["email"], "hashpass" => $hashpass ); if ($redir{0} == "/") { $redir = substr($redir, 1, strlen($redir)); } header("location: http://".$_SERVER['HTTP_HOST']."/".$redir); die(); } } } } } return false; } function logout() { session_start(); session_destroy(); } function setLoginCookie($cookie_length, $id, $passhash="", $salt="") { global $cookie_name, $cookie_url, $cookie_domain; $password = sha1($passhash.$salt); global $SITE_URL, $modSettings; // The cookie may already exist, and have been set with different options. $cookie_state = 0; if (isset($_COOKIE[$cookie_name])) { $array = @unserialize($_COOKIE[$cookie_name]); // Out with the old, in with the new! if (isset($array[3]) && $array[3] != $cookie_state) { setcookie($cookie_name, serialize(array(0, '', 0)), time() - 3600, $cookie_url, $cookie_domain, 0); } } // Get the data. $data = serialize(empty($id) ? array(0, '', 0) : array($id, $password, time() + $cookie_length, $cookie_state)); // Set the cookie, $_COOKIE, and session variable. setcookie($cookie_name, $data, time() + $cookie_length, $cookie_url, $cookie_domain, 0); //$_SESSION['login_' . $cookie_name] = $data; } function usernameExists($user) { $sql = "SELECT 1 FROM users WHERE usr_username = " . sql_str($user); return func_query($sql); } function emailExists($email) { $sql = "SELECT 1 FROM users WHERE usr_email = " . sql_str($email); return func_query($sql); } function activateUser($username, $token) { $activated = false; $sql = "SELECT 1 FROM users WHERE usr_username = " . sql_str($username) . " and usr_activation = " . sql_str($token); $user = func_query($sql); if ($user) { $sql = "UPDATE users SET usr_activation = null, usr_active = 1 WHERE usr_username = " . sql_str($username) . " and usr_activation = " . sql_str($token); mysql_query($sql); $activated = true; } return $activated; } function valid_pass($candidate) { $r1='/[A-Z]/'; //Uppercase $r2='/[a-z]/'; //lowercase //$r3='/[!@#$%^&*()\-_=+{};:,<.>]/'; // whatever you mean by 'special char' $r4='/[0-9]/'; //numbers if(preg_match_all($r1,$candidate, $o)<1) return false; if(preg_match_all($r2,$candidate, $o)<1) return false; //if(preg_match_all($r3,$candidate, $o)<1) return false; if(preg_match_all($r4,$candidate, $o)<1) return false; if(strlen($candidate)<7) return false; return true; } function password_rules_text() { return 'The new password must be at least 7 characters and contain
at least 1 number, 1 lowercase letter, and 1 uppercase letter.'; } ?>$v) { if (!(($v{0} == '`') && ($v{strlen($v)-1} == '`'))) $arr_keys[$k] = "`$v`"; } $arr_values = array_values($arr); foreach ($arr_values as $k=>$v) { if ((!(($v{0} == '"') && ($v{strlen($v)-1} == '"'))) && (!(($v{0} == "'") && ($v{strlen($v)-1} == "'")))) { $arr_values[$k] = "'$v'"; } } $query .= " INTO $tbl (" . implode(", ", $arr_keys) . ") VALUES (" . implode(", ", $arr_values) . ")"; echo $query; $r = mysql_query($query); if ($r) { return mysql_insert_id(); } return false; } # # Update array data to table + where statament # function db_array2update ($tbl, $arr, $where = '') { global $sql_tbl; if (empty($tbl) || empty($arr) || !is_array($arr)) return false; if ($sql_tbl[$tbl]) $tbl = $sql_tbl[$tbl]; $r = array(); foreach ($arr as $k => $v) { if (!(($k{0} == '`') && ($k{strlen($k)-1} == '`'))) $k = "`$k`"; if ((!(($v{0} == '"') && ($v{strlen($v)-1} == '"'))) && (!(($v{0} == "'") && ($v{strlen($v)-1} == "'")))) { $v = "'$v'"; } $r[] = "$k=$v"; } $query = "UPDATE $tbl SET ". implode(", ", $r) . ($where ? " WHERE " . $where : ""); return mysql_query($query); } function db_result_to_array($result) { $arrRes = array(); $count = 0; if ($result && mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { foreach ($row as $key=>$val) { $arrRes[$count][$key] = $val; } $count++; } } else { return false; } return $arrRes; } function formatSQL_Str($str, $bUseNull=true) { if (trim($str)=="") { if ($bUseNull) $sTemp = "NULL"; else $sTemp = "''"; } else { $sTemp = "'".str_replace("'", "''",trim(stripslashes($str)))."'"; } return $sTemp; } function formatSQL_Num($num, $bUseNull=true) { if (trim($num) == "" || !is_numeric($num)) { if ($bUseNull) $sTemp = "NULL"; else $sTemp = "0"; } else $sTemp = $num; return $sTemp; } ?>