<?php
$thisapp="PHProjekt";
$humanapp=str_replace("_", " ", $thisapp);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Fantastico</title>

<?php
if (is_file("/usr/local/cpanel/base/frontend/<cpanel print="$CPDATA{'RS'}">/fantasticoinc.php"))
	{
	include("/usr/local/cpanel/base/frontend/<cpanel print="$CPDATA{'RS'}">/fantasticoinc.php");
	}
	
if ($inxcontroller) {
?>
<cpanel include="../themeheader_subdir1.html">
<cpanel include="includes/mainmenu_icon_subdir.html">
<cpanel include="../themeheader_subdir2.html">
<cpanel include="includes/mainmenu_label.html">
<cpanel include="../themeheader_subdir3.html">

<?php
} else {
?>
<cpanel include="includes/fantasticoheader.html">

<?php
}
?>

<cpanel include="admin/adminuser.inc.php">
<cpanel include="admin/fantasticopath.inc.php">
<cpanel include="includes/adminsettingspath.inc.php">
<cpanel include="includes/restrictions.inc.php">
<cpanel include="includes/masterfilespath.inc.php">
<cpanel include="includes/sidemenu.php">
<cpanel include="includes/mysqlconfig.php">



<p class="TableMiddleHead">Install <?=$humanapp ?> (3/3)</p>

<cpanel Mysql="adddb($FORM{'thismakedb'})"> 
<cpanel Mysql="adduser($FORM{'thismakedb'},$FORM{'SQLPass'})">
<cpanel Mysql="adduserdb($FORM{'connect'},$FORM{'connect'})">

<?
$INSTALLDIR=$installdir;
$MYSQLUSER = $connect;
$MYSQLDB = $connect;
$MYSQLPASS = $SQLPass;
$USER = $REMOTE_USER;
$DOMAIN = "<cpanel print="DOMAIN">";
$USER_ROOT = "<cpanel print="$homedir">/public_html";
$SCRIPTPATH = $scriptpath;
$THISDEPOT = $DEPOT.$thisapp;
$SQLDATA = $SCRIPTPATH."/data.sql";
$ADMIN = $adminuser;
$ADMINPASS = crypt($password, $password);
$ADMINNAME = $adminname;
$ADMINSURNAME = $adminsurname;
$REMINDER = $reminder;
$PAUSE = $pause;
$FIRSTHOUR = $firsthour;
$LASTHOUR = $lasthour;
$RTSSUPPORT = $rtssupport;
$RTSEMAIL = $rtsemail;
$RTSALLOWED = $rtsallowed;
//-----------------------------------------

if (!(is_dir($userdata)))
	{
	mkdir($userdata) or die("<p><span class=Hint><b>ERROR!</b></span> Your base directory must have write permissions for user to proceed");
	}
if (!(is_dir($userdata."/".$thisapp))) 
	{
	mkdir($userdata."/".$thisapp) or die("<p><span class=Hint><b>ERROR!</b></span> Your base directory must have write permissions for user to proceed");
	}

$myprefs = fopen($userdata."/".$thisapp."/"."$INSTALLDIR","w");
$fp = fputs($myprefs,"<?");
$fp = fwrite($myprefs,"\n");
$fp = fwrite($myprefs,"\$thisdb = \"".$mysqldb."\"; ");
$fp = fwrite($myprefs,"\n");
$fp = fputs($myprefs,"?>");
fclose($myprefs);

mkdir($SCRIPTPATH);
	$shell="cp -rfp ". $THISDEPOT ."/* ". $SCRIPTPATH."/";
	system($shell);

$CONFIG_FILE[]=$SCRIPTPATH."/config.inc.php";
$CONFIG_FILE[]=$SQLDATA;

foreach($CONFIG_FILE AS $FILE){
	if(is_file($FILE)){
		echo "<b>".$FILE."</b> configured<br>";
		$fd = fopen ($FILE, "r");
		$contents = fread ($fd, filesize ($FILE));
		$contents = str_replace("<MYSQLHOST>", $MYSQLHOST, $contents);
		$contents = str_replace("<MYSQLUSER>", $MYSQLUSER, $contents);
		$contents = str_replace("<MYSQLDB>", $MYSQLDB, $contents);
		$contents = str_replace("<MYSQLPASS>", $MYSQLPASS, $contents);		
		$contents = str_replace("<USER>", $USER, $contents);
		$contents = str_replace("<DOMAIN>", $DOMAIN, $contents);
		$contents = str_replace("<ADMIN>", $ADMIN, $contents);
		$contents = str_replace("<ADMINPASS>", $ADMINPASS, $contents);
		$contents = str_replace("<ADMINNAME>", $ADMINNAME, $contents);
		$contents = str_replace("<ADMINSURNAME>", $ADMINSURNAME, $contents);
		$contents = str_replace("<REMINDER>", $REMINDER, $contents);
		$contents = str_replace("<PAUSE>", $PAUSE, $contents);
		$contents = str_replace("<FIRSTHOUR>", $FIRSTHOUR, $contents);
		$contents = str_replace("<LASTHOUR>", $LASTHOUR, $contents);
		$contents = str_replace("<RTSSUPPORT>", $RTSSUPPORT, $contents);
		$contents = str_replace("<RTSEMAIL>", $RTSEMAIL, $contents);
		$contents = str_replace("<RTSALLOWED>", $RTSALLOWED, $contents);
		$contents = str_replace("<SCRIPTPATH>", $SCRIPTPATH, $contents);
		$contents = str_replace("<INSTALLDIR>", $INSTALLDIR, $contents);

		fclose ($fd);
		$fd = fopen ($FILE, "w");
		fputs($fd, $contents);
		fclose($fd);
	}else{
echo ++$i.") File:<b> ".$FILE."</b> [<span class='Hint'><i>Error </i></span>]<br>";
	}
}
	$shellsqlimport=$MYSQLPATH. " -h" .$MYSQLHOST. " -u ". $MYSQLUSER ." -p". $MYSQLPASS." ".$MYSQLDB." < $SQLDATA";
	system($shellsqlimport);
?>

<p align="center"><b>Please notice:</b></p>
<p align="left">We only offer auto-installation and auto-configuration of <span class="Emphasize"><?=$humanapp ?></span> but do not offer any kind of support.</p>
<p align="left">The full URL to this installation of <span class="Emphasize"><?=$humanapp ?></span>: <a href="http://<?=$DOMAIN ?>/<?=$installdir ?>" target="blank">http://<?=$DOMAIN ?>/<?=$installdir ?></a>. </p>
<p align="left">Login with username <span class="Hint"><b><?=$ADMIN ?></b></span>, password <span class="Hint"><b><?=$password ?></b></span> to access the administration menu.</p>

<cpanel include="includes/fantasticofooter.html">
