Skip to content

Instantly share code, notes, and snippets.

@jblac
Created January 8, 2013 01:55
Show Gist options
  • Save jblac/4480404 to your computer and use it in GitHub Desktop.
Save jblac/4480404 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by JetBrains PhpStorm.
* User: bonk
* Date: 1/6/13
* Time: 1:55 PM
* To change this template use File | Settings | File Templates.
*/
class users extends BM_Controller {
public function __construct() {
parent::__construct();
$this->load->model('bm_users');
}
public function login() {
$data = '';
if ($this->input->post('username')) {
$user = $this->bm_users->login($this->input->post());
if ($user != false) {
$data['resp'] = '1';
$data['redirect'] = base_url();
} else {
$data['resp'] = '0';
$data['err'] = 'The username/password combination did not match. Please try again.';
}
echo json_encode($data);
} else {
$this->load->view('login');
}
}
public function logout() {
$this->session->unset_userdata('user');
redirect('/login');
}
public function index() {
$data['viewPage'] = "/users/userlist";
$data['breadcrumbs'][] = "Users List";
$data['pageTitle'] = "User List";
$data['pageDesc'] = "Add, View, Edit Users";
$data['users'] = $this->bm_users->getAll();
$this->load->view('wrapper', $data);
}
public function userToggle($id, $val) {
$this->bm_common->toggleStatus($id, $val, 'Users', 'userStatus');
$data['resp'] = "reload";
echo json_encode($data);
}
public function addUser() {
if ($this->input->post('firstName')) {
$data1 = $this->input->post();
$data1 = array_filter($data1, 'strlen');
$data1['userPassword'] = sha1($data1['userPassword']);
$this->bm_common->addIt($data1, 'Users');
$data['resp'] = 'reload';
echo json_encode($data);
} else {
$data['formType'] = 'add';
$this->load->view('/users/userlist_add', $data);
}
}
public function editUser($id) {
if ($this->input->post('firstName')) {
$data1 = $this->input->post();
if ($data1['userPassword'] != '') {
$data1['userPassword'] = sha1($data1['userPassword']);
}
$this->bm_common->updateIt($id, $data1, 'Users', 'id');
$data['resp'] = 'reload';
echo json_encode($data);
} else {
$data['formType'] = 'edit';
$data['user'] = $this->bm_common->selectIt($id, 'Users', 'id');
$this->load->view('/users/userlist_add', $data);
}
}
public function departments() {
if ($this->input->post('departmentTitle')) {
$data1 = array_filter($this->input->post(), 'strlen');
$this->bm_common->addIt($data1, 'userDepartments');
$data['resp'] = 'reload';
echo json_encode($data);
} else {
$data['viewPage'] = "/users/departments";
$data['breadcrumbs'][] = "Users";
$data['breadcrumbs'][] = "Departments";
$data['pageTitle'] = "User Departments";
$data['pageDesc'] = "Add, View, Edit User Departments";
$data['departments'] = $this->bm_common->getAll('userDepartments');
$this->load->view('wrapper', $data);
}
}
public function editDepartment($id) {
if ($this->input->post('departmentTitle')) {
$this->bm_common->updateIt($id, $this->input->post(), 'userDepartments', 'id');
$data['resp'] = 'reload';
echo json_encode($data);
} else {
$data['department'] = $this->bm_common->selectIt($id, 'userDepartments', 'id');
$this->load->view('/users/departments_edit', $data);
}
}
public function userTypes() {
if ($this->input->post('typeTitle')) {
$this->bm_common->addIt($this->input->post(), 'userTypes');
$data['resp'] = "reload";
echo json_encode($data);
} else {
$data['viewPage'] = "/users/usertypes";
$data['breadcrumbs'][] = "Users";
$data['breadcrumbs'][] = "User Types";
$data['pageTitle'] = "User Types";
$data['pageDesc'] = "Add, View, Edit User Classification Types";
$data['types'] = $this->bm_common->getAll('userTypes');
$this->load->view('wrapper', $data);
}
}
public function editUserType($id) {
if ($this->input->post('typeTitle')) {
$this->bm_common->updateIt($id, $this->input->post(), 'userTypes', 'id');
$data['resp'] = 'reload';
echo json_encode($data);
} else {
$data['type'] = $this->bm_common->selectIt($id, 'userTypes', 'id');
$this->load->view('/users/usertypes_edit', $data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment