| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- <?php
- namespace ModulesGarden\Servers\KerioEmail\App\UI\Client\Ressource\Providers;
- use ModulesGarden\Servers\KerioEmail\App\Enums\Kerio;
- use ModulesGarden\Servers\KerioEmail\App\Helpers\KerioManager;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Ressource;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Response;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Update\UpdateRessource;
- use ModulesGarden\Servers\KerioEmail\App\Services\ConfigurableOptions\Strategy\Types\ClassOfServicesOptions;
- use function ModulesGarden\Servers\KerioEmail\Core\Helper\di;
- use ModulesGarden\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
- use ModulesGarden\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- /**
- *
- * Created by PhpStorm.
- * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
- * Date: 18.09.19
- * Time: 09:35
- * Class EditRessourceDataProvider
- */
- class EditRessourceDataProvider extends BaseDataProvider
- {
- /**
- *
- */
- public function read()
- {
- /**
- * hosting id
- */
- $hid = $this->getRequestValue('id');
- /**
- * load hosting
- */
- $hosting = Hosting::where('id', $hid)->first();
- /**
- * load api
- */
- $api = (new KerioManager())->getApiByServer($hosting->server);
- $repository = new Repository($api->soap);
- $result = $repository->ressources->getRessourceOptionsById($this->actionElementId);
- if($result instanceof Response && $result->getLastError())
- {
- throw new \Exception($result->getLastError());
- }
- $mailBoxParams = explode('@', $result->getName());
- $this->data['id'] = $result->getId();
- $this->data['username'] = $mailBoxParams[0];
- $this->data['domain'] = $mailBoxParams[1];
- $this->data['status'] = $result->getDataResourceA(Ressource::ATTR_STATUS);
- $this->data['type'] = $result->getDataResourceA(Ressource::ATTR_TYPE);
- $this->data['display_name'] = $result->getDataResourceA(Ressource::ATTR_DISPLAY_NAME);
- $this->data['description'] = $result->getDataResourceA(Ressource::ATTR_DESC);
- $this->data['capacity'] = $result->getDataResourceA(Ressource::ATTR_CAPACITY);
- $this->data['notes'] = $result->getDataResourceA(Ressource::ATTR_NOTE);
- $this->data['contact'] = $result->getDataResourceA(Ressource::ATTR_CONT);
- $this->data['site'] = $result->getDataResourceA(Ressource::ATTR_SITE);
- $this->data['contact_mail'] = $result->getDataResourceA(Ressource::ATTR_CONT_EMAIL);
- $this->data['contact_phone'] = $result->getDataResourceA(Ressource::ATTR_CONT_PHONE);
- $this->data['street'] = $result->getDataResourceA(Ressource::ATTR_STREET);
- $this->data['building'] = $result->getDataResourceA(Ressource::ATTR_BUILDING);
- $this->data['floor'] = $result->getDataResourceA(Ressource::ATTR_FLOOR);
- $this->data['room'] = $result->getDataResourceA(Ressource::ATTR_ROOM);
- $this->data['post_code'] = $result->getDataResourceA(Ressource::ATTR_POSTAL_CODE);
- $this->data['town'] = $result->getDataResourceA(Ressource::ATTR_TOWN);
- $this->data['state'] = $result->getDataResourceA(Ressource::ATTR_STATE);
- $this->data['county'] = $result->getDataResourceA(Ressource::ATTR_COUNTY);
- $this->data['auto_accept'] = $result->getDataResourceA(Ressource::ATTR_AUTO) == 'TRUE' ? 'on' : 'off';
- $this->data['auto_busy'] = $result->getDataResourceA(Ressource::ATTR_BUSY) == 'TRUE' ? 'on' : 'off';
- $lang = di('lang');
- $this->availableValues['status'] = [
- Kerio::ACC_STATUS_ACTIVE => $lang->absoluteT('kerio','account','status','active'),
- Kerio::ACC_STATUS_LOCKED => $lang->absoluteT('kerio','account','status','locked'),
- Kerio::ACC_STATUS_MAINTENANCE => $lang->absoluteT('kerio','account','status','maintenance'),
- Kerio::ACC_STATUS_CLOSED => $lang->absoluteT('kerio','account','status','closed'),
- Kerio::ACC_STATUS_LOCKOUT => $lang->absoluteT('kerio','account','status','lockout'),
- Kerio::ACC_STATUS_PENDING => $lang->absoluteT('kerio','account','status','pending')
- ];
- $this->availableValues['type'] = [
- Kerio::RES_TYPE_LOCATION => $lang->absoluteT('kerio','ressource','type','location'),
- Kerio::RES_TYPE_EQUIPMENT => $lang->absoluteT('kerio','ressource','type','equipment')
- ];
- }
- /**
- * @return HtmlDataJsonResponse
- */
- public function update()
- {
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- $fieldToProtection = [
- 'display_name',
- 'status',
- 'type',
- 'capacity',
- 'description',
- 'notes',
- 'contact',
- 'site',
- 'contact_mail',
- 'contact_phone',
- 'street',
- 'building',
- 'floor',
- 'room',
- 'post_code',
- 'town',
- 'state',
- 'county',
- 'auto_accept',
- 'auto_busy'
- ];
- foreach ($this->formData as $field => &$value)
- {
- $value = in_array($field, $fieldToProtection) ? htmlentities($value) : $value;
- }
- /**
- * product manager allow to check product settings
- */
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hid);
- /**
- *
- * get soap create domain service
- */
- $service =(new KerioManager())
- ->getApiByHosting($hid)
- ->soap
- ->service()
- ->updateRessource();
- /**
- *
- * set product manager & form data to service
- */
- $service
- ->setProductManager($productManager)
- ->setFormData($this->formData);
- /**
- * run service
- */
- $result = $service->run();
- /**
- * return success or error response
- */
- if(!$result)
- {
- return (new HtmlDataJsonResponse())->setMessageAndTranslate($service->getError())->setStatusError();
- }
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceHasBeenUpdated')->setStatusSuccess();
- }
- /**
- * @return HtmlDataJsonResponse
- */
- public function updateStatus()
- {
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- /**
- * product manager allow to check product settings
- */
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hid);
- /**
- *
- * get soap create domain service
- */
- $service =(new KerioManager())
- ->getApiByHosting($hid)
- ->soap
- ->service()
- ->updateRessourceStatus()
- ->setProductManager($productManager)
- ;
- /**
- *
- * set product manager & form data to service
- */
- /**
- * run service for each id
- */
- $service->setFormData($this->formData);
- $result = $service->run();
- if(!$result)
- {
- return (new HtmlDataJsonResponse())->setMessageAndTranslate($service->getError())->setStatusError();
- }
- /**
- * return success
- */
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceStatusHasBeenUpdated')->setStatusSuccess();
- }
- /**
- * @return HtmlDataJsonResponse
- */
- public function changePassword()
- {
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- /**
- * product manager allow to check product settings
- */
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hid);
- /**
- *
- * get soap create domain service
- */
- $service =(new KerioManager())
- ->getApiByHosting($hid)
- ->soap
- ->service()
- ->updateRessourcePassword()
- ->setProductManager($productManager)
- ;
- /**
- *
- * set product manager & form data to service
- */
- /**
- * run service for each id
- */
- $service->setFormData($this->formData);
- $result = $service->run();
- if(!$result)
- {
- return (new HtmlDataJsonResponse())->setMessageAndTranslate($service->getError())->setStatusError();
- }
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('passwordChangedSuccessfully')->setStatusSuccess();
- }
- }
|