egroupware/setup/inc/functions.inc.php

152 lines
4.2 KiB
PHP
Raw Normal View History

2001-07-30 17:59:25 +02:00
<?php
/**
* Setup
*
* @link http://www.egroupware.org
* @package setup
* @author Joseph Engo <jengo@phpgroupware.org>
* @author Dan Kuykendall <seek3r@phpgroupware.org>
* @author Mark Peters <skeeter@phpgroupware.org>
* @author Miles Lott <milos@groupwhere.org>
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
error_reporting(error_reporting() & ~E_NOTICE);
2008-08-13 09:19:32 +02:00
// for an old header, we need to setup the reference before including it
$GLOBALS['phpgw_info'] =& $GLOBALS['egw_info'];
$GLOBALS['egw_info'] = array(
'flags' => array(
'noheader' => True,
'nonavbar' => True,
'currentapp' => 'setup',
'noapi' => True
));
if(file_exists('../header.inc.php'))
{
include('../header.inc.php');
}
// for an old header we need to setup a reference for the domains
if (!is_array($GLOBALS['egw_domain'])) $GLOBALS['egw_domain'] =& $GLOBALS['phpgw_domain'];
2008-08-13 09:19:32 +02:00
if (!function_exists('version_compare'))//version_compare() is only available in PHP4.1+
{
echo 'eGroupWare now requires PHP 4.1 or greater.<br>';
echo 'Please contact your System Administrator';
exit;
}
/* If we included the header.inc.php, but it is somehow broken, cover ourselves... */
if(!defined('EGW_SERVER_ROOT') && !defined('EGW_INCLUDE_ROOT'))
{
if (defined('PHPGW_SERVER_ROOT') && defined('PHPGW_INCLUDE_ROOT')) // pre 1.2 install
{
2008-08-13 09:19:32 +02:00
define('EGW_SERVER_ROOT',PHPGW_SERVER_ROOT);
define('EGW_INCLUDE_ROOT',PHPGW_INCLUDE_ROOT);
}
2008-08-13 09:19:32 +02:00
else // no install
2001-07-30 17:59:25 +02:00
{
2008-08-13 09:19:32 +02:00
define('EGW_SERVER_ROOT','..');
define('EGW_INCLUDE_ROOT','..');
define('PHPGW_SERVER_ROOT','..');
define('PHPGW_INCLUDE_ROOT','..');
2001-07-30 17:59:25 +02:00
}
2008-08-13 09:19:32 +02:00
define('EGW_API_INC',EGW_SERVER_ROOT.'/phpgwapi/inc');
}
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
require_once(EGW_INCLUDE_ROOT . '/phpgwapi/inc/common_functions.inc.php');
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
define('SEP',filesystem_separator());
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
/**
* function to handle multilanguage support
*
*/
function lang($key,$vars=null)
{
if(!is_array($vars))
2001-07-30 17:59:25 +02:00
{
2008-08-13 09:19:32 +02:00
$vars = func_get_args();
array_shift($vars); // remove $key
2001-07-30 17:59:25 +02:00
}
2008-08-13 09:19:32 +02:00
return $GLOBALS['egw_setup']->translation->translate("$key", $vars);
}
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
/**
* returns array of languages we support, with enabled set to True if the lang file exists
*/
function get_langs()
{
$f = fopen('./lang/languages','rb');
while($line = fgets($f,200))
2001-07-30 17:59:25 +02:00
{
list($x,$y) = explode("\t",$line);
2008-08-13 09:19:32 +02:00
$languages[$x]['lang'] = trim($x);
$languages[$x]['descr'] = trim($y);
$languages[$x]['available'] = False;
}
fclose($f);
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
$d = dir('./lang');
while($file=$d->read())
{
if(preg_match('/^(php|e)gw_([-a-z]+).lang$/i',$file,$matches))
2001-07-30 17:59:25 +02:00
{
2008-08-13 09:19:32 +02:00
$languages[$matches[2]]['available'] = True;
2001-07-30 17:59:25 +02:00
}
}
2008-08-13 09:19:32 +02:00
$d->close();
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
//print_r($languages);
return $languages;
}
function lang_select($onChange=False,$ConfigLang='')
{
if (!$ConfigLang)
2001-07-30 17:59:25 +02:00
{
2008-08-13 09:19:32 +02:00
$ConfigLang = get_var('ConfigLang',Array('POST','COOKIE'));
}
$select = '<select name="ConfigLang"'.($onChange ? ' onchange="this.form.submit();"' : '').'>' . "\n";
$languages = get_langs();
usort($languages,create_function('$a,$b','return strcmp(@$a[\'descr\'],@$b[\'descr\']);'));
foreach($languages as $data)
{
if($data['available'] && !empty($data['lang']))
2001-07-30 17:59:25 +02:00
{
2008-08-13 09:19:32 +02:00
$short = substr($data['lang'],0,2);
if ($short == $ConfigLang || $data['lang'] == $ConfigLang || empty($ConfigLang) && $short == substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2))
{
$selected = ' selected';
}
else
2001-07-30 17:59:25 +02:00
{
2008-08-13 09:19:32 +02:00
$selected = '';
2001-07-30 17:59:25 +02:00
}
2008-08-13 09:19:32 +02:00
$select .= '<option value="' . $data['lang'] . '"' . $selected . '>' . $data['descr'] . '</option>' . "\n";
2001-07-30 17:59:25 +02:00
}
}
2008-08-13 09:19:32 +02:00
$select .= '</select>' . "\n";
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
return $select;
}
if(file_exists(EGW_SERVER_ROOT.'/phpgwapi/setup/setup.inc.php'))
{
include(EGW_SERVER_ROOT.'/phpgwapi/setup/setup.inc.php'); /* To set the current core version */
/* This will change to just use setup_info */
$GLOBALS['egw_info']['server']['versions']['current_header'] = $setup_info['phpgwapi']['versions']['current_header'];
}
else
{
$GLOBALS['egw_info']['server']['versions']['phpgwapi'] = 'Undetected';
}
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
$GLOBALS['egw_info']['server']['app_images'] = 'templates/default/images';
2001-07-30 17:59:25 +02:00
2008-08-13 09:19:32 +02:00
CreateObject('setup.setup',True,True); // setup constuctor assigns itself to $GLOBALS['egw_setup'], doing it twice fails on some php4
$GLOBALS['phpgw_setup'] =& $GLOBALS['egw_setup'];