<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005-2006 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts EasyCreate 1.1                 |
// +----------------------------------------------------------------------+
// | Authors: jimmy<jimmy.jos@armia.com>        		              	  |
// +----------------------------------------------------------------------+
//This screen helps the user select various options for creating a new page
//(i)	Type Of Page
//			Does the user wants to create a page with the layout of an index page or sub page
//(ii)	Name of the page		
//			Pagename without extension that consists of only alphabets and numbers
//(iii)	Guestbook
//			Does the user want the page for a guestbook.
//These three options are given and the user selects appropriate options, enters a pagename and clicks 
//'Submit' to assign the selected values and pagename to an object, assign the objects as returnValue and
//close the window. 		 
include "../includes/session.php";
include "../includes/config.php";
$currentloc="../";	  
include "../includes/applicationheader.php";
?>
<script>
returnValue = new Object();
returnValue.type="";
returnValue.name="";
returnValue.gb="";
//	(i)		check for pagename validity(must contain only alphabets and numbers without extension)
//	(ii)	assign type as index/sub based on user selection of page type
//	(iii)	assign name as pageName.php if guestbook option is selected  else
//	 		assign name as pageName.htm
//	(iv)	close the window.
function createPage() {
	//var re = /^[a-z]+[0-9]*[a-z]*\.{1}h{1}t{1}m{1}$/gi;
	var re = /^[a-z]+[0-9]*[a-z]*[^\.]$/gi;
	if(re.test(document.frmNew.txtName.value) == false) {
		alert("Please enter a valid name for your document.");
		return;			
	}
	if(document.frmNew.rdType[0].checked == true) {
		returnValue.type="index";
	}
	else {
		returnValue.type="sub";
	}
	if(document.frmNew.txtName.value.length <= 0 || document.frmNew.txtName.value.indexOf(' ') == 0) {
		alert('Please enter a valid name for your page.');
		return;
	}
	if(document.frmNew.cmbGuestbook.value == "yes") {
		returnValue.gb="yes";
		returnValue.name=document.frmNew.txtName.value + ".php";
	}
	else {
		returnValue.name=document.frmNew.txtName.value + ".htm";
	}
	window.close();
}
//cancel button clicked
//close the window.
function cancel() {
	window.close();
}
</script>
<body>
<form name="frmNew" method="post">
<table width="100%">
	<tr>
		<td>
		<fieldset>
			<legend class=maintextbold>Create new page</legend>	
				<table width="100%"  border="0">
				  <tr>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td class="maintext"><b>Type Of Page :</b> &nbsp;&nbsp;<input name="rdType" type="radio" value="index"> 
					  Index Page      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				      <input name="rdType" type="radio" value="sub" checked="true">
				Sub Page </td>
				  </tr>
				  <tr>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td class="maintext"><b>Page Name&nbsp;&nbsp;&nbsp; :</b>&nbsp;&nbsp;&nbsp;&nbsp;
				    <input name="txtName" type="text" id="txtName" size="30" maxlength="50" class="textbox"></td>
				  </tr>
				  <tr>
				    <td class="maintext"><b>Guestbook&nbsp;&nbsp;&nbsp;&nbsp; :</b>&nbsp;&nbsp;&nbsp;&nbsp;
					<select name="cmbGuestbook" class="selectbox">
					<option value="no">No</option>
					<option value="yes">Yes</option>
					</select></td>
			      </tr>
				  <tr>
					<td align="center"><br><input name="Submit" type="button" id="Submit" value="Submit" onClick="javascript:createPage();" class="editorbutton">&nbsp;<input name="Cancel" type="button" id="Cancel" value="Cancel" onClick="javascript:cancel();" class="editorbutton"></td>
				  </tr>
				</table>
		</fieldset>
		</td>
	</tr>
</table>
</form>
<?php
  include "./includes/editorfooter.php";
?> 	
