CmsArtist.php 11.3 KB
Newer Older
Phạm Văn Đoan committed
1 2 3 4 5 6 7 8 9
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 25/12/2015
 * Time: 2:22 CH
 */
if (!defined('BASEPATH')) exit('No direct script access allowed');

Phạm Văn Đoan committed
10
class CmsArtist extends CI_Controller
Phạm Văn Đoan committed
11 12 13 14 15 16
{
    public function __construct()
    {
        parent::__construct();
        date_default_timezone_set("Asia/Ho_Chi_Minh");
        //
17 18
        $this->load->model('user_model');
        $this->load->model('actionlog_model');
Phạm Văn Đoan committed
19 20
    }

Phạm Văn Đoan committed
21
    public function listArtist()
Phạm Văn Đoan committed
22
    {
Phạm Văn Đoan committed
23 24 25 26
        $this->_data['functionName'] = 'Nghệ sĩ';
        $this->_data['action'] = 'listArtist';
        $this->_data['titlePage'] = 'Nghệ sĩ';
        $this->_data['loadPage'] = 'backend/cms_artist/list_artist_view';
Phạm Văn Đoan committed
27 28 29
        $this->load->view('backend/admin_template_view', $this->_data);
    }

Phạm Văn Đoan committed
30
    public function listArtistAjax()
Phạm Văn Đoan committed
31 32 33 34 35 36 37
    {
        $data = array();
        $fByName = $this->input->post('fByName');
        $pageId = $this->input->post('pageId');
        //
        $pageId = ($pageId == 0) ? 1 : $pageId;
        //
Phạm Văn Đoan committed
38
        $limit = 25;
Phạm Văn Đoan committed
39 40
        $offset = ($pageId - 1) * $limit;
        $data['offset'] = ($pageId - 1) * $limit;
41
        $totalRecord = $this->user_model->cmsCountAll($fByName);
Phạm Văn Đoan committed
42
        $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
43
        $data['listData'] = $this->user_model->cmsGetPagination($limit, $offset, $fByName);
Phạm Văn Đoan committed
44
        //
Phạm Văn Đoan committed
45
        $this->load->view('backend/ajax/cms_artist/list_artist_view', $data);
Phạm Văn Đoan committed
46 47
    }

48
    public function editArtist($user_id)
Phạm Văn Đoan committed
49
    {
50
        $this->_data['contest'] = $contest = $this->user_model->getById($user_id);
Phạm Văn Đoan committed
51 52 53 54 55 56 57 58 59 60
        // Kiểm tra trùng giá trị nếu thay đổi ở form

        // Thiết lập validate
        $this->form_validation->set_rules(
            'id',
            'ID',
            'trim'
        );

        $this->form_validation->set_rules(
61 62 63
            'username',
            'Tên tài khoản',
            'trim|required|callback_check_username|xss_clean'
Phạm Văn Đoan committed
64 65 66
        );

        $this->form_validation->set_rules(
67 68 69 70 71 72 73
            'email',
            'Email',
            'trim|required|callback_check_email|xss_clean'
        );
        $this->form_validation->set_rules(
            'full_name',
            'text',
Phạm Văn Đoan committed
74 75 76
            'trim|required|xss_clean'
        );

77 78
        $this->form_validation->set_message('required', '<li class="list-unstyled">Bắt buộc nhập, chọn.</li>');
        $this->form_validation->set_message('is_unique', '<li class="list-unstyled">Đã tồn tại.</li>');
Phạm Văn Đoan committed
79 80
        // Xử lý form đăng nhập
        if($this->form_validation->run($this) == false) {
81 82 83 84 85 86
            $this->_data['email'] = $this->input->post('email');
            $this->_data['username'] = $this->input->post('username');
            $this->_data['full_name'] = $this->input->post('full_name');
            $this->_data['link_zing'] = $this->input->post('link_zing');
            $this->_data['link_nct'] = $this->input->post('link_nct');
            $this->_data['link_keeng'] = $this->input->post('link_keeng');
Phạm Văn Đoan committed
87
            //
88
            $this->_data['functionName'] = 'Cập nhật thông tin Ca sĩ/Nghệ sĩ';
89
            $this->_data['action'] = 'editArtist';
90 91
            $this->_data['titlePage'] = 'Cập nhật thông tin Ca sĩ/Nghệ sĩ';
            $this->_data['loadPage'] = 'backend/cms_artist/edit_artist_view';
Phạm Văn Đoan committed
92 93
            $this->load->view('backend/admin_template_view', $this->_data);
        }else{
94 95 96 97 98 99 100
            $email = $this->input->post('email');
            $username = trim($this->input->post('username'));
            $full_name = $this->input->post('full_name');
            $link_zing = $this->input->post('link_zing');
            $link_nct = $this->input->post('link_nct');
            $link_keeng = $this->input->post('link_keeng');
            if($username && $email && $full_name){
Phạm Văn Đoan committed
101
                $dataUpdate = array(
102 103
                    'username' => $username,
                    'email' => $email,
104
                    'user_type' => 2,
105 106 107 108
                    'full_name' => $full_name,
                    'link' => $link_zing,
                    'link_nct' => $link_nct,
                    'link_keeng' => $link_keeng
Phạm Văn Đoan committed
109
                );
110
                $this->user_model->update($user_id, $dataUpdate);
Phạm Văn Đoan committed
111
                // Ghi log
112
                // $this->mactionlog->add('UPDATED', 'Cập nhật Cuộc đua thành công!', 'Mactionlog', 'action_log', $contest_id);
Phạm Văn Đoan committed
113 114 115 116 117
                //
                $this->session->set_flashdata('success', 'Cập nhật Cuộc đua thành công');
            }else{
                $this->session->set_flashdata('error', 'Cập nhật Cuộc đua không thành công');
            }
118 119 120 121
            redirect(base_url().'backend/cmsArtist/listArtist');
        }
    }

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    public function addArtistAjax()
    {
        $email = $this->input->post('email');
        $username = $this->input->post('username');
        $full_name = $this->input->post('full_name');
        $link_zing = $this->input->post('link_zing');
        $link_nct = $this->input->post('link_nct');
        $link_keeng = $this->input->post('link_keeng');
        $password = MyHelper::genKeyCode(trim('123456'));
        $result = $this->user_model->getByEmail($email, 2, '');
        // MyHelper::echoPreDie($result);
        $check_username = $this->user_model->getByUsername($username, 2, '');
        if($email == '' || $username == '' || $full_name == '') {
            $data['required'] = 'Vui lòng điền Vào chỗ trống!';
        } else if($result) {
            $data['check_email'] = 'Email đã được sử dụng!';
        } else if($check_username) {
            $data['check_username'] = 'Username đã tồn tại!';
        } else {
            $dataUpdate = array(
                'username' => $username,
                'password' => $password,
                'email' => $email,
                'user_type' => 2,
                'full_name' => $full_name,
                'link' => ($link_zing == '') ? null: $link_zing,
                'link_nct' => ($link_nct == '') ? null: $link_nct,
                'link_keeng' => ($link_keeng == '') ? null: $link_keeng,
                'date_created' => time()
            );
            $insert_id = $this->user_model->add($dataUpdate);
            if($insert_id) {
                $this->session->set_flashdata('success', 'Tạo nghệ sĩ thành công!');
                $data['success'] = 'Thành công!';
            } else{
                $this->session->set_flashdata('error', 'Tạo nghệ sĩ không thành công!');
                $data['error'] = 'Xảy ra lỗi! Vui lòng thử lại.';
            }
        }
        echo json_encode($data);
    }

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
    public function addArtist()
    {
        // Thiết lập validate
        $this->form_validation->set_rules(
            'id',
            'ID',
            'trim'
        );

        $this->form_validation->set_rules(
            'username',
            'Tên tài khoản',
            'trim|required|callback_check_username|xss_clean'
        );

        $this->form_validation->set_rules(
            'email',
            'Email',
            'trim|required|callback_check_email|xss_clean'
        );
        $this->form_validation->set_rules(
            'full_name',
            'text',
            'trim|required|xss_clean'
        );

        $this->form_validation->set_message('required', '<li class="list-unstyled">Bắt buộc nhập, chọn.</li>');
        $this->form_validation->set_message('is_unique', '<li class="list-unstyled">Đã tồn tại.</li>');
        // Xử lý form đăng nhập
        if($this->form_validation->run($this) == false) {
            $this->_data['email'] = $this->input->post('email');
            $this->_data['username'] = $this->input->post('username');
            $this->_data['full_name'] = $this->input->post('full_name');
            $this->_data['link_zing'] = $this->input->post('link_zing');
            $this->_data['link_nct'] = $this->input->post('link_nct');
            $this->_data['link_keeng'] = $this->input->post('link_keeng');
            //
            $this->_data['functionName'] = 'Tạo mới Ca sĩ/Nghệ sĩ';
            $this->_data['action'] = 'addArtist';
            $this->_data['titlePage'] = 'Tạo mới Ca sĩ/Nghệ sĩ';
            $this->_data['loadPage'] = 'backend/cms_artist/add_artist_view';
            $this->load->view('backend/admin_template_view', $this->_data);
        }else{
            $username = trim($this->input->post('username'));
            $password = MyHelper::genKeyCode(trim('123456'));
            $email = $this->input->post('email');
            // $username = $this->input->post('username');
            $full_name = $this->input->post('full_name');
            $link_zing = $this->input->post('link_zing');
            $link_nct = $this->input->post('link_nct');
            $link_keeng = $this->input->post('link_keeng');
            if($username && $email && $full_name){
                $dataUpdate = array(
                    'username' => $username,
                    'password' => $password,
                    'email' => $email,
220
                    'user_type' => 2,
221
                    'full_name' => $full_name,
222 223 224
                    'link' => ($link_zing == '') ? null: $link_zing,
                    'link_nct' => ($link_nct == '') ? null: $link_nct,
                    'link_keeng' => ($link_keeng == '') ? null: $link_keeng,
225
                    'date_created' => time()
226 227 228 229 230 231 232 233 234 235
                );
                $this->user_model->add($dataUpdate);
                // Ghi log
                // $this->mactionlog->add('UPDATED', 'Cập nhật Cuộc đua thành công!', 'Mactionlog', 'action_log', $contest_id);
                //
                $this->session->set_flashdata('success', 'Cập nhật Cuộc đua thành công');
            }else{
                $this->session->set_flashdata('error', 'Cập nhật Cuộc đua không thành công');
            }
            redirect(base_url().'backend/cmsArtist/listArtist');
Phạm Văn Đoan committed
236 237 238 239 240
        }
    }

    public function showUser($user_id)
    {
241
        $this->_data['user'] = $this->user_model->getById($user_id);
Phạm Văn Đoan committed
242 243 244 245
        //
        $this->_data['functionName'] = 'Thông tin Người chơi';
        $this->_data['action'] = 'showUser';
        $this->_data['titlePage'] = 'Thông tin Người chơi';
246
        $this->_data['loadPage'] = 'backend/cms_artist/show_artist_view';
Phạm Văn Đoan committed
247 248 249
        $this->load->view('backend/admin_template_view', $this->_data);
    }

250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
    public function check_username($username)
    {
        if ($this->input->post('id')) {
            $id = $this->input->post('id');
        }
        else {
            $id = '';
        }
        $result = $this->user_model->getByUsername($username, $id, 2);
        if($result) {
            //die('2335');
            $this->form_validation->set_message('check_username', '<li class="list-unstyled">Đã tồn tại.</li>');
           return false;
        }else{
            return TRUE;
        }
    }
    public function check_email($email)
    {
        // die($email);
        if ($this->input->post('id')) {
            $id = $this->input->post('id');
        }
        else {
            $id = '';
        }
        $result = $this->user_model->getByEmail($email, $id, 2);
        if($result) {
            // die('2335');
            $this->form_validation->set_message('check_email', '<li class="list-unstyled">Email đã tồn tại.</li>');
           return false;
        }else{
            return TRUE;
        }
    }

Phạm Văn Đoan committed
286
}