CmsTrack.php 4.7 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 CmsTrack extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        date_default_timezone_set("Asia/Ho_Chi_Minh");
        //
        $this->load->model('mtrack');
        $this->load->model('muser');
        $this->load->model('mactionlog');
    }

    public function listTrack()
    {
        $this->_data['functionName'] = 'Track';
        $this->_data['action'] = 'listTrack';
        $this->_data['titlePage'] = 'Track';
        $this->_data['loadPage'] = 'backend/cms_track/list_track_view';
        $this->load->view('backend/admin_template_view', $this->_data);
    }

    public function listTrackAjax()
    {
        $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->mtrack->cmsCountAll($fByName);
        $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
        $data['listData'] = $this->mtrack->cmsGetPagination($limit, $offset, $fByName);
        //
        $this->load->view('backend/ajax/cms_track/list_track_view', $data);
    }

    public function editContest($contest_id)
    {
        $this->_data['contest'] = $contest = $this->mtrack->getById($contest_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(
            'date_limit',
            'Số ngày diễn ra cuộc thi',
            'trim|required|xss_clean'
        );

        $this->form_validation->set_rules(
            'date_from',
            'Ngày bắt đầu diễn ra cuộc thi',
            'trim|required|xss_clean'
        );

        $this->form_validation->set_message('required', '<li>Bắt buộc nhập, chọn.</li>');
        $this->form_validation->set_message('is_unique', '<li>Đã tồn tại.</li>');
        // Xử lý form đăng nhập
        if($this->form_validation->run($this) == false) {
            $this->_data['date_limit'] = $this->input->post('name');
            $this->_data['date_from'] = $this->input->post('description');
            //
            $this->_data['functionName'] = 'QL Cuộc đua';
            $this->_data['action'] = 'editContest';
            $this->_data['titlePage'] = 'QL Cuộc đua';
            $this->_data['loadPage'] = 'backend/cms_track/edit_track_view';
            $this->load->view('backend/admin_template_view', $this->_data);
        }else{
            $date_limit = intval(trim($this->input->post('date_limit')));
            $date_from = trim($this->input->post('date_from'));
            if(($date_limit >= 7) && ($date_limit <= 50) && (strtotime($date_from) >= strtotime(date('Y-m-d', time())))){
                $dataUpdate = array(
                    'date_limit' => $date_limit,
                    'date_from' => $date_from,
                    'updated_at'=> date("Y-m-d H:i:s")
                );
                $this->mtrack->update($contest_id, $dataUpdate);
                // Cap nhat mang thoi gian ngay tham gia tu so ngay
                for($i=1; $i <= $date_limit; $i++){
                    $data_update_contest_details = array(
                        'date_play' => date('Y-m-d', strtotime($date_from) + ($i-1)*86400)
                    );
                    $this->mcontest_details->update($i, $data_update_contest_details);
                }
                // 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/cmsContest/listContest');
        }
    }

    public function showUser($user_id)
    {
        $this->_data['user'] = $this->muser->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_user/show_user_view';
        $this->load->view('backend/admin_template_view', $this->_data);
    }

}