<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="" id="addSub">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal heading -->
<div class="modal-header">
    <a class="btn pull-right mar" href="<?php echo base_url(); ?>index.php/subscriber/subscriber_list"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> </a>
    <h3 class="modal-title" align="left">Edit Subscriber Details</h3>
    <!-- <div>
        <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-fw"></i>
            Back
        </a>
    </div> -->

</div>
<!-- // Modal heading END -->
<!-- Modal body -->
<div class="modal-body">
<div class="innerAll">
<div class="innerLR">
<form class="form-horizontal" role="form" id = "add_subscriber" action="<?php echo base_url();?>index.php/subscriber/edit_subscriber" method = "post" enctype="multipart/form-data">
<?php $this->load->view('admin/flashdata_admin'); ?>
<div class = "form-group mmar" id="give_msgs" style="text-align: center"></div>
<div class = "form-group mmar" id="all_msgs" style="text-align: center"></div>
<div class="form-group mmar">
    <label  class="col-sm-3 control-label text-center ">Upload  Subscriber Image: </label>
    <div class="col-sm-9">
        <input type="file" class="form-control" name = "sub_image" id="sub_image"/>
    </div>
</div>
<div  class="form-group mmar">
    <label  class="col-sm-3 control-label text-center">Previous Image: </label>
    <div class="col-sm-9">
        <? if ($details['photo'] != NULL) {?>
            <img src="<?php echo base_url(); ?>uploads/users/<?php echo $details['photo']; ?>" class="img-thumbnail prof-table-img" alt="people" />
        <?php } else {?>
            <img src="<?php echo base_url(); ?>assets/images/default_profile.jpg" class="img-thumbnail prof-table-img" alt="people" />
        <?php } ?>

    </div>
</div>
<!-- <div class="form-group mmar">
    <label  class="col-sm-3 control-label text-center">Salutation: </label>
    <div class="col-sm-2">
        <select class="cust_select col-md-12 marl-n validate[required] text-input" name = "sub_salution">
            <option value = "mr"
                <?php if ($details['salution'] == 'mr') {?> selected <?php } ?>
                >Mr.</option>
            <option value = "mrs"
                <?php if ($details['salution'] == 'mrs') {?> selected <?php } ?>
                >Mr.s</option>
        </select>
    </div>
    <label  class="col-sm-3 control-label text-center">Full Name: </label>
    <div class="col-sm-4">
        <input type="text" class="form-control validate[required, maxSize[100], custom[onlyLetterSp]] text-input" name = "sub_name" value = "<?php echo $details['name']; ?>"/>
    </div>

</div> -->
<div class="form-group mmar">
    <label  class="col-sm-3 control-label text-left">Surname: </label>
    <div class="col-sm-9">
        <input type="text" class="form-control" name = "sub_last_name" id = "sub_last_name" value="<?php if ($details['last_name'] != "") { echo $details['last_name']; }?>"/>
    </div>


</div>
<div class="form-group mmar">
    <label  class="col-sm-3 control-label text-left">Name: </label>
    <div class="col-sm-9">
        <input type="text" class="form-control" name = "sub_first_name" id = "sub_first_name" value="<?php if ($details['first_name'] != "") { echo $details['first_name']; }?>"/>
    </div>

</div>
<div class="form-group mmar">
    <label  class="col-sm-3 control-label text-left ">Date of Birth: </label>
    <div class="col-sm-4">
        <input type="text" class="form-control date" data-date-format="dd-mm-yyyy" name = "sub_dob" id = "sub_dob" value = "<?php if ($details['dob'] != "") { echo date("d-m-Y", strtotime($details['dob']));} ?>" readonly/>
    </div>

    <label  class="col-sm-2 control-label text-left ">NRIC: </label>
    <div class="col-sm-3">
        <input type="text" class="form-control" name = "sub_nric" id = "sub_nric" value = "<?php if ($details['nric'] != "") { echo $details['nric']; } ?>"/>
    </div>
</div>

<div class="form-group mmar">
    <label  class="col-sm-3 control-label text-left">Email ID: </label>
    <div class="col-sm-4">
        <input type="text" class="form-control" value="<?php if ($details['email'] != "") { echo $details['email']; } ?>" name = "sub_email" id = "sub_email"/>
    </div>
    <label  class="col-sm-2 control-label text-left">Gender: </label>
    <div class="col-sm-3">
        <select class="cust_select marl-n" id = "gender" name = "gender">
            <option value = "">--select--</option>
            <option value = "1" <?php if ($details['gender'] == '1') {?>selected="selected" <?php }?>>Male</option>
            <option value = "2" <?php if ($details['gender'] == '2') {?>selected="selected" <?php }?>>Female</option>
        </select>
    </div>
