352 lines
12 KiB
PHP

<?php
namespace Objectify\Modules;
use WebFX\Controls\ButtonGroup;
use WebFX\Controls\ButtonGroupButton;
use WebFX\Controls\ButtonGroupButtonAlignment;
use WebFX\Controls\Panel;
use Objectify\Objects\Tenant;
use Objectify\Objects\User;
use Objectify\Objects\UserProfileVisibility;
use Objectify\Objects\UserPresenceStatus;
use WebFX\System;
use WebFX\Module;
use WebFX\ModulePage;
use DataFX\DataFX;
use DataFX\Table;
use DataFX\Column;
use DataFX\ColumnValue;
use DataFX\Record;
use DataFX\RecordColumn;
use WebFX\WebPage;
use Objectify\Pages\ErrorPage;
System::$Modules[] = new Module("net.objectify.Setup", array
(
new ModulePage("setup", function($path)
{
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
function Success($taskname)
{
?>
<tr>
<td style="background-color: #AAFFAA;"><?php echo($taskname); ?></td>
</tr>
<?php
}
function Message($taskname)
{
?>
<tr>
<td style="background-color: #AACCFF;"><?php echo($taskname); ?></td>
</tr>
<?php
}
function Failure($taskname)
{
?>
<tr>
<td style="background-color: #FFAAAA;"><?php echo($taskname); ?></td>
</tr>
<?php
}
function VariableToString($value)
{
if (is_string($value))
{
return "\"" . $value . "\"";
}
return $value;
}
function SaveConfiguration()
{
global $RootPath;
$FileName = $RootPath . "/Include/Configuration.inc.php";
$f = fopen($FileName, "w");
Message("Configuration file path is<br />" . $FileName);
if ($f === false) return false;
fwrite($f, "<?php\n");
fwrite($f, "\tuse WebFX\\System;\n");
fwrite($f, "\n");
fwrite($f, "\t// Whether we should enable users to run the setup application\n");
fwrite($f, "\tSystem::\$Configuration[\"Setup.Enabled\"] = false;\n");
fwrite($f, "\n");
fwrite($f, "\t// The base path of the Web site\n");
fwrite($f, "\tSystem::\$Configuration[\"Application.BasePath\"] = \"" . System::$Configuration["Application.BasePath"] . "\";\n");
fwrite($f, "\n");
fwrite($f, "\t// The default tenant for the Web site\n");
fwrite($f, "\tSystem::\$Configuration[\"Application.DefaultTenant\"] = \"" . $_POST["Application_DefaultTenant"] . "\";\n");
fwrite($f, "\n");
fwrite($f, "\t// Administration credentials for Tenant Manager\n");
fwrite($f, "\tSystem::\$Configuration[\"Administration.UserName\"] = \"" . $_POST["TenantManager_UserName"] . "\";\n");
fwrite($f, "\tSystem::\$Configuration[\"Administration.Password\"] = \"" . $_POST["TenantManager_Password"] . "\";\n");
fwrite($f, "\n");
fwrite($f, "\t// The location of static WebFramework-related files (scripts, stylesheets, etc.)\n");
fwrite($f, "\tSystem::\$Configuration[\"WebFramework.StaticPath\"] = \"" . System::$Configuration["WebFramework.StaticPath"] . "\";\n");
fwrite($f, "\n");
fwrite($f, "\n");
fwrite($f, "\t// *** GENERATED BY " . System::$Configuration["Application.Name"] . " SETUP APPLICATION - DO NOT EDIT BELOW THIS LINE ***\n");
$preinstalledKeys = array("Setup.Enabled", "Application.BasePath", "WebFramework.StaticPath", "Account.LoginPath", "Account.RegisterPath", "Account.ResetPasswordPath", "Application.DefaultTenant", "AdministratorUserName", "AdministratorPassword");
foreach (System::$Configuration as $key => $value)
{
$skip = false;
foreach ($preinstalledKeys as $pikey)
{
if ($key == $pikey)
{
$skip = true;
break;
}
}
if ($skip) continue;
fwrite($f, "\tSystem::\$Configuration[\"" . $key . "\"] = " . VariableToString($value) . ";\n");
}
fwrite($f, "?>\n");
fclose($f);
return true;
}
?>
<div style="text-align: center;">
<img src="<?php echo(System::ExpandRelativePath("~/Images/Logo.png")); ?>" style="height: 200px;" />
</div>
<p style="text-align: center;">
<?php echo(System::$Configuration["Application.Name"]); ?> is configuring your initial instance. This would be a good time for a coffee break...
</p>
<table style="width: 600px; margin-left: auto; margin-right: auto;" border="1">
<?php
Message("Writing configuration file");
// set the database configuration
System::$Configuration["Database.ServerName"] = $_POST["database_servername"];
System::$Configuration["Database.DatabaseName"] = $_POST["database_databasename"];
System::$Configuration["Database.UserName"] = $_POST["database_username"];
System::$Configuration["Database.Password"] = $_POST["database_password"];
System::$Configuration["Database.TablePrefix"] = $_POST["database_tableprefix"];
$retval = SaveConfiguration();
if ($retval)
{
Success("Configuration file wrote successfully");
}
else
{
Failure("Could not write the configuration file!");
return true;
}
$retval = DataFX::Initialize();
if ($retval)
{
Success("Initialized DataFX library");
}
else
{
Failure("Could not initialize DataFX library with the new configuration!");
Message("Database returned error " . DataFX::$Errors->Items[0]->Code . ": " . DataFX::$Errors->Items[0]->Message);
Message(DataFX::$Errors->Items[0]->Query);
return true;
}
// create the Users table
/*
$tables = array
(
new Table("MarketResourceBankDetails", "bankdetail_", array
(
// $name, $dataType, $size, $value, $allowNull, $primaryKey, $autoIncrement
new Column("ResourceTypeID", "INT", null, null, false),
new Column("Name", "VARCHAR", 50, null, false),
new Column("TitleSingular", "VARCHAR", 100, null, false),
new Column("TitlePlural", "VARCHAR", 100, null, false)
)),
new Table("Tasks", "task_", array
(
// $name, $dataType, $size, $value, $allowNull, $primaryKey, $autoIncrement
new Column("ID", "INT", null, null, false, true, true),
new Column("TenantID", "INT", null, null, false),
new Column("Title", "VARCHAR", 100, null, false),
new Column("URL", "LONGTEXT", null, null, false)
)),
new Table("Themes", "theme_", array
(
// $name, $dataType, $size, $value, $allowNull, $primaryKey, $autoIncrement
new Column("ID", "INT", null, null, false, true, true),
new Column("TenantID", "INT", null, null, false),
new Column("Name", "VARCHAR", 100, null, false),
new Column("Title", "VARCHAR", 100, null, false),
new Column("CreationUserID", "INT", null, null, false),
new Column("CreationTimestamp", "DATETIME", null, null, false)
)),
new Table("UserEquippedItems", "equippeditem_", array
(
new Column("UserID", "INT", null, null, false),
new Column("ItemID", "INT", null, null, false)
)),
new Table("UserInventoryFolders", "inventoryitem_", array
(
new Column("ID", "INT", null, null, false),
new Column("Title", "VARCHAR", 100, null, false),
new Column("ParentFolderID", "INT", null, null, true)
)),
new Table("UserInventoryItems", "inventoryitem_", array
(
new Column("UserID", "INT", null, null, false),
new Column("ItemID", "INT", null, null, false),
new Column("ParentFolderID", "INT", null, null, true)
)),
new Table("UserProfileContents", "content_", array
(
// posts by the user on their profile. can be scrolled back and forth like a journal. supports HTML!
new Column("ID", "INT", null, null, false, true, true),
new Column("TenantID", "INT", null, null, false),
new Column("CreationUserID", "INT", null, null, false),
new Column("CreationTimestamp", "DATETIME", null, null, false),
new Column("Content", "LONGTEXT", null, null, false)
)),
new Table("UserProfileContentFeedbacks", "feedback_", array
(
// likes and dislikes for user profile contents
new Column("ContentID", "INT", null, null, false),
new Column("FeedbackTypeID", "INT", null, null, false),
new Column("Comments", "VARCHAR", 200, null, false),
new Column("CreationUserID", "INT", null, null, false),
new Column("CreationTimestamp", "DATETIME", null, null, false)
))
);
*/
$tables = array();
$tablefilepath = dirname(__FILE__) . "/Tables/*.inc.php";
$tablefiles = glob($tablefilepath);
foreach ($tablefiles as $tablefile)
{
require($tablefile);
}
foreach ($tables as $table)
{
if ($table->Exists())
{
Message("Table '" . $table->Name . "' already exists, skipping creation");
}
else
{
$retval = $table->Create();
if ($retval)
{
Success("Created table '" . $table->Name . "'");
}
else
{
Failure("Could not create table '" . $table->Name . "'");
Message("Database returned error " . DataFX::$Errors->Items[0]->Code . ": " . DataFX::$Errors->Items[0]->Message);
Message(DataFX::$Errors->Items[0]->Query);
}
}
}
$tenant = Tenant::Create($_POST["Application_DefaultTenant"], "The default tenant for " . System::$Configuration["Application.Name"] . ".");
$tablefilepath = dirname(__FILE__) . "/TenantObjects/*.inc.php";
$tablefiles = glob($tablefilepath);
foreach ($tablefiles as $tablefile)
{
require($tablefile);
}
require(dirname(__FILE__) . "/DefaultTenant.inc.php");
?>
</table>
<?php
return true;
}
$page = new WebPage();
$page->BeginContent();
?>
<div style="text-align: center;">
<img src="<?php echo(System::ExpandRelativePath("~/Images/Logo.png")); ?>" style="height: 200px;" />
</div>
<p style="text-align: center;">
Please provide some information about your server to create the initial <?php echo(System::$Configuration["Application.Name"]); ?> tenant. Other
tenants may be created and removed at any time by entering the Administrator Control Panel.
</p>
<form method="POST">
<table style="width: 400px; margin-left: auto; margin-right: auto;">
<tr>
<td style="width: 128px;"><label for="txtServerName">Server name:</label></td>
<td><input type="text" id="txtServerName" name="database_servername" style="width: 100%;" value="<?php echo(System::GetConfigurationValue("Database.ServerName", "localhost")); ?>" />
</tr>
<tr>
<td><label for="txtDatabaseName">Database name:</label></td>
<td><input type="text" id="txtDatabaseName" name="database_databasename" style="width: 100%;" value="<?php echo(System::GetConfigurationValue("Database.DatabaseName", "Objectify")); ?>" /></td>
</tr>
<tr>
<td><label for="txtUserName">User name:</label></td>
<td><input type="text" id="txtUserName" name="database_username" style="width: 100%;" value="<?php echo(System::GetConfigurationValue("Database.UserName", "Objectify")); ?>" /></td>
</tr>
<tr>
<td><label for="txtPassword">Password:</label></td>
<td><input type="password" id="txtPassword" name="database_password" value="" style="width: 100%;" /></td>
</tr>
<tr>
<td><label for="txtTablePrefix">Table prefix:</label></td>
<td><input type="text" id="txtTablePrefix" name="database_tableprefix" value="<?php echo(System::GetConfigurationValue("Database.TablePrefix", "phoenix_")); ?>" style="width: 100%;" /></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<tr>
<td><label for="txtAdministratorUserName">Administrator user name:</label></td>
<td><input type="text" id="txtAdministratorUserName" name="TenantManager_UserName" /></td>
</tr>
<tr>
<td><label for="txtAdministratorPassword">Administrator password:</label></td>
<td><input type="password" id="txtAdministratorPassword" name="TenantManager_Password" /></td>
</tr>
<tr>
<td><label for="txtDefaultTenant">Initial tenant:</label></td>
<td><input type="text" id="txtDefaultTenant" name="Application_DefaultTenant" value="default" /></td>
</tr>
<tr>
<td colspan="2" style="text-align: center;"><input type="submit" value="Continue" /></td>
</tr>
</table>
</form>
<?php
$page->EndContent();
return true;
},
function($path)
{
$enabled = false;
if (isset(System::$Configuration["Setup.Enabled"]))
{
$enabled = (System::$Configuration["Setup.Enabled"] == "true");
}
if (!$enabled)
{
$page = new \WebFX\WebPage();
$page->Title = "Configuration Error";
$page->BeginContent();
echo("<div style=\"text-align: center;\"><img style=\"height: 120px;\" src=\"" . System::ExpandRelativePath("~/Images/ObjectifyLogo.png") . "\" /></div><div>This Objectify installation has not been configured. Please contact the server administrator.</div>");
$page->EndContent();
return false;
}
})
));
?>