group_topics.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 '../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. $content = null;
  43. $social_right_content = '';
  44. if (isset($_POST['action'])) {
  45. $title = isset($_POST['title']) ? $_POST['title'] : null;
  46. $content = $_POST['content'];
  47. $group_id = intval($_POST['group_id']);
  48. $parent_id = intval($_POST['parent_id']);
  49. if ($_POST['action'] == 'reply_message_group') {
  50. $title = cut($content, 50);
  51. }
  52. if ($_POST['action'] == 'edit_message_group') {
  53. $edit_message_id = intval($_POST['message_id']);
  54. $res = MessageManager::send_message(
  55. 0,
  56. $title,
  57. $content,
  58. $_FILES,
  59. [],
  60. $group_id,
  61. $parent_id,
  62. $edit_message_id,
  63. 0,
  64. $topic_id
  65. );
  66. } else {
  67. if ($_POST['action'] == 'add_message_group' && !$is_member) {
  68. api_not_allowed();
  69. }
  70. $res = MessageManager::send_message(
  71. 0,
  72. $title,
  73. $content,
  74. $_FILES,
  75. [],
  76. $group_id,
  77. $parent_id,
  78. 0,
  79. $topic_id
  80. );
  81. }
  82. // display error messages
  83. if (!$res) {
  84. $social_right_content .= Display::return_message(get_lang('Error'),'error');
  85. }
  86. $topic_id = isset($_GET['topic_id']) ? intval($_GET['topic_id']) : null;
  87. if ($_POST['action'] == 'add_message_group') {
  88. $topic_id = $res;
  89. }
  90. $message_id = $res;
  91. }
  92. $htmlHeadXtra[] = '<script>
  93. var counter_image = 1;
  94. function remove_image_form(id_elem1) {
  95. var elem1 = document.getElementById(id_elem1);
  96. elem1.parentNode.removeChild(elem1);
  97. counter_image--;
  98. var filepaths = document.getElementById("filepaths");
  99. if (filepaths.childNodes.length < 3) {
  100. var link_attach = document.getElementById("link-more-attach");
  101. if (link_attach) {
  102. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>\';
  103. }
  104. }
  105. }
  106. function add_image_form() {
  107. // Multiple filepaths for image form
  108. var filepaths = document.getElementById("filepaths");
  109. if (document.getElementById("filepath_"+counter_image)) {
  110. counter_image = counter_image + 1;
  111. } else {
  112. counter_image = counter_image;
  113. }
  114. var elem1 = document.createElement("div");
  115. elem1.setAttribute("id","filepath_"+counter_image);
  116. filepaths.appendChild(elem1);
  117. id_elem1 = "filepath_"+counter_image;
  118. id_elem1 = "\'"+id_elem1+"\'";
  119. 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.gif').'\"></a>";
  120. if (filepaths.childNodes.length == 3) {
  121. var link_attach = document.getElementById("link-more-attach");
  122. if (link_attach) {
  123. link_attach.innerHTML="";
  124. }
  125. }
  126. }
  127. function show_icon_edit(element_html) {
  128. ident="#edit_image";
  129. $(ident).show();
  130. }
  131. function hide_icon_edit(element_html) {
  132. ident="#edit_image";
  133. $(ident).hide();
  134. }
  135. function validate_text_empty(str,msg) {
  136. var str = str.replace(/^\s*|\s*$/g,"");
  137. if (str.length == 0) {
  138. alert(msg);
  139. return true;
  140. }
  141. }
  142. $(document).ready(function() {
  143. if ($("#msg_'.$message_id.'").length) {
  144. $("html,body").animate({
  145. scrollTop: $("#msg_'.$message_id.'").offset().top
  146. })
  147. }
  148. $(\'.group_message_popup\').on(\'click\', function() {
  149. var url = this.href;
  150. var dialog = $("#dialog");
  151. if ($("#dialog").length == 0) {
  152. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  153. }
  154. // load remote content
  155. dialog.load(
  156. url,
  157. {},
  158. function(responseText, textStatus, XMLHttpRequest) {
  159. dialog.dialog({
  160. modal : true,
  161. width : 520,
  162. height : 400,
  163. });
  164. });
  165. //prevent the browser to follow the link
  166. return false;
  167. });
  168. });
  169. </script>';
  170. $this_section = SECTION_SOCIAL;
  171. $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
  172. $interbreadcrumb[] = array('url' => 'group_view.php?id='.$group_id, 'name' => Security::remove_XSS($group_info['name']));
  173. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Discussions'));
  174. $social_left_content = SocialManager::show_social_menu('member_list', $group_id);
  175. $show_message = null;
  176. if (!empty($show_message)) {
  177. $social_right_content .= Display::return_message($show_message, 'confirmation');
  178. }
  179. $social_right_content .= MessageManager::display_message_for_group(
  180. $group_id,
  181. $topic_id,
  182. $is_member,
  183. $message_id
  184. );
  185. $social_menu_block = SocialManager::show_social_menu('member_list', $group_id);
  186. $tpl = new Template(null);
  187. $tpl->setHelp('Groups');
  188. // Block Social Avatar
  189. SocialManager::setSocialUserBlock($tpl, $user_id, 'groups', $group_id);
  190. $tpl->assign('social_menu_block', $social_menu_block);
  191. $tpl->assign('social_right_content', $social_right_content);
  192. $tpl->assign('content', $content);
  193. $social_layout = $tpl->get_template('social/home.tpl');
  194. $tpl->display($social_layout);