group_topics.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. $language_file = array('userInfo');
  8. $cidReset = true;
  9. require '../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') !='true') {
  12. api_not_allowed();
  13. }
  14. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  16. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  17. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  18. //jquery thickbox already called from main/inc/header.inc.php
  19. $htmlHeadXtra[] = '<script type="text/javascript">
  20. function show_icon_edit(element_html) {
  21. ident="#edit_image";
  22. $(ident).show();
  23. }
  24. function hide_icon_edit(element_html) {
  25. ident="#edit_image";
  26. $(ident).hide();
  27. }
  28. </script>';
  29. $this_section = SECTION_SOCIAL;
  30. $interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('Social'));
  31. $interbreadcrumb[] = array('url' => 'groups.php','name' => get_lang('Groups'));
  32. $interbreadcrumb[] = array('url' => '#','name' => get_lang('MemberList'));
  33. api_block_anonymous_users();
  34. $group_id = intval($_GET['id']);
  35. $topic_id = intval($_GET['topic_id']);
  36. //todo @this validation could be in a function in group_portal_manager
  37. if (empty($group_id)) {
  38. api_not_allowed(true);
  39. } else {
  40. $group_info = GroupPortalManager::get_group_data($group_id);
  41. if (empty($group_info)) {
  42. api_not_allowed(true);
  43. }
  44. $is_member = GroupPortalManager::is_group_member($group_id);
  45. if ($group_info['visibility'] == GROUP_PERMISSION_CLOSED && !$is_member ) {
  46. api_not_allowed(true);
  47. }
  48. }
  49. Display::display_header($tool_name, 'Groups');
  50. // save message group
  51. if (isset($_POST['token']) && $_POST['token'] === $_SESSION['sec_token']) {
  52. if (isset($_POST['action'])) {
  53. $title = $_POST['title'];
  54. $content = $_POST['content'];
  55. $group_id = intval($_POST['group_id']);
  56. $parent_id = intval($_POST['parent_id']);
  57. if ($_POST['action'] == 'reply_message_group') {
  58. $title = cut($content, 50);
  59. }
  60. if ($_POST['action'] == 'edit_message_group') {
  61. $edit_message_id = intval($_POST['message_id']);
  62. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id, $edit_message_id);
  63. } else {
  64. if ($_POST['action'] == 'add_message_group' && !$is_member) {
  65. api_not_allowed();
  66. }
  67. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id);
  68. }
  69. // display error messages
  70. if (is_string($res)) {
  71. Display::display_error_message($res);
  72. }
  73. if (!empty($res)) {
  74. $groups_user = GroupPortalManager::get_users_by_group($group_id);
  75. $group_info = GroupPortalManager::get_group_data($group_id);
  76. $admin_user_info = api_get_user_info(1);
  77. $sender_name = api_get_person_name($admin_user_info['firstName'], $admin_user_info['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
  78. $sender_email = $admin_user_info['mail'];
  79. $subject = sprintf(get_lang('ThereIsANewMessageInTheGroupX'),$group_info['name']);
  80. $link = api_get_path(WEB_PATH).'main/social/groups.php?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
  81. $text_link = '<a href="'.$link.'">'.get_lang('ClickHereToSeeMessageGroup')."</a><br />\r\n<br />\r\n".get_lang('OrCopyPasteTheFollowingUrl')." <br />\r\n ".$link;
  82. $message = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $group_info['name'])."<br />$text_link";
  83. foreach ($groups_user as $group_user) {
  84. if ($group_user == $current_user) continue;
  85. $group_user_info = api_get_user_info($group_user['user_id']);
  86. $recipient_name = api_get_person_name($group_user_info['firstName'], $group_user_info['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
  87. $recipient_email = $group_user_info['mail'];
  88. @api_mail_html($recipient_name, $recipient_email, stripslashes($subject), $message, $sender_name, $sender_email);
  89. }
  90. }
  91. $topic_id = intval($_GET['topic_id']);
  92. if ($_POST['action'] == 'add_message_group') {
  93. $topic_id = $res;
  94. }
  95. }
  96. }
  97. echo '<div id="social-content">';
  98. echo '<div id="social-content-left">';
  99. //this include the social menu div
  100. SocialManager::show_social_menu('member_list', $group_id);
  101. echo '</div>';
  102. echo '<div id="social-content-right">';
  103. echo '<h1><a href="groups.php?id='.$group_id.'">'.$group_info['name'].'</a></h1>';
  104. if (!empty($show_message)){
  105. Display::display_confirmation_message($show_message);
  106. }
  107. $content = MessageManager::display_message_for_group($group_id, $topic_id, $is_member);
  108. echo $content;
  109. echo '</div>';
  110. echo '</div>';
  111. Display :: display_footer();