connectByName('infectionData'); echo $db->getLastError(); if( is_callable( $func ) ) echo jsencode( call_user_func($func), true ); else echo '{ "error" : "Function: "'. $func .'" does NOT exist!" }'; //function section function worldView() { global $db, $date; $qry = "select * from mis.return_fls_infection_country('". $date['from'] ."','". $date['to'] ."',1,50) as (\"Country\" character varying, \"Total\" integer);"; return $db->sqlExec($qry); } function cityView() { global $db, $date; $qry = "SELECT \"CountryCode\",\"CityName\",sum(\"Total\") AS total FROM mis.report_fls_infection_city WHERE (\"Ts\" BETWEEN '". $date['from'] ."' and '". $date['to'] ."') AND (\"CallerTypeId\" = 1) GROUP BY \"CountryCode\",\"CityName\" ORDER BY total DESC LIMIT 25"; $tmp = $db->sqlExec($qry); shuffle($tmp); return $tmp; } function prevMalView() { global $db, $date; $tmp = array();$i=0; $qry = "SELECT * FROM mis.return_fls_infection_view('". $date['from'] ."','". $date['to'] ."',1) as (\"MalwareName\" character varying, \"Total\" integer);"; $tmp2 = $db->sqlExec($qry); foreach($tmp2 as $arr){ $rr = array_push($tmp, $arr); $i++; if($i >=10) break; } return $tmp; } //utility section function getInterval($interval) { switch($interval){ case 'hour': return array('from'=>date("D, d M Y H:00:00", strtotime("-2 month -1 day -1 hour")), 'to'=>date("D, d M Y H:00:00", strtotime("-2 month")) ); break; case 'day': break; } } function jsencode( $obj, $json = false ){ switch( gettype( $obj ) ){ case 'array': case 'object': $code = array(); // is it anything other than a simple linear array if( array_keys($obj) !== range(0, count($obj) - 1) ){ foreach( $obj as $key => $val ){ $code []= $json ? '"' . $key . '":' . jsencode( $val ) : '"' . $key . '":' . jsencode( $val ); } $code = '{' . implode( ',', $code ) . '}'; } else { foreach( $obj as $val ){ $code []= jsencode( $val ); } $code = '[' . implode( ',', $code ) . ']'; } return $code; break; case 'boolean': return $obj ? 'true' : 'false' ; break; case 'integer': case 'double': return floatVal( $obj ); break; case 'NULL': case 'resource': case 'unknown': return 'null'; break; default: return '"' . addslashes( $obj ) . '"'; } } ?>