SWS PHP Cross Reference Web Portal Systems

Source: /common.php - 643 lines - 24115 bytes - Summary - Text - Print

   1  <?php
   2  /*#################################################################
   3  #
   4  # Name:    common.php
   5  #
   6  # Description:
   7  #   Routines common to generate headers etc
   8  #
   9  # Copyright (C) 2004-2005 Terry Gliedt, University of Michigan
  10  # This is free software; you can redistribute it and/or modify it under the
  11  # terms of the GNU General Public License as published by the Free Software
  12  # Foundation; See http://www.gnu.org/copyleft/gpl.html
  13  #################################################################*/
  14  $VERSION = '2.0';                   // Version of this release of SWS
  15  
  16  $REVISIONDATE = '';                 // Date of PHP or HTML file
  17  global $SWSDIR;
  18  //print "<!-- _GET=\n"; print_r($_GET); print " -->\n";
  19  include_once "$SWSDIR/local_config.php";    // Define site, same dir as common.php
  20  
  21  /*---------------------------------------------------------------
  22  # do_page - Generate an HTML page using all the default layout
  23  #
  24  # Parameters:
  25  #   title - optional title
  26  #   centerhtml - optional HTML to show in center panel
  27  #
  28  # Returns:
  29  #   nothing
  30  ---------------------------------------------------------------*/
  31  function do_page($title='No title provided', $centerhtml = '') {
  32      global $LHMENUS, $RHMENUS, $LOCALLHMENUS, $LOCALRHMENUS;
  33      global $RHMENUS_IF_AUTH, $HEADERLINES, $KEYWORDS, $JSCRIPT;
  34  
  35      //  Get things from any session that was set up
  36      session();
  37  
  38      //  If no HTML was provided, get HTML from an inferred file
  39      //  and get possible meta keywords and jscript/style lines
  40      $f = '';
  41      if (! $centerhtml) {
  42          list($centerhtml, $keywords) = do_center();
  43          $KEYWORDS .= ' ' . $keywords;
  44      }
  45  
  46     //  Generate a page, using our default page construction
  47      $hlines = '';
  48      if ($KEYWORDS) { $hlines .= "<meta name='keywords' content='$KEYWORDS'/>\n"; }
  49      do_header($title, $HEADERLINES . $hlines . $JSCRIPT);
  50      do_banner();
  51  
  52      //  We always have LH menus
  53      print "<!-- Generate page. Menus on left. Page in middle. Possibly menus on right -->\n" .
  54          "<table summary='2,3 columns'>\n<tr>  <td valign='top' class='leftcol'>\n";
  55      do_staticnav($LHMENUS);
  56      if (isset($LOCALLHMENUS)) {
  57          foreach ($LOCALLHMENUS as $m) { do_staticnav($m); }
  58      }
  59      print "  </td>\n";
  60  
  61      //  Show principal page here. HTML will either be inferred, based
  62      //  on the name of this PHP file, or we'll use HTML provided by caller
  63      print "  <td valign='top' class='middlecol'>\n";
  64      print $centerhtml;
  65      print "</td>\n";
  66  
  67      //  Show RH menus if a file is provided.
  68      //  Maybe only show them if we are authenticated
  69      if ($RHMENUS) {
  70          if ((! $RHMENUS_IF_AUTH) ||
  71              ($RHMENUS_IF_AUTH && $_SESSION['SESSTIME'])) {
  72              print "<td valign='top' class='rightcol'>\n";
  73              do_staticnav($RHMENUS);
  74              foreach ($LOCALRHMENUS as $m) { do_staticnav($m); }
  75              print "</td>\n";
  76          }
  77      }
  78      print "</tr></table>\n";
  79  
  80      do_footer($f);
  81      flush();                // Sourceforge did not flush!!
  82  }
  83  
  84  /*---------------------------------------------------------------
  85  # do_header - Generate an HTML header
  86  #
  87  # Parameters:
  88  #   title - optional title or use global variable $TITLE
  89  #   more  - optional additional header lines (like javascript etc)
  90  #           If this ends in '.inc', it is a file to be read
  91  #           and put to STDOUT
  92  #
  93  # Returns:
  94  #   nothing
  95  ---------------------------------------------------------------*/
  96  function do_header($title='No title provided', $more='') {
  97      global $SITEJS, $SITELOCALJS, $TITLE, $VERSION, $STYLE, $SITEBODYCLASS, $SITEONLOAD, $SWSURL;
  98  
  99      //  If $TITLE is provided, use that
 100      if ($TITLE) { $title = $TITLE; }
 101  
 102      //  Generate the header
 103      print <<<END
 104  <?xml version='1.0' encoding='iso-8859-1'?>
 105  <!DOCTYPE html 
 106       PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
 107       'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
 108  <html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
 109  <head>
 110  <title>$title</title>
 111  <meta http-equiv='Content-Type' content='text/html;charset=iso-8859-1'/>
 112  <meta name='keywords' content='This uses SWS version $VERSION'/>
 113  <!-- Style controls for look and feel of page -->
 114  <link rel='stylesheet' type='text/css' href='$SWSURL/print.css' media='print'/>
 115  
 116  END;
 117  
 118      //  SWS style sheet
 119      //  The JS global variables are all screwed up. JS can mean
 120      //  either Javascript OR Css (dumb). Try to cope with this mess.
 121      if (isset($SITEJS) && $SITEJS != '') {
 122          print "<style type='text/css'>@import url('$SITEJS');</style>\n";
 123      }
 124      //  Local style sheets
 125      if (isset($SITELOCALJS)) {
 126          foreach ($SITELOCALJS as $s) {
 127              if (preg_match('/css/',$s))  {
 128                  print "<style type='text/css'>@import url('$s');</style>\n";
 129              }
 130              else {
 131                  print "<script type='text/javascript' src='$s'></script>\n";
 132              }
 133          }
 134      }
 135      if ($STYLE) { print $STYLE; }
 136      //  Add user lines
 137      $c = '';
 138      if ($SITEBODYCLASS) { $c .= " class='$SITEBODYCLASS'"; }
 139      if ($SITEONLOAD) { $c .= "onLoad='$SITEONLOAD'"; }
 140      print "$more\n</head><body $c>\n";
 141  }
 142  
 143  /*---------------------------------------------------------------
 144  # do_banner - Generate default banner for site
 145  #
 146  # Parameters:
 147  #   none
 148  #
 149  # Returns:
 150  #   none
 151  ---------------------------------------------------------------*/
 152  function do_banner() {
 153      global $BANNERFILE;
 154      
 155      if (! $BANNERFILE) { return; }
 156      if (! file_exists($BANNERFILE)) { return; }
 157      
 158      if (! readfile($BANNERFILE)) {
 159          redmsg("do_banner: Unable to read file '$BANNERFILE'");
 160      }
 161  }
 162  
 163  /*---------------------------------------------------------------
 164  # do_staticnav - Generate static menus
 165  #
 166  # Parameters:
 167  #   file - file of menus to read
 168  #       File has the following format:
 169  #           END in col 1, pseudo EOF (useful for debugging)
 170  #           # in col 1, comment
 171  #           Blank lines are ignored
 172  #           BLANKLINE in col 1, insert spacer in menu
 173  #           BLOCK= in col 1 defines title of a menu block
 174  #           Users authorized to see this menu are in [] after block title
 175  #           Authorized user [*] means 'all authenticated users'
 176  #           Menu link starts in col 1 with <a and is on one line
 177  #           Indented menu link starts in col 1 with INDENT <a and is on one line
 178  #           Anything else in col 1 is HTML which is inserted unchanged
 179  #
 180  # Examples:
 181  #
 182  #   BLOCK=See Me
 183  #   <a class="menu-item" href="/Repository" target="_blank">My Data</a>
 184  #   BLANKLINE
 185  #   BLOCK=See Some of Me [fred deb]
 186  #   <a class="menu-item" href="/Yours" target="_blank">Your Data</a>
 187  #   BLOCK=See All of Me [*]
 188  #   <a class="menu-item" href="/Ours" target="_blank">Our Data</a>
 189  #   #   This block is everything from <form to </form
 190  #   INDENT<a class="menus" href="/Ours" target=_blank>Our Data</a>
 191  #   #   This block is everything from <form to </form
 192  #   BLOCK=Search Here
 193  #   <form method="get" action="/pubcgi/swish.cgi">
 194  #     <input maxlength="200" size="18" type="text" name="query">
 195  #     <input value="Search!" type="submit" name="submit">
 196  #     <input value="fusion" type="hidden" name="use">
 197  #     <input value="selected" type="hidden" name="swishrank'>
 198  #   </form>
 199  #
 200  # Returns:
 201  #   none
 202  ---------------------------------------------------------------*/
 203  function do_staticnav($file) {
 204      global $BLOCKNAMEHTML, $MENUITEMHTML, $MENUINDENTHTML, $SHOWBLOCK, $_SESSION;
 205      if (! file_exists($file)) { return; }
 206  
 207      $blocktop = "<table class='menus'>\n";
 208      $blockbottom = "<tr><td class='menus-spacer'></td></tr>\n</table>\n<br/>\n";
 209  
 210      print "<!-- Static menus $file -->\n";
 211      $lines = file($file);
 212      $html = '';
 213      $blockname = '';
 214      for ($n=0; $n<count($lines); $n++) {
 215          $line = $lines[$n];
 216          if (preg_match('/^END/', $line)) { break; } // Pseudo EOF
 217          if (preg_match('/^#/', $line)) { continue; }
 218          if (preg_match('/^\s*$/', $line)) { continue; }
 219  
 220          if (preg_match('/^BLOCK=(.+)\s*$/', $line, $m)) {
 221              $noshow = 0;
 222              $blockname = $m[1];
 223              $authorizedids = array();
 224              //  Watch if special authentication is needed
 225              if (preg_match('/^(.+)\s*\[(.+)\]/', $blockname, $m)) {
 226                  if (! $_SESSION['REMOTE_USER']) {     // Not authenticated
 227                      $blockname = '';
 228                      continue;
 229                  }
 230                  $blockname = $m[1];
 231                  if ($m[2] != '*') {     // Not 'ALL USERS', check it out
 232                      $authorizedids = explode(' ',$m[2]);
 233                      //  If this menu is only for SOME users, see if this
 234                      //  person is allowed to see this
 235                      if (! in_array($_SESSION['REMOTE_USER'],$authorizedids)) {
 236                          $blockname = '';
 237                          continue;
 238                      }
 239                  }
 240              }
 241  
 242              //  Watch if this BLOCK applies to only certain pages
 243              if (preg_match('/^(.+)\s+SHOWONLY=(\w+)\s*/', $blockname, $m)) {
 244                  if ($SHOWBLOCK != $m[2]) {  // Skip this block
 245                      $blockname = '';
 246                      continue;
 247                  }
 248                  $blockname = $m[1];         // Correct blockname
 249              }
 250  
 251              //  Show this menu block
 252              if ($blockname == 'NOSHOW') { $noshow = 1; }
 253              if ($html) { print $html . $blockbottom; } // If started, finish it
 254              $html = $blocktop;
 255              if (! $noshow) {
 256                  $html .= "<tr><td valign='middle' class='menu-top'>&nbsp;" .
 257                      $BLOCKNAMEHTML . $blockname . "</td></tr>\n";
 258              }
 259              continue;
 260          }
 261          if (! $blockname) { continue; }     // No play if no block found
 262  
 263          //  Maybe insert a little spacer for looks
 264          if (preg_match('/^BLANKLINE/', $line)) {
 265              $html .= "<tr><td class='menus-blank'>&nbsp;</td></tr>\n";
 266              continue;
 267          }
 268  
 269          //  This is a bullet item
 270          if (preg_match ("/^<a+.*href=/", $line)) {
 271              $html .= "<tr><td class='menu-item'>\n" .
 272                  "  &nbsp;$MENUITEMHTML$line" .
 273                  "</td></tr>\n";
 274              continue;
 275          }
 276  
 277          //  This is an indented bullet item
 278          if (preg_match ("/^INDENT<a+.*href=/", $line)) {
 279              $line = substr($line,6);
 280              $html .= "  <tr><td class='menu-item'>\n" .
 281                  "  &nbsp;$MENUINDENTHTML$line" .
 282                  "  </td></tr>\n";
 283              continue;
 284          }
 285  
 286          //  What remains better be a set of lines of the form <key ... </key
 287          if (! preg_match ("/^<(\w+)/", $line, $m)) {
 288              redmsg("Invalid menu line $n in '$file': $line");
 289              continue;
 290          }
 291          $startn = $n;
 292          $key = $m[1];                   // Take all lines up until </key
 293          $h = $line;
 294          for ($n++; $n<count($lines); $n++) {
 295              $line = $lines[$n];
 296              $h .= $line;
 297              if (preg_match ("/^<\/$key/", $line)) { break; }
 298          }
 299          if (! preg_match ("/^<\/$key/", $line)) {
 300              redmsg("Menu block '$key' started at $startn not terminated in '$file'");
 301              continue;
 302          }
 303          $html .= "  <tr><td class='menu-item'>\n$h\n</td></tr>\n";
 304      }
 305      if ($html) { print $html . $blockbottom; } // If started, finish it
 306      print "<!-- End menu $file -->\n";
 307  }
 308  
 309  /*---------------------------------------------------------------
 310  # do_center - Read a file and insert it in the center section
 311  #
 312  # Parameters:
 313  #   file - option file to read. If not provided, the file to
 314  #           insert will be derived from $_SERVER[PHP_SELF]
 315  #           with .htm or .html appended.
 316  #
 317  # Note:
 318  #   Title line in file of form TITLE=string
 319  #   Lines in file of form KEYWORDS=w1 w2 w3 are extracted
 320  #   Footer line in file of form FOOTER=string
 321  #   Style import line in file of form STYLE=@import url("/sws/styleSWS.css");
 322  #
 323  # Returns:
 324  #   html
 325  #   keywords from KEYWORDS are generated in header
 326  ---------------------------------------------------------------*/
 327  function do_center($file = '') {
 328      global $REVISIONDATE, $_SERVER, $TITLE, $FOOTER, $STYLE, $CALL;
 329  
 330      //  If no file provided, derive one
 331      if (! $file) {
 332          $file = $_SERVER['PHP_SELF'];
 333          if (! preg_match('/\/([^\/]+)\.php$/', $file, $m)) {
 334              redmsg("do_center: Unable to derive file to read from '$file'");
 335              return array('','','');
 336          }
 337          $file = $m[1] . '.htm';
 338          if (! file_exists($file)) { $file = $m[1] . '.html'; }
 339          if (! file_exists($file)) {
 340              redmsg("do_center: No HTML file found for " . $_SERVER['PHP_SELF'] . "'");
 341              return array('','');
 342          }
 343      }
 344  
 345      //  Just read and print file to STDOUT
 346      $html = "<!-- Centerfile $file -->\n";
 347      $kw = '';
 348      if (file_exists($file)) {
 349          $REVISIONDATE = "<br/>Last Revision: " . date('M d, Y', filemtime($file));
 350          $lines = file($file);
 351          for ($i=0; $i<count($lines); $i++) {
 352              if (preg_match ('/^<\!--\s*KEYWORDS=\s*(.+)\s+-->\s*$/', $lines[$i], $m)) {
 353                  $kw .= $m[1] . ' ';
 354                  continue;
 355              }
 356              if (preg_match ('/^<\!--\s*TITLE=\s*(.+)\s+-->\s*$/', $lines[$i], $m)) {
 357                  $TITLE = $m[1];
 358                  continue;
 359              }
 360              if (preg_match ('/^<\!--\s*INSERT=\s*(.+)\s+-->\s*$/', $lines[$i], $m)) {
 361                  if (is_file($m[1])) {           // Ignore when file does not exist
 362                      $lines[$i] = file_get_contents($m[1]);
 363                  }
 364                  else {
 365                      $s = getcwd();
 366                      $lines[$i] = "<!-- File '$m[1]' not found in '$s' -->\n";
 367                  }
 368                  $html .= $lines[$i];
 369                  continue;
 370              }
 371              if (preg_match ('/^<\!--\s*FOOTER=\s*(.+)\s+-->\s*$/', $lines[$i], $m)) {
 372                  $FOOTER = $m[1];
 373                  continue;
 374              }
 375              if (preg_match ('/^<\!--\s*STYLE=\s*(.+)\s+-->\s*$/', $lines[$i], $m)) {
 376                  $STYLE = "<style type='text/css'>$m[1]</style>\n";
 377                  continue;
 378              }
 379              if (preg_match ('/^<\!--\s*OPTIONS=\s*(.+)\s+-->\s*$/', $lines[$i], $m)) {
 380                  $opts = explode(' ', $m[1]);            // Extract all keys from OPTIONS=
 381                  $dobreak = 0;
 382                  $doh2 = 0;
 383                  $popuplist = array();                   // Get HTML for each popup.  Ends in </div>\n
 384                  foreach ($opts as $o) {
 385                      //  call(user/group,callname)
 386                      if (preg_match ('/call\((\S+),(\S+)\)/', $o, $mm)) {   // Call some user provided code
 387                          $h = gen_popup($mm[1], $mm[2]);
 388                          if ($h) {
 389                              $dobreak++;
 390                              array_push($popuplist, $h);
 391                          }
 392                          continue;
 393                      }
 394                      if (preg_match ('/h2/', $o)) {          // Add title as h2
 395                          $doh2++;
 396                          continue;
 397                      }
 398                      if (preg_match ('/printpage/', $o)) {   // Add print this page
 399                          $h = "<div class='popup'><a href='javascript:window.print()' class='popup'>Print Page</a></div>";
 400                          $dobreak++;
 401                          array_push($popuplist, $h);
 402                          continue;
 403                      }
 404                      if (preg_match ('/breadcrumbs/', $o)) {
 405                          // Show path parts of _SERVER['REQUEST_URI']
 406                          $a = explode('/', $_SERVER['REQUEST_URI']);    // Gets '' a b c d.php
 407                          $a[0] = 'Home';
 408                          $b = array_pop($a);       // Now Home a b c
 409                          $b = implode(' -> ', $a);
 410                          $html .= "<div class='breadcrumbs'>$b</div>\n";
 411                          $dobreak++;
 412                          continue;
 413                      }
 414                  }
 415                  //  Add in the HTML for each popup with a separator
 416                  $last = sizeof($popuplist) - 1;
 417                  for($i=0; $i <= $last; ++$i) {
 418                      if ($i == $last) { $html .=  $popuplist[$i]; }
 419                      else {
 420                          $aa = str_replace('</div>', $CALL['sep'] . '</div>', $popuplist[$i]);
 421                          $html .= $aa;
 422                      }
 423                  }
 424                  if ($dobreak) { $html .= "<br>\n"; }
 425                  if (isset($TITLE) && $doh2) {
 426                      $html .= "<h2 align='center'>$TITLE</h2>\n";
 427                  }
 428                  continue;
 429              }
 430              $html .= $lines[$i];
 431          }
 432      }
 433      else { $html .= "<font color=red>File '$file' not found</font>\n"; }
 434      $html .= "<!-- End centerfile $file -->\n";
 435      return array($html, $kw);
 436  }
 437  
 438  /*---------------------------------------------------------------
 439  # gen_popup - Generate HTML code to call something in a popup window
 440  #
 441  # Parameters:
 442  #   authuser - name of user who can do this (*=all)
 443  #   callname - entry in CALL to be invoked
 444  #
 445  # Returns:
 446  #   nothing or string of HTML
 447  ---------------------------------------------------------------*/
 448  function gen_popup($authuser, $callname) {
 449      global $CALL, $_SERVER, $_GET, $GROUP;
 450  
 451      //  Verify this user is authorized and $callname is defined
 452      if (! isset($authuser)) { return ''; }
 453      $ok = 0;
 454      if ($authuser == '*') { $ok = 1; }
 455      else {
 456          if (isset($_SERVER['REMOTE_USER'])) {
 457              if ($_SERVER['REMOTE_USER'] == $authuser) { $ok = 1; }
 458              if (isset($GROUP[$authuser]) && in_array($_SERVER['REMOTE_USER'], $GROUP[$authuser])) { $ok = 1; }
 459          }
 460      }
 461      if (! $ok) { return ''; }
 462      if (! isset($CALL['calls'][$callname])) { return ''; }
 463  
 464      //  User OK, generate HTML for popup
 465      $a = str_replace('_', ' ', $callname);
 466      $b =$CALL['calls'][$callname];
 467      return "<div class='popup'><a href=\"javascript:popup('$b'," .
 468          $CALL['width'] . ',' . $CALL['height'] . ",'')\" class='popup'>$a</a></div>\n";   
 469  }
 470  
 471  
 472  /*---------------------------------------------------------------
 473  # do_footer - Generate footer
 474  #
 475  # Parameters:
 476  #   none            Will use GLOBAL variable $FOOTER
 477  #
 478  # Returns:
 479  #   nothing
 480  ---------------------------------------------------------------*/
 481  function do_footer() {
 482      global $CONTACT, $REVISIONDATE, $SITENAME, $COPYRIGHTYEAR, $FOOTER;
 483  
 484      //  If $FOOTER is provided, use that
 485      if ($FOOTER) { print $FOOTER . "\n</body></html>\n"; return; }
 486  
 487      $copyryr = date('Y');
 488      if ($copyryr != $COPYRIGHTYEAR) { $copyryr = "$COPYRIGHTYEAR-$copyryr"; }
 489  
 490      print <<<END
 491  <div class='footer'>
 492  <hr size='4' width='80%' noshade='noshade'/>
 493  Copyright (c) $copyryr, $SITENAME<br/>
 494  Report problems to <a class='footer' href='mailto:$CONTACT'>$CONTACT</a><br/>
 495  $REVISIONDATE <br/>
 496  </div>
 497  </body></html>
 498  
 499  END;
 500  }
 501  
 502  /*---------------------------------------------------------------
 503  # redmsg - Displays message in red
 504  #
 505  # Parameters:
 506  #   msg - message to issue
 507  #
 508  # Returns:
 509  #   nothing
 510  ---------------------------------------------------------------*/
 511  function redmsg($msg) {
 512  
 513      print "<br/><font color='#ff0000'><b>$msg</b></font><br/>\n";
 514  }
 515  
 516  /*---------------------------------------------------------------
 517  # findfile - Return the HTML for a file if it exists
 518  #
 519  # Parameters:
 520  #   f - file to read. May be null. Must be filename (without
 521  #       extension and no directory). File in current working
 522  #       directory only.
 523  #
 524  # Returns:
 525  #   html
 526  ---------------------------------------------------------------*/
 527  function findfile($f) {
 528      global $REVISIONDATE, $KEYWORDS, $TITLE, $FOOTER;
 529  
 530      //  If empty, nothing to do
 531      if (! $f) { return ''; }
 532  
 533      //  Be sure this is a simple filename
 534      if (preg_match('/^[^\/]+$/', $f)) {
 535          if (! $_SERVER) { $me = $HTTP_SERVER_VARS["SCRIPT_FILENAME"]; }
 536          else { $me = $_SERVER["SCRIPT_FILENAME"]; }
 537          $p = strrpos($me, '/');         // Work around broken PHP sites
 538          $m = substr($me,0,$p);
 539          $file = "$m/$f.html";
 540          if (! file_exists($file)) { $file = "$m/$f.htm"; }
 541          if (file_exists($file)) {
 542              $lines = file($file);
 543              $REVISIONDATE = "<br/>Last Revision: " . date('M d, Y', filemtime($file));
 544              $html = '';
 545              for ($i=0; $i<count($lines); $i++) {
 546                  if (preg_match ('/^<\!--\s*KEYWORDS=\s*(.+)\s*-->\s*$/', $lines[$i], $m)) {
 547                      $KEYWORDS .= ' ' . $m[1] . "\n";
 548                      continue;
 549                  }
 550                  if (preg_match ('/^<\!--\s*TITLE=\s*(.+)\s*-->\s*$/', $lines[$i], $m)) {
 551                      $TITLE = $m[1];
 552                      continue;
 553                  }
 554                  if (preg_match ('/^<\!--\s*FOOTER=\s*(.+)\s*-->\s*$/', $lines[$i], $m)) {
 555                      $FOOTER = $m[1];
 556                      continue;
 557                  }
 558                  $html .= $lines[$i];
 559              }
 560              return $html;
 561          }
 562      }
 563      
 564      return "<br/><font color='#ff0000'><b>Invalid FILE: $f</b></font>\n";
 565  }
 566  
 567  /*---------------------------------------------------------------
 568  # session - Does the PHP session retrieval. If anything is 
 569  #           being saved in a session, some other program did it all.
 570  #           This assumes a session of the name we use was set up.
 571  #
 572  # Parameters:
 573  #   setup - optional boolean if a sesssion is to be set up or not
 574  #
 575  # Returns:
 576  #   nothing
 577  ---------------------------------------------------------------*/
 578  function session($setup = 0) {
 579      global $EXPIRATION_PERIOD, $SESSIONCOOKIENAME, $_SERVER, $_SESSION;
 580  
 581      //  Watch for authorization to expire
 582      //ini_set('session.use_trans_sid', 0);    // Stop adding SID to URLs   Comment out to avoid error tpg
 583      ini_set('session.use_cookies', 1);      // Use cookie to store the session ID
 584      ini_set('session.name', $SESSIONCOOKIENAME);    // Set name of our cookie
 585      session_cache_limiter ('private, must-revalidate');
 586  
 587      //  If we are not to set up a session, just check for time to expire
 588      if (! $setup) {
 589          if (! session_id()) { session_start(); }
 590          if (! isset($_SESSION['SESSTIME'])) { $_SESSION['SESSTIME'] = 0; }
 591          $exp = $_SESSION['SESSTIME'] - time();
 592          if ( $exp < 0) {            // If session expired, clean up
 593              unset($_SESSION['SESSTIME']);
 594              unset($_SESSION['REMOTE_USER']);
 595          }
 596          else {                      // We have a session, call user override
 597              if (function_exists('CONFIG_OVERRIDE')) { CONFIG_OVERRIDE($_SESSION['REMOTE_USER']); }
 598          }
 599          return;
 600      }
 601  
 602      // Set up a new session, set expiration time
 603      $t = time();
 604      session_id($t);
 605      session_start();
 606      $SESSTIME = $t + $EXPIRATION_PERIOD;        // We are authorized until this time
 607      $_SESSION['SESSTIME'] = $SESSTIME;
 608      //  session_register is deprecated
 609      //session_register ('SESSTIME');              // Actually creates session
 610      $_SESSION['REMOTE_USER'] = $_SERVER['REMOTE_USER'];
 611      //  session_register ('REMOTE_USER');           // Useless unless /private requires pw
 612      // We have a session, call user override
 613      if (function_exists('CONFIG_OVERRIDE')) { CONFIG_OVERRIDE($_SESSION['REMOTE_USER']); }
 614  }
 615  
 616  /*---------------------------------------------------------------
 617  # isolate_parms - Given a list of parameter keys, build an
 618  #       array of values taken from POST, GET or SESSION data.
 619  #
 620  # Recommended call:  extract(isolate_parms('a','b','c'));
 621  #
 622  # Parameters:
 623  #   key1, key2, ... keyN - variables we want set
 624  #
 625  # Returns:
 626  #   array for extract
 627  ---------------------------------------------------------------*/
 628  function isolate_parms() {
 629      global $_POST, $_GET, $_SESSION;
 630  
 631      $parmvars = func_get_args();        // Get arguments to me as an array
 632      $myvars = array();
 633      while (list ($key, $val) = each($parmvars)) {
 634          $v = '';
 635          if (isset($_POST[$val])) { $v=$_POST[$val]; }
 636          elseif (isset($_GET[$val])) { $v=$_GET[$val]; }
 637          elseif (isset($_SESSION[$val])) { $v=$_SESSION[$val]; }
 638          $myvars[$val]=$v;
 639      }
 640      return $myvars;
 641  }
 642  
 643  ?>

title

Description

title

Description

title

Description

title

title

Body