<link rel="stylesheet" href="<?php echo base_url();?>assets/js/validationEngine.jquery.css" type="text/css" />
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/cust_paginition.css" type="text/css" />
<div class="layout-app">
<div class="container">
<div class="row row-app">
    <div class="col-md-12">
        <div class="col-md-12">
            <?php if (!isset($allMagazines)) {?>
                <div class="widget">
                    <div class="widget-head">
                        <h4 class="heading">Upload ExcelSheet</h4>

                    </div>
                    <h5 align = "left">
                        <h4 class="heading" style="color: sienna;margin-left: 10px"></h4>
                        <lable style="color:red"><?php echo validation_errors(); ?> </lable>
                        <lable style="color:red"><?php echo $error; ?> </lable>
                    </h5>
                    <div class="widget-body innerAll inner-2x">
                        <form id="fileupload" action="<?php echo base_url();?>index.php/postings/insert_excel" method="POST" enctype="multipart/form-data">
                            <table class="table table-white table-vertical-center margin-none footable">
                                <tr>
                                    <th  data-class="highlight" class="text-center">Select File</th>
                                    <td><input type="file" name="userfile" required> &nbsp; <small>File uploading system will allow only <b>".xls"</b> and <b>".xlsx"</b> file types to upload.</small></td>
                                </tr>
                                <tr>
                                    <th  data-class="highlight" class="text-center"></th>
                                    <td><input type="submit" name="submit" value="Upload" class="btn btn-success" /></td>
                                </tr>
                            </table>
                            <div>
                                <!-- <img src="<?php //echo base_url();?>assets/images/loader.gif"> -->
                            </div>
                        </form>
                    </div>
                </div>
            <?php } ?>
            <?php if (isset($allMagazines)) {?>
                <div class="widget">
                    <div class="widget-head">
                        <h4 class="heading">Downloads</h4>
                    </div>
                    <div class="widget-body innerAll inner-2x">
                        <?php $this->load->view('admin/flashdata_admin'); ?>
                        <form action="<?php echo base_url();?>index.php/postings/singpost_listing" method="GET" id="Singpost_Listing_form">
                            <h5>Date range to download Stickers</h5>

                            <table class="table table-white table-vertical-center margin-none footable" align="left">
                                <tr>

                                    <td class="col-md-2">From : &nbsp; <input type="text" readonly data-date-format="dd-mm-yyyy" class="form-control date validate[required] text-input" name="from_date" id ="from_date" value="<?php if ($arrGetData['from_date'] != "") echo date("m/d/Y", strtotime($arrGetData['from_date'])); ?>"/></th>
                                    <td class="col-md-2">End : &nbsp; <input type="text" readonly data-date-format="dd-mm-yyyy" class="form-control date validate[required] text-input" name="end_date_singList" id="end_date" value="<?php if ($arrGetData['end_date'] != "") echo date("m/d/Y", strtotime($arrGetData['end_date'])); ?>"/></th>
                                    <td class="col-md-2">
                                        Select Country for Sticker.&nbsp;
                                        <select class="cust_select" name="country_name" id="country_name">
                                            <option value="">--Select country for stickers</option>
                                            <option value="1">Singapore</option>
                                            <option value="2">Malaysia</option>
                                            <option value="3">Hong Kong</option>
                                            <option value="4">Thiland</option>
                                        </select>
                                    </td>
                                    <!-- <td>&nbsp;&nbsp;<button type="submit" class="btn btn-primary">Search</button></td> -->
                                </tr>
                            </table>
                            <div id="further_actions">
                                <div style="width: 500px !important;">
                                    <div style="float: left;">
                                        <input type="checkbox" name="select_mag" id="select_mag" value="all" style="margin-left: 10px"><b> Check All</b>
                                    </div>
                                    <div style="float: right">
                                        <small> <i class="fa fa-asterisk" style="color: red"></i> For Singpost Listing you can select maximum 5 magazines at a time</small>
                                    </div>
                                </div>
                                <div style="clear: both"></div>
                                <br />
                                <table class="table table-white table-vertical-center margin-none footable">

                                    <?php
                                    $arrAllIds = array();
                                    $intLimit = count($allMagazines);
                                    for($intCounter = 0; $intCounter < count($allMagazines); $intCounter= $intCounter+5) { $arrAllIds[$intCounter] = $allMagazines[$intCounter]['id'];?>
                                        <tr>
                                            <?php if ($allMagazines[$intCounter]['id'] != "") {?>
                                                <td class="col-md-2">
                                                    <input type="checkbox" name="select_mag[]" value="<?php echo $allMagazines[$intCounter]['id'];?>" class="checkbox1"> <?php echo $allMagazines[$intCounter]['magezine_id'];?>
                                                </td>
                                            <?php }?>

                                            <?php if ($allMagazines[$intCounter+1]['id'] != "") {?>
                                                <td class="col-md-2">
                                                    <input type="checkbox" name="select_mag[]" value="<?php echo $allMagazines[$intCounter+1]['id'];?>" class="checkbox1"> <?php echo $allMagazines[$intCounter+1]['magezine_id'];?>
                                                </td>
                                                <?php $arrAllIds[$intCounter+1] = $allMagazines[$intCounter+1]['id']; } ?>

                                            <?php if ($allMagazines[$intCounter+ 2]['id'] != "") {?>
                                                <td class="col-md-2">
                                                    <input type="checkbox" name="select_mag[]" value="<?php echo $allMagazines[$intCounter+2]['id'];?>" class="checkbox1"> <?php echo $allMagazines[$intCounter+2]['magezine_id'];?>
                                                </td>
                                                <?php $arrAllIds[$intCounter+2] = $allMagazines[$intCounter+2]['id']; } ?>

                                            <?php if ($allMagazines[$intCounter+ 3]['id'] != "") {?>
                                                <td class="col-md-2">
                                                    <input type="checkbox" name="select_mag[]" value="<?php echo $allMagazines[$intCounter+3]['id'];?>" class="checkbox1"> <?php echo $allMagazines[$intCounter+3]['magezine_id'];?>
                                                </td>
                                                <?php $arrAllIds[$intCounter+3] = $allMagazines[$intCounter+3]['id']; } ?>

                                            <?php if ($allMagazines[$intCounter+ 4]['id'] != "") {?>
                                                <td class="col-md-2">
                                                    <input type="checkbox" name="select_mag[]" value="<?php echo $allMagazines[$intCounter+4]['id'];?>" class="checkbox1"> <?php echo $allMagazines[$intCounter+4]['magezine_id'];?>
                                                </td>
                                                <?php $arrAllIds[$intCounter+4] = $allMagazines[$intCounter+4]['id']; } ?>
                                        </tr>

                                    <?php } ?>

                                </table>
                            </div>
                            <hr />
                            <br >
                            <input type="hidden" name="ids" id="ids" value="" />
                            <input type="hidden" name="st_date" id="st_date" value="" />
                            <input type="hidden" name="end_date" id="end_date" value="" />
                            <input type="hidden" name="select-country" id="select-country" value="" />
                            <input type="hidden" name="all_ids" id="all_ids" value="<?php echo implode(",", $arrAllIds);?>" />
                            <!-- <p>Sticker | Excel Report | CSV Repprt | SINGPOST Listing </p> -->
                            <p>Sticker | SINGPOST Listing <!-- | Renewal Report --> </p>
                            <button type="button" id="sticker" class="btn btn-primary"><i class="fa fa-2x fa-print" title="print"></i></button> &nbsp;
                            <!-- <button type="submit" id="excel_report" class="btn btn-primary" style="margin-left:30px;margin-right:20px;"><i class="fa fa-2x fa-file-excel-o" title="Excel Download"></i></button>
                            <button type="submit" id="csv_report" class="btn btn-primary" style="margin-left:35px;margin-right:20px;"><i class="fa fa-2x fa-file-text-o" title="CSV Download"></i></button> &nbsp; -->
                            <!-- <a id="sing_list" href="<?php //echo base_url();?>index.php/postings/singpost_listing" style="margin-left:40px;margin-right:20px;"><button type="submit" id="" class="btn btn-primary"><i class="fa fa-2x fa-download" title="SINGPOST Download"></i></button></a> -->
                            <button type="submit" id="sing_list" class="btn btn-primary" style="margin-left: 35px"><i class="fa fa-2x fa-download" title="SINGPOST Download"></i></button>
                            <!-- <a href="fnRenewalReport" title="Renewal Report" style="margin-left: 60px"><button type="button" id="sing_list" class="btn btn-primary"><i class="fa fa-2x fa-file-excel-o" title="Renewal Report"></i></button></a> -->
                            <input type="hidden" id="sys_base_url" value="<?php echo base_url();?>" />
                        </form>
                    </div>
                </div>
            <?php } ?>
        </div>
        <hr />
    </div>
