Commit ce500d2d by Trần Văn Minh

update form add, edit nghệ sĩ

parent 7662ec53
......@@ -58,28 +58,15 @@ class CmsArtist extends CI_Controller
);
$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'
'trim|callback_check_full_name|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');
......@@ -91,16 +78,12 @@ class CmsArtist extends CI_Controller
$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){
if( $full_name){
$dataUpdate = array(
'username' => $username,
'email' => $email,
'user_type' => 2,
'full_name' => $full_name,
'link' => $link_zing,
......@@ -121,27 +104,19 @@ class CmsArtist extends CI_Controller
public function addArtistAjax()
{
$email = $this->input->post('email');
$username = $this->input->post('username');
// Kiểm tra trùng giá trị nếu thay đổi ở form
$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 == '') {
$check_full_name = $this->user_model->getByFullName($full_name, 2, '');
if($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 if($check_full_name) {
$data['check_full_name'] = 'Tên nghệ sĩ đã 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,
......@@ -171,28 +146,15 @@ class CmsArtist extends CI_Controller
);
$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'
'trim|callback_check_full_name|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');
......@@ -204,19 +166,13 @@ class CmsArtist extends CI_Controller
$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){
if($full_name){
$dataUpdate = array(
'username' => $username,
'password' => $password,
'email' => $email,
'user_type' => 2,
'full_name' => $full_name,
'link' => ($link_zing == '') ? null: $link_zing,
......@@ -247,7 +203,7 @@ class CmsArtist extends CI_Controller
$this->load->view('backend/admin_template_view', $this->_data);
}
public function check_username($username)
public function check_full_name($full_name)
{
if ($this->input->post('id')) {
$id = $this->input->post('id');
......@@ -255,28 +211,10 @@ class CmsArtist extends CI_Controller
else {
$id = '';
}
$result = $this->user_model->getByUsername($username, 2, $id);
$result = $this->user_model->getByFullName($full_name, 2, $id);
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, 2, $id);
if($result) {
// die('2335');
$this->form_validation->set_message('check_email', '<li class="list-unstyled">Email đã tồn tại.</li>');
$this->form_validation->set_message('check_full_name', '<li class="list-unstyled">Tên ca sĩ đã tồn tại.</li>');
return false;
}else{
return TRUE;
......
......@@ -46,6 +46,20 @@ class User_model extends CI_Model
return $query->result_array();
}
public function getByFullName($full_name, $account_type, $id = '')
{
$this->db->select($this->_table . '.*');
$this->db->from($this->_table);
$this->db->where($this->_table . '.full_name', $full_name);
$this->db->where($this->_table . '.user_type', $account_type);
if ($id || $id != '') {
$this->db->where_not_in('id', $id);
}
$this->db->limit(1);
$query = $this->db->get();
return $query->result_array();
}
public function getByEmail($email, $account_type, $id = '')
{
// MyHelper::echoPreDie($email);
......@@ -99,6 +113,7 @@ class User_model extends CI_Model
$this->db->like('username', $name, 'both');
$this->db->or_like('email', $name, 'both');
$this->db->or_like('full_name', $name, 'both');
$this->db->or_where('id', intval($name));
}
$query = $this->db->get();
$result = $query->result_array();
......@@ -111,12 +126,14 @@ class User_model extends CI_Model
public function cmsGetPagination($record, $start, $name = null)
{
$this->db->select($this->_table . '.*');
$this->db->from($this->_table);
if ($name != null) {
$this->db->like('username', $name, 'both');
$this->db->or_like('email', $name, 'both');
$this->db->or_like('full_name', $name, 'both');
$this->db->or_where('id', intval($name));
}
$this->db->order_by($this->_table . '.username', 'asc');
$this->db->limit($record, $start);
......
......@@ -5,8 +5,6 @@
<th style="text-align: center">TT</th>
<th style="text-align: center">#ID</th>
<th style="text-align: center">Tên Ca sĩ/Nhạc sĩ</th>
<th style="text-align: center">Tài khoản</th>
<th style="text-align: center">Email</th>
<th style="text-align: center">Xử lý</th>
</tr>
</thead>
......@@ -16,8 +14,6 @@
<td style="text-align: center"><?php echo ($key+1+$offset); ?></td>
<td style="text-align: center">#<?php echo $data['id']; ?></td>
<td style="text-align: left"><?php echo $data['full_name']; ?></td>
<td style="text-align: left"><?php echo $data['username']; ?></td>
<td style="text-align: left"><?php echo $data['email']; ?></td>
<td style="text-align: center">
<a href="<?php echo base_url().'backend/cmsArtist/editArtist/'.$data['id']; ?>" title="Sửa thông tin">
<i class="ace-icon fa fa-pencil bigger-130"></i>
......
......@@ -92,36 +92,6 @@ $input_link_keeng = array(
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Username (*)</label>
<div class="col-lg-3">
<?php
echo form_input($input_username);
if(validation_errors()){echo form_error('username', '<div class="error">', '</div>');}
?>
</div>
<div><span name></span></div>
</div>
<!-- <?php if (!$contest[0]) { ?>
<div class="form-group">
<label class="col-lg-3">Password (*)</label>
<div class="col-lg-3">
<?php
echo form_input($input_password);
if(validation_errors()){echo form_error('username', '<div class="error">', '</div>');}
?>
</div>
</div>
<?php } ?> -->
<div class="form-group">
<label class="col-lg-3">Email (*)</label>
<div class="col-lg-3">
<?php
echo form_input($input_email);
if(validation_errors()){echo form_error('email', '<div class="error">', '</div>');}
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Tên đầu đủ (*)</label>
<div class="col-lg-3">
<?php
......@@ -130,54 +100,38 @@ $input_link_keeng = array(
?>
</div>
</div>
<!-- <div class="form-group">
<label class="col-lg-3">Bio </label>
<div class="col-lg-3">
<?php
echo form_textarea($input_bio);
if(validation_errors()){echo form_error('date_from', '<div class="error">', '</div>');}
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Avartar</label>
<div class="col-lg-3">
<?php
echo form_upload($input_avatar);
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Cover</label>
<div class="col-lg-3">
<?php
echo form_upload($input_cover);
?>
</div>
</div> -->
<div class="form-group">
<label class="col-lg-3">Link Zingmp3</label>
<div class="col-lg-3">
<div class="col-lg-6">
<?php
echo form_input($input_link_zing);
?>
</div>
<div class="col-lg-3">
<span><a href="https://zingmp3.vn/the-loai-nghe-si/Viet-Nam/IWZ9Z08I.html" target="_blank" >Lấy link ở ZingMp3</a></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Link Nhạc của tui</label>
<div class="col-lg-3">
<div class="col-lg-6">
<?php
echo form_input($input_link_nct);
?>
</div>
<div class="col-lg-3">
<span><a href="https://www.nhaccuatui.com/nghe-si.html" target="_blank">Lấy link ở NCT</a></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Link Keeng</label>
<div class="col-lg-3">
<div class="col-lg-6">
<?php
echo form_input($input_link_keeng);
?>
</div>
<div class="col-lg-3">
<span><a href="http://keeng.vn/danh-sach-ca-si" target="_blank">Lấy link ở Keeng</a></span>
</div>
</div>
<div class="form-group">
<div class="col-lg-3">
......
......@@ -100,36 +100,6 @@ $input_link_keeng = array(
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Username (*)</label>
<div class="col-lg-3">
<?php
echo form_input($input_username);
if(validation_errors()){echo form_error('username', '<div class="error">', '</div>');}
?>
</div>
<div><span name></span></div>
</div>
<!-- <?php if (!$contest[0]) { ?>
<div class="form-group">
<label class="col-lg-3">Password (*)</label>
<div class="col-lg-3">
<?php
echo form_input($input_password);
if(validation_errors()){echo form_error('username', '<div class="error">', '</div>');}
?>
</div>
</div>
<?php } ?> -->
<div class="form-group">
<label class="col-lg-3">Email (*)</label>
<div class="col-lg-3">
<?php
echo form_input($input_email);
if(validation_errors()){echo form_error('email', '<div class="error">', '</div>');}
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Tên đầu đủ (*)</label>
<div class="col-lg-3">
<?php
......@@ -138,54 +108,38 @@ $input_link_keeng = array(
?>
</div>
</div>
<!-- <div class="form-group">
<label class="col-lg-3">Bio </label>
<div class="col-lg-3">
<?php
echo form_textarea($input_bio);
if(validation_errors()){echo form_error('date_from', '<div class="error">', '</div>');}
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Avartar</label>
<div class="col-lg-3">
<?php
echo form_upload($input_avatar);
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Cover</label>
<div class="col-lg-3">
<?php
echo form_upload($input_cover);
?>
</div>
</div> -->
<div class="form-group">
<label class="col-lg-3">Link Zingmp3</label>
<div class="col-lg-3">
<div class="col-lg-6">
<?php
echo form_input($input_link_zing);
?>
</div>
<div class="col-lg-3">
<span><a href="https://zingmp3.vn/the-loai-nghe-si/Viet-Nam/IWZ9Z08I.html" target="_blank" >Lấy link ở ZingMp3</a></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Link Nhạc của tui</label>
<div class="col-lg-3">
<div class="col-lg-6">
<?php
echo form_input($input_link_nct);
?>
</div>
<div class="col-lg-3">
<span><a href="https://www.nhaccuatui.com/nghe-si.html" target="_blank">Lấy link ở NCT</a></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Link Keeng</label>
<div class="col-lg-3">
<div class="col-lg-6">
<?php
echo form_input($input_link_keeng);
?>
</div>
<div class="col-lg-3">
<span><a href="http://keeng.vn/danh-sach-ca-si" target="_blank">Lấy link ở Keeng</a></span>
</div>
</div>
<div class="form-group">
<div class="col-lg-3">
......
......@@ -25,7 +25,7 @@
<?php echo form_open(base_url().'backend/cmsArtist/listArtistAjax'); ?>
<div class="col-lg-3">
<input class="form-control" type="text" name="input-name" id="input-name"
placeholder="Nhập tên nghệ sĩ, email..." />
placeholder="Nhập id, tên nghệ sĩ, email..." />
</div>
<div class="col-lg-1">
<button class="btn btn-sm btn-default" id="delete-filter">Xóa bộ lọc</button>
......
......@@ -91,24 +91,6 @@
<input type="hidden" name="id" value="" />
</div>
</div>
<div class="form-group" id="err-username">
<label class="col-lg-3"></label>
<label class="col-lg-3">Username (*)</label>
<div class="col-lg-3">
<input type="text" name="username" value="" class="form-control"
style="width:100%;" placeholder="Nhập username" />
</div>
<label class="col-lg-3"></label>
<div><span name></span></div>
</div>
<div class="form-group" id="err-email">
<label class="col-lg-3"></label>
<label class="col-lg-3">Email (*)</label>
<div class="col-lg-3">
<input type="email" name="email" value="" class="form-control"
style="width:100%;" placeholder="Nhập email" />
</div>
</div>
<div class="form-group err-full-name">
<label class="col-lg-3"></label>
<label class="col-lg-3">Tên đầu đủ (*)</label>
......@@ -118,28 +100,34 @@
</div>
</div>
<div class="form-group">
<label class="col-lg-3"></label>
<label class="col-lg-3">Link Zingmp3</label>
<div class="col-lg-3">
<input type="text" name="link_zing" value="" class="form-control"
style="width:100%;" placeholder="Nhập link ZingMp3" />
</div>
<div class="col-lg-3">
<span><a href="https://zingmp3.vn/the-loai-nghe-si/Viet-Nam/IWZ9Z08I.html" target="_blank" >Lấy link ở ZingMp3</a></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3"></label>
<label class="col-lg-3">Link Nhạc của tui</label>
<div class="col-lg-3">
<input type="text" name="link_nct" value="" class="form-control"
style="width:100%;" placeholder="Nhập link NCT" />
</div>
<div class="col-lg-3">
<span><a href="https://www.nhaccuatui.com/nghe-si.html" target="_blank">Lấy link ở NCT</a></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3"></label>
<label class="col-lg-3">Link Keeng</label>
<div class="col-lg-3">
<input type="text" name="link_keeng" value="" class="form-control"
style="width:100%;" placeholder="Nhập Link Keeng" />
</div>
<div class="col-lg-3">
<span><a href="http://keeng.vn/danh-sach-ca-si" target="_blank">Lấy link ở Keeng</a></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3"></label>
......@@ -232,9 +220,6 @@ $('#add_artists').click(function(e) {
$('#err').empty();
e.preventDefault();
var formData = new FormData();
//append some non-form data also
formData.append('username', $("input[name='username']").val());
formData.append('email', $("input[name='email']").val());
formData.append('full_name', $("input[name='full_name']").val());
formData.append('link_zing', $("input[name='link_zing']").val());
formData.append('link_nct', $("input[name='link_nct']").val());
......@@ -248,16 +233,12 @@ $('#add_artists').click(function(e) {
processData: false,
contentType: false,
success: function(data) {
if (data['check_username']) {
$('#err').append(data['check_username']);
$('#err-username').addClass('has-error');
} else
$('#err-username').removeClass('has-error');
if (data['check_email']) {
$('#err').append(data['check_email']);
$('#err-email').addClass('has-error');
if (data['check_full_name']) {
$('#err').append(data['check_full_name']);
$('#err-full-name').addClass('has-error');
} else
$('#err-email').removeClass('has-error');
$('#err-full-name').removeClass('has-error');
if(data['success']){
$("#form_add_artist").trigger("reset");
alert('Tạo nghệ sĩ thành công!');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment