From: Paul J R Date: Wed, 19 Sep 2012 21:07:03 +0000 (+1000) Subject: Disable/enable user switch X-Git-Url: http://git.pjr.cc/?p=gwvp-mini.git;a=commitdiff_plain;h=b465be6b98b6bc09b37bba18aa65251fdd224555 Disable/enable user switch --- diff --git a/gwvpmini/gwvpmini_admin.php b/gwvpmini/gwvpmini_admin.php index 7078542..15db43c 100644 --- a/gwvpmini/gwvpmini_admin.php +++ b/gwvpmini/gwvpmini_admin.php @@ -36,6 +36,9 @@ function gwvpmini_AdminCallMe() if($qspl[1] == "confremoveuser") { return "gwvpmini_ConfRemoveUser"; } + if($qspl[1] == "switchenable") { + return "gwvpmini_SwitchEnableUser"; + } } else { error_log("i got here, where next?"); return "gwvpmini_AdminMainPage"; @@ -94,6 +97,8 @@ function gwvpmini_AdminMainPageBody() $st_t = $val["status"]; $st_l = $val["level"]; + $astat = "0"; + $cstat = "WTF"; $level = "WTF"; if($st_l == 0) $level = "User"; if($st_l == 1) $level = "Admin"; @@ -101,8 +106,12 @@ function gwvpmini_AdminMainPageBody() $status = ""; if($st_t[0] == "1") { $status = ", disabled"; - } - if($st_t[0] == "2") { + $astat = 0; + $cstat = "Enable"; + } else if ($st_t[0] == "0") { + $astat = 1; + $cstat = "Disable"; + } else if($st_t[0] == "2") { $vl = explode(":", $st_t); error_log("VL: ".print_r($vl, true)); $status = " Awaiting Confirmation (Confirm)"; @@ -111,7 +120,9 @@ function gwvpmini_AdminMainPageBody() $st = "$level$status"; $unlval = "$un"; - echo "$unlval$em$fn$ds$stRemove Disable"; + echo "$unlval$em$fn$ds$stRemove "; + if ($st_t[0] == "0"||$st_t[0] == "1") echo "$cstat"; + else echo ""; } @@ -142,7 +153,7 @@ function gwvpmini_AdminMainPageBody() $rn = $val["name"]; $ds = $val["desc"]; $ow = $val["owner"]; - echo "$rn$ds$owRemove Disable"; + echo "$rn$ds$owRemove Disable"; } echo ""; } @@ -288,6 +299,39 @@ function gwvpmini_ConfRemoveUser() } header("Location: $BASE_URL/admin"); -} +} +function gwvpmini_SwitchEnableUser() +{ + global $BASE_URL; + + $uid = -1; + $newst = -1; + if(isset($_REQUEST["q"])) { + $query = $_REQUEST["q"]; + $qspl = explode("/", $query); + if(isset($qspl[2])) { + $newst = $qspl[2]; + } + if(isset($qspl[3])) { + $uid = $qspl[3]; + } + } + + if($newst == 1) $stat = "disabled"; + else $stat = "enabled"; + + if($uid > 0 && ($newst == 1 || $newst == 0)) { + $details = gwvpmini_getUser(null, null, $uid); + $uname = $details["username"]; + if($newst == 1) gwvpmini_DisableUser($uid); + if($newst == 0) gwvpmini_EnableUser($uid); + gwvpmini_SendMessage("info", "User $uname ($uid) has been $stat"); + } else { + gwvpmini_SendMessage("info", "Problem disabling user with uid $uid"); + } + + header("Location: $BASE_URL/admin"); + +} ?> \ No newline at end of file diff --git a/gwvpmini/gwvpmini_db.php b/gwvpmini/gwvpmini_db.php index 5ce6b9a..d75ebcd 100644 --- a/gwvpmini/gwvpmini_db.php +++ b/gwvpmini/gwvpmini_db.php @@ -37,7 +37,7 @@ function gwvpmini_getUser($username=null, $email=null, $id=null) } else if($email != null) { $res = $conn->query("select * from users where user_email='$email'"); } else if($id != null) { - $res = $conn->query("select * from users where users_id='$id'"); + $res = $conn->query("select * from users where user_id='$id'"); } else return false; $returns = false; @@ -64,8 +64,31 @@ function gwvpmini_RemoveUser($uid) $sql = "delete from users where user_id='$uid'"; return $conn->query($sql); +} + +function gwvpmini_DisableUser($uid) +{ + $conn = gwvpmini_ConnectDB(); + + if($uid < 0) return; + + $sql = "update users set user_status=1 where user_id='$uid'"; + + return $conn->query($sql); } +function gwvpmini_EnableUser($uid) +{ + $conn = gwvpmini_ConnectDB(); + + if($uid < 0) return; + + $sql = "update users set user_status=0 where user_id='$uid'"; + + return $conn->query($sql); +} + + function gwvpmini_ConnectDB() { global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name, $DB_CONNECTION;