Guest User

Untitled

a guest
Apr 5th, 2020
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.90 KB | None | 0 0
  1. <?php
  2.  
  3. include("common.php");
  4. if (isset($_GET['backup'])) {
  5.     $Config = new _Config;
  6.     $Db = new _Db($Config->dbhost, $Config->dbuser, $Config->dbpass, $Config->dbname);
  7.     $Db->connect();
  8.  
  9.     backup_tables($Db);
  10.     exit();
  11. }
  12.  
  13. function backup_tables($Db)
  14. {
  15.     $tables = '*';
  16.     if ($tables == '*') {
  17.         $tables = array();
  18.         mysqli_query($Db->link, "SET NAMES utf8");
  19.         $result = mysqli_query($Db->link, 'SHOW TABLES');
  20.         while ($row = mysqli_fetch_row($result)) {
  21.             $tables[] = $row[0];
  22.         }
  23.     } else {
  24.         $tables = is_array($tables) ? $tables : explode(',', $tables);
  25.     }
  26.  
  27.     //cycle through
  28.     foreach ($tables as $table) {
  29.         $result = mysqli_query($Db->link, 'SELECT * FROM ' . $table);
  30.         $num_fields = mysqli_num_fields($result);
  31.  
  32.         $return = 'DROP TABLE ' . $table . ';';
  33.         $row2 = mysqli_fetch_row(mysqli_query($Db->link, 'SHOW CREATE TABLE ' . $table));
  34.         $return .= "\n\n" . $row2[1] . ";\n\n";
  35.  
  36.         for ($i = 0; $i < $num_fields; $i++) {
  37.             while ($row = mysqli_fetch_row($result)) {
  38.                 $return .= 'INSERT INTO ' . $table . ' VALUES(';
  39.                 for ($j = 0; $j < $num_fields; $j++) {
  40.                     $row[$j] = addslashes($row[$j]);
  41.                     //$row[$j] = ereg_replace("\n", "\\n", $row[$j]);
  42.                     if (isset($row[$j])) {
  43.                         $return .= '"' . $row[$j] . '"';
  44.                     }else {
  45.                         $return .= '""';
  46.                     }
  47.                     if ($j < ($num_fields - 1)) {
  48.                         $return .= ',';
  49.                     }
  50.                 }
  51.                 $return .= ");\n";
  52.             }
  53.         }
  54.         $return .= "\n\n\n";
  55.     }
  56.  
  57.     //save file
  58.     header('Content-Encoding: utf-8');
  59.     header('Content-Type: text/plain; charset=utf-8');
  60.     header('Content-Disposition: attachment; filename=dump.sql');
  61.     echo $return;
  62.     exit();
  63. }
  64.  
  65. ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  66. <html>
  67. <head>
  68.     <?php
  69.     $Db->query = "select Value from Config WHERE Name = 'TITLE'";
  70.     $res = $Db->query();
  71.     $title = 'Коментарии';
  72.     if (mysqli_num_rows($res) != 0) {
  73.         $title = mysqli_fetch_object($res)->Value;
  74.     }
  75.     echo '<title>', $title, '</title>';
  76.     ?>
  77.     <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  78.     <link href="/js/jquery.wysiwyg.css" rel="stylesheet" type="text/css">
  79.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
  80.     <script language="javascript">
  81.             $(document).ready(function(){
  82.                 $('#checkbox').change(function(){
  83.                     $('input:checkbox').prop('checked', this.checked);
  84.                 });
  85.             });
  86.     </script>
  87.     <style>
  88.  
  89.         #qs_table{
  90.         }
  91.         #qs_table tr{
  92.             text-align:center;
  93.         }
  94.         #qs_table tr.a0{
  95.             background-color:#ccc;
  96.         }
  97.         #qs_table tr.a1{
  98.             background-color:#aaa;
  99.         }
  100.         #qs_table tr.ano{
  101.             background-color:#f30;
  102.         }
  103.  
  104.  
  105.     </style>
  106.  
  107. </head>
  108.  
  109. <body>
  110.  
  111. <div style="width:100%;text-align:center;height:30px;background:#999">
  112.     <a href="?comment">[Редактировать комментарии]</a><a href="?count">[Кол-во]</a>
  113.     <a href="?config">[Кофигурация]</a><a href="?black_list">[Черный лист]</a><a href="?import">[Импорт]</a><a href="?backup">[Backup]</a>
  114. </div>
  115.  
  116. <?php
  117.  
  118. ini_set('display_errors', 1);
  119. error_reporting(E_ALL | E_NOTICE);
  120.  
  121. $Config = new _Config;
  122. $Db = new _Db($Config->dbhost, $Config->dbuser, $Config->dbpass, $Config->dbname);
  123. $Db->connect();
  124.  
  125.  
  126. $edit = 0;
  127. if (isset($_POST["edit"])) {
  128.     $edit = 1;
  129. }
  130.  
  131.  
  132. if (isset($_GET["count"]))
  133. {
  134.     $Db->query = "select Url, count(1) from Comments GROUP BY Url ORDER BY Url";
  135.     $res = $Db->query();
  136.  
  137.     echo '<table id="qs_table">';
  138.  
  139.     echo '<tr class="a1"><th>URL</th><th>Кол-во</th></tr>';
  140.     $a = 0;
  141.     while ($row = mysqli_fetch_array($res)) {
  142.         echo "<tr class='a" . ($a) . "'>";
  143.         echo "<td>" . $row[0] . '</td>';
  144.         echo '<td>' . $row[1] . '</td>';
  145.         $a = $a == 0 ? 1 : 0;
  146.         echo "</tr>";
  147.     }
  148.  
  149.     echo "</table>";
  150.  
  151. }
  152. else {
  153. if (isset($_GET["config"]))
  154. {
  155.     $Db->query = "select * from Config";
  156.     $res = $Db->query();
  157.  
  158.     echo "<form method='post'>";
  159.  
  160.     while ($row = mysqli_fetch_array($res)) {
  161.         //$this->Config[$row[0]] = $row[1];
  162.  
  163.         if ($edit && $row[1] != $_POST[$row[0]]) {
  164.             $Db->query = "update Config set Value='" . $_POST[$row[0]] . "' where Name='" . $row[0] . "'";
  165.             $Db->query();
  166.             $row[1] = $_POST[$row[0]];
  167.         }
  168.  
  169.         echo $row[0] . ": <input type='text' value='" . $row[1] . "' name='" . $row[0] . "' /> <br/>";
  170.     }
  171.  
  172.     echo "<input type='hidden' name='edit' /><input type='submit' value='OK' /><br/>";
  173.     echo "BODYID - название поля текста коментария в форме<br/>CAPTID - название поля капчи<br/>EMAILID - название поля e-mail<br/>FormName - индификатор формы <br/> NAMEID - навзание поля имени коментирующего <br/> NCPP - количество коментарий на странице <br/>ROWSPP - коментариев на странице в админке</br> SENDMSG - какой сообщение пишем после отправки<br/> остальные поля уточняйте";
  174.  
  175.     echo "</form>";
  176.  
  177.  
  178. }
  179. else {
  180. if (isset($_GET['import']))
  181. {
  182.     if (isset($_FILES['file'])) {
  183.         $array = file($_FILES['file']["tmp_name"]);
  184.         $Db->query = 'TRUNCATE TABLE `titles`';
  185.         $Db->query();
  186.         foreach ($array as $row) {
  187.             list($Title, $Url) = explode(';', $row);
  188.             $Title = str_replace(array("\r", "\n", '\r', '\n'), '', mysqli_real_escape_string($Db->link, $Title));
  189.             $Url = str_replace(array("\r", "\n", '\r', '\n'), '', mysqli_real_escape_string($Db->link, $Url));
  190.             $Db->query = 'INSERT INTO `titles` (`Title`, `Url`) VALUES (\'' . $Title . '\', \'' . $Url . '\')';
  191.             $Db->query();
  192.         }
  193.         echo "Готово";
  194.     }
  195.     ?>
  196.     <form action="" method="post" enctype="multipart/form-data" name="form1">
  197.         <label for="file">Фаил</label> <input type="file" name="file" id="file"> <input type="submit" value="Загрузить">
  198.     </form>
  199.     <?php
  200. }
  201. else {
  202. if (isset($_GET['black_list']))
  203. {
  204.     $Db->query = "select * from black_list";
  205.     $res = $Db->query();
  206.  
  207.     echo "<form method='post'><table id='qs_table'>";
  208.     $a = 0;
  209.  
  210.     while ($row = mysqli_fetch_array($res)) {
  211.  
  212.  
  213.         if ($edit && isset($_POST[$row[0]])) {
  214.             $Db->query = "delete from black_list where id=" . $row[0];
  215.             $Db->query();
  216.         }else {
  217.             echo "<tr class='a" . $a . "'><td>" . $row[1] . '</td><td><input type="checkbox" name="' . $row[0] . '"/></td></tr>';
  218.             $a = ($a == 0 ? 1 : 0);
  219.         }
  220.     }
  221.  
  222.     echo "</table><input type='hidden' name='edit' /><input type='submit' value='УДАЛИТЬ ОТМЕЧЕНОЕ' /><br/>";
  223. }
  224. else {
  225. if (isset($_GET['backup']))
  226. {
  227.     backup_tables();
  228. }
  229. else
  230. {
  231.  
  232.  
  233. $filter = "*";
  234.  
  235. if (isset($_GET['url_filter']) && $_GET['url_filter'] != "") {
  236.     $filter = $_GET['url_filter'];
  237. }
  238.  
  239.  
  240. if (isset($_POST["action"]))
  241. {
  242. $idall = '';
  243. if (isset($_POST['id'])) {
  244.     for ($i = 0; $i < count($_POST["id"]); $i++) {
  245.         $idall .= $_POST["id"][$i] . (($i + 1) < count($_POST["id"]) ? ',' : '');
  246.     }
  247. }
  248.  
  249.  
  250. if ($_POST['action'] == 'edit')
  251. {
  252.  
  253. if (isset($_POST["id"]))
  254. {
  255.  
  256. $Db->query = "select * from Comments where id=" . $_POST["id"][0];
  257. $Db->query();
  258.  
  259. echo "<form action='' method='post'>";
  260. echo "URL:<input type='text' disabled value='" . mysqli_result($Db->lQueryResult, 0, 1) . "' /><br/>";
  261. echo "Автор:<input type='text' name='avtor'  value='" . mysqli_result($Db->lQueryResult, 0, 2) . "' /><br/>";
  262. echo "Дата:<input type='text' name='date' value='" . mysqli_result($Db->lQueryResult, 0, 3) . "' /><br/>";
  263. echo "Коментарий:<textarea name='comm' id='editor' style='width:250px;height:200px;'>" . mysqli_result($Db->lQueryResult, 0, 4) . "</textarea><br/>";
  264. echo "IP:<input type='text' disabled value='" . mysqli_result($Db->lQueryResult, 0, 5) . "' /><br/>";
  265. echo "Public:<input type='checkbox' name='public' " . (mysqli_result($Db->lQueryResult, 0, 6) == 1 ? 'checked' : '') . " /><br/>";
  266. echo "<input type='hidden' name='nid' value='" . mysqli_result($Db->lQueryResult, 0, 0) . "'/> <input type='hidden' name='action' value='edit' />";
  267. echo "<input type='submit' value='Сохранить'/>";
  268. ?>
  269. <script type="text/javascript" src="/js/jquery.js"></script>
  270. <script type="text/javascript" src="/js/jquery.wysiwyg.js"></script>
  271. <script type="text/javascript">
  272.     $(document).ready(function(){
  273.         $("#editor").css("width", "500px").wysiwyg({
  274.             controls:{
  275.                 bold:{visible:true, tags:["b", "strong"], css:{fontWeight:"bold"}},
  276.                 italic:{visible:true, tags:["i", "em"], css:{fontStyle:"italic"}},
  277.                 strikeThrough:{visible:true},
  278.                 underline:{visible:true},
  279.                 separator00:{visible:false},
  280.                 justifyLeft:{visible:true},
  281.                 justifyCenter:{visible:true},
  282.                 justifyRight:{visible:true},
  283.                 justifyFull:{visible:true},
  284.                 separator01:{visible:false},
  285.                 indent:{visible:true},
  286.                 outdent:{visible:true},
  287.                 separator02:{visible:false},
  288.                 subscript:{visible:true},
  289.                 superscript:{visible:true},
  290.                 separator03:{visible:true},
  291.                 undo:{visible:false},
  292.                 redo:{visible:false},
  293.                 separator04:{visible:false},
  294.                 insertOrderedList:{visible:false},
  295.                 insertUnorderedList:{visible:false},
  296.                 insertHorizontalRule:{visible:false},
  297.                 separator06:{separator:false},
  298.                 separator07:{visible:false},
  299.                 cut:{visible:false},
  300.                 copy:{visible:false},
  301.                 paste:{visible:false},
  302.                 html:{visible:false}
  303.             }
  304.         });
  305.         $('.wysiwyg').css("width", "500px");
  306.     });
  307. </script>
  308. </body>
  309. </html>
  310.     <?php
  311.     return;
  312.     }
  313.     else {
  314.         if (isset($_POST["avtor"]) && isset($_POST["nid"])) {
  315.             $Db->query = "update Comments set Name='" . $_POST['avtor'] . "', Date='" . $_POST["date"] . "',Body='" . $_POST["comm"] . "',Public=" . (isset($_POST["public"]) ? '1' : '0') . " where id=" . $_POST["nid"];
  316.             $Db->query();
  317.         }
  318.     }
  319.  
  320.  
  321.     }
  322.     else {
  323.         if ($_POST['action'] == 'delete') {
  324.             $Db->query = "delete from Comments where Id in (" . $idall . ")";
  325.             $Db->query();
  326.  
  327.  
  328.         }else {
  329.             if ($_POST['action'] == 'del_new') {
  330.                 $Db->query = "delete from Comments where Public = 0";
  331.                 $Db->query();
  332.             }else {
  333.                 if ($_POST["action"] == 'addBL') {
  334.                     $Db->query = "insert ignore into black_list  (ip) select ip from Comments where Id in (" . $idall . ")";
  335.                     $Db->query();
  336.  
  337.                     if (isset($_POST["delAll"])) {
  338.                         $q2 = "delete from Comments where IP in (";
  339.                         $Db->query = "select ip from comments where id in (" . $idall . ")";
  340.                         $Db->query();
  341.  
  342.                         $row = mysqli_fetch_array($Db->lQueryResult);
  343.                         $q2 .= "'" . $row[0] . "'";
  344.  
  345.                         while ($row = mysqli_fetch_array($Db->lQueryResult)) {
  346.                             $q2 .= ",'" . $row[0] . "'";
  347.                         }
  348.                         $q2 .= ")";
  349.                         $Db->query = $q2;
  350.                         $Db->query();
  351.                     }
  352.  
  353.  
  354.                 }else {
  355.                     if ($_POST['action'] == 'public') {
  356.  
  357.                         $Db->query = "update Comments set Public = (!Public) where Id in (" . $idall . ")";
  358.                         $Db->query();
  359.                     }
  360.                 }
  361.             }
  362.         }
  363.     }
  364.     }
  365.  
  366.     $Db->query = "select Url from Comments group by url";
  367.     $Db->query();
  368.  
  369.     echo "<form name='filter'><br/>"; //    <select name='url_filter' onchange='document.filter.submit()'>";
  370.     /*echo "<option value='*'>Все</option>";
  371.  
  372.       while($row = mysqli_fetch_array($Db->lQueryResult))
  373.       {
  374.       echo "<option value='".$row[0]."' ". ($filter==$row[0]?'selected':'').">".$row[0]."</option>";
  375.       }
  376.  
  377.     echo "</select><br/></form>";
  378.     */
  379.     echo "<input type='text' name='url_filter' value='" . ($filter == '*' ? '' : $filter) . "' /><input type='submit' value='применить' /></form>";
  380.  
  381.     ##########################################
  382.  
  383.     $Db->query = "select Value from Config WHERE Name = 'ROWSPP'";
  384.     $res = $Db->query();
  385.     $num_rows = 0;
  386.     if (mysqli_num_rows($res) != 0) {
  387.         $num_rows = mysqli_fetch_object($res)->Value;
  388.     }
  389.  
  390.     if ($num_rows) {
  391.         $Db->query = "select count(1) as count from Comments";
  392.         $res = $Db->query();
  393.         $total = mysqli_fetch_object($res)->count;
  394.         $pages = ceil($total / $num_rows);
  395.         $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
  396.  
  397.         for ($i = 1; $i <= $pages; $i++) {
  398.             if ($i * $num_rows == $offset) {
  399.                 echo ($i - 1) * $num_rows . ' - ', $num_rows * $i, ' ';
  400.             }else {
  401.                 echo '<a href="?comment&offset=', ($i - 1) * $num_rows, '">' . ($i - 1) * $num_rows . ' - ', $num_rows * $i, '</a> ';
  402.             }
  403.         }
  404.  
  405.     }
  406.  
  407.     ##########################################
  408.  
  409.     $Db->query = "select * from Comments";
  410.     if ($filter != '*') {
  411.         $Db->query .= " where url='" . $_GET['url_filter'] . "'";
  412.     }
  413.     $Db->query .= ' ORDER BY Id DESC ';
  414.     if ($num_rows) {
  415.         if (isset($_GET['offset'])) {
  416.             $Db->query .= ' LIMIT ' . $_GET['offset'] . ', ' . $num_rows;
  417.         }else {
  418.             $Db->query .= ' LIMIT ' . $num_rows;
  419.         }
  420.     }
  421.  
  422.     $res = $Db->query();
  423.  
  424.     echo "<form method='post'><table id='qs_table'>";
  425.     $a = 0;
  426.     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>';
  427.  
  428.     while ($row = mysqli_fetch_array($res)) {
  429.  
  430.  
  431.         echo "<tr class='a" . ($row[6] == 0 ? 'no' : $a) . "'>";
  432.         echo "<td><input type='checkbox' name='id[]' value='" . $row[0] . "'/></td>";
  433.         echo "<td>" . $row[1] . '</td>';
  434.         echo '<td>' . $row[2] . '</td>';
  435.         echo '<td>' . $row[3] . '</td>';
  436.         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>';
  437.         echo '<td>' . $row[5] . '</td>';
  438.         $a = $a == 0 ? 1 : 0;
  439.     }
  440.  
  441.     echo "</table>";
  442.     echo "<input type='radio' name='action' value='delete' />Удалить отмеченое<br/>";
  443.     echo "<input type='radio' name='action' value='public' />Опубликовать/снять публикацию отмеченого<br/>";
  444.     echo "<input type='radio' name='action' value='addBL' />Добавить IP в черный список (<font style='color:#f00'><input type='checkbox' name='delAll' /> удалить все сообщения с данного IP</font>)<br/>";
  445.     echo "<input type='radio' name='action' value='edit' />Редактировать (первое отмеченое)<br/>";
  446.     echo "<input type='radio' name='action' value='del_new' />Удалить неопубликованные<br/>";
  447.  
  448.     echo "<input type='submit' value='OK' /><br/>";
  449.     }
  450.     }
  451.     }
  452.     }
  453.     }
  454.  
  455.  
  456.     ?>
  457.  
  458. <script type="text/javascript" src="/js/jquery.js"></script>
  459. <script type="text/javascript" src="/js/jquery.wysiwyg.js"></script>
  460. <script type="text/javascript">
  461.     $(document).ready(function(){
  462.         $("#editor").css("width", "500px").wysiwyg({
  463.             controls:{
  464.                 bold:{visible:true, tags:["b", "strong"], css:{fontWeight:"bold"}},
  465.                 italic:{visible:true, tags:["i", "em"], css:{fontStyle:"italic"}},
  466.                 strikeThrough:{visible:true},
  467.                 underline:{visible:true},
  468.                 separator00:{visible:false},
  469.                 justifyLeft:{visible:true},
  470.                 justifyCenter:{visible:true},
  471.                 justifyRight:{visible:true},
  472.                 justifyFull:{visible:true},
  473.                 separator01:{visible:false},
  474.                 indent:{visible:true},
  475.                 outdent:{visible:true},
  476.                 separator02:{visible:false},
  477.                 subscript:{visible:true},
  478.                 superscript:{visible:true},
  479.                 separator03:{visible:true},
  480.                 undo:{visible:false},
  481.                 redo:{visible:false},
  482.                 separator04:{visible:false},
  483.                 insertOrderedList:{visible:false},
  484.                 insertUnorderedList:{visible:false},
  485.                 insertHorizontalRule:{visible:false},
  486.                 separator06:{separator:false},
  487.                 separator07:{visible:false},
  488.                 cut:{visible:false},
  489.                 copy:{visible:false},
  490.                 paste:{visible:false},
  491.                 html:{visible:false}
  492.             }
  493.         });
  494.         $('.wysiwyg').css("width", "500px");
  495.     });
  496. </script>
  497. </body>
  498. </html>
Advertisement
Add Comment
Please, Sign In to add comment