diff --git a/WebsitePanel.WHMCSModule/includes/hooks/websitepanel_sync.php b/WebsitePanel.WHMCSModule/includes/hooks/websitepanel_sync.php new file mode 100644 index 00000000..12ff3ad0 --- /dev/null +++ b/WebsitePanel.WHMCSModule/includes/hooks/websitepanel_sync.php @@ -0,0 +1,107 @@ + 0) + { + // Include the WebsitePanel ES Class + require_once(ROOTDIR . '/modules/servers/websitepanel/websitepanel.class.php'); + + // Retrieve the WebsitePanel Addons module settings + $modSettings = websitepanel_sync_GetSettings(); + + // Create the WebsitePanel object instance + $wsp = new WebsitePanel($modSettings['username'], $modSettings['password'], $modSettings['serverhost'], $modSettings['serverport'], (($modSettings['serversecured']) == 'on' ? TRUE : FALSE)); + + // Get all WSP users with the old email + $items = (array)$wsp->get_users_paged_recursive(1, 'Email', $params['olddata']['email'], 0, 0, ''); + + // Load / parse the XML response + $xml = simplexml_load_string($items['any']); + $rootPath = $xml->NewDataSet; + + // Total number of elements to update + $total = $rootPath->Table->Column1; + + // Begin updating WebsitePanel accounts + for ($i = 0; $i < $total; $i++) + { + // Set the current root element and get the users details from WebsitePanel + // We cannot use the details provided by the get_users_paged_recursive method as it does not return all the required elements to fully update the user + $currentRoot = $rootPath->Table1->$i; + $userDetails = (array)$wsp->get_user_by_username($currentRoot->Username); + + // Update the current user + $wsp->update_user_details($userDetails['RoleId'], (($userDetails['RoleId'] == 2) ? 'Reseller' : 'User'), $userDetails['StatusId'], $userDetails['Status'], $userDetails['LoginStatusId'], $userDetails['LoginStatus'], $userDetails['FailedLogins'], $userDetails['UserId'], $userDetails['OwnerId'], $userDetails['Created'], $userDetails['Changed'], $userDetails['IsDemo'], $userDetails['IsPeer'], $currentRoot->Comments, $params['lastname'], $userDetails['Username'], $userDetails['Password'], $params['firstname'], $params['email'], $params['phonenumber'], $params['postcode'], '', '', '', '', $params['country'], $params['address1'] . (!empty($params['address2']) ? " {$params['address2']}" : ''), $params['city'], $params['state'], TRUE, $params['companyname'], (($userDetails['RoleId'] == 2) ? TRUE : FALSE)); + + // Add log entry to client log + logactivity("WebsitePanel Sync - Account {$currentRoot->Username} contact details updated successfully", $params['userid']); + } + } +} + +/* Update Client Contact Details - WebsitePanel */ +add_hook('ClientEdit', 1, 'websitepanel_sync_ClientEdit'); + +/** + * websitepanel_addons_GetSettings + * + * @access public + * @return array + */ +function websitepanel_sync_GetSettings() +{ + $settings = array(); + + // Retrieve the settings from the modules configuration table + $results = select_query('tbladdonmodules', 'setting,value', array('module' => 'websitepanel_sync')); + while (($row = mysql_fetch_array($results)) != false) + { + $settings[$row['setting']] = $row['value']; + } + return $settings; +} \ No newline at end of file diff --git a/WebsitePanel.WHMCSModule/modules/addons/websitepanel_sync/websitepanel_sync.php b/WebsitePanel.WHMCSModule/modules/addons/websitepanel_sync/websitepanel_sync.php new file mode 100644 index 00000000..8822fa44 --- /dev/null +++ b/WebsitePanel.WHMCSModule/modules/addons/websitepanel_sync/websitepanel_sync.php @@ -0,0 +1,59 @@ + 'WebsitePanel Sync Automation', + 'description' => 'Syncs WHMCS client details / contact changes with WebsitePanel', + 'version' => '1.0', + 'author' => 'Christopher York', + 'fields' => array('serverhost' => array('FriendlyName', 'Enterprise Server Host', 'Type' => 'text', 'Size' => 25, 'Description' => 'Enterprise Server hostname / IP address', 'Default' => '127.0.0.1'), + 'serverport' => array('FriendlyName', 'Enterprise Server Port', 'Type' => 'text', 'Size' => 4, 'Description' => 'Enterprise Server port', 'Default' => 9002), + 'serversecured' => array('FriendlyName', 'Use Secured Connection', 'Type' => 'yesno', 'Description' => 'Tick to use SSL secured connection'), + 'username' => array('FriendlyName', 'Username', 'Type' => 'text', 'Size' => 25, 'Description' => 'Enterprise Server username', 'Default' => 'serveradmin'), + 'password' => array('FriendlyName', 'Password', 'Type' => 'password', 'Size' => 25, 'Description' => 'Enterprise Server password') + ) + ); + return $configarray; +} \ No newline at end of file diff --git a/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.class.php b/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.class.php index a8690372..7c99db93 100644 --- a/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.class.php +++ b/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.class.php @@ -290,6 +290,27 @@ class WebsitePanel return (array)$this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'GetMyPackages', array('userId' => $userid))->GetMyPackagesResult->PackageInfo; } + /** + * + * @param int $userId User id + * @param string $filterColumn Column name to filter on + * @param string $filterValue Filter value + * @param int $statusId Status id + * @param int $roleId Role id + * @param string $sortColumn Column name to sort on + * @param int $startRow Row to start at + * @param int $maximumRows Maximum rows to return + */ + public function get_users_paged_recursive($userId, $filterColumn, $filterValue, $statusId, $roleId, $sortColumn, $startRow = 0, $maximumRows = 999) + { + $params = array(); + foreach (get_defined_vars() as $name => $value) + { + $params[$name] = $value; + } + return $this->execute_server_method(WebSitePanel::SERVICEFILE_USERS, 'GetUsersPagedRecursive', $params)->GetUsersPagedRecursiveResult; + } + /** * WebsitePanel::UpdatePackageLiteral() *