source: trunk/phpgwapi/inc/class.common.inc.php @ 2857

Revision 2857, 63.1 KB checked in by amuller, 14 years ago (diff)

Ticket #1086 - Corrigindo caminho de inclusão do rsa.inc.php

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare API - Commononly used functions                               *
4  * This file written by Dan Kuykendall <seek3r@phpgroupware.org>            *
5  * and Joseph Engo <jengo@phpgroupware.org>                                 *
6  * and Mark Peters <skeeter@phpgroupware.org>                               *
7  * and Lars Kneschke <lkneschke@linux-at-work.de>                           *
8  * Functions commonly used by eGroupWare developers                         *
9  * Copyright (C) 2000, 2001 Dan Kuykendall                                  *
10  * Copyright (C) 2003 Lars Kneschke                                         *
11  * -------------------------------------------------------------------------*
12  * This library is part of the eGroupWare API                               *
13  * http://www.egroupware.org                                                *
14  * ------------------------------------------------------------------------ *
15  * This library is free software; you can redistribute it and/or modify it  *
16  * under the terms of the GNU Lesser General Public License as published by *
17  * the Free Software Foundation; either version 2.1 of the License,         *
18  * or any later version.                                                    *
19  * This library is distributed in the hope that it will be useful, but      *
20  * WITHOUT ANY WARRANTY; without even the implied warranty of               *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
22  * See the GNU Lesser General Public License for more details.              *
23  * You should have received a copy of the GNU Lesser General Public License *
24  * along with this library; if not, write to the Free Software Foundation,  *
25  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
26  \**************************************************************************/
27
28        function ldap_rebind($ldap_connection, $ldap_url)
29        {
30                @ldap_bind($ldap_connection, $GLOBALS['phpgw_info']['server']['user_ldap_referral'], $GLOBALS['phpgw_info']['server']['password_ldap_referral']);
31        }
32        $d1 = strtolower(@substr(PHPGW_API_INC,0,3));
33        $d2 = strtolower(@substr(PHPGW_SERVER_ROOT,0,3));
34        $d3 = strtolower(@substr(PHPGW_APP_INC,0,3));
35        if($d1 == 'htt' || $d1 == 'ftp' || $d2 == 'htt' || $d2 == 'ftp' || $d3 == 'htt' || $d3 == 'ftp')
36        {
37                echo 'Failed attempt to break in via an old Security Hole!<br>'."\n";
38                exit;
39        }
40        unset($d1);unset($d2);unset($d3);
41
42        /*!
43        @class common
44        @abstract common class that contains commonly used functions
45        */
46        class common
47        {
48                var $debug_info; // An array with debugging info from the API
49                var $found_files;
50
51                /*!
52                @function cmp_version
53                @abstract Compares two Version strings and return 1 if str2 is newest (bigger version number) than str1
54                @discussion This function checks for major version only.
55                @param $str1
56                @param $str2
57                */
58                function cmp_version($str1,$str2,$debug=False)
59                {
60                        ereg("([0-9]+)\.([0-9]+)\.([0-9]+)[a-zA-Z]*([0-9]*)",$str1,$regs);
61                        ereg("([0-9]+)\.([0-9]+)\.([0-9]+)[a-zA-Z]*([0-9]*)",$str2,$regs2);
62                        if($debug) { echo "<br>$regs[0] - $regs2[0]"; }
63
64                        for($i=1;$i<5;$i++)
65                        {
66                                if($debug) { echo "<br>$i: $regs[$i] - $regs2[$i]"; }
67                                if($regs2[$i] == $regs[$i])
68                                {
69                                        continue;
70                                }
71                                if($regs2[$i] > $regs[$i])
72                                {
73                                        return 1;
74                                }
75                                elseif($regs2[$i] < $regs[$i])
76                                {
77                                        return 0;
78                                }
79                        }
80                }
81
82                /*!
83                @function cmp_version_long
84                @abstract Compares two Version strings and return 1 if str2 is newest (bigger version number) than str1
85                @discussion This function checks all fields. cmp_version() checks release version only.
86                @param $str1
87                @param $str2
88                */
89                function cmp_version_long($str1,$str2,$debug=False)
90                {
91                        ereg("([0-9]+)\.([0-9]+)\.([0-9]+)[a-zA-Z]*([0-9]*)\.([0-9]*)",$str1,$regs);
92                        ereg("([0-9]+)\.([0-9]+)\.([0-9]+)[a-zA-Z]*([0-9]*)\.([0-9]*)",$str2,$regs2);
93                        if($debug) { echo "<br>$regs[0] - $regs2[0]"; }
94
95                        for($i=1;$i<6;$i++)
96                        {
97                                if($debug) { echo "<br>$i: $regs[$i] - $regs2[$i]"; }
98
99                                if($regs2[$i] == $regs[$i])
100                                {
101                                        if($debug) { echo ' are equal...'; }
102                                        continue;
103                                }
104                                if($regs2[$i] > $regs[$i])
105                                {
106                                        if($debug) { echo ', and a > b'; }
107                                        return 1;
108                                }
109                                elseif($regs2[$i] < $regs[$i])
110                                {
111                                        if($debug) { echo ', and a < b'; }
112                                        return 0;
113                                }
114                        }
115                        if($debug) { echo ' - all equal.'; }
116                }
117
118                // Convert an array into the format needed for the access column.
119                /*!
120                @function array_to_string
121                @abstract Convert an array into the format needed for the access column
122                @param $access
123                @param $array
124                */
125                function array_to_string($access,$array)
126                {
127                        $this->debug_info[] = 'array_to_string() is a depreciated function - use ACL instead';
128                        $s = '';
129                        if ($access == 'group' || $access == 'public' || $access == 'none')
130                        {
131                                if (count($array))
132                                {
133                                        while ($t = each($array))
134                                        {
135                                                $s .= ',' . $t[1];
136                                        }
137                                        $s .= ',';
138                                }
139                                if (! count($array) && $access == 'none')
140                                {
141                                        $s = '';
142                                }
143                        }
144                        return $s;
145                }
146
147                // This is used for searching the access fields
148                /*!
149                @function sql_search
150                @abstract this function is used for searching the access fields
151                @param $table
152                @param $owner
153                */
154                function sql_search($table,$owner=0)
155                {
156                        $this->debug_info[] = 'sql_search() is a deprecated function - use ACL instead';
157                        $s = '';
158                        if (!$owner)
159                        {
160                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
161                        }
162                        $groups = $GLOBALS['phpgw']->accounts->membership((int)$owner);
163                        if(@is_array($groups))
164                        {
165                                while ($group = each($groups))
166                                {
167                                        $s .= " OR $table LIKE '%," . $group[2] . ",%'";
168                                }
169                        }
170                        return $s;
171                }
172
173                // return a array of installed languages
174                /*!
175                @function getInstalledLanguages
176                @abstract return an array of installed languages
177                @result $installedLanguages; an array containing the installed languages
178                */
179                function getInstalledLanguages()
180                {
181                        $GLOBALS['phpgw']->db->query('SELECT DISTINCT lang FROM phpgw_lang');
182                        while (@$GLOBALS['phpgw']->db->next_record())
183                        {
184                                $installedLanguages[$GLOBALS['phpgw']->db->f('lang')] = $GLOBALS['phpgw']->db->f('lang');
185                        }
186
187                        return $installedLanguages;
188                }
189
190                // return the preferred language of the users
191                // it's using HTTP_ACCEPT_LANGUAGE (send from the users browser)
192                // and ...(to find out which languages are installed)
193                /*!
194                @function getPreferredLanguage
195                @abstract return the preferred langugae of the users
196                @discussion it uses HTTP_ACCEPT_LANGUAGE (from the users browser) <br>
197                and .... to find out which languages are installed
198                */
199                function getPreferredLanguage()
200                {
201                        // create a array of languages the user is accepting
202                        $userLanguages = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
203                        $supportedLanguages = $this->getInstalledLanguages();
204
205                        // find usersupported language
206//                      while (list($key,$value) = each($userLanguages))
207                        foreach($userLanguages as $key => $value)
208                        {
209                                // remove everything behind '-' example: de-de
210                                $value = trim($value);
211                                $pieces = explode('-', $value);
212                                $value = $pieces[0];
213                                # print 'current lang $value<br>';
214                                if ($supportedLanguages[$value])
215                                {
216                                        $retValue=$value;
217                                        break;
218                                }
219                        }
220
221                        // no usersupported language found -> return english
222                        if (empty($retValue))
223                        {
224                                $retValue='en';
225                        }
226
227                        return $retValue;
228                }
229
230                /*!
231                @function ldap_addslashes
232                @abstract escapes a string for use in searchfilters meant for ldap_search.
233                Escaped Characters are: '*', '(', ')', ' ', '\', NUL
234                It's actually a PHP-Bug, that we have to escape space.
235                For all other Characters, refer to RFC2254.
236                @param $string string to be escaped
237                */
238                function ldap_addslashes($string='')
239                {
240                        return str_replace(array('\\','*','(',')','\0',' '),array('\\\\','\*','\(','\)','\\0','\20'),$string);
241                }
242
243                // connect to the ldap server and return a handle
244                /*!
245                @function ldapConnect
246                @abstract connect to the ldap server and return a handle
247                @param $host ldap host
248                @param $dn ldap_root_dn
249                @param $passwd ldap_root_pw
250                */
251                function ldapConnect($host='', $dn='', $passwd='', $ldapreferral=false) #default: dont follow the referral
252                {
253                       
254                        if(!$host || $host == $GLOBALS['phpgw_info']['server']['ldap_host']) {                       
255                                $dn     = $dn ? $dn : $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
256                                $passwd = $passwd ? $passwd : $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
257                                $host   = $host ? $host : $GLOBALS['phpgw_info']['server']['ldap_host'];
258                        }
259
260                        /*else if(strstr($host, "ldap://")){
261                                $dn = '';
262                                $passwd = '';
263                        }*/
264
265                        if(!function_exists('ldap_connect'))
266                        {
267                                /* log does not exist in setup(, yet) */
268                                if(is_object($GLOBALS['phpgw']->log))
269                                {
270                                        $GLOBALS['phpgw']->log->message('F-Abort, LDAP support unavailable');
271                                        $GLOBALS['phpgw']->log->commit();
272                                }
273
274                                printf('<b>Error: LDAP support unavailable</b><br>',$host);
275                                return False;
276                        }
277
278                        // connect to ldap server
279                        if(!$ds = ldap_connect($host))
280                        {
281                                /* log does not exist in setup(, yet) */
282                                if(is_object($GLOBALS['phpgw']->log))
283                                {
284                                        $GLOBALS['phpgw']->log->message('F-Abort, Failed connecting to LDAP server');
285                                        $GLOBALS['phpgw']->log->commit();
286                                }
287
288                                printf("<b>Error: Can't connect to LDAP server %s!</b><br>",$host);
289                                return False;
290                        }
291
292                        if($GLOBALS['phpgw_info']['server']['ldap_version3'])
293                        {
294                                if(!ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3))
295                                {
296                                        $GLOBALS['phpgw_info']['server']['ldap_version3'] = False;
297                                }
298                        }
299                       
300                        ldap_set_option($ds, LDAP_OPT_REFERRALS, $ldapreferral);
301                        if($ldapreferral){
302                                $GLOBALS['phpgw_info']['server']['user_ldap_referral'] = $dn;
303                                $GLOBALS['phpgw_info']['server']['password_ldap_referral'] = $passwd;
304                                ldap_set_rebind_proc($ds, ldap_rebind);
305                        }
306                        // bind as admin
307                        if($dn && $passwd && !@ldap_bind($ds,$dn,$passwd))
308                        {                               
309                                // Try rebind for connection problem
310                                if(!@ldap_bind($ds,$dn,$passwd)) {
311                                        if(is_object($GLOBALS['phpgw']->log))
312                                        {
313                                                $GLOBALS['phpgw']->log->message('F-Abort, Failed binding to LDAP server');
314                                                $GLOBALS['phpgw']->log->commit();
315                                        }
316
317                                        if(function_exists("lang"))
318                                                echo '<center><b>'.lang("ExpressoLivre is unavailable at this moment. Code %1<br>Please, try later.","002").'</b></center>';
319                                        else
320                                                printf("Error: Can't bind to LDAP server (invalid credentials): %s",$dn);
321                                        return False;
322                                }
323                        }
324                        // bind as anonymous
325                        if(!$dn && !$passwd && !@ldap_bind($ds))
326                        {
327                                if(is_object($GLOBALS['phpgw']->log))
328                                {
329                                        $GLOBALS['phpgw']->log->message('F-Abort, Failed  (anonymous bind) to LDAP server');
330                                        $GLOBALS['phpgw']->log->commit();
331                                }
332                                if(function_exists("lang"))
333                                        echo '<center><b>'.lang("ExpressoLivre is unavailable at this moment. Code %1<br>Please, try later.","002").'</b></center>';
334                                else
335                                        printf("Error: Can't bind to LDAP server (anonymous bind): %s",$dn);
336                                return False;
337                        }                                               
338                        return $ds;
339                }
340
341                // This function is used if the developer wants to stop a running app in the middle of execution
342                // We may need to do some clean up before hand
343                /*!
344                @function phpgw_exit
345                @abstract function to stop running an app
346                @discussion used to stop running an app in the middle of execution <br>
347                There may need to be some cleanup before hand
348                @param $call_footer boolean value to if true then call footer else exit
349                */
350                function phpgw_exit($call_footer = False)
351                {
352                        if (!defined('PHPGW_EXIT'))
353                        {
354                                define('PHPGW_EXIT',True);
355
356                                if ($call_footer)
357                                {
358                                        $this->phpgw_footer();
359                                }
360                        }
361                        exit;
362                }
363
364                function phpgw_final()
365                {
366                        if (!defined('PHPGW_FINAL'))
367                        {
368                                define('PHPGW_FINAL',True);
369
370                                $module_content = ob_get_contents( );
371
372                                ob_clean( );
373
374                                /*************************************************************************\
375                                * Load the header unless the developer turns it off                       *
376                                \*************************************************************************/
377                                if ( array_key_exists( 'HTTP_BACKGROUNDREQUEST', $_SERVER ) || array_key_exists( 'BackgroundRequest', $_GET ) )
378                                        $GLOBALS['phpgw_info']['flags'] = array_merge( $GLOBALS['phpgw_info']['flags'], array(
379                                                'noheader'   => true,
380                                                'nonavbar'   => true
381                                        ) );
382
383                                if ( ! @$GLOBALS['phpgw_info']['flags']['noheader'] )
384                                {
385                                        if ( ! isset( $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script_thirst' ] ) )
386                                                $GLOBALS['phpgw_info']['flags']['java_script_thirst'] = '';
387
388                                        $webserver_url = ( ! empty( $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'webserver_url' ] ) ) ?
389                                                $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'webserver_url' ] : '/';
390
391                                        if ( strpos( $webserver_url, '/' ) != ( strlen( $webserver_url ) - 1 ) )
392                                                $webserver_url .= '/';
393
394                                        require_once(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.rsa.inc.php');
395                                        $rsa = new rsa();
396                                        $expressolivre = CreateObject( 'phpgwapi.expressolivre' );
397
398                                        $GLOBALS['phpgw_info']['flags']['java_script_thirst'] .= '<script type="text/javascript">'
399                                                . 'var URL_SERVER = window.location.protocol + "//" + window.location.host + "' . $webserver_url . '";'
400                                                . 'var template = "' . $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'template_set' ] . '";'
401                                                . 'var ExpressoLivre = function ExpressoLivre( ) { return String( \'' . $expressolivre -> configuration( ) . '\' ); };'
402                                                . 'keys = ['.$rsa->get_publKey().','.$rsa->get_mod().'];'
403                                                . '</script>';
404
405                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'wz_dragdrop', 'wz_dragdrop', NULL, true );
406                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'expressoAjax', 'expressoAjax', NULL, true );
407
408                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'expressoAjax', 'bigInt', NULL, true );
409
410                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'expressoAjax', 'dom', NULL, true );
411                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'expressolivre','expressolivre', NULL, true );
412                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xform', NULL, true );
413                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xlink', NULL, true );
414                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xscript', NULL, true );
415                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xconnector', NULL, true );
416                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xml', NULL, true );
417                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xevent', NULL, true );
418                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xobject', NULL, true );
419                                        $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'cookieManager', 'phpgwapi/templates/' . $GLOBALS['phpgw_info']['server']['template_set'] );
420
421                                        $this -> phpgw_header( $module_content );
422                                }
423                                else
424                                {
425                                        echo $this -> get_java_script( );
426                                        echo $module_content;
427                                }
428
429                                /*if (is_object($GLOBALS['phpgw']->accounts))
430                                {
431                                        $GLOBALS['phpgw']->accounts->save_session_cache();
432                                }*/
433
434                                // call the asyncservice check_run function if it is not explicitly set to cron-only
435                                //
436                                if (!$GLOBALS['phpgw_info']['server']['asyncservice'])  // is default
437                                {
438                                        ExecMethod('phpgwapi.asyncservice.check_run','fallback');
439                                }
440
441                                /* Clean up mcrypt */
442                                if (@is_object($GLOBALS['phpgw']->crypto))
443                                {
444                                        $GLOBALS['phpgw']->crypto->cleanup();
445                                        unset($GLOBALS['phpgw']->crypto);
446                                }
447
448                                $GLOBALS['phpgw']->db->disconnect();
449                        }
450                }
451
452                /*!
453                @function randomstring
454                @abstract return a random string of size $size
455                @param $size int-size of random string to return
456                */
457                function randomstring($size)
458                {
459                        $s = '';
460                        srand((double)microtime()*1000000);
461                        $random_char = array(
462                                '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f',
463                                'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
464                                'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L',
465                                'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
466                        );
467
468                        for ($i=0; $i<$size; $i++)
469                        {
470                                $s .= $random_char[rand(1,61)];
471                        }
472                        return $s;
473                }
474
475                // Look at the note towards the top of this file (jengo)
476                function filesystem_separator()
477                {
478                        return filesystem_separator();
479                }
480
481                /*!
482                @function error_list
483                @abstract This is used for reporting errors in a nice format.
484                @param $error - array of errors
485                */
486                function error_list($errors,$text='Error')
487                {
488                        if (! is_array($errors))
489                        {
490                                return False;
491                        }
492
493                        $html_error = '<table border="0" width="100%"><tr><td align="right"><b>' . lang($text)
494                                . '</b>: </td><td align="left">' . $errors[0] . '</td></tr>';
495                        for ($i=1; $i<count($errors); $i++)
496                        {
497                                $html_error .= '<tr><td>&nbsp;</td><td align="left">' . $errors[$i] . '</td></tr>';
498                        }
499                        return $html_error . '</table>';
500                }
501
502                /*!
503                @function check_owner
504                @abstract none yet
505                @param $record ?
506                @param $link ?
507                @param $label ?
508                @param $extravars
509                */
510                // This is a depreciated function - use ACL instead (jengo)
511                function check_owner($record,$link,$label,$extravars = '')
512                {
513                        $this->debug_info[] = 'check_owner() is a depreciated function - use ACL instead';
514                        /*
515                        $s = '<a href="' . $GLOBALS['phpgw']->link($link,$extravars) . '"> ' . lang($label) . ' </a>';
516                        if (ereg('^[0-9]+$',$record))
517                        {
518                                if ($record != $GLOBALS['phpgw_info']['user']['account_id'])
519                                {
520                                        $s = '&nbsp;';
521                                }
522                        }
523                        else
524                        {
525                                if ($record != $GLOBALS['phpgw_info']['user']['userid'])
526                                {
527                                        $s = '&nbsp';
528                                }
529                        }
530
531                        return $s;
532                        */
533                }
534
535                /*!
536                @function display_fullname
537                @abstract return the fullname of a user
538                @param $lid account loginid
539                @param $firstname firstname
540                @param $lastname lastname
541                */
542                function display_fullname($lid = '', $firstname = '', $lastname = '')
543                {
544                        if (! $lid && ! $firstname && ! $lastname)
545                        {
546                                $lid       = $GLOBALS['phpgw_info']['user']['account_lid'];
547                                $firstname = $GLOBALS['phpgw_info']['user']['firstname'];
548                                $lastname  = $GLOBALS['phpgw_info']['user']['lastname'];
549                        }
550
551                        $display = $GLOBALS['phpgw_info']['user']['preferences']['common']['account_display'];
552
553                        if ($firstname && $lastname)
554                        {
555                                $delimiter = ', ';
556                        }
557                        else
558                        {
559                                $delimiter = '';
560                        }
561                       
562                        $name = '';
563                        switch($display)
564                        {
565                                case 'firstname':
566                                        $name = $firstname . ' ' . $lastname;
567                                        break;
568                                case 'lastname':
569                                        $name = $lastname . $delimiter . $firstname;
570                                        break;
571                                case 'username':
572                                        $name = $lid;
573                                        break;
574                                case 'firstall':
575                                        $name = $firstname . ' ' . $lastname . ' ['.$lid.']';
576                                        break;
577                                case 'lastall':
578                                        $name = $lastname . $delimiter . $firstname . ' ['.$lid.']';
579                                        break;
580                                case 'all':
581                                        /* fall through */
582                                default:
583                                        $name = '['.$lid.'] ' . $firstname . ' ' . $lastname;
584                        }
585                        return $name;
586                }
587
588                /*!
589                @function grab_owner_name
590                @abstract grab the owner name
591                @param $id account id
592                */
593                function grab_owner_name($accountid = '')
594                {
595                        $GLOBALS['phpgw']->accounts->get_account_name($accountid,$lid,$fname,$lname);
596                        return $this->display_fullname($lid,$fname,$lname);
597                }
598
599                /*!
600                @function create_tabs
601                @abstract create tabs
602                @param $tabs ?
603                @param $selected ?
604                @param $fontsize optional
605                */
606                function create_tabs($tabs, $selected, $fontsize = '')
607                {
608                        $output_text = '<table border="0" cellspacing="0" cellpadding="0"><tr>';
609
610                        /* This is a php3 workaround */
611                        if(PHPGW_IMAGES_DIR == 'PHPGW_IMAGES_DIR')
612                        {
613                                $ir = ExecMethod('phpgwapi.phpgw.common.get_image_path', 'phpgwapi');
614                        }
615                        else
616                        {
617                                $ir = PHPGW_IMAGES_DIR;
618                        }
619
620                        if ($fontsize)
621                        {
622                                $fs  = '<font size="' . $fontsize . '">';
623                                $fse = '</font>';
624                        }
625
626                        $i = 1;
627                        while ($tab = each($tabs))
628                        {
629                                if ($tab[0] == $selected)
630                                {
631                                        if ($i == 1)
632                                        {
633                                                $output_text .= '<td align="right"><img src="' . $ir . '/tabs-start1.gif"></td>';
634                                        }
635
636                                        $output_text .= '<td align="left" background="' . $ir . '/tabs-bg1.gif">&nbsp;<b><a href="'
637                                                . $tab[1]['link'] . '" class="tablink" '.$tab[1]['target'].'>' . $fs . $tab[1]['label']
638                                                . $fse . '</a></b>&nbsp;</td>';
639                                        if ($i == count($tabs))
640                                        {
641                                                $output_text .= '<td align="left"><img src="' . $ir . '/tabs-end1.gif"></td>';
642                                        }
643                                        else
644                                        {
645                                                $output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepr.gif"></td>';
646                                        }
647                                }
648                                else
649                                {
650                                        if ($i == 1)
651                                        {
652                                                $output_text .= '<td align="right"><img src="' . $ir . '/tabs-start0.gif"></td>';
653                                        }
654                                        $output_text .= '<td align="left" background="' . $ir . '/tabs-bg0.gif">&nbsp;<b><a href="'
655                                                . $tab[1]['link'] . '" class="tablink" '.$tab[1]['target'].'>' . $fs . $tab[1]['label'] . $fse
656                                                . '</a></b>&nbsp;</td>';
657                                        if (($i + 1) == $selected)
658                                        {
659                                                $output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepl.gif"></td>';
660                                        }
661                                        elseif ($i == $selected || $i != count($tabs))
662                                        {
663                                                $output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepm.gif"></td>';
664                                        }
665                                        elseif ($i == count($tabs))
666                                        {
667                                                if ($i == $selected)
668                                                {
669                                                        $output_text .= '<td align="left"><img src="' . $ir . '/tabs-end1.gif"></td>';
670                                                }
671                                                else
672                                                {
673                                                        $output_text .= '<td align="left"><img src="' . $ir . '/tabs-end0.gif"></td>';
674                                                }
675                                        }
676                                        else
677                                        {
678                                                if ($i != count($tabs))
679                                                {
680                                                        $output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepr.gif"></td>';
681                                                }
682                                        }
683                                }
684                                $i++;
685                                $output_text .= "\n";
686                        }
687                        $output_text .= "</table>\n";
688                        return $output_text;
689                }
690
691                /*!
692                @function get_app_dir
693                @abstract get directory of application
694                @discussion $appname can either be passed or derived from $phpgw_info['flags']['currentapp'];
695                @param $appname name of application
696                */
697                function get_app_dir($appname = '')
698                {
699                        $_SESSION['phpgw_info']['expresso']['currentapp'] = $GLOBALS['phpgw_info']['flags']['currentapp'];
700
701                        if ($appname == '')
702                        {
703                                $appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
704                        }
705                        if ($appname == 'home' || $appname == 'logout' || $appname == 'login')
706                        {
707                                $appname = 'phpgwapi';
708                        }
709
710                        $appdir         = PHPGW_INCLUDE_ROOT . '/'.$appname;
711                        $appdir_default = PHPGW_SERVER_ROOT . '/'.$appname;
712
713                        if (@is_dir ($appdir))
714                        {
715                                return $appdir;
716                        }
717                        elseif (@is_dir ($appdir_default))
718                        {
719                                return $appdir_default;
720                        }
721                        else
722                        {
723                                return False;
724                        }
725                }
726
727                /*!
728                @function get_inc_dir
729                @abstract get inc (include dir) of application
730                @discussion $appname can either be passed or derived from $phpgw_info['flags']['currentapp'];
731                @param $appname name of application
732                */
733                function get_inc_dir($appname = '')
734                {
735                        if (! $appname)
736                        {
737                                $appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
738                        }
739                        if ($appname == 'home' || $appname == 'logout' || $appname == 'login' || $appname == 'about')
740                        {
741                                $appname = 'phpgwapi';
742                        }
743
744                        $incdir         = PHPGW_INCLUDE_ROOT . '/' . $appname . '/inc';
745                        $incdir_default = PHPGW_SERVER_ROOT . '/' . $appname . '/inc';
746
747                        if (@is_dir ($incdir))
748                        {
749                                return $incdir;
750                        }
751                        elseif (@is_dir ($incdir_default))
752                        {
753                                return $incdir_default;
754                        }
755                        else
756                        {
757                                return False;
758                        }
759                }
760
761                /*!
762                @function list_themes
763                @abstract list themes available
764                @note themes can either be css file like in HEAD (if the template has a css-dir and has css-files in is) \
765                        or ordinary .14 themes-files
766                */
767                function list_themes()
768                {
769                        $tpl_dir = $this->get_tpl_dir('phpgwapi');
770
771                        if ($dh = @opendir($tpl_dir . SEP . 'css'))
772                        {
773                                while ($file = readdir($dh))
774                                {
775                                        if (eregi("\.css$", $file) && $file != 'phpgw.css')
776                                        {
777                                                $list[] = substr($file,0,strpos($file,'.'));
778                                        }
779                                }
780                        }
781                        if(!is_array($list))
782                        {
783                                $dh = opendir(PHPGW_SERVER_ROOT . '/phpgwapi/themes');
784                                while ($file = readdir($dh))
785                                {
786                                        if (eregi("\.theme$", $file))
787                                        {
788                                                $list[] = substr($file,0,strpos($file,'.'));
789                                        }
790                                }
791                        }
792                        closedir($dh);
793                        reset ($list);
794                        return $list;
795                }
796
797                /**
798                * List available templates
799                *
800                * @returns array alphabetically sorted list of templates
801                */
802                function list_templates()
803                {
804                        $d = dir(PHPGW_SERVER_ROOT . '/phpgwapi/templates');
805                        while ($entry=$d->read())
806                        {
807                                if ($entry != '.' && $entry != '..' && is_dir(PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry) && !is_link(PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry) && file_exists(PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry . '/head.inc.php'))
808                                {
809                                        $list[$entry]['title'] = $entry;
810                                        $list[$entry]['name'] = $entry;
811
812                                        $f = PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry . '/details.inc.php';
813                                        if (file_exists ($f))
814                                        {
815                                                include($f);
816                                                if ( defined( $entry.'_TEMPLATE_TITLE' ) )
817                                                        $list[$entry]['title'] = utf8_decode( constant($entry.'_TEMPLATE_TITLE') );
818                                        }
819                                }
820                        }
821                        $d->close();
822                        ksort($list);
823                        return $list;
824                }
825
826                /*!
827                @function get_tpl_dir
828                @abstract get template dir of an application
829                @param $appname appication name optional can be derived from $phpgw_info['flags']['currentapp'];
830                */
831                function get_tpl_dir($appname = '')
832                {
833                        if (! $appname)
834                        {
835                                $appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
836                        }
837                        if ($appname == 'home' || $appname == 'logout' || $appname == 'login')
838                        {
839                                $appname = 'phpgwapi';
840                        }
841
842                        if (!isset($GLOBALS['phpgw_info']['server']['template_set']) && isset($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']))
843                        {
844                                $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];
845                        }
846
847                        // Setting this for display of template choices in user preferences
848                        if ($GLOBALS['phpgw_info']['server']['template_set'] == 'user_choice')
849                        {
850                                $GLOBALS['phpgw_info']['server']['usrtplchoice'] = 'user_choice';
851                        }
852
853                        if (($GLOBALS['phpgw_info']['server']['template_set'] == 'user_choice' ||
854                                !isset($GLOBALS['phpgw_info']['server']['template_set'])) &&
855                                isset($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']))
856                        {
857                                $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];
858                        }
859                        elseif ($GLOBALS['phpgw_info']['server']['template_set'] == 'user_choice' ||
860                                !isset($GLOBALS['phpgw_info']['server']['template_set']))
861                        {
862                                $GLOBALS['phpgw_info']['server']['template_set'] = 'default';
863                        }
864
865                        $tpldir         = PHPGW_SERVER_ROOT . '/' . $appname . '/templates/' . $GLOBALS['phpgw_info']['server']['template_set'];
866                        $tpldir_default = PHPGW_SERVER_ROOT . '/' . $appname . '/templates/default';
867
868                        if (@is_dir($tpldir))
869                        {
870                                return $tpldir;
871                        }
872                        elseif (@is_dir($tpldir_default))
873                        {
874                                return $tpldir_default;
875                        }
876                        else
877                        {
878                                return False;
879                        }
880                }
881
882                /*!
883                @function is_image_dir
884                @abstract checks if image_dir exists and has more than just a navbar-icon
885                @note this is just a workaround for idots, better to use find_image, which has a fallback \
886                        on a per image basis to the default dir
887                */
888                function is_image_dir($dir)
889                {
890                        if (!@is_dir($dir))
891                        {
892                                return False;
893                        }
894                        if ($d = opendir($dir))
895                        {
896                                while ($f = readdir($d))
897                                {
898                                        $ext = strtolower(strrchr($f,'.'));
899                                        if (($ext == '.gif' || $ext == '.png') && strstr($f,'navbar') === False)
900                                        {
901                                                return True;
902                                        }
903                                }
904                        }
905                        return False;
906                }
907
908                /*!
909                @function get_image_dir
910                @abstract get image dir of an application
911                @param $appname application name optional can be derived from $phpgw_info['flags']['currentapp'];
912                */
913                function get_image_dir($appname = '')
914                {
915                        if ($appname == '')
916                        {
917                                $appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
918                        }
919                        if (empty($GLOBALS['phpgw_info']['server']['template_set']))
920                        {
921                                $GLOBALS['phpgw_info']['server']['template_set'] = 'default';
922                        }
923
924                        $imagedir            = PHPGW_SERVER_ROOT . '/' . $appname . '/templates/'
925                                . $GLOBALS['phpgw_info']['server']['template_set'] . '/images';
926                        $imagedir_default    = PHPGW_SERVER_ROOT . '/' . $appname . '/templates/default/images';
927                        $imagedir_olddefault = PHPGW_SERVER_ROOT . '/' . $appname . '/images';
928
929                        if ($this->is_image_dir ($imagedir))
930                        {
931                                return $imagedir;
932                        }
933                        elseif ($this->is_image_dir ($imagedir_default))
934                        {
935                                return $imagedir_default;
936                        }
937                        elseif ($this->is_image_dir ($imagedir_olddefault))
938                        {
939                                return $imagedir_olddefault;
940                        }
941                        else
942                        {
943                                return False;
944                        }
945                }
946
947                /*!
948                @function get_image_path
949                @abstract get image path of an application
950                @param $appname appication name optional can be derived from $phpgw_info['flags']['currentapp'];
951                */
952                function get_image_path($appname = '')
953                {
954                        if ($appname == '')
955                        {
956                                $appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
957                        }
958
959                        if (empty($GLOBALS['phpgw_info']['server']['template_set']))
960                        {
961                                $GLOBALS['phpgw_info']['server']['template_set'] = 'default';
962                        }
963
964                        $imagedir            = PHPGW_SERVER_ROOT . '/'.$appname.'/templates/'.$GLOBALS['phpgw_info']['server']['template_set'].'/images';
965                        $imagedir_default    = PHPGW_SERVER_ROOT . '/'.$appname.'/templates/default/images';
966                        $imagedir_olddefault = PHPGW_SERVER_ROOT . '/'.$appname.'/images';
967
968                        if ($this->is_image_dir ($imagedir))
969                        {
970                                return $GLOBALS['phpgw_info']['server']['webserver_url'].'/'.$appname.'/templates/'.$GLOBALS['phpgw_info']['server']['template_set'].'/images';
971                        }
972                        elseif ($this->is_image_dir ($imagedir_default))
973                        {
974                                return $GLOBALS['phpgw_info']['server']['webserver_url'].'/'.$appname.'/templates/default/images';
975                        }
976                        elseif ($this->is_image_dir ($imagedir_olddefault))
977                        {
978                                return $GLOBALS['phpgw_info']['server']['webserver_url'].'/'.$appname.'/images';
979                        }
980                        else
981                        {
982                                return False;
983                        }
984                }
985
986                function find_image($appname,$image)
987                {
988                        $imagedir = '/'.$appname.'/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].'/images';
989                       
990                        if (!@is_array($this->found_files[$appname]))
991                        {
992                                $imagedir_olddefault = '/'.$appname.'/images';
993                                $imagedir_default    = '/'.$appname.'/templates/default/images';
994                               
995                                if (@is_dir(PHPGW_INCLUDE_ROOT.$imagedir_olddefault))
996                                {
997                                        $d = dir(PHPGW_INCLUDE_ROOT.$imagedir_olddefault);
998                                        while (false != ($entry = $d->read()))
999                                        {
1000                                                if ($entry != '.' && $entry != '..')
1001                                                {
1002                                                        $this->found_files[$appname][$entry] = $imagedir_olddefault;
1003                                                }
1004                                        }
1005                                        $d->close();
1006                                }
1007
1008                                if (@is_dir(PHPGW_INCLUDE_ROOT.$imagedir_default))
1009                                {
1010                                        $d = dir(PHPGW_INCLUDE_ROOT.$imagedir_default);
1011                                        while (false != ($entry = $d->read()))
1012                                        {
1013                                                if ($entry != '.' && $entry != '..')
1014                                                {
1015                                                        $this->found_files[$appname][$entry] = $imagedir_default;
1016                                                }
1017                                        }
1018                                        $d->close();
1019                                }
1020
1021                                if (@is_dir(PHPGW_INCLUDE_ROOT.$imagedir))
1022                                {
1023                                        $d = dir(PHPGW_INCLUDE_ROOT.$imagedir);
1024                                        while (false != ($entry = $d->read()))
1025                                        {
1026                                                if ($entry != '.' && $entry != '..')
1027                                                {
1028                                                        $this->found_files[$appname][$entry] = $imagedir;
1029                                                }
1030                                        }
1031                                        $d->close();
1032                                }
1033                        }
1034                       
1035                        if (!$GLOBALS['phpgw_info']['server']['image_type'])
1036                        {
1037                                // priority: GIF->JPG->PNG
1038                                $img_type=array('.gif','.jpg','.png');
1039                        }
1040                        else
1041                        {
1042                                // priority: : PNG->JPG->GIF
1043                                $img_type=array('.png','.jpg','.gif');
1044                        }
1045
1046                        // first look in the selected template dir
1047                        if(@$this->found_files[$appname][$image.$img_type[0]]==$imagedir)
1048                        {
1049                                $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[0]].'/'.$image.$img_type[0];
1050                        }
1051                        elseif(@$this->found_files[$appname][$image.$img_type[1]]==$imagedir)
1052                        {
1053                                $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[1]].'/'.$image.$img_type[1];
1054                        }
1055                        elseif(@$this->found_files[$appname][$image.$img_type[2]]==$imagedir)
1056                        {
1057                                $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[2]].'/'.$image.$img_type[2];
1058                        }
1059                        // then look everywhere else
1060                        elseif(isset($this->found_files[$appname][$image.$img_type[0]]))
1061                        {
1062                                $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[0]].'/'.$image.$img_type[0];
1063                        }
1064                        elseif(isset($this->found_files[$appname][$image.$img_type[1]]))
1065                        {
1066                                $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[1]].'/'.$image.$img_type[1];
1067                        }
1068                        elseif(isset($this->found_files[$appname][$image.$img_type[2]]))
1069                        {
1070                                $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[2]].'/'.$image.$img_type[2];
1071                        }
1072                        elseif(isset($this->found_files[$appname][$image]))
1073                        {
1074                                $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image].'/'.$image;
1075                        }
1076                        else
1077                        {
1078                                // searching the image in the api-dirs
1079                                if (!isset($this->found_files['phpgwapi']))
1080                                {
1081                                        $this->find_image('phpgwapi','');
1082                                }
1083
1084                                if(isset($this->found_files['phpgwapi'][$image.$img_type[0]]))
1085                                {
1086                                        $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files['phpgwapi'][$image.$img_type[0]].'/'.$image.$img_type[0];
1087                                }
1088                                elseif(isset($this->found_files['phpgwapi'][$image.$img_type[1]]))
1089                                {
1090                                        $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files['phpgwapi'][$image.$img_type[1]].'/'.$image.$img_type[1];
1091                                }
1092                                elseif(isset($this->found_files['phpgwapi'][$image.$img_type[2]]))
1093                                {
1094                                        $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files['phpgwapi'][$image.$img_type[2]].'/'.$image.$img_type[2];
1095                                }
1096                                elseif(isset($this->found_files['phpgwapi'][$image]))
1097                                {
1098                                        $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files['phpgwapi'][$image].'/'.$image;
1099                                }
1100                                else
1101                                {
1102                                        $imgfile = '';
1103                                }
1104                        }
1105                        return $imgfile;
1106                }
1107
1108                function image($appname,$image='',$ext='',$use_lang=True)
1109                {
1110                        if (!is_array($image))
1111                        {
1112                                if (empty($image))
1113                                {
1114                                        return '';
1115                                }
1116                                $image = array($image);
1117                        }
1118                        if ($use_lang)
1119                        {
1120                                while (list(,$img) = each($image))
1121                                {
1122                                        $lang_images[] = $img . '_' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
1123                                        $lang_images[] = $img;
1124                                }
1125                                $image = $lang_images;
1126                        }
1127                        while (empty($image_found) && list(,$img) = each($image))
1128                        {
1129                                if(isset($this->found_files[$appname][$img.$ext]))
1130                                {
1131                                        $image_found = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$img.$ext].'/'.$img.$ext;
1132                                }
1133                                else
1134                                {
1135                                        $image_found = $this->find_image($appname,$img.$ext);
1136                                }
1137                        }
1138                        return $image_found;
1139                }
1140
1141                function image_on($appname,$image,$extension='_on')
1142                {
1143                        $with_extension = $this->image($appname,$image,$extension);
1144                        $without_extension = $this->image($appname,$image);
1145                        if($with_extension != '')
1146                        {
1147                                return $with_extension;
1148                        }
1149                        elseif($without_extension != '')
1150                        {
1151                                return $without_extension;
1152                        }
1153                        else
1154                        {
1155                                return '';
1156                        }
1157                }
1158
1159                /*!
1160                @function navbar
1161                @abstract none yet
1162                @discussion *someone wanna add some detail here*
1163                */
1164                function navbar( )
1165                {
1166                        $GLOBALS['phpgw_info']['navbar']['home']['title'] = 'Home';
1167                        $GLOBALS['phpgw_info']['navbar']['home']['url']   = $GLOBALS['phpgw']->link('/home.php');
1168                        $GLOBALS['phpgw_info']['navbar']['home']['icon']  = $this->image('phpgwapi',Array('home','nonav'));
1169                        $GLOBALS['phpgw_info']['navbar']['home']['icon_hover']  = $this->image_on('phpgwapi',Array('home','nonav'),'-over');
1170
1171                        list($first) = each($GLOBALS['phpgw_info']['user']['apps']);
1172                        if(is_array($GLOBALS['phpgw_info']['user']['apps']['admin']) && $first != 'admin')
1173                        {
1174                                $newarray['admin'] = $GLOBALS['phpgw_info']['user']['apps']['admin'];
1175                                foreach($GLOBALS['phpgw_info']['user']['apps'] as $index => $value)
1176                                {
1177                                        if($index != 'admin')
1178                                        {
1179                                                $newarray[$index] = $value;
1180                                        }
1181                                }
1182                                $GLOBALS['phpgw_info']['user']['apps'] = $newarray;
1183                                reset($GLOBALS['phpgw_info']['user']['apps']);
1184                        }
1185                        unset($index);
1186                        unset($value);
1187                        unset($newarray);
1188
1189                        foreach($GLOBALS['phpgw_info']['user']['apps'] as $app => $data)
1190                        {
1191                                if (is_long($app))
1192                                {
1193                                        continue;
1194                                }
1195
1196                                if ($app == 'preferences' || $GLOBALS['phpgw_info']['apps'][$app]['status'] != 2 && $GLOBALS['phpgw_info']['apps'][$app]['status'] != 3)
1197                                {
1198                                        $GLOBALS['phpgw_info']['navbar'][$app]['title'] = $GLOBALS['phpgw_info']['apps'][$app]['title'];
1199                                        $GLOBALS['phpgw_info']['navbar'][$app]['url']   = $GLOBALS['phpgw']->link('/' . $app . '/index.php',$GLOBALS['phpgw_info']['flags']['params'][$app]);
1200                                        $GLOBALS['phpgw_info']['navbar'][$app]['name']  = $app;
1201
1202                                        // create popup target
1203                                        if ($data['status'] == 4)
1204                                        {
1205                                                $GLOBALS['phpgw_info']['navbar'][$app]['target'] = ' target="'.$app.'" onClick="'."if (this != '') { window.open(this+'".
1206                                                        (strstr($GLOBALS['phpgw_info']['navbar'][$app]['url'],'?') ||
1207                                                        ini_get('session.use_trans_sid') && $GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4' ?'&':'?').
1208                                                        "referer='+encodeURI(location),this.target,'width=800,height=600,scrollbars=yes,resizable=yes'); return false; } else { return true; }".'"';
1209                                        }
1210
1211                                        if ($app != $GLOBALS['phpgw_info']['flags']['currentapp'])
1212                                        {
1213                                                $GLOBALS['phpgw_info']['navbar'][$app]['icon']  = $this->image($app,Array('navbar','nonav'));
1214                                                $GLOBALS['phpgw_info']['navbar'][$app]['icon_hover']  = $this->image_on($app,Array('navbar','nonav'),'-over');
1215                                        }
1216                                        else
1217                                        {
1218                                                $GLOBALS['phpgw_info']['navbar'][$app]['icon']  = $this->image_on($app,Array('navbar','nonav'),'-over');
1219                                                $GLOBALS['phpgw_info']['navbar'][$app]['icon_hover']  = $this->image($app,Array('navbar','nonav'));
1220                                        }
1221
1222//                                      if($GLOBALS['phpgw_info']['navbar'][$app]['icon'] == '')
1223//                                      {
1224//                                              $GLOBALS['phpgw_info']['navbar'][$app]['icon']  = $this->image('phpgwapi','nonav');
1225//                                      }
1226                                }
1227                        }
1228                        if ($GLOBALS['phpgw_info']['flags']['currentapp'] == 'home' || $GLOBALS['phpgw_info']['flags']['currentapp'] == 'preferences' || $GLOBALS['phpgw_info']['flags']['currentapp'] == 'about')
1229                        {
1230                                $app = $app_title = ':: ExpressoLivre ::';
1231                        }
1232                        else
1233                        {
1234                                $app = $GLOBALS['phpgw_info']['flags']['currentapp'];
1235                                $app_title = $GLOBALS['phpgw_info']['apps'][$app]['title'];
1236                        }
1237
1238                        if ($GLOBALS['phpgw_info']['user']['apps']['preferences'])      // preferences last
1239                        {
1240                                $prefs = $GLOBALS['phpgw_info']['navbar']['preferences'];
1241                                unset($GLOBALS['phpgw_info']['navbar']['preferences']);
1242                                $GLOBALS['phpgw_info']['navbar']['preferences'] = $prefs;
1243                        }
1244
1245                        // We handle this here becuase its special
1246                        $GLOBALS['phpgw_info']['navbar']['about']['title'] = lang('About %1',$app_title);
1247
1248                        $GLOBALS['phpgw_info']['navbar']['about']['url']   = $GLOBALS['phpgw']->link('/about.php','app='.$app);
1249                        $GLOBALS['phpgw_info']['navbar']['about']['icon']  = $this->image('phpgwapi',Array('about','nonav'));
1250                        $GLOBALS['phpgw_info']['navbar']['about']['icon_hover']  = $this->image_on('phpgwapi',Array('about','nonav'),'-over');
1251
1252                        $GLOBALS['phpgw_info']['navbar']['logout']['title'] = lang('Logout');
1253                        $GLOBALS['phpgw_info']['navbar']['logout']['url']   = $GLOBALS['phpgw']->link('/logout.php');
1254                        $GLOBALS['phpgw_info']['navbar']['logout']['icon']  = $this->image('phpgwapi',Array('logout','nonav'));
1255                        $GLOBALS['phpgw_info']['navbar']['logout']['icon_hover']  = $this->image_on('phpgwapi',Array('logout','nonav'),'-over');
1256                }
1257
1258                /*!
1259                @function app_header
1260                @abstract load header.inc.php for an application
1261                */
1262                function app_header()
1263                {
1264                        if (file_exists(PHPGW_APP_INC . '/header.inc.php'))
1265                        {
1266                                include(PHPGW_APP_INC . '/header.inc.php');
1267                        }
1268                }
1269                /*!
1270                @function phpgw_header
1271                @abstract load the phpgw header
1272                */
1273                function phpgw_header( $content )
1274                {
1275                        // add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv)
1276                        header( "Content-type: text/html; charset={$GLOBALS[ 'phpgw' ] -> translation -> charset( )}" );
1277
1278                        $path = PHPGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS['phpgw_info']['server']['template_set'];
1279
1280                        $this -> navbar( false );
1281
1282                        include_once( "{$path}/navbar.inc.php" );
1283
1284                        if ( ! @$GLOBALS['phpgw_info']['flags']['nonavbar'] && !@$GLOBALS['phpgw_info']['flags']['navbar_target'])
1285                        {
1286                                parse_navbar( );
1287                                $content = ob_get_contents( ) . $content;
1288                                ob_clean( );
1289
1290                                parse_navbar_end( );
1291                                $content .= ob_get_contents( ) . "\t";
1292                                ob_clean( );
1293                        }
1294
1295                        require_once "{$path}/head.inc.php";
1296                }
1297
1298                function phpgw_footer()
1299                {
1300                        if ( ! defined( 'PHPGW_FOOTER' ) )
1301                        {
1302                                define( 'PHPGW_FOOTER', true );
1303                                if ( ! isset( $GLOBALS['phpgw_info']['flags']['nofooter']) || !$GLOBALS['phpgw_info']['flags']['nofooter'] )
1304                                        include_once PHPGW_API_INC . '/footer.inc.php';
1305                        }
1306                }
1307
1308                /**
1309                * Used by template headers for including CSS in the header
1310                *
1311                * This first loads up the basic global CSS definitions, which support
1312                * the selected user theme colors.  Next we load up the app CSS.  This is
1313                * all merged into the selected theme's css.tpl file.
1314                *
1315                * @author Dave Hall (*based* on verdilak? css inclusion code)
1316                */
1317                function get_css( )
1318                {
1319                        $tpl = createObject('phpgwapi.Template', $this->get_tpl_dir('phpgwapi'));
1320                        $tpl->set_file('css', 'css.tpl');
1321                        $tpl->set_var($GLOBALS['phpgw_info']['theme']);
1322                        $app_css = '';
1323
1324                        if(@isset($_GET['menuaction']))
1325                        {
1326                                list($app,$class,$method) = explode('.',$_GET['menuaction']);
1327                                if(is_array($GLOBALS[$class]->public_functions) &&
1328                                        $GLOBALS[$class]->public_functions['css'])
1329                                {
1330                                        $app_css .= $GLOBALS[$class]->css();
1331                                }
1332                        }
1333
1334                        if ( isset( $GLOBALS['phpgw_info']['flags']['css'] ) )
1335                                $app_css .= $GLOBALS['phpgw_info']['flags']['css'];
1336
1337                        $tpl->set_var( 'app_css', $app_css );
1338
1339                        // search for app specific css file
1340                        if ( @ isset( $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'currentapp' ] ) )
1341                        {
1342                                $template = $GLOBALS['phpgw_info']['server']['template_set'];           
1343                                $GLOBALS['phpgw']->css->validate_file( "phpgwapi/templates/".$template."/css/base.css");
1344                                $GLOBALS['phpgw']->css->validate_file( "phpgwapi/templates/".$template."/css/".$GLOBALS[ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ].".css");
1345                                $GLOBALS['phpgw']->css->validate_file( $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'currentapp' ]."/templates/".$template."/css/".$GLOBALS[ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ].".css");
1346                                $GLOBALS['phpgw']->css->validate_file( $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'currentapp' ]."/templates/".$template."/css/app.css");
1347                               
1348                                $tpl -> set_var( 'css_file',  $GLOBALS['phpgw']->css->get_css() );
1349                        }
1350
1351                        return $tpl -> subst( 'css' );
1352                }
1353
1354                /**
1355                * Used by the template headers for including javascript in the header
1356                *
1357                * The method is included here to make it easier to change the js support
1358                * in phpgw.  One change then all templates will support it (as long as they
1359                * include a call to this method).
1360                *
1361                * @author Dave Hall (*vaguely based* on verdilak? css inclusion code)
1362                * @return string the javascript to be included
1363                */
1364                function get_java_script( )
1365                {
1366                        $java_script = "\t\t";
1367
1368                        /* this flag is for all javascript code that has to be put before other jscode.
1369                        Think of conf vars etc...  (pim@lingewoud.nl) */
1370                        if ( isset( $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script_thirst' ] ) )
1371                                $java_script .= $GLOBALS['phpgw_info']['flags']['java_script_thirst'];
1372
1373                        if( is_object( $GLOBALS[ 'phpgw' ] -> js ) )
1374                                $java_script .= $GLOBALS[ 'phpgw' ] -> js -> get_script_links( );
1375
1376                        if(@isset($_GET['menuaction']))
1377                        {
1378                                list($app,$class,$method) = explode('.',$_GET['menuaction']);
1379                                if(is_array($GLOBALS[$class]->public_functions) &&
1380                                        $GLOBALS[$class]->public_functions['java_script'])
1381                                {
1382                                        $java_script .= $GLOBALS[$class]->java_script();
1383                                }
1384                        }
1385
1386                        if ( isset( $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script' ] ) )
1387                                $java_script .= $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script' ];
1388
1389                        return $java_script;
1390                }
1391
1392                /**
1393                * Returns on(Un)Load attributes from js class
1394                *
1395                *@author Dave Hall - skwashd at phpgroupware.org
1396                *@returns string body attributes
1397                */
1398                function get_body_attribs()
1399                {
1400                        if(@is_object($GLOBALS['phpgw']->js))
1401                        {
1402                                return $GLOBALS['phpgw']->js->get_body_attribs();
1403                        }
1404                        else
1405                        {
1406                                return '';
1407                        }
1408                }
1409
1410                function hex2bin($data)
1411                {
1412                        $len = strlen($data);
1413                        return @pack('H' . $len, $data);
1414                }
1415
1416                /*!
1417                @function encrypt
1418                @abstract encrypt data passed to the function
1419                @param $data data (string?) to be encrypted
1420                */
1421                function encrypt($data)
1422                {
1423                        return $GLOBALS['phpgw']->crypto->encrypt($data);
1424                }
1425
1426                /*!
1427                @function decrypt
1428                @abstract decrypt $data
1429                @param $data data to be decrypted
1430                */
1431                function decrypt($data)
1432                {
1433                        return $GLOBALS['phpgw']->crypto->decrypt($data);
1434                }
1435
1436                /*!
1437                @function encrypt_password
1438                @abstract legacy wrapper for newer auth class function, encrypt_password
1439                @abstract uses the encryption type set in setup and calls the appropriate encryption functions
1440                @param $password password to encrypt
1441                */
1442                function encrypt_password($password,$sql=False)
1443                {
1444                        if(!@is_object($GLOBALS['phpgw']->auth))
1445                        {
1446                                $GLOBALS['phpgw']->auth = CreateObject('phpgwapi.auth');
1447                        }
1448                        return $GLOBALS['phpgw']->auth->encrypt_password($password,$sql);
1449                }
1450
1451                /*!
1452                @function find_portal_order
1453                @abstract find the current position of the app is the users portal_order preference
1454                @param $app application id to find current position - required
1455                @discussion No discussion
1456                */
1457                function find_portal_order($app)
1458                {
1459                        if(!is_array($GLOBALS['phpgw_info']['user']['preferences']['portal_order']))
1460                        {
1461                                return -1;
1462                        }
1463                        @reset($GLOBALS['phpgw_info']['user']['preferences']['portal_order']);
1464                        while(list($seq,$appid) = each($GLOBALS['phpgw_info']['user']['preferences']['portal_order']))
1465                        {
1466                                if($appid == $app)
1467                                {
1468                                        @reset($GLOBALS['phpgw_info']['user']['preferences']['portal_order']);
1469                                        return $seq;
1470                                }
1471                        }
1472                        @reset($GLOBALS['phpgw_info']['user']['preferences']['portal_order']);
1473                        return -1;
1474                }
1475
1476                /*!
1477                @function hook
1478                @abstract temp wrapper to new hooks class
1479                */
1480                function hook($location, $appname = '', $no_permission_check = False)
1481                {
1482                        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>';
1483                        return $GLOBALS['phpgw']->hooks->process($location, $order, $no_permission_check);
1484                }
1485
1486                /*!
1487                @function hook_single
1488                @abstract temp wrapper to new hooks class
1489                */
1490                // Note: $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo)
1491                function hook_single($location, $appname = '', $no_permission_check = False)
1492                {
1493                        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>';
1494                        return $GLOBALS['phpgw']->hooks->single($location, $order, $no_permission_check);
1495                }
1496
1497                /*!
1498                @function hook_count
1499                @abstract temp wrapper to new hooks class
1500                */
1501                function hook_count($location)
1502                {
1503                        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>';
1504                        return $GLOBALS['phpgw']->hooks->count($location);
1505                }
1506
1507                /* Wrapper to the session->appsession() */
1508                function appsession($data = '##NOTHING##')
1509                {
1510                        $this->debug_info[] = '$phpgw->common->appsession() is a depreciated function'
1511                                . ' - use $phpgw->session->appsession() instead';
1512
1513                        return $GLOBALS['phpgw']->session->appsession('default','',$data);
1514                }
1515
1516                /*!
1517                @function show_date
1518                @abstract show current date
1519                @param $t time - optional can be pulled from user preferences
1520                @param $format - optional can be pulled from user prefernces
1521                */
1522                function show_date($t = '', $format = '')
1523                {
1524                        if(!is_object($GLOBALS['phpgw']->datetime))
1525                        {
1526                                $GLOBALS['phpgw']->datetime = createobject('phpgwapi.date_time');
1527                        }
1528
1529                        if (!$t || (int)$t <= 0)
1530                        {
1531                                $t = $GLOBALS['phpgw']->datetime->gmtnow;
1532                        }
1533                        //  + (date('I') == 1?3600:0)
1534                        $t += $GLOBALS['phpgw']->datetime->tz_offset;
1535                       
1536                        if (! $format)
1537                        {
1538                                $format = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'] . ' - ';
1539                                if ($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12')
1540                                {
1541                                        $format .= 'h:i a';
1542                                }
1543                                else
1544                                {
1545                                        $format .= 'H:i';
1546                                }
1547                        }
1548                       
1549                        if((PHP_OS == 'Windows' || PHP_OS == 'WINNT') && (int)$t < 21600)
1550                        /*if(PHP_OS == 'Windows' && (int)$t < 21600)*/
1551                        {
1552                                $t = 21600;
1553                        }
1554                        return date($format,$t);
1555                }
1556
1557                /*!
1558                @function dateformatorder
1559                @abstract
1560                @param $yearstr year - string
1561                @param $monthstr month - string
1562                @param $day day - string
1563                @param $add_seperator boolean defaults to false
1564                */
1565                function dateformatorder($yearstr,$monthstr,$daystr,$add_seperator = False)
1566                {
1567                        $dateformat = strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
1568                        $sep = substr($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],1,1);
1569
1570                        $dlarr[strpos($dateformat,'y')] = $yearstr;
1571                        $dlarr[strpos($dateformat,'m')] = $monthstr;
1572                        $dlarr[strpos($dateformat,'d')] = $daystr;
1573                        ksort($dlarr);
1574
1575                        if ($add_seperator)
1576                        {
1577                                return (implode($sep,$dlarr));
1578                        }
1579                        else
1580                        {
1581                                return (implode(' ',$dlarr));
1582                        }
1583                }
1584
1585                /*!
1586                @function formattime
1587                @abstract format the time takes settings from user preferences
1588                @param $hour hour
1589                @param $min minutes
1590                @param $sec defaults to ''
1591                */
1592                function formattime($hour,$min,$sec='')
1593                {
1594                        $h12 = $hour;
1595                        if ($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12')
1596                        {
1597                                if ($hour >= 12)
1598                                {
1599                                        $ampm = ' pm';
1600                                }
1601                                else
1602                                {
1603                                        $ampm = ' am';
1604                                }
1605
1606                                $h12 %= 12;
1607
1608                                if ($h12 == 0 && $hour)
1609                                {
1610                                        $h12 = 12;
1611                                }
1612                                if ($h12 == 0 && !$hour)
1613                                {
1614                                        $h12 = 0;
1615                                }
1616                        }
1617                        else
1618                        {
1619                                $h12 = $hour;
1620                        }
1621
1622                        if ($sec !== '')
1623                        {
1624                                $sec = ":$sec";
1625                        }
1626
1627                        return "$h12:$min$sec$ampm";
1628                }
1629
1630                // This is not the best place for it, but it needs to be shared bewteen Aeromail and SM
1631                /*!
1632                @function get_email_passwd_ex
1633                @abstract uses code in /email class msg to obtain the appropriate password for email
1634                @param  (none - it will abtain the info it needs on its own)
1635                */
1636                /*
1637                function get_email_passwd_ex()
1638                {
1639                        // ----  Create the email Message Class  if needed  -----
1640                        if (is_object($GLOBALS['phpgw']->msg))
1641                        {
1642                                $do_free_me = False;
1643                        }
1644                        else
1645                        {
1646                                $GLOBALS['phpgw']->msg = CreateObject('email.mail_msg');
1647                                $do_free_me = True;
1648                        }
1649                        // use the Msg class to obtain the appropriate password
1650                        $tmp_prefs = $GLOBALS['phpgw']->preferences->read();
1651                        if (!isset($tmp_prefs['email']['passwd']))
1652                        {
1653                                $email_passwd = $GLOBALS['phpgw_info']['user']['passwd'];
1654                        }
1655                        else
1656                        {
1657                                $email_passwd = $GLOBALS['phpgw']->msg->decrypt_email_passwd($tmp_prefs['email']['passwd']);
1658                        }
1659                        // cleanup and return
1660                        if ($do_free_me)
1661                        {
1662                                unset ($GLOBALS['phpgw']->msg);
1663                        }
1664                        return $email_passwd;
1665                }
1666                */
1667
1668                // This is not the best place for it, but it needs to be shared bewteen Aeromail and SM
1669                /*!
1670                @function create_emailpreferences
1671                @abstract create email preferences
1672                @discussion This is not the best place for it, but it needs to be shared between Aeromail and SM
1673                @param $prefs
1674                @param $account_id -optional defaults to : phpgw_info['user']['account_id']
1675                */
1676                function create_emailpreferences($prefs='',$accountid='')
1677                {
1678                        return $GLOBALS['phpgw']->preferences->create_email_preferences($accountid);
1679                        // ----  Create the email Message Class  if needed  -----
1680                        if (is_object($GLOBALS['phpgw']->msg))
1681                        {
1682                                $do_free_me = False;
1683                        }
1684                        else
1685                        {
1686                                $GLOBALS['phpgw']->msg = CreateObject('email.mail_msg');
1687                                $do_free_me = True;
1688                        }
1689
1690                        // this sets the preferences into the phpgw_info structure
1691                        $GLOBALS['phpgw']->msg->create_email_preferences();
1692
1693                        // cleanup and return
1694                        if ($do_free_me)
1695                        {
1696                                unset ($GLOBALS['phpgw']->msg);
1697                        }
1698                }
1699
1700                /*
1701                function create_emailpreferences($prefs,$accountid='')
1702                {
1703                        $account_id = get_account_id($accountid);
1704
1705                        // NEW EMAIL PASSWD METHOD (shared between SM and aeromail)
1706                        $prefs['email']['passwd'] = $this->get_email_passwd_ex();
1707
1708                        // Add default preferences info
1709                        if (!isset($prefs['email']['userid']))
1710                        {
1711                                if ($GLOBALS['phpgw_info']['server']['mail_login_type'] == 'vmailmgr')
1712                                {
1713                                        $prefs['email']['userid'] = $GLOBALS['phpgw']->accounts->id2name($account_id)
1714                                                . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix'];
1715                                }
1716                                else
1717                                {
1718                                        $prefs['email']['userid'] = $GLOBALS['phpgw']->accounts->id2name($account_id);
1719                                }
1720                        }
1721                        // Set Server Mail Type if not defined
1722                        if (empty($GLOBALS['phpgw_info']['server']['mail_server_type']))
1723                        {
1724                                $GLOBALS['phpgw_info']['server']['mail_server_type'] = 'imap';
1725                        }
1726
1727                        // OLD EMAIL PASSWD METHOD
1728                        if (!isset($prefs['email']['passwd']))
1729                        {
1730                                $prefs['email']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd'];
1731                        }
1732                        else
1733                        {
1734                                $prefs['email']['passwd'] = $this->decrypt($prefs['email']['passwd']);
1735                        }
1736                        // NEW EMAIL PASSWD METHOD Located at the begining of this function
1737
1738                        if (!isset($prefs['email']['address']))
1739                        {
1740                                $prefs['email']['address'] = $GLOBALS['phpgw']->accounts->id2name($account_id)
1741                                        . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix'];
1742                        }
1743                        if (!isset($prefs['email']['mail_server']))
1744                        {
1745                                $prefs['email']['mail_server'] = $GLOBALS['phpgw_info']['server']['mail_server'];
1746                        }
1747                        if (!isset($prefs['email']['mail_server_type']))
1748                        {
1749                                $prefs['email']['mail_server_type'] = $GLOBALS['phpgw_info']['server']['mail_server_type'];
1750                        }
1751                        if (!isset($prefs['email']['imap_server_type']))
1752                        {
1753                                $prefs['email']['imap_server_type'] = $GLOBALS['phpgw_info']['server']['imap_server_type'];
1754                        }
1755                        // These sets the mail_port server variable
1756                        if ($prefs['email']['mail_server_type']=='imap')
1757                        {
1758                                $prefs['email']['mail_port'] = '143';
1759                        }
1760                        elseif ($prefs['email']['mail_server_type']=='pop3')
1761                        {
1762                                $prefs['email']['mail_port'] = '110';
1763                        }
1764                        elseif ($prefs['email']['mail_server_type']=='imaps')
1765                        {
1766                                $prefs['email']['mail_port'] = '993';
1767                        }
1768                        elseif ($prefs['email']['mail_server_type']=='pop3s')
1769                        {
1770                                $prefs['email']['mail_port'] = '995';
1771                        }
1772                        // This is going to be used to switch to the nntp class
1773                        if (isset($phpgw_info['flags']['newsmode']) &&
1774                                $GLOBALS['phpgw_info']['flags']['newsmode'])
1775                        {
1776                                $prefs['email']['mail_server_type'] = 'nntp';
1777                        }
1778                        // DEBUG
1779                        //echo "<br>prefs['email']['passwd']: " .$prefs['email']['passwd'] .'<br>';
1780                        return $prefs;
1781                }
1782                */
1783
1784                // This will be moved into the applications area.
1785                /*!
1786                @function check_code
1787                @abstract ?
1788                @discussion This will be moved into the applications area
1789                */
1790                function check_code($code)
1791                {
1792                        $s = '<br>';
1793                        switch ($code)
1794                        {
1795                                case 13:        $s .= lang('Your message has been sent');break;
1796                                case 14:        $s .= lang('New entry added sucessfully');break;
1797                                case 15:        $s .= lang('Entry updated sucessfully');        break;
1798                                case 16:        $s .= lang('Entry has been deleted sucessfully'); break;
1799                                case 18:        $s .= lang('Password has been updated');        break;
1800                                case 38:        $s .= lang('Password could not be changed');    break;
1801                                case 19:        $s .= lang('Session has been killed');  break;
1802                                case 27:        $s .= lang('Account has been updated'); break;
1803                                case 28:        $s .= lang('Account has been created'); break;
1804                                case 29:        $s .= lang('Account has been deleted'); break;
1805                                case 30:        $s .= lang('Your settings have been updated'); break;
1806                                case 31:        $s .= lang('Group has been added');     break;
1807                                case 32:        $s .= lang('Group has been deleted');   break;
1808                                case 33:        $s .= lang('Group has been updated');   break;
1809                                case 34:        $s .= lang('Account has been deleted') . '<p>'
1810                                                . lang('Error deleting %1 %2 directory',lang('users'),' '.lang('private').' ')
1811                                                . ',<br>' . lang('Please %1 by hand',lang('delete')) . '<br><br>'
1812                                                . lang('To correct this error for the future you will need to properly set the')
1813                                                . '<br>' . lang('permissions to the files/users directory')
1814                                                . '<br>' . lang('On *nix systems please type: %1','chmod 770 '
1815                                                . $GLOBALS['phpgw_info']['server']['files_dir'] . '/users/');
1816                                        break;
1817                                case 35:        $s .= lang('Account has been updated') . '<p>'
1818                                                . lang('Error renaming %1 %2 directory',lang('users'),
1819                                                ' '.lang('private').' ')
1820                                                . ',<br>' . lang('Please %1 by hand',
1821                                                lang('rename')) . '<br><br>'
1822                                                . lang('To correct this error for the future you will need to properly set the')
1823                                                . '<br>' . lang('permissions to the files/users directory')
1824                                                . '<br>' . lang('On *nix systems please type: %1','chmod 770 '
1825                                                . $GLOBALS['phpgw_info']['server']['files_dir'] . '/users/');
1826                                        break;
1827                                case 36:        $s .= lang('Account has been created') . '<p>'
1828                                                . lang('Error creating %1 %2 directory',lang('users'),
1829                                                ' '.lang('private').' ')
1830                                                . ',<br>' . lang('Please %1 by hand',
1831                                                lang('create')) . '<br><br>'
1832                                                . lang('To correct this error for the future you will need to properly set the')
1833                                                . '<br>' . lang('permissions to the files/users directory')
1834                                                . '<br>' . lang('On *nix systems please type: %1','chmod 770 '
1835                                                . $GLOBALS['phpgw_info']['server']['files_dir'] . '/users/');
1836                                        break;
1837                                case 37:        $s .= lang('Group has been added') . '<p>'
1838                                                . lang('Error creating %1 %2 directory',lang('groups'),' ')
1839                                                . ',<br>' . lang('Please %1 by hand',
1840                                                lang('create')) . '<br><br>'
1841                                                . lang('To correct this error for the future you will need to properly set the')
1842                                                . '<br>' . lang('permissions to the files/users directory')
1843                                                . '<br>' . lang('On *nix systems please type: %1','chmod 770 '
1844                                                . $GLOBALS['phpgw_info']['server']['files_dir'] . '/groups/');
1845                                        break;
1846                                case 38:        $s .= lang('Group has been deleted') . '<p>'
1847                                                . lang('Error deleting %1 %2 directory',lang('groups'),' ')
1848                                                . ',<br>' . lang('Please %1 by hand',
1849                                                lang('delete')) . '<br><br>'
1850                                                . lang('To correct this error for the future you will need to properly set the')
1851                                                . '<br>' . lang('permissions to the files/users directory')
1852                                                . '<br>' . lang('On *nix systems please type: %1','chmod 770 '
1853                                                . $GLOBALS['phpgw_info']['server']['files_dir'] . '/groups/');
1854                                        break;
1855                                case 39:        $s .= lang('Group has been updated') . '<p>'
1856                                                . lang('Error renaming %1 %2 directory',lang('groups'),' ')
1857                                                . ',<br>' . lang('Please %1 by hand',
1858                                                lang('rename')) . '<br><br>'
1859                                                . lang('To correct this error for the future you will need to properly set the')
1860                                                . '<br>' . lang('permissions to the files/users directory')
1861                                                . '<br>' . lang('On *nix systems please type: %1','chmod 770 '
1862                                                . $GLOBALS['phpgw_info']['server']['files_dir'] . '/groups/');
1863                                        break;
1864                                case 40: $s .= lang('You have not entered a title').'.';
1865                                        break;
1866                                case 41: $s .= lang('You have not entered a valid time of day').'.';
1867                                        break;
1868                                case 42: $s .= lang('You have not entered a valid date').'.';
1869                                        break;
1870                                case 43: $s .= lang('You have not entered participants').'.';
1871                                        break;
1872                                case 44: $s .= lang('You must choose the days of the week for the appointment to repeat').'.';
1873                                        break;
1874                                case 45: $s .= lang('Recurrent appointments with alarms must have a final date').'.';
1875                                        break;
1876                                case 46: $s .= lang('Recurrent appointments must have a final date').'.';
1877                                        break;
1878                                case 47: $s .= lang('The starting time can not be greater than end time').'.';
1879                                        break;
1880                                default:        return '';
1881                        }
1882                        return $s;
1883                }
1884                /*!
1885                @function phpgw_error
1886                @abstract process error message
1887                @param $error error
1888                @param $line line
1889                @param $file file
1890                */
1891                function phpgw_error($error,$line = '', $file = '')
1892                {
1893                        echo '<p><b>phpGroupWare internal error:</b><p>'.$error;
1894                        if ($line)
1895                        {
1896                                echo 'Line: '.$line;
1897                        }
1898                        if ($file)
1899                        {
1900                                echo 'File: '.$file;
1901                        }
1902                        echo '<p>Your session has been halted.';
1903                        exit;
1904                }
1905
1906                /*!
1907                @function create_phpcode_from_array
1908                @abstract create phpcode from array
1909                @param $array - array
1910                */
1911                function create_phpcode_from_array($array)
1912                {
1913                        while (list($key, $val) = each($array))
1914                        {
1915                                if (is_array($val))
1916                                {
1917                                        while (list($key2, $val2) = each($val))
1918                                        {
1919                                                if (is_array($val2))
1920                                                {
1921                                                        while (list($key3, $val3) = each ($val2))
1922                                                        {
1923                                                                if (is_array($val3))
1924                                                                {
1925                                                                        while (list($key4, $val4) = each ($val3))
1926                                                                        {
1927                                                                                $s .= '$phpgw_info["' . $key . '"]["' . $key2 . '"]["' . $key3 . '"]["' .$key4 . '"]="' . $val4 . '";';
1928                                                                                $s .= "\n";
1929                                                                        }
1930                                                                }
1931                                                                else
1932                                                                {
1933                                                                        $s .= '$phpgw_info["' . $key . '"]["' . $key2 . '"]["' . $key3 . '"]="' . $val3 . '";';
1934                                                                        $s .= "\n";
1935                                                                }
1936                                                        }
1937                                                }
1938                                                else
1939                                                {
1940                                                        $s .= '$phpgw_info["' . $key .'"]["' . $key2 . '"]="' . $val2 . '";';
1941                                                        $s .= "\n";
1942                                                }
1943                                        }
1944                                }
1945                                else
1946                                {
1947                                        $s .= '$phpgw_info["' . $key . '"]="' . $val . '";';
1948                                        $s .= "\n";
1949                                }
1950                        }
1951                        return $s;
1952                }
1953
1954                // This will return the full phpgw_info array, used for debugging
1955                /*!
1956                @function debug_list_array_contents
1957                @abstract return the full phpgw_info array for debugging
1958                @param array - array
1959                */
1960                function debug_list_array_contents($array)
1961                {
1962                        while (list($key, $val) = each($array))
1963                        {
1964                                if (is_array($val))
1965                                {
1966                                        while (list($key2, $val2) = each($val))
1967                                        {
1968                                                if (is_array($val2))
1969                                                {
1970                                                        while (list($key3, $val3) = each ($val2))
1971                                                        {
1972                                                                if (is_array($val3))
1973                                                                {
1974                                                                        while (list($key4, $val4) = each ($val3))
1975                                                                        {
1976                                                                                echo $$array . "[$key][$key2][$key3][$key4]=$val4<br>";
1977                                                                        }
1978                                                                }
1979                                                                else
1980                                                                {
1981                                                                        echo $$array . "[$key][$key2][$key3]=$val3<br>";
1982                                                                }
1983                                                        }
1984                                                }
1985                                                else
1986                                                {
1987                                                        echo $$array . "[$key][$key2]=$val2<br>";
1988                                                }
1989                                        }
1990                                }
1991                                else
1992                                {
1993                                        echo $$array . "[$key]=$val<br>";
1994                                }
1995                        }
1996                }
1997
1998                // This will return a list of functions in the API
1999                /*!
2000                @function debug_list_core_functions
2001                @abstract return a list of functionsin the API
2002                */
2003                function debug_list_core_functions()
2004                {
2005                        echo '<br><b>core functions</b><br>';
2006                        echo '<pre>';
2007                        chdir(PHPGW_INCLUDE_ROOT . '/phpgwapi');
2008                        system("grep -r '^[ \t]*function' *");
2009                        echo '</pre>';
2010                }
2011
2012                // This will return a value for the next id an app/class may need to insert values into ldap.
2013                /*!
2014                @function next_id
2015                @abstract return the next higher value for an integer, and increment it in the db.
2016                */
2017                function next_id($appname,$min=0,$max=0)
2018                {
2019                        if (!$appname)
2020                        {
2021                                return -1;
2022                        }
2023
2024                        $GLOBALS['phpgw']->db->query("SELECT id FROM phpgw_nextid WHERE appname='".$appname."'",__LINE__,__FILE__);
2025                        while( $GLOBALS['phpgw']->db->next_record() )
2026                        {
2027                                $id = $GLOBALS['phpgw']->db->f('id');
2028                        }
2029
2030                        if (empty($id) || !$id)
2031                        {
2032                                $id = 1;
2033                                $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_nextid (appname,id) VALUES ('".$appname."',".$id.")",__LINE__,__FILE__);
2034                        }
2035                        elseif($id<$min)
2036                        {
2037                                $id = $min;
2038                                $GLOBALS['phpgw']->db->query("UPDATE phpgw_nextid SET id=".$id." WHERE appname='".$appname."'",__LINE__,__FILE__);
2039                        }
2040                        elseif ($max && ($id > $max))
2041                        {
2042                                return False;
2043                        }
2044                        else
2045                        {
2046                                $id = $id + 1;
2047                                $GLOBALS['phpgw']->db->query("UPDATE phpgw_nextid SET id=".$id." WHERE appname='".$appname."'",__LINE__,__FILE__);
2048                        }
2049
2050                        return (int)$id;
2051                }
2052
2053                // This will return a value for the last id entered, which an app may need to check
2054                // values for ldap.
2055                /*!
2056                @function last_id
2057                @abstract return the current id in the next_id table for a particular app/class.
2058                */
2059                function last_id($appname,$min=0,$max=0)
2060                {
2061                        if (!$appname)
2062                        {
2063                                return -1;
2064                        }
2065
2066                        $GLOBALS['phpgw']->db->query("SELECT id FROM phpgw_nextid WHERE appname='".$appname."'",__LINE__,__FILE__);
2067                        while( $GLOBALS['phpgw']->db->next_record() )
2068                        {
2069                                $id = $GLOBALS['phpgw']->db->f('id');
2070                        }
2071
2072                        if (empty($id) || !$id)
2073                        {
2074                                if($min)
2075                                {
2076                                        $id = $min;
2077                                }
2078                                else
2079                                {
2080                                        $id = 1;
2081                                }
2082                                $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_nextid (appname,id) VALUES ('".$appname."',".$id.")",__LINE__,__FILE__);
2083                        }
2084                        elseif($id<$min)
2085                        {
2086                                $id = $min;
2087                                $GLOBALS['phpgw']->db->query("UPDATE phpgw_nextid SET id=".$id." WHERE appname='".$appname."'",__LINE__,__FILE__);
2088                        }
2089                        elseif ($max && ($id > $max))
2090                        {
2091                                return False;
2092                        }
2093                        return (int)$id;
2094                }
2095        }//end common class
Note: See TracBrowser for help on using the repository browser.