Location: PHPKode > projects > dizzyPages > dizzypages/htdocs/dze_install.php
<?php
// The installation script may require more than the default 30 seconds
set_time_limit(0);
error_reporting(E_ERROR | E_WARNING);
ini_set('display_errors', 1);

// setup configuration
print "<HTML><HEAD></HEAD><BODY>";

/*
if (! extension_loaded("domxml")) {
   print "Error: your installation of PHP is missing the DOMXML extension.  DOMXML is required by dizzypages.  See trouble shooting section of the installation instructions ...<BR><BR>";
   print "The following information is supplied to assist you while trouble shooting.";
   phpinfo(INFO_GENERAL);
   cleanExit();
}
*/

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

$directoryS = array(
     $_SERVER["DOCUMENT_ROOT"] . "/dze/usr"
   , $config["directory"] . "/formprocess"
   , $config["directory"] . "/pageoutput"
);

foreach ($directoryS as $directory) {
   $newDir = $directory . "/tmp_" . gmstrftime("%Y%m%d%H%M%S");
   if (! mkdir($newDir, 0755)) {
      print "Error: the web server must have write privilege to the '$directory' directory ...";
      cleanExit();
   }
   else rmdir($newDir);
}
  
// establish an SQL connection
include $config["directory"] . "/include/DzeMySQL.class.php";
$sql = new DzeMySQL($config);

if (   ! extension_loaded("dom")
    && ! function_exists("xslt_process")) {
   print "Error: your PHP installion requires either the DOM XSLT features of the PHP DOM XML library (http://www.php.net/manual/en/ref.domxml.php) or the PHP XSLT library (http://www.php.net/manual/en/ref.xslt.php) installed ...";
   cleanExit();
}

if (isMySQLInnoDBAvailable() != "Y") {
   print "Error: your MySQL installation must have InnoDB table types setup and enabled (http://dev.mysql.com/doc/mysql/en/InnoDB.html) ...";
   cleanExit();
}

if (isPreviousInstall() == "Y") {
   print "dizzyPages is already installed ...<BR>";
   print   "To start building a dizzyPages application run the "
         . "<A HREF='/dze.php'>dizzyPages CASE tool</A>.";
   cleanExit();
}

