diff --git a/whmcs.class.php b/whmcs.class.php index 78d4a5b..574e353 100644 --- a/whmcs.class.php +++ b/whmcs.class.php @@ -26,7 +26,7 @@ public function __construct($url = 'http://whmcs.com/include/api.php', $username public function authenticate($username, $password){ $response = $this->api("validatelogin", array("email" => $username, "password2" => $password)); if($response->userid){ - return true; + return $response->userid; // Same as returning true } return false; @@ -126,6 +126,28 @@ public function getDomainWHOIS($domainId){ return $response; } + /** + * Get product groups - Custom API + * @param int $gid + * @return object + * @throws WhmcsException + */ + public function getProductsGroups($gid = 0){ + $params = array(); + + if($gid > 0){ + $params['gid'] = $gid; + } + + $response = $this->api("getproductgroups", $params); + + if($response->result == 'error'){ + throw new WhmcsException("WHMCS complained: ".$response->message); + } + + return $response; + } + /** * Get products * @param int $pid @@ -136,6 +158,8 @@ public function getDomainWHOIS($domainId){ * @link http://docs.whmcs.com/API:Get_Products */ public function getProducts($pid = 0, $gid = 0, $module = null){ + $params = array(); + if($pid > 0){ $params['pid'] = $pid; } @@ -176,7 +200,7 @@ public function getServices($uid = 0, $serviceId = 0, $domain = '', $productId = } $params['limitnum'] = $limit; - $params['limitstart'] = $limitstart; + //$params['limitstart'] = $limitstart; // TODO: Unused variable if($uid > 0){ $params['clientid'] = $uid; @@ -217,6 +241,8 @@ public function getServices($uid = 0, $serviceId = 0, $domain = '', $productId = * @link http://docs.whmcs.com/API:Get_Transactions */ public function getTransactions($uid = 0, $invoiceId = 0, $transactionId = 0){ + $params = array(); + if($uid > 0){ $params['clientid'] = $uid; } @@ -284,6 +310,8 @@ public function getEmails($uid, $filter = '', $filterdate = '', $start = 0, $lim * @link http://docs.whmcs.com/API:Add_Credit */ public function addCredit($data){ + $credit = array(); + $attributes = array("clientid", "description", "amount"); foreach($attributes as $k){ @@ -305,7 +333,7 @@ public function addCredit($data){ /** * Get Credits - * @param id $uid + * @param int $uid * @return object * @link http://docs.whmcs.com/API:Get_Credits */ @@ -350,7 +378,9 @@ public function updateClient($uid = 0, $update){ */ public function addClient($data){ $attributes = array("firstname", "lastname", "companyname", "email", "address1", "address2", "city", "state", "postcode", "country", "phonenumber", "password2", "currency", "clientip", "language", "groupid", "securityqid", "securityqans", "notes", "cctype", "cardnum", "expdate", "startdate", "issuenumber", "customfields", "noemail", "skipvalidation"); - + + $customer = array(); + foreach($attributes as $k){ $customer[$k] = $data[$k]; } @@ -408,6 +438,8 @@ public function getClient($uid = 0, $email = ''){ public function addContact($data){ $attributes = array("clientid", "firstname", "lastname", "companyname", "email", "address1", "address2", "city", "state", "postcode", "country", "phonenumber", "password2", "permissions", "generalemails", "productemails", "domainemails", "invoiceemails", "supportemails", "skipvalidation"); + $contact = array(); + foreach($attributes as $k){ $contact[$k] = $data[$k]; } @@ -486,13 +518,15 @@ public function createInvoice($data){ "taxrate", "taxrate2", "notes", "sendinvoice", "autoapplycredit"); + $params = array(); + foreach($attributes as $a){ if(!empty($params[$a])){ $params[$a] = $data[$a]; } } - for($i = 0; $i < count($data['items']; $i++)){ + for($i = 0; $i < count($data['items']); $i++){ $params['itemdescription' . $i] = $data['items'][$i]['description']; $params['itemamount' . $i] = $data['items'][$i]['amount']; $params['itemtaxed' . $i] = $data['items'][$i]['taxed']; @@ -557,7 +591,7 @@ public function getOrders($uid = 0, $orderId = 0, $status = '', $start = 0, $lim } if($orderId > 0){ - $params['id'] = $invoiceId; + $params['id'] = $orderId; } if($status == "Pending" || $status == "Active" || $status == "Fraud" || $status == "Cancelled"){ @@ -695,6 +729,8 @@ public function acceptOrder($orderid, $serverid = null, $serviceusername = null, * @link http://docs.whmcs.com/API:Get_Stats */ public function getStats(){ + $params = array(); + $response = $this->api("getstats", $params); if($response->result == 'error'){ diff --git a/whmcs/includes/api/getproductgroups.php b/whmcs/includes/api/getproductgroups.php new file mode 100644 index 0000000..751e38d --- /dev/null +++ b/whmcs/includes/api/getproductgroups.php @@ -0,0 +1,49 @@ + array(), 'params' => array()); + if (isset($vars['cmd'])) { + //Local API mode + $array['action'] = $vars['cmd']; + $array['params'] = (object)$vars['apivalues1']; + $array['adminuser'] = $vars['adminuser']; + + } else { + //Post CURL mode + $array['action'] = $vars['_POST']['action']; + unset($vars['_POST']['username']); + unset($vars['_POST']['password']); + unset($vars['_POST']['action']); + $array['params'] = (object)$vars['_POST']; + } + return (object)$array; +} + +try { + $vars = get_defined_vars(); + //Get the parameters + $request = get_env($vars); + + $gid = (int)$request->params->gid; + + if ($gid) + $productGroups = Capsule::table('tblproductgroups')->where('id', $gid)->get(); + else + $productGroups = Capsule::table('tblproductgroups')->get(); + + if (count($productGroups)) + $apiresults = array( + "result" => "success", + "productGroups" => $productGroups + ); + else + $apiresults = array( + "result" => "error", + "message" => 'There are no product groups' + ); +} catch (Exception $e) { + $apiresults = array("result" => "error", "message" => $e->getMessage()); +} +?> \ No newline at end of file