<?php
defined('WikyBlog') or die("Not an entry point...");
if( $_SESSION['userlevel'] !== 5){
global $page;
$page->contentA['Admin Only'] = 'You must be an administrator to access this page.';
return;
}
global $rootDir;
pluginIncludeFile('include/admin/adminSync.php');
pluginIncludeFile('include/allForumScripts.php');
wbLang::pluginFile('admin.php');
class forumAdmin{
function forumAdmin(&$pathArray){
global $page,$dbObject,$langA,$pageOwner,$dbInfo,$wbPluginSpace;
$dbObject->links[$langA['forum_admin']] = '/Admin/'.$pageOwner['username'].'/'.$wbPluginSpace.'/Admin';
$dbObject->links[$langA['categories']] = '/Admin/'.$pageOwner['username'].'/'.$wbPluginSpace.'/Categories';
$dbObject->links[$langA['permissions']] = '/Admin/'.$pageOwner['username'].'/'.$wbPluginSpace.'/Permissions';
$dbObject->links['forums'] = '/'.$wbPluginSpace;
$this->forumsMain();
}
function forumsMain(){
global $page,$langA,$dbObject;
$this->title = $page->displayTitle = $langA['forum_admin'];
$page->formAction = $dbObject->links[$this->title];
ob_start();
$showList = true;
switch($page->userCmd){
case 'sync':
forumSync::sync($_GET['id']);
break;
// forum add/edit
case 'editforum';
if( $this->updateForum() ){
break;
}
case 'fedit';
$this->editForum();
$showList = false;
break;
case 'addforum':
if( $this->saveForum() ){
break;
}
case 'newforum':
$this->newForum();
$showList = false;
break;
case 'fdelconf':
$this->deleteForumConfirmed();
break;
case 'fdelete';
$this->deleteForum();
$showList = false;
break;
//up and down
case 'cup':
$this->categoryUp();
break;
case 'cdown':
$this->categoryDown();
break;
case 'fup':
$this->forumUp();
break;
case 'fdown':
$this->forumDown();
break;
}
if($showList){
$this->getList();
}
$page->contentA[$this->title] = wb::get_clean();
}
function getList(){
global $wbTables,$langA,$pageOwner,$wbPluginSpace;
$query = 'SELECT '.$wbTables['bb_forums'].'.*, '.$wbTables['bb_categories'].'.`title` as `cat_title` ';
$query .= ' FROM '.$wbTables['bb_forums'];
$query .= ' LEFT JOIN '.$wbTables['bb_categories'].' USING (`cat_id`) ';
$query .= ' ORDER BY `cat_position` , '.$wbTables['bb_forums'].'.`position` ';
$result = wbDB::runQuery($query);
if( mysql_num_rows($result) < 1){
$this->newForum();
message('EMPTY_FORUM');
return;
}
echo '<table width="100%" cellpadding="3">';
$currentCat = false;
while($row = mysql_fetch_assoc($result)){
if( $currentCat != $row['cat_id'] ){
$this->catHeader($row);
$currentCat = $row['cat_id'];
$i = 0;
}
echo '<tr>';
echo '<td>';
echo wbLinks::local('/'.$wbPluginSpace.'/'.$row['id'].'_'.$row['title'],toDisplay($row['title']));
echo '<br/>';
echo '<span class="sm">';
echo $row['topics'].' '.$langA['topics'];
echo ' - ';
echo $row['posts'].' '.$langA['posts'];
echo '</td>';
echo '<td style="width:100px;white-space:nowrap">';
echo wbLinks::admin($wbPluginSpace.'/Admin?cmd=fedit&id='.$row['id'],'<img alt="" height="16" width="16" src="'.wbLinks::getDir('/imgs/icons/pencil.gif').'" /> ');
echo ' ';
echo wbLinks::admin($wbPluginSpace.'/Permissions?cmd=edit&id='.$row['id'],'<img alt="" height="16" width="16" src="'.wbLinks::getDir('/imgs/icons/user.gif').'" alt="'.$langA['permissions'].'" title="'.$langA['permissions'].'" /> ');
echo ' ';
echo wbLinks::admin($wbPluginSpace.'/Admin?cmd=fup&cat='.$row['cat_id'].'&pos='.$row['position'],'<img alt="" height="16" width="16" src="'.wbLinks::getDir('/imgs/icons/arrow_up.gif').'" /> ');
echo ' ';
echo wbLinks::admin($wbPluginSpace.'/Admin?cmd=fdown&cat='.$row['cat_id'].'&pos='.$row['position'],'<img alt="" height="16" width="16" src="'.wbLinks::getDir('/imgs/icons/arrow_down.gif').'" /> ');
echo ' ';
echo wbLinks::admin($wbPluginSpace.'/Admin?cmd=sync&id='.$row['id'],'<img alt="" height="16" width="16" src="'.wbLinks::getDir('/imgs/icons/wrench.gif').'" alt="'.$langA['synchronize'].'" title="'.$langA['synchronize'].'" /> ');
echo ' ';
echo wbLinks::admin($wbPluginSpace.'/Admin?cmd=fdelete&id='.$row['id'],'<img alt="" height="16" width="16" src="'.wbLinks::getDir('/imgs/icons/delete.gif').'" /> ');
echo '</td>';
echo '</tr>';
$i++;
}
if( $currentCat !== false){
echo '<tr class="sm" style="background-color:#f1f1f1;line-height:100%;">';
echo '<td colspan="4"> </td>';
echo '</tr>';
}
echo '</table>';
echo '<div style="text-align:center;margin-top:1em;">';
echo wbLinks::admin($wbPluginSpace.'/Admin?cmd=newforum','new_forum');
echo ' - ';
echo wbLinks::admin($wbPluginSpace.'/Categories','categories');
echo '</div>';
}
function catHeader(&$row){
global $langA,$pageOwner,$wbPluginSpace;
echo '<tr>';
echo '<th style="font-size:140%;background-color:#f1f1f1;" >';
echo toDisplay($row['cat_title']);
echo '</th>';
echo '<th style="font-size:140%;background-color:#f1f1f1;text-align:right;" >';
echo wbLinks::admin($wbPluginSpace.'/Admin?cmd=cup&pos='.$row['cat_position'],'<img alt="" height="16" width="16" src="'.wbLinks::getDir('/imgs/icons/arrow_up.gif').'" /> ');
echo wbLinks::admin($wbPluginSpace.'/Admin?cmd=cdown&pos='.$row['cat_position'],'<img alt="" height="16" width="16" src="'.wbLinks::getDir('/imgs/icons/arrow_down.gif').'" /> ');
echo '</th>';
echo '</tr>';
}
function setCategories(){
global $wbTables;
$this->categories = array();
//get categories
$query = 'SELECT '.$wbTables['bb_categories'].'.* ';
$query .= ', '.$wbTables['bb_forums'].'.`id` as `not_empty` ';
$query .= ' FROM '.$wbTables['bb_categories'];
$query .= ' LEFT JOIN '.$wbTables['bb_forums'].' using(`cat_id`)';
$query .= ' GROUP BY `cat_id` ';
$query .= ' ORDER BY `position` ASC ';
$result = wbDB::runQuery($query);
while($row = mysql_fetch_assoc($result) ){
$this->categories[$row['cat_id']] = toDisplay($row['title']);
$this->categoryContents[$row['cat_id']] = $row['not_empty'];
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Forum add/edit
//
function saveForum(){
global $wbTables;
if( empty($_POST['title']) ){
message('EMPTY_TITLE');
return false;
}
//$_POST['title'] = htmlspecialchars($_POST['title']); //not for forums
if( strlen($_POST['title']) > 150 ){
message('TITLE_TOO_LONG');
return false;
}
if( empty($_POST['desc']) ){
message('EMPTY_TEXT');
return false;
}
//get position
$nextPos = $this->getNextPosition($_POST['cat_id']);
$catPos = $this->getCatPosition($_POST['cat_id']);
//insert
$query = ' INSERT INTO '.$wbTables['bb_forums'];
$query .= ' SET ';
$query .= ' `title` = "'. wbDB::escape(toStorage($_POST['title'])) .'" ';
$query .= ' , `desc` = "'. wbDB::escape($_POST['desc']) .'" ';
$query .= ' , `cat_id` = "'. wbDB::escape($_POST['cat_id']) .'" ';
$query .= ' , `position` = "'. wbDB::escape($nextPos) .'" ';
$query .= ' , `cat_position` = "'. wbDB::escape($catPos) .'" ';
$query .= ' , `topics_per_page` = "'. wbDB::escape((int)$_POST['topics_per_page']) .'" ';
$query .= ' , `posts_per_page` = "'. wbDB::escape((int)$_POST['posts_per_page']) .'" ';
$query .= ' , `last_post_user` = "" ';
$query .= ' , `last_post_ip` = "" ';
if( !wbDB::runQuery($query) ){
return false;
}
return true;
}
function updateForum(){
global $wbTables;
if( !isset($_POST['id']) ){
message('INVALID_REQUEST');
return true;
}
if( !is_numeric($_POST['id'])){
message('INVALID_REQUEST');
return;
}
$row = $this->getForumData($_POST['id']);
if( !$row ){
message('INVALID_REQUEST');
return;
}
$nextPos = false;
$catPos = false;
//what has changed
if( $row['cat_id'] !== $_POST['cat_id'] ){
$nextPos = $this->getNextPosition($_POST['cat_id']);
$catPos = $this->getCatPosition($_POST['cat_id']);
$query = 'UPDATE '.$wbTables['bb_forums'];
$query .= ' SET ';
$query .= ' `modified` = `modified` ';
$query .= ', `position` = `position`-1 ';
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($row['cat_id']) .'" ';
$query .= ' AND `position` > "'. wbDB::escape($row['position']) .'" ';
if( !wbDB::runQuery($query) ){
return false;
}
}
$this->updateForumPrune($row['id'],$_POST);
$query = 'UPDATE '.$wbTables['bb_forums'];
$query .= ' SET ';
$query .= ' `modified` = `modified` ';
$query .= ' ,`title` = "'. wbDB::escape(htmlspecialchars(toStorage($_POST['title']))) .'" ';
$query .= ' , `desc` = "'. wbDB::escape($_POST['desc']) .'" ';
$query .= ' , `topics_per_page` = "'. wbDB::escape((int)$_POST['topics_per_page']) .'" ';
$query .= ' , `posts_per_page` = "'. wbDB::escape((int)$_POST['posts_per_page']) .'" ';
if( $nextPos ){
$query .= ', `cat_id` = "'. wbDB::escape($_POST['cat_id']) .'" ';
$query .= ' , `position` = "'. wbDB::escape($nextPos) .'" ';
$query .= ' , `cat_position` = "'. wbDB::escape($catPos) .'" ';
}
$query .= ' WHERE ';
$query .= ' `id` = "'. wbDB::escape($row['id']) .'" ';
if( !wbDB::runQuery($query) ){
return false;
}
message('saved');
return true;
}
function updateForumPrune($id,&$values){
global $wbTables;
$values += array('prune'=>'','age'=>'','stickies'=>'');
if( empty($values['age']) || !is_numeric($values['age']) ){
$values['age'] = '365';
}
if( $values['prune'] != '1'){
$values['prune'] = '0';
}
if( $values['stickies'] != '1'){
$values['stickies'] = '0';
}
$query = 'REPLACE INTO '.$wbTables['bb_forums_prune'];
$query .= ' SET ';
$query .= ' `forum_id` = "'. wbDB::escape($id) .'" ';
$query .= ' , `age` ="'. wbDB::escape($values['age']) .'" ';
$query .= ' , `prune` = "'. wbDB::escape($values['prune']) .'" ';
$query .= ' , `stickies` = "'. wbDB::escape($values['stickies']) .'" ';
wbDB::runQuery($query);
}
function getCatPosition(&$cat_id){
global $wbTables;
$query = 'SELECT `position` ';
$query .= ' FROM '.$wbTables['bb_categories'];
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($cat_id) .'" ';
$query .= ' GROUP BY `cat_id` ';
$result = wbDB::runQuery($query);
if( mysql_num_rows($result) == 0){
return '0';
}else{
$row = mysql_fetch_assoc($result);
return $row['position'];
}
}
function getNextPosition(&$cat_id){
global $wbTables;
$query = 'SELECT MAX(`position`)+1 as `position` ';
$query .= ' FROM '.$wbTables['bb_forums'];
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($cat_id) .'" ';
$query .= ' GROUP BY `cat_id` ';
$result = wbDB::runQuery($query);
if( mysql_num_rows($result) == 0){
return '0';
}else{
$row = mysql_fetch_assoc($result);
return $row['position'];
}
}
function newForum(){
global $langA,$page,$wbTables;
$this->setCategories();
if( count($this->categories) < 1){
$this->newCatForm();
return;
}
if(isset($_GET['cat_id']) ){
$_POST['cat_id'] = $_GET['cat_id'];
}
echo '<input type="hidden" name="cmd" value="addforum" />';
$this->forumForm($langA['new_forum'],$_POST);
}
function newCatForm(){
global $langA,$page,$dbObject;
$this->title = $page->displayTitle = $langA['categories'];
$page->formAction = $dbObject->links[$this->title];
echo '<table class="tableRows" style="margin:0 auto 0 auto;">';
echo '<tr>';
echo '<th colspan="2">';
echo $langA['new_category'];
echo '</th>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '<input type="input" name="title" value="" />';
echo '<input type="hidden" name="cmd" value="addcat" />';
echo '</td>';
echo '<td>';
echo '<input type="submit" name="" value="'.$langA['submit'].'" />';
echo ' <input type="submit" name="cmd" value="'.$langA['cancel'].'" />';
echo '</td>';
echo '</tr>';
echo '</table>';
}
function getForumData($id){
global $wbTables;
//get the data
$query = 'SELECT * FROM '.$wbTables['bb_forums'];
$query .= ' LEFT JOIN '.$wbTables['bb_forums_prune'];
$query .= ' ON '.$wbTables['bb_forums'].'.`id` = '.$wbTables['bb_forums_prune'].'.`forum_id` ';
$query .= ' WHERE ';
$query .= ' `id` = "'. wbDB::escape($id) .'" ';
$query .= ' LIMIT 1 OFFSET 0 ';
$result = wbDB::runQuery($query);
if( mysql_num_rows($result) !== 1){
return false;
}
$row = mysql_fetch_assoc($result);
return $row;
}
function editForum(){
global $langA,$wbTables;
if( isset($_POST['id']) ){
$id = $_POST['id'];
}else{
$id = $_GET['id'];
}
if( !is_numeric($id)){
message('INVALID_REQUEST');
return;
}
echo '<input type="hidden" name="cmd" value="editforum" />';
echo '<input type="hidden" name="id" value="'.$id.'" />';
if( isset($_POST['id']) ){
$this->forumForm($langA['edit_forum'],$_POST);
return;
}
$row = $this->getForumData($id);
if( !$row ){
message('INVALID_REQUEST');
return;
}
$row['title'] = toDisplay($row['title']);
$this->forumForm($langA['edit_forum'],$row);
}
function forumForm($title,&$vars){
global $langA,$pageOwner,$page,$wbPluginSpace,$page;
$page->css2 = true;
$page->displayTitle .= ' > '.$title;
$vars += array('desc'=>'','title'=>'','prune'=>'','stickies'=>'','age'=>'365');
if( empty($vars['age']) ){
$vars['age'] = '365';
}
if( empty($vars['topics_per_page']) ){
$vars['topics_per_page'] = '20';
}
if( empty($vars['posts_per_page']) ){
$vars['posts_per_page'] = '20';
}
echo '<table style="margin:1em auto 0 auto">';
echo '<tr><td style="text-align:center">';
echo '<table cellpadding="5" class="WBeditArea1">';
echo '<tr>';
echo '<th style="text-align:right">';
echo $langA['category'];
echo ':</th>';
echo '<td style="text-align:left">';
echo '<select name="cat_id">';
if( empty($this->categories) ){
$this->setCategories();
}
foreach($this->categories as $id => $title){
if( isset($vars['cat_id']) && ($vars['cat_id'] == $id) ){
echo '<option value="'.$id.'" selected="selected">'.strip_tags($title).'</option>';
}else{
echo '<option value="'.$id.'">'.strip_tags($title).'</option>';
}
}
echo '</select>';
echo ' <span class="sm">';
echo wbLinks::local('/Admin/'.$pageOwner['username'].'/'.$wbPluginSpace.'/Categories','categories');
echo '</span>';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th style="text-align:right">';
echo $langA['title'];
echo ':</th>';
echo '<td style="text-align:left">';
echo '<input type="text" name="title" style="width:40em" maxwidth="60" value="'.htmlspecialchars($vars['title']).'" />';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th style="text-align:right">';
echo $langA['description'];
echo ':</th>';
echo '<td colspan="2">';
echo '<textarea rows="10" style="width:40em" name="desc">';
echo htmlspecialchars($vars['desc']);
echo '</textarea>';
echo '</td>';
echo '</tr>';
//
// Limits
//
echo '<tr>';
echo '<th style="text-align:right">';
echo $langA['topics_per_page'];
echo ':</th>';
echo '<td style="text-align:left">';
echo '<input type="text" name="topics_per_page" style="width:5em" maxwidth="60" value="'.htmlspecialchars($vars['topics_per_page']).'" />';
echo ' <span class="sm">'.$langA['defaults_20'].'</span>';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th style="text-align:right">';
echo $langA['posts_per_page'];
echo ':</th>';
echo '<td style="text-align:left">';
echo '<input type="text" name="posts_per_page" style="width:5em" maxwidth="60" value="'.htmlspecialchars($vars['posts_per_page']).'" />';
echo ' <span class="sm">'.$langA['defaults_20'].'</span>';
echo '</td>';
echo '</tr>';
//
// Pruniing
//
echo '<tr>';
echo '<th style="text-align:right">';
echo $langA['auto_pruning'];
echo ':</th>';
echo '<td style="text-align:left">';
$this->formRadios('prune',$vars['prune']);
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th style="text-align:right">';
echo $langA['prune_stickies'];
echo ':</th>';
echo '<td style="text-align:left">';
$this->formRadios('stickies',$vars['stickies']);
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th style="text-align:right">';
echo $langA['prune_post_age'];
echo ':</th>';
echo '<td style="text-align:left">';
echo '<input type="text" name="age" style="width:5em" maxwidth="60" value="'.htmlspecialchars($vars['age']).'" />';
echo ' <span class="sm">'.$langA['PRUNE_POST_AGE'].'</span>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<input type="submit" name="" value="'.$langA['submit'].'" />';
echo ' ';
echo '<input type="submit" name="cmd" value="'.$langA['cancel'].'" />';
echo '</td></tr>';
echo '</table>';
}
function formRadios($name,$value){
global $langA;
echo '<input type="radio" name="'.$name.'" value="1" ';
if( $value == '1' ){
echo ' checked="checked" ';
}
echo '/>'.$langA['yes'];
echo ' ';
echo '<input type="radio" name="'.$name.'" value="0" ';
if( $value != '1' ){
echo ' checked="checked" ';
}
echo '/>'.$langA['no'];
}
////////////////////////////////////////////////////////////////////////////////
//
// Forum Deletion
//
function deleteForum(){
global $langA,$page;
$page->css2 = true;
echo '<table style="margin: 4em auto 4em auto;" class="WBeditArea1">';
echo '<tr><td style="text-align:center">';
echo '<input type="hidden" name="cmd" value="fdelconf" />';
echo '<input type="hidden" name="id" value="'.$_GET['id'].'" />';
echo $langA['CONFIRM_DELETE_FORUM'];
echo '<br/> <br/>';
echo '<input type="submit" name="" value="'.$langA['confirm'].'" />';
echo ' ';
echo '<input type="submit" name="cmd" value="'.$langA['cancel'].'" />';
echo '</td></tr></table>';
}
function deleteForumConfirmed(){
global $wbTables;
if( !isset($_POST['id']) || !is_numeric($_POST['id']) ){
message('INVALID_REQUEST');
return;
}
//posts
$query = 'DELETE FROM '.$wbTables['bb_posts'];
$query .= 'WHERE ';
$query .= ' `forum_id` = "'.wbDB::escape($_POST['id']).'" ';
if( !wbDB::runQuery($query) ){
message('DELETE_FAILED');
return;
}
//topics
$query = 'DELETE FROM '.$wbTables['bb_topics'];
$query .= 'WHERE ';
$query .= ' `forum_id` = "'.wbDB::escape($_POST['id']).'" ';
if( !wbDB::runQuery($query) ){
message('DELETE_FAILED');
return;
}
// forums
$query = 'DELETE FROM '.$wbTables['bb_forums'];
$query .= 'WHERE ';
$query .= ' `id` = "'.wbDB::escape($_POST['id']).'" ';
if( !wbDB::runQuery($query) ){
message('DELETE_FAILED');
return;
}
// forums_access
$query = 'DELETE FROM '.$wbTables['bb_forums_access'];
$query .= 'WHERE ';
$query .= ' `forum_id` = "'.wbDB::escape($_POST['id']).'" ';
if( !wbDB::runQuery($query) ){
message('DELETE_FAILED');
return;
}
// forums_prune
$query = 'DELETE FROM '.$wbTables['bb_forums_prune'];
$query .= 'WHERE ';
$query .= ' `forum_id` = "'.wbDB::escape($_POST['id']).'" ';
if( !wbDB::runQuery($query) ){
message('DELETE_FAILED');
return;
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Category Order
//
function categoryUp(){
if( !isset($_GET['pos']) ){
message('COULDNT_MOVE');
return false;
}
$this->categoryMove($_GET['pos']-1);
}
function categoryDown(){
if( !isset($_GET['pos']) ){
message('COULDNT_MOVE');
return false;
}
$this->categoryMove($_GET['pos']);
}
function categoryMove($position){
global $wbTables;
if( !is_numeric($position) ){
message('COULDNT_MOVE');
return false;
}
if( $position < 0){
message('COULDNT_MOVE');
return false;
}
//get down category
$query = 'SELECT `cat_id` FROM '.$wbTables['bb_categories'];
$query .= ' WHERE ';
$query .= ' `position` = "'. wbDB::escape($position) .'" ';
$query .= ' LIMIT 1 OFFSET 0';
$result = wbDB::runQuery($query);
if( mysql_num_rows($result) !== 1){
message('COULDNT_MOVE');
return false;
}
$row = mysql_fetch_assoc($result);
$downId = $row['cat_id'];
//get up category
$query = 'SELECT `cat_id` FROM '.$wbTables['bb_categories'];
$query .= ' WHERE ';
$query .= ' `position` = "'. wbDB::escape($position+1) .'" ';
$query .= ' LIMIT 1 OFFSET 0';
$result = wbDB::runQuery($query);
if( mysql_num_rows($result) !== 1){
message('COULDNT_MOVE');
return false;
}
$row = mysql_fetch_assoc($result);
$upId = $row['cat_id'];
//move down - categories
$query = 'UPDATE '.$wbTables['bb_categories'];
$query .= ' SET ';
$query .= ' `position` = `position`+1 ';
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($downId) .'" ';
$query .= ' LIMIT 1';
if( !wbDB::runQuery($query) ){
message('COULDNT_MOVE');
return;
}
//move down - forums
$query = 'UPDATE '.$wbTables['bb_forums'];
$query .= ' SET ';
$query .= ' `cat_position` = `cat_position`+1 ';
$query .= ' , `modified` = `modified` ';
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($downId) .'" ';
if( !wbDB::runQuery($query) ){
message('COULDNT_MOVE');
return;
}
//move up
$query = 'UPDATE '.$wbTables['bb_categories'];
$query .= ' SET ';
$query .= ' `position` = `position`-1 ';
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($upId) .'" ';
$query .= ' LIMIT 1';
if( !wbDB::runQuery($query) ){
message('COULDNT_MOVE');
return;
}
//move up - forums
$query = 'UPDATE '.$wbTables['bb_forums'];
$query .= ' SET ';
$query .= ' `cat_position` = `cat_position`-1 ';
$query .= ' , `modified` = `modified` ';
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($upId) .'" ';
if( !wbDB::runQuery($query) ){
message('COULDNT_MOVE');
return;
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Forum Editing
//
function forumUp(){
if( !isset($_GET['pos']) ){
message('COULDNT_MOVE');
return;
}
$this->forumMove($_GET['pos']-1);
}
function forumDown(){
if( !isset($_GET['pos']) ){
message('COULDNT_MOVE');
return;
}
$this->forumMove($_GET['pos']);
}
function forumMove($position){
global $wbTables;
if( !is_numeric($position) ){
message('COULDNT_MOVE');
return;
}
if( $position < 0 ){
message('COULDNT_MOVE');
return;
}
//category
if( !isset($_GET['cat']) ){
message('COULDNT_MOVE');
return;
}
$category = $_GET['cat'];
if( !is_numeric($category) ){
message('COULDNT_MOVE');
return;
}
//get category and position
$query = 'SELECT `id`FROM '.$wbTables['bb_forums'];
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($category) .'" ';
$query .= ' AND `position` = "'. wbDB::escape($position) .'" ';
$query .= ' LIMIT 1 OFFSET 0';
$result = wbDB::runQuery($query);
if( mysql_num_rows($result) == 0){
message('COULDNT_MOVE');
return;
}
$row = mysql_fetch_assoc($result);
$downId = $row['id'];
//make sure there's a forum below
$next = $position+1;
$query = 'SELECT `id` FROM '.$wbTables['bb_forums'];
$query .= ' WHERE ';
$query .= ' `cat_id` = "'. wbDB::escape($category) .'" ';
$query .= ' AND `position` = "'. wbDB::escape($next) .'" ';
$result = wbDB::runQuery($query);
if( mysql_num_rows($result) == 0){
message('COULDNT_MOVE');
return;
}
$row = mysql_fetch_assoc($result);
$upId = $row['id'];
//move down
$query = 'UPDATE '.$wbTables['bb_forums'];
$query .= ' SET ';
$query .= ' `modified` = `modified` ';
$query .= ', `position` = `position`+1 ';
$query .= ' WHERE ';
$query .= ' `id` = "'. wbDB::escape($downId) .'" ';
$query .= ' LIMIT 1';
if( !wbDB::runQuery($query) ){
message('COULDNT_MOVE');
return;
}
//move up
$query = 'UPDATE '.$wbTables['bb_forums'];
$query .= ' SET ';
$query .= ' `modified` = `modified` ';
$query .= ', `position` = `position`-1 ';
$query .= ' WHERE ';
$query .= ' `id` = "'. wbDB::escape($upId) .'" ';
$query .= ' LIMIT 1';
if( !wbDB::runQuery($query) ){
message('COULDNT_MOVE');
return;
}
}
}
global $initiateFileClass;
if( $initiateFileClass ){
new forumAdmin($pathArray);
}