<?php
	global $db,$amp_conf;
	$root_path = dirname(__FILE__);
    if(  @$_GET['receivesms'] ){ 
echo <<<EOF
<script type="text/javascript">
	$(function(){
		$("#sender").hide();
		$("#receiver").show();
	});
</script>
EOF;
    }
	
$line_counts = 10;

function show_msg($str){
	echo "<br/><br/><br/><br/><h2 style=\"text-align:center\">";
	echo $str;
	echo "</h2><br/><br/>";
}

/********************************************************************/
if($_POST) {	
	if(isset($_POST['sendmsg'])) {
		if($_POST['sendmsg'] == 'Delete') {
			if(isset($_POST['sms'])) {
				del_sms($_POST['sms']);
			}
		} else if($_POST['sendmsg'] == 'Clean Up') {
			del_all_sms();
		} else if($_POST['sendmsg'] == 'Export') {
			$export_to_excel = true;
		}
	}
}

/********************************************************************/
$cur_page = 1;
if(isset($_GET['current_page']) && is_numeric($_GET['current_page']))
	$cur_page = $_GET['current_page'];
else if(isset($_POST['current_page']) && is_numeric($_POST['current_page']))
	$cur_page = $_POST['current_page'];
	
/* filter */

$filter_sql = '';
$port_filter = "all";
$port_check = "";

if(isset($_GET['port_filter']))
	$port_filter = $_GET['port_filter'];
else if(isset($_POST['port_filter']))	
	$port_filter = $_POST['port_filter'];

if($port_filter != 'all' && $port_filter != ''){
	$port_array = explode(',',$port_filter);
	
	foreach($port_array as $key=>$port){
		//$port_check[$port] = "checked";
		//$bc = get_gsm_channel_by_name($port);
		//$port = get_gsm_value_by_channel($bc['channel'],$bc['board']);
		/*
		if($key == 0){
			$filter_sql = "where (port='".$port."'";
			if(strstr($port, $__BRD_HEAD__."1-")){	//find Board-1-gsm-? record
				$port = substr($port, -1);
				$filter_sql .= " OR port='".$port."'";
			}else if(strstr($port, $__BRD_HEAD__) < 0){	//find gsm-? record
				$port = $__BRD_HEAD__."1-".$__GSM_HEAD__.$port;
				$filter_sql .= " OR port='".$port."'";
			}
		}else{
			$filter_sql .= " OR port='".$port."'";
			if(strstr($port, $__BRD_HEAD__."1-")){	//find Board-1-gsm-? record
				$port = substr($port, -1);
				$filter_sql .= " OR port='".$port."'";
			}else if(strstr($port, $__BRD_HEAD__) < 0){	//find gsm-? record
				$port = $__BRD_HEAD__."1-".$__GSM_HEAD__.$port;
				$filter_sql .= " OR port='".$port."'";
			}
		}
		*/
		if($key == 0){
			$filter_sql = "where (port='".$port."'";
				$filter_sql .= " OR port='".$port."'";
		}else{
			$filter_sql .= " OR port='".$port."'";
		}

	}
	if($filter_sql != '')$filter_sql .= ")";
}
//var_dump( $filter_sql );
/* for stand alone mode and slave mode */
/*
$cluster_info = get_cluster_info();
if($cluster_info['mode'] != 'master' && $filter_sql == "") {
	$filter_sql  = "where (port='1' OR port='2' OR port='3' OR port='4'";
	$filter_sql .= " OR port='".$__BRD_HEAD__."1-".$__GSM_HEAD__."1'";
	$filter_sql .= " OR port='".$__BRD_HEAD__."1-".$__GSM_HEAD__."2'";
	$filter_sql .= " OR port='".$__BRD_HEAD__."1-".$__GSM_HEAD__."3'";
	$filter_sql .= " OR port='".$__BRD_HEAD__."1-".$__GSM_HEAD__."4'";
	$filter_sql .= ")";
}
*/

$phone_number_filter = "";
if(isset($_GET['phone_number_filter']))
	$phone_number_filter =  $_GET['phone_number_filter'];
else if(isset($_POST['phone_number_filter']))
	$phone_number_filter =  $_POST['phone_number_filter'];
	
if($phone_number_filter != '' && preg_match("/^[-+*_\d]*$/",$phone_number_filter)){
	$phone_number_filter_sql = str_replace('*', '%', $phone_number_filter);
	if($filter_sql == '')
		$filter_sql = "where phone like '%".$phone_number_filter_sql."%'";
	else
		$filter_sql .= " and phone like '%".$phone_number_filter_sql."%'";
}

