groups.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. $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. $url_open = '<a href="group_view.php?id='.$id.'">';
  55. $url_close = '</a>';
  56. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  57. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  58. $name .= ' '.Display::return_icon('social_group_admin.png', get_lang('Admin'), array('style'=>'vertical-align:middle'));
  59. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  60. $name .= ' '.Display::return_icon('social_group_moderator.png', get_lang('Moderator'), array('style'=>'vertical-align:middle'));
  61. }
  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. $item_0 = Display::div($result['picture'], array('class'=>'box_description_group_image'));
  71. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  72. $item_1 = Display::div(Display::tag('h4', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  73. $item_2 = '';
  74. $item_3 = '';
  75. if ($result['description'] != '') {
  76. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  77. } else {
  78. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  79. $item_3 = '<div class="box_description_group_content" ></div>';
  80. }
  81. $grid_item_2 = $item_0.$item_1.$item_2.$item_3;
  82. $grid_my_groups[]= array($grid_item_2);
  83. }
  84. }
  85. // Newest groups
  86. $results = $usergroup->get_groups_by_age(4,false);
  87. $grid_newest_groups = array();
  88. foreach ($results as $result) {
  89. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  90. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  91. $id = $result['id'];
  92. $url_open = '<a href="group_view.php?id='.$id.'">';
  93. $url_close = '</a>';
  94. $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));
  95. if ($count_users_group == 1 ) {
  96. $count_users_group = $count_users_group.' '.get_lang('Member');
  97. } else {
  98. $count_users_group = $count_users_group.' '.get_lang('Members');
  99. }
  100. $name = cut($result['name'],GROUP_TITLE_LENGTH,true);
  101. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  102. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  103. $item_0 = Display::div($result['picture'], array('class'=>'box_description_group_image'));
  104. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  105. $item_1 = Display::div(Display::tag('h4', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  106. if ($result['description'] != '') {
  107. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  108. } else {
  109. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  110. $item_3 = '<div class="box_description_group_content" ></div>';
  111. }
  112. //Avoiding my groups
  113. $join_url = '';
  114. if (!in_array($id,$my_group_list)) {
  115. $join_url = '<a class="btn" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  116. }
  117. $item_4 = '<div class="box_description_group_actions" >'.$join_url.'</div>';
  118. $grid_item_2 = $item_0.$item_1.$item_2.$item_3.$item_4;
  119. $grid_newest_groups[]= array($grid_item_2);
  120. }
  121. // Pop groups
  122. $results = $usergroup->get_groups_by_popularity(4,false);
  123. $grid_pop_groups = array();
  124. if (is_array($results) && count($results) > 0) {
  125. foreach ($results as $result) {
  126. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  127. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  128. $id = $result['id'];
  129. $url_open = '<a href="group_view.php?id='.$id.'">';
  130. $url_close = '</a>';
  131. $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));
  132. if ($count_users_group == 1 ) {
  133. $count_users_group = $count_users_group.' '.get_lang('Member');
  134. } else {
  135. $count_users_group = $count_users_group.' '.get_lang('Members');
  136. }
  137. $name = cut($result['name'],GROUP_TITLE_LENGTH,true);
  138. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  139. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  140. $item_0 = Display::div($result['picture'], array('class'=>'box_description_group_image'));
  141. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  142. $item_1 = Display::div(Display::tag('h4', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  143. if ($result['description'] != '') {
  144. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  145. } else {
  146. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  147. $item_3 = '<div class="box_description_group_content" ></div>';
  148. }
  149. $join_url = '';
  150. if (!in_array($id,$my_group_list)) {
  151. $join_url = '<a class="btn" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  152. }
  153. $item_4 = '<div class="box_description_group_actions" >'.$join_url.'</div>';
  154. $grid_item_2 = $item_0.$item_1.$item_2.$item_3.$item_4;
  155. $grid_pop_groups[]= array($grid_item_2);
  156. }
  157. }
  158. // Display groups (newest, mygroups, pop)
  159. $query_vars = array();
  160. $newest_content = $popular_content = $my_group_content = null;
  161. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  162. $view_group = $_GET['view'];
  163. switch ($view_group) {
  164. case 'mygroups':
  165. if (count($grid_my_groups) > 0) {
  166. $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));
  167. }
  168. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  169. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  170. get_lang('CreateASocialGroup').'</a>';
  171. } else {
  172. if (api_is_allowed_to_edit(null,true)) {
  173. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  174. get_lang('CreateASocialGroup').'</a>';
  175. }
  176. }
  177. break;
  178. case 'newest':
  179. if (count($grid_newest_groups) > 0) {
  180. $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));
  181. }
  182. break;
  183. default:
  184. if (count($grid_pop_groups) > 0) {
  185. $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));
  186. }
  187. break;
  188. }
  189. } else {
  190. $my_group_content = null;
  191. if (count($grid_my_groups) > 0) {
  192. $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));
  193. } else {
  194. $my_group_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  195. }
  196. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  197. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  198. get_lang('CreateASocialGroup').'</a>';
  199. } else {
  200. if (api_is_allowed_to_edit(null,true)) {
  201. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  202. }
  203. }
  204. if (count($grid_newest_groups) > 0) {
  205. $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));
  206. } else {
  207. $newest_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  208. }
  209. if (count($grid_pop_groups) > 0) {
  210. $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));
  211. } else {
  212. $popular_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  213. }
  214. }
  215. if (!empty($create_group_item)) {
  216. $social_right_content .= Display::page_subheader($create_group_item);
  217. }
  218. $headers = array(get_lang('Newest'), get_lang('Popular'), get_lang('MyGroups'));
  219. $social_right_content .= Display::tabs($headers, array($newest_content, $popular_content, $my_group_content),'tab_browse');
  220. $show_message = null;
  221. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && isset($_REQUEST['msg']) && $_REQUEST['msg'] == 'topic_deleted') {
  222. $show_message = Display::return_message(get_lang('Deleted'), 'success');
  223. }
  224. $tpl = new Template(null);
  225. // Block Social Avatar
  226. SocialManager::setSocialUserBlock($tpl, $user_id, $show_menu);
  227. $show_menu = 'browse_groups';
  228. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  229. $show_menu = $_GET['view'];
  230. }
  231. $social_menu_block = SocialManager::show_social_menu($show_menu);
  232. $templateName = 'social/groups.tpl';
  233. $tpl->setHelp('Groups');
  234. $tpl->assign('message', $show_message);
  235. $tpl->assign('social_menu_block', $social_menu_block);
  236. $tpl->assign('social_right_content', $social_right_content);
  237. $social_layout = $tpl->get_template($templateName);
  238. $tpl->display($social_layout);