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

Revision 2903, 63.3 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Corrigindo problemas na inclusão de folhas de estilo.

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