index.php 2.9 KB

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