forked from Mahmoudb7/faculty_meeting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
346 lines (315 loc) · 10.5 KB
/
functions.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
require_once "db.php";
if (session_status() === PHP_SESSION_NONE)
{
session_start();
}
if (empty(@$_SESSION["app_name"]))
{
// Get Website header information
$header_stmt = $conn->prepare("SELECT `app_name`,
`Uni_name`,
`Faculty_name`,
`Program_name`,
`Faculty-Uni_logo`,
`Program_logo`
FROM application_data");
$header_stmt->execute();
$header_result = $header_stmt->get_result();
$header_row = $header_result->fetch_assoc();
$_SESSION["app_name"] = $header_row["app_name"];
$_SESSION["uni_name"] = $header_row["Uni_name"];
$_SESSION["faculty_name"] = $header_row["Faculty_name"];
$_SESSION["program_name"] = $header_row["Program_name"];
$_SESSION["faculty_logo"] = $header_row["Faculty-Uni_logo"];
$_SESSION["program_logo"] = $header_row["Program_logo"];
}
if (empty(@$_SESSION["image"]))
{
$user_stmt = $conn->prepare("SELECT name, image FROM p39_users WHERE user_id = ?");
$user_stmt->bind_param("i", $_SESSION["user_id"]);
$user_stmt->execute();
$user_result = $user_stmt->get_result();
$user_row = $user_result->fetch_assoc();
@$_SESSION["image"] = $user_row['image'];
@$_SESSION["name"] = $user_row['name'];
}
function Headers()
{
?>
<header>
<div class="user-logged">
<?php
if (!empty($_SESSION["loggedin"])) {
?>
<img src="<?= @$_SESSION['image'] ?>" alt="">
<h5 class="user-name">د. <?= @$_SESSION['name'] ?></h5>
<button class="button btn-basic" onclick="location.href='logout.php'">خروج</button>
<?php
}
?>
</div>
<div class="header-container">
<img class="logo univ-logo" src="images/<?= $_SESSION["faculty_logo"] ?>" alt=""/>
<div class="header-title">
<h3 class="univ-name"><?= $_SESSION["uni_name"] ?> - <?= $_SESSION["faculty_name"] ?></h3>
<h4 class="prog-name" dir=ltr><?= $_SESSION["program_name"] ?></h4>
<h1 class="project-title">
<?= $_SESSION["app_name"] ?>
</h1>
</div>
<img class="logo prog-logo" src="images/<?= $_SESSION["program_logo"] ?>" alt=""/>
</div>
</header>
<?php
}
function Nav()
{
?>
<section class="nav-bar">
<nav>
<ul>
<button class="icon" href="#"><i class="fa-solid fa-bars fa-2xl"></i></button>
<div class="links">
<li><a href="index.php">الصفحة الرئيسية</a></li>
<li><a href="formation.php">التشكيلات</a></li>
<li><a href="meetings.php">المجالس</a></li>
<!-- <li><a href="#">الموضوعات</a></li>-->
<?php if (@$_SESSION["admin"]): ?>
<li><a href="all_subjects.php?f=all">الموضوعات</a></li>
<li><a href="members.php">الاعضاء</a></li>
<li><a href="executive_decisions.php">القرارات التنفيذية</a></li>
<?php
endif;
?>
</div>
</ul>
<?php SearchBar() ?>
</nav>
</section>
<?php
}
function SearchBar()
{
?>
<form class="search" action="<?= basename($_SERVER['PHP_SELF']) ?>" method="get">
<?php switch (basename($_SERVER["PHP_SELF"])) {
case "formation.php": ?>
<div class="select-basic">
<select name="f">
<option value="">عن طريق</option>
<option value="fn">رقم التشكيل</option>
<option value="y">سنة التشكيل</option>
</select>
</div>
<input type="text" placeholder="ابحث عن تشكيل" name="search"/>
<button type="submit" class="btn-basic">
<i class="fa fa-search"></i>
</button>
<?php break;
case "meetings.php": ?>
<div class="select-basic">
<select name="f">
<option value="">عن طريق</option>
<option value="mn">رقم المجلس</option>
<option value="fn">رقم التشكيل</option>
<option value="my">سنة المجلس</option>
</select>
</div>
<input type="text" placeholder="ابحث عن مجلس" name="search"/>
<button type="submit" class="btn-basic">
<i class="fa fa-search"></i>
</button>
<?php break;
case "members.php": ?>
<div class="select-basic">
<select name="f">
<option value="">عن طريق</option>
<option value="mn">اسم العضو</option>
<option value="jt">المسمى الوظيفي</option>
</select>
</div>
<input type="text" placeholder="ابحث عن عضو" name="search"/>
<button type="submit" class="btn-basic">
<i class="fa fa-search"></i>
</button>
<?php break;
} ?>
</form>
<?php
}
function Head($title)
{
?>
<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><?=$title?></title>
<!-- Css -->
<!-- Css Components and Initialize Styles -->
<link rel="stylesheet" href="css/initialize.css" />
<!-- Your Css Here -->
<link rel="stylesheet" href="css/style.css" />
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800;900&family=Work+Sans:wght@200;300;400;500;600;700;800&display=swap"
rel="stylesheet" />
</head>
<?php
}
function Footer()
{
$y = date("Y");
?>
<footer>
<p>جميع الحقوق محفوظة © لدى فريق رقم 39 Bis Seniors <?=$y?></p>
</footer>
<?php
}
function clean_data($str)
{
$str = trim($str);
$str = stripslashes($str);
$str = htmlspecialchars($str, ENT_QUOTES, "UTF-8");
return $str;
}
// Function for validating email
function is_valid_email($email)
{
if (empty($email))
{
return false;
}
else
{
$email = clean_data($email);
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
return false;
}
}
return $email;
}
function is_admin():bool
{
if(@$_SESSION["admin"])
{
return true;
}
else
{
?>
<div class="error">
<img src="./images/icons/error.svg" alt="">
<p>
ليس لديك صلاحية لتحميل هذه الصفحة، سيتم تحويلك تلقائيًا خلال 5 ثواني إلى الصفحة الرئيسية
</p>
</div>
<br>
<?php
header("refresh:5; url=index.php");
footer();
die();
}
}
function is_logged_in():bool
{
if(@$_SESSION["loggedin"] === true)
{
return true;
}
else
{
?>
<div class="error">
<img src="./images/icons/error.svg" alt="">
<p>
You need to log in to view this page. You'll be redirected to the login page in 5 seconds
</p>
</div>
<br>
<?php
header("refresh:5; url=loginn.php");
footer();
die();
}
}
function Upload($source, $destination, $allowed_formats)
{
$result = array();
// $destination = self::Path($destination);
if ((is_dir($destination) === true) && (array_key_exists($source, $_FILES) === true))
{
if (count($_FILES[$source], COUNT_RECURSIVE) == 5)
{
foreach ($_FILES[$source] as $key => $value)
{
$_FILES[$source][$key] = array($value);
}
}
foreach (array_map('basename', $_FILES[$source]['name']) as $key => $value)
{
$new_file_path = $destination . $value;
$file_type = pathinfo($new_file_path, PATHINFO_EXTENSION);
if (in_array($file_type, $allowed_formats))
{
$result[$value] = false;
if ($_FILES[$source]['error'][$key] == UPLOAD_ERR_OK)
{
// $file = ph()->Text->Slug($value, '_', '.');
$file = NULL;
$file = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $file)));
if (file_exists($destination . $file) === true)
{
$file = substr_replace($file, '_' . md5_file($_FILES[$source]['tmp_name'][$key]) . ".$file_type", strrpos($value, '.'), 0);
// $file = substr_replace($file, '_' . hash_file('sha256', $_FILES[$source]['tmp_name'][$key]) . ".$file_type", strrpos($value,'.'),0);
}
if (move_uploaded_file($_FILES[$source]['tmp_name'][$key], $destination . $file) === true)
{
$result[$value] = $destination . $file;
}
}
}
}
}
return $result;
}
function Search($conn, $table = NULL, $query = NULL)
{
if (!empty(clean_data($_GET["f"])))
{
switch (clean_data($_GET["f"]))
{
case "y":
$column = "start_year";
break;
case "fn":
$column = "formation_number";
break;
case "mn":
$column = "meeting_number";
break;
}
$search = "%" . clean_data($_GET["search"]) . "%";
if ($query === NULL)
{
$search_stmt = $conn->prepare("SELECT * FROM $table WHERE " . $column . " LIKE ?");
}
else
{
$search_stmt = $conn->prepare($query);
}
$search_stmt->bind_param("s", $search);
$search_stmt->execute();
$search_result = $search_stmt->get_result();
return $search_result;
}
}
function Delete($conn, $table, $where)
{
$delete_stmt = $conn->prepare("DELETE FROM {$table} WHERE {$where}");
return $delete_stmt;
}