<?php
// p2 - 書き込み履歴のクラス

//======================================================================
//クラス
//======================================================================

//レス記事のクラス
class ResArticle{
	var $name;
	var $mail;
	var $daytime;
	var $msg;
	var $ttitle;
	var $host;
	var $bbs;
	var $itaj;
	var $key;
	var $order; //記事番号
}

//書き込み履歴のクラス
class ResHist{
	var $articles; // クラス ResArticle のオブジェクトを格納する配列
	var $num; // 格納された BrdMenuCate オブジェクトの数
	
	var $resrange; // array( 'start' => i, 'to' => i, 'nofirst' => bool )
	
	function ResHist()
	{
		$this->articles = array();
		$this->num = 0;
	}
	
	function addRes($aResArticle)
	{
		$this->articles[] = $aResArticle;
		$this->num++;
	}	
	
	//レス記事を表示するメソッド ===============================================
	function showArticles()
	{
		global $_conf, $subject_php, $STYLE;
		global $k_at_a, $k_at_q, $k_input_ht;
	
		$tores="<dl>";
		
		foreach($this->articles as $a_res){
			$href_ht="";
			if($a_res->key){
				$href_ht = $_conf['read_php']."?host=".$a_res->host."&amp;bbs=".$a_res->bbs."&amp;key=".$a_res->key."{$k_at_a}#footer";
			}
			$info_view_ht = <<<EOP
		<a href="info.php?host={$a_res->host}&amp;bbs={$a_res->bbs}&amp;key={$a_res->key}{$k_at_a}" target="_self" onClick="return OpenSubWin('info.php?host={$a_res->host}&amp;bbs={$a_res->bbs}&amp;key={$a_res->key}&amp;popup=1',{$STYLE['info_pop_size']},0,0)">情報</a>
EOP;

			$res_ht = "<dt><input name=\"checked_hists[]\" type=\"checkbox\" value=\"{$a_res->order},,,,{$a_res->daytime}\"> ";
			$res_ht .= "{$a_res->order} ："; //番号
			$res_ht .= "<span class=\"name\"><b>{$a_res->name}</b></span> ："; //名前
			if($a_res->mail){$res_ht .= "{$a_res->mail} ：";} //メール
			$res_ht .= "{$a_res->daytime}</dt>\n"; //日付とID
			$res_ht .= "<dd><a href=\"{$subject_php}?host={$a_res->host}&amp;bbs={$a_res->bbs}{$k_at_a}\" target=\"subject\">{$a_res->itaj}</a> / ";
			if($href_ht){
				$res_ht .= "<a href=\"{$href_ht}\"><b>{$a_res->ttitle}</b></a> - {$info_view_ht}\n";
			}elseif($a_res->ttitle){
				$res_ht .= "<b>{$a_res->ttitle}</b>\n";
			}
			$res_ht .= "<br><br>";
			$res_ht .= "{$a_res->msg}<br><br></dd>\n"; //内容

			$tores .= $res_ht;
		}
		
		$tores .= "</dl>";
		
		echo $tores;
	}
	
