/** * Returns full map marks for builds with filled GEO field * * @return string */ function um_MapDrawBuilds() { $ym_conf = rcms_parse_ini_file(CONFIG_PATH . "ymaps.ini"); $query = "SELECT * from `build` WHERE `geo` != '' "; $allbuilds = simple_queryall($query); $allstreets = zb_AddressGetStreetAllData(); $streetData = array(); $cacheDir = 'exports/'; $cacheTime = 10; $cacheTime = time() - $cacheTime * 60; //street id => streetname if (!empty($allstreets)) { foreach ($allstreets as $ia => $eachstreet) { $streetData[$eachstreet['id']] = $eachstreet['streetname']; } } //get apts in all builds aggregated with users logins $aptData = array(); $allapts_q = "SELECT `buildid`,`apt`,`login` from `apt` JOIN `address` ON `apt`.`id`=`address`.`aptid`"; $allapts = simple_queryall($allapts_q); if (!empty($allapts)) { $aptData = $allapts; } //get all user ips $alluserips = zb_UserGetAllIPs(); //form alive ips array $aliveIps = array(); if (file_exists("exports/nmaphostscan")) { $nmapData = file_get_contents("exports/nmaphostscan"); $nmapData = explodeRows($nmapData); if (!empty($nmapData)) { foreach ($nmapData as $ic => $eachnmaphost) { $zhost = zb_ExtractIpAddress($eachnmaphost); if ($zhost) { $aliveIps[$zhost] = $zhost; } } } } $result = ''; if (!empty($allbuilds)) { foreach ($allbuilds as $io => $each) { $geo = mysql_real_escape_string($each['geo']); @($streetname = $streetData[$each['streetid']]); $title = wf_Link("?module=builds&action=editbuild&streetid=" . $each['streetid'] . "&buildid=" . $each['id'], $streetname . ' ' . $each['buildnum'], false); $content = ''; $cells = wf_TableCell(__('apt.')); $cells .= wf_TableCell(__('User')); $cells .= wf_TableCell(__('Status')); $rows = wf_tag('tr', false, '', 'bgcolor=#DCDCDC') . $cells . wf_tag('tr', true); $iconlabel = ''; $footer = ''; $aliveUsers = 0; $usersCount = 0; if (!empty($aptData)) { //build users data caching $cacheName = $cacheDir . $each['id'] . '.inbuildusers'; if (file_exists($cacheName)) { $updateCache = false; if (filemtime($cacheName) > $cacheTime) { $updateCache = false; } else { $updateCache = true; } } else { $updateCache = true; } if (!$updateCache) { $cachePrev = file_get_contents($cacheName); $cachePrev = unserialize($cachePrev); $rows = $cachePrev['rows']; $usersCount = $cachePrev['userscount']; $aliveUsers = $cachePrev['aliveusers']; } else { foreach ($aptData as $ib => $eachapt) { if ($eachapt['buildid'] == $each['id']) { if (isset($alluserips[$eachapt['login']])) { $userIp = $alluserips[$eachapt['login']]; $usersCount++; if (isset($aliveIps[$userIp])) { $aliveFlag = web_bool_led(true); $aliveUsers++; } else { $aliveFlag = web_bool_led(false); } $cells = wf_TableCell($eachapt['apt']); $cells .= wf_TableCell(wf_Link('?module=userprofile&username='******'login'], $userIp, false)); $cells .= wf_TableCell($aliveFlag); $rows .= wf_TableRow($cells); } } } $cacheStore = array(); $cacheStore['rows'] = $rows; $cacheStore['userscount'] = $usersCount; $cacheStore['aliveusers'] = $aliveUsers; $cacheStore = serialize($cacheStore); file_put_contents($cacheName, $cacheStore); } } $footer = __('Active') . ' ' . $aliveUsers . '/' . $usersCount; $icon = um_MapBuildIcon($usersCount); $content = json_encode(wf_TableBody($rows, '', 0)); $title = json_encode($title); $content = str_replace('"', '', $content); $content = str_replace("'", '', $content); $content = str_replace("\n", '', $content); $title = str_replace('"', '', $title); $title = str_replace("'", '', $title); $title = str_replace("\n", '', $title); $result .= sm_MapAddMark($geo, $title, $content, $footer, $icon, $iconlabel, true); } } return $result; }
/** * Renders minimap if long/lat is present * * @global object $ubillingConfig * * @return string */ protected function renderMinimap() { $result = ''; if (!empty($this->geoData->latitude) and !empty($this->geoData->longitude)) { global $ubillingConfig; $ymconf = $ubillingConfig->getYmaps(); $result = wf_tag('div', false, '', 'id="swmap" style="width: 100%; height:300px;"'); $result .= wf_tag('div', true); $placemarks = sm_MapAddMark($this->geoData->latitude . ',' . $this->geoData->longitude); sm_MapInit($this->geoData->latitude . ',' . $this->geoData->longitude, 8, $ymconf['TYPE'], $placemarks, '', $ymconf['LANG']); } return $result; }