<?php include("../../check.php"); ?>
<!DOCTYPE html>
<html>
    <head>
        <!-- Stylesheet file -->
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <?php include("../common/head.php") ?>
    </head>
    <body class="fixed-navbar fixed-sidebar">
        <?php include("../common/header.php") ?>
        <?php include("../common/aside.php") ?>
        <div id="wrapper">
            <div class="small-header transition animated fadeIn">
                <div class="hpanel">
                    <div class="panel-body">
                        <div id="hbreadcrumb" class="pull-right">
                            <ol class="hbreadcrumb breadcrumb">
                                <li><a href="<?php print $baseurl; ?>welcome/master/addEdit.php"><button class="btn btn-info " type="button"><i class="fa fa-paste"></i> Add Pages</button></a></li>
                                <li><a href="<?php print $baseurl; ?>welcome/master/customer.php"><button class="btn btn-success " type="button"><i class="fa fa-list"></i> <span class="bold">All Pages Show</span></button></a></li>
                            </ol>
                        </div>
                        
                        <h2 class="font-light m-b-xs"><button class="btn btn-orange " type="button"><strong class="emailmsg" >Message:- <?= $_SESSION['message']; unset($_SESSION['message']);?></strong>
                        
                        
                        </button></h2>
                    </div>
                </div>
            </div>
            <div class="content animate-panel">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="hpanel">
                            
                            <div class="panel-body">
                                
                                <form name="bulk_action_form" action="#" method="post" onSubmit="return deleteConfirm();"/>
                                    <table id="example2" class="table table-striped table-bordered table-hover" width="100%" style="font-size:12px;">
                                        <thead class="thead-dark">
                                            <tr>
                                                <th width="2%"></th>
                                                <th width="7%">Created</th>
                                                <th width="7%">Name</th>
                                                <th width="7%">Body</th>
                                                <th width="14%">Standard</th>
                                                <th width="19%">Send to Email</th>
                                                <th width="8%">Status</th>
                                                <th width="18%">Action</th>
                                                <th>Download</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                            $j=1;
                                            $sess_id = $_SESSION['user_id'];
                                            $getall = $getData->runQuery("SELECT * FROM `customer` WHERE master_id='$sess_id'");
                                            foreach($getall as $rows){
                                            
                                            $dataaa = $rows['standard'];
                                            $result = explode(',',$dataaa);
                                            $counts = count($result);
                                            
                                            ?>
                                            <tr>
                                                <td><?= $j++;?></td>
                                                <td><?= date("d M Y h:i:s A", strtotime($rows['date']));?></td>
                                                <td><?= $rows['name']?></td>
                                                <!--  -->
                                                <?php
                                                    $body = $rows['body'];
                                                    $getallb = $getData->runQuery("SELECT * FROM `bodies_tbl` where id=$body");
                                                ?>
                                                <!--  -->
                                                <td><?= $getallb[0]['title']?></td>
                                                
                                                <td>
                                                    <?php
                                                    for($i=0; $i < $counts; $i++){
                                                    $getalls = $getData->runQuery("SELECT * FROM `standard_tbl` where id='".$result[$i]."'");
                                                    echo $getalls[0]['title']."<br>";
                                                    }?>
                                                </td>
                                                
                                                <!-- <td onCLick="send_email('<?= $rows['id']?>')" ><a href="javascript:void(0)"><img src="../images/email.png" ></a></td> -->
                                                <td onclick="form(<?php echo $rows['body']; ?>)" ><a href="javascript:void(0)" ><img src="../images/email.png" ></a></td>
                                                
                                                <td class="status_<?= $rows['id']?>" onClick = 'status("<?= $rows['id']?>")'><?php if($rows['status'] == "A"){ echo '<span class="badge badge-success">Active</span>'; }elseif($rows['status'] == "I"){ echo '<span class="badge badge-danger">Inactive</span>'; } ?></td>
                                                <td>
                                                    <a href="addEdit.php?edit=<?= $rows['id']?>" class="btn btn-primary">edit</a>
                                                    <a href="postAction_customer.php?del=<?= $rows['id']?>" class="btn btn-danger" onclick="return confirm('Are you sure to delete data?')?true:false;">Delete</a>
                                                </td>
                                                <td>
                                                    <?php
                                                    for($i=0; $i < $counts; $i++){
                                                    $getalls = $getData->runQuery("SELECT * FROM `standard_tbl` where id='".$result[$i]."'");?>
                                                    <a target="_blank" href="pdf.php?id=<?php echo $rows['id']?>&st=<?php echo $getalls[0]['title']?>&body=<?php echo $rows['body']?>">Click Here</a><br>
                                                    <?php } ?>
                                                    
                                                </td>
                                            </tr>
                                            <?php } ?>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                        </div>
                        
                    </div>
                </div>
            </div>
            <div class="modal fade" id="myModal" role="dialog">
                <div class="modal-dialog">
                    
                    <!-- Modal content-->
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title">Email Certificate</h4>
                        </div>
                        <div class="modal-body">
                            <form action="pdf.php">
                                <div class="form-group">
                                    <input type="hidden" name="id" value="<?php echo $rows['id']; ?>">
                                    <input type="email" name="email" class="form-control">
                                    <input type="hidden" name="mail" value="true">
                                    <input type="hidden" name="body" id="boddy">
                                </div>
                                <div class="form-group">
                                    <select class="form-control " name="st" id="stand">
                                        <option value=""> -- Select Standard -- </option>
                                         <?php
                                        for($i=0; $i < $counts; $i++){
                                        $getalls = $getData->runQuery("SELECT * FROM `standard_tbl` where id='".$result[$i]."'");?>
                                            <option value="<?php echo $getalls[0]['title']?>" ><?php echo $getalls[0]['title']?></option>
                                        <?php }
                                         ?>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <button type="submit" name="submit" class="btn btn-success">Submit</button>
                                </div>
                            </form>
                        </div>
                    </div>
                    
                </div>
            </div>
            <?php include("../common/footer.php") ?>
        </div>
        <?php include("../common/js.php") ?>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
        <script>
            
        $(function () {
        // Initialize Example 1
        $('#example2').dataTable( {
        
        dom: "<'row'<'col-sm-4'l><'col-sm-4 text-center'B><'col-sm-4'f>>tp",
        "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
        buttons: [
        {extend: 'copy',className: 'btn-sm'},
        {extend: 'csv',title: 'ExampleFile', className: 'btn-sm'},
        {extend: 'pdf', title: 'ExampleFile', className: 'btn-sm'},
        {extend: 'print',className: 'btn-sm'}
        ]
        });
        // Initialize Example 2
        $('#example1').dataTable();
        });
        function status(id){
        $.ajax({
        url:'postAction_customer.php',
        type:'POST',
        data:{'status':id},
        success:function(data){
        $(".status_"+id).html(data);
        }
        });
        }
        function send_email(id){
        //alert(id);
        //return false;
        var table = "customer";
        $.ajax({
        url:'../../email.php',
        //url:'email.php',
        type:'POST',
        data:{'id':id,'table':table},
        success:function(data){
        $(".emailmsg").html(data);
        }
        });
        }
        function  form(id) {
            document.getElementById('boddy').value=id;
            $("#myModal").modal('show')
        }
        </script>
    </body>
</html>