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_category.php
134 lines (128 loc) · 4 KB
/
creat_category.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
<?php
require_once 'autoload.php';
// Check for accses
User::CheckLogin();
$category = new Category();
$access = User::getSessionAccses();
if (!$access->hasAccsesAdmin()) {
header("Location: accses_denied.php");
}
// Update
if (isset($_GET["id"])) {
if ($category->read($_GET["id"])) {
$Data = array(
"title_en" => $category->getNameEnglish(),
"title_ar" => $category->getNameArabic(),
"Category" => $category->getParentID()
);
} else {
header("Location: 404.php");
exit;
}
}
if (valAllNotnull()) {
// setting the data
$iscorrect = array(
"title_en" => (bool) $category->setNameEnglish($_POST["title_en"]),
"title_ar" => (bool) $category->setNameArabic($_POST["title_ar"]),
"Category" => (bool) $category->setParentID($_POST["Category"])
);
$passed = FALSE;
// check if the imput is valid
if (Validation::valAll($iscorrect)) {
if (isset($_GET["id"])) {
$passed = (bool) $category->update();
} else {
$passed = (bool) $category->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"],
"Category" => $_POST["Category"]
);
}
}
function valAllNotnull() {
return
isset($_POST["title_en"]) &&
isset($_POST["title_ar"]) &&
isset($_POST["Category"]);
}
?><!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_category.php<?php if (isset($_GET["id"])) echo "?id=" . $_GET["id"] ?>">
<div class="form-group">
<label class="control-label col-sm-2" for="title_en">Category name:</label>
<div class="controls col-sm-10">
<input type="text"
name="title_en"
id="title_en"
value="<?php echo @$Data["title_en"]; ?>"
placeholder="Enter category name in English"
class="form-control"
onBlur="valTitle(this)"
maxlength="32"
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">Category name:</label>
<div class="controls col-sm-10">
<input type="text"
name="title_ar"
id="title_ar"
value="<?php echo @$Data["title_ar"]; ?>"
placeholder="Enter category name in arabic"
class="form-control"
onBlur="valTitle(this)"
maxlength="32"
required
autocomplete="on">
<span class="help-block">
<ul>
<?php PrintHTML::validation("title_ar", @$iscorrect["title_ar"], "Invalid Input") ?>
</ul>
</span></div>
</div>
<!-- #################################################################### Category #################################################################### -->
<div class="form-group">
<label class="control-label col-sm-2" for="Category">Category:</label>
<div class="col-sm-10">
<select class="form-control" id="Category" name="Category">
<option value="-1">Major category</option>
<?php
foreach (Category::readAll() as $Category) {
$Category->PrintOptionMainCategory(@$Data["title_ar"]);
}
?>
</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>