<!--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">
            <a href="<?php echo base_url(); ?>smis/add_Student/" class="btn btn-sm btn-success">Add Student</a>
            <input type="submit" value="Set Role" id="change_role_button" class="btn btn-sm btn-success"  data-toggle="modal" data-target="#setRole" disabled="true">
            <input type="submit" value="Assign Course" id="assign_course" class="btn btn-sm btn-success"  data-toggle="modal" data-target="#assignCourse" disabled="true">
            <input type="submit" value="Change Status" id="change_status_button" class="btn btn-sm btn-success"  data-toggle="modal" data-target="#changeStatus" disabled="true">
        </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">
            <hr>
            <div class="">
                <a href="<?php echo base_url(); ?>super_admin">Dashboard</a>->>
                <span> Student Detail</span>
                <div>
                    <?php
                    $message = $this->session->userdata('message');
                    if ($message) {
                        echo $message;
                    }
                    ?>
                </div>
            </div>
            <hr>

            <div class="span11 right">
                <div class="col-lg-6 col-md-4" ><h4> Student Information</h4> </div>
            </div>
            <!--    
            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-5 col-md-5 col-sm-5">
                        <div class="col-xs-6 col-md-5">
                            <a href="<?php echo base_url(); ?>super_admin_student/student_list" class="thumbnail">
                                <img src="<?php echo base_url() . $student_info->person_image_thumb; ?>" alt="..." width="100px" height="100px">
                            </a>
                        </div>
                        <div class="span10">
                            <div class="col-sm-3 col-md-3">Name</div>
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_first_name . $student_info->person_last_name; ?></div>
                        </div>
                        <br><br>
                        <div class="span10">
                            <div class="col-sm-3 col-md-3">Email</div>
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_email; ?></div>
                        </div>
                        <br><br>
                        <div class="span10">
                            <div class="col-sm-3 col-md-3">Contact Number</div>
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_contact_number; ?></div>
                        </div>
                    </div>

                    <div class="col-lg-5 col-md-5 col-sm-5">
                        <div class="span10">
                            <div class="col-sm-3 col-md-3">Person ID</div>
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_id; ?></div>
                        </div>
                        <br><br>
                        <div class="span10">
                            <div class="col-sm-3 col-md-3">Email</div>
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_country; ?></div>
                        </div>
                        <br><br>
                        <div class="span10">
                            <div class="col-sm-3 col-md-3">Contact Number</div>
                            <div class="col-sm-3 col-md-6"><?php echo $student_info->person_city; ?></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="table-responsive col-lg-11 col-md-10 col-sm-7" id="student_list">
                <br>
                <br>
                <h3>Student Al Invoice</h3>
            </div>
            <div class="row">
                <form name="myform" action=""  method="post">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th><input type="checkbox" name="all_student" id="all_student" onchange="toggleAllStudentSelection(document.myform.student_id);"/></th>
                                <th>Payment ID</th>
                                <th>Invoice No</th>
                                <th>Payment Date</th>
                                <th>Due Date</th>
                                <th>Payment Amount</th>
                                <th>Discount Amount</th>
                                <th>Paid Amount</th>
                                <th>payment Detail</th>
                                <th>payment Status</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $i = 1;
                            $total_price = 0;
                            $total_paid_amount = 0;
                            $total_due = 0;
                            $discount_price = 0;
                            $discount = 0.00;
                            foreach ($student_all_invoice as $v_payment) {
                                ?>
                                <tr>
                                    <td><input name="student_id" id="student_id" type="checkbox"  value="" onchange="setStudentIdList(this.value);"/></td>
                                    <td style="width:30px;"><?php echo $i++; ?></td>
                                    <td style="width:30px;"><?php echo $v_payment->invoice_number; ?></td>
                                    <td><?php echo $v_payment->paid_on; ?></td>
                                    <td ><?php echo $v_payment->due_date; ?></td>
                                    <td style="width:100px;"><?php echo $v_payment->course_price; ?></td>

                                    <?php
                                    $price = $v_payment->course_price;
                                    $discount = $v_payment->coupon_discount_amount;
                                    if ($discount != 0) {
                                        $discount_price = $price - (($price * $discount) / 100);
                                        $price = $discount_price;
                                    }
                                    ?>

                                    <td style="width:100px;"><?php echo $discount_price ?></td>
                                    <td style="width:100px;"><?php echo $v_payment->total ?></td>
                                    <?php $due = $price - $v_payment->total; ?>
                                    <td><?php echo $due; ?></td>
                                    <td style="width:200px;">
                                        <?php
                                        if ($v_payment->cash_payment_receipt_no) {
                                            echo $v_payment->cash_payment_receipt_no;
                                        }
                                        if ($v_payment->check_payment_receipt_no) {
                                            echo $v_payment->check_payment_receipt_no;
                                        }
                                        if ($v_payment->bkash_payment_no) {
                                            echo $v_payment->bkash_payment_no;
                                        }
                                        if ($v_payment->credit_card_type) {
                                            echo $v_payment->credit_card_type;
                                        }
                                        if ($v_payment->credit_card_number) {
                                            echo $v_payment->credit_card_number;
                                        }
                                        if ($v_payment->credit_card_expiry_date) {
                                            echo $v_payment->credit_card_expiry_date;
                                        }
                                        if ($v_payment->credit_card_verification_number) {
                                            echo $v_payment->credit_card_verification_number;
                                        }
                                        if ($v_payment->paypal_email_address) {
                                            echo $v_payment->paypal_email_address;
                                        }
                                        if ($v_payment->bkash_payment_no) {
                                            echo $v_payment->bkash_payment_no;
                                        }
                                        if ($v_payment->money_receipt_number) {
                                            echo $v_payment->money_receipt_number;
                                        }
                                        ?>
                                    </td>
                                    <!-- Actions -->

                                    <td>
                                        <?php
                                        if ($v_payment->payment_status == '1') {
                                            echo 'Paid';
                                            ?>
                                            <?php
                                        } else if ($v_payment->payment_status == '2') {
                                            echo 'Partialy Paid';
                                            ?>
                                            <?php
                                        } else if ($v_payment->payment_status == '3') {
                                            echo 'Unpaid';
                                        } else if ($v_payment->payment_status == '4') {
                                            echo 'Canceled';
                                            ?>                                            
                                        <?php } ?>
                                    </td>
                                    <td>
                                    <td>
                                        <a href="<?php echo base_url(); ?>super_admin_student/pay_for_course/<?php echo $v_payment->payment_id . '/' . $v_payment->course_batch_id; ?>"><div class="span1"><i class="fa fa-edit">Pay Due</i></div></a>
                                        <a href="<?php echo base_url() ?>super_admin_student/student_all_invoice/<?php echo $v_payment->person_id.'/'.$this->uri->segment(4); ?>">View Invoices</a><br>
                                    </td>
                                </tr>
                                <?php
                                $total_price += $price;
                                $total_paid_amount += $v_payment->total;
                                $total_due += $due;
                            }
                            ?>
                            <tr style="color:white; font-size: 15px; background-color: grey;"> 
                                <td></td>
                                <td><span><b>Total</b></span></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td colspan="2" style="background-color: #333333; color: white;"><center><b><?php echo $total_price; ?></center></b></td>
                        <td><b><?php echo $total_paid_amount;    ?></b></td>
                        <td><b><?php echo $total_due;    ?></b></td>
                        <td></td>
                        <td></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>