$start_datetime_filter = "from";
if(isset($_GET['start_datetime_filter']))
	$start_datetime_filter = $_GET['start_datetime_filter'];
else if(isset($_POST['start_datetime_filter']))
	$start_datetime_filter = $_POST['start_datetime_filter'];
$start_datetime_filter = str_replace('/','-',$start_datetime_filter);

if($start_datetime_filter != 'from' && $start_datetime_filter != '') {
	if($filter_sql == '')
		$filter_sql = "where sendtime >= '".$start_datetime_filter."'";
	else
		$filter_sql .= " and sendtime >= '".$start_datetime_filter."'";
}

$end_datetime_filter = "to";
if(isset($_GET['end_datetime_filter']))
	$end_datetime_filter = $_GET['end_datetime_filter'];
else if(isset($_POST['end_datetime_filter']))
	$end_datetime_filter = $_POST['end_datetime_filter'];
$end_datetime_filter = str_replace('/','-',$end_datetime_filter);	

if($end_datetime_filter != 'to' && $end_datetime_filter != ''){
	if($filter_sql == '')
		$filter_sql = "where sendtime <= '".$end_datetime_filter."'";
	else
		$filter_sql .= " and sendtime <= '".$end_datetime_filter."'";
}
//echo $start_datetime_filter;
//echo $end_datetime_filter;
$message_filter = "";
if(isset($_GET['message_filter']))
	$message_filter = $_GET['message_filter'];
else if(isset($_POST['message_filter']))
	$message_filter = $_POST['message_filter'];
if($message_filter != ''){
	$message_array = preg_split("/[^0-9a-zA-Z\x{4e00}-\x{9fa5}]+/u", $message_filter);
	foreach($message_array as $message){
		if($message != ""){
			if($filter_sql == '')
				$filter_sql = "where message like '%".$message."%'";
			else
				$filter_sql .= " and message like '%".$message."%'";
		}
	}
}

/* sort */
$sort = '';
if(isset($_GET['sort']))
	$sort = $_GET['sort'];
if(isset($_POST['sort']))
	$sort = $_POST['sort'];

$order = '';
if(isset($_GET['order']))
	$order = $_GET['order'];
if(isset($_POST['order']))
	$order = $_POST['order'];

$sort_sql = 'order by `id` desc';
$port_class='sort';
$phonenumber_class='sort';
$time_class='sort';

$port_order = 'des';
$phonenumber_order = 'des';
$time_order = 'des';
switch($sort) {
case 'port':
	if($order == 'des') {
		$port_order = 'asc';
		$port_class = 'asc';
		$sort_sql = 'order by `port` asc';
	} else {
		$port_class = 'des';
		$sort_sql = 'order by `port` desc';
	}
	break;
case 'phone':
	if($order == 'des') {
		$phonenumber_order = 'asc';
		$phonenumber_class = 'asc';
		$sort_sql = 'order by `phone` asc';
	} else {
		$phonenumber_class = 'des';
		$sort_sql = 'order by `phone` desc';
	}
	break;
case 'time':
	if($order == 'des') {
		$time_order = 'asc';
		$time_class = 'asc';
		$sort_sql = 'order by `sendtime` asc';
	} else {
		$time_class = 'des';
		$sort_sql = 'order by `sendtime` desc';
	}
	break;
}

/* count */
$sql = "select count(*) from smsender_messages $filter_sql $sort_sql";
$res2 = $db->query($sql);

if($res2){
	$counts = $res2->fetchRow();
	$counts = $counts[0];
}else{
	$counts = 0;
}
$page_count = ceil($counts / $line_counts);

if($cur_page > $page_count) {
	$cur_page = $page_count;
}
$start_record = ($cur_page-1)*$line_counts;

function del_sms($sms_array){
	global $db,$amp_conf;
	$str="";
	$index = 0;

	foreach($sms_array as $key=>$id) {
		if( count($sms_array) > 1){
			if( $key == (count($sms_array)-1) ){
				$str .= "id=$id";
			}else{
				if(is_numeric($id)){
					$str .= "id=$id or ";
				}
			}
		}else{
			$id2 = $id +0;
			$str .= "id=$id2";
		}
	}
	
	if($str){
		$sql = 'delete from smsender_messages where '.$str;
		$db->query($sql);
	}
}

