<? 
require_once "include/application.php"; 
require_once "include/function.php";
require_once "include/parameter.php";

if($btnSave || $btnSend){
	$err=true;
	
	if($err){
		$senddate=$year."-".$month."-".$day;
		$sql="
		INSERT INTO `eb_alert` (
		`eba_name` ,
		`eba_template` ,	
		`eba_from` ,		
		`eba_cc` ,		
		`eba_bcc` ,		
		`eba_subject` ,				
		`eba_pselect` ,
		`eba_title` ,
		`eba_role` ,
		`eba_race` ,
		`eba_status` ,
		`eba_gender` ,
		`eba_ageformula` ,
		`eba_age` ,
		`eba_type` ,
		`eba_industry` ,
		`eba_source` ,
		`eba_classification` ,
		`eba_country` ,
		`eba_cselect` ,
		`eba_cband` ,
		`eba_ctype` ,
		`eba_cindustry` ,
		`eba_csource` ,
		`eba_cclassification` ,
		`eba_ccountry` ,
		`eba_dob` ,
		`eba_spdob` ,
		`eba_senddate` ,
		`eba_pdear` ,
		`eba_cdear` ,
		`eba_responder` ,
		`eba_created` ,
		`eba_user` 
		)

	VALUES (
	\"$name\",'$template','$from','$cc','$bcc',\"$subject\",'$p_select','$title', '$role','$race','$status', '$gender','$formula', '$age','$type', '$industry', '$source', '$classification', \"$country\",
	'$c_select','$c_band','$c_type', '$c_industry', '$c_source', '$c_classification', \"$c_country\",'$dob','$spdob','$senddate','$p_dear','$c_dear','$responder',CURRENT_TIMESTAMP,'".$_SESSION["egoUser"]."')
	";
		@mysql_query($sql) or die(mysql_error());
		$iid=mysql_insert_id();		
		
		if($btnSave){
			print("<script type='text/javascript'>alert('Scheduler Saved.')</script>");
		}else if($btnSend){
			$sql="INSERT INTO `eb_outbox` (
				`ebob_alert` ,ebob_created ,ebob_status,ebob_user)
				VALUES ('$iid',CURRENT_TIMESTAMP,'Pending','".$_SESSION["egoUser"]."'
				);
				";
			@mysql_query($sql) or die(mysql_error());
			print("<script type='text/javascript'>alert('e-Blaster Sent.')</script>");			
		}
		print("<script type='text/javascript'>location.href='eb_alertSearch.php'</script>");		
	}
}

if(!$p_select)$p_select="";
if(!$c_select)$c_select="";
if(!$from)$from=EMAIL;
?>

<!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 onload="enable_person_alert('<? echo $p_select ?>');enable_company_alert('<? echo $c_select ?>')">

<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 ?>" onsubmit="return ValidateAddAlert(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 Scheduler </td>
          </tr>
          <tr>
            <td height="1" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;</td>
          </tr>

        </table>
          <table width="100%" border="0" cellspacing="1" cellpadding="1">
            <tr>
              <td width="23%" height="15" class="TextH1">Choose Template : <span class="require">*</span></td>
              <td width="77%"><span class="TextH1">
                <select name="template" id="template">
                 <option value=""></option>
                  <?
				if(array_search("viewall",$permlist)==true)$sql="select * from eb_template where ebt_id >'0' order by ebt_name ";
				else $sql="select * from eb_template where ebt_user='".$_SESSION["egoUser"]."' order by ebt_name ";

				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["ebt_id"]."' ";
					if($template==$myrow["ebt_id"])echo "selected";
					echo ">".$myrow["ebt_name"]." </option>";
				}
			
