1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22if ($data['uncheck']) { 23 uncheckTableRows(); 24} 25 26$widget = (new CWidget()) 27 ->setTitle(_('Media types')) 28 ->setControls((new CForm()) 29 ->cleanItems() 30 ->addItem((new CList())->addItem(new CRedirectButton(_('Create media type'), 'zabbix.php?action=mediatype.edit'))) 31 ); 32 33// create form 34$mediaTypeForm = (new CForm())->setName('mediaTypesForm'); 35 36// create table 37$mediaTypeTable = (new CTableInfo()) 38 ->setHeader([ 39 (new CColHeader( 40 (new CCheckBox('all_media_types')) 41 ->onClick("checkAll('".$mediaTypeForm->getName()."', 'all_media_types', 'mediatypeids');") 42 ))->addClass(ZBX_STYLE_CELL_WIDTH), 43 make_sorting_header(_('Name'), 'description', $data['sort'], $data['sortorder']), 44 make_sorting_header(_('Type'), 'type', $data['sort'], $data['sortorder']), 45 _('Status'), 46 _('Used in actions'), 47 _('Details') 48 ]); 49 50foreach ($data['mediatypes'] as $mediaType) { 51 switch ($mediaType['typeid']) { 52 case MEDIA_TYPE_EMAIL: 53 $details = 54 _('SMTP server').NAME_DELIMITER.'"'.$mediaType['smtp_server'].'", '. 55 _('SMTP helo').NAME_DELIMITER.'"'.$mediaType['smtp_helo'].'", '. 56 _('SMTP email').NAME_DELIMITER.'"'.$mediaType['smtp_email'].'"'; 57 break; 58 59 case MEDIA_TYPE_EXEC: 60 $details = _('Script name').NAME_DELIMITER.'"'.$mediaType['exec_path'].'"'; 61 break; 62 63 case MEDIA_TYPE_SMS: 64 $details = _('GSM modem').NAME_DELIMITER.'"'.$mediaType['gsm_modem'].'"'; 65 break; 66 67 case MEDIA_TYPE_JABBER: 68 $details = _('Jabber identifier').NAME_DELIMITER.'"'.$mediaType['username'].'"'; 69 break; 70 71 case MEDIA_TYPE_EZ_TEXTING: 72 $details = _('Username').NAME_DELIMITER.'"'.$mediaType['username'].'"'; 73 break; 74 75 default: 76 $details = ''; 77 break; 78 } 79 80 // action list 81 $actionLinks = []; 82 if (!empty($mediaType['listOfActions'])) { 83 foreach ($mediaType['listOfActions'] as $action) { 84 $actionLinks[] = new CLink($action['name'], 'actionconf.php?form=update&actionid='.$action['actionid']); 85 $actionLinks[] = ', '; 86 } 87 array_pop($actionLinks); 88 } 89 else { 90 $actionLinks = ''; 91 } 92 $actionColumn = new CCol($actionLinks); 93 $actionColumn->setAttribute('style', 'white-space: normal;'); 94 95 $statusLink = 'zabbix.php'. 96 '?action='.($mediaType['status'] == MEDIA_TYPE_STATUS_DISABLED 97 ? 'mediatype.enable' 98 : 'mediatype.disable' 99 ). 100 '&mediatypeids[]='.$mediaType['mediatypeid']; 101 102 $status = (MEDIA_TYPE_STATUS_ACTIVE == $mediaType['status']) 103 ? (new CLink(_('Enabled'), $statusLink)) 104 ->addClass(ZBX_STYLE_LINK_ACTION) 105 ->addClass(ZBX_STYLE_GREEN) 106 ->addSID() 107 : (new CLink(_('Disabled'), $statusLink)) 108 ->addClass(ZBX_STYLE_LINK_ACTION) 109 ->addClass(ZBX_STYLE_RED) 110 ->addSID(); 111 112 $name = new CLink($mediaType['description'], '?action=mediatype.edit&mediatypeid='.$mediaType['mediatypeid']); 113 114 // append row 115 $mediaTypeTable->addRow([ 116 new CCheckBox('mediatypeids['.$mediaType['mediatypeid'].']', $mediaType['mediatypeid']), 117 (new CCol($name))->addClass(ZBX_STYLE_NOWRAP), 118 media_type2str($mediaType['typeid']), 119 $status, 120 $actionColumn, 121 $details 122 ]); 123} 124 125// append table to form 126$mediaTypeForm->addItem([ 127 $mediaTypeTable, 128 $data['paging'], 129 new CActionButtonList('action', 'mediatypeids', [ 130 'mediatype.enable' => ['name' => _('Enable'), 'confirm' => _('Enable selected media types?')], 131 'mediatype.disable' => ['name' => _('Disable'), 'confirm' => _('Disable selected media types?')], 132 'mediatype.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected media types?')] 133 ]) 134]); 135 136// append form to widget 137$widget->addItem($mediaTypeForm)->show(); 138