Welcome Guest, Not a member yet? Register   Sign In
about upgrading CI version
#3

[eluser]kikz4life[/eluser]
Controller

Code:
class Main extends Controller {

    function Main()
    {
        parent::Controller();
        $method = $this->uri->rsegment(2);
        $user = $this->session->userdata('user');
        if (!$user) redirect('sec_users/login');
        
        $this->load->model('Dataset_db');
    }
    
    function index()
    {
        $data['navs'] = $this->Dataset_db->buildNav(0);
        $data['current_tab'] = 'dashboard';
        
        $data['content'] = $this->load->view('home',$data,true);
        $this->load->vars($data);
        $this->load->view('default_view');
    }
    
    function close_tab($module,$nogo=false)
    {
        if (!$module) return true;

        $tabs = $this->session->userdata('tabs');
        if (!$tabs) $tabs = array();
        $last_tab = '';
                
        foreach ($tabs as $tab) {
            if ($tab['link']==$module)
                {
                unset($tabs[$module]);
                $this->session->set_userdata('tabs',$tabs);
                if ($nogo) return true;
                redirect($last_tab);
                }
            $last_tab = $tab['link'];
        }
    }
    
    function options()
    {
        $item = $this->input->post('item');        
        $data['prop']="class='tb'";
        $data['name']=$this->input->post('type');
        $data['value']=$this->input->post('value');
        $data['options'] = $this->Dataset_db->getProvince($item);
        $this->load->view("template/options",$data);
    }

    
}

Model

Code:
class Dataset_db extends Model {

    function Dataset_db()
    {
        parent::Model();
    }

    function getTypes($datacode)
    {
        $this->db->select('data_id,data_value,data_display,description');
         $this->db->where("data_code='$datacode' AND display='1'");
        $this->db->orderby("order_idx", "asc");
        $query = $this->db->get('sec_dataset');
        return $query->result();        
    }
    
    function getSearchTypes($datacode)
    {
        $this->db->select('data_id,data_value,data_display,description');
         $this->db->where("data_code='$datacode'");
        $this->db->orderby("order_idx", "asc");
        $query = $this->db->get('sec_dataset');
        return $query->result();        
    }
    
    function getNavs($parent)
    {
        $this->db->select('module_id,module,link,icon');
        $this->db->orderby("sort", "asc");
        $query = $this->db->get_where('sec_modules', array('publish' => '1','parent' => $parent));
        return $query->result_array();        
    }
    
    function buildNav($p)
    {
        $rs = $this->getNavs($p);
        $nav = array();
        foreach ($rs as $row)
            {
                $nav[] = array ('row'=>$row,'child'=>$this->buildNav($row['module_id']));            
            }                
        return $nav;
    }
    
    function getModule($module)
    {
        $this->db->select('module_id,module,link,icon');
        $query = $this->db->get_where('sec_modules', array('publish' => '1','link' => $module));
        return $query->row_array();        
    }
    
    function getAccess($role_id, $module_id, $company_id)
    {
        $query = $this->db->get_where('sec_accesslevel', array('role_id' => $role_id, 'module_id' => $module_id, 'company_id' => $company_id));
        return $query->row_array();    
    }
    
    function getCountries()
    {
        $this->db->select('iso,printable_name');
        $this->db->orderby("printable_name", "asc");
        $query = $this->db->get('maint_country');
        return $query->result();        
    }
    
    function getProvince($c)
    {
        $this->db->select('id,state');
        $this->db->orderby("state", "asc");
        $query = $this->db->get_where('maint_state', array('iso' => $c));
        return $query->result_array();        
    }
    
    function getData()
    {
        $this->db->select('data_id,data_code');
        $this->db->orderby("data_id", "asc");
        $this->db->groupby("data_code");
        $query = $this->db->get('sec_dataset');
        return $query->result();        
    }
    
    function saveLog($data)
    {
        $company = $this->session->userdata('company');
        $data['company_id'] = $company['company_id'];
        
        $user = $this->session->userdata('user');
        $data['user_id'] = $user['user_id'];
        
        $data['log_date'] = date("Y-m-d H:i:s");
        $data['machine_name'] = gethostbyaddr($_SERVER['REMOTE_ADDR']);
        $data['ip_address'] = $_SERVER['REMOTE_ADDR'];  
        
        $this->db->insert('sec_logs', $data);
    }

}

this is the entire codes which trigger all module links of my website.


Messages In This Thread
about upgrading CI version - by El Forum - 10-21-2009, 05:05 AM
about upgrading CI version - by El Forum - 10-21-2009, 05:27 AM
about upgrading CI version - by El Forum - 10-21-2009, 05:36 AM
about upgrading CI version - by El Forum - 10-21-2009, 06:00 AM
about upgrading CI version - by El Forum - 10-21-2009, 09:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB