public static function update_notam() { global $tmp_dir, $globalDebug, $globalNOTAMSource; require '../require/class.NOTAM.php'; date_default_timezone_set('UTC'); $query = 'TRUNCATE TABLE notam'; try { $Connection = new Connection(); $sth = Connection::$db->prepare($query); $sth->execute(); } catch (PDOException $e) { return "error : " . $e->getMessage(); } $error = ''; if ($globalDebug) { echo "Notam : Download..."; } update_db::download($globalNOTAMSource, $tmp_dir . 'notam.rss'); if (file_exists($tmp_dir . 'notam.rss')) { $notams = json_decode(json_encode(simplexml_load_file($tmp_dir . 'notam.rss')), true); foreach ($notams['channel']['item'] as $notam) { $title = explode(':', $notam['title']); $data['ref'] = trim($title[0]); unset($title[0]); $data['title'] = trim(implode(':', $title)); $description = strip_tags($notam['description'], '<pre>'); preg_match(':^(.*?)<pre>:', $description, $match); $q = explode('/', $match[1]); $data['fir'] = $q[0]; $data['code'] = $q[1]; $ifrvfr = $q[2]; if ($ifrvfr == 'IV') { $data['rules'] = 'IFR/VFR'; } if ($ifrvfr == 'I') { $data['rules'] = 'IFR'; } if ($ifrvfr == 'V') { $data['rules'] = 'VFR'; } if ($q[4] == 'A') { $data['scope'] = 'Airport warning'; } if ($q[4] == 'E') { $data['scope'] = 'Enroute warning'; } if ($q[4] == 'W') { $data['scope'] = 'Navigation warning'; } if ($q[4] == 'AE') { $data['scope'] = 'Airport/Enroute warning'; } if ($q[4] == 'AW') { $data['scope'] = 'Airport/Navigation warning'; } //$data['scope'] = $q[4]; $data['lower_limit'] = $q[5]; $data['upper_limit'] = $q[6]; $latlonrad = $q[7]; sscanf($latlonrad, '%4c%c%5c%c%3d', $las, $lac, $lns, $lnc, $radius); $latitude = Common::convertDec($las, 'latitude'); $longitude = Common::convertDec($lns, 'longitude'); if ($lac == 'S') { $latitude = '-' . $latitude; } if ($lnc == 'W') { $longitude = '-' . $longitude; } $data['center_latitude'] = $latitude; $data['center_longitude'] = $longitude; $data['radius'] = intval($radius); preg_match(':<pre>(.*?)</pre>:', $description, $match); $data['text'] = $match[1]; preg_match(':</pre>(.*?)$:', $description, $match); $fromto = $match[1]; preg_match('#FROM:(.*?)TO:#', $fromto, $match); $fromall = trim($match[1]); preg_match('#^(.*?) \\((.*?)\\)$#', $fromall, $match); $from = trim($match[1]); $data['date_begin'] = date("Y-m-d H:i:s", strtotime($from)); preg_match('#TO:(.*?)$#', $fromto, $match); $toall = trim($match[1]); if (!preg_match(':Permanent:', $toall)) { preg_match('#^(.*?) \\((.*?)\\)#', $toall, $match); $to = trim($match[1]); $data['date_end'] = date("Y-m-d H:i:s", strtotime($to)); $data['permanent'] = false; } else { $data['date_end'] = ''; $data['permanent'] = true; } $data['full_notam'] = $notam['title'] . '<br>' . $notam['description']; NOTAM::addNOTAM($data['ref'], $data['title'], '', $data['fir'], $data['code'], '', $data['scope'], $data['lower_limit'], $data['upper_limit'], $data['center_latitude'], $data['center_longitude'], $data['radius'], $data['date_begin'], $data['date_end'], $data['permanent'], $data['text'], $data['full_notam']); unset($data); } } else { $error = "File " . $tmp_dir . 'notam.rss' . " doesn't exist. Download failed."; } if ($error != '') { echo $error; exit; } elseif ($globalDebug) { echo "Done\n"; } }