<?php
// +------------------------------------------------------------------------+
// | PHP Melody version 1.6.7 ( www.phpsugar.com )
// +------------------------------------------------------------------------+
// | PHP Melody IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2011 PhpSugar.com. All rights reserved.
// +------------------------------------------------------------------------+

$showm = 'mod_pages';
include('header.php');

$action = $_GET['do'];
if ( ! in_array($action, array('edit', 'new', 'delete')) )
{
	$action = 'new';	//	default action
}

?>
<div id="sub_menu">
<li><a href="page_manager.php?do=new">Add new</a></li>
<li><a href="pages.php">Manage pages</a></li>
</div>

<div id="content">
<h2>Add new page</h2>
<div id="display_result" style="display:none;"></div>

<?php 

$inputs = array();

if ('' != $_POST['submit'])
{
	$_POST['title'] = after_post_filter($_POST['title']);
		
	if ($action == 'new')
	{
		$result = insert_new_page($_POST);
	}
	else if ($action == 'edit')
	{
		$result = update_page($_POST['id'], $_POST);
	}
	
	if ($result['type'] == 'error')
	{
		echo '<div class="info_msg_err"><strong>'. $result['msg'] .'</strong></div>';
	}
	else
	{
		echo '<div class="info_msg_ok"><strong>'. $result['msg'] .'</strong> <a href="'. _URL .'/page.php?p='. $result['page_id'] .'" target="_blank">View page.</a></div>';
		echo '<br />';
		echo '<input name="continue" type="button" value="&laquo; Manage pages" onClick="location.href=\'pages.php\'" class="inputbutton" />';
		echo '<input name="add_new" type="button" value="Add new page &raquo;" onClick="location.href=\'page_manager.php?do=new\'" class="inputbutton" />';
	}	
}

if ($action == 'edit')
{
	$id = (int) $_GET['id'];
	if ($id == 0)
	{
		$action = 'new';
		$inputs = array();
		$inputs['status'] = 1;
		$inputs['author'] = $userdata['id'];
	}
	else
	{
		$inputs = get_page($id);
	}
}
else if ($action == 'new')
{
	if ('' != $_POST['submit'])
	{
		$inputs = $_POST;
	}
}

//	Filter some fields before output
$inputs['title'] = pre_post_filter($inputs['title']);

