groups.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. $language_file = array('userInfo');
  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. $join_url = '';
  15. $this_section = SECTION_SOCIAL;
  16. $allowed_views = array('mygroups','newest','pop');
  17. $content = null;
  18. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  19. if ($_GET['view'] == 'mygroups') {
  20. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  21. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('MyGroups'));
  22. } else if ( $_GET['view'] == 'newest') {
  23. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  24. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Newest'));
  25. } else {
  26. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  27. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Popular'));
  28. }
  29. } else {
  30. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  31. if (!isset($_GET['id'])) {
  32. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('GroupList'));
  33. }
  34. }
  35. // getting group information
  36. $relation_group_title = '';
  37. $my_group_role = 0;
  38. $usergroup = new UserGroup();
  39. $create_thread_link = '';
  40. $show_menu = 'browse_groups';
  41. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  42. $show_menu = $_GET['view'];
  43. }
  44. $social_right_content = null;
  45. // My groups
  46. $results = $usergroup->get_groups_by_user(api_get_user_id(), 0);
  47. $grid_my_groups = array();
  48. $my_group_list = array();
  49. if (is_array($results) && count($results) > 0) {
  50. foreach ($results as $result) {
  51. $id = $result['id'];
  52. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  53. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  54. $my_group_list[] = $id;
  55. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  56. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  57. $name .= ' '.Display::return_icon('social_group_admin.png', get_lang('Admin'), array('style'=>'vertical-align:middle'));
  58. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  59. $name .= ' '.Display::return_icon('social_group_moderator.png', get_lang('Moderator'), array('style'=>'vertical-align:middle'));
  60. }
  61. $url = '<a href="group_view.php?id='.$id.'">' . $name . '</a>';
  62. $count_users_group = count($usergroup->get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  63. if ($count_users_group == 1 ) {
  64. $count_users_group = $count_users_group.' '.get_lang('Member');
  65. } else {
  66. $count_users_group = $count_users_group.' '.get_lang('Members');
  67. }
  68. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  69. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  70. $members = Display::returnFontAwesomeIcon('user').$count_users_group;
  71. $html = '<div class="row">';
  72. $html .= '<div class="col-md-2">';
  73. $html .= $result['picture'];
  74. $html .= '</div>';
  75. $html .= '<div class="col-md-10">';
  76. $html .= '<div class="title-groups">';
  77. $html .= Display::tag('h5', $url);
  78. $html .= '</div>';
  79. $html .= '<div class="members-groups">' . $members . '</div>';
  80. if ($result['description'] != '') {
  81. $html .= '<div class="description-groups">' . cut($result['description'],100,true) . '</div>';
  82. } else {
  83. $html .= '';
  84. }
  85. $html .= '</div>';
  86. $html .= '</div>';
  87. $grid_item_2 = $html;
  88. $grid_my_groups[]= array($grid_item_2);
  89. }
  90. }
  91. // Newest groups
  92. $results = $usergroup->get_groups_by_age(4,false);
  93. $grid_newest_groups = array();
  94. foreach ($results as $result) {
  95. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  96. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  97. $id = $result['id'];
  98. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  99. $count_users_group = count($usergroup->get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  100. if ($count_users_group == 1 ) {
  101. $count_users_group = $count_users_group.' '.get_lang('Member');
  102. } else {
  103. $count_users_group = $count_users_group.' '.get_lang('Members');
  104. }
  105. $url = '<a href="group_view.php?id='.$id.'">' . $name . '</a>';
  106. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  107. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  108. $members = Display::returnFontAwesomeIcon('user').$count_users_group;
  109. $html = '<div class="row">';
  110. $html .= '<div class="col-md-2">';
  111. $html .= $result['picture'];
  112. $html .= '</div>';
  113. $html .= '<div class="col-md-10">';
  114. $html .= '<div class="title-groups">';
  115. $html .= Display::tag('h5', $url);
  116. $html .= '</div>';
  117. $html .= '<div class="members-groups">' . $members . '</div>';
  118. if ($result['description'] != '') {
  119. $html .= '<div class="description-groups">' . cut($result['description'],100,true) . '</div>';
  120. } else {
  121. $html .= '';
  122. }
  123. //Avoiding my groups
  124. if (!in_array($id,$my_group_list)) {
  125. $html .= '<a class="btn" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  126. }
  127. $html .= '<div class="group-actions" >'.$join_url.'</div>';
  128. $html .= '</div>';
  129. $html .= '</div>';
  130. $grid_item_2 = $html;
  131. $grid_newest_groups[]= array($grid_item_2);
  132. }
  133. // Pop groups
  134. $results = $usergroup->get_groups_by_popularity(4,false);
  135. $grid_pop_groups = array();
  136. if (is_array($results) && count($results) > 0) {
  137. foreach ($results as $result) {
  138. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  139. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  140. $id = $result['id'];
  141. $name = cut($result['name'],GROUP_TITLE_LENGTH,true);
  142. $count_users_group = count($usergroup->get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  143. if ($count_users_group == 1 ) {
  144. $count_users_group = $count_users_group.' '.get_lang('Member');
  145. } else {
  146. $count_users_group = $count_users_group.' '.get_lang('Members');
  147. }
  148. $url = '<a href="group_view.php?id='.$id.'">' . $name . '</a>';
  149. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  150. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  151. $html = '<div class="row">';
  152. $html .= '<div class="col-md-2">';
  153. $html .= $result['picture'];
  154. $html .= '</div>';
  155. $html .= '<div class="col-md-10">';
  156. $html .= '<div class="title-groups">';
  157. $html .= Display::tag('h5', $url);
  158. $html .= '</div>';
  159. $html .= '<div class="members-groups">' . $members . '</div>';
  160. if ($result['description'] != '') {
  161. $html .= '<div class="description-groups">' . cut($result['description'],100,true) . '</div>';
  162. } else {
  163. $html .= '';
  164. }
  165. //Avoiding my groups
  166. if (!in_array($id,$my_group_list)) {
  167. $html .= '<a class="btn" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  168. }
  169. $html .= '<div class="group-actions" >'.$join_url.'</div>';
  170. $html .= '</div>';
  171. $html .= '</div>';
  172. $grid_item_2 = $html;
  173. $grid_pop_groups[]= array($grid_item_2);
  174. }
  175. }
  176. // Display groups (newest, mygroups, pop)
  177. $query_vars = array();
  178. $newest_content = $popular_content = $my_group_content = null;
  179. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  180. $view_group = $_GET['view'];
  181. switch ($view_group) {
  182. case 'mygroups':
  183. if (count($grid_my_groups) > 0) {
  184. $my_group_content = Display::return_sortable_grid('mygroups', array(), $grid_my_groups, array('hide_navigation'=>true, 'per_page' => 2), $query_vars, false, array(true, true, true,false));
  185. }
  186. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  187. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  188. get_lang('CreateASocialGroup').'</a>';
  189. } else {
  190. if (api_is_allowed_to_edit(null,true)) {
  191. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  192. get_lang('CreateASocialGroup').'</a>';
  193. }
  194. }
  195. break;
  196. case 'newest':
  197. if (count($grid_newest_groups) > 0) {
  198. $newest_content = Display::return_sortable_grid('newest', array(), $grid_newest_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
  199. }
  200. break;
  201. default:
  202. if (count($grid_pop_groups) > 0) {
  203. $popular_content = Display::return_sortable_grid('popular', array(), $grid_pop_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,true,true));
  204. }
  205. break;
  206. }
  207. } else {
  208. $my_group_content = null;
  209. if (count($grid_my_groups) > 0) {
  210. $my_group_content = Display::return_sortable_grid('mygroups', array(), $grid_my_groups, array('hide_navigation'=>true, 'per_page' => 2), $query_vars, false, array(true, true, true,false));
  211. } else {
  212. $my_group_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  213. }
  214. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  215. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  216. get_lang('CreateASocialGroup').'</a>';
  217. } else {
  218. if (api_is_allowed_to_edit(null,true)) {
  219. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  220. }
  221. }
  222. if (count($grid_newest_groups) > 0) {
  223. $newest_content = Display::return_sortable_grid('mygroups', array(), $grid_newest_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
  224. } else {
  225. $newest_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  226. }
  227. if (count($grid_pop_groups) > 0) {
  228. $popular_content = Display::return_sortable_grid('mygroups', array(), $grid_pop_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,true,true));
  229. } else {
  230. $popular_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  231. }
  232. }
  233. if (!empty($create_group_item)) {
  234. $social_right_content .= Display::page_subheader($create_group_item);
  235. }
  236. $headers = array(get_lang('Newest'), get_lang('Popular'), get_lang('MyGroups'));
  237. $social_right_content .= Display::tabs($headers, array($newest_content, $popular_content, $my_group_content),'tab_browse');
  238. $show_message = null;
  239. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && isset($_REQUEST['msg']) && $_REQUEST['msg'] == 'topic_deleted') {
  240. $show_message = Display::return_message(get_lang('Deleted'), 'success');
  241. }
  242. $tpl = new Template(null);
  243. // Block Social Avatar
  244. SocialManager::setSocialUserBlock($tpl, $user_id, $show_menu);
  245. $show_menu = 'browse_groups';
  246. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  247. $show_menu = $_GET['view'];
  248. }
  249. $social_menu_block = SocialManager::show_social_menu($show_menu);
  250. $templateName = 'social/groups.tpl';
  251. $tpl->setHelp('Groups');
  252. $tpl->assign('message', $show_message);
  253. $tpl->assign('social_menu_block', $social_menu_block);
  254. $tpl->assign('social_right_content', $social_right_content);
  255. $social_layout = $tpl->get_template($templateName);
  256. $tpl->display($social_layout);