<?php
//  ------------------------------------------------------------------------ //
// 本模組由 tad 製作
// 製作日期：2008-03-23
// $Id: tadgallery_good.php,v 1.3 2008/05/05 03:21:42 tad Exp $
// ------------------------------------------------------------------------- //


//區塊主函式 (cooliris)
function tadgallery_cooliris_show($options){
	global $xoopsDB;
	
	$block=block_cooliris($options[0],$options[1],$options[2]);
	return $block;
}



//區塊編輯函式
function tadgallery_cooliris_edit($options){
	$cate_select=get_tad_gallery_block_cate_option(0,0,$options[0]);

	$form="
	"._MB_TADGAL_BLOCK_SHOWCATE."
	<select name='options[0]'>
		$cate_select
	</select><br>
	"._MB_TADGAL_BLOCK_WIDTH."
	<INPUT type='text' name='options[1]' value='{$options[1]}' size=3> x
	"._MB_TADGAL_BLOCK_HEIGHT."
	<INPUT type='text' name='options[2]' value='{$options[2]}' size=3> px<br>
	";
	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'>"._MB_TADGAL_BLOCK_ALL."</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]))?"":$cate_count[$csn];
			$option.="<option value='{$csn}' $selected>{$syb}{$title}({$count})</option>";
			$option.=get_tad_gallery_block_cate_option($csn,$level,$v);
		}
		return $option;
	}
}

function block_cooliris($csn="",$width=650,$height=450){
  if(empty($csn))$csn="";
  $main = "<div align='center'>
  <object id='block_cooliris' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
    width='{$width}' height='{$height}'>
  <param name='movie' value='http://apps.cooliris.com/embed/cooliris.swf' />
  <param name='allowFullScreen' value='true' />
  <param name='allowScriptAccess' value='always' />
  <param name='flashvars' value='feed=".XOOPS_URL."/uploads/tadgallery/photos{$csn}.rss' />
  <embed type='application/x-shockwave-flash'
    src='http://apps.cooliris.com/embed/cooliris.swf'
    flashvars='feed=".XOOPS_URL."/uploads/tadgallery/photos{$csn}.rss'
    width='{$width}'
    height='{$height}'
    allowFullScreen='true'
    allowScriptAccess='always'>
  </embed>
  </object>
  </div>";
  return $main;
}
?>