SWS PHP Cross Reference Web Portal Systems

Source: /printme.php - 87 lines - 2349 bytes - Text - Print

   1  <?php
   2  /*#################################################################
   3  #
   4  # Name:    printme.php
   5  #
   6  # Description:
   7  #   Generate HTML from _SERVER["HTTP_REFERER"]. Requires ability
   8  #   to read the actual data from DOCUMENT_ROOT.
   9  #   The file is read and puts a Print button at the top.
  10  #
  11  #################################################################*/
  12  $SWSURL = '/sws';
  13  $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL;   // Where all my files are
  14  include_once "$SWSDIR/common.php";
  15  
  16  $refurl = $_SERVER['HTTP_REFERER'];
  17  if ($refurl == '') {
  18      print "<h3 align='center'>Unable to parse HTTP_REFERER</h3>\n";
  19      print "<pre>\n";
  20      system('pwd');
  21      phpinfo(INFO_VARIABLES);
  22      print "</pre>\n";
  23      exit;
  24  }
  25  
  26  //  Get the path to this file
  27  $f = parse_url($refurl, PHP_URL_PATH);
  28  if (! $f ) {
  29      print "<h3 align='center'>Unable to parse HTTP_REFERER to get the path to the file</h3>\n" .
  30          "<p>HTTP_REFERER=$refurl</p>\n";
  31      exit;
  32  }
  33  
  34  $f = str_replace('.php', '.html', $f);      // If file ends in php, change to html
  35  if (preg_match ('/\/$/', $f)) { $f .= 'index.html'; }   // Directories default to this
  36  
  37  
  38  //  Local style sheets 
  39  foreach ($SITELOCALJS as $s) {
  40      print "<style type='text/css'>@import url('$s');</style>\n";
  41  }  
  42  print <<<END
  43  <style type='text/css'>
  44  DIV.printleft {
  45  float: left;
  46  padding-left: 10px;
  47  font: bold 11px Tahoma, Verdana, sans-serif;
  48  }
  49  DIV.printright {
  50  float: right;
  51  font: bold 11px Tahoma, Verdana, sans-serif;
  52  padding-right: 10px;
  53  }
  54  </style>
  55  
  56  END;
  57  
  58  print "<div class='printleft'>\n" . 
  59      "<form><input type='button' value=' Print This Page '" .
  60      "onclick='window.print();return false;' /></form>\n" .
  61      "</div>\n" .
  62      "<div class='printright'>URL=$refurl</div>\n<br>\n";
  63  
  64  $f = $_SERVER['DOCUMENT_ROOT'] . '/' . $f;
  65  $lines = file($f);
  66  if (! $lines) {
  67      print "<h3 align='center'>Unable to read file '$f'</h3>\n";
  68      system('pwd');
  69      phpinfo(INFO_VARIABLES);
  70      print "</pre>\n";
  71      exit;
  72  }
  73  
  74  //  If this is an SWS-like file, first line could be TITLE
  75  $TITLE = '';
  76  if (preg_match ('/^<\!--\s*TITLE=\s*(.+)\s*-->\s*$/', $lines[0], $m)) {
  77      $TITLE = $m[1];
  78  }
  79  if (preg_match ('/^<\!--\s*OPTIONS=\s*(.+)\s*-->\s*$/', $lines[1], $m)) {
  80      if (preg_match ('/h2/', $m[1])) {
  81          $lines[1] = "<h2 align='center'>$TITLE</h2>\n";
  82      }
  83  }
  84  for ($i=0; $i<count($lines); $i++) { print $lines[$i]; }
  85  
  86  ?>
  87  

title

Description

title

Description

title

Description

title

title

Body