/*--------------------------------------------------------------------------------------
日 期 : 2007/9/28
單 位 : 創意人資訊 (Http://www.a-team.com.tw)
修改模組 : shop_content.php
---------------------------------------------------------------------------------------*/
require('includes/application_top.php');
// create smarty elements
$smarty = new Smarty;
// include boxes
require(DIR_FS_CATALOG .'templates/'.CURRENT_TEMPLATE. '/source/boxes.php');
// include needed functions
require_once(DIR_FS_INC . 'twe_image_button.inc.php');
require_once(DIR_FS_INC . 'twe_url_get_compiler.inc.php');
$_SESSION['NOW_FILE']=url_get_compiler(basename(__FILE__));
//您現在的位置
$breadcrumb->add(TEXT_BALLOT_NAME,twe_href_link(FILENAME_BALLOT,''));
require(DIR_WS_INCLUDES . 'header.php');
$now_time=date("Y-m-d");
$smarty->assign('CONTENT_HEADING',TEXT_BALLOT_NAME);
//一頁最多秀幾筆
$max_count=10;
$now_page=trim($_GET['page']);
if($now_page=="")
$now_page=1;
//目前頁數
$smarty->assign('NOW_PAGE',$now_page);
//總投票主題數
$query="select od,title,talk_code,class,begin_time,end_time,memo from " . TABLE_BALLOT . " where show_flag='1' and begin_time<='$now_time' order by od desc";
$ballot_data=$db->Execute($query);
$ballot_total=$ballot_data->_numOfRows;
$smarty->assign('BALLOT_TOTAL',$ballot_total);
//顯示範圍
$range=((($now_page-1)*$max_count)+1)."-".($now_page*$max_count-1);
$smarty->assign('SHOW_RANGE',$range);
//讀取投票主題
$query="select od,title,talk_code,class,begin_time,end_time,memo from " . TABLE_BALLOT . " where show_flag='1' and begin_time<='$now_time' order by od desc limit ".(($now_page-1)*$max_count).",$max_count";
$ballot_data=$db->Execute($query);
$i=0;unset($detail_array);
$b_code=(($now_page-1)*$max_count);
while(!$ballot_data->EOF)
{
if($ballot_data->fields['title']!=""):
$detail_array[$i]['code']=$b_code+1;
$detail_array[$i]['url']="ballot_content.php?action=yes&od=".$ballot_data->fields['od']."&".twe_session_name()."=".twe_session_id();
$detail_array[$i]['title']=$ballot_data->fields['title'];
$detail_array[$i]['begin_time']=$ballot_data->fields['begin_time'];
$detail_array[$i]['end_time']=$ballot_data->fields['end_time'];
//總投票數
$query="select ballot_content from " . TABLE_BALLOT_RECORD . " where od_code='".$ballot_data->fields['od']."'";
$ballot_record=$db->Execute($query);
$total_count=0;
while(!$ballot_record->EOF)
{
$tt=explode(",",$ballot_record->fields['ballot_content']);
$total_count+=count($tt);
$ballot_record->MoveNext();
}
$detail_array[$i]['total_count']=$total_count;
//圖片顯示
if(file_exists('images/ballot/'.$ballot_data->fields['od'].'.jpg')):
$max_width=125;
//$max_height=340;
$tt=getimagesize('images/ballot/'.$ballot_data->fields['od'].'.jpg');
$height=$tt[1];
$width=$tt[0];
//if($height>$max_height):
// $width=$width*($max_height/$height);
// $height=$height*($max_height/$height);
//endif;
if($width>$max_width):
$height=$height*($max_width/$width);
$width=$width*($max_width/$width);
endif;
$detail_array[$i]['images']="";
endif;
//投票按鈕
$detail_array[$i]['button_view']='' . twe_image_button('button_ballot_view.gif', IMAGE_BUTTON_BALLOT_VIEW) . '';
//如果過期就不秀
if($ballot_data->fields['begin_time']<=$now_time && $ballot_data->fields['end_time']>=$now_time):
$detail_array[$i]['button_ballot']='' . twe_image_button('button_ballot_yes.gif', IMAGE_BUTTON_BALLOT_YES) . '';
endif;
$i++;
$b_code++;
endif;
$ballot_data->MoveNext();
}
$smarty->assign('CONTENT_DETAIL',$detail_array);
//頁次處理
if($ballot_total%$max_count!=0):
$total_page=(($ballot_total-($ballot_total%$max_cont))/$max_count)+1;
else:
$total_page=$ballot_total/$max_count;
endif;
unset($page_array);
if($now_page<6): //起始頁次
$b_page=1;
else:
$b_page=$now_page-6;
endif;
for($i=0;$i<10;$i++)
{
if($b_page>$total_page):
break;
else:
$page_array[$i]['code']=$b_page;
$page_array[$i]['url']="ballot.php?page=".$b_page."&".twe_session_name()."=".twe_session_id();
$b_page++;
endif;
}
$smarty->assign('PAGE_CODE',$page_array);
$main_content= $smarty->fetch(CURRENT_TEMPLATE."/module/ballot.html");
$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content',$main_content);
$smarty->caching = 0;
$smarty->display(CURRENT_TEMPLATE . '/index.html');
?>