'; } else if ( file_exists("skins/$skin/css/$css/graphics/favicon.ico") ) { echo " "; } else { echo ' '; } echo output_link_if_exists(array('fonts/material-icons.woff2'), false, $param = ['global', 'preload', ' as="font" type="font/woff2" crossorigin']); //echo output_link_if_exists(array('fonts/material-icons.woff'), false, $param = ['global', 'preload', ' as="font" type="font/woff" crossorigin']); echo output_link_if_exists(array('css/base/material-icons.css'), false); echo output_link_if_exists(array('fonts/fontawesome-webfont.woff2?v=4.7.0'), false, $param = ['global', 'preload font', ' as="font" type="font/woff2" crossorigin']); echo output_script_if_exists(array( 'js/fontfaceobserver.standalone.js', )); ?> '; } // end function xhtmlHeaders( $file, $title ) // True when the monitor filter panel should be shown inline (at the top of the // view) with its own toggle icon, rather than embedded in the left sidebar. // The sidebar can only be used when the navbar is on the left; without a left // navbar there is nothing to embed into, so filters are always inline. The // effective navbar position is the request/cookie/session value resolved into // the global $navbar_type by index.php, not the ZM_WEB_NAVBAR_TYPE default, so // the user's live choice is honoured. This mirrors the panel relocation // condition in skin.js, which uses the same value. function filterSettingsInline() { global $navbar_type; if ($navbar_type != 'left') return true; return defined('ZM_WEB_FILTER_SETTINGS_POSITION') && ZM_WEB_FILTER_SETTINGS_POSITION == 'inline'; } // Outputs an opening body tag, and any additional content that should go at the very top, like warnings and error messages. function getBodyTopHTML() { global $view; //Needed for more flexible global governance $classes = $view.'-page'; if (defined('ZM_WEB_NAVBAR_STICKY') and ZM_WEB_NAVBAR_STICKY) $classes .= ' sticky'; if (filterSettingsInline()) $classes .= ' filter-inline'; if (defined('ZM_WEB_BUTTON_STYLE') and ZM_WEB_BUTTON_STYLE == 'icons') $classes .= ' btn-icons-only'; else if (defined('ZM_WEB_BUTTON_STYLE') and ZM_WEB_BUTTON_STYLE == 'text') $classes .= ' btn-text-only'; if (defined('ZM_WEB_SHOW_NAV_BUTTONS') and !ZM_WEB_SHOW_NAV_BUTTONS) $classes .= ' hide-nav-buttons'; $classHTML = ' class="'.$classes.'"'; echo ' '; global $error_message; if ( $error_message ) { echo '
'.$error_message.'
'; } global $navbar_type; if ($navbar_type == 'left') { getSidebarTopHTML(); } } // end function getBodyTopHTML // Map view names to Menu_Items MenuKey values function getViewMenuKeyMap() { return array( 'console' => 'Console', 'montage' => 'Montage', 'montagereview' => 'MontageReview', 'events' => 'Events', 'options' => 'Options', 'log' => 'Log', 'devices' => 'Devices', 'intelgpu' => 'IntelGpu', 'quadra' => 'Quadra', 'groups' => 'Groups', 'filter' => 'Filters', 'snapshots' => 'Snapshots', 'reports' => 'Reports', 'report_event_audit' => 'ReportEventAudit', 'map' => 'Map', ); } // Map a MenuKey to the href the built-in menu builders use for it. function getMenuKeyHrefMap() { static $map = null; if ($map === null) { $map = array(); foreach (getViewMenuKeyMap() as $viewName => $menuKey) { $map[$menuKey] = '?view='.$viewName; } // Built-in items not covered by the view map / needing extra params. $map['Watch'] = '?view=watch&cycle=true'; } return $map; } // The link a menu item resolves to. Uses the explicit Link when set, // otherwise applies the same ?view= rule as the built-in items: known // MenuKeys use their built-in href, custom keys become ?view=. function menuItemEffectiveLink($item) { $link = $item->Link(); if ($link !== null && $link !== '') return $link; $map = getMenuKeyHrefMap(); $key = $item->MenuKey(); return isset($map[$key]) ? $map[$key] : '?view='.$key; } function renderMenuIcon($icon, $iconType = 'material') { if ($iconType == 'none') { return ''; } else if ($iconType == 'fontawesome') { return ''; } else if ($iconType == 'image') { return ''; } return ''.htmlspecialchars($icon).''; } // Returns icon HTML from the current $menuIconOverride, or empty string if not set function getNavbarIcon() { global $menuIconOverride; if (!isset($menuIconOverride)) return ''; $html = renderMenuIcon($menuIconOverride['icon'], $menuIconOverride['iconType']); if ($html !== '') $html .= ' '; return $html; } function buildMenuItem($viewItemName, $id, $itemName, $href, $icon, $classNameForTag_A = '', $subMenu = '', $skipTranslate = false, $iconType = 'material') { global $view; global $menuIconOverride; // Check for icon override from renderMenuItems if (isset($menuIconOverride)) { $icon = $menuIconOverride['icon']; $iconType = $menuIconOverride['iconType']; } /* Highlighting the active menu section */ if ($viewItemName == 'watch') { $activeClass = ($view == $viewItemName && (isset($_REQUEST['cycle']) && $_REQUEST['cycle'] == "true")) ? ' active' : ''; } else { $activeClass = $view == $viewItemName ? ' active' : ''; } if (!$skipTranslate) $itemName = translate($itemName); // Escape the attribute values here rather than trust every caller to. An // entity a caller already wrote (&) is kept as it is, so a pre-escaped // href is not escaped twice. $id = htmlspecialchars((string)$id, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', false); $href = htmlspecialchars((string)$href, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', false); $classNameForTag_A = htmlspecialchars((string)$classNameForTag_A, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', false); $result = ' '.PHP_EOL; return $result; } function getMenuItemFunctions() { return [ 'Console' => 'getConsoleHTML', 'Watch' => 'getCycleHTML', 'Montage' => 'getMontageHTML', 'MontageReview' => 'getMontageReviewHTML', 'Events' => 'getEventsHTML', 'Options' => 'getOptionsHTML', 'Log' => 'getLogHTML', 'Devices' => 'getDevicesHTML', 'IntelGpu' => 'getIntelGpuHTML', 'Groups' => 'getGroupsHTML', 'Filters' => 'getFilterHTML', 'Snapshots' => 'getSnapshotsHTML', 'Reports' => 'getReportsHTML', 'ReportEventAudit' => 'getRprtEvntAuditHTML', 'Map' => 'getMapHTML', ]; } function getMenuItems() { static $cached = null; if ($cached === null) { require_once('includes/MenuItem.php'); $cached = ZM\MenuItem::find([], ['order' => 'SortOrder ASC']); } return $cached; } // Functions that take only ($forLeftBar, $customLabel) - no $view parameter function getMenuFuncsNoView() { return ['getConsoleHTML', 'getOptionsHTML', 'getLogHTML', 'getDevicesHTML', 'getIntelGpuHTML']; } function renderMenuItems($forLeftBar = false) { global $view; $menuItems = getMenuItems(); $funcMap = getMenuItemFunctions(); $result = ''; if (empty($menuItems)) { // Fallback: no DB rows yet, render all in default order foreach ($funcMap as $key => $funcName) { $noViewFuncs = getMenuFuncsNoView(); if (in_array($funcName, $noViewFuncs)) { $result .= $funcName($forLeftBar); } else { $result .= $funcName($view, $forLeftBar); } } } else { global $menuIconOverride; $noViewFuncs = getMenuFuncsNoView(); foreach ($menuItems as $item) { if (!$item->Enabled()) continue; $key = $item->MenuKey(); if (!isset($funcMap[$key])) { // Custom entry: link to its explicit Link, or fall back to the same // ?view= rule the built-in items use. $link = menuItemEffectiveLink($item); $menuIconOverride = ['icon' => $item->effectiveIcon(), 'iconType' => $item->effectiveIconType()]; $result .= buildMenuItem( 'customMenu-'.$item->Id(), 'menuItem-custom-'.$item->Id(), $item->displayLabel(), htmlspecialchars($link), $item->effectiveIcon(), '', '', true, $item->effectiveIconType() ); $menuIconOverride = null; continue; } $funcName = $funcMap[$key]; $customLabel = ($item->Label() !== null && $item->Label() !== '') ? $item->displayLabel() : null; // Set icon override for buildMenuItem/getOptionsHTML to pick up $effIcon = $item->effectiveIcon(); $effIconType = $item->effectiveIconType(); $menuIconOverride = ['icon' => $effIcon, 'iconType' => $effIconType]; if (in_array($funcName, $noViewFuncs)) { $result .= $funcName($forLeftBar, $customLabel); } else { $result .= $funcName($view, $forLeftBar, $customLabel); } } $menuIconOverride = null; } $result .= getAdditionalLinksHTML($view, $forLeftBar); return $result; } function buildSidebarMenu() { global $view; global $user; if ( $user and $user->Username() ) { $menuForAuthUser = renderMenuItems($forLeftBar = true) ; } else { // USER IS NOT AUTHORIZED! $menuForAuthUser = ''; } $menu = ' '; return $menu; } function getSidebarTopHTML() { global $skin; global $user; global $running; $blockExtruder = '
'; $block = '
'; echo $block; } // end function getSidebarTopHTML function getSidebarBottomHTML() { global $skin; $block = ''; if (defined('ZM_SIDEBAR_FOOTER') and ZM_SIDEBAR_FOOTER) { $block .= ZM_SIDEBAR_FOOTER; } $block .= '
'; echo $block; } // end function getSidebarBottomHTML function getNavBarHTML() { # Provide a facility to turn off the headers if you put navbar=0 into the url if ( isset($_REQUEST['navbar']) and $_REQUEST['navbar'] == '0' ) return ''; global $running; global $user; global $bandwidth_options; global $view; global $skin; global $navbar_type; ob_start(); if ( $navbar_type == 'normal' || $navbar_type == 'left') { echo getNormalNavBarHTML($running, $user, $bandwidth_options, $view, $skin); } else { echo getCollapsedNavBarHTML($running, $user, $bandwidth_options, $view, $skin); } return ob_get_clean(); } function output_link($files) { foreach ( $files as $file ) { $html[] = ''; } $html[] = ''; // So we ge a trailing \n return implode(PHP_EOL, $html); } function output_link_if_exists($files, $cache_bust=true, $param=false) { global $skin; $html = array(); if ($param) { $global_file = $param[0]; // The file is global or from a skin $rel = '"'.$param[1].'"'; $suffix = $param[2]; } else { $global_file = false; $rel = '"stylesheet"'; $suffix = ' type="text/css"'; } foreach ( $files as $file ) { // The file name can be for example "fontawesome-webfont.woff2?v=4.7.0". We need to select what is before the "?" $file_ = ($global_file && file_exists(explode('?', $file)[0])) ? $file : getSkinFile($file); if ($file_) { if ( $cache_bust ) { $html[] = ''; } else { $html[] = ''; } } } $html[] = ''; // So we ge a trailing \n return implode(PHP_EOL, $html); } function output_script($files, $cache_bust=true, $must_exist=true) { global $skin; $html = array(); if (!is_array($files)) $files = [$files]; foreach ( $files as $file ) { $found = false; if ( file_exists('skins/'.$skin.'/'.$file) ) { $found = true; if ( $cache_bust ) { $html[] = ''; } else { $html[] = ''; } } else if ( file_exists($file) ) { $found = true; if ( $cache_bust ) { $html[] = ''; } else { $html[] = ''; } } if (!$found and $must_exist) { ZM\Error("Script $file not found"); } } $html[] = ''; // So we ge a trailing \n return implode(PHP_EOL, $html); } function output_script_if_exists($files, $cache_bust=true) { return output_script($files, $cache_bust, false); } function output_cache_busted_stylesheet_links($files) { $html = array(); foreach ( $files as $file ) { $html[] = ''; } if ( ! count($html) ) { ZM\Warning("No files found for $files"); } $html[] = ''; // So we ge a trailing \n return implode(PHP_EOL, $html); } // // The legacy navigation bar that collapses into a pulldown menu on small screens. // function getNormalNavBarHTML($running, $user, $bandwidth_options, $view, $skin) { $status = runtimeStatus($running); ?> menu '; } $block .= '
'. ((!defined('ZM_WEB_SHOW_SERVER_STATS') or ZM_WEB_SHOW_SERVER_STATS) ? '' : '') .'
'; return $block; } // // A new, slimmer navigation bar, permanently collapsed into a dropdown // function getCollapsedNavBarHTML($running, $user, $bandwidth_options, $view, $skin) { $status = runtimeStatus($running); ?> ReadStats(); $result .= ''.PHP_EOL; } return $result; } // Returns the html representing the current unix style system load function getSysLoadHTML() { $result = ''; if ( !canView('System') ) return $result; global $thisServer; if ($thisServer) { $thisServer->ReadStats(); $result .= ''.PHP_EOL; } return $result; } // Returns the html representing the current number of connections made to the database function getDbConHTML() { $result = ''; if ( !canView('System') ) return $result; $connections = dbFetchOne('SHOW status WHERE variable_name=\'threads_connected\'', 'Value'); $max_connections = dbFetchOne('SHOW variables WHERE variable_name=\'max_connections\'', 'Value'); $percent_used = $max_connections ? 100 * $connections / $max_connections : 100; $class = ( $percent_used > 90 ) ? ' text-warning' : ''; $result .= ''.PHP_EOL; return $result; } // Returns an html dropdown showing capacity of all storage areas function getStorageHTML() { $result = ''; if ( !canView('System') ) return $result; $func = function($S, $class='') { if ( $S->disk_usage_percent() > 98 ) { $class .= 'text-danger'; } else if ( $S->disk_usage_percent() > 95 ) { $class .= 'text-warning'; } $title = human_filesize($S->disk_used_space()) . ' of ' . human_filesize($S->disk_total_space()). ( ( $S->disk_used_space() != $S->event_disk_space() ) ? ' ' .human_filesize($S->event_disk_space()) . ' used by events' : '' ); return ''.validHtmlStr($S->Name()) . ': ' . $S->disk_usage_percent().'%' . ''; }; $storage_areas = ZM\Storage::find(array('Enabled'=>true)); $num_storage_areas = count($storage_areas); $full_warning = 0; $full_error = 0; foreach ( $storage_areas as $area ) { if ( $area->disk_usage_percent() > 98 ) { $full_error++; continue; } if ( $area->disk_usage_percent() > 95 ) $full_warning++; } $class = ''; if ( $full_error ) { $class = 'text-danger'; } else if ( $full_warning ) { $class = 'text-warning'; } if (count($storage_areas) <= 2) { $result .= ''.PHP_EOL; } else { $result .= ''.PHP_EOL; } return $result; } function getRamHTML() { $result = ''; if ( !canView('System') ) return $result; if (file_exists('/proc') && file_exists('/proc/meminfo')) { $contents = file_get_contents('/proc/meminfo'); preg_match_all('/(\w+):\s+(\d+)\s/', $contents, $matches); $meminfo = array_combine($matches[1], array_map(function($v){return 1024*$v;}, $matches[2])); if (!isset($meminfo['MemTotal'])) { ZM\Debug(print_r($meminfo, true)); return ''; } $mem_used = $meminfo['MemTotal'] - $meminfo['MemFree'] - $meminfo['Buffers'] - $meminfo['Cached']; $mem_used_percent = $meminfo['MemTotal'] ? (int)(100*$mem_used/$meminfo['MemTotal']) : 0; $used_class = ''; if ($mem_used_percent > 95) { $used_class = 'text-danger'; } else if ($mem_used_percent > 90) { $used_class = 'text-warning'; } $result .= ' '.PHP_EOL; } return $result; } // Returns the html representing the current capacity of mapped memory filesystem (usually /dev/shm) function getShmHTML() { $result = ''; if ( !canView('System') ) return $result; $shm_percent = getDiskPercent(ZM_PATH_MAP); $shm_total_space = disk_total_space(ZM_PATH_MAP); $shm_used = $shm_total_space - disk_free_space(ZM_PATH_MAP); $class = ''; if ( $shm_percent > 98 ) { $class = 'text-danger'; } else if ( $shm_percent > 90 ) { $class = 'text-warning'; } $result .= ' '.PHP_EOL; return $result; } // Returns the html representing the optional web console banner text function getConsoleBannerHTML() { $result = ''; if ( defined('ZM_WEB_CONSOLE_BANNER') and ZM_WEB_CONSOLE_BANNER != '' ) { $result .= ''; } return $result; } // Returns the html representing the current high,medium,low bandwidth setting function getBandwidthHTML($bandwidth_options, $user) { # Limit available options to what are available in user if ( $user && !empty($user->MaxBandwidth()) ) { if ( $user->MaxBandwidth() == 'low' ) { unset($bandwidth_options['high']); unset($bandwidth_options['medium']); } else if ( $user->MaxBandwidth() == 'medium' ) { unset($bandwidth_options['high']); } } $result = ''; if (count($bandwidth_options) > 1) { $result .= ''.PHP_EOL; } return $result; } // Returns the html representing the version of ZoneMinder function getZMVersionHTML() { $result = ''; if ( !canView('System') ) return $result; $content = ''; if ( ZM_DYN_DB_VERSION && (ZM_DYN_DB_VERSION != ZM_VERSION) ) { // Must upgrade before proceeding $class = 'text-danger'; $tt_text = translate('RunLocalUpdate'); $content = 'v'.ZM_VERSION.PHP_EOL; } else if ( verNum( ZM_DYN_LAST_VERSION ) <= verNum( ZM_VERSION ) || verNum( ZM_DYN_LAST_VERSION ) <= verNum( ZM_DYN_CURR_VERSION ) || !ZM_CHECK_FOR_UPDATES || ZM_DYN_NEXT_REMINDER > time() ) { // No update needed $class = ''; // Don't change the text color under normal conditions $tt_text = translate('UpdateNotNecessary'); $content = 'v'.ZM_VERSION.PHP_EOL; } else if ( canEdit('System') ) { // An update is available and the user is an administrator $class = 'text-warning'; $tt_text = translate('UpdateAvailable'); $content = 'v' .ZM_VERSION. ''.PHP_EOL; $content .= ''.PHP_EOL; } else { // An update is available and the user is NOT an administrator $class = 'text-warning'; $tt_text = translate('UpdateAvailable'); $content = 'v'.ZM_VERSION.PHP_EOL; } $result .= ''.PHP_EOL; return $result; } // Returns the html representing the ZoneMinder logo and about menu function getNavBrandHTML() { $result = ''; if ( ZM_HOME_ABOUT ) { $result .= 'ZoneMinder'.PHP_EOL; $result .= ''.PHP_EOL; } else { $result .= '' .ZM_HOME_CONTENT. ''.PHP_EOL; } return $result; } // Returns the html representing the Console menu item function getConsoleHTML($forLeftBar = false, $customLabel = null) { global $user; $result = ''; $label = $customLabel !== null ? $customLabel : 'Console'; $skipTranslate = $customLabel !== null; if (count($user->viewableMonitorIds()) or !ZM\Monitor::find_one()) { if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'console', $id = 'getConsoleHTML', $itemName = $label, $href = '?view=console', $icon = 'dashboard', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the Options menu item function getOptionsHTML($forLeftBar = false, $customLabel = null) { global $zmMenu; $result = ''; $label = $customLabel !== null ? $customLabel : translate('Options'); // Sorting order of the "Options" submenu items. If a submenu item is in the DB but is not here, it will be automatically added to the end of the list. $categoryDisplayOrder = [ 'display', 'system', 'auth', 'config', ]; if (defined('ZM_PATH_DNSMASQ_CONF') and ZM_PATH_DNSMASQ_CONF) { $categoryDisplayOrder[] = 'dnsmasq'; } $categoryDisplayOrder = array_merge($categoryDisplayOrder, [ 'API', 'servers', 'storage', 'web', 'images', 'logging', 'network', 'mail', 'upload', ]); if (defined('ZM_OPT_X10') and ZM_OPT_X10) { $categoryDisplayOrder[] = 'x10'; } $categoryDisplayOrder = array_merge($categoryDisplayOrder, [ 'highband', 'medband', 'lowband', 'users', 'roles', 'groups', 'control', 'encoderTemplates', 'privacy', 'MQTT', 'telemetry', 'version', 'menu' ]); $zmMenu::buildSubMenuOptions($categoryDisplayOrder); // AI object-detection management tabs. These are not Config categories, so // register them explicitly with readable labels instead of the auto-generated // "Ai_datasets" style names. if ( canView('System') ) { $zmMenu::$submenuOptionsItems['cron'] = translate('ScheduledTasks'); $zmMenu::$submenuOptionsItems['ai_datasets'] = translate('AI Datasets'); $zmMenu::$submenuOptionsItems['ai_models'] = translate('AI Models'); $zmMenu::$submenuOptionsItems['ai_classes'] = translate('AI Classes'); } if ( canView('System') ) { if ($forLeftBar) { global $view; //$tab = isset($_REQUEST['tab']) ? validHtmlStr($_REQUEST['tab']) : 'system'; $tab = isset($_REQUEST['tab']) ? validHtmlStr($_REQUEST['tab']) : ''; $subMenuOptions = ' '; global $menuIconOverride; $optIcon = 'settings'; $optIconType = 'material'; if (isset($menuIconOverride)) { $optIcon = $menuIconOverride['icon']; $optIconType = $menuIconOverride['iconType']; } $result .= ' '.PHP_EOL; } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the Log menu item function getLogHTML($forLeftBar = false, $customLabel = null) { $result = ''; $label = $customLabel !== null ? $customLabel : 'Log'; $skipTranslate = $customLabel !== null; if ( canView('System') ) { if ( ZM\logToDatabase() > ZM\Logger::NOLOG ) { $logstate = logState(); $class = ($logstate == 'ok') ? 'text-success' : ($logstate == 'alert' ? 'text-warning' : (($logstate == 'alarm' ? 'text-danger' : ''))); if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'log', $id = 'getLogHTML', $itemName = $label, $href = '?view=log', $icon = 'notification_important', $classNameForTag_A = $class, $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } } return $result; } // Returns the html representing the log icon function getLogIconHTML() { $result = ''; if ( canView('System') ) { if ( ZM\logToDatabase() > ZM\Logger::NOLOG ) { $logstate = logState(); $class = ($logstate == 'ok') ? 'text-success' : ($logstate == 'alert' ? 'text-warning' : (($logstate == 'alarm' ? 'text-danger' : ''))); $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the X10 Devices menu item function getDevicesHTML($forLeftBar = false, $customLabel = null) { $result = ''; $label = $customLabel !== null ? $customLabel : 'Devices'; $skipTranslate = $customLabel !== null; if ( ZM_OPT_X10 && canView('Devices') ) { if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'devices', $id = 'getDevicesHTML', $itemName = $label, $href = '?view=devices', $icon = 'devices_other', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the Intel GPU status menu item function getIntelGpuHTML($forLeftBar = false, $customLabel = null) { $result = ''; $label = $customLabel !== null ? $customLabel : 'Intel GPU'; $skipTranslate = $customLabel !== null; // Only show if intel_gpu_top is available and user can view System if (canView('System')) { // Check if intel_gpu_top command exists $intel_gpu_top_exists = shell_exec('which intel_gpu_top 2>/dev/null'); if ($intel_gpu_top_exists) { if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'intelgpu', $id = 'getIntelGpuHTML', $itemName = $label, $href = '?view=intelgpu', $icon = 'memory', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } } return $result; } // Returns the html representing the Groups menu item function getGroupsHTML($view, $forLeftBar = false, $customLabel = null) { $result = ''; if ( !canView('Groups') ) return $result; $label = $customLabel !== null ? $customLabel : 'Groups'; $skipTranslate = $customLabel !== null; $class = $view == 'groups' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'groups', $id = 'getGroupsHTML', $itemName = $label, $href = '?view=groups', $icon = 'group', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } return $result; } // Returns the html representing the Filter menu item function getFilterHTML($view, $forLeftBar = false, $customLabel = null) { $result = ''; if ( !canView('Events') ) return $result; $label = $customLabel !== null ? $customLabel : 'Filters'; $skipTranslate = $customLabel !== null; $class = $view == 'filter' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'filter', $id = 'getFilterHTML', $itemName = $label, $href = '?view=filter', $icon = 'filter_alt', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } return $result; } // Returns the html representing the Cycle menu item (Watch view in cycle mode) function getCycleHTML($view, $forLeftBar = false, $customLabel = null) { $result = ''; if ( !canView('Stream') ) return $result; $label = $customLabel !== null ? $customLabel : 'Cycle'; $skipTranslate = $customLabel !== null; $class = $view == 'cycle' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'watch', $id = 'getCycleHTML', $itemName = $label, $href = '?view=watch&cycle=true', $icon = 'repeat', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } return $result; } // Returns the html representing the Montage menu item function getMontageHTML($view, $forLeftBar = false, $customLabel = null) { global $user; $result = ''; $label = $customLabel !== null ? $customLabel : 'Montage'; $skipTranslate = $customLabel !== null; if (canView('Stream') and count($user->viewableMonitorIds())) { $class = $view == 'montage' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'montage', $id = 'getMontageHTML', $itemName = $label, $href = '?view=montage', $icon = 'live_tv', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the MontageReview menu item function getMontageReviewHTML($view, $forLeftBar = false, $customLabel = null) { $result = ''; $label = $customLabel !== null ? $customLabel : 'MontageReview'; $skipTranslate = $customLabel !== null; if ( canView('Events') ) { if ( isset($_REQUEST['filter']['Query']['terms']['attr']) ) { $terms = $_REQUEST['filter']['Query']['terms']; $count = 0; foreach ($terms as $term) { if (!is_array($term) or !isset($term['attr'], $term['op'], $term['val'])) continue; if ( $term['attr'] == 'StartDateTime' ) { $count += 1; if ($term['op'] == '>=') $minTime = $term['val']; if ($term['op'] == '<=') $maxTime = $term['val']; } } if ( $count == 2 and isset($minTime, $maxTime) and is_string($minTime) and is_string($maxTime) ) { // Request values: encode them for the query string here, the whole href is HTML-escaped below. $montageReviewQuery = '&minTime='.urlencode($minTime).'&maxTime='.urlencode($maxTime); } } $live = isset($montageReviewQuery) ? '&fit=1'.$montageReviewQuery.'&live=0' : ''; $href = validHtmlStr('?view=montagereview'.$live); $class = $view == 'montagereview' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'montagereview', $id = 'getMontageReviewHTML', $itemName = $label, $href, $icon = 'movie', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the Montage menu item function getSnapshotsHTML($view, $forLeftBar = false, $customLabel = null) { $result = ''; $label = $customLabel !== null ? $customLabel : 'Snapshots'; $skipTranslate = $customLabel !== null; if (defined('ZM_FEATURES_SNAPSHOTS') and ZM_FEATURES_SNAPSHOTS and canView('Snapshots')) { $class = $view == 'snapshots' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'snapshots', $id = 'getSnapshotsHTML', $itemName = $label, $href = '?view=snapshots', $icon = 'preview', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the Events menu item function getEventsHTML($view, $forLeftBar = false, $customLabel = null) { global $user; $result = ''; $label = $customLabel !== null ? $customLabel : 'Events'; $skipTranslate = $customLabel !== null; if (canView('Events')) { $class = $view == 'events' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'events', $id = 'getEventsHTML', $itemName = $label, $href = '?view=events', $icon = 'event', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } function getReportsHTML($view, $forLeftBar = false, $customLabel = null) { $result = ''; $label = $customLabel !== null ? $customLabel : 'Reports'; $skipTranslate = $customLabel !== null; if (canView('Events')) { $class = ($view == 'reports' or $view == 'report') ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'reports', $id = 'getReportsHTML', $itemName = $label, $href = '?view=reports', $icon = 'report', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the Audit Events Report menu item function getRprtEvntAuditHTML($view, $forLeftBar = false, $customLabel = null) { $result = ''; $label = $customLabel !== null ? $customLabel : 'ReportEventAudit'; $skipTranslate = $customLabel !== null; if ( canView('Events') ) { $class = $view == 'report_event_audit' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'report_event_audit', $id = 'getRprtEvntAuditHTML', $itemName = $label, $href = '?view=report_event_audit', $icon = 'shield', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the Audit Events Report menu item function getMapHTML($view, $forLeftBar = false, $customLabel = null) { $result = ''; $label = $customLabel !== null ? $customLabel : 'Map'; $skipTranslate = $customLabel !== null; if (defined('ZM_OPT_USE_GEOLOCATION') and ZM_OPT_USE_GEOLOCATION) { $class = $view == 'map' ? ' selected' : ''; if ($forLeftBar) { $result .= buildMenuItem( $viewItemName = 'map', $id = 'getMapHTML', $itemName = $label, $href = '?view=map', $icon = 'language', $classNameForTag_A = '', $subMenu = '', $skipTranslate ); } else { $result .= ''.PHP_EOL; } } return $result; } // Returns the html representing the content of the ZM_WEB_NAVBAR_LINKS content function getAdditionalLinksHTML($view, $forLeftBar = false) { $result = ''; if (defined('ZM_WEB_NAVBAR_LINKS')) { if (ZM_WEB_NAVBAR_LINKS) { foreach (explode(',', ZM_WEB_NAVBAR_LINKS) as $link) { if ($forLeftBar) { $doc = new DomDocument(); fixAmps($link); $doc->loadHTML('' . $link); $url = $doc->getElementsByTagName('a')[0]; $value_ = translate('Error in link string: "') . htmlspecialchars($link) . '"'; $href_ = ''; $icon_ = ''; $class_ = ''; $queryView = ''; if ($url) { $value_ = $url->nodeValue; $href_ = $url->getAttribute( 'href' ); $icon_ = $url->getAttribute('data-icon'); $class_ = $url->getAttribute('class'); $parts = parse_url($href_); if (isset($parts['query'])) { parse_str($parts['query'], $query); if (isset($query['view'])) $queryView = $query['view']; } } $result .= buildMenuItem( $viewItemName = $queryView, $id = '', $itemName = $value_, $href = $href_, $icon = $icon_, $classNameForTag_A = $class_, $subMenu = '' ); } else { $result .= ''.PHP_EOL; } } } } return $result; } // Returns the html representing the header collapse toggle menu item function getHeaderFlipHTML() { $result = ''; $header = ( isset($_COOKIE['zmHeaderFlip']) and $_COOKIE['zmHeaderFlip'] == 'down') ? 'down' : 'up'; $result .= ''.PHP_EOL; return $result; } // Returns the html representing the logged in user name and avatar function getAccountCircleHTML($skin, $user=null, $forLeftBar = false) { $result = ''; if ( ZM_OPT_USE_AUTH and $user ) { $result .= ''.PHP_EOL; } return $result; } // Returns the html representing the runtime status button function getStatusBtnHTML($status) { $result = ''; if (canEdit('System')) { $result .= '
  • '.PHP_EOL; $result .= ''.PHP_EOL; $result .= '
  • '.PHP_EOL; if (ZM_SYSTEM_SHUTDOWN) { $result .= '
  • '.PHP_EOL; $result .= ''.PHP_EOL; $result .= '
  • '.PHP_EOL; } } else if (canView('System')) { $result .= ''.PHP_EOL; } return $result; } function runtimeStatus($running=null) { if ( $running == null ) $running = daemonCheck(); if ( $running ) { $state = dbFetchOne('SELECT Name FROM States WHERE isActive=1', 'Name'); if ( $state == 'default' ) $state = ''; } return $running ? ($state ? $state : translate('Running')) : translate('Stopped'); } function getStatsTableHTML($eid, $fid, $row='') { if ( !canView('Events') ) return; $result = ''; $sql = 'SELECT S.*,E.*,Z.Name AS ZoneName,Z.Units,Z.Area,Z.Coords,M.Name AS MonitorName FROM Stats AS S LEFT JOIN Events AS E ON S.EventId = E.Id LEFT JOIN Zones AS Z ON S.ZoneId = Z.Id LEFT JOIN Monitors AS M ON E.MonitorId = M.Id WHERE S.EventId = ? AND S.FrameId = ? ORDER BY S.ZoneId'; $stats = dbFetchAll( $sql, NULL, array( $eid, $fid ) ); $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; if ( count($stats) ) { foreach ( $stats as $stat ) { // Area is in percentage coordinate space (0-10000 for full frame). // Convert to pixel area for percentage calculations since Stats values are pixel counts. $pixelArea = $stat['Area'] / 10000.0 * $stat['Width'] * $stat['Height']; $pct = function($n) use ($pixelArea) { return $pixelArea > 0 ? sprintf('%d (%d%%)', $n, 100*$n/$pixelArea) : sprintf('%d', $n); }; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; if ( $stat['Blobs'] > 1 ) { if ( $pixelArea > 0 ) { $result .= ''.PHP_EOL; } else { $result .= ''.PHP_EOL; } } else { $result .= ''.PHP_EOL; } $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; $result .= ''.PHP_EOL; } } else { $result .= ''.PHP_EOL; //IMPORTANT! There is a problem with Bootstrap here. The class is being moved from '.PHP_EOL; $result .= ''.PHP_EOL; } $result .= ''.PHP_EOL; $result .= '
    ' .translate('Zone'). '' .translate('PixelDiff'). '' .translate('AlarmPx'). '' .translate('FilterPx'). '' .translate('BlobPx'). '' .translate('Blobs'). '' .translate('BlobSizes'). '' .translate('AlarmLimits'). '' .translate('Score'). '
    ' .validHtmlStr($stat['ZoneName']). '' .validHtmlStr($stat['PixelDiff']). '' .$pct($stat['AlarmPixels']). '' .$pct($stat['FilterPixels']).'' .$pct($stat['BlobPixels']). '' .validHtmlStr($stat['Blobs']). '' .sprintf( "%d-%d (%d%%-%d%%)", $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$pixelArea), (100*$stat['MaxBlobSize']/$pixelArea) ). '' .sprintf( "%d-%d", $stat['MinBlobSize'], $stat['MaxBlobSize'] ). '' .$pct($stat['MinBlobSize']). '' .validHtmlStr($stat['MinX'].",".$stat['MinY']."-".$stat['MaxX'].",".$stat['MaxY']). '' .$stat['Score']. '
    and "colspan" is not being applied $result .= '' .translate('NoStatisticsRecorded'). '
    '.PHP_EOL; return $result; } // Use this function to manually insert the csrf key into the form when using a modal generated via ajax call function getCSRFinputHTML() { if ( isset($GLOBALS['csrf']['key']) ) { $result = ''.PHP_EOL; } else { $result = ''; } return $result; } function fixAmps(&$html) { //https://stackoverflow.com/questions/1685277/warning-domdocumentloadhtml-htmlparseentityref-expecting-in-entity // Escape every '&' that does not start a character reference, so that // DOMDocument::loadHTML() does not warn about it. One pass over the string: // the recursive version restarted at the first '&' on every call and never // returned once the string held an entity. $html = preg_replace('/&(?!#[0-9]+;|#x[0-9a-f]+;|[a-z][a-z0-9]*;)/i', '&', $html); } function xhtmlFooter() { global $css; global $cspNonce; global $view; global $skin; global $basename; global $navbar_type; if ($navbar_type == 'left') { getSidebarBottomHTML(); } ?> 'Versions', 'display' => 'ThisSession', 'web' => 'Display', ]; private static function categoryLabel($cat) { return translate(isset(self::$categoryLabels[$cat]) ? self::$categoryLabels[$cat] : mb_ucfirst($cat)); } public function __construct(string $typeMenu, array $menuItems) { } private static function addCategoryToOptionsMenu(array $categoriesOptionsInDB, array $categoryDisplayOrder) { foreach ($categoryDisplayOrder as $cat) { $key = array_search(strtolower($cat), array_map('strtolower', $categoriesOptionsInDB)); $added = false; if ($cat == 'display' && (!defined('ZM_FORCE_CSS_DEFAULT') or !defined('ZM_FORCE_SKIN_DEFAULT'))) { $added = true; } else if ($cat == 'dnsmasq' && (defined('ZM_PATH_DNSMASQ_CONF') and ZM_PATH_DNSMASQ_CONF)) { $added = true; } else { $added = true; } if ($added) { self::$submenuOptionsItems[$cat] = self::categoryLabel($cat); unset($categoriesOptionsInDB[$key]); } } // If not all categories from the database were added (according to the sorted array $categoryDisplayOrder), then add the categories to the end of the "Options" menu if (count($categoriesOptionsInDB)) { foreach ($categoriesOptionsInDB as $cat) { if (!in_array(strtolower($cat), ['dynamic', 'hidden'], $strict = false)) // Prohibited categories self::$submenuOptionsItems[$cat] = self::categoryLabel($cat); } } } public static function buildSubMenuOptions($categoryDisplayOrder) { $categoriesOptionsInDB = []; foreach ( dbFetchAll('SELECT DISTINCT `Category` FROM `Config` ORDER BY lower(`Category`) ASC') as $category_row ) { array_push($categoriesOptionsInDB, $category_row['Category']); } self::addCategoryToOptionsMenu($categoriesOptionsInDB, $categoryDisplayOrder); } } // $typeMenu we are not using it yet. From now on we will specify either 'leftMenu' or 'topMenu' // $menuItems we are not using it yet. These are main menu items with the ability to be customized by the user. $zmMenu = new ZM_Menu($typeMenu = '', $menuItems = [ ]); ?>