Location: PHPKode > projects > Replex > replex-0.9.0/lib/domain.php
<?php
/*************************************************************
$Id: domain.php,v 1.5 2001/05/19 03:30:31 jimir Exp $
 
 ***************************************************************/
 
class Domain {

  var $name;
  var $prefix;
  var $maxaccounts;
  
  function retrieveDomains($DBCONN,$type=NULL,$search=NULL,$sort=NULL,$perpage=NULL,$page=NULL) {
    if(empty($sort)) {
      $sortby="domain_name";	
    }
    else {
      if($sort==1)
      $sortby="domain_name";
      else
      $sortby="prefix";
    }
    if(empty($type)) {
      $type="showall";	
    }
    
    if(empty($perpage)) {
      $perpage_number=30;
    }
    else {
      switch($perpage) {
        case 1:
        $perpage_number=30;
        break;
        case 2:
        $perpage_number=50;
        break;
        case 3:
        $perpage_number=100;
        break;
        case 4:
        $perpage_number=5;
        break;
      }
    }
    
    if(empty($page)) {
      $page=1;	
    }
    
  
    if($type=="search") {
       if($search["COLUMN"]==1)
      	$column="domain_name";
      else {
        $column="prefix";
	}	

      	$content=$search["CONTENT"];
      	$this->perpage=$perpage_number;
        //fetch all domains that match
        $query = "SELECT domain_name,prefix,rd.maxaccounts FROM domain rd WHERE rd.".$column." like '%".$content."%' ORDER BY rd.".$sortby;
      }
      else if($type=="search_id") {
       $SEARCH = new Search;
       $SEARCH->retrieveSearchSql($DBCONN,$search);
       $query =	trim($SEARCH->getSearchSql());
       $this->perpage = $perpage_number = $SEARCH->getPerpage();
      }
      else {
       //fetch all domains
       $this->perpage=$perpage_number;
       $query = "SELECT domain_name,prefix,rd.maxaccounts FROM domain rd ORDER BY rd.".$sortby;
      }
    

    //calculate the limit
    $limit_end=$perpage_number;   
    $limit_start=($page*$limit_end)-$perpage_number;
    $limit="LIMIT ".$limit_start.",".$limit_end;
    
    $DBCONN->Query($query." ".$limit);
    for($i=0;$i<$DBCONN->rows;$i++){   // for each row of results
      $DBCONN->GetRow($i);       // get the data for row $i
      $this->name[$i]=$DBCONN->data[domain_name];
      $this->prefix[$i]=$DBCONN->data[prefix];
      $this->maxaccounts[$i]=$DBCONN->data[maxaccounts];
    }
    
    $DBCONN->Query($query); //doing the query againg just for getting total number of rows....hmmmm not good
    $this->affected_rows=$DBCONN->rows;
    $temp_total=$this->affected_rows/$perpage_number;
    if($temp_total/1==0)
    $this->total_pages=$temp_total;
    else
    $this->total_pages=((int)$temp_total)+1;
    
    $this->search_sql=$query;
  }
 
  
  function retrieveDomain($DBCONN,$domain) {
      $query = "SELECT * FROM domain WHERE domain_name='".$domain."'";
      $DBCONN->QueryRow($query);
      if($DBCONN->rows==1) {
       $this->name[0]=$DBCONN->data[domain_name];
       $this->prefix[0]=$DBCONN->data[prefix];
       $this->maxaccounts[0]=$DBCONN->data[maxaccounts];
       return 1;
      }
      else {
      	$this->name[0]=$domain;
        return 0;
      }
  }
  
  function retrieveAllDomains($DBCONN) {
      $query = "SELECT * FROM domain";
      $DBCONN->Query($query);
      for($i=0;$i<$DBCONN->rows;$i++) {
       $DBCONN->GetRow($i);
       $this->names[$i]=$DBCONN->data[domain_name];
       //$this->prefix[$i]=$DBCONN->data[prefix];
       //$this->maxaccounts[$i]=$DBCONN->data[maxaccounts];
      }
      return 1;
  }

  function deleteDomain($DBCONN,$IMAP,$domain) {
     //delete everything belonging to a domain
     $query1 = "SELECT username FROM accountuser WHERE domain_name='".$domain."'";
     $query2 = "DELETE FROM domain WHERE domain_name='".$domain."'";  
     $query3 = "DELETE FROM virtual WHERE alias='".$domain."' OR alias like '%@".$domain."'"; 
     $query4 = "DELETE FROM accountuser WHERE domain_name='".$domain."'";
     
     $DBCONN->Query($query1);
     for($i=0;$i<$DBCONN->rows;$i++) {
       $DBCONN->GetRow($i);
       $account=$DBCONN->data[username];
       $IMAP->deletemb("user.".$account);
     }
     
     $DBCONN->Delete($query2);
     $DBCONN->Delete($query3);
     $DBCONN->Delete($query4);

     return 1;
  }

 
  # GET Functions
  function getName($i=0) {
    return $this->name[$i];
  }  
  function getPrefix($i=0) {
    return $this->prefix[$i];	
  }
  
  function getMaxAccounts($i=0) {
    return $this->maxaccounts[$i];	
  }
  
  function getAffectedRows() {
    return $this->affected_rows;	
  }
  
  
  
} //class end
?>
Return current item: Replex