</div>

<div class="form-group mmar">
    <label  class="col-sm-3 control-label text-left">Phone No.: </label>
    <div class="col-sm-9">
        <div style="float: left;margin-right:5px;margin-left: 10px">
            <?php if (count($country_code) > 0) {?>
                <select name="country_code" id="country_code" class="cust_select marl-n" style="width:118px">
                    <option value="">Country Code</option>
                    <?php
                    foreach($country_code as $code => $name) {
                        echo $code;?>
                        <option value="<?php echo $code;?>"
                            <?php if ($details['country_code'] == $code) { ?> selected="selected" <?php } ?>
                            ><?php echo $name;?></option>
                    <?php } ?>
                </select>
            <?php } ?>
        </div>
        <div style="margin-left: 10px">
            <div id ="phone_no" style="float:left;margin-right:10px; margin-left: 15px" > +<?php echo $details['country_code']; ?> </div>
            <input type="text" class="form-control" value="<?php if($details['phone'] != "") { echo $details['phone']; } ?>" name = "sub_phonno" id = "sub_phonno" style="width:180px"/>
        </div>
    </div>
</div>
<div class="form-group mmar">
    <label  class="col-sm-3 control-label text-left">Mobile Number: </label>
    <div style="float: left;margin-right:5px;margin-left: 15px">
        <?php if (count($country_code) > 0) {?>
            <select name="country_code_mobile" id="country_code_mobile" class="cust_select marl-n validate[required] text-input" style="width:118px">
                <option value="">Country Code</option>
                <?php
                foreach($country_code as $code => $name) {?>
                    <option value="<?php echo $code;?>"
                        <?php if ($details['country_code_mobile'] == $code) { ?> selected="selected" <?php } ?>
                        ><?php echo $name;?></option>
                <?php } ?>
            </select>
        <?php } ?>
    </div>
    <div class="col-sm-6">
        <div id ="mobile_no" style="float:left;margin-right:10px;margin-left: 15px"> +<?php echo $details['country_code_mobile']; ?></div>
        <input type="text" class="form-control" name = "mobile_number" id = "mobile_number" value="<?php if($details['mobile']) { echo $details['mobile']; }?>" style="width: 180px"/>
    </div>
</div>

<div class="form-group mmar" style="margin-left: 10px">
    <label  class="col-sm-3 control-label text-left">Subscriber Type: </label>
    <div class="col-sm-9">
        <select class="cust_select marl-n validate[required] text-input" id = "subscriber_type" name = "sub_type">
            <option value = "1"
                <?php if ($details['subscriber_type'] == '1') {?> selected <?php } ?>
                >Individual</option>
            <option value = "2"
                <?php if ($details['subscriber_type'] == '2') {?> selected <?php } ?>
                >School Library</option>
            <option value = "3"
                <?php if ($details['subscriber_type'] == '3') {?> selected <?php } ?>
                >Student</option>
            <option value = "4"
                <?php if ($details['subscriber_type'] == '4') {?> selected <?php } ?>
                >Other</option>
        </select>
    </div>

</div>


<div class = "form-group mmar" id = "sub_details">
    <?php if (isset($details['company_name']) &&  $details['company_name'] != "") { ?>
        <label  class="col-sm-3 control-label text-left">Company Name: </label>
        <div class="col-sm-9">
            <input type="text" class="form-control validate[required] text-input" value="<?php echo  $details['company_name']; ?>" name= "cname"/>
        </div>
    <?php } ?>

    <?php if (isset($details['guardian_name']) &&  $details['guardian_name'] != "") { ?>
        <label  class="col-sm-3 control-label text-left">Guardian Name: </label>
        <div class="col-sm-9">
            <input type="text" class="form-control validate[required] text-input" value="<?php echo  $details['guardian_name']; ?>" name= "gname"/>
        </div>

        <br>
        <label  class="col-sm-3 control-label text-left">Guardian(2) Name: </label>
        <br>
        <div class="col-sm-9">
            <input type="text" class="form-control validate[required] text-input" value="<?php echo  $details['guardian2_name']; ?>" name= "gname2"/>
        </div>
    <?php } ?>
</div>
<div class = "form-group mmar" id = "sub_school_details">
    <?php if (isset($details['school_name']) &&  $details['school_name'] != "") { ?>
        <label  class="col-sm-3 control-label text-left">School Library Name: </label>
        <div class="col-sm-9">
            <input type="text" class="form-control validate[required] text-input" value="<?php echo  $details['school_name']; ?>" name= "sname"/>
        </div>
    <?php } ?>
