initial commit with snapshot 20140213
This commit is contained in:
34
inc/askModel.class.php
Normal file
34
inc/askModel.class.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
abstract class AskModel
|
||||
{
|
||||
protected $models = array();
|
||||
|
||||
function loadModel($model)
|
||||
{
|
||||
if (file_exists('./inc/models/'.$model.'.class.php') && !array_key_exists($model, $this->models)) //realizowany singleton
|
||||
{
|
||||
require_once('./inc/models/'.$model.'.class.php');
|
||||
$this->models[$model] = new $model($this->db);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception('Could not load selected model: '.$model);
|
||||
}
|
||||
}
|
||||
|
||||
function getModel($model)
|
||||
{
|
||||
if (array_key_exists($model, $this->models))
|
||||
return $this->models[$model];
|
||||
else
|
||||
throw new Exception('Could not get selected model: '.$model);
|
||||
}
|
||||
|
||||
function putExistingModel($model, &$model_ptr)
|
||||
{
|
||||
$this->models[$model] = $model_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
111
inc/bbcode.php
Normal file
111
inc/bbcode.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
function BBCode($content)
|
||||
{
|
||||
$pattern = array(
|
||||
'/\:\)/s', # :)
|
||||
'/\:\|/s', # :|
|
||||
'/\:\(/s', # :(
|
||||
'/\;\(/s', # ;(
|
||||
'/\:D/is', # :D
|
||||
'/\:o/is', # :o
|
||||
'/\;\)/s', # ;)
|
||||
'/\:p/is', # :p
|
||||
'/\:curve:/is', # :curve:
|
||||
'/\:!:/is', # :!:
|
||||
'/\:lol\:/is', # :lol:
|
||||
'/\:evil\:/is', # :evil:
|
||||
'/\:mad\:/is', # :mad:
|
||||
'/\:roll\:/is', # :roll:
|
||||
'/\:cool\:/is', # :cool:
|
||||
'/\:redface\:/is', # :redface:
|
||||
'/\[b\](.*?)\[\/b\]/is', # [b]
|
||||
'/\[i\](.*?)\[\/i\]/is', # [i]
|
||||
'/\[u\](.*?)\[\/u\]/is', # [u]
|
||||
'/\[s\](.*?)\[\/s\]/is', # [s]
|
||||
'/\[center\](.*?)\[\/center\]/is', # [center]
|
||||
'/\[url=((http:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)\](.*?)\[\/url\]/is', # [url=]
|
||||
'/\[url]((http:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)\[\/url\]/is', # [url]
|
||||
'/\[color=#?([A-F0-9]{3}|[A-F0-9]{6})\](.*?)\[\/color\]/is', # [color] (hex)
|
||||
'/\[color=?([A-Z]+)\](.*?)\[\/color\]/is', # [color] (text)
|
||||
'/\[list\](.*?)\[\/list\]/is', # [list]
|
||||
'/\[\*\](.*?)(\n|\r\n)/is', # [*]
|
||||
'/\[quote\](.*?)\[\/quote\]/is', # [quote]
|
||||
'/\[quote=(.+?)\](.*?)\[\/quote\]/is', # [quote=]
|
||||
'/\[code\](.*?)\[\/code\]/is', # [code]
|
||||
'/\\n/', # \n
|
||||
'/\\r/', # \r
|
||||
'/(^|[^"])((http:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
|
||||
|
||||
);
|
||||
|
||||
$replace = array(
|
||||
'<img src="images/smiles/smile.gif" alt=":)">', # :)
|
||||
'<img src="images/smiles/neutral.gif" alt=":|">', # :|
|
||||
'<img src="images/smiles/sad.gif" alt=":(" >', # :(
|
||||
'<img src="images/smiles/cry.png" alt=":(" >', # ;(
|
||||
'<img src="images/smiles/big_smile.gif" alt=":D" >', # :D
|
||||
'<img src="images/smiles/yikes.gif" alt=":o" >', # :o
|
||||
'<img src="images/smiles/wink.gif" alt=";)" >', # ;)
|
||||
'<img src="images/smiles/tongue.gif" alt=":p" >', # :p
|
||||
'<img src="images/smiles/curve.gif" alt=":/" >', # :curve:
|
||||
'<img src="images/smiles/exclaim.gif" alt=":!:" >', # :!:
|
||||
'<img src="images/smiles/lol.gif" alt=":lol:" >', # :lol:
|
||||
'<img src="images/smiles/evil.gif" alt=":evil:" >', # :evil:
|
||||
'<img src="images/smiles/mad.gif" alt=":mad:" >', # :mad:
|
||||
'<img src="images/smiles/roll.gif" alt=":roll:" >', # :roll:
|
||||
'<img src="images/smiles/cool.gif" alt=":cool:" >', # :cool:
|
||||
'<img src="images/smiles/redface.gif" alt=":redface:" >', # :redface:
|
||||
'<span style="font-weight: bold;">\1</span>', # [b]
|
||||
'<span style="font-style: italic;">\1</i>', # [i]
|
||||
'<span style="text-decoration: underline;">\1</span>', # [u]
|
||||
'<span style="text-decoration: line-through;">\1</span>', # [s]
|
||||
'<p style="text-align: center;">\1</p>', # [center]
|
||||
'<a href="\1">\3</a>', # [url=]
|
||||
'<a href="\1">\1</a>', # [url]
|
||||
'<span style="color: #\1;">\2</span>', # [color] (hex)
|
||||
'<span style="color: \1;">\2</span>', # [color] (text)
|
||||
'<ul>\1</ul>', # [list]
|
||||
'<li>\1</li>', # [*]
|
||||
'<div class="qpost"><span style="font-weight: bold">Quote:</span><br>\1</div>', # [quote]
|
||||
'<div class="qpost"><span style="font-weight: bold">\1 wrote:</span><br>\2</div>', # [quote=]
|
||||
'<div class="cpost"><span style="font-weight: bold">Code:</span><br>\1</div>', # [code]
|
||||
'<br>', # \n
|
||||
'', # \r
|
||||
'\\1<a href="\\2">\\2</a>',
|
||||
);
|
||||
|
||||
return preg_replace($pattern, $replace, $content);
|
||||
}
|
||||
|
||||
function StripBBCode($content)
|
||||
{
|
||||
$pattern = array(
|
||||
'/\\n/', # \n
|
||||
'/\\r/', # \r
|
||||
'/\[b\](.*?)\[\/b\]/is', # [b]
|
||||
'/\[i\](.*?)\[\/i\]/is', # [i]
|
||||
'/\[u\](.*?)\[\/u\]/is', # [u]
|
||||
'/\[s\](.*?)\[\/s\]/is', # [s]
|
||||
'/\[url=(.*?)\](.*?)\[\/url\]/is', # [url=]
|
||||
'/\[url](.*?)\[\/url\]/is', # [url]
|
||||
'/\[img](.*?)\[\/img\]/is', # [img]
|
||||
'/\[color=(.*?)\](.*?)\[\/color\]/is', # [color]
|
||||
);
|
||||
|
||||
$replace = array(
|
||||
'', # \n
|
||||
'', # \r
|
||||
'\1', # [b]
|
||||
'\1', # [i]
|
||||
'\1', # [u]
|
||||
'\1', # [s]
|
||||
'\2', # [url=]
|
||||
'\1', # [url]
|
||||
'', # [img]
|
||||
'\2', # [color]
|
||||
);
|
||||
|
||||
return preg_replace($pattern, $replace, $content);
|
||||
}
|
||||
?>
|
||||
35
inc/constants.php
Normal file
35
inc/constants.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
//tables
|
||||
define('BANLIST_TABLE',DB_PREFIX.'banlist');
|
||||
define('CATS_TABLE',DB_PREFIX.'categories');
|
||||
define('CONFIG_TABLE',DB_PREFIX.'config');
|
||||
define('FORUMS_TABLE',DB_PREFIX.'forums');
|
||||
define('POSTS_TABLE',DB_PREFIX.'posts');
|
||||
define('SESSIONS_TABLE',DB_PREFIX.'sessions');
|
||||
define('USERS_TABLE',DB_PREFIX.'users');
|
||||
define('USERS_INFO_TABLE',DB_PREFIX.'users_information');
|
||||
define('TOPICS_TABLE',DB_PREFIX.'topics');
|
||||
|
||||
//views
|
||||
define('FORUMS_VIEW', DB_PREFIX.'view_forums');
|
||||
define('TOPICS_VIEW', DB_PREFIX.'view_topics');
|
||||
define('POSTS_VIEW', DB_PREFIX.'view_posts');
|
||||
define('LOGGED_USERS_VIEW', DB_PREFIX.'view_logged_users');
|
||||
define('USERS_PC_VIEW', DB_PREFIX.'view_users_post_count');
|
||||
define('TOPICS_PC_VIEW', DB_PREFIX.'view_topics_post_count');
|
||||
define('COOKIE_NAME', 'uf2_auth');
|
||||
|
||||
define('RANK_USER', 0);
|
||||
define('RANK_MOD', 1);
|
||||
define('RANK_ADMIN', 2);
|
||||
|
||||
define('POSTING_REPLY', 'reply');
|
||||
define('POSTING_QUOTE', 'quote');
|
||||
define('POSTING_EDIT', 'edit');
|
||||
define('POSTING_NEWTOPIC', 'new_topic');
|
||||
define('POSTING_EDITTOPIC', 'edit_topic');
|
||||
|
||||
|
||||
$allowed_avatars = array('image/jpeg', 'image/gif', 'image/png');
|
||||
?>
|
||||
53
inc/controller.class.php
Normal file
53
inc/controller.class.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/askModel.class.php');
|
||||
|
||||
abstract class Controller extends AskModel {
|
||||
|
||||
protected $views = array();
|
||||
protected $db;
|
||||
|
||||
abstract public function loadDefault(); //domyślna metoda
|
||||
|
||||
public function __call($m, $arg)
|
||||
{
|
||||
if(method_exists($this, $m))
|
||||
$this->$m($arg);
|
||||
else
|
||||
$this->forward('index.php');
|
||||
}
|
||||
|
||||
public function __construct(&$db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function forward($address)
|
||||
{
|
||||
header('Location: ' . $address);
|
||||
}
|
||||
|
||||
|
||||
public function loadView($view)
|
||||
{
|
||||
if (file_exists('./inc/views/'.$view.'.class.php') && !array_key_exists($view, $this->views))
|
||||
{
|
||||
require_once('./inc/views/'.$view.'.class.php');
|
||||
$this->views[$view] = new $view($this->db);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception('Could not load selected view: '.$view);
|
||||
}
|
||||
}
|
||||
|
||||
public function getView($view)
|
||||
{
|
||||
if (array_key_exists($view, $this->views))
|
||||
return $this->views[$view];
|
||||
else
|
||||
throw new Exception('Could not get selected view: '.$widok);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
605
inc/controllers/AdminController.class.php
Normal file
605
inc/controllers/AdminController.class.php
Normal file
@@ -0,0 +1,605 @@
|
||||
<?php
|
||||
|
||||
require ('./inc/controller.class.php');
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
|
||||
public function loadDefault()
|
||||
{
|
||||
$this->main();
|
||||
}
|
||||
|
||||
private function loadDependencies() // zależności (sesje itp)
|
||||
{
|
||||
$this->loadModel('SessionModel'); //aktywacja sesji
|
||||
$this->loadModel('ConfigModel'); //konfiguracja ogólna skryptu
|
||||
$this->loadView('MainView');
|
||||
$this->getView('MainView')->putExistingModel('SessionModel', $this->getModel('SessionModel'));
|
||||
$this->getView('MainView')->putExistingModel('ConfigModel', $this->getModel('ConfigModel'));
|
||||
|
||||
if ($_SERVER['REQUEST_SCHEME'] == 'http')
|
||||
$this->forward('https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
|
||||
|
||||
if (!$this->getModel('SessionModel')->isLogged())
|
||||
{
|
||||
$this->getView('MainView')->forum_message('You are not logged.', 'index.php?mode=login', true);
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
if ($this->getModel('SessionModel')->getRank() == RANK_USER && !isset($lockv))
|
||||
{
|
||||
$this->getView('MainView')->forum_message('You are not admin', 'index.php');
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function main()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->getView('MainView')->admin_main();
|
||||
}
|
||||
}
|
||||
|
||||
public function eduser()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->loadModel('UsersModel');
|
||||
$user_info = $this->getModel('UsersModel')->getUserInformation($_GET['id'], true);
|
||||
|
||||
if ($user_info == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('User does not exist!', 'index.php?mode=admin&submode=users');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$msg = '';
|
||||
if (isset($_POST['nick'], $_POST['passwd'], $_POST['passwd_confirm'], $_POST['email']))
|
||||
{
|
||||
//secure pools
|
||||
$_POST['nick'] = trim(strip_tags($this->db->real_escape_string($_POST['nick'])));
|
||||
$_POST['passwd'] = trim(strip_tags($_POST['passwd']));
|
||||
$_POST['passwd_confirm'] = trim(strip_tags($_POST['passwd_confirm']));
|
||||
$_POST['email'] = trim(strip_tags($this->db->real_escape_string($_POST['email'])));
|
||||
$_POST['location'] = trim(strip_tags($this->db->real_escape_string($_POST['location'])));
|
||||
$_POST['signature'] = trim(strip_tags($this->db->real_escape_string($_POST['signature'])));
|
||||
$_POST['user_rank'] = trim(strip_tags($this->db->real_escape_string($_POST['user_rank'])));
|
||||
|
||||
if ($_POST['passwd'] != '')
|
||||
{
|
||||
if (strlen($_POST['passwd']) < 8)
|
||||
$msg .= 'Password is too short (min 8 characters)<br>';
|
||||
|
||||
if ($_POST['passwd'] != $_POST['passwd_confirm'])
|
||||
$msg .= 'Password do not match!<br>';
|
||||
}
|
||||
|
||||
if ($_GET['id'] == $this->getModel('SessionModel')->getID() && $_POST['user_rank'] != RANK_ADMIN)
|
||||
{
|
||||
$msg .= 'You cannot set rank for your profile<br>';
|
||||
$_POST['user_rank'] = RANK_ADMIN;
|
||||
}
|
||||
|
||||
if ($this->getModel('UsersModel')->nickExists($_POST['nick']) == true && $_POST['nick'] != $user_info['nick'])
|
||||
$msg .= 'Nick is in use. Type another one.<br>';
|
||||
|
||||
if (strlen($_POST['nick']) < 3)
|
||||
$msg .= 'Nick is too short (min 3 characters)<br>';
|
||||
|
||||
if ($_POST['user_rank'] > RANK_ADMIN || $_POST['user_rank'] < RANK_USER)
|
||||
$msg .= 'Rank is not valid!<br>';
|
||||
|
||||
//check if avatar is uploaded
|
||||
if ($_FILES['avatar']['tmp_name'] != null)
|
||||
{
|
||||
global $allowed_avatars;
|
||||
$image_size = @getimagesize($_FILES['avatar']['tmp_name']);
|
||||
|
||||
if ($image_size == null)
|
||||
$msg .= 'Type of uploaded file are not allowed.<br>';
|
||||
else
|
||||
if (!in_array($image_size['mime'], $allowed_avatars))
|
||||
$msg .= 'Type of uploaded avatar is not supported.<br>';
|
||||
else
|
||||
if ($image_size[0] > 120 || $image_size[1] > 150)
|
||||
$msg .= 'Uploaded avatar is too big (maximum 120x150 px).<br>';
|
||||
}
|
||||
|
||||
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
|
||||
$msg .= 'Email is incorrect<br>';
|
||||
|
||||
if ($msg == '')
|
||||
{
|
||||
if ($_FILES['avatar']['tmp_name'] != null && !isset($_POST['delete_avatar'])) //change an avatar
|
||||
{
|
||||
if ($user_info['avatar'] != '')
|
||||
unlink('./'.$user_info['avatar']);
|
||||
|
||||
$ext = pathinfo($_FILES['avatar']['name'], PATHINFO_EXTENSION);
|
||||
$av = 'images/avatars/'.$this->getModel('SessionModel')->getID().'.'.$ext;
|
||||
move_uploaded_file($_FILES['avatar']['tmp_name'], './'.$av);
|
||||
}
|
||||
else
|
||||
if (isset($_POST['delete_avatar']))
|
||||
{
|
||||
unlink('./'.$user_info['avatar']);
|
||||
$av = '';
|
||||
}
|
||||
else
|
||||
$av = $user_info['avatar']; //if new avatar is not set
|
||||
|
||||
if ($_POST['passwd'] != '')
|
||||
$this->getModel('UsersModel')->changeUserPassword($_GET['id'], sha1($_POST['passwd']));
|
||||
|
||||
$this->getModel('UsersModel')->changeUserRank($_GET['id'], $_POST['user_rank']);
|
||||
$this->getModel('UsersModel')->updateUserProfile($_GET['id'], $_POST['nick'], $_POST['email'], $_POST['location'], $_POST['signature'], $av);
|
||||
$this->getView('MainView')->forum_message('User profile has changed.', 'index.php?mode=admin&submode=users');
|
||||
$lockv = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$_POST['nick'] = (isset($_POST['nick'])) ? $_POST['nick'] : $user_info['nick'];
|
||||
$_POST['email'] = (isset($_POST['email'])) ? $_POST['email'] : $user_info['email'];
|
||||
$_POST['location'] = (isset($_POST['location'])) ? $_POST['location'] : $user_info['location'];
|
||||
$_POST['signature'] = (isset($_POST['signature'])) ? $_POST['signature'] : $user_info['signature'];
|
||||
$_POST['user_rank'] = (isset($_POST['user_rank'])) ? $_POST['user_rank'] : $user_info['rank'];
|
||||
|
||||
$this->getView('MainView')->putExistingModel('UsersModel', $this->getModel('UsersModel'));
|
||||
|
||||
if (!isset($lockv))
|
||||
$this->getView('MainView')->edprofile_form($msg, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
if (isset($_GET['rank']))
|
||||
{
|
||||
switch ($_GET['rank'])
|
||||
{
|
||||
case 'admin':
|
||||
$_GET['rank'] = RANK_ADMIN;
|
||||
break;
|
||||
case 'mod':
|
||||
$_GET['rank'] = RANK_MOD;
|
||||
break;
|
||||
case 'user':
|
||||
$_GET['rank'] = RANK_USER;
|
||||
break;
|
||||
default:
|
||||
$_GET['rank'] = '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
$_GET['rank'] = '';
|
||||
|
||||
$_POST['sort_type'] = (isset($_POST['sort_type'])) ? $this->db->real_escape_string($_POST['sort_type']) : 'regdate';
|
||||
$allowed_sorting = array('regdate', 'lastvisit', 'nick', 'post_count');
|
||||
if (!in_array($_POST['sort_type'], $allowed_sorting))
|
||||
$_POST['sort_type'] = '';
|
||||
$_POST['sort_desc'] = (isset($_POST['sort_desc'])) ? 'DESC' : 'ASC';
|
||||
|
||||
$this->getView('MainView')->admin_userlist();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deluser()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->loadModel('UsersModel');
|
||||
$this->getView('MainView')->putExistingModel('UsersModel', $this->getModel('UsersModel'));
|
||||
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
|
||||
$user_info = $this->getModel('UsersModel')->getUserInformation($_GET['id']);
|
||||
if ($user_info == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('User does not exist!', 'index.php?mode=admin&submode=users');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_GET['id'] == $this->getModel('SessionModel')->getID())
|
||||
{
|
||||
$this->getView('MainView')->forum_message('You cannot delete own profile!', 'index.php?mode=admin&submode=users');
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($_POST['confirmed']) && !isset($lockv))
|
||||
{
|
||||
if (!isset($_POST['rejected']))
|
||||
{
|
||||
$this->getModel('UsersModel')->deleteUser($_GET['id']);
|
||||
$this->getView('MainView')->forum_message('Profile deleted. Redirecting to users list...', 'index.php?mode=admin&submode=users');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->forward('index.php?mode=admin&submode=users');
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
$this->getView('MainView')->confirm_action('Do you want delete user <span style="font-weight: bold">'.$user_info['nick'].'</span>? This operation cannot undone.');
|
||||
}
|
||||
}
|
||||
|
||||
public function config()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$msg = '';
|
||||
|
||||
if (isset($_POST['forum_name'], $_POST['forum_desc']))
|
||||
{
|
||||
$_POST['forum_name'] = trim(htmlspecialchars($this->db->real_escape_string($_POST['forum_name'])));
|
||||
$_POST['forum_desc'] = trim(htmlspecialchars($_POST['forum_desc']));
|
||||
|
||||
if (strlen($_POST['forum_name']) < 3)
|
||||
{
|
||||
$msg .= 'Forum name is too short (min 3 characters)!<br>';
|
||||
}
|
||||
|
||||
if (strlen($_POST['forum_name']) > 30)
|
||||
{
|
||||
$msg .= 'Forum name is too long (max 30 characters)!<br>';
|
||||
}
|
||||
|
||||
if (strlen($_POST['forum_desc']) > 50)
|
||||
{
|
||||
$msg .= 'Forum description is too long (max 50 characters)!<br>';
|
||||
}
|
||||
|
||||
if ($msg == '')
|
||||
{
|
||||
$what = '';
|
||||
if ($_POST['forum_name'] != $this->getModel('ConfigModel')->getConf('forum_name'))
|
||||
$this->getModel('ConfigModel')->updateConf('forum_name', $_POST['forum_name']);
|
||||
|
||||
if ($_POST['forum_desc'] != $this->getModel('ConfigModel')->getConf('forum_desc'))
|
||||
$this->getModel('ConfigModel')->updateConf('forum_desc', $_POST['forum_desc']);
|
||||
|
||||
$this->getView('MainView')->forum_message('Forum configuration updated. Redirecting...', 'index.php?mode=admin&submode=config');
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
$_POST['forum_name'] = (isset($_POST['forum_name'])) ? $_POST['forum_name'] : $this->getModel('ConfigModel')->getConf('forum_name');
|
||||
$_POST['forum_desc'] = (isset($_POST['forum_desc'])) ? $_POST['forum_desc'] : $this->getModel('ConfigModel')->getConf('forum_desc');
|
||||
if (!isset($lockv))
|
||||
{
|
||||
$this->getView('MainView')->admin_config($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function forums()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->getView('MainView')->admin_forums();
|
||||
}
|
||||
}
|
||||
|
||||
public function addcat()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->modify_cat('add');
|
||||
}
|
||||
}
|
||||
|
||||
public function edcat()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->modify_cat('edit');
|
||||
}
|
||||
}
|
||||
|
||||
public function addforum()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->modify_forum('add');
|
||||
}
|
||||
}
|
||||
|
||||
public function edforum()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->modify_forum('edit');
|
||||
}
|
||||
}
|
||||
|
||||
public function delforum()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->loadModel('ForumsModel');
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
$forum_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
|
||||
|
||||
if ($forum_info == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Forum does not exist!', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
if (isset($_POST['confirmed']) && !isset($lockv))
|
||||
{
|
||||
if (!isset($_POST['rejected']))
|
||||
{
|
||||
$this->getModel('ForumsModel')->deleteForum($_GET['id']);
|
||||
$this->getView('MainView')->forum_message('Forum deleted. Redirecting...', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
$this->forward('index.php?mode=admin&submode=forums');
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
$this->getView('MainView')->confirm_action('Do you REALLY want delete forum <span style="font-weight: bold">'.$forum_info['name'].'</span> with ALL CONTENT? <span style="text-decoration: underline">This operation cannot undone!</span>');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function delcat()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->loadModel('ForumsModel');
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
$cat_info = $this->getModel('ForumsModel')->getCat($_GET['id']);
|
||||
|
||||
if ($cat_info == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Category does not exist!', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
if (isset($_POST['confirmed']) && !isset($lockv))
|
||||
{
|
||||
if (!isset($_POST['rejected']))
|
||||
{
|
||||
$this->getModel('ForumsModel')->deleteCat($_GET['id']);
|
||||
$this->getView('MainView')->forum_message('Category deleted. Redirecting...', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
$this->forward('index.php?mode=admin&submode=forums');
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
$this->getView('MainView')->confirm_action('Do you REALLY want delete category <span style="font-weight: bold">'.$cat_info['name'].'</span> with ALL FORUMS AND CONTENT? <span style="text-decoration: underline">This operation cannot undone!</span>');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function modify_cat($m)
|
||||
{
|
||||
$msg = '';
|
||||
|
||||
$this->loadModel('ForumsModel');
|
||||
|
||||
if ($m == 'edit')
|
||||
{
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
$cat_info = $this->getModel('ForumsModel')->getCat($_GET['id']);
|
||||
|
||||
if ($cat_info == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Category does not exist!', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($_POST['name']) && !isset($lockv))
|
||||
{
|
||||
$_POST['name'] = trim(htmlspecialchars($this->db->real_escape_string($_POST['name'])));
|
||||
if (strlen($_POST['name']) < 3)
|
||||
$msg .= 'Category name is too short (min 3 characters)!<br>';
|
||||
|
||||
if ($msg == '')
|
||||
{
|
||||
if ($m == 'add')
|
||||
{
|
||||
$this->getModel('ForumsModel')->addCat($_POST['name']);
|
||||
$this->getView('MainView')->forum_message('Category added. Redirecting...', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->getModel('ForumsModel')->changeCat($_GET['id'], $_POST['name']);
|
||||
$this->getView('MainView')->forum_message('Category updated. Redirecting...', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
{
|
||||
if ($m == 'add')
|
||||
$_POST['name'] = (isset($_POST['name'])) ? $_POST['name'] : '';
|
||||
else
|
||||
$_POST['name'] = (isset($_POST['name'])) ? $_POST['name'] : $cat_info['name'];
|
||||
|
||||
$this->getView('MainView')->putExistingModel('ForumsModel', $this->getModel('ForumsModel'));
|
||||
$this->getView('MainView')->admin_cat_form($msg, $m);
|
||||
}
|
||||
}
|
||||
|
||||
private function modify_forum($m)
|
||||
{
|
||||
$msg = '';
|
||||
|
||||
$this->loadModel('ForumsModel');
|
||||
|
||||
if ($m == 'edit')
|
||||
{
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
$forum_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
|
||||
|
||||
if ($forum_info == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Forum does not exist!', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($_POST['name']) && !isset($lockv))
|
||||
{
|
||||
$_POST['name'] = trim(htmlspecialchars($this->db->real_escape_string($_POST['name'])));
|
||||
$_POST['desc'] = trim(htmlspecialchars($this->db->real_escape_string($_POST['desc'])));
|
||||
$_POST['category_id'] = trim(strip_tags($this->db->real_escape_string($_POST['category_id'])));
|
||||
$_POST['locked'] = trim(strip_tags($this->db->real_escape_string($_POST['locked'])));
|
||||
$_POST['locked'] = ($_POST['locked'] == true) ? true : false;
|
||||
|
||||
if (strlen($_POST['name']) < 3)
|
||||
$msg .= 'Forum name is too short (min 3 characters)!<br>';
|
||||
|
||||
$c = $this->getModel('ForumsModel')->getCat($_POST['category_id']);
|
||||
|
||||
if ($c == null)
|
||||
$msg .= 'Category does not exist!<br>';
|
||||
|
||||
if ($msg == '')
|
||||
{
|
||||
if ($m == 'add')
|
||||
{
|
||||
$this->getModel('ForumsModel')->addForum($_POST['name'], $_POST['desc'], $_POST['category_id'], $_POST['locked']);
|
||||
$this->getView('MainView')->forum_message('Forum added. Redirecting...', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->getModel('ForumsModel')->changeForum($_GET['id'], $_POST['name'], $_POST['desc'], $_POST['category_id'], $_POST['locked']);
|
||||
$this->getView('MainView')->forum_message('Forum updated. Redirecting...', 'index.php?mode=admin&submode=forums');
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
{
|
||||
if ($m == 'add')
|
||||
{
|
||||
$_POST['name'] = (isset($_POST['name'])) ? $_POST['name'] : '';
|
||||
$_POST['desc'] = (isset($_POST['desc'])) ? $_POST['desc'] : '';
|
||||
$_POST['category_id'] = (isset($_POST['category_id'])) ? $_POST['category_id'] : '';
|
||||
$_POST['locked'] = (isset($_POST['locked'])) ? $_POST['locked'] : '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$_POST['name'] = (isset($_POST['name'])) ? $_POST['name'] : $forum_info['name'];
|
||||
$_POST['desc'] = (isset($_POST['desc'])) ? $_POST['desc'] : $forum_info['desc'];
|
||||
$_POST['category_id'] = (isset($_POST['category_id'])) ? $_POST['category_id'] : $forum_info['category_id'];
|
||||
$_POST['locked'] = (isset($_POST['locked'])) ? $_POST['locked'] : $forum_info['locked'];
|
||||
}
|
||||
|
||||
$this->getView('MainView')->putExistingModel('ForumsModel', $this->getModel('ForumsModel'));
|
||||
$this->getView('MainView')->admin_forum_form($msg, $m);
|
||||
}
|
||||
}
|
||||
|
||||
public function banlist()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
$this->getView('MainView')->admin_banlist();
|
||||
}
|
||||
|
||||
public function delban()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$this->loadModel('BansModel');
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
$ban_info = $this->getModel('BansModel')->getBan($_GET['id']);
|
||||
|
||||
if ($ban_info == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Ban does not exist!', 'index.php?mode=admin&submode=banlist');
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
if (isset($_POST['confirmed']) && !isset($lockv))
|
||||
{
|
||||
if (!isset($_POST['rejected']))
|
||||
{
|
||||
$this->getModel('BansModel')->deleteBan($_GET['id']);
|
||||
$this->getView('MainView')->forum_message('Ban deleted. Redirecting...', 'index.php?mode=admin&submode=banlist');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
$this->forward('index.php?mode=admin&submode=banlist');
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
$this->getView('MainView')->confirm_action('Do you want delete ban for user <span style="font-weight: bold">'.$ban_info['nick'].'</span>?');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function addban()
|
||||
{
|
||||
if ($this->loadDependencies())
|
||||
{
|
||||
$msg = '';
|
||||
|
||||
$this->loadModel('BansModel');
|
||||
$this->loadModel('UsersModel');
|
||||
|
||||
if (isset($_POST['user_id'], $_POST['reason']))
|
||||
{
|
||||
$_POST['user_id'] = trim(strip_tags($this->db->real_escape_string($_POST['user_id'])));
|
||||
$_POST['reason'] = trim(strip_tags($this->db->real_escape_string($_POST['reason'])));
|
||||
|
||||
if ($_POST['user_id'] == $this->getModel('SessionModel')->getID())
|
||||
$msg .= 'You cannot ban your profile!<br>';
|
||||
|
||||
if ($this->getModel('BansModel')->getUserBan($_POST['user_id']) != null)
|
||||
$msg .= 'This user has already been banned!<br>';
|
||||
|
||||
if ($this->getModel('UsersModel')->getUserInformation($_POST['user_id']) == null)
|
||||
$msg .= 'User does not exist!<br>';
|
||||
|
||||
if ($msg == '')
|
||||
{
|
||||
$this->getModel('BansModel')->addBan($_POST['user_id'], $_POST['reason']);
|
||||
$this->getView('MainView')->forum_message('Ban added. Redirecting...', 'index.php?mode=admin&submode=banlist');
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
{
|
||||
$_POST['user_id'] = (isset($_POST['user_id'])) ? $_POST['user_id'] : '';
|
||||
$_POST['reason'] = (isset($_POST['reason'])) ? $_POST['reason'] : '';
|
||||
|
||||
$this->getView('MainView')->admin_ban_form($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
724
inc/controllers/MainController.class.php
Normal file
724
inc/controllers/MainController.class.php
Normal file
@@ -0,0 +1,724 @@
|
||||
<?php
|
||||
|
||||
require ('./inc/controller.class.php');
|
||||
|
||||
class MainController extends Controller
|
||||
{
|
||||
|
||||
public function loadDefault()
|
||||
{
|
||||
$this->main();
|
||||
}
|
||||
|
||||
private function loadDependencies() // zależności (sesje itp)
|
||||
{
|
||||
$this->loadModel('SessionModel'); //aktywacja sesji
|
||||
$this->loadModel('ConfigModel'); //konfiguracja ogólna skryptu
|
||||
$this->loadView('MainView');
|
||||
$this->getView('MainView')->putExistingModel('SessionModel', $this->getModel('SessionModel'));
|
||||
$this->getView('MainView')->putExistingModel('ConfigModel', $this->getModel('ConfigModel'));
|
||||
}
|
||||
|
||||
public function main()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
|
||||
$this->getView('MainView')->main();
|
||||
}
|
||||
|
||||
public function viewforum()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
|
||||
$this->loadModel('ForumsModel');
|
||||
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
|
||||
$f = $this->getModel('ForumsModel')->getForum($_GET['id']);
|
||||
|
||||
if ($f == null)
|
||||
$this->getView('MainView')->forum_message('Forum does not exist!', 'index.php');
|
||||
else
|
||||
{
|
||||
$this->getView('MainView')->putExistingModel('ForumsModel', $this->getModel('ForumsModel'));
|
||||
$this->getView('MainView')->viewforum();
|
||||
}
|
||||
}
|
||||
|
||||
public function userlist()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
|
||||
if (isset($_GET['rank']))
|
||||
{
|
||||
switch ($_GET['rank'])
|
||||
{
|
||||
case 'admin':
|
||||
$_GET['rank'] = RANK_ADMIN;
|
||||
break;
|
||||
case 'mod':
|
||||
$_GET['rank'] = RANK_MOD;
|
||||
break;
|
||||
case 'user':
|
||||
$_GET['rank'] = RANK_USER;
|
||||
break;
|
||||
default:
|
||||
$_GET['rank'] = '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
$_GET['rank'] = '';
|
||||
|
||||
$_POST['sort_type'] = (isset($_POST['sort_type'])) ? $this->db->real_escape_string($_POST['sort_type']) : 'regdate';
|
||||
$allowed_sorting = array('regdate', 'lastvisit', 'nick', 'post_count');
|
||||
if (!in_array($_POST['sort_type'], $allowed_sorting))
|
||||
$_POST['sort_type'] = '';
|
||||
$_POST['sort_desc'] = (isset($_POST['sort_desc'])) ? 'DESC' : 'ASC';
|
||||
|
||||
$this->getView('MainView')->userlist();
|
||||
|
||||
}
|
||||
|
||||
public function viewtopic()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
|
||||
$this->loadModel('PostsModel');
|
||||
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
|
||||
$t = $this->getModel('PostsModel')->getTopic($_GET['id']);
|
||||
|
||||
if ($t == null)
|
||||
$this->getView('MainView')->forum_message('Topic does not exist!', 'index.php');
|
||||
else
|
||||
{
|
||||
$this->getView('MainView')->putExistingModel('PostsModel', $this->getModel('PostsModel'));
|
||||
$this->getView('MainView')->viewtopic();
|
||||
}
|
||||
}
|
||||
|
||||
public function newtopic()
|
||||
{
|
||||
$this->posting(POSTING_NEWTOPIC);
|
||||
}
|
||||
|
||||
public function reply()
|
||||
{
|
||||
$this->posting(POSTING_REPLY);
|
||||
}
|
||||
|
||||
public function editpost()
|
||||
{
|
||||
$this->posting(POSTING_EDIT);
|
||||
}
|
||||
|
||||
public function quote()
|
||||
{
|
||||
$this->posting(POSTING_QUOTE);
|
||||
}
|
||||
|
||||
public function moderate()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
$this->loadModel('PostsModel');
|
||||
$this->loadModel('ForumsModel');
|
||||
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
$_GET['submode'] = (isset($_GET['submode'])) ? trim(strip_tags($this->db->real_escape_string($_GET['submode']))) : 0;
|
||||
|
||||
if (!$this->getModel('SessionModel')->isLogged())
|
||||
{
|
||||
$this->getView('MainView')->forum_message('You are not logged.', 'index.php?mode=login');
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
if ($this->getModel('SessionModel')->getRank() == RANK_USER && !isset($lockv))
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Only mods have access to this menu', 'index.php');
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
//sprawdź czy wątek/post istnieje
|
||||
|
||||
if (!isset($lockv))
|
||||
switch($_GET['submode'])
|
||||
{
|
||||
case 'deletetopic':
|
||||
case 'locktopic':
|
||||
case 'movetopic':
|
||||
$t = $this->getModel('PostsModel')->getTopic($_GET['id']);
|
||||
|
||||
if ($t == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Topic does not exist!', 'index.php');
|
||||
$lockv = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'deletepost':
|
||||
$p = $this->getModel('PostsModel')->getPost($_GET['id']);
|
||||
if ($p == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Post does not exist!', 'index.php');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = $this->getModel('PostsModel')->getTopic($p['topic_id']);
|
||||
|
||||
if ($t['post_count'] == 1)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('If topic has only one post, use <span style="font-weight: bold">delete topic</span> option.', 'index.php?mode=viewtopic&id='.$p['topic_id'], 3);
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->getView('MainView')->forum_message('Invalid mode', 'index.php');
|
||||
$lockv = true;
|
||||
break;
|
||||
}
|
||||
|
||||
//wysyłanie formularza
|
||||
if (isset($_POST['confirmed']) && !isset($lockv))
|
||||
{
|
||||
if (!isset($_POST['rejected']))
|
||||
{
|
||||
switch($_GET['submode'])
|
||||
{
|
||||
case 'deletepost':
|
||||
$this->getModel('PostsModel')->deletePost($_GET['id']);
|
||||
$this->getView('MainView')->forum_message('Post deleted. Redirecting...', 'index.php?mode=viewtopic&id='.$p['topic_id']);
|
||||
$lockv = true;
|
||||
break;
|
||||
|
||||
case 'deletetopic':
|
||||
$this->getModel('PostsModel')->deleteTopic($_GET['id']);
|
||||
$this->getView('MainView')->forum_message('Topic deleted. Redirecting...', 'index.php?mode=viewforum&id='.$t['forum_id']);
|
||||
$lockv = true;
|
||||
break;
|
||||
|
||||
case 'locktopic':
|
||||
if ($t['topic_locked'] == false)
|
||||
{
|
||||
$this->getModel('PostsModel')->lockTopic($_GET['id']);
|
||||
$this->getView('MainView')->forum_message('Topic locked. Redirecting...', 'index.php?mode=viewtopic&id='.$_GET['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->getModel('PostsModel')->lockTopic($_GET['id'], false);
|
||||
$this->getView('MainView')->forum_message('Topic unlocked. Redirecting...', 'index.php?mode=viewtopic&id='.$_GET['id']);
|
||||
}
|
||||
$lockv = true;
|
||||
break;
|
||||
case 'movetopic':
|
||||
if ($this->getModel('ForumsModel')->getForum($_POST['forum_id']) == null)
|
||||
$this->getView('MainView')->forum_message('Forum does not exist!', 'index.php?mode=viewtopic&id='.$_GET['id']);
|
||||
else
|
||||
{
|
||||
$this->getModel('PostsModel')->moveTopic($_GET['id'], $_POST['forum_id']);
|
||||
$this->getView('MainView')->forum_message('Topic moved. Redirecting...', 'index.php?mode=viewtopic&id='.$_GET['id']);
|
||||
}
|
||||
$lockv = true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($_GET['submode'])
|
||||
{
|
||||
case 'deletetopic':
|
||||
case 'locktopic':
|
||||
case 'movetopic':
|
||||
$this->forward('index.php?mode=viewtopic&id='.$_GET['id']);
|
||||
break;
|
||||
case 'deletepost':
|
||||
$this->forward('index.php?mode=viewtopic&id='.$p['topic_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
switch($_GET['submode'])
|
||||
{
|
||||
case 'deletepost':
|
||||
$this->getView('MainView')->confirm_action('Do you really want delete post <span style="font-weight: bold">#'.$_GET['id'].'</span>?');
|
||||
break;
|
||||
case 'deletetopic':
|
||||
$this->getView('MainView')->confirm_action('Do you really want delete topic <span style="font-weight: bold">#'.$_GET['id'].'</span> with all posts? This operation cannot undone.');
|
||||
break;
|
||||
|
||||
case 'locktopic':
|
||||
if ($t['topic_locked'] == false)
|
||||
$this->getView('MainView')->confirm_action('Do you want lock topic <span style="font-weight: bold">#'.$_GET['id'].'</span>?');
|
||||
else
|
||||
$this->getView('MainView')->confirm_action('Do you want unlock topic <span style="font-weight: bold">#'.$_GET['id'].'</span>?');
|
||||
break;
|
||||
case 'movetopic':
|
||||
$this->getView('MainView')->putExistingModel('PostsModel', $this->getModel('PostsModel'));
|
||||
$this->getView('MainView')->move_topic();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function posting($type)
|
||||
{
|
||||
$this->loadDependencies();
|
||||
$msg = '';
|
||||
|
||||
$this->loadModel('PostsModel');
|
||||
$this->loadModel('ForumsModel');
|
||||
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
|
||||
if (!$this->getModel('SessionModel')->isLogged())
|
||||
{
|
||||
$this->getView('MainView')->forum_message('You are not logged.', 'index.php?mode=login');
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
//SPRAWDZANIE CZY TEMAT/FORUM ISTNIEJE I CZY NIE ZABLOKOWANE
|
||||
if (!isset($lockv))
|
||||
switch($type)
|
||||
{
|
||||
case POSTING_NEWTOPIC: //sprawdzenie czy forum istnieje i czy nie zablokowane
|
||||
$f = $this->getModel('ForumsModel')->getForum($_GET['id']);
|
||||
|
||||
if ($f == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Forum does not exist!', 'index.php');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
if ($f['locked'] == true)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Forum is locked', 'index.php?mode=viewforum&id='.$_GET['id']);
|
||||
$lockv = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case POSTING_REPLY: //sprawdzenie czy temat istnieje
|
||||
case POSTING_QUOTE:
|
||||
$t = $this->getModel('PostsModel')->getTopic($_GET['id']);
|
||||
|
||||
if ($t == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Topic does not exist!', 'index.php');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($t['forum_locked'] == true && $this->getModel('SessionModel')->getRank() < RANK_MOD)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Forum is locked', 'index.php?mode=viewtopic&id='.$t['topic_id']);
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
if ($t['topic_locked'] == true && $this->getModel('SessionModel')->getRank() < RANK_MOD)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Topic is locked', 'index.php?mode=viewtopic&id='.$t['topic_id']);
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
if ($type == POSTING_QUOTE)
|
||||
{
|
||||
$_GET['q'] = (isset($_GET['q'])) ? trim(strip_tags($this->db->real_escape_string($_GET['q']))) : 0;
|
||||
$qp = $this->getModel('PostsModel')->getPost($_GET['q']);
|
||||
|
||||
if ($qp == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Invalid quoted post', 'index.php?mode=viewtopic&id='.$t['topic_id']);
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($qp['topic_id'] != $_GET['id'])
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Invalid quoted post', 'index.php?mode=viewtopic&id='.$t['topic_id']);
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case POSTING_EDIT:
|
||||
$p = $this->getModel('PostsModel')->getPost($_GET['id']);
|
||||
|
||||
if ($p == null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Post does not exist!', 'index.php');
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = $this->getModel('PostsModel')->getTopic($p['topic_id']);
|
||||
if ($t['forum_locked'] == true && $this->getModel('SessionModel')->getRank() < RANK_MOD)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Forum is locked', 'index.php?mode=viewtopic&id='.$t['topic_id']);
|
||||
$lockv = true;
|
||||
}
|
||||
if ($t['topic_locked'] == true && $this->getModel('SessionModel')->getRank() < RANK_MOD)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Topic is locked', 'index.php?mode=viewtopic&id='.$t['topic_id']);
|
||||
$lockv = true;
|
||||
}
|
||||
|
||||
//sprawdzić czy edycja tematu
|
||||
// i ustawić opdowiednie parametry $type = POSTING_EDITTOPIC
|
||||
$first = $this->getModel('PostsModel')->getFirstPost($t['topic_id']);
|
||||
|
||||
if ($first['post_id'] == $_GET['id'])
|
||||
$type = POSTING_EDITTOPIC;
|
||||
|
||||
if ($p['user_id'] != $this->getModel('SessionModel')->getID() && $this->getModel('SessionModel')->getRank() < RANK_MOD)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('You can edit only own posts', 'index.php?mode=viewtopic&id='.$t['topic_id']);
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//przesłanie formularza --------------------------------------------------------------------------------
|
||||
if (isset($_POST['post']) && !isset($_POST['preview']) && !isset($lockv))
|
||||
{
|
||||
$_POST['post'] = trim(htmlspecialchars($this->db->real_escape_string($_POST['post'])));
|
||||
|
||||
if ($type == POSTING_NEWTOPIC || $type == POSTING_EDITTOPIC) //walidacja tytułu tematu (add, edit)
|
||||
{
|
||||
$_POST['topic'] = trim(strip_tags($this->db->real_escape_string($_POST['topic'])));
|
||||
|
||||
if (strlen($_POST['topic']) < 3)
|
||||
$msg .= 'Topic title is too short (min 3 characters)<br>';
|
||||
}
|
||||
|
||||
if (strlen($_POST['post']) < 3)
|
||||
$msg .= 'Post content is too short (min 3 characters)<br>';
|
||||
|
||||
if ($msg == null)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case POSTING_NEWTOPIC: //akcje dodania nowego tematu
|
||||
|
||||
$topic_id = $this->getModel('PostsModel')->addTopic($_POST['topic'], $_POST['post'], $_GET['id'], $this->getModel('SessionModel')->getID());
|
||||
if ($topic_id != null)
|
||||
{
|
||||
$this->getView('MainView')->forum_message('Topic created, Redirecting...', 'index.php?mode=viewtopic&id='.$topic_id);
|
||||
$lockv = true;
|
||||
}
|
||||
else
|
||||
$msg .= 'Something went wrong, try again.';
|
||||
break;
|
||||
case POSTING_EDITTOPIC:
|
||||
case POSTING_EDIT:
|
||||
$this->getModel('PostsModel')->changePost($_GET['id'], $_POST['post']);
|
||||
|
||||
if ($type == POSTING_EDITTOPIC)
|
||||
$this->getModel('PostsModel')->changeTopic($t['topic_id'], $_POST['topic']);
|
||||
|
||||
$this->getView('MainView')->forum_message('Post edited. Redirecting to topic...', 'index.php?mode=viewtopic&id='.$t['topic_id']);
|
||||
$lockv = true;
|
||||
break;
|
||||
|
||||
case POSTING_QUOTE:
|
||||
case POSTING_REPLY:
|
||||
$this->getModel('PostsModel')->addPost($_GET['id'], $this->getModel('SessionModel')->getID(), $_POST['post']);
|
||||
|
||||
$this->getView('MainView')->forum_message('Reply saved. Redirecting to topic...', 'index.php?mode=viewtopic&id='.$_GET['id']);
|
||||
$lockv = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($lockv))
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case POSTING_NEWTOPIC:
|
||||
case POSTING_REPLY:
|
||||
$_POST['post'] = (isset($_POST['post'])) ? $_POST['post'] : '';
|
||||
break;
|
||||
case POSTING_EDITTOPIC:
|
||||
$_POST['post'] = (isset($_POST['post'])) ? $_POST['post'] : $p['content'];
|
||||
$_POST['topic'] = (isset($_POST['topic'])) ? $_POST['topic'] : $t['topic_title'];
|
||||
break;
|
||||
case POSTING_EDIT:
|
||||
$_POST['post'] = (isset($_POST['post'])) ? $_POST['post'] : $p['content'];
|
||||
break;
|
||||
|
||||
case POSTING_QUOTE:
|
||||
$quote = ($qp['nick'] != null) ? '='.$qp['nick'] : '';
|
||||
$_POST['post'] = (isset($_POST['post'])) ? $_POST['post'] : '[quote'.$quote.']'.$qp['content'].'[/quote]';
|
||||
break;
|
||||
|
||||
}
|
||||
if ($type == POSTING_NEWTOPIC)
|
||||
$_POST['topic'] = (isset($_POST['topic'])) ? $_POST['topic'] : ''; //tylko edycja/tworzenie tematu
|
||||
|
||||
$this->getView('MainView')->putExistingModel('PostsModel', $this->getModel('PostsModel'));
|
||||
$this->getView('MainView')->putExistingModel('ForumsModel', $this->getModel('ForumsModel'));
|
||||
|
||||
$this->getView('MainView')->posting_form($type, $msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function myprofile()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
if (!$this->getModel('SessionModel')->isLogged())
|
||||
$this->forward('index.php');
|
||||
else
|
||||
$this->forward('index.php?mode=viewprofile&id='.$this->getModel('SessionModel')->getID());
|
||||
}
|
||||
|
||||
public function viewprofile()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
|
||||
$this->loadModel('UsersModel');
|
||||
$this->getView('MainView')->putExistingModel('UsersModel', $this->getModel('UsersModel'));
|
||||
|
||||
$_GET['id'] = (isset($_GET['id'])) ? trim(strip_tags($this->db->real_escape_string($_GET['id']))) : 0;
|
||||
|
||||
if ($this->getModel('UsersModel')->getUserInformation($_GET['id']) == null)
|
||||
$this->getView('MainView')->forum_message('User does not exist!', 'index.php');
|
||||
else
|
||||
{
|
||||
//$this->getView('MainView')->putExistingModel('PostsModel', $this->getModel('PostsModel'));
|
||||
$this->getView('MainView')->viewprofile();
|
||||
}
|
||||
}
|
||||
|
||||
public function editprofile()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
$this->loadModel('UsersModel');
|
||||
$user_info = $this->getModel('UsersModel')->getUserInformation($this->getModel('SessionModel')->getID(), true);
|
||||
|
||||
if (!$this->getModel('SessionModel')->isLogged())
|
||||
{
|
||||
$this->getView('MainView')->forum_message('You are not logged.', 'index.php?mode=login');
|
||||
}
|
||||
else
|
||||
{
|
||||
$msg = '';
|
||||
if (isset($_POST['nick'], $_POST['passwd'], $_POST['passwd_confirm'], $_POST['email']))
|
||||
{
|
||||
//secure pools
|
||||
$_POST['nick'] = trim(strip_tags($this->db->real_escape_string($_POST['nick'])));
|
||||
$_POST['passwd_old'] = trim(strip_tags($_POST['passwd_old']));
|
||||
$_POST['passwd'] = trim(strip_tags($_POST['passwd']));
|
||||
$_POST['passwd_confirm'] = trim(strip_tags($_POST['passwd_confirm']));
|
||||
$_POST['email'] = trim(strip_tags($this->db->real_escape_string($_POST['email'])));
|
||||
$_POST['location'] = trim(strip_tags($this->db->real_escape_string($_POST['location'])));
|
||||
$_POST['signature'] = trim(strip_tags($this->db->real_escape_string($_POST['signature'])));
|
||||
|
||||
if ($_POST['email'] != $user_info['email'] || $_POST['passwd'] != '')
|
||||
{
|
||||
if (sha1($_POST['passwd_old']) != $user_info['password'])
|
||||
$msg .= 'Old password is incorrect!<br>';
|
||||
}
|
||||
if ($_POST['passwd'] != '')
|
||||
{
|
||||
if (strlen($_POST['passwd']) < 8)
|
||||
$msg .= 'Password is too short (min 8 characters)<br>';
|
||||
|
||||
if ($_POST['passwd'] != $_POST['passwd_confirm'])
|
||||
$msg .= 'Password do not match!<br>';
|
||||
}
|
||||
|
||||
//check if avatar is uploaded
|
||||
if ($_FILES['avatar']['tmp_name'] != null)
|
||||
{
|
||||
global $allowed_avatars;
|
||||
$image_size = @getimagesize($_FILES['avatar']['tmp_name']);
|
||||
|
||||
if ($image_size == null)
|
||||
$msg .= 'Type of uploaded file are not allowed.<br>';
|
||||
else
|
||||
if (!in_array($image_size['mime'], $allowed_avatars))
|
||||
$msg .= 'Type of uploaded avatar is not supported.<br>';
|
||||
else
|
||||
if ($image_size[0] > 120 || $image_size[1] > 150)
|
||||
$msg .= 'Uploaded avatar is too big (maximum 120x150 px).<br>';
|
||||
}
|
||||
|
||||
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
|
||||
$msg .= 'Email is incorrect<br>';
|
||||
|
||||
if ($msg == '')
|
||||
{
|
||||
if ($_FILES['avatar']['tmp_name'] != null && !isset($_POST['delete_avatar'])) //change an avatar
|
||||
{
|
||||
if ($user_info['avatar'] != '')
|
||||
unlink('./'.$user_info['avatar']);
|
||||
|
||||
$ext = pathinfo($_FILES['avatar']['name'], PATHINFO_EXTENSION);
|
||||
$av = 'images/avatars/'.$this->getModel('SessionModel')->getID().'.'.$ext;
|
||||
move_uploaded_file($_FILES['avatar']['tmp_name'], './'.$av);
|
||||
}
|
||||
else
|
||||
if (isset($_POST['delete_avatar']))
|
||||
{
|
||||
unlink('./'.$user_info['avatar']);
|
||||
$av = '';
|
||||
}
|
||||
else
|
||||
$av = $user_info['avatar']; //if new avatar is not set
|
||||
|
||||
if ($_POST['passwd'] != '')
|
||||
$this->getModel('UsersModel')->changeUserPassword($this->getModel('SessionModel')->getID(), sha1($_POST['passwd']));
|
||||
|
||||
$this->getModel('UsersModel')->updateUserProfile($this->getModel('SessionModel')->getID(), '', $_POST['email'], $_POST['location'], $_POST['signature'], $av);
|
||||
$this->getView('MainView')->forum_message('Your profile has changed.', 'index.php?mode=viewprofile&id='.$this->getModel('SessionModel')->getID());
|
||||
$lockv = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$_POST['nick'] = (isset($_POST['nick'])) ? $_POST['nick'] : $user_info['nick'];
|
||||
$_POST['email'] = (isset($_POST['email'])) ? $_POST['email'] : $user_info['email'];
|
||||
$_POST['location'] = (isset($_POST['location'])) ? $_POST['location'] : $user_info['location'];
|
||||
$_POST['signature'] = (isset($_POST['signature'])) ? $_POST['signature'] : $user_info['signature'];
|
||||
|
||||
$this->getView('MainView')->putExistingModel('UsersModel', $this->getModel('UsersModel'));
|
||||
|
||||
if (!isset($lockv))
|
||||
$this->getView('MainView')->edprofile_form($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
|
||||
if (!$this->getModel('SessionModel')->isLogged())
|
||||
$this->forward('index.php');
|
||||
|
||||
$this->getModel('SessionModel')->deleteSession();
|
||||
|
||||
$this->getView('MainView')->forum_message('You are logged out.', 'index.php');
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
$this->loadModel('BansModel');
|
||||
|
||||
if ($_SERVER['REQUEST_SCHEME'] == 'http')
|
||||
$this->forward('https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
|
||||
|
||||
if ($this->getModel('SessionModel')->isLogged())
|
||||
$this->forward('index.php');
|
||||
|
||||
$msg = '';
|
||||
if (isset($_POST['nick'], $_POST['passwd']))
|
||||
{
|
||||
//secure pools
|
||||
$_POST['nick'] = trim(strip_tags($this->db->real_escape_string($_POST['nick'])));
|
||||
$_POST['passwd'] = sha1(trim(strip_tags($this->db->real_escape_string($_POST['passwd']))));
|
||||
|
||||
$userinfo = $this->getModel('SessionModel')->tryGetUser($_POST['nick'], $_POST['passwd']);
|
||||
|
||||
if (count($userinfo) == 0)
|
||||
$msg = 'Invalid username or password.';
|
||||
|
||||
if ($msg == '')
|
||||
{
|
||||
$ban_info = $this->getModel('BansModel')->getUserBan($userinfo['user_id']);
|
||||
|
||||
if ($ban_info == null)
|
||||
{
|
||||
$this->getModel('SessionModel')->registerNewSession($userinfo['user_id']);
|
||||
$this->getView('MainView')->forum_message('You are logged as: <span style="font-weight: bold">'.$userinfo['nick'].'</span>', 'index.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$reason = ($ban_info['reason'] != '') ? '<br>Reason: <span style="font-style: italic">'.$ban_info['reason'].'</span>' : '';
|
||||
$this->getView('MainView')->forum_message('You are banned!'.$reason);
|
||||
}
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
$_POST['nick'] = (isset($_POST['nick'])) ? $_POST['nick'] : '';
|
||||
if (!isset($lockv))
|
||||
$this->getView('MainView')->login_form($msg);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
$this->loadDependencies();
|
||||
$this->loadModel('UsersModel');
|
||||
|
||||
if ($this->getModel('SessionModel')->isLogged())
|
||||
$this->forward('index.php');
|
||||
|
||||
if ($_SERVER['REQUEST_SCHEME'] == 'http')
|
||||
$this->forward('https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
|
||||
|
||||
$msg = '';
|
||||
if (isset($_POST['nick'], $_POST['passwd'], $_POST['passwd_confirm'], $_POST['email']))
|
||||
{
|
||||
//secure pools
|
||||
$_POST['nick'] = trim(strip_tags($this->db->real_escape_string($_POST['nick'])));
|
||||
$_POST['passwd'] = trim(strip_tags($_POST['passwd']));
|
||||
$_POST['passwd_confirm'] = trim(strip_tags($_POST['passwd_confirm']));
|
||||
$_POST['email'] = trim(strip_tags($this->db->real_escape_string($_POST['email'])));
|
||||
|
||||
if (strlen($_POST['nick']) < 3)
|
||||
$msg .= 'Nick is too short (min 3 characters)<br>';
|
||||
|
||||
if (strlen($_POST['passwd']) < 8)
|
||||
$msg .= 'Password is too short (min 8 characters)<br>';
|
||||
|
||||
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
|
||||
$msg .= 'Email is incorrect<br>';
|
||||
|
||||
if ($this->getModel('UsersModel')->nickExists($_POST['nick']) == true)
|
||||
$msg .= 'Nick is in use. Type another one.<br>';
|
||||
|
||||
if ($_POST['passwd'] != $_POST['passwd_confirm'])
|
||||
$msg .= 'Password do not match';
|
||||
|
||||
if ($msg == '')
|
||||
{
|
||||
$this->getModel('UsersModel')->createNewUser($_POST['nick'], sha1($_POST['passwd']), $_POST['email']);
|
||||
$this->getView('MainView')->forum_message('Your account has created. Log in to write new posts.', 'index.php');
|
||||
$lockv = true;
|
||||
}
|
||||
}
|
||||
|
||||
$_POST['nick'] = (isset($_POST['nick'])) ? $_POST['nick'] : '';
|
||||
$_POST['email'] = (isset($_POST['email'])) ? $_POST['email'] : '';
|
||||
|
||||
if (!isset($lockv))
|
||||
$this->getView('MainView')->register_form($msg);
|
||||
}
|
||||
|
||||
public function checknick()
|
||||
{
|
||||
$this->loadModel('UsersModel');
|
||||
if (!isset($_GET['nick']))
|
||||
$_GET['nick'] = '';
|
||||
|
||||
$_GET['nick'] = trim($this->db->real_escape_string(strip_tags($_GET['nick'])));
|
||||
|
||||
if ($this->getModel('UsersModel')->nickExists($_GET['nick']) == true)
|
||||
echo 'true';
|
||||
else
|
||||
echo 'false';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
6
inc/database_connection.php
Normal file
6
inc/database_connection.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
$DB = new MySQLi(DB_HOST, DB_USER, DB_PASSWD, DB_NAME);
|
||||
|
||||
$DB->query("SET NAMES `utf8`");
|
||||
?>
|
||||
5
inc/misc_functions.php
Normal file
5
inc/misc_functions.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
?>
|
||||
56
inc/model.class.php
Normal file
56
inc/model.class.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/askModel.class.php');
|
||||
|
||||
abstract class Model extends AskModel
|
||||
{
|
||||
protected $db;
|
||||
|
||||
function __construct(&$db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function select($table, $what='*', $where = '', $sorting = '', $limit = '')
|
||||
{
|
||||
$sql="SELECT $what FROM $table";
|
||||
|
||||
if ($where != '')
|
||||
$sql .= " WHERE $where";
|
||||
|
||||
if($sorting != '')
|
||||
$sql .= " ORDER BY $sorting";
|
||||
|
||||
if($limit != '')
|
||||
$sql .= " LIMIT $limit";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
$out = array();
|
||||
if ($result->num_rows > 0)
|
||||
{
|
||||
while ($row = $result->fetch_assoc())
|
||||
{
|
||||
$out[]=$row;
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function select_query($sql)
|
||||
{
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
$out = array();
|
||||
if ($result->num_rows > 0)
|
||||
{
|
||||
while ($row = $result->fetch_assoc())
|
||||
{
|
||||
$out[]=$row;
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
64
inc/models/BansModel.class.php
Normal file
64
inc/models/BansModel.class.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/model.class.php');
|
||||
|
||||
class BansModel extends Model
|
||||
{
|
||||
private $ban_info = null;
|
||||
public function getBans()
|
||||
{
|
||||
$query = 'SELECT b.ban_id as ban_id, b.user_id as user_id, u.nick as nick, b.reason as reason
|
||||
FROM '.BANLIST_TABLE.' b
|
||||
LEFT JOIN '.USERS_TABLE.' u ON u.user_id = b.user_id';
|
||||
|
||||
return $this->select_query($query);
|
||||
}
|
||||
|
||||
public function getBan($ban_id)
|
||||
{
|
||||
if ($this->ban_info == null)
|
||||
{
|
||||
$query = 'SELECT b.ban_id as ban_id, b.user_id as user_id, u.nick as nick, b.reason as reason
|
||||
FROM '.BANLIST_TABLE.' b
|
||||
LEFT JOIN '.USERS_TABLE.' u ON u.user_id = b.user_id
|
||||
WHERE `ban_id`=\''.$ban_id.'\'';
|
||||
|
||||
$out = $this->select_query($query);
|
||||
|
||||
if (count($out) > 0)
|
||||
$this->ban_info = $out[0];
|
||||
}
|
||||
|
||||
return $this->ban_info;
|
||||
}
|
||||
|
||||
public function getUserBan($user_id)
|
||||
{
|
||||
$out = $this->select(BANLIST_TABLE, '*', 'user_id=\''.$user_id.'\'');
|
||||
|
||||
if (count($out) > 0)
|
||||
return $out[0];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addBan($user_id, $reason)
|
||||
{
|
||||
$query = 'INSERT INTO '.BANLIST_TABLE.'
|
||||
(`ban_id`, `user_id`, `reason`)
|
||||
VALUES (NULL, \''.$user_id.'\', \''.$reason.'\')';
|
||||
|
||||
$this->db->query($query);
|
||||
|
||||
$query = 'DELETE FROM '.SESSIONS_TABLE.' WHERE `user_id`=\''.$user_id.'\'';
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function deleteBan($ban_id)
|
||||
{
|
||||
$query = 'DELETE FROM '.BANLIST_TABLE.' WHERE `ban_id`=\''.$ban_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
}
|
||||
?>
|
||||
38
inc/models/ConfigModel.class.php
Normal file
38
inc/models/ConfigModel.class.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/model.class.php');
|
||||
|
||||
class ConfigModel extends Model
|
||||
{
|
||||
private $confList = array();
|
||||
|
||||
public function __construct(&$db)
|
||||
{
|
||||
$this->db = $db;
|
||||
|
||||
$result = $this->select (CONFIG_TABLE);
|
||||
|
||||
for ($i=0; $i<count($result); $i++)
|
||||
$this->confList[$result[$i]['name']] = $result[$i]['value'];
|
||||
|
||||
}
|
||||
|
||||
public function getConf($name)
|
||||
{
|
||||
if (isset($this->confList[$name]))
|
||||
return $this->confList[$name];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function updateConf($name, $value)
|
||||
{
|
||||
$query = 'UPDATE '.CONFIG_TABLE.'
|
||||
SET `value`=\''.$value.'\'
|
||||
WHERE `name`=\''.$name.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
119
inc/models/ForumsModel.class.php
Normal file
119
inc/models/ForumsModel.class.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/model.class.php');
|
||||
|
||||
class ForumsModel extends Model
|
||||
{
|
||||
private $forum_info = null;
|
||||
private $cat_info = null;
|
||||
public function getForums()
|
||||
{
|
||||
return $this->select (FORUMS_VIEW);
|
||||
}
|
||||
|
||||
public function getCats()
|
||||
{
|
||||
return $this->select (CATS_TABLE);
|
||||
}
|
||||
|
||||
public function getForumsNames()
|
||||
{
|
||||
$out = $this->select (FORUMS_TABLE, 'forum_id, name', '', 'forum_id ASC');
|
||||
if (count($out) > 0)
|
||||
return $out;
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getForum($forum_id)
|
||||
{
|
||||
if ($this->forum_info == null)
|
||||
{
|
||||
$out = $this->select(FORUMS_TABLE, '*', 'forum_id=\''.$forum_id.'\'');
|
||||
|
||||
if (count($out) > 0)
|
||||
$this->forum_info = $out[0];
|
||||
}
|
||||
|
||||
return $this->forum_info;
|
||||
}
|
||||
|
||||
public function getTopics($forum_id)
|
||||
{
|
||||
$out = $this->select(TOPICS_VIEW, '*', 'forum_id=\''.$forum_id.'\'', 'lastpost_post_id DESC');
|
||||
if (count($out) > 0)
|
||||
return $out;
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getCat($cat_id)
|
||||
{
|
||||
if ($this->cat_info == null)
|
||||
{
|
||||
$out = $this->select(CATS_TABLE, '*', 'category_id=\''.$cat_id.'\'');
|
||||
|
||||
if (count($out) > 0)
|
||||
$this->cat_info = $out[0];
|
||||
}
|
||||
|
||||
return $this->cat_info;
|
||||
}
|
||||
|
||||
public function changeCat($cat_id, $cat_name)
|
||||
{
|
||||
$query = 'UPDATE '.CATS_TABLE.'
|
||||
SET `name`=\''.$cat_name.'\'
|
||||
WHERE `category_id`=\''.$cat_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function addCat($cat_name)
|
||||
{
|
||||
$query = 'INSERT INTO '.CATS_TABLE.'
|
||||
(category_id, name)
|
||||
VALUES (NULL, \''.$cat_name.'\')';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function deleteCat($cat_id)
|
||||
{
|
||||
$query = 'DELETE FROM '.CATS_TABLE.'
|
||||
WHERE `category_id`=\''.$cat_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function changeForum($forum_id, $forum_name, $forum_desc, $forum_category_id, $forum_locked)
|
||||
{
|
||||
$query = 'UPDATE '.FORUMS_TABLE.'
|
||||
SET `name`=\''.$forum_name.'\',
|
||||
`desc`=\''.$forum_desc.'\',
|
||||
`category_id`=\''.$forum_category_id.'\',
|
||||
`locked`=\''.$forum_locked.'\'
|
||||
WHERE `forum_id`=\''.$forum_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function addForum($forum_name, $forum_desc, $forum_category_id, $forum_locked)
|
||||
{
|
||||
$query = 'INSERT INTO '.FORUMS_TABLE.'
|
||||
(`forum_id`, `name`, `desc`, `category_id`, `locked`)
|
||||
VALUES (NULL, \''.$forum_name.'\', \''.$forum_desc.'\', \''.$forum_category_id.'\', \''.$forum_locked.'\')';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function deleteForum($forum_id)
|
||||
{
|
||||
$query = 'DELETE FROM '.FORUMS_TABLE.'
|
||||
WHERE `forum_id`=\''.$forum_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
43
inc/models/NavigationModel.class.php
Normal file
43
inc/models/NavigationModel.class.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/model.class.php');
|
||||
|
||||
class NavigationModel extends Model
|
||||
{
|
||||
private $linksList = array();
|
||||
private $title = '';
|
||||
|
||||
public function setForumName($fn)
|
||||
{
|
||||
$this->addLink('Forum '.$fn, 'index.php');
|
||||
$this->title = $fn. ' • ';
|
||||
}
|
||||
public function addLink($name, $url = '')
|
||||
{
|
||||
if ($url == null)
|
||||
$url = $_SERVER['REQUEST_URI'];
|
||||
$l = array(
|
||||
'name' => $name,
|
||||
'url' => $url
|
||||
);
|
||||
|
||||
array_push($this->linksList, $l);
|
||||
}
|
||||
|
||||
public function setSubTitle($t)
|
||||
{
|
||||
$this->title .= $t;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getNav()
|
||||
{
|
||||
return $this->linksList;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
126
inc/models/PostsModel.class.php
Normal file
126
inc/models/PostsModel.class.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/model.class.php');
|
||||
|
||||
class PostsModel extends Model
|
||||
{
|
||||
private $topic_info = null;
|
||||
private $post_info = null;
|
||||
|
||||
public function getTopic($topic_id)
|
||||
{
|
||||
if ($this->topic_info == null)
|
||||
{
|
||||
$query = '
|
||||
SELECT
|
||||
t.topic_id as topic_id, t.title as topic_title, t.locked as topic_locked, t.forum_id as forum_id, f.name as forum_name, f.locked as forum_locked, pc.post_count as post_count
|
||||
FROM '.TOPICS_TABLE.' t
|
||||
LEFT JOIN '.FORUMS_TABLE.' f ON f.forum_id = t.forum_id
|
||||
LEFT JOIN '.TOPICS_PC_VIEW.' pc ON pc.topic_id = t.topic_id
|
||||
WHERE t.topic_id=\''.$topic_id.'\'';
|
||||
$out = $this->select_query($query);
|
||||
if (count($out) > 0)
|
||||
$this->topic_info = $out[0];
|
||||
}
|
||||
|
||||
return $this->topic_info;
|
||||
}
|
||||
|
||||
public function getPosts($topic_id)
|
||||
{
|
||||
$out = $this->select (POSTS_VIEW, '*', 'topic_id=\''.$topic_id.'\'', 'post_id ASC');
|
||||
|
||||
if ($out != null)
|
||||
return $out;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPost($post_id)
|
||||
{
|
||||
$out = $this->select (POSTS_VIEW, '*', 'post_id=\''.$post_id.'\'');
|
||||
|
||||
if (count($out) > 0)
|
||||
return $out[0];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getFirstPost($topic_id)
|
||||
{
|
||||
$out = $this->select (POSTS_VIEW, 'post_id', 'topic_id=\''.$topic_id.'\'', 'post_id ASC', 1);
|
||||
|
||||
if (count($out) > 0)
|
||||
return $out[0];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
//mod options
|
||||
public function deletePost($post_id)
|
||||
{
|
||||
$query = 'DELETE FROM '.POSTS_TABLE.' WHERE post_id=\''.$post_id.'\';';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function deleteTopic($topic_id)
|
||||
{
|
||||
$query = 'call delete_topic(\''.$topic_id.'\');';
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function lockTopic($topic_id, $locked = true)
|
||||
{
|
||||
$query = 'UPDATE '.TOPICS_TABLE.' SET locked=\''.$locked.'\' WHERE topic_id=\''.$topic_id.'\';';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function moveTopic($topic_id, $forum_id)
|
||||
{
|
||||
$query = 'UPDATE '.TOPICS_TABLE.' SET forum_id=\''.$forum_id.'\' WHERE topic_id=\''.$topic_id.'\';';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function addTopic($title, $content, $forum_id, $user_id)
|
||||
{
|
||||
$query = 'call add_topic(\''.$title.'\',
|
||||
\''.$content.'\',
|
||||
\''.$forum_id.'\',
|
||||
\''.$user_id.'\',
|
||||
\''.$_SERVER['HTTP_USER_AGENT'].'\',
|
||||
@out);';
|
||||
$this->db->query($query);
|
||||
$result = $this->db->query('select @out as topic_id');
|
||||
|
||||
if ($result != null)
|
||||
return $result->fetch_assoc()['topic_id'];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function changePost($post_id, $content)
|
||||
{
|
||||
$query = 'UPDATE '.POSTS_TABLE.' SET `content`=\''.$content.'\' WHERE `post_id`=\''.$post_id.'\'';
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function changeTopic($topic_id, $title)
|
||||
{
|
||||
$query = 'UPDATE '.TOPICS_TABLE.' SET `title`=\''.$title.'\' WHERE `topic_id`=\''.$topic_id.'\'';
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function addPost($topic_id, $user_id, $content)
|
||||
{
|
||||
$query = 'INSERT INTO '.POSTS_TABLE.'
|
||||
(post_id, topic_id, user_id, content, date, user_agent)
|
||||
VALUES
|
||||
(NULL, \''.$topic_id.'\', \''.$user_id.'\', \''.$content.'\', NOW(), \''.$_SERVER['HTTP_USER_AGENT'].'\')';
|
||||
$this->db->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
125
inc/models/SessionModel.class.php
Normal file
125
inc/models/SessionModel.class.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/model.class.php');
|
||||
|
||||
class SessionModel extends Model
|
||||
{
|
||||
private $userdata = array();
|
||||
|
||||
public function __construct(&$db)
|
||||
{
|
||||
$this->db = $db;
|
||||
|
||||
if (isset($_COOKIE[COOKIE_NAME]))
|
||||
{
|
||||
$result = $this->select(SESSIONS_TABLE, '*', 'session_id=\''.$_COOKIE[COOKIE_NAME].'\' AND expiry_time>=NOW()');
|
||||
if (count($result) > 0)
|
||||
{
|
||||
//update session expiry time in database and in cookie
|
||||
if ($result[0]['IP'] != $_SERVER['REMOTE_ADDR'])
|
||||
{
|
||||
$this->deleteSession();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->updateSession();
|
||||
$uid = $result[0]['user_id'];
|
||||
|
||||
$result = $this->select(USERS_TABLE, 'user_id, nick, rank', 'user_id=\''.$uid.'\'');
|
||||
$this->userdata = $result[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->deleteSession();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSession()
|
||||
{
|
||||
/*$this->db->query('UPDATE '.SESSIONS_TABLE.' SET expiry_time=(NOW() + INTERVAL 120 MINUTE) WHERE session_id=\''.$_COOKIE[COOKIE_NAME].'\'');
|
||||
setcookie(COOKIE_NAME, $_COOKIE[COOKIE_NAME], $_SERVER['REQUEST_TIME']+7200, COOKIE_PATH, COOKIE_DOMAIN, false, true); */
|
||||
$newid = $this->generateSessionID();
|
||||
$this->db->query('UPDATE '.SESSIONS_TABLE.' SET expiry_time=(NOW() + INTERVAL 120 MINUTE), session_id=\''.$newid.'\' WHERE session_id=\''.$_COOKIE[COOKIE_NAME].'\'');
|
||||
setcookie(COOKIE_NAME, $newid, $_SERVER['REQUEST_TIME']+7200, COOKIE_PATH, COOKIE_DOMAIN, false, true);
|
||||
$_COOKIE[COOKIE_NAME] = $newid;
|
||||
}
|
||||
|
||||
public function deleteSession()
|
||||
{
|
||||
setcookie(COOKIE_NAME, '', $_SERVER['REQUEST_TIME']-3600, COOKIE_PATH, COOKIE_DOMAIN, false, true);
|
||||
$this->db->query('DELETE FROM '.SESSIONS_TABLE.' WHERE session_id=\''.$_COOKIE[COOKIE_NAME].'\'');
|
||||
}
|
||||
|
||||
private function generateSessionID()
|
||||
{
|
||||
$out = $_SERVER['HTTP_USER_AGENT'].$_SERVER['REQUEST_TIME_FLOAT'].$_SERVER['REMOTE_ADDR'].rand(1, 50000);
|
||||
return md5($out);
|
||||
}
|
||||
|
||||
public function registerNewSession($user_id)
|
||||
{
|
||||
$newID = $this->generateSessionID();
|
||||
$query = 'UPDATE '.USERS_INFO_TABLE.'
|
||||
SET lastvisit=NOW()
|
||||
WHERE user_id=\''.$user_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
|
||||
$query =
|
||||
'INSERT INTO
|
||||
'.SESSIONS_TABLE.'
|
||||
(session_id, user_id, IP, expiry_time)
|
||||
VALUES
|
||||
(\''.$newID.'\', \''.$user_id.'\', \''.$_SERVER['REMOTE_ADDR'].'\', (NOW() + INTERVAL 120 MINUTE) );';
|
||||
|
||||
$this->db->query($query);
|
||||
|
||||
setcookie(COOKIE_NAME, $newID, $_SERVER['REQUEST_TIME']+7200, COOKIE_PATH, COOKIE_DOMAIN, false, true);
|
||||
}
|
||||
|
||||
public function tryGetUser($nick, $passwd)
|
||||
{
|
||||
$result = $this->select(USERS_TABLE, 'user_id, nick', 'nick=\''.$nick.'\' AND password=\''.$passwd.'\'', '', 1);
|
||||
|
||||
if (count($result) > 0 )
|
||||
return $result[0];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
public function isLogged()
|
||||
{
|
||||
if (count($this->userdata) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getNick()
|
||||
{
|
||||
if ($this->isLogged())
|
||||
return $this->userdata['nick'];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRank()
|
||||
{
|
||||
if ($this->isLogged())
|
||||
return $this->userdata['rank'];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
if ($this->isLogged())
|
||||
return $this->userdata['user_id'];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
56
inc/models/StatisticsModel.class.php
Normal file
56
inc/models/StatisticsModel.class.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/model.class.php');
|
||||
|
||||
class StatisticsModel extends Model
|
||||
{
|
||||
private $logged_users = null;
|
||||
|
||||
public function getPostsCount()
|
||||
{
|
||||
$out = $this->select(POSTS_TABLE, 'count(post_id) AS posts_count');
|
||||
return $out[0]['posts_count'];
|
||||
}
|
||||
|
||||
public function getTopicsCount()
|
||||
{
|
||||
$out = $this->select(TOPICS_TABLE, 'count(topic_id) AS topics_count');
|
||||
return $out[0]['topics_count'];
|
||||
}
|
||||
|
||||
public function getUsersCount()
|
||||
{
|
||||
$out = $this->select(USERS_TABLE, 'count(user_id) AS users_count');
|
||||
return $out[0]['users_count'];
|
||||
}
|
||||
|
||||
public function getLastRegisteredUser()
|
||||
{
|
||||
$out = $this->select(USERS_TABLE, 'user_id, nick, rank', '', 'user_id DESC', '1');
|
||||
return $out[0];
|
||||
}
|
||||
|
||||
private function retrieveLoggedUsers()
|
||||
{
|
||||
if ($this->logged_users == null)
|
||||
{
|
||||
$this->logged_users = $this->select(LOGGED_USERS_VIEW);
|
||||
}
|
||||
}
|
||||
|
||||
public function getLoggedUsersCount()
|
||||
{
|
||||
$this->retrieveLoggedUsers();
|
||||
|
||||
return count($this->logged_users);
|
||||
}
|
||||
|
||||
public function getLoggedUsers()
|
||||
{
|
||||
$this->retrieveLoggedUsers();
|
||||
|
||||
return $this->logged_users;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
128
inc/models/UsersModel.class.php
Normal file
128
inc/models/UsersModel.class.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/model.class.php');
|
||||
|
||||
class UsersModel extends Model
|
||||
{
|
||||
private $user_info = null;
|
||||
|
||||
public function nickExists($nick)
|
||||
{
|
||||
$out = $this->select(USERS_TABLE, 'nick', '`nick`=\''.$nick.'\'', '', 1);
|
||||
if (count($out) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function createNewUser($nick, $passwd, $email)
|
||||
{
|
||||
$this->db->query('call add_user(\''.$nick.'\', \''.$passwd.'\', \''.$email.'\');');
|
||||
}
|
||||
|
||||
public function getUsersNicks()
|
||||
{
|
||||
$out = $this->select (USERS_TABLE, 'user_id, nick', '', 'user_id ASC');
|
||||
if (count($out) > 0)
|
||||
return $out;
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getUserInformation($user_id, $passwd = false)
|
||||
{
|
||||
if ($this->user_info == null)
|
||||
{
|
||||
$query = '
|
||||
SELECT
|
||||
u.nick as nick, u.email as email, u.rank as rank, u.active as active,
|
||||
ui.regdate as regdate, ui.lastvisit as lastvisit, ui.avatar as avatar, ui.location as location, ui.signature as signature, pc.post_count as post_count, lu.IP as user_IP ';
|
||||
if ($passwd)
|
||||
$query .= ',u.password as password ';
|
||||
$query .= '
|
||||
FROM '.USERS_TABLE.' u
|
||||
LEFT JOIN '.USERS_INFO_TABLE.' ui on ui.user_id = u.user_id
|
||||
LEFT JOIN '.USERS_PC_VIEW.' pc on pc.user_id = u.user_id
|
||||
LEFT JOIN '.LOGGED_USERS_VIEW.' lu on lu.user_id = u.user_id
|
||||
WHERE u.user_id = \''.$user_id.'\'';
|
||||
|
||||
$out = $this->select_query($query);
|
||||
if (count($out) > 0)
|
||||
$this->user_info = $out[0];
|
||||
}
|
||||
|
||||
return $this->user_info;
|
||||
}
|
||||
|
||||
public function changeUserPassword($user_id, $passwd)
|
||||
{
|
||||
$query =
|
||||
'UPDATE .'.USERS_TABLE.'
|
||||
SET `password`=\''.$passwd.'\'
|
||||
WHERE `user_id` = \''.$user_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function changeUserRank($user_id, $rank)
|
||||
{
|
||||
$query =
|
||||
'UPDATE .'.USERS_TABLE.'
|
||||
SET `rank`=\''.$rank.'\'
|
||||
WHERE `user_id` = \''.$user_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function updateUserProfile($user_id, $nick, $email, $location, $signature, $avatar)
|
||||
{
|
||||
$query =
|
||||
'UPDATE .'.USERS_TABLE.'
|
||||
SET ';
|
||||
if ($nick != null)
|
||||
$query .= '`nick`=\''.$nick.'\',';
|
||||
$query .= '`email`=\''.$email.'\'
|
||||
WHERE `user_id` = \''.$user_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
|
||||
//profile informations
|
||||
$query =
|
||||
'UPDATE .'.USERS_INFO_TABLE.'
|
||||
SET
|
||||
`avatar`=\''.$avatar.'\',
|
||||
`location`=\''.$location.'\',
|
||||
`signature`=\''.$signature.'\'
|
||||
WHERE `user_id` = \''.$user_id.'\'';
|
||||
|
||||
$this->db->query($query);
|
||||
}
|
||||
|
||||
public function getUsers($stype, $sorder, $rank)
|
||||
{
|
||||
$query = '
|
||||
SELECT
|
||||
u.user_id as user_id, u.nick as nick, u.rank as rank, ui.regdate as regdate, ui.lastvisit as lastvisit, pc.post_count as post_count
|
||||
FROM '.USERS_TABLE.' u
|
||||
LEFT JOIN '.USERS_INFO_TABLE.' ui on ui.user_id = u.user_id
|
||||
LEFT JOIN '.USERS_PC_VIEW.' pc on pc.user_id = u.user_id ';
|
||||
if ($rank !== '')
|
||||
$query .= 'WHERE rank=\''.$rank.'\'';
|
||||
$query .= '
|
||||
ORDER BY '.$stype.' '.$sorder;
|
||||
|
||||
$out = $this->select_query($query);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function deleteUser($user_id)
|
||||
{
|
||||
$query =
|
||||
'DELETE FROM .'.USERS_TABLE.'
|
||||
WHERE `user_id` = \''.$user_id.'\'';
|
||||
$this->db->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
29
inc/view.class.php
Normal file
29
inc/view.class.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/askModel.class.php');
|
||||
|
||||
abstract class View extends AskModel
|
||||
{
|
||||
protected $TPL = array();
|
||||
protected $db;
|
||||
|
||||
function show($template)
|
||||
{
|
||||
if (file_exists('./templates/'.$template.'.tpl.php'))
|
||||
require_once('./templates/'.$template.'.tpl.php');
|
||||
else
|
||||
throw new Exception('Could not show selected template: '.$template);
|
||||
}
|
||||
|
||||
function assign($n, $v) //osadzanie elementu skórki
|
||||
{
|
||||
$this->TPL[$n] = $v;
|
||||
}
|
||||
|
||||
function __construct(&$db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
536
inc/views/MainView.class.php
Normal file
536
inc/views/MainView.class.php
Normal file
@@ -0,0 +1,536 @@
|
||||
<?php
|
||||
|
||||
require_once('./inc/view.class.php');
|
||||
|
||||
class MainView extends View
|
||||
{
|
||||
private function setDefaults($admin = false)
|
||||
{
|
||||
//logged user information
|
||||
$this->assign('is_logged', $this->getModel('SessionModel')->isLogged());
|
||||
$this->assign('my_nick', $this->getModel('SessionModel')->getNick());
|
||||
$this->assign('my_id', $this->getModel('SessionModel')->getID());
|
||||
$this->assign('my_rank', $this->getModel('SessionModel')->getRank());
|
||||
$this->assign('actual_time', date('Y-m-d G:i', $_SERVER['REQUEST_TIME']));
|
||||
|
||||
//forum prefs
|
||||
$this->assign('forum_name', $this->getModel('ConfigModel')->getConf('forum_name'));
|
||||
$this->assign('forum_desc', $this->getModel('ConfigModel')->getConf('forum_desc'));
|
||||
|
||||
//navigation
|
||||
$this->loadModel('NavigationModel');
|
||||
$this->getModel('NavigationModel')->setForumName($this->getModel('ConfigModel')->getConf('forum_name'));
|
||||
if ($admin)
|
||||
$this->getModel('NavigationModel')->addLink('ACP Admin', 'index.php?mode=admin');
|
||||
}
|
||||
|
||||
//widok strony głównej
|
||||
public function main()
|
||||
{
|
||||
$this->setDefaults();
|
||||
|
||||
// get categories, forums, forums statistics
|
||||
$this->loadModel('ForumsModel');
|
||||
$this->assign('forums_list', $this->getModel('ForumsModel')->getForums());
|
||||
|
||||
//get data for bottom statistics
|
||||
$this->loadModel('StatisticsModel');
|
||||
$this->assign('posts_count', $this->getModel('StatisticsModel')->getPostsCount());
|
||||
$this->assign('users_count', $this->getModel('StatisticsModel')->getUsersCount());
|
||||
$this->assign('last_user', $this->getModel('StatisticsModel')->getLastRegisteredUser());
|
||||
$this->assign('logged_users_count', $this->getModel('StatisticsModel')->getLoggedUsersCount());
|
||||
$this->assign('logged_users', $this->getModel('StatisticsModel')->getLoggedUsers());
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('Main Page');
|
||||
$this->getModel('NavigationModel')->addLink('Main Page', 'index.php');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('main');
|
||||
}
|
||||
|
||||
public function viewforum()
|
||||
{
|
||||
$this->setDefaults();
|
||||
|
||||
// get forum info
|
||||
$f_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
|
||||
|
||||
$this->assign('f_name', $f_info['name']);
|
||||
$this->assign('forum_info', $f_info);
|
||||
$this->assign('topics_list', $this->getModel('ForumsModel')->getTopics($_GET['id']));
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('View forum: '.$f_info['name']);
|
||||
$this->getModel('NavigationModel')->addLink($f_info['name'], 'index.php?mode=viewforum&id='.$_GET['id']);
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('viewforum');
|
||||
}
|
||||
|
||||
public function userlist()
|
||||
{
|
||||
$this->setDefaults();
|
||||
|
||||
$this->loadModel('UsersModel');
|
||||
$this->assign('users_list', $this->getModel('UsersModel')->getUsers($_POST['sort_type'], $_POST['sort_desc'], $_GET['rank']));
|
||||
|
||||
$this->assign('regdate_selected', ($_POST['sort_type'] == 'regdate') ? 'selected="selected"' : '');
|
||||
$this->assign('lastvisit_selected', ($_POST['sort_type'] == 'lastvisit') ? 'selected="selected"' : '');
|
||||
$this->assign('username_selected', ($_POST['sort_type'] == 'nick') ? 'selected="selected"' : '');
|
||||
$this->assign('posts_selected', ($_POST['sort_type'] == 'post_count') ? 'selected="selected"' : '');
|
||||
$this->assign('desc_checked', ($_POST['sort_desc'] == 'DESC') ? 'checked="checked"' : '');
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('Users list');
|
||||
$this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=userlist');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('userlist');
|
||||
}
|
||||
|
||||
public function viewtopic()
|
||||
{
|
||||
$this->setDefaults();
|
||||
|
||||
// get forum info
|
||||
$t_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
|
||||
|
||||
$this->assign('topic_info', $t_info);
|
||||
$this->assign('posts_list', $this->getModel('PostsModel')->getPosts($_GET['id']));
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('View topic: '.$t_info['topic_title']);
|
||||
$this->getModel('NavigationModel')->addLink($t_info['forum_name'], 'index.php?mode=viewforum&id='.$t_info['forum_id']);
|
||||
$this->getModel('NavigationModel')->addLink($t_info['topic_title'], 'index.php?mode=viewtopic&id='.$_GET['id']);
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('viewtopic');
|
||||
}
|
||||
|
||||
public function login_form($msg)
|
||||
{
|
||||
$this->setDefaults();
|
||||
|
||||
$this->assign('nick', $_POST['nick']);
|
||||
$this->assign('error_msg', $msg);
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('Log in');
|
||||
$this->getModel('NavigationModel')->addLink('Log in', 'index.php?mode=login');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('login_form');
|
||||
}
|
||||
|
||||
public function register_form($msg)
|
||||
{
|
||||
$this->setDefaults();
|
||||
|
||||
$this->assign('nick', $_POST['nick']);
|
||||
$this->assign('email', $_POST['email']);
|
||||
$this->assign('error_msg', $msg);
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('Register');
|
||||
$this->getModel('NavigationModel')->addLink('Register', 'index.php?mode=register');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('register_form');
|
||||
}
|
||||
|
||||
public function viewprofile()
|
||||
{
|
||||
$this->setDefaults();
|
||||
$this->loadModel('StatisticsModel');
|
||||
|
||||
$user_info = $this->getModel('UsersModel')->getUserInformation($_GET['id']);
|
||||
|
||||
$this->assign('user_info', $user_info);
|
||||
$total_posts = $this->getModel('StatisticsModel')->getPostsCount();
|
||||
$posts_ration = ($total_posts > 0) ? round(100*$user_info['post_count']/$total_posts, 2) : 0;
|
||||
$this->assign('post_ratio', $total_posts);
|
||||
$this->assign('logged_id', $this->getModel('SessionModel')->getID());
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=userlist');
|
||||
$this->getModel('NavigationModel')->setSubTitle('View profile: '.$user_info['nick']);
|
||||
$this->getModel('NavigationModel')->addLink('Profile: '.$user_info['nick'], 'index.php?mode=viewprofile&id='.$_GET['id']);
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('viewprofile');
|
||||
}
|
||||
|
||||
public function edprofile_form($msg, $admin = false)
|
||||
{
|
||||
$this->setDefaults($admin);
|
||||
|
||||
if ($admin)
|
||||
$user_info = $this->getModel('UsersModel')->getUserInformation($_GET['id']);
|
||||
else
|
||||
$user_info = $this->getModel('UsersModel')->getUserInformation($this->getModel('SessionModel')->getID());
|
||||
$this->assign('nick', $_POST['nick']);
|
||||
$this->assign('is_admin', $admin);
|
||||
$this->assign('email', $_POST['email']);
|
||||
$this->assign('location', $_POST['location']);
|
||||
$this->assign('signature', $_POST['signature']);
|
||||
$this->assign('avatar', $user_info['avatar']);
|
||||
$this->assign('error_msg', $msg);
|
||||
|
||||
if ($admin)
|
||||
{
|
||||
$this->assign('user_selected', ($_POST['user_rank'] == RANK_USER) ? 'checked="checked"' : '');
|
||||
$this->assign('mod_selected', ($_POST['user_rank'] == RANK_MOD) ? 'checked="checked"' : '');
|
||||
$this->assign('admin_selected', ($_POST['user_rank'] == RANK_ADMIN) ? 'checked="checked"' : '');
|
||||
}
|
||||
|
||||
//nawigacja po witrynie
|
||||
if ($admin)
|
||||
{
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Edit profile');
|
||||
$this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=admin&submode=users');
|
||||
$this->getModel('NavigationModel')->addLink('Edit user: '.$user_info['nick']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->getModel('NavigationModel')->setSubTitle('Edit profile');
|
||||
$this->getModel('NavigationModel')->addLink('Edit profile', 'index.php?mode=editprofile');
|
||||
}
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('edprofile');
|
||||
}
|
||||
|
||||
public function posting_form($type, $msg='')
|
||||
{
|
||||
$this->setDefaults();
|
||||
$this->assign('error_msg', $msg);
|
||||
|
||||
//nawigacja po witrynie
|
||||
switch ($type)
|
||||
{
|
||||
case POSTING_NEWTOPIC:
|
||||
$forum_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
|
||||
$this->getModel('NavigationModel')->setSubTitle('New topic');
|
||||
$this->getModel('NavigationModel')->addLink($forum_info['name'], 'index.php?mode=viewforum&id='.$forum_info['forum_id']);
|
||||
$this->getModel('NavigationModel')->addLink('New topic', $_SERVER['REQUEST_URI']);
|
||||
break;
|
||||
case POSTING_REPLY:
|
||||
case POSTING_QUOTE:
|
||||
$topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
|
||||
|
||||
$this->getModel('NavigationModel')->setSubTitle('Reply');
|
||||
$this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&id='.$topic_info['forum_id']);
|
||||
$this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&id='.$topic_info['topic_id']);
|
||||
$this->getModel('NavigationModel')->addLink('Write a reply', $_SERVER['REQUEST_URI']);
|
||||
break;
|
||||
|
||||
case POSTING_EDIT:
|
||||
$topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
|
||||
|
||||
$this->getModel('NavigationModel')->setSubTitle('Edit post');
|
||||
$this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&id='.$topic_info['forum_id']);
|
||||
$this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&id='.$topic_info['topic_id']);
|
||||
$this->getModel('NavigationModel')->addLink('Edit post', $_SERVER['REQUEST_URI']);
|
||||
break;
|
||||
|
||||
case POSTING_EDITTOPIC:
|
||||
$topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
|
||||
|
||||
$this->getModel('NavigationModel')->setSubTitle('Edit topic');
|
||||
$this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&id='.$topic_info['forum_id']);
|
||||
$this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&id='.$topic_info['topic_id']);
|
||||
$this->getModel('NavigationModel')->addLink('Edit topic', $_SERVER['REQUEST_URI']);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->assign('post', $_POST['post']);
|
||||
if (isset($_POST['preview']))
|
||||
$this->assign('preview', addslashes(htmlspecialchars($_POST['post'])));
|
||||
|
||||
if ($type == POSTING_NEWTOPIC || $type == POSTING_EDITTOPIC)
|
||||
$this->assign('topic', $_POST['topic']);
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('posting');
|
||||
}
|
||||
|
||||
public function move_topic()
|
||||
{
|
||||
$this->setDefaults();
|
||||
$this->loadModel('ForumsModel');
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('Move topic');
|
||||
$this->getModel('NavigationModel')->addLink('Move topic', $_SERVER['REQUEST_URI']);
|
||||
|
||||
$this->assign('topic_info', $this->getModel('PostsModel')->getTopic($_GET['id']));
|
||||
$this->assign('forums_list', $this->getModel('ForumsModel')->getForumsNames());
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('move_topic');
|
||||
}
|
||||
|
||||
public function forum_message($msg, $url = '', $timeout = 2)
|
||||
{
|
||||
$this->setDefaults();
|
||||
|
||||
$this->assign('message', $msg);
|
||||
$this->assign('url', $url);
|
||||
$this->assign('timeout', $timeout);
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('Forum message');
|
||||
$this->getModel('NavigationModel')->addLink('Forum message', 'index.php');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('forum_message');
|
||||
}
|
||||
|
||||
public function confirm_action($msg)
|
||||
{
|
||||
$this->setDefaults();
|
||||
|
||||
$this->assign('message', $msg);
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('Confirm action');
|
||||
$this->getModel('NavigationModel')->addLink('Confirm action', $_SERVER['REQUEST_URI']);
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('confirm_action');
|
||||
}
|
||||
|
||||
public function colorRank($username, $rank)
|
||||
{
|
||||
if ($rank == RANK_ADMIN)
|
||||
return '<span class="fadmin">'.$username.'</span>';
|
||||
|
||||
if ($rank == RANK_MOD)
|
||||
return '<span class="fmod">'.$username.'</span>';
|
||||
|
||||
return $username;
|
||||
}
|
||||
|
||||
public function getRankLevel($rank)
|
||||
{
|
||||
if ($rank == RANK_ADMIN)
|
||||
return $this->colorRank('Admin', $rank);
|
||||
if ($rank == RANK_MOD)
|
||||
return $this->colorRank('Mod', $rank);
|
||||
|
||||
return 'User';
|
||||
}
|
||||
|
||||
// ADMIN PANEL -----------------------------------------------------------------
|
||||
public function admin_main()
|
||||
{
|
||||
$this->setDefaults(true);
|
||||
$this->loadModel('StatisticsModel');
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('Main Page');
|
||||
$this->assign('installation_date', $this->getModel('ConfigModel')->getConf('installation_date'));
|
||||
$this->assign('topics_total', $this->getModel('StatisticsModel')->getTopicsCount());
|
||||
$this->assign('posts_total', $this->getModel('StatisticsModel')->getPostsCount());
|
||||
$this->assign('users_total', $this->getModel('StatisticsModel')->getUsersCount());
|
||||
$this->assign('script_version', VERSION);
|
||||
$this->assign('logged_users', $this->getModel('StatisticsModel')->getLoggedUsers());
|
||||
$this->assign('logged_users_total', $this->getModel('StatisticsModel')->getLoggedUsersCount());
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('admin/main');
|
||||
}
|
||||
|
||||
public function admin_userlist()
|
||||
{
|
||||
$this->setDefaults(true);
|
||||
|
||||
$this->loadModel('UsersModel');
|
||||
$this->assign('users_list', $this->getModel('UsersModel')->getUsers($_POST['sort_type'], $_POST['sort_desc'], $_GET['rank']));
|
||||
|
||||
$this->assign('regdate_selected', ($_POST['sort_type'] == 'regdate') ? 'selected="selected"' : '');
|
||||
$this->assign('lastvisit_selected', ($_POST['sort_type'] == 'lastvisit') ? 'selected="selected"' : '');
|
||||
$this->assign('username_selected', ($_POST['sort_type'] == 'nick') ? 'selected="selected"' : '');
|
||||
$this->assign('posts_selected', ($_POST['sort_type'] == 'post_count') ? 'selected="selected"' : '');
|
||||
$this->assign('desc_checked', ($_POST['sort_desc'] == 'DESC') ? 'checked="checked"' : '');
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Users list');
|
||||
$this->getModel('NavigationModel')->addLink('Users list');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('admin/userlist');
|
||||
}
|
||||
|
||||
public function admin_config($msg)
|
||||
{
|
||||
$this->setDefaults(true);
|
||||
|
||||
$this->loadModel('UsersModel');
|
||||
|
||||
|
||||
$this->assign('forum_name', $_POST['forum_name']);
|
||||
$this->assign('forum_desc', $_POST['forum_desc']);
|
||||
$this->assign('error_msg', $msg);
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Admin config');
|
||||
$this->getModel('NavigationModel')->addLink('Forum configuration');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('admin/config');
|
||||
}
|
||||
|
||||
//widok strony głównej
|
||||
public function admin_forums()
|
||||
{
|
||||
$this->setDefaults(true);
|
||||
|
||||
// get categories, forums, forums statistics
|
||||
$this->loadModel('ForumsModel');
|
||||
$this->assign('forums_list', $this->getModel('ForumsModel')->getForums());
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Forums list');
|
||||
$this->getModel('NavigationModel')->addLink('Forums list');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('admin/forums');
|
||||
}
|
||||
|
||||
public function admin_cat_form($msg, $m)
|
||||
{
|
||||
$this->setDefaults(true);
|
||||
|
||||
$this->assign('name', $_POST['name']);
|
||||
$this->assign('error_msg', $msg);
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->addLink('Forums list', 'index.php?mode=admin&submode=forums');
|
||||
if ($m == 'add')
|
||||
{
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Add category');
|
||||
$this->getModel('NavigationModel')->addLink('Add category');
|
||||
$this->assign('cat_form_name', 'Add new category');
|
||||
}
|
||||
else
|
||||
{
|
||||
$cat_info = $this->getModel('ForumsModel')->getCat($_GET['id']);
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Edit category');
|
||||
$this->getModel('NavigationModel')->addLink('Edit category: '.$cat_info['name']);
|
||||
$this->assign('cat_form_name', 'Edit category');
|
||||
}
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('admin/cat_form');
|
||||
}
|
||||
|
||||
public function admin_forum_form($msg, $m)
|
||||
{
|
||||
$this->setDefaults(true);
|
||||
|
||||
$this->assign('name', $_POST['name']);
|
||||
$this->assign('desc', $_POST['desc']);
|
||||
$this->assign('category_id', $_POST['category_id']);
|
||||
$this->assign('lock_selected', ($_POST['locked']) ? 'checked="checked"' : '');
|
||||
$this->assign('unlock_selected', (!$_POST['locked']) ? 'checked="checked"' : '');
|
||||
$this->assign('error_msg', $msg);
|
||||
$this->assign('cats_list', $this->getModel('ForumsModel')->getCats());
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->addLink('Forums list', 'index.php?mode=admin&submode=forums');
|
||||
if ($m == 'add')
|
||||
{
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Add forum');
|
||||
$this->getModel('NavigationModel')->addLink('Add forum');
|
||||
$this->assign('forum_form_name', 'Add new forum');
|
||||
}
|
||||
else
|
||||
{
|
||||
$forum_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Edit forum');
|
||||
$this->getModel('NavigationModel')->addLink('Edit forum'.$forum_info['name']);
|
||||
$this->assign('forum_form_name', 'Edit forum');
|
||||
}
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('admin/forum_form');
|
||||
}
|
||||
|
||||
public function admin_banlist()
|
||||
{
|
||||
$this->setDefaults(true);
|
||||
|
||||
$this->loadModel('BansModel');
|
||||
$this->assign('bans_list', $this->getModel('BansModel')->getBans());
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Banlist');
|
||||
$this->getModel('NavigationModel')->addLink('Banlist');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('admin/banlist');
|
||||
}
|
||||
|
||||
public function admin_ban_form($msg)
|
||||
{
|
||||
$this->setDefaults(true);
|
||||
|
||||
$this->assign('user_id', $_POST['user_id']);
|
||||
$this->assign('reason', $_POST['reason']);
|
||||
|
||||
$this->loadModel('UsersModel');
|
||||
$this->assign('error_msg', $msg);
|
||||
$this->assign('users_list', $this->getModel('UsersModel')->getUsersNicks());
|
||||
|
||||
//nawigacja po witrynie
|
||||
$this->getModel('NavigationModel')->addLink('Banlist', 'index.php?mode=admin&submode=banlist');
|
||||
|
||||
$this->getModel('NavigationModel')->setSubTitle('ACP • Add ban');
|
||||
$this->getModel('NavigationModel')->addLink('Add ban');
|
||||
$this->assign('forum_form_name', 'Add ban');
|
||||
|
||||
// końcowe rzeczy
|
||||
$this->assign('nav', $this->getModel('NavigationModel')->getNav());
|
||||
$this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
|
||||
$this->show('admin/ban_form');
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user