<?php
//  ------------------------------------------------------------------------ //
// 本模組由 tad 製作
// 製作日期：2008-03-23
// $Id: index.php,v 1.2 2008/04/10 01:19:38 tad Exp $
// ------------------------------------------------------------------------- //

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

//列出所有tad_gallery資料
function list_tad_gallery($csn=""){
	global $xoopsDB,$xoopsModule,$xoopsModuleConfig;
	$MDIR=$xoopsModule->getVar('dirname');

  $cate_all=get_tad_gallery_cate_all();
 	$cate_option=get_tad_gallery_cate_option(0,0,$csn);

	if(!empty($csn)){
		$ok_cat=chk_cate_power();
		if(!in_array($csn,$ok_cat)){
		  $main="<select  onChange=\"window.location.href='{$_SERVER['PHP_SELF']}?csn=' + this.value\">
			$cate_option
			</select>";
			return $main.div_3d(_TADGAL_NO_POWER_TITLE,sprintf(_TADGAL_NO_POWER_CONTENT,$cate_all[$csn]),"corners");
		}
	}

	$main="";
  $data="";
  $sql = "select csn,title 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)=$xoopsDB->fetchRow($result)){
	  $data.="<a href='index.php?csn={$fcsn}'><div style='margin:4px 8px 4px 8px;float:left;width:150px;height:110px;background-image:url(images/folder_picture.png);position:relative;'>
		<div style='width:100%;text-align:center;position:absolute;bottom:10px;'>$title</div></div></a>";
	}
	
	$sql = "select * from ".$xoopsDB->prefix("tad_gallery")." where csn='{$csn}' order by sn";

	//PageBar(資料數, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
	$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
	$total=$xoopsDB->getRowsNum($result);

	$navbar = new PageBar($total, 50, 10);
	$mybar = $navbar->makeBar();
	$bar= sprintf(_BP_TOOLBAR,$mybar['total'],$mybar['current'])."{$mybar['left']}{$mybar['center']}{$mybar['right']}";
	$sql.=$mybar['sql'];

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

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

  	if($xoopsModuleConfig['thumbnail_mode']=="edge"){
      $data.="<a href='view.php?sn={$sn}'><img src='".get_pic_url($dir,$sn,$filename,"s")."' class='edges inbuilt imask2'  alt='{$title}' title='{$title}'  style='margin:10px'></a>";
  	}elseif($xoopsModuleConfig['thumbnail_mode']=="slided"){
      $data.="<a href='view.php?sn={$sn}'><img src='".get_pic_url($dir,$sn,$filename,"s")."' class='slided ibgcolorFBFBFB ishadow20'  alt='{$title}' title='{$title}' style='margin:10px'></a>";
    }elseif($xoopsModuleConfig['thumbnail_mode']=="instant"){
      $data.="<a href='view.php?sn={$sn}'><img src='".get_pic_url($dir,$sn,$filename,"s")."' class='instant icolorFCFCFC'  alt='{$title}' title='{$title}' style='margin:10px;'></a>";
  	}else{
  	  $pic=getimagesize(get_pic_url($dir,$sn,$filename,"s","dir"));
	    $data.=pic_3d($pic[0],$pic[1],"<a href='view.php?sn={$sn}'><img src='".get_pic_url($dir,$sn,$filename,"s")."' alt='{$title}' title='{$title}'></a>");
		}
    	

		$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' onmouseover=\"showToolTip(event,'"._MA_TADGAL_SHOW_ONE_MODE."');return false\" onmouseout=\"hideToolTip()\">":"";
		
		$pp.="<a rel='shadowbox[{$cate_all[$csn]}]' href='".get_pic_url($dir,$sn,$filename,"m")."' class='{$option_pic}' title='{$title}'>{$description}</a>";
		$i++;
	}

	if($xoopsModuleConfig['thumbnail_mode']=="edge"){
		$script="
		<script type='text/javascript'>
		var mask2load = new Array();
		mask2load[0] = '".XOOPS_URL."/modules/{$MDIR}/class/edge/masks/8bit/crippleedge.png';
		mask2load[1] = '".XOOPS_URL."/modules/{$MDIR}/class/edge/masks/8bit/frizzedge.png';
		mask2load[2] = '".XOOPS_URL."/modules/{$MDIR}/class/edge/masks/8bit/softedge.png';
		// if you want IE to use mask images: add GIF versions
		// of the same name to the array (edge.js will find them)
		mask2load[3] = '".XOOPS_URL."/modules/{$MDIR}/class/edge/masks/2bit/crippleedge.gif';
		mask2load[4] = '".XOOPS_URL."/modules/{$MDIR}/class/edge/masks/2bit/frizzedge.gif';
		mask2load[5] = '".XOOPS_URL."/modules/{$MDIR}/class/edge/masks/2bit/softedge.gif';
		</script>
		<script type='text/javascript' src='".XOOPS_URL."/modules/{$MDIR}/class/edge/edge.js'></script>";
	}elseif($xoopsModuleConfig['thumbnail_mode']=="slided"){
    $script="<script type='text/javascript' src='".XOOPS_URL."/modules/{$MDIR}/class/slided/slided.js'></script>";
  }elseif($xoopsModuleConfig['thumbnail_mode']=="instant"){
    $script="<script type='text/javascript' src='".XOOPS_URL."/modules/{$MDIR}/class/instant/instant.js'></script>";
	}else{
    $script="";
	}

	$main="
	<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/bubble-tooltip.js'></script>
	<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'>
	window.onload = function(){
	    Shadowbox.init();
	};
	</script>
  $script
  <div id='bubble_tooltip'>
	<div class='bubble_top'><span></span></div>
	<div class='bubble_middle'><span id='bubble_tooltip_content'>Content is comming here as you probably can see.Content is comming here as you probably can see.</span></div>
	<div class='bubble_bottom'></div>
	</div>
	<div style='width:100%;margin-left:auto;margin-right:auto;'>
		<dl class='bot_rgt'>
		<dt><select  onChange=\"window.location.href='{$_SERVER['PHP_SELF']}?csn=' + this.value\" style='margin-right:20px'>$cate_option</select> <a rel='shadowbox' class='option' title='{$cate_all[$csn]}' 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' onmouseover=\"showToolTip(event,'"._MA_TADGAL_3D_MODE."');return false\" onmouseout=\"hideToolTip()\"></a>{$pp}<a href='{$_SERVER['PHP_SELF']}?op=slideshow&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' onmouseover=\"showToolTip(event,'"._MA_TADGAL_SLIDE_SHOW_MODE."');return false\" onmouseout=\"hideToolTip()\"></a></dt>
		<dd>
		<p>$data</p>
		<p align='center' style='color:white;background-color:#AAAAAA;clear:both;'>{$bar}</p>
		</dd>
		</dl>
	</div>
	<p style='clear:both'> </p>";
	return $main;
}

