devvendors.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. $default_displayed=25;
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  5. // Сохранение изменений
  6. if (getPOST("save") !== null) {
  7. $selected_ids = getPOST("f_id", null, []);
  8. if (!empty($selected_ids) && is_array($selected_ids)) {
  9. // Преобразуем в целые числа и оставляем только >= 10000
  10. $selected_ids = array_filter(array_map('intval', $selected_ids), fn($id) => $id >= 10000);
  11. if (!empty($selected_ids)) {
  12. $r_ids = array_map('intval', getPOST("r_id", null, []));
  13. $f_names = getPOST("f_name", null, []);
  14. foreach ($selected_ids as $vendor_id) {
  15. $idx = array_search($vendor_id, $r_ids, true);
  16. if ($idx === false) continue;
  17. $name = trim($f_names[$idx] ?? '');
  18. if ($name === '') continue;
  19. update_record($db_link, "vendors", "id = ?", ['name' => $name], [$vendor_id]);
  20. }
  21. }
  22. }
  23. header("Location: " . $_SERVER["REQUEST_URI"]);
  24. exit;
  25. }
  26. // Создание нового производителя
  27. if (getPOST("create") !== null) {
  28. $vendor_name = trim(getPOST("new_vendor", null, ''));
  29. if ($vendor_name !== '') {
  30. $max_record = get_record_sql($db_link, "SELECT MAX(id) AS max_id FROM vendors");
  31. $next_id = (isset($max_record['max_id']) && $max_record['max_id'] >= 10000)
  32. ? (int)$max_record['max_id'] + 1
  33. : 10000;
  34. insert_record($db_link, "vendors", [
  35. 'id' => $next_id,
  36. 'name' => $vendor_name
  37. ]);
  38. }
  39. header("Location: " . $_SERVER["REQUEST_URI"]);
  40. exit;
  41. }
  42. unset($_POST);
  43. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  44. print_control_submenu($page_url);
  45. ?>
  46. <div id="cont">
  47. <br>
  48. <form name="def" action="devvendors.php" method="post">
  49. <table class="data">
  50. <tr>
  51. <td><b><?php print WEB_list_vendors; ?></b></td>
  52. <td><?php print WEB_rows_at_page."&nbsp:";print_row_at_pages('rows',$displayed); ?></td>
  53. <td><input type="submit" name="OK" value="<?php print WEB_btn_show; ?>"></td>
  54. </tr>
  55. </table>
  56. <?php
  57. $countSQL="SELECT Count(*) FROM vendors";
  58. $count_records = get_single_field($db_link,$countSQL);
  59. $total=ceil($count_records/$displayed);
  60. if ($page>$total) { $page=$total; }
  61. if ($page<1) { $page=1; }
  62. $start = ($page * $displayed) - $displayed;
  63. print_navigation($page_url,$page,$displayed,$count_records,$total);
  64. ?>
  65. <table class="data">
  66. <tr align="center">
  67. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  68. <td><b>Id</b></td>
  69. <td><b><?php echo WEB_model_vendor; ?></b></td>
  70. <td><input type="submit" name='save' value="<?php echo WEB_btn_save; ?>"></td>
  71. </tr>
  72. <?php
  73. $params[]=$displayed;
  74. $params[]=$start;
  75. $t_ou = get_records_sql($db_link,"SELECT * FROM vendors ORDER BY name LIMIT ? OFFSET ?", $params);
  76. foreach ($t_ou as $row) {
  77. print "<tr align=center>\n";
  78. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  79. print "<td class=\"data\"><input type=\"hidden\" name='r_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  80. print "<td class=\"data\"><input type=\"text\" name='f_name[]' value='{$row['name']}'></td>\n";
  81. print "<td class=\"data\"></td>\n";
  82. print "</tr>\n";
  83. }
  84. ?>
  85. </table>
  86. <table>
  87. <tr>
  88. <td><input type=text name=new_vendor value="Unknown"></td>
  89. <td><input type="submit" name="create" value="<?php echo WEB_btn_add; ?>"></td>
  90. <td align="right"></td>
  91. </tr>
  92. </table>
  93. </form>
  94. <?php
  95. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  96. ?>