-
Notifications
You must be signed in to change notification settings - Fork 2
/
storage_edit.php
158 lines (138 loc) · 5.19 KB
/
storage_edit.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
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
require 'lib/global.php';
if(isset($_POST['submit'])) {
// Clean input
foreach($_POST as $key => $value) {
$$key=$DB->real_escape_string($value);
}
// Only available for managers or above
if($USER->auth>1) {
if(isset($storage_id)) {
// Edit item
if($storage_data=sql_fetch("SELECT * FROM storage WHERE storage_id=$storage_id")) {
// Check which values are different from the saved version
foreach($storage_data as $key => $value) {
if($key!='log' && $$key!=$value) {
$updates[]=$key."=".$$key;
}
}
// Only update if the new data is different
if(count($updates)) {
// Add summary of updates in log message
$log=addLog('Update storage information: '.implode(',',$updates),'update',0,$USER->data['user_email'],$storage_data['log']);
$update=sql_query("UPDATE storage SET
storage_name='$storage_name',
storage_status='$storage_status',
storage_description='$storage_description',
storage_type='$storage_type',
storage_temp='$storage_temp',
storage_location='$storage_location',
log='$log'
WHERE storage_id=$storage_id");
$id=renderStorageID($storage_id);
if($update) {
header('Location: storage_view.php?id='.$id);
} else {
$ALERTS->setAlert("Could not update information for $id");
}
} else {
header('Location: storage_view.php?id='.renderStorageID($storage_id));
}
} else {
$ALERTS->setAlert('Invalid storage ID');
}
} else {
// Add new item
$log=addLog('Adding new storage','add',0,$USER->data['user_email']);
$add=sql_query("INSERT INTO storage SET
storage_name='$storage_name',
storage_status='$storage_status',
storage_description='$storage_description',
storage_type='$storage_type',
storage_temp='$storage_temp',
storage_location='$storage_location',
log='$log'");
if($add) {
$storage_id=$DB->insert_id;
header('Location: storage_view.php?id='.renderStorageID($storage_id));
} else {
$ALERTS->setAlert("Could not add information to database");
}
}
} else {
$ALERTS->setAlert('Not authorised');
$id=isset($storage_id) ? renderStorageID($storage_id) : FALSE;
}
} elseif(isset($_POST['cancel'])) {
if(isset($_POST['storage_id'])) {
header('Location: storage_view.php?id='.renderStorageID($_POST['storage_id']));
} else {
header('Location: storage.php');
}
}
$theform=new htmlForm('storage_edit.php');
$showform=FALSE;
if(isset($_GET['id']) || isset($id)) {
// Edit storage unit
$position=isset($_GET['id']) ? parsePosition($_GET['id']) : parsePosition($id);
if($position['type']=='storage') {
$storage_id=$position['storage_id'];
$storage=getStorage($storage_id);
if($storage['error']) {
$ALERTS->setAlert($storage['error']);
} else {
$showform=TRUE;
$submit='Save';
$theform->addInput(FALSE,array('type' => 'hidden', 'name' => 'storage_id', 'value' => $storage_id));
}
} else {
$ALERTS->setAlert('Invalid storage ID');
}
} else {
// Add new storage unit
$showform=TRUE;
$submit='Add';
}
if($showform) {
$theform->addInput('Name',array('type' => 'text', 'name' => 'storage_name', 'value' => $storage['data']['storage_name']));
$theform->addTextarea('Description',array('name' => 'storage_description'),$storage['data']['storage_description']);
if(count($storage['racks'])>0) {
// Storage can not be disabled if it contains racks
$theform->addSelect('Status','storage_status',array('enabled' => 'Enabled', 'service' => 'Service'), array($storage['data']['storage_status']));
} else {
$theform->addSelect('Status','storage_status',array('enabled' => 'Enabled', 'service' => 'Service', 'disabled' => 'Disabled'), array($storage['data']['storage_status']));
}
$theform->addSelect('Type','storage_type',array('fridge' => 'Fridge', 'freezer' => 'Freezer'), array($storage['data']['storage_type']));
$theform->addInput('Temperature',array('type' => 'number', 'name' => 'storage_temp', 'value' => $storage['data']['storage_temp']));
$theform->addInput('Location',array('type' => 'text', 'name' => 'storage_location', 'value' => $storage['data']['storage_location']));
$theform->addInput(FALSE,array('type' => 'submit', 'name' => 'submit', 'value' => $submit, 'class' => 'button'));
}
$theform->addInput(FALSE,array('type' => 'submit', 'name' => 'cancel', 'value' => 'Cancel', 'class' => 'secondary button'));
// Render Page
//=================================================================================================
?>
<!doctype html>
<html class="no-js" lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PlateJuggler</title>
<link rel="stylesheet" href="css/foundation.css">
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/icons/foundation-icons.css" />
</head>
<body>
<?php require '_menu.php'; ?>
<div class="row">
<br>
<div class="large-12 columns">
<?php echo $theform->render(); ?>
</div>
</div>
<script src="js/vendor/jquery.js"></script>
<script src="js/vendor/what-input.js"></script>
<script src="js/vendor/foundation.js"></script>
<script src="js/app.js"></script>
</body>
</html>