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

if($btnSave || $btnSend){
	$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="
				INSERT INTO `eb_template` (
				`ebt_name` ,
				`ebt_msg` ,
				`ebt_attach` ,
				`ebt_user` ,
				`ebt_created` 
				)
				VALUES (\"$name\", \"$FCKeditor1\", '".$_FILES['uploadedfile']['name']."', '".$_SESSION["egoUser"]."', CURRENT_TIMESTAMP 
				);
			";
			@mysql_query($sql) or die(mysql_error());
			$iid=mysql_insert_id();
			
			if($btnSend){
				print("<script type='text/javascript'>location.href='eb_newAlert.php?template=$iid'</script>");
			}else if($btnSave){
				print("<script type='text/javascript'>alert('Template Saved.')</script>");
				print("<script type='text/javascript'>location.href='eb_tempSearch.php'</script>");
			}
		}
	}
}
?>

<!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 ValidateAddEB(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">New e-Blaster </td>
          </tr>
          <tr>
            <td height="1" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;
              <input name="ty" type="hidden" id="ty" value="<? echo $ty ?>" /></td>
          </tr>

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

$sBasePath = "/tcrm/fck/";
//$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "_samples" ) ) ;

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

?>			  </td>
            </tr>
            <tr>
              <td class="TextH1">File Attachment</td>
              <td><input type="hidden" name="MAX_FILE_SIZE" value="100000" />
                <input name="uploadedfile" type="file" />
                <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="btn150" id="btnSave" value="Save as Template" onclick="return confirm('Are you sure ?')"/>
                <input name="btnSend" type="submit" class="btn150" id="btnSend" value="Send Now / Set Scheduler" onclick="return confirm('Are you sure ?')"/>
              </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>");
?>