1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?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);
}
}