<?php
include_once('inc/util.inc');
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'._('lang').'" lang="'._('lang').'">
<head>
<title>SAM: Simple Application Management</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/reset/reset-min.css"/>
<link rel="stylesheet" type="text/css" href="themes/default/style.css"/>
<style>
body { text-align: center; }
#content { margin: 0 auto; width: 750px; text-align: left; }
h1 { font: bold 26px/160% Arial, Helvetica, sans-serif; padding: 0 0 30px 0; }
#install-progress { float: left; width: 200px; font: normal 20px/160% Arial, Helvetica, sans-serif; }
#install-progress ul li { border: 1px solid #ddd; background-color: #eee; padding: 10px; }
#install-progress ul li a { color: #000; font: 16px/100% Arial, Helvetica, sans-serif; }
#install-progress ul li.current { padding-left: 35px; background: #fff url(http://simpleappmanagement.com/themes/images/install-current.png) 10px 50% no-repeat; }
#install-progress ul li.finished { padding-left: 35px; background: #eee url(http://simpleappmanagement.com/themes/images/install-success.png) 10px 50% no-repeat; color: #ccc; }
#install { margin: 0 0 0 230px; }
#install .sub1 { float: right; }
.passed { background-color: #79b933; font-weight: bold; padding: 10px; }
.failed { background-color: #cd5a38; font-weight: bold; padding: 10px; }
#first { width: 180px; }
#last { width: 240px; }
</style>
<script type="text/javascript" src="inc/prototype.js"></script>
</head>
<body>
<div id="header" class="clearfix"><ul id="header-nav"><li>'._('SAM Installation').'</li></ul></div>
<div id="content">
<div id="content-wrapper">';
//----------------------------------------------------------------------------------------
// Progress through steps
//----------------------------------------------------------------------------------------
if (isset($_POST['step1'])) {
displayInstallCheck();
} else if (isset($_POST['step2'])) {
displayConfigDBSetup();
} else if (isset($_POST['step3'])) {
displaySiteConfigSetup();
} else if (isset($_POST['step4'])) {
displayModuleSetup();
} else {
// If config exists then the site is installed already
if (file_exists('inc/config.php')) {
echo '
<h1>'._('Installation Complete').'</h1>
<p>'._('SAM has already been installed, please delete the inc/config.php file if you wish to continue.').'</p>';
displayFooter();
exit();
// Else begin the installation process
} else {
displayStepOne();
}
}
//----------------------------------------------------------------------------------------
// Step One
//----------------------------------------------------------------------------------------
function displayStepOne () {
displayProgress(1);
echo '
<div id="install">
<h1>'._('Simple Application Management Installation').'</h1>
<p>'._('Thank you for choosing Simple Application Management.').'</p>
<p>'._('You will now be guided through a series of steps that will install your version of SAM.').'</p>
<p>'._('On each step, please fill out all required fields and click the \'Next\' button to proceed to the next step.').'</p>
<p>'._('Once all steps are complete, you can login and begin managing your open source project.').'</p>
<form action="install.php" method="post">
<div><input type="submit" class="sub1" name="step1" id="step1" value="'._('Next').'"/></div>
</form>
</div>';
}
//----------------------------------------------------------------------------------------
// Installation Check
//----------------------------------------------------------------------------------------
function displayInstallCheck () {
if (isWritable('inc/')) {
displayStepTwo();
} else {
displayProgress(1);
echo '
<div id="install">
<h1>'._('Installation Check').'</h1>
<div class="failed">'._('Failed').'</div>
<p>'._('The inc/ directory is not writable, either this directory is missing or you need to change the permissions before continuing.').'</p>
</div>';
}
}
//----------------------------------------------------------------------------------------
// Step Two
//----------------------------------------------------------------------------------------
function displayStepTwo ($error = false, $msg = '', $server = '', $username = '', $database = '') {
displayProgress(2);
echo '
<script type="text/javascript">
Event.observe(window, \'load\', function() { $(\'server\').focus(); });
</script>
<div id="install">
<h1>'._('Database').'</h1>';
if ($error) {
echo '
<div class="error-alert">'.$msg.'</div>';
}
echo '
<form action="install.php" method="post">
<p>
<label for="server">'._('Server').'</label><br/>
<input type="text" class="txt" name="server" id="server" value="'.$server.'"/>
</p>
<p>
<label for="username">'._('Username').'</label><br/>
<input type="text" class="txt" name="username" id="username" value="'.$username.'"/>
</p>
<p>
<label for="password">'._('Password').'</label><br/>
<input type="text" class="txt" name="password" id="password"/>
</p>
<p>
<label for="database">'._('Database').'</label><br/>
<input type="text" class="txt" name="database" id="database" value="'.$database.'"/>
</p>
<div><input type="submit" class="sub1" name="step2" id="step2" value="'._('Next').'"/></div>
</form>
</div>';
}
//----------------------------------------------------------------------------------------
// Config File and DB Setup
//----------------------------------------------------------------------------------------
function displayConfigDBSetup () {
if (
empty($_POST['server']) ||
empty($_POST['username']) ||
empty($_POST['password']) ||
empty($_POST['database'])
) {
// Missing req field
$msg = _('All fields are required.');
displayStepTwo(true, $msg, $_POST['server'], $_POST['username'], $_POST['database']);
} else {
// Try and create config
$file = @fopen('inc/config.php', 'w');
if (!$file) {
$msg = _('Could not create inc/config.php');
displayStepTwo(true, $msg, $_POST['server'], $_POST['username'], $_POST['database']);
return;
}
$str = "<?php \$db_server = '".$_POST['server']."'; \$db_database = '".$_POST['database']."'; \$db_username = '".$_POST['username']."'; \$db_password = '".$_POST['password']."'; ?".">";
fwrite($file, $str) or die("Could not write to inc/config.php");
fclose($file) or die("Could not close inc/config.php");
// Try to connect to DB
$connection = @mysql_connect($_POST['server'], $_POST['username'], $_POST['password']);
if (!$connection) {
// Bad Connection
unlink('inc/config.php') or print("Could not delete inc/config.php. Please manually delete this file and run the installation again.");
$msg = _('A connection to the database could not be made.');
displayStepTwo(true, $msg, $_POST['server'], $_POST['username'], $_POST['database']);
exit();
} else {
// Create Configuration Table
mysql_select_db($_POST['database']);
mysql_query("DROP TABLE IF EXISTS `sam_configuration`") or die(mysql_error());
$sql = "CREATE TABLE `sam_configuration` (
`sitename` VARCHAR(100) NOT NULL,
`contact` VARCHAR(100) NOT NULL,
`theme` VARCHAR(50) NOT NULL DEFAULT 'default',
`repo` VARCHAR(255) NOT NULL,
`projects` VARCHAR(50) NOT NULL DEFAULT 'Projects',
`components` VARCHAR(50) NOT NULL DEFAULT 'Components',
`use_type` TINYINT(1) NOT NULL DEFAULT '1',
`use_priority` TINYINT(1) NOT NULL DEFAULT '1',
`use_project` TINYINT(1) NOT NULL DEFAULT '1',
`use_component` TINYINT(1) NOT NULL DEFAULT '1',
`use_start` TINYINT(1) NOT NULL DEFAULT '1',
`use_due` TINYINT(1) NOT NULL DEFAULT '1',
`use_discovered` TINYINT(1) NOT NULL DEFAULT '1',
`use_target` TINYINT(1) NOT NULL DEFAULT '1',
`use_fixed` TINYINT(1) NOT NULL DEFAULT '1',
`use_progress` TINYINT(1) NOT NULL DEFAULT '1',
`use_est_hours` TINYINT(1) NOT NULL DEFAULT '1',
`use_dev_hours` TINYINT(1) NOT NULL DEFAULT '1',
`use_tested` TINYINT(1) NOT NULL DEFAULT '1'
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
displayStepThree();
}
}
}
//----------------------------------------------------------------------------------------
// Step Three
//----------------------------------------------------------------------------------------
function displayStepThree ($error = false, $msg = '', $sitename = '', $username = '', $first = '', $last = '', $email = '') {
displayProgress(3);
echo '
<script type="text/javascript">
Event.observe(window, \'load\', function() { $(\'sitename\').focus(); });
</script>
<div id="install">
<h1>'._('Configuration').'</h1>';
if ($error) {
echo '
<div class="error-alert">'.$msg.'</div>';
}
echo '
<form action="install.php" method="post">
<p>
<label for="sitename">'._('Site Name').'</label><br/>
<input type="text" class="txt" name="sitename" id="sitename" value="'.$sitename.'"/>
</p>
<p>
<label for="username">'._('Admin Username').'</label><br/>
<input type="text" class="txt" name="username" id="username" value="'.$username.'"/>
</p>
<p>
<label for="password">'._('Admin Password').'</label><br/>
<input type="text" class="txt" name="password" id="password"/>
</p>
<p>
<label for="first">'._('Admin Name (first, last)').'</label><br/>
<input type="text" class="txt" name="first" id="first" value="'.$first.'"/>
<input type="text" class="txt" name="last" id="last" value="'.$last.'"/>
</p>
<p>
<label for="email">'._('Admin Email').'</label><br/>
<input type="text" class="txt" name="email" id="email" value="'.$email.'"/>
</p>
<div><input type="submit" class="sub1" name="step3" id="step3" value="'._('Next').'"/></div>
</form>
</div>';
}
//----------------------------------------------------------------------------------------
// Site Config Setup
//----------------------------------------------------------------------------------------
function displaySiteConfigSetup () {
include_once('inc/config.php');
$connection = @mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_database);
if (
empty($_POST['sitename']) ||
empty($_POST['username']) ||
empty($_POST['password']) ||
empty($_POST['first']) ||
empty($_POST['last']) ||
empty($_POST['email'])
) {
// Missing req field
$msg = _('All fields are required.');
displayStepThree(true, $msg, $_POST['sitename'], $_POST['username'], $_POST['password'], $_POST['first'], $_POST['last'], $_POST['email']);
} else {
// Create User Table
mysql_query("DROP TABLE IF EXISTS `sam_user`") or die(mysql_error());
$sql = "CREATE TABLE `sam_user` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`username` VARCHAR(20) NOT NULL,
`first` VARCHAR(50) NOT NULL,
`last` VARCHAR(50) NOT NULL,
`password` VARCHAR(255) NOT NULL DEFAULT '0',
`email` VARCHAR(100) NOT NULL,
`admin` TINYINT(1) NOT NULL DEFAULT '0',
`joindate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
)";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Escape input
$sitename = stripMagicQuotes($_POST['sitename']);
$sitename = escape_string($sitename);
$username = stripMagicQuotes($_POST['username']);
$username = escape_string($username);
$first = stripMagicQuotes($_POST['first']);
$first = escape_string($first);
$last = stripMagicQuotes($_POST['last']);
$last = escape_string($last);
$password = md5($_POST['password']);
$email = stripMagicQuotes($_POST['email']);
$email = escape_string($email);
$sql = "INSERT INTO `sam_configuration` (`sitename`, `contact`)
VALUES ('$sitename', '$email')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$sql = "INSERT INTO `sam_user` (`username`, `first`, `last`, `password`, `email`, `admin`, `joindate`)
VALUES ('$username', '$first', '$last', '$password', '$email', 1, NOW())";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Setup the rest of the tables
setupTables();
displayStepFour();
}
}
//----------------------------------------------------------------------------------------
// Step Four
//----------------------------------------------------------------------------------------
function displayStepFour ($error = false, $msg = '') {
displayProgress(4);
echo '
<script type="text/javascript">
Event.observe(window, \'load\', function() { $(\'sitename\').focus(); });
</script>
<div id="install">
<h1>'._('Module Setup').'</h1>';
if ($error) {
echo '
<div class="error-alert">'.$msg.'</div>';
}
echo '
<form action="install.php" method="post">
<p>
'._('Choose the Modules you would like to use. These can be changed/configured after installation also.').'
</p>
<p>
<input type="checkbox" class="chk" name="tracker" id="tracker" checked="checked" value="tracker"/>
<label for="tracker">'._('Tracker').'</label><br/>
<input type="checkbox" class="chk" name="progress" id="progress" value="progress"/>
<label for="progress">'._('Progress').'</label><br/>
<input type="checkbox" class="chk" name="code" id="code" value="code"/>
<label for="code">'._('Source Code').'</label><br/>
<input type="checkbox" class="chk" name="ideas" id="ideas" value="ideas"/>
<label for="ideas">'._('Idea Management').'</label><br/>
<input type="checkbox" class="chk" name="blog" id="blog" value="blog"/>
<label for="blog">'._('Blog').'</label><br/>
</p>
<div><input type="submit" class="sub1" name="step4" id="step4" value="'._('Next').'"/></div>
</form>
</div>';
}
//----------------------------------------------------------------------------------------
// Module Setup
//----------------------------------------------------------------------------------------
function displayModuleSetup () {
include_once('inc/config.php');
$connection = @mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_database);
if (count($_POST) <= 1) {
$msg = _('You must choose at least one module.');
displayStepFour(true, $msg);
} else {
// Setup modules
$order = 1;
if (isset($_POST['tracker'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('tracker', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
include('install/tracker.php');
}
if (isset($_POST['progress'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('progress', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
}
if (isset($_POST['code'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('code', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
}
if (isset($_POST['ideas'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('ideas', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
include('install/ideas.php');
}
if (isset($_POST['blog'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('blog', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
include('install/blog.php');
}
// Installation complete
displayProgress(5);
echo '
<div id="install">
<h1>'._('Installation Complete').'</h1>
<p>'._('Simple Application Management has been installed.').'</p>
<p><a href="index.php">'._('View Website').'</a></p>
</div>';
}
}
//----------------------------------------------------------------------------------------
// Progress
//----------------------------------------------------------------------------------------
function displayProgress ($sel) {
$start = '';
if ($sel > 1) {
$start = '<a href="install.php">'._('Start Over').'</a>';
}
echo '
<div id="install-progress" class="clearfix">
<ul class="clearfix">
<li class="'; if ($sel == 1) echo 'current'; if (1 < $sel) echo 'finished'; echo '"><div>'._('Step 1').'</div>'.$start.'</li>
<li class="'; if ($sel == 2) echo 'current'; if (2 < $sel) echo 'finished'; echo '"><div>'._('Step 2').'</div></li>
<li class="'; if ($sel == 3) echo 'current'; if (3 < $sel) echo 'finished'; echo '"><div>'._('Step 3').'</div></li>
<li class="'; if ($sel == 4) echo 'current'; if (4 < $sel) echo 'finished'; echo '"><div>'._('Step 4').'</div></li>
<li class="'; if ($sel == 5) echo 'current'; if (5 < $sel) echo 'finished'; echo '"><div>'._('Step 5').'</div></li>
</ul>
</div>';
}
//----------------------------------------------------------------------------------------
// Footer
//----------------------------------------------------------------------------------------
function displayFooter () {
echo '
<div id="footer">
'.sprintf(_('Powered by %s'), '<a href="http://www.simpleappmanagement.com/">SAM</a>').'
</div>
</div><! /#content-wrapper >
</div><! /#content >
</div><! /#wrapper >
</body>
</html>';
}
//----------------------------------------------------------------------------------------
// Setup Tables
//----------------------------------------------------------------------------------------
function setupTables () {
// Drop existing tables
mysql_query("DROP TABLE IF EXISTS `sam_category`") or die(mysql_error());
mysql_query("DROP TABLE IF EXISTS `sam_comment`") or die(mysql_error());
mysql_query("DROP TABLE IF EXISTS `sam_module`") or die(mysql_error());
mysql_query("DROP TABLE IF EXISTS `sam_module_type`") or die(mysql_error());
mysql_query("DROP TABLE IF EXISTS `sam_layout`") or die(mysql_error());
// Create Category Table
$sql = "CREATE TABLE `sam_category` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`type` VARCHAR(10) NOT NULL,
`parent` INT(11) NOT NULL DEFAULT '0',
`date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Create Comment Table
$sql = "CREATE TABLE `sam_comment` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`type` VARCHAR(10) NOT NULL,
`type_id` INT(11) NOT NULL DEFAULT '0',
`user` INT(11) NOT NULL DEFAULT '0',
`comment` TEXT,
`date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Create Module Table
$sql = "CREATE TABLE `sam_module` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`type` VARCHAR(20) NOT NULL,
`order` TINYINT(1) NOT NULL
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Create Layout Table
$sql = "CREATE TABLE `sam_layout` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`type` VARCHAR(20) NOT NULL,
`row` TINYINT(2) NOT NULL,
`position` TINYINT(1) NOT NULL,
`data` TEXT
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$sql = "INSERT INTO `sam_layout` (`type`, `row`, `position`, `data`)
VALUES ('text', 1, 3, 'Welcome to SAM, check out the Widgets page of the Administration section to edit what is displayed here.')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
}
displayFooter();