<script src="<?php echo base_url(); ?>assets/library/jquery/jquery.min.js"></script>
<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-separator col-separator-first col-unscrollable bg-none">
<div class="col-table">
<div class="row">
<div class="col-md-2" style="min-height: 800px">
    <div class="col-separator box col-separator-first reset-components">
        <div class="bg-white">
            <div class="profile-avatar">
                <div class="text-center">
                    <? if ($arrUser['photo'] != NULL) {?>
                        <img src="<?php echo base_url(); ?>uploads/users/<?php echo $arrUser['photo']; ?>" class="img-responsive img-clean" alt="people" />
                    <?php } else {?>
                        <img src="<?php echo base_url(); ?>assets/images/default_profile.jpg" class="img-responsive img-clean" alt="people" />
                    <?php } ?>
                </div>
            </div>

            <div class="mar container">
                <?php $arrUserType = array(1 => 'Individual', 2 => 'Company', 3 => 'Student', 4 => 'Other');?>
                <article class="posts-by-cat_article-222">
                <div style="margin-top:8px"><p class="margin-none text-muted">Name: </p><b><span><?php echo ucwords($arrUser['last_name']." ".$arrUser['first_name']); ?></span></b></div>
                <div style="margin-top:8px"><p class="margin-none text-muted">NRIC: </p><b><span><?php echo $arrUser['nric']; ?></span></b></div>
                <!-- <div style="margin-top:8px"><p class="margin-none text-muted">Subscriber Id: </p><span><?php echo $arrUser['id']; ?></span></div> -->
                <div style="margin-top:8px"><p class="margin-none text-muted">Email: </p><span><?php if ($arrUser['email'] != "") { ?><b><a href="mailto:<?php echo $arrUser['email']; ?>"><?php echo $arrUser['email']; ?></a></b><?php } else{ ?>N/A<?php }?></span></div>
                <div style="margin-top:8px"> <p class="margin-none text-muted">Date of Birth: </p><span><?php if ($arrUser['dob'] != "") { ?><?php ?><?php echo date("d M Y", strtotime($arrUser['dob'])); ?><?php } else{ ?>N/A<?php }?></span></div>
                <div style="margin-top:8px"><p class="margin-none text-muted">Phone No.: </p><span><?php if ($arrUser['phone'] != "") { ?><a href="tel: +<?php echo $arrUser['country_code']." ".$arrUser['phone']; ?>">+<?php echo $arrUser['country_code']." ".$arrUser['phone']; ?></a><?php } else{ ?>N/A<?php }?></span></div>
                <div style="margin-top:8px"><p class="margin-none text-muted">Mobile No.: </p><span><?php if ($arrUser['mobile'] != "") { ?><a href="tel: +<?php echo $arrUser['mobile_code']; ?>">+<?php echo $arrUser['mobile']; ?></a><?php } else{ ?>N/A<?php }?></span></div>
                <?php if ($arrUser['is_overseas'] == 0) {?>
                    <div style="margin-top:8px"><p class="margin-none text-muted">Mailing Address: </p><span><?php if ($arrUser['mailing_block'] != "") { ?><?php echo ucfirst($arrUser['mailing_block'])." ".ucfirst($arrUser['mailing_unit_no'])." ".$arrUser['mailing_street_name']." ".$arrUser['building_name_mail']." ".$country_name." ".$city_name." ".$arrUser['mailing_postal_code']; ?><?php } else{ ?>N/A<?php }?></span></div>
                    <div style="margin-top:8px"><p class="margin-none text-muted">Home Address: </p><span><?php if ($arrUser['mailing_block'] != "") { ?><?php echo ucfirst($arrUser['home_block'])." ".ucfirst($arrUser['home_unit_no'])." ".$arrUser['home_street_name']." ".$arrUser['building_name_home']." ".$country_name." ".$city_name." ".$arrUser['home_postal_code']; ?><?php } else{ ?>N/A<?php }?></span></div>
                <?php }else {?>
                    <div style="margin-top:8px"><p class="margin-none text-muted">Mailing Address: </p><span><?php echo $arrUser['address_1']; ?></span></div>
                    <div style="margin-top:8px"><p class="margin-none text-muted">Home Address: </p><span><?php echo $arrUser['address_2']; ?></span></div>
                <?php }?>
                <?php if ($arrUser['subscriber_type'] != "") { ?><div style="margin-top:8px"><p class="margin-none text-muted">Subscriber Type: </p><span><?php echo ucfirst($arrUserType[$arrUser['subscriber_type']]);?></span></div><?php } ?>
                <?php if ($arrUser['guardian_name'] != "") { ?><div style="margin-top:8px"><p class="margin-none text-muted">1.Guardian Name: </p><span><?php echo ucfirst($arrUser['guardian_name']);?></span></div><?php } ?>
                <?php if ($arrUser['guardian2_name'] != "") { ?><div style="margin-top:8px"><p class="margin-none text-muted">2.Guardian Name: </p><span><?php echo ucfirst($arrUser['guardian2_name']);?></span></div><?php } ?>
                <?php if ($arrUser['company_name'] != "") { ?><div style="margin-top:8px"><p class="margin-none text-muted">School Library Name: </p><span><?php echo ucfirst($arrUser['company_name']);?></span></div><?php } ?>
                <?php if ($arrUser['school_name'] != "") { ?><div style="margin-top:8px"><p class="margin-none text-muted">School Name: </p><span><?php echo ucfirst($arrUser['school_name']);?></span></div><?php } ?>
                <?php if ($arrUser['teacher_name'] != "") { ?><div style="margin-top:8px"><p class="margin-none text-muted">Teacher Name: </p><span><?php echo ucfirst($arrUser['teacher_name']);?></span></div><?php } ?>
                <?php if ($arrUser['other_details'] != "") { ?><div style="margin-top:8px"><p class="margin-none text-muted">Other Details: </p><span><?php echo ucfirst($arrUser['other_details']);?></span></div><?php } ?>
                </article>
                <a id="expand_it" href="#" />
            </div>


        </div>


    </div>
