<?php
// +---------------------------------------------+
// |     Copyright 2006-2009 weenCompany |
// |     http://www.weentech.com               |
// |     This file may not be redistributed.     |
// +---------------------------------------------+

define('IN_WEENCOMPANY', true);

$rootpath = "../../";

// ########################### LOAD WEENCOMPANY CORE ############################

include($rootpath . 'includes/core.php');


// ######################### GET CHATTERBOX SETTINGS ###########################

$getsettings = $DB->query("SELECT title, value FROM " . TABLE_PREFIX . "modulesettings WHERE moduleid = 7");
while($setting = $DB->fetch_array($getsettings))
{
  $settings[$setting['title']] = $setting['value'];
}



$gettimezoneoffset = $DB->query_first("SELECT value FROM " . TABLE_PREFIX . "mainsettings WHERE varname = 'timezoneoffset'");
$mainsettings['timezoneoffset']  = $gettimezoneoffset['value'];


// ######################### CHECK FOR INCORRECT DATA ##########################

if(!preg_match("/^[0-9]+$/", $categoryid))
{
  exit();
}

if(!$settings['显示全部内容'])
{
  exit();
}

// ############################## DISPLAY HISTORY ##############################

$m7_language = GetLanguage(7);
$m16_language = GetLanguage(16);
$start = (isset($_GET['m7_start']) AND preg_match("/^[0-9]+$/", $_GET['m7_start'])) ? $_GET['m7_start'] : 0;
$limit = 10;

echo '<html>
      <head>
	  <title>'.$m7_language['view_history'].'</title>
		<style type="text/css">
		<!--
		.pages_nav a {BACKGROUND: #cad9ea; PADDING-TOP: 5px; PADDING-BOTTOM: 5px; PADDING-RIGHT: 7px; PADDING-LEFT: 7px;  LINE-HEIGHT: 24px;}
		.pages_nav STRONG{font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; FONT-WEIGHT: bold; BACKGROUND: #BBBBBB; COLOR: #CC0000;PADDING-TOP: 5px; PADDING-BOTTOM: 5px; PADDING-RIGHT: 7px; PADDING-LEFT: 7px;LINE-HEIGHT: 24px;}
		a:link  { font-family: Arial, Verdana, Helvetica, sans-serif; font-size:   12px; color: #373B3F; text-decoration: underline; }
		a:active  { font-family: Arial, Verdana, Helvetica, sans-serif; font-size:   12px; color: #373B3F; text-decoration: underline; }
		a:visited { font-family: Arial, Verdana, Helvetica, sans-serif; font-size:   12px; color: #373B3F; text-decoration: underline; }
		a:hover  { font-family: Arial, Verdana, Helvetica, sans-serif; font-size:   12px; color: #395E70; text-decoration: none; }
		-->
		</style>
	  </head>
      <body bgcolor="#B4BFD3">

      <table width="90%" border="0" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td bgcolor="#FFFFFF" style="border: 1px solid #000000; padding: 10px;" valign="top">';

$getposts = $DB->query("SELECT username, comment, datecreated FROM " . TABLE_PREFIX . "m7_chatterbox
                        " . iif($settings['目标菜单'], "WHERE categoryid = '$categoryid'") . "
                        ORDER BY commentid DESC LIMIT $start, " . ($limit+1) . "");

$rows = $DB->get_num_rows($getposts); 

$maxrows = $DB->query_first("SELECT COUNT(*) AS value FROM " . TABLE_PREFIX . "m7_chatterbox " . iif($settings['目标菜单'], "WHERE categoryid = '$categoryid'"));

 for($i = 0; $i < $rows AND $i < $limit; $i++) {
  $post = $DB->fetch_array($getposts);
  $username = $post['username'];
  $comment  = $post['comment'];

  if($settings['换行字符数'])
  {
    $comment  = cws_wordwrap($comment,  $settings['换行字符数'], "<br />", 1);
  }


  if($settings['允许表情符号'])
  {
    $comment = AddSmilies($comment);
  }

  echo '<b>' . $username . '</b>:<br />';

  if($settings['显示发表时间'])
  {
    echo  DisplayDate($post['datecreated'], $settings['日期时间格式']) . '<br />';
  }

  echo $comment . '<br /><hr size="1" noshade="noshade" />';
}

							 
					 
if($start > 0 OR $rows > $limit)
{
		echo '<br />
			  <table width="100%" cellpadding="0" cellspacing="0" border="0">
			  <tr>';

		if($start > 0)
		{
		  echo '<td style="padding-left: 3px; vertical-align:middle;" width="10%" nowrap="nowrap"><a href="'.$weenurl.'modules/m7_chatterbox/viewhistory.php?categoryid='.$categoryid.'&m7_start=' . ($start - $limit) . '">'.$m16_language['previous_links'].'</a></td>';
		}else{
		  echo '<td style="padding-left: 3px; vertical-align:middle;" width="10%" nowrap="nowrap">&nbsp;</td>';
		}
		

		$sectionarticlesnum = $maxrows['value'];
		$page_num = ceil($sectionarticlesnum / $limit);
		$page_group = floor($start/$limit/8)*8+1;
		$now_page_num = $start/$limit+1;

		if($page_num - $now_page_num < 10){
			$start_page = $page_num - 9;
			if($start_page<1){
				$start_page = 1;
			}
			$end_page = $page_num + 1;
		}else{
			$start_page = $page_group;
			$end_page = $start_page + 8;
		}

		if($start_page > 1){
			$direct_bar = '<a href="'.$weenurl.'modules/m7_chatterbox/viewhistory.php?categoryid='.$categoryid.'&m7_start==0">1</a><a href="'.$weenurl.'modules/m7_chatterbox/viewhistory.php?categoryid='.$categoryid.'&m7_start=' . ($start_page-2)*$limit . '">&lsaquo;&lsaquo;...</a>';
		}

		for ($p=$start_page; $p < $end_page; $p++ ) 
		{	
			if (($start/$limit+1) == $p){
				$direct_bar .= '<STRONG>'.$p.'</STRONG>';
			}else{
				$direct_bar .= '<a href="'.$weenurl.'modules/m7_chatterbox/viewhistory.php?categoryid='.$categoryid.'&m7_start=' . ($p-1)*$limit . '">'.$p.'</a>';
			}


			if($p >= $page_num){
				break;
			}

		}
		
		if($page_num - $now_page_num >= 10){
			$direct_bar .= '<a href="'.$weenurl.'modules/m7_chatterbox/viewhistory.php?categoryid='.$categoryid.'&m7_start=' . (($page_group + 7)*$limit) . '">...&rsaquo;&rsaquo;</a><a href="'.$weenurl.'modules/m7_chatterbox/viewhistory.php?categoryid='.$categoryid.'&m7_start=' .($page_num-1)*$limit . '">'.$page_num.'</a>';
		}

		echo '<td width="80%" style="text-align:center; vertical-align:middle;" class="pages_nav">'.$direct_bar.'</td>';


		if($rows > $limit)
		{
		  echo '<td style="padding-right: 3px; vertical-align:middle;" width="10%" nowrap="nowrap"><div align="right"><a href="'.$weenurl.'modules/m7_chatterbox/viewhistory.php?categoryid='.$categoryid.'&m7_start=' . ($start + $limit) . '">'.$m16_language['more_links'].'</a></div></td>';
		}else{
		  echo '<td style="padding-right: 3px; vertical-align:middle;" width="10%" nowrap="nowrap">&nbsp;</td>';
		}

		echo '</tr></table><br>';
}

echo '</td>
      </tr>
      </table></body>
      </html>';

unset($m7_language, $m16_language);
?>