<? 

require_once "include/application.php"; 
require_once "include/function.php";
include("fck/fckeditor.php") ;

if($btnDelete){
	$sql="delete from `eb_template` where ebt_id='$id'";	
	@mysql_query($sql) or die(mysql_error());
	
	$target_path = "uploads/".$_SESSION["egoUser"];
	
	if($att)unlink("$target_path/$att");
	
	print("<script type='text/javascript'>alert('Record is deleted.')</script>");
	print("<script type='text/javascript'>location.href='eb_tempSearch.php'</script>");

}
if($btnSave){
	$err=true;
	
	$target_path = "uploads/".$_SESSION["egoUser"]."/";
	
	if($err){
		$insRd=true;
		if($_FILES['uploadedfile']['name']){
			$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
		
			if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
		//		echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
			//	" has been uploaded";
			} else{
				$action_msg="There was an error uploading the file, please try again!";
				$insRd=false;
			}
		}	
	
		if($insRd){
			$sql="
				update `eb_template` set `ebt_name`=\"$name\" ,
				`ebt_msg` =\"$FCKeditor1\" ";
			if($_FILES['uploadedfile']['name'])$sql.=",`ebt_attach`='".$_FILES['uploadedfile']['name']."' ";
			$sql.="where ebt_id='$id'";			
			@mysql_query($sql) or die(mysql_error());

			print("<script type='text/javascript'>alert('Saved.')</script>");
			print("<script type='text/javascript'>location.href='eb_tempSearch.php'</script>");
		}
	}
}else{
	$sql="select * from eb_template where ebt_id='$id' ";
	$result=mysql_query($sql);	
	while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC))
	{
		$name=$myrow["ebt_name"];		
		$FCKeditor1=$myrow["ebt_msg"];		
		$att=$myrow["ebt_attach"];		
	}
	
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="sddm.css" >
<script src="include/validation.js" type="text/javascript"></script>

<title><? echo TITLE?></title>
</head>
<body>

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f1efd8">
  <tr>
    <td  colspan="2" align="center"><? require_once "include/header.php"; ?></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="185" valign="top" bgcolor="e6f3f9">
	
<? require_once "include/columnLeft.php"; ?>	</td>
    <td width="834" valign="top">
	<form name="form" method="post" action="<?=$PHP_SELF ?>" enctype="multipart/form-data" onsubmit="return ValidateAddMemo(this);">
	  <table width="810" border="0" align="center" cellpadding="0" cellspacing="0">
      
      <tr>

        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="100%" height="30" class="TitleH3">Update e-Blaster Template </td>
          </tr>
          <tr>
            <td height="1" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;<strong><strong><strong><strong><strong><strong><strong><strong><strong>
              <input name="id" type="hidden" id="id" value="<? echo $id ?>" />
              </strong></strong></strong></strong></strong></strong></strong></strong></strong></td>
          </tr>

        </table>
          <table width="100%" border="0" cellspacing="1" cellpadding="1">
            <tr>
              <td height="30" class="TextH1">Template Name :<span class="require"> *</span></td>
              <td><input name="name" type="text" id="name" value="<? echo $name ?>" size="50" maxlength="50" /></td>
            </tr>
            <tr>
              <td colspan="2">
			  <?php

$sBasePath = "/tcrm/fck/";

$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath	= $sBasePath ;
$oFCKeditor->Value		= $FCKeditor1;
$oFCKeditor->Create() ;

?>			  </td>
            </tr>
            <tr>
              <td width="19%" class="TextH1">File Attachment</td>
              <td width="81%"><input type="hidden" name="MAX_FILE_SIZE" value="100000" />
                <input name="uploadedfile" type="file" /><? echo $att ?>
                <input name="att" type="hidden" id="att" value="<? echo $att ?>" /> 
                <span class="subItem">file size &lt; 10M</span> </td>
            </tr>
            <tr>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td height="30" colspan="2"><span class="require">* Denotes a require_onced field</span></td>
            </tr>
            <tr>
              <td colspan="2"><span class="text12">
                <input name="btnSave" type="submit" class="btn" id="btnSave" value="Save" onclick="return confirm('Are you sure want to save?')"/>
                <? if($_SESSION["egoBlock"]<>"Yes"){ ?>
                <input name="btnDelete" type="submit" class="btn" id="btnDelete" value="Delete " onclick="return confirm('Are you sure want to delete?')"/>
                <? } ?>
<input name="btnBack" type="button" class="btn" id="btnBack" onclick="location.href='eb_tempSearch.php'" value="BACK" />
              </span></td>
            </tr>
          </table></td>

      </tr>
 
    </table>
	  <br />
	</form>	</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#333333"><div align="center"><span class="Footer">
      <br />
      <? require_once "footer.php"; ?>
    </span></div></td>
  </tr>
</table>
</body>
</html>
<?
if(array_search("e-Blaster",$menulist)==false)
		print("<script type='text/javascript'>location.href='index.php'</script>");
?>