This repository has been archived by the owner on Dec 7, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
creat_access.php
198 lines (191 loc) · 8.01 KB
/
creat_access.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
<?php
require_once 'autoload.php';
// Check for accses
User::CheckLogin();
$access = new Access();
$UserAccess = User::getSessionAccses();
if (!$UserAccess->hasAccsesAdmin()) {
header("Location: accses_denied.php");
}
// Update
if (isset($_GET["id"])) {
if ($access->read($_GET["id"])) {
$Data = array(
"title_en" => $access->getTitleEnglish(),
"title_ar" => $access->getTitleArabic(),
"Article" => $access->getArticle(),
"Poll" => $access->getPoll(),
"Gallery" => $access->getGallery(),
"Multimedia" => $access->getYoutube(),
"User" => $access->getUser()
);
} else {
header("Location: 404.php");
exit;
}
}
if (valAllNotnull()) {
// setting the data
$iscorrect = array(
"title_en" => (bool) $access->setTitleEnglish($_POST["title_en"]),
"title_ar" => (bool) $access->setTitleArabic($_POST["title_ar"]),
"Article" => (bool) $access->setArticle($_POST["Article"]),
"Poll" => (bool) $access->setPoll($_POST["Poll"]),
"Gallery" => (bool) $access->setGallery($_POST["title_en"]),
"Multimedia" => (bool) $access->setYoutube($_POST["Multimedia"]),
"User" => (bool) $access->setUser($_POST["User"])
);
$passed = FALSE;
// check if the imput is valid
if (Validation::valAll($iscorrect)) {
if (isset($_GET["id"])) {
$passed = (bool) $access->update();
} else {
$passed = (bool) $access->create();
}
}
// check if every thing went right
if ($passed) {
header("Location: index.php");
exit;
} else {
$Data = array(
"title_en" => $_POST["title_en"],
"title_ar" => $_POST["title_ar"],
"Article" => $_POST["Article"],
"Poll" => $_POST["Poll"],
"Gallery" => $_POST["Gallery"],
"Multimedia" => $_POST["Multimedia"],
"User" => $_POST["User"]
);
}
}
function valAllNotnull() {
return
isset($_POST["title_en"]) &&
isset($_POST["title_ar"]) &&
isset($_POST["Article"]) &&
isset($_POST["Poll"]) &&
isset($_POST["Gallery"]) &&
isset($_POST["Multimedia"]) &&
isset($_POST["User"]);
}
?><!DOCTYPE html>
<html lang="en">
<head>
<title>ACU Times | Article</title>
<?php require_once("header.php"); ?>
<script type="text/javascript" src="js/Poll.js"></script>
<script type="text/javascript" src="js/SocialMedia.js"></script>
</head>
<body>
<?php include ("navbar.php"); ?>
<div class="container">
<br><br>
<form class="form-horizontal" role="form" method="post" action="creat_access.php<?php if (isset($_GET["id"])) echo "?id=" . $_GET["id"] ?>">
<div class="form-group">
<label class="control-label col-sm-2" for="title_en">Title :</label>
<div class="controls col-sm-10">
<input type="text"
name="title_en"
id="title_en"
value="<?php echo @$Data["title_en"]; ?>"
placeholder="Enter title in English"
class="form-control"
onBlur="valTitle(this)"
maxlength="128"
required
autocomplete="on">
<span class="help-block">
<ul>
<?php PrintHTML::validation("title_en", @$iscorrect["title_en"], "Invalid Input") ?>
</ul>
</span></div>
</div>
<!-- #################################################################### Title-AR #################################################################### -->
<div class="form-group">
<label class="control-label col-sm-2" for="title_ar">Title :</label>
<div class="controls col-sm-10">
<input type="text"
name="title_ar"
id="title_ar"
value="<?php echo @$Data["title_ar"]; ?>"
placeholder="Enter title in arabic"
class="form-control"
onBlur="valTitle(this)"
maxlength="128"
required
autocomplete="on">
<span class="help-block">
<ul>
<?php PrintHTML::validation("title_ar", @$iscorrect["title_ar"], "Invalid Input") ?>
</ul>
</span></div>
</div>
<br>
<h4 class="text-center text-primary">Has access to</h4>
<hr>
<div class="form-group">
<label class="control-label col-sm-2" for="Article">Article:</label>
<div class="col-sm-5">
<select class="form-control" id="Article" name="Article">
<option value="<?php Access::READ ?>" <?php if (@$Data[Article] == 0) echo ' selected="selected"'; ?>>Read</option>
<option value="<?php Access::CREATE ?>"<?php if (@$Data[Article] == 1) echo ' selected="selected"'; ?>>Create</option>
<option value="<?php Access::APPROVE ?>"<?php if (@$Data[Article] == 2) echo ' selected="selected"'; ?>>Approve</option>
<option value="<?php Access::PUBLISH ?>"<?php if (@$Data[Article] == 3) echo ' selected="selected"'; ?>>Publish</option>
<option value="<?php Access::FULL ?>"<?php if (@$Data[Article] == 4) echo ' selected="selected"'; ?>>Full</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Poll">Poll:</label>
<div class="col-sm-5">
<select class="form-control" id="Poll" name="Poll">
<option value="<?php Access::READ ?>" <?php if (@$Data[Poll] == 0) echo ' selected="selected"'; ?>>Read</option>
<option value="<?php Access::CREATE ?>"<?php if (@$Data[Poll] == 1) echo ' selected="selected"'; ?>>Create</option>
<option value="<?php Access::APPROVE ?>"<?php if (@$Data[Poll] == 2) echo ' selected="selected"'; ?>>Approve</option>
<option value="<?php Access::PUBLISH ?>"<?php if (@$Data[Poll] == 3) echo ' selected="selected"'; ?>>Publish</option>
<option value="<?php Access::FULL ?>"<?php if (@$Data[Poll] == 4) echo ' selected="selected"'; ?>>Full</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Gallery">Gallery:</label>
<div class="col-sm-5">
<select class="form-control" id="Gallery" name="Gallery">
<option value="<?php Access::READ ?>" selected<?php if (@$Data[Gallery] == 0) echo ' selected="selected"'; ?>>Read</option>
<option value="<?php Access::CREATE ?>"<?php if (@$Data[Gallery] == 1) echo ' selected="selected"'; ?>>Create</option>
<option value="<?php Access::APPROVE ?>"<?php if (@$Data[Gallery] == 2) echo ' selected="selected"'; ?>>Approve</option>
<option value="<?php Access::PUBLISH ?>"<?php if (@$Data[Gallery] == 3) echo ' selected="selected"'; ?>>Publish</option>
<option value="<?php Access::FULL ?>"<?php if (@$Data[Gallery] == 4) echo ' selected="selected"'; ?>>Full</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Multimedia">Multimedia:</label>
<div class="col-sm-5">
<select class="form-control" id="Multimedia" name="Multimedia">
<option value="<?php Access::READ ?>" <?php if (@$Data[Multimedia] == 0) echo ' selected="selected"'; ?>>Read</option>
<option value="<?php Access::CREATE ?>"<?php if (@$Data[Multimedia] == 1) echo ' selected="selected"'; ?>>Create</option>
<option value="<?php Access::APPROVE ?>"<?php if (@$Data[Multimedia] == 2) echo ' selected="selected"'; ?>>Approve</option>
<option value="<?php Access::PUBLISH ?>"<?php if (@$Data[Multimedia] == 3) echo ' selected="selected"'; ?>>Publish</option>
<option value="<?php Access::FULL ?>"<?php if (@$Data[Multimedia] == 4) echo ' selected="selected"'; ?>>Full</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="User">User:</label>
<div class="col-sm-5">
<select class="form-control" id="User" name="User">
<option value="<?php Access::READ ?>" <?php if (@$Data[User] == 0) echo ' selected="selected"'; ?>>Read</option>
<option value="<?php Access::CREATE ?>"<?php if (@$Data[User] == 1) echo ' selected="selected"'; ?>>Create</option>
<option value="<?php Access::FULL ?>"<?php if (@$Data[User] == 4) echo ' selected="selected"'; ?>>Full</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary pull-right" name="submit" id="submit" >Submit</button>
</form>
</div>
<?php include ("footer.php"); ?>
</body>
</html>