<?php 
ob_start();
ini_set("display_errors", "1");
error_reporting(E_ALL);

require_once 'PHPMailerAutoload.php';
include "../dbconfig.php";


?>






<!DOCTYPE html>
<html>
<head>
  <title></title>
  <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

<!------ Include the above in your HEAD tag ---------->
<style>
    
    body{
    background: -webkit-linear-gradient(left, #0072ff, #00c6ff);
}
.contact-form{
    background: #fff;
    margin-top: 10%;
    margin-bottom: 5%;
    width: 70%;
}
.contact-form .form-control{
    border-radius:1rem;
}
.contact-image{
    text-align: center;
}
.contact-image img{
    border-radius: 6rem;
    width: 11%;
    margin-top: -3%;
    transform: rotate(29deg);
}
.contact-form form{
    padding: 14%;
}
.contact-form form .row{
    margin-bottom: -7%;
}
.contact-form h3{
    margin-bottom: 8%;
    margin-top: -10%;
    text-align: center;
    color: #0062cc;
}
.contact-form .btnContact {
    width: 50%;
    border: none;
    border-radius: 1rem;
    padding: 1.5%;
    background: #dc3545;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
}
.btnContactSubmit
{
    width: 50%;
    border-radius: 1rem;
    padding: 1.5%;
    color: #fff;
    background-color: #0062cc;
    border: none;
    cursor: pointer;
}
</style>
  
  
</head>
<body>

        

<div class="container contact-form">
            <div class="contact-image">
                <img src="https://image.ibb.co/kUagtU/rocket_contact.png" alt="rocket_contact"/>
            </div>
            
            
            
            
            
            <?php 
            
               
                             if(isset($_POST['checkbox'])){
                                 
                                ?>
                                
                            <script>
                                $(document).ready(function(){
                                swal({
                              title: "Do You Want Create new Campaign List ",
                              text: "Or You want use same and campaign List",
                              icon: "success",
                              buttons: [
                                'No, cancel it!',
                                'Yes, I am sure!'
                              ],
                              dangerMode: true,
                            }).then(function(isConfirm) {
                              if (isConfirm) {
                                 
                                 $("#list_old").css('display','none');
                                   $("#list").css('display','block');
                                 
                              } else {
                                swal("Cancelled", "Enter New List :)", "error");
                                 
                              }
                            })
                            
                          
                                })
                           
                            </script>    
                                
                                <?php 
                                 
                                 
                             }
            ?>
            
            
        
            
            
            <form method="post" id = "new" action = "sent_email.php" >
                <h3>Send Email For New Campaign</h3>
               <div class="row">
                    <div class="col-md-12">
                        
                         <div class="form-group">
                             <?php
                               $query = "SELECT * FROM list_name";
                               $result = mysqli_query($con,$query);?>
                           <select class="form-control" id ="list_old" name ="list_old">
                               <option >Select Campaign List </option>
                              <?php
                               while($row = mysqli_fetch_assoc($result)){
                                  
                                  ?>
                                  <option value = "<?php echo $row['id'] ?>"><?php echo $row['list_name'] ?></option>
                                  
                                  <?php
                                
                               }
                               
                              
                               ?>
                        </div>
                        
                    
                        <div class="form-group">
                            <input type="text" id="list" name="list_name" class="form-control" placeholder="List Name" value="" style="display:none"/ >
                        </div>
                         <div class="form-group">
                           <ul>
                             <input type="hidden" name = "checkbox" value="<?php echo implode(",",$_POST['checkbox'])?>">
                         <?php 
                         if(isset($_POST['checkbox'])){
                                 
                                 $id = $_POST['checkbox'];
                                 
                                 
                                 $arr = array();
                                   foreach($id as $value){
                                       $query = "select * from client_admin where id = $value";
                                       $result = mysqli_query($con,$query);
                                     
                                       $row  = mysqli_fetch_assoc($result);
                                       $arr[] = $row['email'];
                                   }
                                   foreach($arr as $key => $value){
                                      ?>
                             <li>
                                <label><input type="text" name = "<?php echo $key?>" style="border: none; border-width: 0; box-shadow: none;" value="<?php echo $value?>"></label>
                                <button class="btn btn-danger btn-sm">X</button>
                            </li>
                                      <?php
                                   }
                         }
                                  ?>   
                        </ul>
                      
                        </div>
                         <div class="form-group">
                            <input type="text" id="subject" name="subject" class="form-control" placeholder="subject" value="" / >
                        </div>
                         <div class="form-group">
                            <?php
                             if(isset($_POST['checkbox'])){
                                 
                             }else{
                                 ?>
                                 <table class="table table-bordered" id="dynamic_field" style="border:none">  
                                    <tr>  
                                         <td><input type="email" name="name[]" placeholder="Enter your Email" class="form-control name_list" /></td>  
                                         <td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>  
                                    </tr>  
                               </table>  
                              
                       <?php
                             }
                            
                            ?>
                            
                            
                        </div>
                        
                        <div class="form-group"> 
                         <?php
                               $query = "SELECT * FROM email_template";
                               $result = mysqli_query($con,$query);?>
                           <select class="form-control" id ="template" name ="template_art">
                               <option >Select Campain </option>
                              <?php
                               while($row = mysqli_fetch_assoc($result)){
                                   
                                  ?>
                                  <option value = "<?php echo $row['id'] ?>"><?php echo $row['campaign_name'] ?></option>
                                  
                                  <?php
                                
                               }
                               
                              
                               ?>
                               
                           </select>
                        </div>
                        
                         <div class="col-md-12">
                        <div class="form-group" id ="show">
                            
                       </div>
                    </div>
                        <div class="form-group">
                              <?php
                             if(isset($_POST['checkbox'])){?>
                                 <input type="submit" name="sent_all" class="btnContact" value="Send Message" />
                           <?php  }else{
                                 ?>
                                 
                               <input type="submit" name="sent" class="btnContact" value="Send Message" />
                       <?php
                             }
                            
                            ?>
                            
                        </div>
                    </div>
                   
                </div>
            </form>
</div>

<script>
    $(document).ready(function(){
        $("ul").on("click", "button", function(e) {
    e.preventDefault();
    $(this).parent().remove();
});

 $("#template").on("change",function(){
     var template_id = $(this).val();
     $.post("page.php",{template_id:template_id},function(data){
                  $("#show").html(data);
                })  
})
var i=0;  
      $('#add').click(function(){  
           i++;  
           $('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');  
      });  
      $(document).on('click', '.btn_remove', function(){  
           var button_id = $(this).attr("id");   
           $('#row'+button_id+'').remove();  
      });  
    })
    
</script>
</body>
</html>

