/
edit_notice.php
297 lines (271 loc) · 11.9 KB
/
edit_notice.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
//login.php
$page_name="Edit_notice.php";
include 'core.php';
$ids=@$_GET['ref'];
$ids=htmlentities($ids);
include 'dbms/dbms_imp.php';
$ids=netutralize($ids,$connection);
mysqli_close($connection);
$notice = new notice($ids);
$user = new user ;
$user->get_user($userid); // to get the current user
$title="Edit notice : $notice->title";
$keywords="Edit notice : $notice->title";
?>
<!doctype html>
<html lang="en">
<?php
//includind the head tag
require 'head.php';
?>
<body>
<?php
// including the header of the document
require 'header.php';
// including the blog layout
?>
<div>
<div class="demo-blog demo-blog--blogpost mdl-layout mdl-js-layout has-drawer is-upgraded">
<main class="mdl-layout__content">
<!--<div class="demo-back">
<a class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon" href="index.html" title="go back" role="button">
<i class="material-icons" role="presentation">arrow_back</i>
</a>
</div>-->
<div class="demo-blog__posts mdl-grid">
<?php
// user can only post a notice iff he/she is logged in
if (!islogin()) //if user is not loged in prompt login
{
//echo "You need to be loged in to post a notice. <br/> Login here <a href=\"login\">Login</a>";
include_once 'display/functions/login.func.php';
login('You need to be logged in to edit this notice.');
}
else //display the add notice forum
{
?>
<div class="mdl-card mdl-shadow--4dp mdl-cell mdl-cell--12-col">
<style>
.demo-blog--blogpost .demo-blog__posts > .mdl-card .mdl-card__media
{
background-image: url('images/road_big.jpg');
height: 300px;
}
</style>
<div class="mdl-card__media mdl-color-text--grey-50">
<h3>Edit notice</h3>
</div>
<div class="mdl-color-text--grey-700 mdl-card__supporting-text meta">
</div>
<div class="mdl-color-text--grey-700 mdl-card__supporting-text">
<p>
<!-- Add notice forum -->
<?php
include 'core.php';
include_once 'functions/category_list.func.php';
// variables for the adding notice
$title=$_POST['title'];
$cat=$_POST['cat'];
$tags=$_POST['tags'];
$bref=$_POST['bref'];
$desc=$_POST['desc'];
$piroity=$_POST['piroity']; //can be null
$exlink=$_POST['exlink']; //can be null
$img=$_POST['img']; //can be null
// if the post data is set
if (isset($title) && isset($cat) && isset($tags) && isset($bref) && isset($desc))
{
if (!empty($title) && !empty($cat) && !empty($tags) && !empty($bref) && !empty($desc))
{
$pass=true; //by default checking assume that the data inputed is Valid
// validate the data using validate function
// neutralizing the data
include 'dbms/dbms_imp.php';
$title=netutralize($title,$connection);
$cat=netutralize($cat,$connection);
$tags=netutralize($tags,$connection);
$bref=netutralize($bref,$connection);
$desc=netutralize($desc,$connection);
if (isset($piroity) && !empty($piroity)) //if piroity field is set
{
$piroity=netutralize($piroity,$connection);
}
if (isset($exlink) && !empty($exlink)) //if exlink field is set
{
$exlink=netutralize($exlink,$connection);
}
if (isset($img) && !empty($img)) //if image is uploaded -currently not working :(
{
//netutralization script for it
}
mysqli_close($connection); // terminate database connection
// contitions to check the input data
// if all data inputed is correct then give this data to add notice class to update the notice
if ($pass)
{
$add_notice = new addnotice ;
$add_notice->title=$title;
$add_notice->cat=$cat;
$add_notice->tags=$tags;
$add_notice->bref=$bref;
$add_notice->description=$desc;
if (isset($piroity) && !empty($piroity))
{
$add_notice->piroity=$piroity;
}
else
{
$add_notice->piroity='0'; //0 means low pirority
}
if (isset($exlink) && !empty($exlink))
{
$add_notice->exlink=$exlink;
}
else
{
$add_notice->exlink=''; // exlink is set to empty (default value)
}
if (isset($img) && !empty($img))
{
// code for doing something with it
}
else
{
$add_notice->img='NULL';
}
$add_notice->update_notice($ids);
//var_dump($add_notice); // only for testing
//put a redirector to some page
header('location: entry.php?ref='.$ids); //to redirect to default notice page
}
}
else
{
echo "Make the changes in it";
}
}
?>
<form action="<?php echo "$current_file?ref=$ids"; ?>" method="POST" enctype="" target="">
<div class="mdl-textfield mdl-js-textfield">
<fieldset>
<legend>Title :
<?php
if (isset($title) && empty($title))
{
echo "<br/>Title is missing";
}
?>
</legend>
<input class="mdl-textfield__input" id="title" type="text" name="title" value="<?php if (isset($title)) {echo "$title";} else {echo "$notice->title";}?>">
</fieldset>
<br/>
<?php
$stu='';
if ($user->gender=='m')
{
$stu="Sir,";
}
else if ($user->gender=='f')
{
$stu="Madam,";
}
?>
<fieldset>
<legend>Category : selected one is (sorry <?php echo "$stu"; ?> it can't be changed :( )
<?php
if (isset($cat) && empty($cat))
{
echo "<br/>category is missing";
}
?>
</legend>
<select class="mdl-textfield__input" name="cat" size="1">
<option value="<?php echo "$notice->cat"; ?>"><?php echo "$notice->cat";?></option>
</select>
</fieldset>
<br/>
<fieldset>
<legend>Tags (some words related to it for facilate search feature seperated by comma ',') :
<?php
if (isset($tags) && empty($tags))
{
echo "<br/>Tags is/are missing";
}
?>
</legend>
<input class="mdl-textfield__input" id="tags" type="text" name="tags" value="<?php if (isset($tags)) {echo "$tags";} else {echo "$notice->tags";}?>">
</fieldset>
<br/>
<fieldset>
<legend>briefly describe the notice (in 200 words):
<?php
if (isset($bref) && empty($bref))
{
echo "<br/>Brief description is missing";
}
?>
</legend>
<div class="mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" rows="3" cols="60" id="bref" name="bref" value="<?php if (isset($bref)) {echo "$bref";} else {echo "$notice->bref";}?>"><?php if (isset($bref)) {echo "$bref";} else {echo "$notice->bref";}?></textarea>
</div>
</fieldset>
<br/>
<fieldset>
<legend>Description (full description of the notice in 1000 words max):
<?php
if (isset($desc) && empty($desc))
{
echo "<br/>Description is missing";
}
?>
</legend>
<div class="mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" rows="6" cols="60" id="desc" name="desc" value="<?php if (isset($desc)) {echo "$desc";} else {echo "$notice->description";}?>"><?php if (isset($desc)) {echo "$desc";} else {echo "$notice->description";} ?></textarea>
</div>
</fieldset>
<br/>
<fieldset>
<legend>Pirorty (optional): selected one is (sorry <?php echo "$stu"; ?> it can't be changed :( )
</legend>
<select class="mdl-textfield__input " name="piroity" size="1">
<?php
$result=pirorty_list();
echo "<option value=\""."$notice->piroity"."\">".$result[$notice->piroity]."</option>";
?>
</select>
</fieldset>
<br/>
<fieldset>
<legend>External Link (optional):
</legend>
<input class="mdl-textfield__input" id="exlink" type="text" name="exlink" value="<?php if (isset($exlink)) {echo "$exlink";} else {echo "$notice->exlink";}?>">
</fieldset>
<br/>
<!--<input type="submit" name="log in" value="log in" size="5">-->
<!-- Flat button -->
<div class="mdl-color-text--grey-700 mdl-card__supporting-text meta">
<button class="mdl-button mdl-js-button">
Update it
</button>
</div>
</div>
</form>
</p>
</div>
</div>
<!--navigation panel for large database-->
<?php
}
?>
</div>
<?php
require 'footer.php';
?>
</main>
<!--<div class="mdl-layout__obfuscator"></div>-->
</div>
<script src="material.min.js"></script>
</div>
</body>
</html>