Location: PHPKode > projects > Merchant Empires > merchempires/php/local.inc
<?php
/*
 * Session Management for PHP3
 *
 * Copyright (c) 1998-2000 NetUSE AG
 *                    Boris Erdmann, Kristian Koehntopp
 *
 * $Id: local.inc,v 1.3 2000/07/12 18:25:43 kk Exp $
 *
 */

class ME_DB extends DB_Sql {
  var $Host     = "192.168.1.2";
  var $Database = "spacegame";
  var $User     = "postgres";
  var $Password = "post22";
}

class doc_reader {
  var $string = "";
  var $type = "";
  var $bignum = 1000000;
  var $uri = "";

  function doc_reader($uri) {
    $this->set_uri($uri);
    $this->set_type();

    $fp = fopen($this->get_uri(),"r");

    if($fp) {
      if ($this->get_type() == 'file') {
        $length = filesize($this->get_uri());
      } else {
        $length = $this->bignum;
      }

      $this->set_string(fread($fp,$length));
      return 1;
    } else {
      return 0;
    }
  }

  function is_file($uri) {
    if (strstr($uri,'http://') == $uri) {
      return false;
    } else {
      return true;
    }
  }

  function set_uri($string) {
    $this->uri = $string;
  }

  function get_uri() {
    return $this->uri;
  }

  function set_string($string) {
    $this->string = $string;
  }

  function get_string() {
    return $this->string;
  }

  function set_type() {
    if ($this->is_file($this->uri)) {
      $this->type = 'file';
    } else {
      $this->type = 'url';
    }
  }

  function get_type() {
    return $this->type;
  }
}

class ME_DB_Xml extends DB_Sql {
  var $Host     = "192.168.1.2";
  var $Database = "spacegame";
  var $User     = "postgres";
  var $Password = "post22";

  var $xsl = "";
  var $xml = "";
  var $xml_initialized = 0;
  var $output = "";
  var $params = array();

  function set_output($string) {
    $this->output = $string;
  }

  function get_output() {
    return $this->output;
  }

  function set_xml($uri) {
    if ( $uri[0] == "<" ) {
      $this->xml = $uri;
      return true;
    } elseif ( $uri == "" ) {
      $this->xml = '<?xml version="1.0" encoding="ISO-8859-1"?><result><row></row></result>';
      return true;
    } else {
      if($doc = new doc_reader($uri)) {
        $this->xml = $doc->get_string();
        return true;
      } else {
        $this->set_error("Could not open $uri");
        return false;
      }
    }
  }

  function set_xsl($uri) {
    if ( $uri[0] == "<" ) {
      $this->xsl = $uri;
      return true;
    } else {
      if($doc = new doc_reader($uri)) {
        $this->xsl = $doc->get_string();
        return true;
      } else {
        $this->set_error("Could not open $uri");
        return false;
      }
    }
  }

  function add_parameter($name, $value) {
    $this->params[$name] = $value;
  }

  function transform() {
    if ( count($this->params) ) {
      $buffers = array("result" => $result, "template" => $this->xsl, "data" => $this->xml);
      xslt_transform("arg:/template", "arg:/data", "arg:/result", $this->params, $buffers, $result);
    } else {
      xslt_process($this->xsl, $this->xml, $result);
    }

    $this->set_output($result);
  }

  function get_transform($xsl, $xml) {
    $this->set_xsl($xsl);
    $this->set_xml($xml);
    $this->transform();
    return $this->get_output();
  }

  function set_error($string) {
    $this->error = $string;
  }

  function get_error() {
    return $this->error;
  }

  function xml_encode($text) {
    $str = $text;

    $str = str_replace("&", "&amp;", $str);
    $str = str_replace("<", "&lt;", $str);
    $str = str_replace(">", "&gt;", $str);
    $str = str_replace('"', "&quot;", $str);
    $str = str_replace("'", "&apos;", $str);

    return $str;
  }

  function alter_dom() {

  }

  function get_result_xml() {
    $this->xml = "";

    $this->xml = $this->xml . '<?xml version="1.0" encoding="ISO-8859-1"?>';
    $this->xml = $this->xml . '<result>';

    for ($index = 0; $index < pg_numrows($this->Query_ID); $index++)
    {
      $this->xml = $this->xml . '<row>';

      $this->Record = @pg_fetch_array($this->Query_ID, $index, 1);

      while (list($key, $val) = each($this->Record)) {
        $this->xml = $this->xml . '<' . $key . '>' . $this->xml_encode($val) . '</' . $key . '>';
      }

      $this->alter_dom();
      $this->xml = $this->xml . '</row>';
    }

    $this->xml = $this->xml . '</result>';

    return $this->xml;
  }

  function get_simple_xml() {
    return $this->xml;
  }

  function get_xml() {
    if ( !$this->xml_initialized ) {
      $this->xml = $this->get_result_xml();
      $this->xml_initialized = 1;
    }

    return $this->xml;
  }
}

class ME_DB_Tran extends XDB_Sql {
  var $Host     = "192.168.1.2";
  var $Database = "spacegame";
  var $User     = "postgres";
  var $Password = "post22";
}

class ME_CT_Sql extends CT_Sql {
  var $database_class = "ME_DB";          ## Which database to connect...
  var $database_table = "active_sessions"; ## and find our session data in this table.
}

class ME_Session_Cached extends Session {
  var $classname = "ME_Session_Cached";

  var $cookiename     = "";                ## defaults to classname
  var $magic          = "Hocuspocus";      ## ID seed
  var $mode           = "cookie";          ## We propagate session IDs with cookies
  var $fallback_mode  = "";
  var $lifetime       = 0;                 ## 0 = do session cookies, else minutes
  var $that_class     = "ME_CT_Sql"; ## name of data storage container
  var $gc_probability = 2;
  var $allowcache      = "private";
}


class ME_Session_Uncached extends ME_Session_Cached {
  var $classname = "ME_Session_Uncached";

  var $allowcache     = "no";
}

class ME_User extends User {
  var $classname = "ME_User";

  var $magic          = "Abracadabra";     ## ID seed
  var $that_class     = "ME_CT_Sql"; ## data storage container
}


class ME_Auth extends Auth {
  var $classname      = "ME_Auth";

  var $lifetime       =  25;

  var $database_class = "ME_DB";
  var $database_table = "auth_user";

  function auth_loginform() {
    global $sess;
    global $_PHPLIB;

    include($_PHPLIB["libdir"] . "/var/www/html/merchantempires/login.php");
  }

  function auth_validatelogin() {
    global $username, $password;

    if(isset($username)) {
      $this->auth["uname"]=$username;        ## This provides access for "loginform.ihtml"
    }


    $uid = false;

    $this->db->query(sprintf("select user_id, perms ".
                             "        from %s ".
                             "       where username = '%s' ".
                             "         and password = '%s'",
                          $this->database_table,
                          $username,
                          $password));

    while($this->db->next_record()) {
      $uid = $this->db->f("user_id");
      $this->auth["perm"] = $this->db->f("perms");
    }
    return $uid;
  }
}

?>
Return current item: Merchant Empires