home *** CD-ROM | disk | FTP | other *** search
/ csi.uticak12.org / csi.uticak12.org.tar / csi.uticak12.org / back / profile.php < prev    next >
PHP Script  |  2011-10-20  |  5KB  |  164 lines

  1. <?
  2. include 'guard.php';
  3. $act=$_REQUEST['act'];
  4. $err=$_REQUEST['err'];
  5. $newuname=$_REQUEST['newuname'];
  6. $mail=$_REQUEST['mail'];
  7. $oldpass=$_REQUEST['oldpass'];
  8. $newupass=$_REQUEST['newupass'];
  9. $cpass=$_REQUEST['cpass'];
  10. mysql_connect(HostName,UserName,Password) or die("<html><body>Can not connect to MySql server!<br></body></html>");
  11. mysql_select_db (DBName) or die ("<html><body>Could not select database ".DBName."<br></body></html>");
  12.  
  13.  
  14. if(IntVal($act)==1){
  15. if(Strval($admpass)==Strval($oldpass)){
  16.       if (isset($newuname)) {
  17.  
  18. if (trim($newupass)=="")  {mysql_query("update gal_admin set Alogin='".addslashes(($newuname))."', Aemail='".addslashes(($mail))."'");};
  19. if (trim($newupass)!="")  {
  20.  
  21. if (trim($newupass)==trim($cpass)) {
  22. mysql_query("update gal_admin set Alogin='".addslashes(($newuname))."', Apassword='".addslashes(($newupass))."', Aemail='".addslashes(($mail))."'"); $_SESSION["admpass"]=$newupass; }
  23. else
  24. {
  25. echo '<script>location.href="profile.php?err=1"</script>';
  26. };
  27.  
  28.  
  29. };
  30.  
  31.            $_SESSION["admname"]=$newuname;
  32.            echo '<script>location.href="profile.php?err=2"</script>';
  33.            exit;
  34.       }else{
  35.         echo '<script>location.href="profile.php?err=1"</script>';
  36.         exit;
  37.       }
  38.   }else{
  39.     echo '<script>location.href="profile.php?err=3"</script>';
  40.     exit;
  41.   }
  42.  
  43.  
  44. }
  45. else
  46. {
  47. $res=mysql_query ("SELECT * FROM gal_admin");
  48. $f=mysql_fetch_array ($res);
  49. $a_name=$f['Alogin'];
  50. $a_mail=$f['Aemail'];
  51. };
  52.  
  53. ?>
  54.  
  55. <script language="JavaScript">
  56. function trim(s1) {
  57.   var s=new String(s1);
  58.   while ((s.length>0) && (s.charAt(s.length-1)==" ")) 
  59.     s = s.substr(s,s.length-1);
  60.   return s;
  61. }
  62.  
  63. function form_valid() {
  64.    
  65.    if (trim(document.form1.newuname.value)==""){
  66.         alert("User name field cannot be empty!");
  67.         return false;
  68.         }
  69.    if (trim(document.form1.mail.value)==""){
  70.         alert("Mail field cannot be empty!");
  71.         return false;
  72.         }
  73.  
  74.    if (trim(document.form1.newuname.value).length<3){
  75.         alert("Incorrect username!");
  76.         return false;
  77.         }        
  78.    if (trim(document.form1.oldpass.value)=="" || trim(document.form1.newupass.value)=="" || trim(document.form1.cpass.value)==""){
  79.         alert("All fields are required!");
  80.         return false;
  81.         }    
  82.    
  83.    if (trim(document.form1.oldpass.value).length<3 || trim(document.form1.newupass.value).length<3 || trim(document.form1.cpass.value).length<3){
  84.         alert("Incorrect password!");
  85.         return false;
  86.         }
  87.    var s = new String(trim(document.form1.oldpass.value));
  88.    if (s.match(/[^0-9a-zA-Z]/)) {
  89.      alert("Wrong old password!");
  90.      return false;
  91.    }    
  92.    if (document.form1.newupass.value!=document.form1.cpass.value){        
  93.        alert("Wrong confirmation of password!\nPlease, try again!!");
  94.         return false;
  95.         }        
  96.    var s = new String(trim(document.form1.newuname.value));
  97.    if (s.match(/[^0-9a-zA-Z]/)) {
  98.      alert("Wrong username!");
  99.      return false;
  100.    }        
  101.    var s = new String(trim(document.form1.newupass.value));
  102.    if (s.match(/[^0-9a-zA-Z]/)) {
  103.      alert("Wrong new password!");
  104.      return false;
  105.    }        
  106. }
  107. </script>
  108.  
  109. <?    $header = "Change My Profile";
  110.     include ('top.inc'); ?>
  111.  
  112.     <?php if (isset($err) and IntVal($err)==1){?>
  113.                       <h1 align='center'class="maintxt">Wrong password confirmation! Please, try again!</font></h1>
  114.                   <?php }?>
  115.                   <?php if (isset($err) and IntVal($err)==2){?>
  116.                       <h1 align='center' class="maintxt">Administrator's details have been changed!</font></h1>
  117.                   <?php }?>
  118.                   <?php if (isset($err) and IntVal($err)==3){?>
  119.                       <h1 align='center' class="maintxt">Old password is wrong!</font></h1>
  120.                   <?php }?>
  121.  
  122. <form name="form1" method="post" action="profile.php">
  123.     
  124. <table border=0 cellspacing=0 cellpadding=5 align=center width="100%">
  125.     <tr>
  126.         <td class="border">
  127.             <table border=0 cellspacing=1 cellpadding=5 width="100%" class="back">
  128.                 <tr>
  129.                     <td class="th" colspan=2><p align="center">All fields marked * are required!<br>Fields marked ** are required while password is changing!  </p></td>
  130.                 </tr>
  131.  
  132.                 <tr>
  133.                     <td class="odd" align=right><b>Username:</b></td>
  134.                     <td class="odd"><input type=text size=30 class="inp" name="newuname" value="<? echo $a_name; ?>"></td>
  135.                 </tr>
  136.                 <tr>
  137.                     <td class="even" align=right><b>E-mail address:</b></td>
  138.                     <td class="even"><input type=text size=30 class="inp" name="mail" value="<? echo $a_mail; ?>"></td>
  139.                 </tr>
  140.                 <tr>
  141.                     <td class="odd" align=right><b>Old password *:</b></td>
  142.                     <td class="odd"><input type=password size=30 class="inp" name="oldpass"></td>
  143.                 </tr>
  144.                 <tr>
  145.                     <td class="even" align=right><b>New password **:</b></td>
  146.                     <td class="even"><input type=password size=30 class="inp" name="newupass"></td>
  147.                 </tr>
  148.                 <tr>
  149.                     <td class="odd" align=right><b>Re-enter new password **:</b></td>
  150.                     <td class="odd"><input type=password size=30 class="inp" name="cpass"></td>
  151.                 </tr>
  152.                 <tr>
  153.                     <td class="tf" colspan=2 align=center>
  154.                     <input type=submit value="Update" class="btn">
  155.                     <!-- <input type=button value="Cancel" class="btn" onClick ="location.href='home.php'">-->
  156.                     </td>
  157.                 </tr>
  158.             </table>
  159.         </td>
  160.     </tr>
  161. </table>
  162. <input type="hidden" name="act" value="1">
  163. </form>
  164. <? include ('btm.inc'); ?>