<?php
session_start();
/**
 * TMBLOG 首页文件
 * ============================================================================
 * 版权所有 2008-2009 梧州腾马网络服务中心，并保留所有权利。
 * 网站地址: http://php.tmacn.cn；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: tm $
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

$smarty->assign('siteinfo',      get_site_info()); // 网站信息

$smarty->assign('tmbloggree',    get_gree_info()); // 导航栏

$smarty->assign('tmcategory',    get_category()); // 日志分类

$smarty->assign('tmpiccategory',    get_pic_category()); // 相册分类

$smarty->assign('tmarttj',         get_art_tj()); // 文章列表

$smarty->assign('userlist',        get_user_px()); // 评论用户排名

$smarty->assign('adtoplist',        get_adtop_list()); // 顶部通栏广告

$smarty->assign('adflashlist',        get_adflash_list()); // 右边轮播广告

$smarty->assign('adrightlist',        get_adright_list()); // 右边广告

$smarty->assign('tmdate',        get_date_list()); // 文章归档

$smarty->assign('tmtag',        get_tag_list()); // 网站标签

$smarty->assign('sitefoot',      get_foot_info()); // 底部信息

$smarty->assign('tmblog_dir',      request_uri()); // 目录

$smarty->assign('gglist',      get_gg_list()); // 公告

$smarty->assign('tmrss',      "rss.php?action=piclist"); // 订阅

$sql="select * from tm_pic_setup where id=1";
$rs=mysql_fetch_object(mysql_query($sql));
if($rs->retsh==0)
   {
      $message=array();
      $message[sb]=0;
      $message[info]="相册功能已禁用!";
      $message[url]="javascript:history.go(-1);";
      $smarty->assign('message', $message);
      $smarty->display('message.dwt');
      exit();
   }

if(isset($_GET['id']))
  $id=$_GET['id'];

$sql="select * from tm_pic_class where id='$id'";
$rs=mysql_fetch_object(mysql_query($sql));
if($rs->password<>"" and $rs->password<>$_SESSION["tm_pic_pass"])
   {
      $message=array();
      $message[info]="相册需密码访问,请输入密码！";
      $message[url]="javascript:history.go(-1);";
      $message[id]=$id;
      $smarty->assign('message', $message);
      $smarty->display('pass.dwt');
      exit();
   }

$smarty->assign('ctitle',      $rs->title);
$smarty->assign('cdes',      $rs->des);

$sql="select count(*) from tm_pic_list where cid='$id'";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_array($resultc);
$num=$rsc[0];
$size = 12;
if(isset($_GET['tm_page']))
   {
   $tm_page=trim($_GET['tm_page'])-1;
   if($tm_page<0)$tm_page=0;
   if($tm_page>(intval($num/$size)))$tm_page=intval($num/$size);
   }
else
	$tm_page=0;


$sql="select * from tm_pic_list where cid='$id' order by id ASC limit ".$size*$tm_page.",".$size;
$rsql=mysql_query($sql);

    $tmart = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	  {
    $tmart[$i]['title']= $res->title;
		$tmart[$i]['imgs']=$res->imgs;
		$tmart[$i]['img']=$res->img;
		$tmart[$i]['date']=$res->date;
		$i++;
		}
$smarty->assign('tmart',      $tmart);
//文章列表结束

//分页开始
 $tmpage = array();
 $tmpage[0]['sum']=$num;
 $tmpage[0]['num']=ceil($num/$size);
 $tmpage[0]['page']=$size;
 $tmpage[0]['nowpage']=$tm_page+1;
 $tmpage[0]['fpage']="<a href=pic.php?id=".$id.">首页</a>";
 		 if($tm_page>0)
 		    {
 		    if($tm_page==1)
 		    $tmpage[0]['upage']="<a href=pic.php?id=".$id.">上一页</a>";
 		    else
		    $tmpage[0]['upage']="<a href=pic.php?id=".$id."&tm_page=".$tm_page.">上一页</a>";
		    }
		 if($tm_page<ceil($num/$size)-1)
		    $tmpage[0]['dpage']="<a href=pic.php?id=".$id."&tm_page=".($tm_page+2).">下一页</a> ";
		 if(round(ceil($num/$size))==1)
		 $tmpage[0]['lpage']="<a href=pic.php?id=".$id.">末页</a>";
     else
		 $tmpage[0]['lpage']="<a href=pic.php?id=".$id."&tm_page=".round(ceil($num/$size)).">末页</a>";
	$j=0;
	for($i=($tm_page>4?($tm_page-3):1);$i<=(ceil($num/$size)<9?ceil($num/$size):(ceil($num/$size)>($tm_page+5)?($tm_page+($tm_page>5?5:(9-$tm_page))):ceil($num/$size)));$i++)
	     {
		 if(($tm_page+1)==($i))
           $tmpage[$j]['url']= '<span class="this-page">'.$i.'</span>';
		 else
		    $tmpage[$j]['url']="<a href=pic.php?id=".$id."&tm_page=".$i.">".($i)."</a>";
		 if($i==1)
		     {
         if(($tm_page+1)==($i))
            $tmpage[$j]['url']= '<span class="this-page">'.$i.'</span>';
         else
            $tmpage[$j]['url']="<a href=pic.php?id=".$id.">".($i)."</a>";
         } 
		$j++;
		}
$smarty->assign('tmpage',      $tmpage);		
//分页结束  
   
$smarty->assign('dhindex',      "http://".$_SERVER['SERVER_NAME'].request_uri()."piclist.php");//当前页

$smarty->display('pic.dwt');
?>