group_topics.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. *
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') != 'true') {
  12. api_not_allowed(true);
  13. }
  14. $group_id = intval($_GET['id']);
  15. $topic_id = isset($_GET['topic_id']) ? intval($_GET['topic_id']) : null;
  16. $message_id = isset($_GET['msg_id']) ? intval($_GET['msg_id']) : null;
  17. $usergroup = new UserGroup();
  18. $is_member = false;
  19. //todo @this validation could be in a function in group_portal_manager
  20. if (empty($group_id)) {
  21. api_not_allowed(true);
  22. } else {
  23. $group_info = $usergroup->get($group_id);
  24. if (empty($group_info)) {
  25. api_not_allowed(true);
  26. }
  27. $is_member = $usergroup->is_group_member($group_id);
  28. if ($group_info['visibility'] == GROUP_PERMISSION_CLOSED && !$is_member) {
  29. api_not_allowed(true);
  30. }
  31. }
  32. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
  33. $group_role = $usergroup->get_user_group_role(api_get_user_id(), $group_id);
  34. if (api_is_platform_admin() ||
  35. in_array($group_role, [GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR])
  36. ) {
  37. $usergroup->delete_topic($group_id, $topic_id);
  38. Display::addFlash(Display::return_message(get_lang('Deleted')));
  39. header("Location: group_view.php?id=$group_id");
  40. exit;
  41. }
  42. }
  43. // My friends
  44. $friend_html = SocialManager::listMyFriendsBlock(
  45. $user_id
  46. );
  47. $content = null;
  48. $social_right_content = '';
  49. if (isset($_POST['action'])) {
  50. $title = isset($_POST['title']) ? $_POST['title'] : null;
  51. $content = $_POST['content'];
  52. $group_id = intval($_POST['group_id']);
  53. $parent_id = intval($_POST['parent_id']);
  54. if ($_POST['action'] == 'reply_message_group') {
  55. $title = cut($content, 50);
  56. }
  57. if ($_POST['action'] == 'edit_message_group') {
  58. $edit_message_id = intval($_POST['message_id']);
  59. $res = MessageManager::send_message(
  60. 0,
  61. $title,
  62. $content,
  63. $_FILES,
  64. [],
  65. $group_id,
  66. $parent_id,
  67. $edit_message_id,
  68. 0,
  69. $topic_id
  70. );
  71. } else {
  72. if ($_POST['action'] == 'add_message_group' && !$is_member) {
  73. api_not_allowed(true);
  74. }
  75. $res = MessageManager::send_message(
  76. 0,
  77. $title,
  78. $content,
  79. $_FILES,
  80. [],
  81. $group_id,
  82. $parent_id,
  83. 0,
  84. $topic_id
  85. );
  86. }
  87. // display error messages
  88. if (!$res) {
  89. Display::addFlash(Display::return_message(get_lang('Error'), 'error'));
  90. }
  91. $topic_id = isset($_GET['topic_id']) ? intval($_GET['topic_id']) : null;
  92. if ($_POST['action'] == 'add_message_group') {
  93. $topic_id = $res;
  94. }
  95. $message_id = $res;
  96. }
  97. $htmlHeadXtra[] = '<script>
  98. var counter_image = 1;
  99. function remove_image_form(id_elem1) {
  100. var elem1 = document.getElementById(id_elem1);
  101. elem1.parentNode.removeChild(elem1);
  102. counter_image--;
  103. var filepaths = document.getElementById("filepaths");
  104. if (filepaths.childNodes.length < 3) {
  105. var link_attach = document.getElementById("link-more-attach");
  106. if (link_attach) {
  107. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>\';
  108. }
  109. }
  110. }
  111. function add_image_form() {
  112. // Multiple filepaths for image form
  113. var filepaths = document.getElementById("filepaths");
  114. if (document.getElementById("filepath_"+counter_image)) {
  115. counter_image = counter_image + 1;
  116. } else {
  117. counter_image = counter_image;
  118. }
  119. var elem1 = document.createElement("div");
  120. elem1.setAttribute("id","filepath_"+counter_image);
  121. filepaths.appendChild(elem1);
  122. id_elem1 = "filepath_"+counter_image;
  123. id_elem1 = "\'"+id_elem1+"\'";
  124. 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=\"'.Display::returnIconPath('delete.png').'\"></a>";
  125. if (filepaths.childNodes.length == 3) {
  126. var link_attach = document.getElementById("link-more-attach");
  127. if (link_attach) {
  128. link_attach.innerHTML="";
  129. }
  130. }
  131. }
  132. $(function() {
  133. if ($("#msg_'.$message_id.'").length) {
  134. $("html,body").animate({
  135. scrollTop: $("#msg_'.$message_id.'").offset().top
  136. })
  137. }
  138. $(\'.group_message_popup\').on(\'click\', function() {
  139. var url = this.href;
  140. var dialog = $("#dialog");
  141. if ($("#dialog").length == 0) {
  142. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  143. }
  144. // load remote content
  145. dialog.load(
  146. url,
  147. {},
  148. function(responseText, textStatus, XMLHttpRequest) {
  149. dialog.dialog({
  150. modal : true,
  151. width : 520,
  152. height : 400,
  153. });
  154. });
  155. //prevent the browser to follow the link
  156. return false;
  157. });
  158. });
  159. </script>';
  160. $this_section = SECTION_SOCIAL;
  161. $interbreadcrumb[] = ['url' => 'groups.php', 'name' => get_lang('Groups')];
  162. $interbreadcrumb[] = ['url' => 'group_view.php?id='.$group_id, 'name' => Security::remove_XSS($group_info['name'])];
  163. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Discussions')];
  164. $social_left_content = SocialManager::show_social_menu('member_list', $group_id);
  165. $show_message = null;
  166. if (!empty($show_message)) {
  167. $social_right_content .= Display::return_message($show_message, 'confirmation');
  168. }
  169. $group_message = MessageManager::display_message_for_group(
  170. $group_id,
  171. $topic_id,
  172. $is_member,
  173. $message_id
  174. );
  175. $social_menu_block = SocialManager::show_social_menu('member_list', $group_id);
  176. $tpl = new Template(null);
  177. $tpl->setHelp('Groups');
  178. // Block Social Avatar
  179. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'groups', $group_id);
  180. $tpl->assign('social_menu_block', $social_menu_block);
  181. $tpl->assign('social_friend_block', $friend_html);
  182. $tpl->assign('group_message', $group_message);
  183. $tpl->assign('social_right_content', $social_right_content);
  184. $social_layout = $tpl->get_template('social/groups_topics.tpl');
  185. $tpl->display($social_layout);