Location: PHPKode > projects > Replex > replex-0.9.0/admin/domain_update.php
<?php
/*************************************************************
$Id: domain_update.php,v 1.7 2001/05/21 15:05:14 jimir Exp $

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

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

  # *****************************************************
  # Create new domain
  # Input: $createdomain (trigger this action)
  #        $domainname
  #	   $prefix  

  
  
  if(!empty($createdomain)) {
    if(empty($domainname) || empty($prefix) || empty($maxaccounts)) {
      //redirect missing fields
      HTTPRedirect("domain2.php?error=error1&domainname=$domainname&prefix=$prefix&maxaccounts=$maxaccounts");
      exit;
    }
    
    //does the domainname already exists?
    $query = "SELECT * FROM domain WHERE domain_name='".$domainname."'";
    if($DBCONN->Exists($query)) {
      //redirect error
      HTTPRedirect("domain2.php?error=error2&domainname=$domainname&prefix=$prefix&maxaccounts=$maxaccounts");
      exit;
    }
    
    //is the prefix already taken
    $query = "SELECT prefix FROM domain WHERE prefix='".$prefix."'";
    if($DBCONN->Exists($query)) {
      //redirect error
      HTTPRedirect("domain2.php?error=error3&domainname=$domainname&prefix=$prefix&maxaccounts=$maxaccounts");
      exit; 
    }
    
    	
    $query = "INSERT INTO domain (domain_name, prefix, maxaccounts) VALUES('".$domainname."','".$prefix."','".$maxaccounts."')";
    if($DBCONN->Insert($query)) {
      //SUCCESS	
      $query = "INSERT INTO virtual (alias,username) VALUES ('".$domainname."','".$USER->getUsername()."')";
      if($DBCONN->Insert($query)) {
      	//SUCCESS	
        HTTPRedirect("domain3.php?domain=$domainname");
        exit;
      }
      else {
        //DB-ERROR
        HTTPRedirect("domain2.php?error=error5&domainname=$domainname&prefix=$prefix&maxaccounts=$maxaccounts");
        exit;	
      }
    }
    else {
      //DB-ERROR	
      HTTPRedirect("domain2.php?error=error5&domainname=$domainname&prefix=$prefix&maxaccounts=$maxaccounts");
      exit;
    
    }
    
  }
  
  # *****************************************************
  # Update domain
  # Input: $updatedomain (trigger this action)
  #        $domainname
  #	   $prefix  
  #	   $maxaccounts
  
  if(!empty($updatedomain)) {
    if(empty($domainname) || empty($maxaccounts)) {
      //redirect missing fields
      HTTPRedirect("domain4.php?error=error1&domainname=$domainname&prefix=$prefix&maxaccounts=$maxaccounts");
      exit;
    }
    else {
        
      $query = "UPDATE domain SET maxaccounts='".$maxaccounts."' WHERE domain_name='".$domainname."'";
      if($DBCONN->Update($query)) {
        //SUCCESS	
          HTTPRedirect("domain4.php?domain=$domainname");
      }
      else {
        //DB-ERROR	
        HTTPRedirect("domain4.php?error=error4&domainname=$domainname&prefix=$prefix&maxaccounts=$maxaccounts");
        exit;
    
      }	
    }
  	
  }
  
  # *****************************************************
  # Delete domain
  # Input: $deletedomain (trigger this action)
  #        $domainname
  #        $prefix
  #	   $maxaccounts
  
  if(!empty($deletedomain)) {
       $DOMAIN=new Domain;       
       $IMAP=new cyradm;
       $IMAP->imap_login();

       if($DOMAIN->deleteDomain($DBCONN,$IMAP,$domainname)) {
     	//SUCCESS
     	HTTPRedirect("domain1.php");
     	exit;
       }
       else {
       	 //DB-ERROR	
         HTTPRedirect("domain4.php?error=error4&domainname=$domainname&prefix=$prefix&maxaccounts=$maxaccounts");
         exit;
       }
  }

?>
Return current item: Replex