<?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_artistid"]) && $_SESSION["sess_artistid"]!= ""){
	$artistid = $_SESSION["sess_artistid"];
}else{
	header("Location:login.php");
	exit;
}

if(checkArtistExpired($artistid)){
	header("Location:seller_plan_upgrade.php?sellerid=".$artistid);
	exit;
}
include "../includes/htmltop.php";

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

		
			if (!isNotNull($_POST['txtTemplateTitle']))
			{
				$message = MSG_TEMP_REQ;
			}
			if (!isNotNull($_POST['txtEmailBody']))
			{
				$message = MSG_EMAIL_REQ;
			}
			
			if($message == "")
			{	
                            
                            $artist_id = $_POST['artist_id'];

                            if($artist_id !=''){
				$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");
                            }
                            else{
                                  $update_template = "INSERT INTO ".$tableprefix."email_templates (
                                            vtemplate_name,vtemplate_title,vemail_body,vreplaceable_variables,vtemplate_flag,artist_id
                                            ) VALUES (
                                                ".GetSQLValueString($_POST['vtemplate_name'],"text").",
                                                ".GetSQLValueString($_POST['txtTemplateTitle'],"text").",
                                                ".GetSQLValueString($_POST['txtEmailBody'],"text").",
                                                ".GetSQLValueString($_POST['vreplaceable_variables'],"text").",
                                                'S',
                                                '".addslashes($artistid)."')";
               
                            }
                            mysql_query($update_template) or die(mysql_error());									  
	
                            header('Location:email_templates_seller.php?msg='.MSG_EMAIL_UPDT_SUC);								  
			}				  

}


	$select_template_edit = "SELECT vtemplate_name,vtemplate_title,vemail_body,vreplaceable_variables,artist_id
							 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="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

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

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

if(mysql_num_rows($result_template_edit) > 0)
{

	$template_edit_row = mysql_fetch_assoc($result_template_edit)

?>						
						
						
						<tr>
							<td width="29%" align="right" valign="top"><?php echo TEXT_TEMP_TITLE;?>&nbsp;<span class="required">*</span></td>
							<td width="4%" >&nbsp;</td>
							<td width="67%" align="left" valign="top">
								<input type="text" size="45" name="txtTemplateTitle" class="textarea2" maxlength="100" value="<?php echo $template_edit_row['vtemplate_title']?>">
                                                                
                                                                   <input type="hidden" name="artist_id" id="artist_id" value="<?php echo $template_edit_row['artist_id']?>">
                                            <input type="hidden" name="vreplaceable_variables" id="vreplaceable_variables" value="<?php echo $template_edit_row['vreplaceable_variables']?>">
                                            <input type="hidden" name="vtemplate_name" id="vtemplate_name" value="<?php echo $template_edit_row['vtemplate_name']?>">
                                            
							</td>
						</tr>
						<tr>
							<td width="29%" align="right" valign="top"><?php echo TEXT_EMAIL_BODY;?>&nbsp;<span class="required">*</span></td>
							<td width="4%" >&nbsp;</td>
							<td width="67%" align="left" valign="top">
								<textarea name="txtEmailBody" rows="10" class="textarea2" cols="35"><?php echo $template_edit_row['vemail_body']?></textarea>
							</td>
						</tr>
						<tr>
							<td width="29%" align="right" valign="top"><?php echo TEXT_REPLACE_VAR;?>&nbsp;</td>
							<td width="4%" >&nbsp;</td>
							<td width="67%" 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="29%" align="left"></td>
							<td width="4%" class="text_information"><img src="../images/arrow1.gif"></td>
							<td width="67%" align="left" valign="top"><?php echo $replaceable_value?><?php echo MSG_WILL_REPLACE;?><b><?php echo ucwords(trim($format_value))?></b></td>
						</tr>
						
<?php
	}

}

?>						
						
						<tr><td colspan="3">&nbsp;</td></tr>
						<tr>
							<td colspan="3"><font class="required"><?php echo MSG_REPLACE_VAR;?>.</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 BTN_BACK;?>&nbsp;" onClick="window.location='email_templates_seller.php'">
                                                        <input type="submit" value="<?php echo BTN_UPDATE;?>" name="update" class="button">
							</td>
						</tr>
						<tr><td colspan="3">&nbsp;</td></tr>
					</table>
				</form>
				
				</div>
												
				<!--content area end-->
								
				</div>
				
								
					<div align="left" 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();
?>