Location: PHPKode > projects > WaveWatcher > wavewatcher3/html/profile.php
<?
    require_once("../classes/user.php");
require_once("../classes/network.php");
    session_start();

    // User ID. 0 => the user loggedin
    $user_id = 0;

    $user = new User();
$network = new Network();

    $err = false;

    // Are we entering the page with posted variables (from allusers.php)
    if (IsSet($id))
    {
        if (!$user->IsAdmin())
            header("Location: profile.php");

        if ($id != $user->GetUserID())
            $user_id = $id;
    }

    // update user information
    if ($HTTP_POST_VARS)
    {

        // Get FORM values
        $password = $HTTP_POST_VARS["password1"];
        $email = $HTTP_POST_VARS["email"];
        $company = $HTTP_POST_VARS["company"];
        $location = $HTTP_POST_VARS["location"];
        $phone = $HTTP_POST_VARS["phone"];

        if ($user->IsAdmin() && $user_id != 0)
            $type = $HTTP_POST_VARS["user_type"];

        if ($user_id == 0)
            if ($user->SetUserDetails($user->GetUserName(), $password, $company, $email, $location, $phone, $user->GetUserID()))
                header("location: profile.php");
            else
                $err = true;
        else
            if ($user->SetUserDetails($user->GetUserName($user_id), $password, $company, $email, $location, $phone, $user_id))
            {
                if ($user->IsAdmin() && $user_id != 0)
                {
                    if ($type == "admin")
                        $user->SetUserType($user_id, 1);
                    else
                        $user->SetUserType($user_id, 0);
                }

                header("location: profile.php?id=$user_id");
            }
            else
                $err = true;
    }

    // shows a menu
    function ShowMenu($user,$user_id)
    {
        if ($user->IsAdmin())
        {
            $name = $user->GetUserName($user_id);

            print "<td height=19>[ <a href=selnodes.php?id=id0>your nodes</a> ]</td>\n";

            if ($user_id == 0)
			{
                print "<td height=19>[ your details ]</td>\n";
			}
            else
			{
                print "<td height=19>[ <a href=profile.php?id=0>your details</a> ]</td>\n";
			}

			print "<td>[ <a href=prefs.php>preferences</a> ]</td>";
            print "</tr></table><table align=center><tr>\n";

            if ($user_id != 0)
            {
                print "<td height=19>[ <a href=selnodes.php?id=id$user_id>$name's nodes</a> ]</td>\n";
                print "<td height=19>[ $name's details ]</td></tr></table><table align=center><tr>\n";
            }

            print "<tr><td height=19>[ <a href=allusers.php>users</a> ]</td>\n";
        }
        else
        {
            print "<td height=19>[ your details ]</td>\n";
            print "<td height=19>[ <a href=selnodes.php?id=id0>your nodes</a> ]</td>\n";
			print "<td>[ <a href=prefs.php>preferences</a> ]</td>";
        }
    }
?>

<html>
    <head>
        <title>WaveWatcher </title>
		<link href="css/style1.css" rel="styleSheet" type="text/css">
        <script>
            function CheckForm()
            {
                if (navigator.appName != "Netscape")
                {
                    // Check form
                    var strMsg = "";

                    // 1. Password must not be empty
                    if (document.forms("profile").item("password1").value == "")
                        strMsg += "You must enter a password\n";


                    // 2. Password and the confirmed password must be equal
                    if (document.forms("profile").item("password1").value != document.forms("profile").item("password2").value)
                        strMsg += "Please check your password!\n";

                    // 3. Email must not be empty!
                    if (document.forms("profile").item("email").value == "")
                        strMsg += "You must enter an email address!\n";

                    // If errors, show them, else register user!
                    if (strMsg != "")
                        alert(strMsg);
                    else
                        document.profile.submit();
                }
                else
                {
                    // Check form
                    var strMsg = "";

                    // 1. Password must not be empty
                    if (document.profile.password1.value == "")
                        strMsg += "You must enter a password\n";

                    // 2. Password and the confirmed password must be equal
                    if (document.profile.password1.value != document.profile.password2.value)
                        strMsg += "Please check your password!\n";

                    // 3. Email must not be empty!
                    if (document.profile.email.value == "")
                        strMsg += "You must enter an email address!\n";

                    // If errors, show them, else register user!
                    if (strMsg != "")
                        alert(strMsg);
                    else
                        document.profile.submit();
                }
            }

        </script>
    </head>
    <body>

