object.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <script src="objectdesc.js" type="text/javascript"></script>
  2. <script src="objectcalendar.js" type="text/javascript"></script>
  3. <script src="objectdateget.js" type="text/javascript"></script>
  4. <script src="objectdateadd.js" type="text/javascript"></script>
  5. <?php
  6. if (!$logged_me_in_successfully234)
  7. return;
  8. include "auth.php";
  9. echo " <form id='form2' name='form2' action='?act=object' method='post' enctype='multipart/form-data'>
  10. <input type='submit' name='added' value='Добавить объект'>
  11. <input type='submit' name='delete' value='Удалить объект'>";
  12. echo "<br>";
  13. echo " Объект: <select id='machine' name='machine' size = '5'>";
  14. $query = mysqli_query($link,"select * from object_field WHERE company='$companyID'");
  15. while ($res = mysqli_fetch_array($query))
  16. {
  17. echo "<option value='".$res['id']."'>".$res['name']." ".$res['position']." sc: ".$res['scale']."</option>";
  18. }
  19. echo "</select>";
  20. echo " Тип: <select id='machine2' name='machine2' size = '5'>";
  21. $query = mysqli_query($link,"select * from type_object WHERE company='$companyID'");
  22. while ($res = mysqli_fetch_array($query)) {
  23. echo "<option value='".$res['id']."'>".$res['name']."</option>";
  24. }
  25. echo "</select>
  26. <input id='submittype' type='submit' name='addedtype' value='Присвоить'>
  27. <div id='message' name='message'></div>
  28. <br>
  29. <p>Выберите дату: <input id='calendar' type='date' name='calendar'>
  30. <input id='dateget' type='button' name = 'dateget' value='Вывести'>
  31. <br>
  32. Введите событие: <input id='dateevent' type='text' name='dateevent' id='dateevent'>
  33. <input id='dateadd' type='button' name = 'dateadd' value='Добавить'>
  34. </p>
  35. <div id='message1' name='message1'></div>";
  36. echo"</form>";
  37. if (isset($_POST['added']))
  38. {
  39. echo "
  40. <form id='form3' name='form3' action='?act=object' method='POST'>
  41. <p>Название:<br>
  42. <input type='text' name='namemachine' id='namemachine'></p>
  43. <input type='hidden' name='company' id='company' value='".$companyID."'>
  44. <input id='submit' type='submit' name='added2' value='Добавить'>";
  45. echo "</form>";
  46. }
  47. if (isset($_POST['delete']) )
  48. {
  49. $namemachine = $_POST['machine'];
  50. $company = htmlentities(mysqli_real_escape_string($link, $_POST['company']));
  51. $query = "SELECT * FROM object_field WHERE id='$namemachine'";
  52. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  53. while($id_object=mysqli_fetch_array($result))
  54. $id_deleteobject=$id_object['id'];
  55. $query = "DELETE FROM object_field WHERE id='$namemachine'";
  56. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  57. $query = "DELETE FROM object_detals WHERE id_name='$id_deleteobject'";
  58. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  59. echo "Объект удален";
  60. }
  61. if (isset($_POST['namemachine']) && isset($_POST['added2']) )
  62. {
  63. $namemachine = htmlentities(mysqli_real_escape_string($link, $_POST['namemachine']));
  64. $company = htmlentities(mysqli_real_escape_string($link, $_POST['company']));
  65. $query = "INSERT INTO object_field VALUES (NULL,'$namemachine','$company')";
  66. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  67. echo "Объект добавлен";
  68. }
  69. if (isset($_POST['addedtype']))
  70. {
  71. $idmach=$_POST['machine'];
  72. $idmach2=$_POST['machine2'];
  73. $oldtypequery= mysqli_query($link, "select * from object_detals WHERE id_name='$idmach'");
  74. while ($oldtyperes=mysqli_fetch_array($oldtypequery))
  75. $oldtype=$oldtyperes['id_type'];
  76. $oldtypequery= mysqli_query($link, "select * from type_detals WHERE id='$oldtype'");
  77. while ($oldtyperes=mysqli_fetch_array($oldtypequery))
  78. $oldtype=$oldtyperes['id_type'];
  79. $oldtypequery= mysqli_query($link, "select * from type_object WHERE id='$oldtype'");
  80. while ($oldtyperes=mysqli_fetch_array($oldtypequery))
  81. $oldtype=$oldtyperes['name'];
  82. $query2 = mysqli_query($link, "select * from type_detals WHERE id_type='$idmach2'");
  83. $query ="DELETE FROM object_detals WHERE id_name = '$idmach'";
  84. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  85. while ($res2 = mysqli_fetch_array($query2)) {
  86. $id = $res2['id'];
  87. $type=$res2['type'];
  88. $count = $res2[$type];
  89. $name=$res2['name_detals'];
  90. $links = $res2['link'];
  91. switch ($type)
  92. {
  93. case 'typetext' :
  94. $query = "INSERT INTO object_detals VALUES
  95. (NULL,'$idmach','$id','$name',null,'$type','$count',null,null,'')";
  96. break;
  97. case 'typeint' :
  98. $query = "INSERT INTO object_detals VALUES
  99. (NULL,'$idmach','$id','$name',null,'$type',null,'$count',null,'')";
  100. break;
  101. case 'typefloat' :
  102. $query = "INSERT INTO object_detals VALUES
  103. (NULL,'$idmach','$id','$name',null,'$type',null,null,'$count','')";
  104. break;
  105. case 'typebinary' :
  106. $query = "INSERT INTO object_detals VALUES
  107. (NULL,'$idmach','$id','$name',null,'$type',null,null,null,'$count')";
  108. break;
  109. }
  110. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  111. }
  112. $newtypequery= mysqli_query($link, "select * from object_detals WHERE id_name='$idmach'");
  113. while ($newtyperes=mysqli_fetch_array($newtypequery))
  114. $newtype=$newtyperes['id_type'];
  115. $newtypequery= mysqli_query($link, "select * from type_detals WHERE id='$newtype'");
  116. while ($newtyperes=mysqli_fetch_array($newtypequery))
  117. $newtype=$newtyperes['id_type'];
  118. $newtypequery= mysqli_query($link, "select * from type_object WHERE id='$newtype'");
  119. while ($newtyperes=mysqli_fetch_array($newtypequery))
  120. $newtype=$newtyperes['name'];
  121. $text = "ТИП ".$oldtype." --> ".$newtype;
  122. $queryins = "INSERT INTO object_event VALUES (NULL ,NOW(),'$text','$idmach' )";
  123. $result = mysqli_query($link, $queryins) or die("Ошибка " . mysqli_error($link));
  124. }
  125. if(isset($_POST['save']))
  126. {
  127. /*
  128. $idmach=$_POST['machine'];
  129. $idmach2=$_POST['machine2'];
  130. $textcount = htmlentities(mysqli_real_escape_string($link, $_POST['textcount']));
  131. $textid = htmlentities(mysqli_real_escape_string($link, $_POST['textid'])
  132. $uploaddir = 'temp/';
  133. $uploadfile = $uploaddir .$idmach."/".basename($_FILES['file']['name']);
  134. echo "<br>";
  135. if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
  136. echo "Файл корректен и был успешно загружен.";
  137. $query4 = "UPDATE object_detals SET count='$textcount', link='$uploadfile' WHERE id_type=$textid AND id_name=$idmach";
  138. $result = mysqli_query($link, $query4) or die("Ошибка " . mysqli_error($link));
  139. echo "this";
  140. }
  141. else {
  142. $query4 = mysqli_query($link,
  143. "update object_detals SET count='$textcount', link=null WHERE id_type=$textid AND id_name=$idmach");
  144. echo "thos";
  145. }
  146. */
  147. $id_name = ($_POST['id_name']);
  148. $query = mysqli_query($link, "select * from object_detals where id_name='$id_name'");
  149. while ($res = mysqli_fetch_array($query)) {
  150. $id_type = $res['id_type'];
  151. $count = "count" . $id_type;
  152. $type = "type" . $id_type;
  153. $count = ($_POST[$count]);
  154. $type = ($_POST[$type]);
  155. $query3="SELECT * FROM object_detals WHERE id_type='$id_type' AND id_name='$id_name'";
  156. $result3 = mysqli_query($link, $query3) or die("Ошибка " . mysqli_error($link));
  157. $res3 = mysqli_fetch_array($result3);
  158. $oldvalue=$res3[$type];
  159. if($type!='typetext')
  160. $query2 = "UPDATE object_detals SET $type=".$count.", link=null WHERE id_type='$id_type' AND id_name='$id_name'";
  161. else
  162. $query2 ="UPDATE object_detals SET $type='$count', link=null WHERE id_type='$id_type' AND id_name='$id_name'";
  163. $result2 = mysqli_query($link, $query2) or die("Ошибка " . mysqli_error($link));
  164. $query3="SELECT * FROM object_detals WHERE id_type='$id_type' AND id_name='$id_name'";
  165. $result3 = mysqli_query($link, $query3) or die("Ошибка " . mysqli_error($link));
  166. $res3 = mysqli_fetch_array($result3);
  167. $newvalue=$res3[$type];
  168. $name_detals = $res['name_detals'];
  169. if($newvalue!=$oldvalue) {
  170. $text="ПОЛЕ ".$name_detals." ".$oldvalue." --> ".$newvalue;
  171. $queryins = "INSERT INTO object_event VALUES (NULL ,NOW(),'$text','$id_name' )";
  172. $result = mysqli_query($link, $queryins) or die("Ошибка " . mysqli_error($link));
  173. }
  174. }
  175. }
  176. ?>