adding first code

This commit is contained in:
Janis Steiner
2024-06-17 20:24:20 +01:00
parent 15d13ebd55
commit fe23e852d0
12 changed files with 2250 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<?php
include "../config/config.php"
$apikey=htmlspecialchars($_GET["apikey"]);
$apikey_fromdb="";
$sql="select apikey from api where id=1";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $apikey_fromdb);
mysqli_stmt_fetch($stmt);
if($apikey!=$apikey_fromdb)
{
echo("wrong apikey");
exit;
}
else
{
$id=htmlspecialchars($_GET["id"]);
$sql="update printer set free=1,printing=0,cancel=0 ,used_by_userid=0 where id=$id";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
}
?>

View File

@@ -0,0 +1,45 @@
<?php
session_start();
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true || $_SESSION["role"][9]!=="1"){
header("location: login.php");
exit;
}
include "../config/config.php";
if($_GET['action']=="update_rotation")
{
$printer_id=htmlspecialchars($_GET['id']);
$rotation=htmlspecialchars($_GET["value"]);
$sql="update printer set rotation=$rotation where id=$printer_id";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
}
if($_GET["action"]=="update_color")
{
$printer_id=htmlspecialchars($_GET['id']);
$color=htmlspecialchars($_GET["value"]);
$sql="update printer set color='$color' where id=$printer_id";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
}
if($_GET["action"]=="update_filament")
{
$id=htmlspecialchars($_GET['id']);
$color=htmlspecialchars($_GET["value"]);
$sql="update filament set name='$color' where internal_id=$id";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
}
if($_GET["action"]=="delete_filament")
{
$id=htmlspecialchars($_GET['id']);
$color=htmlspecialchars($_GET["value"]);
$sql="delete from filament where internal_id=$id";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
}
?>

View File

@@ -0,0 +1,92 @@
<!DOCTYPE html>
<html>
<?php
include "../config/config.php";
?>
<script src="/assets/js/load_page.js"></script>
<script>
function load_user()
{
$(document).ready(function(){
$('#content').load("/assets/php/user_page.php");
});
}
</script>
<?php
echo "<script type='text/javascript' >load_user()</script>";
?>
<?php
$color=$_SESSION["color"];
include "../assets/components.php";
if(isset($_POST["printer"])){
$color=htmlspecialchars($_GET["color"]);
$id=htmlspecialchars($_POST["printer"]);
$sql="update printer set color='$color' where id=$id;";
//echo($sql);
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
}
?>
<div id="content"></div>
<head>
<title>Filamentfarbe Aktualisieren</title>
</head>
<body>
<div class="container mt-5" style="min-height: 95vh;">
<div class="row justify-content-center">
<div style="width: 100hh">
<h1>Filamentfarbe Aktualisieren</h1>
<form class="mt-5" enctype="multipart/form-data" method="POST" action="">
<input type="text" value="<?php echo($_GET["color"]); ?>" name="color" disabled><br><br>
<select class="form-control selector" name="printer" required>
<?php
//get number of printers
$num_of_printers=0;
$sql="select count(*) from printer;";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $num_of_printers);
mysqli_stmt_fetch($stmt);
//echo("test1:".$num_of_printers);
$last_id=0;
$printers_av=0;
while($num_of_printers!=0)
{
$id=0;
$sql="Select id from printer where id>$last_id order by id";
//echo $sql;
$color="";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $id);
mysqli_stmt_fetch($stmt);
if($id!=0 && $id!=$last_id)
{
echo("<option printer='$id' value='$id'>Printer $id</option>");
}
$last_id=$id;
$num_of_printers--;
}
?>
</select><br><br>
<input type="submit" class="btn btn-dark mb-5" value="Farbe aktualisieren" id="button">
</form>
</div>
</div>
</div>
<div id="footer"></div>
</body>
</html>

View File

@@ -0,0 +1,30 @@
<?php
include "../config/config.php";
$apikey=htmlspecialchars($_GET["apikey"]);
$apikey_fromdb="";
$octoapikey=htmlspecialchars($_GET["octoapikey"]);
$sql="select apikey from api where id=1";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $apikey_fromdb);
mysqli_stmt_fetch($stmt);
//echo('got from db:');
//echo($apikey_fromdb);
if($apikey!=$apikey_fromdb)
{
echo("wrong apikey");
exit;
}
else
{
$url=htmlspecialchars($_GET["url"]);
$id=htmlspecialchars($_GET["id"]);
$sql="insert into printer (id, printer_url,printing,free,used_by_userid,system_status,apikey) values ($id,'$url',0,1,0,0,'$octoapikey') on duplicate key update printer_url='$url', apikey='$octoapikey'";
echo($sql);
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
}
?>