getMessage(), null, null, null); } $request=$_GET['request']; $error=0; $errorText=""; switch($request){ case "category": $category_name = $_GET['name']; $tsql = "SELECT * FROM category WHERE parent_id >= 0"; $q = $DBH->prepare($tsql); $q->execute(); $category_arr = array(); while($row = $q->fetch()) { $b = array('id' => $row['id'], 'name'=>utf8_encode($row['name'])); if(seoUrl(utf8_encode($row['name'])) == utf8_encode($category_name)){ $title = "Lastekaubad > " . utf8_encode($row['name']); $h1 = utf8_encode($row['name']); $category_id = $row['id']; } array_push($category_arr, $b); } case "seller": case "product": $sqlParams = array(); $getSellerInfo = false; if($request == "product"){ $getSellerInfo = true; $sqlParams["product_id"] =$_GET['id']; $tsql = "SELECT *, DATE_FORMAT(create_date, '%d-%c') as sdate, 0 AS distance, (select image_url from album a where a.owner_id = p.id and owner_type = 'product' order by id limit 1) as image0_url FROM product p WHERE id = :product_id"; } if($request == "seller"){ $getSellerInfo = true; $sqlParams["seller_id"] = $_GET['id']; $tsql = "SELECT * , DATE_FORMAT(create_date, '%d-%c') as sdate, 0 AS distance, (select image_url from album a where a.owner_id = p.id and owner_type = 'product' order by id limit 1) as image0_url FROM product p WHERE seller_id = :seller_id"; } if($request == "category"){ $sqlParams["category_id"] = $category_id; $tsql = "SELECT * , DATE_FORMAT(create_date, '%d-%c') as sdate, 0 AS distance, (select image_url from album a where a.owner_id = p.id and owner_type = 'product' order by id limit 1) as image0_url FROM product p WHERE category_id = :category_id"; } $q = $DBH->prepare($tsql); $q->execute($sqlParams); $fields = getProductFieldsArray(); $resarr = Array(); // echo $tsql; // print_r($sqlParams); while($row = $q->fetch()) { $prodArr = Array(); $product_id = $row['id']; $prodArr['id'] = $product_id; $prodArr['time'] = $row['sdate']; $prodArr['image0_url'] = $row['image0_url']; $prodArr['thumb_url'] = $row['thumb_url']; $prodArr['distance'] = $row['distance']; $prodArr['url'] = $row['url']; for($i=0;$iprepare($tsql); $q->execute(array("product_id" => $resarr[$i]['id'])); while($row = $q->fetch()) { $tagNames = Array(); $tagNames["male"] = "poiss"; $tagNames["female"] = "tüdruk"; $tagNames["twins"] = "kaksikud"; $tagNames["free"] = "tasuta"; $tagNames["new"] = "uus"; $tagNames["used"] = "kasutatud"; $tagNames["selfmade"] = "käsitöö"; $tagNames["eco"] = "öko"; array_push($resarr[$i]['tags'], $tagNames[$row['tag']]); } $tsql = "select c1.id as 'c1_id', c2.id as 'c2_id', c3.id as 'c3_id', c4.id as 'c4_id', c5.id as 'c5_id', c6.id as 'c6_id', c7.id as 'c7_id', c1.name as 'c1_name', c2.name as 'c2_name', c3.name as 'c3_name', c4.name as 'c4_name', c5.name as 'c5_name', c6.name as 'c6_name', c7.name as 'c7_name' from category c1 join category as c2 on c2.id = c1.parent_id || c1.id = 0 join category as c3 on c3.id = c2.parent_id || c2.id = 0 join category as c4 on c4.id = c3.parent_id || c3.id = 0 join category as c5 on c5.id = c4.parent_id || c4.id = 0 join category as c6 on c6.id = c5.parent_id || c5.id = 0 join category as c7 on c7.id = c6.parent_id || c6.id = 0 where c1.id = :category_id limit 1"; $q = $DBH->prepare($tsql); $q->execute(array("category_id" => $resarr[$i]['category_id'])); $cat_arr = array(); while($row = $q->fetch()) { for($a=1;$a<8;$a++){ if($row['c'.$a.'_id']!=0){ $b = array('id' => $row['c'.$a.'_id'], 'name'=>utf8_encode($row['c'.$a.'_name'])); array_push($cat_arr, $b); } } } if(count($cat_arr)==0){ $resarr[$i]['categories'] = array(); $resarr[$i]['categories'][0] = array("name"=>"Lastele"); } else{ $resarr[$i]['categories'] = $cat_arr; } } if($getSellerInfo){ $seller = Array(); $sql = "SELECT first_name, email, gsm, url, X( location ) AS loc_lat, Y( location ) AS loc_lng, description from seller where id = :seller_id"; $q2 = $DBH->prepare($sql); $q2->execute(array("seller_id" => $seller_id)); while($row2 = $q2->fetch()) { $seller['id']=$seller_id; $seller['first_name']=$row['first_name']; $seller['email']=$row['email']; $seller['gsm']=$row['gsm']; $seller['url']=$row['url']; $seller['loc_lat']=$row['loc_lat']; $seller['loc_lng']=$row['loc_lng']; $seller['description']=$row['description']; } } if($request == "product"){ redirectVisitor("/#/productView/" . $product_id); if(isset($resarr[0]['categories'])){ $title = "Lastekaubad > " . $resarr[0]["categories"][0]["name"] . " > " . $resarr[0]["name"]; }else{ $title = "Lastekaubad > " . $resarr[0]["name"]; } require_once("productView.php"); } if($request == "seller"){ redirectVisitor("/#/sellerView/" . $seller_id); $title = "Lastekaubad > Kasutaja " . $seller["first_name"] . " pood"; require_once("sellerView.php"); } if($request == "category"){ redirectVisitor("/#?cat=" . $category_id); require_once("categoryView.php"); } break; } function getProductFieldsArray(){ $fields = Array(); //name, type, max length, is required array_push($fields,array("name", "text", 30, true)); array_push($fields,array("description", "text", 1000, false)); array_push($fields,array("brand", "text", 100, false)); array_push($fields,array("category_id", "int", 5, false)); array_push($fields,array("size", "int", 8, false)); array_push($fields,array("price", "int", 8, false)); return $fields; } function getProductTagsArray(){ $fields = Array(); array_push($fields,array("free")); array_push($fields,array("male")); array_push($fields,array("female")); array_push($fields,array("twins")); array_push($fields,array("new")); array_push($fields,array("used")); array_push($fields,array("selfmade")); array_push($fields,array("eco")); return $fields; } function handleError($errNr,$err){ echo json_encode(array('answerType' => 'error', 'errorID' => $errNr, 'errorMessage' => $err)); exit; } ?>