Advertisement
Guest User

Untitled

a guest
Sep 16th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.13 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6. <?php
  7.  
  8. include('connect.php');
  9. session_start();
  10. //Let's make page as UTF-8 character set
  11. mb_internal_encoding('UTF-8');
  12. mb_http_output('UTF-8');
  13. mb_http_input('UTF-8');
  14. mb_language('uni');
  15. mb_regex_encoding('UTF-8');
  16. ob_start('mb_output_handler');
  17.  
  18. $scripturl = 'http://zapperhosting.byethost14.com/s32ucp/index.php'; ///must be index.php at the end
  19. $variables['date'] = date("d.m.Y");
  20.  
  21. $variables['load_time_start'] = microtime(true);
  22. $y = 0;
  23. for($x = 0; $x <= 1000000; $x++)
  24. {
  25. $y = $x;
  26. $y *= pi();
  27. $y *= (pi() * 2);
  28. }
  29. $variables['load_time_end'] = number_format((microtime(true) - $variables['load_time_start']), 2);
  30.  
  31. if(isset($_POST['keywords']))
  32. {
  33. $variables['keywords'] = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
  34.  
  35. $variables['errors'] = array();
  36.  
  37. if(empty($variables['keywords']))
  38. {
  39. $variables['errors'][] = 'Please enter query!';
  40. }
  41. else if(strlen($variables['keywords']) < 3)
  42. {
  43. $variables['errors'][] = 'Length must be at leaset 3 characters';
  44. }
  45. else if(SearchResults($variables['keywords']) === false)
  46. {
  47. $variables['errors'][] = 'No result found for keyword'.' <strong>'.$variables['keywords'].'</strong> !';
  48. }
  49. }
  50.  
  51. function toolbar_template()
  52. {
  53. global $variables, $scripturl;
  54. $variables['buttons'] = array(
  55. 'home' => array(
  56. 'title' => 'Home',
  57. 'href' => $scripturl,
  58. 'show' => true
  59. ),
  60. 'news' => array(
  61. 'title' => 'News',
  62. 'href' => $scripturl . '?action=news',
  63. 'show' => true
  64. ),
  65. 'search' => array(
  66. 'title' => 'Search',
  67. 'href' => $scripturl . '?action=search',
  68. 'show' => true
  69. ),
  70. 'admin' => array(
  71. 'title' => 'Admin',
  72. 'href' => $scripturl . '?action=admin',
  73. 'show' => IsUserAdmin(ReturnUsername(), 1)
  74. ),
  75. 'logout' => array(
  76. 'title' => 'Logout',
  77. 'href' => $scripturl . '?action=logout',
  78. 'show' => IsUserLogged()
  79. ),
  80. 'login' => array(
  81. 'title' => 'Login',
  82. 'href' => $scripturl . '?action=login',
  83. 'show' => !IsUserLogged()
  84. ),
  85. );
  86. $menu_buttons = array();
  87. foreach ($variables['buttons'] as $act => $button)
  88. {
  89. if (!empty($button['show']))
  90. {
  91. $button['active_button'] = false;
  92. $menu_buttons[$act] = $button;
  93. }
  94. }
  95. $variables['menu_buttons'] = $menu_buttons;
  96.  
  97. echo '
  98. <ul id="topnav">';
  99.  
  100. foreach ($variables['menu_buttons'] as $act => $button)
  101. {
  102. if(GetCurrentPageAdress() == $button['href']) $button['active_button'] = true;
  103. echo '
  104. <li id="button_', $act, '">';
  105.  
  106. if($button['active_button'] == true) { echo ' <a class="active" href="' .$button['href']. '">'.$button['title'].'</a>'; }
  107. else echo '
  108. <a href="' .$button['href']. '">'.$button['title'].'</a>
  109. </li>';
  110. }
  111.  
  112. echo '
  113. </ul>';
  114. }
  115.  
  116. function content_template()
  117. {
  118. global $variables;
  119. if(isset($_GET['action']))
  120. {
  121. if($_GET['action'] == 'login')
  122. {
  123. if(IsUserLogged()) header('location: index.php');
  124. echo '
  125. <div align="center">';
  126. ?>
  127. <p id="login_user_error_report1"></p>
  128. <p id="login_user_error_report"></p>
  129. <form action="post" method="post">
  130. <input type="text" maxlength="25" name="login_username" id="login_username" placeholder="Username"><br><br>
  131. <input type="password" name="login_password" id="login_password" placeholder="Password"><br><br>
  132. <input type="checkbox" name="login_rembme" id="login_rembme"> Remember me<br><br>
  133. <input type="button" onClick="SubmitLoginUser()" value="Login">
  134. </form>
  135. <?php
  136. echo '
  137. </div>';
  138. }
  139. if($_GET['action'] == 'logout')
  140. {
  141. if(!IsUserLogged()) header('location: index.php');
  142. setcookie("logged_username_cookie", "", time() - (60 * 60 * 24 * 365 * 5));
  143. unset($_SESSION['logged_username_session']);
  144. header('location: index.php');
  145. }
  146. if($_GET['action'] == 'admin')
  147. {
  148. if(!IsUserAdmin(ReturnUsername(), 1)) header('location: index.php');
  149. echo '
  150. <div align="center">';
  151. echo '
  152. <div id="tabs">
  153. <ul>
  154. <li>Add News</li>
  155. <li>Ban User</li>
  156. <li>Delete User</li>
  157. <li>Register User</li>
  158. <li>View Bans</li>
  159. <li>View Users</li>
  160. </ul>
  161. </div>
  162. <div id="desc">
  163. <div>';
  164. ?>
  165. <p id="add_news_preview" align="left"></p>
  166. <p id="add_news_error_report"></p>
  167. <form method="post" action="post">
  168. <input type="text" id="news_title" name="news_title" maxlength="20" size="60" placeholder="Title"><br><br>
  169. <?php ShowBBCodes('news_text'); ?><br>
  170. <textarea cols="152" rows="10" id="news_text" name="news_text" placeholder="Text"></textarea><br><br>
  171. <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">
  172. </form>
  173. <?php
  174. echo '
  175. </div>
  176. <div>';
  177. ?>
  178. <p id="add_bans_error_report"></p>
  179. <form method="post" action="post">
  180. <input type="text" name="add_bans_username" id="add_bans_username" style="width: 158px;" class="autosuggest_users" placeholder="Player name">
  181. <ul class="result"></ul>
  182. <br><br>
  183. <textarea name="add_bans_reason" id="add_bans_reason" cols="50" rows="5" placeholder="Reason"></textarea><br><br>
  184. <input type="button" onClick="SubmitAddBansForm('<?php echo ReturnUsername(); ?>')" value="Ban">
  185. </form>
  186. <?php
  187. echo'
  188. </div>
  189. <div>';
  190. ?>
  191. <p id="delete_user_error_report"></p>
  192. <form method="post" action="post">
  193. <input type="text" name="delete_username" id="delete_username" style="width: 158px;" class="autosuggest_users" placeholder="Player name">
  194. <ul class="result"></ul>
  195. <br><br>
  196. <input type="button" onClick="SubmitDeleteUserForm()" value="Delete">
  197. </form>
  198. <?php
  199. echo '
  200. </div>
  201. <div>';
  202. ?>
  203. <p id="register_user_error_report"></p>
  204. <form method="post" action="post">
  205. <input type="text" name="register_user_username" id="register_user_username" maxlength="24" placeholder="Player name"><br><br>
  206. <input type="password" name="register_user_password" id="register_user_password" placeholder="Password"><br><br>
  207. <input type="password" name="register_user_repeat_password" id="register_user_repeat_password" placeholder="Repeat password"><br><br>
  208. <select name="register_user_admin_level">
  209. <option selected="selected">Admin level</option>
  210. <option>0</option>
  211. <option>1</option>
  212. <option>2</option>
  213. <option>3</option>
  214. </select><br><br>
  215. <input type="button" onClick="SubmitRegisterUserForm()" value="Register">
  216. </form>
  217. <?php
  218. echo '
  219. </div>
  220. <div align="left">';
  221. $num = 1;
  222. $query = mysql_query("SELECT * FROM `bans`") or die(mysql_error());
  223. if(mysql_num_rows($query) >= 1)
  224. {
  225. while($row = mysql_fetch_assoc($query))
  226. {
  227. echo '
  228. <p id="delete_ban_'.$row['ID'].'"></p>
  229. <table cellpadding="0" cellspacing="5" border="0">
  230. <tbody>
  231. <tr>
  232. <td id="counter">'.$num.'</td>
  233. <td><em>'.$row['Banned'].'</em> banned by <strong>'.$row['Administrator'].'</strong><br>';
  234. ?>
  235. <a onClick="DeleteBanForm(<?php echo $row['ID']; ?>)" title="Delete ban!"><img style="padding-top: 3px;" src="images/delete.png"></a>
  236. <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>
  237. <?php
  238. echo '
  239. </td>
  240. </tr>
  241. </tbody>
  242. </table>
  243. <p id="addnews_separator"></p>
  244. <p style="padding: 7px; font-size: 18px; width: 41%; margin: 0" id="ban_reason_'.$row['ID'].'">'.$row['Reason'].'</p>
  245. <p id="bans_separator"></p>';
  246. $num ++;
  247. }
  248. }
  249. else echo '<h2>No existing bans!</h2>';
  250. echo '
  251. </div>
  252. <div id="search_users">';
  253. ?>
  254. <p id="search_users_error_report"></p>
  255. <p align="center">
  256. <input type="text" id="search_users_text" class="autosuggest_users" style="width: 158px;" placeholder="Player name">
  257. <ul class="result"></ul>
  258. </p>
  259. <?php
  260. $query = mysql_query("SELECT * FROM `users`") or die(mysql_error());
  261. if(mysql_num_rows($query) >= 1)
  262. {
  263. while($row = mysql_fetch_assoc($query))
  264. {
  265. echo '
  266. <h2 id="'.$row['User'].'">'.$row['User'].'</h2>
  267. <table cellpadding="0" cellspacing="5" border="0">
  268. <tbody>
  269. <tr>
  270. <td>Money: '.$row['Money'].'</td><td style="padding-left: 15px;">Score: '.$row['Score'].'</td>
  271. </tr>
  272. <tr>
  273. <td>Kills: '.$row['Kills'].'</td><td style="padding-left: 15px;">Deaths: '.$row['Deaths'].'</td>
  274. </tr>
  275. <tr>
  276. <td>Admin: '.$row['Admin'].'</td><td style="padding-left: 15px;">Warns: '.$row['Warns'].'</td>
  277. </tr>
  278. </tbody>
  279. </table><br>
  280. <p id="view_user_separator"></p>';
  281. }
  282. }
  283. else echo '<h2>Currently no users!</h2>';
  284. echo '
  285. </div>
  286. </div>
  287. <div id="addnews_separator" style="padding-top: 8px;"></div>
  288. </div>
  289. <br><p class="admin_message_hi">Hi ',ReturnUsername(),'!
  290. <br>
  291. This is your admin control panel, please choose on of the actions in the tab list
  292. <br>
  293. and press ESC if you want to hide tab!</p>';
  294. }
  295. if($_GET['action'] == 'news')
  296. {
  297. $num = 1;
  298. $query = mysql_query("SELECT * FROM `news`") or die(mysql_error());
  299. echo '
  300. <div align="left">';
  301. if(mysql_num_rows($query) >= 1)
  302. {
  303. while($row = mysql_fetch_assoc($query))
  304. {
  305. echo '
  306. <p id="delete_news_'.$row['ID'].'"></p>
  307. <table cellpadding="0" cellspacing="5" border="0">
  308. <tbody>
  309. <tr>
  310. <td id="counter">'.$num.'</td>
  311. <td><em>'.$row['Title'].'</em><br>
  312. Date: '.$row['Date'].'';
  313. if($row['Update'] != 'Never') echo '
  314. <em style="color: orange;"> | Last update: '.$row['Update'].'</em>';
  315. if(IsUserAdmin(ReturnUsername(), 1))
  316. {
  317. ?>
  318. <br>
  319. <a onClick="DeleteNewsForm(<?php echo $row['ID']; ?>)" title="Delete news!"><img style="padding-top: 3px;" src="images/delete.png"></a>
  320. <a href="index.php?action=editnews&id=<?php echo $row['ID']; ?>" style="padding-left: 5px;" title="Edit news!"><img src="images/edit.png"></a>
  321. <?php
  322. }
  323. echo '
  324. </td>
  325. </tr>
  326. </tbody>
  327. </table>
  328. <p id="addnews_separator"></p>
  329. <p style="padding: 7px; margin: 0" id="ban_reason_'.$row['ID'].'">'.BBCode($row['Text']).'</p>
  330. <p id="bans_separator"></p>';
  331. $num ++;
  332. }
  333. }
  334. else echo '<h2>No existing bans!</h2>';
  335. echo '
  336. </div>';
  337. }
  338. if($_GET['action'] == 'editnews')
  339. {
  340. $query = mysql_query("SELECT * FROM `news` WHERE ID = '".$_GET['id']."'") or die(mysql_error());
  341. if(mysql_num_rows($query) == 1)
  342. {
  343. while($row = mysql_fetch_assoc($query))
  344. {
  345. echo '
  346. <div id="edit_news_preview"></div>
  347. <div id="edit_news_error_report"></div>
  348. <div align="center">';
  349. ?>
  350. <input type="text" size="60" name="edit_news_title" id="edit_news_title" value="<?php echo $row['Title']; ?>"><br><br>
  351. <?php echo ShowBBCodes('edit_news_text'); ?>
  352. <textarea cols="154" rows="10" name="edit_news_text" id="edit_news_text"><?php echo $row['Text']; ?></textarea><br><br>
  353. <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">
  354. <?php
  355. echo '
  356. </div>';
  357. }
  358. }
  359. else echo '
  360. <h2 style="text-align: center; text-shadow: 1px 1px 0 white;">News doesn\'t exist!</div>';
  361. }
  362. if($_GET['action'] == 'search')
  363. {
  364. echo '
  365. <div align="center">';
  366. ?>
  367. <form action="index.php?action=search" method="post">
  368. <input type="text" size="70" speellchec="false" name="keywords" placeholder="Enter text"><br><br>
  369. <input type="submit" name="search_submit" value="Search">
  370. </form>
  371. <?php
  372. echo '
  373. </div>';
  374. if(isset($_POST['search_submit']))
  375. {
  376. echo '
  377. <p id="addnews_separator"></p>';
  378. if(!isset($variables['keywords']))
  379. {
  380. echo '
  381. <div id="error">Please enter query!</div>';
  382. return;
  383. }
  384. if(empty($variables['errors']))
  385. {
  386. $num = 0;
  387. $results = SearchResults($variables['keywords']);
  388. $results_num = count($results);
  389. $suffix = ($results_num != 1) ? 's' : '';
  390.  
  391. echo '
  392. <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>';
  393. foreach($results as $result)
  394. {
  395. $num ++;
  396. $string = $result['post'];
  397. $words = array($variables['keywords']);
  398. $string = BBCode($string);
  399. $string = HighlightWords($string, $words);
  400.  
  401. $string1 = $result['title'];
  402. $words = array($variables['keywords']);
  403. $string1 = HighlightWords($string1, $words);
  404. echo '
  405. <br>
  406. <div style="font-size: 13px; text-shadow: 1px 1px 0 white;">
  407. <div style="text-align: left;">
  408. <table cellpadding="0" cellspacing="10" border="0">
  409. <tbody>
  410. <tr>
  411. <td>
  412. <div class="search_counter">'.$num.'</div>
  413. </td>
  414. <td>
  415. <h5 style="margin: 0; padding: 0; font-size: 15px;">'.$string1.'</h5>
  416. <em style="font-size: 13px;">'.$result['author'].'</em>
  417. </td>
  418. </tr>
  419. </tbody>
  420. </table>
  421. </div>
  422. <br>
  423. <p id="addnews_separator"></p>
  424. <p style="text-align: left; margin-left: 2%;">'.$string.'</p>
  425. </div>
  426. <div id="bans_separator" style="margin-left: 0; width: 100%;"></div>';
  427. }
  428. }
  429. else
  430. {
  431. foreach($variables['errors'] as $error)
  432. {
  433. echo '
  434. <div id="error">'.$error.'</div>';
  435. }
  436. }
  437. }
  438. }
  439. }
  440. else
  441. {
  442. echo '
  443. <div style="text-align: center"><h1>Welcome to S32_Admin - UCP</h1>
  444. <br>
  445. Here you can register, view your stats, control this UCP...
  446. <br>
  447. Thanks to anyone who use this!<br></div>';
  448. }
  449. }
  450.  
  451. function footer_template()
  452. {
  453. global $variables;
  454. echo '
  455. S32_Admin - UCP © System32
  456. <br>All rights reserved
  457. <br>Page generated for '.$variables['load_time_end'].' seconds';
  458. }
  459.  
  460. function IsUserLogged()
  461. {
  462. global $variables;
  463. if(isset($_SESSION['logged_username_session']) || isset($_COOKIE['logged_username_cookie']))
  464. {
  465. $variables['is_logged'] = true;
  466. return $variables['is_logged'];
  467. }
  468. }
  469.  
  470. function IsUserAdmin($username, $level)
  471. {
  472. global $variables;
  473. $query = mysql_query("SELECT * FROM `users` WHERE User = '$username'") or die(mysql_error());
  474. while($row = mysql_fetch_assoc($query))
  475. {
  476. $admin = $row['Admin'];
  477. if($admin >= $level)
  478. {
  479. $variables['user_admin'] = true;
  480. return $variables['user_admin'];
  481. }
  482. }
  483. }
  484.  
  485. function ReturnUsername()
  486. {
  487. if(isset($_SESSION['logged_username_session'])) return $_SESSION['logged_username_session'];
  488. else if(isset($_COOKIE['logged_username_cookie'])) return $_COOKIE['logged_username_cookie'];
  489. }
  490.  
  491. function ShowBBCodes($area)
  492. {
  493. global $variables;
  494. $variables['bbcodes'] = array(
  495. //Bulletin Board Codes
  496. 'bold' => array(
  497. 'title' => 'Bold',
  498. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'b', 'b')",
  499. 'img' => 'images/bbc/bold.gif'
  500. ),
  501. 'italicize' => array(
  502. 'title' => 'Italicize',
  503. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'i', 'i')",
  504. 'img' => 'images/bbc/italicize.gif'
  505. ),
  506. 'underline' => array(
  507. 'title' => 'Underline',
  508. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'u', 'u')",
  509. 'img' => 'images/bbc/underline.gif'
  510. ),
  511. 'strike' => array(
  512. 'title' => 'Strike',
  513. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 's', 's')",
  514. 'img' => 'images/bbc/strike.gif',
  515. 'extra_tags' => '<img style="margin: 0 3px 0 3px;" src="images/bbc/divider.gif">'
  516. ),
  517. 'center' => array(
  518. 'title' => 'Center',
  519. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'center', 'center')",
  520. 'img' => 'images/bbc/center.gif'
  521. ),
  522. 'left' => array(
  523. 'title' => 'Left',
  524. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'left', 'left')",
  525. 'img' => 'images/bbc/left.gif',
  526. ),
  527. 'right' => array(
  528. 'title' => 'Right',
  529. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'right', 'right')",
  530. 'img' => 'images/bbc/right.gif',
  531. 'extra_tags' => '<img style="margin: 0 3px 0 3px;" src="images/bbc/divider.gif">'
  532. ),
  533. 'img' => array(
  534. 'title' => 'Image',
  535. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'img', 'img')",
  536. 'img' => 'images/bbc/img.gif'
  537. ),
  538. 'url' => array(
  539. 'title' => 'URL',
  540. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'url', 'url')",
  541. 'img' => 'images/bbc/url.gif',
  542. 'extra_tags' => '<img style="margin: 0 3px 0 3px;" src="images/bbc/divider.gif">'
  543. ),
  544. 'sup' => array(
  545. 'title' => 'Index',
  546. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'sup', 'sup')",
  547. 'img' => 'images/bbc/sup.gif'
  548. ),
  549. 'sub' => array(
  550. 'title' => 'Exponent',
  551. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'sub', 'sub')",
  552. 'img' => 'images/bbc/sub.gif'
  553. ),
  554. 'hr' => array(
  555. 'title' => 'Horizontal Line',
  556. 'onclick' => "AddText('".$area."', '[hr]')",
  557. 'img' => 'images/bbc/hr.gif',
  558. 'extra_tags' => '<br>'
  559. ),
  560. 'size' => array(
  561. 'title' => 'Size',
  562. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'size=10pt', 'size')",
  563. 'img' => 'images/bbc/size.gif'
  564. ),
  565. 'font' => array(
  566. 'title' => 'Font',
  567. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'font=arial', 'font')",
  568. 'img' => 'images/bbc/font.gif'
  569. ),
  570. 'color' => array(
  571. 'title' => 'Color',
  572. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'color=black', 'color')",
  573. 'img' => 'images/bbc/color.gif',
  574. 'extra_tags' => '<img style="margin: 0 3px 0 3px;" src="images/bbc/divider.gif">'
  575. ),
  576. 'glow' => array(
  577. 'title' => 'Glow',
  578. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'glow=5,black', 'glow')",
  579. 'img' => 'images/bbc/glow.gif'
  580. ),
  581. 'shadow' => array(
  582. 'title' => 'Shadow',
  583. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'shadow=5,black', 'shadow')",
  584. 'img' => 'images/bbc/shadow.gif'
  585. ),
  586. 'move' => array(
  587. 'title' => 'Moving track',
  588. 'onclick' => "ApplyTag(document.getElementById('".$area."'), 'move', 'move')",
  589. 'img' => 'images/bbc/move.gif',
  590. ),
  591. );
  592. foreach($variables['bbcodes'] as $name => $bbc)
  593. {
  594. echo '
  595. <a style="cursor: pointer;" id="bbc_'.$name.'" title="'.$bbc['title'].'" onclick="'.$bbc['onclick'].'"><img src="'.$bbc['img'].'"></a>';
  596. if(isset($bbc['extra_tags'])) echo $bbc['extra_tags'];
  597. }
  598. }
  599.  
  600. function GetCurrentPageAdress()
  601. {
  602. $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  603. return $url;
  604. }
  605.  
  606. function SearchResults($keywords)
  607. {
  608. global $variables;
  609. $returned_results = array();
  610. $where = "";
  611. $keywords = preg_split('/[\s]+/', $keywords);
  612. $total_keywords = count($keywords);
  613. foreach($keywords as $key => $keyword)
  614. {
  615. $where .= "`Title` LIKE '%$keyword%' OR `Text` LIKE '%$keyword%'";
  616. if($key != ($total_keywords) - 1)
  617. {
  618. $where .= " AND ";
  619. }
  620. }
  621. $results = "SELECT `Title`, `Text`, `Author` FROM `news` WHERE $where";
  622. $results_num = ($results = mysql_query($results) or die(mysql_error())) ? mysql_num_rows($results) : 0;
  623.  
  624. if($results_num === 0)
  625. {
  626. $variables['errors'][] = 'There is no results for word <strong>'.$variables['keywords'].'</strong> !';
  627. }
  628. else
  629. {
  630. while($row = mysql_fetch_assoc($results))
  631. {
  632. $returned_results[] = array(
  633. 'title' => $row['Title'],
  634. 'post' => $row['Text'],
  635. 'author' => $row['Author'],
  636. );
  637. }
  638. }
  639. return $returned_results;
  640. }
  641.  
  642. function HighlightWords($string, $words)
  643. {
  644. foreach ($words as $word)
  645. {
  646. $string = str_ireplace($word, '<span class="highlight_word">'.$word.'</span>', $string);
  647. }
  648. return $string;
  649. }
  650.  
  651. echo '
  652. <div id="wrapper">
  653. <a href="index.php" id="logo"><img src="images/logo.png"></a>
  654. <div id="toolbar" align="center">' ,toolbar_template(), '</div>
  655. <div id="content">' ,content_template(), '</div>
  656. <div id="footer">' ,footer_template(), '</div>
  657. </div>';
  658.  
  659. mysql_close($connect);
  660.  
  661. ?>
  662.  
  663. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  664. <html xmlns="http://www.w3.org/1999/xhtml">
  665. <head>
  666. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  667. <title>S32_Admin - UCP</title>
  668. <link href="index.css" rel="stylesheet" type="text/css" />
  669. <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
  670. <script type="text/javascript">
  671. function isVisible(elem) <!-- not by me :P -->
  672. {
  673. var cmpstyle = ('getComputedStyle' in window) ? window.getComputedStyle(elem,null) : elem.currentStyle;
  674. return (parseFloat(cmpstyle.opacity) > 0 &&
  675. cmpstyle.visibility != 'hidden' &&
  676. cmpstyle.display != 'none');
  677. }
  678. $(document).keydown(function (e) {
  679. if(isVisible(parent.document.getElementById("search_users")))
  680. {
  681. if(e.keyCode == 13)
  682. {
  683. SearchUsers('#search_users_text', '.autosuggest_users', '#search_users_error_report');
  684. }
  685. }
  686. });
  687. $(document).ready(function() {
  688. $('.autosuggest_users').keyup(function() {
  689. var search_users_term = $(this).attr('value');
  690. $.post('search_users.php', {search_users_term:search_users_term}, function(data) {
  691. $('.result').html(data);
  692. $('.result li').click(function() {
  693. var result_value = $(this).text();
  694. $('.autosuggest_users').attr('value', result_value);
  695. $('.result').html('');
  696. });
  697. });
  698. });
  699. });
  700. $(document).ready(function(){
  701. $('#desc div').hide();
  702. $('#tabs li').click(function(event){
  703. var id = $(event.target).index();
  704. $('.activetab').removeClass('activetab');
  705. $(event.target).addClass('activetab');
  706. $('#desc div').hide().eq(id).show();
  707. $('#tabs li').css({'border-bottom':'none', 'height':'17px'});
  708. $('.autosuggest_users').attr('value', '');
  709. $('.result').html('');
  710. });
  711. $(document).keydown(function (e) {
  712. if (e.keyCode == 27) {
  713. $('.activetab').removeClass('activetab');
  714. $('#desc div').slideUp('slow');
  715. $('#tabs li').css({'border-bottom':'1px solid #DADADA', 'height':'16px'});
  716. $('.autosuggest_users').attr('value', '');
  717. $('.result').html('');
  718. }
  719. });
  720. });
  721. function SearchUsers(elementtoget, element, error_element)
  722. {
  723. var search_value = $(elementtoget).val();
  724. if(search_value == '')
  725. {
  726. $(error_element).css({'border':'1px solid #F00', 'padding':'5px 5px 5px 5px', 'background':'#F2BCBD', 'color':'white'}).html('<center>Please fill the form!</center>').show();
  727. }
  728. else
  729. {
  730. $(error_element).hide();
  731. var $elem = $('#'+search_value);
  732. $('html, body').animate({scrollTop: $elem.offset().top}, 1);
  733. $('#'+search_value).css({'color':'#088cc2'});
  734. }
  735. }
  736. var textarea_created = false;
  737. 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;
  738. function CreateTextarea(element, text, id)
  739. {
  740. if(textarea_created == true) return false;
  741. $(element).empty();
  742. $(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>');
  743. document.getElementById('edit_ban_textarea').value += text;
  744. textarea_created = true;
  745. }
  746. function RemoveTextarea(element, value)
  747. {
  748. $(element).empty();
  749. $(element).html(value);
  750. textarea_created = false;
  751. }
  752. function SubmitEditBanForm(element_remove_textarea, id)
  753. {
  754. var edit_ban_value = $('#edit_ban_textarea').val();
  755. if(edit_ban_value == '')
  756. {
  757. $('#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();
  758. }
  759. else
  760. {
  761. $.ajax({
  762. type: 'POST',
  763. url: 'edit_ban.php',
  764. data: datastr = "edit_ban_textarea=" + edit_ban_value + "&edit_ban_id=" + id,
  765. success: function(response) {
  766. $('#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();
  767. editban_timer = setTimeout('FadeOutBanEdit(\''+element_remove_textarea+'\', \''+response+'\')', 3000);
  768. }
  769. });
  770. }
  771. }
  772. function SubmitAddNewsForm(author, date)
  773. {
  774. var news_title_value = $('#news_title').val(), news_text_value = $('#news_text').val();
  775. if(news_title_value == '' || news_text_value == '')
  776. {
  777. $('#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();
  778. }
  779. else
  780. {
  781. $.ajax({
  782. type: 'POST',
  783. url: 'add_news.php',
  784. data: "add_news_title=" + news_title_value + "&add_news_textarea=" + news_text_value + "&add_news_author=" + author + "&add_news_date=" + date,
  785. success: function(response) {
  786. $('#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();
  787. add_news_timer = setTimeout('FadeOutAddNews()', 3000);
  788. }
  789. });
  790. }
  791. }
  792. function SubmitAddBansForm(author)
  793. {
  794. var add_bans_username_value = $('#add_bans_username').val(), add_bans_reason_value = $('#add_bans_reason').val(), add_bans_admin_value = "";
  795. if(add_bans_username_value == '' || add_bans_reason_value == '')
  796. {
  797. $('#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();
  798. }
  799. else
  800. {
  801. $.ajax({
  802. type: 'POST',
  803. url: 'add_bans.php',
  804. data: "add_bans_username=" + add_bans_username_value + "&add_bans_reason=" + add_bans_reason_value + "&add_bans_author=" + author,
  805. success: function(response) {
  806. $('#add_bans_error_report').html(response);
  807. if(response == '1')
  808. {
  809. $('#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();
  810. addnews_timer = setTimeout('FadeOutAddBans()', 3000);
  811. }
  812. else if(response == '2')
  813. {
  814. $('#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();
  815. }
  816. else if(response == '3')
  817. {
  818. $('#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();
  819. }
  820. }
  821. });
  822. }
  823. }
  824. function SubmitRegisterUserForm()
  825. {
  826. 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 = "";
  827. $("select option:selected").each(function () {
  828. register_user_admin_level_value += $(this).text() + " ";
  829. });
  830. if(register_user_username_value == '' || register_user_password_value == '' || register_user_repeat_password_value == '')
  831. {
  832. $('#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();
  833. }
  834. else if(register_user_password_value != register_user_repeat_password_value)
  835. {
  836. $('#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();
  837. }
  838. else if($('select').val() == "Admin level")
  839. {
  840. $('#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();
  841. }
  842. else
  843. {
  844. $.ajax({
  845. type: 'POST',
  846. url: 'register_user.php',
  847. data: "register_user_username=" + register_user_username_value + "&register_user_password=" + register_user_password_value + "&register_user_admin_level=" + register_user_admin_level_value,
  848. success: function(response) {
  849. $('#register_user_error_report').html(response);
  850. if(response == '1')
  851. {
  852. $('#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>');
  853. registeruser_timer = setTimeout('FadeOutRegisterUser()', 3000).show();
  854. }
  855. else if(response == '2')
  856. {
  857. $('#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();
  858. }
  859. }
  860. });
  861. }
  862. }
  863. function SubmitDeleteUserForm()
  864. {
  865. var delete_username_value = $('#delete_username').val();
  866. if(delete_username_value == '')
  867. {
  868. $('#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();
  869. }
  870. else
  871. {
  872. $.ajax({
  873. type: 'POST',
  874. url: 'delete_user.php',
  875. data: "delete_username=" + delete_username_value,
  876. success: function(response) {
  877. $('#delete_user_error_report').html(response);
  878. if(response == '1')
  879. {
  880. $('#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();
  881. delete_user_timer = setTimeout('FadeOutDeleteUser()', 3000);
  882. }
  883. else if(response == '2')
  884. {
  885. $('#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();
  886. }
  887. }
  888. });
  889. }
  890. }
  891. function DeleteBanForm(id)
  892. {
  893. $.ajax({
  894. type: 'POST',
  895. url: 'delete_ban.php',
  896. data: "delete_ban_id=" + id,
  897. success: function(response)
  898. {
  899. $('#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();
  900. delete_ban_timer = setTimeout('FadeOutDeleteBan(\''+ id + '\')', 3000);
  901. }
  902. });
  903. }
  904. function DeleteNewsForm(id)
  905. {
  906. $.ajax({
  907. type: 'POST',
  908. url: 'delete_news.php',
  909. data: "delete_news_id=" + id,
  910. success: function(response)
  911. {
  912. $('#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();
  913. delete_news_timer = setTimeout('FadeOutDeleteNews(\''+ id + '\')', 3000);
  914. }
  915. });
  916. }
  917. function SubmitEditNewsForm(id, date)
  918. {
  919. var edit_news_title_value = $('#edit_news_title').val(), edit_news_text_value = $('#edit_news_text').val();
  920. if(edit_news_title_value == '' || edit_news_text_value == '')
  921. {
  922. $('#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();
  923. }
  924. else
  925. {
  926. $.ajax({
  927. type: 'POST',
  928. url: 'edit_news.php',
  929. data: "edit_news_title=" + edit_news_title_value + "&edit_news_text=" + edit_news_text_value + "&edit_news_id=" + id + "&edit_news_date=" + date,
  930. success: function(response)
  931. {
  932. $('#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();
  933. edit_news_timer = setTimeout('FadeOutEditNews()', 3000);
  934. }
  935. });
  936. }
  937. }
  938. function SubmitLoginUser()
  939. {
  940. var login_username_value = $('#login_username').val(), login_password_value = $('#login_password').val(), login_rembme_value = null;
  941. if($('#login_rembme').is(':checked')) login_rembme_value = '1';
  942. else login_rembme_value = '0';
  943. if(login_username_value == '' || login_password_value == '')
  944. {
  945. $('#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();
  946. }
  947. else
  948. {
  949. $.ajax({
  950. type: 'POST',
  951. url: 'login_user.php',
  952. data: "login_username=" + login_username_value + "&login_password=" + login_password_value + "&login_rembme=" + login_rembme_value,
  953. success: function(response)
  954. {
  955. $('#login_user_error_report').html(response);
  956. if(response == '1')
  957. {
  958. $('#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();
  959. login_user_timer = setTimeout('FadeOutLoginUser()', 3000);
  960. }
  961. else if(response == '2')
  962. {
  963. $('#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();
  964. }
  965. else if(response == '3')
  966. {
  967. $('#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();
  968. }
  969. }
  970. });
  971. }
  972. }
  973. function FadeOutBanEdit(element_remove_textarea, response)
  974. {
  975. location.reload(true);
  976. RemoveTextarea(element_remove_textarea, response);
  977. clearTimeout(editban_timer);
  978. }
  979. function FadeOutAddNews()
  980. {
  981. $('#add_news_error_report').fadeOut('slow');
  982. window.location = "index.php?action=news";
  983. clearTimeout(add_news_timer);
  984. }
  985. function FadeOutAddBans()
  986. {
  987. $('#add_bans_error_report').fadeOut('slow');
  988. $('.activetab').removeClass('activetab');
  989. $('#desc div').slideUp('slow');
  990. $('#tabs li').css({'border-bottom':'1px solid #DADADA', 'height':'16px'});
  991. $('#add_bans_username').val('');
  992. $('#add_bans_reason').val('');
  993. clearTimeout(addnews_timer);
  994. }
  995. function FadeOutRegisterUser()
  996. {
  997. $('#register_user_error_report').fadeOut('slow');
  998. $('.activetab').removeClass('activetab');
  999. $('#desc div').slideUp('slow');
  1000. $('#tabs li').css({'border-bottom':'1px solid #DADADA', 'height':'16px'});
  1001. $('#register_user_username').val('');
  1002. $('#register_user_password').val('');
  1003. $('#register_user_repeat_password').val('');
  1004. clearTimeout(registeruser_timer);
  1005. }
  1006. function FadeOutDeleteUser()
  1007. {
  1008. $('#register_user_error_report').fadeOut('slow');
  1009. $('.activetab').removeClass('activetab');
  1010. $('#desc div').slideUp('slow');
  1011. $('#tabs li').css({'border-bottom':'1px solid #DADADA', 'height':'16px'});
  1012. $('#delete_username').val('');
  1013. clearTimeout(delete_user_timer);
  1014. }
  1015. function FadeOutDeleteBan(id)
  1016. {
  1017. $('#delete_ban_'+ id +'').fadeOut('slow');
  1018. location.reload(true);
  1019. clearTimeout(delete_ban_timer);
  1020. }
  1021. function FadeOutDeleteNews(id)
  1022. {
  1023. $('#delete_news_'+ id +'').fadeOut('slow');
  1024. location.reload(true);
  1025. clearTimeout(delete_news_timer);
  1026. }
  1027. function FadeOutEditNews()
  1028. {
  1029. $('#edit_news_error_report').fadeOut('slow');
  1030. window.location = "index.php?action=news";
  1031. clearTimeout(edit_news_timer);
  1032. }
  1033. function FadeOutLoginUser()
  1034. {
  1035. $('#login_user_error_report').fadeOut('slow');
  1036. window.location = "index.php";
  1037. clearTimeout(login_user_timer);
  1038. }
  1039. function PreviewPost(element, value)
  1040. {
  1041. var preview_value = $(value).val();
  1042. $.ajax({
  1043. type: 'POST',
  1044. url: 'preview_post.php',
  1045. data: 'preview_post=' + preview_value,
  1046. success: function(response)
  1047. {
  1048. $(element).css({'border':'1px solid #ddd', 'background':'#ededed', 'padding':'10px', 'border-radius':'10px', 'margin-bottom':'10px', 'overflow':'auto'}).html(response).show();
  1049. }
  1050. });
  1051. }
  1052. function ApplyTag(obj, first_tag, last_tag) <!-- not by me :P -->
  1053. {
  1054. WrapText(obj, '['+first_tag+']', '[/'+last_tag+']');
  1055. }
  1056. function WrapText(obj, beginTag, endTag) <!-- not by me :P -->
  1057. {
  1058. if(typeof obj.selectionStart == 'number')
  1059. {
  1060. var start = obj.selectionStart;
  1061. var end = obj.selectionEnd;
  1062. obj.value = obj.value.substring(0, start) + beginTag + obj.value.substring(start, end) + endTag + obj.value.substring(end, obj.value.length);
  1063. }
  1064. else if(document.selection)
  1065. {
  1066. obj.focus();
  1067. var range = document.selection.createRange();
  1068. if(range.parentElement() != obj) return false;
  1069. if(typeof range.text == 'string') document.selection.createRange().text = beginTag + range.text + endTag;
  1070. }
  1071. else obj.value += text;
  1072. }
  1073. function AddText(input, text) <!-- not by me :P -->
  1074. {
  1075. document.getElementById(input).value += text;
  1076. }
  1077. function SlideElement(element, speed)
  1078. {
  1079. $(element).slideToggle(speed);
  1080. }
  1081. </script>
  1082. </head>
  1083. <body>
  1084. </body>
  1085. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement