Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('connect.php');
- session_start();
- //Let's make page as UTF-8 character set
- mb_internal_encoding('UTF-8');
- mb_http_output('UTF-8');
- mb_http_input('UTF-8');
- mb_language('uni');
- mb_regex_encoding('UTF-8');
- ob_start('mb_output_handler');
- $scripturl = 'http://zapperhosting.byethost14.com/s32ucp/index.php'; ///must be index.php at the end
- $variables['date'] = date("d.m.Y");
- $variables['load_time_start'] = microtime(true);
- $y = 0;
- for($x = 0; $x <= 1000000; $x++)
- {
- $y = $x;
- $y *= pi();
- $y *= (pi() * 2);
- }
- $variables['load_time_end'] = number_format((microtime(true) - $variables['load_time_start']), 2);
- if(isset($_POST['keywords']))
- {
- $variables['keywords'] = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
- $variables['errors'] = array();
- if(empty($variables['keywords']))
- {
- $variables['errors'][] = 'Please enter query!';
- }
- else if(strlen($variables['keywords']) < 3)
- {
- $variables['errors'][] = 'Length must be at leaset 3 characters';
- }
- else if(SearchResults($variables['keywords']) === false)
- {
- $variables['errors'][] = 'No result found for keyword'.' <strong>'.$variables['keywords'].'</strong> !';
- }
- }
- function toolbar_template()
- {
- global $variables, $scripturl;
- $variables['buttons'] = array(
- 'home' => array(
- 'title' => 'Home',
- 'href' => $scripturl,
- 'show' => true
- ),
- 'news' => array(
- 'title' => 'News',
- 'href' => $scripturl . '?action=news',
- 'show' => true
- ),
- 'search' => array(
- 'title' => 'Search',
- 'href' => $scripturl . '?action=search',
- 'show' => true
- ),
- 'admin' => array(
- 'title' => 'Admin',
- 'href' => $scripturl . '?action=admin',
- 'show' => IsUserAdmin(ReturnUsername(), 1)
- ),
- 'logout' => array(
- 'title' => 'Logout',
- 'href' => $scripturl . '?action=logout',
- 'show' => IsUserLogged()
- ),
- 'login' => array(
- 'title' => 'Login',
- 'href' => $scripturl . '?action=login',
- 'show' => !IsUserLogged()
- ),
- );
- $menu_buttons = array();
- foreach ($variables['buttons'] as $act => $button)
- {
- if (!empty($button['show']))
- {
- $button['active_button'] = false;
- $menu_buttons[$act] = $button;
- }
- }
- $variables['menu_buttons'] = $menu_buttons;
- echo '
- <ul id="topnav">';
- foreach ($variables['menu_buttons'] as $act => $button)
- {
- if(GetCurrentPageAdress() == $button['href']) $button['active_button'] = true;
- echo '
- <li id="button_', $act, '">';
- if($button['active_button'] == true) { echo ' <a class="active" href="' .$button['href']. '">'.$button['title'].'</a>'; }
- else echo '
- <a href="' .$button['href']. '">'.$button['title'].'</a>
- </li>';
- }
- echo '
- </ul>';
- }
- function content_template()
- {
- global $variables;
- if(isset($_GET['action']))
- {
- if($_GET['action'] == 'login')
- {
- if(IsUserLogged()) header('location: index.php');
- echo '
- <div align="center">';
- ?>
- <p id="login_user_error_report1"></p>
- <p id="login_user_error_report"></p>
- <form action="post" method="post">
- <input type="text" maxlength="25" name="login_username" id="login_username" placeholder="Username"><br><br>
- <input type="password" name="login_password" id="login_password" placeholder="Password"><br><br>
- <input type="checkbox" name="login_rembme" id="login_rembme"> Remember me<br><br>
- <input type="button" onClick="SubmitLoginUser()" value="Login">
- </form>
- <?php
- echo '
- </div>';
- }
- if($_GET['action'] == 'logout')
- {
- if(!IsUserLogged()) header('location: index.php');
- setcookie("logged_username_cookie", "", time() - (60 * 60 * 24 * 365 * 5));
- unset($_SESSION['logged_username_session']);
- header('location: index.php');
- }
- if($_GET['action'] == 'admin')
- {
- if(!IsUserAdmin(ReturnUsername(), 1)) header('location: index.php');
- echo '
- <div align="center">';
- echo '
- <div id="tabs">
- <ul>
- <li>Add News</li>
- <li>Ban User</li>
- <li>Delete User</li>
- <li>Register User</li>
- <li>View Bans</li>
- <li>View Users</li>
- </ul>
- </div>
- <div id="desc">
- <div>';
- ?>
- <p id="add_news_preview" align="left"></p>
- <p id="add_news_error_report"></p>
- <form method="post" action="post">
- <input type="text" id="news_title" name="news_title" maxlength="20" size="60" placeholder="Title"><br><br>
- <?php ShowBBCodes('news_text'); ?><br>
- <textarea cols="152" rows="10" id="news_text" name="news_text" placeholder="Text"></textarea><br><br>
- <input type="button" onClick="SubmitAddNewsForm('<?php echo ReturnUsername(); ?>', '<?php echo date("d.m.Y"); ?>');" value="Add"> <input type="button" onClick="PreviewPost('#add_news_preview', '#news_text')" value="Preview">
- </form>
- <?php
- echo '
- </div>
- <div>';
- ?>
- <p id="add_bans_error_report"></p>
- <form method="post" action="post">
- <input type="text" name="add_bans_username" id="add_bans_username" style="width: 158px;" class="autosuggest_users" placeholder="Player name">
- <ul class="result"></ul>
- <br><br>
- <textarea name="add_bans_reason" id="add_bans_reason" cols="50" rows="5" placeholder="Reason"></textarea><br><br>
- <input type="button" onClick="SubmitAddBansForm('<?php echo ReturnUsername(); ?>')" value="Ban">
- </form>
- <?php
- echo'
- </div>
- <div>';
- ?>
- <p id="delete_user_error_report"></p>
- <form method="post" action="post">
- <input type="text" name="delete_username" id="delete_username" style="width: 158px;" class="autosuggest_users" placeholder="Player name">
- <ul class="result"></ul>
- <br><br>
- <input type="button" onClick="SubmitDeleteUserForm()" value="Delete">
- </form>
- <?php
- echo '
- </div>
- <div>';
- ?>
- <p id="register_user_error_report"></p>
- <form method="post" action="post">
- <input type="text" name="register_user_username" id="register_user_username" maxlength="24" placeholder="Player name"><br><br>
- <input type="password" name="register_user_password" id="register_user_password" placeholder="Password"><br><br>
- <input type="password" name="register_user_repeat_password" id="register_user_repeat_password" placeholder="Repeat password"><br><br>
- <select name="register_user_admin_level">
- <option selected="selected">Admin level</option>
- <option>0</option>
- <option>1</option>
- <option>2</option>
- <option>3</option>
- </select><br><br>
- <input type="button" onClick="SubmitRegisterUserForm()" value="Register">
- </form>
- <?php
- echo '
- </div>
- <div align="left">';
- $num = 1;
- $query = mysql_query("SELECT * FROM `bans`") or die(mysql_error());
- if(mysql_num_rows($query) >= 1)
- {
- while($row = mysql_fetch_assoc($query))
- {
- echo '
- <p id="delete_ban_'.$row['ID'].'"></p>
- <table cellpadding="0" cellspacing="5" border="0">
- <tbody>
- <tr>
- <td id="counter">'.$num.'</td>
- <td><em>'.$row['Banned'].'</em> banned by <strong>'.$row['Administrator'].'</strong><br>';
- ?>
- <a onClick="DeleteBanForm(<?php echo $row['ID']; ?>)" title="Delete ban!"><img style="padding-top: 3px;" src="images/delete.png"></a>
- <a onClick="CreateTextarea('#ban_reason_<?php echo $row['ID']; ?>', '<?php echo $row['Reason']; ?>', <?php echo $row['ID']; ?>);" style="padding-left: 5px;" title="Edit ban!"><img src="images/edit.png"></a>
- <?php
- echo '
- </td>
- </tr>
- </tbody>
- </table>
- <p id="addnews_separator"></p>
- <p style="padding: 7px; font-size: 18px; width: 41%; margin: 0" id="ban_reason_'.$row['ID'].'">'.$row['Reason'].'</p>
- <p id="bans_separator"></p>';
- $num ++;
- }
- }
- else echo '<h2>No existing bans!</h2>';
- echo '
- </div>
- <div id="search_users">';
- ?>
- <p id="search_users_error_report"></p>
- <p align="center">
- <input type="text" id="search_users_text" class="autosuggest_users" style="width: 158px;" placeholder="Player name">
- <ul class="result"></ul>
- </p>
- <?php
- $query = mysql_query("SELECT * FROM `users`") or die(mysql_error());
- if(mysql_num_rows($query) >= 1)
- {
- while($row = mysql_fetch_assoc($query))
- {
- echo '
- <h2 id="'.$row['User'].'">'.$row['User'].'</h2>
- <table cellpadding="0" cellspacing="5" border="0">
- <tbody>
- <tr>
- <td>Money: '.$row['Money'].'</td><td style="padding-left: 15px;">Score: '.$row['Score'].'</td>
- </tr>
- <tr>
- <td>Kills: '.$row['Kills'].'</td><td style="padding-left: 15px;">Deaths: '.$row['Deaths'].'</td>
- </tr>
- <tr>
- <td>Admin: '.$row['Admin'].'</td><td style="padding-left: 15px;">Warns: '.$row['Warns'].'</td>
- </tr>
- </tbody>
- </table><br>
- <p id="view_user_separator"></p>';
- }
- }
- else echo '<h2>Currently no users!</h2>';
- echo '
- </div>
- </div>
- <div id="addnews_separator" style="padding-top: 8px;"></div>
- </div>
- <br><p class="admin_message_hi">Hi ',ReturnUsername(),'!
- <br>
- This is your admin control panel, please choose on of the actions in the tab list
- <br>
- and press ESC if you want to hide tab!</p>';
- }
- if($_GET['action'] == 'news')
- {
- $num = 1;
- $query = mysql_query("SELECT * FROM `news`") or die(mysql_error());
- echo '
- <div align="left">';
- if(mysql_num_rows($query) >= 1)
- {
- while($row = mysql_fetch_assoc($query))
- {
- echo '
- <p id="delete_news_'.$row['ID'].'"></p>
- <table cellpadding="0" cellspacing="5" border="0">
- <tbody>
- <tr>
- <td id="counter">'.$num.'</td>
- <td><em>'.$row['Title'].'</em><br>
- Date: '.$row['Date'].'';
- if($row['Update'] != 'Never') echo '
- <em style="color: orange;"> | Last update: '.$row['Update'].'</em>';
- if(IsUserAdmin(ReturnUsername(), 1))
- {
- ?>
- <br>
- <a onClick="DeleteNewsForm(<?php echo $row['ID']; ?>)" title="Delete news!"><img style="padding-top: 3px;" src="images/delete.png"></a>
- <a href="index.php?action=editnews&id=<?php echo $row['ID']; ?>" style="padding-left: 5px;" title="Edit news!"><img src="images/edit.png"></a>
- <?php
- }
- echo '
- </td>
- </tr>
- </tbody>
- </table>
- <p id="addnews_separator"></p>
- <p style="padding: 7px; margin: 0" id="ban_reason_'.$row['ID'].'">'.BBCode($row['Text']).'</p>
- <p id="bans_separator"></p>';
- $num ++;
- }
- }
- else echo '<h2>No existing bans!</h2>';
- echo '
- </div>';
- }
- if($_GET['action'] == 'editnews')
- {
- $query = mysql_query("SELECT * FROM `news` WHERE ID = '".$_GET['id']."'") or die(mysql_error());
- if(mysql_num_rows($query) == 1)
- {
- while($row = mysql_fetch_assoc($query))
- {
- echo '
- <div id="edit_news_preview"></div>
- <div id="edit_news_error_report"></div>
- <div align="center">';
- ?>
- <input type="text" size="60" name="edit_news_title" id="edit_news_title" value="<?php echo $row['Title']; ?>"><br><br>
- <?php echo ShowBBCodes('edit_news_text'); ?>
- <textarea cols="154" rows="10" name="edit_news_text" id="edit_news_text"><?php echo $row['Text']; ?></textarea><br><br>
- <input type="button" onClick="SubmitEditNewsForm(<?php echo $_GET['id']; ?>, '<?php echo date("d.m.Y"); ?>')" value="Edit"> <input type="button" onClick="PreviewPost('#edit_news_preview', '#edit_news_text')" value="Preview">
- <?php
- echo '
- </div>';
- }
- }
- else echo '
- <h2 style="text-align: center; text-shadow: 1px 1px 0 white;">News doesn\'t exist!</div>';
- }
- if($_GET['action'] == 'search')
- {
- echo '
- <div align="center">';
- ?>
- <form action="index.php?action=search" method="post">
- <input type="text" size="70" speellchec="false" name="keywords" placeholder="Enter text"><br><br>
- <input type="submit" name="search_submit" value="Search">
- </form>
- <?php
- echo '
- </div>';
- if(isset($_POST['search_submit']))
- {
- echo '
- <p id="addnews_separator"></p>';
- if(!isset($variables['keywords']))
- {
- echo '
- <div id="error">Please enter query!</div>';
- return;
- }
- if(empty($variables['errors']))
- {
- $num = 0;
- $results = SearchResults($variables['keywords']);
- $results_num = count($results);
- $suffix = ($results_num != 1) ? 's' : '';
- echo '
- <h2 style="font-size: 16px; text-shadow: 1px 1px 0 white; text-align: center;">Total <strong>'.$results_num.'</strong> result'.$suffix.' for keyword <strong>\''.$variables['keywords'].'\'</strong></h2>';
- foreach($results as $result)
- {
- $num ++;
- $string = $result['post'];
- $words = array($variables['keywords']);
- $string = BBCode($string);
- $string = HighlightWords($string, $words);
- $string1 = $result['title'];
- $words = array($variables['keywords']);
- $string1 = HighlightWords($string1, $words);
- echo '
- <br>
- <div style="font-size: 13px; text-shadow: 1px 1px 0 white;">
- <div style="text-align: left;">
- <table cellpadding="0" cellspacing="10" border="0">
- <tbody>
- <tr>
- <td>
- <div class="search_counter">'.$num.'</div>
- </td>
- <td>
- <h5 style="margin: 0; padding: 0; font-size: 15px;">'.$string1.'</h5>
- <em style="font-size: 13px;">'.$result['author'].'</em>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <br>
- <p id="addnews_separator"></p>
- <p style="text-align: left; margin-left: 2%;">'.$string.'</p>
- </div>
- <div id="bans_separator" style="margin-left: 0; width: 100%;"></div>';
- }
- }
- else
- {
- foreach($variables['errors'] as $error)
- {
- echo '
- <div id="error">'.$error.'</div>';
- }
- }
- }
- }
- }
- else
- {
- echo '
- <div style="text-align: center"><h1>Welcome to S32_Admin - UCP</h1>
- <br>
- Here you can register, view your stats, control this UCP...
- <br>
- Thanks to anyone who use this!<br></div>';
- }
- }
- function footer_template()
- {
- global $variables;
- echo '
- S32_Admin - UCP © System32
- <br>All rights reserved
- <br>Page generated for '.$variables['load_time_end'].' seconds';
- }
- function IsUserLogged()
- {
- global $variables;
- if(isset($_SESSION['logged_username_session']) || isset($_COOKIE['logged_username_cookie']))
- {
- $variables['is_logged'] = true;
- return $variables['is_logged'];
- }
- }
- function IsUserAdmin($username, $level)
- {
- global $variables;
- $query = mysql_query("SELECT * FROM `users` WHERE User = '$username'") or die(mysql_error());
- while($row = mysql_fetch_assoc($query))
- {
- $admin = $row['Admin'];
- if($admin >= $level)
- {
- $variables['user_admin'] = true;
- return $variables['user_admin'];
- }
- }
- }
- function ReturnUsername()
- {
- if(isset($_SESSION['logged_username_session'])) return $_SESSION['logged_username_session'];
- else if(isset($_COOKIE['logged_username_cookie'])) return $_COOKIE['logged_username_cookie'];
- }
- function ShowBBCodes($area)
- {
- global $variables;
- $variables['bbcodes'] = array(
- //Bulletin Board Codes
- 'bold' => array(
- 'title' => 'Bold',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'b', 'b')",
- 'img' => 'images/bbc/bold.gif'
- ),
- 'italicize' => array(
- 'title' => 'Italicize',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'i', 'i')",
- 'img' => 'images/bbc/italicize.gif'
- ),
- 'underline' => array(
- 'title' => 'Underline',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'u', 'u')",
- 'img' => 'images/bbc/underline.gif'
- ),
- 'strike' => array(
- 'title' => 'Strike',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 's', 's')",
- 'img' => 'images/bbc/strike.gif',
- 'extra_tags' => '<img style="margin: 0 3px 0 3px;" src="images/bbc/divider.gif">'
- ),
- 'center' => array(
- 'title' => 'Center',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'center', 'center')",
- 'img' => 'images/bbc/center.gif'
- ),
- 'left' => array(
- 'title' => 'Left',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'left', 'left')",
- 'img' => 'images/bbc/left.gif',
- ),
- 'right' => array(
- 'title' => 'Right',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'right', 'right')",
- 'img' => 'images/bbc/right.gif',
- 'extra_tags' => '<img style="margin: 0 3px 0 3px;" src="images/bbc/divider.gif">'
- ),
- 'img' => array(
- 'title' => 'Image',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'img', 'img')",
- 'img' => 'images/bbc/img.gif'
- ),
- 'url' => array(
- 'title' => 'URL',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'url', 'url')",
- 'img' => 'images/bbc/url.gif',
- 'extra_tags' => '<img style="margin: 0 3px 0 3px;" src="images/bbc/divider.gif">'
- ),
- 'sup' => array(
- 'title' => 'Index',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'sup', 'sup')",
- 'img' => 'images/bbc/sup.gif'
- ),
- 'sub' => array(
- 'title' => 'Exponent',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'sub', 'sub')",
- 'img' => 'images/bbc/sub.gif'
- ),
- 'hr' => array(
- 'title' => 'Horizontal Line',
- 'onclick' => "AddText('".$area."', '[hr]')",
- 'img' => 'images/bbc/hr.gif',
- 'extra_tags' => '<br>'
- ),
- 'size' => array(
- 'title' => 'Size',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'size=10pt', 'size')",
- 'img' => 'images/bbc/size.gif'
- ),
- 'font' => array(
- 'title' => 'Font',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'font=arial', 'font')",
- 'img' => 'images/bbc/font.gif'
- ),
- 'color' => array(
- 'title' => 'Color',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'color=black', 'color')",
- 'img' => 'images/bbc/color.gif',
- 'extra_tags' => '<img style="margin: 0 3px 0 3px;" src="images/bbc/divider.gif">'
- ),
- 'glow' => array(
- 'title' => 'Glow',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'glow=5,black', 'glow')",
- 'img' => 'images/bbc/glow.gif'
- ),
- 'shadow' => array(
- 'title' => 'Shadow',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'shadow=5,black', 'shadow')",
- 'img' => 'images/bbc/shadow.gif'
- ),
- 'move' => array(
- 'title' => 'Moving track',
- 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'move', 'move')",
- 'img' => 'images/bbc/move.gif',
- ),
- );
- foreach($variables['bbcodes'] as $name => $bbc)
- {
- echo '
- <a style="cursor: pointer;" id="bbc_'.$name.'" title="'.$bbc['title'].'" onclick="'.$bbc['onclick'].'"><img src="'.$bbc['img'].'"></a>';
- if(isset($bbc['extra_tags'])) echo $bbc['extra_tags'];
- }
- }
- function GetCurrentPageAdress()
- {
- $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
- return $url;
- }
- function SearchResults($keywords)
- {
- global $variables;
- $returned_results = array();
- $where = "";
- $keywords = preg_split('/[\s]+/', $keywords);
- $total_keywords = count($keywords);
- foreach($keywords as $key => $keyword)
- {
- $where .= "`Title` LIKE '%$keyword%' OR `Text` LIKE '%$keyword%'";
- if($key != ($total_keywords) - 1)
- {
- $where .= " AND ";
- }
- }
- $results = "SELECT `Title`, `Text`, `Author` FROM `news` WHERE $where";
- $results_num = ($results = mysql_query($results) or die(mysql_error())) ? mysql_num_rows($results) : 0;
- if($results_num === 0)
- {
- $variables['errors'][] = 'There is no results for word <strong>'.$variables['keywords'].'</strong> !';
- }
- else
- {
- while($row = mysql_fetch_assoc($results))
- {
- $returned_results[] = array(
- 'title' => $row['Title'],
- 'post' => $row['Text'],
- 'author' => $row['Author'],
- );
- }
- }
- return $returned_results;
- }
- function HighlightWords($string, $words)
- {
- foreach ($words as $word)
- {
- $string = str_ireplace($word, '<span class="highlight_word">'.$word.'</span>', $string);
- }
- return $string;
- }
- echo '
- <div id="wrapper">
- <a href="index.php" id="logo"><img src="images/logo.png"></a>
- <div id="toolbar" align="center">' ,toolbar_template(), '</div>
- <div id="content">' ,content_template(), '</div>
- <div id="footer">' ,footer_template(), '</div>
- </div>';
- mysql_close($connect);
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>S32_Admin - UCP</title>
- <link href="index.css" rel="stylesheet" type="text/css" />
- <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
- <script type="text/javascript">
- function isVisible(elem) <!-- not by me :P -->
- {
- var cmpstyle = ('getComputedStyle' in window) ? window.getComputedStyle(elem,null) : elem.currentStyle;
- return (parseFloat(cmpstyle.opacity) > 0 &&
- cmpstyle.visibility != 'hidden' &&
- cmpstyle.display != 'none');
- }
- $(document).keydown(function (e) {
- if(isVisible(parent.document.getElementById("search_users")))
- {
- if(e.keyCode == 13)
- {
- SearchUsers('#search_users_text', '.autosuggest_users', '#search_users_error_report');
- }
- }
- });
- $(document).ready(function() {
- $('.autosuggest_users').keyup(function() {
- var search_users_term = $(this).attr('value');
- $.post('search_users.php', {search_users_term:search_users_term}, function(data) {
- $('.result').html(data);
- $('.result li').click(function() {
- var result_value = $(this).text();
- $('.autosuggest_users').attr('value', result_value);
- $('.result').html('');
- });
- });
- });
- });
- $(document).ready(function(){
- $('#desc div').hide();
- $('#tabs li').click(function(event){
- var id = $(event.target).index();
- $('.activetab').removeClass('activetab');
- $(event.target).addClass('activetab');
- $('#desc div').hide().eq(id).show();
- $('#tabs li').css({'border-bottom':'none', 'height':'17px'});
- $('.autosuggest_users').attr('value', '');
- $('.result').html('');
- });
- $(document).keydown(function (e) {
- if (e.keyCode == 27) {
- $('.activetab').removeClass('activetab');
- $('#desc div').slideUp('slow');
- $('#tabs li').css({'border-bottom':'1px solid #DADADA', 'height':'16px'});
- $('.autosuggest_users').attr('value', '');
- $('.result').html('');
- }
- });
- });
- function SearchUsers(elementtoget, element, error_element)
- {
- var search_value = $(elementtoget).val();
- if(search_value == '')
- {
- $(error_element).css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
- }
- else
- {
- $(error_element).hide();
- var $elem = $('#'+search_value);
- $('html, body').animate({scrollTop: $elem.offset().top}, 1);
- $('#'+search_value).css({'color':'#088cc2'});
- }
- }
- var textarea_created = false;
- var editban_timer = null, add_news_timer = null, add_ban_timer = null, registeruser_timer = null, delete_user_timer = null, delete_ban_timer = null, delete_news_timer = null, edit_news_timer = null, login_user_timer = null;
- function CreateTextarea(element, text, id)
- {
- if(textarea_created == true) return false;
- $(element).empty();
- $(element).append('<div id="edit_ban_error_report" style="border: none;"></div><form method="post" action="post"><textarea style="font-size: 12px;" id="edit_ban_textarea" name="edit_ban_textarea" cols="50" rows="5"></textarea><div align="center" style="border: none; padding-top: 5px; width: 85%;"><input type="button" value="Edit" id="edit_ban_submit" onclick="SubmitEditBanForm(\''+element+'\', \''+id+'\');"> <input type="button" value="Close" onClick="RemoveTextarea(\''+element+'\', \''+text+'\');"></form></div>');
- document.getElementById('edit_ban_textarea').value += text;
- textarea_created = true;
- }
- function RemoveTextarea(element, value)
- {
- $(element).empty();
- $(element).html(value);
- textarea_created = false;
- }
- function SubmitEditBanForm(element_remove_textarea, id)
- {
- var edit_ban_value = $('#edit_ban_textarea').val();
- if(edit_ban_value == '')
- {
- $('#edit_ban_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
- }
- else
- {
- $.ajax({
- type: 'POST',
- url: 'edit_ban.php',
- data: datastr = "edit_ban_textarea=" + edit_ban_value + "&edit_ban_id=" + id,
- success: function(response) {
- $('#edit_ban_error_report').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully add!</center>').show();
- editban_timer = setTimeout('FadeOutBanEdit(\''+element_remove_textarea+'\', \''+response+'\')', 3000);
- }
- });
- }
- }
- function SubmitAddNewsForm(author, date)
- {
- var news_title_value = $('#news_title').val(), news_text_value = $('#news_text').val();
- if(news_title_value == '' || news_text_value == '')
- {
- $('#add_news_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
- }
- else
- {
- $.ajax({
- type: 'POST',
- url: 'add_news.php',
- data: "add_news_title=" + news_title_value + "&add_news_textarea=" + news_text_value + "&add_news_author=" + author + "&add_news_date=" + date,
- success: function(response) {
- $('#add_news_error_report').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully add!</center>').show();
- add_news_timer = setTimeout('FadeOutAddNews()', 3000);
- }
- });
- }
- }
- function SubmitAddBansForm(author)
- {
- var add_bans_username_value = $('#add_bans_username').val(), add_bans_reason_value = $('#add_bans_reason').val(), add_bans_admin_value = "";
- if(add_bans_username_value == '' || add_bans_reason_value == '')
- {
- $('#add_bans_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
- }
- else
- {
- $.ajax({
- type: 'POST',
- url: 'add_bans.php',
- data: "add_bans_username=" + add_bans_username_value + "&add_bans_reason=" + add_bans_reason_value + "&add_bans_author=" + author,
- success: function(response) {
- $('#add_bans_error_report').html(response);
- if(response == '1')
- {
- $('#add_bans_error_report').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully add!</center>').show();
- addnews_timer = setTimeout('FadeOutAddBans()', 3000);
- }
- else if(response == '2')
- {
- $('#add_bans_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>Username doesn\'t exist!</center>').show();
- }
- else if(response == '3')
- {
- $('#add_bans_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>User is already banned!</center>').show();
- }
- }
- });
- }
- }
- function SubmitRegisterUserForm()
- {
- var register_user_username_value = $('#register_user_username').val(), register_user_password_value = $('#register_user_password').val(), register_user_repeat_password_value = $('#register_user_repeat_password').val(), register_user_admin_level_value = "";
- $("select option:selected").each(function () {
- register_user_admin_level_value += $(this).text() + " ";
- });
- if(register_user_username_value == '' || register_user_password_value == '' || register_user_repeat_password_value == '')
- {
- $('#register_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
- }
- else if(register_user_password_value != register_user_repeat_password_value)
- {
- $('#register_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>Passwords are not the same!</center>').show();
- }
- else if($('select').val() == "Admin level")
- {
- $('#register_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please select admin level!</center>').show();
- }
- else
- {
- $.ajax({
- type: 'POST',
- url: 'register_user.php',
- data: "register_user_username=" + register_user_username_value + "®ister_user_password=" + register_user_password_value + "®ister_user_admin_level=" + register_user_admin_level_value,
- success: function(response) {
- $('#register_user_error_report').html(response);
- if(response == '1')
- {
- $('#register_user_error_report').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully add!</center>');
- registeruser_timer = setTimeout('FadeOutRegisterUser()', 3000).show();
- }
- else if(response == '2')
- {
- $('#register_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>User alerady exist!</center>').show();
- }
- }
- });
- }
- }
- function SubmitDeleteUserForm()
- {
- var delete_username_value = $('#delete_username').val();
- if(delete_username_value == '')
- {
- $('#delete_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
- }
- else
- {
- $.ajax({
- type: 'POST',
- url: 'delete_user.php',
- data: "delete_username=" + delete_username_value,
- success: function(response) {
- $('#delete_user_error_report').html(response);
- if(response == '1')
- {
- $('#delete_user_error_report').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully deleted!</center>').show();
- delete_user_timer = setTimeout('FadeOutDeleteUser()', 3000);
- }
- else if(response == '2')
- {
- $('#delete_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'width': '83.5%', 'background':'#F2BCBD', 'color':'white'}).html('<center>User doesn\'t exist!</center>').show();
- }
- }
- });
- }
- }
- function DeleteBanForm(id)
- {
- $.ajax({
- type: 'POST',
- url: 'delete_ban.php',
- data: "delete_ban_id=" + id,
- success: function(response)
- {
- $('#delete_ban_'+ id +'').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '98.8%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully deleted!</center>').show();
- delete_ban_timer = setTimeout('FadeOutDeleteBan(\''+ id + '\')', 3000);
- }
- });
- }
- function DeleteNewsForm(id)
- {
- $.ajax({
- type: 'POST',
- url: 'delete_news.php',
- data: "delete_news_id=" + id,
- success: function(response)
- {
- $('#delete_news_'+ id +'').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '98.8%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully deleted!</center>').show();
- delete_news_timer = setTimeout('FadeOutDeleteNews(\''+ id + '\')', 3000);
- }
- });
- }
- function SubmitEditNewsForm(id, date)
- {
- var edit_news_title_value = $('#edit_news_title').val(), edit_news_text_value = $('#edit_news_text').val();
- if(edit_news_title_value == '' || edit_news_text_value == '')
- {
- $('#edit_news_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
- }
- else
- {
- $.ajax({
- type: 'POST',
- url: 'edit_news.php',
- data: "edit_news_title=" + edit_news_title_value + "&edit_news_text=" + edit_news_text_value + "&edit_news_id=" + id + "&edit_news_date=" + date,
- success: function(response)
- {
- $('#edit_news_error_report').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '98.8%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully edited!</center>').show();
- edit_news_timer = setTimeout('FadeOutEditNews()', 3000);
- }
- });
- }
- }
- function SubmitLoginUser()
- {
- var login_username_value = $('#login_username').val(), login_password_value = $('#login_password').val(), login_rembme_value = null;
- if($('#login_rembme').is(':checked')) login_rembme_value = '1';
- else login_rembme_value = '0';
- if(login_username_value == '' || login_password_value == '')
- {
- $('#login_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
- }
- else
- {
- $.ajax({
- type: 'POST',
- url: 'login_user.php',
- data: "login_username=" + login_username_value + "&login_password=" + login_password_value + "&login_rembme=" + login_rembme_value,
- success: function(response)
- {
- $('#login_user_error_report').html(response);
- if(response == '1')
- {
- $('#login_user_error_report').css({'border':'1px solid #098fc7', 'padding':'5px 5px 5px 5px', 'width': '98.8%', 'background':'#94ddfb', 'color':'white'}).html('<center>Successfully logged in!</center>').show();
- login_user_timer = setTimeout('FadeOutLoginUser()', 3000);
- }
- else if(response == '2')
- {
- $('#login_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'background':'#F2BCBD', 'color':'white'}).html('<center>Username doesn\'t exist!</center>').show();
- }
- else if(response == '3')
- {
- $('#login_user_error_report').css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'background':'#F2BCBD', 'color':'white'}).html('<center>Password is not correct!</center>').show();
- }
- }
- });
- }
- }
- function FadeOutBanEdit(element_remove_textarea, response)
- {
- location.reload(true);
- RemoveTextarea(element_remove_textarea, response);
- clearTimeout(editban_timer);
- }
- function FadeOutAddNews()
- {
- $('#add_news_error_report').fadeOut('slow');
- window.location = "index.php?action=news";
- clearTimeout(add_news_timer);
- }
- function FadeOutAddBans()
- {
- $('#add_bans_error_report').fadeOut('slow');
- $('.activetab').removeClass('activetab');
- $('#desc div').slideUp('slow');
- $('#tabs li').css({'border-bottom':'1px solid #DADADA', 'height':'16px'});
- $('#add_bans_username').val('');
- $('#add_bans_reason').val('');
- clearTimeout(addnews_timer);
- }
- function FadeOutRegisterUser()
- {
- $('#register_user_error_report').fadeOut('slow');
- $('.activetab').removeClass('activetab');
- $('#desc div').slideUp('slow');
- $('#tabs li').css({'border-bottom':'1px solid #DADADA', 'height':'16px'});
- $('#register_user_username').val('');
- $('#register_user_password').val('');
- $('#register_user_repeat_password').val('');
- clearTimeout(registeruser_timer);
- }
- function FadeOutDeleteUser()
- {
- $('#register_user_error_report').fadeOut('slow');
- $('.activetab').removeClass('activetab');
- $('#desc div').slideUp('slow');
- $('#tabs li').css({'border-bottom':'1px solid #DADADA', 'height':'16px'});
- $('#delete_username').val('');
- clearTimeout(delete_user_timer);
- }
- function FadeOutDeleteBan(id)
- {
- $('#delete_ban_'+ id +'').fadeOut('slow');
- location.reload(true);
- clearTimeout(delete_ban_timer);
- }
- function FadeOutDeleteNews(id)
- {
- $('#delete_news_'+ id +'').fadeOut('slow');
- location.reload(true);
- clearTimeout(delete_news_timer);
- }
- function FadeOutEditNews()
- {
- $('#edit_news_error_report').fadeOut('slow');
- window.location = "index.php?action=news";
- clearTimeout(edit_news_timer);
- }
- function FadeOutLoginUser()
- {
- $('#login_user_error_report').fadeOut('slow');
- window.location = "index.php";
- clearTimeout(login_user_timer);
- }
- function PreviewPost(element, value)
- {
- var preview_value = $(value).val();
- $.ajax({
- type: 'POST',
- url: 'preview_post.php',
- data: 'preview_post=' + preview_value,
- success: function(response)
- {
- $(element).css({'border':'1px solid #ddd', 'background':'#ededed', 'padding':'10px', 'border-radius':'10px', 'margin-bottom':'10px', 'overflow':'auto'}).html(response).show();
- }
- });
- }
- function ApplyTag(obj, first_tag, last_tag) <!-- not by me :P -->
- {
- WrapText(obj, '['+first_tag+']', '[/'+last_tag+']');
- }
- function WrapText(obj, beginTag, endTag) <!-- not by me :P -->
- {
- if(typeof obj.selectionStart == 'number')
- {
- var start = obj.selectionStart;
- var end = obj.selectionEnd;
- obj.value = obj.value.substring(0, start) + beginTag + obj.value.substring(start, end) + endTag + obj.value.substring(end, obj.value.length);
- }
- else if(document.selection)
- {
- obj.focus();
- var range = document.selection.createRange();
- if(range.parentElement() != obj) return false;
- if(typeof range.text == 'string') document.selection.createRange().text = beginTag + range.text + endTag;
- }
- else obj.value += text;
- }
- function AddText(input, text) <!-- not by me :P -->
- {
- document.getElementById(input).value += text;
- }
- function SlideElement(element, speed)
- {
- $(element).slideToggle(speed);
- }
- </script>
- </head>
- <body>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement