<!--Add / Change / Assign / Short-->
<div id="change">
    <div class="col-sm-10 col-sm-offset-3 main col-md-10 col-md-offset-2 main">
        <div class="col-sm-4 col-md-7">
            <!--Header Button Here-->

        </div>

        <!-- Student List with Some Action  -->    
        <div class="container col-sm-8 col-sm-offset-2 col-md-offset-0 col-md-12" id="res">
            <div class="span11 right">
                <div class="col-lg-6 col-md-4" ><h4> Student Billing Information</h4> </div>
            </div>
            <br>
            <hr>
            <div class="">
                <a href="<?php echo base_url().$this->uri->segment(1); ?>">Dashboard</a>->>
                <span><a href="<?php echo base_url().$this->uri->segment(1).'/student_detail/'.$student_info->person_id.''; ?>" > Student Detail</a></span>->>
                <span> Student Course Invoice</span>
                <div>
                    <?php
                    $message = $this->session->userdata('message');
                    if ($message) {
                        echo $message;
                    }
                    ?>
                </div>
            </div>
            <hr>


            <!--    
            Only List with Pagination 
            Change Status / Edit / Delete
            -->
            <div class="col-lg-12 col-md-8 col-sm-7" id="student_list">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6">
                        <span><b>Invoice: </b><?php echo '#' . $student_course_invoice->invoice_number; ?></span>
                    </div>
                    <div class="col-lg-6 col-md-6 col-sm-6">
                        <div class="col-sm-12">
                            <div class="col-sm-6">
                                <select class="form-control col-sm-5" name="payment_method" id="payment_method">
                                    <option value="">select Payment Method</option>
                                    <!--<option value="1">Paypal</option>-->
                                    <option value="2">Credit Card</option>
                                    <!--<option value="3">Account Pay</option>-->
                                    <!--<option value="4">bKash</option>-->
                                    <!--<option value="5">Hand Cash</option>-->
                                </select>
                            </div>
                            <div class="col-sm-6">
                                <button class="col-sm-12" style="font-size: 12px; color: white; background-color: green;">Choose Payment Method</button>
                            </div>
                        </div>
                    </div>
                    <hr>
                    <div class="col-lg-6 col-md-6 col-sm-6">
                        <div class="span10">
                            <span><b>TO</b></span>
                        </div>
                        <div class="span10">
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_first_name . $student_info->person_last_name; ?></div>
                        </div><br>
                        <div class="span10">
                            <div class="col-sm-3 col-md-6"></div>
                        </div><br>
                        <div class="span10">
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_address; ?></div>
                        </div><br>
                        <div class="span10">
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_city; ?></div>
                        </div><br>
                        <div class="span10">
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_country; ?></div>
                        </div>
                    </div>

                    <div class="col-lg-6 col-md-6 col-sm-6">
                        <br><br><br><br>
                        <div class="col-sm-12">
                            <div class="col-sm-3 col-md-3">Invoice Date</div>
                            <div class="col-sm-3 col-md-6"><?php echo $student_course_invoice->paid_on; ?></div>
                        </div>
                        <br>
                        <div class="col-sm-12">
                            <div class="col-sm-3 col-md-3">Invoice Due Date</div>
                            <div class="col-sm-3 col-md-6"><?php echo $student_course_invoice->due_date; ?></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-lg-12 col-md-8 col-sm-7">

            </div>

            <div class="row">
                <form name="myform" action=""  method="post">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>Description</th>
                                <th>Unit Price</th>
                                <th>Quantity</th>
                                <th>Total Price</th>
                                <th>Discount Price</th>
                                <th>Line Total</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
