getRequestValue('id'))->first(); $this->data['domain'] = $hosting->domain; $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0'); try { $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword')); $domains = $api->getDomains(['id','name']); } catch (KerioApiException $error) { logModuleCall( 'kerioEmail', __FUNCTION__, $error, 'Debug Error', $error->getMessage() ); return ['error' => $error->getMessage()]; } foreach($domains as $maildomain) { if(($maildomain['name']) === $this->getWhmcsParamByKey('domain')){ $this->maildomainID = $maildomain['id']; $this->maildomain = $maildomain['name']; } } $productManager = new ProductManager(); $productManager->loadByHostingId($hosting->id); $fields = array( "id", "loginName"); try { $accounts = $api->getUsers($fields,$this->maildomainID); } catch (KerioApiException $error) { logModuleCall( 'kerioEmail', __FUNCTION__, $error, 'Debug Error', $error->getMessage() ); return ['error' => $error->getMessage()]; } $api->logout(); /** * * load lang */ $lang = di('lang'); $this->availableValues['moderator']['none'] = $lang->absoluteT('none'); foreach($accounts as $account) { $this->availableValues['memberList'][$account['loginName']] = $account['loginName'] . '@' . $this->maildomain; $this->availableValues['moderator'][$account['loginName']] = $account['loginName'] . '@' . $this->maildomain; } /** * subscription requests */ $this->availableValues['subscriptionRequest'] = [ Kerio::STATUS_ACCEPT => $lang->absoluteT('Automatically accept'), Kerio::STATUS_APPROVAL => $lang->absoluteT('Require moderator approval'), Kerio::STATUS_REJECT => $lang->absoluteT('Automatically reject') ]; /** * postings */ $this->availableValues['memberPosting'] = [ Kerio::STATUS_ACCEPT => $lang->absoluteT('Automatically accept'), Kerio::STATUS_APPROVAL => $lang->absoluteT('Require moderator approval'), Kerio::STATUS_REJECT => $lang->absoluteT('Automatically reject') ]; $this->availableValues['nonMemberPosting'] = [ Kerio::STATUS_ACCEPT => $lang->absoluteT('Automatically accept'), Kerio::STATUS_APPROVAL => $lang->absoluteT('Require moderator approval'), Kerio::STATUS_REJECT => $lang->absoluteT('Automatically reject') ]; $this->availableValues['lang'] = [ 'de' => $lang->absoluteT('german'), 'en' => $lang->absoluteT('english') ]; if($this->formData) { $this->loadReloadedData(); } } /** * */ public function loadReloadedData() { foreach($this->formData as $key => $value) { $this->data[$key] = $value; } } public function create() { // add domain to members foreach($this->formData['memberList'] as $member) { $memberList[] = $member . '@' . $this->getWhmcsParamByKey('domain'); } /** * custom members */ $customMembers = explode(',',$this->formData['customMember']); foreach($customMembers as $customMember) { if($customMember !== '' && !in_array($customMember, $this->formData['memberList'])) { $customMemberList[] = $customMember; } } $paramsCreate['name'] = $this->formData['listmail']; $paramsCreate['description'] = $this->formData['description']; $paramsCreate['languageId'] = $this->formData['lang']; $paramsCreate['subscription']['type'] = $this->formData['subscriptionRequest']; $paramsCreate['subscription']['moderatorNotification'] = $this->formData['subscriptionNotify'] === 'on' ? TRUE : FALSE; $paramsCreate['replyTo'] = 'OtherAddress'; $paramsCreate['OtherAddress'] = $this->formData['replyEmailAddress']; $paramsCreate['posting']['memberPosting'] = $this->formData['memberPosting']; $paramsCreate['posting']['nonMemberPosting'] = $this->formData['nonMemberPosting']; $paramsCreate['posting']['sendErrorsToModerator'] = $this->formData['sendErrorsToModerator'] === 'on' ? TRUE : FALSE; if($this->formData['moderator'] != 'none') { $moderator = array( "hasId" => true, "emailAddress" => $this->formData['moderator'] . '@' . $this->getWhmcsParamByKey('domain'), "kind" => "Moderator" ); } $paramsAddMembers[] = $moderator; foreach($memberList as $member) { $intMembers[] = array( "hasId" => true, "emailAddress" => $member, "kind" => "Member" ); } array_push($paramsAddMembers, $intMembers); foreach($customMemberList as $customMember) { $extMembers[] = array( "hasId" => false, "emailAddress" => $customMember, "kind" => "Member" ); } array_push($paramsAddMembers = $extMembers); /** * hosting id */ $hid = $this->request->get('id'); logModuleCall( 'kerioEmail', __FUNCTION__, $paramsCreate, 'Debug add ML', $paramsAddMembers ); return (new HtmlDataJsonResponse())->setMessageAndTranslate('distributionListHasBeenAdded')->setStatusSuccess(); } public function update() { // TODO: Implement update() method. } }