about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Mandura <webmaster@kevin-mandura.de>2024-03-11 00:25:29 +0100
committerKevin Mandura <webmaster@kevin-mandura.de>2024-03-11 00:25:29 +0100
commit1ea44a84a54d421cd157d6fcac0165e4505672de (patch)
tree09a163b208bc17e6c0adc2656ad8055a9f44bbb6
parentf35af9d770bc952142fa046a0a7009121f33cc61 (diff)
downloadktls-website-1ea44a84a54d421cd157d6fcac0165e4505672de.tar.gz
ktls-website-1ea44a84a54d421cd157d6fcac0165e4505672de.zip
Add function getUserFileUploadQuota
-rw-r--r--includes/functions/user-account-functions/getUserFileUploadQuota.inc.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/includes/functions/user-account-functions/getUserFileUploadQuota.inc.php b/includes/functions/user-account-functions/getUserFileUploadQuota.inc.php
new file mode 100644
index 0000000..76f9e35
--- /dev/null
+++ b/includes/functions/user-account-functions/getUserFileUploadQuota.inc.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Return the file upload quota (in bytes) for a user
+ *
+ * Specify the database connection object and the ID of an user to
+ * fetch the file upload quota that corresponds to the user.
+ *
+ * @author    Kevin Mandura <webmaster@kevin-mandura.de>
+ * @license   GPL
+ * @param     object  $dbConn  The database connection object
+ * @param     int  $userID  The ID of an user in the database
+ * @return    int  The user's file upload quota in bytes
+ *
+ * @copyright Copyright (c) 2024, Kevin Mandura <webmaster@kevin-mandura.de>
+ */
+function getUserFileUploadQuota(object $dbConn, int $userID):int {
+    /* Require dependencies */
+    require_once(__DIR__ . "/../template-component-functions/errorPage.inc.php");
+    require_once(__DIR__ . "/../logIP.inc.php");
+    require_once(__DIR__ . "/../database-functions/createDatabaseConnection.inc.php");
+
+    $result = 0;
+
+    /* Define SQL statement for reading the 'upload_quota_bytes' column */
+    $sql = "SELECT upload_quota_bytes FROM accounts WHERE id=?;";
+    $stmt = mysqli_stmt_init($dbConn);
+
+    /* If statement preparation fails, abort with error message */
+    if (!mysqli_stmt_prepare($stmt, $sql)) {
+        logIP($dbConn, $_SERVER["REMOTE_ADDR"]);
+        errorPage(500); /* Internal Server Error */
+    }
+
+    /* Complete and execute SQL statement */
+    mysqli_stmt_bind_param($stmt, "d", $userID);
+    mysqli_stmt_execute($stmt);
+
+    /* Get the result of the query */
+    $resultData = mysqli_stmt_get_result($stmt);
+    if (!$row = mysqli_fetch_assoc($resultData)) {
+        /* In case the user ID does not exist for whatever reason */
+        logIP($dbConn, $_SERVER["REMOTE_ADDR"]);
+        errorPage(500);
+    }
+
+    /* Read file upload quota bytes value */
+    $result = $row['upload_quota_bytes'];
+
+    /* Close the statement */
+    mysqli_stmt_close($stmt);
+
+    /* Return the result array */
+    return $result;
+}