<? include("menuinclude.php");?>
  <br><br>
  <table align="center">
  
    <tr>
        <? ShowMenu($user,$user_id) ?>
    </tr>
  </table>

  <br>
  <br>
 <form method="post" name="profile">
  <table width = "50%" align="center" border="0">
                <tr>
                    <td>
                        <!-- background table -->
                        <table width="350" align="center" border="0" cellspacing="1" cellpadding="0" bgcolor="#000000">
                            <tr>
                                <td>
                                    <!-- gui table -->

              <table width="350" border="0" cellspacing="1" cellpadding="2">
                <!-- title row -->
                <tr>
                  <td bgcolor="#515173"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b>User
                    details</b></font> </td>
                </tr>

                <!-- message row -->
                <?
                if ($err)
                {
                ?>

                <tr>
                    <td bgcolor="#FC4848">
                        <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
                            Update failed.
                        </font>
                    </td>
                </tr>

                <?
                }
                ?>

                <!-- username, password etc row -->
                <tr bgcolor="#fcfcfc">
                  <td>
                    <table width="100%" border="0" cellspacing="0" cellpadding="2">
                      <tr>
                        <td width="150" align="right"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Username
                          (*): </font> </td>
                        <td width="200">
                          <input disabled name="username" type="text" value="<? echo $user->GetUserName($user_id)?>" size="25">
                        </td>
                      </tr>
                      <tr>
                        <td width="150" align="right"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Password
                          (*): </font> </td>
                        <td width="200">
                          <input name="password1" type="Password" value="<? echo $user->GetUserPassword($user_id)?>" size="25">
                        </td>
                      </tr>
                      <tr>
                        <td width="150" align="right"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Confirm
                          password (*): </font> </td>
                        <td width="200">
                          <input name="password2" type="Password" value="<? echo $user->GetUserPassword($user_id)?>" size="25">
                        </td>
                      </tr>
                      <tr>
                        <td width="150" align="right"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Email
                          (*): </font> </td>
                        <td width="200">
                          <input name="email" type="text" value="<? echo $user->GetUserEmail($user_id)?>" size="25">
                        </td>
                      </tr>
                      <tr>
                        <td width="150" align="right"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Company:
                          </font> </td>
                        <td width="200">
                          <input name="company" type="text" value="<? echo $user->GetUserCompany($user_id)?>" size="25">
                        </td>
                      </tr>
                      <tr>
                        <td width="150" align="right"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Location:
                          </font> </td>
                        <td width="200">
                          <input name="location" type="text" value="<? echo $user->GetUserLocation($user_id)?>" size="25">
                        </td>
                      </tr>
                      <tr>
                        <td width="150" align="right"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Phone:
                          </font> </td>
                        <td width="200">
                          <input name="phone" type="text" value="<? echo $user->GetUserPhone($user_id)?>" size="25">
                        </td>
                      </tr>
						<?
							if ($user->IsAdmin() && $user_id != 0)
							{
								$type = $user->GetUserType($user_id);
						?>
                      <tr>
                        <td width="150" align="right"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">User type:
                        </font> </td>
                        <td width="200">
						<select name="user_type" style="WIDTH:174; color: #000000;">
						<option <?if ($type == "admin") print "selected"?> >admin</option>
						<option <?if ($type == "reguser") print "selected"?> >reguser</option>
						</select>
                        </td>
                      </tr>
						<?
							}
						?>
                    </table>
                  </td>
                </tr>
                <!-- Submit -->
                <tr bgcolor="#fcfcfc">
                  <td align="center">
                    <input name="register" type="button" value="Update" onClick="javascript:CheckForm();">
                  </td>
                </tr>
              </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</form>
    </body>
</html>
Return current item: WaveWatcher