group_topics.php 6.6 KB

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