$value) { if($search_key == $key) { return true; } } return false; } #----------------------------------------------------------------------------- # Returns cleaned version of a _POST variable, or if variable does not exist, # returns a default value. # # INPUT: # _POST variable name # default value for variable # OUTPUT: # cleaned version of _POST variable or the default value #----------------------------------------------------------------------------- function util_clean_post_vars( $var, $default=null ) { $result = ''; if( isset( $_POST[$var] ) && !empty($_POST[$var]) ) { $result = trim( $_POST[$var] ); $result = stripslashes( $result ); $result = str_replace( "'", "\'", "$result"); $result = htmlentities($result, ENT_QUOTES); } elseif( func_num_args() > 1 ) { $result = $default; } return $result; } #----------------------------------------------------------------------------- # Returns cleaned version of a _GET variable, or if variable does not exist, # returns a default value. # # INPUT: # _GET variable name # default value for variable # OUTPUT: # cleaned version of _GET variable or the default value #----------------------------------------------------------------------------- function util_clean_get_vars( $var, $default=null ) { $result = ''; if( isset($_GET[$var]) && !empty($_GET[$var]) ) { $result = trim( $_GET[$var] ); $result = stripslashes( $result ); } elseif( !is_null($default) ) { $result = $default; } return $result; } #----------------------------------------------------------------------------- # Returns cleaned version of a passed string, or if variable does not exist, # returns a default value. # # INPUT: # string # default value of string # OUTPUT: # string stripped of leading white spaces, trailing white spaces, slashes, # and replaces characters with a html entitity code # or the default value #----------------------------------------------------------------------------- function util_clean_var_html( $var, $default=null ) { $result = ''; if( isset($var) && !empty($var) && is_string($var) ) { $result = trim($var); $result = stripslashes($result); $result = str_replace("'", "\'", "$result"); $result = htmlentities($result, ENT_QUOTES); } elseif( !is_null($default) ) { $result = $default; } return $result; } #----------------------------------------------------------------------------- # Returns cleaned version of a passed string, or if variable does not exist, # returns a default value. # # INPUT: # string # default value of string # OUTPUT: # string stripped of leading white spaces, trailing white spaces and slashes # or the default value #----------------------------------------------------------------------------- function util_clean_var_strip( $var, $default=null ) { $result = ''; if( isset($var) && !empty($var) ) { $result = trim( $var ); $result = stripslashes( $result ); } elseif( !is_null($default) ) { $result = $default; } return $result; } #----------------------------------------------------------------------------- # Retrieve a cookie variable # You may pass in any variable as a default (including null) but if # you pass in *no* default then an error will be triggered if the cookie # cannot be found #----------------------------------------------------------------------------- function util_get_cookie( $p_var_name, $p_default=null ) { $t_result = ''; if ( isset( $_COOKIE[$p_var_name] ) ) { $t_result = $_COOKIE[$p_var_name]; #check for a default passed in (allowing null) } else if ( func_num_args() > 1 ) { $t_result = $p_default; } return $t_result; } #------------------------------------------------------------------------ # Set a cookie variable # If $p_expire is false instead of a number, the cookie will expire when # the browser is closed; if it is true, the default time from the config # file will be used # If $p_path or $p_domaain are omitted, defaults are used #------------------------------------------------------------------------ function util_set_cookie( $p_name, $p_value, $p_path=null, $p_domain=null ) { return setcookie( $p_name, $p_value, time() + COOKIE_EXPIRE_LENGTH, COOKIE_PATH, COOKIE_DOMAIN ); } # ---------------------------------------------------------------------- # Prepare text for exporting to csv file # INPUT: # text to prepare # OUTPUT: # text without embedded commas, tags and carriage return/linefeeds # ---------------------------------------------------------------------- function util_prepare_text_for_export($text) { $text = str_replace(",", ":", $text); $text = strip_tags($text); $text = str_replace("\r", " ", $text); $text = str_replace("\n", " ", $text); return $text; } # ---------------------------------------------------------------------- # Get file type # INPUT: # file name # OUTPUT: # file extension # ---------------------------------------------------------------------- function util_get_filetype($file_name) { $extension_start = strrpos($file_name, '.'); if ($extension_start === false) { return ''; } else { return substr ( $file_name, $extension_start+1); } } # ---------------------------------------------------------------------- # Validate date # # INPUT: # Date to verify # OUTPUT: # True if date is valid, false if date is invalid # ---------------------------------------------------------------------- function util_date_isvalid($date) { $date_isvalid = true; if (!empty($date)) { # split date into parts $year = substr($date, 0, 4); $separator1 = substr($date, 4, 1); $month = substr($date, 5, 2); $separator2 = substr($date, 7, 1); $day = substr($date, 8, 2); if ( strlen($date) == 10 && is_numeric($year) && is_numeric($month) && is_numeric($day) && $separator1 == '-' && $separator2 == '-') { return checkdate($month, $day, $year); } else { $date_isvalid = false; } } return $date_isvalid; } # ---------------------------------------------------------------------- # Prints table row with whitespace in td field # ---------------------------------------------------------------------- function util_add_spacer() { print"
' . preg_replace('#\n|\r#', "
\n", $str) . "
\n"; } function util_space2nbsp($str) { return str_replace(' ', ' ', $str); } /* function util_string_insert_href($p_string) { # Find any URL in a string and replace it by a clickable link $p_string = preg_replace( '/([http|irc|ftp|https]{2,}:\/\/([a-z0-9_-]|\/|\@|:{0,1}\.{0,1}){1,})/i', '\1 [^]', $p_string); # Set up a simple subset of RFC 822 email address parsing # We don't allow domain literals or quoted strings # We also don't allow the & character in domains even though the RFC # appears to do so. This was to prevent > etc from being included. # Note: we could use email_get_rfc822_regex() but it doesn't work well # when applied to data that has already had entities inserted. # # bpfennig: '@' doesn't accepted anymore $t_atom = '[^\'@\'](?:[^()<>@,;:\\\".\[\]\000-\037\177 &]+)'; # In order to avoid selecting URLs containing @ characters as email # addresses we limit our selection to addresses that are preceded by: # * the beginning of the string # * a < entity (allowing '