<?LassoScript
// Last modified 11/9/09 by ECL, Landmann InterActive

// FUNCTIONALITY
// itPage Installer

// CHANGE NOTES
// 11/9/09
// Better error trapping.

// Debugging
// Var:'svDebug' = 'Y';

// Convert action_params
Var('ErrorMsgOut' = string);
Var('vError' = string);
Var('vProcess' = (Action_Param:'Process'));
Var('vPlatform' = (Action_Param:'Platform'));
Var('vDomain' = (Action_Param:'Domain'));
Var('vHostname' = (Action_Param:'Hostname'));
Var('vSiteDatabase' = (Action_Param:'SiteDatabase'));
Var('vInitializeID' = (Action_Param:'UserID'));
Var('vInitializePW' = (Action_Param:'Password'));
Var('vPathToIM' = (Action_Param('PathToIM')));
Var('vPathToPassThru' = (Action_Param('PathToPassThru')));
Var('vPathToffmpeg' = (Action_Param('PathToffmpeg')));
Var('vPathToswftools' = (Action_Param('PathToswftools')));

If(Var('vPathToPassThru') == '');
	$vPathToPassThru = '///Applications/Lasso Professional 8/LassoModules/EC_PassThru.dylib';
/If;

//  Used on forms to show input is required	
Var:'svInputRequired'='&nbsp;<font color="red"><strong>&loz;</strong></font>';