</div>
<div class = "form-group mmar" id = "sub_teacher_details">
    <?php if (isset($details['teacher_name']) &&  $details['teacher_name'] != "") { ?>
        <label  class="col-sm-3 control-label text-left">Teacher Name: </label>
        <div class="col-sm-9">
            <input type="text" class="form-control validate[required] text-input" value="<?php echo  $details['teacher_name']; ?>" name= "tname"/>
        </div>
    <?php } ?>
</div>
<div class = "form-group mmar" id = "sub_other_details">
    <?php if (isset($details['other_details']) &&  $details['other_details'] != "") { ?>
        <label  class="col-sm-3 control-label text-left">Details: </label>
        <div class="col-sm-9">
            <input type="text" class="form-control validate[required] text-input" value="<?php echo  $details['other_details']; ?>" name= "other_details"/>
        </div>
    <?php } ?>
</div>

<div class="modal-header">
    <h3 class="modal-title">Subscription References</h3>
</div>

<div class="form-group mmar">
    <!-- <label  class="col-sm-3 control-label text-left">Campaign: </label>
    <div class="col-sm-3">
        <select class="cust_select marl-n" id = "campaign" name = "campaign">
            <option value = "">--Select--</option>
            <?php //foreach($arrCampaign as $campaign) {?>
                <option value = "<?php //echo $campaign['id'];?>"
                        <?//php if($campaign['id'] == $details['campaign_id']) {?>selected="selected" <?php //} ?>><?php //echo $campaign['name'];?></option>
            <?php //} ?>
        </select>
    </div> -->
    <label  class="col-sm-3 control-label text-left">Sales Agent: </label>
    <div class="col-sm-3">
        <select class="cust_select marl-n" id = "sales_agent" name = "sales_agent">
            <option value = "">--Select--</option>
            <?php foreach($arrAgent as $Agent) {?>
                <option value = "<?php echo $Agent['id'];?>"
                        <?php if($Agent['id'] == $details['sales_agent']) {?>selected="selected" <?php } ?>><?php echo $Agent['first_name']." ".$Agent['last_name'];?></option>
            <?php } ?>
        </select>
    </div>

</div>

<div class="modal-header">
    <h3 class="modal-title">Home Address</h3>
</div>
<div class="form-group mmar">
    <label  class="col-sm-3 control-label text-left">Country: </label>
    <div class="col-sm-3">
        <select class="cust_select marl-n" name = "sub_home_country" id = "sub_home_country">
            <option value="">-- Select --</option>
            <option value = "1"
                <?php if ($details['home_country'] == '1') {?> selected <?php } ?>
                >Singapore</option>
            <option value = "2"
                <?php if ($details['home_country'] == '2') {?> selected <?php } ?>
                >Malaysia</option>
            <option value = "3"
                <?php if ($details['home_country'] == '3') {?> selected <?php } ?>
                >Hong Kong</option>
            <option value = "4"
                <?php if ($details['home_country'] == '4') {?> selected <?php } ?>
                >Malaysia</option>
        </select>
    </div>
    <label  class="col-sm-3 control-label text-left">City: </label>
    <div class="col-sm-3">
        <select class="cust_select marl-n" name = "sub_home_city" id = "sub_home_city">
            <option value="">-- Select --</option>
            <option value = "1"
                <?php if ($details['home_city'] == '1') {?> selected <?php } ?>
                >Singapore</option>
            <option value = "2"
                <?php if ($details['home_city'] == '2') {?> selected <?php } ?>
                >Kuala Lumpur</option>
            <option value = "3"
                <?php if ($details['home_city'] == '3') {?> selected <?php } ?>
                >Victoria City</option>
            <option value = "4"
                <?php if ($details['home_city'] == '4') {?> selected <?php } ?>
                >Bankok</option>
        </select>
    </div>
