devices.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 
  2. <?
  3. if (!$logged_me_in_successfully234)
  4. return;
  5. include "qrcode.php";
  6. if (isset($_POST['delete']) && isset($_POST['id']) )
  7. {
  8. $id_remove = htmlentities(mysqli_real_escape_string($link, $_POST['id']));
  9. $query = "DELETE FROM device_requests WHERE id='$id_remove'";
  10. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  11. }
  12. if (isset($_POST['new']) == 1)
  13. {$new=$_POST['new'];
  14. $rand=rand(1,1000);
  15. $query1 = mysqli_query($link, "SELECT id FROM devices");
  16. while ($res1 = mysqli_fetch_array($query1)) {
  17. if ($res1['id']=$rand)
  18. {$rand=rand(1,1000);}
  19. }
  20. $id =$rand;
  21. ?>
  22. <script src="validate.js" type="text/javascript"></script>
  23. <?
  24. echo '<form action="?act=devices" method="post">
  25. <b>Отсканируйте данный QR-код для привязки устройства!</b>
  26. <br></form>';
  27. echo "<br>";
  28. $company = $companyID;
  29. $dateToBin=pack("Cl*",3, $id);
  30. $datebase64=base64_encode($dateToBin);
  31. echo "$datebase64<br>";
  32. $filename = $PNG_TEMP_DIR . $id . md5('binddevice'. '|' . $errorCorrectionLevel . '|7') . '.png';
  33. QRcode::png($datebase64, $filename, $errorCorrectionLevel, 7, 2);
  34. echo '<img src="' . $PNG_WEB_DIR . basename($filename) . '" />';
  35. ?>
  36. <form method='POST'">
  37. <span id="message"></span>
  38. <?php
  39. echo "<input type='hidden' id='max' name='max' value=$id>";
  40. ?>
  41. </form>
  42. <?php
  43. ?>
  44. <script src="buttonClick.js" type="text/javascript"></script>
  45. <?
  46. echo "<button class='button' data-url=$id >переход по ссылке</button>";
  47. }
  48. else
  49. {
  50. ?>
  51. <form method='POST'">
  52. <span id="message"></span>
  53. <?php
  54. echo "
  55. <form id='form2' action='?act=devices' name='form2' method='POST'>
  56. <input type='submit' value='Добавить новое устройство'>
  57. <input type='hidden' name='new' value='1'>
  58. </form> ";
  59. $query1 = mysqli_query($link, "SELECT * FROM device_requests ORDER BY date DESC");
  60. echo "
  61. <form id='form1' name='form1' method='post'>";
  62. echo"<table border='1px' cellspacing='0'>
  63. <tr>
  64. <th >Date:</th>
  65. <th >Device ID:</th>
  66. <th ></th>
  67. <tr>";
  68. while ($res1 = mysqli_fetch_array($query1)) {
  69. echo "<tr>";
  70. echo "<td border='1px'>" . $res1['date'] . "</td>";
  71. echo "<td border='1px'>" . $res1['device_id'] . "</td>";
  72. echo "<td border='1px'>
  73. <form id='form2' action='?act=devices' name='form2' method='POST'>
  74. <input type='submit' name='delete' value='удалить'>
  75. <input type='hidden' name='id' value='$res1[id]'></td>
  76. </form>
  77. </tr >";
  78. }
  79. echo"</table>";
  80. /* $query1 = mysqli_query($link, "SELECT * FROM devices ORDER BY date DESC");
  81. echo "
  82. <form id='form1' name='form1' method='post'>";
  83. echo"<table border='1px' cellspacing='0'>
  84. <tr>
  85. <th >Date:</th>
  86. <th >Device ID:</th>
  87. <th>Name</th>
  88. <th>OS</th>
  89. <th >Company_id</th>
  90. <th ></th>
  91. </tr>";
  92. while ($res1 = mysqli_fetch_array($query1)) {
  93. echo "<td border='1px'>". $res1['date'] . "</td>";
  94. echo "<td border='1px'>". $res1['id'] . "</td>";
  95. echo "<td border='1px'>". $res1['name'] . "</td>";
  96. echo "<td border='1px'>". $res1['os'] . "</td>";
  97. echo "<td border='1px'>". $res1['company_id'] . "</td>";
  98. echo "<td border='1px'>
  99. <form id='form2' action='?act=devices' name='form2' method='POST'>
  100. <input type='submit' name='delete' value='удалить'>
  101. <input type='hidden' name='id' value='$res1[id]'></td>
  102. </form>
  103. </tr >";
  104. }
  105. echo"</table>";
  106. */
  107. }
  108. ?>