Skip to content

Commit 71b06da

Browse files
committed
Add management: avatar, color, default for groups
1 parent dfb78da commit 71b06da

File tree

7 files changed

+171
-56
lines changed

7 files changed

+171
-56
lines changed

assets/users/groups/index.html

Whitespace-only changes.

assets/users/index.html

Whitespace-only changes.

modules/users/admin/groups.php

+112-53
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
$xtpl = new XTemplate($op . '.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file);
210210
$xtpl->assign('LANG', $lang_module);
211211
$xtpl->assign('GLANG', $lang_global);
212+
$xtpl->assign('TEMPLATE', $global_config['module_theme']);
212213
$xtpl->assign('NV_BASE_SITEURL', NV_BASE_SITEURL);
213214
$xtpl->assign('MODULE_URL', NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE);
214215
$xtpl->assign('OP', $op);
@@ -301,73 +302,120 @@
301302
}
302303

303304
if ($nv_Request->isset_request('save', 'post')) {
304-
$post['title'] = $nv_Request->get_title('title', 'post', '', 1);
305-
if (empty($post['title'])) {
306-
die($lang_module['title_empty']);
307-
}
308-
309-
// Kiểm tra trùng tên nhóm
310-
$stmt = $db->prepare('SELECT group_id FROM ' . NV_GROUPS_GLOBALTABLE . ' WHERE title LIKE :title AND group_id!= ' . intval($post['id']) . ' AND (idsite=' . $global_config['idsite'] . ' or (idsite=0 AND siteus=1))');
311-
$stmt->bindParam(':title', $post['title'], PDO::PARAM_STR);
312-
$stmt->execute();
313-
if ($stmt->fetchColumn()) {
314-
die(sprintf($lang_module['error_title_exists'], $post['title']));
315-
}
316-
317-
$post['description'] = $nv_Request->get_title('description', 'post', '', 1);
318-
if (empty($post['description'])) {
319-
die($lang_module['group_description_empty']);
320-
}
321-
322-
$post['content'] = $nv_Request->get_editor('content', '', NV_ALLOWED_HTML_TAGS);
323-
324-
$post['exp_time'] = $nv_Request->get_title('exp_time', 'post', '');
325-
326-
if (preg_match('/^([\d]{1,2})\/([\d]{1,2})\/([\d]{4})$/', $post['exp_time'], $matches)) {
327-
$post['exp_time'] = mktime(23, 59, 59, $matches[2], $matches[1], $matches[3]);
328-
} else {
329-
$post['exp_time'] = 0;
305+
// Sửa / Thêm full thông tin
306+
if (empty($post['id']) or $post['id'] > 9) {
307+
$post['title'] = $nv_Request->get_title('title', 'post', '', 1);
308+
if (empty($post['title'])) {
309+
die($lang_module['title_empty']);
310+
}
311+
312+
// Kiểm tra trùng tên nhóm
313+
$stmt = $db->prepare('SELECT group_id FROM ' . NV_GROUPS_GLOBALTABLE . ' WHERE title LIKE :title AND group_id!= ' . intval($post['id']) . ' AND (idsite=' . $global_config['idsite'] . ' or (idsite=0 AND siteus=1))');
314+
$stmt->bindParam(':title', $post['title'], PDO::PARAM_STR);
315+
$stmt->execute();
316+
if ($stmt->fetchColumn()) {
317+
die(sprintf($lang_module['error_title_exists'], $post['title']));
318+
}
319+
320+
$post['description'] = $nv_Request->get_title('description', 'post', '', 1);
321+
if (empty($post['description'])) {
322+
die($lang_module['group_description_empty']);
323+
}
324+
325+
$post['content'] = $nv_Request->get_editor('content', '', NV_ALLOWED_HTML_TAGS);
326+
327+
$post['exp_time'] = $nv_Request->get_title('exp_time', 'post', '');
328+
329+
if (preg_match('/^([\d]{1,2})\/([\d]{1,2})\/([\d]{4})$/', $post['exp_time'], $matches)) {
330+
$post['exp_time'] = mktime(23, 59, 59, $matches[2], $matches[1], $matches[3]);
331+
} else {
332+
$post['exp_time'] = 0;
333+
}
334+
335+
$post['group_type'] = $nv_Request->get_int('group_type', 'post', 0);
336+
if (!in_array($post['group_type'], array(0, 1, 2))) {
337+
$post['group_type'] = 0;
338+
}
339+
340+
$post['siteus'] = $nv_Request->get_int('siteus', 'post', 0);
341+
if ($post['siteus'] != 1) {
342+
$post['siteus'] = 0;
343+
}
344+
345+
$post['is_default'] = $nv_Request->get_int('is_default', 'post', 0);
346+
if ($post['is_default'] != 1) {
347+
$post['is_default'] = 0;
348+
}
330349
}
331-
332-
$post['group_type'] = $nv_Request->get_int('group_type', 'post', 0);
333-
if (!in_array($post['group_type'], array(0, 1, 2))) {
334-
$post['group_type'] = 0;
350+
351+
// Thông tin của tất cả các nhóm kể cả các nhóm hệ thống
352+
$post['group_color'] = nv_substr($nv_Request->get_title('group_color', 'post', '', 1), 0, 10);
353+
354+
if (preg_match("/^([0-9a-fA-F]{6})$/i", $post['group_color']) or preg_match("/^([0-9a-fA-F]{3})$/i", $post['group_color'])) {
355+
$post['group_color'] = '#' . $post['group_color'];
335356
}
336-
337-
$post['siteus'] = $nv_Request->get_int('siteus', 'post', 0);
338-
if ($post['siteus'] != 1) {
339-
$post['siteus'] = 0;
357+
358+
$post['group_avatar'] = $nv_Request->get_title('group_avatar', 'post', '');
359+
360+
if (! nv_is_url($post['group_avatar']) and nv_is_file($post['group_avatar'], NV_UPLOADS_DIR . '/' . $module_upload)) {
361+
$lu = strlen(NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/');
362+
$post['group_avatar'] = substr($post['group_avatar'], $lu);
363+
} elseif (!nv_is_url($post['group_avatar'])) {
364+
$post['group_avatar'] = '';
340365
}
341366

342-
if (isset($post['id']) and $post['id'] > 9) {
343-
$stmt = $db->prepare("UPDATE " . NV_GROUPS_GLOBALTABLE . " SET
344-
title= :title,
345-
description= :description,
346-
content= :content,
347-
group_type='" . $post['group_type'] . "',
348-
exp_time='" . $post['exp_time'] . "',
349-
siteus='" . $post['siteus'] . "'
350-
WHERE group_id=" . $post['id']);
351-
352-
$stmt->bindParam(':title', $post['title'], PDO::PARAM_STR);
353-
$stmt->bindParam(':description', $post['description'], PDO::PARAM_STR);
354-
$stmt->bindParam(':content', $post['content'], PDO::PARAM_STR, strlen($post['content']));
355-
$ok = $stmt->execute();
367+
if (isset($post['id'])) {
368+
if ($post['id'] > 9) {
369+
// Sửa nhóm tự tạo
370+
$stmt = $db->prepare("UPDATE " . NV_GROUPS_GLOBALTABLE . " SET
371+
title = :title,
372+
description = :description,
373+
content = :content,
374+
group_type = '" . $post['group_type'] . "',
375+
group_color = :group_color,
376+
group_avatar = :group_avatar,
377+
is_default = " . $post['is_default'] . ",
378+
exp_time ='" . $post['exp_time'] . "',
379+
siteus = '" . $post['siteus'] . "'
380+
WHERE group_id = " . $post['id']);
381+
382+
$stmt->bindParam(':title', $post['title'], PDO::PARAM_STR);
383+
$stmt->bindParam(':description', $post['description'], PDO::PARAM_STR);
384+
$stmt->bindParam(':content', $post['content'], PDO::PARAM_STR, strlen($post['content']));
385+
$stmt->bindParam(':group_color', $post['group_color']);
386+
$stmt->bindParam(':group_avatar', $post['group_avatar']);
387+
388+
$ok = $stmt->execute();
389+
} else {
390+
// Sửa nhóm hệ thống
391+
$stmt = $db->prepare("UPDATE " . NV_GROUPS_GLOBALTABLE . " SET
392+
group_color = :group_color,
393+
group_avatar = :group_avatar
394+
WHERE group_id=" . $post['id']);
395+
396+
$stmt->bindParam(':group_color', $post['group_color']);
397+
$stmt->bindParam(':group_avatar', $post['group_avatar']);
398+
399+
$ok = $stmt->execute();
400+
}
356401
} elseif ($nv_Request->isset_request('add', 'get')) {
357402
$weight = $db->query("SELECT max(weight) FROM " . NV_GROUPS_GLOBALTABLE . " WHERE idsite=" . $global_config['idsite'])->fetchColumn();
358403
$weight = intval($weight) + 1;
359404

360405
$_sql = "INSERT INTO " . NV_GROUPS_GLOBALTABLE . "
361-
(title, description, content, group_type, add_time, exp_time, weight, act, idsite, numbers, siteus)
362-
VALUES ( :title, :description, :content, " . $post['group_type'] . ", " . NV_CURRENTTIME . ", " . $post['exp_time'] . ", " . $weight . ", 1, " . $global_config['idsite'] . ", 0, " . $post['siteus'] . ")";
406+
(title, description, content, group_type, group_color, group_avatar, is_default, add_time, exp_time, weight, act, idsite, numbers, siteus)
407+
VALUES ( :title, :description, :content, " . $post['group_type'] . ", :group_color, :group_avatar, " . $post['is_default'] . ", " . NV_CURRENTTIME . ", " . $post['exp_time'] . ", " . $weight . ", 1, " . $global_config['idsite'] . ", 0, " . $post['siteus'] . ")";
363408

364409
$data_insert = array();
365410
$data_insert['title'] = $post['title'];
366411
$data_insert['description'] = $post['description'];
367412
$data_insert['content'] = $post['content'];
413+
$data_insert['group_color'] = $post['group_color'];
414+
$data_insert['group_avatar'] = $post['group_avatar'];
368415

369416
$ok = $post['id'] = $db->insert_id($_sql, 'group_id', $data_insert);
370417
}
418+
371419
if ($ok) {
372420
$nv_Cache->delMod($module_name);
373421
nv_insert_logs(NV_LANG_DATA, $module_name, $log_title, 'Id: ' . $post['id'], $admin_info['userid']);
@@ -386,15 +434,20 @@
386434
} else {
387435
$post['title'] = $post['description'] = $post['content'] = $post['exp_time'] = '';
388436
$post['group_type'] = 0;
389-
$post['id'] = 0;
437+
$post['id'] = $post['is_default'] = 0;
390438
}
391439

392440
$post['content'] = htmlspecialchars(nv_editor_br2nl($post['content']));
441+
$post['is_default'] = $post['is_default'] ? ' checked="checked"' : '';
442+
443+
if (! empty($post['group_avatar']) and is_file(NV_UPLOADS_REAL_DIR . '/' . $module_upload . '/' . $post['group_avatar'])) {
444+
$post['group_avatar'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/' . $post['group_avatar'];
445+
}
393446

394447
$xtpl->assign('DATA', $post);
395448

396449
if (defined('NV_CONFIG_DIR') and empty($global_config['idsite'])) {
397-
$xtpl->parse('add.siteus');
450+
$xtpl->parse('add.basic_infomation.siteus');
398451
}
399452

400453
if (defined('NV_EDITOR') and nv_function_exists('nv_aleditor')) {
@@ -411,17 +464,23 @@
411464
);
412465

413466
$xtpl->assign('GROUP_TYPE', $group_type);
414-
$xtpl->parse('add.group_type');
467+
$xtpl->parse('add.basic_infomation.group_type');
415468
}
416469

417470
$xtpl->assign('CONTENT', $_cont);
418471
$xtpl->assign('NV_BASE_SITEURL', NV_BASE_SITEURL);
419472
$xtpl->assign('NV_LANG_INTERFACE', NV_LANG_INTERFACE);
473+
$xtpl->assign('AVATAR_PATH', NV_UPLOADS_DIR . '/' . $module_upload);
474+
$xtpl->assign('AVATAR_CURENT_PATH', NV_UPLOADS_DIR . '/' . $module_upload . '/groups');
420475

421476
if ($post['id'] > 9 or $post['id'] == 0) {
422477
$xtpl->parse('add.basic_infomation');
423478
}
424479

480+
if (!empty($post['group_color'])) {
481+
$xtpl->parse('add.group_color');
482+
}
483+
425484
$xtpl->parse('add');
426485
$contents = $xtpl->text('add');
427486
} else {

modules/users/language/admin_vi.php

+3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@
158158
$lang_module['group_type_0'] = 'Nhóm cố định';
159159
$lang_module['group_type_1'] = 'Nhóm tham gia phải gửi yêu cầu';
160160
$lang_module['group_type_2'] = 'Nhóm tham gia tự do';
161+
$lang_module['group_color'] = 'Màu nhóm';
162+
$lang_module['group_avatar'] = 'Ảnh đại diện nhóm';
163+
$lang_module['group_is_default'] = 'Nhóm mặc định khi đăng ký thành viên vào';
161164
$lang_module['siteus'] = 'Cho phép các subsite thêm tài khoản vào nhóm';
162165
$lang_module['users'] = 'Thành viên';
163166
$lang_module['error_title_exists'] = 'Tên nhóm "%s" đã tồn tại';

themes/admin_default/js/users.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -571,5 +571,15 @@ $(document).ready(function(){
571571
$("select[name=choicetypes]").change(function() {
572572
nv_users_check_choicetypes(this);
573573
});
574-
574+
575+
// Group
576+
$("[name='browse-image']").click(function(e) {
577+
e.preventDefault()
578+
var area = $(this).data('area'),
579+
path = $(this).data('path'),
580+
currentpath = $(this).data('currentpath'),
581+
type = "image"
582+
583+
nv_open_browse(script_name + "?" + nv_name_variable + "=upload&popup=1&area=" + area + "&path=" + path + "&type=" + type + "&currentpath=" + currentpath, "NVImg", 850, 420, "resizable=no,scrollbars=no,toolbar=no,location=no,status=no");
584+
});
575585
});

themes/admin_default/modules/users/groups.tpl

+45-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
<link type="text/css" href="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/ui/jquery.ui.core.css" rel="stylesheet" />
33
<link type="text/css" href="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/ui/jquery.ui.theme.css" rel="stylesheet" />
44
<link type="text/css" href="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/ui/jquery.ui.datepicker.css" rel="stylesheet" />
5+
<link rel="stylesheet" href="{NV_BASE_SITEURL}themes/{TEMPLATE}/js/colpick.css">
6+
57
<script type="text/javascript" src="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/ui/jquery.ui.core.min.js"></script>
68
<script type="text/javascript" src="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/ui/jquery.ui.datepicker.min.js"></script>
79
<script type="text/javascript" src="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/language/jquery.ui.datepicker-{NV_LANG_INTERFACE}.js"></script>
10+
<script src="{NV_BASE_SITEURL}themes/{TEMPLATE}/js/colpick.js"></script>
11+
812
<div id="pageContent">
913
<form id="addCat" method="post" action="{ACTION_URL}">
1014
<h3 class="myh3">{PTITLE}</h3>
@@ -36,6 +40,10 @@
3640
</select>
3741
</td>
3842
</tr>
43+
<tr>
44+
<td>{LANG.group_is_default}:</td>
45+
<td><input type="checkbox" name="is_default" value="1"{DATA.is_default}/></td>
46+
</tr>
3947
<!-- BEGIN: siteus -->
4048
<tr>
4149
<td>{LANG.siteus}:</td>
@@ -45,13 +53,37 @@
4553
</tbody>
4654
</table>
4755
</div>
48-
<div>
56+
<div class="clearfix">
4957
{LANG.content}
5058
</div>
51-
<div>
59+
<div class="clearfix m-bottom">
5260
{CONTENT}
5361
</div>
5462
<!-- END: basic_infomation -->
63+
<div class="table-responsive">
64+
<table class="table table-striped table-bordered table-hover">
65+
<colgroup>
66+
<col class="w300"/>
67+
<col />
68+
</colgroup>
69+
<tbody>
70+
<tr>
71+
<td>{LANG.group_color}:</td>
72+
<td class="form-inline">
73+
<input class="form-control w200" type="text" name="group_color" value="{DATA.group_color}" maxlength="10"/>
74+
<input name="group_color_demo" class="form-control w50"<!-- BEGIN: group_color --> style="background-color:{DATA.group_color}"<!-- END: group_color --> readonly="readonly"/>
75+
</td>
76+
</tr>
77+
<tr>
78+
<td>{LANG.group_avatar}:</td>
79+
<td class="form-inline">
80+
<input class="form-control" type="text" name="group_avatar" id="group_avatar" value="{DATA.group_avatar}" maxlength="10"/>
81+
<input type="button" name="browse-image" value="{LANG.select}" class="btn btn-default" data-area="group_avatar" data-path="{AVATAR_PATH}" data-currentpath="{AVATAR_CURENT_PATH}"/>
82+
</td>
83+
</tr>
84+
</tbody>
85+
</table>
86+
</div>
5587
<input type="hidden" name="save" value="1" />
5688
<p class="text-center"><input name="submit" type="submit" value="{LANG.save}" class="btn btn-primary w100" style="margin-top: 10px" /></p>
5789
</form>
@@ -68,6 +100,17 @@
68100
buttonImage : nv_base_siteurl + "assets/images/calendar.gif",
69101
buttonImageOnly : true
70102
});
103+
$('[name="group_color"]').colpick({
104+
layout:'hex',
105+
submit:0,
106+
colorScheme:'dark',
107+
onChange:function(hsb,hex,rgb,el,bySetColor) {
108+
$('[name="group_color_demo"]').css('background-color','#'+hex);
109+
if(!bySetColor) $(el).val('#' + hex);
110+
}
111+
}).keyup(function(){
112+
$(this).colpickSetColor(this.value);
113+
});
71114
});
72115
$("form#addCat").submit(function() {
73116
var a = $("input[name=title]").val(), a = trim(a);

uploads/users/groups/index.html

Whitespace-only changes.

0 commit comments

Comments
 (0)