Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("common.php");
- if (isset($_GET['backup'])) {
- $Config = new _Config;
- $Db = new _Db($Config->dbhost, $Config->dbuser, $Config->dbpass, $Config->dbname);
- $Db->connect();
- backup_tables($Db);
- exit();
- }
- function backup_tables($Db)
- {
- $tables = '*';
- if ($tables == '*') {
- $tables = array();
- mysqli_query($Db->link, "SET NAMES utf8");
- $result = mysqli_query($Db->link, 'SHOW TABLES');
- while ($row = mysqli_fetch_row($result)) {
- $tables[] = $row[0];
- }
- } else {
- $tables = is_array($tables) ? $tables : explode(',', $tables);
- }
- //cycle through
- foreach ($tables as $table) {
- $result = mysqli_query($Db->link, 'SELECT * FROM ' . $table);
- $num_fields = mysqli_num_fields($result);
- $return = 'DROP TABLE ' . $table . ';';
- $row2 = mysqli_fetch_row(mysqli_query($Db->link, 'SHOW CREATE TABLE ' . $table));
- $return .= "\n\n" . $row2[1] . ";\n\n";
- for ($i = 0; $i < $num_fields; $i++) {
- while ($row = mysqli_fetch_row($result)) {
- $return .= 'INSERT INTO ' . $table . ' VALUES(';
- for ($j = 0; $j < $num_fields; $j++) {
- $row[$j] = addslashes($row[$j]);
- //$row[$j] = ereg_replace("\n", "\\n", $row[$j]);
- if (isset($row[$j])) {
- $return .= '"' . $row[$j] . '"';
- }else {
- $return .= '""';
- }
- if ($j < ($num_fields - 1)) {
- $return .= ',';
- }
- }
- $return .= ");\n";
- }
- }
- $return .= "\n\n\n";
- }
- //save file
- header('Content-Encoding: utf-8');
- header('Content-Type: text/plain; charset=utf-8');
- header('Content-Disposition: attachment; filename=dump.sql');
- echo $return;
- exit();
- }
- ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <?php
- $Db->query = "select Value from Config WHERE Name = 'TITLE'";
- $res = $Db->query();
- $title = 'Коментарии';
- if (mysqli_num_rows($res) != 0) {
- $title = mysqli_fetch_object($res)->Value;
- }
- echo '<title>', $title, '</title>';
- ?>
- <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
- <link href="/js/jquery.wysiwyg.css" rel="stylesheet" type="text/css">
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
- <script language="javascript">
- $(document).ready(function(){
- $('#checkbox').change(function(){
- $('input:checkbox').prop('checked', this.checked);
- });
- });
- </script>
- <style>
- #qs_table{
- }
- #qs_table tr{
- text-align:center;
- }
- #qs_table tr.a0{
- background-color:#ccc;
- }
- #qs_table tr.a1{
- background-color:#aaa;
- }
- #qs_table tr.ano{
- background-color:#f30;
- }
- </style>
- </head>
- <body>
- <div style="width:100%;text-align:center;height:30px;background:#999">
- <a href="?comment">[Редактировать комментарии]</a><a href="?count">[Кол-во]</a>
- <a href="?config">[Кофигурация]</a><a href="?black_list">[Черный лист]</a><a href="?import">[Импорт]</a><a href="?backup">[Backup]</a>
- </div>
- <?php
- ini_set('display_errors', 1);
- error_reporting(E_ALL | E_NOTICE);
- $Config = new _Config;
- $Db = new _Db($Config->dbhost, $Config->dbuser, $Config->dbpass, $Config->dbname);
- $Db->connect();
- $edit = 0;
- if (isset($_POST["edit"])) {
- $edit = 1;
- }
- if (isset($_GET["count"]))
- {
- $Db->query = "select Url, count(1) from Comments GROUP BY Url ORDER BY Url";
- $res = $Db->query();
- echo '<table id="qs_table">';
- echo '<tr class="a1"><th>URL</th><th>Кол-во</th></tr>';
- $a = 0;
- while ($row = mysqli_fetch_array($res)) {
- echo "<tr class='a" . ($a) . "'>";
- echo "<td>" . $row[0] . '</td>';
- echo '<td>' . $row[1] . '</td>';
- $a = $a == 0 ? 1 : 0;
- echo "</tr>";
- }
- echo "</table>";
- }
- else {
- if (isset($_GET["config"]))
- {
- $Db->query = "select * from Config";
- $res = $Db->query();
- echo "<form method='post'>";
- while ($row = mysqli_fetch_array($res)) {
- //$this->Config[$row[0]] = $row[1];
- if ($edit && $row[1] != $_POST[$row[0]]) {
- $Db->query = "update Config set Value='" . $_POST[$row[0]] . "' where Name='" . $row[0] . "'";
- $Db->query();
- $row[1] = $_POST[$row[0]];
- }
- echo $row[0] . ": <input type='text' value='" . $row[1] . "' name='" . $row[0] . "' /> <br/>";
- }
- echo "<input type='hidden' name='edit' /><input type='submit' value='OK' /><br/>";
- echo "BODYID - название поля текста коментария в форме<br/>CAPTID - название поля капчи<br/>EMAILID - название поля e-mail<br/>FormName - индификатор формы <br/> NAMEID - навзание поля имени коментирующего <br/> NCPP - количество коментарий на странице <br/>ROWSPP - коментариев на странице в админке</br> SENDMSG - какой сообщение пишем после отправки<br/> остальные поля уточняйте";
- echo "</form>";
- }
- else {
- if (isset($_GET['import']))
- {
- if (isset($_FILES['file'])) {
- $array = file($_FILES['file']["tmp_name"]);
- $Db->query = 'TRUNCATE TABLE `titles`';
- $Db->query();
- foreach ($array as $row) {
- list($Title, $Url) = explode(';', $row);
- $Title = str_replace(array("\r", "\n", '\r', '\n'), '', mysqli_real_escape_string($Db->link, $Title));
- $Url = str_replace(array("\r", "\n", '\r', '\n'), '', mysqli_real_escape_string($Db->link, $Url));
- $Db->query = 'INSERT INTO `titles` (`Title`, `Url`) VALUES (\'' . $Title . '\', \'' . $Url . '\')';
- $Db->query();
- }
- echo "Готово";
- }
- ?>
- <form action="" method="post" enctype="multipart/form-data" name="form1">
- <label for="file">Фаил</label> <input type="file" name="file" id="file"> <input type="submit" value="Загрузить">
- </form>
- <?php
- }
- else {
- if (isset($_GET['black_list']))
- {
- $Db->query = "select * from black_list";
- $res = $Db->query();
- echo "<form method='post'><table id='qs_table'>";
- $a = 0;
- while ($row = mysqli_fetch_array($res)) {
- if ($edit && isset($_POST[$row[0]])) {
- $Db->query = "delete from black_list where id=" . $row[0];
- $Db->query();
- }else {
- echo "<tr class='a" . $a . "'><td>" . $row[1] . '</td><td><input type="checkbox" name="' . $row[0] . '"/></td></tr>';
- $a = ($a == 0 ? 1 : 0);
- }
- }
- echo "</table><input type='hidden' name='edit' /><input type='submit' value='УДАЛИТЬ ОТМЕЧЕНОЕ' /><br/>";
- }
- else {
- if (isset($_GET['backup']))
- {
- backup_tables();
- }
- else
- {
- $filter = "*";
- if (isset($_GET['url_filter']) && $_GET['url_filter'] != "") {
- $filter = $_GET['url_filter'];
- }
- if (isset($_POST["action"]))
- {
- $idall = '';
- if (isset($_POST['id'])) {
- for ($i = 0; $i < count($_POST["id"]); $i++) {
- $idall .= $_POST["id"][$i] . (($i + 1) < count($_POST["id"]) ? ',' : '');
- }
- }
- if ($_POST['action'] == 'edit')
- {
- if (isset($_POST["id"]))
- {
- $Db->query = "select * from Comments where id=" . $_POST["id"][0];
- $Db->query();
- echo "<form action='' method='post'>";
- echo "URL:<input type='text' disabled value='" . mysqli_result($Db->lQueryResult, 0, 1) . "' /><br/>";
- echo "Автор:<input type='text' name='avtor' value='" . mysqli_result($Db->lQueryResult, 0, 2) . "' /><br/>";
- echo "Дата:<input type='text' name='date' value='" . mysqli_result($Db->lQueryResult, 0, 3) . "' /><br/>";
- echo "Коментарий:<textarea name='comm' id='editor' style='width:250px;height:200px;'>" . mysqli_result($Db->lQueryResult, 0, 4) . "</textarea><br/>";
- echo "IP:<input type='text' disabled value='" . mysqli_result($Db->lQueryResult, 0, 5) . "' /><br/>";
- echo "Public:<input type='checkbox' name='public' " . (mysqli_result($Db->lQueryResult, 0, 6) == 1 ? 'checked' : '') . " /><br/>";
- echo "<input type='hidden' name='nid' value='" . mysqli_result($Db->lQueryResult, 0, 0) . "'/> <input type='hidden' name='action' value='edit' />";
- echo "<input type='submit' value='Сохранить'/>";
- ?>
- <script type="text/javascript" src="/js/jquery.js"></script>
- <script type="text/javascript" src="/js/jquery.wysiwyg.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $("#editor").css("width", "500px").wysiwyg({
- controls:{
- bold:{visible:true, tags:["b", "strong"], css:{fontWeight:"bold"}},
- italic:{visible:true, tags:["i", "em"], css:{fontStyle:"italic"}},
- strikeThrough:{visible:true},
- underline:{visible:true},
- separator00:{visible:false},
- justifyLeft:{visible:true},
- justifyCenter:{visible:true},
- justifyRight:{visible:true},
- justifyFull:{visible:true},
- separator01:{visible:false},
- indent:{visible:true},
- outdent:{visible:true},
- separator02:{visible:false},
- subscript:{visible:true},
- superscript:{visible:true},
- separator03:{visible:true},
- undo:{visible:false},
- redo:{visible:false},
- separator04:{visible:false},
- insertOrderedList:{visible:false},
- insertUnorderedList:{visible:false},
- insertHorizontalRule:{visible:false},
- separator06:{separator:false},
- separator07:{visible:false},
- cut:{visible:false},
- copy:{visible:false},
- paste:{visible:false},
- html:{visible:false}
- }
- });
- $('.wysiwyg').css("width", "500px");
- });
- </script>
- </body>
- </html>
- <?php
- return;
- }
- else {
- if (isset($_POST["avtor"]) && isset($_POST["nid"])) {
- $Db->query = "update Comments set Name='" . $_POST['avtor'] . "', Date='" . $_POST["date"] . "',Body='" . $_POST["comm"] . "',Public=" . (isset($_POST["public"]) ? '1' : '0') . " where id=" . $_POST["nid"];
- $Db->query();
- }
- }
- }
- else {
- if ($_POST['action'] == 'delete') {
- $Db->query = "delete from Comments where Id in (" . $idall . ")";
- $Db->query();
- }else {
- if ($_POST['action'] == 'del_new') {
- $Db->query = "delete from Comments where Public = 0";
- $Db->query();
- }else {
- if ($_POST["action"] == 'addBL') {
- $Db->query = "insert ignore into black_list (ip) select ip from Comments where Id in (" . $idall . ")";
- $Db->query();
- if (isset($_POST["delAll"])) {
- $q2 = "delete from Comments where IP in (";
- $Db->query = "select ip from comments where id in (" . $idall . ")";
- $Db->query();
- $row = mysqli_fetch_array($Db->lQueryResult);
- $q2 .= "'" . $row[0] . "'";
- while ($row = mysqli_fetch_array($Db->lQueryResult)) {
- $q2 .= ",'" . $row[0] . "'";
- }
- $q2 .= ")";
- $Db->query = $q2;
- $Db->query();
- }
- }else {
- if ($_POST['action'] == 'public') {
- $Db->query = "update Comments set Public = (!Public) where Id in (" . $idall . ")";
- $Db->query();
- }
- }
- }
- }
- }
- }
- $Db->query = "select Url from Comments group by url";
- $Db->query();
- echo "<form name='filter'><br/>"; // <select name='url_filter' onchange='document.filter.submit()'>";
- /*echo "<option value='*'>Все</option>";
- while($row = mysqli_fetch_array($Db->lQueryResult))
- {
- echo "<option value='".$row[0]."' ". ($filter==$row[0]?'selected':'').">".$row[0]."</option>";
- }
- echo "</select><br/></form>";
- */
- echo "<input type='text' name='url_filter' value='" . ($filter == '*' ? '' : $filter) . "' /><input type='submit' value='применить' /></form>";
- ##########################################
- $Db->query = "select Value from Config WHERE Name = 'ROWSPP'";
- $res = $Db->query();
- $num_rows = 0;
- if (mysqli_num_rows($res) != 0) {
- $num_rows = mysqli_fetch_object($res)->Value;
- }
- if ($num_rows) {
- $Db->query = "select count(1) as count from Comments";
- $res = $Db->query();
- $total = mysqli_fetch_object($res)->count;
- $pages = ceil($total / $num_rows);
- $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
- for ($i = 1; $i <= $pages; $i++) {
- if ($i * $num_rows == $offset) {
- echo ($i - 1) * $num_rows . ' - ', $num_rows * $i, ' ';
- }else {
- echo '<a href="?comment&offset=', ($i - 1) * $num_rows, '">' . ($i - 1) * $num_rows . ' - ', $num_rows * $i, '</a> ';
- }
- }
- }
- ##########################################
- $Db->query = "select * from Comments";
- if ($filter != '*') {
- $Db->query .= " where url='" . $_GET['url_filter'] . "'";
- }
- $Db->query .= ' ORDER BY Id DESC ';
- if ($num_rows) {
- if (isset($_GET['offset'])) {
- $Db->query .= ' LIMIT ' . $_GET['offset'] . ', ' . $num_rows;
- }else {
- $Db->query .= ' LIMIT ' . $num_rows;
- }
- }
- $res = $Db->query();
- echo "<form method='post'><table id='qs_table'>";
- $a = 0;
- echo '<tr class="a1"><th><input type="checkbox" id="checkbox"></th><th>URL</th><th>Name</th><th>Date</th><th>Comment</th><th>IP</th></tr>';
- while ($row = mysqli_fetch_array($res)) {
- echo "<tr class='a" . ($row[6] == 0 ? 'no' : $a) . "'>";
- echo "<td><input type='checkbox' name='id[]' value='" . $row[0] . "'/></td>";
- echo "<td>" . $row[1] . '</td>';
- echo '<td>' . $row[2] . '</td>';
- echo '<td>' . $row[3] . '</td>';
- echo '<td style="text-align: left; font-size: 18px; padding: 5px;">' . (mb_strlen($row[4]) > 60 ? mb_substr($row[4], 0, 2000) . '' : $row[4]) . '</td>';
- echo '<td>' . $row[5] . '</td>';
- $a = $a == 0 ? 1 : 0;
- }
- echo "</table>";
- echo "<input type='radio' name='action' value='delete' />Удалить отмеченое<br/>";
- echo "<input type='radio' name='action' value='public' />Опубликовать/снять публикацию отмеченого<br/>";
- echo "<input type='radio' name='action' value='addBL' />Добавить IP в черный список (<font style='color:#f00'><input type='checkbox' name='delAll' /> удалить все сообщения с данного IP</font>)<br/>";
- echo "<input type='radio' name='action' value='edit' />Редактировать (первое отмеченое)<br/>";
- echo "<input type='radio' name='action' value='del_new' />Удалить неопубликованные<br/>";
- echo "<input type='submit' value='OK' /><br/>";
- }
- }
- }
- }
- }
- ?>
- <script type="text/javascript" src="/js/jquery.js"></script>
- <script type="text/javascript" src="/js/jquery.wysiwyg.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $("#editor").css("width", "500px").wysiwyg({
- controls:{
- bold:{visible:true, tags:["b", "strong"], css:{fontWeight:"bold"}},
- italic:{visible:true, tags:["i", "em"], css:{fontStyle:"italic"}},
- strikeThrough:{visible:true},
- underline:{visible:true},
- separator00:{visible:false},
- justifyLeft:{visible:true},
- justifyCenter:{visible:true},
- justifyRight:{visible:true},
- justifyFull:{visible:true},
- separator01:{visible:false},
- indent:{visible:true},
- outdent:{visible:true},
- separator02:{visible:false},
- subscript:{visible:true},
- superscript:{visible:true},
- separator03:{visible:true},
- undo:{visible:false},
- redo:{visible:false},
- separator04:{visible:false},
- insertOrderedList:{visible:false},
- insertUnorderedList:{visible:false},
- insertHorizontalRule:{visible:false},
- separator06:{separator:false},
- separator07:{visible:false},
- cut:{visible:false},
- copy:{visible:false},
- paste:{visible:false},
- html:{visible:false}
- }
- });
- $('.wysiwyg').css("width", "500px");
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment