prepare($sql); $stmt->execute(array( "id"=>$id )); if ($stmt->rowCount() == 0) { throw new Exception("NOT_FOUND", 404); } $toilet = $stmt->fetch(PDO::FETCH_ASSOC); //var_dump($toilet);exit; if (empty($toilet["id"])) { throw new Exception("NOT_FOUND", 404); } $images = @explode(",", $toilet["images"]); $toilet["images"] = $images; $trend_values = @explode(",", $toilet["trends"]); $trends = array( array("title"=>"清潔さ", "value"=>str_repeat("★", floor($trend_values[0]))), array("title"=>"臭い", "value"=>str_repeat("★", floor($trend_values[1]))), array("title"=>"虫", "value"=>str_repeat("★", floor($trend_values[2]))), array("title"=>"設備", "value"=>str_repeat("★", floor($trend_values[3]))), array("title"=>"安全性", "value"=>str_repeat("★", floor($trend_values[4]))) ); //var_dump($trend_values); exit(); $rating = floatval($toilet["rating"]) * 5; $rating = floor($rating + 0.5); $toilet["rating"] = str_repeat("★", $rating); $toilet["trends"] = $trends; $dateUpdated = new DateTime($toilet["dateUpdated"]); $toilet["dateUpdated"] = $dateUpdated->format("Y/m/d"); $dateChecked = new DateTime($toilet["dateChecked"]); $toilet["dateChecked"] = $dateChecked->format("Y/m/d"); //var_dump($toilet); exit; $others = array(); if (FETCH_OTHERS) { if (@$user_info["is_admin"]) { $sql = "select toilets.*, concat(images.id, '.', images.type) as image from toilets left join images on images.toiletId = toilets.id and images.`index` = 0 where (toilets.status = 0 or toilets.status = 1) and area=:area group by toilets.id order by rand() limit 5"; } else { $sql = "select toilets.*, concat(images.id, '.', images.type) as image from toilets left join images on images.toiletId = toilets.id and images.`index` = 0 where toilets.status = 0 and area=:area group by toilets.id order by rand() limit 5"; } $stmt = $pdo->prepare($sql); $stmt->execute(array( "area"=>$toilet["area"] )); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $other = $row; $dateChecked = new DateTime($other["dateChecked"]); $other["dateChecked"] = $dateChecked->format("Y/m/d"); $rating = floatval($other["rating"]) * 5; $rating = floor($rating + 0.5); $other["rating"] = str_repeat("★", $rating); $others[] = $other; } //var_dump($others); exit; } $detail_token = uniqid("detail-", true); $_SESSION["detail_token"] = $detail_token; $meta_template = "parts/meta_tags/".$toilet["id"].".html"; if ($smarty->templateExists($meta_template)) { $smarty->assign("meta_template", $meta_template); } $description_template = "parts/descriptions/".$toilet["id"].".html"; if ($smarty->templateExists($description_template)) { $smarty->assign("description_template", $description_template); } $smarty->assign("toilet", $toilet); $smarty->assign("others", $others); $smarty->assign("detail_token", $detail_token); $smarty->assign("is_admin", @$user_info["is_admin"]); $smarty->display("detail.html"); } catch (Exception $e) { $code = $e->getCode(); $message = $e->getMessage(); echo $message; exit(); } ?>