1
0

editcustom.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. $msg_error = "";
  6. $customer=get_record($db_link,'customers',"id=?", [$id]);
  7. if (getPOST("edituser") !== null) {
  8. global $salt;
  9. $new = [];
  10. // Логин (макс. 20 символов)
  11. $new['login'] = substr(trim(getPOST("login", null, $customer['login'])), 0, 20);
  12. // Описание (макс. 100 символов)
  13. $new['description'] = substr(trim(getPOST("description", null, '')), 0, 100);
  14. // Пароль (если задан и не пустой)
  15. $pass = trim(getPOST("pass", null, ''));
  16. if ($pass !== '') {
  17. $new['password'] = password_hash($pass, PASSWORD_BCRYPT);
  18. }
  19. // API-ключ (если длина > 20)
  20. $api_key = getPOST("api_key", null, randomPassword(20));
  21. if (strlen(trim($api_key)) > 20) {
  22. $new['api_key'] = substr(trim($api_key),0,20);
  23. }
  24. if (strlen(trim($api_key)) <20) {
  25. $new['api_key'] = $customer['api_key'];
  26. }
  27. $new['api_key'] = trim($api_key);
  28. // Права доступа
  29. $new['rights'] = (int)getPOST("f_acl", null, 0);
  30. // Обновление записи
  31. update_record($db_link, "customers", "id = ?", $new, [$id]);
  32. header("Location: " . $_SERVER["REQUEST_URI"]);
  33. exit;
  34. }
  35. unset($_POST);
  36. print_control_submenu($page_url);
  37. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  38. ?>
  39. <div id="cont">
  40. <br><b><?php echo WEB_customer_titles; ?></b><br>
  41. <form name="def" action="editcustom.php?id=<?php echo $id; ?>" method="post">
  42. <input type="hidden" name="id" value="<?php echo $id; ?>">
  43. <table class="data">
  44. <tr>
  45. <td><?php echo WEB_customer_login; ?></td>
  46. <td><input type="text" name="login" value="<?php print htmlspecialchars($customer['login']); ?>" size=20></td>
  47. </tr>
  48. <tr>
  49. <td><?php echo WEB_cell_description; ?></td>
  50. <td><input type="text" name="description" value="<?php print htmlspecialchars($customer['description']); ?>" size=50></td>
  51. </tr>
  52. <tr>
  53. <td><?php echo WEB_customer_password; ?></td>
  54. <td><input type="password" name="pass" value="" size=20></td>
  55. </tr>
  56. <tr>
  57. <td><?php echo WEB_customer_api_key; ?></td>
  58. <td>
  59. <input type="text" name="api_key" id="api_key" value="<?php print htmlspecialchars($customer['api_key']); ?>" size=50>
  60. <!-- Кнопка перегенерации -->
  61. <button type="button" onclick="generateApiKey()">🔄</button>
  62. </td>
  63. </tr>
  64. <tr>
  65. <td><?php echo WEB_customer_mode; ?></td>
  66. <td><?php print_acl_select($db_link,'f_acl',$customer['rights']); ?></td>
  67. </tr>
  68. <tr>
  69. <td colspan=2>
  70. <input type="submit" name="edituser" value="<?php echo WEB_btn_save; ?>">
  71. </td>
  72. </tr>
  73. </table>
  74. </form>
  75. <script>
  76. function generateApiKey() {
  77. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  78. let result = '';
  79. for (let i = 0; i < 20; i++) {
  80. result += chars.charAt(Math.floor(Math.random() * chars.length));
  81. }
  82. document.getElementById('api_key').value = result;
  83. }
  84. </script>
  85. <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>