admin.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. require_once('include/config.php');
  3. require_once('include/db.php');
  4. $content = '';
  5. $script = '';
  6. $mode = @$_GET['mode'];
  7. switch ($mode) {
  8. default: admin_main_menu(); break;
  9. case 'dirfill': admin_dir_fill(); break;
  10. }
  11. function admin_main_menu() {
  12. global $content;
  13. $content = '<a href="admin.php?mode=dirfill">Automagiczne uzupełnianie katalogów</a>';
  14. }
  15. function admin_dir_fill() {
  16. global $content;
  17. global $config;
  18. global $script;
  19. $path = $config['basedir'];
  20. $dir_handle = @opendir($path) or die('Błąd otwarcia basedir');
  21. $dirlist = [];
  22. while ($file = readdir($dir_handle)) {
  23. if(!is_dir($path.$file)) continue;
  24. if (in_array($file, array('miniatury', '.', '..')))
  25. continue;
  26. $dirlist[] = array('name' => $file, 'date' => filemtime($path.$file));
  27. }
  28. usort($dirlist, 'dir_compare');
  29. $content .= '<form id="dirfillForm" onsubmit="return dirfill_submit(event)"><table><tr><th>Ścieżka</th><th>Nazwa</th><th>Data</th><th>Komentarz</th><th>Już jest</th><th>Dodaj<br><a id="addSelectAll" href="#">Zaznacz wszystko<br><a id="addDeselectAll" href="#">Odznacz wszystko</a></th></tr>';
  30. foreach($dirlist as $dir) {
  31. $dirinfo = get_dir_info($dir['name']);
  32. $dirname = htmlspecialchars($dir['name']);
  33. $dirselect = md5($dir['name']);
  34. if ($dirinfo) {
  35. $content .= '<tr><td>' . $dirname . '</td>';
  36. $content .= '<td><input type="text" id="' . $dirselect . '-name" value="' . htmlspecialchars($dirinfo['name']) . '"></td>';
  37. $content .= '<td>Baza danych: <input type="text" id="' . $dirselect . '-date" value="' . $dirinfo['date'] . '"><br>Katalog: ' . $dir['date'] . '</td>';
  38. $content .= '<td><textarea id="' . $dirselect . '-comment">' . htmlspecialchars($dirinfo['comment']) . '</textarea></td>';
  39. $content .= '<td>Tak</td><td><input type="checkbox" id="' . $dirselect . '-add" class="addBox">(tylko brakujące pliki)</td></tr>';
  40. $content .= '<input type="hidden" id="' . $dirselect . '-new" value="0">';
  41. } else {
  42. $content .= '<tr><td>' . $dirname . '</td>';
  43. $content .= '<td><input type="text" id="' . $dirselect . '-name" value="' . $dirname . '"></td>';
  44. $content .= '<td><input type="text" id="' . $dirselect . '-date" value="' . $dir['date'] . '"></input></td>';
  45. $content .= '<td><textarea id="' . $dirselect . '-comment"></textarea></td>';
  46. $content .= '<td>Nie</td><td><input type="checkbox" checked="checked" id="' . $dirselect . '-add" class="addBox"></td></tr>';
  47. $content .= '<input type="hidden" id="' . $dirselect . '-new" value="1">';
  48. }
  49. }
  50. $content .= '</table><input type="submit" value="OK"></form>';
  51. // $content = '<pre>' . print_r($dirlist, true) . '</pre>';
  52. $dirlist_json = json_encode($dirlist);
  53. $script = 'const dirlist = ' . $dirlist_json . ';';
  54. }
  55. function dir_compare($a, $b){
  56. return $b['date']-$a['date'];
  57. }
  58. ?><!DOCTYPE html>
  59. <html>
  60. <head>
  61. <title>Obrazki: Admin</title>
  62. <link rel="stylesheet" href="/obrazki/style.css" type="text/css">
  63. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  64. <script type="text/javascript" src="https://k4be.pl/jquery/jquery-3.6.3.min.js"></script>
  65. <script type="text/javascript" src="admin.js"></script>
  66. <script type="text/javascript" src="md5.js"></script>
  67. <script type="text/javascript">
  68. <?=$script?>
  69. </script>
  70. </head>
  71. <body>
  72. <?=$content?>
  73. </body>
  74. </html>