egroupware/setup/inc/functions.inc.php

180 lines
5.6 KiB
PHP
Raw Normal View History

2001-07-30 17:59:25 +02:00
<?php
/**************************************************************************\
2004-01-27 21:49:25 +01:00
* eGroupWare - Setup *
* http://www.egroupware.org *
2001-07-30 17:59:25 +02:00
* -------------------------------------------- *
* This file written by Joseph Engo<jengo@phpgroupware.org> *
* and Dan Kuykendall<seek3r@phpgroupware.org> *
* and Mark Peters<skeeter@phpgroupware.org> *
2004-01-27 21:49:25 +01:00
* and Miles Lott<milosch@groupwhere.org> *
* -------------------------------------------- *
2001-07-30 17:59:25 +02:00
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
error_reporting(error_reporting() & ~E_NOTICE);
// for an old header, we need to setup the reference before including it
$GLOBALS['phpgw_info'] =& $GLOBALS['egw_info'];
2001-07-30 17:59:25 +02:00
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'];
if (!function_exists('version_compare'))//version_compare() is only available in PHP4.1+
{
2003-10-10 01:08:04 +02:00
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'))
2001-07-30 17:59:25 +02:00
{
define('EGW_SERVER_ROOT','..');
define('EGW_INCLUDE_ROOT','..');
2001-07-30 17:59:25 +02:00
define('PHPGW_SERVER_ROOT','..');
define('PHPGW_INCLUDE_ROOT','..');
}
require(EGW_INCLUDE_ROOT . '/phpgwapi/inc/common_functions.inc.php');
2001-07-30 17:59:25 +02:00
define('SEP',filesystem_separator());
/**
* Checks if a directory exists, is writable by the webserver and optionaly is in the docroot
*
* @param string $dir path
* @param string &$msg error-msg: 'does not exist', 'is not writeable by the webserver' or 'is in the webservers docroot' (run through lang)
* @param boolean $check_in_docroot=false run an optional in docroot check
* @return boolean
*/
function check_dir($dir,&$msg,$check_in_docroot=false)
{
if (!@is_dir($dir) && !(@is_writeable(dirname($dir)) && @mkdir($dir,0700,true)))
{
$msg = lang('does not exist');
return false;
}
if (!@is_writeable($dir))
{
$msg = lang('is not writeable by the webserver');
return false;
}
if ($check_in_docroot)
{
$docroots = array(EGW_SERVER_ROOT,$_SERVER['DOCUMENT_ROOT']);
$dir = realpath($dir);
foreach ($docroots as $docroot)
{
$len = strlen($docroot);
if ($docroot == substr($dir,0,$len))
{
$rest = substr($dir,$len);
if (!strlen($rest) || $rest[0] == DIRECTORY_SEPARATOR)
{
$msg = lang('is in the webservers docroot');
return false;
}
}
}
}
return true;
}
/**
* function to handle multilanguage support
*
*/
function lang($key,$vars=null)
2001-07-30 17:59:25 +02:00
{
if(!is_array($vars))
{
$vars = func_get_args();
array_shift($vars); // remove $key
}
return $GLOBALS['egw_setup']->translation->translate("$key", $vars);
2001-07-30 17:59:25 +02:00
}
/**
* returns array of languages we support, with enabled set to True if the lang file exists
*/
2001-07-30 17:59:25 +02:00
function get_langs()
{
$f = fopen('./lang/languages','rb');
while($line = fgets($f,200))
2001-07-30 17:59:25 +02:00
{
list($x,$y) = split("\t",$line);
$languages[$x]['lang'] = trim($x);
$languages[$x]['descr'] = trim($y);
$languages[$x]['available'] = False;
}
fclose($f);
$d = dir('./lang');
while($file=$d->read())
2001-07-30 17:59:25 +02:00
{
if(preg_match('/^phpgw_([-a-z]+).lang$/i',$file,$matches))
2001-07-30 17:59:25 +02:00
{
$languages[$matches[1]]['available'] = True;
2001-07-30 17:59:25 +02:00
}
}
$d->close();
//print_r($languages);
return $languages;
}
function lang_select($onChange=False,$ConfigLang='')
2001-07-30 17:59:25 +02:00
{
if (!$ConfigLang)
{
$ConfigLang = get_var('ConfigLang',Array('POST','COOKIE'));
}
$select = '<select name="ConfigLang"'.($onChange ? ' onchange="this.form.submit();"' : '').'>' . "\n";
2001-07-30 17:59:25 +02:00
$languages = get_langs();
2004-07-10 11:25:53 +02:00
usort($languages,create_function('$a,$b','return strcmp(@$a[\'descr\'],@$b[\'descr\']);'));
foreach($languages as $data)
2001-07-30 17:59:25 +02:00
{
if($data['available'] && !empty($data['lang']))
2001-07-30 17:59:25 +02:00
{
$selected = '';
$short = substr($data['lang'],0,2);
if ($short == $ConfigLang || empty($ConfigLang) && $short == substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2))
2001-07-30 17:59:25 +02:00
{
$selected = ' selected="selected"';
2001-07-30 17:59:25 +02:00
}
$select .= '<option value="' . $data['lang'] . '"' . $selected . '>' . $data['descr'] . '</option>' . "\n";
}
}
$select .= '</select>' . "\n";
return $select;
}
if(file_exists(EGW_SERVER_ROOT.'/phpgwapi/setup/setup.inc.php'))
2001-07-30 17:59:25 +02:00
{
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'];
2001-07-30 17:59:25 +02:00
}
else
{
$GLOBALS['egw_info']['server']['versions']['phpgwapi'] = 'Undetected';
2001-07-30 17:59:25 +02:00
}
$GLOBALS['egw_info']['server']['app_images'] = 'templates/default/images';
2001-07-30 17:59:25 +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'];