<?php
ob_start();
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php

include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";



if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


include "../includes/htmltop.php";

$message = "";
			
if(isset($_POST['update']))
{

		
			if (!isNotNull($_POST['txtTemplateTitle']))
			{
				$message = "* ".TEMP_TITLE_REQUIRED." !! <br>";
			}
			if (!isNotNull($_POST['txtEmailBody']))
			{
				$message = "* ".EMAIL_BODY_REQD." !! <br>";
			}
			
			if($message == "")
			{			
				$update_template = "UPDATE ".$tableprefix."email_templates
									SET vemail_body = ".GetSQLValueString($_POST['txtEmailBody'],"text").",
										vtemplate_title = ".GetSQLValueString($_POST['txtTemplateTitle'],"text").
									" WHERE nemail_id = ".GetSQLValueString($_GET['edit_id'],"text");
				mysql_query($update_template) or die(mysql_error());									  
	
				header("Location:email_templates.php?".$_GET['qstring']."&msg=S");								  
			}				  

}


	$select_template_edit = "SELECT vtemplate_title,vemail_body,vreplaceable_variables 
							 FROM ".$tableprefix."email_templates 
							 WHERE nemail_id = ".GetSQLValueString($_GET['edit_id'],"text");
						
	$result_template_edit = mysql_query($select_template_edit) or die(mysql_error()); 						




?>
		
		<body>
		
		<center>
		
<script>

	function checkEmailTemplate()
	{
	
	  var form_name = new Array('txtTemplateTitle');		
	  var display_name = new Array('Template Title');
	  var count = 1;	
	
	  if(check_fields('frmEditEmailTemplate',form_name,display_name,count))	
	  {
	  
		
		 //document.frmAddBanner.submit();	
	   
	  }
	  else
	  {
	  
			return false;
	  
	  }
	   
	}

</script>
		
		<div align="right" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="right" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="right" class="content_area">
					
					<!--content area start -->
					<div align="left" class="page_title"><?php echo EDIT_EMAIL_TMP;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="right">																			
																									
					<form name="frmEditEmailTemplate" action="#" method="POST" onSubmit="return checkEmailTemplate();">
																									
					<table cellpadding="0" cellspacing="0" width="100%" class="manage_table" border="0">
						<tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
						<tr><td colspan="3">&nbsp;</td></tr>
						
<?php

if(mysql_num_rows($result_template_edit) > 0)
{

	$template_edit_row = mysql_fetch_assoc($result_template_edit)

?>						
						
						
						<tr>
							<td width="38%" align="right" valign="top"><?php echo TEMP_TITLE;?>&nbsp;<span class="required">*</span></td>
							<td width="3%" valign="top" >:</td>
							<td width="59%" align="left" valign="top">
								<input type="text" class="textarea2" size="45" name="txtTemplateTitle" maxlength="100" value="<?php echo $template_edit_row['vtemplate_title']?>">
							</td>
						</tr>
						<tr>
							<td width="38%" align="right" valign="top"><?php echo EMAIL_BODY;?>&nbsp;<span class="required">*</span></td>
							<td width="3%" valign="top" >:</td>							
							<td width="59%" align="left" valign="top">
								<textarea name="txtEmailBody" class="textarea2" rows="10" cols="60"><?php echo $template_edit_row['vemail_body']?></textarea>
							</td>
						</tr>
						<tr>
							<td width="38%" align="right" valign="top"><?php echo REPLACE_VAR;?>&nbsp;</td>
							<td width="3%" >&nbsp;</td>
							<td width="59%" align="left" valign="top"><?php echo $template_edit_row['vreplaceable_variables']?></td>
						</tr>
						<tr>
							<td colspan="3">&nbsp;</td>
						</tr>
						
<?php
	$replaceable_variables = explode(',',$template_edit_row['vreplaceable_variables']);
		
	foreach($replaceable_variables as $replaceable_value)
	{
	
		$format_value = str_replace('[',' ',$replaceable_value);
		$format_value = str_replace(']',' ',$format_value);
		$format_value = str_replace('_',' ',$format_value);
		
?>						
						<tr>
							<td width="38%" align="right"class="text_information">&nbsp;</td>
							<td width="3%" align="right"><img src="../images/arrow1.gif"></td>
							<td width="59%" align="left" valign="top"><?php echo $replaceable_value?> <?php echo WIIL_BE_REPLCD;?> <b><?php echo ucwords(trim($format_value))?></b></td>						
							
						</tr>
						
<?php
	}

}

?>						
						
						<tr><td colspan="3">&nbsp;</td></tr>
						<tr>
							<td colspan="3" align="center"><font class="required">*</font>&nbsp;<?php echo REPLACBL_VAR;?> <b><?php echo SYS_VARIABLES;?></b> <?php echo WILL_REPLAC_REAL_VAL;?>,<br>&nbsp;&nbsp;&nbsp;<?php echo DO_NOT_DELETE_RENAME;?> <b><?php echo SYS_VARIABLES;?>.</b></td>
						</tr>
						<tr><td colspan="3">&nbsp;</td></tr>
						<tr>
							<td colspan="3" align="center">
							<input type="button" class="button" name="back" value="&nbsp;<?php echo BACK;?>&nbsp;" onClick="window.location='email_templates.php'">
							<input type="submit" value="<?php echo UPDATE;?>" name="update" class="button">
							</td>
						</tr>
						<tr><td colspan="3">&nbsp;</td></tr>
					</table>
				</form>
				
				</div>
												
				<!--content area end-->
								
				</div>
				
								
					<div align="right" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
	
	ob_end_flush();
?>