</div>
<div id="home_address_id">
    <div class="form-group mmar">
        <label  class="col-sm-3 control-label text-left">Block: </label>
        <div class="col-sm-3">
            <input type="text" class="form-control" name = "sub_home_block" id = "sub_home_block" value = "<?php if($details['home_block'] != null) { echo $details['home_block']; } ?>"/>
        </div>
        <label  class="col-sm-3 control-label text-left">Unit No.: </label>
        <div class="col-sm-3">
            <input type="text" class="form-control" name = "sub_home_unit_no" id = "sub_home_unit_no" value = "<?php echo $details['home_unit_no']; ?>"/>
        </div>
    </div>
    <div class="form-group mmar">
        <label  class="col-sm-3 control-label text-left">Street name: </label>
        <div class="col-sm-3">
            <input type="text" class="form-control" name = "sub_home_street" id = "sub_home_street" value = "<?php echo $details['home_street_name']; ?>"/>
        </div>
        <label  class="col-sm-3 control-label text-left">Building Name: </label>
        <div class="col-sm-3">
            <input type="text" class="form-control " name = "sub_home_build" id = "sub_home_build" value = "<?php if ($details['building_name_home'] != "") { echo $details['building_name_home']; } ?>"/>
        </div>
    </div>
    <div class="form-group mmar">
        <label  class="col-sm-3 control-label text-left">Postal Code: </label>
        <div class="col-sm-5">
            <input type="text" class="form-control" name = "sub_home_code" id = "sub_home_code" value = "<?php if ($details['home_postal_code'] != "") { echo $details['home_postal_code']; } ?>"/>
        </div>
    </div>
</div>
<div class="form-group mmar" id="address_1">
    <label  class="col-sm-3 control-label text-left">Address 1: </label>
    <div class="col-sm-9">
        <textarea name="address_1" id="address_1_text" class="form-control" placeholder="please enter address 1"><?php echo $details['address_1']; ?></textarea>
    </div>
</div>
 <div class="form-group mmar">
    <input type="checkbox" name="same_above" id="same_above" value="same" onclick="sameAsAbove()"/> <b>Mailing address same as above</b>
    <br/>
</div>

<div style = "clear:both">
    <div class="modal-header">
        <h3 class="modal-title">Mailing Address</h3>
    </div>
    <div class="form-group mmar">
        <label  class="col-sm-3 control-label text-center ">Country: </label>
        <div class="col-sm-3">
            <select class="cust_select marl-n validate[required] text-input" name = "sub_country" id = "sub_country">
                <option value="">-- Select --</option>
                <option value = "1"
                    <?php if ($details['mailing_country'] == '1') {?> selected <?php } ?>
                    >Singapore</option>
                <option value = "2"
                    <?php if ($details['mailing_country'] == '2') {?> selected <?php } ?>
                    >Malaysia</option>
                <option value = "3"
                    <?php if ($details['home_country'] == '3') {?> selected <?php } ?>
                    >Hong Kong</option>
                <option value = "4"
                    <?php if ($details['home_country'] == '4') {?> selected <?php } ?>
                    >Malaysia</option>
            </select>
        </div>
        <label  class="col-sm-3 control-label text-center">City: </label>
        <div class="col-sm-3">
            <select class="cust_select marl-n validate[required] text-input" name = "sub_city" id = "sub_city">
                <option value="">-- Select --</option>
                <option value = "1"
                    <?php if ($details['mailing_city'] == '1') {?> selected <?php } ?>
                    >Singapore</option>
                <option value = "2"
                    <?php if ($details['mailing_city'] == '2') {?> selected <?php } ?>
                    >Kuala Lumpur</option>
                <option value = "3"
                    <?php if ($details['home_city'] == '3') {?> selected <?php } ?>
                    >Victoria City</option>
                <option value = "4"
                    <?php if ($details['home_city'] == '4') {?> selected <?php } ?>
                    >Bankok</option>
            </select>
        </div>
    </div>
    <div id="mail_address_all_field">
        <div class="form-group mmar">
            <label  class="col-sm-3 control-label text-center">Block: </label>
            <div class="col-sm-3">
                <input type="text" class="form-control" name = "sub_block" value = "<?php if ($details['mailing_block'] != "") { echo $details['mailing_block']; } ?>" id = "sub_block"/>
            </div>
            <label  class="col-sm-3 control-label text-center">Unit No.: </label>
            <div class="col-sm-3">
                <input type="text" class="form-control" name = "sub_unit_no" value = "<?php if($details['mailing_unit_no'] != "") { echo $details['mailing_unit_no']; } ?>" id = "sub_unit_no"/>
            </div>
        </div>
        <div class="form-group mmar">
            <label  class="col-sm-3 control-label text-center">Street name: </label>
            <div class="col-sm-3">
                <input type="text" class="form-control" name = "sub_street" value = "<?php if ($details['mailing_street_name'] != "") { echo $details['mailing_street_name']; }?>" id = "sub_street"/>
            </div>
            <label  class="col-sm-3 control-label text-left">Building Name: </label>
            <div class="col-sm-3">
                <input type="text" class="form-control " name = "sub_build" id = "sub_build" value = "<?php if($details['building_name_mail'] != "") { echo $details['building_name_mail']; } ?>"/>
            </div>
        </div>
        <div class="form-group mmar">
            <label  class="col-sm-3 control-label text-left ">Postal Code: </label>
            <div class="col-sm-5">
                <input type="text" class="form-control validate[required] text-input" name = "sub_code" value = "<?php if($details['mailing_postal_code'] != "") { echo $details['mailing_postal_code']; } ?>" id = "sub_code"/>
            </div>

        </div>
    </div>
    <div class="form-group mmar" id="address_2">
        <label  class="col-sm-3 control-label text-left">Address 2: </label>
        <div class="col-sm-9">
            <textarea name="address_2" id="address_2_text" class="form-control" placeholder="please enter address 1"><?php echo $details['address_2']; ?></textarea>
        </div>
    </div>

