<?php

class Programs extends Controller {

    private $_programModel;
    private $data;
    
    public function __construct() {
        $this->_programModel = $this->model('ProgramModel');
    }

    public function index() {
        $this->data['programs'] = $this->_programModel->getAllPrograms();
        $this->view('Manage/programs/index', $this->data);
    }   

    public function create() {
        $this->view('Manage/programs/new');
    }

    public function edit($id) {
        $this->data['programs'] = $this->_programModel->getProgramById($id);
        $this->view('Manage/programs/edit', $this->data);
    }

    public function update() {
        $POST = $_POST;
        $this->data['programs'] = $this->_programModel->getAllPrograms();
        $this->_programModel->updateProgram($POST['codigoactual'], $POST);
        redirect('/Programs/index');
    }

    public function persist() {
        $POST = $_POST;
        $this->_programModel->createProgram($POST);
        redirect('/Programs/index');
    }
}