2002-03-01 13:31:50 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2005-11-09 14:54:36 +01:00
|
|
|
* eGroupWare API - commonly used functions included by eGW AND setup *
|
|
|
|
* The file was originaly written by Dan Kuykendall <seek3r@phpgroupware.org> *
|
2002-03-01 13:31:50 +01:00
|
|
|
* and Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* Copyright (C) 2000, 2001 Dan Kuykendall *
|
|
|
|
* -------------------------------------------------------------------------*
|
2004-05-05 14:06:13 +02:00
|
|
|
* This library is part of the eGroupWare API *
|
2005-11-09 14:54:36 +01:00
|
|
|
* http://www.egroupware.org *
|
2002-03-01 13:31:50 +01:00
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
|
|
\**************************************************************************/
|
2002-03-02 05:08:20 +01:00
|
|
|
|
2002-03-01 13:31:50 +01:00
|
|
|
/* $Id$ */
|
2002-03-02 05:08:20 +01:00
|
|
|
|
2002-03-01 13:31:50 +01:00
|
|
|
/****************************************************************************\
|
2002-03-02 05:08:20 +01:00
|
|
|
* Direct functions which are not part of the API classes *
|
|
|
|
* because they are required to be available at the lowest level. *
|
|
|
|
\***************************************************************************/
|
2003-10-16 18:34:45 +02:00
|
|
|
|
2007-09-29 11:17:42 +02:00
|
|
|
/**
|
|
|
|
* Return the number of bytes of a string, independent of mbstring.func_overload
|
|
|
|
* AND the availability of mbstring
|
|
|
|
*
|
|
|
|
* @param string $str
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function bytes($str)
|
|
|
|
{
|
|
|
|
static $func_overload;
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2007-09-29 11:17:42 +02:00
|
|
|
if (is_null($func_overload)) $func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2007-09-29 11:17:42 +02:00
|
|
|
return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
|
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* @internal Not to be used directly. Should only be used by print_debug()
|
|
|
|
*/
|
2002-03-01 13:31:50 +01:00
|
|
|
function print_debug_subarray($array)
|
|
|
|
{
|
2004-01-02 06:47:24 +01:00
|
|
|
foreach($array as $key => $value)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
|
|
|
if (is_array($value))
|
|
|
|
{
|
|
|
|
$vartypes[$key] = print_debug_subarray($value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vartypes[$key] = gettype($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $vartypes;
|
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
2005-11-09 14:54:36 +01:00
|
|
|
* print debug data only when debugging mode is turned on.
|
|
|
|
*
|
|
|
|
* @author seek3r
|
2008-04-18 16:59:59 +02:00
|
|
|
* This function is used to debugging data.
|
2005-11-09 14:54:36 +01:00
|
|
|
* print_debug('this is some debugging data',$somevar);
|
2005-11-09 13:44:32 +01:00
|
|
|
*/
|
2002-03-01 13:31:50 +01:00
|
|
|
function print_debug($message,$var = 'messageonly',$part = 'app', $level = 3)
|
|
|
|
{
|
2002-08-22 05:05:58 +02:00
|
|
|
if (($part == 'app' && DEBUG_APP == True) || ($part == 'api' && DEBUG_API == True))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
|
|
|
if (!defined('DEBUG_OUTPUT'))
|
|
|
|
{
|
|
|
|
define('DEBUG_OUTPUT', 1);
|
|
|
|
}
|
|
|
|
if ($level >= DEBUG_LEVEL)
|
|
|
|
{
|
|
|
|
if (!is_array($var))
|
|
|
|
{
|
|
|
|
if ($var != 'messageonly')
|
|
|
|
{
|
|
|
|
if (!DEBUG_DATATYPES)
|
|
|
|
{
|
|
|
|
$output = "$message\n$var";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$output = "$message\n$var is a ".gettype($var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$output = $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bit 1 means to output to screen */
|
|
|
|
if (!!(DEBUG_OUTPUT & 1))
|
|
|
|
{
|
|
|
|
echo "$output<br>\n";
|
|
|
|
}
|
|
|
|
/* Bit 2 means to output to sql */
|
|
|
|
if (!!(DEBUG_OUTPUT & 2))
|
|
|
|
{
|
|
|
|
/* Need to flesh this out still. I dont have a table to dump this in yet.*/
|
|
|
|
/* So the SQL statement will go here*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Example of how this can be extended to output to other locations as well. This example uses a COM object */
|
|
|
|
/*
|
|
|
|
if (!!(DEBUG_OUTPUT & 32))
|
|
|
|
{
|
2005-11-09 13:44:32 +01:00
|
|
|
$obj_debug =& new COM('Some_COM_App.Class','localhost');
|
2002-03-01 13:31:50 +01:00
|
|
|
if (is_object($obj_debug))
|
|
|
|
{
|
|
|
|
$DebugMessage_return = $obj_debug->DebugMessage($output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (floor(phpversion()) > 3 && !!(DEBUG_OUTPUT & 2))
|
|
|
|
{
|
|
|
|
ob_start();
|
|
|
|
}
|
|
|
|
echo "<pre>\n$message\n";
|
|
|
|
print_r($var);
|
|
|
|
if (DEBUG_DATATYPES)
|
|
|
|
{
|
2004-01-02 06:47:24 +01:00
|
|
|
// while(list($key, $value) = each($var))
|
|
|
|
foreach($var as $key => $value)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
|
|
|
if (is_array($value))
|
|
|
|
{
|
|
|
|
$vartypes[$key] = print_debug_subarray($value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vartypes[$key] = gettype($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "Data Types:\n";
|
|
|
|
print_r($vartypes);
|
|
|
|
}
|
|
|
|
echo "\n<pre>\n";
|
|
|
|
if (floor(phpversion()) > 3 && !!(DEBUG_OUTPUT & 2))
|
|
|
|
{
|
|
|
|
$output .= ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
/* Need to flesh this out still. I dont have a table to dump this in yet.*/
|
|
|
|
/* So the SQL statement will go here*/
|
|
|
|
if (!!(DEBUG_OUTPUT & 1))
|
|
|
|
{
|
|
|
|
echo "$output<br>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-02 05:08:20 +01:00
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* Allows for array and direct function params as well as sanatization.
|
|
|
|
*
|
|
|
|
* @author seek3r
|
|
|
|
* This function is used to validate param data as well as offer flexible function usage.
|
2008-04-18 16:59:59 +02:00
|
|
|
*
|
2003-01-11 09:32:44 +01:00
|
|
|
function somefunc()
|
|
|
|
{
|
|
|
|
$expected_args[0] = Array('name'=>'fname','default'=>'joe', 'type'=>'string');
|
|
|
|
$expected_args[1] = Array('name'=>'mname','default'=>'hick', 'type'=>'string');
|
|
|
|
$expected_args[2] = Array('name'=>'lname','default'=>'bob', 'type'=>'string');
|
|
|
|
$recieved_args = func_get_args();
|
|
|
|
$args = safe_args($expected_args, $recieved_args,__LINE__,__FILE__);
|
|
|
|
echo 'Full name: '.$args['fname'].' '.$args['fname'].' '.$args['lname'].'<br>';
|
|
|
|
//default result would be:
|
|
|
|
// Full name: joe hick bob<br>
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2003-01-11 09:32:44 +01:00
|
|
|
Using this it is possible to use the function in any of the following ways
|
|
|
|
somefunc('jack','city','brown');
|
|
|
|
or
|
|
|
|
somefunc(array('fname'=>'jack','mname'=>'city','lname'=>'brown'));
|
|
|
|
or
|
|
|
|
somefunc(array('lname'=>'brown','fname'=>'jack','mname'=>'city'));
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2003-01-11 09:32:44 +01:00
|
|
|
For the last one, when using named params in an array you dont have to follow any order
|
|
|
|
All three would result in - Full name: jack city brown<br>
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2003-01-11 09:32:44 +01:00
|
|
|
When you use this method of handling params you can secure your functions as well offer
|
|
|
|
flexibility needed for both normal use and web services use.
|
|
|
|
If you have params that are required just set the default as ##REQUIRED##
|
2008-04-18 16:59:59 +02:00
|
|
|
Users of your functions can also use ##DEFAULT## to use your default value for a param
|
2003-01-11 09:32:44 +01:00
|
|
|
when using the standard format like this:
|
|
|
|
somefunc('jack','##DEFAULT##','brown');
|
|
|
|
This would result in - Full name: jack hick brown<br>
|
|
|
|
Its using the default value for the second param.
|
|
|
|
Of course if you have the second param as a required field it will fail to work.
|
2005-11-09 13:44:32 +01:00
|
|
|
*/
|
2003-01-11 09:32:44 +01:00
|
|
|
function safe_args($expected, $recieved, $line='??', $file='??')
|
|
|
|
{
|
|
|
|
/* This array will contain all the required fields */
|
|
|
|
$required = Array();
|
|
|
|
|
|
|
|
/* This array will contain all types for sanatization checking */
|
|
|
|
/* only used when an array is passed as the first arg */
|
|
|
|
$types = Array();
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2003-01-11 09:32:44 +01:00
|
|
|
/* start by looping thru the expected list and set params with */
|
|
|
|
/* the default values */
|
|
|
|
$num = count($expected);
|
2003-12-10 12:45:03 +01:00
|
|
|
for ($i = 0; $i < $num; $i++)
|
2003-01-11 09:32:44 +01:00
|
|
|
{
|
|
|
|
$args[$expected[$i]['name']] = $expected[$i]['default'];
|
|
|
|
if ($expected[$i]['default'] === '##REQUIRED##')
|
|
|
|
{
|
|
|
|
$required[$expected[$i]['name']] = True;
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
$types[$expected[$i]['name']] = $expected[$i]['type'];
|
2003-12-10 12:45:03 +01:00
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2003-01-11 09:32:44 +01:00
|
|
|
/* Make sure they passed at least one param */
|
|
|
|
if(count($recieved) != 0)
|
|
|
|
{
|
|
|
|
/* if used as standard function we loop thru and set by position */
|
|
|
|
if(!is_array($recieved[0]))
|
|
|
|
{
|
2003-12-10 12:45:03 +01:00
|
|
|
for ($i = 0; $i < $num; $i++)
|
2003-01-11 09:32:44 +01:00
|
|
|
{
|
2003-01-12 04:43:55 +01:00
|
|
|
if(isset($recieved[$i]) && $recieved[$i] !== '##DEFAULT##')
|
2003-01-11 09:32:44 +01:00
|
|
|
{
|
|
|
|
if(sanitize($recieved[$i],$expected[$i]['type']))
|
|
|
|
{
|
|
|
|
$args[$expected[$i]['name']] = $recieved[$i];
|
|
|
|
unset($required[$expected[$i]['name']]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo 'Fatal Error: Invalid paramater type for '.$expected[$i]['name'].' on line '.$line.' of '.$file.'<br>';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2003-12-10 12:45:03 +01:00
|
|
|
}
|
2003-01-11 09:32:44 +01:00
|
|
|
}
|
|
|
|
/* if used as standard function we loop thru and set by position */
|
|
|
|
else
|
|
|
|
{
|
2003-12-10 12:45:03 +01:00
|
|
|
for ($i = 0; $i < $num; $i++)
|
2003-01-11 09:32:44 +01:00
|
|
|
{
|
2008-04-18 16:59:59 +02:00
|
|
|
$types[$expected[$i]['name']] = $expected[$i]['type'];
|
2003-12-10 12:45:03 +01:00
|
|
|
}
|
2003-01-11 09:32:44 +01:00
|
|
|
while(list($key,$val) = each($recieved[0]))
|
|
|
|
{
|
2003-01-12 04:43:55 +01:00
|
|
|
if($val !== '##DEFAULT##')
|
2003-01-11 09:32:44 +01:00
|
|
|
{
|
|
|
|
if(sanitize($val,$types[$key]) == True)
|
|
|
|
{
|
|
|
|
$args[$key] = $val;
|
|
|
|
unset($required[$key]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo 'Fatal Error: Invalid paramater type for '.$key.' on line '.$line.' of '.$file.'<br>';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(count($required) != 0)
|
|
|
|
{
|
|
|
|
while (list($key) = each($required))
|
|
|
|
{
|
|
|
|
echo 'Fatal Error: Missing required paramater '.$key.' on line '.$line.' of '.$file.'<br>';
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
2005-11-09 14:54:36 +01:00
|
|
|
* Validate data.
|
|
|
|
*
|
|
|
|
* @author seek3r
|
2008-04-18 16:59:59 +02:00
|
|
|
* This function is used to validate input data.
|
2005-11-09 14:54:36 +01:00
|
|
|
* sanitize('number',$somestring);
|
2005-11-09 13:44:32 +01:00
|
|
|
*/
|
2002-03-01 13:31:50 +01:00
|
|
|
function sanitize($string,$type)
|
|
|
|
{
|
|
|
|
switch ($type)
|
|
|
|
{
|
|
|
|
case 'bool':
|
|
|
|
if ($string == 1 || $string == 0)
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
break;
|
2002-05-26 22:00:35 +02:00
|
|
|
case 'isprint':
|
2002-05-26 10:26:44 +02:00
|
|
|
$length = strlen($string);
|
|
|
|
$position = 0;
|
|
|
|
while ($length > $position)
|
|
|
|
{
|
|
|
|
$char = substr($string, $position, 1);
|
2002-05-26 22:00:35 +02:00
|
|
|
if ($char < ' ' || $char > '~')
|
2002-05-26 10:26:44 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$position = $position + 1;
|
|
|
|
}
|
|
|
|
return True;
|
2002-05-26 22:00:35 +02:00
|
|
|
break;
|
2002-05-26 10:26:44 +02:00
|
|
|
case 'alpha':
|
|
|
|
if (preg_match("/^[a-z]+$/i", $string))
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
break;
|
2002-03-01 13:31:50 +01:00
|
|
|
case 'number':
|
|
|
|
if (preg_match("/^[0-9]+$/i", $string))
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
break;
|
2002-05-26 10:26:44 +02:00
|
|
|
case 'alphanumeric':
|
|
|
|
if (preg_match("/^[a-z0-9 -._]+$/i", $string))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
break;
|
2002-05-26 10:26:44 +02:00
|
|
|
case 'string':
|
|
|
|
if (preg_match("/^[a-z]+$/i", $string))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'ip':
|
|
|
|
if (eregi("^[0-9]{1,3}(\.[0-9]{1,3}){3}$",$string))
|
|
|
|
{
|
|
|
|
$octets = split('\.',$string);
|
|
|
|
for ($i=0; $i != count($octets); $i++)
|
|
|
|
{
|
|
|
|
if ($octets[$i] < 0 || $octets[$i] > 255)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
break;
|
|
|
|
case 'file':
|
|
|
|
if (preg_match("/^[a-z0-9_]+\.+[a-z]+$/i", $string))
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'email':
|
|
|
|
if (eregi("^([[:alnum:]_%+=.-]+)@([[:alnum:]_.-]+)\.([a-z]{2,3}|[0-9]{1,3})$",$string))
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
break;
|
2002-05-26 22:00:35 +02:00
|
|
|
case 'password':
|
2002-05-26 10:26:44 +02:00
|
|
|
$password_length = strlen($string);
|
|
|
|
$password_numbers = Array('0','1','2','3','4','5','6','7','8','9');
|
|
|
|
$password_special_chars = Array(' ','~','`','!','@','#','$','%','^','&','*','(',')','_','+','-','=','{','}','|','[',']',"\\",':','"',';',"'",'<','>','?',',','.','/');
|
|
|
|
|
2005-03-04 21:48:05 +01:00
|
|
|
if(@isset($GLOBALS['egw_info']['server']['pass_min_length']) && is_int($GLOBALS['egw_info']['server']['pass_min_length']) && $GLOBALS['egw_info']['server']['pass_min_length'] > 1)
|
2002-05-26 10:26:44 +02:00
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
$min_length = $GLOBALS['egw_info']['server']['pass_min_length'];
|
2002-05-26 10:26:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$min_length = 1;
|
|
|
|
}
|
2002-05-26 10:50:40 +02:00
|
|
|
|
2005-03-04 21:48:05 +01:00
|
|
|
if(@isset($GLOBALS['egw_info']['server']['pass_require_non_alpha']) && $GLOBALS['egw_info']['server']['pass_require_non_alpha'] == True)
|
2002-05-26 10:50:40 +02:00
|
|
|
{
|
|
|
|
$pass_verify_non_alpha = False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$pass_verify_non_alpha = True;
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2005-03-04 21:48:05 +01:00
|
|
|
if(@isset($GLOBALS['egw_info']['server']['pass_require_numbers']) && $GLOBALS['egw_info']['server']['pass_require_numbers'] == True)
|
2002-05-26 10:26:44 +02:00
|
|
|
{
|
|
|
|
$pass_verify_num = False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$pass_verify_num = True;
|
|
|
|
}
|
|
|
|
|
2005-03-04 21:48:05 +01:00
|
|
|
if(@isset($GLOBALS['egw_info']['server']['pass_require_special_char']) && $GLOBALS['egw_info']['server']['pass_require_special_char'] == True)
|
2002-05-26 10:26:44 +02:00
|
|
|
{
|
|
|
|
$pass_verify_special_char = False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$pass_verify_special_char = True;
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2002-05-26 10:26:44 +02:00
|
|
|
if ($password_length >= $min_length)
|
|
|
|
{
|
|
|
|
for ($i=0; $i != $password_length; $i++)
|
|
|
|
{
|
|
|
|
$cur_test_string = substr($string, $i, 1);
|
2002-05-26 10:50:40 +02:00
|
|
|
if (in_array($cur_test_string, $password_numbers) || in_array($cur_test_string, $password_special_chars))
|
2002-05-26 10:26:44 +02:00
|
|
|
{
|
2002-05-26 10:50:40 +02:00
|
|
|
$pass_verify_non_alpha = True;
|
|
|
|
if (in_array($cur_test_string, $password_numbers))
|
|
|
|
{
|
|
|
|
$pass_verify_num = True;
|
|
|
|
}
|
|
|
|
elseif (in_array($cur_test_string, $password_special_chars))
|
|
|
|
{
|
|
|
|
$pass_verify_special_char = True;
|
|
|
|
}
|
2002-05-26 10:26:44 +02:00
|
|
|
}
|
|
|
|
}
|
2002-05-26 22:00:35 +02:00
|
|
|
|
2002-05-26 10:50:40 +02:00
|
|
|
if ($pass_verify_num == False)
|
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['msgbox_data']['Password requires at least one non-alpha character']=False;
|
2002-05-26 10:50:40 +02:00
|
|
|
}
|
|
|
|
|
2002-05-26 10:26:44 +02:00
|
|
|
if ($pass_verify_num == False)
|
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['msgbox_data']['Password requires at least one numeric character']=False;
|
2002-05-26 10:26:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($pass_verify_special_char == False)
|
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['msgbox_data']['Password requires at least one special character (non-letter and non-number)']=False;
|
2002-05-26 10:26:44 +02:00
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2002-05-26 10:26:44 +02:00
|
|
|
if ($pass_verify_num == True && $pass_verify_special_char == True)
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
2005-03-04 21:48:05 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['msgbox_data']['Password must be at least '.$min_length.' characters']=False;
|
2002-05-26 10:26:44 +02:00
|
|
|
return False;
|
|
|
|
break;
|
2002-03-01 13:31:50 +01:00
|
|
|
case 'any':
|
|
|
|
return True;
|
|
|
|
break;
|
|
|
|
default :
|
2005-03-04 21:48:05 +01:00
|
|
|
if (isset($GLOBALS['egw_info']['server']['sanitize_types'][$type]['type']))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
if ($GLOBALS['egw_info']['server']['sanitize_types'][$type]['type']($GLOBALS['egw_info']['server']['sanitize_types'][$type]['string'], $string))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-18 12:36:34 +02:00
|
|
|
function reg_var($varname, $method='any', $valuetype='alphanumeric',$default_value='',$register=True)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2003-10-18 12:36:34 +02:00
|
|
|
if($method == 'any' || $method == array('any'))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2003-10-18 12:36:34 +02:00
|
|
|
$method = Array('POST','GET','COOKIE','SERVER','FILES','GLOBAL','DEFAULT');
|
2002-05-30 11:47:09 +02:00
|
|
|
}
|
|
|
|
elseif(!is_array($method))
|
|
|
|
{
|
|
|
|
$method = Array($method);
|
|
|
|
}
|
|
|
|
$cnt = count($method);
|
|
|
|
for($i=0;$i<$cnt;$i++)
|
|
|
|
{
|
|
|
|
switch(strtoupper($method[$i]))
|
|
|
|
{
|
|
|
|
case 'DEFAULT':
|
|
|
|
if($default_value)
|
|
|
|
{
|
|
|
|
$value = $default_value;
|
|
|
|
$i = $cnt+1; /* Found what we were looking for, now we end the loop */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'GLOBAL':
|
|
|
|
if(@isset($GLOBALS[$varname]))
|
|
|
|
{
|
|
|
|
$value = $GLOBALS[$varname];
|
|
|
|
$i = $cnt+1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'POST':
|
|
|
|
case 'GET':
|
|
|
|
case 'COOKIE':
|
|
|
|
case 'SERVER':
|
2003-04-02 12:42:12 +02:00
|
|
|
if(phpversion() >= '4.1.0')
|
2002-05-30 11:47:09 +02:00
|
|
|
{
|
|
|
|
$meth = '_'.strtoupper($method[$i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$meth = 'HTTP_'.strtoupper($method[$i]).'_VARS';
|
|
|
|
}
|
|
|
|
if(@isset($GLOBALS[$meth][$varname]))
|
|
|
|
{
|
|
|
|
$value = $GLOBALS[$meth][$varname];
|
|
|
|
$i = $cnt+1;
|
|
|
|
}
|
2004-01-12 07:11:23 +01:00
|
|
|
if(get_magic_quotes_gpc() && isset($value))
|
2004-01-02 02:42:23 +01:00
|
|
|
{
|
2004-06-04 08:17:23 +02:00
|
|
|
// we need to stripslash 3 levels of arrays
|
2004-01-20 06:28:04 +01:00
|
|
|
// because of the password function in preferences
|
|
|
|
// it's named ['user']['variablename']['pw']
|
2004-06-04 08:17:23 +02:00
|
|
|
// or something like this in projects
|
|
|
|
// $values['budgetBegin']['1']['year']
|
2004-01-10 16:04:17 +01:00
|
|
|
if(@is_array($value))
|
|
|
|
{
|
|
|
|
/* stripslashes on the first level of array values */
|
|
|
|
foreach($value as $name => $val)
|
|
|
|
{
|
2004-01-20 06:28:04 +01:00
|
|
|
if(@is_array($val))
|
|
|
|
{
|
|
|
|
foreach($val as $name2 => $val2)
|
|
|
|
{
|
2004-06-04 08:17:23 +02:00
|
|
|
if(@is_array($val2))
|
|
|
|
{
|
|
|
|
foreach($val2 as $name3 => $val3)
|
|
|
|
{
|
|
|
|
$value[$name][$name2][$name3] = stripslashes($val3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$value[$name][$name2] = stripslashes($val2);
|
|
|
|
}
|
2004-01-20 06:28:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$value[$name] = stripslashes($val);
|
|
|
|
}
|
2004-01-10 16:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* stripslashes on this (string) */
|
|
|
|
$value = stripslashes($value);
|
|
|
|
}
|
2004-01-02 02:42:23 +01:00
|
|
|
}
|
2002-05-30 11:47:09 +02:00
|
|
|
break;
|
2003-10-18 12:36:34 +02:00
|
|
|
case 'FILES':
|
|
|
|
if(phpversion() >= '4.1.0')
|
|
|
|
{
|
|
|
|
$meth = '_FILES';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$meth = 'HTTP_POST_FILES';
|
|
|
|
}
|
|
|
|
if(@isset($GLOBALS[$meth][$varname]))
|
|
|
|
{
|
|
|
|
$value = $GLOBALS[$meth][$varname];
|
|
|
|
$i = $cnt+1;
|
|
|
|
}
|
|
|
|
break;
|
2002-05-30 11:47:09 +02:00
|
|
|
default:
|
|
|
|
if(@isset($GLOBALS[strtoupper($method[$i])][$varname]))
|
|
|
|
{
|
|
|
|
$value = $GLOBALS[strtoupper($method[$i])][$varname];
|
|
|
|
$i = $cnt+1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
|
2002-05-30 11:47:09 +02:00
|
|
|
if (@!isset($value))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
$value = $default_value;
|
|
|
|
}
|
2002-08-20 14:41:48 +02:00
|
|
|
|
2002-05-30 11:47:09 +02:00
|
|
|
if (@!is_array($value))
|
|
|
|
{
|
|
|
|
if ($value == '')
|
|
|
|
{
|
|
|
|
$result = $value;
|
|
|
|
}
|
|
|
|
else
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
if (sanitize($value,$valuetype) == 1)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
$result = $value;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
$result = $default_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reset($value);
|
|
|
|
while(list($k, $v) = each($value))
|
|
|
|
{
|
|
|
|
if ($v == '')
|
|
|
|
{
|
|
|
|
$result[$k] = $v;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (is_array($valuetype))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
$vt = $valuetype[$k];
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
$vt = $valuetype;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
2002-05-30 11:47:09 +02:00
|
|
|
|
|
|
|
if (sanitize($v,$vt) == 1)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
$result[$k] = $v;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (is_array($default_value))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
$result[$k] = $default_value[$k];
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-30 11:47:09 +02:00
|
|
|
$result[$k] = $default_value;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-05-30 11:47:09 +02:00
|
|
|
if($register)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
$GLOBALS['egw_info'][$GLOBALS['egw_info']['flags']['currentapp']][$varname] = $result;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
2002-05-30 11:47:09 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* retrieve a value from either a POST, GET, COOKIE, SERVER or from a class variable.
|
|
|
|
*
|
|
|
|
* @author skeeter
|
2008-04-18 16:59:59 +02:00
|
|
|
* This function is used to retrieve a value from a user defined order of methods.
|
2005-11-09 13:44:32 +01:00
|
|
|
* $this->id = get_var('id',array('HTTP_POST_VARS'||'POST','HTTP_GET_VARS'||'GET','HTTP_COOKIE_VARS'||'COOKIE','GLOBAL','DEFAULT'));
|
|
|
|
* @param $variable name
|
|
|
|
* @param $method ordered array of methods to search for supplied variable
|
|
|
|
* @param $default_value (optional)
|
|
|
|
*/
|
2002-05-30 11:47:09 +02:00
|
|
|
function get_var($variable,$method='any',$default_value='')
|
|
|
|
{
|
2003-10-18 12:36:34 +02:00
|
|
|
if(!@is_array($method))
|
|
|
|
{
|
|
|
|
$method = array($method);
|
|
|
|
}
|
2002-05-30 11:47:09 +02:00
|
|
|
return reg_var($variable,$method,'any',$default_value,False);
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* Load a class and include the class file if not done so already.
|
|
|
|
*
|
2008-04-18 16:59:59 +02:00
|
|
|
* This function is used to create an instance of a class, and if the class file has not been included it will do so.
|
2005-11-09 13:44:32 +01:00
|
|
|
* $GLOBALS['egw']->acl =& CreateObject('phpgwapi.acl');
|
|
|
|
*
|
|
|
|
* @author RalfBecker@outdoor-training.de
|
|
|
|
* @param $classname name of class
|
|
|
|
* @param $p1,$p2,... class parameters (all optional)
|
|
|
|
* @return object reference to an object
|
|
|
|
*/
|
2005-03-04 21:48:05 +01:00
|
|
|
function &CreateObject($class)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
list($appname,$classname) = explode('.',$class);
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2006-10-22 08:39:49 +02:00
|
|
|
if ($classname == 'datetime') $classname = 'egw_datetime'; // php5.2 fix
|
2002-03-01 13:31:50 +01:00
|
|
|
|
2006-10-03 17:16:42 +02:00
|
|
|
include_once(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php');
|
2002-03-01 13:31:50 +01:00
|
|
|
|
2005-03-15 16:36:44 +01:00
|
|
|
if (class_exists($classname))
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2005-03-15 16:36:44 +01:00
|
|
|
$args = func_get_args();
|
2008-03-21 21:11:59 +01:00
|
|
|
switch(count($args))
|
2005-03-15 16:36:44 +01:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
case 1:
|
|
|
|
$obj =& new $classname;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$obj =& new $classname($args[1]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
$obj =& new $classname($args[1],$args[2]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
$obj =& new $classname($args[1],$args[2],$args[3]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$code = '$obj =& new ' . $classname . '(';
|
|
|
|
foreach($args as $n => $arg)
|
2005-03-15 16:36:44 +01:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
if ($n)
|
|
|
|
{
|
|
|
|
$code .= ($n > 1 ? ',' : '') . '$args[' . $n . ']';
|
|
|
|
}
|
2005-03-15 16:36:44 +01:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
$code .= ');';
|
|
|
|
eval($code);
|
|
|
|
break;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
2005-03-04 21:48:05 +01:00
|
|
|
}
|
|
|
|
if (!is_object($obj))
|
|
|
|
{
|
2005-03-15 16:36:44 +01:00
|
|
|
echo "<p>CreateObject('$class'): Cant instanciate class!!!<br />\n".function_backtrace(1)."</p>\n";
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
2005-03-04 21:48:05 +01:00
|
|
|
return $obj;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
|
2005-11-01 15:19:00 +01:00
|
|
|
/**
|
2005-11-09 13:44:32 +01:00
|
|
|
* Execute a function with multiple arguments
|
|
|
|
* We take object $GLOBALS[classname] from class if exists
|
|
|
|
*
|
|
|
|
* @param string app.class.method method to execute
|
|
|
|
* @example ExecObject('etemplates.so_sql.search',$criteria,$key_only,...);
|
|
|
|
* @return mixed reference to returnvalue of the method
|
|
|
|
*/
|
2005-11-01 15:19:00 +01:00
|
|
|
function &ExecMethod2($acm)
|
|
|
|
{
|
|
|
|
list($app,$class,$method) = explode('.',$acm);
|
|
|
|
if (!is_object($obj =& $GLOBALS[$class]))
|
|
|
|
{
|
|
|
|
$obj =& CreateObject($acm);
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2005-11-01 15:19:00 +01:00
|
|
|
if (!method_exists($obj,$method))
|
|
|
|
{
|
|
|
|
echo "<p><b>".function_backtrace()."</b>: no methode '$method' in class '$class'</p>\n";
|
|
|
|
return False;
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2005-11-01 15:19:00 +01:00
|
|
|
$args = func_get_args();
|
|
|
|
unset($args[0]);
|
2008-03-21 21:11:59 +01:00
|
|
|
|
|
|
|
return call_user_func_array(array($obj,$method),$args);
|
2005-11-01 15:19:00 +01:00
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* Execute a function, and load a class and include the class file if not done so already.
|
|
|
|
*
|
|
|
|
* This function is used to create an instance of a class, and if the class file has not been included it will do so.
|
|
|
|
*
|
|
|
|
* @author seek3r
|
|
|
|
* @param $method to execute
|
|
|
|
* @param $functionparams function param should be an array
|
|
|
|
* @param $loglevel developers choice of logging level
|
|
|
|
* @param $classparams params to be sent to the contructor
|
|
|
|
* @return mixed returnvalue of method
|
|
|
|
*/
|
2002-03-01 13:31:50 +01:00
|
|
|
function ExecMethod($method, $functionparams = '_UNDEF_', $loglevel = 3, $classparams = '_UNDEF_')
|
|
|
|
{
|
|
|
|
/* Need to make sure this is working against a single dimensional object */
|
|
|
|
$partscount = count(explode('.',$method)) - 1;
|
|
|
|
if ($partscount == 2)
|
|
|
|
{
|
|
|
|
list($appname,$classname,$functionname) = explode(".", $method);
|
|
|
|
if (!is_object($GLOBALS[$classname]))
|
|
|
|
{
|
2005-11-09 14:54:36 +01:00
|
|
|
// please note: no reference assignment (=&) here, as $GLOBALS is a reference itself!!!
|
2002-03-01 13:31:50 +01:00
|
|
|
if ($classparams != '_UNDEF_' && ($classparams || $classparams != 'True'))
|
|
|
|
{
|
2005-11-09 14:54:36 +01:00
|
|
|
$GLOBALS[$classname] = CreateObject($appname.'.'.$classname, $classparams);
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-09 14:54:36 +01:00
|
|
|
$GLOBALS[$classname] = CreateObject($appname.'.'.$classname);
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-16 18:34:45 +02:00
|
|
|
if (!method_exists($GLOBALS[$classname],$functionname))
|
|
|
|
{
|
2003-10-19 20:25:14 +02:00
|
|
|
echo "<p><b>".function_backtrace()."</b>: no methode '$functionname' in class '$classname'</p>\n";
|
2003-10-16 18:34:45 +02:00
|
|
|
return False;
|
|
|
|
}
|
2002-03-01 13:31:50 +01:00
|
|
|
if ((is_array($functionparams) || $functionparams != '_UNDEF_') && ($functionparams || $functionparams != 'True'))
|
|
|
|
{
|
|
|
|
return $GLOBALS[$classname]->$functionname($functionparams);
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
return $GLOBALS[$classname]->$functionname();
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
/* if the $method includes a parent class (multi-dimensional) then we have to work from it */
|
2008-04-18 16:59:59 +02:00
|
|
|
/* RalfBecker: let's check if this is still in use, I don't think so:
|
2002-03-01 13:31:50 +01:00
|
|
|
elseif ($partscount >= 3)
|
|
|
|
{
|
|
|
|
$GLOBALS['methodparts'] = explode(".", $method);
|
|
|
|
$classpartnum = $partscount - 1;
|
|
|
|
$appname = $GLOBALS['methodparts'][0];
|
|
|
|
$classname = $GLOBALS['methodparts'][$classpartnum];
|
|
|
|
$functionname = $GLOBALS['methodparts'][$partscount];
|
2008-03-21 21:11:59 +01:00
|
|
|
// Now we clear these out of the array so that we can do a proper
|
|
|
|
// loop and build the $parentobject
|
2002-03-01 13:31:50 +01:00
|
|
|
unset ($GLOBALS['methodparts'][0]);
|
|
|
|
unset ($GLOBALS['methodparts'][$classpartnum]);
|
|
|
|
unset ($GLOBALS['methodparts'][$partscount]);
|
|
|
|
reset ($GLOBALS['methodparts']);
|
|
|
|
$firstparent = 'True';
|
2004-01-02 06:47:24 +01:00
|
|
|
foreach($GLOBALS['methodparts'] as $val)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
|
|
|
if ($firstparent == 'True')
|
|
|
|
{
|
|
|
|
$parentobject = '$GLOBALS["'.$val.'"]';
|
|
|
|
$firstparent = False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$parentobject .= '->'.$val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($GLOBALS['methodparts']);
|
|
|
|
$code = '$isobject = is_object('.$parentobject.'->'.$classname.');';
|
|
|
|
eval ($code);
|
|
|
|
if (!$isobject)
|
|
|
|
{
|
|
|
|
if ($classparams != '_UNDEF_' && ($classparams || $classparams != 'True'))
|
|
|
|
{
|
|
|
|
if (is_string($classparams))
|
|
|
|
{
|
2005-11-09 13:44:32 +01:00
|
|
|
eval($parentobject.'->'.$classname.' =& CreateObject("'.$appname.'.'.$classname.'", "'.$classparams.'");');
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-09 13:44:32 +01:00
|
|
|
eval($parentobject.'->'.$classname.' =& CreateObject("'.$appname.'.'.$classname.'", '.$classparams.');');
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-09 13:44:32 +01:00
|
|
|
eval($parentobject.'->'.$classname.' =& CreateObject("'.$appname.'.'.$classname.'");');
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($functionparams != '_UNDEF_' && ($functionparams || $functionparams != 'True'))
|
|
|
|
{
|
|
|
|
eval('$returnval = '.$parentobject.'->'.$classname.'->'.$functionname.'('.$functionparams.');');
|
|
|
|
return $returnval;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eval('$returnval = '.$parentobject.'->'.$classname.'->'.$functionname.'();');
|
|
|
|
return $returnval;
|
|
|
|
}
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
*/
|
|
|
|
return "<p>ExecMethod('$method'): error in parts!<br />".function_backtrace()."</p>\n";
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* duplicates the result of copying an object under php3/4 even when using php5
|
|
|
|
*
|
|
|
|
* This is critical when looping on db object output and updating or inserting to the database using a copy of the db object. This was first added to GroupWhere
|
2008-04-18 16:59:59 +02:00
|
|
|
*
|
2005-11-09 13:44:32 +01:00
|
|
|
* @deprecated use $copy = clone($obj);
|
|
|
|
* @author milosch
|
|
|
|
* @param $a - Source Object
|
|
|
|
* @param $b - Target Object (copy)
|
|
|
|
*/
|
2003-10-16 12:37:31 +02:00
|
|
|
function copyobj($a,&$b)
|
|
|
|
{
|
|
|
|
if(floor(phpversion()) > 4)
|
|
|
|
{
|
2004-10-19 16:54:57 +02:00
|
|
|
$b = clone($a);
|
2003-10-16 12:37:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$b = $a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* Return a properly formatted account_id.
|
|
|
|
*
|
|
|
|
* @author skeeter
|
|
|
|
* This function will return a properly formatted account_id. This can take either a name or an account_id as paramters. If a name is provided it will return the associated id.
|
|
|
|
* $account_id = get_account_id($accountid);
|
|
|
|
* @param int/string $account_id either a name or an id
|
|
|
|
* @param int/string $default_id either a name or an id
|
|
|
|
* @return int account_id
|
|
|
|
*/
|
2002-03-01 13:31:50 +01:00
|
|
|
function get_account_id($account_id = '',$default_id = '')
|
|
|
|
{
|
|
|
|
if (gettype($account_id) == 'integer')
|
|
|
|
{
|
|
|
|
return $account_id;
|
|
|
|
}
|
|
|
|
elseif ($account_id == '')
|
|
|
|
{
|
|
|
|
if ($default_id == '')
|
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
return (isset($GLOBALS['egw_info']['user']['account_id'])?$GLOBALS['egw_info']['user']['account_id']:0);
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
elseif (is_string($default_id))
|
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
return $GLOBALS['egw']->accounts->name2id($default_id);
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
2003-12-10 12:45:03 +01:00
|
|
|
return (int)$default_id;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
elseif (is_string($account_id))
|
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
if($GLOBALS['egw']->accounts->exists((int)$account_id) == True)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2003-12-10 12:45:03 +01:00
|
|
|
return (int)$account_id;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-04 21:48:05 +01:00
|
|
|
return $GLOBALS['egw']->accounts->name2id($account_id);
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* sets the file system seperator depending on OS
|
|
|
|
*
|
|
|
|
* This is completely unnecessary, as you can use forward slashes in php under every OS -- RalfBecker 2005/11/09
|
|
|
|
*
|
|
|
|
* @return file system separator
|
|
|
|
*/
|
2002-03-01 13:31:50 +01:00
|
|
|
function filesystem_separator()
|
|
|
|
{
|
2004-01-28 14:34:47 +01:00
|
|
|
if(PHP_OS == 'Windows' || PHP_OS == 'OS/2' || PHP_OS == 'WINNT')
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
|
|
|
return '\\';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* print an array or object as pre-formatted html
|
|
|
|
*
|
|
|
|
* @param mixed $array
|
|
|
|
* @param boolean $print=true print or return the content
|
|
|
|
* @return string if !$print
|
|
|
|
*/
|
2002-04-06 17:13:51 +02:00
|
|
|
function _debug_array($array,$print=True)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2006-10-03 17:16:42 +02:00
|
|
|
$output = '<pre>'.print_r($array,true)."</pre>\n";
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2006-10-03 17:16:42 +02:00
|
|
|
if ($print)
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2006-10-03 17:16:42 +02:00
|
|
|
echo $output;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
2002-04-06 17:13:51 +02:00
|
|
|
else
|
2002-03-01 13:31:50 +01:00
|
|
|
{
|
2006-10-03 17:16:42 +02:00
|
|
|
return $output;
|
2002-03-01 13:31:50 +01:00
|
|
|
}
|
|
|
|
}
|
2002-03-16 03:56:57 +01:00
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* eGW version checking, is eGW version in $a < $b
|
|
|
|
*
|
|
|
|
* @param string $a egw version number to check if less than $b
|
|
|
|
* @param string $b egw version number to check $a against
|
|
|
|
* @return boolean True if $a < $b
|
|
|
|
*/
|
2002-03-16 03:56:57 +01:00
|
|
|
function alessthanb($a,$b,$DEBUG=False)
|
|
|
|
{
|
|
|
|
$num = array('1st','2nd','3rd','4th');
|
|
|
|
|
|
|
|
if ($DEBUG)
|
|
|
|
{
|
2004-01-02 06:47:24 +01:00
|
|
|
echo'<br>Input values: ' . 'A="'.$a.'", B="'.$b.'"';
|
2002-03-16 03:56:57 +01:00
|
|
|
}
|
2003-12-10 12:45:03 +01:00
|
|
|
$newa = str_replace('pre','.',$a);
|
|
|
|
$newb = str_replace('pre','.',$b);
|
2002-03-16 03:56:57 +01:00
|
|
|
$testa = explode('.',$newa);
|
|
|
|
if(@$testa[1] == '')
|
|
|
|
{
|
|
|
|
$testa[1] = 0;
|
|
|
|
}
|
|
|
|
if(@$testa[3] == '')
|
|
|
|
{
|
|
|
|
$testa[3] = 0;
|
|
|
|
}
|
|
|
|
$testb = explode('.',$newb);
|
|
|
|
if(@$testb[1] == '')
|
|
|
|
{
|
|
|
|
$testb[1] = 0;
|
|
|
|
}
|
|
|
|
if(@$testb[3] == '')
|
|
|
|
{
|
|
|
|
$testb[3] = 0;
|
|
|
|
}
|
|
|
|
$less = 0;
|
|
|
|
|
|
|
|
for ($i=0;$i<count($testa);$i++)
|
|
|
|
{
|
2003-12-10 12:45:03 +01:00
|
|
|
if ($DEBUG) { echo'<br>Checking if '. (int)$testa[$i] . ' is less than ' . (int)$testb[$i] . ' ...'; }
|
|
|
|
if ((int)$testa[$i] < (int)$testb[$i])
|
2002-03-16 03:56:57 +01:00
|
|
|
{
|
|
|
|
if ($DEBUG) { echo ' yes.'; }
|
|
|
|
$less++;
|
|
|
|
if ($i<3)
|
|
|
|
{
|
|
|
|
/* Ensure that this is definitely smaller */
|
|
|
|
if ($DEBUG) { echo" This is the $num[$i] octet, so A is definitely less than B."; }
|
|
|
|
$less = 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-10 12:45:03 +01:00
|
|
|
elseif((int)$testa[$i] > (int)$testb[$i])
|
2002-03-16 03:56:57 +01:00
|
|
|
{
|
|
|
|
if ($DEBUG) { echo ' no.'; }
|
|
|
|
$less--;
|
|
|
|
if ($i<2)
|
|
|
|
{
|
|
|
|
/* Ensure that this is definitely greater */
|
|
|
|
if ($DEBUG) { echo" This is the $num[$i] octet, so A is definitely greater than B."; }
|
|
|
|
$less = -5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo ' no, they are equal.'; }
|
|
|
|
$less = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($DEBUG) { echo '<br>Check value is: "'.$less.'"'; }
|
|
|
|
if ($less>0)
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo '<br>A is less than B'; }
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
elseif($less<0)
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo '<br>A is greater than B'; }
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo '<br>A is equal to B'; }
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* eGW version checking, is eGW version in $a > $b
|
|
|
|
*
|
|
|
|
* @param string $a eGW version number to check if more than $b
|
|
|
|
* @param string $b eGW version number to check check $a against
|
|
|
|
* @return boolean True if $a > $b
|
|
|
|
*/
|
2002-03-16 03:56:57 +01:00
|
|
|
function amorethanb($a,$b,$DEBUG=False)
|
|
|
|
{
|
|
|
|
$num = array('1st','2nd','3rd','4th');
|
|
|
|
|
|
|
|
if ($DEBUG)
|
|
|
|
{
|
2004-01-02 06:47:24 +01:00
|
|
|
echo'<br>Input values: ' . 'A="'.$a.'", B="'.$b.'"';
|
2002-03-16 03:56:57 +01:00
|
|
|
}
|
2003-12-10 12:45:03 +01:00
|
|
|
$newa = str_replace('pre','.',$a);
|
|
|
|
$newb = str_replace('pre','.',$b);
|
2002-03-16 03:56:57 +01:00
|
|
|
$testa = explode('.',$newa);
|
|
|
|
if($testa[3] == '')
|
|
|
|
{
|
|
|
|
$testa[3] = 0;
|
|
|
|
}
|
|
|
|
$testb = explode('.',$newb);
|
|
|
|
if($testb[3] == '')
|
|
|
|
{
|
|
|
|
$testb[3] = 0;
|
|
|
|
}
|
|
|
|
$less = 0;
|
|
|
|
|
|
|
|
for ($i=0;$i<count($testa);$i++)
|
|
|
|
{
|
2003-12-10 12:45:03 +01:00
|
|
|
if ($DEBUG) { echo'<br>Checking if '. (int)$testa[$i] . ' is more than ' . (int)$testb[$i] . ' ...'; }
|
|
|
|
if ((int)$testa[$i] > (int)$testb[$i])
|
2002-03-16 03:56:57 +01:00
|
|
|
{
|
|
|
|
if ($DEBUG) { echo ' yes.'; }
|
|
|
|
$less++;
|
|
|
|
if ($i<3)
|
|
|
|
{
|
|
|
|
/* Ensure that this is definitely greater */
|
|
|
|
if ($DEBUG) { echo" This is the $num[$i] octet, so A is definitely greater than B."; }
|
|
|
|
$less = 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-10 12:45:03 +01:00
|
|
|
elseif((int)$testa[$i] < (int)$testb[$i])
|
2002-03-16 03:56:57 +01:00
|
|
|
{
|
|
|
|
if ($DEBUG) { echo ' no.'; }
|
|
|
|
$less--;
|
|
|
|
if ($i<2)
|
|
|
|
{
|
|
|
|
/* Ensure that this is definitely smaller */
|
|
|
|
if ($DEBUG) { echo" This is the $num[$i] octet, so A is definitely less than B."; }
|
|
|
|
$less = -5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo ' no, they are equal.'; }
|
|
|
|
$less = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($DEBUG) { echo '<br>Check value is: "'.$less.'"'; }
|
|
|
|
if ($less>0)
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo '<br>A is greater than B'; }
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
elseif($less<0)
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo '<br>A is less than B'; }
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo '<br>A is equal to B'; }
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* prepend a prefix to an array of table names
|
|
|
|
*
|
|
|
|
* @author Adam Hull (aka fixe) - No copyright claim
|
|
|
|
* @param $prefix the string to be prepended
|
|
|
|
* @param $tables and array of tables to have the prefix prepended to
|
|
|
|
* @return array of table names with the prefix prepended
|
|
|
|
*/
|
2003-08-28 16:31:11 +02:00
|
|
|
function prepend_tables_prefix($prefix,$tables)
|
|
|
|
{
|
|
|
|
foreach($tables as $key => $value)
|
|
|
|
{
|
|
|
|
$tables[$key] = $prefix.$value;
|
|
|
|
}
|
|
|
|
return $tables;
|
|
|
|
}
|
2003-10-16 18:34:45 +02:00
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* backtrace of the calling functions for php4.3+ else menuaction/scriptname
|
|
|
|
*
|
|
|
|
* @author RalfBecker-AT-outdoor-training.de
|
|
|
|
* @param int $remove=0 number of levels to remove
|
|
|
|
* @return string function-names separated by slashes (beginning with the calling function not this one)
|
|
|
|
*/
|
2003-10-19 20:25:14 +02:00
|
|
|
function function_backtrace($remove=0)
|
2003-10-16 18:34:45 +02:00
|
|
|
{
|
|
|
|
if (function_exists('debug_backtrace'))
|
|
|
|
{
|
|
|
|
$backtrace = debug_backtrace();
|
2005-07-17 23:00:49 +02:00
|
|
|
//echo "function_backtrace($remove)<pre>".print_r($backtrace,True)."</pre>\n";
|
2003-10-16 18:34:45 +02:00
|
|
|
foreach($backtrace as $level)
|
|
|
|
{
|
2003-10-19 20:25:14 +02:00
|
|
|
if ($remove-- < 0)
|
|
|
|
{
|
2005-07-17 23:00:49 +02:00
|
|
|
$ret[] = (isset($level['class'])?$level['class'].'::':'').$level['function'].
|
2008-04-18 16:59:59 +02:00
|
|
|
(!$level['class'] && !is_object($level['args'][0]) && $level['function'] != 'unserialize' ?
|
|
|
|
'('.substr(str_replace(EGW_SERVER_ROOT,'',$level['args'][0]),0,64).')' : '');
|
2003-10-19 20:25:14 +02:00
|
|
|
}
|
2003-10-16 18:34:45 +02:00
|
|
|
}
|
2005-07-17 23:00:49 +02:00
|
|
|
if (is_array($ret))
|
|
|
|
{
|
|
|
|
return implode(' / ',$ret);
|
|
|
|
}
|
2003-10-16 18:34:45 +02:00
|
|
|
}
|
2005-03-04 21:48:05 +01:00
|
|
|
return $_GET['menuaction'] ? $_GET['menuaction'] : str_replace(EGW_SERVER_ROOT,'',$_SERVER['SCRIPT_FILENAME']);
|
2003-10-16 18:34:45 +02:00
|
|
|
}
|
2004-04-04 19:58:00 +02:00
|
|
|
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* check $_REQUEST data for XSS, vars containing script tags are moved to $GLOBALS['egw_unset_vars']
|
|
|
|
*
|
2008-04-18 16:59:59 +02:00
|
|
|
* @internal
|
2005-11-09 13:44:32 +01:00
|
|
|
* @param array &$var reference of array to check
|
|
|
|
* @param string $name='' name of the array
|
|
|
|
*/
|
2004-08-24 12:45:07 +02:00
|
|
|
function _check_script_tag(&$var,$name='')
|
2004-08-22 16:14:38 +02:00
|
|
|
{
|
|
|
|
if (is_array($var))
|
|
|
|
{
|
|
|
|
foreach($var as $key => $val)
|
|
|
|
{
|
|
|
|
if (is_array($val))
|
|
|
|
{
|
2004-08-24 12:45:07 +02:00
|
|
|
_check_script_tag($var[$key],$name.'['.$key.']');
|
2004-08-22 16:14:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-15 16:36:44 +01:00
|
|
|
if (preg_match('/<\/?[^>]*(iframe|script|onabort|onblur|onchange|onclick|ondblclick|onerror|onfocus|onkeydown|onkeypress|onkeyup|onload|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onreset|onselect|onsubmit|onunload|javascript)+[^>]*>/i',$val))
|
2004-08-22 16:14:38 +02:00
|
|
|
{
|
2005-03-15 16:36:44 +01:00
|
|
|
//echo "<p>*** _check_script_tag($name): unset(${name}[$key]) ***</p>\n";
|
|
|
|
$GLOBALS['egw_unset_vars'][$name.'['.$key.']'] =& $var[$key];
|
2004-08-22 16:14:38 +02:00
|
|
|
unset($var[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-24 22:01:49 +02:00
|
|
|
// in case some stupid old code expects the array-pointer to be at the start of the array
|
|
|
|
reset($var);
|
2004-08-22 16:14:38 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2005-03-15 16:36:44 +01:00
|
|
|
foreach(array('_GET','_POST','_REQUEST','HTTP_GET_VARS','HTTP_POST_VARS') as $n => $where)
|
2004-04-04 19:58:00 +02:00
|
|
|
{
|
|
|
|
$pregs = array(
|
2006-03-09 23:33:06 +01:00
|
|
|
'order' => '/^[a-zA-Z0-9_,]*$/',
|
2004-04-20 04:43:11 +02:00
|
|
|
'sort' => '/^(ASC|DESC|asc|desc|0|1|2|3|4|5|6|7){0,1}$/',
|
2004-04-04 19:58:00 +02:00
|
|
|
);
|
|
|
|
foreach(array('order','sort') as $name)
|
|
|
|
{
|
2004-05-03 12:39:42 +02:00
|
|
|
if (isset($GLOBALS[$where][$name]) && !is_array($GLOBALS[$where][$name]) && !preg_match($pregs[$name],$GLOBALS[$where][$name]))
|
2004-04-04 19:58:00 +02:00
|
|
|
{
|
|
|
|
$GLOBALS[$where][$name] = '';
|
|
|
|
}
|
|
|
|
}
|
2005-03-15 16:36:44 +01:00
|
|
|
// do the check for script-tags only for _GET and _POST or if we found something in _GET and _POST
|
|
|
|
// speeds up the execusion a bit
|
|
|
|
if (is_array($GLOBALS[$where]) && ($n < 2 || is_array($GLOBALS['egw_unset_vars'])))
|
2004-08-22 16:14:38 +02:00
|
|
|
{
|
2004-08-24 12:45:07 +02:00
|
|
|
_check_script_tag($GLOBALS[$where],$where);
|
2004-08-22 16:14:38 +02:00
|
|
|
}
|
2004-04-04 19:58:00 +02:00
|
|
|
}
|
2005-03-15 16:36:44 +01:00
|
|
|
//if (is_array($GLOBALS['egw_unset_vars'])) { echo "egw_unset_vars=<pre>".htmlspecialchars(print_r($GLOBALS['egw_unset_vars'],true))."</pre>"; exit; }
|
|
|
|
|
2006-10-03 17:16:42 +02:00
|
|
|
// neutralises register_globals On, which is not used by eGW
|
|
|
|
// some code from the hardend php project: http://www.hardened-php.net/articles/PHPUG-PHP-Sicherheit-Parametermanipulationen.pdf
|
|
|
|
if (ini_get('register_globals'))
|
|
|
|
{
|
|
|
|
function unregister_globals()
|
|
|
|
{
|
|
|
|
// protect against GLOBALS overwrite or setting egw_info
|
|
|
|
if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS']) || isset($_REQUEST['egw_info']) || isset($_FILES['egw_info']))
|
|
|
|
{
|
|
|
|
die('GLOBALS overwrite detected!!!');
|
|
|
|
}
|
|
|
|
// unregister all globals
|
|
|
|
$noUnset = array('GLOBALS','_GET','_POST','_COOKIE','_SERVER','_ENV','_FILES','xajax');
|
|
|
|
foreach(array_unique(array_merge(
|
|
|
|
array_keys($_GET),array_keys($_POST),array_keys($_COOKIE),array_keys($_SERVER),array_keys($_ENV),array_keys($_FILES),
|
|
|
|
isset($_SESSION) && is_array($_SESSION) ? array_keys($_SESSION) : array())) as $k)
|
|
|
|
{
|
|
|
|
if (!in_array($k,$noUnset) && isset($GLOBALS[$k]))
|
|
|
|
{
|
|
|
|
unset($GLOBALS[$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unregister_globals();
|
|
|
|
}
|
|
|
|
|
2004-10-19 16:54:57 +02:00
|
|
|
if(floor(phpversion()) <= 4)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* clone function for php4, use as $new_obj = clone($old_obj);
|
|
|
|
*/
|
2004-10-21 20:12:11 +02:00
|
|
|
eval('
|
2004-10-19 16:54:57 +02:00
|
|
|
function clone($obj)
|
|
|
|
{
|
|
|
|
return $obj;
|
|
|
|
}
|
2004-10-21 20:12:11 +02:00
|
|
|
');
|
2004-10-19 16:54:57 +02:00
|
|
|
}
|
2005-07-17 23:00:49 +02:00
|
|
|
|
|
|
|
if (!function_exists('lang')) // setup declares an own version
|
|
|
|
{
|
2005-11-09 13:44:32 +01:00
|
|
|
/**
|
|
|
|
* function to handle multilanguage support
|
|
|
|
*
|
|
|
|
* @param string $key message in englich with %1, %2, ... placeholders
|
|
|
|
* @param string $vars=null multiple values to replace the placeholders
|
|
|
|
* @return string translated message with placeholders replaced
|
|
|
|
*/
|
|
|
|
function lang($key,$vars=null)
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2006-02-24 04:06:40 +01:00
|
|
|
if(!is_array($vars))
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
|
|
|
$vars = func_get_args();
|
|
|
|
array_shift($vars); // remove $key
|
|
|
|
}
|
2008-04-01 12:47:50 +02:00
|
|
|
return $GLOBALS['egw']->translation->translate($key,$vars);
|
|
|
|
}
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2008-04-01 12:47:50 +02:00
|
|
|
/**
|
|
|
|
* Translate message only if translation object is already loaded
|
2008-04-18 16:59:59 +02:00
|
|
|
*
|
2008-04-01 12:47:50 +02:00
|
|
|
* This function is usefull for exception handlers or early stages of the initialisation of the egw object,
|
|
|
|
* as calling lang would try to load the translations, evtl. cause more errors, eg. because there's no db-connection.
|
|
|
|
*
|
|
|
|
* @param string $key message in englich with %1, %2, ... placeholders
|
|
|
|
* @param string $vars=null multiple values to replace the placeholders
|
|
|
|
* @return string translated message with placeholders replaced
|
|
|
|
*/
|
|
|
|
function try_lang($key,$vars=null)
|
|
|
|
{
|
|
|
|
static $varnames = array('%1','%2','%3','%4');
|
|
|
|
|
|
|
|
if(!is_array($vars))
|
|
|
|
{
|
|
|
|
$vars = func_get_args();
|
|
|
|
array_shift($vars); // remove $key
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
return is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->translations) ?
|
2008-04-01 12:47:50 +02:00
|
|
|
$GLOBALS['egw']->translation->translate($key,$vars) :
|
|
|
|
str_replace($varnames,$vars,$key);
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2007-12-06 09:00:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* php5 autoload function for eGroupWare understanding the following naming schema:
|
|
|
|
* 1. new (prefered) nameing schema: app_class_something loading app/inc/class.class_something.inc.php
|
|
|
|
* 2. API classes: classname loading phpgwapi/inc/class.classname.inc.php
|
|
|
|
* 2a.API classes containing multiple classes per file eg. egw_exception* in class.egw_exception.inc.php
|
|
|
|
* 3. eTemplate classes: classname loading etemplate/inc/class.classname.inc.php
|
|
|
|
* 4. classes of the current app: classname loading $GLOBALS['egw_info']['flags']['currentapp']/inc/class.classname.inc.php
|
|
|
|
*
|
|
|
|
* @param string $class name of class to load
|
|
|
|
*/
|
|
|
|
function __autoload($class)
|
|
|
|
{
|
2008-01-11 13:33:17 +01:00
|
|
|
$components = explode('_',$class);
|
2008-01-19 06:28:33 +01:00
|
|
|
$app = array_shift($components);
|
|
|
|
$baseclass = $components[0];
|
2007-12-06 09:00:41 +01:00
|
|
|
// classes using the new naming schema app_class_name, eg. admin_cmd
|
|
|
|
if (file_exists($file = EGW_INCLUDE_ROOT.'/'.$app.'/inc/class.'.$class.'.inc.php') ||
|
|
|
|
// classes using the new naming schema app_class_name, eg. admin_cmd
|
|
|
|
file_exists($file = EGW_INCLUDE_ROOT.'/'.$app.'/inc/class.'.$app.'_'.$baseclass.'.inc.php') ||
|
|
|
|
// eGW api classes using the old naming schema, eg. html
|
|
|
|
file_exists($file = EGW_API_INC.'/class.'.$class.'.inc.php') ||
|
|
|
|
// eGW api classes using the old naming schema, eg. html
|
|
|
|
file_exists($file = EGW_API_INC.'/class.'.$app.'_'.$baseclass.'.inc.php') ||
|
|
|
|
// eGW eTemplate classes using the old naming schema, eg. etemplate
|
|
|
|
file_exists($file = EGW_INCLUDE_ROOT.'/etemplate/inc/class.'.$class.'.inc.php') ||
|
|
|
|
// classes of the current application using the old naming schema
|
|
|
|
file_exists($file = EGW_INCLUDE_ROOT.'/'.$GLOBALS['egw_info']['flags']['currentapp'].'/inc/class.'.$class.'.inc.php'))
|
|
|
|
{
|
|
|
|
//error_log("autoloaded class $class from $file");
|
|
|
|
include_once($file);
|
2008-04-18 16:59:59 +02:00
|
|
|
}
|
2008-01-19 06:28:33 +01:00
|
|
|
else
|
|
|
|
{
|
2008-03-07 11:18:17 +01:00
|
|
|
if (is_array($GLOBALS['egw_info']['apps'])) {
|
|
|
|
foreach($GLOBALS['egw_info']['apps'] as $lapp => $appvalue)
|
2008-01-19 06:28:33 +01:00
|
|
|
{
|
2008-03-07 11:18:17 +01:00
|
|
|
if (file_exists($file = EGW_INCLUDE_ROOT.'/'.$lapp.'/inc/class.'.$class.'.inc.php'))
|
|
|
|
{
|
|
|
|
#echo "$lapp,$class<br>";
|
|
|
|
include_once($file);
|
|
|
|
}
|
2008-01-11 13:33:17 +01:00
|
|
|
}
|
|
|
|
}
|
2007-12-06 09:00:41 +01:00
|
|
|
}
|
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2007-12-06 09:00:41 +01:00
|
|
|
/**
|
|
|
|
* Fail a little bit more gracefully then an uncought exception
|
2008-04-18 16:59:59 +02:00
|
|
|
*
|
2007-12-06 09:00:41 +01:00
|
|
|
* Does NOT return
|
|
|
|
*
|
|
|
|
* @param Exception $e
|
|
|
|
*/
|
|
|
|
function egw_exception_handler(Exception $e)
|
|
|
|
{
|
|
|
|
if ($e instanceof egw_exception_no_permission)
|
|
|
|
{
|
2008-04-01 12:47:50 +02:00
|
|
|
$headline = try_lang('Permission denied!');
|
2007-12-06 09:00:41 +01:00
|
|
|
}
|
|
|
|
elseif ($e instanceof egw_exception_db)
|
|
|
|
{
|
2008-04-01 12:47:50 +02:00
|
|
|
$headline = try_lang('Database error');
|
2007-12-06 09:00:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-01 12:47:50 +02:00
|
|
|
$headline = try_lang('An error happend');
|
2007-12-06 09:00:41 +01:00
|
|
|
}
|
2008-01-19 06:28:33 +01:00
|
|
|
$message = '<h3>'.$headline."</h3>\n".
|
2007-12-06 09:00:41 +01:00
|
|
|
'<pre><b>'.$e->getMessage()."</b>\n\n".
|
2008-01-19 06:28:33 +01:00
|
|
|
$e->getTraceAsString()."</pre>\n";
|
2007-12-06 09:00:41 +01:00
|
|
|
|
2008-04-01 12:33:54 +02:00
|
|
|
if (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->session))
|
2008-01-19 06:28:33 +01:00
|
|
|
{
|
2008-04-18 16:59:59 +02:00
|
|
|
'<p><a href="'.$GLOBALS['egw']->link('/index.php').'">'.try_lang('Click here to resume your eGroupWare Session.').'</a></p>';
|
2008-01-19 06:28:33 +01:00
|
|
|
}
|
2008-04-01 12:33:54 +02:00
|
|
|
if (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->framework))
|
2008-01-19 06:28:33 +01:00
|
|
|
{
|
|
|
|
$GLOBALS['egw']->framework->render($message,$headline);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo "<html>\n<head>\n<title>$headline</title>\n</head>\n<body>\n$message\n</body>\n</html>\n";
|
|
|
|
}
|
2008-04-01 12:33:54 +02:00
|
|
|
if (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->common))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
|
|
|
}
|
|
|
|
exit;
|
2007-12-06 09:00:41 +01:00
|
|
|
}
|
2008-04-18 16:59:59 +02:00
|
|
|
|
2007-12-06 09:00:41 +01:00
|
|
|
set_exception_handler('egw_exception_handler');
|