</div>
<div class="form-group">
    <div class="col-sm-offset-4 col-sm-8">
        <button type="submit" class="btn btn-primary" id="submit_sub">Submit</button>
        <a class="btn" href="<?php echo base_url(); ?>index.php/subscriber/subscriber_list"> <button type="button" class="btn btn-primary">Cancel</button></a>
    </div>
</div>
<input type="hidden" id="system_base_url" value="<?php echo base_url();?>">
<input type = "hidden" name = "comp_name"  id = "comp_name" value ="<?php echo $details['company_name'];?>" />
<input type = "hidden" name = "guard_name"  id = "guard_name" value ="<?php echo $details['guardian_name'];?>" />
<input type = "hidden" name = "guard_name2"  id = "guard_name2" value ="<?php echo $details['guardian2_name'];?>" />
<input type = "hidden" name = "school_name"  id = "school_name" value ="<?php echo $details['school_name'];?>" />
<input type = "hidden" name = "other_detas"  id = "other_details" value ="<?php echo $details['other_details'];?>" />
<input type = "hidden" name = "prevEmail"  id = "prevEmail" value ="<?php echo $details['email'];?>" />
<input type = "hidden" name = "user_id"  id = "user_id" value ="<?php echo base64_encode($details['id']);?>" />

<input type = "hidden" name = "prevNric"  id = "prevNric" value ="<?php echo $details['nric'];?>" />
<input type = "hidden" name = "prevFirstName"  id = "prevFirstName" value ="<?php echo $details['first_name'];?>" />
<input type = "hidden" name = "prevLastName"  id = "prevLastName" value ="<?php echo $details['last_name'];?>" />
<input type = "hidden" name = "prevDob"  id = "prevDob" value ="<?php echo date("d-m-Y", strtotime($details['dob']));?>" />
<input type = "hidden" name = "given_overseas_type"  id = "given_overseas_type" value ="<?php echo (int)$details['is_overseas'];?>" />
</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_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() {
        $("#add_subscriber").validationEngine();

        if (parseInt($('#given_overseas_type').val()) == 1) {
            $("#address_2").show();
            $("#address_1").show();
            $("#mail_address_all_field").hide();
            $("#home_address_id").hide();
        } else {
            $("#address_2").hide();
            $("#address_1").hide();
            $("#mail_address_all_field").show();
            $("#home_address_id").show();
        }
        $("#sub_country").change(function(){
            var country_val = parseInt($("#sub_country").val());
            if (country_val > 1) {
                $("#address_2").show();
                $("#mail_address_all_field").hide();
            } else {
                $("#address_2").hide();
                $("#mail_address_all_field").show();
            }
        });

        $("#sub_home_country").change(function(){
            var sub_home_country = parseInt($("#sub_home_country").val());
            if (sub_home_country > 1) {
                $("#address_1").show();
                $("#home_address_id").hide();
            } else {
                $("#address_1").hide();
                $("#home_address_id").show();
            }
        });
    });
    function sameAsAbove(){
        if($('#same_above').is(":checked")) {
            $('#sub_block').val($('#sub_home_block').val());
            $('#sub_unit_no').val($('#sub_home_unit_no').val());
            $('#sub_street').val($('#sub_home_street').val());
            $('#sub_country').val($('#sub_home_country').val());
            $('#sub_city').val($('#sub_home_city').val());
            $('#sub_build').val($('#sub_home_build').val());
            $('#sub_code').val($('#sub_home_code').val());
            $("#address_2_text").val($("#address_1_text").val());

            var intCountryVal = parseInt($("#sub_country").val());
            if (intCountryVal > 1) {
                $("#address_2").show();
                $("#mail_address_all_field").hide();
            } else {
                $("#address_2").hide();
                $("#mail_address_all_field").show();
            }

        }
    }
</script>
