query($sql)){ die('There was an error running the query [' . $db->error . ']'); } else{ while($row = $result->fetch_assoc()){ $mailbox_limit_default = $row[DBC_USERS_MAILBOXLIMIT]; } } } if(isset($_POST['savemode'])){ $savemode = $_POST['savemode']; if($savemode === "edit"){ // Edit mode entered $id = $db->escape_string($_POST['id']); if(defined('DBC_USERS_MAILBOXLIMIT')){ if($mailbox_limit == ""){ $mailbox_limit = $mailbox_limit_default; } $mailbox_limit = $db->escape_string($_POST['mailbox_limit']); $sql = "UPDATE `".DBT_USERS."` SET `".DBC_USERS_MAILBOXLIMIT."` = '$mailbox_limit' WHERE `".DBC_USERS_ID."` = '$id';"; if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']'); } } // Is there a changed password? if($_POST['password'] !== ""){ $pass_ok = check_new_pass($_POST['password'], $_POST['password_rep']); if($pass_ok === true){ // Password is okay and can be set $pass_hash = gen_pass_hash($_POST['password']); write_pass_hash_to_db($pass_hash, $id); // $editsuccessful = true; add_message("success", "User edited successfully."); } else{ // Password is not okay // $editsuccessful = 2; add_message("fail", $PASS_ERR_MSG); } } else{ // Redirect user to user list header("Location: ".FRONTEND_BASE_PATH."admin/listusers/?edited=1"); } } else if($savemode === "create"){ // Create mode entered $username = $db->escape_string($_POST['username']); $username = strtolower($username); $domain = $db->escape_string($_POST['domain']); $domain = strtolower($domain); if(defined('DBC_USERS_MAILBOXLIMIT')){ $mailbox_limit = $db->escape_string($_POST['mailbox_limit']); } else{ // make mailbox_limit dummy for "if" $mailbox_limit = 0; } $pass = $_POST['password']; $pass_rep = $_POST['password_rep']; if($username !== "" && $domain !== "" && $mailbox_limit !== ""){ // Check if user already exists $user_exists = $db->query("SELECT `".DBC_USERS_USERNAME."`, `".DBC_USERS_DOMAIN."` FROM `".DBT_USERS."` WHERE `".DBC_USERS_USERNAME."` = '$username' AND `".DBC_USERS_DOMAIN."` = '$domain';"); if($user_exists->num_rows == 0){ // All fields filled with content // Check passwords $pass_ok = check_new_pass($pass, $pass_rep); if($pass_ok === true){ // Password is okay ... continue $pass_hash = gen_pass_hash($pass); // Differ between version with mailbox_limit and version without if(defined('DBC_USERS_MAILBOXLIMIT')){ $sql = "INSERT INTO `".DBT_USERS."` (`".DBC_USERS_USERNAME."`, `".DBC_USERS_DOMAIN."`, `".DBC_USERS_PASSWORD."`, `".DBC_USERS_MAILBOXLIMIT."`) VALUES ('$username', '$domain', '$pass_hash', '$mailbox_limit')"; } else{ $sql = "INSERT INTO `".DBT_USERS."` (`".DBC_USERS_USERNAME."`, `".DBC_USERS_DOMAIN."`, `".DBC_USERS_PASSWORD."`) VALUES ('$username', '$domain', '$pass_hash')"; } if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']'); } // Redirect user to user list header("Location: ".FRONTEND_BASE_PATH."admin/listusers/?created=1"); } else{ // Password not okay add_message("fail", $PASS_ERR_MSG); } } else{ add_message("fail", "User already exists in database."); } } else{ // Fields missing add_message("fail", "Not all fields were filled out."); } } } // Select mode $mode = "create"; if(isset($_GET['id'])){ $mode = "edit"; $id = $db->escape_string($_GET['id']); } if($mode === "edit"){ //Load user data from DB $sql = "SELECT * from `".DBT_USERS."` WHERE `".DBC_USERS_ID."` = '$id' LIMIT 1;"; if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']'); } while($row = $result->fetch_assoc()){ $username = $row[DBC_USERS_USERNAME]; $domain = $row[DBC_USERS_DOMAIN]; if(defined('DBC_USERS_MAILBOXLIMIT')){ $mailbox_limit = $row[DBC_USERS_MAILBOXLIMIT]; } } } ?>

Create Edit User

❬ Back to user list

Username Domain Password Mailbox limit (in MB)
value="" placeholder="Username" required="required"/> @