<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.2 www.exoops.info 2006/03 
// $Id: newbb_new.php,v 1.15 2003/03/19 07:00:47 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Half-Dead
// Author Website : http://www.e-xoops.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function b_newbb_new_show($options) {
global $db, $myts, $bcoosConfig, $xoopsUser;
$uid   = $xoopsUser ? $xoopsUser->uid() : 0;
$block = array();
$block['title'] = _MB_NEWBB_RECENT;
$from_forum = intval($options[9]);
if (!empty($from_forum)) {
	$extra = "AND f.forum_id = $from_forum";
}
 $sql = "SELECT p.uid, p.topic_id, p.forum_id, p.post_time, p.icon, t.topic_title, t.topic_views, t.topic_replies, f.forum_name,p.post_id 
      FROM ".$db->prefix("bb_posts")." p, ".$db->prefix("bb_forums")." f 
      INNER JOIN ".$db->prefix("bb_topics")." t 
      LEFT JOIN ".$db->prefix("bb_forum_access")." a ON a.user_id IN($uid) 
      WHERE t.topic_last_post_id = p.post_id AND f.forum_id = t.forum_id AND ( ( f.forum_type =0 ) OR ( a.forum_id = f.forum_id ) ) 
      GROUP BY p.topic_id 
      ORDER BY t.topic_time DESC";
      
if ( empty($options[7]) || !is_numeric($options[7]) ) {
	$options[7] = 5;
}
if ( !$query = $db->query($sql, $options[7], 0) ) {
	echo 'ERROR';
}
if ( $db->getRowsNum($query) > 0 ) {
	$block['content']  = '<table border="0" cellpadding="0" cellspacing="0" valign="top" width="100%" class="bg2"><tr><td><table width="100%" border="0" cellpadding="4" cellspacing="1"><tr class="bg3">';
	// Show Posticon?
	if ( $options[8] == 1) {
		$block['content'] .= '<td align="center">&nbsp;</td>';
	}
	// Show Forum?
	if ( $options[4] == 1 ) {
		$block['content'] .= '<td align="center"><b>'._MB_NEWBB_FORUM.'</b></td>';
	}
	$block['content'] .= '<td align="center"><b>'._MB_NEWBB_TOPIC.'</b></td>';
	// Show Replies?
	if ( $options[2] == 1 ) {
		$block['content'] .= '<td align="center"><b>'._MB_NEWBB_RPLS.'</b></td>';
	}
	// Show Views?
	if ( $options[3] == 1 ) {
		$block['content'] .= '<td align="center"><b>'._MB_NEWBB_VIEWS.'</b></td>';
	}
	// Show Time || Poster?
	if ( $options[1] == 1 || $options[0] == 1 ) {
		$block['content'] .= '<td align="center"><b>'._MB_NEWBB_LPOST.'</b></td>';
	}
	$block['content'] .= '</tr>';
	if ( empty($options[5]) || !is_numeric($options[5]) ) {
		$options[5] = 35;
	}
	if ( empty($options[6]) || !is_numeric($options[6]) ) {
		$options[6] = 19;
	}
	while ( list($userid, $topicid, $forumid, $time, $icon, $title, $views, $replies, $forumname,$post_id) = $db->fetchRow($query) ) {
		$forumname = $myts->makeTboxData4Show($forumname);
		$title     = $myts->makeTareaData4Show($title);
		
		$timenow = formatTimestamp(time(), "s");
		$timepost = formatTimestamp($time, "s");
		if ( $timenow == $timepost) { $time  = formatTimestamp($time, "t");
		} else { $time  = formatTimestamp($time, "m"); }
		if ( strlen($title) > $options[5] ) {
			$title = substr($title, 0, $options[5])."..";
		}
		$block['content'] .= '<tr class="bg1">';
	// Show Posticon?
	if ( $options[8] == 1 ) {
		if ($icon) {
			$block['content'] .= '<td><img src="'.XOOPS_URL.'/images/subject/'.$icon.'" /></td>';
			} else {
				$block['content'] .= '<td><img src="'.XOOPS_URL.'/images/subject/icon1.gif" /></td>';
			}
	}
	// Show Forum?
	if ( $options[4] == 1 ) {
		$block['content'] .= '<td><a href="'.XOOPS_URL.'/modules/newbb/viewforum.php?forum='.$forumid.'">'.$forumname.'</a></td>';
	}
	$block['content'] .= '<td><a href="'.XOOPS_URL.'/modules/newbb/viewtopic.php?topic_id='.$topicid.'&amp;forum='.$forumid.'">'.$title.'</a></td>';
	// Show Replies?
	if ( $options[2] == 1 ) {
		$block['content'] .= '<td align="center">'.$replies.'</td>';
	}
	// Show Views?
	if ( $options[3] == 1 ) {
		$block['content'] .= '<td align="center">'.$views.'</td>';
		}
	// Show Time || Poster?
	if ( $options[1] == 1 || $options[0] == 1 ) {
		$block['content'] .= '<td align="right" nowrap>';
		if ( $options[0] == 1 ) {
			$poster = new XoopsUser($userid);
			!$poster->uname() ? $postername = $bcoosConfig['anonymous'] : $postername = $poster->uname();
			$postername = $myts->makeTboxData4Show($postername);
			if ( strlen($postername) > $options[6] ) {
				$postername = substr($postername, 0, $options[6])."..";
				}
			$block['content'] .= '<b>'.$postername.'</b>';
			}
		if ( $options[1] == 1 && $options[0] == 1 ) {
			$block['content'] .= '<br />';
			}
		if ( $options[1] == 1 ) {
			$block['content'] .= $time;
			}
		$block['content'] .= '</td>';
		}
	} // END WHILE
	$block['content'] .= '</tr></table></td></tr><tr class="bg4"><td align="right"><span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;<b><a href="'.XOOPS_URL.'/modules/newbb/">'._MB_NEWBB_VSTFRMS.'</a></b></td></tr></table>';
	} else {
		$block = false;
	}
