Accounts.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Pages;
  3. use ThurData\Servers\KerioEmail\App\Helpers\BuildUrlExtended;
  4. use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
  5. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  6. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Connection;
  7. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Helpers\AccountHelper;
  8. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Account;
  9. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
  10. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Filters\EmailAccounts\FilterByCosId;
  11. use ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Fields\EnabledField;
  12. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\AddAccountButton;
  13. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\ChangePasswordButton;
  14. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\ChangeStatusButton;
  15. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\DeleteAccountButton;
  16. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\EditAccountButton;
  17. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\LoginToPanelButton;
  18. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\MassChangeStatusButton;
  19. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\MassDeleteAccountButton;
  20. use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\SpanDropdownButton;
  21. use function ThurData\Servers\KerioEmail\Core\Helper\di;
  22. use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
  23. use ThurData\Servers\KerioEmail\Core\UI\Widget\Buttons\DropdawnButtonWrappers\ButtonDropdown;
  24. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\Column;
  25. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\DataProvider;
  26. use ThurData\Servers\KerioEmail\Core\UI\Interfaces\ClientArea;
  27. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
  28. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataTable;
  29. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  30. use ThurData\Servers\KerioEmail\Core\UI\Traits\WhmcsParams;
  31. /**
  32. *
  33. * Created by PhpStorm.
  34. * User: ThurData
  35. * Date: 10.09.19
  36. * Time: 10:51
  37. * Class Accounts
  38. */
  39. class Accounts extends DataTable implements ClientArea
  40. {
  41. use WhmcsParams;
  42. /**
  43. * labels for statuses
  44. */
  45. const STATUS_LABEL = [
  46. 'active' => 'success',
  47. 'locked' => 'default',
  48. 'maintenance' => 'warning',
  49. 'closed' => 'default',
  50. 'lockout' => 'info',
  51. 'pending' => 'warning',
  52. 'default' => 'default'
  53. ];
  54. protected $id = 'accounts';
  55. protected $name = 'accounts';
  56. protected $title = null;
  57. /**
  58. * load columns
  59. */
  60. protected function loadHtml()
  61. {
  62. $this
  63. ->addColumn((new Column('mailbox'))
  64. ->setOrderable(DataProvider::SORT_ASC)
  65. ->setSearchable(true, Column::TYPE_STRING))
  66. ->addColumn((new Column('date_created'))
  67. ->setOrderable()
  68. ->setSearchable(true))
  69. ->addColumn((new Column('date_created'))
  70. ->setOrderable()
  71. ->setSearchable(true))
  72. ->addColumn((new Column('last_login'))
  73. ->setOrderable()
  74. ->setSearchable(true))
  75. ->addColumn((new Column('quota'))
  76. ->setOrderable()
  77. ->setSearchable(true, Column::TYPE_INT))
  78. ->addColumn((new Column('status'))
  79. ->setOrderable()
  80. ->setSearchable(true));
  81. }
  82. /**
  83. * @param $key
  84. * @param $row
  85. * @return mixed
  86. */
  87. public function replaceFieldStatus($key, $row)
  88. {
  89. $status = self::STATUS_LABEL[$row[$key]] ? self::STATUS_LABEL[$row[$key]] : self::STATUS_LABEL['default'];
  90. $label = di('lang')->absoluteT('kerio','account','status',$row[$key]);
  91. $field = new EnabledField();
  92. $field->setRawType($status);
  93. $field->setRawTitle($label);
  94. return $field->getHtml();
  95. }
  96. /**
  97. * @param $key
  98. * @param $row
  99. * @return mixed
  100. */
  101. public function replaceFieldLast_login($key, $row)
  102. {
  103. return $row[$key] ? $row[$key] : '-';
  104. }
  105. /**
  106. * load buttons
  107. */
  108. public function initContent()
  109. {
  110. $productManager = new ProductManager();
  111. $productManager->loadByHostingId($this->getRequestValue('id'));
  112. $this->addMassActionButton(new MassChangeStatusButton());
  113. $this->addMassActionButton(new MassDeleteAccountButton());
  114. $this->addButton(new AddAccountButton());
  115. $this->addActionButton(new EditAccountButton());
  116. $this->addActionButton(new DeleteAccountButton());
  117. $actions = new SpanDropdownButton('actions');
  118. $actions->addButton(new ChangeStatusButton());
  119. $actions->addButton(new ChangePasswordButton());
  120. $this->addActionButton($actions);
  121. }
  122. /**
  123. * load data
  124. */
  125. public function loadData()
  126. {
  127. /**
  128. * load hosting
  129. */
  130. $hosting = Hosting::where('id', $this->getRequestValue('id'))->first();
  131. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  132. logModuleCall(
  133. 'kerioEmail',
  134. __FUNCTION__,
  135. $params,
  136. 'Debug params',
  137. $this
  138. );
  139. try {
  140. $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
  141. $domains = $api->getDomains(['id','name']);
  142. } catch (KerioApiException $error) {
  143. logModuleCall(
  144. 'kerioEmail',
  145. __FUNCTION__,
  146. $error,
  147. 'Debug Error',
  148. $error->getMessage()
  149. );
  150. return ['error' => $error->getMessage()];
  151. }
  152. logModuleCall(
  153. 'kerioEmail',
  154. __FUNCTION__,
  155. $params,
  156. 'Debug Accounts',
  157. $domains
  158. );
  159. $api->logout();
  160. $productManager = new ProductManager();
  161. $productManager->loadByHostingId($hosting->id);
  162. /**
  163. * format model to array
  164. */
  165. $data = [];
  166. /* foreach ($accounts as $account)
  167. {
  168. $accountArray = [
  169. 'id' => $account->getId(),
  170. 'mailbox' => $account->getName(),
  171. 'date_created' => AccountHelper::getFormattedData($account->getDataResourceA('kerioCreateTimestamp')),
  172. 'last_login' => AccountHelper::getFormattedData($account->getDataResourceA('kerioLastLogonTimestamp'), 'd/m/Y H:i'),
  173. 'quota' => AccountHelper::getQuotaAsMb($account->getDataResourceA('kerioMailQuota')),
  174. 'status' => $account->getDataResourceA('kerioAccountStatus'),
  175. ];
  176. $data[] = $accountArray;
  177. } */
  178. $dataProv = new ArrayDataProvider();
  179. $dataProv->setDefaultSorting('mailbox', 'ASC')->setData($data);
  180. $this->setDataProvider($dataProv);
  181. }
  182. }