X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=testing%2FMCTXWeb%2Fpublic_html%2Fusers%2Fmodels%2Ffuncs.php;h=a3a9928005c4994343e0417df54c94c2c7bdaaf2;hb=828cdbf49f52572e93c5c5a48e05277525a4055f;hp=b1afc72946b023bb03228f487130be304ae9216e;hpb=4d7acf83795a57a89150d27d21ac86dcb4c33804;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..a3a9928 100644 --- a/testing/MCTXWeb/public_html/users/models/funcs.php +++ b/testing/MCTXWeb/public_html/users/models/funcs.php @@ -154,31 +154,59 @@ function resultBlock($errors,$successes){ //Error block if(count($errors) > 0) { - echo "
- [X] - "; echo "
"; } //Success block if(count($successes) > 0) { - echo "
- [X] - "; echo "
"; } } +function notificationBlock($errors, $successes) { + if (count($errors) > 0 || count($successes) > 0) + { + echo ' +
+
+ Dismiss +
+ +
Notifications
+ '; + + foreach ($errors as $error) + { + echo '

'.$error.'

'; + } + + foreach ($successes as $success) + { + echo '

'.$success.'

'; + } + + echo ' +
+ + '; + } +} + //Completely sanitizes text function sanitize($str) { @@ -285,6 +313,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 +405,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 +1298,7 @@ function securePage($uri){ return true; } else { - header("Location: account.php"); + header("Location: index.php"); return false; } }