<?php require_once("inc/init.php"); ?>
<?php include 'controller/mailCode2.php'; ?>
<?php include 'controller/profileCode.php'; ?>
<h2 class="email-open-header">
	Reply to > <?php echo $opened_email[0]['subject']; ?><span class="label txt-color-white">inbox</span>
	<a href="javascript:void(0);" rel="tooltip" data-placement="left" data-original-title="Print" class="txt-color-darken pull-right"><i class="fa fa-print"></i></a>	
</h2>

<form enctype="multipart/form-data" action="" id="email-compose-form" method="POST" class="form-horizontal" onsubmit="return false;">

	<div class="inbox-info-bar no-padding">
		<div class="row">
			<div class="form-group">
				<label class="control-label col-md-1"><strong>To</strong></label>
				<div class="col-md-11">
					<select multiple style="width:100%" name="staff[]" id="staff" class="select2" data-select-search="true">
						<option value="<?php echo $opened_email[0]['user_from']; ?>" selected="selected"><?php echo $opened_email[0]['first_name'] . ' ' . $opened_email[0]['last_name']; ?></option>
						<?php 
						if($get_all_staff){
							foreach ($get_all_staff as $staff) {
								if($opened_email[0]['user_from']!=$staff['staff_id']){
						 ?>
						<option value="<?php echo $staff['staff_id']; ?>"><?php echo $staff['first_name'] . ' ' . $staff['last_name']; ?></option>
					<?php
				}
					 }
				}
					 ?>
					</select>
					<!-- <em><a href="javascript:void(0);" class="show-next" rel="tooltip" data-placement="bottom" data-original-title="Carbon Copy">CC</a></em>
 -->				</div>
			</div>
		</div>	
	</div>
	
<!-- 	<div class="inbox-info-bar no-padding hidden">
		<div class="row">
			<div class="form-group">
				<label class="control-label col-md-1"><strong>CC</strong></label>
				<div class="col-md-11">
					<select multiple style="width:100%" class="select2" data-select-search="true">
						<option value="sunny.orlaf@smartadmin.com">sunny.orlaf@smartadmin.com</option>
						<option value="rachael.hawi@smartadmin.com">rachael.hawi@smartadmin.com</option>
						<option value="michael.safiel@smartadmin.com">michael.safiel@smartadmin.com</option>
						<option value="alex.jones@infowars.com">alex.jones@infowars.com</option>
						<option value="oruf.matalla@gmail.com">oruf.matalla@gmail.com</option>
						<option value="hr@smartadmin.com">hr@smartadmin.com</option>
						<option value="IT@smartadmin.com">IT@smartadmin.com</option>
					</select>
					<em><a href="javascript:void(0);" class="show-next" rel="tooltip" data-placement="bottom" data-original-title="Blind Carbon Copy">BCC</a></em>
				</div>
			</div>
		</div>	
	</div> -->