$sql_ddl = array(
"
drop table IF EXISTS DZE_SESSION
",
"
drop table IF EXISTS DZE_USR_IN_APP
",
"
drop table IF EXISTS DZE_USR_FORM_ERR
",
"
drop table IF EXISTS DZE_USR_ATTRIB_ERR
",
"
drop table IF EXISTS DZE_ATTRIB_IN_FORM
",
"
drop table IF EXISTS DZE_SEQ
",
"
drop table IF EXISTS DZE_USR
",
"
drop table IF EXISTS DZE_USR_ATTRIB_ADT
",
"
drop table IF EXISTS DZE_USR_ATTRIB
",
"
drop table IF EXISTS DZE_ATTRIB_RULE
",
"
drop table IF EXISTS DZE_FORM_IN_PAGE
",
"
drop table IF EXISTS DZE_SLCT_OPTION
",
"
drop table IF EXISTS DZE_ATTRIB
",
"
drop table IF EXISTS DZE_FORM
",
"
drop table IF EXISTS DZE_PAGE
",


"
Create table DZE_PAGE (
	PAGE_URL Varchar(200) NOT NULL,
	TITLE Varchar(200) ,
	DESCRIP Varchar(200) ,
	STAND_ALONE_B Char(1) NOT NULL,
 Primary Key (PAGE_URL)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_FORM (
	FORM_NAME Varchar(100) NOT NULL,
	TYPE Char(1) NOT NULL,
	METHOD Varchar(4) NOT NULL,
	TITLE Varchar(200) ,
	ACTION_URL Varchar(200) ,
	TRAP_ON_ERR_TYPE Char(1) NOT NULL,
	R_SAVE_TYPE Char(1) ,
	R_AUDIT_TYPE Char(1) ,
	R_ITEMS_MIN Varchar(3) ,
	R_ITEMS_MAX Varchar(3) ,
	DESCRIP Varchar(200) ,
 Primary Key (FORM_NAME)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_ATTRIB (
	ATTRIB_NAME Varchar(100) NOT NULL,
	TYPE Char(1) NOT NULL,
	SAVE_TYPE Char(1) NOT NULL,
	AUDIT_TYPE Char(1) NOT NULL,
	REQUIRED_B Char(1) NOT NULL,
	FORM_LABEL Varchar(100) ,
	DFLT_VALUE Varchar(255),
	T_FORM_TYPE Char(1) ,
	T_FORM_LEN Varchar(4) ,
	T_FORM_LEN_MAX Varchar(4) ,
	T_AREA_FORM_ROWS Varchar(4) ,
	S_FORM_TYPE Char(1),
	S_FORM_COLS Varchar(4),
	S_FORM_ORDER_TYPE Char(1),
	S_SLCT_DYN_B Char(1) NOT NULL,
	M_SLCT_OPTION_MIN Varchar(4) ,
	M_SLCT_OPTION_MAX Varchar(4) ,
	P_ENCRYPT_B Char(1) NOT NULL,
	DESCRIP Varchar(200) ,
 Primary Key (ATTRIB_NAME)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_SLCT_OPTION (
	ATTRIB_NAME Varchar(100) NOT NULL,
	DISPLAY_ORDER Decimal(4,0) NOT NULL,
	VALUE Varchar(255) NOT NULL,
	FORM_LABEL Varchar(100) NOT NULL,
	DEFAULT_B Char(1) NOT NULL,
 Primary Key (ATTRIB_NAME,DISPLAY_ORDER)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_FORM_IN_PAGE (
	PAGE_URL Varchar(200) NOT NULL,
	FORM_NAME Varchar(100) NOT NULL,
	DISPLAY_ORDER Decimal(4,0) NOT NULL,
 Primary Key (PAGE_URL,FORM_NAME)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_ATTRIB_RULE (
	ATTRIB_NAME Varchar(100) NOT NULL,
	FIRE_ORDER Decimal(2,0) NOT NULL,
	RULE Varchar(255) NOT NULL,
	RULE_TYPE Char(1) NOT NULL,
	ERR_TXT Varchar(255) ,
 Primary Key (ATTRIB_NAME,FIRE_ORDER)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_USR_ATTRIB (
	USR_ID Decimal(10,0) NOT NULL,
	ATTRIB_NAME Varchar(100) NOT NULL,
	REC_ID Decimal(4,0) NOT NULL,
	VALUE Varchar(255) NOT NULL,
	SET_TS Varchar(23) NOT NULL,
 Primary Key (USR_ID,ATTRIB_NAME,REC_ID)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_USR_ATTRIB_ADT (
	USR_ID Decimal(10,0) NOT NULL,
	ATTRIB_NAME Varchar(100) NOT NULL,
	REC_ID Decimal(4,0) NOT NULL,
	CREATE_TS Varchar(23) NOT NULL,
	VALUE Varchar(255) NOT NULL,
 Primary Key (USR_ID,ATTRIB_NAME,REC_ID,CREATE_TS)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_USR (
	USR_ID Decimal(10,0) NOT NULL,
	LWR_CASE_NAME Varchar(20) NOT NULL,
	NAME Varchar(20) NOT NULL,
	IS_APP_B Char(1) NOT NULL,
	UNIQUE (LWR_CASE_NAME),
 Primary Key (USR_ID)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_SEQ (
	SEQ_NAME Varchar(60) NOT NULL,
	VALUE Decimal(10,0) NOT NULL,
	FIRST_VALUE Decimal(10,0),
	LAST_VALUE Decimal(10,0),
 Primary Key (SEQ_NAME)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_ATTRIB_IN_FORM (
	FORM_NAME Varchar(100) NOT NULL,
	ATTRIB_NAME Varchar(100) NOT NULL,
	DISPLAY_ORDER Decimal(4,0) NOT NULL,
 Primary Key (FORM_NAME,ATTRIB_NAME)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_USR_ATTRIB_ERR (
	USR_ID Decimal(10,0) NOT NULL,
	ATTRIB_NAME Varchar(100) NOT NULL,
	REC_ID Decimal(4,0) NOT NULL,
	ERR_TXT Varchar(255) ,
 Primary Key (USR_ID,ATTRIB_NAME,REC_ID)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_USR_FORM_ERR (
	USR_ID Decimal(10,0) NOT NULL,
	FORM_NAME Varchar(100) NOT NULL,
	REC_ID Decimal(4,0) NOT NULL,
	ERR_TXT Varchar(255) ,
 Primary Key (USR_ID,FORM_NAME,REC_ID)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_USR_IN_APP (
	APP_ID Decimal(10,0) NOT NULL,
	USR_ID Decimal(10,0) NOT NULL,
 Primary Key (APP_ID,USR_ID)) TYPE = InnoDB
ROW_FORMAT = Default
",
"
Create table DZE_SESSION (
	SESSION_ID Varchar(100) NOT NULL,
	SESSION_USR_ID Decimal(10,0) NOT NULL,
	REGISTER_USR_ID Decimal(10,0),
   LAST_HIT_TS Char(23) NOT NULL,
	TIME_OUT_AT_TS Char(19) NOT NULL,
	LAST_PAGE_URL Varchar(200) NOT NULL,
	UNIQUE (SESSION_ID),
 Primary Key (SESSION_ID)) TYPE = InnoDB
ROW_FORMAT = Default
",


"
Create Index IX1_DZE_FORM_IN_PAGE  ON DZE_FORM_IN_PAGE (FORM_NAME)
",
"
Create Index IX1_DZE_USR_ATTRIB  ON DZE_USR_ATTRIB (ATTRIB_NAME)
",
"
Create Index IX1_DZE_USR_ATTRIB_ADT  ON DZE_USR_ATTRIB_ADT (ATTRIB_NAME)
",
"
Create Index IX1_DZE_ATTRIB_IN_FORM  ON DZE_ATTRIB_IN_FORM (ATTRIB_NAME)
",
"
Create Index IX1_DZE_FORM  ON DZE_FORM (ACTION_URL)
",
"
Create Index IX1_DZE_USR_ATTRIB_ERR  ON DZE_USR_ATTRIB_ERR (ATTRIB_NAME)
",
"
Create Index IX1_DZE_USR_FORM_ERR  ON DZE_USR_FORM_ERR (FORM_NAME)
",
"
Create Index IX1_DZE_SESSION  ON DZE_SESSION (SESSION_USR_ID)
",
"
Create Index IX2_DZE_SESSION  ON DZE_SESSION (REGISTER_USR_ID)
",

"
Alter table DZE_FORM_IN_PAGE add Foreign Key (PAGE_URL) references DZE_PAGE (PAGE_URL) on delete no action on update no action
",
"
Alter table DZE_FORM_IN_PAGE add Foreign Key (FORM_NAME) references DZE_FORM (FORM_NAME) on delete no action on update no action
",
"
Alter table DZE_ATTRIB_IN_FORM add Foreign Key (FORM_NAME) references DZE_FORM (FORM_NAME) on delete no action on update no action
",
"
Alter table DZE_USR_FORM_ERR add Foreign Key (FORM_NAME) references DZE_FORM (FORM_NAME) on delete no action on update no action
",
"
Alter table DZE_SLCT_OPTION add Foreign Key (ATTRIB_NAME) references DZE_ATTRIB (ATTRIB_NAME) on delete no action on update no action
",
"
Alter table DZE_USR_ATTRIB add Foreign Key (ATTRIB_NAME) references DZE_ATTRIB (ATTRIB_NAME) on delete no action on update no action
",
"
Alter table DZE_ATTRIB_RULE add Foreign Key (ATTRIB_NAME) references DZE_ATTRIB (ATTRIB_NAME) on delete no action on update no action
",
"
Alter table DZE_USR_ATTRIB_ADT add Foreign Key (ATTRIB_NAME) references DZE_ATTRIB (ATTRIB_NAME) on delete no action on update no action
",
"
Alter table DZE_ATTRIB_IN_FORM add Foreign Key (ATTRIB_NAME) references DZE_ATTRIB (ATTRIB_NAME) on delete no action on update no action
",
"
Alter table DZE_USR_ATTRIB_ERR add Foreign Key (ATTRIB_NAME) references DZE_ATTRIB (ATTRIB_NAME) on delete no action on update no action
",
"
Alter table DZE_USR_ATTRIB add Foreign Key (USR_ID) references DZE_USR (USR_ID) on delete no action on update no action
",
"
Alter table DZE_USR_ATTRIB_ADT add Foreign Key (USR_ID) references DZE_USR (USR_ID) on delete no action on update no action
",
"
Alter table DZE_USR_ATTRIB_ERR add Foreign Key (USR_ID) references DZE_USR (USR_ID) on delete no action on update no action
",
"
Alter table DZE_USR_FORM_ERR add Foreign Key (USR_ID) references DZE_USR (USR_ID) on delete no action on update no action
",
"
Alter table DZE_USR_IN_APP add Foreign Key (APP_ID) references DZE_USR (USR_ID) on delete no action on update no action
",
"
Alter table DZE_SESSION add Foreign Key (SESSION_USR_ID) references DZE_USR (USR_ID) on delete no action on update no action
",
"
Alter table DZE_SESSION add Foreign Key (REGISTER_USR_ID) references DZE_USR (USR_ID) on delete no action on update no action
"
);

print "Building dizzyPages database schema ...<BR>";
foreach($sql_ddl as $query){
    $sql->query($query);
}

$pageTs = gmstrftime("%Y-%m-%d %H:%M:%S") . ".000";
$password = sha1($pageTs . rand());

$sql->beginWork();

print "Populating dizzyPages database ...<BR>";
include $config["directory"] . "/include/install/casetool.inc.php";

$sql->insert("DZE_USR", array(
   "USR_ID"        => "1000001",
   "NAME"          => "dze",
   "LWR_CASE_NAME" => "dze",
   "IS_APP_B"      => "Y"
));

$sql->insert("DZE_USR_IN_APP", array(
   "APP_ID" => "1000001",
   "USR_ID" => "1000001"
));

$sql->insert("DZE_USR_ATTRIB", array(
   "USR_ID"      => "1000001",
   "ATTRIB_NAME" => "common-UserLoginPassword",
   "REC_ID"      => "1",
   "VALUE"       => $password,
   "SET_TS"      => $pageTs
));

$sql->insert("DZE_USR_ATTRIB", array(
   "USR_ID"      => "1000001",
   "ATTRIB_NAME" => "common-ApplicationTitle",
   "REC_ID"      => "1",
   "VALUE"       => "dizzyPages CASE Tool",
   "SET_TS"      => $pageTs
));

$sql->insert("DZE_USR", array(
   "USR_ID"        => "1000002",
   "NAME"          => "common",
   "LWR_CASE_NAME" => "common",
   "IS_APP_B"      => "Y"
));

$sql->insert("DZE_USR_IN_APP", array(
   "APP_ID" => "1000001",
   "USR_ID" => "1000002"
));

$sql->insert("DZE_USR_IN_APP", array(
   "APP_ID" => "1000002",
   "USR_ID" => "1000002"
));

$sql->insert("DZE_USR_ATTRIB", array(
   "USR_ID"      => "1000002",
   "ATTRIB_NAME" => "common-UserLoginPassword",
   "REC_ID"      => "1",
   "VALUE"       => $password,
   "SET_TS"      => $pageTs
));

$sql->insert("DZE_USR_ATTRIB", array(
   "USR_ID"      => "1000002",
   "ATTRIB_NAME" => "common-ApplicationTitle",
   "REC_ID"      => "1",
   "VALUE"       => "dizzyPages Common",
   "SET_TS"      => $pageTs
));

$sql->insert("DZE_SEQ", array(
   "SEQ_NAME" => "DZE-USR_ID",
   "VALUE"    => "1000003"
));

$sql->insert("DZE_SEQ", array(
   "SEQ_NAME"    => "DZE-SESSION_ID",
   "VALUE"       => "10001",
   "FIRST_VALUE" => "10001",
   "LAST_VALUE"  => "20000"
));

for ($i = 10001; $i <= 20000; $i++) {
   $sql->insert("DZE_USR", array(
      "USR_ID"        => $i,
      "NAME"          => "common-SES-" . sprintf("%06d", $i),
      "LWR_CASE_NAME" => "common-ses-" . sprintf("%06d", $i),
      "IS_APP_B"      => "N"
   ));
}

// set install to finished
$sql->insert("DZE_USR_ATTRIB", array(
   "USR_ID"      => "1000001",
   "ATTRIB_NAME" => "dze-INSTALL-STATE",
   "REC_ID"      => "1",
   "VALUE"       => "F",
   "SET_TS"      => $pageTs
));

print "dizzyPages installation completed ...<BR>";
print   "To start building a dizzyPages application run the "
      . "<A HREF='/dze.php'>dizzyPages CASE tool</A>.";

cleanExit();

function cleanExit() {
   global $sql;

   if ($sql) {
      $sql->commitWork();
      $sql->closeDB();
   }
   print "<BODY><HTNL>";
   exit;
}

function isPreviousInstall() {
   global $sql;
   $retValue = 'N';

   $sql->query("show table status");
   while ($statusRow = $sql->fetchAssoc())
      if (strtoupper($statusRow["Name"]) == "DZE_USR_ATTRIB") {
         $sql->select(  "DZE_USR_ATTRIB"
                      , array("VALUE")
                      , array(
                             "USR_ID"      => "1000001"
                           , "ATTRIB_NAME" => "dze-INSTALL-STATE"
                           , "REC_ID"      => "1"
                        )
         );

         $installState = $sql->fetchAssoc();
         if ($installState["VALUE"] && $installState["VALUE"] == "F")
            $retValue = "Y";
         break;
      }

   return $retValue;
}

function isMySQLInnoDBAvailable() {
   global $sql;

   $sql->query("drop table IF EXISTS DZE_CHECK_INNODB");
   $sql->query("create table DZE_CHECK_INNODB (col1 char(1)) type=innodb");
   $sql->query("show table status");
   while ($statusRow = $sql->fetchAssoc())
      if (strtoupper($statusRow["Name"]) == "DZE_CHECK_INNODB") break;
   $sql->query("drop table DZE_CHECK_INNODB");
   if (strtoupper($statusRow["Type"]) == "INNODB") return "Y";
   else return "N";
}

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);
            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.";

   return $retValue;
}
?>
Return current item: dizzyPages