groups.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. * @package dokeos.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. $cidReset=true;
  8. $language_file = array('userInfo');
  9. require_once '../inc/global.inc.php';
  10. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  11. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  13. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'text.lib.php';
  15. api_block_anonymous_users();
  16. $this_section = SECTION_SOCIAL;
  17. $htmlHeadXtra[] = '<script type="text/javascript" src="/main/inc/lib/javascript/jquery.js"></script>';
  18. $htmlHeadXtra[] = '<script type="text/javascript" src="/main/inc/lib/javascript/thickbox.js"></script>';
  19. $htmlHeadXtra[] = '<link rel="stylesheet" href="/main/inc/lib/javascript/thickbox.css" type="text/css" media="projection, screen">';
  20. $htmlHeadXtra[] = '<script type="text/javascript">
  21. var counter_image = 1;
  22. function remove_image_form(id_elem1) {
  23. var elem1 = document.getElementById(id_elem1);
  24. elem1.parentNode.removeChild(elem1);
  25. counter_image--;
  26. var filepaths = document.getElementById("filepaths");
  27. if (filepaths.childNodes.length < 3) {
  28. var link_attach = document.getElementById("link-more-attach");
  29. if (link_attach) {
  30. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>&nbsp;('.get_lang('MaximunFileSizeXMB').')\';
  31. }
  32. }
  33. }
  34. function add_image_form() {
  35. // Multiple filepaths for image form
  36. var filepaths = document.getElementById("filepaths");
  37. if (document.getElementById("filepath_"+counter_image)) {
  38. counter_image = counter_image + 1;
  39. } else {
  40. counter_image = counter_image;
  41. }
  42. var elem1 = document.createElement("div");
  43. elem1.setAttribute("id","filepath_"+counter_image);
  44. filepaths.appendChild(elem1);
  45. id_elem1 = "filepath_"+counter_image;
  46. id_elem1 = "\'"+id_elem1+"\'";
  47. 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>";
  48. if (filepaths.childNodes.length == 3) {
  49. var link_attach = document.getElementById("link-more-attach");
  50. if (link_attach) {
  51. link_attach.innerHTML="";
  52. }
  53. }
  54. }
  55. </script>';
  56. $interbreadcrumb[]= array ('url' =>'profile.php','name' => get_lang('Social'));
  57. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Groups'));
  58. Display :: display_header($tool_name, 'Groups');
  59. //show the action menu
  60. SocialManager::show_social_menu();
  61. echo '<div class="actions-title">';
  62. echo get_lang('Groups');
  63. echo '</div>';
  64. // save message group
  65. if (isset($_POST['token']) && $_POST['token'] == $_SESSION['sec_token']) {
  66. if (isset($_POST['action']) && $_POST['action']=='send_message_group') {
  67. $title = $_POST['title'];
  68. $content = $_POST['content'];
  69. $group_id = $_POST['group_id'];
  70. $parent_id = $_POST['parent_id'];
  71. $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id);
  72. if (is_string($res)) {
  73. Display::display_error_message($res);
  74. }
  75. Security::clear_token();
  76. }
  77. } else {
  78. $tok = Security::get_token();
  79. }
  80. // getting group information
  81. $group_id = intval($_GET['id']);
  82. if ($group_id != 0 ) {
  83. //Loading group information
  84. if (isset($_GET['status']) && $_GET['status']=='sent') {
  85. Display::display_confirmation_message(get_lang('MessageHasBeenSent'), false);
  86. }
  87. if (isset($_GET['action']) && $_GET['action']=='leave') {
  88. $user_leaved = intval($_GET['u']);
  89. //I can "leave me myself"
  90. if (api_get_user_id() == $user_leaved) {
  91. GroupPortalManager::delete_user_rel_group($user_leaved, $group_id);
  92. }
  93. }
  94. // add a user to a group if its open
  95. if (isset($_GET['action']) && $_GET['action']=='join') {
  96. // we add a user only if is a open group
  97. $user_join = intval($_GET['u']);
  98. if (api_get_user_id() == $user_join && !empty($group_id)) {
  99. $group_info = GroupPortalManager::get_group_data($group_id);
  100. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  101. GroupPortalManager::add_user_to_group($user_join, $group_id);
  102. } else {
  103. GroupPortalManager::add_user_to_group($user_join, $group_id, GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER);
  104. }
  105. }
  106. }
  107. //-- Shows left column
  108. echo GroupPortalManager::show_group_column_information($group_id, api_get_user_id());
  109. //---
  110. //-- Show message groups
  111. echo '<div id="layout_right" style="margin-left: 282px;">';
  112. echo '<div class="messages">';
  113. if (GroupPortalManager::is_group_member($group_id)) {
  114. $content = MessageManager::display_messages_for_group($group_id);
  115. if (!empty($content)) {
  116. echo $content;
  117. } else {
  118. echo get_lang('YouShouldCreateATopic');
  119. }
  120. } else {
  121. echo get_lang('YouShouldJoinTheGroup');
  122. }
  123. echo '</div>'; // end layout messages
  124. echo '</div>'; // end layout right
  125. } else {
  126. // My groups -----
  127. $results = GroupPortalManager::get_groups_by_user(api_get_user_id(), 0, true);
  128. $groups = array();
  129. if (is_array($results) && count($results) > 0) {
  130. foreach ($results as $result) {
  131. //cutting text
  132. //$result['name'] = cut($result['name'],150);
  133. //$result['description'] = cut($result['description'],180);
  134. $id = $result['id'];
  135. $url_open = '<a href="groups.php?id='.$id.'">';
  136. $url_close = '</a>';
  137. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  138. $result['name'] .= Display::return_icon('admin_star.png', get_lang('Admin'));
  139. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  140. $result['name'] .= Display::return_icon('moderator_star.png', get_lang('Moderator'));
  141. }
  142. $groups[]= array($url_open.$result['picture_uri'].$url_close, $url_open.$result['name'].$url_close, cut($result['description'],180,true));
  143. }
  144. }
  145. echo '<br/>';
  146. // Everybody can create groups
  147. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  148. echo '<a href="group_add.php">'.get_lang('CreateAgroup').'</a>';
  149. } else {
  150. // Only admins and teachers can create groups
  151. if (api_is_allowed_to_edit(null,true)) {
  152. echo '<a href="group_add.php">'.get_lang('CreateAgroup').'</a>';
  153. }
  154. }
  155. echo '<h1>'.get_lang('MyGroups').'</h1>';
  156. if (count($groups) > 0) {
  157. Display::display_sortable_grid('mygroups', array(), $groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
  158. }
  159. // Newest groups --------
  160. $results = GroupPortalManager::get_groups_by_age();
  161. $groups = array();
  162. foreach ($results as $result) {
  163. $id = $result['id'];
  164. $url_open = '<a href="groups.php?id='.$id.'">';
  165. $url_close = '</a>';
  166. $groups[]= array($url_open.$result['picture_uri'].$url_close, $url_open.$result['name'].$url_close, cut($result['description'],180,true));
  167. }
  168. if (count($groups) > 0) {
  169. echo '<h1>'.get_lang('Newest').'</h1>';
  170. Display::display_sortable_grid('newest', array(), $groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
  171. }
  172. // Pop groups -----
  173. $results = GroupPortalManager::get_groups_by_popularity();
  174. $groups = array();
  175. foreach ($results as $result) {
  176. $id = $result['id'];
  177. $url_open = '<a href="groups.php?id='.$id.'">';
  178. $url_close = '</a>';
  179. if ($result['count'] == 1 ) {
  180. $result['count'] = $result['count'].' '.get_lang('Member');
  181. } else {
  182. $result['count'] = $result['count'].' '.get_lang('Members');
  183. }
  184. $groups[]= array($url_open.$result['picture_uri'].$url_close, $url_open.$result['name'].$url_close,$result['count'],cut($result['description'],180,true));
  185. }
  186. if (count($groups) > 0) {
  187. echo '<h1>'.get_lang('Popular').'</h1>';
  188. Display::display_sortable_grid('popular', array(), $groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,true,true));
  189. }
  190. }
  191. Display :: display_footer();
  192. ?>