?>
                </select>
              </span></td>
            </tr>
            <tr>
              <td class="TextH1">From  : <span class="require">*</span></td>
              <td><input name="from" type="text" id="from" value="<? echo $from ?>" size="50" maxlength="50" /></td>
            </tr>
            <tr>
              <td class="TextH1">CC  :</td>
              <td><input name="cc" type="text" id="cc" value="<? echo $cc ?>" size="50" /> <input name="btnInfo2" type="button" class="btnInfo" id="btnInfo2" value="..." onclick="DialogWindow('popup/popContact.php?fld=cc','Search','width=450,height=600')"/></td>
            </tr>
            <tr>
              <td class="TextH1">BCC  :</td>
              <td><input name="bcc" type="text" id="bcc" value="<? echo $bcc ?>" size="50" />
                <input name="btnInfo" type="button" class="btnInfo" id="btnInfo" value="..." onclick="DialogWindow('popup/popContact.php?fld=bcc','Search','width=450,height=600')"/></td>
            </tr>
            <tr>
              <td class="TextH1">Subject : <span class="require">*</span></td>
              <td><input name="subject" type="text" id="subject" value="<? echo $subject ?>" size="50" maxlength="50" /></td>
            </tr>
            <tr>
              <td class="TextH1">&nbsp;</td>
              <td><span class="TextH1">
                <input name="responder" type="checkbox" id="responder" value="Y" />
Email Auto Responder to Sender </span></td>
            </tr>
            <tr>
              <td colspan="2"><table width="100%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#FFCC33">
                <tr>
                  <td class="TextH1"><span class="MenuTitle">Choose Person Group </span>                    <select name="p_select" id="p_select" onChange="enable_person_alert(this.value)">
                      <option value="None">None</option>
                      <option value="All">All Members</option>
                      <option value="Individual">Individual</option>
                      </select></td>
                  <td><span class="MenuTitle">Choose Company Group</span><span class="TextH1">
                    <select name="c_select" id="c_select" onChange="enable_company_alert(this.value)">
                      <option value="None">None</option>
                      <option value="All">All Members</option>
                      <option value="Individual">Individual</option>
                    </select>
                  </span></td>
                  </tr>
                <tr>
                  <td class="TextH1"><table class='person' style=display:'none' width="100%" border="0" cellspacing="1" cellpadding="1">
	                <tr >
                      <th width="28%" height="23" class="TextH1"><div align="left">Title</div></th>
                      <td width="72%" class="TextH1"><span class="main">
                        <select name="title" id="title" style="WIDTH: 180px" >
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Title' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($title==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                        </select>
                      </span></td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Role </div></th>
                      <td class="TextH1"><select style="WIDTH: 180px"
      name="role" id="role">
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Role' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($role==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>

                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Gender</div></th>
                      <td class="TextH1"><select name="gender" id="gender" style="WIDTH: 180px">
                          <option value=""></option>
                          <option value="Male">Male</option>
                          <option 
        value="Female">Female</option>
                        </select></td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Age</div></th>
                      <td class="TextH1"><select name="formula" id="formula">
                        <option value=""></option>
                        <option value="=">Equal</option>
                        <option value="<">Bigger than</option>
                        <option value=">">Smaller than</option>
                        <option value="<=">Bigger &amp; equal than</option>
                        <option value=">=">Smaller &amp; equal than</option>
                      </select>
                        <input name="age" type="text" id="age" value="<? echo $age ?>" size="2" maxlength="2" /></td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Race</div></th>
                      <td class="TextH1"><select style="WIDTH: 180px"
      name="race" id="race">
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Race' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($race==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>

                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Status</div></th>
                      <td class="TextH1"><select style="WIDTH: 180px"
      name="status" id="status" >
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Status' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($status==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Type</div></th>
                      <td class="TextH1"><select 
      name="type" id="type" style="WIDTH: 180px"> 

                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Type' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($type==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                  
                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Industry</div></th>
                      <td class="TextH1"><select 
      name="industry" id="industry" style="WIDTH: 180px">
      
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Industry' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($industry==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Source</div></th>
                      <td class="TextH1"><select 
      name="source" id="source" style="WIDTH: 180px"> 

                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Source' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($source==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                       
                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Classification</div></th>
                      <td class="TextH1"><select 
      name="classification" id="classification" style="WIDTH: 180px" >

                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Classification' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($classification==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                          
                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Country</div></th>
                      <td class="TextH1"> <select name="country" id="country">
						<option value=""></option>
						                <? require "country.inc"; ?>
										</select></td>
                    </tr>
                    
                  </table></td>
                  <td valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="1" class='company' style=display:'none'>
	                <tr >
                      <th width="31%" height="23" class="TextH1"><div align="left">Employee band</div></th>
                      <td width="69%" class="TextH1"><select name="c_band" id="c_band" style="WIDTH: 180px" >

                        <option value=""></option>
                        <?
			 
			 	$sql="select * from newvalue where nv_type='Band' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($role==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                      </select></td>
                    </tr>

                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Type</div></th>
                      <td class="TextH1"><select 
      name="c_type"  style="WIDTH: 180px">
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Type' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($c_type==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Industry</div></th>
                      <td class="TextH1"><select 
      name="c_industry"  style="WIDTH: 180px">
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Industry' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($c_industry==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Source</div></th>
                      <td class="TextH1"><select 
      name="source" style="WIDTH: 180px">
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Source' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($c_source==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                        </select>                      </td>
                    </tr>
                    <tr class="editTbl">
                      <th height="23" class="TextH1"><div align="left">Classification</div></th>
                      <td class="TextH1"><select 
      name="c_classification" style="WIDTH: 180px" >
                          <option value=""></option>
                          <?
			 
			 	$sql="select * from newvalue where nv_type='Classification' order by nv_id";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["nv_id"]."' ";
					if($c_classification==$myrow["nv_id"])echo "selected";
					echo ">".$myrow["nv_name"]." </option>";
				}
			
