0) { // Get the results of the query $row = mysql_fetch_assoc($result); // Start processing the users addon $username = $row['username']; $serverUsername = $row['serverusername']; $serverPassword = decrypt($row['serverpassword']); $serverPort = $row['configoption6']; $serverHost = empty($row['serverhostname']) ? $row['serverip'] : $row['serverhostname']; $serverSecure = $row['serversecure'] == 'on' ? TRUE : FALSE; try { // Create the WebsitePanel Enterprise Server Client object instance $wsp = new websitepanel_EnterpriseServer($serverUsername, $serverPassword, $serverHost, $serverPort, $serverSecure); // Get the user's details from WebsitePanel - We need the UserId $user = $wsp->getUserByUsername($username); if (empty($user)) { throw new Exception("User {$username} does not exist - Cannot allocate addon for unknown user"); } // Get the user's package details from WebsitePanel - We need the PackageId $package = $wsp->getUserPackages($user['UserId']); $packageId = $package['PackageId']; // Get the associated WebsitePanel addon id $results = select_query('mod_wspaddons', 'wsp_id,is_ipaddress', array('whmcs_id' => $addonId)); $addon = mysql_fetch_array($results); $addonPlanId = $addon['wsp_id']; $addonIsIpAddress = $addon['is_ipaddress']; // Add the Addon Plan to the customer's WebsitePanel package / hosting space $results = $wsp->addPackageAddonById($packageId, $addonPlanId); // Check the results to verify that the addon has been successfully allocated if ($results['Result'] > 0) { // If this addon is an IP address addon - attempt to randomly allocate an IP address to the customer's hosting space if ($addonIsIpAddress) { $wsp->allocatePackageIPAddresses($packageId); } // Add log entry to client log logactivity("WebsitePanel Addon - Account {$username} addon successfully completed - Addon ID: {$addonId}", $userId); } else { // Add log entry to client log throw new Exception("Unknown", $results['Result']); } } catch (Exception $e) { // Error message to log / return $errorMessage = "websitepanel_addons_AddonActivation Fault: (Code: {$e->getCode()}, Message: {$e->getMessage()}, Service ID: {$serviceId})"; // Log to WHMCS logactivity($errorMessage, $userId); } } } /* Addon Activation - WebsitePanel */ add_hook('AddonActivation', 1, 'websitepanel_addons_AddonActivation');