</div>
<div class="col-md-10">
    <div class="widget">
        <?php $this->load->view('admin/flashdata_admin'); ?>
        <div class="widget-head" style="height:45px">
            <?php $strEncodedId =  base64_encode($current_user_id); ?>
            <!-- <a href="<?php //echo base_url(); ?>index.php/subscriber/subscribe_product/?user_id=<?php //echo base64_encode($arrUser['id']); ?>" data-toggle="modal" class="btn btn-inverse pull-right mar"><i class="fa fa-fw fa-plus"></i>Subscribe Magazines</a> -->
            <!--<a href="#subscribe_magazine" onclick="return subscribe_magazine_wise('<?php echo base64_encode($current_user_id); ?>')" data-toggle="modal" class="pull-right mar"><button class="btn btn-warning" type="button">Magazine</button></a>
                                        <a href="<?php echo base_url();?>index.php/subscriber/fnSubscribeCampaign/?subscriber_id=<?php echo base64_encode($current_user_id); ?>" onclick="return subscribe_campaign_wise('<?php echo base64_encode($current_user_id); ?>')" data-toggle="modal" class=" pull-right mar"><button class="btn btn-info" type="button">Campaign</button></a> -->
            <a href="<?php echo base_url();?>index.php/subscriber/subscribe_product?user_id=<?php echo base64_encode($current_user_id); ?>" class=" pull-right mar"><button class="btn btn-info" type="button">Subscribe Magazines</button></a>
            <a href="<?php echo base_url();?>index.php/subscriber/fnSendSubscriptionEmail?user_id=<?php echo base64_encode($current_user_id); ?>" class=" pull-right mar"><button class="btn btn-info" type="button">Email Subscription Details</button></a>
            <?php $strCommentUrl = base_url().'index.php/subscriber/add_comment_subscriber/?subscriber_id='.base64_encode($current_user_id); ?>

            <a href="javascript:void(0);"  onClick= 'window.open("<?php echo $strCommentUrl;?>","Ratting", "width=800,height=370,left=150,top=200,toolbar=1,status=1,scrollbars=1");' class=" pull-right mar"><button class="btn btn-info" type="button">Comments</button></a>
            <h4 class="heading">Subscribed Magazines For: <span class="username_display"> &nbsp; <?php echo ucwords($arrUser['last_name']." ".$arrUser['first_name']); ?>  - &nbsp; <?php echo $arrUser["memberId"]; ?></span></h4>
        </div>
        <div style="clear: both"></div>
        <div class="widget-body innerAll inner-2x">
            <table class="table table-white table-vertical-center margin-none table-striped footable">
                <thead>
                <tr>

                    <th  class="text-center">Magazine</th>
                    <th data-hide="phone" class="text-center">Year(s)</th>
                    <th data-hide="phone" class="text-center">Start Date</th>
                    <th data-hide="phone" class="text-center">Expiry</th>
                    <th data-hide="phone" class="text-center">Issues</th>
                    <th data-hide="phone" class="text-center">Amount</th>
                    <th class="text-center">Status</th>
                    <th class="text-center">Transaction Id</th>
                    <th class="text-center">View</th>
                    <th class="text-center"></th>
                    <th class="text-center"></th>

                </tr>
                </thead>
                <tbody>
                <?php
                if (count($subscribed_product) > 0) {
                    foreach ($subscribed_product as $product) {?>
                        <tr>

                            <td class="text-center"><?php echo $product['magezine_id']; ?></td>
                            <td class="text-center"><?php echo $product['period']; ?> year</td>
                            <td class="text-center"><?php echo date("d M Y", strtotime($product['subscribed_on']));?></td>
                            <td class="text-center"><?php
                                echo $strDate =  date('d M Y',strtotime($product['subscription_end_on']));
                                ?></td>

                            <td class="text-center"><?php echo $product['no_of_issue']; ?></td>
                            <td class="text-center"><?php
                            if($product['total_due'] == '1'){
                                 echo '0.00 '.'SGD';
                            } else{
                                echo number_format($product['total_due'], 2).' '.'SGD';
                            }
                            ?></td>

                            <?php if ($product['status'] == 1) {
                                $strThisTransactionStatus = 'Pay';
                                $strClassForButton = 'btn-danger';
                            } elseif($product['status'] == 2) {
                                $strThisTransactionStatus = 'Processing';
                                $strClassForButton = 'btn-warning';
                            } elseif($product['status'] == 3) {

                                switch($product['is_active']) {
                                    case 0:
                                        $strThisTransactionStatus = 'Expired';
                                        $strClassForButton = '';
                                        break;
                                    case 1:
                                        $strThisTransactionStatus = 'Active';
                                        $strClassForButton = 'btn-success';
                                        break;
                                    case 2:
                                        $strThisTransactionStatus = 'Terminated'; //Refunded
                                        $strClassForButton = 'btn-info disabled';
                                        break;
                                    case 3:
                                        $strThisTransactionStatus = 'Transferred';
                                        $strClassForButton = 'btn-info';
                                        break;
                                    case 4:
                                        $strThisTransactionStatus = 'Deleted';
                                        $strClassForButton = 'btn-danger disabled';
                                        break;
                                    case 5:
                                        $strThisTransactionStatus = 'Renewed';
                                        $strClassForButton = 'btn-warning disabled';
                                        break;
                                }
                            }

                            ?>

                            <td class="text-center">
                                <!-- Check whether the status Pay -->
                                <?php $strPaidFlag = null;?>
                                <?php if ($product['status'] == 1 ) { ?>
                                    <a href="<?php echo base_url();?>index.php/subscriber/make_payment/?transaction_id=<?php echo base64_encode($product['transaction_id']); ?>&sub_id=<?php echo base64_encode($current_user_id);?>" >
                                        <button class="btn <?php echo $strClassForButton;?>">
                                            <?php echo $strThisTransactionStatus;?>
                                        </button>
                                    </a>
                                    <!-- Check whether the status Processing -->
                                <?php } elseif ($product['status'] == 2) {?>
                                    <button class="btn <?php echo $strClassForButton;?>">
                                        <?php echo $strThisTransactionStatus;?>
                                    </button>
                                    <!-- Check whether the status Paid, it has some addiotnal scenarios -->
                                <?php } elseif ($product['status'] == 3) {?>
                                    <!-- 1. First check whether it is expired or not -->
                                    <?php if ($product['is_active'] == '0') {?>
                                        <button class="btn <?php echo $strClassForButton;?>">
                                            <?php echo $strThisTransactionStatus;?>
                                        </button>
                                        <!-- 2. Check whether it is open for renew. -->
                                    <?php } elseif ($product['is_active'] == '2') {?>
                                    <button class="btn <?php echo $strClassForButton;?>">
                                            <?php echo $strThisTransactionStatus;?>
                                        </button>
                                    <?php } elseif (in_array($product['trans_id'], $expired_magazines)) {?>
                                        <a href="#renew_magazine" onclick="return renew_magazine('<?php echo base64_encode($product['trans_id']); ?>', '<?php echo base64_encode($current_user_id); ?>', '<?php echo $product['magezine_id']; ?>')" data-toggle="modal" class="">
                                            <button class="btn btn-danger" type="button">
                                                Renew
                                            </button>
                                        </a>
                                        <!-- 3. Check whether it is paid. -->

                                    <?php } else { $strPaidFlag = 1;?>

                                        <?php
                                        $expiryData = date('d-m-Y', strtotime($strDate));
                                        $toDay = date('d-m-Y');

                                        if($product['is_active'] == 5) { ?>
                                            <?php if(strtotime($toDay) > strtotime($expiryData)) { ?>
                                                //echo 'expired';
                                                <button class="btn <?php echo $strClassForButton;?>">
                                                    <?php echo $strThisTransactionStatus;?> 
                                                </button>
                                            <?php }else { ?> 
                                                <button class="btn btn-success" style="padding:5px 0px;background: lightgreen;color: #000;font-size: 13px;">
                                                    SingPost Active 
                                                </button>
                                            <?php } ?>

                                        <?php }else { ?> 
                                            <button class="btn <?php echo $strClassForButton;?>">
                                                <?php echo $strThisTransactionStatus;?> 
                                            </button>
                                        <?php } ?>


                                        
                                    <?php }?>
                                <?php } ?>
                            </td>
                            <td class="text-center"><?php echo $product['transaction_id']; ?></td>
                            <td class="text-center"><a href="#editSub" data-toggle="modal" onclick="return fnGetPreview(<?php echo $product['transaction_id'];?>)"><i class="fa fa-list"></i></a></td>
                            <td class="text-center">
                                <?php if ($product['status'] == 1) { ?>
                                    <a href="<?php echo base_url();?>index.php/subscriber/edit_subscribed_magazine/?user_id=<?php echo base64_encode($current_user_id); ?>&id=<?php echo base64_encode($product['id']);?>" data-toggle="modal"><i class="fa fa-pencil"></i></a>
                                <?php } elseif($strPaidFlag == 1 && $product['is_active'] == 1) {?>
                                    <a href="#update_active_magazine_status" data-toggle="modal" onclick=" return fnGetUpdateStatusOptions('<?php echo base64_encode($product['id']); ?>', '<?php echo base64_encode($current_user_id);?>')" title="Option to reprocess your paid magazines">
                                        <i class="fa fa-times-circle-o"></i>
                                    </a>
                                <?php }?>
                            </td>
                            <td class="text-center">
                                <?php if ($product['status'] == 1) { ?>
                                    <a href="<?php echo base_url();?>index.php/subscriber/delete_subscribed_magazine/?user_id=<?php echo base64_encode($current_user_id); ?>&id=<?php echo base64_encode($product['id']);?>" data-toggle="modal" onClick="return confirm('Are you sure to delete this subscription?');"><i class="fa fa-times"></i></a>
                                <?php } ?>
                            </td>

                        </tr>
                    <?php }} else {?>
                    <tr>
                        <td class="text-center" colspan="5">No magazine subscribed yet !!!!!!</td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
        </div>
        <!-- // END TRENDS -->
        <div class="text-center innerAll border-top pagination margin-none" align = "center">
            <?php echo $pagination; ?>
        </div>
    </div>

</div>
<!-- // END REVENUE -->

<!-- Start Notification HTML -->
<div class="col-md-10" style="margin-top: 3em">
    <div class="widget">
        <div class="widget-head">
            <h4 class="heading">Sent notification(s) For: <span class="username_display"> &nbsp; <?php echo ucwords($arrUser['last_name']." ".$arrUser['first_name']); ?></span></h4>
        </div>
        <div class="widget-body">
            <div>
                <form action="" method="GET" >
                    <div class="col-md-12 selectBox">
                        <div class="col-xs-4 col-md-2 bot-mar">
                            <label class="col-xs-12">From</label>
                            <input type="text" class="form-control date" name="from_date" value="<?php echo $start_date;?>" readonly/>
                        </div>
                        <div class="col-xs-4 col-md-2 bot-mar">
                            <label class="col-xs-12">To</label>
                            <input type="text" class="form-control date" name="to_date" value="<?php echo $end_date;?>" readonly/>
                        </div>

                        <div class="col-xs-4 col-md-2 bot-mar">
                            <label class="col-xs-12">&nbsp;</label>
                            <div>
                                <input type="hidden" name="user_id" value="<?php echo base64_encode($current_user_id);?>">
                                <button type="submit" class="btn btn-primary">Search</button>
                            </div>
                        </div>
                </form>
                <div class="clearfix"></div>
            </div>
        </div>
        <div style="clear: both"></div>
        <div class="widget-body innerAll inner-2x">
            <table class="table table-white table-vertical-center margin-none table-striped footable">
                <thead>
                <tr>
                    <!-- <th data-hide="phone" class="text-center">Transaction Id</th> -->
                    <th data-hide="phone" class="text-center">Subject</th>
                    <th data-hide="phone" class="text-center">Status</th>
                    <th class="text-center">Sent on</th>
                    <th class="text-center">Download</th>
                    <th class="text-center">Resend</th>

                </tr>
                </thead>
                <tbody>
                <?php if (count($notifications) > 0) {
                    foreach ($notifications as $notification) {?>
                        <tr>
                            <!-- <td class="text-center"><?php echo $notification['transaction_id']; ?></td> -->
                            <td class="text-center"><?php echo $notification['subject']; ?></td>
                            <td class="text-center"><?php echo $notification['status']; ?></td>
                            <td class="text-center"><?php echo date("d M Y", strtotime($notification['send_on']));?></td>
                            <td class="text-center">
                                <?php if ($notification['transaction_id'] != null) {?>
                                <a href="<?php echo base_url();?>index.php/subscriber/GenerateReceiptPdfForSubscriber/?id=<?php echo base64_encode($notification['transaction_id']); ?>" >
                                    <i class="fa fa-2x fa-file-pdf-o" title="pdf"></i>
                                </a>
                                <?php }?>
                            </td>
                            <td class="text-center">
                                <a href="<?php echo base_url();?>index.php/subscriber/ResendSendEmail/?id=<?php echo base64_encode($notification['id']); ?>&sub_id=<?php echo $strEncodedId; ?>">
                                    <button class="btn btn-success">
                                        Resend
                                    </button>
                                </a>
                            </td>
                        </tr>
                    <?php }} else {?>
                    <tr>
                        <td class="text-center" colspan="5">No notification found !!!!!!</td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
        </div>

        <!-- // END TRENDS -->
    </div>
    <div class="col-separator-h"></div>
    <!--<div class="widget-head" style="float:left;margin-top:50px;">
                                    <a class="btn btn-inverse pull-right mar" data-toggle="modal" href="<?php echo base_url(); ?>index.php/subscriber/subscriber_list">
                                        <i class="fa fa-arrow-left"></i>
                                        Back
                                    </a>
                                </div> -->
</div>

</div>

</div>
<div class="col-separator-h"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="subscribe_magazine" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content" id="sub_magazine">

        </div>
    </div>
</div>
<div class="modal fade" id="subscribe_campaign" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content" id="sub_campaign">

        </div>
    </div>
</div>
<div class="modal fade" id="renew_magazine" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content" id="renew_mag">

        </div>
    </div>
</div>
<div class="modal fade" id="editSub">
    <div class="modal-dialog">
        <div class="modal-content" id="tran_preview">

        </div>
    </div>
</div>
<div class="modal fade" id="subscriber_comment">
    <div class="modal-dialog">

    </div>
</div>
<div class="modal fade" id="update_active_magazine_status" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content" id="new_status_options">

        </div>
    </div>
</div>
<div style="clear: both"></div>
<style type="text/css">
    .error_msg_for_trp{
        margin-left: 5px; display: inline-block; position: relative; top: 5px;
    }
</style>
<input type="hidden" id="system_base_url" value="<?php echo base_url();?>" />
<script src="<?php echo base_url(); ?>assets/library/jquery/jquery.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/subscriber.js"></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/custom.js"></script>
<script>
    $(document).ready(function() {
        $(".container article").click(function() {
            $(this).toggleClass("expand");
        })
    });
    function fnGetPreview(intTransactionId)
    {
        $.ajax({
            url:"<?php echo base_url();?>index.php/users/transaction_preview",
            'type' : 'GET',
            'data' : {
                'transaction_id' :intTransactionId
            },
            success:function(result){
                $("#tran_preview").html(result);
            }
        });
    }

    function add_new_comments()
    {
        window.open("http://www.w3schools.com", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=500, height=400");
    }

    function fnGetUpdateStatusOptions(intTransactionMagazineId, $intSubscriberId)
    {
        $.ajax({
            url:"<?php echo base_url();?>index.php/subscriber/rearrange_active_magazine",
            'type' : 'GET',
            'data' : {
                'prime_tran_id' :intTransactionMagazineId,
                'sub_id' :$intSubscriberId
            },
            success:function(result){
                $("#new_status_options").html(result);
            }
        });
    }

</script>