-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigDB.php
136 lines (115 loc) · 4.91 KB
/
ConfigDB.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
<?php
// Connect To Database
$UserNameOfDB = "root"; //2
$Password = ""; //3
$HostName = "Localhost"; //1
$DataBaseName = "journaling"; //4
$DB = mysqli_connect($HostName, $UserNameOfDB, $Password, $DataBaseName);
$DB->set_charset("UTF8");
/* //Debug
if ($DB) echo PrintMessage("Done Connecting To DB", "Normal");
else echo PrintMessage("FAILED Connecting To DB", "Danger");
*/
// Set Time Zone To Cairo
date_default_timezone_set('Africa/Cairo');
// Store Vlaue Of Today'S Date With This Format (2022-1-9) In This Variable
$TodayDate = date("Y-m-d");
#Debug
//echo $TodayDate;
//If User didnt logged in yet this function will force him to go to login page , so he wont be able to access any page unless he logged in
function Authunticate()
{
if (!isset($_SESSION['UserID']) && !isset($_COOKIE['RememberMe'])) {
header('location:Login.php');
exit;
}
if (isset($_COOKIE['RememberMe'])) $_SESSION['UserID'] = $_COOKIE['RememberMe'];
}
function IsUserLoggedIn()
{
if (isset($_SESSION['UserID']) || isset($_COOKIE['RememberMe'])) {
if (isset($_COOKIE['RememberMe'])) $_SESSION['UserID'] = $_COOKIE['RememberMe'];
header('location:index.php');
}
}
function AddDateID($TodayDate, $DB)
{
//Initialize with NULL value
$Day_ID = NULL;
//Check if todat's date already exist in `Date` Table
$SelectQueryFromDateT = "SELECT * FROM `date` WHERE Date = '$TodayDate' ";
$ExceuteSelectQuery = mysqli_query($DB, $SelectQueryFromDateT);
$NumOfRows = mysqli_num_rows($ExceuteSelectQuery);
//If todat's date does not exist in `Date` Table, THEN insert it in Table
if (!$NumOfRows) {
$InsertQueryToDateT = "INSERT INTO `Date` VALUES(NULL,'$TodayDate')";
$ExceuteInsertQuery = mysqli_query($DB, $InsertQueryToDateT);
}
// SELECT Today's Date row to be able to store it's ID in $Day_ID variable after fetching row
$SelectQueryFromDateT = "SELECT * FROM `date` WHERE Date = '$TodayDate' ";
$ExceuteSelectQuery = mysqli_query($DB, $SelectQueryFromDateT);
$FetchData = mysqli_fetch_assoc($ExceuteSelectQuery);
$Day_ID = $FetchData['ID'];
//VIP: To Make Today's Date ID Global amoung ALL Pages
$_SESSION['Day_ID'] = $Day_ID;
}
// Create Global Array $_Session
session_start();
// A Function That Print an alert if it takes "Danger" parameter, its color will be read, if "Normal" its color will be blue
function PrintMessage($text, $Type)
{
if ($Type == "Danger") echo "<div style='text-align:center;margin-bottom:0;' class = 'alert alert-danger' role = 'alert' >" . $text . "</div>";
else echo "<div style='text-align:center;margin-bottom:0;' class = 'alert alert-primary' role = 'alert' >" . $text . "</div>";
}
?>
<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<!-- <link rel="stylesheet" href="assets/css/index.css?v=--><?php //echo time(); ?><!--">-->
<!-- Bootstrap -->
<link rel="stylesheet" href="assets/css/bootstrap.css">
</head>
<body>
<!-- Nav Bar Start That will be Shared in All Pages thats why it is in this page as this page is inluded in all pages to connect to Databse-->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="index.php"><span style="color:salmon;">J</span>ournaling</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="TodayList.php">Today's List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="AddData.php">Add Data</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="History.php">History</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="AddQuestions.php">Add Questions</a>
</li>
<?php if (!isset($_SESSION['UserID'])) : ?>
<li class="nav-item">
<a class="nav-link" href="Login.php">Login</a>
</li>
<?php else : ?>
<li style="width:15%;" class="nav-item">
<a id="Logout" class="nav-link" href="index.php?LogOut=1">Logout</a>
</li>
<?php endif ?>
</ul>
</div>
</nav>
<!-- Nav Bar End-->
<!-- Core -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
</body>
</html>