<?php
//$this->load->library('ForeignExchange');
//$fx = new ForeignExchange('BDT', 'USD');

if ($course_type == 'free') {
    if ($total_free_courses > 0) {
        $i = 0;
        foreach ($free_courses as $course_value) {
            $i++;
            ?>
            <div class="col-sm-12 white text-center">
                <div class="col-sm-9 text-center" style="padding-top: 10px ">
                    <a href="<?php echo base_url() . $course_value->url; ?>" target="_blank" >
                        <span id="courseNameView<?php echo $course_value->url ?>">
                            <?php
                            if (strlen($course_value->course_name) > 50) {
                                echo mb_substr($course_value->course_name, 0, 50, 'utf-8');
                            } else {
                                echo $course_value->course_name;
                            }
                            ?>
                        </span>
                    </a>
                    <?php
                    if (strlen($course_value->course_name) > 50) {
                        echo '<span id="moreCourseNameView' . $course_value->url . '" style="cursor:pointer;padding-right: 10px;">>>></span>';
                    }
                    ?>
                    <input type="hidden" id="hiddenCourseName<?php echo $course_value->url ?>" value="<?php echo $course_value->course_name ?>">
                </div>

                <div class="col-sm-3 text-center" style="padding-top: 10px">
                    <!--<a href="<?php // echo base_url() . 'course/' . $course_value->url . '/schedule'                                                       ?>">-->
                        <!--<i class="fa fa-calendar" title="View Schedule"></i>-->
                    <!--&nbsp;&nbsp;&nbsp;-->
                    <!--</a>-->

            <!--                    <a href="javascript:;<?php // echo base_url() . 'course/' . $value->url . '/certificate'                                                                          ?>">
                                    <i class="fa  fa-graduation-cap" title="View Certificate"></i>
                                    &nbsp;&nbsp;&nbsp;
                                </a>-->

            <!--                    <a href="<?php // echo base_url() . $course_value->url;                                                    ?>">
                                    <i class="fa  fa  fa-lightbulb-o fa-lg" title="View quiz"></i>
                                    &nbsp;&nbsp;&nbsp;
                                </a>-->
                    <a href="javascript:void(0)"  data-toggle="modal" data-target="#deleteFreeCourse<?php echo $course_value->url; ?>" >
                        <i class="fa  fa-remove" title="Cancel"></i>
                    </a>&nbsp;&nbsp;&nbsp;
                </div>

            </div>
            <div class="modal" style="" id="deleteFreeCourse<?php echo $course_value->url; ?>" tabindex="-1" role="dialog" aria-labelledby="changeRole" aria-hidden="true">
                <?php
                $status_message1 = 'Are you sure you want to Cancel this Course Registration?';
                $status_function_name1 = 'cancelCourseStatus(&quot;' . base_url('course/cancel-learner-registration') . '&quot;,&quot;' . $course_value->student_roll_number . '&quot;,&quot;free&quot;)';
                $this->cf->get_status_modal($status_function_name1, $status_message1);
                ?>
            </div>
            <div class="col-sm-12"><br></div>
            <?php
        }
        echo $free_course_paginzation_link;
    } else {
        echo 'You do not get enrollment in any course!';
    }
}

