prefix("bb_topics")." WHERE forum_id = $forum_id";
} else {
$sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_topics");
}
if ( !$result = $xoopsDB->query($sql) ) {
return _MD_ERROR;
}
if ( !$myrow = $xoopsDB->fetchArray($result) ) {
return _MD_ERROR;
}
return $myrow['total'];
}
/*
* Returns the total number of posts in the whole system, a forum, or a topic
* Also can return the number of users on the system.
*/
function get_total_posts($id, $type)
{
global $xoopsDB;
switch ( $type ) {
case 'users':
$sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("users")." WHERE (uid > 0) AND ( level >0 )";
break;
case 'all':
$sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_posts");
break;
case 'forum':
$sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_posts")." WHERE forum_id = $id";
break;
case 'topic':
$sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_posts")." WHERE topic_id = $id";
break;
// Old, we should never get this.
case 'user':
exit("Should be using the users.user_posts column for this.");
}
if ( !$result = $xoopsDB->query($sql) ) {
return "ERROR";
}
if ( !$myrow = $xoopsDB->fetchArray($result) ) {
return 0;
}
return $myrow['total'];
}
/*
* Returns the most recent post in a forum, or a topic
*/
function get_last_post($id, $type)
{
global $xoopsDB;
switch ( $type ) {
case 'time_fix':
$sql = "SELECT post_time FROM ".$xoopsDB->prefix("bb_posts")." WHERE topic_id = $id ORDER BY post_time DESC";
break;
case 'forum':
$sql = "SELECT p.post_time, p.uid, u.uname FROM ".$xoopsDB->prefix("bb_posts")." p, ".$xoopsDB->prefix("users")." u WHERE p.forum_id = $id AND p.uid = u.uid ORDER BY post_time DESC";
break;
case 'topic':
$sql = "SELECT p.post_time, u.uname FROM ".$xoopsDB->prefix("bb_posts")." p, ".$xoopsDB->prefix("users")." u WHERE p.topic_id = $id AND p.uid = u.uid ORDER BY post_time DESC";
break;
case 'user':
$sql = "SELECT post_time FROM ".$xoopsDB->prefix("bb_posts")." WHERE uid = $id";
break;
}
if ( !$result = $xoopsDB->query($sql,1,0) ) {
return _MD_ERROR;
}
if ( !$myrow = $xoopsDB->fetchArray($result) ) {
return _MD_NOPOSTS;
}
if ( ($type != 'user') && ($type != 'time_fix') ) {
$val = sprintf("%s
%s %s", $myrow['post_time'], _MD_BY, $myrow['uname']);
} else {
$val = $myrow['post_time'];
}
return $val;
}
/*
* Returns an array of all the moderators of a forum
*/
function get_moderators($forum_id)
{
global $xoopsDB;
$sql = "SELECT u.uid, u.uname FROM ".$xoopsDB->prefix("users")." u, ".$xoopsDB->prefix("bb_forum_mods")." f WHERE f.forum_id = $forum_id and f.user_id = u.uid";
//echo $sql;
if ( !$result = $xoopsDB->query($sql) ) {
return array();
}
if ( !$myrow = $xoopsDB->fetchArray($result) ) {
return array();
}
do {
$array[] = array($myrow['uid'] => $myrow['uname']);
} while ( $myrow = $xoopsDB->fetchArray($result) );
return $array;
}
/*
* Checks if a user (user_id) is a moderator of a perticular forum (forum_id)
* Retruns 1 if TRUE, 0 if FALSE or Error
*/
function is_moderator($forum_id, $user_id)
{
global $xoopsDB;
$sql = "SELECT COUNT(*) FROM ".$xoopsDB->prefix("bb_forum_mods")." WHERE forum_id = $forum_id AND user_id = $user_id";
$ret = false;
if ( $result = $xoopsDB->query($sql) ) {
if ( $myrow = $xoopsDB->fetchRow($result) ) {
if ( $myrow[0] > 0 ) {
$ret = true;
}
}
}
return $ret;
}
/*
* Checks if a topic is locked
*/
function is_locked($topic)
{
global $xoopsDB;
$ret = false;
$sql = "SELECT topic_status FROM ".$xoopsDB->prefix("bb_topics")." WHERE topic_id = $topic";
if ( $r = $xoopsDB->query($sql) ) {
if ( $m = $xoopsDB->fetchArray($r) ) {
if ( $m['topic_status'] == 1 ) {
$ret = true;
}
}
}
return $ret;
}
/**
* Checks if the given userid is allowed to log into the given (private) forumid.
* If the "is_posting" flag is true, checks if the user is allowed to post to that forum.
*/
function check_priv_forum_auth($userid, $forumid, $is_posting)
{
global $xoopsDB;
$sql = "SELECT count(*) AS user_count FROM ".$xoopsDB->prefix("bb_forum_access")." WHERE (user_id = $userid) AND (forum_id = $forumid) ";
if ( $is_posting ) {
$sql .= "AND (can_post = 1)";
}
if ( !$result = $xoopsDB->query($sql) ) {
// no good..
return false;
}
if ( !$row = $xoopsDB->fetchArray($result) ) {
return false;
}
if ( $row['user_count'] <= 0 ) {
return false;
}
return true;
}
function make_jumpbox($selected=0)
{
global $xoopsDB;
$myts = MyTextSanitizer::getInstance();
$box = '