group_topics.php 7.3 KB

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