CmsArtist.php 9.28 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 25/12/2015
 * Time: 2:22 CH
 */
if (!defined('BASEPATH')) exit('No direct script access allowed');

class CmsArtist extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        date_default_timezone_set("Asia/Ho_Chi_Minh");
        //
        $this->load->model('user_model');
        $this->load->model('actionlog_model');
    }

    public function listArtist()
    {
        $this->_data['functionName'] = 'Nghệ sĩ';
        $this->_data['action'] = 'listArtist';
        $this->_data['titlePage'] = 'Nghệ sĩ';
        $this->_data['loadPage'] = 'backend/cms_artist/list_artist_view';
        $this->load->view('backend/admin_template_view', $this->_data);
    }

    public function listArtistAjax()
    {
        $data = array();
        $fByName = $this->input->post('fByName');
        $pageId = $this->input->post('pageId');
        //
        $pageId = ($pageId == 0) ? 1 : $pageId;
        //
        $limit = 25;
        $offset = ($pageId - 1) * $limit;
        $data['offset'] = ($pageId - 1) * $limit;
        $totalRecord = $this->user_model->cmsCountAll($fByName);
        $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
        $data['listData'] = $this->user_model->cmsGetPagination($limit, $offset, $fByName);
        //
        $this->load->view('backend/ajax/cms_artist/list_artist_view', $data);
    }

    public function editArtist($user_id)
    {
        $this->_data['contest'] = $contest = $this->user_model->getById($user_id);
        // 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(
            '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'] = 'Cập nhật thông tin Ca sĩ/Nghệ sĩ';
            $this->_data['action'] = 'editArtist';
            $this->_data['titlePage'] = 'Cập nhật thông tin Ca sĩ/Nghệ sĩ';
            $this->_data['loadPage'] = 'backend/cms_artist/edit_artist_view';
            $this->load->view('backend/admin_template_view', $this->_data);
        }else{
            $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){
                $dataUpdate = array(
                    'username' => $username,
                    'email' => $email,
                    'full_name' => $full_name,
                    'link' => $link_zing,
                    'link_nct' => $link_nct,
                    'link_keeng' => $link_keeng
                );
                $this->user_model->update($user_id, $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');
        }
    }

    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,
                    'full_name' => $full_name,
                    'link' => $link_zing,
                    'link_nct' => $link_nct,
                    'link_keeng' => $link_keeng,
                    'date_created' => time()
                );
                $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');
        }
    }

    public function showUser($user_id)
    {
        $this->_data['user'] = $this->user_model->getById($user_id);
        //
        $this->_data['functionName'] = 'Thông tin Người chơi';
        $this->_data['action'] = 'showUser';
        $this->_data['titlePage'] = 'Thông tin Người chơi';
        $this->_data['loadPage'] = 'backend/cms_artist/show_artist_view';
        $this->load->view('backend/admin_template_view', $this->_data);
    }

    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;
        }
    }

}