|
209 | 209 | $xtpl = new XTemplate($op . '.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file);
|
210 | 210 | $xtpl->assign('LANG', $lang_module);
|
211 | 211 | $xtpl->assign('GLANG', $lang_global);
|
| 212 | +$xtpl->assign('TEMPLATE', $global_config['module_theme']); |
212 | 213 | $xtpl->assign('NV_BASE_SITEURL', NV_BASE_SITEURL);
|
213 | 214 | $xtpl->assign('MODULE_URL', NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE);
|
214 | 215 | $xtpl->assign('OP', $op);
|
|
301 | 302 | }
|
302 | 303 |
|
303 | 304 | 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 | + } |
330 | 349 | }
|
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']; |
335 | 356 | }
|
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'] = ''; |
340 | 365 | }
|
341 | 366 |
|
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 | + } |
356 | 401 | } elseif ($nv_Request->isset_request('add', 'get')) {
|
357 | 402 | $weight = $db->query("SELECT max(weight) FROM " . NV_GROUPS_GLOBALTABLE . " WHERE idsite=" . $global_config['idsite'])->fetchColumn();
|
358 | 403 | $weight = intval($weight) + 1;
|
359 | 404 |
|
360 | 405 | $_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'] . ")"; |
363 | 408 |
|
364 | 409 | $data_insert = array();
|
365 | 410 | $data_insert['title'] = $post['title'];
|
366 | 411 | $data_insert['description'] = $post['description'];
|
367 | 412 | $data_insert['content'] = $post['content'];
|
| 413 | + $data_insert['group_color'] = $post['group_color']; |
| 414 | + $data_insert['group_avatar'] = $post['group_avatar']; |
368 | 415 |
|
369 | 416 | $ok = $post['id'] = $db->insert_id($_sql, 'group_id', $data_insert);
|
370 | 417 | }
|
| 418 | + |
371 | 419 | if ($ok) {
|
372 | 420 | $nv_Cache->delMod($module_name);
|
373 | 421 | nv_insert_logs(NV_LANG_DATA, $module_name, $log_title, 'Id: ' . $post['id'], $admin_info['userid']);
|
|
386 | 434 | } else {
|
387 | 435 | $post['title'] = $post['description'] = $post['content'] = $post['exp_time'] = '';
|
388 | 436 | $post['group_type'] = 0;
|
389 |
| - $post['id'] = 0; |
| 437 | + $post['id'] = $post['is_default'] = 0; |
390 | 438 | }
|
391 | 439 |
|
392 | 440 | $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 | + } |
393 | 446 |
|
394 | 447 | $xtpl->assign('DATA', $post);
|
395 | 448 |
|
396 | 449 | if (defined('NV_CONFIG_DIR') and empty($global_config['idsite'])) {
|
397 |
| - $xtpl->parse('add.siteus'); |
| 450 | + $xtpl->parse('add.basic_infomation.siteus'); |
398 | 451 | }
|
399 | 452 |
|
400 | 453 | if (defined('NV_EDITOR') and nv_function_exists('nv_aleditor')) {
|
|
411 | 464 | );
|
412 | 465 |
|
413 | 466 | $xtpl->assign('GROUP_TYPE', $group_type);
|
414 |
| - $xtpl->parse('add.group_type'); |
| 467 | + $xtpl->parse('add.basic_infomation.group_type'); |
415 | 468 | }
|
416 | 469 |
|
417 | 470 | $xtpl->assign('CONTENT', $_cont);
|
418 | 471 | $xtpl->assign('NV_BASE_SITEURL', NV_BASE_SITEURL);
|
419 | 472 | $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'); |
420 | 475 |
|
421 | 476 | if ($post['id'] > 9 or $post['id'] == 0) {
|
422 | 477 | $xtpl->parse('add.basic_infomation');
|
423 | 478 | }
|
424 | 479 |
|
| 480 | + if (!empty($post['group_color'])) { |
| 481 | + $xtpl->parse('add.group_color'); |
| 482 | + } |
| 483 | + |
425 | 484 | $xtpl->parse('add');
|
426 | 485 | $contents = $xtpl->text('add');
|
427 | 486 | } else {
|
|
0 commit comments