function del_all_sms(){
	//todo
	//$sql
	global $db,$amp_conf;
	$sql = 'delete from smsender_messages';
	$db->query($sql);
	/*
	global $smsinbox_file;
	global $db;
	if(!file_exists($smsinbox_file)) {
		return ;
	}
	$hlock = lock_file($smsinbox_file);
	//$db->try_query("delete from sms");
	$db->drop_alldata();
	unlock_file($hlock);
	*/
}

function export_excel(){
	
	global $db;
	global $amp_conf;
	global $filter_sql;
	global $sort_sql;	

	/*
	$output_name = 'smsinbox.xls';
	$all_time = trim(`date "+%Y:%m:%d:%H:%M:%S"`);
	$item = explode(':', $all_time, 6);
	
	if(isset($item[5])) {
		$year = $item[0];
		$month = $item[1];
		$date = $item[2];
		$hour = $item[3];
		$minute = $item[4];
		$second = $item[5];
		$output_name = "smsinbox-$year-$month-$date-$hour-$minute-$second.txt";
	}
	*/
	$date = date('Y-m-d-H-i-s',time());
	$output_name = "smsinbox-{$date}.txt";
	
	ob_clean();
	ob_end_clean();//这个要加上，不然会输出之前的东西
	//flush();
	
	//header('Content-Transfer-Encoding: binary');
	//header("Content-type:application/vnd.ms-excel");
	@header("Content-type: application/octet-stream"); 
	@header("Accept-Ranges: bytes"); 
	@header("Content-Disposition:attachment; filename=$output_name");
	//header("Content-Type: application/force-download");
	
	//Add UTF-8 BOM
	$utf8_bom = pack("C*",0xEF,0xBB,0xBF);
	echo $utf8_bom;
	
	//todo
	$sql="select * from smsender_messages $filter_sql $sort_sql";
	$res = $db->query($sql);
	$results='';
	
	while( $row = @$res->fetchRow() ){
		echo  $row[1].'	'.$row[2].'	'.$row[3].'	'.$row[4]."\r\n\r\n";
	}
	//flush();
	//ob_flush();

	if($results === false){
		echo "Database is busy now. Please try later.";
	}
	exit(0);
}