if($course_type == 'paid'){
    if ($total_paid_courses > 0) {
        $j = 0;
        foreach ($paid_courses as $course_value) {
            foreach($random_number as $random_num){
                $j++;
                if($course_value->course_id == $random_num['course_id']){ 
                    if($random_num['payment_status'] == 2 || $random_num['payment_status'] == 6){
                        ?>
                <div class="col-sm-12 white text-center">
                    <div class="col-sm-2" style="padding-top: 10px "><img src="<?php echo base_url() ?>image/no_image_course.png" style="width: 50px"></div>
                    <div class="col-sm-4" style="padding-top: 10px ">
                        <a href="<?php echo base_url() . $course_value->url; ?>" target="_blank" >
                            <span id="courseNameView<?php echo $course_value->url ?>">
                                <?php
                                if (strlen($course_value->course_name) > 50) {
                                    echo mb_substr($course_value->course_name, 0, 50, 'utf-8');
                                } else {
                                    echo $course_value->course_name;
                                }
                                ?>
                            </span>
                        </a>
                        <?php
                        if (strlen($course_value->course_name) > 50) {
                            echo '<span id="moreCourseNameView' . $course_value->url . '" style="cursor:pointer;padding-right: 10px;">>>></span>';
                        }
                        ?>
                        <input type="hidden" id="hiddenCourseName<?php echo $course_value->url ?>" value="<?php echo $course_value->course_name ?>">
                    </div>
                    <div class="col-sm-2" style="padding-top: 10px">
                        <?php
                        if ($course_value->payment_currency == 1) {
                            
                            //echo 'BDT ' . $course_value->total_price . ' / USD ' . $this->tt_currency->set($course_value->total_price, 'BDT', 'USD')->convert_currency()->get();
                            echo 'BDT ' . $course_value->total_price;
                        } else if ($course_value->payment_currency == 2) {
                            
                            //echo 'BDT ' . $this->tt_currency->set($course_value->total_price, 'USD', 'BDT')->convert_currency()->get() . ' / USD ' . $course_value->total_price;
                            echo ' USD ' . $course_value->total_price;
                        }
                        ?>
                    </div>
                    <div class="col-sm-2 form-group" style="padding-top: 10px">
                                        <strong>
                                            <?php
                                            switch ($random_num['payment_status']) {
                                                case 1:
                                                    echo 'Paid';
                                                    break;
                                                case 2:
                                                    echo 'Partial Paid';
                                                    break;
                                                case 3:
                                                    echo 'Unpaid';
                                                    break;
                                                case 4:
                                                    echo 'Drop';
                                                    break;
                                                case 5:
                                                    echo 'Cancel';
                                                    break;
                                                case 6:
                                                    echo 'Pending';
                                                    break;
                                                case 7:
                                                    echo 'Refund Request';
                                                    break;
                                                case 8:
                                                    echo 'Refunded';
                                                    break;
                                                default :
                                                    echo 'None';
                                                    break;
                                            }
                                            ?>
                                        </strong>
                                    </div>
                                    <div class="col-sm-2 padding-zero text-center">
                                        <a href="<?php echo base_url('user/partial-invoice/'.$course_value->url); ?>" target="_blank" title="Details"><i class="fa fa-dollar"></i></a>&nbsp;
                                    </div>
                                    <input type="hidden" id="hiddenPaymentStatus<?php echo $random_num['random_number']; ?>" value="<?php echo $random_num['payment_status'] ?>">

                </div>
                <div class="col-sm-12"><br></div> 
                <?php
                    break;
                    }
                    if($random_num['payment_status'] == 1){
                    ?>
                <div class="col-sm-12 white text-center">
                    <div class="col-sm-2" style="padding-top: 10px "><img src="<?php echo base_url() ?>image/no_image_course.png" style="width: 50px"></div>
                    <div class="col-sm-4" style="padding-top: 10px ">
                        <a href="<?php echo base_url() . $course_value->url; ?>" target="_blank" >
                            <span id="courseNameView<?php echo $course_value->url ?>">
                                <?php
                                if (strlen($course_value->course_name) > 50) {
                                    echo mb_substr($course_value->course_name, 0, 50, 'utf-8');
                                } else {
                                    echo $course_value->course_name;
                                }
                                ?>
                            </span>
                        </a>
                        <?php
                        if (strlen($course_value->course_name) > 50) {
                            echo '<span id="moreCourseNameView' . $course_value->url . '" style="cursor:pointer;padding-right: 10px;">>>></span>';
                        }
                        ?>
                        <input type="hidden" id="hiddenCourseName<?php echo $course_value->url ?>" value="<?php echo $course_value->course_name ?>">
                    </div>
                    <div class="col-sm-2" style="padding-top: 10px">
                        <?php
                        if ($course_value->payment_currency == 1) {
                            
                            //echo 'BDT ' . $course_value->total_price . ' / USD ' . $this->tt_currency->set($course_value->total_price, 'BDT', 'USD')->convert_currency()->get();
                            echo 'BDT ' . $course_value->total_price;
                        } else if ($course_value->payment_currency == 2) {
                            
                            //echo 'BDT ' . $this->tt_currency->set($course_value->total_price, 'USD', 'BDT')->convert_currency()->get() . ' / USD ' . $course_value->total_price;
                            echo ' USD ' . $course_value->total_price;
                        }
                        ?>
                    </div>
                    <div class="col-sm-2 form-group" style="padding-top: 10px">
                                        <strong>
                                            <?php
                                            switch ($random_num['payment_status']) {
                                                case 1:
                                                    echo 'Paid';
                                                    break;
                                                case 2:
                                                    echo 'Partial Paid';
                                                    break;
                                                case 3:
                                                    echo 'Unpaid';
                                                    break;
                                                case 4:
                                                    echo 'Drop';
                                                    break;
                                                case 5:
                                                    echo 'Cancel';
                                                    break;
                                                case 6:
                                                    echo 'Pending';
                                                    break;
                                                case 7:
                                                    echo 'Refund Request';
                                                    break;
                                                case 8:
                                                    echo 'Refunded';
                                                    break;
                                                default :
                                                    echo 'None';
                                                    break;
                                            }
                                            ?>
                                        </strong>
                                    </div>
                                    <div class="col-sm-2 padding-zero text-center">
                                        <a href="<?php echo base_url('user/view-invoice/' . $random_num['random_number']); ?>" target="_blank" title="Details"><i class="fa fa-dollar"></i></a>&nbsp;

                                        <?php
                                        //if (in_array($random_num['payment_status'], [1, 2])) {
                                            ?>
                                        <!--    <a href="javascript:void(0)" id="refundRequestInvoice<?php echo $random_num['random_number']; ?>"><i class="fa fa-arrow-right" title="Refund Request" aria-hidden="true"></i></a>
                                        <?php //} ?>
                                        <!--
                                        <a href="javascript:void(0)" id="cancelInvoice<?php echo $random_num['random_number']; ?>"><i class="glyphicon glyphicon-remove"></i></a>
                                        -->
                                    </div>
                                    <!--
                                    <div class="modal fade" style="" id="viewRefundRequestInvoiceModal" tabindex="-1" role="dialog" aria-labelledby="changeRole" aria-hidden="true">
                                        <?php
//                                        $message3 = '<span style="text-align:center">Are you sure you want to refund this Invoice?</span>';
//                                        $this->cf->view_modal('refundImvoice', $message3);
                                        ?>
                                    </div>

                                    <div class="modal fade" style="" id="viewCancelInvoiceModal<?php echo $random_num['random_number']; ?>" tabindex="-1" role="dialog" aria-labelledby="changeRole" aria-hidden="true">
                                        <?php
//                                        $message1 = '<span style="text-align:center">Are you sure you want to delete Invoice?</span>';
//                                        $this->cf->view_modal($random_num['random_number'], $message1);
                                        ?>
                                    </div>
                                    <div class="modal fade" style="" id="viewDoNotCancelInvoiceModal<?php echo $random_num['random_number']; ?>" tabindex="-1" role="dialog" aria-labelledby="changeRole" aria-hidden="true">
                                        <?php
//                                        $message2 = '<span style="text-align:center">You do not this delete Invoice?</span>';
//                                        $this->cf->view_single_modal($random_num['random_number'], $message2);
                                        ?>
                                    </div>
                                    -->
                                    <input type="hidden" id="hiddenPaymentStatus<?php echo $random_num['random_number']; ?>" value="<?php echo $random_num['payment_status'] ?>">

                </div>
                <div class="col-sm-12"><br></div>
                    
                <?php
                    break;
                    }
                }
            }
        }
        echo $paid_course_paginzation_link;
    } else { ?>
        <p>You do not paid for any course! <a href="<?php echo base_url().'course'?>" target="_blank">Course Registration</a></p>
    <?php    
    }
    
}

