<?php

include_once("../include/main.inc.php");

include_once("../ajax_functions.php");

check_session('MyCpanel','index.php');

################ Paging Starts From Here ##################

@extract($_REQUEST);

$heading="Add new Mailer";

//$record_type="member";

$script_name="add-new-mail.php";

$table_name="mailer_list";

admin_header();

if($_REQUEST['action']=="add_record" && $mailer_code!="") {
	@extract($_REQUEST);
    $mailer_code=mysqli_real_escape_string($mailer_code,true);
		$sql=db_query("insert into $table_name set mailer_title='$mailer_title', mailer_reply='$mailer_reply', mailer_code='$mailer_code', message='$message', status='N'");
		$_SESSION['session_message']=$record_type.' has been added successfully';
		header('Location: manage_emails.php');
		exit;
}

if($_REQUEST['action']=='update_record' && $mailer_id!="" ) {
	@extract($_REQUEST);
$mailer_code=mysqli_real_escape_string($mailer_code,true);
	updateTable($table_name,"mailer_title='$mailer_title', mailer_reply='$mailer_reply', mailer_code='$mailer_code', message='$message', status='N' where mailer_id='$mailer_id'");
  $_SESSION['session_message']=$record_type.' has been updated successfully';
	header('Location: manage_emails.php');
	exit;
}

echo $mailer_id."id";
echo $id."record";
if($id=="delete_record" && $mailer_id!="" ) {
	@extract($_REQUEST);

	updateTable($table_name," status='Y' where mailer_id='$mailer_id'");
		$_SESSION['session_message']='Mailer has been deleted successfully';
		header('Location: manage_emails.php');
			exit;
	}
	
	if($id=="active_record" && $mailer_id!="" ) {
	@extract($_REQUEST);

		updateTable($table_name," status='Y' where mailer_id='$mailer_id'");
		$_SESSION['session_message']='Mailer has been activated successfully';
		header('Location: manage-mails-active.php');
			exit;
	}
	
	if($id=="inprocess_record" && $mailer_id!="" ) {
	@extract($_REQUEST);

		updateTable($table_name," status='I' where mailer_id='$mailer_id'");
		$_SESSION['session_message']='Mailer has been Inprocess successfully';
		header('Location: manage-mails-inprocess.php');
			exit;
	}
?>
<style type="text/css">		

form.appnitro
{
	margin:20px 20px 0;
	padding:0 0 20px;
	background:#fff;
	margin:0 auto;
	text-align:left;
	width:640px;
}

img
{
	behavior:url(css/iepngfix.htc);
	border:none;
}

/**** Form Section ****/
.appnitro
{
	font-family:Lucida Grande, Tahoma, Arial, Verdana, sans-serif;
	font-size:small;
}

.appnitro li
{
	width:61%;
}

form input:focus,
form textarea:focus {
				border:1px solid #666;
				background:#e3f1f1;
				}
form ul
{
	font-size:100%;
	list-style-type:none;
	margin:0;
	padding:0;
	width:100%;
}

form li
{
	display:block;
	margin:0;
	padding:4px 5px 2px 9px;
	position:relative;
}

form li:after
{
	clear:both;
	content:".";
	display:block;
	height:0;
	visibility:hidden;
}

.buttons:after
{
	clear:both;
	content:".";
	display:block;
	height:0;
	visibility:hidden;
}

.buttons
{
	clear:both;
	display:block;
	margin-top:10px;
}

* html form li
{
	height:1%;
}

* html .buttons
{
	height:1%;
}

* html form li div
{
	display:inline-block;
}

form li div
{
	color:#444;
	margin:0 4px 0 0;
	padding:0 0 8px;
}

form li span
{
	color:#444;
	float:left;
	margin:0 4px 0 0;
	padding:0 0 8px;
}

form li div.left
{
	display:inline;
	float:left;
	width:48%;
}

form li div.right
{
	display:inline;
	float:right;
	width:48%;
}

form li div.left .medium
{
	width:100%;
}

