Repository navigation
Expand file tree
/
Copy pathincluded_functions.php
More file actions
174 lines (156 loc) · 7.49 KB
/
Copy pathincluded_functions.php
File metadata and controls
174 lines (156 loc) · 7.49 KB
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
<?php
function redirect_to($new_location) {
header("Location: " . $new_location);
exit;
}
function db_connection() {
require_once("/home/agarrett/DBgarrett.php");
$mysqli = new mysqli(DBHOST, USERNAME, PASSWORD, DBNAME);
if($mysqli->connect_errno) {
die("Could not connect to server!<br />");
}
return $mysqli;
}
function new_header($name="Default", $urlLink="") {
echo "<head>";
echo " <title>$name</title>";
// <!-- Link to Foundation -->";
echo "<link href='/~agarrett/MDB-Free_4.5.12/css/addons/datatables.min.css' rel='stylesheet'>";
//original css imports
echo " <link rel='stylesheet' href='css/normalize.css'>";
echo " <link rel='stylesheet' href='css/foundation.css'>";
echo "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css' integrity='sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm' crossorigin='anonymous'>";
echo "<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js' charset='utf-8'></script>";
echo "<script src='https://code.jquery.com/jquery-3.2.1.slim.min.js' integrity='sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN' crossorigin='anonymous'></script>";
echo "<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js' integrity='sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q' crossorigin='anonymous'></script>";
echo "<script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js' integrity='sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl' crossorigin='anonymous'></script>";
echo "<script type='text/javascript' src='/~agarrett/MDB-Free_4.5.12/js/addons/datatables.min.js'></script>";
echo "<script type='text/javascript'>";
//needed to make tables sortable and searchable
echo "$(document).ready(function () {";
echo "$('#projects').DataTable({";
echo "'ordering': true";
echo "});";
echo "$('.dataTables_length').addClass('bs-select');";
echo "});";
echo "</script>";
echo "<script src='js/vendor/modernizr.js'></script>";
echo "</head>";
echo "<nav class='navbar navbar-expand-lg navbar-dark bg-primary justify-content-between'>";
echo "<a class='navbar-brand' href='#'>The Big Event</a>";
echo "<button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarSupportedContent' aria-controls='navbarSupportedContent' aria-expanded='false' aria-label='Toggle navigation'>";
echo "<span class='navbar-toggler-icon'></span>";
echo "</button>";
echo "<div class='collapse navbar-collapse' id='navbarSupportedContent'>";
echo "<ul class='navbar-nav mr-auto'>";
echo "<li class='nav-item active'>";
echo "<a class='nav-link' href='/~agarrett/index.php'>Home <span class='sr-only'>(current)</span></a>";
echo "</li>";
//only the exec members see this option
if (isset($_SESSION["username"]) && isset($_SESSION["permission"]) && $_SESSION["permission"] === "4") {
echo "<li class='nav-item'>";
echo "<a class='nav-link' href='/~agarrett/register.php'>Volunteers</a>";
echo "</li>";
}
echo "<li class='nav-item'>";
echo "<a class='nav-link' href='/~agarrett/registerHost.php'>Host</a>";
echo "</li>";
//only the exec members see this option
if (isset($_SESSION["username"]) && isset($_SESSION["permission"]) && $_SESSION["permission"] === "4") {
echo "<li class='nav-item dropdown'>";
echo "<a class='nav-link dropdown-toggle' href='#' id='navbarDropdown' role='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>";
echo "Executive Options";
echo "</a>";
echo "<div class='dropdown-menu' aria-labelledby='navbarDropdown'>";
echo "<a class='dropdown-item' href='/~agarrett/volunteer.php'>View Volunteers</a>";
echo "<a class='dropdown-item' href='/~agarrett/execProjectView.php'>View Projects</a>";
echo "<a class='dropdown-item' href='/~agarrett/teamleaders.php'>View Team Leaders</a>";
echo "<a class='dropdown-item' href='/~agarrett/uploadTL.php'>Upload Team Leaders</a>";
//<!-- <div class="dropdown-divider"></div> -->
echo "<a class='dropdown-item' href='groupVolunteers'>Search for a Specific Group</a>";
echo "<a class='dropdown-item' href='addLogin'>Add Organization or Exec Login</a>";
echo "</div>";
// echo "<li class='nav-item'>";
// echo "<a class='nav-link' href='/~agarrett/index.php'>Login</a>";
echo "</li>";
}
echo "</ul>";
echo "<ul class='navbar-nav ml-auto'>";
//see login options if not logged in; see logout if logged in
if (isset($_SESSION["username"])) {
echo "<li class='nav-item'>";
echo "<a class='nav-link' href='/~agarrett/logout.php'>Logout</a>";
echo "</li>";
}
else{
echo "<li class='nav-item dropdown'>";
echo "<a class='nav-link dropdown-toggle' href='#' id='navbarDropdown' role='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>";
echo "Login";
echo "</a>";
echo "<div class='dropdown-menu dropdown-menu-right' aria-labelledby='navbarDropdown'>";
echo "<a class='dropdown-item' href='/~agarrett/volRegister'>Volunteer Login</a>";
echo "<a class='dropdown-item' href='/~agarrett/hostLogin.php'>Host Login</a>";
echo "<a class='dropdown-item' href='/~agarrett/orgLogin.php'>Organization Login</a>";
echo "<a class='dropdown-item' href='/~agarrett/execLogin.php'>Exec Login</a>";
echo "</div>";
echo "</li>";
}
echo "</ul>";
echo "</div>";
echo "</nav>";
echo "<style>";
echo "body{";
echo "background: url('oxford.jpg');";
echo "background-size: cover;";
echo "}";
echo "</style>";
echo "<body>";
}
//function to have new footer
function new_footer($name="Default", $mysqli){
echo "<br /><br /><br />";
echo "<h4><div class='text-center'><small>Copyright ".date("M Y").", ".$name."</small></div></h4>";
echo "</body>";
echo "</html>";
//$mysqli -> close;
}
function print_alert($name="") {
echo "<br />";
echo "<div class='row'>";
echo "<div data-alert class='alert-box info round'>".$name;
echo "</div>";
echo "</div>";
}
//encrypts password
function password_encrypt($password) {
$hash_format = "$2y$10$"; // Use Blowfish with a "cost" of 10
$salt_length = 22; // Blowfish salts should be 22-characters or more
$salt = generate_salt($salt_length);
$format_and_salt = $hash_format . $salt;
$hash = crypt($password, $format_and_salt);
return $hash;
}
//generates salt to encrypt password
function generate_salt($length) {
// MD5 returns 32 characters
$unique_random_string = md5(uniqid(mt_rand(), true));
// Valid characters for a salt are [a-zA-Z0-9./]
$base64_string = base64_encode($unique_random_string);
// Replace '+' with '.' from the base64 encoding
$modified_base64_string = str_replace('+', '.', $base64_string);
// Truncate string to the correct length
$salt = substr($modified_base64_string, 0, $length);
return $salt;
}
//checks password entered and hashed password
function password_check($password, $existing_hash) {
// existing hash contains format and salt at start
$hash = crypt($password, $existing_hash);
if ($hash === $existing_hash) {
return true;
}
else {
return false;
}
}
?>