"; echo "
"; echo " Объект: "; echo " Тип:

Выберите дату:
Введите событие:

"; echo""; if (isset($_POST['added'])) { echo "

Название:

"; echo "
"; } 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 "
"; 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)); } } } ?>