Get("variable_with_id", 60); if (!$variable) { // Cache file expired or is inexistant // Do something to get new data $cache->Set("variable_with_id", $newdata); $variable = $newdata; } echo $variable; **/ class Cacher { // Where things are cached to (must have trailing slash!) var $cacheDir = "smarty/cache/"; // How long to cache something for in seconds, default 1hr var $defaultCacheLife = "3600"; function Cacher() { $_rDir = dirname(dirname(dirname(__FILE__))); $this->cacheDir = $_rDir . "/" . $this->cacheDir; } /** SetCacheDir($varValue) -- Sets the path to cache directory. **/ function SetCacheDir($varValue) { // Clean up old caches with same varId if ($varValue != '') $this->cacheDir = $varValue; } /** Set($varId, $varValue) -- Creates a file named "cache.VARID.TIMESTAMP" and fills it with the serialized value from $varValue. If a cache file with the same varId exists, Delete() will remove it. **/ function Set($varId, $varValue) { // Clean up old caches with same varId $this->Delete($varId); // Create new file $fileHandler = fopen($this->cacheDir . "cache." . $varId . "." . time(), "a"); // Write serialized data fwrite($fileHandler, serialize($varValue)); fclose($fileHandler); } /** Get($varID, $cacheLife) -- Retrives the value inside a cache file specified by $varID if the expiration time (specified by $cacheLife) is not over. If expired, returns FALSE **/ function Get($varId, $cacheLife="") { // Set default cache life $cacheLife = (!empty($cacheLife)) ? $cacheLife : $this->defaultCacheLife; /* Loop through the directory looking for cache file */ $dirHandler = dir($this->cacheDir); while ($file = $dirHandler->read()) { /* Check for cache file with requested varId */ if (preg_match("/cache.$varId.[0-9]/", $file)) { $cacheFileName = explode(".", $file); // Cache file creation time $cacheFileLife = $cacheFileName[2]; // Full location $cacheFile = $this->cacheDir . $file; /* Check to see if cache file has expired or not */ if ((time() - $cacheFileLife) < $cacheLife) { $fileHandler = fopen($cacheFile, "r"); $varValueResult = fread($fileHandler, filesize($cacheFile)); fclose($fileHandler); // Still good, return unseralized data return unserialize($varValueResult); } else { // Cache expired, break loop break; } } } $dirHandler->close(); return FALSE; } /** Delete($varId) -- Loops through the cache directory and removes any cache files with the varId specified in $varID **/ function Delete($varId) { $dirHandler = dir($this->cacheDir); while ($file = $dirHandler->read()) { if (preg_match("/cache.$varId.[0-9]/", $file)) { unlink($this->cacheDir . $file); // Delete cache file } } $dirHandler->close(); } } ?>connect($g_db_host, $g_db_username, $g_db_password, $g_db) or die("Cannot connect to DB"); /* $rs = $dbConn->query("set character_set_client = 'cp1251'"); $rs = $dbConn->query("set character_set_results='cp1251'"); $rs = $dbConn->query("set collation_connection='cp1251_general_ci'"); */ $result = $dbConn->query($sql) or die("Cannot get recordset
" . mysql_error()."
".$sql); $dbConn->disconnect(); unset($dbConn); unset($rs); //error_reporting (E_ALL ^ E_NOTICE); return (gettype($result) == "object"); } //-------------------------------------- // EXEC QUERY //-------------------------------------- function ExecQuery($sql) { global $dbms, $g_db_host, $g_db, $g_db_username, $g_db_password; error_reporting(0); $dbConn = new DB(); $dbConn->connect($g_db_host, $g_db_username, $g_db_password, $g_db) or die("Cannot connect to DB"); /* $rs = $dbConn->query("set character_set_client='cp1251'"); $rs = $dbConn->query("set character_set_results='cp1251'"); $rs = $dbConn->query("set collation_connection='cp1251_general_ci'"); */ $result = $dbConn->query($sql) or die("Cannot execute sql
" . mysql_error()."
".$sql); $dbConn->disconnect(); unset($dbConn); unset($rs); //error_reporting (E_ALL ^ E_NOTICE); return ($result); } //-------------------------------------- // PREPARED CONNECTION //-------------------------------------- function &PrepareCon() { global $dbms, $g_db_host, $g_db, $g_db_username, $g_db_password; error_reporting(0); $dbConn = new DB(); $dbConn->connect($g_db_host, $g_db_username, $g_db_password, $g_db) or die("Cannot connect to DB"); /* $rs = $dbConn->query("set character_set_client = 'cp1251'"); $rs = $dbConn->query("set character_set_results='cp1251'"); $rs = $dbConn->query("set collation_connection='cp1251_general_ci'"); */ unset($rs); //error_reporting (E_ALL ^ E_NOTICE); return $dbConn; } class DB { var $connection; var $result; function &connect($g_db_host, $g_db_username, $g_db_password, $g_db) { // $this->connection = @mysql_connect($g_db_host, $g_db_username, $g_db_password)//, 'link_id', MYSQL_CLIENT_COMPRESS) $this->connection = @mysql_pconnect($g_db_host, $g_db_username, $g_db_password)//, 'link_id', MYSQL_CLIENT_COMPRESS) or die("Cannot connect to DB"); mysql_select_db($g_db, $this->connection) or die ('Can\'t use ' . $g_db . ' : ' . mysql_error()); return $this->connection; } function &query($query) { $result = @mysql_query($query, $this->connection); if (is_resource($result)) { //return $result; $this->result = $result; return $this; } else { if (strpos(strtoupper($query), "UPDATE") !== false || strpos(strtoupper($query), "REPLACE") !== false || strpos(strtoupper($query), "DELETE") !== false || strpos(strtoupper($query), "INSERT") !== false) { return (mysql_errno() == 0); } else { return false; } } } function &disconnect() { $ret = @mysql_close($this->connection); $this->connection = null; return $ret; } function fetchRow($fetchmode = 0) { if ($fetchmode == DB_FETCHMODE_ASSOC) { return @mysql_fetch_array($this->result, MYSQL_ASSOC); } else { return @mysql_fetch_array($this->result, MYSQL_NUM); } } function numRows() { return mysql_num_rows($this->result); } } ?>", ">", str_replace("<", "<", $st)))); else return ""; } function ShowHTML($st) { if (trim($st) != "") return str_replace(array(">", "<", """, "&", " "), array(">", "<", "\"", "&", " "), $st); else return ""; } function Right($str, $count){ return substr ($str, (-$count)); } function Left($str, $count){ return substr ($str, 0, $count); } function sortme($a,$b) { // setup $n = 1; $m = 1; if ( $a[$n] == $b[$n] ) return 0; return ($a[$n] > $b[$n]) ? $m : -1*$m; } function ImageFileDelete($str_file, $strRelativePath) { if (file_exists(@realpath($strRelativePath . $str_file))) @unlink (@realpath($strRelativePath . $str_file)); } function stri_replace($find,$replace,$string) { if(!is_array($find)) $find = array($find); if(!is_array($replace)) { if(!is_array($find)) $replace = array($replace); else { // this will duplicate the string into an array the size of $find $c = count($find); $rString = $replace; unset($replace); for ($i = 0; $i < $c; $i++) { $replace[$i] = $rString; } } } foreach($find as $fKey => $fItem) { $between = explode(strtolower($fItem),strtolower($string)); $pos = 0; foreach($between as $bKey => $bItem) { $between[$bKey] = substr($string,$pos,strlen($bItem)); $pos += strlen($bItem) + strlen($fItem); } $string = implode($replace[$fKey],$between); } return($string); } function ClearSmartyCache() { $smarty = new Smarty_Init; $smarty->clear_all_cache(); unset($smarty); } function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function dump($var, $vardump = false, $return = false) { static $dumpCnt; if (is_null($dumpCnt)) { $dumpCnt = 0; } ob_start(); echo 'DUMP #' . $dumpCnt . ': '; echo '

'; echo '

';
	if ($vardump) {
		var_dump($var);
	} else {
		print_r($var);
	}
	echo '
'; echo '

'; $cnt = ob_get_contents(); ob_end_clean(); $dumpCnt++; if ($return) { return $cnt; } else { echo $cnt; } } function ClearString($str) { $str = GetString($str); return str_replace(" ", "_", $str); } function RandomString($len = "64"){ $ret = NULL; for($i=0; $i<$len; $i++) { $char = chr(rand(48,122)); while (!ereg("[a-zA-Z0-9]", $char)){ if($char == $lchar) continue; $char = chr(rand(48,90)); } $ret .= $char; $lchar = $char; } return $ret; } function buildTemplateName($category_name) { $template_name = buildBaseName($category_name); $template_name = strtolower($template_name) . ".htm"; return $template_name; } function buildBaseName($category_name) { $template_name = str_replace('&', '', $category_name); $template_name = str_replace('&', '', $template_name); $template_name = str_replace('\'', '', $template_name); $template_name = str_replace(',', '', $template_name); $template_name = str_replace(' ', ' ', $template_name); $template_name = str_replace(' ', '_', $template_name); return $template_name; } ?>fetchRow(); if (!($recordcount > 0)) { unset($res); unset($result); $sql = "SELECT COUNT(*) FROM " . DB_PREFIX . "users WHERE login = '" . DoQuote($login) . "' OR screenname = '" . DoQuote($screenname) . "'"; $res = GetRS($result, $sql); if ($res) { list($recordcount) = $result->fetchRow(); if ($recordcount > 0) { $user_id = -1; return true; } } else { $user_id = 0; return true; } unset($res); unset($result); } } else { $user_id = 0; return false; } if ($user_id == 0) { $user_id = "NULL"; $sql = "REPLACE " . DB_PREFIX . "users SET user_id=" . $user_id . ", login ='" . DoQuote($login) . "'" . ", password ='" . DoQuote($password) . "'" . ", email ='" . DoQuote($email) . "'" . ", screenname='" . DoQuote($screenname) . "'" . ", first_name='" . DoQuote($first_name) . "'" . ", last_name ='" . DoQuote($last_name) . "'" . ", address1 ='" . DoQuote($address1) . "'" . ", address2 ='" . DoQuote($address2) . "'" . ", city ='" . DoQuote($city) . "'" . ", zip ='" . DoQuote($zip) . "'" . ", phone ='" . DoQuote($phone) . "'" . ", enabled = " . $enabled . ", user_type = " . $user_type . ", reg_date = NOW()"; } else { $sql = "UPDATE " . DB_PREFIX . "users SET login='" . DoQuote($login) . "'" . ", password ='" . DoQuote($password) . "'" . ", email ='" . DoQuote($email) . "'" . ", screenname='" . DoQuote($screenname) . "'" . ", first_name='" . DoQuote($first_name) . "'" . ", last_name ='" . DoQuote($last_name) . "'" . ", address1 ='" . DoQuote($address1) . "'" . ", address2 ='" . DoQuote($address2) . "'" . ", city ='" . DoQuote($city) . "'" . ", zip ='" . DoQuote($zip) . "'" . ", phone ='" . DoQuote($phone) . "'" . ", enabled = " . $enabled . ", user_type = " . $user_type . " WHERE user_id=" . $user_id; } $dbConns = PrepareCon(); $result = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
".$sql); if ($result) { if ($user_id == "NULL") { $sql = "select LAST_INSERT_ID()"; $subresult = $dbConns->query($sql); if ($subresult) { list($user_id) = $subresult->fetchRow(); } } $dbConns->disconnect(); return ($user_id > 0); } else { return false; } } //'================================================================================== //' Purpose: //' Deletes user //' Return Values: //' True if succeeded //'================================================================================== function userDelete($user_id) { $result = false; if (ExecQuery("DELETE FROM " . DB_PREFIX . "users WHERE user_id = " . $user_id)) $result = true; // if (ExecQuery("DELETE FROM " . DB_PREFIX . "users WHERE user_id = ?", array($user_id))) $result = true; return $result; } //'================================================================================== //' Purpose: //' Searches for users //' Return Values: //' True if succeeded //'================================================================================== function userGet(&$rs, $user_id, $login, $email, $first_name, $last_name, $user_type) { $login = DoQuote($login); $email = DoQuote($email); $first_name = DoQuote($first_name); $last_name = DoQuote($last_name); $sql = "SELECT * FROM " . DB_PREFIX . "users WHERE ($user_id = 0 OR `user_id` = " . $user_id . ") AND ('$login' = '' OR login LIKE '%" . ($login) . "%') AND ('$email' = '' OR email LIKE '%" . ($email) . "%') AND ('$first_name' = '' OR first_name LIKE '%" . ($first_name) . "%') AND ('$last_name' = '' OR last_name LIKE '%" . ($last_name) . "%') AND ($user_type = 0 OR user_type = " . $user_type . ")"; return GetRS($rs, $sql); } //'================================================================================== //' Purpose: //' Searches for authors registered with SLOR //' Return Values: //' True if succeeded //'================================================================================== function SLORAuthorsGet(&$rs) { $sql = "SELECT u.* FROM " . DB_PREFIX . "users u, " . DB_PREFIX . "business_listings bl WHERE ( (u.`first_name` IS NOT NULL) OR (u.`last_name` IS NOT NULL) ) AND (u.user_type <> 1) AND (bl.user_id IS NOT NULL) AND (u.user_id = bl.user_id) ORDER BY last_name, first_name"; return GetRS($rs, $sql); } function SLORReviewersGet(&$rs) { $sql = "SELECT u.* FROM " . DB_PREFIX . "users u WHERE (u.user_type <> 1) AND login NOT LIKE 'business%' AND login NOT LIKE 'alex.kolesnik%' ORDER BY u.login"; return GetRS($rs, $sql); } function SLORBuildReviewersCnt() { $arr_votes = array(); $sql = "SELECT u.user_id, count(v.vote_id) votes FROM " . DB_PREFIX . "users u LEFT JOIN " . DB_PREFIX . "vote v ON u.user_id = v.user_id GROUP BY v.user_id ORDER BY u.user_id"; if (GetRS($result, $sql)) { while ($rs=$result->fetchRow(DB_FETCHMODE_ASSOC)) { $arr_votes[$rs["user_id"]] = $rs["votes"]; } } return $arr_votes; } function SLORReviewerStatusUI($user_id, $status) { $result = false; if (ExecQuery("UPDATE " . DB_PREFIX . "users SET reviewer = " . $status . " WHERE user_id = " . $user_id)) $result = true; return $result; } //******************************************************************************** // CATEGORIES MANAGEMENT //******************************************************************************** function CategoryIU(&$category_id, $parent_id, $category_title, $category_subtitle, $category_image, $category_type = CATEGORY_TYPE_REGULAR, $category_color = CATEGORY_COLOR_NAVY, $banners = array()) { $sql_ban_del = "DELETE FROM " . DB_PREFIX . "category_banners WHERE category_id = " . $category_id; if ( ($category_type == CATEGORY_TYPE_FEATURE) && ($parent_id > 0) ) { $sql = "UPDATE " . DB_PREFIX . "categories SET category_parent_id = 0 WHERE category_type = '" . CATEGORY_TYPE_FEATURE . "' AND category_parent_id = " . $parent_id; ExecQuery($sql); } $category_type = strtoupper($category_type); if ($category_id > 0) { // Simply update item $sql = "UPDATE " . DB_PREFIX . "categories SET " . " category_parent_id = " . $parent_id . ", category_title ='" . DoQuote($category_title) . "'" . ", category_subtitle ='" . DoQuote($category_subtitle) . "'" . ", category_image ='" . DoQuote($category_image) . "'" . ", category_type ='" . DoQuote($category_type) . "'" . ", category_color ='" . DoQuote($category_color) . "'" . " WHERE category_id=" . $category_id; $ret_val = false; if (ExecQuery($sql)) { $ret_val = true; if (is_array($banners)) $res = ExecQuery($sql_ban_del); if ($res !== false) { foreach ($banners as $banner_id => $banner) { if ($banner['name'] != '' || $banner['url'] != '') { $sql = "INSERT INTO " . DB_PREFIX . "category_banners (category_id, category_banner, category_banner_url, date_added) VALUES (" . $category_id . ", '" . DoQuote($banner['name']) . "', '" . DoQuote($banner['url']) . "', NOW())"; ExecQuery($sql); } } } } return $ret_val; } else { $dbConns = PrepareCon(); $sql = "REPLACE " . DB_PREFIX . "categories SET " . " category_parent_id = " . $parent_id . ", category_title ='" . DoQuote($category_title) . "'" . ", category_subtitle ='" . DoQuote($category_subtitle) . "'" . ", category_image ='" . DoQuote($category_image) . "'" . ", category_type ='" . DoQuote($category_type) . "'" . ", category_color ='" . DoQuote($category_color) . "'" . ", category_added = NOW()"; $result = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($result) { $sql = "select LAST_INSERT_ID()"; $subresult = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($subresult) { list($category_id) = $subresult->fetchRow(); } $dbConns->disconnect(); unset($dbConns); unset($result); unset($sql); if ($category_id > 0) { if (is_array($banners)) $res = ExecQuery($sql_ban_del); if ($res !== false) { foreach ($banners as $banner_id => $banner) { if ($banner['name'] != '' || $banner['url'] != '') { $sql = "INSERT INTO " . DB_PREFIX . "category_banners (category_id, category_banner, category_banner_url, date_added) VALUES (" . $category_id . ", '" . DoQuote($banner['name']) . "', '" . DoQuote($banner['url']) . "', NOW())"; ExecQuery($sql); } } } } return ($category_id > 0); } else { return false; } } return false; } function CategoryGet(&$rs, $category_id = 0, $parent_id = -1, $category_type = CATEGORY_TYPE_REGULAR) { $sql = "SELECT * FROM " . DB_PREFIX . "categories WHERE ( ( (category_id = " . $category_id . ") OR (0 = " . $category_id . ") ) AND ( (category_parent_id = " . $parent_id . ") OR (-1 = " . $parent_id . ") ) AND ( (category_type = '" . strtoupper($category_type) . "') ) ) ORDER BY category_title"; return GetRS($rs, $sql); } function CategoryBannersGet(&$rs, $category_id = 0) { if ($category_id > 0) { $sql = "SELECT * FROM " . DB_PREFIX . "category_banners WHERE (category_id = " . $category_id . ")"; return GetRS($rs, $sql); } else return true; } function GetRootCategories(&$rs, $category_type = CATEGORY_TYPE_REGULAR) { if ($category_type == CATEGORY_TYPE_REGULAR) return CategoryGet($rs, 0, 0, $category_type); else return CategoryGet($rs, 0, -1, $category_type); } function GetSubCategories(&$rs, $category_id) { return CategoryGet($rs, 0, $category_id); } //'================================================================================== //' Purpose: //' Deletes Category //' Return Values: //' True if succeeded //'================================================================================== function CategoryDelete($category_id) { $result = false; if (ExecQuery("DELETE FROM " . DB_PREFIX . "categories WHERE category_id = " . $category_id)) $result = true; return $result; } //******************************************************************************** // STORIES MANAGEMENT //******************************************************************************** function StoryIU(&$story_id, $fcategory_id, $story_title, $story_description, $story_text, $story_image_title, $story_image_th, $story_image, $story_image1_title, $story_image1_th, $story_image1, $story_image2_title, $story_image2_th, $story_image2, $story_image3_title, $story_image3_th, $story_image3, $story_image4_title, $story_image4_th, $story_image4, $story_image5_title, $story_image5_th, $story_image5, $story_image6_title, $story_image6_th, $story_image6, $story_image7_title, $story_image7_th, $story_image7, $story_image8_title, $story_image8_th, $story_image8, $pub_date, $story_type, $author_type, $author_id, $author_fname, $author_lname, $author_link, $author_image, $sponsor_title, $sponsor_link) { if (trim($pub_date) == '') $pub_date = " NOW()"; else $pub_date = "'" . DoQuote($pub_date) . "'"; if ($story_type == STORY_TYPE_EXPERT_ID) { if ($author_type == 'I') { $author_fname = ''; $author_lname = ''; } else { $author_id = 'NULL'; } } else { $author_type = ''; $author_id = 'NULL'; $author_fname = ''; $author_lname = ''; $author_link = ''; $author_image = ''; } if ($story_id > 0) { // Simply update item $sql = "UPDATE " . DB_PREFIX . "stories SET " . " fcategory_id =" . $fcategory_id . ", story_title ='" . DoQuote($story_title) . "'" . ", story_description='" . DoQuote($story_description) . "'" . ", story_text ='" . DoQuote($story_text) . "'" . ", story_image_title='" . DoQuote($story_image_title) . "'" . ", story_image_th ='" . DoQuote($story_image_th) . "'" . ", story_image ='" . DoQuote($story_image) . "'" . ", story_image1_title='" . DoQuote($story_image1_title) . "'" . ", story_image1_th ='" . DoQuote($story_image1_th) . "'" . ", story_image1 ='" . DoQuote($story_image1) . "'" . ", story_image2_title='" . DoQuote($story_image2_title) . "'" . ", story_image2_th ='" . DoQuote($story_image2_th) . "'" . ", story_image2 ='" . DoQuote($story_image2) . "'" . ", story_image3_title='" . DoQuote($story_image3_title) . "'" . ", story_image3_th ='" . DoQuote($story_image3_th) . "'" . ", story_image3 ='" . DoQuote($story_image3) . "'" . ", story_image4_title='" . DoQuote($story_image4_title) . "'" . ", story_image4_th ='" . DoQuote($story_image4_th) . "'" . ", story_image4 ='" . DoQuote($story_image4) . "'" . ", story_image5_title='" . DoQuote($story_image5_title) . "'" . ", story_image5_th ='" . DoQuote($story_image5_th) . "'" . ", story_image5 ='" . DoQuote($story_image5) . "'" . ", story_image6_title='" . DoQuote($story_image6_title) . "'" . ", story_image6_th ='" . DoQuote($story_image6_th) . "'" . ", story_image6 ='" . DoQuote($story_image6) . "'" . ", story_image7_title='" . DoQuote($story_image7_title) . "'" . ", story_image7_th ='" . DoQuote($story_image7_th) . "'" . ", story_image7 ='" . DoQuote($story_image7) . "'" . ", story_image8_title='" . DoQuote($story_image8_title) . "'" . ", story_image8_th ='" . DoQuote($story_image8_th) . "'" . ", story_image8 ='" . DoQuote($story_image8) . "'" . ", pub_date =" . $pub_date . ", story_type ='" . DoQuote($story_type) . "'" . ", author_type ='" . DoQuote($author_type) . "'" . ", author_id = " . $author_id . ", author_fname ='" . DoQuote($author_fname) . "'" . ", author_lname ='" . DoQuote($author_lname) . "'" . ", author_link ='" . DoQuote($author_link) . "'" . ", author_image ='" . DoQuote($author_image) . "'" . ", sponsor_title ='" . DoQuote($sponsor_title) . "'" . ", sponsor_link ='" . DoQuote($sponsor_link) . "'" . " WHERE story_id=" . $story_id; return (ExecQuery($sql)); } else { $dbConns = PrepareCon(); $sql = "REPLACE " . DB_PREFIX . "stories SET " . " fcategory_id =" . $fcategory_id . ", story_title ='" . DoQuote($story_title) . "'" . ", story_description ='" . DoQuote($story_description) . "'" . ", story_text ='" . DoQuote($story_text) . "'" . ", story_image_title ='" . DoQuote($story_image_title) . "'" . ", story_image_th ='" . DoQuote($story_image_th) . "'" . ", story_image ='" . DoQuote($story_image) . "'" . ", story_image1_title='" . DoQuote($story_image1_title) . "'" . ", story_image1_th ='" . DoQuote($story_image1_th) . "'" . ", story_image1 ='" . DoQuote($story_image1) . "'" . ", story_image2_title='" . DoQuote($story_image2_title) . "'" . ", story_image2_th ='" . DoQuote($story_image2_th) . "'" . ", story_image2 ='" . DoQuote($story_image2) . "'" . ", story_image3_title='" . DoQuote($story_image3_title) . "'" . ", story_image3_th ='" . DoQuote($story_image3_th) . "'" . ", story_image3 ='" . DoQuote($story_image3) . "'" . ", story_image4_title='" . DoQuote($story_image4_title) . "'" . ", story_image4_th ='" . DoQuote($story_image4_th) . "'" . ", story_image4 ='" . DoQuote($story_image4) . "'" . ", story_image5_title='" . DoQuote($story_image5_title) . "'" . ", story_image5_th ='" . DoQuote($story_image5_th) . "'" . ", story_image5 ='" . DoQuote($story_image5) . "'" . ", story_image6_title='" . DoQuote($story_image6_title) . "'" . ", story_image6_th ='" . DoQuote($story_image6_th) . "'" . ", story_image6 ='" . DoQuote($story_image6) . "'" . ", story_image7_title='" . DoQuote($story_image7_title) . "'" . ", story_image7_th ='" . DoQuote($story_image7_th) . "'" . ", story_image7 ='" . DoQuote($story_image7) . "'" . ", story_image8_title='" . DoQuote($story_image8_title) . "'" . ", story_image8_th ='" . DoQuote($story_image8_th) . "'" . ", story_image8 ='" . DoQuote($story_image8) . "'" . ", pub_date =" . $pub_date . ", story_type ='" . DoQuote($story_type) . "'" . ", author_type ='" . DoQuote($author_type) . "'" . ", author_id = " . $author_id . ", author_fname ='" . DoQuote($author_fname) . "'" . ", author_lname ='" . DoQuote($author_lname) . "'" . ", author_link ='" . DoQuote($author_link) . "'" . ", author_image ='" . DoQuote($author_image) . "'" . ", sponsor_title ='" . DoQuote($sponsor_title) . "'" . ", sponsor_link ='" . DoQuote($sponsor_link) . "'" . ", story_added = NOW()"; $result = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($result) { $sql = "select LAST_INSERT_ID()"; $subresult = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($subresult) { list($story_id) = $subresult->fetchRow(); } $dbConns->disconnect(); unset($dbConns); unset($result); unset($sql); return ($story_id > 0); } else { return false; } } return false; } function StoryGet(&$rs, $story_id = 0, $is_admin = false, $story_type = '') { if (!$is_admin) $sql_now = " AND ( s.pub_date <= NOW() ) "; /* if ( ($story_type == STORY_TYPE_SPOTLIGHT_ID) || ($story_type == STORY_TYPE_FEATURED_ID) ) { $sql_now = " AND ( fcategory_id > 0 ) " . $sql_now; //$story_type = ''; } */ if ($story_type == STORY_TYPE_SPOTLIGHT_ID) { $sql_now = " AND ( fcategory_id > 0 ) AND s.story_type <> '" . STORY_TYPE_EXPERT_ID . "' AND (c.category_title <> '" . GENERAL . "')" . $sql_now; $story_type = ''; } if ($story_type == STORY_TYPE_FEATURED_ID) { $sql_now = " AND ( c.category_title = '" . GENERAL . "' ) " . $sql_now; $story_type = ''; } // $stor = " OR s.story_type IS NOT NULL"; if ($story_type == STORY_TYPE_REGULAR_ID) { $stor = " OR s.story_type IS NULL"; } $sql = "SELECT s.*, c.category_title FROM " . DB_PREFIX . "stories s LEFT OUTER JOIN " . DB_PREFIX . "categories c ON c.category_id = s.fcategory_id WHERE ( ( (s.story_id = " . $story_id . ") OR (0 = " . $story_id . ") ) AND ( (s.story_type = '" . $story_type . "') OR ('' = '" . $story_type . "' " . $stor . ") ) ) " . $sql_now . " ORDER BY s.pub_date DESC"; // echo $sql; return GetRS($rs, $sql); } //'================================================================================== //' Purpose: //' Deletes Category //' Return Values: //' True if succeeded //'================================================================================== function StoryDelete($story_id) { $result = false; if (ExecQuery("DELETE FROM " . DB_PREFIX . "stories WHERE story_id = " . $story_id)) $result = true; return $result; } function GetStoryCategories($story_category) { $story_category = trim($story_category); if ($story_category != '') { if (strpos($story_category, ',') !== false) $story_category = str_replace(',', '\',\'', $story_category); $sql = "SELECT * FROM " . DB_PREFIX . "categories WHERE category_id IN ('" . $story_category . "')"; if (GetRS($result, $sql)) { while ($rs=$result->fetchRow(DB_FETCHMODE_ASSOC)) { $st_parent = ''; if ($rs["category_parent_id"] > 0) { $sql = "SELECT category_title FROM " . DB_PREFIX . "categories WHERE category_id = " . $rs["category_parent_id"]; if (GetRS($result2, $sql)) { if ($rs2=$result2->fetchRow(DB_FETCHMODE_ASSOC)) { $st_parent = $rs2["category_title"] . " » "; } } } $st .= "

" . $st_parent . $rs["category_title"] . "

"; } } } return $st; } //******************************************************************************** // NEWS MANAGEMENT //******************************************************************************** function NewsIU(&$news_id, $news_title, $news_desc, $news_text, $news_image, $news_pub_date) { if (trim($news_pub_date) == '') $news_pub_date = " NOW()"; else $news_pub_date = "'" . DoQuote($news_pub_date) . "'"; if ($news_id > 0) { // Simply update item $sql = "UPDATE " . DB_PREFIX . "news SET " . " news_title ='" . DoQuote($news_title) . "'" . ", news_desc ='" . DoQuote($news_desc) . "'" . ", news_text ='" . DoQuote($news_text) . "'" . ", news_image ='" . DoQuote($news_image) . "'" . ", news_pub_date =" . $news_pub_date . " WHERE news_id =" . $news_id; return (ExecQuery($sql)); } else { $dbConns = PrepareCon(); $sql = "REPLACE " . DB_PREFIX . "news SET " . " news_title ='" . DoQuote($news_title) . "'" . ", news_desc ='" . DoQuote($news_desc) . "'" . ", news_text ='" . DoQuote($news_text) . "'" . ", news_image ='" . DoQuote($news_image) . "'" . ", news_pub_date =" . $news_pub_date . ", news_added = NOW()"; $result = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($result) { $sql = "select LAST_INSERT_ID()"; $subresult = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($subresult) { list($news_id) = $subresult->fetchRow(); } $dbConns->disconnect(); unset($dbConns); unset($result); unset($sql); return ($news_id > 0); } else { return false; } } return false; } function NewsGet(&$rs, $news_id = 0, $is_admin = false) { if (!$is_admin) $sql_now = " AND ( news_pub_date <= NOW() ) "; $sql = "SELECT * FROM " . DB_PREFIX . "news WHERE ( (news_id = " . $news_id . ") OR (0 = " . $news_id . ") ) " . $sql_now . " ORDER BY news_pub_date DESC"; return GetRS($rs, $sql); } //'================================================================================== //' Purpose: //' Deletes Category //' Return Values: //' True if succeeded //'================================================================================== function NewsDelete($news_id) { $result = false; if (ExecQuery("DELETE FROM " . DB_PREFIX . "news WHERE news_id = " . $news_id)) $result = true; return $result; } function BusinessListGet(&$rs, $arr_params = array()) { $sql_where = ''; $sql = "SELECT * FROM " . DB_PREFIX . "business_listings"; if (is_array($arr_params)) { foreach ($arr_params as $rap => $rap_val) { if (strlen($rap_val) > 0) if (Right($rap, 3) == '_id') { if ($rap_val > 0) { if ($rap == 'category_id') { $sql2 = "SELECT UPPER(REPLACE(category_title, 'amp;', '')) AS categ FROM " . DB_PREFIX . "categories WHERE category_id = " . $rap_val; $tmp_buss_cat = ''; if (GetRs($result2, $sql2)) { if ($rs2=$result2->fetchRow(DB_FETCHMODE_ASSOC)) { $tmp_buss_cat = $rs2["categ"]; } } if ($tmp_buss_cat != '') { $sql_where .= " AND UPPER(business_category) = '" . DoQuote($tmp_buss_cat) . "'"; } } else { if ($rap == 'mb_id') { $sql_where .= " AND mb_id > 0"; } else { $sql_where .= " AND " . $rap . " = " . $rap_val; } } } } else { if (Right($rap, 3) != '_id') $sql_where .= " AND " . $rap . " LIKE '%" . DoQuote($rap_val) . "%'"; } } } if ($sql_where !== '') { $sql .= " WHERE 1=1" . $sql_where; }; // echo $sql; return GetRs($rs, $sql); } function BusinessListIU(&$listing_id, $category_id, $subcategory_id, $business_name, $business_street, $business_street2, $business_city, $business_state, $business_zip, $business_phone, $business_hours, $business_short_desc, $business_desc, $business_methods_paym, $business_since_date, $business_keywords, $business_url, $business_logo, $business_coupon, $business_img1, $business_img2, $business_img3, $business_img4, $mb_id, $business_info) { if ($category_id > 0) $category_title = str_replace('&', '&', CategoryNameById($category_id)); if ($subcategory_id > 0) $category_subtitle = str_replace('&', '&', CategoryNameById($subcategory_id)); // START# make sure user edit it's own profile $user_id = Session("user_id"); $ses_user_type = Session("ses_user_type"); if ($ses_user_type != 1 && $user_id > 0) { // this is not admin if (BusinessListGet($result, array('user_id' => $user_id))) { if ($rs=$result->fetchRow(DB_FETCHMODE_ASSOC)) { // rewrite listing_id with correct value for this user $listing_id = GetLong($rs["listing_id"], 0); } } } // STOP# make sure user edit it's own profile $l_strMB = ''; if ($mb_id > 0) { $l_strMB = ", mb_id = " . $mb_id; } if ($mb_id < 0) { $l_strMB = ", mb_id = NULL"; } if ($listing_id > 0) { $sql = "UPDATE " . DB_PREFIX . "business_listings SET " . " business_name ='" . DoQuote($business_name) . "'" . ", business_category ='" . DoQuote($category_title) . "'" . ", business_subcategory='" . DoQuote($category_subtitle) . "'" . ", business_street ='" . DoQuote($business_street) . "'" . ", business_street2 ='" . DoQuote($business_street2) . "'" . ", business_city ='" . DoQuote($business_city) . "'" . ", business_state ='" . DoQuote($business_state) . "'" . ", business_zip ='" . DoQuote($business_zip) . "'" . ", business_phone ='" . DoQuote($business_phone) . "'" . ", business_hours ='" . DoQuote($business_hours) . "'" . ", business_short_desc ='" . DoQuote($business_short_desc) . "'" . ", business_desc ='" . DoQuote($business_desc) . "'" . ", business_methods_paym='" . DoQuote($business_methods_paym) . "'" . ", business_since_date ='" . DoQuote($business_since_date) . "'" . ", business_keywords ='" . DoQuote($business_keywords) . "'" . ", business_url ='" . DoQuote($business_url) . "'" . ", business_logo ='" . DoQuote($business_logo) . "'" . ", business_coupon ='" . DoQuote($business_coupon) . "'" . ", business_img1 ='" . DoQuote($business_img1) . "'" . ", business_img2 ='" . DoQuote($business_img2) . "'" . ", business_img3 ='" . DoQuote($business_img3) . "'" . ", business_img4 ='" . DoQuote($business_img4) . "'" . $l_strMB . ", date_changed = NOW()" . " WHERE listing_id =" . $listing_id; SaveBusinessDesc($listing_id, $business_info); return (ExecQuery($sql)); } else { $dbConns = PrepareCon(); $sql = "REPLACE " . DB_PREFIX . "business_listings SET " . " business_name ='" . DoQuote($business_name) . "'" . ", business_category ='" . DoQuote($category_title) . "'" . ", business_subcategory='" . DoQuote($category_subtitle) . "'" . ", business_street ='" . DoQuote($business_street) . "'" . ", business_street2 ='" . DoQuote($business_street2) . "'" . ", business_city ='" . DoQuote($business_city) . "'" . ", business_state ='" . DoQuote($business_state) . "'" . ", business_zip ='" . DoQuote($business_zip) . "'" . ", business_phone ='" . DoQuote($business_phone) . "'" . ", business_hours ='" . DoQuote($business_hours) . "'" . ", business_short_desc ='" . DoQuote($business_short_desc) . "'" . ", business_desc ='" . DoQuote($business_desc) . "'" . ", business_methods_paym='" . DoQuote($business_methods_paym) . "'" . ", business_since_date ='" . DoQuote($business_since_date) . "'" . ", business_keywords ='" . DoQuote($business_keywords) . "'" . ", business_url ='" . DoQuote($business_url) . "'" . ", business_logo ='" . DoQuote($business_logo) . "'" . ", business_coupon ='" . DoQuote($business_coupon) . "'" . ", business_img1 ='" . DoQuote($business_img1) . "'" . ", business_img2 ='" . DoQuote($business_img2) . "'" . ", business_img3 ='" . DoQuote($business_img3) . "'" . ", business_img4 ='" . DoQuote($business_img4) . "'" . $l_strMB . ", date_added = NOW()" . ", date_changed = NOW()"; $result = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($result) { $sql = "select LAST_INSERT_ID()"; $subresult = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($subresult) { list($listing_id) = $subresult->fetchRow(); } $dbConns->disconnect(); unset($dbConns); unset($result); unset($sql); if ($listing_id > 0) { SaveBusinessDesc($listing_id, $business_info); $user_data = Session("user_data"); if ($user_id == 0) $user_id = GetLong($user_data["user_id"], 0); if ( ($user_id == 0) || ($ses_user_type == 1) ) { //insert user data. $sql = "INSERT INTO " . DB_PREFIX . "users (login, password, address1, address2, city, zip, phone, enabled, user_type, reg_date) VALUES ('business" . $listing_id . "', '" . DoQuote(RandomString(6)) . "', '" . DoQuote($business_street) . "', '" . DoQuote($business_street2) . "', '" . DoQuote($business_city) . "', '" . DoQuote($business_zip) . "', '" . DoQuote($business_phone) . "', 1, 2, NOW())"; $dbConns2 = PrepareCon(); $res = $dbConns2->query($sql); if ($res) { $sql = "select LAST_INSERT_ID()"; $subresult = $dbConns2->query($sql); if ($subresult) { list($user_id) = $subresult->fetchRow(); } } $dbConns2->disconnect(); unset($dbConns2); } $user_id = GetLong($user_id, 0); if ($user_id > 0) { $sql = "UPDATE " . DB_PREFIX . "business_listings SET user_id = " . $user_id . " WHERE listing_id = " . $listing_id; ExecQuery($sql); } } return ($listing_id > 0); } else { return false; } } return false; } function BusinessListDel($listing_id) { if (BusinessListGet($result, array('listing_id' => $listing_id))) { if ($rs=$result->fetchRow(DB_FETCHMODE_ASSOC)) { $sql = "DELETE FROM " . DB_PREFIX . "business_listings WHERE listing_id = " . $listing_id; if (ExecQuery($sql)) { ImageFileDelete($rs['business_logo'], '../' . BUSINESS_IMGS_PATH); ImageFileDelete($rs['business_logo'], '../' . BUSINESS_IMGS_TH_PATH); ImageFileDelete($rs['business_coupon'],'../'. BUSINESS_IMGS_PATH); ImageFileDelete($rs['business_coupon'],'../'. BUSINESS_IMGS_TH_PATH); ImageFileDelete($rs['business_img1'], '../' . BUSINESS_IMGS_PATH); ImageFileDelete($rs['business_img1'], '../' . BUSINESS_IMGS_TH_PATH); ImageFileDelete($rs['business_img2'], '../' . BUSINESS_IMGS_PATH); ImageFileDelete($rs['business_img2'], '../' . BUSINESS_IMGS_TH_PATH); ImageFileDelete($rs['business_img3'], '../' . BUSINESS_IMGS_PATH); ImageFileDelete($rs['business_img3'], '../' . BUSINESS_IMGS_TH_PATH); ImageFileDelete($rs['business_img4'], '../' . BUSINESS_IMGS_PATH); ImageFileDelete($rs['business_img4'], '../' . BUSINESS_IMGS_TH_PATH); $sql = "DELETE FROM " . DB_PREFIX . "business_desc WHERE listing_id = " . $listing_id; ExecQuery($sql); $sql = "DELETE FROM " . DB_PREFIX . "stats_business WHERE stat_listing_id = " . $listing_id; ExecQuery($sql); $sql = "DELETE FROM " . DB_PREFIX . "vote WHERE listing_id = " . $listing_id; ExecQuery($sql); $sql = "DELETE FROM " . DB_PREFIX . "users WHERE user_type <> 1 AND user_id = " . $rs['user_id']; ExecQuery($sql); } } } return true; } function SaveBusinessDesc($listing_id, $business_info) { if ( ($listing_id > 0) && (is_array($business_info)) ) { $sql = "DELETE FROM " . DB_PREFIX . "business_desc WHERE listing_id = " . $listing_id; if (ExecQuery($sql)) { foreach ($business_info as $desc_name => $desc_value) { $desc_name = Left($desc_name, 100); $desc_value = Left($desc_value, 255); $sql = "INSERT INTO " . DB_PREFIX . "business_desc (listing_id, desc_name, desc_value) VALUES (" . $listing_id . ", '" . $desc_name . "', '" . $desc_value . "')"; ExecQuery($sql); } } } } function LoadBusinessDesc($listing_id) { $ret = array(); if ($listing_id > 0) { $sql = "SELECT * FROM " . DB_PREFIX . "business_desc WHERE listing_id = " . $listing_id; if (GetRs($result, $sql)) { while ($rs=$result->fetchRow(DB_FETCHMODE_ASSOC)): $ret[$rs["desc_name"]] = $rs["desc_value"]; endwhile; } } return $ret; } function AdminVotesGet(&$rs, $vote_id = 0) { $sql = "SELECT v.*, v.date_added as vote_date_added, u.*, l.* FROM " . DB_PREFIX . "vote v, " . DB_PREFIX . "users u, " . DB_PREFIX . "business_listings l WHERE u.user_id = v.user_id AND v.listing_id = l.listing_id AND (0 = " . $vote_id . " OR vote_id = " . $vote_id . ") ORDER BY v.date_added DESC"; // $sql = "SELECT v.*, v.date_added as vote_date_added, u.*, l.* FROM " . DB_PREFIX . "vote v, " . DB_PREFIX . "users u, " . DB_PREFIX . "business_listings l WHERE u.user_id = v.user_id AND v.listing_id = l.listing_id AND v.approved = 2 AND (0 = " . $vote_id . " OR vote_id = " . $vote_id . ") ORDER BY v.date_added DESC"; return GetRs($rs, $sql); } function VoteDelete($vote_id) { $result = false; if (ExecQuery("DELETE FROM " . DB_PREFIX . "vote WHERE vote_id = " . $vote_id)) $result = true; return $result; } function VoteApprove($vote_id) { $result = false; if (ExecQuery("UPDATE " . DB_PREFIX . "vote SET approved = 1 WHERE vote_id = " . $vote_id)) $result = true; return $result; } function VoteSuspend($vote_id) { $result = false; if (ExecQuery("UPDATE " . DB_PREFIX . "vote SET approved = 3 WHERE vote_id = " . $vote_id)) $result = true; return $result; } function AdminVoteIU(&$vote_id, $rating, $review_text) { if ($vote_id > 0) { // Simply update item $sql = "UPDATE " . DB_PREFIX . "vote SET " . " rating = " . $rating . ", review_text = '" . DoQuote($review_text) . "'" . " WHERE vote_id=" . $vote_id; return (ExecQuery($sql)); } return false; } function GetReviewStatus($int_approved, $date_edited) { switch ($int_approved) { case 0: return "Unknown"; case 1: if ($date_edited != '') { return "Edited and approved"; } else { return "Approved"; } case 2: return "Pending for approve"; case 3: return "Suspended"; default: return "Unknown"; } } function VoteStats() { $result = array(); $cnt_users = $cnt_votes = 0; if (GetRS($result, "SELECT COUNT(1) AS cnt FROM " . DB_PREFIX . "users WHERE enabled = 1 AND user_type = 2")) { if ($rs=$result->fetchRow(DB_FETCHMODE_ASSOC)) { $cnt_users = $rs["cnt"]; } } if (GetRS($result, "SELECT COUNT(1) AS cnt FROM " . DB_PREFIX . "vote WHERE approved = 1")) { if ($rs=$result->fetchRow(DB_FETCHMODE_ASSOC)) { $cnt_votes = $rs["cnt"]; } } return (array($cnt_users, $cnt_votes)); } //******************************************************************************** // PLUGIN SITES MANAGEMENT //******************************************************************************** function PlugSiteIU(&$site_id, $site_name, $site_url, $site_image, $site_category, $site_phrases) { $site_category = strtoupper($site_category); if ($site_id > 0) { // Simply update item $sql = "UPDATE " . DB_PREFIX . "plugin_sites SET " . " site_name ='" . DoQuote($site_name) . "'" . ", site_url ='" . DoQuote($site_url) . "'" . ", site_image ='" . DoQuote($site_image) . "'" . ", site_category ='" . DoQuote($site_category) . "'" . ", site_phrases ='" . DoQuote($site_phrases) . "'" . " WHERE site_id=" . $site_id; $ret_val = false; if (ExecQuery($sql)) { $ret_val = true; } return $ret_val; } else { $dbConns = PrepareCon(); $sql = "REPLACE " . DB_PREFIX . "plugin_sites SET " . " site_name ='" . DoQuote($site_name) . "'" . ", site_url ='" . DoQuote($site_url) . "'" . ", site_image ='" . DoQuote($site_image) . "'" . ", site_category ='" . DoQuote($site_category) . "'" . ", site_phrases ='" . DoQuote($site_phrases) . "'" . ", date_added = NOW()"; $result = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($result) { $sql = "select LAST_INSERT_ID()"; $subresult = $dbConns->query($sql) or die("Cannot get recordset
" . mysql_error()."
"); if ($subresult) { list($site_id) = $subresult->fetchRow(); } $dbConns->disconnect(); unset($dbConns); unset($result); unset($sql); return ($site_id > 0); } else { return false; } } return false; } function PlugSiteGet(&$rs, $site_id = 0, $site_category = '', $order_by = 'site_name') { $sql = "SELECT * FROM " . DB_PREFIX . "plugin_sites WHERE ( ( (site_id = " . $site_id . ") OR (0 = " . $site_id . ") ) AND ( (site_category = '" . strtoupper($site_category) . "') OR ('' = '" . strtoupper($site_category) . "') ) ) ORDER BY '" . $order_by . "'"; return GetRS($rs, $sql); } //'================================================================================== //' Purpose: //' Deletes PlugSite //' Return Values: //' True if succeeded //'================================================================================== function PlugSiteDelete($site_id) { $result = false; if (ExecQuery("DELETE FROM " . DB_PREFIX . "plugin_sites WHERE site_id = " . $site_id)) $result = true; return $result; } ?>