<?php
$tpl .= '<div class="forumContent">';
$tpl .= '<h1>Fórum</h1>';
$forum = new forum($uid, $username, $email, $admin);
if(!(int)$_GET['category']){
$categories = $forum->listCategories(null,'`name` ASC');
if($categories){
foreach($categories as $category){
$tpl .= '<p class="box"><a href="'.selfURL('category').'&category='.$category['cid'].'">'.$category['name'].'</a><br />'.$category['desc'].'<div class="cl"></div></p>';
}
}
if($forum->checkPermissions('categories')){
if($_POST['addCat']){
if(!empty($_POST['name']) && !empty($_POST['desc']))$forum->addCategory($_POST['name'], $_POST['desc']);
}
$tpl .= '<form action="'.selfURL().'" method="post">
<p>Pridať kategóriu</p>
<p><label for="name">Názov:</label><input type="text" name="name" id="name" /></p>
<p><label for="desc">Popis:</label><input type="text" name="desc" id="desc" /></p>
<p><input type="submit" name="addCat" value="Vytvoriť" /></p>
</form>';
}
}elseif(!(int)$_GET['topic']){
if(isset($_GET['del'])){
$out = $forum->delTopic($_GET['topic_id']);
if($out === '403'){
$tpl .= 'Nemáte oprávnenie.';
}elseif($out === '0'){
$tpl .= 'Nepodarilo sa.';
}else{
$tpl .= 'Zmazané.';
}
}
$category = $forum->listCategories($_GET['category']);
$tpl .= '<h3>'.$category[0]['name'].'</h3>';
if($_POST['addTopic']){
if(!empty($_POST['name']) && !empty($_POST['desc']) && !empty($_POST['text'])){
$forum->addPost($_POST['text'],$forum->addTopic($_POST['name'], $_POST['desc'], $_GET['category'], $_POST['notify']),0);
}
}
$topics = $forum->listTopics($_GET['category'],null,'`name` ASC');
if($topics){
foreach($topics as $topic){
$tpl .= '<p class="box"><a href="'.selfURL('category,topic').'&category='.$_GET['category'].'&topic='.$topic['tid'].'">'.$topic['name'].'</a><br />'.$topic['desc'];
if($forum->checkPermissions('topics',$topic['tid']))$tpl .= '<a href="'.selfURL('topic_id,del').'&topic_id='.$topic['tid'].'&del" class="del">Zmazať</a>';
$tpl .= '<div class="cl"></div></p>';
}
}
$tpl .= '<form action="'.selfURL('del').'" method="post">
<p>Nová téma</p>
<p><label for="name">Názov:</label><input type="text" name="name" id="name" /></p>
<p><label for="desc">Popis:</label><input type="text" name="desc" id="desc" /></p>
<p><label for="text">Text:</label><textarea name="text" id="text"></textarea></p>
<p><label for="notify">Notifikovať o nových správach:</label><input type="checkbox" name="notify" value="1" id="notify" checked="checked" /></p>
<p><input type="submit" name="addTopic" value="Vytvoriť" /></p>
</form>';
}else{
$category = $forum->listCategories($_GET['category']);
$topic = $forum->listTopics($_GET['category'],$_GET['topic']);
$tpl .= '<h3><a href="'.selfURL('category,topic').'&category='.$_GET['category'].'">'.$category[0]['name'].'</a> => '.$topic[0]['name'].'</h3>';
if($_POST['addPost']){
if(!empty($_POST['text']))$forum->addPost($_POST['text'], $_GET['topic'], 1);
}
$posts = $forum->listPosts($_GET['topic'],'`pid` ASC');
if($posts){
foreach($posts as $post){
$tpl .= '<p class="box">User: '.$post['uid'].'<br />'.$post['text'];
if($forum->checkPermissions('posts',$post['pid']))$tpl .= '<br /><a href="'.selfURL('post_id,del').'&post_id='.$post['pid'].'&del" class="del">Zmazať</a>';
$tpl .= '</p>';
}
}
$tpl .= '<form action="'.selfURL().'" method="post">
<p>Nový príspevok</p>
<p><label for="text">Text:</label><textarea name="text" id="text"></textarea></p>
<p><input type="submit" name="addPost" value="Pridať" /></p>
</form>';
}
$tpl .= '</div>';
function selfURL($what=0){//what is regular
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
if($what){
$wh = explode(',',$what);
$ex = explode('?',$_SERVER['REQUEST_URI']);
$query = explode('&',$ex[1]);
$max=count($query);
for($i=0;$i<$max;$i++){
$qu = explode('=',$query[$i]);
if(!in_array($qu[0],$wh))$out[] = $query[$i];
}
if($out){
$query = implode('&',$out);
$end = $ex[0].'?'.$query;
}else{
$end = $ex[0];
}
}else{
$end = $_SERVER['REQUEST_URI'];
}
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$end;
}
function strleft($s1, $s2){
return substr($s1, 0, strpos($s1, $s2));
}
?>
|