| ";
$FORM_ITEMS[-2]="hidden|AdminID:".$AdminID;
$FORM_ITEMS[-1]="submit|Save:1-admins";
$FORM=new AdminForm;
$FORM->title="EditAdmin";
$FORM->items=$FORM_ITEMS;
$FORM->action=MakeAdminLink("admins?Action=UpdateAdmin");
$FORM->MakeForm("User Account Details");
if ($Action == 'Add') {
$FORM->output = "Complete the form below to create a new user account. When you are done, click on the 'Save' button." . $FORM->output;
$OUTPUT =MakeBox("Create User", $FORM->output);
} else {
$FORM->output = "Complete the form below to edit a user account. When you are done, click on the 'Save' button." . $FORM->output;
$OUTPUT =MakeBox("Edit User", $FORM->output);
}
$OUTPUT .= '
';
}
}
if ($Action == 'UpdateAdmin') {
$qry = "SELECT COUNT(*) FROM " . $TABLEPREFIX . "admins WHERE Username='" . addslashes($_POST['Username']) . "' AND AdminID != '" . addslashes($_POST['AdminID']) . "'";
$username_check = mysql_result(mysql_query($qry), 0, 0);
if ($username_check > 0) {
$OUTPUT = MakeErrorBox("Duplicate Account Username", "The account username that you entered is already in use. Please choose another username.");
} else {
$AdminID = $_POST['AdminID'];
$do = true;
if ($AdminID > 0) {
// check to make sure that we're not the only user left that's active.
if ($_POST['Status'] != 1) {
$qry = "SELECT COUNT(*) FROM " . $TABLEPREFIX . "admins WHERE AdminID != '" . addslashes($AdminID) . "' AND Status='1'";
$result = mysql_result(mysql_query($qry), 0, 0);
if ($result <= 0) {
$OUTPUT = MakeErrorBox("Last Active User", "If you disable this admin account, there will be no active users left.");
$do = false;
}
}
// check to make sure that we're not the only user left that's active.
if ($_POST['Root'] != 1) {
$qry = "SELECT COUNT(*) FROM " . $TABLEPREFIX . "admins WHERE AdminID != '" . addslashes($AdminID) . "' AND Root='1'";
$result = mysql_result(mysql_query($qry), 0, 0);
if ($result <= 0) {
$OUTPUT = MakeErrorBox("Last All Access User", "If you remove 'All Access' from this admin account, there will be no users left with access to all functionality (including this page).");
$do = false;
}
}
// check to make sure that we're not the only user left that's active.
if ($_POST['Manager'] != 1) {
$qry = "SELECT COUNT(*) FROM " . $TABLEPREFIX . "admins WHERE AdminID != '" . addslashes($AdminID) . "' AND Manager='1'";
$result = mysql_result(mysql_query($qry), 0, 0);
if ($result <= 0) {
$OUTPUT = MakeErrorBox("Last All Lists User", "If you remove 'All Lists' from this admin account, there will be no users left with access to all lists.");
$do = false;
}
}
if ($do) {
$qry = "UPDATE " . $TABLEPREFIX . "admins SET Username='" . addslashes($_POST['Username']) . "', ";
if (trim($_POST['Password']) != '********') $qry .= " Password='" . addslashes(md5($_POST['Password'])) . "', ";
$qry .= " AdminName='" . addslashes($_POST['AdminName']) . "', Email='" . addslashes($_POST['Email']) . "', Status='" . (int)addslashes($_POST['Status']) . "', Root='" . (int)addslashes($_POST['Root']) . "', Manager='" . (int)addslashes($_POST['Manager']) . "', Attachments='" . (int)addslashes($_POST['Attachments']) . "', MaxLists='" . addslashes($_POST['MaxLists']) . "', PerHour='" . (int)str_replace(array(' ', ','), '', addslashes($_POST['PerHour'])) . "', PerMonth='" . (int)str_replace(array(' ', ','), '', addslashes($_POST['PerMonth'])) . "', EmailServer='" . addslashes($_POST['EmailServer']) . "', EmailServerPort='" . (int)addslashes($_POST['EmailServerPort']) . "', DisplaySummaries='" . (int)addslashes($_POST['DisplaySummaries']) . "' WHERE AdminID='" . addslashes($AdminID)."'";
mysql_query($qry);
}
} else {
$qry = "INSERT INTO " . $TABLEPREFIX . "admins (Username, Password, AdminName, Email, Status, Root, Manager, Attachments, MaxLists, PerHour, PerMonth, EmailServer, EmailServerPort, DisplaySummaries) VALUES ('" . addslashes($_POST['Username']) . "', '" . addslashes(md5($_POST['Password'])) . "', '" . addslashes($_POST['AdminName']) . "', '" . addslashes($_POST['Email']) . "', '" . (int)addslashes($_POST['Status']) . "', '" . (int)addslashes($_POST['Root']) . "', '" . (int)addslashes($_POST['Manager']) . "', '" . (int)addslashes($_POST['Attachments']) . "', '" . (int)addslashes($_POST['MaxLists']) . "', '" . (int)addslashes($_POST['PerHour']) . "', '" . (int)addslashes($_POST['PerMonth']) . "', '" . addslashes($_POST['EmailServer']) . "', '" . (int)addslashes($_POST['EmailServerPort']) . "', '" . (int)addslashes($_POST['DisplaySummaries']) . "')";
mysql_query($qry);
$AdminID = mysql_insert_id();
}
if ($do) {
mysql_query("DELETE FROM " . $TABLEPREFIX . "allow_functions WHERE AdminID='".addslashes($AdminID)."'");
if(isset($_POST['AllowFunction'])) {
foreach($_POST['AllowFunction'] as $functionid=>$val) {
mysql_query("INSERT INTO " . $TABLEPREFIX . "allow_functions SET AdminID='".addslashes($AdminID)."', SectionID='".addslashes($functionid)."'");
}
}
//allowed lists
mysql_query("DELETE FROM " . $TABLEPREFIX . "allow_lists WHERE AdminID='".addslashes($AdminID)."'");
if(isset($_POST['AllowList'])) {
foreach($_POST['AllowList'] as $listid=>$val) {
mysql_query("INSERT INTO " . $TABLEPREFIX . "allow_lists SET AdminID='".addslashes($AdminID)."', ListID='".addslashes($listid)."'");
}
}
if ($_POST['AdminID'] > 0) {
$OUTPUT = MakeSuccessBox("User Account Updated Successfully", "The selected user account has been updated successfully.", MakeAdminLink("admins"));
} else {
$OUTPUT = MakeSuccessBox("User Account Created Successfully", "A new user account has been created successfully.", MakeAdminLink("admins"));
}
}
}
}
?>
|