Location: PHPKode > projects > Vehicle Service Tracker > VST/updateprofile.php
<?php
//==========================================================================
// updateprofile.php
//
// The VST Profile Edit form
//
// Copyright (c) 2006 Kenneth J. Snyder
// Licensed under the GNU GPL. For full terms see the file LICENSE
// -------------------------------------------------------------------------
//
// Created: 22Feb2007 hide@address.com v2.1.0
//
//
//==========================================================================
?>
<html>
  <link rel='stylesheet' type='text/css' href='vst.css'>
  <head>
    <title>Vehicle Service Tracker - Update Profile</title>
  </head>
  </body>
  <H1>
  <CENTER>
   <P CLASS='Header1'>Vehicle Service Tracker - Update Profile</P>
  </CENTER>
  </H1>

<?php
if (isset($_REQUEST['SID'])) { $SID=$_REQUEST['SID']; } else { $SID=""; }
include_once("includes.php");
$dbconn = odbc_connect("$dbname","$dbuid","$dbpasswd");
if ($dbconn==0) {
   $a = odbc_errormsg("DB2 Connect Failed. DB2 might not be running");
   echo($a);
 } else {
   authuser($dbconn,$USERNAME,$SID);

include_once("profile.php");

// Set some generic things
$MAINURL=$homepage.$webpath."/main.php?SID=$SID&USERNAME=$USERNAME";
$BUTTONTXT='Update Profile';


// If the Form was submitted
if (isset($_POST['RegisterMe'])) {
   // Encrypt the password
   // ----------------------
   $EPASSWD=sha1($PASSWD);

   // Then This was submitted...lets check the input..
   // --------------------------------------------------
   if ( ! validate_email($EMAIL) ) {
    if (!isset($UIErrors)) $UIErrors="";
    $UIErrors.="<b><ul><li><font color=#ff0000>";
    $UIErrors.="Your eMail Address doesn't look right</font></li></b>";
    $UIErrors.="We need your full internet eMail address<BR>";
    $UIErrors.="Examples of a proper e-mail address are:";
    $UIErrors.="<ul><li>hide@address.com</li>";
    $UIErrors.="<li>hide@address.com</li>";
    $UIErrors.="<li>hide@address.com</li></ul>";
    $UIErrors.="</ul>";
   }
   if ( $FIRST=="" ) { 
    if (!isset($UIErrors)) $UIErrors="";
    $UIErrors.="<b><ul><li><font color=#ff0000>";
    $UIErrors.="You didn't enter your First name</font></li></ul></b>";
   }
   if ( $LAST == "" ) {
    if (!isset($UIErrors)) $UIErrors="";
    $UIErrors.="<b><ul><li><font color=#ff0000>";
    $UIErrors.="You didn't enter your Last name</font></li></ul></b>";
   }
   if ( $PASSWD  == "" && $PASSWD2!="") {
    if (!isset($UIErrors)) $UIErrors="";
    $UIErrors.="<b><ul><li><font color=#ff0000>";
    $UIErrors.="You entered a Confirmation password but didn't enter a Password</font></li></ul></b>";
   }
   if ( $PASSWD2  == "" && $PASSWD!="") {
    if (!isset($UIErrors)) $UIErrors="";
    $UIErrors.="<b><ul><li><font color=#ff0000>";
    $UIErrors.="You didn't enter a Confirmation Password</font></li></ul></b>";
   }
   if ( $PASSWD!="" && $PASSWD2!="" && $PASSWD == $USERNAME ) {
    if (!isset($UIErrors)) $UIErrors="";
    $UIErrors.="<b><ul><li><font color=#ff0000>";
    $UIErrors.="You used your username for a password. This is not allowed";
    $UIErrors.="</font></li></ul></b>";
   }
   if ( $PASSWD!="" && $PASSWD2!="" && $PASSWD==$PASSWD2 && strlen($PASSWD)<5 ) {
    if (!isset($UIErrors)) $UIErrors="";
    $UIErrors.="<b><ul><li><font color=#ff0000>";
    $UIErrors.="Your Password is not at least 6 characters in length";
    $UIErrors.="</font></li></ul></b>";
   }
   if ( $PASSWD  != $PASSWD2 ) {
    if (!isset($UIErrors)) $UIErrors="";
    $UIErrors.="<b><ul><li><font color=#ff0000>";
    $UIErrors.="Your passwords don't match</font></li></ul></b>";
   }
   if (isset($UIErrors)) {
     echo "<b><center><font size=+1>";
     echo "There was trouble with proccessing your information.</font>";
     echo "</b></center>";
     echo $UIErrors;
     RegisterForm($FIRST,$LAST,$EMAIL,$USERNAME,$MAINURL,"updateprofile.php",$BUTTONTXT,0,$SID);
    } else {
     // Alrighty..everything passes so lets update this user!
     // ----------------------------------------------------------
     $LAST2=str_replace("'","''",$LAST);
     $UpdateProfile="update vst.CLIENTS set ";
     $UpdateProfile.="FIRST='$FIRST',";
     $UpdateProfile.="LAST='$LAST2',";
     $UpdateProfile.="EMAIL='$EMAIL'";
     if ($PASSWD!="") { $UpdateProfile.=",PASSWD='$EPASSWD'"; }
     $UpdateProfile.=" where USRNAME='$USERNAME'";
     //echo "Insert stmt [$UpdateProfile]<br>";
     if (odbc_exec($dbconn,$UpdateProfile)) {
        echo "<TABLE BORDER='0' WIDTH='100%' CELLSPACING='1' CELLPADDING='2'>";
        echo "<TR CLASS='band'>";
        echo "<TD>";
        echo "<A CLASS='header2'>";
        echo "</A>";
        echo "<BR>";
        echo "&nbsp;";
        echo "<A CLASS='header2'>";
        if ($PASSWD!="") { $pmes=" and password "; } else { $pmes=""; }
        echo "&nbsp;Profile $pmes for User [$USERNAME] have been Sucessfully Updated</A>";
        echo "<BLOCKQUOTE>";
        echo "First Name: $FIRST<br>";
        echo "Last Name: $LAST<br>";
        echo "eMail: $EMAIL<br>";
        echo "</BLOCKQUOTE> ";
        echo "</TD>";
        echo "</TR>";
        echo "</TABLE>";        
        echo "<center><big><B><a href=main.php?SID=$SID&USERNAME=$USERNAME>";
        echo "To Main</a></B></big></center>";

        // Send me and the person a mail
        $headers = "MIME-Version:1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= "From: Vehicle Service Tracker Admin <$adminemail>";
        $Subject="Profile Successfully updated on Vehicle Service Tracker";

$message="
<html><body><center><B>Vehicle Service Tracker</B></center>
<br>
Hello $FIRST $LAST<BR>
<BR>
Your profile $pmes on the Vehicle Service Tracker has been suscessfully updated<BR>
Access the Tracker at <a href='$homepage$webpath'>
$homepage$webpath</a><BR><BR>
If the request was not initiated by you, please notify $orgname's administrator at $adminemail.<BR>
</body>
</html>
";

         mail($EMAIL,$Subject,$message,$headers);
      } else {
       echo "Something went wrong with the update...try again mabey?";
    } // if the insert is succesful

   }

 } else {// if submitted
   // Just someone trying to register..display the form
  $ProfileSelect="select rtrim(FIRST),rtrim(LAST),rtrim(EMAIL) ";
  $ProfileSelect.="from VST.CLIENTS where ";
  $ProfileSelect.="USRNAME='$USERNAME'";
  $ProfileResult=odbc_exec($dbconn,$ProfileSelect);
  if (! $ProfileResult ) die("Something went wrong with select from db2 clients");
  //echo $ProfileSelect;
  $Vehicles=0;
  while (odbc_fetch_row($ProfileResult)) {
    $FIRST=odbc_result($ProfileResult,1);
    $LAST=odbc_result($ProfileResult,2);
    $EMAIL=odbc_result($ProfileResult,3);
  }

   RegisterForm($FIRST,$LAST,$EMAIL,$USERNAME,$MAINURL,"updateprofile.php",$BUTTONTXT,0,$SID);
}

footer($PHP_SELF,$adminemail);
odbc_commit($dbconn);
odbc_close_all();
} // close dbconn
?>
</body>
</html>
Return current item: Vehicle Service Tracker