group_topics.php 6.5 KB

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