1 | <?php
|
---|
2 |
|
---|
3 | if (!defined('BASEPATH'))
|
---|
4 | exit('No direct script access allowed');
|
---|
5 |
|
---|
6 | class Collaborator extends MX_Controller {
|
---|
7 |
|
---|
8 | const TOKENPW = 'violet';
|
---|
9 |
|
---|
10 | public function __construct() {
|
---|
11 | parent::__construct();
|
---|
12 | $this->load->helper('cookie');
|
---|
13 | $this->load->helper('language');
|
---|
14 | $this->lang->load('messages', 'message');
|
---|
15 | }
|
---|
16 |
|
---|
17 | public function profile(){
|
---|
18 | $collaborator_info = $this->session->userdata('collaboratorInfo');
|
---|
19 | if ($collaborator_info) {
|
---|
20 | $data['collaborator_id'] = $collaborator_info['id'];
|
---|
21 | $data['username'] = $collaborator_info['login_name'];
|
---|
22 | $data['fullname'] = $collaborator_info['fullname'];
|
---|
23 | $this->load->view('collaborator/collaborator_profile', $data);
|
---|
24 | }else{
|
---|
25 | $this->load->view('login');
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public function updateCollaborator(){
|
---|
30 | $this->load->model('collaborator_model');
|
---|
31 | $collaborator_info = $this->session->userdata('collaboratorInfo');
|
---|
32 | $result['success'] = 0;
|
---|
33 | if ($collaborator_info) {
|
---|
34 |
|
---|
35 | $collaborator_id = $collaborator_info['id'];
|
---|
36 | $login_name = $collaborator_info['login_name'];
|
---|
37 | $input = $this->input->post();
|
---|
38 | if (strlen($input['fullname']) == 0) {
|
---|
39 | $result['errors'][] = array("content"=>lang('_SBG_FULLNAME_REQUIRED_MSG'),"field"=>"fullname_err");
|
---|
40 | }
|
---|
41 | if (!isset($result['errors'])) {
|
---|
42 | $collaborator = array('full_name' => $input['fullname']);
|
---|
43 | $result['success'] = 1;
|
---|
44 | $result['data'] = $this->collaborator_model->updateCollaborator($collaborator_id, $collaborator);
|
---|
45 | $collaboratorData = array('login_name' => $login_name, 'id' => $collaborator_id, 'fullname' => $input['fullname'], 'logined_in' => TRUE);
|
---|
46 | $this->session->set_userdata('collaboratorInfo', $collaboratorData);
|
---|
47 | }
|
---|
48 | echo json_encode($result);
|
---|
49 | }else{
|
---|
50 | $this->load->view('login');
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public function change_password(){
|
---|
55 | $this->load->model('collaborator_model');
|
---|
56 | $collaborator_info = $this->session->userdata('collaboratorInfo');
|
---|
57 | if ($collaborator_info) {
|
---|
58 | $collaborator_id = (int)$collaborator_info['id'];
|
---|
59 | $input = $this->input->post();
|
---|
60 | if (strlen($input['passwd']) == 0) {
|
---|
61 | $result['errors']['passwd_old_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
62 | }
|
---|
63 |
|
---|
64 | if (strlen($input['passwd_new']) == 0) {
|
---|
65 | $result['errors']['passwd_new_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
66 | } else if (strcmp($input['passwd'], $input['passwd_new']) == 0) {
|
---|
67 | $result['errors']['passwd_new_err'] = lang('_SBG_PASSWORD_DUPLICATE_MSG');
|
---|
68 | }else
|
---|
69 | {
|
---|
70 | if (!preg_match('/^([0-9a-zA-Z]{6,65})*$/', $input['passwd_new']))
|
---|
71 | {
|
---|
72 | $result['errors']['passwd_new_err'] = lang('_SBG_USER_PASSWORD_CHANGE_REQUIRED_MSG');
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | if ($input['passwd_new'] != $input['confirm_passwd_new']) {
|
---|
77 | $result['errors']['confirm_passwd_new_err'] = lang('_SBG_PASSWORD_CONFIRM_MSG');
|
---|
78 | }
|
---|
79 | $passwd = $input['passwd'];
|
---|
80 | $checkPass = $this->collaborator_model->checkPassCollaborator($collaborator_id, $passwd);
|
---|
81 | if ($checkPass == false){
|
---|
82 | $result['errors']['passwd_old_err'] = lang('_SBG_OLD_PASSWORD_FAIL_MSG');
|
---|
83 | }
|
---|
84 |
|
---|
85 | if (!isset($result['errors'])) {
|
---|
86 | $collaborator = array('passwd'=>md5($input['passwd_new']));
|
---|
87 | $check = $this->collaborator_model->updateCollaborator($collaborator_id, $collaborator);
|
---|
88 | if ($check){
|
---|
89 | $result['success'] = 1;
|
---|
90 | }else{
|
---|
91 | $result['success'] = 0;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | echo json_encode($result);
|
---|
95 |
|
---|
96 | }else{
|
---|
97 | $this->load->view('login');
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|