Location: PHPKode > projects > Replex > replex-0.9.0/admin/alias_update.php
<?php
/*************************************************************
$Id: alias_update.php,v 1.4 2001/05/20 00:21:51 jimir Exp $
 
 ***************************************************************/

include("include/config.php");
include("lib/user.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 alias
  # Input: $createalias (trigger this action)
  #        $domain
  #        $alias
  #        $dest
  #        $email
  #	   $accounts
  
  if(!empty($createalias)) {
    if(empty($domain) || empty($alias) || empty($dest)) {
      //redirect missing fields
      if($caller=="domain") {
       HTTPRedirect("domain8.php?error=error1&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts");
       exit; 
      } 
      else {      
       exit;
      }
    }
    $ALIAS = new Alias;
    if($ALIAS->isAliasUsed($DBCONN,$alias,$domain)) {
      //alias is already used by another user....!
      if($caller=="domain") {
        HTTPRedirect("domain8.php?error=error2&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts");
       exit;
      }
      else {
      
       exit;
      }
    }

    //tjeck if alias is valid  
    if(!isEmailValid($alias."@".$domain) && $alias!="*") {
      if($caller=="domain") {
        HTTPRedirect("domain8.php?error=error8&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts");
       exit;
      }
      else {
 
       exit;
      }

    }
        
  
    if($dest=="email")
    $destination=$email;
    else
    $destination=$accounts;   

    if($dest=="account" && $destination=="none") {
      //thats not allowed....an account must be chosen!!
      if($caller=="domain") {
        HTTPRedirect("domain8.php?error=error4&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts");
       exit;
      }
      else {
 
       exit;
      }
    }
 

    //tjeck if email is valid
    if($dest=="email" && !isEmailValid($destination)) { 
      //emailadress must be valid!!
      if($caller=="domain") {
        HTTPRedirect("domain8.php?error=error7&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts");
       exit;
      }
      else {
 
       exit;
      }
    }

    $username=$USER->getUsername();

    if(!$ALIAS->createAlias($DBCONN, $domain, $alias, $destination, $username)) {
      //error occured
      if($caller=="domain") {
        HTTPRedirect("domain8.php?error=error5&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts");
       exit;
      }
      else {
 
       exit;
      }

    }
    else {
      //SUCCESS
            if($caller=="domain") {
        HTTPRedirect("domain7.php?domain=$domain");
       exit;
      }
      else {
 
       exit;
      }
    }  
  }



  # *****************************************************
  # Update alias
  # Input: $updatealias (trigger this action)
  #        $domain
  #        $alias
  #        $dest
  #        $email
  #        $accounts
  #	   $oldalias //the existing alias
 
  if(!empty($updatealias)) { 
    if(empty($domain) || empty($alias)) {
      //redirect missing fields
      if($caller=="domain") {
       HTTPRedirect("domain10.php?error=error1&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts&oldalias=$oldalias");
       exit;
      }
      else {
       exit;
      }
    }
    $ALIAS = new Alias;
    if($ALIAS->isAliasUsed($DBCONN,$alias,$domain,$oldalias)) {
      //alias is already used by another user....!
      if($caller=="domain") {
        HTTPRedirect("domain10.php?error=error2&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts&oldalias=$oldalias");
       exit;
      }
      else {
 
       exit;
      }
    }

    //tjeck if alias is valid
    if(!isEmailValid($alias."@".$domain) && $alias!="*") {
      if($caller=="domain") {
        HTTPRedirect("domain10.php?error=error8&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts&oldalias=$oldalias");
       exit;
      }
      else {
 
       exit;
      }
 
    }
 
    if($dest=="email")
    $destination=$email;
    else
    $destination=$accounts;
 /*
    if($dest=="account" && $destination=="none") {
      //thats not allowed....an account must be chosen!!
      if($caller=="domain") {
        HTTPRedirect("domain10.php?error=error4&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts&oldalias=$oldalias");
       exit;
      }
      else {
 
       exit;
      }
    }
*/

    //tjeck if email is valid
    if($dest=="email" && !isEmailValid($destination)) {
      //emailadress must be valid!!
      $destination="none";
     /*
      if($caller=="domain") {
        HTTPRedirect("domain10.php?error=error7&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts&oldalias=$oldalias");
       exit;
      }
      else {
 
       exit;
      }
      */
    }
    if(!$ALIAS->updateAlias($DBCONN, $domain, $alias, $oldalias, $destination)) {
      //error occured
      if($caller=="domain") {
        HTTPRedirect("domain10.php?error=error5&domain=$domain&alias=$alias&dest=$dest&email=$email&accounts=$accounts&oldalias=$oldalias");
       exit;
      }
      else {
 
       exit;
      }
 
    }
    else {
      //SUCCESS
        if($caller=="domain") {
          if($alias=="*") $alias="";
        HTTPRedirect("domain10.php?alias=".$alias."@".$domain);
       exit;
      }
      else {
 
       exit;
      }
    }
  }
 

   # *****************************************************
  # Delete alias
  # Input: $deletealias (trigger this action)
  #        $oldalias //the existing alias
  #        $caller
  #        $domain
 
  if(!empty($deletealias)) {
	$ALIAS = new Alias; 

 
	if(!$ALIAS->checkAliasDependencies($DBCONN,$oldalias)) {
		//we could not delete....some accounts have this alias as the only one!
		if($caller=="domain") {
                        HTTPRedirect("domain10.php?error=error9&alias=$oldalias");
                }
	}
	else {

		if(!$ALIAS->deleteAlias($DBCONN,$oldalias)) {  
			//DB-ERROR in deleting
			if($caller=="domain") {
        			HTTPRedirect("domain10.php?error=error5&alias=$alias");
			}
		}
		else {
		 	//SUCCESS, alias deleted
                        if($caller=="domain") {
                                HTTPRedirect("domain7.php?domain=$domain");
                        }
		}
	}

  } 
Return current item: Replex