<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Loan extends MY_Controller
{

    public $data = array();


    function __construct()
    {
        parent::__construct();
        $this->load->model('Loan_Model', 'loan', true);
    }


    public function index()
    {

        // Get all posts
        $data['posts'] = $this->loan->get_data();

        // Load the view to display all posts
        $this->load->layout->title('Manage Loan' . ' | ' . SMS);
        $this->load->layout->view('academic/loan/index', $data);
    }
    public function add()
    {
        // echo $data;
        // Load necessary libraries and helpers
        $this->load->helper('form');
        $this->load->library('form_validation');
        // $this->load->model('Pathfinder_model');

        // Form validation rules
        $this->form_validation->set_rules('school_name', 'School name', 'required');
        $this->form_validation->set_rules('student_id', 'Student ID', 'required');
        $this->form_validation->set_rules('date', 'Date', 'required');
        $this->form_validation->set_rules('student_name', 'Student Name', 'required');
        $this->form_validation->set_rules('parent_name', 'Parent Name', 'required');
        $this->form_validation->set_rules('email', 'email', 'required');
        $this->form_validation->set_rules('phone_no', 'Phone no');
        $this->form_validation->set_rules('loan_amount', 'loan amount', 'required');
        $this->form_validation->set_rules('installments', 'installments', 'required');
        $this->form_validation->set_rules('installment_amount', 'installment amount', 'required');

        if ($this->form_validation->run() === FALSE) {
            redirect('academic/loan/index');
            // $this->load->view('academic/pathfinder/index');
        } else {
            // Validation successful, process the form data
            $data = array(
                'school_name' => $this->input->post('school_name'),
                'student_id' => $this->input->post('student_id'),
                'date' => $this->input->post('date'),
                'parent_name' => $this->input->post('parent_name'),
                'student_name' => $this->input->post('student_name'),
                'email' => $this->input->post('email'),
                'phone_no' => $this->input->post('phone_no'),
                'loan_amount' => $this->input->post('loan_amount'),
                'installments' => $this->input->post('installments'),
                'installment_amount' => $this->input->post('installment_amount'),
                // Add more fields as needed
            );
            // print_r($data);
            // Call the model to insert data into the database
            // $this->Pathfinder_Model->insert_syllabus($data);
            $this->loan->insert('loan', $data);
            // $this->db->insert('pathfinder', $data);
            // Redirect to a success page or load another view
            redirect('academic/loan/index');
            // }
        }
    }
}
