<?php

class Suppliers extends CI_Controller {
    
    var $tablename = SUPPLIERS;
    var $primarykey = "SupplierID";
        
    public function index(){               
        $data['current'] = "suppliers";
        $data['suppliers'] = $this->general->getAllRecordsWhere($this->tablename,array(),"$this->primarykey","asc");
        $this->load->view(ADMINFOLDER."/supplierslist",$data);
    }
    
    public function edit($id){
        $this->load->library('form_validation');
         
        $this->form_validation->set_rules('txt_active', 'Is Active', 'trim');

        $data['message'] = "";
		
        if ($this->form_validation->run() == TRUE)
	{                        
            $updateData = array(
                "$this->primarykey" 	=> $id,
                "is_active"             => $this->input->post("txt_active"),                 
                "date_modified"         => date("Y-m-d H:i:s")
            );
                        
            $this->general->updateRecord($this->tablename, $updateData, "$this->primarykey");                                        
            $data['message'] = "Supplier updated successfully";
        }
            
        $data['record'] = $this->general->getRecordWhere($this->tablename,array("$this->primarykey"=>$id), "$this->primarykey","desc");    
        $this->load->view(ADMINFOLDER."/editsupplier",$data);
    }
        
        
    
}
