2001-01-11 10:52:33 +01:00
< ? php
2005-11-02 12:45:52 +01:00
/************************************************************************** \
* eGroupWare API - Commononly used functions *
* This file written by Dan Kuykendall < seek3r @ phpgroupware . org > *
* and Joseph Engo < jengo @ phpgroupware . org > *
* and Mark Peters < skeeter @ phpgroupware . org > *
* and Lars Kneschke < lkneschke @ linux - at - work . de > *
* Functions commonly used by eGroupWare developers *
* Copyright ( C ) 2000 , 2001 Dan Kuykendall *
* Copyright ( C ) 2003 Lars Kneschke *
* -------------------------------------------------------------------------*
* This library is part of the eGroupWare API *
* http :// www . egroupware . org *
* ------------------------------------------------------------------------ *
* 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 *
\ **************************************************************************/
/* $Id$ */
2001-01-11 10:52:33 +01:00
2005-03-03 11:47:28 +01:00
$d1 = strtolower ( @ substr ( EGW_API_INC , 0 , 3 ));
$d2 = strtolower ( @ substr ( EGW_SERVER_ROOT , 0 , 3 ));
$d3 = strtolower ( @ substr ( EGW_APP_INC , 0 , 3 ));
2001-06-13 23:10:36 +02:00
if ( $d1 == 'htt' || $d1 == 'ftp' || $d2 == 'htt' || $d2 == 'ftp' || $d3 == 'htt' || $d3 == 'ftp' )
{
echo 'Failed attempt to break in via an old Security Hole!<br>' . " \n " ;
exit ;
}
unset ( $d1 ); unset ( $d2 ); unset ( $d3 );
2005-11-02 12:45:52 +01:00
/**
* common class that contains commonly used functions
*
*/
2001-03-18 06:16:00 +01:00
class common
{
2001-12-27 16:48:42 +01:00
var $debug_info ; // An array with debugging info from the API
2001-12-29 11:57:35 +01:00
var $found_files ;
2001-12-27 16:48:42 +01:00
2005-11-02 12:45:52 +01:00
/**
* Compares two Version strings and return 1 if str2 is newest ( bigger version number ) than str1
*
* This function checks for major version only .
* @ param $str1
* @ param $str2
*/
2002-01-05 16:33:46 +01:00
function cmp_version ( $str1 , $str2 , $debug = False )
2001-03-23 06:56:15 +01:00
{
ereg ( " ([0-9]+) \ .([0-9]+) \ .([0-9]+)[a-zA-Z]*([0-9]*) " , $str1 , $regs );
ereg ( " ([0-9]+) \ .([0-9]+) \ .([0-9]+)[a-zA-Z]*([0-9]*) " , $str2 , $regs2 );
2003-08-28 16:31:11 +02:00
if ( $debug ) { echo " <br> $regs[0] - $regs2[0] " ; }
2002-01-05 16:33:46 +01:00
2001-09-08 18:02:59 +02:00
for ( $i = 1 ; $i < 5 ; $i ++ )
{
2002-01-05 16:33:46 +01:00
if ( $debug ) { echo " <br> $i : $regs[$i] - $regs2[$i] " ; }
2001-03-23 06:56:15 +01:00
if ( $regs2 [ $i ] == $regs [ $i ])
2001-09-08 18:02:59 +02:00
{
2001-03-23 06:56:15 +01:00
continue ;
2001-09-08 18:02:59 +02:00
}
2001-03-23 06:56:15 +01:00
if ( $regs2 [ $i ] > $regs [ $i ])
2001-09-08 18:02:59 +02:00
{
2001-03-23 06:56:15 +01:00
return 1 ;
2001-09-08 18:02:59 +02:00
}
elseif ( $regs2 [ $i ] < $regs [ $i ])
{
return 0 ;
}
}
}
2005-11-02 12:45:52 +01:00
/**
* Compares two Version strings and return 1 if str2 is newest ( bigger version number ) than str1
*
* This function checks all fields . cmp_version () checks release version only .
* @ param $str1
* @ param $str2
*/
2002-01-04 05:44:09 +01:00
function cmp_version_long ( $str1 , $str2 , $debug = False )
2001-09-08 18:02:59 +02:00
{
ereg ( " ([0-9]+) \ .([0-9]+) \ .([0-9]+)[a-zA-Z]*([0-9]*) \ .([0-9]*) " , $str1 , $regs );
ereg ( " ([0-9]+) \ .([0-9]+) \ .([0-9]+)[a-zA-Z]*([0-9]*) \ .([0-9]*) " , $str2 , $regs2 );
2003-08-28 16:31:11 +02:00
if ( $debug ) { echo " <br> $regs[0] - $regs2[0] " ; }
2002-01-04 05:44:09 +01:00
2001-09-08 18:02:59 +02:00
for ( $i = 1 ; $i < 6 ; $i ++ )
{
2002-01-04 05:44:09 +01:00
if ( $debug ) { echo " <br> $i : $regs[$i] - $regs2[$i] " ; }
2001-09-08 18:02:59 +02:00
if ( $regs2 [ $i ] == $regs [ $i ])
{
2002-01-04 05:44:09 +01:00
if ( $debug ) { echo ' are equal...' ; }
2001-09-08 18:02:59 +02:00
continue ;
}
if ( $regs2 [ $i ] > $regs [ $i ])
{
2003-08-28 16:31:11 +02:00
if ( $debug ) { echo ', and a > b' ; }
2001-09-08 18:02:59 +02:00
return 1 ;
}
elseif ( $regs2 [ $i ] < $regs [ $i ])
{
2003-08-28 16:31:11 +02:00
if ( $debug ) { echo ', and a < b' ; }
2001-09-08 18:02:59 +02:00
return 0 ;
}
2001-03-23 06:56:15 +01:00
}
2003-08-28 16:31:11 +02:00
if ( $debug ) { echo ' - all equal.' ; }
2001-03-23 06:56:15 +01:00
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* Convert an array into the format needed for the access column
*
* @ param $access
* @ param $array
*/
2001-03-18 06:16:00 +01:00
function array_to_string ( $access , $array )
{
$this -> debug_info [] = 'array_to_string() is a depreciated function - use ACL instead' ;
$s = '' ;
if ( $access == 'group' || $access == 'public' || $access == 'none' )
{
if ( count ( $array ))
{
2005-11-13 11:13:16 +01:00
while (( $t = each ( $array )))
2004-01-18 22:12:53 +01:00
{
2001-03-18 06:16:00 +01:00
$s .= ',' . $t [ 1 ];
}
$s .= ',' ;
}
if ( ! count ( $array ) && $access == 'none' )
{
$s = '' ;
}
}
return $s ;
}
2005-02-28 00:27:36 +01:00
/**
2005-11-13 11:13:16 +01:00
* generate a unique id , which can be used for syncronisation
2005-02-28 00:27:36 +01:00
*
* @ param string $_appName the appname
* @ param string $_eventID the id of the content
* @ return string the unique id
*/
function generate_uid ( $_appName , $_eventID )
{
if ( empty ( $_appName ) || empty ( $_eventID )) return false ;
2005-03-03 11:47:28 +01:00
$suffix = $GLOBALS [ 'egw_info' ][ 'server' ][ 'hostname' ] ? $GLOBALS [ 'egw_info' ][ 'server' ][ 'hostname' ] : 'local' ;
$prefix = $_appName . '-' . $_eventID . '-' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'install_id' ];
2005-02-28 00:27:36 +01:00
2005-06-20 13:14:40 +02:00
return $prefix ;
2005-02-28 00:27:36 +01:00
}
/**
* get the local content id from a global UID
*
* @ param sting $_globalUid the global UID
* @ return int local egw content id
*/
function get_egwId ( $_globalUid )
{
if ( empty ( $_globalUid )) return false ;
$globalUidParts = explode ( '-' , $_globalUid );
return $globalUidParts [ 1 ];
}
2001-02-05 17:37:38 +01:00
2001-03-18 06:16:00 +01:00
// This is used for searching the access fields
2005-11-02 12:45:52 +01:00
/**
* this function is used for searching the access fields
*
* @ param $table
* @ param $owner
*/
2001-03-18 06:16:00 +01:00
function sql_search ( $table , $owner = 0 )
{
2001-08-04 16:26:10 +02:00
$this -> debug_info [] = 'sql_search() is a deprecated function - use ACL instead' ;
2001-03-18 06:16:00 +01:00
$s = '' ;
if ( ! $owner )
{
2005-03-03 11:47:28 +01:00
$owner = $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ];
2001-03-18 06:16:00 +01:00
}
2005-03-03 11:47:28 +01:00
$groups = $GLOBALS [ 'egw' ] -> accounts -> membership (( int ) $owner );
2003-12-20 19:41:42 +01:00
if ( @ is_array ( $groups ))
2001-03-18 06:16:00 +01:00
{
while ( $group = each ( $groups ))
{
2003-12-20 19:41:42 +01:00
$s .= " OR $table LIKE '%, " . $group [ 2 ] . " ,%' " ;
2001-03-18 06:16:00 +01:00
}
}
return $s ;
}
2001-02-05 17:37:38 +01:00
2001-06-13 23:10:36 +02:00
// return a array of installed languages
2005-11-02 12:45:52 +01:00
/**
* return an array of installed languages
*
* @ return $installedLanguages ; an array containing the installed languages
*/
2001-06-13 23:10:36 +02:00
function getInstalledLanguages ()
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> query ( 'SELECT DISTINCT lang FROM phpgw_lang' );
while ( @ $GLOBALS [ 'egw' ] -> db -> next_record ())
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$installedLanguages [ $GLOBALS [ 'egw' ] -> db -> f ( 'lang' )] = $GLOBALS [ 'egw' ] -> db -> f ( 'lang' );
2001-06-13 23:10:36 +02:00
}
return $installedLanguages ;
}
2001-01-11 10:52:33 +01:00
2001-06-13 23:10:36 +02:00
// return the preferred language of the users
// it's using HTTP_ACCEPT_LANGUAGE (send from the users browser)
// and ...(to find out which languages are installed)
2005-11-02 12:45:52 +01:00
/**
* return the preferred langugae of the users
*
* it uses HTTP_ACCEPT_LANGUAGE ( from the users browser ) < br >
* and .... to find out which languages are installed
*/
2001-06-13 23:10:36 +02:00
function getPreferredLanguage ()
{
// create a array of languages the user is accepting
2004-04-13 09:54:25 +02:00
$userLanguages = explode ( ',' , $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ]);
2001-06-13 23:10:36 +02:00
$supportedLanguages = $this -> getInstalledLanguages ();
// find usersupported language
2004-01-21 14:55:22 +01:00
// while (list($key,$value) = each($userLanguages))
foreach ( $userLanguages as $key => $value )
2001-06-13 23:10:36 +02:00
{
// remove everything behind '-' example: de-de
$value = trim ( $value );
$pieces = explode ( '-' , $value );
$value = $pieces [ 0 ];
# print 'current lang $value<br>';
if ( $supportedLanguages [ $value ])
{
$retValue = $value ;
break ;
}
}
// no usersupported language found -> return english
if ( empty ( $retValue ))
{
$retValue = 'en' ;
}
return $retValue ;
}
2005-11-02 12:45:52 +01:00
/**
* escapes a string for use in searchfilters meant for ldap_search .
*
* Escaped Characters are : '*' , '(' , ')' , ' ' , ' \ ' , NUL
* It ' s actually a PHP - Bug , that we have to escape space .
* For all other Characters , refer to RFC2254 .
* @ param $string either a string to be escaped , or an array of values to be escaped
*/
2004-05-12 11:55:30 +02:00
function ldap_addslashes ( $string = '' )
{
return str_replace ( array ( '\\' , '*' , '(' , ')' , '\0' , ' ' ), array ( '\\\\' , '\*' , '\(' , '\)' , '\\0' , '\20' ), $string );
}
2001-06-13 23:10:36 +02:00
// connect to the ldap server and return a handle
2005-11-02 12:45:52 +01:00
/**
* connect to the ldap server and return a handle
*
* @ param $host ldap host
* @ param $dn ldap_root_dn
* @ param $passwd ldap_root_pw
*/
2004-01-21 14:55:22 +01:00
function ldapConnect ( $host = '' , $dn = '' , $passwd = '' )
2001-06-13 23:10:36 +02:00
{
2004-01-21 14:55:22 +01:00
if ( ! function_exists ( 'ldap_connect' ))
{
/* log does not exist in setup(, yet) */
2005-03-03 11:47:28 +01:00
if ( is_object ( $GLOBALS [ 'egw' ] -> log ))
2004-01-21 14:55:22 +01:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> log -> message ( 'F-Abort, LDAP support unavailable' );
$GLOBALS [ 'egw' ] -> log -> commit ();
2004-01-21 14:55:22 +01:00
}
printf ( '<b>Error: LDAP support unavailable</b><br>' , $host );
return False ;
}
if ( ! $host )
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$host = $GLOBALS [ 'egw_info' ][ 'server' ][ 'ldap_host' ];
2001-06-13 23:10:36 +02:00
}
2001-01-11 10:52:33 +01:00
2004-01-21 14:55:22 +01:00
if ( ! $dn )
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$dn = $GLOBALS [ 'egw_info' ][ 'server' ][ 'ldap_root_dn' ];
2001-06-13 23:10:36 +02:00
}
2001-01-11 10:52:33 +01:00
2004-01-21 14:55:22 +01:00
if ( ! $passwd )
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$passwd = $GLOBALS [ 'egw_info' ][ 'server' ][ 'ldap_root_pw' ];
2001-06-13 23:10:36 +02:00
}
// connect to ldap server
2004-01-21 14:55:22 +01:00
if ( ! $ds = ldap_connect ( $host ))
2001-06-13 23:10:36 +02:00
{
2001-11-25 02:24:42 +01:00
/* log does not exist in setup(, yet) */
2005-03-03 11:47:28 +01:00
if ( is_object ( $GLOBALS [ 'egw' ] -> log ))
2001-11-25 02:24:42 +01:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> log -> message ( 'F-Abort, Failed connecting to LDAP server' );
$GLOBALS [ 'egw' ] -> log -> commit ();
2001-11-25 02:24:42 +01:00
}
2001-08-05 11:54:44 +02:00
2001-06-13 23:10:36 +02:00
printf ( " <b>Error: Can't connect to LDAP server %s!</b><br> " , $host );
2005-11-02 12:45:52 +01:00
echo function_backtrace ( 1 );
2001-06-13 23:10:36 +02:00
return False ;
}
2004-01-18 22:12:53 +01:00
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'ldap_version3' ])
2003-12-20 19:41:42 +01:00
{
2003-09-14 08:11:52 +02:00
if ( ! ldap_set_option ( $ds , LDAP_OPT_PROTOCOL_VERSION , 3 ))
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'ldap_version3' ] = False ;
2003-09-14 08:11:52 +02:00
}
2003-09-14 08:02:25 +02:00
}
2003-12-20 19:41:42 +01:00
2004-01-21 14:55:22 +01:00
// bind as admin
if ( ! ldap_bind ( $ds , $dn , $passwd ))
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
if ( is_object ( $GLOBALS [ 'egw' ] -> log ))
2001-11-25 02:29:04 +01:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> log -> message ( 'F-Abort, Failed binding to LDAP server' );
$GLOBALS [ 'egw' ] -> log -> commit ();
2001-11-25 02:29:04 +01:00
}
2001-08-05 11:54:44 +02:00
2001-06-13 23:10:36 +02:00
printf ( " <b>Error: Can't bind to LDAP server: %s!</b><br> " , $dn );
2005-11-02 12:45:52 +01:00
echo function_backtrace ( 1 );
2001-06-13 23:10:36 +02:00
return False ;
}
return $ds ;
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* function to stop running an app
*
* used to stop running an app in the middle of execution < br >
* There may need to be some cleanup before hand
* @ param $call_footer boolean value to if true then call footer else exit
*/
2005-03-03 11:47:28 +01:00
function egw_exit ( $call_footer = False )
2003-08-28 16:31:11 +02:00
{
2005-03-03 11:47:28 +01:00
if ( ! defined ( 'EGW_EXIT' ))
2003-08-28 16:31:11 +02:00
{
2005-03-03 11:47:28 +01:00
define ( 'EGW_EXIT' , True );
2003-08-28 16:31:11 +02:00
if ( $call_footer )
{
2005-03-03 11:47:28 +01:00
$this -> egw_footer ();
2003-08-28 16:31:11 +02:00
}
}
exit ;
}
2005-03-03 11:47:28 +01:00
function egw_final ()
2003-08-28 16:31:11 +02:00
{
2005-03-03 11:47:28 +01:00
if ( ! defined ( 'EGW_FINAL' ))
2003-08-28 16:31:11 +02:00
{
2005-03-03 11:47:28 +01:00
define ( 'EGW_FINAL' , True );
2003-08-28 16:31:11 +02:00
2005-03-03 11:47:28 +01:00
if ( is_object ( $GLOBALS [ 'egw' ] -> accounts ))
2004-05-05 15:49:32 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> accounts -> save_session_cache ();
2004-05-05 15:49:32 +02:00
}
2003-08-28 16:31:11 +02:00
// call the asyncservice check_run function if it is not explicitly set to cron-only
//
2005-03-03 11:47:28 +01:00
if ( ! $GLOBALS [ 'egw_info' ][ 'server' ][ 'asyncservice' ]) // is default
2003-08-28 16:31:11 +02:00
{
ExecMethod ( 'phpgwapi.asyncservice.check_run' , 'fallback' );
}
/* Clean up mcrypt */
2005-03-03 11:47:28 +01:00
if ( @ is_object ( $GLOBALS [ 'egw' ] -> crypto ))
2003-08-28 16:31:11 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> crypto -> cleanup ();
unset ( $GLOBALS [ 'egw' ] -> crypto );
2003-08-28 16:31:11 +02:00
}
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> disconnect ();
2003-08-28 16:31:11 +02:00
}
}
2005-11-02 12:45:52 +01:00
/**
* return a random string of size $size
*
* @ param $size int - size of random string to return
*/
2001-06-13 23:10:36 +02:00
function randomstring ( $size )
{
$s = '' ;
srand (( double ) microtime () * 1000000 );
2003-12-10 12:35:22 +01:00
$random_char = array (
'0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' ,
2001-06-13 23:10:36 +02:00
'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' ,
'w' , 'x' , 'y' , 'z' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' ,
2003-12-10 12:35:22 +01:00
'M' , 'N' , 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z'
);
2001-06-13 23:10:36 +02:00
for ( $i = 0 ; $i < $size ; $i ++ )
{
$s .= $random_char [ rand ( 1 , 61 )];
}
return $s ;
}
2001-01-11 10:52:33 +01:00
2001-04-04 09:14:31 +02:00
// Look at the note towards the top of this file (jengo)
function filesystem_separator ()
{
return filesystem_separator ();
}
2005-11-02 12:45:52 +01:00
/**
* This is used for reporting errors in a nice format .
*
* @ param $error - array of errors
*/
2001-12-27 16:16:22 +01:00
function error_list ( $errors , $text = 'Error' )
2001-04-04 09:14:31 +02:00
{
if ( ! is_array ( $errors ))
{
return False ;
}
2001-01-11 10:52:33 +01:00
2003-08-28 16:31:11 +02:00
$html_error = '<table border="0" width="100%"><tr><td align="right"><b>' . lang ( $text )
. '</b>: </td><td align="left">' . $errors [ 0 ] . '</td></tr>' ;
for ( $i = 1 ; $i < count ( $errors ); $i ++ )
2002-05-25 00:30:35 +02:00
{
2003-08-28 16:31:11 +02:00
$html_error .= '<tr><td> </td><td align="left">' . $errors [ $i ] . '</td></tr>' ;
2002-05-25 00:30:35 +02:00
}
2003-08-28 16:31:11 +02:00
return $html_error . '</table>' ;
2001-04-04 09:14:31 +02:00
}
2001-03-18 06:16:00 +01:00
2005-11-02 12:45:52 +01:00
/**
2005-11-13 11:13:16 +01:00
* @ deprecated use ACL instead
2005-11-02 12:45:52 +01:00
*/
2001-03-18 06:16:00 +01:00
function check_owner ( $record , $link , $label , $extravars = '' )
{
$this -> debug_info [] = 'check_owner() is a depreciated function - use ACL instead' ;
2001-06-13 23:10:36 +02:00
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* return the fullname of a user
*
2005-11-02 21:43:04 +01:00
* @ param $lid = '' account loginid
* @ param $firstname = '' firstname
* @ param $lastname = '' lastname
* @ param $accountid = 0 id , to check if it ' s a user or group , otherwise the lid will be used
2005-11-02 12:45:52 +01:00
*/
2005-11-02 21:43:04 +01:00
function display_fullname ( $lid = '' , $firstname = '' , $lastname = '' , $accountid = 0 )
2001-03-22 14:25:06 +01:00
{
if ( ! $lid && ! $firstname && ! $lastname )
{
2005-03-03 11:47:28 +01:00
$lid = $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_lid' ];
$firstname = $GLOBALS [ 'egw_info' ][ 'user' ][ 'firstname' ];
$lastname = $GLOBALS [ 'egw_info' ][ 'user' ][ 'lastname' ];
2001-03-22 14:25:06 +01:00
}
2005-11-02 21:43:04 +01:00
if ( empty ( $firstname )) $firstname = $lid ;
if ( empty ( $lastname ))
{
$lastname = $GLOBALS [ 'egw' ] -> accounts -> get_type ( $accountid ? $accountid : $lid ) == 'g' ?
lang ( 'Group' ) : lang ( 'User' );
}
2005-03-03 11:47:28 +01:00
$display = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'account_display' ];
2003-05-04 00:23:50 +02:00
2004-08-26 20:47:29 +02:00
if ( $firstname && $lastname )
2001-03-22 14:25:06 +01:00
{
2004-08-26 20:47:29 +02:00
$delimiter = ', ' ;
2001-03-22 14:25:06 +01:00
}
2004-08-26 20:47:29 +02:00
else
2001-03-25 16:41:17 +02:00
{
2004-08-26 20:47:29 +02:00
$delimiter = '' ;
2001-05-13 06:08:01 +02:00
}
2004-08-26 20:47:29 +02:00
2003-05-17 22:34:55 +02:00
$name = '' ;
2003-05-04 00:23:50 +02:00
switch ( $display )
2001-05-13 06:08:01 +02:00
{
2004-08-26 20:47:29 +02:00
case 'firstname' :
$name = $firstname . ' ' . $lastname ;
break ;
2003-05-04 00:23:50 +02:00
case 'lastname' :
2004-08-26 20:47:29 +02:00
$name = $lastname . $delimiter . $firstname ;
break ;
case 'username' :
$name = $lid ;
2003-05-04 00:23:50 +02:00
break ;
2003-05-04 17:14:06 +02:00
case 'firstall' :
2004-08-26 20:47:29 +02:00
$name = $firstname . ' ' . $lastname . ' [' . $lid . ']' ;
break ;
case 'lastall' :
$name = $lastname . $delimiter . $firstname . ' [' . $lid . ']' ;
2003-05-04 00:23:50 +02:00
break ;
2004-08-26 20:47:29 +02:00
case 'all' :
/* fall through */
default :
$name = '[' . $lid . '] ' . $firstname . ' ' . $lastname ;
2001-03-25 16:41:17 +02:00
}
2003-05-04 00:23:50 +02:00
return $name ;
2001-03-22 14:25:06 +01:00
}
2005-11-02 12:45:52 +01:00
/**
* grab the owner name
*
* @ param $id account id
*/
2001-06-13 23:10:36 +02:00
function grab_owner_name ( $accountid = '' )
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> accounts -> get_account_name ( $accountid , $lid , $fname , $lname );
2005-11-02 21:43:04 +01:00
return $this -> display_fullname ( $lid , $fname , $lname , $accountid );
2001-06-13 23:10:36 +02:00
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* create tabs
*
* @ param array $tabs an array repersenting the tabs you wish to display , each element
* * * in the array is an array of 3 elements , 'label' which is the
* * * text displaed on the tab ( you should pass translated string ,
* * * create_tabs will not do < code > lang () </ code > for you ), 'link'
* * * which is the uri , 'target' , the frame name or '_blank' to show
* * * page in a new browser window .
* @ param mixed $selected the tab whos key is $selected will be displayed as current tab
* @ param $fontsize optional
* @ return string return html that displays the tabs
*/
2003-08-28 16:31:11 +02:00
function create_tabs ( $tabs , $selected , $fontsize = '' )
2001-06-13 23:10:36 +02:00
{
2003-08-28 16:31:11 +02:00
$output_text = '<table border="0" cellspacing="0" cellpadding="0"><tr>' ;
2001-09-05 05:06:14 +02:00
2003-08-28 16:31:11 +02:00
/* This is a php3 workaround */
2005-03-03 11:47:28 +01:00
if ( EGW_IMAGES_DIR == 'EGW_IMAGES_DIR' )
2001-09-05 05:06:14 +02:00
{
$ir = ExecMethod ( 'phpgwapi.phpgw.common.get_image_path' , 'phpgwapi' );
}
else
{
2005-03-03 11:47:28 +01:00
$ir = EGW_IMAGES_DIR ;
2003-08-28 16:31:11 +02:00
}
if ( $fontsize )
{
$fs = '<font size="' . $fontsize . '">' ;
$fse = '</font>' ;
}
2001-06-13 23:10:36 +02:00
$i = 1 ;
while ( $tab = each ( $tabs ))
{
if ( $tab [ 0 ] == $selected )
{
if ( $i == 1 )
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="right"><img src="' . $ir . '/tabs-start1.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left" background="' . $ir . '/tabs-bg1.gif"> <b><a href="'
2004-04-13 10:18:06 +02:00
. $tab [ 1 ][ 'link' ] . '" class="tablink" ' . $tab [ 1 ][ 'target' ] . '>' . $fs . $tab [ 1 ][ 'label' ]
2001-06-13 23:10:36 +02:00
. $fse . '</a></b> </td>' ;
if ( $i == count ( $tabs ))
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left"><img src="' . $ir . '/tabs-end1.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
else
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepr.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
}
else
{
if ( $i == 1 )
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="right"><img src="' . $ir . '/tabs-start0.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left" background="' . $ir . '/tabs-bg0.gif"> <b><a href="'
2004-04-13 10:18:06 +02:00
. $tab [ 1 ][ 'link' ] . '" class="tablink" ' . $tab [ 1 ][ 'target' ] . '>' . $fs . $tab [ 1 ][ 'label' ] . $fse
2001-06-13 23:10:36 +02:00
. '</a></b> </td>' ;
if (( $i + 1 ) == $selected )
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepl.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
2001-12-28 07:02:30 +01:00
elseif ( $i == $selected || $i != count ( $tabs ))
2001-06-13 23:10:36 +02:00
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepm.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
2001-12-28 07:02:30 +01:00
elseif ( $i == count ( $tabs ))
2001-06-13 23:10:36 +02:00
{
if ( $i == $selected )
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left"><img src="' . $ir . '/tabs-end1.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
else
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left"><img src="' . $ir . '/tabs-end0.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
}
else
{
if ( $i != count ( $tabs ))
{
2003-08-28 16:31:11 +02:00
$output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepr.gif"></td>' ;
2001-06-13 23:10:36 +02:00
}
}
}
$i ++ ;
$output_text .= " \n " ;
}
$output_text .= " </table> \n " ;
return $output_text ;
}
2002-01-04 05:06:13 +01:00
2005-11-02 12:45:52 +01:00
/**
* get directory of application
*
* $appname can either be passed or derived from $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
* @ param $appname name of application
*/
2001-06-13 23:10:36 +02:00
function get_app_dir ( $appname = '' )
{
if ( $appname == '' )
{
2005-03-03 11:47:28 +01:00
$appname = $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
2001-06-13 23:10:36 +02:00
}
2005-06-15 13:16:27 +02:00
if ( $appname == 'logout' || $appname == 'login' )
2001-06-13 23:10:36 +02:00
{
$appname = 'phpgwapi' ;
}
2005-03-03 11:47:28 +01:00
$appdir = EGW_INCLUDE_ROOT . '/' . $appname ;
$appdir_default = EGW_SERVER_ROOT . '/' . $appname ;
2001-06-13 23:10:36 +02:00
2002-01-02 15:33:05 +01:00
if ( @ is_dir ( $appdir ))
2001-06-13 23:10:36 +02:00
{
return $appdir ;
}
2002-01-02 15:33:05 +01:00
elseif ( @ is_dir ( $appdir_default ))
2001-06-13 23:10:36 +02:00
{
return $appdir_default ;
}
else
{
return False ;
}
}
2005-11-02 12:45:52 +01:00
/**
* get inc ( include dir ) of application
*
* $appname can either be passed or derived from $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
* @ param $appname name of application
*/
2001-06-13 23:10:36 +02:00
function get_inc_dir ( $appname = '' )
{
if ( ! $appname )
{
2005-03-03 11:47:28 +01:00
$appname = $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
2001-06-13 23:10:36 +02:00
}
2005-06-15 13:16:27 +02:00
if ( $appname == 'logout' || $appname == 'login' || $appname == 'about' )
2001-06-13 23:10:36 +02:00
{
$appname = 'phpgwapi' ;
}
2004-01-18 22:12:53 +01:00
2005-03-03 11:47:28 +01:00
$incdir = EGW_INCLUDE_ROOT . '/' . $appname . '/inc' ;
$incdir_default = EGW_SERVER_ROOT . '/' . $appname . '/inc' ;
2004-01-18 22:12:53 +01:00
2002-01-02 15:33:05 +01:00
if ( @ is_dir ( $incdir ))
2001-06-13 23:10:36 +02:00
{
return $incdir ;
}
2002-01-02 15:33:05 +01:00
elseif ( @ is_dir ( $incdir_default ))
2001-06-13 23:10:36 +02:00
{
return $incdir_default ;
}
else
{
return False ;
}
}
2005-11-02 12:45:52 +01:00
/**
* list themes available
*
* themes can either be css file like in HEAD ( if the template has a css - dir and has css - files in is ) \
* or ordinary . 14 themes - files
*/
2002-09-27 19:39:49 +02:00
function list_themes ()
{
$tpl_dir = $this -> get_tpl_dir ( 'phpgwapi' );
2003-08-28 16:31:11 +02:00
if ( $dh = @ opendir ( $tpl_dir . SEP . 'css' ))
{
while ( $file = readdir ( $dh ))
{
if ( eregi ( " \ .css $ " , $file ) && $file != 'phpgw.css' )
{
$list [] = substr ( $file , 0 , strpos ( $file , '.' ));
}
}
}
2003-09-19 10:51:26 +02:00
if ( ! is_array ( $list ))
2002-09-27 19:39:49 +02:00
{
2005-03-03 11:47:28 +01:00
$dh = opendir ( EGW_SERVER_ROOT . '/phpgwapi/themes' );
2003-08-28 16:31:11 +02:00
while ( $file = readdir ( $dh ))
2002-09-27 19:39:49 +02:00
{
2003-08-28 16:31:11 +02:00
if ( eregi ( " \ .theme $ " , $file ))
{
$list [] = substr ( $file , 0 , strpos ( $file , '.' ));
}
2002-09-27 19:39:49 +02:00
}
}
closedir ( $dh );
reset ( $list );
return $list ;
2001-06-13 23:10:36 +02:00
}
2003-08-30 10:44:51 +02:00
/**
* List available templates
*
* @ returns array alphabetically sorted list of templates
2001-03-14 18:21:09 +01:00
*/
2001-06-13 23:10:36 +02:00
function list_templates ()
{
2005-03-03 11:47:28 +01:00
$d = dir ( EGW_SERVER_ROOT . '/phpgwapi/templates' );
2001-06-13 23:10:36 +02:00
while ( $entry = $d -> read ())
{
2005-11-02 12:45:52 +01:00
if ( $entry != '..' && is_file ( EGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry . '/setup/setup.inc.php' )
2005-06-29 23:06:52 +02:00
)
2001-06-13 23:10:36 +02:00
{
$list [ $entry ][ 'name' ] = $entry ;
2005-06-29 23:06:52 +02:00
$f = EGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry . '/setup/setup.inc.php' ;
2001-06-13 23:10:36 +02:00
if ( file_exists ( $f ))
{
include ( $f );
2005-06-29 23:06:52 +02:00
$list [ $entry ][ 'title' ] = $GLOBALS [ 'egw_info' ][ 'template' ][ $entry ][ 'title' ];
2001-06-13 23:10:36 +02:00
}
else
{
$list [ $entry ][ 'title' ] = $entry ;
}
}
}
2005-06-29 23:06:52 +02:00
//_debug_array($GLOBALS['egw_info'][template]);
//die();
2001-06-13 23:10:36 +02:00
$d -> close ();
2003-08-30 10:44:51 +02:00
ksort ( $list );
2001-06-13 23:10:36 +02:00
return $list ;
}
2005-11-02 12:45:52 +01:00
/**
* get template dir of an application
*
* @ param $appname appication name optional can be derived from $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
*/
2003-08-28 16:31:11 +02:00
function get_tpl_dir ( $appname = '' )
2001-06-13 23:10:36 +02:00
{
if ( ! $appname )
{
2005-03-03 11:47:28 +01:00
$appname = $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
2001-06-13 23:10:36 +02:00
}
2005-06-15 13:16:27 +02:00
if ( $appname == 'logout' || $appname == 'login' )
2001-06-13 23:10:36 +02:00
{
$appname = 'phpgwapi' ;
}
2005-03-03 11:47:28 +01:00
if ( ! isset ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ]) && isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'template_set' ]))
2001-09-18 05:50:00 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'template_set' ];
2001-09-18 05:50:00 +02:00
}
2001-06-13 23:10:36 +02:00
// Setting this for display of template choices in user preferences
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] == 'user_choice' )
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'usrtplchoice' ] = 'user_choice' ;
2001-06-13 23:10:36 +02:00
}
2005-03-03 11:47:28 +01:00
if (( $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] == 'user_choice' ||
! isset ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ])) &&
isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'template_set' ]))
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'template_set' ];
2001-06-13 23:10:36 +02:00
}
2005-03-03 11:47:28 +01:00
elseif ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] == 'user_choice' ||
! isset ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ]))
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] = 'default' ;
2001-06-13 23:10:36 +02:00
}
2002-05-31 23:22:25 +02:00
2005-03-03 11:47:28 +01:00
$tpldir = EGW_SERVER_ROOT . '/' . $appname . '/templates/' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ];
$tpldir_default = EGW_SERVER_ROOT . '/' . $appname . '/templates/default' ;
2001-06-13 23:10:36 +02:00
2001-12-30 10:42:55 +01:00
if ( @ is_dir ( $tpldir ))
2001-06-13 23:10:36 +02:00
{
return $tpldir ;
}
2001-12-30 10:42:55 +01:00
elseif ( @ is_dir ( $tpldir_default ))
2001-06-13 23:10:36 +02:00
{
return $tpldir_default ;
}
else
{
return False ;
}
}
2005-11-02 12:45:52 +01:00
/**
* checks if image_dir exists and has more than just a navbar - icon
*
* this is just a workaround for idots , better to use find_image , which has a fallback \
* on a per image basis to the default dir
*/
2003-05-03 12:59:16 +02:00
function is_image_dir ( $dir )
{
if ( !@ is_dir ( $dir ))
{
return False ;
}
if ( $d = opendir ( $dir ))
{
while ( $f = readdir ( $d ))
{
$ext = strtolower ( strrchr ( $f , '.' ));
if (( $ext == '.gif' || $ext == '.png' ) && strstr ( $f , 'navbar' ) === False )
{
return True ;
}
}
}
return False ;
}
2005-11-02 12:45:52 +01:00
/**
* get image dir of an application
*
* @ param $appname application name optional can be derived from $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
*/
2003-08-28 16:31:11 +02:00
function get_image_dir ( $appname = '' )
2001-06-13 23:10:36 +02:00
{
if ( $appname == '' )
{
2005-03-03 11:47:28 +01:00
$appname = $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
2001-06-13 23:10:36 +02:00
}
2005-03-03 11:47:28 +01:00
if ( empty ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ]))
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] = 'default' ;
2001-06-13 23:10:36 +02:00
}
2005-03-03 11:47:28 +01:00
$imagedir = EGW_SERVER_ROOT . '/' . $appname . '/templates/'
. $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] . '/images' ;
$imagedir_default = EGW_SERVER_ROOT . '/' . $appname . '/templates/default/images' ;
$imagedir_olddefault = EGW_SERVER_ROOT . '/' . $appname . '/images' ;
2001-06-13 23:10:36 +02:00
2003-05-03 12:59:16 +02:00
if ( $this -> is_image_dir ( $imagedir ))
2001-06-13 23:10:36 +02:00
{
return $imagedir ;
}
2003-05-03 12:59:16 +02:00
elseif ( $this -> is_image_dir ( $imagedir_default ))
2001-06-13 23:10:36 +02:00
{
return $imagedir_default ;
}
2003-05-03 12:59:16 +02:00
elseif ( $this -> is_image_dir ( $imagedir_olddefault ))
2001-06-13 23:10:36 +02:00
{
return $imagedir_olddefault ;
}
else
{
return False ;
}
}
2005-11-02 12:45:52 +01:00
/**
* get image path of an application
*
* @ param $appname appication name optional can be derived from $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
*/
2003-08-28 16:31:11 +02:00
function get_image_path ( $appname = '' )
2001-03-08 09:44:57 +01:00
{
if ( $appname == '' )
{
2005-03-03 11:47:28 +01:00
$appname = $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
2001-03-08 09:44:57 +01:00
}
2005-03-03 11:47:28 +01:00
if ( empty ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ]))
2001-03-08 09:44:57 +01:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] = 'default' ;
2001-03-08 09:44:57 +01:00
}
2005-03-03 11:47:28 +01:00
$imagedir = EGW_SERVER_ROOT . '/' . $appname . '/templates/' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] . '/images' ;
$imagedir_default = EGW_SERVER_ROOT . '/' . $appname . '/templates/default/images' ;
$imagedir_olddefault = EGW_SERVER_ROOT . '/' . $appname . '/images' ;
2001-03-08 09:44:57 +01:00
2003-05-03 12:59:16 +02:00
if ( $this -> is_image_dir ( $imagedir ))
2001-03-08 09:44:57 +01:00
{
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . '/' . $appname . '/templates/' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] . '/images' ;
2001-03-08 09:44:57 +01:00
}
2003-05-03 12:59:16 +02:00
elseif ( $this -> is_image_dir ( $imagedir_default ))
2001-03-08 09:44:57 +01:00
{
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . '/' . $appname . '/templates/default/images' ;
2001-03-08 09:44:57 +01:00
}
2003-05-03 12:59:16 +02:00
elseif ( $this -> is_image_dir ( $imagedir_olddefault ))
2001-03-08 09:44:57 +01:00
{
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . '/' . $appname . '/images' ;
2001-03-08 09:44:57 +01:00
}
else
{
return False ;
2001-06-13 23:10:36 +02:00
}
2001-03-08 09:44:57 +01:00
}
2001-05-06 18:37:40 +02:00
2003-08-28 16:31:11 +02:00
function find_image ( $appname , $image )
2001-05-06 18:37:40 +02:00
{
2005-03-03 11:47:28 +01:00
$imagedir = '/' . $appname . '/templates/' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'template_set' ] . '/images' ;
2004-02-13 16:09:22 +01:00
2002-01-06 07:01:07 +01:00
if ( !@ is_array ( $this -> found_files [ $appname ]))
2001-05-06 18:37:40 +02:00
{
2003-08-28 16:31:11 +02:00
$imagedir_olddefault = '/' . $appname . '/images' ;
$imagedir_default = '/' . $appname . '/templates/default/images' ;
2004-02-13 16:09:22 +01:00
2005-03-03 11:47:28 +01:00
if ( @ is_dir ( EGW_INCLUDE_ROOT . $imagedir_olddefault ))
2001-12-29 11:57:35 +01:00
{
2005-03-03 11:47:28 +01:00
$d = dir ( EGW_INCLUDE_ROOT . $imagedir_olddefault );
2003-08-28 16:31:11 +02:00
while ( false != ( $entry = $d -> read ()))
2001-12-29 11:57:35 +01:00
{
2003-08-28 16:31:11 +02:00
if ( $entry != '.' && $entry != '..' )
2001-12-29 11:57:35 +01:00
{
2003-08-28 16:31:11 +02:00
$this -> found_files [ $appname ][ $entry ] = $imagedir_olddefault ;
2001-12-29 11:57:35 +01:00
}
2003-08-28 16:31:11 +02:00
}
$d -> close ();
}
2002-01-04 05:06:13 +01:00
2005-03-03 11:47:28 +01:00
if ( @ is_dir ( EGW_INCLUDE_ROOT . $imagedir_default ))
2003-08-28 16:31:11 +02:00
{
2005-03-03 11:47:28 +01:00
$d = dir ( EGW_INCLUDE_ROOT . $imagedir_default );
2003-08-28 16:31:11 +02:00
while ( false != ( $entry = $d -> read ()))
2001-12-29 11:57:35 +01:00
{
2003-08-28 16:31:11 +02:00
if ( $entry != '.' && $entry != '..' )
2001-12-29 11:57:35 +01:00
{
2003-08-28 16:31:11 +02:00
$this -> found_files [ $appname ][ $entry ] = $imagedir_default ;
2001-12-29 11:57:35 +01:00
}
}
2003-08-28 16:31:11 +02:00
$d -> close ();
2001-12-29 11:57:35 +01:00
}
2002-01-04 05:06:13 +01:00
2005-03-03 11:47:28 +01:00
if ( @ is_dir ( EGW_INCLUDE_ROOT . $imagedir ))
2001-12-29 11:57:35 +01:00
{
2005-03-03 11:47:28 +01:00
$d = dir ( EGW_INCLUDE_ROOT . $imagedir );
2001-12-29 18:35:13 +01:00
while ( false != ( $entry = $d -> read ()))
2001-12-29 11:57:35 +01:00
{
if ( $entry != '.' && $entry != '..' )
{
2001-12-30 09:24:41 +01:00
$this -> found_files [ $appname ][ $entry ] = $imagedir ;
2001-12-29 11:57:35 +01:00
}
}
$d -> close ();
}
2001-05-06 18:37:40 +02:00
}
2004-02-13 02:25:30 +01:00
2005-03-03 11:47:28 +01:00
if ( ! $GLOBALS [ 'egw_info' ][ 'server' ][ 'image_type' ])
2004-02-13 02:25:30 +01:00
{
// priority: GIF->JPG->PNG
$img_type = array ( '.gif' , '.jpg' , '.png' );
}
else
{
// priority: : PNG->JPG->GIF
$img_type = array ( '.png' , '.jpg' , '.gif' );
}
2001-12-29 11:57:35 +01:00
2004-02-13 16:09:22 +01:00
// first look in the selected template dir
if ( @ $this -> found_files [ $appname ][ $image . $img_type [ 0 ]] == $imagedir )
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ $appname ][ $image . $img_type [ 0 ]] . '/' . $image . $img_type [ 0 ];
2004-02-13 16:09:22 +01:00
}
elseif ( @ $this -> found_files [ $appname ][ $image . $img_type [ 1 ]] == $imagedir )
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ $appname ][ $image . $img_type [ 1 ]] . '/' . $image . $img_type [ 1 ];
2004-02-13 16:09:22 +01:00
}
elseif ( @ $this -> found_files [ $appname ][ $image . $img_type [ 2 ]] == $imagedir )
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ $appname ][ $image . $img_type [ 2 ]] . '/' . $image . $img_type [ 2 ];
2004-02-13 16:09:22 +01:00
}
// then look everywhere else
elseif ( isset ( $this -> found_files [ $appname ][ $image . $img_type [ 0 ]]))
2001-12-29 18:35:13 +01:00
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ $appname ][ $image . $img_type [ 0 ]] . '/' . $image . $img_type [ 0 ];
2001-12-29 18:35:13 +01:00
}
2004-02-13 02:25:30 +01:00
elseif ( isset ( $this -> found_files [ $appname ][ $image . $img_type [ 1 ]]))
2001-12-29 18:35:13 +01:00
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ $appname ][ $image . $img_type [ 1 ]] . '/' . $image . $img_type [ 1 ];
2001-12-29 18:35:13 +01:00
}
2004-02-13 02:25:30 +01:00
elseif ( isset ( $this -> found_files [ $appname ][ $image . $img_type [ 2 ]]))
2001-12-29 18:35:13 +01:00
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ $appname ][ $image . $img_type [ 2 ]] . '/' . $image . $img_type [ 2 ];
2001-12-29 18:35:13 +01:00
}
2001-12-30 09:24:41 +01:00
elseif ( isset ( $this -> found_files [ $appname ][ $image ]))
2001-05-06 18:37:40 +02:00
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ $appname ][ $image ] . '/' . $image ;
2001-05-06 18:37:40 +02:00
}
else
{
2003-12-18 07:11:08 +01:00
// searching the image in the api-dirs
if ( ! isset ( $this -> found_files [ 'phpgwapi' ]))
{
$this -> find_image ( 'phpgwapi' , '' );
}
2004-02-13 02:25:30 +01:00
if ( isset ( $this -> found_files [ 'phpgwapi' ][ $image . $img_type [ 0 ]]))
2003-12-18 07:11:08 +01:00
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ 'phpgwapi' ][ $image . $img_type [ 0 ]] . '/' . $image . $img_type [ 0 ];
2003-12-18 07:11:08 +01:00
}
2004-02-13 02:25:30 +01:00
elseif ( isset ( $this -> found_files [ 'phpgwapi' ][ $image . $img_type [ 1 ]]))
2003-12-18 07:11:08 +01:00
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ 'phpgwapi' ][ $image . $img_type [ 1 ]] . '/' . $image . $img_type [ 1 ];
2003-12-18 07:11:08 +01:00
}
2004-02-13 02:25:30 +01:00
elseif ( isset ( $this -> found_files [ 'phpgwapi' ][ $image . $img_type [ 2 ]]))
2003-12-18 07:11:08 +01:00
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ 'phpgwapi' ][ $image . $img_type [ 2 ]] . '/' . $image . $img_type [ 2 ];
2003-12-18 07:11:08 +01:00
}
elseif ( isset ( $this -> found_files [ 'phpgwapi' ][ $image ]))
{
2005-03-03 11:47:28 +01:00
$imgfile = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ 'phpgwapi' ][ $image ] . '/' . $image ;
2003-12-18 07:11:08 +01:00
}
else
{
$imgfile = '' ;
}
2001-05-06 18:37:40 +02:00
}
return $imgfile ;
}
2003-08-28 16:31:11 +02:00
function image ( $appname , $image = '' , $ext = '' , $use_lang = True )
2001-05-06 18:37:40 +02:00
{
2002-10-28 05:50:43 +01:00
if ( ! is_array ( $image ))
2001-05-06 18:37:40 +02:00
{
2002-10-28 05:50:43 +01:00
if ( empty ( $image ))
2002-01-08 03:14:47 +01:00
{
2002-10-28 05:50:43 +01:00
return '' ;
2002-01-08 03:14:47 +01:00
}
2002-10-28 05:50:43 +01:00
$image = array ( $image );
}
if ( $use_lang )
{
while ( list (, $img ) = each ( $image ))
2002-01-08 03:14:47 +01:00
{
2005-03-03 11:47:28 +01:00
$lang_images [] = $img . '_' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'lang' ];
2002-10-28 05:50:43 +01:00
$lang_images [] = $img ;
2002-01-08 03:14:47 +01:00
}
2002-10-28 05:50:43 +01:00
$image = $lang_images ;
2001-05-06 18:37:40 +02:00
}
2003-10-03 04:01:21 +02:00
while ( empty ( $image_found ) && list (, $img ) = each ( $image ))
2001-05-06 18:37:40 +02:00
{
2002-10-28 05:50:43 +01:00
if ( isset ( $this -> found_files [ $appname ][ $img . $ext ]))
2002-01-08 03:14:47 +01:00
{
2005-03-03 11:47:28 +01:00
$image_found = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $this -> found_files [ $appname ][ $img . $ext ] . '/' . $img . $ext ;
2002-01-08 03:14:47 +01:00
}
else
{
2003-08-28 16:31:11 +02:00
$image_found = $this -> find_image ( $appname , $img . $ext );
2002-01-08 03:14:47 +01:00
}
2001-05-06 18:37:40 +02:00
}
2002-10-28 05:50:43 +01:00
return $image_found ;
2001-05-06 18:37:40 +02:00
}
2001-12-29 18:35:13 +01:00
2003-08-28 16:31:11 +02:00
function image_on ( $appname , $image , $extension = '_on' )
2001-12-29 18:35:13 +01:00
{
2003-08-28 16:31:11 +02:00
$with_extension = $this -> image ( $appname , $image , $extension );
$without_extension = $this -> image ( $appname , $image );
2001-12-29 18:35:13 +01:00
if ( $with_extension != '' )
{
return $with_extension ;
}
elseif ( $without_extension != '' )
{
return $without_extension ;
}
else
{
return '' ;
}
}
2005-11-02 12:45:52 +01:00
/**
* none yet
*
* * someone wanna add some detail here *
*/
2001-03-08 09:44:57 +01:00
function navbar ()
2001-06-13 23:10:36 +02:00
{
2005-06-15 13:16:27 +02:00
2001-03-08 09:44:57 +01:00
2005-03-03 11:47:28 +01:00
list ( $first ) = each ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ]);
if ( is_array ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ]) && $first != 'admin' )
2001-12-31 17:10:12 +01:00
{
2005-03-03 11:47:28 +01:00
$newarray [ 'admin' ] = $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ];
foreach ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ] as $index => $value )
2001-12-31 17:10:12 +01:00
{
if ( $index != 'admin' )
{
$newarray [ $index ] = $value ;
}
}
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ] = $newarray ;
reset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ]);
2001-12-31 17:10:12 +01:00
}
unset ( $index );
unset ( $value );
unset ( $newarray );
2004-01-18 22:12:53 +01:00
2005-03-03 11:47:28 +01:00
foreach ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ] as $app => $data )
2001-03-08 09:44:57 +01:00
{
2002-10-28 05:50:43 +01:00
if ( is_long ( $app ))
2001-03-08 09:44:57 +01:00
{
continue ;
}
2005-03-03 11:47:28 +01:00
if ( $app == 'preferences' || $GLOBALS [ 'egw_info' ][ 'apps' ][ $app ][ 'status' ] != 2 && $GLOBALS [ 'egw_info' ][ 'apps' ][ $app ][ 'status' ] != 3 )
2001-03-08 09:44:57 +01:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'title' ] = $GLOBALS [ 'egw_info' ][ 'apps' ][ $app ][ 'title' ];
$GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'url' ] = $GLOBALS [ 'egw' ] -> link ( '/' . $app . '/index.php' , $GLOBALS [ 'egw_info' ][ 'flags' ][ 'params' ][ $app ]);
$GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'name' ] = $app ;
2001-12-30 05:58:39 +01:00
2004-04-13 09:54:25 +02:00
// create popup target
if ( $data [ 'status' ] == 4 )
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'target' ] = ' target="' . $app . '" onClick="' . " if (this != '') { window.open(this+' " .
( strstr ( $GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'url' ], '?' ) ||
2005-10-13 16:14:01 +02:00
ini_get ( 'session.use_trans_sid' ) && substr ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'sessions_type' ], 0 , 4 ) == 'php4' ? '&' : '?' ) .
2004-08-07 15:15:06 +02:00
" referer='+encodeURI(location),this.target,'width=800,height=600,scrollbars=yes,resizable=yes'); return false; } else { return true; } " . '"' ;
2004-04-13 09:54:25 +02:00
}
2005-03-03 11:47:28 +01:00
if ( $app != $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ])
2001-12-29 18:35:13 +01:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'icon' ] = $this -> image ( $app , Array ( 'navbar' , 'nonav' ));
$GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'icon_hover' ] = $this -> image_on ( $app , Array ( 'navbar' , 'nonav' ), '-over' );
2001-12-29 18:35:13 +01:00
}
else
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'icon' ] = $this -> image_on ( $app , Array ( 'navbar' , 'nonav' ), '-over' );
$GLOBALS [ 'egw_info' ][ 'navbar' ][ $app ][ 'icon_hover' ] = $this -> image ( $app , Array ( 'navbar' , 'nonav' ));
2001-12-29 18:35:13 +01:00
}
2003-08-28 16:31:11 +02:00
2005-03-03 11:47:28 +01:00
// if($GLOBALS['egw_info']['navbar'][$app]['icon'] == '')
2003-08-28 16:31:11 +02:00
// {
2005-03-03 11:47:28 +01:00
// $GLOBALS['egw_info']['navbar'][$app]['icon'] = $this->image('phpgwapi','nonav');
2003-08-28 16:31:11 +02:00
// }
2001-03-08 09:44:57 +01:00
}
}
2005-06-15 13:16:27 +02:00
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] == 'preferences' || $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] == 'about' )
2001-03-08 09:44:57 +01:00
{
2004-04-13 09:54:25 +02:00
$app = $app_title = 'eGroupWare' ;
2001-03-08 09:44:57 +01:00
}
else
{
2005-03-03 11:47:28 +01:00
$app = $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
$app_title = $GLOBALS [ 'egw_info' ][ 'apps' ][ $app ][ 'title' ];
2003-03-28 17:19:46 +01:00
}
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'preferences' ]) // preferences last
2003-03-28 17:19:46 +01:00
{
2005-03-03 11:47:28 +01:00
$prefs = $GLOBALS [ 'egw_info' ][ 'navbar' ][ 'preferences' ];
unset ( $GLOBALS [ 'egw_info' ][ 'navbar' ][ 'preferences' ]);
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'preferences' ] = $prefs ;
2001-03-08 09:44:57 +01:00
}
2001-01-11 10:52:33 +01:00
2003-08-28 16:31:11 +02:00
// We handle this here becuase its special
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'about' ][ 'title' ] = lang ( 'About %1' , $app_title );
2003-04-27 21:27:28 +02:00
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'about' ][ 'url' ] = $GLOBALS [ 'egw' ] -> link ( '/about.php' , 'app=' . $app );
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'about' ][ 'icon' ] = $this -> image ( 'phpgwapi' , Array ( 'about' , 'nonav' ));
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'about' ][ 'icon_hover' ] = $this -> image_on ( 'phpgwapi' , Array ( 'about' , 'nonav' ), '-over' );
2001-01-11 10:52:33 +01:00
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'logout' ][ 'title' ] = lang ( 'Logout' );
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'logout' ][ 'url' ] = $GLOBALS [ 'egw' ] -> link ( '/logout.php' );
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'logout' ][ 'icon' ] = $this -> image ( 'phpgwapi' , Array ( 'logout' , 'nonav' ));
$GLOBALS [ 'egw_info' ][ 'navbar' ][ 'logout' ][ 'icon_hover' ] = $this -> image_on ( 'phpgwapi' , Array ( 'logout' , 'nonav' ), '-over' );
2001-03-08 09:44:57 +01:00
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* load header . inc . php for an application
*
*/
2003-08-28 16:31:11 +02:00
function app_header ()
2002-05-30 23:13:07 +02:00
{
2005-03-03 11:47:28 +01:00
if ( file_exists ( EGW_APP_INC . '/header.inc.php' ))
2002-05-30 23:13:07 +02:00
{
2005-03-03 11:47:28 +01:00
include ( EGW_APP_INC . '/header.inc.php' );
2002-05-30 23:13:07 +02:00
}
}
2005-03-03 11:47:28 +01:00
2005-11-02 12:45:52 +01:00
/**
* load the phpgw header
*
*/
2005-03-03 11:47:28 +01:00
function egw_header ()
2002-10-26 22:33:04 +02:00
{
2004-06-10 09:13:37 +02:00
// add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv)
2005-03-03 11:47:28 +01:00
header ( 'Content-type: text/html; charset=' . $GLOBALS [ 'egw' ] -> translation -> charset ());
2004-06-10 09:13:37 +02:00
2005-03-03 11:47:28 +01:00
ob_end_flush ();
2005-07-17 23:00:49 +02:00
include_once ( EGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ]
2003-08-28 16:31:11 +02:00
. '/head.inc.php' );
$this -> navbar ( False );
2005-07-17 23:00:49 +02:00
include_once ( EGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ]
2003-08-28 16:31:11 +02:00
. '/navbar.inc.php' );
2005-03-03 11:47:28 +01:00
if ( !@ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'nonavbar' ] && !@ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'navbar_target' ])
2002-10-26 22:33:04 +02:00
{
2003-08-28 16:31:11 +02:00
echo parse_navbar ();
2002-10-26 22:33:04 +02:00
}
}
2005-03-03 11:47:28 +01:00
function egw_footer ()
2003-04-21 10:32:53 +02:00
{
2005-03-03 11:47:28 +01:00
if ( ! defined ( 'EGW_FOOTER' ))
2002-10-26 00:34:04 +02:00
{
2005-03-03 11:47:28 +01:00
define ( 'EGW_FOOTER' , True );
if ( ! isset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'nofooter' ]) || ! $GLOBALS [ 'egw_info' ][ 'flags' ][ 'nofooter' ])
2002-10-26 00:34:04 +02:00
{
2005-03-03 11:47:28 +01:00
include ( EGW_API_INC . '/footer.inc.php' );
2002-10-26 00:34:04 +02:00
}
}
}
2003-08-30 10:44:51 +02:00
/**
* Used by template headers for including CSS in the header
*
* This first loads up the basic global CSS definitions , which support
* the selected user theme colors . Next we load up the app CSS . This is
* all merged into the selected theme ' s css . tpl file .
*
* @ author Dave Hall ( * based * on verdilak ? css inclusion code )
*/
2003-08-28 16:31:11 +02:00
function get_css ()
{
2005-11-02 12:45:52 +01:00
$tpl =& CreateObject ( 'phpgwapi.Template' , $this -> get_tpl_dir ( 'phpgwapi' ));
2003-08-28 16:31:11 +02:00
$tpl -> set_file ( 'css' , 'css.tpl' );
2005-03-03 11:47:28 +01:00
$tpl -> set_var ( $GLOBALS [ 'egw_info' ][ 'theme' ]);
2003-08-28 16:31:11 +02:00
$app_css = '' ;
2003-12-20 19:41:42 +01:00
if ( @ isset ( $_GET [ 'menuaction' ]))
{
list ( $app , $class , $method ) = explode ( '.' , $_GET [ 'menuaction' ]);
if ( is_array ( $GLOBALS [ $class ] -> public_functions ) &&
$GLOBALS [ $class ] -> public_functions [ 'css' ])
{
$app_css .= $GLOBALS [ $class ] -> css ();
}
}
2005-03-03 11:47:28 +01:00
if ( isset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'css' ]))
2003-12-20 19:41:42 +01:00
{
2005-03-03 11:47:28 +01:00
$app_css .= $GLOBALS [ 'egw_info' ][ 'flags' ][ 'css' ];
2003-12-20 19:41:42 +01:00
}
2003-08-30 10:44:51 +02:00
$tpl -> set_var ( 'app_css' , $app_css );
2003-12-20 19:41:42 +01:00
2003-10-11 09:58:40 +02:00
// search for app specific css file
2005-03-03 11:47:28 +01:00
if ( @ isset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ]))
2003-10-11 09:58:40 +02:00
{
2005-03-03 11:47:28 +01:00
$appname = $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
2003-12-20 19:41:42 +01:00
2005-03-03 11:47:28 +01:00
if ( file_exists ( EGW_SERVER_ROOT . SEP . $appname . SEP
. 'templates' . SEP . $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ]
2003-12-20 19:41:42 +01:00
. SEP . 'app.css' )
)
2003-10-11 09:58:40 +02:00
{
2005-03-03 11:47:28 +01:00
$tpl -> set_var ( 'css_file' , '<LINK href="' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ]
. " / $appname /templates/ " . $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ]
2003-12-20 19:41:42 +01:00
. " /app.css " . '" type=text/css rel=StyleSheet>' );
2003-10-11 09:58:40 +02:00
}
2005-03-03 11:47:28 +01:00
elseif ( file_exists ( EGW_SERVER_ROOT . SEP . $appname . SEP
2003-12-20 19:41:42 +01:00
. 'templates' . SEP . 'default'
. SEP . 'app.css' )
)
2003-10-11 09:58:40 +02:00
{
2005-03-03 11:47:28 +01:00
$tpl -> set_var ( 'css_file' , '<LINK href="' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ]
2003-10-11 09:58:40 +02:00
. " / $appname /templates/default/app.css " . '" type=text/css rel=StyleSheet>' );
}
}
2003-12-20 19:41:42 +01:00
return $tpl -> subst ( 'css' );
2003-08-30 10:44:51 +02:00
}
2003-12-20 19:41:42 +01:00
2003-08-30 10:44:51 +02:00
/**
* Used by the template headers for including javascript in the header
*
* The method is included here to make it easier to change the js support
2004-01-18 22:12:53 +01:00
* in phpgw . One change then all templates will support it ( as long as they
2003-08-30 10:44:51 +02:00
* include a call to this method ) .
*
* @ author Dave Hall ( * vaguely based * on verdilak ? css inclusion code )
* @ return string the javascript to be included
*/
function get_java_script ()
{
$java_script = '' ;
2005-08-28 22:31:36 +02:00
if ( !@ is_object ( $GLOBALS [ 'egw' ] -> js ))
{
$GLOBALS [ 'egw' ] -> js =& CreateObject ( 'phpgwapi.javascript' );
}
// always include javascript helper functions
$GLOBALS [ 'egw' ] -> js -> validate_file ( 'jsapi' , 'jsapi' );
2004-01-29 14:36:38 +01:00
2005-06-18 22:43:14 +02:00
//viniciuscb: in Concisus this condition is inexistent, and in all
//pages the javascript globals are inserted. Today, because
//filescenter needs these javascript globals, this
//include_jsbackend is a must to the javascript globals be
//included.
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'include_jsbackend' ])
{
if ( ! $GLOBALS [ 'egw_info' ][ 'flags' ][ 'nojsapi' ])
{
$GLOBALS [ 'egw' ] -> js -> validate_jsapi ();
}
if ( @ is_object ( $GLOBALS [ 'egw' ] -> js ))
{
$java_script .= $GLOBALS [ 'egw' ] -> js -> get_javascript_globals ();
}
}
2005-07-20 10:07:47 +02:00
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'include_xajax' ])
{
require_once ( EGW_SERVER_ROOT . '/phpgwapi/inc/xajax.inc.php' );
2005-11-02 12:45:52 +01:00
$xajax =& new xajax ( $GLOBALS [ 'egw' ] -> link ( '/xajax.php' ));
2005-07-20 10:07:47 +02:00
$xajax -> registerFunction ( " doXMLHTTP " );
2005-07-20 10:12:21 +02:00
$java_script .= $xajax -> getJavascript ();
2005-07-20 10:07:47 +02:00
}
2004-01-29 14:36:38 +01:00
/* this flag is for all javascript code that has to be put before other jscode .
Think of conf vars etc ... ( pim @ lingewoud . nl ) */
2005-03-03 11:47:28 +01:00
if ( isset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script_thirst' ]))
2004-01-29 14:36:38 +01:00
{
2005-03-03 11:47:28 +01:00
$java_script .= $GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script_thirst' ] . " \n " ;
2004-01-29 14:36:38 +01:00
}
2005-03-03 11:47:28 +01:00
if ( @ is_object ( $GLOBALS [ 'egw' ] -> js ))
2003-08-30 09:15:36 +02:00
{
2005-03-03 11:47:28 +01:00
$java_script .= $GLOBALS [ 'egw' ] -> js -> get_script_links ();
2003-08-30 09:15:36 +02:00
}
2003-12-20 19:41:42 +01:00
if ( @ isset ( $_GET [ 'menuaction' ]))
{
list ( $app , $class , $method ) = explode ( '.' , $_GET [ 'menuaction' ]);
if ( is_array ( $GLOBALS [ $class ] -> public_functions ) &&
$GLOBALS [ $class ] -> public_functions [ 'java_script' ])
{
$java_script .= $GLOBALS [ $class ] -> java_script ();
}
}
2005-03-03 11:47:28 +01:00
if ( isset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ]))
2003-12-20 19:41:42 +01:00
{
2005-03-03 11:47:28 +01:00
$java_script .= $GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] . " \n " ;
2003-12-20 19:41:42 +01:00
}
2003-08-30 10:44:51 +02:00
return $java_script ;
}
/**
* Returns on ( Un ) Load attributes from js class
*
2004-08-09 15:46:03 +02:00
*@ author Dave Hall - skwashd at egroupware . org
2003-08-30 10:44:51 +02:00
*@ returns string body attributes
*/
function get_body_attribs ()
{
2005-03-03 11:47:28 +01:00
if ( @ is_object ( $GLOBALS [ 'egw' ] -> js ))
2003-08-30 09:15:36 +02:00
{
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> js -> get_body_attribs ();
2003-08-30 10:44:51 +02:00
}
else
{
return '' ;
2003-08-30 09:15:36 +02:00
}
2003-04-20 01:17:40 +02:00
}
2003-08-30 10:44:51 +02:00
2001-03-08 09:44:57 +01:00
function hex2bin ( $data )
{
$len = strlen ( $data );
2003-08-30 10:44:51 +02:00
return @ pack ( 'H' . $len , $data );
2001-03-08 09:44:57 +01:00
}
2001-12-27 16:48:42 +01:00
2005-11-02 12:45:52 +01:00
/**
* encrypt data passed to the function
*
* @ param $data data ( string ? ) to be encrypted
*/
2001-06-13 23:10:36 +02:00
function encrypt ( $data )
2001-03-08 09:44:57 +01:00
{
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> crypto -> encrypt ( $data );
2001-03-08 09:44:57 +01:00
}
2003-08-28 16:31:11 +02:00
2005-11-02 12:45:52 +01:00
/**
* decrypt $data
*
* @ param $data data to be decrypted
*/
2001-03-08 09:44:57 +01:00
function decrypt ( $data )
{
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> crypto -> decrypt ( $data );
2001-03-08 09:44:57 +01:00
}
2001-12-27 16:48:42 +01:00
2005-11-02 12:45:52 +01:00
/**
* legacy wrapper for newer auth class function , encrypt_password
*
* uses the encryption type set in setup and calls the appropriate encryption functions
*
* @ param $password password to encrypt
*/
2004-01-29 04:28:00 +01:00
function encrypt_password ( $password , $sql = False )
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
if ( !@ is_object ( $GLOBALS [ 'egw' ] -> auth ))
2004-01-26 04:22:15 +01:00
{
2005-11-02 12:45:52 +01:00
$GLOBALS [ 'egw' ] -> auth =& CreateObject ( 'phpgwapi.auth' );
2004-01-26 04:22:15 +01:00
}
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> auth -> encrypt_password ( $password , $sql );
2001-06-13 23:10:36 +02:00
}
2001-10-21 12:49:29 +02:00
2005-11-02 12:45:52 +01:00
/**
* find the current position of the app is the users portal_order preference
*
* @ param $app application id to find current position - required
* No discussion
*/
2001-10-21 12:49:29 +02:00
function find_portal_order ( $app )
{
2005-03-03 11:47:28 +01:00
if ( ! is_array ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'portal_order' ]))
2001-10-21 12:49:29 +02:00
{
return - 1 ;
}
2005-03-03 11:47:28 +01:00
@ reset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'portal_order' ]);
while ( list ( $seq , $appid ) = each ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'portal_order' ]))
2001-10-21 12:49:29 +02:00
{
if ( $appid == $app )
{
2005-03-03 11:47:28 +01:00
@ reset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'portal_order' ]);
2001-10-21 12:49:29 +02:00
return $seq ;
}
}
2005-03-03 11:47:28 +01:00
@ reset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'portal_order' ]);
2001-10-21 12:49:29 +02:00
return - 1 ;
}
2005-11-02 12:45:52 +01:00
/**
* temp wrapper to new hooks class
*
*/
2002-01-02 15:33:05 +01:00
function hook ( $location , $appname = '' , $no_permission_check = False )
2001-03-14 13:10:01 +01:00
{
2002-01-02 15:33:05 +01:00
echo '$' . " GLOBALS['phpgw']common->hook() " . ' has been replaced. Please change to the new $' . " GLOBALS['phpgw']hooks->process() " . '. For now this will act as a wrapper<br>' ;
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> hooks -> process ( $location , $order , $no_permission_check );
2001-12-27 16:48:42 +01:00
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* temp wrapper to new hooks class
*
*/
2001-09-04 01:02:36 +02:00
// Note: $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo)
function hook_single ( $location , $appname = '' , $no_permission_check = False )
2001-06-07 03:46:12 +02:00
{
2002-01-02 15:33:05 +01:00
echo '$' . " GLOBALS['phpgw']common->hook_single() " . ' has been replaced. Please change to the new $' . " GLOBALS['phpgw']hooks->single() " . '. For now this will act as a wrapper<br>' ;
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> hooks -> single ( $location , $order , $no_permission_check );
2001-06-07 03:46:12 +02:00
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* temp wrapper to new hooks class
*
*/
2001-06-07 03:46:12 +02:00
function hook_count ( $location )
{
2002-01-02 15:33:05 +01:00
echo '$' . " GLOBALS['phpgw']common->hook_count() " . ' has been replaced. Please change to the new $' . " GLOBALS['phpgw']hooks->count() " . '. For now this will act as a wrapper<br>' ;
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> hooks -> count ( $location );
2001-06-07 03:46:12 +02:00
}
/* Wrapper to the session->appsession() */
function appsession ( $data = '##NOTHING##' )
{
2005-11-02 12:45:52 +01:00
$this -> debug_info [] = " \$ GLOBALS['egw']->common->appsession() is a depreciated function "
. " - use \$ GLOBALS['egw']->session->appsession() instead " ;
2001-06-07 03:46:12 +02:00
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> session -> appsession ( 'default' , '' , $data );
2001-06-07 03:46:12 +02:00
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* show current date
*
* @ param $t time - optional can be pulled from user preferences
* @ param $format - optional can be pulled from user prefernces
*/
2001-06-13 23:10:36 +02:00
function show_date ( $t = '' , $format = '' )
{
2005-03-03 11:47:28 +01:00
if ( ! is_object ( $GLOBALS [ 'egw' ] -> datetime ))
2002-06-25 03:38:34 +02:00
{
2005-11-02 12:45:52 +01:00
$GLOBALS [ 'egw' ] -> datetime =& CreateObject ( 'phpgwapi.datetime' );
2002-06-25 03:38:34 +02:00
}
2004-01-18 22:12:53 +01:00
2005-03-03 11:47:28 +01:00
if ( ! $t )
2001-06-13 23:10:36 +02:00
{
2005-03-03 11:47:28 +01:00
$t = $GLOBALS [ 'egw' ] -> datetime -> gmtnow ;
2001-06-13 23:10:36 +02:00
}
2001-01-11 10:52:33 +01:00
2002-04-30 05:35:52 +02:00
// + (date('I') == 1?3600:0)
2005-03-03 11:47:28 +01:00
$t += $GLOBALS [ 'egw' ] -> datetime -> tz_offset ;
2004-01-18 22:12:53 +01:00
2001-06-13 23:10:36 +02:00
if ( ! $format )
{
2005-03-03 11:47:28 +01:00
$format = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'dateformat' ] . ' - ' ;
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'timeformat' ] == '12' )
2001-06-13 23:10:36 +02:00
{
2003-08-28 16:31:11 +02:00
$format .= 'h:i a' ;
2001-06-13 23:10:36 +02:00
}
else
{
2003-08-28 16:31:11 +02:00
$format .= 'H:i' ;
2001-06-13 23:10:36 +02:00
}
}
2005-03-03 11:47:28 +01:00
return adodb_date ( $format , $t );
2001-06-13 23:10:36 +02:00
}
2001-12-27 16:48:42 +01:00
2005-11-02 12:45:52 +01:00
/**
* @ abstract
* @ param $yearstr year - string
* @ param $monthstr month - string
* @ param $day day - string
* @ param $add_seperator boolean defaults to false
*/
2001-06-13 23:10:36 +02:00
function dateformatorder ( $yearstr , $monthstr , $daystr , $add_seperator = False )
{
2005-03-03 11:47:28 +01:00
$dateformat = strtolower ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'dateformat' ]);
$sep = substr ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'dateformat' ], 1 , 1 );
2001-06-13 23:10:36 +02:00
$dlarr [ strpos ( $dateformat , 'y' )] = $yearstr ;
$dlarr [ strpos ( $dateformat , 'm' )] = $monthstr ;
$dlarr [ strpos ( $dateformat , 'd' )] = $daystr ;
ksort ( $dlarr );
if ( $add_seperator )
{
return ( implode ( $sep , $dlarr ));
}
else
{
return ( implode ( ' ' , $dlarr ));
}
2004-01-18 22:12:53 +01:00
}
2001-12-27 16:48:42 +01:00
2005-11-02 12:45:52 +01:00
/**
* format the time takes settings from user preferences
*
* @ param $hour hour
* @ param $min minutes
* @ param $sec defaults to ''
*/
2001-12-08 16:34:12 +01:00
function formattime ( $hour , $min , $sec = '' )
{
$h12 = $hour ;
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'timeformat' ] == '12' )
2001-12-08 16:34:12 +01:00
{
2004-01-18 22:12:53 +01:00
if ( $hour >= 12 )
2001-12-08 16:34:12 +01:00
{
$ampm = ' pm' ;
}
else
{
$ampm = ' am' ;
}
$h12 %= 12 ;
if ( $h12 == 0 && $hour )
{
$h12 = 12 ;
}
if ( $h12 == 0 && ! $hour )
{
$h12 = 0 ;
}
}
2004-01-18 22:12:53 +01:00
else
2001-12-08 16:34:12 +01:00
{
$h12 = $hour ;
}
2003-09-03 14:28:46 +02:00
if ( $sec !== '' )
2001-12-08 16:34:12 +01:00
{
$sec = " : $sec " ;
}
return " $h12 : $min $sec $ampm " ;
}
2001-07-02 22:02:15 +02:00
// This is not the best place for it, but it needs to be shared bewteen Aeromail and SM
2005-11-02 12:45:52 +01:00
/**
* uses code in / email class msg to obtain the appropriate password for email
*
* @ param ( none - it will abtain the info it needs on its own )
*/
2001-08-08 21:37:17 +02:00
/*
2001-07-02 22:02:15 +02:00
function get_email_passwd_ex ()
{
2001-08-08 21:37:17 +02:00
// ---- Create the email Message Class if needed -----
2005-03-03 11:47:28 +01:00
if ( is_object ( $GLOBALS [ 'egw' ] -> msg ))
2001-07-02 22:02:15 +02:00
{
2001-08-08 21:37:17 +02:00
$do_free_me = False ;
2001-07-02 22:02:15 +02:00
}
else
{
2005-11-02 12:45:52 +01:00
$GLOBALS [ 'egw' ] -> msg =& CreateObject ( 'email.mail_msg' );
2001-08-08 21:37:17 +02:00
$do_free_me = True ;
2001-07-02 22:02:15 +02:00
}
// use the Msg class to obtain the appropriate password
2005-03-03 11:47:28 +01:00
$tmp_prefs = $GLOBALS [ 'egw' ] -> preferences -> read ();
2001-07-02 22:02:15 +02:00
if ( ! isset ( $tmp_prefs [ 'email' ][ 'passwd' ]))
{
2005-03-03 11:47:28 +01:00
$email_passwd = $GLOBALS [ 'egw_info' ][ 'user' ][ 'passwd' ];
2001-07-02 22:02:15 +02:00
}
else
{
2005-03-03 11:47:28 +01:00
$email_passwd = $GLOBALS [ 'egw' ] -> msg -> decrypt_email_passwd ( $tmp_prefs [ 'email' ][ 'passwd' ]);
2001-07-02 22:02:15 +02:00
}
2001-08-08 21:37:17 +02:00
// cleanup and return
if ( $do_free_me )
2001-07-02 22:02:15 +02:00
{
2005-03-03 11:47:28 +01:00
unset ( $GLOBALS [ 'egw' ] -> msg );
2001-07-02 22:02:15 +02:00
}
return $email_passwd ;
}
2001-08-08 21:37:17 +02:00
*/
2001-02-20 09:29:31 +01:00
// This is not the best place for it, but it needs to be shared bewteen Aeromail and SM
2005-11-02 12:45:52 +01:00
/**
* create email preferences
*
* This is not the best place for it , but it needs to be shared between Aeromail and SM
* @ param $prefs
* @ param $account_id - optional defaults to : phpgw_info [ 'user' ][ 'account_id' ]
*/
2001-08-08 21:37:17 +02:00
function create_emailpreferences ( $prefs = '' , $accountid = '' )
{
2005-03-03 11:47:28 +01:00
return $GLOBALS [ 'egw' ] -> preferences -> create_email_preferences ( $accountid );
2001-08-08 21:37:17 +02:00
// ---- Create the email Message Class if needed -----
2005-03-03 11:47:28 +01:00
if ( is_object ( $GLOBALS [ 'egw' ] -> msg ))
2001-08-08 21:37:17 +02:00
{
$do_free_me = False ;
}
else
{
2005-11-02 12:45:52 +01:00
$GLOBALS [ 'egw' ] -> msg =& CreateObject ( 'email.mail_msg' );
2001-08-08 21:37:17 +02:00
$do_free_me = True ;
}
2001-12-27 16:48:42 +01:00
// this sets the preferences into the phpgw_info structure
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> msg -> create_email_preferences ();
2001-08-08 21:37:17 +02:00
// cleanup and return
if ( $do_free_me )
{
2005-03-03 11:47:28 +01:00
unset ( $GLOBALS [ 'egw' ] -> msg );
2001-08-08 21:37:17 +02:00
}
}
/*
2001-03-19 21:25:04 +01:00
function create_emailpreferences ( $prefs , $accountid = '' )
2001-02-20 09:29:31 +01:00
{
2001-03-19 21:25:04 +01:00
$account_id = get_account_id ( $accountid );
2004-01-18 22:12:53 +01:00
2001-07-02 22:02:15 +02:00
// NEW EMAIL PASSWD METHOD (shared between SM and aeromail)
$prefs [ 'email' ][ 'passwd' ] = $this -> get_email_passwd_ex ();
2004-01-18 22:12:53 +01:00
2001-08-08 21:37:17 +02:00
// Add default preferences info
2001-03-07 20:02:25 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'userid' ]))
2001-02-20 09:29:31 +01:00
{
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'mail_login_type' ] == 'vmailmgr' )
2001-02-20 09:29:31 +01:00
{
2005-03-03 11:47:28 +01:00
$prefs [ 'email' ][ 'userid' ] = $GLOBALS [ 'egw' ] -> accounts -> id2name ( $account_id )
. '@' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'mail_suffix' ];
2001-02-20 09:29:31 +01:00
}
else
{
2005-03-03 11:47:28 +01:00
$prefs [ 'email' ][ 'userid' ] = $GLOBALS [ 'egw' ] -> accounts -> id2name ( $account_id );
2001-02-20 09:29:31 +01:00
}
}
2001-08-08 21:37:17 +02:00
// Set Server Mail Type if not defined
2005-03-03 11:47:28 +01:00
if ( empty ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'mail_server_type' ]))
2001-02-20 09:29:31 +01:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'mail_server_type' ] = 'imap' ;
2001-02-20 09:29:31 +01:00
}
2004-01-18 22:12:53 +01:00
2001-08-08 21:37:17 +02:00
// OLD EMAIL PASSWD METHOD
2001-03-07 20:02:25 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'passwd' ]))
2001-02-20 09:29:31 +01:00
{
2005-03-03 11:47:28 +01:00
$prefs [ 'email' ][ 'passwd' ] = $GLOBALS [ 'egw_info' ][ 'user' ][ 'passwd' ];
2001-02-20 09:29:31 +01:00
}
2001-02-21 04:48:59 +01:00
else
{
2001-03-07 20:02:25 +01:00
$prefs [ 'email' ][ 'passwd' ] = $this -> decrypt ( $prefs [ 'email' ][ 'passwd' ]);
2001-08-08 21:37:17 +02:00
}
2001-07-02 22:02:15 +02:00
// NEW EMAIL PASSWD METHOD Located at the begining of this function
2004-01-18 22:12:53 +01:00
2001-03-07 20:02:25 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'address' ]))
2001-02-20 09:29:31 +01:00
{
2005-03-03 11:47:28 +01:00
$prefs [ 'email' ][ 'address' ] = $GLOBALS [ 'egw' ] -> accounts -> id2name ( $account_id )
. '@' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'mail_suffix' ];
2001-02-20 09:29:31 +01:00
}
2001-03-07 20:02:25 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'mail_server' ]))
2001-02-20 09:29:31 +01:00
{
2005-03-03 11:47:28 +01:00
$prefs [ 'email' ][ 'mail_server' ] = $GLOBALS [ 'egw_info' ][ 'server' ][ 'mail_server' ];
2001-02-20 09:29:31 +01:00
}
2001-03-07 20:02:25 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'mail_server_type' ]))
2001-02-20 09:29:31 +01:00
{
2005-03-03 11:47:28 +01:00
$prefs [ 'email' ][ 'mail_server_type' ] = $GLOBALS [ 'egw_info' ][ 'server' ][ 'mail_server_type' ];
2001-02-20 09:29:31 +01:00
}
2001-03-07 20:02:25 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'imap_server_type' ]))
2001-02-20 09:29:31 +01:00
{
2005-03-03 11:47:28 +01:00
$prefs [ 'email' ][ 'imap_server_type' ] = $GLOBALS [ 'egw_info' ][ 'server' ][ 'imap_server_type' ];
2001-02-20 09:29:31 +01:00
}
2001-08-08 21:37:17 +02:00
// These sets the mail_port server variable
2001-03-07 20:02:25 +01:00
if ( $prefs [ 'email' ][ 'mail_server_type' ] == 'imap' )
2001-02-20 09:29:31 +01:00
{
2001-03-07 20:02:25 +01:00
$prefs [ 'email' ][ 'mail_port' ] = '143' ;
2001-02-20 09:29:31 +01:00
}
2001-04-09 13:45:01 +02:00
elseif ( $prefs [ 'email' ][ 'mail_server_type' ] == 'pop3' )
2001-02-20 09:29:31 +01:00
{
2001-03-07 20:02:25 +01:00
$prefs [ 'email' ][ 'mail_port' ] = '110' ;
2001-02-20 09:29:31 +01:00
}
2004-01-18 22:12:53 +01:00
elseif ( $prefs [ 'email' ][ 'mail_server_type' ] == 'imaps' )
{
$prefs [ 'email' ][ 'mail_port' ] = '993' ;
}
elseif ( $prefs [ 'email' ][ 'mail_server_type' ] == 'pop3s' )
{
$prefs [ 'email' ][ 'mail_port' ] = '995' ;
}
2001-08-08 21:37:17 +02:00
// This is going to be used to switch to the nntp class
2005-03-03 11:47:28 +01:00
if ( isset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'newsmode' ]) &&
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'newsmode' ])
2001-02-20 09:29:31 +01:00
{
2001-03-07 20:02:25 +01:00
$prefs [ 'email' ][ 'mail_server_type' ] = 'nntp' ;
2001-02-21 04:02:20 +01:00
}
2001-07-02 22:02:15 +02:00
// DEBUG
//echo "<br>prefs['email']['passwd']: " .$prefs['email']['passwd'] .'<br>';
2001-03-08 19:51:17 +01:00
return $prefs ;
2001-02-20 09:29:31 +01:00
}
2001-08-08 21:37:17 +02:00
*/
2001-02-20 09:29:31 +01:00
2001-06-13 23:10:36 +02:00
// This will be moved into the applications area.
2005-11-02 12:45:52 +01:00
/**
* ?
*
* This will be moved into the applications area
*/
2001-06-13 23:10:36 +02:00
function check_code ( $code )
{
$s = '<br>' ;
switch ( $code )
{
case 13 : $s .= lang ( 'Your message has been sent' ); break ;
case 14 : $s .= lang ( 'New entry added sucessfully' ); break ;
case 15 : $s .= lang ( 'Entry updated sucessfully' ); break ;
case 16 : $s .= lang ( 'Entry has been deleted sucessfully' ); break ;
case 18 : $s .= lang ( 'Password has been updated' ); break ;
case 38 : $s .= lang ( 'Password could not be changed' ); break ;
case 19 : $s .= lang ( 'Session has been killed' ); break ;
case 27 : $s .= lang ( 'Account has been updated' ); break ;
case 28 : $s .= lang ( 'Account has been created' ); break ;
case 29 : $s .= lang ( 'Account has been deleted' ); break ;
case 30 : $s .= lang ( 'Your settings have been updated' ); break ;
case 31 : $s .= lang ( 'Group has been added' ); break ;
case 32 : $s .= lang ( 'Group has been deleted' ); break ;
case 33 : $s .= lang ( 'Group has been updated' ); break ;
case 34 : $s .= lang ( 'Account has been deleted' ) . '<p>'
2004-01-18 22:12:53 +01:00
. lang ( 'Error deleting %1 %2 directory' , lang ( 'users' ), ' ' . lang ( 'private' ) . ' ' )
2003-04-23 00:30:38 +02:00
. ',<br>' . lang ( 'Please %1 by hand' , lang ( 'delete' )) . '<br><br>'
2001-06-13 23:10:36 +02:00
. lang ( 'To correct this error for the future you will need to properly set the' )
. '<br>' . lang ( 'permissions to the files/users directory' )
2003-08-28 16:31:11 +02:00
. '<br>' . lang ( 'On *nix systems please type: %1' , 'chmod 770 '
2005-03-03 11:47:28 +01:00
. $GLOBALS [ 'egw_info' ][ 'server' ][ 'files_dir' ] . '/users/' );
2001-06-13 23:10:36 +02:00
break ;
case 35 : $s .= lang ( 'Account has been updated' ) . '<p>'
2003-04-23 00:30:38 +02:00
. lang ( 'Error renaming %1 %2 directory' , lang ( 'users' ),
2004-01-18 22:12:53 +01:00
' ' . lang ( 'private' ) . ' ' )
2003-04-23 00:30:38 +02:00
. ',<br>' . lang ( 'Please %1 by hand' ,
2001-06-13 23:10:36 +02:00
lang ( 'rename' )) . '<br><br>'
. lang ( 'To correct this error for the future you will need to properly set the' )
. '<br>' . lang ( 'permissions to the files/users directory' )
2003-08-28 16:31:11 +02:00
. '<br>' . lang ( 'On *nix systems please type: %1' , 'chmod 770 '
2005-03-03 11:47:28 +01:00
. $GLOBALS [ 'egw_info' ][ 'server' ][ 'files_dir' ] . '/users/' );
2001-06-13 23:10:36 +02:00
break ;
case 36 : $s .= lang ( 'Account has been created' ) . '<p>'
2003-04-23 00:30:38 +02:00
. lang ( 'Error creating %1 %2 directory' , lang ( 'users' ),
2004-01-18 22:12:53 +01:00
' ' . lang ( 'private' ) . ' ' )
2003-04-23 00:30:38 +02:00
. ',<br>' . lang ( 'Please %1 by hand' ,
2001-06-13 23:10:36 +02:00
lang ( 'create' )) . '<br><br>'
. lang ( 'To correct this error for the future you will need to properly set the' )
. '<br>' . lang ( 'permissions to the files/users directory' )
2003-08-28 16:31:11 +02:00
. '<br>' . lang ( 'On *nix systems please type: %1' , 'chmod 770 '
2005-03-03 11:47:28 +01:00
. $GLOBALS [ 'egw_info' ][ 'server' ][ 'files_dir' ] . '/users/' );
2001-06-13 23:10:36 +02:00
break ;
case 37 : $s .= lang ( 'Group has been added' ) . '<p>'
2003-04-23 00:30:38 +02:00
. lang ( 'Error creating %1 %2 directory' , lang ( 'groups' ), ' ' )
. ',<br>' . lang ( 'Please %1 by hand' ,
2001-06-13 23:10:36 +02:00
lang ( 'create' )) . '<br><br>'
. lang ( 'To correct this error for the future you will need to properly set the' )
. '<br>' . lang ( 'permissions to the files/users directory' )
2003-08-28 16:31:11 +02:00
. '<br>' . lang ( 'On *nix systems please type: %1' , 'chmod 770 '
2005-03-03 11:47:28 +01:00
. $GLOBALS [ 'egw_info' ][ 'server' ][ 'files_dir' ] . '/groups/' );
2001-06-13 23:10:36 +02:00
break ;
case 38 : $s .= lang ( 'Group has been deleted' ) . '<p>'
2003-04-23 00:30:38 +02:00
. lang ( 'Error deleting %1 %2 directory' , lang ( 'groups' ), ' ' )
. ',<br>' . lang ( 'Please %1 by hand' ,
2001-06-13 23:10:36 +02:00
lang ( 'delete' )) . '<br><br>'
. lang ( 'To correct this error for the future you will need to properly set the' )
. '<br>' . lang ( 'permissions to the files/users directory' )
2003-08-28 16:31:11 +02:00
. '<br>' . lang ( 'On *nix systems please type: %1' , 'chmod 770 '
2005-03-03 11:47:28 +01:00
. $GLOBALS [ 'egw_info' ][ 'server' ][ 'files_dir' ] . '/groups/' );
2001-06-13 23:10:36 +02:00
break ;
case 39 : $s .= lang ( 'Group has been updated' ) . '<p>'
2003-04-23 00:30:38 +02:00
. lang ( 'Error renaming %1 %2 directory' , lang ( 'groups' ), ' ' )
. ',<br>' . lang ( 'Please %1 by hand' ,
2001-06-13 23:10:36 +02:00
lang ( 'rename' )) . '<br><br>'
. lang ( 'To correct this error for the future you will need to properly set the' )
. '<br>' . lang ( 'permissions to the files/users directory' )
2003-08-28 16:31:11 +02:00
. '<br>' . lang ( 'On *nix systems please type: %1' , 'chmod 770 '
2005-03-03 11:47:28 +01:00
. $GLOBALS [ 'egw_info' ][ 'server' ][ 'files_dir' ] . '/groups/' );
2001-06-13 23:10:36 +02:00
break ;
case 40 : $s .= lang ( 'You have not entered a title' ) . '.' ;
break ;
case 41 : $s .= lang ( 'You have not entered a valid time of day' ) . '.' ;
break ;
case 42 : $s .= lang ( 'You have not entered a valid date' ) . '.' ;
break ;
2001-08-31 03:01:05 +02:00
case 43 : $s .= lang ( 'You have not entered participants' ) . '.' ;
break ;
2001-06-13 23:10:36 +02:00
default : return '' ;
}
return $s ;
}
2005-11-02 12:45:52 +01:00
/**
* process error message
*
* @ param $error error
* @ param $line line
* @ param $file file
*/
2004-01-18 22:12:53 +01:00
function phpgw_error ( $error , $line = '' , $file = '' )
2001-06-13 23:10:36 +02:00
{
2004-08-09 15:46:03 +02:00
echo '<p><b>eGroupWare internal error:</b><p>' . $error ;
2001-06-13 23:10:36 +02:00
if ( $line )
{
echo 'Line: ' . $line ;
}
if ( $file )
{
echo 'File: ' . $file ;
}
echo '<p>Your session has been halted.' ;
exit ;
}
2001-01-11 10:52:33 +01:00
2005-11-02 12:45:52 +01:00
/**
* create phpcode from array
*
* @ param $array - array
*/
2001-06-13 23:10:36 +02:00
function create_phpcode_from_array ( $array )
{
while ( list ( $key , $val ) = each ( $array ))
{
if ( is_array ( $val ))
{
while ( list ( $key2 , $val2 ) = each ( $val ))
{
if ( is_array ( $val2 ))
{
while ( list ( $key3 , $val3 ) = each ( $val2 ))
{
if ( is_array ( $val3 ))
{
while ( list ( $key4 , $val4 ) = each ( $val3 ))
{
2005-03-03 11:47:28 +01:00
$s .= " \$ GLOBALS['egw_info'][' " . $key . " '][' " . $key2 . " '][' " . $key3 . " '][' " . $key4 . " ']=' " . $val4 . " '; " ;
2001-06-13 23:10:36 +02:00
$s .= " \n " ;
}
}
else
{
2005-03-03 11:47:28 +01:00
$s .= " \$ GLOBALS['egw_info'][' " . $key . " '][' " . $key2 . " '][' " . $key3 . " ']=' " . $val3 . " '; " ;
2001-06-13 23:10:36 +02:00
$s .= " \n " ;
}
}
}
else
{
2005-03-03 11:47:28 +01:00
$s .= " \$ GLOBALS['egw_info'][' " . $key . " '][' " . $key2 . " ']=' " . $val2 . " '; " ;
2001-06-13 23:10:36 +02:00
$s .= " \n " ;
}
}
}
else
{
2005-03-03 11:47:28 +01:00
$s .= " \$ GLOBALS['egw_info'][' " . $key . " ']=' " . $val . " '; " ;
2001-06-13 23:10:36 +02:00
$s .= " \n " ;
}
}
return $s ;
}
// This will return the full phpgw_info array, used for debugging
2005-11-02 12:45:52 +01:00
/**
* return the full phpgw_info array for debugging
*
* @ param array - array
*/
2001-06-13 23:10:36 +02:00
function debug_list_array_contents ( $array )
{
while ( list ( $key , $val ) = each ( $array ))
{
if ( is_array ( $val ))
{
while ( list ( $key2 , $val2 ) = each ( $val ))
{
if ( is_array ( $val2 ))
{
while ( list ( $key3 , $val3 ) = each ( $val2 ))
{
if ( is_array ( $val3 ))
{
while ( list ( $key4 , $val4 ) = each ( $val3 ))
{
echo $$array . " [ $key ][ $key2 ][ $key3 ][ $key4 ]= $val4 <br> " ;
}
}
else
{
echo $$array . " [ $key ][ $key2 ][ $key3 ]= $val3 <br> " ;
}
}
}
else
{
echo $$array . " [ $key ][ $key2 ]= $val2 <br> " ;
}
}
}
else
{
echo $$array . " [ $key ]= $val <br> " ;
}
}
}
// This will return a list of functions in the API
2005-11-02 12:45:52 +01:00
/**
* return a list of functionsin the API
*
*/
2001-06-13 23:10:36 +02:00
function debug_list_core_functions ()
{
echo '<br><b>core functions</b><br>' ;
echo '<pre>' ;
2005-03-03 11:47:28 +01:00
chdir ( EGW_INCLUDE_ROOT . '/phpgwapi' );
2001-06-13 23:10:36 +02:00
system ( " grep -r '^[ \t ]*function' * " );
echo '</pre>' ;
}
2005-11-13 11:13:16 +01:00
var $nextid_table = 'egw_nextid' ;
2001-06-13 23:10:36 +02:00
2005-11-02 12:45:52 +01:00
/**
2005-11-13 11:13:16 +01:00
* Return a value for the next id an app / class may need to insert values into LDAP
2005-11-02 12:45:52 +01:00
*
2005-11-13 11:13:16 +01:00
* @ param string $appname app - name
* @ param int $min = 0 if != 0 minimum id
* @ param int $max = 0 if != 0 maximum id allowed , if it would be exceeded we return false
* @ return int / boolean the next id or false if $max given and exceeded
2005-11-02 12:45:52 +01:00
*/
2001-06-13 23:10:36 +02:00
function next_id ( $appname , $min = 0 , $max = 0 )
{
if ( ! $appname )
{
return - 1 ;
}
2001-03-22 09:23:35 +01:00
2005-11-13 11:13:16 +01:00
$GLOBALS [ 'egw' ] -> db -> select ( $this -> nextid_table , 'id' , array ( 'appname' => $appname ), __LINE__ , __FILE__ );
$id = $GLOBALS [ 'egw' ] -> db -> next_record () ? $GLOBALS [ 'egw' ] -> db -> f ( 'id' ) : 0 ;
2001-03-22 09:23:35 +01:00
2005-11-13 11:13:16 +01:00
if ( $max && $id >= $max )
2001-06-13 23:10:36 +02:00
{
return False ;
}
2005-11-13 11:13:16 +01:00
++ $id ;
if ( $id < $min ) $id = $min ;
$GLOBALS [ 'egw' ] -> db -> insert ( $this -> nextid_table , array ( 'id' => $id ), array ( 'appname' => $appname ), __LINE__ , __FILE__ );
2001-03-22 09:23:35 +01:00
2003-12-10 12:35:22 +01:00
return ( int ) $id ;
2001-06-13 23:10:36 +02:00
}
2001-03-23 05:42:22 +01:00
2005-11-02 12:45:52 +01:00
/**
2005-11-13 11:13:16 +01:00
* Return a value for the last id entered , which an app may need to check values for LDAP
2005-11-02 12:45:52 +01:00
*
2005-11-13 11:13:16 +01:00
* @ param string $appname app - name
* @ param int $min = 0 if != 0 minimum id
* @ param int $max = 0 if != 0 maximum id allowed , if it would be exceeded we return false
* @ return int current id in the next_id table for a particular app / class or - 1 for no app and false if $max is exceeded .
2005-11-02 12:45:52 +01:00
*/
2001-06-13 23:10:36 +02:00
function last_id ( $appname , $min = 0 , $max = 0 )
{
if ( ! $appname )
{
return - 1 ;
}
2001-03-23 05:42:22 +01:00
2005-11-13 11:13:16 +01:00
$GLOBALS [ 'egw' ] -> db -> select ( $this -> nextid_table , 'id' , array ( 'appname' => $appname ), __LINE__ , __FILE__ );
$id = $GLOBALS [ 'egw' ] -> db -> next_record () ? $GLOBALS [ 'egw' ] -> db -> f ( 'id' ) : 0 ;
2001-03-23 05:42:22 +01:00
2005-11-13 11:13:16 +01:00
if ( ! $id || $id < $min )
2001-06-13 23:10:36 +02:00
{
2005-11-13 11:13:16 +01:00
return $this -> next_id ( $appname , $min , $max );
2001-06-13 23:10:36 +02:00
}
2005-11-13 11:13:16 +01:00
if ( $max && $id > $max )
2001-06-13 23:10:36 +02:00
{
return False ;
}
2003-12-10 12:35:22 +01:00
return ( int ) $id ;
2001-03-23 05:42:22 +01:00
}
2005-03-03 11:47:28 +01:00
2005-11-09 13:45:48 +01:00
/**
* gets an eGW conformat referer from $_SERVER [ 'HTTP_REFERER' ], suitable for direct use in the link function
*
* @ param string $default = '' default to use if referer is not set by webserver or not determinable
* @ return string
*/
function get_referer ( $default = '' )
{
$referer = $_SERVER [ 'HTTP_REFERER' ];
2005-11-21 09:21:11 +01:00
$webserver_url = $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ];
if ( empty ( $webserver_url ) || $webserver_url == '/' ) // fix for eGW installed in the docroot
{
$referer = preg_replace ( '/^https?:\/\/[^\/]+/' , '' , $referer ); // removing the domain part
}
else
{
$parts = explode ( $webserver_url , $referer );
$referer = array_pop ( $parts );
}
$referer = str_replace ( '/etemplate/process_exec.php' , '/index.php' , $referer );
2005-11-09 14:27:49 +01:00
2005-11-09 13:45:48 +01:00
if ( empty ( $referer )) $referer = $default ;
return $referer ;
}
2005-03-03 11:47:28 +01:00
// some depricated functions for the migration
function phpgw_exit ( $call_footer = False )
{
$this -> egw_exit ( $call_footer );
}
function phpgw_final ()
{
$this -> egw_final ();
}
function phpgw_header ()
{
$this -> egw_header ();
}
function phpgw_footer ()
{
$this -> egw_footer ();
}
2001-06-13 23:10:36 +02:00
} //end common class