-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupapps.php
132 lines (130 loc) · 4.04 KB
/
setupapps.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
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
<?php
require 'inc/functions.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if( isset( $_POST['submit_new'] ) ) {
$name = secureInput( $_POST['name'] );
$URL = secureInput( $_POST['url'] );
$machine = secureInput( $_POST['machine'] );
$insert = $db->query( "INSERT INTO `applications`(`name`,`url`,`machine`) VALUES('$name','$URL','$machine')" );
if( ! $insert ) {
die( "Failed" );
} else {
go( "setupapps.php?added" );
}
}
if( isset( $_POST['submit_delete'] ) ) {
$delete = secureInput( $_POST['delete'] );
$del = $db->query( "DELETE FROM `applications` WHERE `id` ='$delete' LIMIT 1" );
if( ! $del ) {
die( "Failed" );
} else {
go( "setupapps.php?deleted" );
}
}
?>
<!doctype html>
<html lang="en">
<head>
<?php
require 'inc/header.php';
?>
</head>
<body>
<?php require 'inc/menu.php'; ?>
<main role="main" class="container">
<h1>Setup Applications</h1>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item active" aria-current="page">Setup Apps</li>
</ol>
</nav>
<?php
if( isset( $_GET['deleted'] ) ) {
echo '<div class="alert alert-success" role="alert">Application deleted!</div>';
}
if( isset( $_GET['added'] ) ) {
echo '<div class="alert alert-success" role="alert">Application added!</div>';
}
$getApps = $db->query( "SELECT * FROM `applications` ORDER BY `name` ASC" );
?>
<div class="card">
<div class="card-header"><strong>Current Applications:</strong></div>
<div class="card-body">
<ul>
<?php
while( $row = $getApps->fetchArray() ) {
$machine = (int)$row['machine'];
$getMachine = $db->query( "SELECT `name` FROM `machines` WHERE `id` ='$machine' LIMIT 1" );
while( $mac = $getMachine->fetchArray() ) {
echo "<li>" . $row['name'] . " on " . $mac['name'] . "</li>";
}
}
?>
</ul>
</div>
</div>
<div class="card">
<div class="card-header"><strong>New Application</strong></div>
<div class="card-body">
<form method="post">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Name:</span>
</div>
<input type="text" name="name" placeholder="Freenas" class="form-control">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">URL:</span>
</div>
<input type="text" name="url" placeholder="http://192.168.1.1/" class="form-control">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Machine:</span>
</div>
<select name="machine" class="form-control">
<option select disabled>--Select--</option>
<?php
$getMachines = $db->query( "SELECT * FROM `machines`" );
while( $row = $getMachines->fetchArray() ) {
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "</option>";
}
?>
</select>
</div>
<br />
<input type="submit" value="Save" name="submit_new" class="btn btn-success">
</form>
</div>
</div>
<div class="card">
<div class="card-header"><strong>Delete Application</strong></div>
<div class="card-body">
<form method="post">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Select:</span>
</div>
<select name="delete" class="form-control">
<option selected disabled>--Select--</option>
<?php
while( $app = $getApps->fetchArray() ) {
echo "<option value='" . $app['id'] . "'>" . $app['name'] . "</option>";
}
?>
</select>
<div class="input-group-append">
<button type="submit" name="submit_delete" class="btn btn-danger">Delete</button>
</div>
</div>
</form>
</div>
</div>
</main>
<?php require 'inc/footer.php'; ?>
</body>
</html>