+function session_timeout()
+{
+ $tout = @get_company_pref('login_tout'); // mask warning for db ver. 2.2
+ return $tout ? $tout : ini_get('session.gc_maxlifetime');
+}
+
+//-----------------------------------------------------------------------------
+// Inserts $elements into $array at position $index.
+// $elements is list of any objects
+//
+function array_insert(&$array, $index, $elements)
+{
+ if (!is_array($elements)) $elements = array($elements);
+
+ $head = array_splice($array, 0, $index);
+ $array = array_merge($head, $elements, $array);
+}
+
+function array_remove(&$array, $index, $len=1)
+{
+ array_splice($array, $index, $len);
+}
+
+function array_substitute(&$array, $index, $len, $elements)
+{
+ array_splice($array, $index, $len);
+ array_insert($array, $index, $elements);
+}
+
+function array_append(&$array, $elements)
+{
+ foreach($elements as $key => $el) {
+ if(is_int($key))
+ $array[] = $el;
+ else
+ $array[$key] = $el;
+ }
+}
+//
+// Search $needle in $haystack or in $haystack[][$valuekey]
+// returns $needle found or null.
+//
+function array_search_value($needle, $haystack, $valuekey=null)
+{
+ foreach($haystack as $key => $value) {
+ $val = isset($valuekey) ? @$value[$valuekey] : $value;
+ if ($needle == $val){
+ return $value;
+ }
+ }
+ return null;
+}
+//
+// Search $needle in $haystack or in $haystack[][$valuekey]
+// returns array of keys of $haystack elements found
+//
+function array_search_keys($needle, $haystack, $valuekey=null)
+{
+ $keys = array();
+ if($haystack)
+ foreach($haystack as $key => $value) {
+ $val = isset($valuekey) ? @$value[$valuekey] : $value;
+ if ($needle == $val){
+ $keys[] = $key;
+ }
+ }
+ return $keys;
+}
+//
+// Find first (single) $needle in $haystack or in $haystack[][$valuekey]
+// returns $haystack element found or null
+//
+function array_search_key($needle, $haystack, $valuekey=null)
+{
+ $keys = array_search_keys($needle, $haystack, $valuekey);
+ return @$keys[0];
+}
+
+// Recalculate report columns if orientation is landscape.
+function recalculate_cols(&$cols)
+{
+ $factor = (user_pagesize() == "A4" ? 1.4 : 1.3);
+ foreach($cols as $key => $col)
+ $cols[$key] = intval($col * $factor);
+}
+
+function flush_dir($path, $wipe = false)
+{
+ $dir = opendir($path);
+ if(!$dir)
+ return;
+ while(false !== ($fname = readdir($dir))) {
+ if($fname=='.' || $fname=='..' || $fname=='CVS' || (!$wipe && $fname=='index.php')) continue;
+ if(is_dir($path.'/'.$fname)) {
+ flush_dir($path.'/'.$fname, $wipe);
+ if ($wipe) @rmdir($path.'/'.$fname);
+ } else
+ @unlink($path.'/'.$fname);
+ }
+}
+/*
+ Returns current path to company private folder.
+ (Current path can change after chdir).
+*/
+function company_path($comp=null)
+{
+ global $path_to_root, $comp_path;
+
+ if (!isset($comp))
+ $comp = user_company();
+
+ // if path is relative, set current path_to_root
+ return ($comp_path[0]=='.' ? $path_to_root.'/'.basename($comp_path) : $comp_path)
+ . '/'.$comp;
+}
+
+