-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddrmv.php
More file actions
158 lines (143 loc) · 4.9 KB
/
addrmv.php
File metadata and controls
158 lines (143 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
ob_start();
session_start();
//require_once 'dbconnect.php';
// if session is not set this will redirect to login page
if(!isset($_SESSION['user'])) {
header("Location: login.php");
exit;
}
function sessionTimeOut(){
$logLength = 900;
$ctime = strtotime("now");
if(!isset($_SESSION['sessionX'])){
$_SESSION['sessionX'] = $ctime;
}else{
if((strtotime("now") - $_SESSION['sessionX']) > $logLength){
session_destroy();
header("Location: login.php");
exit;
}else{
$_SESSION['sessionX'] = $ctime;
}
}
}
?>
<html>
<head>
<title>Add</title>
<link rel="stylesheet" type="text/css" href="inventory.css">
<?php sessionTimeOut();
$session = $_SESSION['user'];
echo "Bine ai venit " .$session;
?>
</head>
<body>
<h2>Label Team Inventory System</h2>
<ul>
<li><a href="mysqltest.php">Balance</a></li>
<li><a class="active" href="addrmv.php">Add</a></li>
<li><a href="update.php">Update</a></li>
<li><a href="index.php">Balance by Loc</a></li>
<li><a href="delete.php">Delete</a></li>
<li><a href="export.html">Export</a></li>
<li><a href="transactions.php">Transactions</a></li>
<li><a href="logout.php?logout">Logout</a></li>
</ul>
<form id="addmv" method="POST" action="<?php echo $_SERVER['PHP_SELF']?>" name="addmv">
Serial Number* <input id="serial" type="text" name="serial"></input><br>
Descriere* <input id="desc" type="text" name="desc"></input><br>
Locatie* <input id="loc" type="text" name="loc"><br>
Status* <input id="status" type="text" name="status"><br>
Capex <input id="capex" type="text" name="capex"><br>
Nr. Inventar FAR <input id="far" type="text" name="far"><br>
Observatii <input id="obs" type="text" name="obs"><br>
*Campuri obligatorii<br>
<select id="option" name="option">
<option value="monitor" name="monitor">Monitor</option>
<option value="imprimanta" name="imprimanta">Imprimanta</option>
<option value="ups" name="ups">UPS</option>
<option value="scaner" name="scaner">Scaner</option>
<option value="pc" name="pc">PC</option>
<option value="compimp" name="compimp">Componente Imprimanta</option>
<option value="comppc" name="comppc">Componente PC</option>
<option value="amg_assets" name="amg_assets">AMG Assets</option>
<option value="turn_aps" name="turn_aps">Turn APS</option>
</select><br>
<input id="sub2" type="submit" name="submit" value="Submit" /><br>
<?php
$servername = "localhost";
$dbname = "mydb";
if($session === "Raul Filimon" or $session === "Casian Buta"){
$username = "root";
$password = "Multiread23";
}else{
$username = "generic_user";
$password = "AYVkq4^Sb=YFBvu+";
}
$reason = "ADD";
//Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//check connection
if($conn->connect_error){
die("Connection Error: " . $conn->connect_error);
}
//echo "Connected succesfully<br>";
//insert into tables example
if(isset($_POST['submit'])){
if(empty($_POST["serial"] and $_POST["desc"] and $_POST["loc"] and $_POST["status"])){
echo "Va rog completati campurile obligatorii!";
}else{
$str1 = $_POST["serial"];
$str2 = $_POST["desc"];
$str3 = $_POST["loc"];
$str4 = $_POST["status"];
$str5 = $_POST['capex'];
$str6 = $_POST['far'];
$str7 = $_POST['obs'];
$str1 = strtoupper($str1);
$str2 = strtoupper($str2);
$str3 = strtoupper($str3);
$str4 = strtoupper($str4);
$str5 = strtoupper($str5);
$str6 = strtoupper($str6);
$str7 = strtoupper($str7);
$serial = $str1;
$sql = "INSERT INTO ".$_POST['option']." (SerialNumber, Descriere, Location, Status, Capex, nr_inv_far, observatii)
VALUES ('".$str1."', '".$str2."', '".$str3."', '".$str4."','".$str5."','".$str6."','".$str7."')";
$sql_1 = "INSERT INTO transactions (SerialNumber, Descriere, Location, Status, Capex, nr_inv_far, observatii)
VALUES ('".$str1."', '".$str2."', '".$str3."', '".$str4."','".$str5."','".$str6."','".$str7."')";
$sql_2 = "UPDATE transactions SET `user`='".$session."' WHERE SerialNumber = '".$str1."'";
$sql_3 = "SELECT `id` FROM `transactions` WHERE `SerialNumber` = '".$serial."' ORDER BY `id` DESC LIMIT 0,1";
$result = $conn->query($sql_3);
$row = $result->fetch_assoc();
$id = $row['id'];
if($conn->query($sql) === TRUE && $conn->query($sql_1) === TRUE && $conn->query($sql_2) === TRUE){
$sql_3 = "SELECT `id` FROM `transactions` WHERE `SerialNumber` = '".$serial."' ORDER BY `id` DESC LIMIT 0,1";
$result = $conn->query($sql_3);
$row = $result->fetch_assoc();
$id = $row['id'];
$sql_4 = "UPDATE transactions SET `reason`='".$reason."' WHERE `id`='".$id."'";
if($conn->query($sql_4) === TRUE){
echo "I did it!<br>";
}
} else {
echo "I didn't do it because:<br> " .$conn->error;
}
/*if($conn->query($sql_1) === TRUE){
echo "Succesfully inserted into table1<br>";
} else {
echo "Error inserting into table1:<br> " .$conn->error;
}
if($conn->query($sql_2) === TRUE){
echo "Succesfully inserted into table2<br>";
} else {
echo "Error inserting into table2:<br> " .$conn->error;
}*/
}
}
$conn->close();
?>
</div>
</body>
</html>