| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- namespace ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Providers;
- use ThurData\Servers\KerioEmail\App\Enums\ProductParams;
- use ThurData\Servers\KerioEmail\App\Enums\Size;
- use ThurData\Servers\KerioEmail\App\Enums\Kerio;
- use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
- use ThurData\Servers\KerioEmail\App\Http\Admin\ProductConfiguration;
- use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Helpers\ServiceFactory;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Ressource;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
- use ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions\Strategy\Types\ClassOfServicesOptions;
- use function ThurData\Servers\KerioEmail\Core\Helper\di;
- use ThurData\Servers\KerioEmail\Core\Http\JsonResponse;
- 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;
- use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
- /**
- *
- * Created by PhpStorm.
- * User: ThurData
- * Date: 10.09.19
- * Time: 13:06
- * Class RessourceDataProvider
- */
- class RessourceDataProvider extends BaseDataProvider
- {
- public function read()
- {
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- $hosting = Hosting::where('id', $hid)->first();
- //todo refactor
- $this->data['domain'] = $hosting->domain;
- $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
- try {
- $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
- $domainID = $api->getDomainId($this->getWhmcsParamByKey('domain'));
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- $fields = array(
- "id",
- "loginName",
- "isEnabled");
- try {
- $users = $api->getUsers($fields,$domainID);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- $api->logout();
- foreach($users as $user) {
- if($user['isEnabled']){
- $this->availableValues['manager'][ $user['id']] = $user['loginName'] . '@' . $this->getWhmcsParamByKey('domain');
- }
- }
- $lang = di('lang');
- $this->availableValues['status'] = [
- Kerio::ACC_STATUS_ACTIVE => $lang->absoluteT('kerio','account','status','active'),
- Kerio::ACC_STATUS_CLOSED => $lang->absoluteT('kerio','account','status','closed'),
- ];
- $this->availableValues['type'] = [
- Kerio::RES_TYPE_LOCATION => $lang->absoluteT('kerio','ressource','type','location'),
- Kerio::RES_TYPE_EQUIPMENT => $lang->absoluteT('kerio','ressource','type','equipment')
- ];
- }
- public function create()
- {
- $fieldToProtection = [
- 'name',
- 'status',
- 'manager',
- 'type',
- 'description'
- ];
- foreach ($this->formData as $field => &$value)
- {
- $value = in_array($field, $fieldToProtection) ? htmlentities($value) : $value;
- }
- $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
- try {
- $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
- $domainID = $api->getDomainId($this->getWhmcsParamByKey('domain'));
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- try {
- $ressourceID = $api->createResouce($this->formData, $domainID);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- $api->logout();
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceHasBeenAdded')->setStatusSuccess();
- }
- public function updateStatus()
- {
- }
- public function update()
- {
- $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
- try {
- $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
- $domainID = $api->getDomainId($this->getWhmcsParamByKey('domain'));
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- $isEnabled = $this->formData['status'] === Kerio::ACC_STATUS_ACTIVE ? true : false;
- /**
- * run service for each id
- */
- foreach($this->request->get('massActions') as $id)
- {
- try {
- $result = $api->updateResouce(['isEnabled' => $isEnabled], $id);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
-
- }
- $api->logout();
- /**
- * return success
- */
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('massRessourceStatusHasBeenUpdated')->setStatusSuccess();
- }
- }
|