	//携帯用ナビを表示するメソッド=====================================================
	function showNaviK($position)
	{
		global $k_rnum_range;
		global $k_at_a, $k_at_q, $k_input_ht, $accesskey, $k_accesskey;

		//表示数制限====================
		$list_disp_all_num = $this->num;
		$list_disp_range=$k_rnum_range;
		
		if($_GET['from']){
			$list_disp_from=$_GET['from'];
			if($_GET['end']){
				$list_disp_range=$_GET['end']-$list_disp_from+1;
				if($list_disp_range<1){
					$list_disp_range=1;
				}
			}
		}else{
			$list_disp_from=$this->num-$list_disp_range+1;
			if($list_disp_from<1){
				$list_disp_from=1;
			}
		}
		$disp_navi = getListNaviRange($list_disp_from, $list_disp_range, $list_disp_all_num);
		
		$this->resrange['start']=$disp_navi['from'];
		$this->resrange['to']=$disp_navi['end'];
		$this->resrange['nofirst']=false;

		if($disp_navi['from'] > 1){
			if($position=="footer"){
				$mae_ht = <<<EOP
		<a {$accesskey}="{$k_accesskey['prev']}" href="read_res_hist.php?from={$disp_navi['mae_from']}{$k_at_a}">{$k_accesskey['prev']}.前</a>
EOP;
			}else{
				$mae_ht = <<<EOP
		<a href="read_res_hist.php?from={$disp_navi['mae_from']}{$k_at_a}">前</a>
EOP;
			}
		}
		if($disp_navi['end'] < $list_disp_all_num){
			if($position=="footer"){
				$tugi_ht = <<<EOP
		<a {$accesskey}="{$k_accesskey['next']}" href="read_res_hist.php?from={$disp_navi['tugi_from']}{$k_at_a}">{$k_accesskey['next']}.次</a>
EOP;
			}else{
				$tugi_ht = <<<EOP
		<a href="read_res_hist.php?from={$disp_navi['tugi_from']}{$k_at_a}">次</a>
EOP;
			}
		}
		
		if(!$disp_navi['all_once']){
			$list_navi_ht = <<<EOP
		{$disp_navi['range_st']}{$mae_ht} {$tugi_ht}
EOP;
		}

		echo $list_navi_ht;
	
	}
	
	//レス記事を表示するメソッド 携帯用============================================
	function showArticlesK()
	{
		global $_conf, $subject_php, $ktai_res_size, $ktai_ryaku_size;
		global $k_at_a, $k_at_q, $k_input_ht;
	
		//=============
		$tores="";
		foreach($this->articles as $a_res){
		
			if($a_res->order < $this->resrange['start'] or $a_res->order > $this->resrange['to']){
				continue;
			}
		
			$href_ht="";
			if($a_res->key){
				$href_ht = $_conf['read_php']."?host=".$a_res->host."&amp;bbs=".$a_res->bbs."&amp;key=".$a_res->key."{$k_at_a}#footer";
			}
		
		//大きさ制限
		if(! $_GET['k_continue']){
			$msg=$a_res->msg;
			if( strlen($msg) > $ktai_res_size){
				$msg = substr($msg, 0, $ktai_ryaku_size);
				
				//末尾に<br>があれば取り除く
				if( substr($msg, -1)==">" ){
					$msg = substr($msg, 0, strlen($msg)-1);
				}
				if( substr($msg, -1)=="r" ){
					$msg = substr($msg, 0, strlen($msg)-1);
				}
				if( substr($msg, -1)=="b" ){
					$msg = substr($msg, 0, strlen($msg)-1);
				}
				if( substr($msg, -1)=="<" ){
					$msg = substr($msg, 0, strlen($msg)-1);
				}
				
				$msg = $msg."  ";
				$a_res->msg = $msg."<a href=\"read_res_hist?from={$a_res->order}&amp;end={$a_res->order}&amp;k_continue=1{$k_at_a}\">略</a>";
			}
		}

			$res_ht = "[$a_res->order]"; //番号
			$res_ht .= "{$a_res->name}:"; //名前
			if($a_res->mail){$res_ht .= "{$a_res->mail}:";} //メール
			$res_ht .= "{$a_res->daytime}<br>\n"; //日付とID
			$res_ht .= "<a href=\"{$subject_php}?host={$a_res->host}&amp;bbs={$a_res->bbs}{$k_at_a}\">{$a_res->itaj}</a> / ";
			if($href_ht){
				$res_ht .= "<a href=\"{$href_ht}\">{$a_res->ttitle}</a>\n";
			}elseif($a_res->ttitle){
				$res_ht .= "{$a_res->ttitle}\n";
			}
			$res_ht .= "<br>";
			$res_ht .= "{$a_res->msg}<hr>\n"; //内容
			
			$tores .= $res_ht;
	
		}
		
		echo $tores;

	}
}

?>