-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
108 lines (99 loc) · 2.49 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
<?php
function pdo_connect_mysql() {
// Update the details below with your MySQL details
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'root';
$DATABASE_PASS = '';
$DATABASE_NAME = 'helpdesk';
try {
return new PDO('mysql:host=' . $DATABASE_HOST . ';dbname=' . $DATABASE_NAME . ';charset=utf8', $DATABASE_USER, $DATABASE_PASS);
} catch (PDOException $exception) {
// If there is an error with the connection, stop the script and display the error.
exit('Failed to connect to database!');
}
}
// Template header, feel free to customize this
function template_header($title) {
echo <<<EOT
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>$title</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
</head>
<body>
<nav class="navtop">
<div>
<h1>Ticketing System</h1>
<a href="index.php"><i class="fas fa-table"></i>Dashboard</a>
<a href="create.php"><i class="fas fa-ticket-alt"></i>Create Ticket</a>
<a href="account.php"><i class="fas fa-user"></i>My Account</a>
</div>
</nav>
EOT;
}
// Template footer
function template_footer() {
echo <<<EOT
</body>
</html>
EOT;
}
?>
<?php
//testetstststssstststssts
function CheckUsername($username)
{
$file = fopen("login.txt", "r");
if(!$file)
{
die("Unable to open the file");
}
$userExists = false;
while ($line = fgets($file))
{
$data = explode(":", $line);
if ($data[0] == $username)
{
$userExists = true;
break;
}
}
fclose($file);
return $userExists;
}
function UserRegistration($username, $password, $uploadFile)
{
$userDetails = "$username:$password:$uploadFile\n";
// Append the new user to the login.txt file
$file = fopen("login.txt", "a");
if(!$file)
{
die("Unable to open the file");
}
fwrite($file, $userDetails);
fclose($file);
}
function Login($username, $password)
{
$file = fopen("login.txt", "r");
if(!$file)
{
die("Unable to open the file");
}
$authenticated = false;
while ($line = fgets($file))
{
$data = explode(":", $line);
if ($data[0] == $username && $password == $data[1])
{
$authenticated = true;
break;
}
}
fclose($file);
return $authenticated;
}
?>