Location: PHPKode > projects > dizzyPages > dizzypages/htdocs/dze.php
<?php
$dzeLogHandle = null;
$config = null;

// utilities to assist debugging
function html_print_r($in) {
   print "<PRE>\n" . print_r($in, true) . "</PRE>\n";
}

function printNode($node) {
   $tmpDoc = new DOMDocument();
   $tmpDoc->appendChild($tmpDoc->importNode($node, true));
   $tmpDoc->formatOutput = true;
   print "<pre>" . htmlentities($tmpDoc->saveXML()) . "</pre>";
}

function setUpLogging(& $config) {
   global $dzeLogHandle;

   if (   !is_null($config)
       && isset($config["log_level"])) {

      $ext = ".txt";

      if ($config["log_type"] == 3) {
         $ct = 0;
         $file =   $config["directory"]
                 . $config["log_file"] . '.'
                 . $config["run_at"]
                 . sprintf("%03d", $ct)
                 . $ext;
         while (file_exists($file)) {
            $ct++;
            $file =   $config["directory"]
                    . $config["log_file"] . '.'
                    . $config["run_at"]
                    . sprintf("%03d", $ct)
                    . $ext;
         }
      }
      else $file = $config["directory"] . $config["log_file"] . $ext;

      $dzeLogHandle = fopen($file, "a");
      dzeLog("New page at: " . $config["run_at"] . "\n");
   }
}

function dzeLog($string, $level = 5) {
   global $config;
   global $dzeLogHandle;

   if (isset($config["log_level"]) && $level <= $config["log_level"]) {
      fwrite($dzeLogHandle, $string);
      fflush($dzeLogHandle);
   }
}

function getConfig($dir, $inFile, & $config, $setIndexPage = false) {
   $retValue = -1;
   $file = $dir . "/$inFile";

   if (file_exists($file))
      if (is_readable($file))
         if ($conDom = DOMDocument::load($file)) {
            $root = $conDom->getElementsByTagName('param');

            $query = new DOMXPath($conDom);
            #            $conPropNodeS = $root->childNodes();
            foreach ($query->query("/config/*") as $conPropNode) {
               $config[$conPropNode->nodeName] = $conPropNode->nodeValue;
            }

            if (   ! isset($config["directory"])
                || ! file_exists($config["directory"]))
               print "Error: dizzyPages configuration file '$file' parameter 'directory' is not set or the directory does not exist";
            else {
               $retValue = 0;
               if ($setIndexPage)
                  $config["indexPage"] = $_SERVER["SCRIPT_NAME"];
            }
         }
         else
            print "Error: dizzyPages configuration file '$file' is not an XML file or is poorly formed.";
      else
         print "Error: dizzyPages configuration file '$file' is not readable.";
   else
      print "Error: dizzyPages configuration file '$file' is not found.";

   if (!isset($config["run_at"]))
      $config["run_at"] = strftime('%Y%m%d%H%M%S');

   return $retValue;
}

function main() {
   global $config;
   $config = array();

   // TRICKY By default PHP sets HTML directives to turn page caching off

   // ignore_user_abort PHP specific command that causes the current script to
   // finish even if the user disconnects by hitting the browser stop button,
   // surfing to a different page before the current one completes, ...
   ignore_user_abort(true);

   $retValue = getConfig(dirname($_SERVER["SCRIPT_FILENAME"]),
                         "dze.xml", $config, true);
   if ($retValue != -1) getConfig($config["directory"],
                                  "config.xml", $config);

   if ($config['log_level'] > 1) setUpLogging($config);

   if ($retValue != -1) {
      include $config["directory"] . "/include/DzePage.class.php";
      include $config["directory"] . "/include/DzeForm.class.php";
      include $config["directory"] . "/include/DzeDomDoc.class.php";
      include $config["directory"] . "/include/DzeMySQL.class.php";

      $page = new DzePage($config);
   
      if (!is_null($page->getMember("urlBase")))
         $page->processPage();

      if ($page->getMember("loginApp") == 'dze' || $config['log_level'] >= 5)
         $page->createVpi();

      $page->close();
   }
}
main();
?>
Return current item: dizzyPages