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

Revision 2616, 62.4 KB checked in by amuller, 14 years ago (diff)

Ticket #911 - Aproveitamento de funções comuns do expressoMail

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