[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> class.common.inc.php (source)

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


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7