addCssFile('modules/WecomCenter/assets/wecom.center.css');
$e = function ($v) { return htmlspecialchars((string) ($v ?? ''), ENT_QUOTES, 'UTF-8'); };
$t = function (string $k, array $a = []) use ($e) { return $e(I18n::t($k, $a)); };
// Zabbix CTag escapes plain strings; wrap trusted, self-built markup so it renders as HTML.
$raw = function (string $h) {
return new class($h) {
private $h;
public function __construct(string $h) { $this->h = $h; }
public function toString($destroy = true): string { return $this->h; }
public function __toString(): string { return $this->h; }
};
};
$save = $e((new CUrl('zabbix.php'))->setArgument('action', 'wecom.center.save')->getUrl());
$view_url = (new CUrl('zabbix.php'))->setArgument('action', 'wecom.center.view')->getUrl();
$mtid = $e($data['mediatypeid']);
$active_tab = (string) ($_REQUEST['tab'] ?? 'alert');
if (!in_array($active_tab, ['alert', 'opt', 'maint'], true)) {
$active_tab = 'alert';
}
$tabHref = function (string $id) use ($data) {
return htmlspecialchars((new CUrl('zabbix.php'))
->setArgument('action', 'wecom.center.view')
->setArgument('mediatypeid', $data['mediatypeid'])
->setArgument('tab', $id)
->getUrl(), ENT_QUOTES, 'UTF-8');
};
$html_page = (new CHtmlPage())->setTitle(I18n::t('page.title'));
if (!$data['mediatype']) {
$html_page->addItem($raw('
'
.$t('msg.no_mediatype').'
'));
$html_page->show();
return;
}
$mask = (int) $data['severity'];
$enabled = ((int) $data['active'] === 0);
/* helper to build a card */
$card = function (string $ico, string $title, string $body, string $extra = '', string $sub = '') {
return '';
};
/* ============================ TAB 1: ALERT ============================ */
// -- robot --
$robotBody =
'';
$robotCard = $card('🤖', $t('sec.robot'), $robotBody, '', $e($data['mediatype']['name'] ?? ''));
// -- threshold --
$sevChecks = '';
for ($i = 1; $i <= 6; $i++) {
$bit = 1 << ($i - 1);
$chk = (($mask & $bit) !== 0) ? ' checked' : '';
$sevChecks .= '';
}
$thresholdBody =
''.$t('lbl.threshold_hint').'
'
.'';
$thresholdCard = $card('⚙️', $t('sec.threshold'), $thresholdBody);
// -- strategy presets --
$presetRows = '';
foreach ($data['presets'] as $key => $p) {
$is_cur = ((string) $data['current_strategy'] === (string) $key);
$name = $t($p['label']).($is_cur ? ' '.$t('preset.current').'' : '');
$prevUrl = $e((new CUrl('zabbix.php'))
->setArgument('action', 'wecom.center.view')
->setArgument('mediatypeid', $data['mediatypeid'])
->setArgument('tab', 'alert')
->setArgument('preview_preset', $key)
->getUrl());
$presetRows .=
''
.'
'.$name.'
'
.'
'.$t($p['desc']).'
'
.'
';
}
$strategyBody = ''.$t('lbl.strategy_hint').'
'.$presetRows;
$strategyCard = $card('🚨', $t('sec.strategy'), $strategyBody, ' wc-card--wide');
// -- preview --
$previewCard = '';
if ($data['preview'] !== null) {
$pv = $data['preview'];
$pkey = $data['preview_key'];
$rows = '';
foreach ($pv['classes'] as $ck => $c) {
$label = $t($data['classes'][$ck]['label'] ?? $ck);
$rows .= '| '.$label.' | '.$t('sev.'.($c['target'] + 1)).' | '
.''.$e($c['count']).' | '.$e($c['changes']).' |
';
}
$rows .= '| '.$t('cls.total').' | | '
.''.$e($pv['total']).' | '.$e($pv['changes']).' |
';
$tbl = '| '.$t('cls.col.class').' | '.$t('cls.col.target').' | '
.''.$t('cls.col.count').' | '.$t('cls.col.changes').' |
'.$rows.'
';
$body = ''.$t('preview.hint').'
'.$tbl;
$previewCard = $card('🔍', $t('preview.title', [I18n::t($data['presets'][$pkey]['label'] ?? $pkey)]), $body, ' wc-card--wide');
}
$tab_alert = ''.$robotCard.$thresholdCard.$strategyCard.$previewCard.'
';
/* ======================== TAB 2: OPTIMIZATION ========================= */
// -- tuning --
$tuneOpts = '';
foreach (['small', 'medium', 'large'] as $pk) {
$tuneOpts .= '';
}
$tuneBody =
''.$t('lbl.tuning_hint').'
'
.''
.''.$t('tuning.env').'
'
.''.$e($data['tuning']['env']).'
'
.''.$t('tuning.cmd').'
'
.''.$e($data['tuning']['cmd']).'
';
$tuningCard = $card('⚙️', $t('sec.tuning'), $tuneBody, ' wc-card--wide');
// -- template import --
$tplOpts = '';
if (!$data['templates']) {
$tplOpts = '';
}
foreach ($data['templates'] as $tf) {
$tplOpts .= '';
}
$importBody =
''.$t('lbl.template_hint').'
'
.'';
$importCard = $card('📦', $t('sec.template'), $importBody);
// -- map --
if ($data['server_host']) {
$mapBody =
''.$t('map.hint').'
'
.'';
}
else {
$mapBody = ''.$t('msg.no_server_host').'
';
}
$mapCard = $card('🗺️', $t('sec.map'), $mapBody);
// -- template switch --
$srcOpts = '';
$dstOpts = '';
foreach ($data['huawei_tpls'] as $tp) {
$selS = ((string) $data['switch_src'] === (string) $tp['templateid']) ? ' selected' : '';
$selD = ((string) $data['switch_dst'] === (string) $tp['templateid']) ? ' selected' : '';
$srcOpts .= '';
$dstOpts .= '';
}
$switchBody =
''.$t('lbl.switch_hint').'
'
.'';
if ($data['switch_preview'] !== null) {
$sp = $data['switch_preview'];
if ((int) $sp['count'] === 0) {
$switchBody .= ''.$t('switch.none', [$sp['src_name']]).'
';
}
else {
$chips = '';
foreach ($sp['hosts'] as $hn) {
$chips .= ''.$e($hn).'';
}
$switchBody .= ''
.''.$t('switch.result', [$sp['count'], $sp['src_name'], $sp['dst_name']]).'
'
.''.$chips.'
'
.'';
}
}
$switchCard = $card('🔁', $t('sec.switch'), $switchBody, ' wc-card--wide');
$tab_opt = ''.$tuningCard.$importCard.$mapCard.$switchCard.'
';
/* ======================== TAB 3: MAINTENANCE ========================== */
$searchBody =
''.$t('lbl.trig_hint', [$data['trigger_count']]).'
'
.'';
$maintBody = $searchBody;
if ($data['trig_search'] !== '') {
if ($data['triggers']) {
$ids = [];
$list = '';
foreach ($data['triggers'] as $tg) {
$ids[] = $tg['triggerid'];
$host = !empty($tg['hosts']) ? $tg['hosts'][0]['host'] : '';
$sev = ((int) $tg['priority']) + 1;
$chk = ((int) $tg['status'] === 0) ? ' checked' : '';
$list .= '';
}
$maintBody .= ''
.'';
}
else {
$maintBody .= ''.$t('msg.no_trig_search').'
';
}
}
$tab_maint = ''.$card('🔧', $t('sec.triggers'), $maintBody, ' wc-card--wide').'
';
/* ============================ assemble =============================== */
$hero = ''.$t('page.title').'
'
.'
'.$t('hero.sub').'
';
$tabbar = '';
$content = ($active_tab === 'opt') ? $tab_opt : (($active_tab === 'maint') ? $tab_maint : $tab_alert);
$html_page->addItem($raw(''.$hero.$tabbar.$content.'
'));
$html_page->show();