groups.php 12 KB

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