?>

 <form name="write_page" method="post" action="page_manager.php?do=<?php echo $action; ?>&id=<?php echo $_GET['id'];?>" 
   onsubmit="return validateFormOnSubmit(this, 'Please fill in the required fields (highlighted).')">
 <div id="write_article">
   <table width="100%" cellpadding="5" cellspacing="0">
    <tr>
      <td width="70%"><span class="article_field_label">Title</span></td>
      <td width="30%" rowspan="15" valign="top">
	  <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" class="article_rightp">
	  	<tr>
          <td colspan="2"><span class="article_field_label">Permalink</span></td>
        </tr>
        <tr>
          <td colspan="2">
		  <input name="page_name" id="page_name" type="text" value="<?php echo $inputs['page_name']; ?>" size="50" style="width:100%" />
		  <small>
		  <div id="preview_url" class="small-ok">
			  <br />
			<?php 
				if(_SEOMOD == 1) 
				{
			?>
				  Live preview: <?php echo _URL."/pages/"; ?><span id="preview_complete_url"></span>.html
			<?php
				} else {
			?>
				  Live preview: <?php echo _URL."/page.php?name="; ?><span id="preview_complete_url"></span>
			<?php			
				}
			?>
		  </div>
			  <?php
			  if ($action == 'edit' && $inputs['page_name'] != '' && _SEOMOD)
			  {
				echo '<span class="small-warning">Editing the permalink may affect your indexed pages.</span>';
			  }
			  ?>
			  <br />Define how the URL will look like. <em>(e.g. about-us, contact)</em>
		  </small>
		  </td>
        </tr>
		<tr>
          <td colspan="2"><span class="article_field_label">Meta Keywords</span></td>
        </tr>
        <tr>
          <td colspan="2">
		  <input name="meta_keywords" type="text" value="<?php echo $inputs['meta_keywords']; ?>" size="50" style="width:100%" />
		  <br /><small>Optional <em>(e.g. about, about us)</em></small>
		  </td>
        </tr>
		<tr>
          <td colspan="2"><span class="article_field_label">Meta Description</span></td>
        </tr>
        <tr>
          <td colspan="2">
		  <textarea name="meta_description" rows="3" style="width:100%" /><?php echo $inputs['meta_description']; ?></textarea>
		  </td>
        </tr>
        <tr>
          <td colspan="2"><span class="article_field_label">Availability</span></td>
        </tr>
        <tr>
          <td colspan="2">
			<label><input type="radio" name="status" value="0" <?php if ($inputs['status'] == 0) echo 'checked="checked"'; ?> /> Private</label> 
			<label><input name="status" type="radio" value="1" <?php if ($inputs['status'] == 1) echo 'checked="checked"'; ?> /> Public</label>
		  </td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td align="left"><input name="cancel" type="button" value="Cancel" onClick="location.href='pages.php'" class="deletebutton" /></td>
          <td width="50%" align="right"><input name="submit" type="submit" <?php echo ($action == 'edit') ? 'value="Save"' : 'value="Publish"';?> class="approvebutton" /></td>
        </tr>
      </table></td>
    </tr>
    <tr>
	 <td width="47%">
	  <input name="title" type="text" id="must" value="<?php echo $inputs['title']; ?>" style="width: 99%;" class="article_title" />	 </td>
	 </tr>
	<tr>
	  <td><span class="article_field_label">Content</span></td>
	  </tr>
	<tr>
	 <td>
        	 <script language="javascript">
				if(navigator.userAgent.toLowerCase().indexOf('chrome/1') > -1)	//	not compatible with Chrome and older versions of Safari.
				{
					document.write('<div class="info_msg">If the page editor does not contain a RICH TEXT editor please upgrade your browser or try a different browser. Thank you!</div>');
				} else if(navigator.userAgent.toLowerCase().indexOf('safari') > -1) 
				{
					document.write('<div class="info_msg">If the page editor does not contain a RICH TEXT editor please upgrade your browser or try a different browser. Thank you!</div>');
				}
			 </script>
			 <textarea name="content" cols="100" id="textarea-WYSIWYG" style="height: 350px;"><?php echo $inputs['content']; ?></textarea>
				<script language="javascript1.2">
					if(navigator.userAgent.toLowerCase().indexOf('chrome/1') == -1)
					{
						// Overwrite WYSIWYG Width and Height
						wysiwygWidth = '100%';
						wysiwygHeight = 350;
						generate_wysiwyg('textarea-WYSIWYG');
					}
				</script>
				<script type="text/javascript">
					//	Editor not loaded?
					if ($("#wysiwygtextarea-WYSIWYG").length == 0)
					{
						// restore textarea
						$("#textarea-WYSIWYG").show();
					}
				</script>
	  </td>
	 </tr>
	<tr>
	  <td><span class="article_field_label">Select image to upload</span></td>
	  </tr>
	<tr>
	 <td>
	  <script type="text/javascript">
		var swfu;
		var swfu_msg = {
				queue_limit_exceeded : "You have attempted to queue too many files.",
				file_exceeds_size_limit : "This file is too big.", 
				zero_byte_file : "This file is empty. Please try another.",
				invalid_filetype : "This file type is not allowed. Please try another.",
				default_error : "An error occurred in the upload. Please try again later.",
				missing_upload_url : "There was a configuration error. Please contact the server administrator.",
				upload_limit_exceeded : "You may only upload 1 file.",
				http_error : "HTTP error: ",
				upload_failed: "Upload failed.",
				io_error: "IO error.",
				security_error: "Security error.",
				file_cancelled: "File cancelled.",
				upload_stopped: "Upload stopped.",
				dismiss: "Dismiss",
				crunching: "Crunching&hellip;",
				deleted: "Deleted", 
				file_validation_failed: "Failed Validation.  Upload skipped."
		};
		
		window.onload = function() {
		
			var settings = {
				flash_url : "swfupload/swfupload.swf",
				upload_url: "upload_image.php",
				file_size_limit : "<?php echo ($upload_max_filesize > 0) ? $upload_max_filesize.' B' : '0';?>",
				file_types : "*.jpg; *.gif; *.png",
				file_types_description : "Images",
				file_upload_limit : 10,
				file_queue_limit : 1,
				custom_settings : {
					progressTarget : "fsUploadProgress"
				},
				post_params: {
						"PHPSESSID" : "<?php echo session_id(); ?>"
						},

				// Button settings
				button_image_url: "swfupload/upload.png",
				button_placeholder_id: "ButtonPlaceHolder",
				button_width: "132",
				button_height: "24",
				button_text: '<span class="button">Browse ...</span>',
				button_text_style: '.button { text-align: left; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; }',
				button_text_top_padding: 3,
				button_text_left_padding: 18,
				button_window_mode: "window",
				button_cursor: SWFUpload.CURSOR.HAND,
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete, 
				
				debug : false
			};

			swfu = new SWFUpload(settings);
	     };
		</script>
	  <div id="fsUploadProgress"></div>
	  <div>
	  <span id="ButtonPlaceHolder"></span></div>
	  <div id="divStatus"></div>
	  </td>
	 </tr>
	<tr>
	 <td>
	  <input type="hidden" name="author" value="<?php  echo $inputs['author'];?>" />
	  <input type="hidden" name="id" value="<?php echo $inputs['id'];?>" />
	  </td>
	 </tr>
  </table>
</div>
</form>


</div> <!-- #content end -->
<?php
include('footer.php');
?>