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

Revision 2547, 61.5 KB checked in by amuller, 14 years ago (diff)

Ticket #1036 - Corrigindo js e otimizando a criação do jspack

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