| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- namespace ThurData\Servers\KerioEmail\App\UI\Client\DistributionList\Providers;
- use ThurData\Servers\KerioEmail\App\Enums\ProductParams;
- use ThurData\Servers\KerioEmail\App\Enums\Kerio;
- use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
- use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Create\CreateDistributionList;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Update\UpdateDistributionList;
- use function ThurData\Servers\KerioEmail\Core\Helper\di;
- use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
- use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- /**
- *
- * Created by PhpStorm.
- * User: ThurData
- * Date: 02.10.19
- * Time: 08:36
- * Class EditListDataProvider
- */
- class EditListDataProvider extends AddListDataProvider
- {
- public function read()
- {
- /**
- * load hosting
- */
- $hosting = Hosting::where('id', $this->getRequestValue('id'))->first();
- /**
- * load api
- */
- $api = (new KerioManager())->getApiByServer($hosting->server);
- $repository = new Repository($api->soap);
- $list = $repository->lists()->getDistributionListBydId($this->actionElementId);
- $this->data['id'] = $list->getId();
- $res = explode('@', $list->getName());
- $this->data['listmail'] = $res[0];
- $this->data['domain'] = $res[1];
- $this->data['emailAliases'] = implode(',', $list->getResourceAliases());
- $this->data['owners'] = implode(',', $list->getResourceOwners());
- /**
- * allow to check which should be removed
- */
- $this->availableValues['memberListActually'] = $this->data['memberListActually'] = $list->getResourceMembers();
- $this->availableValues['emailAliasesActually'] = $this->data['emailAliasesActually'] = $list->getResourceAliases();
- $this->availableValues['ownersActually'] = $this->data['ownersActually'] = $list->getResourceOwners();
- $this->data['displayName'] = $list->getDataResourceA(DistributionList::ATTR_DISPLAY_NAME);
- $this->data['description'] = $list->getDataResourceA(DistributionList::ATTR_DESCRIPTION);
- $this->data['subscriptionRequest'] = $list->getDataResourceA(DistributionList::ATTR_SUBSCRIPTION_REQUEST);
- $this->data['unsubscriptionRequest'] = $list->getDataResourceA(DistributionList::ATTR_UNSUBSCRIPTION_REQUEST);
- $this->data['replyDisplayName'] = $list->getDataResourceA(DistributionList::REPLY_TO_DISPLAY);
- $this->data['replyEmailAddress'] = $list->getDataResourceA(DistributionList::REPLY_TO_ADDRESS);
- $this->data['sharesNotify'] = $list->getDataResourceA(DistributionList::ATTR_NOTIFY_SHARES) === Kerio::ATTR_ENABLED ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
- $this->data['hideGal'] = $list->getDataResourceA(DistributionList::ATTR_HIDE_IN_GAL) === Kerio::ATTR_ENABLED ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
- $this->data['receiveMail'] = $list->getDataResourceA(DistributionList::ATTR_MAIL_STATUS) === Kerio::ENABLED ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
- $this->data['replyEmail'] = $list->getDataResourceA(DistributionList::REPLY_TO_ENABLED) === Kerio::ATTR_ENABLED ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
- /**
- * is dynamic group
- */
- $this->data['dynamicGroup'] = (int)$list->isDynamic() === Kerio::ENABLED_AS_INT ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
- /**
- * available members
- */
- $accounts = $repository->accounts->getByDomainName($hosting->domain);
- /**
- * load lang
- */
- $lang = di('lang');
- /**
- * subscription requests
- */
- $this->availableValues['subscriptionRequest'] = [
- Kerio::STATUS_ACCEPT => $lang->absoluteT('Automatically accept'),
- Kerio::STATUS_APPROVAL => $lang->absoluteT('Require list owner approval'),
- Kerio::STATUS_REJECT => $lang->absoluteT('Automatically reject')
- ];
- /**
- * unsubscription requests
- */
- $this->availableValues['unsubscriptionRequest'] = [
- Kerio::STATUS_ACCEPT => $lang->absoluteT('Automatically accept'),
- Kerio::STATUS_APPROVAL => $lang->absoluteT('Require list owner approval'),
- Kerio::STATUS_REJECT => $lang->absoluteT('Automatically reject')
- ];
- $members = $list->getResourceMembers();
- /**
- *
- */
- foreach ($accounts as $account)
- {
- if(in_array($account->getName(),$members))
- {
- $this->data['memberList'][] = $account->getName();
- }
- $this->availableValues['memberList'][$account->getName()] = $account->getName();
- }
- /**
- * add custom members to array
- */
- $ownMembers = $this->data['memberList'] ? $this->data['memberList'] : [];
- $this->data['customMember'] = implode(',',array_diff($members, $ownMembers));
- if($this->formData)
- {
- $this->loadReloadedData();
- }
- }
- /**
- *
- */
- public function update()
- {
- /**
- *
- * provided aliases
- */
- $customEmails = explode(',',$this->formData['emailAliases']);
- $this->formData['emailAliases'] = [];
- foreach($customEmails as $email)
- {
- if ($email !== '')
- {
- $this->formData['emailAliases'][] = $email;
- }
- }
- /**
- * provided owners
- */
- $owners = explode(',',$this->formData['owners']);
- $this->formData['owners'] = [];
- foreach($owners as $email)
- {
- if ($email !== '')
- {
- $this->formData['owners'][] = $email;
- }
- }
- /**
- * display name
- */
- $this->formData['displayName'] = htmlentities($this->formData['displayName']);
- /**
- * reply display name
- */
- $this->formData['replyDisplayName'] = htmlentities($this->formData['replyDisplayName']);
- /**
- * custom members
- */
- $customMembers = explode(',',$this->formData['customMember']);
- foreach($customMembers as $customMember)
- {
- if($customMember !== '' && !in_array($customMember, $this->formData['memberList']))
- {
- $this->formData['memberList'][] = $customMember;
- }
- }
- $members = $this->formData['memberList'] ? $this->formData['memberList'] : [];
- $this->formData['memberList'] = array_merge($customMembers, $members);
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- /**
- * get product manager
- */
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hid);
- /**
- * load kerio manager by hosting id
- */
- $service = (new KerioManager())
- ->getApiByHosting($hid)
- ->soap
- ->service()
- ->updateDistributionList()
- ->setFormData($this->formData)
- ->setProductManager($productManager)
- ;
- /**
- *
- */
- $result = $service->run();
- if(!$result)
- {
- return (new HtmlDataJsonResponse())->setMessageAndTranslate($service->getError())->setStatusError();
- }
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('distributionListHasBeenUpdated')->setStatusSuccess();
- }
- }
|