groups.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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(
  62. $usergroup->get_users_by_group(
  63. $id,
  64. false,
  65. array(
  66. GROUP_USER_PERMISSION_ADMIN,
  67. GROUP_USER_PERMISSION_READER,
  68. GROUP_USER_PERMISSION_MODERATOR,
  69. ),
  70. 0,
  71. 1000
  72. )
  73. );
  74. if ($count_users_group == 1) {
  75. $count_users_group = $count_users_group.' '.get_lang('Member');
  76. } else {
  77. $count_users_group = $count_users_group.' '.get_lang('Members');
  78. }
  79. $picture = $usergroup->get_picture_group(
  80. $result['id'],
  81. $result['picture'],
  82. 80
  83. );
  84. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  85. $members = Display::returnFontAwesomeIcon('user').$count_users_group;
  86. $html = '<div class="row">';
  87. $html .= '<div class="col-md-2">';
  88. $html .= $result['picture'];
  89. $html .= '</div>';
  90. $html .= '<div class="col-md-10">';
  91. $html .= '<div class="title-groups">';
  92. $html .= Display::tag('h5', $url);
  93. $html .= '</div>';
  94. $html .= '<div class="members-groups">'.$members.'</div>';
  95. if ($result['description'] != '') {
  96. $html .= '<div class="description-groups">'.cut($result['description'], 100, true).'</div>';
  97. } else {
  98. $html .= '';
  99. }
  100. $html .= '</div>';
  101. $html .= '</div>';
  102. $grid_item_2 = $html;
  103. $grid_my_groups[] = array($grid_item_2);
  104. }
  105. }
  106. // Newest groups
  107. $results = $usergroup->get_groups_by_age(4, false);
  108. $grid_newest_groups = array();
  109. foreach ($results as $result) {
  110. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  111. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  112. $id = $result['id'];
  113. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  114. $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));
  115. if ($count_users_group == 1) {
  116. $count_users_group = $count_users_group.' '.get_lang('Member');
  117. } else {
  118. $count_users_group = $count_users_group.' '.get_lang('Members');
  119. }
  120. $url = '<a href="group_view.php?id='.$id.'">'.$name.'</a>';
  121. $picture = $usergroup->get_picture_group($result['id'], $result['picture'], 80);
  122. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  123. $members = Display::returnFontAwesomeIcon('user').$count_users_group;
  124. $html = '<div class="row">';
  125. $html .= '<div class="col-md-2">';
  126. $html .= $result['picture'];
  127. $html .= '</div>';
  128. $html .= '<div class="col-md-10">';
  129. $html .= '<div class="title-groups">';
  130. $html .= Display::tag('h5', $url);
  131. $html .= '</div>';
  132. $html .= '<div class="members-groups">'.$members.'</div>';
  133. if ($result['description'] != '') {
  134. $html .= '<div class="description-groups">'.cut($result['description'], 100, true).'</div>';
  135. } else {
  136. $html .= '';
  137. }
  138. //Avoiding my groups
  139. if (!in_array($id, $my_group_list)) {
  140. $html .= '<a class="btn btn-primary" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  141. }
  142. $html .= '<div class="group-actions" >'.$join_url.'</div>';
  143. $html .= '</div>';
  144. $html .= '</div>';
  145. $grid_item_2 = $html;
  146. $grid_newest_groups[] = array($grid_item_2);
  147. }
  148. // Pop groups
  149. $results = $usergroup->get_groups_by_popularity(4, false);
  150. $grid_pop_groups = array();
  151. if (is_array($results) && count($results) > 0) {
  152. foreach ($results as $result) {
  153. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  154. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  155. $id = $result['id'];
  156. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  157. $count_users_group = count(
  158. $usergroup->get_users_by_group(
  159. $id,
  160. false,
  161. array(
  162. GROUP_USER_PERMISSION_ADMIN,
  163. GROUP_USER_PERMISSION_READER,
  164. GROUP_USER_PERMISSION_MODERATOR,
  165. ),
  166. 0,
  167. 1000
  168. )
  169. );
  170. if ($count_users_group == 1) {
  171. $count_users_group = $count_users_group.' '.get_lang('Member');
  172. } else {
  173. $count_users_group = $count_users_group.' '.get_lang('Members');
  174. }
  175. $url = '<a href="group_view.php?id='.$id.'">'.$name.'</a>';
  176. $picture = $usergroup->get_picture_group($result['id'], $result['picture'], 80);
  177. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  178. $html = '<div class="row">';
  179. $html .= '<div class="col-md-2">';
  180. $html .= $result['picture'];
  181. $html .= '</div>';
  182. $html .= '<div class="col-md-10">';
  183. $html .= '<div class="title-groups">';
  184. $html .= Display::tag('h5', $url);
  185. $html .= '</div>';
  186. $html .= '<div class="members-groups">'.$members.'</div>';
  187. if ($result['description'] != '') {
  188. $html .= '<div class="description-groups">'.cut($result['description'], 100, true).'</div>';
  189. } else {
  190. $html .= '';
  191. }
  192. //Avoiding my groups
  193. if (!in_array($id, $my_group_list)) {
  194. $html .= '<a class="btn btn-primary" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  195. }
  196. $html .= '<div class="group-actions" >'.$join_url.'</div>';
  197. $html .= '</div>';
  198. $html .= '</div>';
  199. $grid_item_2 = $html;
  200. $grid_pop_groups[] = array($grid_item_2);
  201. }
  202. }
  203. // Display groups (newest, mygroups, pop)
  204. $query_vars = array();
  205. $newest_content = $popular_content = $my_group_content = null;
  206. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  207. $view_group = $_GET['view'];
  208. switch ($view_group) {
  209. case 'mygroups':
  210. if (count($grid_my_groups) > 0) {
  211. $my_group_content = Display::return_sortable_grid(
  212. 'mygroups',
  213. array(),
  214. $grid_my_groups,
  215. array('hide_navigation' => true, 'per_page' => 2),
  216. $query_vars,
  217. false,
  218. array(true, true, true, false)
  219. );
  220. }
  221. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  222. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  223. get_lang('CreateASocialGroup').'</a>';
  224. } else {
  225. if (api_is_allowed_to_edit(null, true)) {
  226. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  227. get_lang('CreateASocialGroup').'</a>';
  228. }
  229. }
  230. break;
  231. case 'newest':
  232. if (count($grid_newest_groups) > 0) {
  233. $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));
  234. }
  235. break;
  236. default:
  237. if (count($grid_pop_groups) > 0) {
  238. $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));
  239. }
  240. break;
  241. }
  242. } else {
  243. $my_group_content = null;
  244. if (count($grid_my_groups) > 0) {
  245. $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));
  246. } else {
  247. $my_group_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  248. }
  249. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  250. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  251. get_lang('CreateASocialGroup').'</a>';
  252. } else {
  253. if (api_is_allowed_to_edit(null, true)) {
  254. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  255. }
  256. }
  257. if (count($grid_newest_groups) > 0) {
  258. $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));
  259. } else {
  260. $newest_content = '<div class="muted">'.get_lang('GroupNone').'</div>';
  261. }
  262. if (count($grid_pop_groups) > 0) {
  263. $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));
  264. } else {
  265. $popular_content = '<div class="muted">'.get_lang('GroupNone').'</div>';
  266. }
  267. }
  268. if (!empty($create_group_item)) {
  269. $social_right_content .= Display::page_subheader($create_group_item);
  270. }
  271. $headers = array(get_lang('Newest'), get_lang('Popular'), get_lang('MyGroups'));
  272. $social_right_content .= Display::tabs($headers, array($newest_content, $popular_content, $my_group_content), 'tab_browse');
  273. $tpl = new Template(null);
  274. // Block Social Avatar
  275. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), $show_menu);
  276. $show_menu = 'browse_groups';
  277. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  278. $show_menu = $_GET['view'];
  279. }
  280. $social_menu_block = SocialManager::show_social_menu($show_menu);
  281. $templateName = 'social/groups.tpl';
  282. $tpl->setHelp('Groups');
  283. $tpl->assign('social_menu_block', $social_menu_block);
  284. $tpl->assign('social_right_content', $social_right_content);
  285. $social_layout = $tpl->get_template($templateName);
  286. $tpl->display($social_layout);