1
0

index.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. $msg_error = "";
  5. // Создание нового пользователя
  6. if (getPOST("create") !== null) {
  7. $login = trim(getPOST("newlogin", null, ''));
  8. if ($login !== '') {
  9. $customer = get_record_sql($db_link, "SELECT * FROM customers WHERE LOWER(login) = LOWER(?)", [$login]);
  10. if (!empty($customer)) {
  11. $msg_error = "Login $login already exists!";
  12. LOG_ERROR($db_link, $msg_error);
  13. } else {
  14. $new = [
  15. 'login' => $login,
  16. 'api_key' => randomPassword(20),
  17. 'rights' => 3
  18. ];
  19. LOG_INFO($db_link, "Create new login: $login");
  20. $id = insert_record($db_link, "customers", $new);
  21. if (!empty($id)) {
  22. header("Location: editcustom.php?id=$id");
  23. exit;
  24. }
  25. }
  26. }
  27. header("Location: " . $_SERVER["REQUEST_URI"]);
  28. exit;
  29. }
  30. // Удаление пользователей
  31. if (getPOST("remove") !== null) {
  32. $fid = getPOST("fid", null, []);
  33. if (!empty($fid) && is_array($fid)) {
  34. foreach ($fid as $val) {
  35. $val = trim($val);
  36. if ($val === '' or $val == '1') continue;
  37. LOG_INFO($db_link, "Remove login with id: $val " . dump_record($db_link, 'customers', 'id = ?', [$val]));
  38. delete_record($db_link, "customers", "id = ?", [$val]);
  39. }
  40. }
  41. header("Location: " . $_SERVER["REQUEST_URI"]);
  42. exit;
  43. }
  44. unset($_POST);
  45. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  46. print_control_submenu($page_url);
  47. ?>
  48. <div id="cont">
  49. <br>
  50. <form name="def" action="index.php" method="post">
  51. <b><?php echo WEB_submenu_customers; ?></b>
  52. <table class="data">
  53. <tr align="center">
  54. <td width="30"><input type="checkbox" onClick="checkAll(this.checked);"></td>
  55. <td><b>Login</b></td>
  56. <td><b><?php echo WEB_cell_description; ?></b></td>
  57. <td><b><?php echo WEB_customer_mode;?></b></td>
  58. </tr>
  59. <?php
  60. $users = get_records_sql($db_link,'SELECT * FROM customers ORDER BY login');
  61. foreach ($users as $row) {
  62. $cl = "data";
  63. $acl = get_record_sql($db_link,'SELECT * FROM acl WHERE id=?', [ $row['rights'] ]);
  64. print "<tr align=center>\n";
  65. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$row['id']."></td>\n";
  66. print "<td class=\"$cl\" align=left width=200><a href=editcustom.php?id=".$row['id'].">" . $row['login'] . "</a></td>\n";
  67. print "<td class=\"$cl\" >". $row['description']. "</a></td>\n";
  68. print "<td class=\"$cl\" >". $acl['name']. "</a></td>\n";
  69. }
  70. ?>
  71. </table>
  72. <table class="data">
  73. <tr>
  74. <td><input type=text name=newlogin value="Unknown"></td>
  75. <td><input type="submit" name="create" value="<?php echo WEB_btn_add; ?>"></td>
  76. <td align="right"><input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="remove" value="<?php print WEB_btn_remove; ?>"></td>
  77. </tr>
  78. </table>
  79. </form>
  80. <?php
  81. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  82. ?>