//                            foreach ($student_course_invoice as $student_course_invoice) {
                            ?>
                            <tr>
                                <td style="width:200px;"><?php echo $student_course_invoice->payment_description; ?></td>
                                <td style="width:20px;"><?php echo $student_course_invoice->unit_price; ?></td>
                                <td style="width:20px;"><?php echo $student_course_invoice->quantity; ?></td>
                                <?php
                                $price = $student_course_invoice->unit_price * $student_course_invoice->quantity;
                                ?>

                                <td style="width:20px;"><?php echo $price; ?></td> 
                                <?php
                                $dis_amount = $student_course_invoice->coupon_discount_amount;
                                if ($dis_amount) {
                                    $discount = ($dis_amount * $price) / 100;
                                    $discount_price = $price - $discount;
                                    $price = $discount_price;
                                }
                                ?>
                                <td style="width:20px;"><?php echo $discount_price . '(' . $dis_amount . '%)'; ?></td>
                                <td style="width:20px;"><?php echo $price; ?></td>
                            </tr>
                            <?php // }   ?>
                            <tr>
                                <td style="width:200px;background-color: none"></td>
                                <td style="width:20px;"></td>
                                <td style="width:20px;"></td>
                                <td style="width:20px;"></td>
                                <td style="width:20px; background-color: grey;color: white;"><b>Subtotal:</b></td>
                                <td style="width:20px; background-color: grey;color: white;"><?php echo ''; ?></td>
                            </tr>
                            <tr>
                                <td style="width:200px;"></td>
                                <td style="width:20px;"></td>
                                <td style="width:20px;"></td>
                                <td style="width:20px;"></td>
                                <td style="width:20px; background-color: grey;color: white;"><b>Total:</b></td>
                                <td style="width:20px; background-color: grey; color: white;"><?php echo $price; ?></td>
                            </tr>
                        </tbody>
                    </table>
                    <br>
                </form>
            </div>
        </div>  
    </div>


    <script type="text/javascript">
        document.forms['pagination'].elements['per_page'].value = '<?php echo $limit ?>';
        document.forms['control_form'].elements['student_status'].value = '<?php echo $status; ?>';
        document.forms['control_form'].elements['student_role_id2'].value = '<?php echo $type_id; ?>';
    </script>



    <!-- Modal Start For Change Role and Status-->

    <!--
    
    Modal:
    Change Role
    
    -->

    <div class="modal fade" id="setRole" tabindex="-1" role="dialog" aria-labelledby="setRole" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Change Role</h4>
                </div>
                <form name="setRole">
                    <div class="modal-body">

                        <label for="user_role_id">Set To Role:</label><span>*</span>
                        <select class="form-control" name="user_role_id" id="user_role_id">
                            <option value="">--Select User Type--</option>
                            <option value="1">Admin</option>
                            <option value="2">Account</option>
                            <option value="3">Resource</option>
                            <option value="4">Register</option>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary" onclick="setStudentRole();">Save changes</button>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <!--
    
    Modal:: 
    Change Status
    
    -->

    <div class="modal fade" id="changeStatus" tabindex="-1" role="dialog" aria-labelledby="changeStatus" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Change Student Status</h4>
                </div>
                <form>
                    <div class="modal-body">
                        <h3>Select Status</h3>
                        <select class="form-control" name="change_status" id="change_status" required>
                            <option value="">--Select Student Status--</option>
                            <option value="1">Active</option>
                            <option value="2">Inactive</option>
                            <option value="3">Archive</option>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" onclick="changeStudentsStatus();">Save changes</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- Modal END For Change Role and Status-->


    <!-- Assign Course To Student List -->

    <div class="modal fade" id="assignCourse" tabindex="-1" role="dialog" aria-labelledby="assignCourse" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Assign Course </h4>
                </div>
                <form>
                    <div class="modal-body">
                        <div id="category" class="col-sm-9 col-md-10 col-md-offset-1">
                            <label>Select Category</label>
                            <select class="form-control span5" name="category_id" id="category_id" required onchange="selectCategoryCourse(this.value, 'course_list');">
                                <option value="">--Select Course Category--</option>
                                <?php foreach ($course_categories as $v_category) { ?>                                                    
                                    <option value="<?php echo $v_category->category_id; ?>"> <?php echo $v_category->category_name; ?></option>
                                <?php } ?>
                            </select>
                        </div>
                        <div id="course_list" class="col-sm-9 col-md-10 col-md-offset-1"></div>

                    </div>
                    <br>
                    <hr>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" onclick="assignCourse();">Assign</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!--
    Print Preview and then Print option
    -->

    <div class="modal fade" id="print" tabindex="-1" role="dialog" aria-labelledby="print" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Change Role</h4>
                </div>
                <form name="print">
                    <div class="modal-body">

                        <label for="student_role_id">Student role:</label><span>*</span>
                        <select class="form-control" name="student_role_id" id="student_role_id" required>
                            <option value="">--Select Student Role--</option>
                            <?php foreach ($student_types as $v_student_role) { ?>
                                <option value="<?php echo $v_student_role->student_role_id; ?>" <?php
                                if ($v_student_role->role_name == $student_type) {
                                    echo 'selected';
                                }
                                ?>> <?php echo $v_student_role->role_name ?></option>
                                    <?php } ?>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" onclick="printDiv('student_list');">print</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </form>
            </div>
        </div>
    </div>



    <!--
    
    Modal:: 
    IMPORT FILE FORM
    
    -->

    <div class="modal fade" id="importFile" tabindex="-1" role="dialog" aria-labelledby="importFile" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Add Student</h4>
                </div>
                <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                    <p>
                        <?php
                        $message = $this->session->userdata('message');
                        $this->session->unset_userdata('message');
                        if ($message) {
                            echo $message;
                        }
                        ?>
                    </p>
                    <div class="table-responsive col-sm-12">
                        <?php // echo validation_errors();                 ?>
                        <form action="<?php echo base_url(); ?>super_admin/import_student_csv_file" method="post" name="import_csv" enctype="multipart/form-data" >
                            <div class="form-group col-sm-8" >
                                <label for="student_info_file" style="float:left;">Select CSV File</label><span class="required"> * <?php // echo form_error('student_image');                                                                        ?></span><br><br>
                                <input style="float:left;" type='file' onchange="readURL(this, 'file_0');" name="student_info_file" value="<?php // echo set_value('student_image');                                                                        ?>"/>
                                <div id="file" style="float:left;width: 50px; height: 50px;" ></div>
                            </div>
                            <div class="form-group col-sm-8" >
                                <label for="student_person_info_file" style="float:left;">Select CSV File</label><span class="required"> * <?php // echo form_error('student_image');                                                                        ?></span><br><br>
                                <input style="float:left;" type='file' onchange="readURL(this, 'file_0');" name="student_person_info_file" value="<?php // echo set_value('student_image');                                                                        ?>"/>
                                <div id="file" style="float:left;width: 50px; height: 50px;" ></div>
                            </div>
                            <div class="checkbox col-sm-8" >
                                <button type="submit" class="btn btn-default">Submit</button>
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <!--<button type="button" class="btn btn-primary">Save changes</button>-->
                </div>
            </div>
        </div>
    </div>



    <SCRIPT LANGUAGE="JavaScript">

        studentList = '';

        /*
         * Set All Student ID to Javascript studentList variable 
         */
        function toggleAllStudentSelection(field) {
            allStudent = document.getElementById("all_student").checked;
            if (allStudent) {
                for (i = 0; i < field.length; i++) {
                    field[i].checked = true;
                    studentList += field[i].value + '.';
                }
                document.getElementById('change_role_button').disabled = false;
                document.getElementById('assign_course').disabled = false;
                document.getElementById('change_status_button').disabled = false;
            } else {
                for (i = 0; i < field.length; i++)
                    field[i].checked = false;
                studentList = '';
                document.getElementById('change_role_button').disabled = true;
                document.getElementById('assign_course').disabled = true;
                document.getElementById('change_status_button').disabled = true;
            }
        }


        /*
         * Set single Student ID to Javascript studentList variable 
         */
        function setStudentIdList(studentID)
        {
            if ($("#student_id" + studentID).is(":checked")) {
                studentList += studentID + '.';
            } else {
                studentList = studentList.replace(studentID + ".", "");
            }
            if (studentList) {
                document.getElementById('change_role_button').disabled = false;
                document.getElementById('assign_course').disabled = false;
                document.getElementById('change_status_button').disabled = false;
            } else {
                document.getElementById('change_role_button').disabled = true;
                document.getElementById('assign_course').disabled = true;
                document.getElementById('change_status_button').disabled = true;
            }
        }


        /*
         * Delete Action Confirmation
         */
        function checkAction(action) {
            message = 'do you want to ' + action + '!!';
            chk = confirm(message);
            if (chk) {
                return true;
            } else {
                return false;
            }
        }

        /*
         * Change Student Role Using JavaScript studentList variable (From Modal)
         */
        function setStudentRole()
        {
            studentRoleId = document.getElementById("student_role_id").value;
            serverPage = '<?php echo base_url(); ?>smis/set_students_role/' + studentList + '/' + studentRoleId;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
                {
                    document.getElementById('res').innerHTML = xmlhttp.responseText;
                    localtion.reload();
                }
            };
            xmlhttp.send(null);
        }


        /*
         * Change Student Status Using JavaScript studentList variable (From Modal)
         */
        function changeStudentsStatus()
        {
            studentStatus = document.getElementById("change_status").value;
            serverPage = '<?php echo base_url(); ?>super_admin/change_students_status/' + studentList + '/' + studentStatus;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
                {
                    document.getElementById(objID).innerHTML = xmlhttp.responseText;
                    localtion.reload();
                }
            };
            xmlhttp.send(null);
        }

        /*
         * Select Course By category Id
         */

        function selectCategoryCourse(categoryID, objID) {
            serverPage = '<?php echo base_url(); ?>cmis/select_all_available_course_by_cateogy_id/' + categoryID;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                //                alert(xmlhttp.readyState);
                //                alert(xmlhttp.status);
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
                {
                    document.getElementById(objID).innerHTML = xmlhttp.responseText;
                    localtion.reload();
                }
            };
            xmlhttp.send(null);
        }

        /*
         * Assign Course to Student Using JavaScript studentList variable (From Modal)
         */
        function assignCourse()
        {
            courseID = document.getElementById("course_id").value;
            serverPage = '<?php echo base_url(); ?>smis/assign_course_to_student/' + studentList + '/' + courseID;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                alert(xmlhttp.readyState + xmlhttp.status);
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
                {
                    alert(xmlhttp.responseText);
                    location.reload();
                }
            };
            xmlhttp.send(null);
        }



        /*
         * Select Student By Student Type and Status 
         */
        function selectStudent(roleID, studentStatus, objID) {
            if (roleID === '') {
                serverPage = '<?php echo base_url(); ?>super_admin/select_student_list/' + null + '/' + studentStatus + '/' + 0;
            } else {
                serverPage = '<?php echo base_url(); ?>super_admin/select_student_list/' + roleID + '/' + studentStatus + '/' + 0;
            }

            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
                {
                    document.getElementById(objID).innerHTML = xmlhttp.responseText;
                }
            };
            xmlhttp.send(null);
        }


        /*
         * Set Per Page List Value
         */
        function setPerPage(perPage) {

            serverPage = '<?php echo base_url(); ?>smis/set_per_page/' + perPage;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
                {
                    location.reload();
                }
            };
            xmlhttp.send(null);
        }


        /*
         * Send Mail To Selected Student using studentList
         */
        function sendMailToStudent() {
            if (studentList === '') {
                studentList = '';
                window.location = '<?php echo base_url(); ?>smis/send_mail_to_student/' + studentList;
            } else {
                window.location = '<?php echo base_url(); ?>smis/send_mail_to_student/' + studentList;
            }
        }


        /*
         * Print Student List
         */
        function printPreview(divName) {
            serverPage = '<?php echo base_url(); ?>super_admin/make_print_data/' + studentList;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
                {
                    window = document.getElementById('print_preview').innerHTML = xmlhttp.responseText;
                }
            };
            xmlhttp.send(null);
        }

    </script>
</div>
