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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<?php
$input_title = array(
'name' => 'title',
'type' => 'text',
'value' => isset($title) ? $title : '',
'placeholder' => 'Tên bài hát',
'checked' => true,
'class' => '',
'style' => 'width: 100%',
'min' => 1,
'max' => 50
);
$input_link = array(
'name' => 'link',
'type' => 'text',
'value' => isset($link) ? $link : '',
'placeholder' => 'Nhập link bài hát',
'class' => '',
'style' => 'width: 100%',
'min' => 1,
'max' => 50
);
$input_nct_id = array(
'name' => 'nct_id',
'type' => 'text',
'value' => isset($nct_id) ? $nct_id : '',
'placeholder' => 'Id bài hát trên NCT',
'class' => '',
'style' => 'width: 100%',
'min' => 1,
'max' => 50
);
$input_zing = array(
'name' => 'source',
'id' => 'zing',
'type' => 'radio',
'value' => 'zing',
'min' => 1,
'max' => 50
);
$input_nct = array(
'name' => 'source',
'type' => 'radio',
'id'=> 'nct',
'value' => 'nct',
'min' => 1,
'max' => 50
);
$input_keeng = array(
'name' => 'source',
'type' => 'radio',
'id' => 'keeng',
'value' => 'keeng',
'max' => 50
);
$input_username = array(
'name' => 'username',
'type' => 'text',
'value' => isset($username) ? $username : '',
'placeholder' => 'Nhập username',
'class' => '',
'style' => 'width: 100%',
'min' => 1,
'max' => 50
);
$input_email = array(
'name' => 'email',
'type' => 'email',
'value' => isset($email) ? $email : '',
'placeholder' => 'Nhập email',
'class' => '',
'style' => 'width: 100%',
);
$input_full_name = array(
'name' => 'full_name',
'type' => 'text',
'value' => isset($full_name) ? $full_name : '',
'placeholder' => 'Nhập tên đầy đủ',
'class' => '',
'style' => 'width: 100%',
);
$input_link_zing = array(
'name' => 'link_zing',
'type' => 'text',
'value' => isset($link_zing) ? $link_zing : '',
'placeholder' => 'Nhập Link Zingmp3',
'class' => '',
'style' => 'width: 100%',
);
$input_link_nct = array(
'name' => 'link_nct',
'type' => 'text',
'value' => isset($link_nct) ? $link_nct : '',
'placeholder' => 'Nhập link NCT',
'class' => '',
'style' => 'width: 100%',
);
$input_link_keeng = array(
'name' => 'link_keeng',
'type' => 'text',
'value' => isset($link_keeng) ? $link_keeng : '',
'placeholder' => 'Nhập link Keeng',
'class' => '',
'style' => 'width: 100%',
);
$check = "checked => 1";
(isset($source) && $source == 'zing' )? array_push($input_zing, $check) : '';
?>
<div class="row">
<div class="widget-box">
<div class="widget-header">
<p class="widget-title">Thêm mới bài hát</p>
</div>
<div class="widget-body">
<div class="widget-main">
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'myform');
echo form_open_multipart(base_url('backend/cmsTrack/addTrack'), $attributes);
?>
<div class="form-group">
<label class="col-lg-3"></label>
<div class="col-lg-3">
<input type="hidden" name="id" value="" />
<?php
if(validation_errors()){echo form_error('id', '<div class="error">', '</div>');}
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Tên bài hát (*)</label>
<div class="col-lg-3">
<?php
echo form_input($input_title);
if(validation_errors()){echo form_error('title', '<div class="error">', '</div>');}
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Tên Ca sĩ (*)</label>
<div class="col-lg-3">
<select id='form-field-select-3' name="singer" style='width: 200px;'
class="chosen-select form-control" data-placeholder="Choose a State...">
<?php if(!$singer):?>
<option value="0">Chọn ca sĩ</option>
<?php endif; ?>
<?php foreach ($list_user as $singers): ?>
<option value="<?php echo $singers['id']; ?>"
<?php if($singer && $singer == $singers['id']){ echo 'selected="selected"';}else echo ''; ?>>
<?php echo $singers['full_name']; ?>
</option>
<?php endforeach;
?>
</select>
<?php if(validation_errors()){echo form_error('singer', '<div class="error">', '</div>');} ?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Tên Người sáng tác (*)</label>
<div class="col-lg-3">
<select id='form-field-select-3' name="artist" style='width: 200px;'
class="chosen-select form-control" data-placeholder="Choose a State...">
<option value="0">Chọn người sáng tác</option>
<?php foreach ($list_user as $artists): ?>
<option value="<?php echo $artists['id']; ?>"
<?php if($artist && $artist == $artists['id']){ echo 'selected="selected"';}else echo ''; ?>>
<?php echo $artists['full_name']; ?>
</option>
<?php endforeach; ?>
</select>
<?php if(validation_errors()){echo form_error('artist', '<div class="error">', '</div>');} ?>
</div>
<div id="add_composer" style="display: none;">
<a href="#myModal" role="button" class="btn btn-success" data-toggle="modal">Thêm nghệ sĩ</a>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Ảnh Bài hát</label>
<div class="col-lg-3">
<input type="file" name="avatar" size="20" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Nguồn nhạc <?php isset($src_option) ? $src_option : ''; ?></label>
<div class="col-lg-3" id="source">
<div class="row">
<div class="col-lg-4">
<label class="src-option">
<input name="source" id="zing" value="zing" type="radio"
<?php if ($source == 'zing' || $source != 'nct' || $source != 'keeng') echo 'checked';?>>
Zing
</label>
</div>
<div class="col-lg-4">
<label class="src-option">
<input name="source" id="nct" value="nct" type="radio"
<?php if($source == 'nct' ) echo 'checked' ;?>> NCT
</label>
</div>
<div class="col-lg-4">
<label class="src-option">
<input name="source" id="keeng" value="keeng" type="radio"
<?php if($source == 'keeng' ) echo 'checked'; ?>> Keeng
</label>
</div>
</div>
<?php
if(validation_errors()){echo form_error('nct_id', '<div class="error">', '</div>');}
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Link nhạc</label>
<div class="col-lg-3">
<?php
echo form_input($input_link);
?>
</div>
</div>
<div class="form-group" id="nct_id" style="display: none;">
<label class="col-lg-3">ID Nhạc của tui </label>
<div class="col-lg-3">
<?php
echo form_input($input_nct_id);
?>
</div>
<input type="hidden" name="src_option"
value="<?php echo isset($src_option) ? $src_option : 'zing'; ?>" id="src_option">
</div>
<div class="form-group">
<div class="col-lg-3">
<a href="<?php echo base_url('backend/cmsTrack/listTrack');?>"
onclick="return confirm('Bạn có chắc chắn muốn quay lại Danh sách không?')">
<button type="button" class="btn btn-sm btn-default">
<i class="ace-icon fa fa-arrow-left"></i>Quay lại
</button>
</a>
</div>
<div class="col-lg-4">
<button class="btn btn-sm btn-primary" type="submit" name="btnSave">
<i class="ace-icon fa fa-check bigger-110"></i>Lưu lại
</button>
<button class="btn btn-sm" type="reset">
<i class="ace-icon fa fa-undo bigger-110"></i>Xóa form
</button>
</div>
</div>
<?php echo form_close(); ?>
<p class="text-danger">Chú ý: Có thể cập nhật lại ca sĩ hoặc nhạc sĩ.</p>
</div>
</div>
</div>
<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Thêm mới Ca sĩ/Nhạc sĩ</h3>
</div>
<div class="modal-body">
<div class="row">
<div class="widget-box">
<div class="widget-body">
<div class="widget-main">
<form id="form_add_artist" method="POST" class="form-horizontal">
<span id="err" class="text-danger"></span>
<div class="form-group">
<label class="col-lg-3"></label>
<div class="col-lg-3">
<input type="hidden" name="id" value="" />
</div>
</div>
<div class="form-group err-full-name" id="err-full-name">
<label class="col-lg-3">Tên đầu đủ (*)</label>
<div class="col-lg-3">
<input type="text" name="full_name" value="" class="form-control"
style="width:100%;" placeholder="Nhập họ tên đầy đủ" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Link Zingmp3</label>
<div class="col-lg-6">
<input type="text" name="link_zing" value="" class="form-control"
style="width:100%;" placeholder="Nhập link ZingMp3" />
</div>
<div class="col-lg-3 text-right">
<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-6">
<input type="text" name="link_nct" value="" class="form-control"
style="width:100%;" placeholder="Nhập link NCT" />
</div>
<div class="col-lg-3 text-right">
<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-6">
<input type="text" name="link_keeng" value="" class="form-control"
style="width:100%;" placeholder="Nhập Link Keeng" />
</div>
<div class="col-lg-3 text-right">
<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">
<a href="<?php echo base_url().'backend/cmsArtist/listArtist'?>"
onclick="return confirm('Bạn có chắc chắn muốn quay lại Danh sách không?')">
<button type="button" class="btn btn-sm btn-default">
<i class="ace-icon fa fa-arrow-left"></i>Quay lại
</button>
</a>
</div>
<div class="col-lg-4">
<button class="btn btn-sm btn-primary" id="add_artists" name="btnSave">
<i class="ace-icon fa fa-check bigger-110"></i>Lưu lại
</button>
<button class="btn btn-sm" type="reset">
<i class="ace-icon fa fa-undo bigger-110"></i>Xóa form
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!-- /.row -->
<script>
$(document).ready(function() {
show_src_option($('#src_option').val());
// Hiện ẩn option khi click nct
$('input[type="radio"]').click(function() {
show_src_option($(this).val());
});
$('input[name="source"]').click(function() {
$('#src_option').val($(this).val());
})
$('.chosen-select').chosen({
allow_single_deselect: true,
no_results_text: "Không có kết quả cần tìm"
});
$(window)
.off('resize.chosen')
.on('resize.chosen', function() {
$('.chosen-select').each(function() {
var $this = $(this);
$this.next().css({
'width': $this.parent().width()
});
})
}).trigger('resize.chosen');
//resize chosen on sidebar collapse/expand
$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
if (event_name != 'sidebar_collapsed') return;
$('.chosen-select').each(function() {
var $this = $(this);
$this.next().css({
'width': $this.parent().width()
});
})
});
//Hiển thị nút thêm mới nghệ sĩ
$('#add_composer').hide();
$('.chosen-single').click(function() {
$('#add_composer').hide();
var count = 0;
var count1 = 0;
$('.chosen-with-drop .chosen-drop .chosen-search input').keyup(function() {
count = $(".chosen-with-drop .chosen-drop .no-results").size();
count1 = $(".chosen-with-drop .chosen-drop .active-result").size();
var keywork1 = $('.chosen-with-drop .chosen-drop .chosen-search input').val();
if (count1 > 0 && keywork1 != '') {
if (count == 1) {
$('#add_composer').hide();
} else if (count == 0) {
$('#add_composer').hide();
}
} else {
if(count == 1) {
$('#add_composer').show();
} else if(count == 0) {
$('#add_composer').hide();
}
}
});
});
});
var url = '<?php echo base_url().'backend/cmsArtist/addArtistAjax'; ?>';
//Thêm mới nghệ sĩ
$('#add_artists').click(function(e) {
$('#err').empty();
e.preventDefault();
var formData = new FormData();
//append some non-form data also
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());
formData.append('link_keeng', $("input[name='link_keeng']").val());
$.ajax({
url: url,
type: 'POST',
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(data) {
if (data['check_full_name']) {
$('#err').append(data['check_full_name']);
$('#err-full-name').addClass('has-error');
} else
$('#err-full-name').removeClass('has-error');
if(data['success']){
$("#form_add_artist").trigger("reset");
alert('Tạo nghệ sĩ thành công!');
location.reload(true);
$('#myModal').modal('hide');
}
}
});
});
// validation
$('#add_composer').click(function() {
$("input[name='full_name']").keyup(function(){
if ($("input[name='full_name']").val() == '') {
$('#err').append('Vui lòng nhập họ tên');
$('.err-full-name').addClass('has-error');
} else {
$('#err').empty();
$('.err-full-name').removeClass('has-error');
$('.err-full-name').addClass('has-success');
}
var full_name = $("input[name='full_name']").val();
// var email = $("input[name='email']").val();
// var username = $("input[name='username']").val();
validation(full_name);
});
});
// validation
function validation(username = null, email = null, full_name) {
// var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
// var email_vali = regex.test(email);
if (full_name != '') {
$("#add_artists").attr("disabled", false);
} else {
$("#add_artists").attr("disabled", true);
}
}
function show_src_option(status) {
if (status == 'nct') {
$('#nct_id').show();
} else
$('#nct_id').hide();
}
</script>