group_topics.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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', 'forum');
  8. $cidReset = true;
  9. require_once '../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. $htmlHeadXtra[] = '<script type="text/javascript">
  19. var counter_image = 1;
  20. function remove_image_form(id_elem1) {
  21. var elem1 = document.getElementById(id_elem1);
  22. elem1.parentNode.removeChild(elem1);
  23. counter_image--;
  24. var filepaths = document.getElementById("filepaths");
  25. if (filepaths.childNodes.length < 3) {
  26. var link_attach = document.getElementById("link-more-attach");
  27. if (link_attach) {
  28. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>\';
  29. }
  30. }
  31. }
  32. function add_image_form() {
  33. // Multiple filepaths for image form
  34. var filepaths = document.getElementById("filepaths");
  35. if (document.getElementById("filepath_"+counter_image)) {
  36. counter_image = counter_image + 1;
  37. } else {
  38. counter_image = counter_image;
  39. }
  40. var elem1 = document.createElement("div");
  41. elem1.setAttribute("id","filepath_"+counter_image);
  42. filepaths.appendChild(elem1);
  43. id_elem1 = "filepath_"+counter_image;
  44. id_elem1 = "\'"+id_elem1+"\'";
  45. document.getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\" size=\"20\" />&nbsp;<a href=\"javascript:remove_image_form("+id_elem1+")\"><img src=\"'.api_get_path(WEB_CODE_PATH).'img/delete.gif\"></a>";
  46. if (filepaths.childNodes.length == 3) {
  47. var link_attach = document.getElementById("link-more-attach");
  48. if (link_attach) {
  49. link_attach.innerHTML="";
  50. }
  51. }
  52. }
  53. function show_icon_edit(element_html) {
  54. ident="#edit_image";
  55. $(ident).show();
  56. }
  57. function hide_icon_edit(element_html) {
  58. ident="#edit_image";
  59. $(ident).hide();
  60. }
  61. </script>';
  62. $this_section = SECTION_SOCIAL;
  63. $interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('Social'));
  64. $interbreadcrumb[] = array('url' => 'groups.php','name' => get_lang('Groups'));
  65. $interbreadcrumb[] = array('url' => '#','name' => get_lang('Thread'));
  66. api_block_anonymous_users();
  67. $group_id = intval($_GET['id']);
  68. $topic_id = intval($_GET['topic_id']);
  69. //todo @this validation could be in a function in group_portal_manager
  70. if (empty($group_id)) {
  71. api_not_allowed(true);
  72. } else {
  73. $group_info = GroupPortalManager::get_group_data($group_id);
  74. if (empty($group_info)) {
  75. api_not_allowed(true);
  76. }
  77. $is_member = GroupPortalManager::is_group_member($group_id);
  78. if ($group_info['visibility'] == GROUP_PERMISSION_CLOSED && !$is_member ) {
  79. api_not_allowed(true);
  80. }
  81. }
  82. Display::display_header($tool_name, 'Groups');
  83. // save message group
  84. if (isset($_POST['token']) && $_POST['token'] === $_SESSION['sec_token']) {
  85. if (isset($_POST['action'])) {
  86. $title = isset($_POST['title']) ? $_POST['title'] : null;
  87. $content = $_POST['content'];
  88. $group_id = intval($_POST['group_id']);
  89. $parent_id = intval($_POST['parent_id']);
  90. if ($_POST['action'] == 'reply_message_group') {
  91. $title = cut($content, 50);
  92. }
  93. if ($_POST['action'] == 'edit_message_group') {
  94. $edit_message_id = intval($_POST['message_id']);
  95. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id, $edit_message_id);
  96. } else {
  97. if ($_POST['action'] == 'add_message_group' && !$is_member) {
  98. api_not_allowed();
  99. }
  100. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id);
  101. }
  102. // display error messages
  103. if (is_string($res)) {
  104. Display::display_error_message($res);
  105. }
  106. if (!empty($res)) {
  107. $groups_user = GroupPortalManager::get_users_by_group($group_id);
  108. $group_info = GroupPortalManager::get_group_data($group_id);
  109. $admin_user_info = api_get_user_info(1);
  110. $sender_name = api_get_person_name($admin_user_info['firstName'], $admin_user_info['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
  111. $sender_email = $admin_user_info['mail'];
  112. $subject = sprintf(get_lang('ThereIsANewMessageInTheGroupX'),$group_info['name']);
  113. $link = api_get_path(WEB_PATH).'main/social/groups.php?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
  114. $text_link = '<a href="'.$link.'">'.get_lang('ClickHereToSeeMessageGroup')."</a><br />\r\n<br />\r\n".get_lang('OrCopyPasteTheFollowingUrl')." <br />\r\n ".$link;
  115. $message = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $group_info['name'])."<br />$text_link";
  116. foreach ($groups_user as $group_user) {
  117. //if ($group_user == $current_user) continue;
  118. $group_user_info = api_get_user_info($group_user['user_id']);
  119. $recipient_name = api_get_person_name($group_user_info['firstName'], $group_user_info['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
  120. $recipient_email = $group_user_info['mail'];
  121. @api_mail_html($recipient_name, $recipient_email, stripslashes($subject), $message, $sender_name, $sender_email);
  122. }
  123. }
  124. $topic_id = intval($_GET['topic_id']);
  125. if ($_POST['action'] == 'add_message_group') {
  126. $topic_id = $res;
  127. }
  128. }
  129. }
  130. echo '<div id="social-content">';
  131. echo '<div id="social-content-left">';
  132. //this include the social menu div
  133. SocialManager::show_social_menu('member_list', $group_id);
  134. echo '</div>';
  135. echo '<div id="social-content-right">';
  136. //echo '<h4><a href="groups.php?id='.$group_id.'">'.$group_info['name'].'</a></h4>';
  137. if (!empty($show_message)){
  138. Display::display_confirmation_message($show_message);
  139. }
  140. $content = MessageManager::display_message_for_group($group_id, $topic_id, $is_member);
  141. echo $content;
  142. echo '</div>';
  143. echo '</div>';
  144. Display :: display_footer();