123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- <script src="objectdesc.js" type="text/javascript"></script>
- <script src="objectcalendar.js" type="text/javascript"></script>
- <script src="objectdateget.js" type="text/javascript"></script>
- <script src="objectdateadd.js" type="text/javascript"></script>
- <?php
- if (!$logged_me_in_successfully234)
- return;
- include "auth.php";
- echo " <form id='form2' name='form2' action='?act=object' method='post' enctype='multipart/form-data'>
- <input type='submit' name='added' value='Добавить объект'>
- <input type='submit' name='delete' value='Удалить объект'>";
- echo "<br>";
- echo " Объект: <select id='machine' name='machine' size = '5'>";
- $query = mysqli_query($link,"select * from object_field WHERE company='$companyID'");
- while ($res = mysqli_fetch_array($query))
- {
- echo "<option value='".$res['id']."'>".$res['name']." ".$res['position']." sc: ".$res['scale']."</option>";
- }
- echo "</select>";
- echo " Тип: <select id='machine2' name='machine2' size = '5'>";
- $query = mysqli_query($link,"select * from type_object WHERE company='$companyID'");
- while ($res = mysqli_fetch_array($query)) {
- echo "<option value='".$res['id']."'>".$res['name']."</option>";
- }
- echo "</select>
-
- <input id='submittype' type='submit' name='addedtype' value='Присвоить'>
- <div id='message' name='message'></div>
- <br>
-
- <p>Выберите дату: <input id='calendar' type='date' name='calendar'>
-
- <input id='dateget' type='button' name = 'dateget' value='Вывести'>
- <br>
- Введите событие: <input id='dateevent' type='text' name='dateevent' id='dateevent'>
- <input id='dateadd' type='button' name = 'dateadd' value='Добавить'>
- </p>
-
- <div id='message1' name='message1'></div>";
- echo"</form>";
- if (isset($_POST['added']))
- {
- echo "
- <form id='form3' name='form3' action='?act=object' method='POST'>
- <p>Название:<br>
- <input type='text' name='namemachine' id='namemachine'></p>
- <input type='hidden' name='company' id='company' value='".$companyID."'>
- <input id='submit' type='submit' name='added2' value='Добавить'>";
- echo "</form>";
- }
- if (isset($_POST['delete']) )
- {
- $namemachine = $_POST['machine'];
- $company = htmlentities(mysqli_real_escape_string($link, $_POST['company']));
- $query = "SELECT * FROM object_field WHERE id='$namemachine'";
- $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
- while($id_object=mysqli_fetch_array($result))
- $id_deleteobject=$id_object['id'];
- $query = "DELETE FROM object_field WHERE id='$namemachine'";
- $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
- $query = "DELETE FROM object_detals WHERE id_name='$id_deleteobject'";
- $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
- echo "Объект удален";
- }
- if (isset($_POST['namemachine']) && isset($_POST['added2']) )
- {
- $namemachine = htmlentities(mysqli_real_escape_string($link, $_POST['namemachine']));
- $company = htmlentities(mysqli_real_escape_string($link, $_POST['company']));
- $query = "INSERT INTO object_field VALUES (NULL,'$namemachine','$company')";
- $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
- echo "Объект добавлен";
- }
- if (isset($_POST['addedtype']))
- {
- $idmach=$_POST['machine'];
- $idmach2=$_POST['machine2'];
- $oldtypequery= mysqli_query($link, "select * from object_detals WHERE id_name='$idmach'");
- while ($oldtyperes=mysqli_fetch_array($oldtypequery))
- $oldtype=$oldtyperes['id_type'];
- $oldtypequery= mysqli_query($link, "select * from type_detals WHERE id='$oldtype'");
- while ($oldtyperes=mysqli_fetch_array($oldtypequery))
- $oldtype=$oldtyperes['id_type'];
- $oldtypequery= mysqli_query($link, "select * from type_object WHERE id='$oldtype'");
- while ($oldtyperes=mysqli_fetch_array($oldtypequery))
- $oldtype=$oldtyperes['name'];
- $query2 = mysqli_query($link, "select * from type_detals WHERE id_type='$idmach2'");
- $query ="DELETE FROM object_detals WHERE id_name = '$idmach'";
- $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
- while ($res2 = mysqli_fetch_array($query2)) {
- $id = $res2['id'];
- $type=$res2['type'];
- $count = $res2[$type];
- $name=$res2['name_detals'];
- $links = $res2['link'];
- switch ($type)
- {
- case 'typetext' :
- $query = "INSERT INTO object_detals VALUES
- (NULL,'$idmach','$id','$name',null,'$type','$count',null,null,'')";
- break;
- case 'typeint' :
- $query = "INSERT INTO object_detals VALUES
- (NULL,'$idmach','$id','$name',null,'$type',null,'$count',null,'')";
- break;
- case 'typefloat' :
- $query = "INSERT INTO object_detals VALUES
- (NULL,'$idmach','$id','$name',null,'$type',null,null,'$count','')";
- break;
- case 'typebinary' :
- $query = "INSERT INTO object_detals VALUES
- (NULL,'$idmach','$id','$name',null,'$type',null,null,null,'$count')";
- break;
- }
- $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
- }
- $newtypequery= mysqli_query($link, "select * from object_detals WHERE id_name='$idmach'");
- while ($newtyperes=mysqli_fetch_array($newtypequery))
- $newtype=$newtyperes['id_type'];
- $newtypequery= mysqli_query($link, "select * from type_detals WHERE id='$newtype'");
- while ($newtyperes=mysqli_fetch_array($newtypequery))
- $newtype=$newtyperes['id_type'];
- $newtypequery= mysqli_query($link, "select * from type_object WHERE id='$newtype'");
- while ($newtyperes=mysqli_fetch_array($newtypequery))
- $newtype=$newtyperes['name'];
- $text = "ТИП ".$oldtype." --> ".$newtype;
- $queryins = "INSERT INTO object_event VALUES (NULL ,NOW(),'$text','$idmach' )";
- $result = mysqli_query($link, $queryins) or die("Ошибка " . mysqli_error($link));
- }
- if(isset($_POST['save']))
- {
- /*
- $idmach=$_POST['machine'];
- $idmach2=$_POST['machine2'];
- $textcount = htmlentities(mysqli_real_escape_string($link, $_POST['textcount']));
- $textid = htmlentities(mysqli_real_escape_string($link, $_POST['textid'])
- $uploaddir = 'temp/';
- $uploadfile = $uploaddir .$idmach."/".basename($_FILES['file']['name']);
- echo "<br>";
- if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
- echo "Файл корректен и был успешно загружен.";
- $query4 = "UPDATE object_detals SET count='$textcount', link='$uploadfile' WHERE id_type=$textid AND id_name=$idmach";
- $result = mysqli_query($link, $query4) or die("Ошибка " . mysqli_error($link));
- echo "this";
- }
- else {
- $query4 = mysqli_query($link,
- "update object_detals SET count='$textcount', link=null WHERE id_type=$textid AND id_name=$idmach");
- echo "thos";
- }
- */
- $id_name = ($_POST['id_name']);
- $query = mysqli_query($link, "select * from object_detals where id_name='$id_name'");
- while ($res = mysqli_fetch_array($query)) {
- $id_type = $res['id_type'];
- $count = "count" . $id_type;
- $type = "type" . $id_type;
- $count = ($_POST[$count]);
- $type = ($_POST[$type]);
- $query3="SELECT * FROM object_detals WHERE id_type='$id_type' AND id_name='$id_name'";
- $result3 = mysqli_query($link, $query3) or die("Ошибка " . mysqli_error($link));
- $res3 = mysqli_fetch_array($result3);
- $oldvalue=$res3[$type];
- if($type!='typetext')
- $query2 = "UPDATE object_detals SET $type=".$count.", link=null WHERE id_type='$id_type' AND id_name='$id_name'";
- else
- $query2 ="UPDATE object_detals SET $type='$count', link=null WHERE id_type='$id_type' AND id_name='$id_name'";
- $result2 = mysqli_query($link, $query2) or die("Ошибка " . mysqli_error($link));
- $query3="SELECT * FROM object_detals WHERE id_type='$id_type' AND id_name='$id_name'";
- $result3 = mysqli_query($link, $query3) or die("Ошибка " . mysqli_error($link));
- $res3 = mysqli_fetch_array($result3);
- $newvalue=$res3[$type];
- $name_detals = $res['name_detals'];
- if($newvalue!=$oldvalue) {
- $text="ПОЛЕ ".$name_detals." ".$oldvalue." --> ".$newvalue;
- $queryins = "INSERT INTO object_event VALUES (NULL ,NOW(),'$text','$id_name' )";
- $result = mysqli_query($link, $queryins) or die("Ошибка " . mysqli_error($link));
- }
- }
- }
- ?>
|