* added forums for guilds and groups

* (internal) new function: OTS_Guild::hasMember(OTS_Player $player)
* (internal) new function: Forum::hasAccess($board_id)
This commit is contained in:
slawkens 2017-10-20 16:59:14 +02:00
parent c2678aa91f
commit 762fa31c28
17 changed files with 280 additions and 136 deletions

View File

@ -28,7 +28,7 @@ session_start();
define('MYAAC', true); define('MYAAC', true);
define('MYAAC_VERSION', '0.6.1'); define('MYAAC_VERSION', '0.6.1');
define('DATABASE_VERSION', 14); define('DATABASE_VERSION', 15);
define('TABLE_PREFIX', 'myaac_'); define('TABLE_PREFIX', 'myaac_');
define('START_TIME', microtime(true)); define('START_TIME', microtime(true));
define('MYAAC_OS', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'WINDOWS' : (strtoupper(PHP_OS) == 'DARWIN' ? 'MAC' : 'LINUX')); define('MYAAC_OS', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'WINDOWS' : (strtoupper(PHP_OS) == 'DARWIN' ? 'MAC' : 'LINUX'));

View File

@ -85,6 +85,8 @@ CREATE TABLE `myaac_forum_boards`
`description` VARCHAR(255) NOT NULL DEFAULT '', `description` VARCHAR(255) NOT NULL DEFAULT '',
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
`closed` TINYINT(1) NOT NULL DEFAULT 0, `closed` TINYINT(1) NOT NULL DEFAULT 0,
`guild` INT(11) NOT NULL DEFAULT 0,
`access` INT(11) NOT NULL DEFAULT 0,
`hidden` TINYINT(1) NOT NULL DEFAULT 0, `hidden` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE = MyISAM; ) ENGINE = MyISAM;

View File

