group_topics.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
  32. $group_role = GroupPortalManager::get_user_group_role(
  33. api_get_user_id(),
  34. $group_id
  35. );
  36. if (api_is_platform_admin() || in_array(
  37. $group_role,
  38. array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR)
  39. )
  40. ) {
  41. GroupPortalManager::delete_topic($group_id, $topic_id);
  42. header(
  43. "Location: groups.php?id=$group_id&action=show_message&msg=topic_deleted"
  44. );
  45. }
  46. }
  47. // save message group
  48. if (isset($_POST['token']) && $_POST['token'] === $_SESSION['sec_token']) {
  49. if (isset($_POST['action'])) {
  50. $title = isset($_POST['title']) ? $_POST['title'] : null;
  51. $content = $_POST['content'];
  52. $group_id = intval($_POST['group_id']);
  53. $parent_id = intval($_POST['parent_id']);
  54. if ($_POST['action'] == 'reply_message_group') {
  55. $title = cut($content, 50);
  56. }
  57. if ($_POST['action'] == 'edit_message_group') {
  58. $edit_message_id = intval($_POST['message_id']);
  59. $res = MessageManager::send_message(
  60. 0,
  61. $title,
  62. $content,
  63. $_FILES,
  64. '',
  65. $group_id,
  66. $parent_id,
  67. $edit_message_id,
  68. 0,
  69. $topic_id
  70. );
  71. } else {
  72. if ($_POST['action'] == 'add_message_group' && !$is_member) {
  73. api_not_allowed();
  74. }
  75. $res = MessageManager::send_message(
  76. 0,
  77. $title,
  78. $content,
  79. $_FILES,
  80. '',
  81. $group_id,
  82. $parent_id,
  83. 0,
  84. $topic_id
  85. );
  86. }
  87. // display error messages
  88. if (!$res) {
  89. $social_right_content .= Display::return_message(
  90. get_lang('Error'),
  91. 'error'
  92. );
  93. }
  94. $topic_id = intval($_GET['topic_id']);
  95. if ($_POST['action'] == 'add_message_group') {
  96. $topic_id = $res;
  97. }
  98. $message_id = $res;
  99. }
  100. }
  101. $htmlHeadXtra[] = '<script type="text/javascript">
  102. var counter_image = 1;
  103. function remove_image_form(id_elem1) {
  104. var elem1 = document.getElementById(id_elem1);
  105. elem1.parentNode.removeChild(elem1);
  106. counter_image--;
  107. var filepaths = document.getElementById("filepaths");
  108. if (filepaths.childNodes.length < 3) {
  109. var link_attach = document.getElementById("link-more-attach");
  110. if (link_attach) {
  111. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">' . get_lang(
  112. 'AddOneMoreFile'
  113. ) . '</a>\';
  114. }
  115. }
  116. }
  117. function add_image_form() {
  118. // Multiple filepaths for image form
  119. var filepaths = document.getElementById("filepaths");
  120. if (document.getElementById("filepath_"+counter_image)) {
  121. counter_image = counter_image + 1;
  122. } else {
  123. counter_image = counter_image;
  124. }
  125. var elem1 = document.createElement("div");
  126. elem1.setAttribute("id","filepath_"+counter_image);
  127. filepaths.appendChild(elem1);
  128. id_elem1 = "filepath_"+counter_image;
  129. id_elem1 = "\'"+id_elem1+"\'";
  130. 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(
  131. WEB_CODE_PATH
  132. ) . 'img/delete.gif\"></a>";
  133. if (filepaths.childNodes.length == 3) {
  134. var link_attach = document.getElementById("link-more-attach");
  135. if (link_attach) {
  136. link_attach.innerHTML="";
  137. }
  138. }
  139. }
  140. function show_icon_edit(element_html) {
  141. ident="#edit_image";
  142. $(ident).show();
  143. }
  144. function hide_icon_edit(element_html) {
  145. ident="#edit_image";
  146. $(ident).hide();
  147. }
  148. function validate_text_empty(str,msg) {
  149. var str = str.replace(/^\s*|\s*$/g,"");
  150. if (str.length == 0) {
  151. alert(msg);
  152. return true;
  153. }
  154. }
  155. $(document).ready(function() {
  156. if ( $("#msg_' . $message_id . '").length) {
  157. $("html,body").animate({
  158. scrollTop: $("#msg_' . $message_id . '").offset().top
  159. })
  160. }
  161. $(\'.group_message_popup\').live(\'click\', function() {
  162. var url = this.href;
  163. var dialog = $("#dialog");
  164. if ($("#dialog").length == 0) {
  165. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  166. }
  167. // load remote content
  168. dialog.load(
  169. url,
  170. {},
  171. function(responseText, textStatus, XMLHttpRequest) {
  172. dialog.dialog({
  173. modal : true,
  174. width : 520,
  175. height : 400,
  176. });
  177. });
  178. //prevent the browser to follow the link
  179. return false;
  180. });
  181. });
  182. </script>';
  183. $this_section = SECTION_SOCIAL;
  184. $interbreadcrumb[] = array('url' => 'home.php', 'name' => get_lang('Social'));
  185. $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
  186. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Thread'));
  187. $social_right_content = '<div class="breadcrumb">
  188. <a href="groups.php?id=' . $group_id . '">' . Security::remove_XSS(
  189. $group_info['name'],
  190. STUDENT,
  191. true
  192. ) . '</a>
  193. <span class="divider">/</span>
  194. <a href="groups.php?id=' . $group_id . '#tabs_2">' . get_lang(
  195. 'Discussions'
  196. ) . '</a>
  197. </div> ';
  198. $social_avatar_block = SocialManager::show_social_avatar_block(
  199. 'member_list',
  200. $group_id
  201. );
  202. $social_menu_block = SocialManager::show_social_menu('member_list', $group_id);
  203. if (!empty($show_message)) {
  204. $social_right_content .= Display::return_message(
  205. $show_message,
  206. 'confirmation'
  207. );
  208. }
  209. $social_right_content .= MessageManager::display_message_for_group(
  210. $group_id,
  211. $topic_id,
  212. $is_member,
  213. $message_id
  214. );
  215. $social_right_content = '<div class="span9">' . $social_right_content . '</div>';
  216. $tpl = new Template($tool_name);
  217. $tpl->set_help('Groups');
  218. $tpl->assign('social_avatar_block', $social_avatar_block);
  219. $tpl->assign('social_menu_block', $social_menu_block);
  220. $tpl->assign('social_right_content', $social_right_content);
  221. $tpl->assign('actions', $actions);
  222. $tpl->assign('message', $show_message);
  223. $tpl->assign('content', $content);
  224. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  225. $tpl->display($social_layout);