Arash Hemmat - 2007-09-29 19:33:45
Hi
If you need to use the Cpanel API2 functions you can make a function like the one below and add it to the class:
<?php
/*
* cPanel API2 Cpanel::Email::listpopswithdisk
* This function lists all email accounts for a domain, along with their disk space quota and disk space usage.
*/
function Email_listpopswithdisk($user,$domain)
{
//connect using prpoer xml api address
$this->connect("/xml-api/cpanel?user=$user&xmlin=<cpanelaction><module>Email</module><func>listpopswithdisk</func><args><domain>$domain</domain></args></cpanelaction>");
//get the output
$xmlstr=$this->getOutput();
if($xmlstr=='')
{
$this->errors[]='No output.';
return false;
}
//disconnect
$this->disconnect();
if($xmlstr)
{
//get the output xml as an array using simple xml
$xml = new SimpleXMLElement($xmlstr);
$i=0;
foreach($xml->data as $entry)
{
$result[$i]['domain']=htmlentities((string) $entry->domain);
$result[$i]['user']=htmlentities((string) $entry->user);
$result[$i]['login']=htmlentities((string) $entry->login);
$result[$i]['email']=htmlentities((string) $entry->email);
$result[$i]['_diskquota']=htmlentities((string) $entry->_diskquota);
$result[$i]['_diskused']=htmlentities((string) $entry->_diskused);
$result[$i]['diskquota']=htmlentities((string) $entry->diskquota);
$result[$i]['diskused']=htmlentities((string) $entry->diskused);
$result[$i]['diskusedpercent']=htmlentities((string) $entry->diskusedpercent);
$result[$i]['diskusedpercent20']=htmlentities((string) $entry->diskusedpercent20);
$result[$i]['humandiskquota']=htmlentities((string) $entry->humandiskquota);
$result[$i]['humandiskused']=htmlentities((string) $entry->humandiskused);
$result[$i]['txtdiskquota']=htmlentities((string) $entry->txtdiskquota);
$i++;
}
return $result;
}
else
{
$this->errors[]='Some errors occured.';
return false;
}
}
?>
Usage:
Usage of this function is just like the other functions in class:
<?php
//include the whm class file.
require_once('whm.php');
// create a new instance of whm class
$test= new whm;
//initilize the whm object
//you can use you hostname or an IP below
//you can find you whm hash when yopu login into your whm account clickong on "Setup Remote Access Key" link.
$test->init('whm_host','whm_user','whm_hash');
$result=$test->Email_listpopswithdisk('user','domain.tld');
print_r($result);
?>