<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" />
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/bootstrap-multiselect.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">
            <div style="clear: both"></div>
                                <br />
                <?php
                    $disply = 'display:none;';
                    if(count($_GET) > 0){
                        $disply = 'display:block;';
                    }
                ?>
                <div class="widget allMagazines">
                    <div class="widget-head">
                        <h4 class="heading">Advance Reports</h4>
                    </div>
                    <div class="widget-body innerAll inner-2x" style="display: inline-block;width: 100%;">
                        <?php $this->load->view('admin/flashdata_admin'); ?>
                        <?php
                            $display = 'display:none;';
                            $checked = '';
                            if($_GET['txtStartDate'] != '' && $_GET['txtEndDate'] != ''){
                                $display = 'display:block;';
                                $checked = 'checked="checked"';
                            }
                        ?>
                        <form action="" method="GET" id="Singpost_Listing_form">
                            <div class="col-md-2" style="padding-left: 0;padding-bottom: 1em;">
                                <input type="text" name="txtStartDate" class="form-control date" placeholder="From" value="<?php echo $_GET['txtStartDate'];?>">
                            </div>
                            <div class="col-md-2">
                                <input type="text" name="txtEndDate" class="form-control date" placeholder="To" value="<?php echo $_GET['txtEndDate'];?>">
                            </div>
                            <button type="submit" class="btn btn-primary" style="padding: 0.32em 1em 0.32em 1em;"> GO </button>
                            <input type="hidden" name="root" value="1">
                        </form>
                        <div class="clearfix"></div>
                        
                        <form action="<?php echo base_url().'index.php/postings/fnSaveAdvanceReports';?>" method="GET" style="<?php echo $display;?>">
                            <input type="hidden" name="txtStartDate" value="<?php echo $_GET['txtStartDate'];?>">
                            <input type="hidden" name="txtEndDate" value="<?php echo $_GET['txtEndDate'];?>">
                            <!-- Magazine Htmls Start -->
                            <label>
                                <input type="checkbox" id="ckhMagazine" value="1" <?php echo $checked;?>> <b style="display: inline-block;position: relative;top: -0.14em;color: #00579e;">Magazine</b>
                            </label>
                            <div class="col-md-12 devMagazine clsMagHideShow" style="<?php echo $display;?>">
                                <div class="col-md-3">
                                    <select id="selMagazineID" name="selMagazineID[]" style="width: 100%;padding: 0.2em;" multiple="multiple">
                                        <?php
                                            if(count($MagazineID) > 0){
                                                asort($MagazineID);
                                                foreach ($MagazineID as $key => $MagazineIDValue) {
                                                    echo '<option value="'.$key.'">'.$MagazineIDValue.'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>

                                <div class="col-md-3">
                                    <select id="selMagazineLanguage" name="selMagazineLanguage[]" style="width: 100%;padding: 0.2em;"  multiple="multiple">
                                        <?php
                                            if(count($language) > 0){
                                                asort($language);
                                                foreach ($language as $key => $languageValue) {
                                                    echo '<option value="'.$key.'">'.ucfirst($languageValue).'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>

                                <div class="col-md-3">
                                    <select id="selMagazineStatus" name="selMagazineStatus[]" style="width: 100%;padding: 0.2em;"  multiple="multiple">
                                        <?php
                                            if(count($MagazineStatus) > 0){
                                                asort($MagazineStatus);
                                                foreach ($MagazineStatus as $key => $MagazineStatusValue) {
                                                    echo '<option value="'.$key.'">'.ucfirst($MagazineStatusValue).'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>

                                <div class="col-md-3">
                                    <select id="selMagazineMonth" name="selMagazineMonth[]" style="width: 100%;padding: 0.2em;"  multiple="multiple">
                                        <?php
                                            if(count($MagazineMonth) > 0){
                                                asort($MagazineMonth);
                                                foreach ($MagazineMonth as $key => $MagazineMonthValue) {
                                                    echo '<option value="'.$key.'">'.ucfirst($MagazineMonthValue).'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>
                                <div class="clearfix" style="margin-bottom: 0.5em;"></div>
                                
                                <label class="col-md-2" style="padding-left: 7px;">
                                    <input type="checkbox" name="ckhStartIssueNo" id="ckhStartIssueNo" value="1"> <b class="styBlist">Start Issue No</b>
                                </label>

                                <label class="col-md-2">
                                    <input type="checkbox" name="ckhEndIssueNo" id="ckhEndIssueNo" value="1"> <b class="styBlist">End Issue No</b>
                                </label>

                                <label class="col-md-2">
                                    <input type="checkbox" name="ckhTotalNoOfIssues" id="ckhTotalNoOfIssues" value="1"> <b class="styBlist">Total No of Issues</b>
                                </label>

                            </div>
                            <div class="clearfix"></div>
                            <div class="clsMagHideShow" style="<?php echo $display;?>border-bottom: 1px solid #eeeeee;margin-bottom: 1em;"></div>
                            <!-- Magazine Htmls End -->


                            <!-- Subscriber Htmls Start -->
                            <label>
                                <input type="checkbox" id="ckhSubscriber" value="2" <?php echo $checked;?>> <b style="display: inline-block;position: relative;top: -0.14em;color: #00579e;">Subscriber</b>
                            </label>

                            <div class="col-md-12 devSubscriber clsSubHideShow" style="<?php echo $display;?>width: 110%;">
                                <div class="col-md-5">
                                    <input type="text" name="scrSubinfo" class="form-control" placeholder="ID, Name, Email, Phone, Address, Postal Code, Transaction ID, Amount">
                                </div>
                                
                                <div class="col-md-3">
                                    <select id="selSubscriberStatus" name="selSubscriberStatus[]" style="width: 100%;padding: 0.2em;"  multiple="multiple">
                                       
                                       <?php
                                            if(count($SubscriberStatus) > 0){
                                                asort($SubscriberStatus);
                                                foreach ($SubscriberStatus as $key => $SubscriberStatusValue) {
                                                    echo '<option value="'.$key.'">'.ucfirst($SubscriberStatusValue).'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>
                                <div class="clearfix" style="margin-bottom: 0.5em;"></div>
                                
                                <label class="col-md-1" style="padding-left: 7px;">
                                    <input type="checkbox" name="ckhID" id="ckhID" value="1"> <b class="styBlist">ID</b>
                                </label>

                                <label class="col-md-1">
                                    <input type="checkbox" name="ckhName" id="ckhName" value="1"> <b class="styBlist">Name</b>
                                </label>

                                <label class="col-md-1">
                                    <input type="checkbox" name="ckhEmail" id="ckhEmail" value="1"> <b class="styBlist">Email</b>
                                </label>

                                <label class="col-md-1">
                                    <input type="checkbox" name="ckhPhone" id="ckhPhone" value="1"> <b class="styBlist">Phone</b>
                                </label>

                                <label class="col-md-1">
                                    <input type="checkbox" name="ckhAddress" id="ckhAddress" value="1"> <b class="styBlist">Address</b>
                                </label>

                                <label class="col-md-2" style="width: 15%;">
                                    <input type="checkbox" name="ckhPostalCode" id="ckhPostalCode" value="1"> <b class="styBlist">Postal Code</b>
                                </label>
                                
                                <label class="col-md-2" style="width: 10%;">
                                    <input type="checkbox" name="ckhNoOfYears" id="ckhNoOfYears" value="1"> <b class="styBlist">No of Years</b>
                                </label>

                                <label class="col-md-2" style="width: 10%;">
                                    <input type="checkbox" name="ckhStartDate" id="ckhStartDate" value="1"> <b class="styBlist">Start Date</b>
                                </label>

                                <label class="col-md-2" style="width: 10%;">
                                    <input type="checkbox" name="ckhExpiryDate" id="ckhExpiryDate" value="1"> <b class="styBlist">Expiry Date</b>
                                </label>
                                
                            </div>
                            <div class="clearfix"></div>
                            <div class="clsSubHideShow" style="<?php echo $display;?>border-bottom: 1px solid #eeeeee;margin-bottom: 1em;"></div>
                            <!-- Subscriber Htmls End -->

                            <!-- Transaction Htmls Start -->
                            <label>
                                <input type="checkbox" id="ckhTransaction" value="3" <?php echo $checked;?>> <b style="display: inline-block;position: relative;top: -0.14em;color: #00579e;">Transaction</b>
                            </label>
                            <div class="col-md-12 devTransaction clsTranhideShow" style="<?php echo $display;?>">
                                <div class="col-md-3">
                                    <select id="selPaymentMode" name="selPaymentMode[]" style="width: 100%;padding: 0.2em;"  multiple="multiple">                                       
                                       <?php
                                            if(count($PaymentModeStatus) > 0){
                                                asort($PaymentModeStatus);
                                                foreach ($PaymentModeStatus as $key => $PaymentModeStatusValue) {
                                                    echo '<option value="'.$key.'">'.ucfirst($PaymentModeStatusValue).'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>
                                <div class="col-md-3">
                                    <select id="selCollectedBy" name="selCollectedBy[]" style="width: 100%;padding: 0.2em;"  multiple="multiple">
                                       
                                       <?php
                                            if(count($CollectedBy) > 0){
                                                asort($CollectedBy);
                                                foreach ($CollectedBy as $key => $CollectedByValue) {
                                                    echo '<option value="'.$key.'">'.ucfirst($CollectedByValue).'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>
                                <div class="col-md-3">
                                    <select id="selTransactionStatus" name="selTransactionStatus[]" style="width: 100%;padding: 0.2em;"  multiple="multiple">
                                       <?php
                                            if(count($TransactionStatus) > 0){
                                                asort($TransactionStatus);
                                                foreach ($TransactionStatus as $key => $TransactionStatusValue) {
                                                    echo '<option value="'.$key.'">'.ucfirst($TransactionStatusValue).'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </div>

                                <div class="clearfix" style="margin-bottom: 0.5em;"></div>

                                <label class="col-md-2" style="padding-left: 7px;">
                                    <input type="checkbox" name="ckhTransactionID" id="ckhTransactionID" value="1"> <b class="styBlist">Transaction ID</b>
                                </label>

                                <label class="col-md-2">
                                    <input type="checkbox" name="ckhTransactionDate" id="ckhTransactionDate" value="1"> <b class="styBlist">Transaction Date</b>
                                </label>

                                <label class="col-md-2">
                                    <input type="checkbox" name="ckhTransactionAmount" id="ckhTransactionAmount" value="1"> <b class="styBlist">Transaction Amount</b>
                                </label>

                                <label class="col-md-2">
                                    <input type="checkbox" name="ckhTransactionStatus" id="ckhTransactionStatus" value="1"> <b class="styBlist">Transaction Status</b>
                                </label>
                                
                            </div>
                            <div class="clearfix"></div>
                            <div class="clsTranhideShow" style="<?php echo $display;?>margin-bottom: 0.5em;"></div>
                            <div class="col-md-3">
                                <button type="submit" class="btn btn-primary pull-left" style="margin-top: 1.4em;padding: 0.3em 1em 0.3em 1em;">Download Xls</button>
                                <a href="<?php echo base_url().'index.php/postings/fnAdvanceReports';?>" style="margin-top: 1.4em;margin-left: 0.5em;padding: 0.3em 1em 0.3em 1em;border: 1px solid #c7c7c7;background: #dedede;color: #111;" class="btn pull-left">Reset</a>
                            </div>
                            <input type="hidden" name="root" value="2">
                            <!-- Transaction Htmls End -->
                        </form>
                    </div>
                </div>
                 <input type="hidden" id="sys_base_url" value="<?php echo base_url();?>">
                <br/><br/><br/><br/><br/><br/>
        </div>
        <hr />
       
    </div>
</div>
<style type="text/css">
    .multiselect.dropdown-toggle.btn.btn-default{
        text-align: left;
        -webkit-border-radius: 0px;
        -moz-border-radius: 0px;
        border-radius: 0px; 
    }
    .multiselect.dropdown-toggle.btn.btn-default  .caret{
        position: relative;
        float: right;
        margin-top: 8px;
        margin-right: 5px;
    }
    .dropdown-menu{
        min-width: 220px;
    }
    ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
      color: #333 !important;
    }
    ::-moz-placeholder { /* Firefox 19+ */
      color: #333 !important;
    }
    :-ms-input-placeholder { /* IE 10+ */
      color: #333 !important;
    }
    :-moz-placeholder { /* Firefox 18- */
      color: #333 !important;
    }
    input[type=text], input[type=password], select, textarea {
        border-color: #d4d4d4;
        color: #00579E !important;
        border-radius: 0 !important;
    }
    .styBlist{
        display: inline-block;position: relative;top: -0.14em;
    }
    .clsTranhideShow,.clsMagHideShow,.clsSubHideShow{
        display: none;
    }
    .btn{
        border-radius: 0px;
    }
</style>
<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 src="<?php echo base_url();?>assets/js/bootstrap-multiselect.js" type="text/javascript"></script>
<script>
    $(document).ready(function() {
        $("#Singpost_Listing_form").validationEngine();
        $('#selMagazineID').multiselect({
            nonSelectedText :'Select Magazine ID',
            maxHeight: 300,
            buttonWidth: '220px',
            includeSelectAllOption: true
        });

        $('#selMagazineLanguage').multiselect({
            nonSelectedText :'Select Magazine Language',
            maxHeight: 300,
            buttonWidth: '220px',
            includeSelectAllOption: true
        });

        $('#selMagazineStatus').multiselect({
            nonSelectedText :'Select Magazine Status',
            maxHeight: 300,
            buttonWidth: '220px',
            includeSelectAllOption: true
        });

        $('#selMagazineMonth').multiselect({
            nonSelectedText :'Select Magazine Month',
            maxHeight: 300,
            buttonWidth: '220px',
            includeSelectAllOption: true
        });

        $('#selSubscriberStatus').multiselect({
            nonSelectedText :'Select Subscriber Status',
            maxHeight: 300,
            buttonWidth: '220px',
            includeSelectAllOption: true
        });

        $('#selPaymentMode').multiselect({
            nonSelectedText :'Select Payment Mode',
            maxHeight: 300,
            buttonWidth: '220px',
            includeSelectAllOption: true
        });

        $('#selCollectedBy').multiselect({
            nonSelectedText :'Select Collected By',
            maxHeight: 300,
            buttonWidth: '220px',
            includeSelectAllOption: true
        });

        $('#selTransactionStatus').multiselect({
            nonSelectedText :'Select Transaction Status',
            maxHeight: 300,
            buttonWidth: '220px',
            includeSelectAllOption: true
        });

        $(document).on('change', '#selMagazineID', function(){
            var selMagazineID = $(this).val();
            if(selMagazineID == null){

            }else{
                fnGetAllSettingINfo(selMagazineID);
            }

        });

        $(document).on('click', '#ckhMagazine', function(){
            
            if($(this).is(':checked')){
                $('.clsMagHideShow').show();
            }else{
                $('.clsMagHideShow').hide();
            }

        });

        $(document).on('click', '#ckhSubscriber', function(){
            
            if($(this).is(':checked')){
                $('.clsSubHideShow').show();
            }else{
                $('.clsSubHideShow').hide();
            }

        });

        $(document).on('click', '#ckhTransaction', function(){
            
            if($(this).is(':checked')){
                $('.clsTranhideShow').show();
            }else{
                $('.clsTranhideShow').hide();
            }

        });

        $('#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"
                });
            }
        });

        
        $(".advanced_search").click(function(){
            $('.allMagazines').slideDown();
        });

        $("#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);*/
        });
        
        $("#donwExls").click(function(){
            var from_date = $('#from_date_').val();
            var status = $('#status_').val();
            var country_name_ = $('#country_name_').val();
            var system_base_url = $("#sys_base_url").val();
            var strRedirectPath = system_base_url+"index.php/postings/saveExls?from_date="+from_date+"&status="+status+"&country_name="+country_name_;
            window.location.replace(strRedirectPath);
        });

        $("#sing_list").click(function(){
            var chkId = null;
            var count = 0;
            $('.chkStatus: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);
        });

        function fnGetAllSettingINfo(selMagazineID){
            $.ajax({
              url:  $("#sys_base_url").val()+"index.php/postings/fnAllSettings",
              'type' : 'GET',
              async:false,
              'data' : {
                  'MagazineID'  : selMagazineID
              },
              success:function(result){

              }
           });
        }
    });
</script>