<?php
//  ------------------------------------------------------------------------ //
// 本模組由 tad 製作
// 製作日期：2008-03-23
// $Id: index.php,v 1.5 2008/05/10 11:46:50 tad Exp $
// ------------------------------------------------------------------------- //

/*-----------引入檔案區--------------*/
include "header.php";
$xoopsOption['template_main'] = "tg_show_tpl.html";


/*-----------function區--------------*/
$csn=(isset($_REQUEST['csn']))?intval($_REQUEST['csn']) : 0;
$passwd=(isset($_POST['passwd']))?$_POST['passwd'] : "";



//路徑選單
if(!file_exists(XOOPS_ROOT_PATH."/modules/tadtools/jBreadCrumb.php")){
   redirect_header("index.php",3, _MA_NEED_TADTOOLS);
 }
 include_once XOOPS_ROOT_PATH."/modules/tadtools/jBreadCrumb.php";
 $arr=get_cate_path($csn);
 $jBreadCrumb=new jBreadCrumb($arr);
 $jBreadCrumbPath=$jBreadCrumb->render();
  
//模組目錄
$MDIR=$xoopsModule->getVar('dirname');


//以流水號取得某筆tad_gallery_cate資料
$cate=get_tad_gallery_cate($csn);

//可觀看相簿
$ok_cat=chk_cate_power();

//密碼檢查
if(!empty($csn)){
  if(empty($passwd) and !empty($_SESSION['tadgallery'][$csn])){
    $passwd=$_SESSION['tadgallery'][$csn];
	}

	$sql = "select csn,passwd from ".$xoopsDB->prefix("tad_gallery_cate")." where csn='{$csn}'";
  $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
	list($ok_csn,$ok_passwd)=$xoopsDB->fetchRow($result);
	if(!empty($ok_csn) and $ok_passwd!=$passwd)redirect_header($_SERVER['PHP_SELF'],3, sprintf(_TADGAL_NO_PASSWD_CONTENT,$cate['title']));
	
	if(!empty($ok_passwd) and empty($_SESSION['tadgallery'][$csn])){
		$_SESSION['tadgallery'][$csn]=$passwd;
	}


  //檢查相簿觀看權限
	if(!in_array($csn,$ok_cat)){
		redirect_header($_SERVER['PHP_SELF'],3, _TADGAL_NO_POWER_TITLE,sprintf(_TADGAL_NO_POWER_CONTENT,$cate['title'],$select));
	}
}



//呈現資料預設值
$data="";

//畫面並不只秀出縮圖，要秀出分類的話。
if($xoopsModuleConfig['only_thumb']!='1'){
  //撈出底下子分類
	$sql = "select csn,title,passwd,show_mode,cover from ".$xoopsDB->prefix("tad_gallery_cate")." where of_csn='{$csn}'  order by sort";
	$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
	while(list($fcsn,$title,$passwd,$show_mode,$cover)=$xoopsDB->fetchRow($result)){
    //無觀看權限則略過
		if(!in_array($fcsn,$ok_cat)){
		  continue;
		}

	  if($show_mode=="3d"){
			$url="3d.php";
			$rel="rel='shadowbox'";
		}elseif($show_mode=="slideshow"){
			$url="slideshow.php";
			$rel="";
		}else{
			$url="index.php";
			$rel="";
		}

		$cover_pic=(empty($cover))?"images/folder_picture.png":XOOPS_URL."/uploads/tadgallery/{$cover}";

	  if(empty($passwd) or $passwd==$_SESSION['tadgallery'][$fcsn]){
      //不需密碼的分類
	  	$data.=mk_gallery_border($rel,"{$url}?csn={$fcsn}",$cover_pic,$title);
		}else{
      //有密碼的分類
      $data.=mk_gallery_border("","#",$cover_pic,$title,true,$fcsn);
		}
	}

}

//找出分類下所有相片
$sql = "select * from ".$xoopsDB->prefix("tad_gallery")." where csn='{$csn}' order by photo_sort , post_date";

//getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
$PageBar=getPageBar($sql,$xoopsModuleConfig['thumbnail_number'], 10);
$bar=$PageBar['bar'];
$sql=$PageBar['sql'];

$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());

$pp="";
$i=1;

$thumbnail_mode=(empty($cate['mode']))?$xoopsModuleConfig['thumbnail_mode']:$cate['mode'];