</div>

<script src="<?php echo base_url(); ?>assets/library/jquery/jquery.min.js"></script>
<script src="<?php echo base_url();?>assets/js/custom.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/plugins/forms_elements_multiselect/js/jquery.multi-select.js?v=v2.0.0-rc1&sv=v0.0.1.2"></script>
<script src="<?php echo base_url();?>assets/plugins/forms_elements_bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_bootstrap-select/bootstrap-select.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_bootstrap-select/bootstrap-select.init.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_fuelux-radio/fuelux-radio.init.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_multiselect/multiselect.init.js?v=v2.0.0-rc1&sv=v0.0.1.2"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validationEngine-en.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validationEngine.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>assets/js/subscriber.js"></script>
<script>
    $(document).ready(function() {
        $("#Singpost_Listing_form").validationEngine();
        $('#select_mag').click(function(event) {  //on click
            if(this.checked) { // check select status
                $('.checkbox1').each(function() { //loop through each checkbox
                    this.checked = true;  //select all checkboxes with class "checkbox1"
                });
            }else{
                $('.checkbox1').each(function() { //loop through each checkbox
                    this.checked = false; //deselect all checkboxes with class "checkbox1"
                });
            }
        });

        $("#sticker").click(function(){
            var chkId = '';
            $('.checkbox1:checked').each(function() {
                chkId += $(this).val() + ",";
            });
            var country_id = parseInt($("#country_name").val());
            chkId = chkId.slice(0,-1);
            $("#ids").val(chkId);
            $("#st_date").val($("#start_date").val());
            $("#end_date").val($("#end_date").val());
            $("#select-country").val($("#country_name").val());

            var all_ids = $("#all_ids").val();
            if (chkId == null || chkId == "") {
                chkId = all_ids;
            }
            var start_date = btoa($("#from_date").val());
            var ids = btoa(chkId);
            var end_date = btoa($("#end_date").val());

            var system_base_url = $("#sys_base_url").val();
            var strRedirectPath = system_base_url+"index.php/postings/print_sticker?ids="+ids+"&st_date="+start_date+"&end_date="+end_date+"&country="+country_id;
            window.location.replace(strRedirectPath);
        });
        $("#sing_list").click(function(){
            var chkId = null;
            var count = 0;
            $('.checkbox1:checked').each(function() {
                chkId += $(this).val() + ",";
                count++;
            });
            if (chkId == null) {
                alert("Please select at least one magazine to generate listing");
                return false;
            }
            if (count > 5) {
                alert("You can select maximum 5 magazine to generate report");
                return false;
            }
        });

        $("#excel_report").click(function(){
            var chkId = '';
            $('.checkbox1:checked').each(function() {
                chkId += $(this).val() + ",";
            });
            chkId = chkId.slice(0,-1);
            $("#ids").val(chkId);
            $("#st_date").val($("#start_date").val());
            $("#end_date").val($("#end_date").val());

            var all_ids = $("#all_ids").val();
            if (chkId == null || chkId == "") {
                chkId = all_ids;
            }
            var start_date = btoa($("#from_date").val());
            var ids = btoa(chkId);
            var end_date = btoa($("#end_date").val());
            var system_base_url = $("#sys_base_url").val();
            var strRedirectPath = system_base_url+"index.php/postings/GenerateExcel?ids="+ids+"&st_date="+start_date+"&end_date="+end_date;
            window.location.replace(strRedirectPath);
        });

        $("#csv_report").click(function(){
            var chkId = '';
            $('.checkbox1:checked').each(function() {
                chkId += $(this).val() + ",";
            });
            chkId = chkId.slice(0,-1);
            $("#ids").val(chkId);
            $("#st_date").val($("#start_date").val());
            $("#end_date").val($("#end_date").val());

            var all_ids = $("#all_ids").val();
            if (chkId == null || chkId == "") {
                chkId = all_ids;
            }
            var start_date = btoa($("#from_date").val());
            var ids = btoa(chkId);
            var end_date = btoa($("#end_date").val());
            var system_base_url = $("#sys_base_url").val();
            var strRedirectPath = system_base_url+"index.php/postings/GenerateCSV?ids="+ids+"&st_date="+start_date+"&end_date="+end_date;
            window.location.replace(strRedirectPath);
        });
    });
</script>