| " . htmlentities( $str ) . " |

\n"; } $VARS = array( "G" => $_GET, "P" => $_POST, "R" => $_REQUEST, "S" => $_SERVER ); function var_string( $type, $name, &$value, $min=0, $max=999999 ) { global $VARS; if( !isset( $VARS[$type] ) || !isset( $VARS[$type][$name] ) ) { return false; } $val = stripslashes( $VARS[$type][$name] ); $len = strlen($val); if( $len < $min || $len > $max ) { return false; } $value = $val; return true; } function var_int( $type, $name, &$value, $min, $max ) { if( !var_string( $type, $name, $valuestr, 1, 20 ) ) { return false; } if( !preg_match( "/^[+-]?[0-9]+\$/", $valuestr ) ) { return false; } $valueint = (int)$valuestr; if( $max != $min ) { if( $valueint > $max || $valueint < $min ) { return false; } } $value = $valueint; return true; } function var_date( $type, $name, &$value ) { if( !var_string( $type, $name, $valuestr, 6, 10 ) ) { return false; } if( !preg_match( "/^[0-9]+-[0-9][0-9]?-[0-9][0-9]?\$/", $valuestr ) ) { return false; } list( $y, $m, $d ) = explode( "-", $valuestr ); $d = (int)$d; $m = (int)$m; if( strlen($y) > 4 || $d < 1 || $d > 31 || $m < 1 || $m > 12 ) { return false; } $y = (int)$y; if( $y < 0 || $y > 2099 ) { return false; } if( $y < 100 ) { $y += 2000; } else if( $y < 1900 ) { return false; } $value = sprintf( "%04d-%02d-%02d", $y, $m, $d ); return true; } function str2time( $str, $fmt ) { $tm = strptime( $str, $fmt ); $t = mktime( $tm["tm_hour"], $tm["tm_min"], $tm["tm_sec"], $tm["tm_mon"]+1, $tm["tm_mday"], $tm["tm_year"]+1900 ); return $t; } function pgtime2str( $time ) { return strftime( "%Y-%m-%d %H:%M:%S", $time ); } function pgstr2time( $s ) { return str2time( $s, "%Y-%m-%d %H:%M:%S" ); } function pgts2str( $name, $alias=null ) { if( $alias == null ) { $alias = $name; } return "to_char( $name, 'YYYY-MM-DD HH24:MI:SS' ) as $alias"; } function str2pgts( $name ) { return "to_timestamp( $name, 'YYYY-MM-DD HH24:MI:SS' )"; } function sql_quick_fetch( $conn, $sql, $values=null, $field=0 ) { $ress = null; if( $values === null ) { $ress = pg_query( $conn, $sql ); } else { $ress = pg_query_params( $conn, $sql, $values ); } if( $ress ) { $row = pg_fetch_array( $ress, NULL, PGSQL_BOTH ); if( $row ) { if( $field === null ) { return $row; } else { return $row[$field]; } } } return null; } function sql_next_id( $conn, $table, $field, $where="" ) { $sql = "select " . "max($field) as maxid, " . "count(*) as cnt " . "from " . "$table " . "$where"; $ress = pg_query( $conn, $sql ); if( $ress ) { $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); if( $row ) { if( $row["cnt"] == 0 ) { return 1; } else { return $row["maxid"] + 1; } } } return null; } function set_caching( $offset=864000 ) { // http://elouai.com/force-download.php // required header( "Pragma: public" ); header( "Expires: 0" ); // header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); header( "Cache-Control: max-age=37739520, public" ); // required for certain browsers // header( "Cache-Control: private", false ); header( "Connection: close" ); /* $t = time(); header( "Expires: " . gmdate( "D, d M Y H:i:s", $t + $offset ) . " GMT" ); header( "Cache-Control: max-age=$offset, must-revalidate" ); header( "Last-Modified: " . gmdate( "D, d M Y H:i:s", $t - $offset ) . " GMT" ); */ } function coord_sub( $x ) { $x = str_replace( " ", "", $x ); $x = substr( $x, 1 ) . '"' . substr( $x, 0, 1 ); $x = str_replace( '""', '"', $x ); return $x; } function maps_url( $lat, $lon ) { if( $lat == "" || $lon == "" ) { return ""; } $lat = coord_sub( $lat ); $lon = coord_sub( $lon ); $coord = urlencode( $lat . "," . $lon ); return "https://www.google.co.in/maps/place/$coord"; } ?>