/** * Attempts to create a client * * @return mixed * @param array $record The client record to create. */ private function createClient($record) { // get the account settings $url = BackendModel::getModuleSetting($this->getModule(), 'cm_url'); $username = BackendModel::getModuleSetting($this->getModule(), 'cm_username'); $password = BackendModel::getModuleSetting($this->getModule(), 'cm_password'); // create a client try { // fetch complete list of timezones as pairs $timezones = BackendMailmotorCMHelper::getTimezonesAsPairs(); // init CampaignMonitor object $cm = new CampaignMonitor($url, $username, $password, 10); // create client $clientID = $cm->createClient($record['company_name'], $record['contact_name'], $record['contact_email'], $record['country'], $timezones[$record['timezone']]); // store ID in a setting if (!empty($clientID)) { BackendModel::setModuleSetting($this->getModule(), 'cm_client_id', $clientID); } } catch (Exception $e) { // add an error to the email field $this->redirect(BackendModel::createURLForAction('settings') . '&error=campaign-monitor-error&var=' . $e->getMessage() . '#tabSettingsClient'); } }