Location: PHPKode > projects > Replex > replex-0.9.0/admin/account_update.php
<?php
/*************************************************************
$Id: account_update.php,v 1.8 2001/05/19 02:43:13 jimir Exp $
 
 ***************************************************************/

include("include/config.php");
include("lib/user.php");
include("lib/account.php");
include("lib/alias.php");
include("lib/cyradm-php.lib");
include("lib/libfunction.php");
include("db/class_mysql.php");

# Authenticate current user
$USER = new User;
if (!$USER->HTTPauthenticate($DBCONN)) {
  $USER->http_refuse();
}

    
  # *****************************************************
  # Create account
  # Input: $createaccount (trigger this action)
  #        $domainname
  #        $username
  #        $password
  #        $alias
  #	   $caller(from domain-page)
  
  if(!empty($createaccount)) {
    if(empty($domainname) || empty($username) || empty($password) || empty($alias)) {
      //redirect missing fields
      if($caller=="domain") {
       HTTPRedirect("domain6.php?error=error1&searchdomain=1&domain=$domainname&username=$username&password=$password&alias=$alias");
       exit; 
      } 
      else {      
       HTTPRedirect("account2.php?error=error1&searchdomain=1&domainname=$domainname&username=$username&password=$password&alias=$alias");
       exit;
      }
    }
    $ACCOUNT=new Account;
    
    //tjeck password length
    if(!(strlen(trim($password))>=$ACCOUNT_PASSWORD_LENGTH)) {
      if($caller=="domain") {
       HTTPRedirect("domain6.php?error=error8&searchdomain=1&domain=$domainname&username=$username&password=$password&alias=$alias");
       exit;
      }
      else {
       HTTPRedirect("account2.php?error=error8&searchdomain=1&domainname=$domainname&username=$username&password=$password&alias=$alias");
       exit;
      }


    }

    //tjeck if alias is valid    
    if(!isEmailValid($alias."@".$domainname) && $alias!="*") {
      //alias is not valid....!
      if($caller=="domain") {
       HTTPRedirect("domain6.php?error=error7&searchdomain=1&domain=$domainname&username=$username&password=$password&alias=$alias");
       exit;
      }
      else {
       HTTPRedirect("account2.php?error=error7&searchdomain=1&domainname=$domainname&username=$username&password=$password&alias=$alias");
       exit;
      }
    }
  
    //tjeck if alias is used
    if($ACCOUNT->isAliasUsed($DBCONN,$alias,$domainname)) {
      //alias is already used by another user....!
      if($caller=="domain") {
       HTTPRedirect("domain6.php?error=error2&searchdomain=1&domain=$domainname&username=$username&password=$password&alias=$alias");
       exit;
      }
      else {
       HTTPRedirect("account2.php?error=error2&searchdomain=1&domainname=$domainname&username=$username&password=$password&alias=$alias");
       exit;
      }
    }
      
    $IMAP=new cyradm;
    $IMAP->imap_login();  
    
    if(!$ACCOUNT->createAccount($DBCONN, $IMAP, $username, $password, $domainname, $prefix, $alias)) {
    	//Error occured
      if($caller=="domain") {   
        HTTPRedirect("domain6.php?error=error3&searchdomain=1&domain=$domainname&username=$username&password=$password&alias=$alias");
        exit;
      }
      else {
       HTTPRedirect("account2.php?error=error3&searchdomain=1&domainname=$domainname&username=$username&password=$password&alias=$alias");
       exit;
      }
    }
    else {
      //SUCCESS	
      if($caller=="domain") { 
       HTTPRedirect("domain5.php?domain=$domainname");
       exit; 
      }
      else {
       HTTPRedirect("account1.php?search=true&content=$domainname&column=2&sort=1&perpage=1&page=1");
       exit;
      }
    }
  
   
  }
  
  # *****************************************************
  # Delete account
  # Input: $deleteaccount (trigger this action)
  #        $account
  #	   $domainname

  
  if(!empty($deleteaccount)) {
    if(empty($account)) {
      if($caller=="domain") {  
        HTTPRedirect("domain9.php?error=error1&account=$account");
        exit;
      }
      else { 
       //redirect missing fields
        HTTPRedirect("account4.php?error=error1&account=$account");
        exit;
      }
    }
    $ACCOUNT=new Account;
    $ALIAS=new Alias;
    $IMAP=new cyradm;
    $IMAP->imap_login();
    
    if(!$ACCOUNT->deleteAccount($DBCONN,$IMAP,$ALIAS,$account)) {
      //Error occured
       if($caller=="domain") {
        HTTPRedirect("domain9.php?error=error2&account=$account");
        exit;
      }
      else {
        HTTPRedirect("account4.php?error=error2&account=$account");
        exit;
      }	
    }
    else {
      //SUCCESS
       if($caller=="domain") {
        HTTPRedirect("domain5.php?domain=$domainname");
        exit;
      }
      else {
        HTTPRedirect("account1.php");
        exit;
      }	
      	
    }
        
  }
  
  # *****************************************************
  # Update account
  # Input: $updateaccount (trigger this action)
  #        $account
  #	   $password
  #	   $alias
  #	   $domainname

  
  if(!empty($updateaccount)) {
   foreach ($alias as $name => $value)
        $post[]="alias[]=".urlencode($value);
        $post = implode ("&", $post);
 

   if(empty($password) || is_array_empty($alias)) {
      if($caller=="domain") {  
       //redirect missing fields
       HTTPRedirect("domain9.php?error=error1&account=$account&password=$password&domain=$domainname&".$post);
       exit;
      }
      else {
       //redirect missing fields
       HTTPRedirect("account4.php?error=error1&account=$account&password=$password&domain=$domainname&".$post);
       exit;
      }
    }
    $ACCOUNT=new Account;
    $ACCOUNT->retrieveAccount($DBCONN,$account);
   

    //tjeck password length
    if(!(strlen(trim($password))>=$ACCOUNT_PASSWORD_LENGTH)) {
      if($caller=="domain") {
       //redirect password length to short
       HTTPRedirect("domain9.php?error=error7&account=$account&password=$password&domain=$domainname&".$post);
       exit;
      }
      else {
       //redirect password length to short
       HTTPRedirect("account4.php?error=error7&account=$account&password=$password&domain=$domainname&".$post);
       exit;
      }

    }
 
    //tjeck if aliases are valid
    for($a=0;$a<count($alias);$a++) {
     $alias_withdom=trim($alias[$a])."@".$domainname;
       if((!isEmailValid($alias_withdom) && ($alias[$a]!="")) && $alias[$a]!="*") {
         $aliaserrortmp[$a]="true";
         $validationerror=1;
       }
       else
         $aliaserrortmp[$a]="false";
    }
    if($validationerror) {
      //alias is not valid....!
       foreach ($aliaserrortmp as $name => $value)
       $errorhandling[]="aliaserror[]=".urlencode($value);
       $errorhandling = implode ("&", $errorhandling);
 
      if($caller=="domain") {
        //echo ("domain9.php?error=error6&account=$account&password=$password&domain=$domainname&".$post."&".$errorhandling);
        //exit;
	HTTPRedirect("domain9.php?error=error6&account=$account&password=$password&domain=$domainname&".$post."&".$errorhandling);
        exit;
      }
      else {
        HTTPRedirect("account4.php?error=error6&account=$account&password=$password&domain=$domainname&".$post."&".$errorhandling);
        exit;
      }
    }
    
    //tjeck if the aliases already is used (by someone else)
    for($a=0;$a<count($alias);$a++) {
     if($alias[$a]=="*") $aliastmp[$a]=""; else $aliastmp[$a]=$alias[$a];
     $alias_withdom=trim($aliastmp[$a])."@".$domainname;
       if($ACCOUNT->isAliasUsed($DBCONN,trim($aliastmp[$a]),$domainname) && !(in_array($alias_withdom,$ACCOUNT->alias))) {  
         $aliaserrortmp[$a]="true";
         $aliasusederror=1;
       }
       else
         $aliaserrortmp[$a]="false";
    }
    if($aliasusederror) {
      //alias is already used by another user....!
       foreach ($aliaserrortmp as $name => $value)   
       $errorhandling[]="aliaserror[]=".urlencode($value);
       $errorhandling = implode ("&", $errorhandling); 
      
      if($caller=="domain") {
        HTTPRedirect("domain9.php?error=error5&account=$account&password=$password&domain=$domainname&".$post."&".$errorhandling);
        exit;
      }
      else {
        HTTPRedirect("account4.php?error=error5&account=$account&password=$password&domain=$domainname&".$post."&".$errorhandling);
        exit;
      }
    }
      
    if(!$ACCOUNT->updateAccount($DBCONN,$account,$password,$alias,$domainname)) {
      if($caller=="domain") {
      //Error occured
        HTTPRedirect("domain9.php?error=error4&account=$account&password=$password&domain=$domainname&".$post);
        exit;
      }
      else {
        HTTPRedirect("account4.php?error=error4&account=$account&password=$password&".$post);
        exit;
      }
    }
    else {
      if($caller=="domain") { 
       //SUCCESS
       HTTPRedirect("domain9.php?account=$account");
       exit;
      }
      else {
        //SUCCESS
       HTTPRedirect("account4.php?account=$account");
       exit;
      }
      	
    }
        
  }

?>
Return current item: Replex