if ($course_type == 'registration') {
    if ($total_register_courses > 0) {
        $j = 0;
        foreach ($register_courses as $course_value) {
            foreach($random_number as $random_num){
                $j++;
                if($course_value->course_id == $random_num['course_id'] && $random_num['payment_status'] == 3){
            ?>
            <div class="col-sm-12 <?php echo ($j % 2) ? 'white' : 'gray'; ?> text-center">
                <div class="col-sm-6" style="padding-top: 10px ">
                    <a href="<?php echo base_url() . $course_value->url; ?>" target="_blank" >
                        <span id="courseNameView<?php echo $course_value->url ?>">
                            <?php
                            if (strlen($course_value->course_name) > 50) {
                                echo mb_substr($course_value->course_name, 0, 50, 'utf-8');
                            } else {
                                echo $course_value->course_name;
                            }
                            ?>
                        </span>
                    </a>
                    <?php
                    if (strlen($course_value->course_name) > 50) {
                        echo '<span id="moreCourseNameView' . $course_value->url . '" style="cursor:pointer;padding-right: 10px;">>>></span>';
                    }
                    ?>
                    <input type="hidden" id="hiddenCourseName<?php echo $course_value->url ?>" value="<?php echo $course_value->course_name ?>">
                </div>

                <div class="col-sm-3" style="padding-top: 10px">
                    <?php
                    if ($price_info[$course_value->student_id]->price_currency == 1) {
                        
                        //echo 'BDT ' . $price_info[$course_value->student_id]->price . ' / USD ' . $this->tt_currency->set($price_info[$course_value->student_id]->price, 'BDT', 'USD')->convert_currency()->get();
                        echo 'BDT ' . $price_info[$course_value->student_id]->price;
                    } else if ($price_info[$course_value->student_id]->price_currency == 2) {
                        
                        //echo 'BDT ' . $this->tt_currency->set($price_info[$course_value->student_id]->price, 'USD', 'BDT')->convert_currency()->get() . ' / USD ' . $price_info[$course_value->student_id]->price;
                        echo ' USD ' . $price_info[$course_value->student_id]->price;
                    }
                    ?>
                </div>
                <div class="col-sm-1" style="padding-top: 10px">Unpaid</div>
                <div class="col-sm-2 text-center" style="padding-top: 10px">
                    <a href="<?php
                    //foreach ($random_number as $random_num){  
                    if ($course_value->course_id == $random_num['course_id']) {
                        echo base_url('user/view-invoice/' . $random_num['random_number']);
                        // } 
                    }
                    ?>" target="_blank">
                        <i class="fa  fa  fa-money" title="View Invoice"></i>
                        &nbsp;&nbsp;
                    </a>
                    <a href="javascript:void(0)"  data-toggle="modal" data-target="#deleteFreeCourse<?php echo $course_value->url; ?>" >
                        <i class="fa  fa-remove" title="Cancel"></i>
                    </a>&nbsp;&nbsp;&nbsp;
                </div>
            </div>
            <div class="modal" style="" id="deleteFreeCourse<?php echo $course_value->url; ?>" tabindex="-1" role="dialog" aria-labelledby="changeRole" aria-hidden="true">
                <?php
                $status_message1 = 'Are you sure you want to Cancel this Course Registration?';
                $status_function_name1 = 'cancelCourseStatus(&quot;' . base_url('course/cancel-learner-registration') . '&quot;,&quot;' . $course_value->student_roll_number . '&quot;,&quot;registration&quot;)';
                $this->cf->get_status_modal($status_function_name1, $status_message1);
                ?>
            </div>
            <div class="col-sm-12"><br></div> 
            <?php
            break;
                }
            }
        }
        echo $register_course_paginzation_link;
    } else {?>
        <p>You do not get enrollment in any paid course! <a href="<?php echo base_url().'course'?>" target="_blank">Course Registration</a></p>
    <?php    
    }
}