group_topics.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. $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. //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() || in_array($group_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) {
  34. $usergroup->delete_topic($group_id, $topic_id);
  35. header("Location: groups.php?id=$group_id&action=show_message&msg=topic_deleted");
  36. exit;
  37. }
  38. }
  39. $content = null;
  40. // save message group
  41. $currentToken = Security::getCurrentToken();
  42. if (isset($_POST['action'])) {
  43. $title = isset($_POST['title']) ? $_POST['title'] : null;
  44. $content = $_POST['content'];
  45. $group_id = intval($_POST['group_id']);
  46. $parent_id = intval($_POST['parent_id']);
  47. if ($_POST['action'] == 'reply_message_group') {
  48. $title = Text::cut($content, 50);
  49. }
  50. if ($_POST['action'] == 'edit_message_group') {
  51. $edit_message_id = intval($_POST['message_id']);
  52. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id, $edit_message_id, 0, $topic_id);
  53. } else {
  54. if ($_POST['action'] == 'add_message_group' && !$is_member) {
  55. api_not_allowed();
  56. }
  57. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id, 0, $topic_id);
  58. }
  59. // display error messages
  60. if (!$res) {
  61. $social_right_content .= Display::return_message(get_lang('Error'),'error');
  62. }
  63. $topic_id = isset($_GET['topic_id']) ? intval($_GET['topic_id']) : null;
  64. if ($_POST['action'] == 'add_message_group') {
  65. $topic_id = $res;
  66. }
  67. $message_id = $res;
  68. }
  69. $htmlHeadXtra[] = '<script>
  70. var counter_image = 1;
  71. function remove_image_form(id_elem1) {
  72. var elem1 = document.getElementById(id_elem1);
  73. elem1.parentNode.removeChild(elem1);
  74. counter_image--;
  75. var filepaths = document.getElementById("filepaths");
  76. if (filepaths.childNodes.length < 3) {
  77. var link_attach = document.getElementById("link-more-attach");
  78. if (link_attach) {
  79. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>\';
  80. }
  81. }
  82. }
  83. function add_image_form() {
  84. // Multiple filepaths for image form
  85. var filepaths = document.getElementById("filepaths");
  86. if (document.getElementById("filepath_"+counter_image)) {
  87. counter_image = counter_image + 1;
  88. } else {
  89. counter_image = counter_image;
  90. }
  91. var elem1 = document.createElement("div");
  92. elem1.setAttribute("id","filepath_"+counter_image);
  93. filepaths.appendChild(elem1);
  94. id_elem1 = "filepath_"+counter_image;
  95. id_elem1 = "\'"+id_elem1+"\'";
  96. 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_IMG_PATH).'delete.gif\"></a>";
  97. if (filepaths.childNodes.length == 3) {
  98. var link_attach = document.getElementById("link-more-attach");
  99. if (link_attach) {
  100. link_attach.innerHTML="";
  101. }
  102. }
  103. }
  104. function show_icon_edit(element_html) {
  105. ident="#edit_image";
  106. $(ident).show();
  107. }
  108. function hide_icon_edit(element_html) {
  109. ident="#edit_image";
  110. $(ident).hide();
  111. }
  112. function validate_text_empty(str,msg) {
  113. var str = str.replace(/^\s*|\s*$/g,"");
  114. if (str.length == 0) {
  115. alert(msg);
  116. return true;
  117. }
  118. }
  119. $(document).ready(function() {
  120. if ( $("#msg_'.$message_id.'").length) {
  121. $("html,body").animate({
  122. scrollTop: $("#msg_'.$message_id.'").offset().top
  123. })
  124. }
  125. $(\'.group_message_popup\').on(\'click\', function() {
  126. var url = this.href;
  127. var dialog = $("#dialog");
  128. if ($("#dialog").length == 0) {
  129. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  130. }
  131. // load remote content
  132. dialog.load(
  133. url,
  134. {},
  135. function(responseText, textStatus, XMLHttpRequest) {
  136. dialog.dialog({
  137. modal : true,
  138. width : 520,
  139. height : 400,
  140. });
  141. });
  142. //prevent the browser to follow the link
  143. return false;
  144. });
  145. });
  146. </script>';
  147. $this_section = SECTION_SOCIAL;
  148. $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
  149. $interbreadcrumb[] = array('url' => 'groups.php?id='.$group_id, 'name' => Security::remove_XSS($group_info['name']));
  150. //$interbreadcrumb[] = array('url' => 'groups.php?id='.$group_id.'#tabs_2', 'name' => get_lang('Discussions'));
  151. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Discussions'));
  152. $social_left_content = SocialManager::show_social_menu('member_list', $group_id);
  153. $show_message = null;
  154. if (!empty($show_message)) {
  155. $social_right_content .= Display::return_message($show_message, 'confirmation');
  156. }
  157. $social_right_content .= MessageManager::display_message_for_group($group_id, $topic_id, $is_member, $message_id);
  158. $social_right_content = '<div class="span9">'.$social_right_content.'</div>';
  159. $app['title'] = get_lang('Social');
  160. $tpl = $app['template'];
  161. $tpl->setHelp('Groups');
  162. $tpl->assign('message', $show_message);
  163. $tpl->assign('content', $social_right_content);