<!-- 	<div class="inbox-info-bar no-padding hidden">
		<div class="row">
			<div class="form-group">
				<label class="control-label col-md-1"><strong>BCC</strong></label>
				<div class="col-md-11">
					<select multiple style="width:100%" class="select2" data-select-search="true">
						<option value="sunny.orlaf@smartadmin.com">sunny.orlaf@smartadmin.com</option>
						<option value="rachael.hawi@smartadmin.com">rachael.hawi@smartadmin.com</option>
						<option value="michael.safiel@smartadmin.com">michael.safiel@smartadmin.com</option>
						<option value="alex.jones@infowars.com">alex.jones@infowars.com</option>
						<option value="oruf.matalla@gmail.com">oruf.matalla@gmail.com</option>
						<option value="hr@smartadmin.com">hr@smartadmin.com</option>
						<option value="IT@smartadmin.com">IT@smartadmin.com</option>
					</select>
				</div>
			</div>
		</div>	
	</div> -->
	
	<div class="inbox-info-bar no-padding">
		<div class="row">
			<div class="form-group">
				<label class="control-label col-md-1"><strong>Subject</strong></label>
				<div class="col-md-11">
					<input class="form-control" placeholder="Email Subject" name="subject" type="text" value="<?php echo $opened_email[0]['subject']; ?>">
					<!-- <em><a href="javascript:void(0);" class="show-next" rel="tooltip" data-placement="bottom" data-original-title="Attachments"><i class="fa fa-paperclip fa-lg"></i></a></em> -->
				</div>
			</div>
		</div>	
	</div>

	<div class="inbox-info-bar no-padding hidden">
		<div class="row">
			<!-- <div class="form-group">
				<label class="control-label col-md-1"><strong>Attachments</strong></label>
				<div class="col-md-11">
					<input class="form-control fileinput" type="file" multiple="multiple">
				</div>
			</div> -->
		</div>	
	</div>
	
	<div class="inbox-message no-padding">
	
		<div id="emailbody">
			
		<?php echo $opened_email[0]['msg']; ?>

				
			</div>

		</div>	
	</div>
	
	<div class="inbox-compose-footer">

	<button class="btn btn-danger" type="button">
		Disregard
	</button>
		
	<button class="btn btn-info" type="button">
		Draft
	</button>
	<em><a href="javascript:void(0);" class="btn btn-sm btn-warning show_dropzone" rel="tooltip" data-placement="bottom" data-original-title="Attachments"><i class="fa fa-paperclip fa-lg"></i></a></em>

	<button data-loading-text="&lt;i class='fa fa-refresh fa-spin'&gt;&lt;/i&gt; &nbsp; Sending..." class="btn btn-primary pull-right" type="submit" id="send" name="mailer">
		Send <i class="fa fa-arrow-circle-right fa-lg"></i>
	</button>


	</div>

</form>
<div class="hidden inbox-message" id="show_dropzone">
<!-- 	<div class="col-md-2"></div>
 -->	<!-- <div class="col-md-9"> -->
		<form action="upload.php" enctype="multipart/form-data" class="dropzone" id="mydropzone"></form>
	<!-- </div>
	<div class="col-md-3"></div>
 -->
</div>
<div class="email-infobox">

<!-- 	<div class="well well-sm well-light">
		<h5>Related Invoice</h5>
		<ul class="list-unstyled">
			<li>
				<i class="fa fa-file fa-fw text-success"></i><a href="javascript:void(0);"> #4831 - Paid</a>
			</li>
			<li>
				<i class="fa fa-file fa-fw text-danger"></i><a href="javascript:void(0);"><strong> #4835 - Unpaid</strong></a>
			</li>
		</ul>


	</div>

	<div class="well well-sm well-light">
		<h5>Upcoming Meetings</h5>
		
		<p>
			<span class="label label-success"><i class="fa fa-check"></i> <strike>Agenda Review @ 10 AM</strike> </span>
		</p>

		<p>
			<span class="label label-primary"><i class="fa fa-clock-o"></i> Client Meeting @ 2:30 PM</span>
		</p>

		<p>
			<span class="label label-warning"><i class="fa fa-clock-o"></i> Salary Review @ 4:00 PM</span>
		</p>		
	</div>	

	<ul class="list-inline">
		<li><img src="img/avatars/5.png" alt="me" width="30px"></li>
		<li><img src="img/avatars/3.png" alt="me" width="30px"></li>
		<li><img src="img/avatars/sunny.png" alt="me" width="30px"></li>
		<li><a href="javascript:void(0);">1 more</a></li>
	</ul>
 -->
</div>
<script src="js/plugin/dropzone/dropzone.min.js"></script>
<script type="text/javascript">
	
	/* DO NOT REMOVE : GLOBAL FUNCTIONS!
	 *
	 * pageSetUp(); WILL CALL THE FOLLOWING FUNCTIONS
	 *
	 * // activate tooltips
	 * $("[rel=tooltip]").tooltip();
	 *
	 * // activate popovers
	 * $("[rel=popover]").popover();
	 *
	 * // activate popovers with hover states
	 * $("[rel=popover-hover]").popover({ trigger: "hover" });
	 *
	 * // activate inline charts
	 * runAllCharts();
	 *
	 * // setup widgets
	 * setup_widgets_desktop();
	 *
	 * // run form elements
	 * runAllForms();
	 *
	 ********************************
	 *
	 * pageSetUp() is needed whenever you load a page.
	 * It initializes and checks for all basic elements of the page
	 * and makes rendering easier.
	 *
	 */

	//pageSetUp();
	
	//here we only run
	runAllForms();

	 // PAGE RELATED SCRIPTS

	$(".table-wrap [rel=tooltip]").tooltip();

	/*
	 * SUMMERNOTE EDITOR
	 */
	loadScript("js/plugin/summernote/summernote.min.js", iniEmailBody);

	function iniEmailBody() {
	    $('#emailbody').summernote({
	        height: '100%',
	        focus: false,
	        tabsize: 2
	    });
	}
