'success', 'closed' => 'default', 'default' => 'default' ]; protected $id = 'accounts'; protected $name = 'accounts'; protected $title = null; /** * load columns */ protected function loadHtml() { $this ->addColumn((new Column('mailbox')) ->setOrderable(DataProvider::SORT_ASC) ->setSearchable(true, Column::TYPE_STRING)) ->addColumn((new Column('last_login')) ->setOrderable() ->setSearchable(true)) ->addColumn((new Column('size')) ->setOrderable() ->setSearchable(true, Column::TYPE_INT)) ->addColumn((new Column('quota')) ->setOrderable() ->setSearchable(true, Column::TYPE_INT)) ->addColumn((new Column('status')) ->setOrderable() ->setSearchable(true)); } /** * @param $key * @param $row * @return mixed */ public function replaceFieldStatus($key, $row) { $status = self::STATUS_LABEL[$row[$key]] ? self::STATUS_LABEL[$row[$key]] : self::STATUS_LABEL['default']; $label = di('lang')->absoluteT('kerio','account','status',$row[$key]); $field = new EnabledField(); $field->setRawType($status); $field->setRawTitle($label); return $field->getHtml(); } /** * @param $key * @param $row * @return mixed */ public function replaceFieldLast_login($key, $row) { return $row[$key] ? $row[$key] : '-'; } /** * load buttons */ public function initContent() { $this->addMassActionButton(new MassChangeStatusButton()); $this->addMassActionButton(new MassDeleteAccountButton()); $this->addButton(new AddAccountButton()); $this->addActionButton(new EditAccountButton()); $this->addActionButton(new DeleteAccountButton()); $actions = new SpanDropdownButton('actions'); $actions->addButton(new ChangeStatusButton()); $actions->addButton(new ChangePasswordButton()); $this->addActionButton($actions); } /** * load data */ public function loadData() { $domain = $this->getWhmcsParamByKey('domain'); $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0'); try { $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword')); $domainID = $api->getDomainId($domain); } catch (KerioApiException $error) { logModuleCall( 'kerioEmail', __FUNCTION__, $error, 'Debug Error', $error->getMessage() ); return ['error' => $error->getMessage()]; } $fields = array( "id", "loginName", "isEnabled", "diskSizeLimit", "consumedSize", "lastLoginInfo", "emailForwarding"); try { $accounts = $api->getUsers($fields,$domainID); } catch (KerioApiException $error) { logModuleCall( 'kerioEmail', __FUNCTION__, $error, 'Debug Error', $error->getMessage() ); return ['error' => $error->getMessage()]; } $api->logout(); $data = []; foreach ($accounts as $account) { logModuleCall( 'kerioEmail', __FUNCTION__, $account, 'Debug Data', '' ); $accountArray = [ 'id' => $account['id'], 'mailbox' => $account['loginName'] . '@' . $domain, 'last_login' => AccountHelper::getFormattedData($account['lastLoginInfo']['dateTime'], 'd/m/Y H:i'), 'size' => AccountHelper::getQuotaAsMb($account['consumedSize']['value'],$account['consumedSize']['units']), 'quota' => $account['diskSizeLimit']['isActive'] ? AccountHelper::getQuotaAsMb($account['diskSizeLimit']['limit']['value'],$account['diskSizeLimit']['limit']['units']) : '∞', 'status' => $account['isEnabled'] ? 'active' : 'default', ]; $data[] = $accountArray; } $dataProv = new ArrayDataProvider(); $dataProv->setDefaultSorting('mailbox', 'ASC')->setData($data); $this->setDataProvider($dataProv); } }