<?php
$hosts = explode('.', $_SERVER['HTTP_HOST']);
$domain = $hosts[count($hosts)-2].'.'.$hosts[count($hosts)-1];
ini_set("session.cookie_domain", ".$domain");
session_start();

$lang = str_replace('_','-',$_GET['lang']);
require $_SERVER['DOCUMENT_ROOT']."/tpl/comm/php/sqlite.class.php";
//require "function.php";
global $sqlite;
$sqlite = new SQLITE;
$sqlite ->connWorkDB($_GET['shopid']);

$lang = $_GET['lang'];
$page = $_GET['page'];
$divid = $_GET['divid'];

$result1 = $sqlite -> query("select value from site_information where key = 'version'");
$version = $sqlite -> fetch_single($result1);
if($version > "1.02"){
	$query = $sqlite -> query("SELECT category, nums, titlelen, datestyle, displaystyle, img_h, img_w, skin_file  FROM boardPlugin WHERE  divid='$divid' and lang = '$lang' and page = '$page'");

}else{
	$query = $sqlite -> query("SELECT category, nums, titlelen, datestyle, displaystyle, img_h, img_w FROM boardPlugin WHERE  divid='$divid' and lang = '$lang' and page = '$page'");
}

if (!$config_myrow = $sqlite -> fetch_array($query)){
	$category = '0';
	$nums = '5';
	$titlelen = '20';
	$datestyle = '0';
	$displaystyle = '0';
	$img_h = '96';
	$img_w = '100';
	$skin_file = 'board.html';
}else{
	$category = $config_myrow['category'];
	$nums = $config_myrow['nums'];
	$titlelen = $config_myrow['titlelen'];
	$datestyle = $config_myrow['datestyle'];
	$displaystyle = $config_myrow['displaystyle'];
	$img_h = $config_myrow['img_h'];
	$img_w = $config_myrow['img_w'];
	$skin_file = $config_myrow['skin_file'];
	
	if (empty($skin_file)){
		$skin_file = 'board.html';
	}
}

$ext_sql = '';

if ($category != '0' ){
	
    if($version < "1.04"){	
		$ext_sql = "  and title <> '' and CAST(category AS TEXT) = '".intval($category)."' ";
	} else {
			$ext_sql = "  and title <> '' and (CAST(category AS TEXT) = '".intval($category)."' or CAST(cate_parent AS TEXT) = '".intval($category)."') ";
	}



}
$ext_sql .= "  order by id desc limit 0,$nums ";

$query = $sqlite->query("SELECT * FROM Board where depth = 0  and lang = '$lang'  $ext_sql ");
$result = $sqlite->fetch_all($query);
if ($result){
//<ul class="boardPluginul_v">
//<li class="img"><img width="100" height="100" border="0" alt="" src="/tpl/comm/img/noimage.gif"/></li>
//<li  class="text">Title</li></ul>
       //�������� Image Gallery
	if ($displaystyle == '1')
	{
		//echo 'document.write("<div class=\"boardPlugin\">");';
		foreach ($result as $myrow){
				if (!empty($myrow['photos'])){
					$photos = explode('|',$myrow['photos']);
					$photo_name = $photos[0];
					if (strpos(basename($photo_name),'demo-') === 0) {
						$photo = '/tpl/demo_img/' . basename($photo_name);
					} else {
						$photo = '/tpl/comm/php/thumb.php?sid='.urlencode($_GET['shopid']).'&f='.urlencode($photo_name).'&w='.$img_w.'&h='.$img_h;
					}
				}else{
					$photo = '/tpl/comm/img/noimage.gif';
				}

				echo 'document.write("<ul class=\"boardPluginul_v\"><li class=\"img\"><a href=\"'.$skin_file.'?action=read&id='.$myrow['id'].'\"><img width=\"'.$img_w.'\" height=\"'.$img_h.'\" border=\"0\"  src=\"'.$photo.'\" /></a></li>");';

                if($titlelen != 0){echo 'document.write("<li  class=\"text\"><a href=\"'.$skin_file.'?action=read&id='.$myrow['id'].'\">'. $sqlite->stringCut($myrow['title'],$titlelen) . '</a></li>");';
				}

				echo 'document.write("</ul>");';
		}
		//echo 'document.write("</div>");';
		
		// slide show �����̵��-�Ѹ��̹���

		$agent = $_SERVER['HTTP_USER_AGENT'];

	}else if($displaystyle == '2'){
		echo 'document.write("<script type=\"text/javascript\" src=\"/tpl/comm/js/slideshow_board.js\"></script>");';					
		

		echo 'document.write("<div id=\"gallery\" class=\"content\" >");';		
		

		//echo 'document.write("<div id=\"controls\" class=\"controls\"  style=\"margin-left:30px;\"></div>");';					
		echo 'document.write("<div class=\"slideshow-container\">");';					
		echo 'document.write("<div id=\"loading\" class=\"loader\"></div>");';					
		echo 'document.write("<div id=\"slideshow\" class=\"slideshow\" ></div>");';				
		echo 'document.write("</div>");';			
		echo 'document.write("</div>");';	
        echo 'document.write("<div id=\"thumbs\" class=\"navigation\" >");';
		echo 'document.write("<ul class=\"thumbs noscript\" style=\"display:none\">");';
		
		foreach ($result as $myrow){
			   if (!empty($myrow['photos'])){
					$photos = explode('|',$myrow['photos']);
					$photo_name = $photos[0];
					if (strpos(basename($photo_name),'demo-') === 0) {
						$photo = '/tpl/demo_img/' . basename($photo_name);
					} else {
						$photo = '/tpl/comm/php/thumb.php?sid='.urlencode($_GET['shopid']).'&f='.urlencode($photo_name).'&w=800&h=600';
					}
				}else{
					$photo = '/tpl/comm/img/noimage.gif';
				}
		
				 
				echo 'document.write("<li>   <a class=\"thumb\" href=\"'.$photo.'\" style=\"clear: both;\"></a></li>");';
		}
		echo 'document.write("</ul>");';
		echo 'document.write("</div>");';
		echo 'document.write("<div style=\"clear: both;\"></div>");';
	//	echo 'document.write("</div> <!-- end box -->");';
	//	echo 'document.write("</div> <!-- end specail gallery -->");';

		




    // �Ϲ� �Խù�
	}else{
		echo 'document.write("<ul>");';
		foreach ($result as $myrow){
		
				if ($datestyle == '0')
				{
					$data = '';
				}else{
					//$data = '<span class=\"fr\">'.date($datestyle,strtotime($myrow['regdate'])).'</span>';
						$data = '<span class=\"fr\">'.$myrow['regdate'].'</span>';
				}
				  if(!empty($myrow['title'])) {
				    echo 'document.write("<li>'.$data.'<a href=\"'.$skin_file.'?action=read&id='.$myrow['id'].'&category='.$category.'\">'. $sqlite->stringCut($myrow['title'],$titlelen) . '</a>&nbsp;</li>");';
				  }
		}
		echo 'document.write("</ul>");';
	}

}else{
echo 'document.write("");';
}
?>