Disable/enable user switch
authorPaul J R <me@pjr.cc>
Wed, 19 Sep 2012 21:07:03 +0000 (07:07 +1000)
committerPaul J R <me@pjr.cc>
Wed, 19 Sep 2012 21:07:03 +0000 (07:07 +1000)
gwvpmini/gwvpmini_admin.php
gwvpmini/gwvpmini_db.php

index 7078542..15db43c 100644 (file)
@@ -36,6 +36,9 @@ function gwvpmini_AdminCallMe()
                                        if($qspl[1] == "confremoveuser") {
                                                return "gwvpmini_ConfRemoveUser";
                                        }
+                                       if($qspl[1] == "switchenable") {
+                                               return "gwvpmini_SwitchEnableUser";
+                                       }
                                } else {\r
                                        error_log("i got here, where next?");\r
                                        return "gwvpmini_AdminMainPage";\r
@@ -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 (<a href=\"$BASE_URL/register/confirmreg/".$vl[1]."\">Confirm</a>)";
@@ -111,7 +120,9 @@ function gwvpmini_AdminMainPageBody()
                $st = "$level$status";
                
                $unlval = "<a href=\"$BASE_URL/user/$un\">$un</a>";
-               echo "<tr><td>$unlval</td><td>$em</td><td>$fn</td><td>$ds</td><td>$st</td><td><a href=\"$BASE_URL/admin/removeuser/$id\">Remove</a> <a href=\"$BASE_URL/admin/disableuser&id=$id\">Disable</a></td></tr>";
+               echo "<tr><td>$unlval</td><td>$em</td><td>$fn</td><td>$ds</td><td>$st</td><td><a href=\"$BASE_URL/admin/removeuser/$id\">Remove</a> ";
+               if ($st_t[0] == "0"||$st_t[0] == "1") echo "<a href=\"$BASE_URL/admin/switchenable/$astat/$id\">$cstat</a></td></tr>";
+               else echo "</td></tr>";
        }
        
        
@@ -142,7 +153,7 @@ function gwvpmini_AdminMainPageBody()
                $rn = $val["name"];
                $ds = $val["desc"];
                $ow = $val["owner"];
-               echo "<tr><td><a href=\"$BASE_URL/view/$rn\">$rn</a></td><td>$ds</td><td>$ow</td><td><a href=\"$BASE_URL/admin/removeuser&id=$id\">Remove</a> <a href=\"$BASE_URL/admin/disableuser&id=$id\">Disable</a></td></tr>";
+               echo "<tr><td><a href=\"$BASE_URL/view/$rn\">$rn</a></td><td>$ds</td><td>$ow</td><td><a href=\"$BASE_URL/admin/removeuser&id=$id\">Remove</a> <a href=\"$BASE_URL/admin/switchenable/$id\">Disable</a></td></tr>";
        }
        echo "</table>";
 }\r
@@ -288,6 +299,39 @@ function gwvpmini_ConfRemoveUser()
        }\r
 
        header("Location: $BASE_URL/admin");\r
-}\r
+}
 
+function gwvpmini_SwitchEnableUser()\r
+{
+       global $BASE_URL;\r
+       \r
+       $uid = -1;
+       $newst = -1;\r
+       if(isset($_REQUEST["q"])) {\r
+               $query = $_REQUEST["q"];\r
+               $qspl = explode("/", $query);\r
+               if(isset($qspl[2])) {\r
+                       $newst = $qspl[2];\r
+               }
+               if(isset($qspl[3])) {
+                       $uid = $qspl[3];
+               }\r
+       }
+       
+       if($newst == 1) $stat = "disabled";
+       else $stat = "enabled";\r
+       \r
+       if($uid > 0 && ($newst == 1 || $newst == 0)) {\r
+               $details = gwvpmini_getUser(null, null, $uid);\r
+               $uname = $details["username"];\r
+               if($newst == 1) gwvpmini_DisableUser($uid);
+               if($newst == 0) gwvpmini_EnableUser($uid);\r
+               gwvpmini_SendMessage("info", "User $uname ($uid) has been $stat");\r
+       } else {\r
+               gwvpmini_SendMessage("info", "Problem disabling user with uid $uid");\r
+       }\r
+       \r
+       header("Location: $BASE_URL/admin");\r
+       
+}
 ?>
\ No newline at end of file
index 5ce6b9a..d75ebcd 100644 (file)
@@ -37,7 +37,7 @@ function gwvpmini_getUser($username=null, $email=null, $id=null)
        } else if($email != null) {\r
                $res = $conn->query("select * from users where user_email='$email'");\r
        } else if($id != null) {\r
-               $res = $conn->query("select * from users where users_id='$id'");\r
+               $res = $conn->query("select * from users where user_id='$id'");\r
        } else return false;\r
 \r
        $returns = false;\r
@@ -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();\r
+       \r
+       if($uid < 0) return;\r
+       \r
+       $sql = "update users set user_status=1 where user_id='$uid'";\r
+       \r
+       return $conn->query($sql);
 }\r
 
+function gwvpmini_EnableUser($uid)\r
+{\r
+       $conn = gwvpmini_ConnectDB();\r
+\r
+       if($uid < 0) return;\r
+\r
+       $sql = "update users set user_status=0 where user_id='$uid'";\r
+\r
+       return $conn->query($sql);\r
+}\r
+\r
+
 function gwvpmini_ConnectDB()\r
 {\r
        global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name, $DB_CONNECTION;\r