form li div.right .medium
{
	width:100%;
}

.clear
{
	clear:both;
}

form li div label
{
	clear:both;
	color:#444;
	display:block;
	font-size:9px;
	line-height:9px;
	margin:0;
	padding-top:3px;
}

form li span label
{
	clear:both;
	color:#444;
	display:block;
	font-size:9px;
	line-height:9px;
	margin:0;
	padding-top:3px;
}

form li .datepicker
{
	cursor:pointer !important;
	float:left;
	height:16px;
	margin:.1em 5px 0 0;
	padding:0;
	width:16px;
}

.form_description
{
	border-bottom:1px dotted #ccc;
	clear:both;
	display:inline-block;
	margin:0 0 1em;
}

.form_description[class]
{
	display:block;
}

.form_description h2
{
	clear:left;
	font-size:160%;
	font-weight:400;
	margin:0 0 3px;
}

.form_description p
{
	font-size:95%;
	line-height:130%;
	margin:0 0 12px;
}

form hr
{
	display:none;
}

form li.section_break
{
	border-top:1px dotted #ccc;
	margin-top:9px;
	padding-bottom:0;
	padding-left:9px;
	padding-top:13px;
	width:97% !important;
}

form ul li.first
{
	border-top:none !important;
	margin-top:0 !important;
	padding-top:0 !important;
}

form .section_break h3
{
	font-size:110%;
	font-weight:400;
	line-height:130%;
	margin:0 0 2px;
}

form .section_break p
{
	font-size:85%;

	margin:0 0 10px;
}

/**** Buttons ****/
input.button_text
{
	overflow:visible;
	padding:0 7px;
	width:auto;
}

.buttons input
{
	font-size:120%;
	margin-right:5px;
}

/**** Inputs and Labels ****/
label.description
{
	border:none;
	color:#222;
	display:block;
	font-size:95%;
	font-weight:700;
	line-height:150%;
	padding:0 0 1px;
}

span.symbol
{
	font-size:115%;
	line-height:130%;
}

input.text
{
	background:#fff url(../images/shadow.gif) repeat-x top;
	border-bottom:1px solid #ddd;
	border-left:1px solid #c3c3c3;
	border-right:1px solid #c3c3c3;
	border-top:1px solid #7c7c7c;
	color:#333;
	font-size:100%;
	margin:0;
	padding:2px 0;
}

input.file
{
	color:#333;
	font-size:100%;
	margin:0;
	padding:2px 0;
}

textarea.textarea
{
	background:#fff url(../../../images/shadow.gif) repeat-x top;
	border-bottom:1px solid #ddd;
	border-left:1px solid #c3c3c3;
	border-right:1px solid #c3c3c3;
	border-top:1px solid #7c7c7c;
	color:#333;
	font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif;
	font-size:100%;
	margin:0;
	width:99%;
}

select.select
{
	color:#333;
	font-size:100%;
	margin:1px 0;
	padding:1px 0 0;
	background:#fff url(../../../images/shadow.gif) repeat-x top;
	border-bottom:1px solid #ddd;
	border-left:1px solid #c3c3c3;
	border-right:1px solid #c3c3c3;
	border-top:1px solid #7c7c7c;
}


input.currency
{
	text-align:right;
}

input.checkbox
{
	display:block;
	height:13px;
	line-height:1.4em;
	margin:6px 0 0 3px;
	width:13px;
}

input.radio
{
	display:block;
	height:13px;
	line-height:1.4em;
	margin:6px 0 0 3px;
	width:13px;
}

label.choice
{
	color:#444;
	display:block;
	font-size:100%;
	line-height:1.4em;
	margin:-1.55em 0 0 25px;
	padding:4px 0 5px;
	width:90%;
}

select.select[class]
{
	margin:0;
	padding:1px 0;
}

*:first-child+html select.select[class]
{
	margin:1px 0;
}

.safari select.select
{
	font-size:120% !important;
	margin-bottom:1px;
}

input.small
{
	width:25%;
}

select.small
{
	width:25%;
}

