-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathadd.php
97 lines (96 loc) · 3.9 KB
/
add.php
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
<?php
include 'header.php';
#ini_set('display_errors', 1);
#ini_set('display_startup_errors', 1);
#error_reporting(E_ALL);
$queryArray = array();
$currentUser = $_SESSION['login_user_'.$sessionID];
# Generate form information if serial provided
# input information from form submit
if (count($_POST) > 0 && $_POST['serial']) {
$_POST['owner'] = $currentUser;
$jsonConfs = json_encode($_POST);
if (! file_exists($botsDir.$_POST['serial'].".json", $jsonConfs)) {
if(file_put_contents($botsDir.$_POST['serial'].".json", $jsonConfs)) {
msgBox("BotVac information saved.", "success");
} else {
msgBox("BotVac information NOT saved. Are you trying to be naughty?", "danger");
}
header("Location: allBots.php");
die();
} else {
msgBox("This device already exists.", "danger");
header("Location: allBots.php");
die();
}
}
if (isset($_GET['serial'])){
if (file_exists($botsDir.$_GET['serial'].".json")) {
if ( isset($_GET['delete'])) {
if (unlink($botssDir.$_GET['serial'].".json")) {
msgBox("This BotVac configuration was deleted.", "success");
} else {
msgBox("This BotVac configuration was NOT deleted. Please try again.", "danger");
}
} else {
$jsonInfo = file_get_contents($botsDir.$_GET['serial'].".json");
$queryArray = json_decode($jsonInfo, true);
}
} else {
$queryArray['serial'] = $_GET['serial'];
msgBox("This BotVac doesn't have configuration information. You can add it below.", "danger");
}
}
?>
<?php
if ($_SESSION['msgBox'] != "") {
echo '<div class="red-text container">';
echo $_SESSION['msgBox'];
echo '</div>';
$_SESSION['msgBox'] = "";
}
?>
<div class="container container-header border rounded bg-light">
<h1>Insert or Update</h1>
<p>This page allows you to add new BotVac's, or if you've searched your serial with the search button above, or clicked edit from the <a href="allBots.php">All BotVacs</a> page, you will be able to modify it's information.</p>
<form method="post" action="add.php?<?php if (isset($queryArray['serial'])) { echo 'serial='.$queryArray['serial']; }?>">
<div class="form-row">
<div class="form-group col-md-2">
<?php
if (isset($queryArray['serial'])) {
$readonly = "readonly";
} else {
$readonly = "";
}
?>
<label>Serial<input <?php echo $readonly; ?> class="form-control" type="text" id="serial" name="serial" value="<?php if (isset($queryArray['serial'])) { echo $queryArray['serial']; }?>"></label>
</div>
<div class="form-group col-md-2">
<label>Model<input class="form-control" type="text" id="model" name="model" value="<?php if (isset($queryArray['model'])) { echo $queryArray['model']; }?>"></label>
</div>
<div class="form-group col-md-2">
<label>Description<input class="form-control" type="text" id="description" name="description" value="<?php if (isset($queryArray['description'])) { echo $queryArray['description']; }?>"></label>
</div>
<?php
# Adding additional facts that exist in the config.php
$factCount = count($addFacts);
for ($row = 0; $row < $factCount; $row++) {
# Use the previously saved value if it exists
if (isset($queryArray[$addFacts[$row][1]])) {
$factValue = $queryArray[$addFacts[$row][1]];
# User the default value if one exists and isn't empty
} else if (!isset($queryArray[$addFacts[$row][1]]) && $addFacts[$row][3] != ''){
$factValue = $addFacts[$row][3];
} else {
$factValue = '';
}
echo '<div class="form-group col-md-2">';
echo ' <label>'.$addFacts[$row][0].'<input placeholder="'.$addFacts[$row][2].'" class="form-control" type="text" name="'.$addFacts[$row][1].'" value="'.$factValue.'"></label>';
echo '</div>';
}
?>
</div>
<input class="btn btn-success" type="submit" name="" value="Submit">
</form>
</div>
<?php include 'footer.php';?>