mark('t1'); // v1.1 19/3/14 --> require_once 'config.php'; if (substr($_SERVER["REQUEST_URI"],strlen($_SERVER["REQUEST_URI"])-1,1) == '.') $_SERVER["REQUEST_URI"] = substr($_SERVER["REQUEST_URI"],0,strlen($_SERVER["REQUEST_URI"])-1); if(strpos($_SERVER["REQUEST_URI"],'logout') > 0) { unset($_SESSION['env']); session_destroy(); setcookie("PHPSESSID","",time()-3600,"/"); if(strpos($_SERVER["REQUEST_URI"], '#')) $url = substr($_SERVER["REQUEST_URI"], 0, strpos($_SERVER["REQUEST_URI"], '#') ); if(strpos($_SERVER["REQUEST_URI"], '?')) $url = substr($_SERVER["REQUEST_URI"], 0, strpos($_SERVER["REQUEST_URI"], '?') ); header("Location: ".$url); return; } if( strpos('_'.$_SERVER['HTTP_HOST'],'ww') > 0 ) { redirect('http://'.getMainDom().$_SERVER["REQUEST_URI"] ); return; } if ($_SERVER["REQUEST_URI"]=='/sitemap.xml') { header( "Content-type: text/xml"); header( "Status: 200"); header("HTTP/1.1 200 OK", true, 200); include('sitemap.php'); return; } elseif ($_SERVER["REQUEST_URI"]=='/robots.txt') { echo 'User-agent: *' . PHP_EOL; if ($_SERVER['HTTP_HOST'] == 'bookup.asia') { echo 'Disallow:' . PHP_EOL; } else { echo 'Disallow: /' . PHP_EOL; } return; } // if ($_SERVER["REQUEST_URI"]=='/th') // { // echo 'dddd'; // return; // } // if ($_SERVER["REQUEST_URI"]=='/en') // { // echo 'dddd'; // return; // } if(@$_REQUEST['resess']) { if($_REQUEST['resess']!='undefined') { $_SESSION['curtab'] = $_REQUEST['resess']; echo 'OK+'.$_REQUEST['resess']; } return; } include_once('common/clib.php'); // if(local()) query('DELETE FROM tmp'); session_start(); include_once 'private.php'; // $url_check = explode("/", $_SERVER['HTTP_REFERER']); // if(substr($url_check[count($url_check)-1], 0,4) == "demo" ) { // if(strpos($_SERVER['HTTP_REFERER'],'demo') > 0 || strpos($_SERVER['HTTP_REFERER'],'customer') > 0) { // // strpos($_SERVER['HTTP_REFERER'],'customer') > 0 // if(strpos($_SERVER['REQUEST_URI'],'demo') <= 0 && strpos($_SERVER['REQUEST_URI'],'customer') <= 0 ) { // // if(empty($_SESSION['user_logged_in']['user'])) { // // $_SESSION = $_SESSION['user_logged_in']; // // } else { // // $_SESSION = $_SESSION['user_logged_in']; // // } // if(empty($_SESSION['user_logged_in'])) { // unset($_SESSION['user']); // } else { // getUser(array('user_id' => $_SESSION['user_logged_in'])); // } // } // if(strpos($_SERVER['REQUEST_URI'],'customer') > 0) { // // $_SESSION['user'] = getUser(array('user_id' => 5, 'demo' => true)); // } // } // if( (empty($env['demo'])) AND ($uid <= 3) ): // $_SESSION = $_SESSION['user_logged_in']; // endif; $_SESSION['packmode'] = 'bundle'; $tran_system = 'bookup'; //$params['user_id'] = 1; if(!$_SESSION['user_id'] || $_SESSION['force_login']) { if($_SESSION['force_login']) { unset($_SESSION['force_login']); $params['user_id'] = $_SESSION['user_id']; } else $params['user_id'] = id_decode($_COOKIE['user_id']); getUser($params); } if (@$_REQUEST['proxy']) { header( "Content-type: text/json"); header( "Status: 200"); header("HTTP/1.1 200 OK", true, 200); $mod = $_REQUEST['proxy']; // $req = json_decode_nice( r( urldecode( $_REQUEST['q'] ),"x"", '\"'), true); $base64 = @$_POST['proxy'] ? true : false; $req = json_decode_nice( $_REQUEST['q'], true, $base64); // if($req) { if( $_SESSION['lang'] && !$req['lang'] ) $req['lang'] = $_SESSION['lang']; if($mod != "book_mobile.a") $req['user_id'] = $_SESSION['user_id']; if($mod == 'book.a' && $req['offer_id']) { $req['staff_id'] = 1; //getDBValue('select staff_id from staff where role_id ="manager" and shop_id = '.$); } // pr($req); echo proxy($mod, $req); } exit(); } $q = array('key'=> KEY); $ender = strpos($_SERVER["REQUEST_URI"],'?') > 0 ? strpos($_SERVER["REQUEST_URI"],'?') : strlen($_SERVER["REQUEST_URI"]); $loc = explode('/',substr($_SERVER['REQUEST_URI'],0, $ender )); $para = array(); parse_str( strpos( $_SERVER["REQUEST_URI"],'?') > 0 ? substr($_SERVER["REQUEST_URI"], strpos($_SERVER["REQUEST_URI"],'?')+1) : '', $para); if(strpos($_SERVER['HTTP_REFERER'],'demo') > 0 || strpos($_SERVER['HTTP_REFERER'],'customer') > 0) { if(strpos($_SERVER['REQUEST_URI'],'demo') <= 0 && strpos($_SERVER['REQUEST_URI'],'customer') <= 0 ) { if(empty($_SESSION['user_logged_in'])) { unset($_SESSION['user']); } else { getUser(array('user_id' => $_SESSION['user_logged_in'])); } } } if(isadmin()){ $_SESSION['role_id'] = 'admin'; } if(iscoor()){ $_SESSION['role_id'] = 'coor'; } $uid = @$_SESSION['user_id']; $role = $_SESSION['role_id']; $user = $_SESSION['user']; // pr($loc); // exit(); $predef = array( BE ,'loc','test', 'profile'); $env = explode('.', r(r($_SERVER['SERVER_NAME'], '.'.DOM ), DOM )); $subdom = str_replace( $predef, "", $env[ count($env)-1 ] ); $region = strtoupper($subdom); // $qq = 'select * from region_v where region_id = "'.$region.'" or alias="'.$subdom.'"'; // $region = query_record($qq); $_env = $_SESSION['env']; $lang = $_SESSION['env']['lang'] ? $_SESSION['env']['lang'] : 'th'; if($uid > 0){ // $lang = getDBValue('select lang_id from user where user_id = '.$uid); $ulang = api2one("user",array("user_id" => $uid)); $lang = $ulang['lang_id']; $_SESSION['lang'] = $ulang['lang_id']; $lang = $_SESSION['lang']; // exit(); } else { /* * one time * * */ if (!isset($_SESSION['lang'])) { if (getCountryFromIP($_SERVER["REMOTE_ADDR"], "code") != "TH") { $_SESSION['lang'] = "en"; } else { $_SESSION['lang'] = "th"; } } $lang = $_SESSION['lang']; } $allowed_curr = getDBArray("select fxcode from forex_v"); if($para['fx']) { if (in_array($para['fx'] , $allowed_curr) ) { $_SESSION['env']['fxcode'] = $para['fx']; } /* * * clear URL * * */ unset($para['fx']); $url = parse_url($_SERVER["REQUEST_URI"]); $url = $url['path'] . (count($para) > 0 ? '?' . http_build_query($para) : ''); header('Location: ' . $url, true, 301); exit; } if(!$curr) $curr = $_SESSION['env']['fxcode'] ? $_SESSION['env']['fxcode'] : $_SESSION['env']['region']['fxcode']; if(!$curr) $curr = 'THB'; $rate = api2one('forex',array('fxcode'=>$curr)); $_SESSION['env']['fxrate'] = $rate['fxrate']; //pr($_SESSION['env']['fxrate']); // $qq = 'select * from region_v where region_id = "'.$region.'" or alias="'.$subdom.'"'; // $region = query_record($qq); if(is_numeric($region)) $region = api2("region",array("region_id" => $region, "alias" => '|?|'.$subdom)); // pr($region); // exit(); if(!$region || !is_numeric($region))// || ! in_array( $region, getDBArray('select region_id from region') )) { /* * Modify script by TAN * 24 Jan 2014 */ $uri = explode("/", $_SERVER['REQUEST_URI']); if($uri[1] == "region" AND !empty($uri[3])): if($uri[3] != $_SESSION['region']): $region = $uri[3]; $_SESSION['region'] = $region; else: $region = $_SESSION['region']; endif; header("Location: $_SERVER[HTTP_REFERER]"); else: if(!empty($_SESSION['region'])): $region = $_SESSION['region']; else: $region = '1'; $_SESSION['region'] = $region; endif; endif; // $qq = 'select * from region_v where region_id = "'.$region.'" or alias="'.$subdom.'"'; //$region = query_record($qq); $region = api2("region",array("region_id" => $region, "alias" => '|?|'.$subdom)); // pr($region); } $page = ''; if ( in_array( $loc[1], getDBArray('select lang_id from lang') ) ) { $lang = $loc[1]; $page = $loc[2]; $demoFront = $loc[3]; $_SESSION['lang'] = $lang; if($uid > 0) query('update user set lang_id = "'.$lang.'" where user_id = '.$uid); if( empty($loc[0]) && empty($loc[2]) && ($loc[1] == "en" || $loc[1] == "th") && ( strpos($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']) ) ) { // header("location: $_SERVER[HTTP_REFERER]"); } } else { $page = $loc[1]; } // if(strlen($loc[1]) == 2) { // if ( in_array( $loc[1], getDBArray('select lang_id from lang where lang_id in("en","th")'))) { // $lang = $loc[1]; // } else { // $lang = "en"; // header("Location: ".r($_SERVER['REQUEST_URI'],"/".$loc[1]."/","/en/")); // } // } if(strlen($loc[1]) == 2 && $page != 'shop') { if ( in_array( $loc[1], getDBArray('select lang_id from lang where lang_id in("en","th")'))) { $lang = $loc[1]; } else { $lang = "en"; header("Location: ".r($_SERVER['REQUEST_URI'],"/".$loc[1]."/","/en/")); } } else { if ( in_array( $loc[1], getDBArray('select lang_id from lang where lang_id in("en","th","ru")'))) { $lang = $loc[1]; $_SESSION['lang'] = $lang; $_SESSION['env']['lang'] = $lang; $_SESSION['env']['lang_name'] = getDBValue('select lang_name from lang where lang_id = "'.$lang.'"'); } } if(!$lang) $lang = 'th'; if( $page == 're' ) { require_once ('review_mobile.php'); return; } if($para['paypal']) { if($para['paypal']!='cancel' && $para['paypal']!='notify' && strlen($para['paypal'])==32 ) query('update invoice set status_id = "PAID" where tracker = "'.$para['paypal'].'"'); $invoice_id = getDBValue('select invoice_id from invoice where tracker = "'.$para['paypal'].'"'); proxy("invoice.evt",array("plan_id"=>"resend","period"=>$invoice_id)); unset($para['paypal']); $spa = joinURLParams($para); header("Location: /shop".($spa?'?'.$spa:'')); return; } $plan = 'basic'; if( $page == 'shop' && $para['admin'] > 0 && iscoor() ) { if (!$uid) $uid = ($_SESSION['user_id']?$_SESSION['user_id']:1); // $checkAdmin = getdata("SELECT role_id FROM user WHERE user_id = '".$uid."'"); $checkAdmin = api2('user' , array('user_id' => $uid)); if($checkAdmin[0]['role_id'] != "coor"): $checkThisShop = getdata("SELECT staff_id FROM staff WHERE staff_id = '".$uid."' AND canceled = '0' AND shop_id = '".$para['admin']."'"); if(!$checkThisShop): include_once('404.php'); return; endif; endif; // $role = 'admin'; // $plan = 'gold'; getCoor($uid, $para['admin']); redirect('/'.$_SESSION['lang'].'/shop'); } if( $page == 'shop' && $para['admin'] > 0 && isadmin() ) { if (!$uid) $uid = ($_SESSION['user_id']?$_SESSION['user_id']:1); // $checkAdmin = getdata("SELECT role_id FROM user WHERE user_id = '".$uid."'"); $checkAdmin = api2('user' , array('user_id' => $uid)); if($checkAdmin[0]['role_id'] != "admin"): $checkThisShop = getdata("SELECT staff_id FROM staff WHERE staff_id = '".$uid."' AND canceled = '0' AND shop_id = '".$para['admin']."'"); if(!$checkThisShop): include_once('404.php'); return; endif; endif; // $role = 'admin'; // $plan = 'gold'; getAdmin($uid, $para['admin']); redirect('/'.$_SESSION['lang'].'/shop'); } if( $page == 'shop' && $para['admin']) // In case of Normal User but have 2 shop manage { if(!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])) { include_once('404.php'); return; } if (!$uid) $uid = ($_SESSION['user_id']?$_SESSION['user_id']:1); // $checkAdmin = getdata("SELECT role_id FROM user WHERE user_id = '".$uid."'"); $checkAdmin = api2('user' , array('user_id' => $uid)); if($checkAdmin[0]['role_id'] == "user"): $checkThisShop = getdata("SELECT staff_id FROM staff WHERE staff_id = '".$uid."' AND canceled = '0' AND shop_id = '".$para['admin']."'"); if(!$checkThisShop): include_once('404.php'); return; endif; endif; //$role = 'staff'; //$plan = 'gold'; getStaff($uid, $para['admin']); redirect('/'.$_SESSION['lang'].'/shop'); } if( $page == 'mobile-shop' && $para['admin'] && $uid ) { $checkAdmin = api2('user' , array('user_id' => $uid)); if($checkAdmin[0]['role_id'] == "user"): $checkThisShop = getdata("SELECT staff_id FROM staff WHERE staff_id = '".$uid."' AND canceled = '0' AND shop_id = '".$para['admin']."' AND role_id = 'manager'"); if(!$checkThisShop): unset($_SESSION['mobile']['shop']); include_once('404.php'); return; endif; endif; $_SESSION['mobile']['shop'] = api2one('shop', array( key => KEY, "shop_id" => $para['admin'])); if(!empty($_SESSION['mobile']['shop'])) { redirect('/'.$_SESSION['lang'].'/mobile-shop'); } else { unset($_SESSION['mobile']['shop']); include_once('404.php'); return; } } if( $page == 'mobile-offer' && $para['admin'] && $uid ) { $checkAdmin = api2('user' , array('user_id' => $uid)); if($checkAdmin[0]['role_id'] == "user"): $checkThisShop = getdata("SELECT staff_id FROM staff WHERE staff_id = '".$uid."' AND canceled = '0' AND shop_id = '".$para['admin']."' AND role_id = 'manager'"); if(!$checkThisShop): unset($_SESSION['mobile']['shop']); include_once('404.php'); return; endif; endif; $_SESSION['mobile']['shop'] = api2one('shop', array( key => KEY, "shop_id" => $para['admin'])); if(!empty($_SESSION['mobile']['shop'])) { redirect('/'.$_SESSION['lang'].'/mobile-offer'); } else { unset($_SESSION['mobile']['shop']); include_once('404.php'); return; } } if( $page == 'mobile-location' && $para['admin'] && $uid ) { $checkAdmin = api2('user' , array('user_id' => $uid)); if($checkAdmin[0]['role_id'] == "user"): $checkThisShop = getdata("SELECT staff_id FROM staff WHERE staff_id = '".$uid."' AND canceled = '0' AND shop_id = '".$para['admin']."' AND role_id = 'manager'"); if(!$checkThisShop): unset($_SESSION['mobile']['shop']); include_once('404.php'); return; endif; endif; $_SESSION['mobile']['shop'] = api2one('shop', array( key => KEY, "shop_id" => $para['admin'])); if(!empty($_SESSION['mobile']['shop'])) { redirect('/'.$_SESSION['lang'].'/mobile-location'); } else { unset($_SESSION['mobile']['shop']); include_once('404.php'); return; } } if($_SESSION['mobile']['shop']) { $_SESSION['mobile']['shop'] = api2one('shop', array( key => KEY, "shop_id" => $_SESSION['mobile']['shop']['shop_id'])); } if( $page == 'demo' || $subdom == 'demo' || $page == 'favicon.ico' || $demoFront == "demo" ) { $mod = $para['mod']; $plan = $para['plan']; $mods = array('manager','staff','boss','website','customer'); $plans = array('basic','silver','gold'); $uids = array('manager'=>4,'staff'=>2,'boss'=>3,'customer'=>5); if(!$mod || ! in_array($mod, $mods) || ! in_array($plan, $plans)) { include_once('demo.php'); return; } $demo = true; if($demoFront != "demo"){ $page = 'shop'; // $demoFront = ""; } $uid = $uids[$mod]; $role = $mod; // // if(!local()) bug('
'.neat_r($_SERVER,true).'
','Demo view at bookup'); // $_SESSION['user_id'] = 1; // $_SESSION['role'] = 'manager'; getUser(array('user_id' => $uid, 'demo' => $demo )); } if(@$_SESSION["icode"]){ $para["icode"] = $_SESSION["icode"]; // unset($_SESSION[icode]); } $lang_name = api2one('lang',array('lang_id' => $lang)); $lang_name = $lang_name['lang_name']; $env = array( 'dev' => in_array( 'loc', $env ), 'test' => in_array( 'test', $env ), 'shop' => in_array( BE, $env ) || $page == BE, 'region' => $region[0], 'lang' => $lang, 'lang_name' => $lang_name, 'page' => $page, 'admin' => $admin, 'plan' => $plan, 'fxcode' => $curr, 'para' => $para, 'demo' => $demo ); $env['reg'] = (!$_SESSION['shop'] && !isdemo()) && !$_REQUEST['proxy'] && $page == 'shop'; if(!$para['proxy']) $_SESSION['env'] = $env; // px("@ session index ".$_SESSION["user"].'-'.$page.'-'.$_SESSION['shop'].'-'.$para["icode"].'='.$_SESSION["referer"].'='.$_SESSION["icode"]); // px($env); if( $page == 'shop' && $_SESSION["user"] && !$_SESSION['shop'] && $env['para']['icode'] ) { // px(ROOT.'/project/php/events.php'); exit(); $res = icode($env['para']); $url = $_SERVER["REQUEST_URI"]; if(strpos($url, '#')) $url = substr($url, 0, strpos($url, '#') ); if(strpos($url, '?')) $url = substr($url, 0, strpos($url, '?') ); header ("Location: ".$url); return; } $head = true; $footer = true; $default_driver = 'frontend2.php'; $driver = $default_driver; $theme = 'medical'; // if(!$apart) $apart = "front"; $ppjs[] = null; $icode_dehash = dehash($page); if( (!$_SESSION["shop"] && $page[0] === "0" && strlen($page) == 7) || strlen($icode_dehash) == 6 ) { $icode = substr($page,1); if( (is_numeric($icode) && getDBValue("select shop_id from shop where icode = '".$icode."'")) || (is_numeric($icode_dehash) && getDBValue("select shop_id from shop where icode = '".$icode_dehash."'")) ) { $head = false; $footer = false; $theme = 'landing'; $driver = 'landing.php'; $apart = 'landing'; if(is_numeric($icode_dehash) && getDBValue("select shop_id from shop where icode = '".$icode_dehash."'")){ $_SESSION["icode"] = $icode_dehash; } else { $_SESSION["icode"] = $icode; } $_SESSION["referer"] = '/'.$lang.'/shop'; } } if($page=='auth'){ if( !uid() ){ $head = false; $footer = false; $theme = 'landing'; $driver = 'auth.php'; $apart = 'landing'; if($_SERVER['HTTP_REFERER']) $_SESSION['referer'] = $_SERVER['HTTP_REFERER']; // px($_SESSION['referer']); // exit(); }else{ if($_SESSION['referer']){ redirect($referer); } else $driver = $default_driver; } } if($page == 'user' AND !empty($_SESSION['user'])): $head = true; $footer = true; $theme = 'v2'; $driver = 'user.php'; endif; if($page == 'promotion'): $head = true; $footer = true; $navigation = true; $theme = 'v2'; $driver = 'all_promotion.php'; endif; if($page == 'partner-client'): $head = true; $footer = true; $navigation = true; $theme = 'v2'; $driver = 'partner.php'; endif; if($page == 'widget'): $head = false; $footer = false; $bootstrap = 3; $theme = 'widget-1.0'; $driver = 'widget.php'; endif; if($page == 'update-shop-admin'): $head = true; $footer = false; $navigation = true; $theme = 'v2'; $driver = 'update-shop-admin.php'; endif; if($page == 'callcenter'): $head = true; $footer = false; $navigation = true; $theme = 'v2'; $driver = 'callcenter.php'; endif; if($page == 'article'): $head = true; $footer = true; $navigation = true; $theme = 'v2'; $driver = 'article.php'; $uri = explode("/", $_SERVER['REQUEST_URI']); if($uri[1] == "article" AND !empty($uri[2]) AND is_numeric($uri[2])) { $article = api2one('article', array("article_id" => $uri[2])); } elseif($uri[2] == "article" AND strlen($uri[1]) == 2 AND !empty($uri[3]) AND is_numeric($uri[3])) { $article = api2one('article', array("article_id" => $uri[3])); // $lang = $uri[1]; } else { // all articles } $canonical_array[] = $page; if (!empty($article)) { $title = $article['title']; $keywords = $article['keyword']; $desc = $article['descr']; $canonical_array[] = $article['article_id']; $canonical_array[] = urlname($article['title']); } // pr($uri); // exit(); endif; if($page == 'search'): $head = true; $footer = true; $navigation = true; $theme = 'v2'; $driver = 'search.php'; $uri = explode("/", $_SERVER['REQUEST_URI']); // pr($uri); // exit(); endif; if($page != 'search') { unset($_SESSION['freesearch']); } $industrys = api2('industry'); $allowed_industrys = array(); $industry_array = array(); foreach ($industrys as $id=>$one) { $allowed_industrys[] = $one['industry_id']; $industry_array[$one['industry_id']] = $one; } // px($env); exit; //print_r($loc); //print_r($page); //exit; if( in_array($page, $allowed_industrys) || $page == "search" ){ $from_old_to_new = array( 'rhinoplasty' => 'nose-surgery', 'antitoxin-mask' => 'facial-mask', 'herb-mask' => 'facial-mask', 'bleaching' => 'tooth-whitening', 'face' => 'facial-treatment', 'hair-wax' => 'wax', 'jacuzzi' => 'hydrotherapy', 'parafango-all-body в parafango', ); $canonical_array[] = $page; $env['industry'] = $page; if (isset($loc[4]) && $loc[4] != '') { $region_info = api2one('industryregion', array('region_name_url' => reurlname($loc[4]))); if (empty($region_info)) { // 404 header('Location: /' . $lang . '/' . $page, true, 301 ); exit; } } if (isset($loc[3]) && $loc[3] != '') { if (is_numeric($loc[3])) { /* * service_id? * * */ $data = api2one('service', array('industry_id' => $page, 'service_id' => $loc[3])); if (empty($data)) { // 404 header('Location: /' . $lang . '/' . $page, true, 301 ); exit; } else { $loc[3] = url($data['alias'], true); if (isset($from_old_to_new[$loc[3]])) { $loc[3] = $from_old_to_new[$loc[3]]; } $service_array[$data['service_id']] = $data; $title_array[] = $data['service_name']; $seo_key[] = $data['alias']; $h1_array[] = $data['service_name']; $canonical_array[] = $loc[3]; } } else { /* * multiple service * * */ $services = explode('+', $loc[3]); $canonical_service = array(); for ($i = 0, $ic = count($services); $i < $ic; $i++) { if (isset($from_old_to_new[$services[$i]])) { $services[$i] = $from_old_to_new[$services[$i]]; } $data = api2one('service', array('industry_id' => $page, 'service_name' => url($services[$i], true))); if (empty($data)) { // 404 // header('Location: /' . $lang . '/' . $page, true, 301 ); // exit; } else { $canonical_service[] = $services[$i]; $service_array[$data['service_id']] = $data; $title_array[] = $data['service_name']; $seo_key[] = $data['alias']; $h1_array[] = $data['service_name']; } } $canonical_array[] = implode('+', $canonical_service); } if (empty($service_array)) { $region_info = api2one('industryregion', array('region_name_url' => reurlname($loc[3]))); } } if (empty($title_array)) { $title_array[] = $industry_array[$page]['industry_name']; } if (!empty($service_array)) $env['service_id'] = array_keys($service_array); /* * * old version. up - new. * * $env['industry'] = $page; if(!is_numeric($loc[2]) ) { // in this case url should look like /en/beauty/bangkok or /en/beauty/bangkok/69 // check fro region, update env, service too, render list of services accordingly if( !is_numeric($loc[3]) ) { if(strstr($loc[3], "?")){ $region = r($loc[3],'?'.$_SERVER['QUERY_STRING'],' '); } $region = clear(strtolower(r($loc[3],'-',' '))); // $qq = "select * from region where region_name like \"$region\" or alias like \"$region\""; // $region = query_record($qq); $region = api2one('industryregion' , array('region_name_url' => $region)); if($region) { $env['region'] = $region; // $_SESSION['env']['region'] = $region; $_SESSION['region_name_url'] = urlname($region['region_name_url']); $_SESSION['region_name'] = $region['region_name']; $_SESSION['region'] = $region['region_id']; $_SESSION['telcode'] = $region['telcode']; // $_SESSION['shop']['fxcode'] = $region['fxcode']; $_SESSION['country_id'] = $region['country_id']; $_SESSION['country_name'] = $region['country_name']; $_SESSION['mobexample'] = $region['mobexample']; $_SESSION['telexample'] = $region['telexample']; } if( $region && is_numeric($loc[4]) ) $env['service_id'] = $loc[4]; } if( is_numeric($loc[3]) ) $env['service_id'] = $loc[3]; } */ if(!empty($_REQUEST['region_id'])) { $region_info = api2one('industryregion', array('region_id' => $_REQUEST['region_id'])); } } else $env['industry'] = $allowed_industrys[0]; if (empty($region_info) && !isset($_SESSION['region_name_url'])) { $region_info = api2one('industryregion', array('region_name_url' => 'bangkok')); } else { if (!empty($region_info)) { $region_request = urlname($region_info['region_name_url']); $canonical_array[] = $region_request; if (!empty($env['service_id'])) { $title_array[count($title_array) - 1] .= ($lang == 'en' ? ' in ' : ' ') . $region_info['region_name'] . ', ' . $region_info['country_name'] ; $h1_array[count($h1_array) - 1] .= ($lang == 'en' ? ' in ' : ' ') . $region_info['region_name']; } else { $title_array[] = $region_info['region_name']; $h1_array[] = $region_info['region_name']; } } } if (!empty($region_info)) { $env['region'] = $region_info; $region = $region_info; $_SESSION['region_name_url'] = urlname($region['region_name_url']); $_SESSION['region_name'] = $region['region_name']; $_SESSION['region'] = $region['region_id']; $_SESSION['telcode'] = $region['telcode']; // $_SESSION['shop']['fxcode'] = $region['fxcode']; $_SESSION['country_id'] = $region['country_id']; $_SESSION['country_name'] = $region['country_name']; $_SESSION['mobexample'] = $region['mobexample']; $_SESSION['telexample'] = $region['telexample']; } if(isset($loc[5]) && $loc[5] != '') { $area = api2one('poparea', array('area_name_url' => reurlname($loc[5]))); if(empty($area)) { $_SESSION['area-lat'] = ''; $_SESSION['area-lng'] = ''; $_SESSION['area'] = ''; } else { $_SESSION['area'] = url($loc[5]); $canonical_array[] = $_SESSION['area']; $_SESSION['area-lat'] = $area['lat']; $_SESSION['area-lng'] = $area['lng']; if($lang == "en") { $a_name = $area['area_name']; } else { $a_name = $area['area_name_'.$lang]; } $title_array[] = $a_name; $h1_array[] = $a_name; } } else { $_SESSION['area-lat'] = ''; $_SESSION['area-lng'] = ''; $_SESSION['area'] = ''; } if( $page == 'check' ) { if(!isadmin()) { $_SESSION['referer'] = 'http://'.domain().'/check'; redirect('http://'.domain().'/auth'); exit(0); } $driver = 'admin.php'; // $theme = 'medical'; $apart = 'admin'; } if( $page == 'profile' || $env['shop'] ) { $driver = 'backend/index.php'; $head = false; $footer = false; } if($page=='help') $driver = 'faq/index.php'; if($page=='demo') $driver = 'demo.php'; if( $driver==$default_driver && $uid == 1 ) unset($_SESSION); if($env['page']=='shop') { $apart = 'shop'; $theme = null; } if($env['reg']) { $apart = 'reg'; } if($driver == 'frontend2.php'){ $theme = 'v2'; $head = true; } // px($env); px($_SESSION); exit; $templates = array( 10 => 'beauty', 11 => 'medical', 12 => 'facebook', 13 => 'landing', 14 => 'fbv2', 15 => 'v2', 77 => 'v2' ); if(is_numeric($env['page']) && !($page[0] === "0") ) { $pid = $env['page']; $pcl = substr($pid, 0, 2); $pid = substr($pid, 2); if(!$pid && $templates[$pcl]=='facebook') { include_once('fb/sdk/facebook.php'); $config = array(); $config['appId'] = '393085174112783'; $config['secret'] = 'bcc89ccbbe4956e5f35c9c590042dc62'; $config['cookie'] = true; try{ $facebook = new Facebook($config); $signed_request = $facebook->getSignedRequest(); }catch(Exception $e){ } // px($signed_request); /* [algorithm]: HMAC-SHA256 [expires]: 1383732000 [issued_at]: 1383726060 [oauth_token]: CAAFlgkYrYg8BAEqahTZCs5i9t9N1qCuNdepvpcnOMDIOa4xDm8Cnn6meZCf5rb0qnEwT4NKK4a3Whuz12fLBZA01Y7DrdZBbbuFeKkjQSnXzEZAhoo2ctOTkSlvwiLlaeuuO7sGbFIwvBArOlj0pJMhxbHpqiVXz122nUIVoyiDTvwXnP2AjnPJZBcyhFy6PQHES7aJ656JwZDZD [page]: [id]: 334123136719136 [liked]: [admin]: 1 [user]: [country]: th [locale]: en_GB [age]: [min]: 21 [user_id]: 803965605 */ $pid = getDBValue('select shop_id from shop where facebook = "'.$signed_request['page']['id'].'"'); /* px("Get shop ID = ".$pid); px("Get user ID = ".$signed_request['user_id']); px($signed_request); */ $uid = //'804064722';//'siriporn.prasongsuk'; $signed_request['user_id']; if(!$uid) { px("Please login to Facebook to book services"); } else { $exist_uid = getDBValue('select user_id from user where facebook_id = "'.$uid.'"'); if( $exist_uid ) { // user exists, login $params = array(); $params['user_id'] = $exist_uid; getUser($params); $user = $_SESSION['user']; } } // px($user); if(!$user) { // $_SESSION['identifier'] = $signed_request['user_id']; // $user = login('facebook', false); $xuser = $facebook->api('/'.$uid,'GET'); $api = array( 'key' => KEY, 'facebook_id' => $uid, 'user_name' => $xuser['first_name'].' '.$xuser['last_name'], 'gender' => $xuser['gender'] == 'female' ? 'F' : 'M', 'lang_id' => substr($xuser['locale'],0,2), 'photo' => 'https://graph.facebook.com/'.$uid.'/picture?type=large' ); // px("trying to login/create"); $result = api(getAppName(), 'user', $api, 'a'); // px($result); if($result['response'][0]['user_id']) getUser(array('user_id'=>$result['response'][0]['user_id'])); } } if(!$pid) { include_once('404.php'); return; } if( in_array( $pcl, array_keys($templates) ) ) // shop $driver = 'dom'.$pcl.'.php'; $q = array( 'key' => KEY, 'shop_id' => $pid, 'active' => 1, 'alt' => ">0", 'lang' => $env['lang'] ); $pageId = getDBArray("SELECT * FROM `shop` WHERE icode = '$pid' AND active = '0'"); if(!$shop) $shop = api2one('shop', $q); $current_template = substr($env['page'], 0, 2); if(!$shop AND $current_template == 11): include_once('404.php'); return; elseif(empty($pageId) AND $current_template == 13): include_once('404.php'); return; endif; $offs = array( 'shop_id' => $pid, 'canceled'=>0, 'limit'=>300 ); if(!$offer) $offer = api2('offer', $offs); $review = api2('review', $q); $blog = api2('blog', $q); $qstaff = $q; // $qstaff['role_id'] = array('staff'); $qstaff['role_id'] = array('staff','manager'); $qstaff['staff_id'] = ">1"; $staff = api2('staff', $qstaff); //$sched = api2('sched', $q); if ($shop['shop_id']) { // $sched = api2('sched', array("shop_id"=>$shop['shop_id'])); $sched = getdata("SELECT * FROM sched WHERE shop_id = ".$shop['shop_id']." AND LENGTH(WEEKDAY) = 1 AND WEEKDAY > 0"); if (empty($sched)) { for ($i=1;$i<=7;$i++){ query("INSERT INTO sched (shop_id,weekday,time_start,time_end,closed) VALUE (".$shop['shop_id'].",".$i.",'10:00:00','20:00:00',0)"); } }else{ foreach ($sched as $key => $value) { $weekday[] = $value['weekday']; } for ($i=1;$i<=7;$i++){ if(!in_array($i, $weekday)){ query("INSERT INTO sched (shop_id,weekday,time_start,time_end,closed) VALUE (".$shop['shop_id'].",".$i.",'10:00:00','20:00:00',0)"); } } } $sched = api2('sched', array("shop_id"=>$shop['shop_id'])); // if(count($sched) < 7){ // for ($i=1;$i<=7;$i++){ // query("INSERT INTO sched (shop_id,weekday,time_start,time_end,closed) VALUE (".$shop['shop_id'].",".$i.",'10:00:00','20:00:00',0)"); // } // $sched = api2('sched', $q); // } } // pr($sched); $worktime = array(); /* new sched */ $new_sched = $sched; if(count($new_sched) == 1 AND $new_sched[0]['weekday'] == 0): $worktime[0]['day_name'] = tran("Daily"); $worktime[0]['day_time'] = ( $new_sched[0]['time_start'] == $new_sched[0]['time_end'] ? "24 ".tran("hrs") : $new_sched[0]['time_start']." - ".$new_sched[0]['time_end'] ); else: if($new_sched[0]['weekday'] == 0): unset($new_sched[0]); endif; foreach($new_sched as $id => $one): if ($one['closed'] == 0 AND strlen($one['weekday']) == 1): $worktime[$one['weekday']]['day_name'] = convert_date($one['weekday']); $worktime[$one['weekday']]['day_time'] = ( $one['time_start'] == $one['time_end'] ? "24 ".tran("hrs") : $one['time_start']." - ".$one['time_end'] ); else: if(strlen($one['weekday']) == 1): $worktime[$one['weekday']]['day_name'] = convert_date($one['weekday']); $worktime[$one['weekday']]['day_time'] = tran("Close"); endif; endif; endforeach; endif; if(empty($worktime)): /* old sched */ $days = str_split($sched[0]['weekday']); foreach($days as $value): $worktime[$value]['day_name'] = convert_date($value); $worktime[$value]['day_time'] = ( $sched[0]['time_start'] == $sched[0]['time_end'] ? "24 ".tran("hrs") : $sched[0]['time_start']." - ".$sched[0]['time_end'] ); endforeach; endif; /* * * show or hide rows * * */ if (isset($_SESSION['user']) && !empty($_SESSION['user'])) { $ppjs[] = 'if(typeof $shared == "undefined")$shared=[];'; function offer_input_hide($i) { $offer_input_hide = array( 'phone' => '', 'phone_other' => '', 'email' => '', ); return array_diff_key($i, $offer_input_hide); } $ppjs[] = '$shared.shop={' . $shop['shop_id'] . ':' . json_encode_nice( array_map('offer_input_hide', $offer) ) . '};'; $ppjs[] = '$shared.sched={' . $shop['shop_id'] . ':' . json_encode_nice( $sched ) . '};'; $shop_input_show = array( 'shop_id' => '', 'shop_name' => '', 'address' => '', 'location' => '', 'branch_name' => '', 'region_id' => '', 'region_name' => '', 'country_name' => '', 'lat' => '', 'lng' => '', 'website' => '', 'facebook' => '', 'google' => '', 'instagram' => '', 'youtube' => '', 'twitter' => '', 'rating' => '', 'reviews' => '', 'icode' => '', ); $ppjs[] = '$shared.shophdr={' . $shop['shop_id'] . ':' . json_encode_nice( array_intersect_key($shop, $shop_input_show) ) . '};'; } $shop_name = $shop['shop_name']; $shopimg = '/images/shop/'.$shop['shop_id'].'/main.jpg'; if( !file_exists(ROOT.$shopimg) ) { $shopimg = '/images/notfound.png';//'/'.rand_file( 'images/front/') if( $shop['lat']) { // $shopimg = 'http://maps.googleapis.com/maps/api/streetview?location='.$shop['lat'].','.$shop['lng'].'&size=280x200&sensor=false'; $shopimg = 'http://maps.googleapis.com/maps/api/staticmap?center='.$shop['lat'].','.$shop['lng'].'&markers=icon:http://bookup.asia/images/icons/marker_red.png|'.$shop['lat'].','.$shop['lng'].'&style=hue:0xd72525|saturation:-50&zoom=15&size=1200x400&sensor=false&key='.$googlekey; } } // if($pcl ==12) // $head=false; // $footer = false; if($pcl == 12) { global $shop_id; $shop_id = substr($env['page'], 2); $head = false; $footer = false; $navigation = false; } if($pcl==14){ $apart = 'fbv2'; $head=false; $footer = false; } if($pcl==13){ $head=false; $footer = false; $driver = 'landing.php'; $apart = 'landing'; } if($pcl==11){ global $shop_id; $shop_id = substr($env['page'], 2); $head = true; $footer = true; $navigation = true; } if($pcl==77){ global $shop_id; $shop_id = substr($env['page'], 2); $head = true; $footer = true; $navigation = true; } $theme = $templates[$pcl]; } // if($env['page'] == "promotions"): // $driver = "promotions.php"; // endif; // $content = getdata("SELECT * FROM frontendpage WHERE frontendpage_url = '".$env['page']."'"); $content = api2('frontendpage' , array('frontendpage_url' => $env['page'])); if($content): $driver = "frontend2.php"; // if($lang == "en"): // $content = $content[0]['frontendpage_text']; // else: // $content = $content[0]['frontendpage_text_'.$lang]; // endif; $content = $content; endif; if($page == 'site-map'): $head = true; $footer = true; $theme = 'v2'; $driver = 'site-map-frontend.php'; endif; if($page == 'search'): $head = true; $footer = true; $navigation = true; $theme = 'v2'; $driver = 'search.php'; endif; if($page == 'mobile-shop'): if(!empty($_SESSION['mobile']['shop'])) { $head = false; $footer = false; $navigation = false; $theme = 'v2'; $driver = 'mobile-shop.php'; } else { redirect('/'); } endif; if($page == 'mobile-offer'): if(!empty($_SESSION['mobile']['shop'])) { $head = false; $footer = false; $navigation = false; $theme = 'v2'; $driver = 'mobile-offer.php'; } else { redirect('/'); } endif; if($page == 'mobile-location'): if(!empty($_SESSION['mobile']['shop'])) { $head = false; $footer = false; $navigation = false; $theme = 'v2'; $driver = 'mobile-location.php'; } else { redirect('/'); } endif; $clickch = array("bp","mo"); if(in_array($page, $clickch )){ // 1 = bookComplete, 2 = regisComplete, 3 = sms if ( $page == 'bp'){ $channel = 3; } else if($page == 'mo') { $channel = 4; } else { } query("INSERT INTO log_click (channel, ip_add, device) VALUES (".$channel.", '".userip()."', '')"); // header("Location: " . $_GET['refer_url']); } if($_GET['ch']) { $_SESSION['channel_book'] = $_GET['ch']; } else { $_SESSION['channel_book'] = ""; } $bm->mark('t1'); $bm->mark('t2'); flush(); if (!$_SESSION['lang']) $_SESSION['lang'] = 'th'; if (!$_SESSION['mobexample']) $_SESSION['mobexample'] = 'xzzzzzzzz'; if (!$_SESSION['telexample']) $_SESSION['telexample'] = '0xxxxxxxx'; if (!$_SESSION['country_name']) $_SESSION['country_name'] = 'Thailand'; if (!$_SESSION['telcode']) $_SESSION['telcode'] = '66'; if(empty($env['page'])): $title = tran("default title"); $desc = tran("default desc"); $keywords = tran("default keyword"); $alt_ing = "bookup-"; $seo_key[] = 'Main'; elseif($env['page'] == "beauty"): if (!isset($env['service_id'])) { $title = tran("beauty title"); $desc = tran("beauty desc"); $keywords = tran("beaty keywords"); } $alt_ing = "bookup-beauty-"; $seo_key[] = $env['page']; elseif($env['page'] == "health"): if (!isset($env['service_id'])) { $title = tran("health title"); $desc = tran("health desc"); $keywords = tran("health keywords"); } $alt_ing = "bookup-health-"; $seo_key[] = $env['page']; elseif($env['page'] == "sport"): if (!isset($env['service_id'])) { $title = tran("sport title"); $desc = tran("sport desc"); $keywords = tran("sport keywords"); } $alt_ing = "bookup-sport-"; $seo_key[] = $env['page']; elseif($env['page'] == "education"): if (!isset($env['service_id'])) { $title = tran("education title"); $desc = tran("education desc"); $keywords = tran("education keywords"); } $alt_ing = "bookup-course-"; $seo_key[] = $env['page']; endif; $sitename = tran("facebook sitename"); if($para['fx']){ $fxt = ', '.tran('show_currency').':'.$para['fx']; }else{ $fxt = ''; } if ($region_request) { if ($region_request == 'bangkok') $seo_key = array(); // --- no seo for region ???? else $seo_key[] = $region_request; } if(!empty($article)): $title = $article['title']; $a_keywords = strip_tags($article['keyword']); $desc = strip_tags($article['descr']); $alt_ing = "bookup-".$title; elseif(!empty($shop)): $title = $shop['shop_name'] . ($lang == 'en' ? ' in ' : ' ') . $shop['region_name']; if ($shop['country_name'] != '') { $title .= ', ' . $shop['country_name'] .''; } $a_keywords = strip_tags($shop['class_code']).", ".$shop['region_name']; $desc = (!$shop['txt']||$shop['txt']!= '' ? strip_tags($shop['shop_name']) : strip_tags($shop['txt'])).", ".$shop['address']; $s_img = "/pic.php?dom=shop&id=".$shop['shop_id']; $alt_ing = "bookup-".$title; if($para['fx']){ $fxt = ', '.tran('show_currency').':'.$para['fx']; }else{ $fxt = ''; } endif; if($page == 'promotion') { $desc = tran('promo_landing_desc'); $keywords = tran('promo_landing_keyword'); $title = tran('promo_landing_title'); } if (isset($shop['shop_name'])) { $canonical_array = array(); $canonical_array[] = '11' . $shop['shop_id']; } elseif (!empty($title_array)&&$title == '') { $title = implode(', ', $title_array); } if ($title == '') { $title = tran("default title"); } if (!empty($canonical_array)) { $canonical = implode('/', $canonical_array); } else { $canonical = $env['page']; } if ($canonical != '') { $canonical = '/' . $canonical; } smsreminder(); ?> '; //} $description = substr(strip_tags($desc),0,($lang == 'th'?270:135)); $description = $description != '' ? $description . '...' : ''; ?> <?=$title;?> loadHTML($article['txt']); $dom->preserveWhiteSpace = false; $images = $dom->getElementsByTagName('img'); $thumbnail = ""; if($images->length != 0): $thumbnail = array(); foreach($images as $image): $thumbnail[] = $image->getAttribute('src'); endforeach; else: $thumbnail = "/images/fb_og.jpg"; endif; echo ""; foreach($thumbnail as $image): echo ""; echo ""; endforeach; echo ""; else: if (!$s_img) : if($page == 'beauty_point') { $og_img = "/images/shop/2/main.jpg"; } else if($page == 'promotion') { $og_img = "/images/shop/5/main.jpg"; } else { $og_img = "/images/shop/1/main.jpg"; } echo ""; else: echo ""; endif; endif; // if(!local()){ // echo ""; // } ?> ?> head.ready(function(){". join("\n",$ppjs). "});"; if($head) include_once('head.php'); include_once($driver); include_once('local/js.php'); if($footer) include_once('footer.php'); ?> sitemapCheck('".$loc[2]."')"; } } if($_GET['offer_id']) { if($_SESSION['user_id']) { echo ""; } else { echo ""; } } if (isset($_SESSION['signup'])) { echo ""; unset($_SESSION['signup']); } $bm->mark('t2'); $bm->mark(); if (isset($_GET['timer'])) { echo ''; }