<?php
//  ------------------------------------------------------------------------ //
// 本模組由 tad 製作
// 製作日期：2008-03-23
// $Id: tadgallery_show.php,v 1.3 2008/04/08 02:43:04 tad Exp $
// ------------------------------------------------------------------------- //


//區塊主函式 (會捲動的相片)
function tadgallery_show($options){
	global $xoopsDB;
	$bycsn=(!empty($options[1]))?"where csn='{$options[1]}'":"";
	$sql = "select sn,title,description,filename,dir from ".$xoopsDB->prefix("tad_gallery")." $bycsn {$options[2]} limit 0,{$options[0]}";
	$result = $xoopsDB->query($sql);
	
	if(empty($options[5]))$options[5]="s";

	$pics="<ul id='animated-portfolio-block{$options[1]}'>";
	while(list($sn,$title,$description,$filename,$dir)=$xoopsDB->fetchRow($result)){
	  $title=(empty($title))?$filename:$title;
		$pics.="<li><a href='".XOOPS_URL."/modules/tadgallery/view.php?sn={$sn}'><img src='".XOOPS_URL."/uploads/tadgallery/{$dir}/{$sn}_{$options[5]}_{$filename}' alt='{$title}' title='{$title}' /></a></li>";
	}
	$pics.="</ul>";

	
	$block="
	<style type='text/css'>
	ul#animated-portfolio-block{$options[1]}{
  	list-style-type: none;
	}
	ul#animated-portfolio-block{$options[1]} li{
	  list-style: none;
	}
	</style>
  <script type='text/javascript' src='".XOOPS_URL."/modules/tadgallery/class/jquery.animated.innerfade/js/jquery.animated.innerfade.js'></script>

	<script type='text/javascript'>
	$(document).ready( function(){
	  $('ul#animated-portfolio-block{$options[1]}').animatedinnerfade({
		speed: 1000,
		timeout: 5000,
		type: 'random',
		containerheight: '{$options[4]}px',
		containerwidth: '{$options[3]}px',
		animationSpeed: 5000,
		animationtype: 'fade',
		bgFrame: 'none',
    controlBox: 'auto',
    controlBoxClass: 'none',
	  controlButtonsPath: '".XOOPS_URL."/modules/tadgallery/class/jquery.animated.innerfade/img',
		displayTitle: 'none'
		});
	} );
	</script>
	$pics";
	return $block;
}

//區塊編輯函式
function tadgallery_edit($options){
	$cate_select=get_tad_gallery_block_cate_option(0,0,$options[1]);
	
	$chked2_0=($options[2]=="order by post_date desc")?"checked":"";
	$chked2_1=($options[2]=="order by counter desc")?"checked":"";
	$chked2_2=($options[2]=="order by rand()")?"checked":"";
	$chked5_0=($options[5]=="s")?"checked":"";
	$chked5_1=($options[5]=="m")?"checked":"";

	$form="
	"._MB_TADGAL_TADGALLERY_EDIT_BITEM0."
	<INPUT type='text' name='options[0]' value='{$options[0]}'><br>
	"._MB_TADGAL_TADGALLERY_EDIT_BITEM1."
	<select name='options[1]'>
		$cate_select
	</select><br>
	"._MB_TADGAL_TADGALLERY_EDIT_BITEM2."
	<INPUT type='radio' $chked2_0 name='options[2]' value='order by post_date desc'>"._MB_TADGAL_TADGALLERY_EDIT_MODE1."
	<INPUT type='radio' $chked2_1 name='options[2]' value='order by counter desc'>"._MB_TADGAL_TADGALLERY_EDIT_MODE2."
	<INPUT type='radio' $chked2_2 name='options[2]' value='order by rand()'>"._MB_TADGAL_TADGALLERY_EDIT_MODE3."
	<br>
	"._MB_TADGAL_TADGALLERY_EDIT_BITEM3."
	<INPUT type='text' name='options[3]' value='{$options[3]}'><br>
	"._MB_TADGAL_TADGALLERY_EDIT_BITEM4."
	<INPUT type='text' name='options[4]' value='{$options[4]}'><br>
	"._MB_TADGAL_TADGALLERY_EDIT_BITEM5."
	<INPUT type='radio' $chked5_0 name='options[5]' value='s'>"._MB_TADGAL_TADGALLERY_EDIT_OPT1."
	<INPUT type='radio' $chked5_1 name='options[5]' value='m'>"._MB_TADGAL_TADGALLERY_EDIT_OPT2."";
	return $form;
}


if(!function_exists("get_tad_gallery_block_cate_option")){
	//取得分類下拉選單
	function get_tad_gallery_block_cate_option($of_csn=0,$level=0,$v=""){
		global $xoopsDB,$xoopsUser;

		$modhandler = &xoops_gethandler('module');
	  $xoopsModule = &$modhandler->getByDirname("tadgallery");

		if ($xoopsUser) {
	    $module_id = $xoopsModule->getVar('mid');
	    $isAdmin=$xoopsUser->isAdmin($module_id);
	  }else{
	    $isAdmin=false;
		}

		$sql = "select count(*),csn from ".$xoopsDB->prefix("tad_gallery")." group by csn";
		$result = $xoopsDB->query($sql);
		while(list($count,$csn)=$xoopsDB->fetchRow($result)){
		  $cate_count[$csn]=$count;
		}

		//$left=$level*10;
		$level+=1;

		$syb=str_repeat("-", $level)." ";

		$option=($of_csn)?"":"<option value='0'></option>";
		$sql = "select csn,title from ".$xoopsDB->prefix("tad_gallery_cate")." where of_csn='{$of_csn}' order by sort";
		$result = $xoopsDB->query($sql);

		while(list($csn,$title)=$xoopsDB->fetchRow($result)){
			$selected=($v==$csn)?"selected":"";
			$count=(empty($cate_count[$csn]))?0:$cate_count[$csn];
			$option.="<option value='{$csn}' $selected>{$syb}{$title}({$count})</option>";
			$option.=get_tad_gallery_block_cate_option($csn,$level,$v);
		}
		return $option;
	}
}

?>