-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_exp.php
245 lines (220 loc) · 8.14 KB
/
edit_exp.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/db_connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php require_once("../includes/validation_functions.php"); ?>
<?php admin_logged_in(); ?>
<?php
$exp = find_exp_by_id($_GET["id"]);
if (!$exp) {
// exp ID was missing or invalid or
// exp couldn't be found in database
redirect_to("404.php");
}
?>
<?php
if (isset($_POST['submit'])) {
// Process the form
// validations
$required_fields = array("name", "path");
validate_presences($required_fields);
$fields_with_max_lengths = array("name" => 30);
validate_max_lengths($fields_with_max_lengths);
if (empty($errors)) {
// Perform Update
$id = $exp["id"];
$name = mysql_prep($_POST["name"]);
$aim = mysql_prep($_POST["aim"]);
$requirement = mysqli_real_escape_string($connection, htmlentities($_POST["requirement"]));
$objective = mysqli_real_escape_string($connection, htmlentities($_POST["objective"]));
$theory = mysqli_real_escape_string($connection, htmlentities($_POST["theory"]));
$path = mysql_prep($_POST["path"]);
$query = "UPDATE experiments SET ";
$query .= "name = '{$name}', ";
$query .= "aim = '{$aim}', ";
$query .= "requirement = '{$requirement}', ";
$query .= "objective = '{$objective}', ";
$query .= "theory = '{$theory}', ";
$query .= "path = '{$path}' ";
$query .= "WHERE id = {$id} ";
$query .= "LIMIT 1";
$result = mysqli_query($connection, $query);
if ($result && mysqli_affected_rows($connection) == 1) {
// Success
$_SESSION["message"] = "Experiment updated.";
redirect_to("admin.php");
} else {
// Failure
$_SESSION["message"] = "exp update failed.";
}
}
} else {
// This is probably a GET request
} // end: if (isset($_POST['submit']))
?>
<!DOCTYPE html>
<html>
<head>
<title>
SAKEC Virtual Lab
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link media="all" type="text/css" rel="stylesheet" href="css/bootstrap.css">
<link media="all" type="text/css" rel="stylesheet" href="css/bootstrap-theme.css">
<link media="all" type="text/css" rel="stylesheet" href="css/signin.css">
<link href="justified-nav.css" rel="stylesheet">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!-- TinyMCE -->
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,visualblocks",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
content_css : "tinymce/examples/css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "tinymce/examples/lists/template_list.js",
external_link_list_url : "tinymce/examples/lists/link_list.js",
external_image_list_url : "tinymce/examples/lists/image_list.js",
media_external_list_url : "tinymce/examples/lists/media_list.js",
// Style formats
style_formats : [
{title : 'Bold text', inline : 'b'},
{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
{title : 'Example 1', inline : 'span', classes : 'example1'},
{title : 'Example 2', inline : 'span', classes : 'example2'},
{title : 'Table styles'},
{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
],
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
<!-- /TinyMCE -->
</head>
<body>
<div id="wrapper">
<div id="header">
<table>
<tr>
<td>
<div id="logo" align='center'>
<table border='0'>
<tr>
<td>
<h1><a href="#">Virtual Labs - SAKEC</a></h1>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
<!-- end #header -->
<div class="navbar-wrapper">
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">SAKEC Virtual Lab</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.php">Home</a></li>
<li><a href="experiments.php">Experiments</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php
if(isset($_SESSION['user_id'])){
if($_SESSION['username']=='admin') {
$link = 'admin.php';
}
else{
$link = '#';
}}
?>
<?php
if(isset($_SESSION['user_id'])){
echo "<li><a href=\"$link\">" . htmlentities($_SESSION["username"]) . "</a></li>" ;
echo "<li><a href=\"logout.php\">Logout</a></li>";
}
else{
echo "<li><a href=\"login.php\">Login</a></li>";
echo "<li><a href=\"register.php\">Register</a></li>";
}
?>
</ul>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<center>
<div id="main">
<div id="navigation">
</div>
<div id="page">
<?php echo message(); ?>
<?php echo form_errors($errors); ?>
<h2>Edit exp: <?php echo htmlentities($exp["name"]); ?></h2>
<form action="edit_exp.php?id=<?php echo urlencode($exp["id"]); ?>" method="post">
<table class="table table-bordered">
<tr>
<td width="10%"><b>Name: </b></td>
<td width="90%"><input type="textarea" name="name" size="60" value="<?php echo htmlentities($exp["name"]); ?>" /></td>
</td>
</tr>
<td width="10%"><b>Aim: </b></td>
<td width="90%"><input type="textarea" name="aim" size="100" value="<?php echo html_entity_decode($exp["aim"]); ?>" /></td>
</tr>
<tr>
<td width="10%"><b>Requirement: </b></td>
<td width="90%"><textarea name="requirement" rows="4" cols="100" /><?php echo html_entity_decode($exp["requirement"]); ?></textarea></td>
</tr>
<tr>
<td width="10%"><b>Objective: </b></td>
<td width="90%"><textarea name="objective" rows="4" cols="100" /><?php echo html_entity_decode($exp["objective"]); ?></textarea></td>
</tr>
<tr>
<td width="10%"><b>Theory: </b></td>
<td width="90%"><textarea name="theory" rows="15" cols="100" /><?php echo html_entity_decode($exp["theory"]); ?></textarea></td>
</tr>
<tr>
<td width="10%"><b>Path: </b></td>
<td width="90%"><input type="textarea" name="path" size="35" value="<?php echo htmlentities($exp["path"]); ?>" /></td>
</tr>
</table>
<input type="submit" name="submit" value="Edit exp" />
</form>
<br />
<a href="admin.php">Cancel</a>
</div>
</div>
</center>
</div>
<?php include("../includes/footer.php"); ?>