<?php $this->load->view("main/drs/header"); ?>
<style>
	textarea{
		resize: none;
		height: 200px !important;
	}
	.right *{
		float: left;
	}
	.right input{
		margin-right:10px;
	}
	.messagers{
		padding-bottom:30px;
	}
	.display_message{
	   width: 100%;
	   height: 100%;
	   position: fixed;
	   top: 0;
	   left: 0;
	   z-index: 3000;
	   background: rgba(0,0,0,0.5);
}
</style>
<div class="display_message" style="display: none;">
	   <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                                <h4 class="modal-title">نمایش پیام</h4>
                                            </div>
                                            <div class="modal-body">

                                               
												 <input type="hidden" id="tellid" name="path" value="123312321423">
												
												 
												
										  
										   <div id="piture">
                                                    <div class="form-group">
                                                        <div class="col-lg-12 row"><label for="exampleInputFile">نام و نام خانوادگی:</label><span class="nameho"></span></div>
														<div class="col-lg-12 row"><label for="exampleInputFile">متن پیغام:</label><p class="textho"></p></div>
                                                    </div>
                                            </div>       
                                                
                                            </div>
                                        </div>
                                    </div>
</div>
<div class="col-lg-12">
<section class="panel">
        <header class="panel-heading">پیام های مشاوره</header>
		 <div class="panel-body">
			<div class="alert alert-success fade in" style="display:none">
                                    <button class="close close-sm" type="button" data-dismiss="alert">
                                        <i class="icon-remove"></i>
                                    </button>
                                    پیام شما با موفقیت فرستاده شد.
                             
                                </div>
			<div class="messagers">
				<div class="form-group">
                                        <label for="idcontant">تلگرام ایدی</label>
                                        <input class="form-control" id="idcontant" type="text">
                                    </div>
				<div class="form-group">
                                        <label for="exampleInputEmail1">متن پیام</label>
                                        <textarea class="form-control masseage_content"></textarea>
                                    </div>
				<button class="btn btn-info sendmessage">فرستادن پیام</button>
			</div>
			
			<table class="table table-striped border-top dataTable" id="sample_1" aria-describedby="sample_1_info">
                                <thead>
                                    <tr role="row">
                                        <th tabindex="0" class="sorting" role="columnheader" aria-controls="sample_1" style="width: 214px;" aria-label="Username: activate to sort column ascending" rowspan="1" colspan="1">ای دی تلگرام</th>
										<th tabindex="0" class="hidden-phone sorting" role="columnheader" aria-controls="sample_1" style="width: 401px;" aria-label="Email: activate to sort column ascending" rowspan="1" colspan="1">نام و نام خانوادگی</th>

										<th tabindex="0" class="hidden-phone sorting" role="columnheader" aria-controls="sample_1" style="width: 219px;" aria-label=": activate to sort column ascending" rowspan="1" colspan="1"></th></tr>
                                </thead>
                                
                            <tbody role="alert" aria-live="polite" aria-relevant="all">
								<?php $count=1; foreach($messages as $value){ ?>
								<?php if($count == 1){ ?>
								<tr class="gradeX odd">
								<?php }else{ ?>
								<tr class="gradeX even">
								<?php } ?>
								
                                <td class="sorting_1"><?php echo $value->tellid ?></td>
                                        <td><?php echo $value->fullname ?></td>
                                        <td class="icons">
											<input type="hidden" class="message_continer" value="<?php echo $value->message ?>">
											<button class="btn btn-success btn-xs"><i class="icon-mail-reply"></i></button></a>
											<button class="btn btn-warning btn-xs"><i class="icon-eye-open"></i></button></a>
											<button class="btn btn-danger btn-xs" style="display: none;"><i class="icon-minus-sign"></i></button></a>
											<button class="btn btn-danger btn-xs" data_id="<?php echo $value->id; ?>" href="#myModal-1" data-toggle="modal"><i class="icon-trash "></i></button>
										</td>
										
                                    </tr>
								<?php } ?>
                                    </tbody></table>
		 </div>
</section>
<?php $this->load->view("main/drs/footer"); ?>
<script>
	$(".btn-success").click(function(){
		$(".alert-success").css({"display":"none"});
		$message = $(this).parent().find("input").val();
		$text = "سوال:";
		$text += $message;
		$text += "\n";
		$text += "................................";
		$text += "\n";
		$text += "پاسخ:";
		$(".masseage_content").val($text);
		$id = $(this).parent().parent().find(".sorting_1").text();
		$("#idcontant").val($id);
		});
	$(".close").click(function(){
		$(".display_message").css({"display":"none"});
		});
	$(".btn-warning").click(function(){
		$message = $(this).parent().find("input").val();
		$fullname = $(this).parent().parent().find("td").eq(1).text();
		$(".nameho").text($fullname);
		$(".textho").text($message);
		$(".display_message").css({"display":"block"});
		});
	$(".btn-danger").click(function(){
		$id = $(this).attr("data_id");
		$value = $(this).parent().parent();
	$.post("<?php echo base_url() ?>panel/delete_messages",{"id":$id},function(e){
		if (e == "done") {
			$value.remove();
		}
		});
		
		});
	$(".sendmessage").click(function(){
 var $id = $("#idcontant").val();
 var $message = $(".masseage_content").val();
 $.post("<?php echo base_url(); ?>panel/send_message",{"tellid":$id,"message":$message},function(e){
	if(e == "done"){
	$(".alert-success").css({"display":"block"});
	}
	});

		});
</script>