//投影片模式
function slideshow($csn=""){
	global $xoopsDB,$xoopsModule,$xoopsModuleConfig;
	$MDIR=$xoopsModule->getVar('dirname');

 	$cate_option=get_tad_gallery_cate_option(0,0,$csn);
  $cate_all=get_tad_gallery_cate_all();
	$main="";

	$sql = "select sn,title,description,filename,dir from ".$xoopsDB->prefix("tad_gallery")." where csn='{$csn}'";
	$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());

	$pics="<ul id='animated-portfolio'>\n";
	while(list($sn,$title,$description,$filename,$dir)=$xoopsDB->fetchRow($result)){
		$pics.="<li><a href='view.php?sn={$sn}'><img src='".get_pic_url($dir,$sn,$filename,"m")."' alt='{$title}'></a></li>\n";
	}
	$pics.="</ul>";
	
	$div_width=$xoopsModuleConfig['thumbnail_m_width']+30;
	
	$main['main']="
  	<div style='width:{$div_width}px;margin-left:auto;margin-right:auto;'>
		<dl class='bot_rgt'>
		<dt><select onChange=\"window.location.href='{$_SERVER['PHP_SELF']}?op=slideshow&csn=' + this.value\" style='margin-right:20px'>$cate_option</select><a href='{$_SERVER['PHP_SELF']}?csn={$csn}'>".sprintf(_MD_TADGAL_BACK_CSN,$cate_all[$csn])."</a></dt>
		<dd>$pics</dd>
		</dl>
	</div>";

	
	return $main;

}

/*-----------執行動作判斷區----------*/
$_REQUEST['op']=(empty($_REQUEST['op']))?"":$_REQUEST['op'];
$csn=(isset($_REQUEST['csn']))?intval($_REQUEST['csn']) : 0;

switch($_REQUEST['op']){
	case "slideshow":
	$ss=slideshow($csn);
	$main=$ss['main'];
	break;

	default:
	$main=list_tad_gallery($csn);
	break;
}

/*-----------秀出結果區--------------*/
include XOOPS_ROOT_PATH."/header.php";
if($_REQUEST['op']=="slideshow"){
	$script="
  <script type='text/javascript' src='".XOOPS_URL."/modules/tadgallery/class/jquery.animated.innerfade/js/jquery.animated.innerfade.js'></script>
	</script>

	<script type='text/javascript'>
	$(document).ready( function(){
	    $('ul#animated-portfolio').animatedinnerfade({
		speed: 1000,
		timeout: 5000,
		type: 'random',
		containerheight: '414px',
		containerwidth: '{$xoopsModuleConfig['thumbnail_m_width']}px',
		animationSpeed: 5000,
		animationtype: 'fade',
		bgFrame: 'none',
    controlBox: 'auto',
    controlBoxClass: 'none',
	  controlButtonsPath: 'class/jquery.animated.innerfade/img',
		displayTitle: 'none'
		});
	} );
	</script>";
}
$xoopsTpl->assign( "css" , "<link rel='stylesheet' type='text/css' media='screen' href='".XOOPS_URL."/modules/tadgallery/module.css' />$script") ;
$xoopsTpl->assign( "toolbar" , toolbar($interface_menu)) ;
$xoopsTpl->assign( "content" , $main) ;
include_once XOOPS_ROOT_PATH.'/footer.php';

?>