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
<?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('track_model');
$this->load->model('user_model');
$this->load->model('actionlog_model');
}
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 = 100;
$offset = ($pageId - 1) * $limit;
$data['offset'] = ($pageId - 1) * $limit;
$totalRecord = $this->track_model->cmsCountAll($fByName);
$data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
$data['listData'] = $this->track_model->cmsGetPagination($limit, $offset, $fByName);
//
$this->load->view('backend/ajax/cms_track/list_track_view', $data);
}
public function editTrack($contest_id, $id_user = '', $id_artist = '')
{
$this->_data['contest'] = $contest = $this->track_model->getById($contest_id, $id_user, $id_artist);
$this->_data['track_artists'] = $track_artists = $this->track_model->getByIdUser('track_artists', $id_artist);
$this->_data['track_user'] = $track_user = $this->track_model->getByIdUser('track_user', $id_user);
$this->_data['list_user'] = $list_user = $this->track_model->getListUsers();
// 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(
'title',
'Số ngày 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['title'] = $this->input->post('title');
$this->_data['update_singer'] = $this->input->post('update_singer');
$this->_data['singer'] = $this->input->post('singer');
$this->_data['artist'] = $this->input->post('artist');
$this->_data['update_artist'] = $this->input->post('update_artist');
//
$this->_data['functionName'] = 'Cập nhật thông tin';
$this->_data['action'] = 'editTrack';
$this->_data['titlePage'] = 'Cập nhật thông tin';
$this->_data['loadPage'] = 'backend/cms_track/edit_track_view';
$this->load->view('backend/admin_template_view', $this->_data);
} else {
$title = $this->input->post('title');
$update_singer = $this->input->post('update_singer');
$singer = $track_user[0]['user_id'];
$artist = $track_artists[0]['user_id'];
$update_artist = $this->input->post('update_artist');
$id_singer = ($update_singer > 0) ? $update_singer: $singer;
$id_artists = ($update_artist > 0) ? $update_artist: $artist;
($singer || $id_user) ? $active_singer = 'update': $active_singer = 'insert';
($artist || $id_artist) ? $active_artist = 'update': $active_artist = 'insert';
// die($id_singer.$id_artists);
$this->track_model->update_track_artists($contest_id, $id_artists, $id_artist, $active_artist);
$this->track_model->update_track_user($contest_id, $id_singer, $id_user, $active_singer);
$this->track_model->update($contest_id, $title);
// 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/cmsTrack/listTrack');
}
}
}