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


//區塊主函式 (最新上傳的相片)
function tadgallery_carousel_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);
	$pic="";
	while(list($sn,$title,$description,$filename,$dir)=$xoopsDB->fetchRow($result)){
			$pic.="<li><a href='".XOOPS_URL."/modules/tadgallery/view.php?sn={$sn}'><img src='".XOOPS_URL."/uploads/tadgallery/{$dir}/{$sn}_s_{$filename}' alt='$title' /></a></li>";
	}

	$block="
	<script type='text/javascript' src='".XOOPS_URL."/modules/tadgallery/class/jcarousel/lib/jquery.jcarousel.pack.js'></script>
	<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/tadgallery/class/jcarousel/lib/jquery.jcarousel.css' />
	<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/tadgallery/class/jcarousel/skins/tango/skin.css' />
	<script type='text/javascript'>
	jQuery(document).ready(function() {
	    jQuery('#mycarousel').jcarousel({
	        vertical: true,
	        scroll: 2
	    });
	});
	</script>
	<ul id='mycarousel' class='jcarousel-skin-tango'>
	$pic
	</ul>";
	return $block;
}

//區塊編輯函式
function tadgallery_carousel_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":"";

	$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."
	";
	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;
	}
}
?>