InfoSettingDataProvider.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\Setting\Providers;
  3. use ThurData\Servers\KerioEmail\App\Enums\Kerio;
  4. use function ThurData\Servers\KerioEmail\Core\Helper\di;
  5. use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  6. use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  7. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  8. /**
  9. *
  10. * Created by PhpStorm.
  11. * User: ThurData
  12. * Date: 10.09.19
  13. * Time: 13:06
  14. * Class SettingDataProvider
  15. */
  16. class InfoSettingDataProvider extends BaseDataProvider
  17. {
  18. public function read()
  19. {
  20. $this->data['domain'] = $this->getWhmcsParamByKey('domain');
  21. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  22. try {
  23. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  24. $domainID = $api->getDomainId($this->getWhmcsParamByKey('domain'));
  25. } catch (KerioApiException $error) {
  26. logModuleCall(
  27. 'kerioEmail',
  28. __FUNCTION__,
  29. $error,
  30. 'Debug Error',
  31. $error->getMessage()
  32. );
  33. return ['error' => $error->getMessage()];
  34. }
  35. $fields = array(
  36. "id",
  37. "loginName",
  38. "isEnabled");
  39. try {
  40. $users = $api->getUsers($fields,$domainID);
  41. } catch (KerioApiException $error) {
  42. logModuleCall(
  43. 'kerioEmail',
  44. __FUNCTION__,
  45. $error,
  46. 'Debug Error',
  47. $error->getMessage()
  48. );
  49. return ['error' => $error->getMessage()];
  50. }
  51. $api->logout();
  52. foreach($users as $user) {
  53. if($user['isEnabled']){
  54. $this->availableValues['manager'][ $user['id']] = $user['loginName'] . '@' . $this->getWhmcsParamByKey('domain');
  55. }
  56. }
  57. $lang = di('lang');
  58. $this->availableValues['status'] = [
  59. Kerio::ACC_STATUS_ACTIVE => $lang->absoluteT('kerio','account','status','active'),
  60. Kerio::ACC_STATUS_CLOSED => $lang->absoluteT('kerio','account','status','closed'),
  61. ];
  62. $this->availableValues['type'] = [
  63. Kerio::RES_TYPE_LOCATION => $lang->absoluteT('kerio','ressource','type','location'),
  64. Kerio::RES_TYPE_EQUIPMENT => $lang->absoluteT('kerio','ressource','type','equipment')
  65. ];
  66. }
  67. public function create()
  68. {
  69. }
  70. public function updateStatus()
  71. {
  72. }
  73. public function update()
  74. {
  75. }
  76. }