?>
                        </select>                      </td>
                    </tr>
                    <tr>
                      <th height="23" class="TextH1"><div align="left">Country</div></th>
                      <td class="TextH1"><select name="c_country">
                          <option value=""></option>
                          <? require "country.inc"; ?>
                      </select></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td ><span class="MenuTitle">Scheduler  Setting</span> </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td class="TextH1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
                    <tr>
                      <td>On Birthday </td>
                      <td><select 
      name="dob" id="dob" style="WIDTH: 180px" >
                          <option value=""></option>
                          <option value="99">On the same day</option>
                          <option value="1">1 Day Before</option>
                          <option value="2">2 Days Before</option>
                          <option value="3">3 Days Before</option>
                          <option value="4">4 Days Before</option>
                          <option value="5">5 Days Before</option>
                          <option value="6">6 Days Before</option>
                          <option value="7">1 Week Before</option>
                        </select>
                          <? stayfocus("form","dob",$dob) ?></td>
                    </tr>
                    <tr>
                      <td>On Spouse Birthday </td>
                      <td><select 
      name="spdob" id="spdob" style="WIDTH: 180px" >
                          <option value=""></option>
                          <option value="99">On the same day</option>
                          <option value="1">1 Day Before</option>
                          <option value="2">2 Days Before</option>
                          <option value="3">3 Days Before</option>
                          <option value="4">4 Days Before</option>
                          <option value="5">5 Days Before</option>
                          <option value="6">6 Days Before</option>
                          <option value="7">1 Week Before</option>
                        </select>
                          <? stayfocus("form","spdob",$spdob) ?></td>
                    </tr>
                    
                    <tr>
                      <td width="28%">Specify Date </td>
                      <td width="72%"><?
echo "<select name='day'>";
echo '<option value=""></option>\n';
foreach ($days as $value) {
	echo '<option value="'.$value.'"';
	if($day==$value)echo ' selected';
	echo '>'.$value.'</option>\n';
} echo '</select> ';

echo "<select name='month'>";
echo '<option value=""></option>\n';
foreach ($months  as $key => $value) {
	echo '<option value="'.$key.'"';
	if($month==$key)echo ' selected';
	echo '>'.$value.'</option>\n';
}
echo '</select> ';

echo "<select name='year'>";
echo '<option value=""></option>\n';
foreach ($thisyears as $value) {
	echo '<option value="'.$value.'"';
	if($year==$value)echo ' selected';
	echo '>'.$value.'</option>\n';
} 
echo '</select> ';
?></td>
                    </tr>
                    
                  </table></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td class="TextH1">Display Dear
                    <input name="p_dear" type="radio" value="name" checked="checked" />
 Person Name 
  <input name="p_dear" type="radio" value="default" />
  Valued Customer </td>
                  <td><span class="TextH1">Display Dear
                      <input name="c_dear" type="radio" value="name" checked="checked" />
Key Person Name
<input name="c_dear" type="radio" value="default" />
Valued Customer </span></td>
                </tr>
              </table></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 Scheduler " onclick="return confirm('Are you sure ?')"/>
                <input name="btnSend" type="submit" class="btn150" id="btnSend" value="Send Now" onclick="return confirm('Are you sure want to send now?')"/>
              </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>");
?>