while(list($sn,$db_csn,$title,$description,$filename,$size,$type,$width,$height,$dir,$uid,$post_date,$counter,$exif)=$xoopsDB->fetchRow($result)){

  $data.="
  <div style='background-image:url(".get_pic_url($dir,$sn,$filename,"s").");' class='PhotoCate' onClick=\"location.href='".XOOPS_URL."/modules/tadgallery/view.php?sn={$sn}';\">
    <div class='pic_title2'>$title</div>
  </div>
  ";

	$option_pic=($i==1)?"option":"hidden";
	$description=($i==1)?"<img src='images/randr.png' alt='"._MA_TADGAL_SHOW_ONE_MODE."' title='"._MA_TADGAL_SHOW_ONE_MODE."' border='0' height='22' width='22' hspace=4 align='absmiddle'>":"";
	
	$pp.="<a rel='shadowbox[{$cate['title']}]' href='".get_pic_url($dir,$sn,$filename,"m")."' class='{$option_pic}' title='{$title}'>{$description}</a>\n";
	$i++;
}


/*-----------秀出結果區--------------*/

include XOOPS_ROOT_PATH."/header.php";

//只有不顯示分類時，才秀出分類切換選單
//if($xoopsModuleConfig['only_thumb']=='1'){
  //分類下拉選單
  $cate_option=get_tad_gallery_cate_option(0,0,$csn);
  $xoopsTpl->assign( "cate_option" , "<select onChange=\"window.location.href='{$_SERVER['PHP_SELF']}?csn=' + this.value\" style='margin-right:20px'>$cate_option</select>") ;
//}else{
//  $xoopsTpl->assign( "cate_option" , "") ;
//}


$xoopsTpl->assign( "xoops_module_header" , "<link rel='alternate' href='"._TADGAL_UP_FILE_URL."photos.rss' type='application/rss+xml' title='{$cate['title']}' id='gallery' />");

$xoopsTpl->assign( "css" , "<link rel='stylesheet' type='text/css' media='screen' href='".XOOPS_URL."/modules/tadgallery/module.css' />
<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/{$MDIR}/class/shadowbox/src/css/shadowbox.css'>
<script type='text/javascript' src='".XOOPS_URL."/modules/{$MDIR}/class/shadowbox/src/js/lib/yui-utilities.js'></script>
<script type='text/javascript' src='".XOOPS_URL."/modules/{$MDIR}/class/shadowbox/src/js/adapter/shadowbox-yui.js'></script>
<script type='text/javascript' src='".XOOPS_URL."/modules/{$MDIR}/class/shadowbox/src/js/shadowbox.js'></script>
<script type='text/javascript' src='".XOOPS_URL."/modules/{$MDIR}/class/jquery.dimensions.js'></script>
<script type='text/javascript' src='".XOOPS_URL."/modules/{$MDIR}/class/jquery.dropshadow.js'></script>
<script type='text/javascript'>

window.onload = function(){
    Shadowbox.init();
    \$(\".PhotoCate\").dropShadow({left: 1, top: 1, blur: 2, opacity: 0.5});
};
</script>
{$script}") ;

$author_menu=get_all_author();

$xoopsTpl->assign( "author_option" , "<select onChange=\"window.location.href='author.php?uid=' + this.value\" style='margin-right:20px'>$author_menu</select>") ;




$xoopsTpl->assign( "show_3d_button" , "<a rel='shadowbox' class='option' title='{$cate['title']}' href='3d.php?csn={$csn}'><img src='images/3d.png' alt='"._MA_TADGAL_3D_MODE."' title='"._MA_TADGAL_3D_MODE."' border='0' height='22' width='22' hspace=4 align='absmiddle'></a>") ;


$xoopsTpl->assign( "show_shadowbox_button" , $pp) ;


$xoopsTpl->assign( "slideshow_button" , "<a href='slideshow.php?csn={$csn}'><img src='images/impress.png' alt='"._MA_TADGAL_SLIDE_SHOW_MODE."' title='"._MA_TADGAL_SLIDE_SHOW_MODE."' border='0' height='22' width='22' hspace=4 align='absmiddle'></a>") ;

//$xoopsTpl->assign( "PicLens_button" , "<a href='javascript:PicLensLite.start();'><img src='images/PicLensButton.png' alt='PicLens' border='0' height='22' width='22' align='absmiddle' style='margin-left:4px;'></a>") ;

$xoopsTpl->assign( "toolbar" , toolbar($interface_menu,$interface_logo)) ;

$xoopsTpl->assign( "data" , $data) ;

$xoopsTpl->assign( "bar" , $bar) ;

$xoopsTpl->assign( "path" , $jBreadCrumbPath) ;

include_once XOOPS_ROOT_PATH.'/footer.php';

?>
