X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=testing%2FMCTXWeb%2Fpublic_html%2Fusers%2Fmodels%2Ffuncs.php;h=9eb69b801d9e83f2176be26b00c61cf4d3888b7d;hb=5303f53cb44fffd4c59890d3c333f74d7cd7cb4e;hp=b1afc72946b023bb03228f487130be304ae9216e;hpb=3dfde391486e81a357e08a24ccb7903c8adfa5aa;p=matches%2FMCTX3420.git
diff --git a/testing/MCTXWeb/public_html/users/models/funcs.php b/testing/MCTXWeb/public_html/users/models/funcs.php
index b1afc72..9eb69b8 100644
--- a/testing/MCTXWeb/public_html/users/models/funcs.php
+++ b/testing/MCTXWeb/public_html/users/models/funcs.php
@@ -154,14 +154,12 @@ function resultBlock($errors,$successes){
//Error block
if(count($errors) > 0)
{
- echo "
-
[X]
-
";
+ echo "";
+
foreach($errors as $error)
{
- echo "
- ".$error."
";
+ echo "
".$error."
";
}
- echo "";
echo "
";
}
//Success block
@@ -179,6 +177,39 @@ function resultBlock($errors,$successes){
}
}
+function notificationBlock($errors, $successes) {
+ if (count($errors) > 0 || count($successes) > 0)
+ {
+ echo '
+
+
+ ';
+ }
+}
+
//Completely sanitizes text
function sanitize($str)
{
@@ -285,6 +316,70 @@ function emailUsernameLinked($email,$username)
}
}
+function permissionNameToId($permission)
+{
+ global $mysqli,$db_table_prefix;
+ $stmt = $mysqli->prepare("SELECT id
+ FROM ".$db_table_prefix."permissions
+ WHERE
+ name = ?
+ LIMIT 1");
+ $stmt->bind_param("s", $permission);
+ $stmt->execute();
+ $stmt->bind_result($id);
+
+ while ($stmt->fetch()){
+ $perm_id = $id;
+ }
+ $stmt->close();
+
+ return $perm_id;
+}
+
+function fetchAllUsersWithPerm($perm_name)
+{
+ global $mysqli,$db_table_prefix;
+
+ $perm_id = permissionNameToId($perm_name);
+ $stmt = $mysqli->prepare("SELECT
+ p1.id
+ FROM ".$db_table_prefix."users p1
+ WHERE EXISTS (SELECT * FROM ".$db_table_prefix."user_permission_matches
+ WHERE user_id=p1.id AND permission_id=?)"
+ );
+ $stmt->bind_param("i", $perm_id);
+ $stmt->execute();
+ $stmt->bind_result($id);
+
+ while ($stmt->fetch()){
+ $row[] = $id;
+ }
+ $stmt->close();
+ return ($row);
+}
+
+function fetchAllUsersWithoutPerm($perm_name)
+{
+ global $mysqli,$db_table_prefix;
+
+ $perm_id = permissionNameToId($perm_name);
+ $stmt = $mysqli->prepare("SELECT
+ p1.id
+ FROM ".$db_table_prefix."users p1
+ WHERE NOT EXISTS (SELECT * FROM ".$db_table_prefix."user_permission_matches
+ WHERE user_id=p1.id AND permission_id=?)"
+ );
+ $stmt->bind_param("i", $perm_id);
+ $stmt->execute();
+ $stmt->bind_result($id);
+
+ while ($stmt->fetch()){
+ $row[] = $id;
+ }
+ $stmt->close();
+ return ($row);
+}
+
//Retrieve information for all users
function fetchAllUsers()
{
@@ -313,6 +408,27 @@ function fetchAllUsers()
return ($row);
}
+//Yeah usercake... Fetches the user id from username
+function fetchUserId($username)
+{
+ global $mysqli,$db_table_prefix;
+ $stmt = $mysqli->prepare("SELECT
+ id
+ FROM ".$db_table_prefix."users
+ WHERE
+ user_name = ?
+ LIMIT 1");
+ $stmt->bind_param("s", $username);
+
+ $stmt->execute();
+ $stmt->bind_result($id);
+ while ($stmt->fetch()){
+ $user_id = $id;
+ }
+ $stmt->close();
+ return $user_id;
+}
+
//Retrieve complete user information by username, token or ID
function fetchUserDetails($username=NULL,$token=NULL, $id=NULL)
{
@@ -1185,7 +1301,7 @@ function securePage($uri){
return true;
}
else {
- header("Location: account.php");
+ header("Location: index.php");
return false;
}
}