input.medium
{
	width:50%;
}

select.medium
{
	width:50%;
}

input.large
{
	width:99%;
}

select.large
{
	width:100%;
}

textarea.small
{
	height:5.5em;
}

textarea.medium
{
	height:10em;
}

textarea.large
{
	height:20em;
}

</style>
<script language="JavaScript">
	function selectAll(source) {
		checkboxes = document.getElementsByName('db[]');
		for(var i in checkboxes)
			checkboxes[i].checked = source.checked;
	}
</script>
<div align="left" class="myTitle"><?=$heading;?></div>
<hr size="2" width="100%" color="#92B2D6">
<?php
print_message();
$res=getResult($table_name," where mailer_id='$mailer_id'");

if($res['mailer_id']!="") {
	$mailer_title=$res['mailer_title'];
	$mailer_reply=$res['mailer_reply'];
	$mailer_code=$res['mailer_code'];
	$message=$res['message'];
	
}
else{
	$mailer_title=$mailer_title;
	$mailer_reply=$mailer_reply;
	$mailer_code=$mailer_code;
	$message=$message;
}
?>
<table width="100%"  border="0" cellpadding="0" cellspacing="2">
 <tr>
  <td align="right"><input type="button" class="button" value="Go Back To Manage <?=$record_type;?>" onclick="window.location.href='manage-mails-active.php';"></td>
 </tr>
</table><br />
<form name="formn" method="post" action="" enctype="multipart/form-data" onsubmit="return validate(this);">
<?=$msg;?>
<li id="li_1" > 
		<label class="description" for="element_1"><input type="checkbox" id="selectall" onClick="selectAll(this)" />Select All</label> 
		<?php
		$sql_mailer="select * from newsletter_member";
		$qry=mysqli_query($dbconn,$sql_mailer);
		while($res=mysqli_fetch_array($qry))
		{
		?>
		<input type="checkbox" name="db[]" value="<?php echo $res['id'];?>" /><?php echo $res['email'];?><br />
		<?php
		}
		?>
		</li>	
<li id="li_1" > 
		<label class="description" for="element_1">Mail Subject</label> 
		<input id="name" name= "mailer_title" class="element text"  value="<?=$mailer_title;?>"/> 
		</li>	
		<li id="li_6" > 
		<label class="description" for="element_6">Mailer Reply ID</label> 
		<div> 
		<input id="cname" name="mailer_reply" class="element text medium" type="text"  value="<?=$mailer_reply;?>"/> 
		</div> 
		</li>		<li id="li_2" > 
		<label class="description" for="element_2">message </label> 
		<div> 
		<input id="message" name="message" class="element text medium" type="text" value="<?=$message;?>"/> 
		</div> 
		</li>		<li id="li_5" > 
		<label class="description" for="element_5">Email Code</label> 
		<div> 
		<textarea id="mailer_code" rows="10" cols="10" name="mailer_code" class="element textarea medium"><?=$mailer_code;?></textarea> 
		</div> 
		</li> 
  <td class="brdrbtm">
   <?php
   if($res['mailer_id']=="") {
	   ?>
	   <input type="submit" name="add_record" class="button" value="Add <?=$record_type;?>"><input type="hidden" name="action" value="add_record">
	   <?php	   
   }
   else{
	   ?>
	   <input type="submit" name="update_record" class="button" value="Update"><input type="hidden" name="action" value="update_record">
	   <input type="hidden" name="mailer_id" value="<?=$res['mailer_id'];?>">
	   <?php	   
   }
   ?>
   &nbsp;&nbsp;<input type="button" name="cancel" class="button" value="Cancel" onclick="javascript: window.location.href='<?=SITE_ADMIN_URL;?>/<?=$redirect_script_name;?>?parentID=<?=$parentID;?>&cityID=<?=$mailer_id;?>&start=<?=$start;?>&pagesize=<?=$pagesize;?>'">   
  </td>
 </tr>
</table>
</form>
<?php
admin_footer();	
exit;
?>