<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/js/validationEngine.jquery.css" type="text/css" />
<div class="" id="addPromotion">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" align = "left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">Add new magazine details</h3>
                <a href="<?php echo base_url();?>index.php/subscriber/fnSubscribeCampaign/?subscriber_id=<?php //echo base64_encode($user['id']); ?>" onclick="return subscribe_campaign_wise('<?php echo base64_encode($user['id']); ?>')" data-toggle="modal" class=" pull-right mar"><button class="btn btn-info" type="button">Subscribe Campaign</button></a>
            </div>
            <div class="modal-body">
                <div class="innerAll">
                    <div class="innerLR">
                        <form class="form-horizontal" role="form" id = "single_subscribe_products" action = "<?php echo base_url(); ?>index.php/subscriber/subscribe_magazine" method = "post">
                            <?php $this->load->view('admin/flashdata_admin'); ?>
                            <?php if(count($magazine_details) > 0) {?>
                                <div id="magazine_list">
                                    <div class="form-group mmar">
                                        <label  class="col-sm-3 control-label text-center">Select Magazine: </label>
                                        <div class="col-sm-9">
                                            <select name="magazine_id" id="single_magazine_products" required="required" class="cust_select marl-n">
                                                <option value="">--Select--</option>
                                                <?php foreach ($magazine_details as $details) {?>
                                                    <option value="<?php echo $details['id'];?>"><?php echo $details['magezine_id'];?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                   <div class="form-group mmar">
                                        <label  class="col-sm-3 control-label text-center">No. Of years: </label>
                                        <div class="col-sm-9">
                                            <select name="number_of_year" id="single_magazine_sub_option" class="form-control validate[required]">
                                                <option value="">---Select Year---</option>
                                                <?php for($intCounter=1; $intCounter <= 12; $intCounter++) {?>
                                                    <option value="<?php echo $intCounter; ?>"><?php echo $intCounter; ?></option>
                                                <?php } ?>
                                            </select>

                                        </div>
                                    </div>
                                    <div class="form-group mmar" style="margin-top: 10px">
                                        <label  class="col-sm-3 control-label text-center">Amount: </label>
                                        <div class="col-sm-9">
                                            <input type="text" value="" class="form-control validate[required,custom[integer],min[1]] text-input" name = "amount" id = "addCampaigncamp_amount" required="required"/>
                                        </div>
                                    </div>
                                    <div class="form-group mmar">
                                        <label  class="col-sm-3 control-label text-center" for="myDate">Subscription Start Date: </label>
                                        <div class="col-sm-9">
                                            <input type="text" value="" class="form-control date" data-date-format="M-yyyy" name = "start_date" id = "addCampaigndate1" readonly required="required"/>
                                        </div>
                                    </div>
                                    <div class="form-group mmar">
                                        <label  class="col-sm-3 control-label text-center" for="myDate">Subscription   End Date: </label>
                                        <div class="col-sm-9">
                                            <input type="text" value="" class="form-control date" data-date-format="M-yyyy" name = "end_date" id = "addCampaigndate2" readonly required="required"/>
                                        </div>
                                    </div>
                                    <div class="form-group mmar">
                                        <label  class="col-sm-3 control-label text-center">Start Issue Number: </label>
                                        <div class="col-sm-9">
                                            <!-- <input type="text" value="" class="form-control validate[required,custom[integer],max[999], min[1]] text-input" name = "start_issue" id = "addCampaignissue1" required="required"/> -->
                                            <input type="text" value="" class="form-control validate[required] text-input" name = "start_issue" id = "addCampaignissue1" required="required"/>
                                        </div>
                                    </div>
                                    <div class="form-group mmar">
                                        <label  class="col-sm-3 control-label text-center">End Issue Number: </label>
                                        <div class="col-sm-9">
                                            <input type="text" value="" class="form-control validate[required] text-input" name = "end_issue" id = "addCampaignissue2" required="required"/>
                                        </div>
                                    </div>
                                    <div class="form-group mmar">
                                        <label  class="col-sm-3 control-label text-center">No of Issues: </label>
                                        <div class="col-sm-9">
                                            <input type="text" value="" class="form-control validate[required,custom[integer],min[1]] text-input" name = "no_issues" id = "no_issues" required="required"/>
                                        </div>
                                    </div>
                                    <!-- <a href="javascript:void(0)" id="add_new_Magazine"><i class="fa fa-fw fa-plus"></i></a> -->
                                </div>
                                <div id="promo_issue_error" class="formErrorContent" align="center"></div><br>
                                <div id="year_error" class="formErrorContent" align="center"></div>
                                <input type="hidden" value="add_new" id="purpose" />
                                <div class="form-group">
                                    <div class="col-sm-offset-4 col-sm-8">
                                        <input type="hidden" id="system_base_url" value="<?php echo base_url();?>">
                                        <input type="hidden" id="previous_id" value="">
                                        <input type="hidden" name="subscriber_id" value="<?php echo base64_encode($strUserId); ?>">
                                        <button type="submit" class="btn btn-primary" id="btnSubmit">Submit</button>
                                        <a class="btn" href="<?php echo base_url(); ?>index.php/promotion/promotion_list"> <button type="button" class="btn btn-primary">Cancel</button></a>
                                    </div>
                                </div>
                            <?php } else {?>
                                Sorry No Magazines found !!!!!!
                            <?php } ?>
                        </form>
                    </div>
                </div>
            </div>
            <!-- // Modal body END -->
        </div>
    </div>
</div>

<script src="<?php echo base_url();?>assets/js/main.js" type="text/javascript"></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_bootstrap-datepicker/js/bootstrap-datepicker.js"></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>
    $(document).ready(function() {
        $("#single_subscribe_products").validationEngine();
        $("#single_magazine_sub_option").change(function(){
            $("#camp_amount").val("");
            var intMagazineId = $("#single_magazine_products").val();
            var intNumberOfYear = $("#single_magazine_sub_option").val();
            var systemBaseUrl = $("#system_base_url").val();
            if (intMagazineId != "" && intNumberOfYear != "") {
                $.ajax({
                    url:systemBaseUrl+"index.php/promotion/fnGetRequestedAmount",
                    'data' : {
                        'prev_ids' :intMagazineId,
                        'no_of_years': intNumberOfYear
                    },
                    'type' : 'GET',
                    success:function(result){
                        $("#addCampaigncamp_amount").val(result);
                    }
                });
            }

        });
        $("#single_subscribe_products").submit(function(){
            var intMagazineAmount = parseInt($("#addCampaigncamp_amount").val());
            var intStartIssue = parseInt($("#addCampaignissue1").val());
            var intEndIssue = parseInt($("#addCampaignissue2").val());
            var intTotalIssue = parseInt($("#no_issues").val());

            if(intMagazineAmount == 0) {
                $("#promo_issue_error").html("Start Issue number can not be greater than End Issue");
                $("#addCampaigncamp_amount").css('border-color', 'red');
                return false;
            }

            if(intStartIssue == 0) {
                $("#promo_issue_error").html("Start Issue number can not be greater than End Issue");
                $("#addCampaignissue1").css('border-color', 'red');
                return false;
            }

            if(intEndIssue == 0) {
                $("#promo_issue_error").html("Start Issue number can not be greater than End Issue");
                $("#addCampaignissue2").css('border-color', 'red');
                return false;
            }

            if (intEndIssue <= intStartIssue) {
                $("#promo_issue_error").html("Start Issue number can not be greater than End Issue");
                $("#addCampaignissue2").css('border-color', 'red');
                return false;
            }

            if(intTotalIssue == 0) {
                $("#promo_issue_error").html("Number of Issues can only be integer value");
                $("#no_issues").css('border-color', 'red');
                return false;
            }

        });
    });
</script>