<?php  session_start(); error_reporting(0); ?>
<?php if(!isset($_SESSION['j_admin'])){ 
    $url = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); header('location:../login/?url='.$url.'');  
} ?>
<!doctype html>
<html lang="en"> 
<head>
	<?php
    require_once("../j_conn/url.php");
    require_once("../j_conn/dbc.php");
    require_once("../j_incs/functions.php");
    $page_name="Compose Message";
    $page_desc="$page_name";
    $page_img="".$dir."j_files/j_img/logo/logo-meta.png";
    $page_author="$company";
    $page_keywords="".$company.", $page_name, $page_desc, ".$company_motto.", $company_desc";
    $page_url="".$dir."compose-mail/";
    require_once("../j_incs/metas.php");
    require_once("../j_incs/scripts-top.php");
    ?>
</head>
<body>
    
    <div class="app">
        <div class="layout">
            <?php 
            require_once("../j_incs/header.php");
            require_once("../j_incs/nav.php");
            ?>
            <!-- Page Container START -->
            <div class="page-container">
                

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="page-header">
                        <h2 class="header-title"><?php echo $page_name; ?></h2>
                        <div class="header-sub-title">
                            <nav class="breadcrumb breadcrumb-dash">
                                <a href="<?php echo $dir; ?>" class="breadcrumb-item"><i class="anticon anticon-dashboard m-r-5"></i>Dashboard</a>
                                <!--<a class="breadcrumb-item" href="#"> </a>-->
                                <span class="breadcrumb-item active"><?php echo $page_name; ?></span>
                            </nav>
                        </div>
                    </div>
                     
                    <div class="container">
                        <div class="tab-content m-t-15">
                            <div class="tab-pane fade show active" id="tab-account">
                                
                                
                                <div class="card">
                                    <div class="card-header">
                                        <p>
											 Send Messages to some Users.
											 <br/>
											 You can make use of some pre-defined variables in your message.
											<br/>
											<a href="javascript:void()" class="p_desc_toggle">SHOW VARIABLES</a>
                                        </p>
										<div class="p_desc form_hide" style="display:none !important;">
											<br/>
											<b>{{name}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">User's Name</span><br/>
											
											<b>{{email}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">User's Email Address</span><br/>
											
											<b>{{phone}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">User's Mobile Number</span><br/>
											
											<b>{{username}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">User's Username</span><br/>
											
											<b>{{company}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">Company's Name</span><br/>
											
											<b>{{company_motto}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">Company's Motto or Slogan</span><br/>
											
											<b>{{company_address}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">Company's Office Address</span><br/>
											
											<b>{{company_email}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">Company's Email Address</span><br/>
											
											<b>{{company_phone}}</b>&nbsp; &nbsp;= &nbsp; &nbsp;<span class="text_sm_gray">Company's Phone Number</span><br/>
										</div>
                                    </div>
                                    <div class="card-body">
                                        <form action="" method="post" id="form" enctype="multipart/form-data">
                                            <div class="row mb-50 ">
                                             
											<div class="form-group mb-50 col-lg-7">
												<!--<label class="font-weight-semibold"> Account Number </label>-->
												<input autofocus autocomplete="off" type="text" class="form-control rMe" name="re_username" placeholder="Username"/>
												<a href="#0" class="app_btn add_user">Add User</a>
											</div>


											<div class="form-group mb-50 col-lg-7">
												<label class="font-weight-semibold">Name: <b id="re_name"></b>
												</label>
											</div>
											
											<div class="form-group mb-50 col-lg-7">
                                                <label class="text-bold-600" for="title"> Recipient(s) </label>
                                                <input type="text" class="form-control rMe" name="users_id" placeholder="Enter Username">
                                            </div>
											
                                            <div class="form-group mb-50 col-lg-7">
                                                <label class="text-bold-600" for="title"> Subject </label>
                                                <input type="text" class="form-control rMe" name="subject" placeholder="Enter Subject">
                                            </div>
                                                
                                                
                                            <div class="form-group mb-50 col-lg-12">
                                                <label class="text-bold-600" for="title"> Message </label>
                                                <textarea rows="6" name="desc" class="form-control" placeholder="Type Message here..."></textarea>
                                                <?php /*<div id="mail-compose-editor" class="form-control rMe" ></div>*/ ?>
                                            </div>
                                                
                                            
                                            

                                            <div class="form-group col-lg-6">
                                                <label class="text-bold-600" for="old_password"> Enter your Password</label>
                                                <input type="password" class="form-control rMe" name="old_password" placeholder="Enter Password">
                                            </div>

                                            </div>

                                            <div class="row mb-50 ">
                                                <div class="col-lg-6 mb-50 ">
                                                    <button type="submit" id="submit" class="btn btn-primary glow w-100 position-relative"> Send Message Now <i id="icon-arrow" class="fa fa-arrow-right"></i></button>
                                                </div>
                                            </div>

                                        </form>
                                        <br/>
                                        <div id="formresult"></div>
                                        
                                        
                                        
                                    </div>
                                </div>
                             
                            </div>
                            
                        </div>
                    </div>
                </div>
                <!-- Content Wrapper END -->

                <?php
                require_once("../j_incs/footer.php");
                ?>

            </div>
            <!-- Page Container END -->
        </div>
    </div>
    
    
    <?php
    require_once("../j_incs/scripts-bottom.php");
    ?>    
    
    <script>
		$('.add_user').click(function(){
			var user_val = $("[name=re_username]").val();
			var users_val = $("[name=users_id]").val();
			var new_users_val = ""+users_val+""+user_val+",";
			$("[name=users_id]").val(new_users_val);
		});
		
		$('.p_desc_toggle').click(function(){
			var input = $(this).text();
			if(input=="SHOW VARIABLES"){
				$('.p_desc_toggle').text('HIDE VARIABLES');
				$('.p_desc').slideDown(3000);	
			}else{
				$('.p_desc').hide();	
				$('.p_desc_toggle').text('SHOW VARIABLES');
			}

		});
		
		$("[name=re_username]").keyup(function () {
        var  re_username_id = $("[name=re_username]");
        var  re_username = re_username_id.val();
        var  re_name_id = $("#re_name");
        if(re_username !==''){
            re_name_id.html('***');
            $.post('re-name.php', 
            {
                re_username:re_username
            },function(data){
                if(data){
                   re_name_id.html(data);
                }else{
                    re_name_id.html('');
                }
            });
        }else{
			re_name_id.html('');
		}
    });
	
        var form = "#form";
        var button = "#submit";
        var button_val = $(button).html();
        var result = "#formresult";
        
        $(button).click(function() {
           //var desc = $(".ql-editor").html(); 
           //$("[name=desc]").html(desc); 
        });
        
        $(form).on('submit',(function(e) {
        e.preventDefault();
        $(button).attr('disabled', '');
        $(button).html("<i class='anticon anticon-loading'></i> Processing");
        $(result).html("<div class='alert alert-warning'> Taking too long? <a href=''>Reload </a></div>");
         $.ajax({
        url: "save.php",
        type: "POST",
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
        success: function(data)
        {
        if(data){
         $(button).removeAttr('disabled');
        $(button).html(button_val);
        $(result).html(data);
        }else{
        $(result).html("Error occurred.");
        $(button).removeAttr('disabled');
        $(button).html(button_val);
        }
        }
        });
        }));
        </script>
        
   
</body>
</html>