$('#parents').select2({
});

	$(".show-next").click(function () {
	    $this = $(this);
	    $this.hide();
	    $this.parent().parent().parent().parent().parent().next().removeClass("hidden");
	})

	$(".show_dropzone").click(function () {
	    $('#show_dropzone').toggle(function(){
	    	 $('#show_dropzone').removeClass("hidden");
	    });
	})

      //
      var Attachments = "";
      var i = 1;
	    	Dropzone.autoDiscover = false;
			$("#mydropzone").dropzone({
				url: "ajax/controller/mail_attatment.php?mA=",
				addRemoveLinks : true,
				maxFilesize: 0.5,
				dictDefaultMessage: '<span class="text-center"><span class="font-lg visible-xs-block visible-sm-block visible-lg-block"><span class="font-sm"><i class="fa fa-caret-right text-danger"></i><i class="fa fa-paperclip fa-lg"></i> Drop files <span class="font-xs">to upload</span></span><span>&nbsp&nbsp<h4 class="display-inline"> (Or Click)</h4></span>',
				dictResponseError: 'Error uploading file!',
				complete:function(response){
					
					if (response['name']) {
						i += 1;
						//console.log(response['name']);
						
					}
				},
				success:function(file,response){
					if (i) {
						Attachments += response+',';
					}else{
						Attachments += response;
					}
					// console.log(Attachments);

					
				}
			});

	    //
function loadInbox() {
			loadURL("ajax/email/email-list.php", $('#inbox-content > .table-wrap'))
		}
	 $("#email-compose-form").on('submit',function(){

	    var $btn = $('#send');
	    $btn.button('loading');



	    // wait for animation to finish and execute send script
	   // setTimeout(function () {
	        //Insert send script here
	        // $("#email-compose-form").on('submit',function(){
	        			   var form = new FormData($(this)[0]);
		   var form2 = new FormData($("#mydropzone")[0]);
// var data = new FormData(form); 
// var data2 = new FormData(form2); 
form.append('Attachments',Attachments);
form.append('msgBody',$('#emailbody').code());
   $.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: "ajax/controller/mail_intercepterCode.php",
            data: form,
            processData: false,
            contentType: false,
            cache: false,
            timeout: 600000,
beforeSend: function(response){
	//console.log(response);
    },
    complete: function(response){
     //  console.log(response);
    },
    success: function(response){
    	 if(response==1){
    		$.smallBox({
					title : "Mail not Sent!",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#C46A69",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    	}else if(response==2){
    		$.smallBox({
					title : "Mail Sent successfully",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#000000",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    		   // ReLoad inbox once send is complete
	        //loadURL("ajax/email-compose.php", $('#inbox-content > .table-wrap'));
    	}else if(response==200){
    		$.smallBox({
					title : "Mail Sent successfully",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#000000",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    		 // ReLoad inbox once send is complete
	        //loadURL("ajax/email-compose.php", $('#inbox-content > .table-wrap'));

    	}else if(response==500){
    		$.smallBox({
					title : "Mail not Sent!",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#C46A69",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    	}
    	else if(response==''){
    		$.smallBox({
					title : "Add receipient(s)!",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#C46A69",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    	}else{
    		$.smallBox({
					title : "System Error!",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#C46A69",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    	}
    	 //alert(response);
    },
    Error:function(response){
    	console.log(response);
    }

	   });
	       
   		
	// });



	     

	 //   }, 1000); // how long do you want the delay to be? 
	});
	

	
	
</script>