return $block;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function b_newbb_new_edit($options) {
global $db, $myts;
$form  = '<table>';
// SHOW POSTER
if ($options[0] == 1) {
	$chk1 = "checked='checked'";
	$chk0 = '';
	} else {
		$chk0 = "checked='checked'";
		$chk1 = '';
	}
$form .= '<tr><td>'._MB_NEWBB_SPOSTER.'</td><td>&nbsp;'._NO.'<input type="radio" class="radio" name="options[0]" value="0" '.$chk0.'>'._YES.'<input type="radio" name="options[0]" value="1" '.$chk1.'></td></tr>';
// SHOW TIME
if ($options[1] == 1) {
	$chk1 = "checked='checked'";
	$chk0 = '';
	} else {
		$chk0 = "checked='checked'";
		$chk1 = '';
	}
$form .= '<tr><td>'._MB_NEWBB_STIME.'</td><td>&nbsp;'._NO.'<input type="radio" class="radio" name="options[1]" value="0" '.$chk0.'>'._YES.'<input type="radio" name="options[1]" value="1" '.$chk1.'></td></tr>';
// SHOW REPLIES
if ($options[2] == 1) {
	$chk1 = "checked='checked'";
	$chk0 = '';
	} else {
		$chk0 = "checked='checked'";
		$chk1 = '';
	}
$form .= '<tr><td>'._MB_NEWBB_SREPLIES.'</td><td>&nbsp;'._NO.'<input type="radio" class="radio" name="options[2]" value="0" '.$chk0.'>'._YES.'<input type="radio" name="options[2]" value="1" '.$chk1.'></td></tr>';
// SHOW VIEWS
if ($options[3] == 1) {
	$chk1 = "checked='checked'";
	$chk0 = '';
	} else {
		$chk0 = "checked='checked'";
		$chk1 = '';
	}
$form .= '<tr><td>'._MB_NEWBB_SVIEWS.'</td><td>&nbsp;'._NO.'<input type="radio" class="radio" name="options[3]" value="0" '.$chk0.'>'._YES.'<input type="radio" name="options[3]" value="1" '.$chk1.'></td></tr>';
// SHOW FORUM
if ($options[4] == 1) {
	$chk1 = "checked='checked'";
	$chk0 = '';
	} else {
		$chk0 = "checked='checked'";
		$chk1 = '';
	}
$form .= '<tr><td>'._MB_NEWBB_SFORUM.'</td><td>&nbsp;'._NO.'<input type="radio" class="radio" name="options[4]" value="0" '.$chk0.'>'._YES.'<input type="radio" name="options[4]" value="1" '.$chk1.'></td></tr>';
// TRIM TOPIC
$form .= '<tr><td>'._MB_NEWBB_TTOPIC.'</td><td><input type="text" class="text" name="options[5]" value="'.$options[5].'" size="3"></td></tr>';
// TRIM POSTER
$form .= '<tr><td>'._MB_NEWBB_TPOSTER.'</td><td><input type="text" class="text" name="options[6]" value="'.$options[6].'" size="3"></td></tr>';
// LIMIT TO
$form .= '<tr><td>'._LIMIT.'</td><td><input type="text" class="text" name="options[7]" value="'.$options[7].'" size="3"></td></tr>';
// SHOW POSTICON?
if ($options[8] == 1) {
	$chk1 = "checked='checked'";
	$chk0 = '';
	} else {
		$chk0 = "checked='checked'";
		$chk1 = '';
	}
$form .= '<tr><td>'._MB_NEWBB_SICON.'</td><td>&nbsp;'._NO.'<input type="radio" class="radio" name="options[8]" value="0" '.$chk0.'>'._YES.'<input type="radio" name="options[8]" value="1" '.$chk1.'></td></tr>';
$result = $db->query("SELECT forum_id, forum_name FROM ".$db->prefix("bb_forums")."");
if ($result) {
	$form .= '<tr><td>'._MB_NEWBB_FORUM.'</td><td><select class="select" name="options[9]"><option value="0">'._ANY.'</option>';
	while (list($fid, $fname) = $db->fetchRow($result)) {
		$chk = ($options[9] == $fid) ? " selected" : "";
		$form .= '<option value="'.$fid.'"'.$chk.'>'.$myts->makeTboxData4PreviewInForm($fname).'</option>';
	}
	$form .= '</select></td></tr>';
}
$form .= '</table>';
return $form;
}
?>
