| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php declare(strict_types = 0);
- /*
- ** WeCom Center - GET controller. Gathers current state and renders the page.
- */
- namespace Modules\WecomCenter\Actions;
- use CController;
- use CControllerResponseData;
- use CWebUser;
- use Modules\WecomCenter\Lib\Helper;
- use Modules\WecomCenter\Lib\I18n;
- class WecomCenterView extends CController {
- protected function init() {
- $this->disableCsrfValidation();
- }
- protected function checkInput() {
- return true;
- }
- protected function checkPermissions() {
- return CWebUser::getType() == USER_TYPE_SUPER_ADMIN;
- }
- protected function doAction() {
- $module_dir = dirname(__DIR__);
- $mediatypes = Helper::webhookMediatypes();
- // selected media type
- $mediatypeid = (string) ($_REQUEST['mediatypeid'] ?? '');
- if ($mediatypeid === '' && $mediatypes) {
- // prefer one whose name mentions wecom
- foreach ($mediatypes as $mt) {
- if (stripos($mt['name'], 'wecom') !== false) {
- $mediatypeid = (string) $mt['mediatypeid'];
- break;
- }
- }
- if ($mediatypeid === '') {
- $mediatypeid = (string) $mediatypes[0]['mediatypeid'];
- }
- }
- $mediatype = null;
- $webhook_url = '';
- $robot = null;
- $media = null;
- if ($mediatypeid !== '') {
- $mediatype = Helper::getMediatype($mediatypeid);
- if ($mediatype) {
- $webhook_url = Helper::webhookUrl($mediatype);
- }
- $robot = Helper::robotUser('wecomrobot');
- $media = Helper::currentMedia($robot, $mediatypeid);
- }
- // selected host for map tab
- $selected_hostid = (string) ($_REQUEST['hostid'] ?? '');
- $host_loc = ['location_lat' => '', 'location_lon' => ''];
- if ($selected_hostid !== '') {
- $h = Helper::hostLocation($selected_hostid);
- $inv = $h['inventory'] ?? [];
- $host_loc = [
- 'location_lat' => $inv['location_lat'] ?? '',
- 'location_lon' => $inv['location_lon'] ?? ''
- ];
- }
- $data = [
- 'title' => I18n::t('page.title'),
- 'mediatypes' => $mediatypes,
- 'mediatypeid' => $mediatypeid,
- 'mediatype' => $mediatype,
- 'webhook_url' => $webhook_url,
- 'robot' => $robot,
- 'robot_name' => 'wecomrobot',
- 'media' => $media,
- 'severity' => $media['severity'] ?? 48,
- 'active' => $media['active'] ?? 0,
- 'sendto' => $media['sendto'] ?? 'WeCom',
- 'schemes' => Helper::SCHEMES,
- 'templates' => Helper::bundledTemplates($module_dir),
- 'hosts' => Helper::hosts(),
- 'selected_hostid' => $selected_hostid,
- 'host_loc' => $host_loc,
- 'lang' => I18n::lang()
- ];
- $response = new CControllerResponseData($data);
- $response->setTitle(I18n::t('page.title'));
- $this->setResponse($response);
- }
- }
|