load->model('Role_model'); } function list_role() { if($this->session->userdata('id')==""){redirect('admin/login');} $data['role']=$this->Role_model->list_roles(); $this->load->view('admin/role/list',$data); } function add_role() { if($this->session->userdata('id')==""){redirect('admin/login');} if($this->input->post('role')) { $name=$this->input->post('rolename'); $table="staff_roles"; //echo $ledgername; $values=array('name'=>$name, 'cdate'=>date('Y-m-d H:i:s'), 'cby'=>$this->session->userdata('id'), 'status'=>1); $result=$this->commonsql_model->insert_table($table,$values); if($result) { $this->session->set_userdata('suc','successfully added'); redirect('admin/role'); } else { $this->session->set_userdata('err','Please try again'); redirect('admin/role'); } } } function roleaction() { if($this->session->userdata('id')==""){redirect('admin/login');} $type=$_POST['type']; //types like view, edit etc., $id=$_POST['id']; //selecting table $tableName="staff_roles"; $select=array('id','name'); $where=array('id'=>$id); $data['role']=$this->commonsql_model->selectTable($tableName,$where,$select); $data['type']=$type; $this->load->view('admin/role/roleaction',$data); } function edit_role($id) { if($this->session->userdata('id')==""){redirect('admin/login');} if($this->input->post('roleupdate')) { $name=$this->input->post('rolename'); $table="staff_roles"; //echo $ledgername; $values=array('name'=>$name, 'udate'=>date('Y-m-d H:i:s'), 'status'=>1); $where=array("id"=>$id); $result=$this->commonsql_model->updatetable($table,$where,$values); if($result) { $this->session->set_userdata('suc','successfully updated'); redirect('admin/role'); } else { $this->session->set_userdata('err','Please try again'); redirect('admin/role'); } } } function delete_role($id) { if($this->session->userdata('id')==""){redirect('admin/login');} if($this->input->post('roleupdate')) { $table="staff_roles"; //echo $ledgername; $values=array( 'status'=>0); $where=array("id"=>$id); $result=$this->commonsql_model->updatetable($table,$where,$values); if($result) { $this->session->set_userdata('suc','successfully deleted'); redirect('admin/role'); } else { $this->session->set_userdata('err','Please try again'); redirect('admin/role'); } } } } ?>