replacing the cli cmds with variables and configuration in config.php
[gwvp-mini.git] / gwvpmini / gwvpmini_user.php
index f2efe02..799ef37 100644 (file)
@@ -37,7 +37,7 @@ function gwvpmini_UserViewCallMe()
 {
        global $user_view_call;
        
-       error_log("in admin callme");
+       // error_log("in admin callme");
        if(isset($_REQUEST["q"])) {
                $query = $_REQUEST["q"];
                $qspl = explode("/", $query);
@@ -48,8 +48,20 @@ function gwvpmini_UserViewCallMe()
                                        if(!gwvpmini_GetUserId($user_view_call)) {
                                                gwvpmini_SendMessage("error", "No such user, $user_view_call");
                                                return false;
+                                       } else {
+                                               if(isset($qspl[2])) {
+                                                       if($qspl[2] == "updateuserdesc") {
+                                                               return "gwvpmini_ViewUpdateUserDesc";
+                                                       }
+                                                       if($qspl[2] == "updateuserpassword") {\r
+                                                               return "gwvpmini_ViewUpdateUserPassword";\r
+                                                       }\r
+                                                       if($qspl[2] == "updateuseremail") {
+                                                               return "gwvpmini_ViewUpdateUserEmail";
+                                                       }
+                                               }
+                                               return "gwvpmini_UserViewPage";
                                        }
-                                       return "gwvpmini_UserViewPage";
                                } else return false;
                        } else return false;
                }
@@ -77,7 +89,7 @@ function gwvpmini_UserViewPageBody()
        
        
        $dets = gwvpmini_getUser($user_view_call);
-       //error_log("show view of user with $user_view_call: ". print_r($dets, true));\r
+       //// error_log("show view of user with $user_view_call: ". print_r($dets, true));\r
 
        echo "<h2>".$dets["fullname"]."</h2><br>";
        echo gwvpmini_HtmlGravatar($dets["email"],80);
@@ -91,13 +103,13 @@ function gwvpmini_UserViewPageBody()
        }
        
        if($isme || gwvpmini_isUserAdmin()) {
-               echo "<form method=\"post\" action=\"$BASE_URL/user/updateuserdesc\">";
+               echo "<form method=\"post\" action=\"$BASE_URL/user/$user_view_call/updateuserdesc\">";
                echo "Your Description<br><textarea name=\"desc\" cols=\"100\" rows=\"4\">".$dets["desc"]."</textarea><br>";
                echo "<input type=\"submit\" name=\"Update\" value=\"Update\">";
                echo "</form>";
                
                echo "<h3>New Password</h3>";
-               echo "<form method=\"post\" action=\"$BASE_URL/user/updateuserpassword\">";
+               echo "<form method=\"post\" action=\"$BASE_URL/user/$user_view_call/updateuserpassword\">";
                echo "<table>";
                if($isme) echo "<tr><td>Old Password</td><td><input type=\"password\" name=\"oldpassword\"></td></tr>";
                echo "<tr><td>New Password</td><td><input type=\"password\" name=\"newpassword1\"></td></tr>";
@@ -106,9 +118,9 @@ function gwvpmini_UserViewPageBody()
                echo "</form>";
                
                echo "<h3>New Email Address</h3>";
-               echo "<form method=\"post\" action=\"$BASE_URL/user/updateuseremail\">";
-               echo "<table><tr><td>New Email Address</td><td><input type=\"password\" name=\"newemail1\"></td></tr>";
-               echo "<tr><td>Confirm New Email Address</td><td><input type=\"password\" name=\"newemail2\"></td></tr></table>";
+               echo "<form method=\"post\" action=\"$BASE_URL/user/$user_view_call/updateuseremail\">";
+               echo "<table><tr><td>New Email Address</td><td><input type=\"text\" name=\"newemail1\"></td></tr>";
+               echo "<tr><td>Confirm New Email Address</td><td><input type=\"text\" name=\"newemail2\"></td></tr></table>";
                echo "<input type=\"submit\" name=\"Update\" value=\"Update\">";
                echo "</form>";
        } else {
@@ -116,4 +128,95 @@ function gwvpmini_UserViewPageBody()
        }
 }
 
+function gwvpmini_ViewUpdateUserPassword()
+{
+       global $user_view_call, $BASE_URL;
+       
+       $newpass1 = $_REQUEST["newpassword1"];
+       $newpass2 = $_REQUEST["newpassword2"];
+       $oldpass = $_REQUEST["oldpassword"];
+       
+       $authd = gwvpmini_authUserPass($user_view_call, $oldpass);\r
+               
+       $doupdate = false;
+       
+       if(isset($_SESSION["username"])) if($_SESSION["username"] == $user_view_call && $authd !== false) {
+               $doupdate = true;
+       }
+       
+       if(gwvpmini_isUserAdmin()) {
+               $doupdate = true;
+       }
+       
+       
+       if($newpass1 != $newpass2) {
+               gwvpmini_SendMessage("error", "Password and confirmation dont match");
+       } else if(!$doupdate) {
+               gwvpmini_SendMessage("error", "Could not update user desc, are you logged in?");
+       } else {
+               // do update
+               $uid = gwvpmini_GetUserId($user_view_call);
+               gwvpmini_UpdateUserPassword($uid, $newpass1);
+               gwvpmini_SendMessage("info", "Password Updated");
+       }
+       
+       header("Location: $BASE_URL/user/$user_view_call");
+}
+
+function gwvpmini_ViewUpdateUserDesc()
+{
+       global $user_view_call, $BASE_URL;
+       
+       $newdesc = $_REQUEST["desc"];
+       $doupdate = false;
+       
+       if(isset($_SESSION["username"])) if($_SESSION["username"] == $user_view_call) {
+               $doupdate = true;
+       }
+       
+       if(gwvpmini_isUserAdmin()) {
+               $doupdate = true;
+       }
+       
+       if(!$doupdate) {
+               gwvpmini_SendMessage("error", "Could not update user desc, are you logged in?");
+       } else {
+               $uid = gwvpmini_GetUserId($user_view_call);\r
+               gwvpmini_UpdateUserDesc($uid, $newdesc);
+               gwvpmini_SendMessage("info", "Description Updated");
+       }
+       
+       header("Location: $BASE_URL/user/$user_view_call");
+       }
+
+function gwvpmini_ViewUpdateUserEmail()
+{
+       global $user_view_call, $BASE_URL;\r
+       \r
+       $newem1 = $_REQUEST["newemail1"];
+       $newem2 = $_REQUEST["newemail2"];
+       $doupdate = false;\r
+       \r
+       if(isset($_SESSION["username"])) if($_SESSION["username"] == $user_view_call) {\r
+               $doupdate = true;\r
+       }\r
+       \r
+       if(gwvpmini_isUserAdmin()) {\r
+               $doupdate = true;\r
+       }\r
+       
+       if($newem1 != $newem2) {
+               gwvpmini_SendMessage("error", "Email and confirmation did not match");
+       } else if(!$doupdate) {\r
+               gwvpmini_SendMessage("error", "Could not update user desc, are you logged in?");\r
+       } else {\r
+               $uid = gwvpmini_GetUserId($user_view_call);\r
+               gwvpmini_UpdateUserEmail($uid, $newem1);
+               gwvpmini_SendMessage("info", "Email Address Updated");\r
+       }\r
+       \r
+       header("Location: $BASE_URL/user/$user_view_call");\r
+       
+}
+
 ?>
\ No newline at end of file