[eluser]Bob Puzld[/eluser]
First controller file... collections.php
<?php
class Collections extends Controller {
function Collections() {
parent::Controller();
$this->load->model('collection_model','mdlCollection');
$this->load->library('auth',array('redirect'=>'main','hash_key'=>$this->config->item('hash_key')));
}
function index() {
$data = array('page_title'=>'Manage Collections',
'left_col'=>$this->load->view('nav',0,true),
'right_col'=>$this->load->view('collections/add',0,true));
$this->load->view('index', $data);
}
function UserCheck($anID) {
$this->db->where('id',$anID);
$query = $this->db->get('users');
if($query->num_rows() == 0) {
$this->validation->set_message('UserCheck','That account number doesnt exist. Please try a different one.');
return FALSE;
}
else
return TRUE;
}
function NumCansCheck($aNum) {
if($aNum >= 1000) {
$this->validation->set_message('NumCansCheck','Number of cans must be less than 1000.');
return FALSE;
}
else
return true;
}
function add_collection() {
// validate input
$rules = array('user_id'=>'required|numeric|callback_UserCheck',
'num_cans'=>'required|numeric|callback_NumCansCheck',
'date'=>'required');
$fields = array('user_id'=>'account number',
'num_cans'=>'number of cans collected');
$this->validation->set_rules($rules);
$this->validation->set_fields($fields);
// check for errors
if($this->validation->run() == FALSE) { // if there were errors...
$this->index();
}
else {
$this->mdlCollection->AddCollection();
redirect('collections/index');
}
}
}
?>