?><html>
<head>
<title>itPage</title>
	<meta http-equiv="Content-Type" content="text/html;">
	<script language="JavaScript" type="text/javascript">
	// Check required fields
	function checkForm()
		{
			// Make sure all required information is supplied
			if ((form.Initialize.Platform == "") ||
				(form.Initialize.Domain == "") ||
				(form.Initialize.SiteDatabase == "") ||
				(form.Initialize.Hostname == "") ||
				(form.Initialize.UserID == "") ||
				(form.Initialize.Password == "") ||
				(form.Initialize.PathToIM == ""));
			{
				alert("Required information is missing, please correct and resubmit.");
				return false;
			}
	
		}
	</script>
	<style type="text/css"><!--
	body { 
		font-family: Verdana, Arial, Helvetica, sans-serif;
		font-size: 10px}
	td {
		font-family: Verdana, Arial, Helvetica, sans-serif;
		font-size: 10px;
		line-height: 11pt}
	h2 {
		font-family: Verdana, Arial, Helvetica, sans-serif;
		font-size: 14px;
		font-weight: bold;
		color: #000000}
	--></style>
</head>
<body bgcolor="#ffffff">
<div align="left"><img src="/site/images/logos/itPage-Logo-120" width="120" height="68" alt="itPage_logo_120"></div>
<div align="left"><h2>Install itPage CMS</h2></div>
<?Lassoscript
//  If form has been submit, initialize the application, otherwise display the form
If: $vProcess == 'Y';

	If: ($vDomain == '') || ($vInitializeID == '') || ($vInitializePW == '');
		Var:'vError' = '<font color="red"><strong>ERROR! </strong>Required field missing,</font> try again.<br>\n<br>\n';
	/If;

	If: $vError == '';

//		'58: Current Username: ' (Admin_CurrentUsername) '<br>\n';

		// Create the Database
		Include:'/install/install_itPage.inc';

//		Protect;

			Inline: -Database=$vSiteDatabase, -SQL=$SQLCreateitPageTables;

//				Handle: (Error_CurrentError: -ErrorCode);
					Var:'ErrorCode' = (Error_CurrentError: -ErrorCode);
					Var:'ErrorMsg' = (Error_CurrentError);

					Debug;
						'<strong>Setting up Database</strong><br>\n';
						'Current Username: ' (Admin_CurrentUsername) '<br>\n';
						'Error_CurrentError: ' (Error_CurrentError) '<br>\n';
					/Debug;

					If(($ErrorMsg >> 'no permission') || ($ErrorMsg >> 'not found') || ($ErrorMsg >> 'Could not find prepared statement'));
						Var('ErrorMsgOut' = ('<font color="red"><strong>ERROR! </font></strong>Problem setting up database. The error was: <strong>"' (Error_CurrentError) '" </strong>.<br><br>\n'));
						$ErrorMsgOut += ('<a href="install.lasso?Platform='($vPlatform)'&Domain='($vDomain)'&UserID='($vInitializeID)'&Password='($vInitializePW)'&SiteDatabase='($vSiteDatabase)'&Hostname='($vHostname)'&PathtoIM='($vPathToIM)'&PathToPassThru='($vPathToPassThru)'&PathToffmpeg='($vPathToffmpeg)'&PathToswftools='($vPathToswftools)'">Return to Initialize</a><br>\n<br>\n');
						$ErrorMsgOut += ('<a href="http://'($vDomain)'/admin/login.lasso">Try logging in to the itPage Admin</a><br>\n');
					Else ($ErrorMsg != 'No error');
						Var('ErrorMsgOut' = ('<font color="red"><strong>ERROR! </font></strong>Problem setting up database. The error was: <strong>"' (Error_CurrentError) '" </strong>.<br><br>\n'));
						$ErrorMsgOut += ('<a href="install.lasso?Platform='($vPlatform)'&Domain='($vDomain)'&UserID='($vInitializeID)'&Password='($vInitializePW)'&SiteDatabase='($vSiteDatabase)'&Hostname='($vHostname)'&PathtoIM='($vPathToIM)'&PathToPassThru='($vPathToPassThru)'&PathToffmpeg='($vPathToffmpeg)'&PathToswftools='($vPathToswftools)'">Return to Initialize</a><br>\n<br>\n');
						$ErrorMsgOut += ('<a href="http://'($vDomain)'/admin/login.lasso">Try logging in to the itPage Admin</a><br>\n');
					Else;
						Var('ErrorMsgOut' = ('<font color="red"><strong>SUCCESS! </font></strong>The database was successfully created.<br><br>\n'));
						$ErrorMsgOut += ('<a href="http://'($vDomain)'/admin/login.lasso">Log in to itPage Admin</a><br>\n');
					/If;

//				/Handle;

			/Inline;

///		/Protect;

//	Else;
	
		// Output the error (required missing)
		// Var:'vError',-EncodeNone;

	/If;

/If;

// Output the error (required missing)
Var:'ErrorMsgOut',-EncodeNone;


If: $vProcess != 'Y' || $vError !='';
?>

<div align="left"><strong>IMPORTANT NOTE:</strong> Clicking "Initialize" will initialize the itPage CMS, and will create all tables and sample data in the database. The database must be created already (see <a href="http://itpage.ws/wiki/Installation">installation instructions</a>).</div>
<br>
<div align="left"><strong>NOTE: </strong>[$svInputRequired] indicates required information.</div>
<br>
<form action="install.lasso" method="post" name="Initialize">
	<table border="0" cellpadding="5" width="680">
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>Server Platform</strong></font>[$svInputRequired]
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<select name="Platform">
					<option value=""[If: (Var:'vPlatform') == ''] selected[/If]></option>
					<option value="Mac"[If: (Var:'vPlatform') == 'Mac'] selected[/If]>Mac</option>
					<option value="Windows"[If: (Var:'vPlatform') == 'Windows'] selected[/If]>Windows</option>
					<option value="Linux"[If: (Var:'vPlatform') == 'Linux'] selected[/If]>Linux</option>
				</select>
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>Domain Name</strong></font>[$svInputRequired]
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="Domain" value="[Var:'vDomain']" size="36" maxlength="64"><br>
			Enter the domain on which the itPage CMS will be running<br>
			<strong>Example:</strong> www.yourdomain.com
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>Database Name</strong></font>[$svInputRequired]
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="SiteDatabase" value="[Var:'vSiteDatabase']" size="36" maxlength="64"><br>
			Enter the name of the itPage database<br>
			<strong>Example:</strong> itpage_cms
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>MySQL Hostname</strong></font>[$svInputRequired]
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="Hostname" value="[Var:'vHostname']" size="18" maxlength="24"><br>
				Enter the IP number or domain name of MySQL server
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>MySQL User ID</strong></font>[$svInputRequired]
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="UserID" value="[Var:'vInitializeID']" size="18" maxlength="24"><br>
				Enter the User ID for the MySQL database
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>MySQL Password</strong></font>[$svInputRequired]
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="Password" value="[Var:'vInitializePW']" size="18" maxlength="24"> <br>
				Enter the Password for the MySQL database
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>Path to ImageMagick</strong></font>[$svInputRequired]
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="PathToIM" value="[Var:'vPathToIM']" size="54" maxlength="128"><br>
			Enter the path to ImageMagick (Note triple slashes at start)<br>
			<strong>Example (Mac):</strong> ///Applications/ImageMagick-6.7.0/bin
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>Path to PassThru</strong></font>
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="PathToPassThru" value="[Var:'vPathToPassThru']" size="54" maxlength="128"><br>
			Enter the path to PassThru (Note triple slashes at start)<br>
			<strong>Example (Mac):</strong> ///Applications/Lasso Professional 8/LassoModules/EC_PassThru.dylib
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>Path to ffmpeg</strong></font>
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="PathToffmpeg" value="[Var:'vPathToffmpeg']" size="54" maxlength="128"><br>
			Enter the path to ffmpeg (Note triple slashes at start)<br>
			<strong>Example (Mac):</strong> ///usr/local/bin/ffmpeg
			</td>
		</tr>
		<tr>
			<td width="150" bgcolor="#666666">
				<div align="right">
					<font color="#FFFFFF"><strong>Path to swftools</strong></font>
				</div>
			</td>
			<td valign="top" bgcolor="#cccccc">
				<input type="text" name="PathToswftools" value="[Var:'vPathToswftools']" size="54" maxlength="128"><br>
			Enter the path to swftools (Note triple slashes at start)<br>
			<strong>Example (Mac):</strong> ///opt/local/bin/swfdump
			</td>
		</tr>

		<tr>
			<td colspan="2" bgcolor="#666666">
				<div align="center">
				<input type="hidden" name="Process" value="Y">
<!-- 
				<input type="submit" name="Action" value="Initialize" onclick="return confirmInitialize(); return checkForm();">
 -->
				<input type="submit" name="Action" value="Initialize" onclick="return checkForm();">
				</div>
			</td>
		</tr>
	</table>
</form>
[/If]
</body>
</html>
