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

class Pathfinder extends MY_Controller
{

    public $data = array();


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


    public function index()
    {
     
        // Get all posts
        $data['posts'] = $this->pathfinder->get_data();

        // Load the view to display all posts
        // $this->load->view('post/index', $data);
        $this->load->layout->title('Manage Pathfinder' . ' | ' . SMS);
        $this->load->layout->view('academic/pathfinder/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('date', 'Date', 'required');
        $this->form_validation->set_rules('pathfinder_id', 'Pathfinder ID', 'required');
        $this->form_validation->set_rules('amount', 'Commision amount', 'required');

        if ($this->form_validation->run() === FALSE) {
            redirect('academic/pathfinder/index');
            // $this->load->view('academic/pathfinder/index');
        } else {
            // Validation successful, process the form data
            $data = array(
                'school_name' => $this->input->post('school_name'),
                'date' => $this->input->post('date'),
                'pathfinder_id' => $this->input->post('pathfinder_id'),
                'commision_amount' => $this->input->post('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->pathfinder->insert('pathfinder', $data);
            // $this->db->insert('pathfinder', $data);
            // Redirect to a success page or load another view
            redirect('academic/pathfinder/index');
            // }
        }
    }
}
