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

Revision 2623, 62.6 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Organizando o HTML do template default.

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