1
0

devvendors.php 3.8 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. if (isset($_POST['save'])) {
  6. $saved = array();
  7. //button save
  8. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  9. for ($i = 0; $i < $len; $i ++) {
  10. $save_id = intval($_POST['save'][$i]);
  11. if ($save_id == 0) { continue; }
  12. if ($save_id<10000) { continue; }
  13. array_push($saved,$save_id);
  14. }
  15. //select box
  16. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  17. if ($len>0) {
  18. for ($i = 0; $i < $len; $i ++) {
  19. $save_id = intval($_POST['f_id'][$i]);
  20. if ($save_id == 0) { continue; }
  21. if ($save_id<10000) { continue; }
  22. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  23. }
  24. }
  25. //save changes
  26. $len = is_array($saved) ? count($saved) : 0;
  27. for ($i = 0; $i < $len; $i ++) {
  28. $save_id = intval($saved[$i]);
  29. if ($save_id == 0) { continue; }
  30. if ($save_id<10000) { continue; }
  31. $len_all = is_array($_POST['r_id']) ? count($_POST['r_id']) : 0;
  32. for ($j = 0; $j < $len_all; $j ++) {
  33. if (intval($_POST['r_id'][$j]) != $save_id) { continue; }
  34. $new['name'] = $_POST['f_name'][$j];
  35. update_record($db_link, "vendors", "id='{$save_id}'", $new);
  36. }
  37. }
  38. header("Location: " . $_SERVER["REQUEST_URI"]);
  39. exit;
  40. }
  41. if (isset($_POST["create"])) {
  42. $vendor_name = $_POST["new_vendor"];
  43. if (isset($vendor_name)) {
  44. $max_record = get_record_sql($db_link,"SELECT MAX(id) as max_id FROM vendors");
  45. if (!isset($max_record) or $max_record['max_id']<10000) { $next_id = 10000; } else { $next_id = $max_record['max_id'] + 1; }
  46. $new['id'] = $next_id;
  47. $new['name'] = $vendor_name;
  48. insert_record($db_link, "vendors", $new);
  49. }
  50. header("Location: " . $_SERVER["REQUEST_URI"]);
  51. exit;
  52. }
  53. unset($_POST);
  54. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  55. print_control_submenu($page_url);
  56. ?>
  57. <div id="cont">
  58. <br>
  59. <form name="def" action="devvendors.php" method="post">
  60. <table class="data">
  61. <tr>
  62. <td><b><?php print WEB_list_vendors; ?></b></td>
  63. <td><?php print WEB_rows_at_page."&nbsp:";print_row_at_pages('rows',$displayed); ?></td>
  64. <td><input type="submit" name="OK" value="<?php print WEB_btn_show; ?>"></td>
  65. </tr>
  66. </table>
  67. <?php
  68. $countSQL="SELECT Count(*) FROM vendors";
  69. $res = mysqli_query($db_link, $countSQL);
  70. $count_records = mysqli_fetch_array($res);
  71. $total=ceil($count_records[0]/$displayed);
  72. if ($page>$total) { $page=$total; }
  73. if ($page<1) { $page=1; }
  74. $start = ($page * $displayed) - $displayed;
  75. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  76. ?>
  77. <table class="data">
  78. <tr align="center">
  79. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  80. <td><b>Id</b></td>
  81. <td><b><?php echo WEB_model_vendor; ?></b></td>
  82. <td><input type="submit" name='save' value="<?php echo WEB_btn_save; ?>"></td>
  83. </tr>
  84. <?php
  85. $t_ou = get_records_sql($db_link,"SELECT * FROM vendors ORDER BY name LIMIT $start,$displayed");
  86. foreach ($t_ou as $row) {
  87. print "<tr align=center>\n";
  88. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  89. print "<td class=\"data\"><input type=\"hidden\" name='r_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  90. print "<td class=\"data\"><input type=\"text\" name='f_name[]' value='{$row['name']}'></td>\n";
  91. print "<td class=\"data\"></td>\n";
  92. print "</tr>\n";
  93. }
  94. ?>
  95. </table>
  96. <table>
  97. <tr>
  98. <td><input type=text name=new_vendor value="Unknown"></td>
  99. <td><input type="submit" name="create" value="<?php echo WEB_btn_add; ?>"></td>
  100. <td align="right"></td>
  101. </tr>
  102. </table>
  103. </form>
  104. <?php
  105. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  106. ?>