if(isset($export_to_excel) && $export_to_excel) {
	export_excel();
}
?>
	<script type="text/javascript">
	$(function() {
		$( "#start_datetime_filter" ).datetimepicker({dateFormat: "yy/mm/dd", timeFormat: "HH:mm:ss"});
		$( "#end_datetime_filter" ).datetimepicker({dateFormat: "yy/mm/dd", timeFormat: "HH:mm:ss"});
		$( "#start_datetime_filter" ).datetimepicker();	
		$( "#end_datetime_filter" ).datetimepicker();
		$("#port_table").css({"top":$("#port_filter").offset().bottom, "left":$("#port_filter").offset().left, "position":"absolute"});
		
		$("#port_filter").click(function(){
			if($("#port_table").css("display") == "none"){
				$("#port_table").css("display", "block"); 
			}else if($("#port_table").css("display") == "block"){
				$("#port_table").css("display", "none");
			}
			
			if( $(this).val() != 'all' ){
				var val_arr = $(this).val().split(',');
				
				$("[name='checkbox_name[]']").removeAttr("checked");
				$("[name='checkbox_name[]']").each(function(){

					for(var i=0;i<val_arr.length;i++){
						if( $(this).val() == val_arr[i] ){
							$(this).attr("checked",true);
						}
					}
				})
			}
			
		});

		$("#port_select").mouseleave(function(){
			$("#port_table").hide();
		});

		$("#check_all").click(function(){
			if($(this).attr("checked") == "checked"){ //check all
				$("#port_filter").attr("value", "all");
				$("input.port_check").each(function(){
					$(this).attr("checked",true);
				});
			}else{
				$("#port_filter").attr("value", "");
				$("input.port_check").each(function(){
					$(this).attr("checked",false);
				});
			}
		});

		$("#do_filter").click(function(){
			if(!check_filter()){
				return;
			}
			$("#port_filter_flag").attr("value", $("#port_filter").attr("value"));
			$("#phone_number_filter_flag").attr("value", $("#phone_number_filter").attr("value"));
			$("#start_datetime_filter_flag").attr("value", $("#start_datetime_filter").attr("value"));
			$("#end_datetime_filter_flag").attr("value", $("#end_datetime_filter").attr("value"));
			$("#message_filter_flag").attr("value", $("#message_filter").attr("value"));
			getpage(1);
		});

		$("#clean_filter").click(function(){
			$("#port_filter").attr("value", "all");
			$("#phone_number_filter").attr("value", "");
			$("#start_datetime_filter").attr("value", "from");
			$("#end_datetime_filter").attr("value", "to");
			$("#message_filter").attr("value", "");

			$("#current_page_flag").attr("value", 1);
			$("#port_filter_flag").attr("value", "all");
			$("#phone_number_filter_flag").attr("value", "");
			$("#start_datetime_filter_flag").attr("value", "from");
			$("#end_datetime_filter_flag").attr("value", "to");
			$("#message_filter_flag").attr("value", "");
			$("#sort_flag").attr("value", "");
			$("#order_flag").attr("value", "");
			
			$("[name='checkbox_name[]']").attr("checked",true);

		});

		$("#input_page").keypress(function(e){
			if(window.event){ // IE
				var keynum = e.keyCode;
			}else if(e.which){ // Netscape/Firefox/Opera
				var keynum = e.which;
			}

			if(keynum == 13) {
				var page = $("#input_page").attr("value");
				$("#current_page_flag").attr("value", page);
				getpage(page);
			}
		});

		$("form").keypress(function(e){
			if(window.event){ // IE
				var keynum = e.keyCode;
			}else if(e.which){ // Netscape/Firefox/Opera
				var keynum = e.which;
			}

			if(keynum == 13) {
				return false;
			}
		});
	});

	function getpage(page){
		//var url = 'http://172.16.8.121/?type=setup&display=smsender&menu=pbxconfig&receivesms=receivesms';
		var url = '/?display=smsender&receivesms=receivesms&';
	
		if(page == 0)
			page = document.getElementById("current_page_flag").value;
		if(page != '')
			url += "current_page="+page+"&";

		var port_filter = document.getElementById("port_filter_flag").value;
		if(port_filter != 'all'){
			url += "port_filter="+port_filter+"&";
		}
		
		var phone_number_filter = document.getElementById("phone_number_filter_flag").value;
		if(phone_number_filter != ''){
			url += "phone_number_filter="+encodeURIComponent(phone_number_filter)+"&";
		}
		
		var start_datetime_filter = document.getElementById("start_datetime_filter_flag").value;
		if(start_datetime_filter != 'from'){
			url += "start_datetime_filter="+encodeURIComponent(start_datetime_filter)+"&";
		}
		var end_datetime_filter = document.getElementById("end_datetime_filter_flag").value;
		if(end_datetime_filter != 'to'){
			url += "end_datetime_filter="+encodeURIComponent(end_datetime_filter)+"&";
		}
		
		var message_filter = document.getElementById("message_filter_flag").value;
		if(message_filter != ''){
			url += "message_filter="+encodeURIComponent(message_filter)+"&";
		}
		
		var sort = document.getElementById("sort_flag").value;
		if(sort != ''){
			url += "sort="+sort+"&";
		}
		var order = document.getElementById("order_flag").value;
		if(order != ''){
			url += "order="+order+"&";
		}
		
		window.location.href = url;
	}

	function sort_click(obj, type){
		document.getElementById("sort_flag").value=type;
		if(document.getElementById("order_flag").value == "des"){
			document.getElementById("order_flag").value = "asc";
		}else{
			document.getElementById("order_flag").value = "des";
		}
		getpage(0);
	}

	function set_check(check_obj,target_id){
		var target_obj = document.getElementById(target_id); 
		if(check_obj.checked == true){  
			if(target_obj.value == "all" || target_obj.value == ""){ 
				target_obj.value = check_obj.value; 
			}else{
				target_obj.value += "," + check_obj.value; 
			} 
		}else{
			if(target_obj.value == "all"){
				var inputs = document.getElementsByTagName("input");     
				for(var i=0;i<inputs.length;i++){
					if( (inputs[i].getAttribute("type")=="checkbox" || inputs[i].getAttribute("type")=="Checkbox") && inputs[i].getAttribute("name")=="checkbox_name[]" && inputs[i] != check_obj){
						inputs[i].checked = true;
						set_check(inputs[i],target_id);
					}
				}		
			}
			if(target_obj.value.indexOf("," + check_obj.value + ",") != -1){ 
				target_obj.value = target_obj.value.replace("," + check_obj.value,''); 
			}else if(target_obj.value.indexOf("," + check_obj.value) != -1){ 
				 target_obj.value = target_obj.value.replace("," + check_obj.value,''); 
			}else if(target_obj.value.indexOf(check_obj.value + ",") != -1){ 
				target_obj.value = target_obj.value.replace(check_obj.value + ",",''); 
			}else if(target_obj.value.indexOf(check_obj.value) != -1){ 
				target_obj.value = target_obj.value.replace(check_obj.value,''); 
			} 
		} 
	}

	function check_filter(){
		var phone_number = document.getElementById("phone_number_filter").value;
		var pattern = /^[-+*_0-9]*$/;
		var result = pattern.exec(phone_number);
		if(result != null){
			return true;
		}else{
			alert("invalid phone number!");
			return false;
		}
	}
	</script>
	<!-- Filter table -->
	<table width="100%" class="" style="table-layout:fixed;" >
		<tr>
			<th width='0%' class="nosort"></th>
			<th width='20%' class="nosort">Port</th>
			<th width='15%' class="nosort">Phone Number</th>
			<th width='25%' class="nosort">Time</th>
			<th width='40%' class="nosort">Message Keywords</th>
		</tr>
		<tr>
			<td colspan="2">
				<div id="port_select" style="zoom:1">
					<input type="text" id="port_filter" name="port_filter" style="width:95%;" value="<?php echo $port_filter;?>" readonly /> 
					<div> <!-- solve IE absolute position problem -->
						<table id="port_table" class="" style="display:none;overflow:hidden;background:#FFFFFF;" > 
							<?php
								for($i=1; $i<=11; $i++) {
									echo "<tr>";
									for($j=1;$j<=4;$j++){
										$name = 'gsm-'.$i.'.'.$j;
										echo "<td>&nbsp;&nbsp;";
										echo "<input type=\"Checkbox\" checked='checked' class=\"port_check\" name=\"checkbox_name[]\" value=\"".$name."\" onclick=\"set_check(this,'port_filter')\" />";
										echo $name;
										echo "</td>";
									}
									echo "</tr>";
								}
							?>
							<tr><td colspan=4>&nbsp; <input type="Checkbox" class="port_check" id="check_all" <?php if($port_filter == "all") echo "checked";?>>All</td></tr>
						</table>   
					</div>
				</div>
			</td>
			<td>
				<input type="text" id="phone_number_filter" name="phone_number_filter"  style='width:95%' value="<?php echo $phone_number_filter;?>" oninput="this.value=this.value.replace(/[^-+*_\d]*/g,'')">
			</td>
			<td>
				<input type="text" id="start_datetime_filter" name="start_datetime_filter" style='width:46%' value="<?php echo $start_datetime_filter;?>"/> 
				<input type="text" id="end_datetime_filter" name="end_datetime_filter" style='width:46%' value="<?php echo $end_datetime_filter;?>"/>
			</td>
			<td>
				<input type="text" id="message_filter" name="message_filter"  style='width:98%' value="<?php echo $message_filter; ?>">
			</td>
		</tr>
	</table>
	<br/>
	<input type="button" class="but" id="do_filter" value="Filter"/> 
	<input type="button" class="but" id="clean_filter" value="Clean Filter"/> 
	<br/>
	<br/>
	<br/>
	<div id="newline"></div>
	<!-- GSM SMS Inbox -->	
	<form id="mainform" enctype="multipart/form-data" action="" method="post">
	<?php
		$sql = "select * from smsender_messages $filter_sql $sort_sql limit $start_record, $line_counts";
		$results=$db->query($sql);
	
		if($counts > 0) {
			echo "<span style=\"font-weight:bold\">";
			echo 'Total Records';
			echo ": $counts";
			echo "</span>";
			$flag = 0;
	?>
	<table width="100%" class="">
		<tr>
			<th width='05%' style="text-align:left;"class="">
				<input type="Checkbox" name="selall" onclick="selectAll(this.checked,'sms[]')" />
			</th>
			<th width='15%' class="<?php echo $port_class?>" onclick="sort_click(this,'port')">Port</th>
			<th width='15%' class="<?php echo $phonenumber_class?>" onclick="sort_click(this,'phone')">Phone Number</th>
			<!-- <th width='15%' class="<?php echo $phonenumber_class?>" onclick="sort_click(this,'phonenumber')">Phone Number</th> -->
			<th width='25%' class="<?php echo $time_class?>" onclick="sort_click(this,'time')">Time</th>
			<th width='40%' class="nosort">Message</th>
		</tr>
		<?php
		if($results){
			while($res = $results->fetchRow() ) {
				$flag++;
		?>
		<tr>
			<td><input type="Checkbox" name="sms[]" id="sms_num" value="<?php echo $res[0]?>" /></td>
			<td class="pl5"><?php echo $res[1];?></td>
			<td class="pl5" ><?php echo $res[2];?></td>
			<td class="pl5" ><?php echo $res[4];?></td>
			<td> <textarea rows="3" style="width:99%;" readonly ><?php echo $res[3];?></textarea></td>
		</tr>
		<?php
			}
		}
		?>
	</table>
<?php
		if($flag == 0){
			show_msg('DATABASE BUSY');
		}
	}

	/* page selector */
	if($page_count >= 2) {
		echo '<br/>';
		echo '<div class="pg">';

		if( $cur_page > 1 ) {
			$page = $cur_page - 1;
			echo "<a title=\"";
			echo 'Previous page';
			echo "\" style=\"cursor:pointer; margin:1px 3px;\" class=\"prev\" onclick=\"getpage($page)\"></a>";
		} 
			
		if($cur_page-5 > 1) {
			$s = $cur_page-5;
		} else {
			$s = 1;
		}

		if($s + 10 < $page_count) {
			$e = $s + 10;
		} else {
			$e = $page_count;
		}

		for($i = $s; $i <= $e; $i++) {
			if($i != $cur_page) {
				echo "<a onclick=\"getpage($i)\" style=\"cursor:pointer;margin:1px 4px;\">$i</a>";
			} else {
				echo "<strong>$cur_page</strong>";
			}
		}

		if( $cur_page < $page_count ) {
			$page = $cur_page + 1;
			echo "<a title=\"";
			echo 'Next page';
			echo "\" style=\"cursor:pointer;;margin:1px 4px;\" class=\"nxt\" onclick=\"getpage($page)\"></a>";
		} 
		echo "<label>";
		echo "<input type=\"text\" id=\"input_page\" name=\"page\" value=\"$cur_page\" size=\"2\" class=\"px\"  title=\"";
		echo 'input page help','Please input your page number, and press [Enter] to skip to.';
		echo "\" >";
		echo "<span title=\"";
		echo 'total pages';
		echo ": $page_count\"> / $page_count</span>";
		echo "</label>";
		echo "<a title=\"";
		echo 'goto input page';
		echo "\" style=\"cursor:pointer;;margin:1px 4px;\" onclick=\"getpage(document.getElementById('input_page').value)\">";
		echo "go";echo "</a>";
		echo '</div>';
	}else if ($page_count == 1){
		echo '<br/>';
		echo '<div class="pg">';
		echo "<strong>1</strong>";
		echo '</div>';
	}

	if($counts > 0) {
?>
	<div id="newline"></div>
	<br/>

	<input type="hidden" name="sendmsg" id="sendmsg" value="" />
	<input type="submit" value='Delete'   onclick="document.getElementById('sendmsg').value='Delete';return confirm('Are you sure to delete you selected ?')"/> 
	<input type="submit" value='Clean Up' onclick="document.getElementById('sendmsg').value='Clean Up';return confirm('Are you sure to delete all smss ?')"/> 
	<input type="submit" value='Export'   onclick="document.getElementById('sendmsg').value='Export';"/>
<?php
	}
?>
	<input type="hidden" id="current_page_flag" name="current_page" value="<?php echo $cur_page;?>" />
	<input type="hidden" id="port_filter_flag" name="port_filter" value="<?php echo $port_filter;?>" />
	<input type="hidden" id="phone_number_filter_flag" name="phone_number_filter" value="<?php echo $phone_number_filter;?>" />
	<input type="hidden" id="start_datetime_filter_flag" name="start_datetime_filter" value="<?php echo $start_datetime_filter;?>" />
	<input type="hidden" id="end_datetime_filter_flag" name="end_datetime_filter" value="<?php echo $end_datetime_filter;?>" />
	<input type="hidden" id="message_filter_flag" name="message_filter" value="<?php echo $message_filter;?>" />
	<input type="hidden" id="sort_flag" name="sort" value="<?php echo $sort;?>" />
	<input type="hidden" id="order_flag" name="order" value="<?php echo $order;?>" />
	</form>
	<div id="newline"></div>
<script type="text/javascript">
$(document).ready(function(){
	$("textarea").each(function(){
		$(this).css("height", this.scrollHeight);
	});
	
	$("[name='checkbox_name[]']").change(function(){
		
	})
});
</script>