@ -215,7 +215,7 @@ function generateRandomString($length, $lowCase = true, $upCase = false, $numeri
function getForumBoards() function getForumBoards()
{ {
global $db, $canEdit; global $db, $canEdit;
$sections = $db->query('SELECT `id`, `name`, `description`, `closed`' . ($canEdit ? ', `hidden`, `ordering`' : '') . ' FROM `' . TABLE_PREFIX . 'forum_boards` ' . (!$canEdit ? ' WHERE `hidden` != 1' : '') . $sections = $db->query('SELECT `id`, `name`, `description`, `closed`, `guild`, `access`' . ($canEdit ? ', `hidden`, `ordering`' : '') . ' FROM `' . TABLE_PREFIX . 'forum_boards` ' . (!$canEdit ? ' WHERE `hidden` != 1' : '') .
' ORDER BY `ordering`;'); ' ORDER BY `ordering`;');
if($sections) if($sections)
return $sections->fetchAll(); return $sections->fetchAll();

View File

@ -74,6 +74,7 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
* *
* @version 0.1.3 * @version 0.1.3
*/ */
/*
public function __clone() public function __clone()
{ {
unset($this->data['id']); unset($this->data['id']);
@ -90,7 +91,7 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
$this->requests->__construct($this); $this->requests->__construct($this);
} }
} }
*/
/** /**
* Assigns invites handler. * Assigns invites handler.
* *
@ -282,6 +283,26 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
$this->data['ownerid'] = $owner->getId(); $this->data['ownerid'] = $owner->getId();
} }
public function hasMember(OTS_Player $player) {
global $db;
if(!$player || !$player->isLoaded()) {
return false;
}
$player_rank = $player->getRank();
if(!$player_rank->isLoaded()) {
return false;
}
foreach($this->getGuildRanksList() as $rank) {
if($rank->getId() == $player_rank->getId()) {
return true;
}
}
return false;
}
/** /**
* Guild creation data. * Guild creation data.
* *

11
system/migrations/15.php Normal file
View File

@ -0,0 +1,11 @@
<?php
// add new forum.guild and forum.access fields
if(!fieldExist('guild', TABLE_PREFIX . 'forum_boards')) {
$db->query("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` ADD `guild` TINYINT(1) NOT NULL DEFAULT 0 AFTER `closed`;");
}
if(!fieldExist('access', TABLE_PREFIX . 'forum_boards')) {
$db->query("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` ADD `access` TINYINT(1) NOT NULL DEFAULT 0 AFTER `guild`;");
}
?>

View File

@ -30,11 +30,19 @@ if(!$logged)
$canEdit = hasFlag(FLAG_CONTENT_FORUM) || superAdmin(); $canEdit = hasFlag(FLAG_CONTENT_FORUM) || superAdmin();
if($canEdit) if($canEdit)
{ {
$groups = new OTS_Groups_List();
if(!empty($action)) if(!empty($action))
{ {
if($action == 'delete_board' || $action == 'edit_board' || $action == 'hide_board' || $action == 'moveup_board' || $action == 'movedown_board') if($action == 'delete_board' || $action == 'edit_board' || $action == 'hide_board' || $action == 'moveup_board' || $action == 'movedown_board')
$id = $_REQUEST['id']; $id = $_REQUEST['id'];
if(isset($_REQUEST['access']))
$access = $_REQUEST['access'];
if(isset($_REQUEST['guild']))
$guild = $_REQUEST['guild'];
if(isset($_REQUEST['name'])) if(isset($_REQUEST['name']))
$name = $_REQUEST['name']; $name = $_REQUEST['name'];
@ -44,7 +52,7 @@ if($canEdit)
$errors = array(); $errors = array();
if($action == 'add_board') { if($action == 'add_board') {
if(Forum::add_board($name, $description, $errors)) if(Forum::add_board($name, $description, $access, $guild, $errors))
$action = $name = $description = ''; $action = $name = $description = '';
} }
else if($action == 'delete_board') { else if($action == 'delete_board') {
@ -56,11 +64,14 @@ if($canEdit)
if(isset($id) && !isset($name)) { if(isset($id) && !isset($name)) {
$board = Forum::get_board($id); $board = Forum::get_board($id);
$name = $board['name']; $name = $board['name'];
$access = $board['access'];
$guild = $board['guild'];
$description = $board['description']; $description = $board['description'];
} }
else { else {
Forum::update_board($id, $name, $description); Forum::update_board($id, $name, $access, $guild, $description);
$action = $name = $description = ''; $action = $name = $description = '';
$access = $guild = 0;
} }
} }
else if($action == 'hide_board') { else if($action == 'hide_board') {
@ -83,12 +94,17 @@ if($canEdit)
} }
if(empty($action) || $action == 'edit_board') { if(empty($action) || $action == 'edit_board') {
$guilds = $db->query('SELECT `id`, `name` FROM `guilds`')->fetchAll();
echo $twig->render('forum.add_board.html.twig', array( echo $twig->render('forum.add_board.html.twig', array(
'link' => getLink('forum', ($action == 'edit_board' ? 'edit_board' : 'add_board')), 'link' => getLink('forum', ($action == 'edit_board' ? 'edit_board' : 'add_board')),
'action' => $action, 'action' => $action,
'id' => isset($id) ? $id : null, 'id' => isset($id) ? $id : null,
'name' => isset($name) ? $name : null, 'name' => isset($name) ? $name : null,
'description' => isset($description) ? $description : null 'description' => isset($description) ? $description : null,
'access' => isset($access) ? $access : 0,
'guild' => isset($guild) ? $guild : null,
'groups' => $groups,
'guilds' => $guilds
)); ));
if($action == 'edit_board') if($action == 'edit_board')
@ -103,7 +119,9 @@ foreach(getForumBoards() as $section)
'id' => $section['id'], 'id' => $section['id'],
'name' => $section['name'], 'name' => $section['name'],
'description' => $section['description'], 'description' => $section['description'],
'closed' => $section['closed'] == '1' 'closed' => $section['closed'] == '1',
'guild' => $section['guild'],
'access' => $section['access']
); );
if($canEdit) { if($canEdit) {
@ -124,6 +142,8 @@ if(empty($action))
$counters[$data['section']] = array('threads' => $data['threads'], 'posts' => $data['replies'] + $data['threads']); $counters[$data['section']] = array('threads' => $data['threads'], 'posts' => $data['replies'] + $data['threads']);
foreach($sections as $id => $section) foreach($sections as $id => $section)
{ {
$show = true;
if(Forum::hasAccess($id)) {
$last_post = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_date` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`section` = ".(int) $id." AND `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` ORDER BY `post_date` DESC LIMIT 1")->fetch(); $last_post = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_date` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`section` = ".(int) $id." AND `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` ORDER BY `post_date` DESC LIMIT 1")->fetch();
$boards[] = array( $boards[] = array(
'id' => $id, 'id' => $id,
@ -140,6 +160,7 @@ if(empty($action))
) )
); );
} }
}
echo $twig->render('forum.boards.html.twig', array( echo $twig->render('forum.boards.html.twig', array(
'boards' => $boards, 'boards' => $boards,
@ -205,7 +226,7 @@ class Forum
'post_ip' => $_SERVER['REMOTE_ADDR'] 'post_ip' => $_SERVER['REMOTE_ADDR']
)); ));
} }
static public function add_board($name, $description, &$errors) static public function add_board($name, $description, $access, $guild, &$errors)
{ {
global $db; global $db;
if(isset($name[0]) && isset($description[0])) if(isset($name[0]) && isset($description[0]))
@ -226,7 +247,7 @@ class Forum
$query = $query->fetch(); $query = $query->fetch();
$ordering = $query['ordering'] + 1; $ordering = $query['ordering'] + 1;
} }
$db->insert(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'ordering' => $ordering)); $db->insert(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'access' => $access, 'guild' => $guild, 'ordering' => $ordering));
} }
else else
$errors[] = 'Forum board with this name already exists.'; $errors[] = 'Forum board with this name already exists.';
@ -242,9 +263,9 @@ class Forum
return $db->select(TABLE_PREFIX . 'forum_boards', array('id' => $id)); return $db->select(TABLE_PREFIX . 'forum_boards', array('id' => $id));
} }
static public function update_board($id, $name, $description) { static public function update_board($id, $name, $access, $guild, $description) {
global $db; global $db;
$db->update(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description), array('id' => $id)); $db->update(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'access' => $access, 'guild' => $guild), array('id' => $id));
} }
static public function delete_board($id, &$errors) static public function delete_board($id, &$errors)
@ -389,4 +410,41 @@ class Forum
$post .= self::parseBBCode($text, $smiles); $post .= self::parseBBCode($text, $smiles);
return $post; return $post;
} }
public static function hasAccess($board_id) {
global $sections, $logged, $account_logged, $logged_access;
if(!isset($sections[$board_id]))
return false;
$hasAccess = true;
$section = $sections[$board_id];
if($section['guild'] > 0) {
if($logged) {
$guild = new OTS_Guild();
$guild->load($section['guild']);
$status = false;
if($guild->isLoaded()) {
$account_players = $account_logged->getPlayers();
foreach ($account_players as $player) {
if($guild->hasMember($player)) {
$status = true;
}
}
}
if (!$status) $hasAccess = false;
}
else {
$hasAccess = false;
}
}
if($section['access'] > 0) {
if($logged_access < $section['access']) {
$hasAccess = false;
}
}
return $hasAccess;
}
} }

View File

@ -19,12 +19,12 @@ if(Forum::canPost($account_logged))
return; return;
} }
$thread = $db->query("SELECT `" . TABLE_PREFIX . "forum`.`author_guid`, `" . TABLE_PREFIX . "forum`.`author_aid`, `" . TABLE_PREFIX . "forum`.`first_post`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`post_date`, `" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_smile`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`section` FROM `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`id` = ".$post_id." LIMIT 1")->fetch(); $thread = $db->query("SELECT `author_guid`, `author_aid`, `first_post`, `post_topic`, `post_date`, `post_text`, `post_smile`, `id`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = ".$post_id." LIMIT 1")->fetch();
if(isset($thread['id'])) if(isset($thread['id']))
{ {
$first_post = $db->query("SELECT `" . TABLE_PREFIX . "forum`.`author_guid`, `" . TABLE_PREFIX . "forum`.`author_aid`, `" . TABLE_PREFIX . "forum`.`first_post`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_smile`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`section` FROM `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`id` = ".(int) $thread['first_post']." LIMIT 1")->fetch(); $first_post = $db->query("SELECT `" . TABLE_PREFIX . "forum`.`author_guid`, `" . TABLE_PREFIX . "forum`.`author_aid`, `" . TABLE_PREFIX . "forum`.`first_post`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_smile`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`section` FROM `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`id` = ".(int) $thread['first_post']." LIMIT 1")->fetch();
echo '<a href="' . getLink('forum') . '">Boards</a> >> <a href="' . getForumBoardLink($thread['section']) . '">'.$sections[$thread['section']]['name'].'</a> >> <a href="' . getForumThreadLink($thread['first_post']) . '">'.$first_post['post_topic'].'</a> >> <b>Edit post</b>'; echo '<a href="' . getLink('forum') . '">Boards</a> >> <a href="' . getForumBoardLink($thread['section']) . '">'.$sections[$thread['section']]['name'].'</a> >> <a href="' . getForumThreadLink($thread['first_post']) . '">'.$first_post['post_topic'].'</a> >> <b>Edit post</b>';
if($account_logged->getId() == $thread['author_aid'] || Forum::isModerator()) if(Forum::hasAccess($thread['section'] && ($account_logged->getId() == $thread['author_aid'] || Forum::isModerator())))
{ {
$char_id = $post_topic = $text = $smile = null; $char_id = $post_topic = $text = $smile = null;
$players_from_account = $db->query("SELECT `players`.`name`, `players`.`id` FROM `players` WHERE `players`.`account_id` = ".(int) $account_logged->getId())->fetchAll(); $players_from_account = $db->query("SELECT `players`.`name`, `players`.`id` FROM `players` WHERE `players`.`account_id` = ".(int) $account_logged->getId())->fetchAll();

View File

@ -11,42 +11,55 @@
*/ */
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$save = isset($_REQUEST['save']) ? (int)$_REQUEST['save'] == 1 : false; if(!Forum::isModerator()) {
if($save) {
if (Forum::isModerator()) {
$id = (int)$_REQUEST['id'];
$board = (int)$_REQUEST['section'];
$post = $db->query("SELECT `id`, `first_post`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = " . $id . " LIMIT 1")->fetch();
if ($post['id'] == $id) {
if ($post['id'] == $post['first_post']) {
$db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `section` = " . $board . " WHERE `id` = " . $post['id'] . "") or die(mysql_error());
$nPost = $db->query('SELECT `section` FROM `' . TABLE_PREFIX . 'forum` WHERE `id` = \'' . $id . '\' LIMIT 1;')->fetch();
header('Location: ' . getForumBoardLink($nPost['section']));
}
} else
echo 'Post with ID ' . $id . ' does not exist.';
} else
echo 'You are not logged in or you are not moderator.'; echo 'You are not logged in or you are not moderator.';
} }
$save = isset($_REQUEST['save']) ? (int)$_REQUEST['save'] == 1 : false;
if($save) {
$post_id = (int)$_REQUEST['id'];
$board = (int)$_REQUEST['section'];
if(!Forum::hasAccess($board)) {
echo "You don't have access to this board.";
return;
}
$post = $db->query("SELECT `id`, `first_post`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = " . $post_id . " LIMIT 1")->fetch();
if ($post['id'] == $post_id) {
if ($post['id'] == $post['first_post']) {
$db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `section` = " . $board . " WHERE `id` = " . $post['id'] . "");
$nPost = $db->query('SELECT `section` FROM `' . TABLE_PREFIX . 'forum` WHERE `id` = \'' . $post_id . '\' LIMIT 1;')->fetch();
header('Location: ' . getForumBoardLink($nPost['section']));
}
}
else
echo 'Post with ID ' . $post_id . ' does not exist.';
}
else { else {
if (Forum::isModerator()) { $post_id = (int)$_REQUEST['id'];
$id = (int)$_REQUEST['id']; $post = $db->query("SELECT `id`, `section`, `first_post`, `post_topic`, `author_guid` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = " . $post_id . " LIMIT 1")->fetch();
$post = $db->query("SELECT `id`, `section`, `first_post`, `post_topic`, `author_guid` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = " . $id . " LIMIT 1")->fetch();
$name = $db->query("SELECT `name` FROM `players` WHERE `id` = " . $post['author_guid'] . " ")->fetch(); $name = $db->query("SELECT `name` FROM `players` WHERE `id` = " . $post['author_guid'] . " ")->fetch();
if ($post['id'] == $id) {
$sections_allowed = array();
foreach($sections as $id => $section) {
if(Forum::hasAccess($id)) {
$sections_allowed[$id] = $section;
}
}
if ($post['id'] == $post_id) {
if ($post['id'] == $post['first_post']) { if ($post['id'] == $post['first_post']) {
echo $twig->render('forum.move_thread.html.twig', array( echo $twig->render('forum.move_thread.html.twig', array(
'thread' => $post['post_topic'], 'thread' => $post['post_topic'],
'author' => $name[0], 'author' => $name['name'],
'board' => $sections[$post['section']]['name'], 'board' => $sections[$post['section']]['name'],
'post_id' => $post['id'], 'post_id' => $post['id'],
'sections' => $sections, 'sections' => $sections_allowed,
'section_link' => getForumBoardLink($post['section']), 'section_link' => getForumBoardLink($post['section']),
)); ));
} }
} else }
echo 'Post with ID ' . $id . ' does not exist.'; else
} else echo 'Post with ID ' . $post_id . ' does not exist.';
echo 'You are not logged in or you are not moderator.';
} }
?> ?>

View File

@ -22,7 +22,7 @@ if(Forum::canPost($account_logged))
$thread = $db->query("SELECT `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`section` FROM `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`id` = ".(int) $thread_id." AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." LIMIT 1")->fetch(); $thread = $db->query("SELECT `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`section` FROM `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`id` = ".(int) $thread_id." AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." LIMIT 1")->fetch();
echo '<a href="' . getLink('forum') . '">Boards</a> >> <a href="' . getForumBoardLink($thread['section']) . '">'.$sections[$thread['section']]['name'].'</a> >> <a href="' . getForumThreadLink($thread_id) . '">'.$thread['post_topic'].'</a> >> <b>Post new reply</b><br /><h3>'.$thread['post_topic'].'</h3>'; echo '<a href="' . getLink('forum') . '">Boards</a> >> <a href="' . getForumBoardLink($thread['section']) . '">'.$sections[$thread['section']]['name'].'</a> >> <a href="' . getForumThreadLink($thread_id) . '">'.$thread['post_topic'].'</a> >> <b>Post new reply</b><br /><h3>'.$thread['post_topic'].'</h3>';
if(isset($thread['id'])) if(isset($thread['id']) && Forum::hasAccess($thread['section']))
{ {
$quote = isset($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : NULL; $quote = isset($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : NULL;
$text = isset($_REQUEST['text']) ? stripslashes(trim($_REQUEST['text'])) : NULL; $text = isset($_REQUEST['text']) ? stripslashes(trim($_REQUEST['text'])) : NULL;
@ -81,6 +81,7 @@ if(Forum::canPost($account_logged))
echo '<br />Thank you for posting.<br /><a href="' . getForumThreadLink($thread_id, $_page) . '">GO BACK TO LAST THREAD</a>'; echo '<br />Thank you for posting.<br /><a href="' . getForumThreadLink($thread_id, $_page) . '">GO BACK TO LAST THREAD</a>';
} }
} }
if(!$saved) if(!$saved)
{ {
if(!empty($errors)) if(!empty($errors))

View File

@ -17,7 +17,7 @@ if(Forum::canPost($account_logged))
$section_id = isset($_REQUEST['section_id']) ? $_REQUEST['section_id'] : null; $section_id = isset($_REQUEST['section_id']) ? $_REQUEST['section_id'] : null;
if($section_id !== null) { if($section_id !== null) {
echo '<a href="' . getLink('forum') . '">Boards</a> >> <a href="' . getForumBoardLink($section_id) . '">' . $sections[$section_id]['name'] . '</a> >> <b>Post new thread</b><br />'; echo '<a href="' . getLink('forum') . '">Boards</a> >> <a href="' . getForumBoardLink($section_id) . '">' . $sections[$section_id]['name'] . '</a> >> <b>Post new thread</b><br />';
if (isset($sections[$section_id]['name'])) { if(isset($sections[$section_id]['name']) && Forum::hasAccess($section_id)) {
if ($sections[$section_id]['closed'] && !Forum::isModerator()) if ($sections[$section_id]['closed'] && !Forum::isModerator())
$errors[] = 'You cannot create topic on this board.'; $errors[] = 'You cannot create topic on this board.';
@ -76,6 +76,7 @@ if(Forum::canPost($account_logged))
echo '<br />Thank you for posting.<br /><a href="' . getForumThreadLink($thread_id) . '">GO BACK TO LAST THREAD</a>'; echo '<br />Thank you for posting.<br /><a href="' . getForumThreadLink($thread_id) . '">GO BACK TO LAST THREAD</a>';
} }
} }
if (!$saved) { if (!$saved) {
if (!empty($errors)) if (!empty($errors))
echo $twig->render('error_box.html.twig', array('errors' => $errors)); echo $twig->render('error_box.html.twig', array('errors' => $errors));

View File

@ -15,7 +15,7 @@ if(Forum::isModerator())
{ {
$id = (int) $_REQUEST['id']; $id = (int) $_REQUEST['id'];
$post = $db->query("SELECT `id`, `first_post`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = ".$id." LIMIT 1")->fetch(); $post = $db->query("SELECT `id`, `first_post`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = ".$id." LIMIT 1")->fetch();
if($post['id'] == $id) if($post['id'] == $id && Forum::hasAccess($post['section']))
{ {
if($post['id'] == $post['first_post']) if($post['id'] == $post['first_post'])
{ {

View File

@ -12,7 +12,18 @@
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$links_to_pages = ''; $links_to_pages = '';
$section_id = (int) $_REQUEST['id']; $section_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
if($section_id == null || !isset($sections[$section_id])) {
echo "Board with this id does't exist.";
return;
}
if(!Forum::hasAccess($section_id)) {
echo "You don't have access to this board.";
return;
}
$_page = (int) (isset($_REQUEST['page']) ? $_REQUEST['page'] : 0); $_page = (int) (isset($_REQUEST['page']) ? $_REQUEST['page'] : 0);
$threads_count = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS threads_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`section` = ".(int) $section_id." AND `" . TABLE_PREFIX . "forum`.`first_post` = `" . TABLE_PREFIX . "forum`.`id`")->fetch(); $threads_count = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS threads_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`section` = ".(int) $section_id." AND `" . TABLE_PREFIX . "forum`.`first_post` = `" . TABLE_PREFIX . "forum`.`id`")->fetch();
for($i = 0; $i < $threads_count['threads_count'] / $config['forum_threads_per_page']; $i++) for($i = 0; $i < $threads_count['threads_count'] / $config['forum_threads_per_page']; $i++)

View File

@ -14,9 +14,18 @@ defined('MYAAC') or die('Direct access not allowed!');
$links_to_pages = ''; $links_to_pages = '';
$thread_id = (int) $_REQUEST['id']; $thread_id = (int) $_REQUEST['id'];
$_page = (int) (isset($_REQUEST['page']) ? $_REQUEST['page'] : 0); $_page = (int) (isset($_REQUEST['page']) ? $_REQUEST['page'] : 0);
$thread_name = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_topic` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." AND `" . TABLE_PREFIX . "forum`.`id` = `" . TABLE_PREFIX . "forum`.`first_post` AND `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` LIMIT 1")->fetch(); $thread_name = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`section` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." AND `" . TABLE_PREFIX . "forum`.`id` = `" . TABLE_PREFIX . "forum`.`first_post` AND `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` LIMIT 1")->fetch();
if(!empty($thread_name['name']))
{ if(empty($thread_name['name'])) {
echo 'Thread with this ID does not exits.';
return;
}
if(Forum::hasAccess($thread_name['section'])) {
echo "You don't have access to view this thread.";
return;
}
$posts_count = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS posts_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id)->fetch(); $posts_count = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS posts_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id)->fetch();
for($i = 0; $i < $posts_count['posts_count'] / $config['forum_threads_per_page']; $i++) for($i = 0; $i < $posts_count['posts_count'] / $config['forum_threads_per_page']; $i++)
{ {
@ -78,8 +87,4 @@ if(!empty($thread_name['name']))
echo '</td></tr>'; echo '</td></tr>';
} }
echo '</table><br /><a href="?subtopic=forum&action=new_post&thread_id='.$thread_id.'"><img src="images/forum/post.gif" border="0" /></a>'; echo '</table><br /><a href="?subtopic=forum&action=new_post&thread_id='.$thread_id.'"><img src="images/forum/post.gif" border="0" /></a>';
}
else
echo 'Thread with this ID does not exits.';
?> ?>

View File

@ -14,6 +14,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$guild_name = $_REQUEST['guild']; $guild_name = $_REQUEST['guild'];
if(!Validator::guildName($guild_name)) if(!Validator::guildName($guild_name))
$errors[] = Validator::getLastError(); $errors[] = Validator::getLastError();
if(empty($errors)) if(empty($errors))
{ {
$guild = $ots->createObject('Guild'); $guild = $ots->createObject('Guild');

View File

@ -87,9 +87,8 @@
<td>Access:</td> <td>Access:</td>
<td> <td>
<select name="access"> <select name="access">
<?php foreach($groups->getGroups() as $id => $group): ?>
{% for id, group in groups %} {% for id, group in groups %}
<option value="{{ group.getAccess() }}"{% if access == group.getAccess() %} selected{% endif %}>{{ group.getName() }}</option> <option value="{{ group.getId() }}"{% if access == group.getId() %} selected{% endif %}>{{ group.getName() }}</option>
{% endfor %} {% endfor %}
</select> </select>
</td> </td>

View File

@ -16,6 +16,27 @@
<td>Description:</td> <td>Description:</td>
<td><textarea name="description" maxlength="300" cols="50" rows="5">{% if description is not null %}{{ description }}{% endif %}</textarea></td> <td><textarea name="description" maxlength="300" cols="50" rows="5">{% if description is not null %}{{ description }}{% endif %}</textarea></td>
<tr/> <tr/>
<tr>
<td>Access:</td>
<td>
<select name="access">
{% for id, group in groups %}
<option value="{{ group.getAccess() }}"{% if access == group.getId() %} selected{% endif %}>{{ group.getName() }}</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<td>Guild:</td>
<td>
<select name="guild">
<option value="0"{% if guild == 0 %} selected{% endif %}>----</option>
{% for guild_ in guilds %}
<option value="{{ guild_.id }}"{% if guild == guild_.id %} selected{% endif %}>{{ guild_.name }}</option>
{% endfor %}
</select>
</td>
</tr>
<tr> <tr>
<td colspan="2" align="center"><input type="submit" value="Submit"/> <td colspan="2" align="center"><input type="submit" value="Submit"/>
</tr> </tr>

View File

@ -18,8 +18,8 @@
<strong>BOARD:</strong> {{ board }}<br/><br/> <strong>BOARD:</strong> {{ board }}<br/><br/>
<strong>Select the new board:&nbsp;</strong> <strong>Select the new board:&nbsp;</strong>
<select name="section"> <select name="section">
{% for section in sections %} {% for id, section in sections %}
<option value="{{ section.id }}">{{ section.name }}</option> <option value="{{ id }}">{{ section.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
<input type="submit" value="Move Thread"> <input type="submit" value="Move Thread">