group_topics.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  15. $group_id = intval($_GET['id']);
  16. $topic_id = intval($_GET['topic_id']);
  17. $message_id = intval($_GET['msg_id']);
  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 = GroupPortalManager::get_group_data($group_id);
  23. if (empty($group_info)) {
  24. api_not_allowed(true);
  25. }
  26. $is_member = GroupPortalManager::is_group_member($group_id);
  27. if ($group_info['visibility'] == GROUP_PERMISSION_CLOSED && !$is_member ) {
  28. api_not_allowed(true);
  29. }
  30. }
  31. // save message group
  32. if (isset($_POST['token']) && $_POST['token'] === $_SESSION['sec_token']) {
  33. if (isset($_POST['action'])) {
  34. $title = isset($_POST['title']) ? $_POST['title'] : null;
  35. $content = $_POST['content'];
  36. $group_id = intval($_POST['group_id']);
  37. $parent_id = intval($_POST['parent_id']);
  38. if ($_POST['action'] == 'reply_message_group') {
  39. $title = cut($content, 50);
  40. }
  41. if ($_POST['action'] == 'edit_message_group') {
  42. $edit_message_id = intval($_POST['message_id']);
  43. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id, $edit_message_id, 0, $topic_id);
  44. } else {
  45. if ($_POST['action'] == 'add_message_group' && !$is_member) {
  46. api_not_allowed();
  47. }
  48. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id, 0, $topic_id);
  49. }
  50. // display error messages
  51. if (!$res) {
  52. Display::display_error_message(get_lang('Error'));
  53. }
  54. $topic_id = intval($_GET['topic_id']);
  55. if ($_POST['action'] == 'add_message_group') {
  56. $topic_id = $res;
  57. }
  58. $message_id = $res;
  59. }
  60. }
  61. $htmlHeadXtra[] = api_get_jquery_ui_js();
  62. $htmlHeadXtra[] = '<script type="text/javascript">
  63. var counter_image = 1;
  64. function remove_image_form(id_elem1) {
  65. var elem1 = document.getElementById(id_elem1);
  66. elem1.parentNode.removeChild(elem1);
  67. counter_image--;
  68. var filepaths = document.getElementById("filepaths");
  69. if (filepaths.childNodes.length < 3) {
  70. var link_attach = document.getElementById("link-more-attach");
  71. if (link_attach) {
  72. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>\';
  73. }
  74. }
  75. }
  76. function add_image_form() {
  77. // Multiple filepaths for image form
  78. var filepaths = document.getElementById("filepaths");
  79. if (document.getElementById("filepath_"+counter_image)) {
  80. counter_image = counter_image + 1;
  81. } else {
  82. counter_image = counter_image;
  83. }
  84. var elem1 = document.createElement("div");
  85. elem1.setAttribute("id","filepath_"+counter_image);
  86. filepaths.appendChild(elem1);
  87. id_elem1 = "filepath_"+counter_image;
  88. id_elem1 = "\'"+id_elem1+"\'";
  89. 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>";
  90. if (filepaths.childNodes.length == 3) {
  91. var link_attach = document.getElementById("link-more-attach");
  92. if (link_attach) {
  93. link_attach.innerHTML="";
  94. }
  95. }
  96. }
  97. function show_icon_edit(element_html) {
  98. ident="#edit_image";
  99. $(ident).show();
  100. }
  101. function hide_icon_edit(element_html) {
  102. ident="#edit_image";
  103. $(ident).hide();
  104. }
  105. function validate_text_empty(str,msg) {
  106. var str = str.replace(/^\s*|\s*$/g,"");
  107. if (str.length == 0) {
  108. alert(msg);
  109. return true;
  110. }
  111. }
  112. $(document).ready(function() {
  113. if ( $("#msg_'.$message_id.'").length) {
  114. $("html,body").animate({
  115. scrollTop: $("#msg_'.$message_id.'").offset().top
  116. })
  117. }
  118. $(\'.group_message_popup\').live(\'click\', function() {
  119. var url = this.href;
  120. var dialog = $("#dialog");
  121. if ($("#dialog").length == 0) {
  122. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  123. }
  124. // load remote content
  125. dialog.load(
  126. url,
  127. {},
  128. function(responseText, textStatus, XMLHttpRequest) {
  129. dialog.dialog({
  130. modal : true,
  131. width : 520,
  132. height : 400,
  133. });
  134. });
  135. //prevent the browser to follow the link
  136. return false;
  137. });
  138. });
  139. </script>';
  140. $this_section = SECTION_SOCIAL;
  141. $interbreadcrumb[]= array ('url' =>'home.php', 'name' => get_lang('Social'));
  142. $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
  143. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Thread'));
  144. Display::display_header($tool_name, 'Groups');
  145. echo '<div id="social-content">';
  146. echo '<div id="social-content-left">';
  147. //this include the social menu div
  148. SocialManager::show_social_menu('member_list', $group_id);
  149. echo '</div>';
  150. echo '<div id="social-content-right">';
  151. echo '<h2><a href="groups.php?id='.$group_id.'">'.Security::remove_XSS($group_info['name'], STUDENT, true).'</a> &raquo; <a href="groups.php?id='.$group_id.'#tabs_2">'.get_lang('Discussions').'</a></h2>';
  152. if (!empty($show_message)){
  153. Display::display_confirmation_message($show_message);
  154. }
  155. $content = MessageManager::display_message_for_group($group_id, $topic_id, $is_member, $message_id);
  156. echo $content;
  157. echo '</div>';
  158. echo '</div>';
  159. Display :: display_footer();