Location: PHPKode > projects > WebMachinek > WMinst-0.62/i4.php
<html><head>
<title>WebMachinek Installation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Author" content="Kolda" />
<meta name="Description" content="no" />
<meta name="Keywords" content="no" />
<link type="text/css" rel="StyleSheet" href="wm.css" />
</head>
<body>
<table border="2" align="center">
<tr><td>
<table>
<tr><td colspan="2">
<p><center><h1>WebMachinek INSTALLATION: Step 4</h1>
</center></p>
<?php
if (!is_dir ($a_path)){
echo("<h1>ADMINISTRATIVE Directory '$a_path' does not exist.</h1>");
$exit = "t";
}
if (!is_dir ($p_path)){
echo("<h1>PUBLIC Directory '$p_path' does not exist.</h1>");
$exit = "t";
}
if (isset($exit)) {
echo("<h3>CREATE REQUIRED DIRECTORIES AND TRY IT AGAIN
<script>
setTimeout('history.back()','7000')
</script></h3></td></tr></table></td></tr></table>");
exit;
}

$conn = pg_connect("dbname=template1 user=$dbuser password=$dbpasswd port=5432");
pg_exec($conn, "CREATE DATABASE $dbname");
pg_close($conn);

$conn = pg_connect("dbname=$dbname user=$dbuser password=$dbpasswd port=5432");
pg_exec($conn, 'CREATE TABLE "category" (
           "dir" text NOT NULL,
           "pos" int4 DEFAULT 0);');
pg_exec($conn, 'CREATE TABLE "page" (
           "file" text NOT NULL, 
           "dir" text NOT NULL,
           "page_pos" int4 DEFAULT 1 NOT NULL,
           "created" timestamp DEFAULT now(),
           "modified" timestamp DEFAULT now() NOT NULL,
           "child" bool DEFAULT bool \'f\',
           "visible" bool DEFAULT bool \'t\');');
pg_exec($conn, 'CREATE TABLE "page_descr" (
           "file" text NOT NULL,
           "dir" text NOT NULL,
           "nav" text NOT NULL,
           "title" text,
           "descr" text,
           "keyword" text);');
pg_exec($conn, 'CREATE TABLE "page_layout" (
           "file" text NOT NULL,
           "dir" text NOT NULL,
           "layout" text DEFAULT \'default\' NOT NULL);');
pg_exec($conn, "INSERT INTO category (dir, pos)
	 VALUES ('main', '1');");
pg_exec($conn, "INSERT INTO page (file, dir, page_pos)
	 VALUES ('index', 'main', '0');");
pg_exec($conn, "INSERT INTO page_descr (file,dir,nav,title,descr,keyword)
	 VALUES ('index','main','WM Installed','WebMachinek','no', 'no');");
pg_exec($conn, "INSERT INTO page_layout (file, dir)
	 VALUES ('index', 'main');");
	 
$font = "$p_path/.sys/frankgob.ttf"; #FONT
$R = "0"; $G = "0"; $B = "128"; #COLOR

exec("mkdir $p_path/.sys");
exec("mkdir $p_path/.img");
exec("mkdir $a_path/.repos");
exec("cp ./* $p_path/.sys");
exec("cp ./.* $p_path/.sys");
pg_close($conn);

$confsource = "<?php\n".
	'$public = "'.$p_path."\";\n".
	'$admin = "'.$a_path."\";\n".
	'$urlpublic = "'.$p_url."\";\n".
	'$urladmin = "'.$a_url."\";\n\n".
	'$dbuser = "'.$dbuser."\";\n".
	'$dbase = "'.$dbname."\";\n\n".
	'$font = "'.$font."\";\n".
	'$R = "'.$R."\";\n".
	'$G = "'.$G."\";\n".
	'$B = "'.$B."\";\n".
	"php?>";

$fp = fopen("$p_path/.sys/.conf.php", "w+");
fwrite($fp, $confsource);
fclose($fp);

$public = $p_path;
$admin = $a_path;
$dbase = $dbname;

$destroysource = "<?php\n".
	'$public = "'.$public."\";\n".
	'$admin = "'.$admin."\";\n".
	'$urlpublic = "'.$urlpublic."\";\n".
	'$urladmin = "'.$urladmin."\";\n\n".
	'$dbuser = "'.$dbuser."\";\n".
	'$dbase = "'.$dbase."\";\n\n".
	'$conn = pg_connect("dbname=template1 user=$dbuser password=$dbpasswd port=5432");'."\n".
	'pg_exec($conn, "DROP DATABASE $dbase");'."\n".
	'pg_close($conn);'."\n".
	'exec("rm -R $public/*");'."\n".
	'exec("rm -R $admin/*");'."\n".
	'exec("rm -R $public/.*");'."\n".
	'exec("rm -R $admin/.*");'."\n".
	'echo "Installation erased";'."\n".
	"php?>";

$fp = fopen("$public/.sys/.DESTROY.php", "w+");
fwrite($fp, $destroysource);
fclose($fp);

require('.dynimage.php');

################# QUERY FOR DATA IN POSTGRESQL
$conn = pg_connect("dbname=$dbname user=$dbuser port=5432");
$prikaz1 = "SELECT page_descr.dir, page_descr.file, page_descr.title, page.child FROM page_descr, page WHERE page_descr.dir=page.dir AND page_descr.file=page.file ORDER BY dir";
$dotaz1 = pg_exec($conn, $prikaz1);
$pocetSouboru = pg_numrows($dotaz1);
#  echo $pocetSouboru;
for ($i = 0; $i < $pocetSouboru; $i++) {
    $radek = pg_fetch_array($dotaz1, $i);
    $path[$i] = "$public/$radek[0]/$radek[1]";
    $pathloc[$i] = "$admin/$radek[0]/$radek[1]";
    $repos[$i] = "$admin/.repos/$radek[0]/$radek[1]";
    $title[$i] = $radek[2];
    $child[$i] = $radek[3];
    $file[$i] = $radek[1];
    $dir[$i] = $radek[0];

    $phpsource[$i] = "<?php\nrequire('$public/.sys/.conf.php');\n".'$file = "'."$radek[1]\";\n".'$dir = "'."$radek[0]\";\n\$child = '$radek[3]';\n\$edit = 'f';"."\nrequire('$public/.sys/wm.php');\n".'php?>';

    $phpsourceloc[$i] = "<?php\nrequire('$public/.sys/.conf.php');\n".'$file = "'."$radek[1]\";\n".'$dir = "'."$radek[0]\";\n\$child = '$radek[3]';\n\$edit = 't';"."\nrequire('$public/.sys/wm.php');\n".'php?>';
    
}

pg_close($conn);

############# CHECK FOLDERS, WRITING FOLDERS AND FILES!

$index = "index";

##PUBLIC
for ($i = 0; $i < $pocetSouboru; $i++) {
$directory = dirname($path[$i]);

$slash = strstr($dir[$i], "/");

if ($slash == ""){ 	###1 WRITING PAGES NOT IN SUBCATEGORY

if (is_dir($directory)) {	###1.1 CATEGORY WITH EXISTING FOLDER
	if ($file[$i] == $index) { #1.1.1 MAIN PAGE
		$fp = fopen("$path[$i].php", "w+");
		fwrite($fp, $phpsource[$i]);
		fclose($fp);
		dynimage($title[$i], "$path[$i]_img.php");
		}
	elseif  (is_dir($path[$i])){ #1.1.2  PAGE WITH EXISTING FOLDER
		$indexpath = "$path[$i]/index.php";
		$fp = fopen($indexpath, "w+");
		fwrite($fp, $phpsource[$i]);
		fclose($fp);
		dynimage($title[$i], "$path[$i]/$file[$i]_img.php");
		}
	else { #1.1.3  PAGE WITHOUT FOLDER
		mkdir ($path[$i], 0755);
		$indexpath = "$path[$i]/index.php";
		$fp = fopen($indexpath, "w+");
		fwrite($fp, $phpsource[$i]);
		fclose($fp);
		dynimage($title[$i], "$path[$i]/$file[$i]_img.php");
		}

} else {				###1.2  NO FOLDER FOR CATEGORY
	mkdir ($directory, 0755);
	if ($file[$i] == $index) { 	#1.2.1 MAIN PAGE
		$fp = fopen("$path[$i].php", "w+");
		fwrite($fp, $phpsource[$i]);
		fclose($fp);
		dynimage($title[$i], "$path[$i]_img.php");
		}
	else { 				#1.2.2 PAGE WITHOUT FOLDER
		mkdir ($path[$i], 0755);
		$fp = fopen("$path[$i]/index.php", "w+");
		fwrite($fp, $phpsource[$i]);
		fclose($fp);
		dynimage($title[$i], "$path[$i]/$file[$i]_img.php");
		}
}
} else {			###2 WRITING FILES IN SUBCATEGORIES (WORK BECAUSE QUERY IS ORDER BY dir)
	$fp = fopen("$path[$i].php", "w+");
	fwrite($fp, $phpsource[$i]);
	fclose($fp);
	dynimage($title[$i], "$path[$i]_img.php");
	}
}

##LOCAL
for ($i = 0; $i < $pocetSouboru; $i++) {
$directory = dirname($pathloc[$i]);
$slash = strstr($dir[$i], "/");

if ($slash == ""){ 	###1 WRITING FILES OUT OF ANY SUBCATEGORY

if (is_dir($directory)) {	###1.1 CATEGORY WITH EXISTING FOLDER
	if ($file[$i] == $index) { #1.1.1 MAIN PAGE
		$fp = fopen("$pathloc[$i].php", "w+");
		fwrite($fp, $phpsourceloc[$i]);
		fclose($fp);
		dynimage($title[$i], "$pathloc[$i]_img.php");
		}
	elseif  (is_dir($pathloc[$i])){ #1.1.2  PAGE WITH EXISTING FOLDER
		$indexpath = "$pathloc[$i]/index.php";
		$fp = fopen($indexpath, "w+");
		fwrite($fp, $phpsourceloc[$i]);
		fclose($fp);
		dynimage($title[$i], "$pathloc[$i]/$file[$i]_img.php");
		}
	else { #1.1.3  PAGE WITHOUT FOLDER
		mkdir ($pathloc[$i], 0755);
		$indexpath = "$pathloc[$i]/index.php";
		$fp = fopen($indexpath, "w+");
		fwrite($fp, $phpsourceloc[$i]);
		fclose($fp);
		dynimage($title[$i], "$pathloc[$i]/$file[$i]_img.php");
		}

} else {				###1.2  NO FOLDER FOR CATEGORY
	mkdir ($directory, 0755);
	if ($file[$i] == $index) { 	#1.2.1 MAIN PAGE
		$fp = fopen("$pathloc[$i].php", "w+");
		fwrite($fp, $phpsourceloc[$i]);
		fclose($fp);
		dynimage($title[$i], "$pathloc[$i]_img.php");
		}
	else { 				#1.2.2 PAGE WITHOUT FOLDER
		mkdir ($pathloc[$i], 0755);
		$fp = fopen("$pathloc[$i]/index.php", "w+");
		fwrite($fp, $phpsourceloc[$i]);
		fclose($fp);
		dynimage($title[$i], "$pathloc[$i]/$file[$i]_img.php");
		}
}
} else {			###2 WRITING FILES IN SUBCATEGORIES (WORK BECAUSE QUERY IS ORDER BY dir)
	$fp = fopen("$pathloc[$i].php", "w+");
	fwrite($fp, $phpsourceloc[$i]);
	fclose($fp);
	dynimage($title[$i], "$pathloc[$i]_img.php");
	}

$dirr = dirname($repos[$i]); ##WORK ALSO FOR SUBDIRS BECAUSE QUERY IS ORDER BY dir
$empty = "";

if (is_dir($dirr)) {
$fp = fopen("$repos[$i].xml", "w+");
fwrite($fp, $empty);
fclose($fp);
} else {
mkdir($dirr, 0755);
$fp = fopen("$repos[$i].xml", "w+");
fwrite($fp, $empty);
fclose($fp);
}
}

symlink("$public/.img", "$admin/main/.img");
symlink("$public/.img", "$public/main/.img");

#echo('<script LANGUAGE="JavaScript1.1" type="text/javascript">');
#echo("document.location=\"$a_url/main/index.php\";\n");
#echo("</script>");
echo"If there are no errors or warnings mentioned above the instalation is finished.<br />";
echo"<h4>WebMachinek has been <a href=\"$a_url/main/index.php\">INSTALLED HERE</h4></a>";
php?>
   </td></tr>
  </table>
 </td></tr>
</table>
</body></html>
Return current item: WebMachinek