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

Revision 2645, 62.6 KB checked in by amuller, 14 years ago (diff)

Ticket #1044 - Adicionando suporte no expressoMail

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