Location: PHPKode > scripts > cpResellerClients > example.php
<?php
//  testing cpResellerClients.class



## change these to your reseller credentials..
## -----------------------------------------
$Domain   = 'reseller.com';
$User     = 'usrname';
$Password = 'weETR3454te';
$UseSSL   = true;

## change this for the example to use (1 to 7)..
## -------------------------------------------
$Example  = 4;

## for testing..
## -----------
define('SOURCE_CSV_FILE', 'csv-sample.txt');
## if SOURCE_CSV_FILE is defined and the file exists, it will be used for 
## the source data instead of contacting WHM ($Domain, $User, $Password 
## and $UseSSL will be ignored)


require 'cpResellerClients.class.php';

$Reseller=new cpResellerClients($Domain, $User, $Password, $UseSSL);
$Err=$Reseller->GetErrors();
if($Err){ echo 'Errors:<pre>'; print_r($Err); echo '</pre>'; die; }

## you can include clients for another reseller..
## --------------------------------------------
if(false) // true for additional reseller
    {
    $Reseller->AddReseller('reseller2.com', 'username2', 'password2', $UseSSL);
    $Err=$Reseller->GetErrors();
    if($Err){ echo 'Errors:<pre>'; print_r($Err); echo '</pre>'; die; }
    }


############ EXAMPLES ############

switch($Example)
    {
    case 1: // show all client data
        $Client=$Reseller->GetClients();
        echo 'Client:<pre>'; print_r($Client); echo '</pre>';
        // you can also specify a template, eg ->GetClients('tpl.toplist.html');
        break;

    case 2: // sort by start date, then show all client data
        $Reseller->SortClients('Unix Startdate', SORT_ASC);
        $Client=$Reseller->GetClients();
        echo 'Client:<pre>'; print_r($Client); echo '</pre>';
        break;
        
    case 3: // show accounts over 60% used (array)..
        $Client=$Reseller->GetClientsOver(60);
        echo 'Client:<pre>'; print_r($Client); echo '</pre>';
        break;
        
    case 4: // show accounts over 60% used (html table)..
        $Percent=60;
        $Client=$Reseller->GetClientsOver($Percent, 'tpl.toplist.html');
        if($Client)
            {
            echo 'Clients with over '.$Percent.'% usage:<table border="1">';
            echo '<tr><th>Reseller</th><th>Domain</th><th>Used</th><th>Used / Quota</th><th>Email</th></tr>';
            echo $Client;
            echo '</table>';
            }
        break;
        
    case 5: // show accounts over 60% used (plain text)..
        $Client=$Reseller->GetClientsOver(60, 'tpl.plain.txt');
        if($Client) echo '<pre>'.$Client.'</pre>';
        //this could be used for sending via email
        break;
        
    case 6: // custom result..
        $Reseller->SortClients('Percent_used', SORT_DESC);
        $Client=$Reseller->GetClients();
        foreach($Client as $ThisClient)
            {
            echo $ThisClient['Domain'].' has used '.$ThisClient['Percent_used'].'% ('
                .$ThisClient['Disk Space Used'].'/'.($ThisClient['Quota (bytes)']/1024).' M) '
                .'Account created on '.date('j M Y \a\t H:i:s', $ThisClient['Unix Startdate'])
                ."<br />\r\n";
            }
        $TotalAllocated=$Reseller->GetTotalAllocated();
        $TotalUsed=$Reseller->GetTotalUsed();
        $TotalPercent=number_format(100*$TotalUsed/$TotalAllocated, 1);
        echo "<br />Total $TotalPercent% ($TotalUsed / $TotalAllocated)<br />\r\n";
        break;
        
    case 7: // show field names..
        $Field=$Reseller->GetFieldNames();
        echo 'Fields:<pre>'; print_r($Field); echo '</pre>';
        break;
    }

$Err=$Reseller->GetErrors();
if($Err){ echo 'Errors:<pre>'; print_r($Err); echo '</pre>'; die; }


?>
Return current item: cpResellerClients