RJ Thomas, Ltd. Fine FurnitureRJ Thomas, Ltd. Fine Furniture

  • Home
  • Browse Products
  • Sample Sale Items
  • Staff
  • Services
  • Manufacturers
  • Location & Hours
  • Contact us
"; if ($debug_error_log) error_log($val); } function notempty($val) { return isset($val) && trim($val)!=''; } ?> ModelBase(); } function getSubCategories($site_id) { if(!isset($this->subcategories) && isset($this->category_nb)) { $this->subcategories = $this->selectSubCategories($this->category_nb,$site_id); } return $this->subcategories; } function getParentCategory($site_id) { if (!isset($this->parentCategory) && isset($this->parent_category_nb)) { $this->parentCategory = $this->selectParentCategory($this->parent_category_nb,$site_id); } return $this->parentCategory; } function getProducts() { if (!isset($this->products) && isset($this->category_nb)) { $this->products=$this->selectProductsByCategory($this->category_nb); } return $this->products; } function getProductsNew() { if (!isset($this->products) && isset($this->category_nb)) { $this->products=$this->selectProductsByCategoryNew($this->category_nb); } return $this->products; } function getFeaturedProducts() { if (!isset($this->featuredProducts)) { $this->featuredProducts=$this->selectFeaturedProductsByCategory($this->category_nb); } return $this->featuredProducts; } function getHtmlMeta() { if (!isset($this->html_meta) && isset($this->html_meta_nb)) { $this->html_meta=new HtmlMeta(); $this->html_meta->select($this->html_meta_nb); } return $this->html_meta; } function getCategoryView() { if (!isset($this->categoryView)) { $this->categoryView=new CategoryView(); $this->categoryView->selectByCategory($this->category_nb); } return $this->categoryView; } function selectByUrlpath($urlpath) { $this->urlpath=$urlpath; $q = 'select h1_title,description,category_nb,parent_category_nb,html_meta_nb,ordinal from category where urlpath = ?'; $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_param("s",$urlpath); $stmt->bind_result($this->h1_title,$this->description, $this->category_nb,$this->parent_category_nb,$this->html_meta_nb,$this->ordinal); $stmt->execute(); $stmt->fetch(); $stmt->close(); } function selectByUrlpathandSiteId($urlpath,$siteid) { $this->urlpath=$urlpath; $q = 'select h1_title,description,category_nb,parent_category_nb,html_meta_nb,ordinal from category where urlpath = ? and site_id= ' .$siteid; $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_param("s",$urlpath); $stmt->bind_result($this->h1_title,$this->description, $this->category_nb,$this->parent_category_nb,$this->html_meta_nb,$this->ordinal); $stmt->execute(); $stmt->fetch(); $stmt->close(); } function selectSubCategories($catNb,$site_id) { $q = 'select category_nb, h1_title,description,urlpath, ordinal from category where site_id = ' . $site_id . ' AND parent_category_nb = ? order by ordinal'; //error_log($q . " : " . $catNb); //debug($q.$catNb); $subs=Array(); $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_param("s",$catNb); $stmt->bind_result($category_nb,$h1_title,$description,$urlpath,$ordinal); $stmt->execute(); while($stmt->fetch()) { $subcategory = new Category(); $subcategory->category_nb = $category_nb; $subcategory->h1_title = $h1_title; $subcategory->description = $description; $subcategory->urlpath = $urlpath; $subcategory->parent_category_nb=$catNb; $subcategory->ordinal=$ordinal; $subs[] = $subcategory; } $stmt->close(); return $subs; } function selectByCategoryNb($catNb) { $q = 'select site_id, category_nb, urlpath, h1_title, description, parent_category_nb, html_meta_nb, ordinal from category where category_nb= ?'; // debug($q.$catNb); $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_param("s",$catNb); $stmt->bind_result($this->site_id,$this->category_nb,$this->urlpath,$this->h1_title,$this->description,$this->parent_category_nb,$this->html_meta_nb,$this->ordinal); $stmt->execute(); $stmt->fetch(); $stmt->close(); } function selectById($id) { $q = 'select category_nb,site_id,urlpath, h1_title, description, parent_category_nb, ordinal from category where category_nb= '.$id; $conn = parent::$dbconn; $stmt = $conn->prepare($q) or die(mysqli_error($conn)); $stmt->bind_result($this->category_nb,$this->site_id,$this->urlpath,$this->h1_title,$this->description,$this->parent_category_nb,$this->ordinal); $stmt->execute(); $stmt->fetch(); $stmt->close(); } function getLatestProducts($site_id,$main_cat){ $c = new Category(); $c->selectByID($main_cat); $s = $c->getSubCategories($site_id); foreach($s as $sc){ $ssc = $sc->getSubCategories($site_id); foreach($ssc as $prod){ $allProds=$prod->getProducts(); foreach($allProds as $prod){ $parts=split("-",$prod->lastup); $syr=$parts[0]; $smo=$parts[1]; $sday=$parts[2]; $parts2=split(":",$prod->lastup); $shour=$parts2[0]; $smin=$parts2[1]; $ssec=$parts2[2]; //print_r("$syr $smo $sday $shour $smin $ssec"); $checkLastup = mktime($shour, $smin, $ssec, $smo, $sday, $syr); $checkDays = mktime(date("H"), date("i"), date("s"), date("m"), date("d") - 45, date("Y")); if ($checkLastup > $checkDays){ $prodsArray[] = $prod; } } } } if (sizeof($prodsArray)) { usort($prodsArray,array("Product","compareTimestamps")); } return $prodsArray; } // and site_id = ' . $_SESSION['site_id'] . ' function selectParentCategory($catNb,$site_id) { $q = 'select category_nb, site_id, urlpath, h1_title, description, parent_category_nb, ordinal from category where site_id = ' . $site_id . ' and category_nb= ?'; // debug($q.$catNb); $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_param("s",$catNb); $stmt->bind_result($category_nb,$site_id,$urlpath,$h1_title,$description,$parent_category_nb,$ordinal); $stmt->execute(); $stmt->fetch(); $stmt->close(); $parentCategory = new Category(); $parentCategory->category_nb=$category_nb; $parentCategory->site_id=$site_id; $parentCategory->h1_title=$h1_title; $parentCategory->description=$description; $parentCategory->urlpath=$urlpath; $parentCategory->parent_category_nb=$parent_category_nb; $parentCategory->ordinal=$ordinal; return $parentCategory; } function selectProductsByCategory($id) { $q='select product_nb from product_category where category_nb=?'; $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_param("s",$id); $stmt->bind_result($product_nb); $stmt->execute(); $products=Array(); while($stmt->fetch()) { $prod=new Product(); $prod->selectByProductNb($product_nb); $products[]=$prod; } usort($products,array("Product","compareTimestamps")); return $products; $stmt->close(); } function selectFeaturedProductsByCategory($id) { $q='select product_nb from category_featured where category_nb=?'; $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_param("s",$id); $stmt->bind_result($product_nb); $stmt->execute(); while($stmt->fetch()) { $prod=new Product(); $prod->selectByProductNb($product_nb); $products[]=$prod; } $stmt->close(); return $products; } function getAllPrimaryCategories($siteid) { $q='select category_nb, site_id, h1_title,description,urlpath,parent_category_nb,html_meta_nb,ordinal from category where site_id = '. $siteid .' and parent_category_nb=0;'; // error_log($q); $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_result($category_nb,$site_id,$h1_title,$description,$urlpath,$parent_category_nb,$html_meta_nb,$ordinal); $stmt->execute(); while($stmt->fetch()) { $cat=new Category(); $cat->category_nb=$category_nb; $cat->site_id=$site_id; $cat->h1_title=$h1_title; $cat->description=$description; $cat->urlpath=$urlpath; $cat->parent_category_nb=$parent_category_nb; $cat->html_meta_nb=$html_meta_nb; $cat->ordinal=$ordinal; $categories[]=$cat; } $stmt->close(); return $categories; } function update() { if (isset($this->html_meta)) { if (isset($this->html_meta->html_meta_nb)) { $this->html_meta->update(); }else { $this->html_meta->insert(); $this->html_meta_nb=$this->html_meta->html_meta_nb; } } foreach ($this->relatedCategories as $relCat) { if (isset($relCat->related_category_id) && $relCat->related_category_nb != 0) { //error_log("udpating Related category"); $relCat->update(); } else { //error_log("inserting Related category"); $relCat->insert(); } } $q='update category set site_id=?, urlpath= ?, html_meta_nb = ? ,parent_category_nb = ?, h1_title = ?, description = ?, ordinal = ? where category_nb = ?'; $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_param("isiissii",$this->site_id,$this->urlpath,$this->html_meta_nb,$this->parent_category_nb,$this->h1_title,$this->description,$this->ordinal,$this->category_nb); $stmt->execute() or die(mysqli_error($conn)); } function insert() { if (!isset($this->parent_category_nb) || trim($this->parent_category_nb)=='') $this->parent_category_nb=0; if (! isset($this->html_meta)) { return -1; } $this->html_meta->insert(); $this->html_meta_nb=$this->html_meta->html_meta_nb; //error_log("PARENT CATEGORY".$this->parent_category_nb); $q='select max(ordinal) from category where parent_category_nb='.$this->parent_category_nb .' and site_id = '.$this->site_id; error_log($q); $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_result($this->ordinal); $stmt->execute(); $stmt->fetch(); $stmt->close(); if (!isset($this->ordinal) || $this->ordinal == null) { $this->ordinal=1; } else { $this->ordinal+=1; } $q='insert into category (site_id,urlpath,parent_category_nb,html_meta_nb,h1_title,description,ordinal) values (?,?,?,?,?,?,?)'; // error_log($q); // error_log($this->site_id.$this->urlpath.$this->parent_category_nb.$this->html_meta_nb.trim($this->h1_title).trim($this->description).$this->ordinal); $stmt = $conn->prepare($q); error_log(mysqli_error($conn)); $stmt->bind_param("isiissi",$this->site_id,$this->urlpath,$this->parent_category_nb,$this->html_meta_nb,trim($this->h1_title),trim($this->description),$this->ordinal)or die(mysqli_error($conn)); $stmt->execute() or die(mysqli_error($conn)); $this->category_nb=$conn->insert_id; foreach ($this->relatedCategories as $relCat) { $relCat->category_nb = $this->category_nb; $relCat->insert(); } } function delete($category_nb) { $q='delete from category where category_nb = ' . $category_nb; $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->execute() or die(mysqli_error($conn)); } function setAllFromScreen() { $this->site_id = $_REQUEST['site_id']; $this->html_meta = new HtmlMeta(); $this->html_meta->meta_title=$_REQUEST['meta_title']; $this->html_meta->meta_description=$_REQUEST['meta_description']; $this->html_meta->meta_keywords=$_REQUEST['meta_keywords']; $this->category_nb=$_REQUEST['category_nb']; $this->urlpath=$_REQUEST['urlpath']; $this->parent_category_nb=$_REQUEST['parent_category_nb']; $this->h1_title=$_REQUEST['h1_title']; $this->description=$_REQUEST['description']; $this->ordinal=$_REQUEST['ordinal']; if (isset($_REQUEST["relatedCategory1"]) && $_REQUEST['relatedCategory1'] != '') { $rcs = $this->getRelatedCategories(); foreach ($rcs as $rc) { if ($rc->related_category_id == $_REQUEST["relatedCategory1_id"]) { $relatedCategory1= $rc; } } $relatedCategory1 = isset($relatedCategory1) ? $relatedCategory1 : new RelatedCategory(); $relatedCategory1->related_category_nb = $_REQUEST["relatedCategory1"]; $relatedCategory1->category_nb = $this->category_nb; $relatedCategory1->ordinal = 0; //if (!isset($relatedCategory->related_category_id)) $this->relatedCategories[] = $relatedCategory; $this->relatedCategories[] = $relatedCategory1; } if (isset($_REQUEST["relatedCategory2"]) && $_REQUEST['relatedCategory2'] != '') { foreach ($rcs as $rc) { if ($rc->related_category_id == $_REQUEST["relatedCategory2_id"]) { $relatedCategory2 = $rc; } } $relatedCategory2 = isset($relatedCategory2) ? $relatedCategory2 : new RelatedCategory(); $relatedCategory2->related_category_nb = $_REQUEST["relatedCategory2"]; $relatedCategory2->category_nb = $this->category_nb; $relatedCategory2->ordinal = 1; // if (!isset($relatedCategory->related_category_id)) $this->relatedCategories[] = $relatedCategory; $this->relatedCategories[] = $relatedCategory2; } if (isset($_REQUEST["relatedCategory3"]) && $_REQUEST['relatedCategory3'] != '') { foreach ($rcs as $rc) { if ($rc->related_category_id == $_REQUEST["relatedCategory3_id"]) $relatedCategory3 = $rc; } $relatedCategory3 = isset($relatedCategory3) ? $relatedCategory3 : new RelatedCategory(); $relatedCategory3->related_category_nb = $_REQUEST["relatedCategory3"]; $relatedCategory3->category_nb = $this->category_nb; $relatedCategory3->ordinal = 2; //if (!isset($relatedCategory->related_category_id)) $this->relatedCategories[] = $relatedCategory; $this->relatedCategories[] = $relatedCategory3; } } /* ----------------------------------------------------------------------- Functions for re-ordering categories within their parent categories ---------------------------------------------------------------------*/ function moveUp($site_id) { $sql0 = 'select ordinal from category where category_nb = '. $this->category_nb; $conn = parent::$dbconn; $stmt = $conn->prepare($sql0); $stmt->bind_result($ordinal); $stmt->execute(); $stmt->fetch(); $stmt->close(); // see if it's already on top if ($ordinal==0) { // do nothing } else { $this->selectById($this->category_nb); $parent = $this->getParentCategory($site_id); $sql1 = "update category set ordinal = ordinal+1 where ordinal = " . ($ordinal-1) . " and parent_category_nb = " . $parent->category_nb ; $stmt = $conn->prepare($sql1); $stmt->execute(); $stmt->close(); $sql2 = "update category set ordinal = ordinal-1 where category_nb = ". $this->category_nb; $stmt = $conn->prepare($sql2); $stmt->execute(); $stmt->close(); } } function moveDown($site_id) { $sql0 = 'select ordinal from category where category_nb = '. $this->category_nb; $conn = parent::$dbconn; $stmt = $conn->prepare($sql0); $stmt->bind_result($ordinal); $stmt->execute(); $stmt->fetch(); $stmt->close(); $this->selectById($this->category_nb); $parent = $this->getParentCategory($site_id); $maxSql = 'select max(ordinal) from category where parent_category_nb ='.$parent->category_nb; //error_log("max sql: ".$maxSql); $stmt = $conn->prepare($maxSql); $stmt->bind_result($max); $stmt->execute(); $stmt->fetch(); $stmt->close(); // see if it's already on the bottom if ($ordinal==$max) { // do nothing } else { $sql1 = "update category set ordinal = ordinal-1 where ordinal = " . ($ordinal+1) . " and parent_category_nb = " . $parent->category_nb; $stmt = $conn->prepare($sql1); $stmt->execute(); $stmt->close(); $sql2 = "update category set ordinal = ordinal+1 where category_nb = ". $this->category_nb; $stmt = $conn->prepare($sql2); $stmt->execute(); $stmt->close(); } } /* ------------------------------------------------------------- Functions for related products ----------------------------------------------------------*/ function getRelatedCategories() { if (! isset($this->relatedCategories) ) { $rc = new RelatedCategory(); $this->relatedCategories = $rc->selectByCategory($this->category_nb); } return $this->relatedCategories; } function getRandomProduct() { $products = $this->getProducts(); //error_log("product list: ".sizeof($products)); $rp = rand(0,sizeof($products)-1); return $products[$rp]; } function getLastBaseTimestamp() { $q='select date_format(max(timestamp), "%m-%d-%Y") from google_base_history where category_nb='. $this->category_nb ; $conn = parent::$dbconn; $stmt = $conn->prepare($q); $stmt->bind_result($ts); $stmt->execute(); $stmt->fetch(); $stmt->close(); return $ts; } } ?>