group_space.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script shows the group space for one specific group, possibly displaying
  5. * a list of users in the group, subscribe or unsubscribe option, tutors...
  6. *
  7. * @package chamilo.group
  8. * @todo Display error message if no group ID specified
  9. */
  10. require_once '../inc/global.inc.php';
  11. $current_course_tool = TOOL_GROUP;
  12. // Notice for unauthorized people.
  13. api_protect_course_script(true);
  14. /* Libraries & config files */
  15. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  16. require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php';
  17. /* MAIN CODE */
  18. $group_id = api_get_group_id();
  19. $user_id = api_get_user_id();
  20. $current_group = GroupManager::get_group_properties($group_id);
  21. if (empty($current_group)) {
  22. api_not_allowed(true);
  23. }
  24. $this_section = SECTION_COURSES;
  25. $nameTools = get_lang('GroupSpace');
  26. $interbreadcrumb[] = array('url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups'));
  27. /* Ensure all private groups // Juan Carlos Raña Trabado */
  28. $forums_of_groups = get_forums_of_group($current_group['id']);
  29. if (!GroupManager::userHasAccessToBrowse($user_id, $current_group, api_get_session_id())) {
  30. api_not_allowed(true);
  31. }
  32. Display::display_header($nameTools.' '.Security::remove_XSS($current_group['name']), 'Group');
  33. /* Introduction section (editable by course admin) */
  34. Display::display_introduction_section(TOOL_GROUP);
  35. /* Actions and Action links */
  36. /*
  37. * User wants to register in this group
  38. */
  39. if (!empty($_GET['selfReg']) &&
  40. GroupManager :: is_self_registration_allowed($user_id, $current_group['id'])
  41. ) {
  42. GroupManager :: subscribe_users($user_id, $current_group['id']);
  43. Display :: display_normal_message(get_lang('GroupNowMember'));
  44. }
  45. /*
  46. * User wants to unregister from this group
  47. */
  48. if (!empty($_GET['selfUnReg']) &&
  49. GroupManager :: is_self_unregistration_allowed($user_id, $current_group['id'])
  50. ) {
  51. GroupManager :: unsubscribe_users($user_id, $current_group['id']);
  52. Display::display_normal_message(get_lang('StudentDeletesHimself'));
  53. }
  54. echo '<div class="actions">';
  55. echo '<a href="group.php">'.
  56. Display::return_icon('back.png',get_lang('BackToGroupList'),'',ICON_SIZE_MEDIUM).
  57. '</a>';
  58. /*
  59. * Register to group
  60. */
  61. $subscribe_group = '';
  62. if (GroupManager :: is_self_registration_allowed($user_id, $current_group['id'])) {
  63. $subscribe_group = '<a class="btn btn-default" href="'.api_get_self().'?selfReg=1&group_id='.$current_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.
  64. get_lang("RegIntoGroup").'</a>';
  65. }
  66. /*
  67. * Unregister from group
  68. */
  69. $unsubscribe_group = '';
  70. if (GroupManager :: is_self_unregistration_allowed($user_id, $current_group['id'])) {
  71. $unsubscribe_group = '<a class="btn btn-default" href="'.api_get_self().'?selfUnReg=1" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."'".')) return false;">'.
  72. get_lang("StudentUnsubscribe").'</a>';
  73. }
  74. echo '&nbsp;</div>';
  75. /* Main Display Area */
  76. $edit_url = '';
  77. if (api_is_allowed_to_edit(false, true) ||
  78. GroupManager::is_tutor_of_group(api_get_user_id(), api_get_group_id())
  79. ) {
  80. $my_origin = isset($origin) ? $origin : '';
  81. $edit_url = '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?'.api_get_cidreq().'&origin='.$my_origin.'">'.
  82. Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
  83. }
  84. echo Display::page_header(
  85. Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group
  86. );
  87. if (!empty($current_group['description'])) {
  88. echo '<p>'.Security::remove_XSS($current_group['description']).'</p>';
  89. }
  90. /*
  91. * Group Tools
  92. */
  93. // If the user is subscribed to the group or the user is a tutor of the group then
  94. if (api_is_allowed_to_edit(false, true) ||
  95. GroupManager::is_user_in_group(api_get_user_id(), $current_group['id'])
  96. ) {
  97. $actions_array = array();
  98. // Link to the forum of this group
  99. $forums_of_groups = get_forums_of_group($current_group['id']);
  100. if (is_array($forums_of_groups)) {
  101. if ($current_group['forum_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  102. foreach ($forums_of_groups as $key => $value) {
  103. if ($value['forum_group_public_private'] == 'public' ||
  104. ($value['forum_group_public_private'] == 'private') ||
  105. !empty($user_is_tutor) ||
  106. api_is_allowed_to_edit(false, true)
  107. ) {
  108. $actions_array[] = array(
  109. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$value['forum_id'].'&'.api_get_cidreq().'&origin=group',
  110. 'content' => Display::return_icon(
  111. 'forum.png',
  112. get_lang('Forum').': '.$value['forum_title'],
  113. array(),
  114. 32
  115. ),
  116. );
  117. }
  118. }
  119. }
  120. }
  121. if ($current_group['doc_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  122. // Link to the documents area of this group
  123. $actions_array[] = array(
  124. 'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(),
  125. 'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32)
  126. );
  127. }
  128. if ($current_group['calendar_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  129. $groupFilter = null;
  130. if (!empty($group_id)) {
  131. $groupFilter = "&type=course&user_id=GROUP:$group_id";
  132. }
  133. // Link to a group-specific part of agenda
  134. $actions_array[] = array(
  135. 'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?'.api_get_cidreq().$groupFilter,
  136. 'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32)
  137. );
  138. }
  139. if ($current_group['work_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  140. // Link to the works area of this group
  141. $actions_array[] = array(
  142. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  143. 'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), 32)
  144. );
  145. }
  146. if ($current_group['announcements_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  147. // Link to a group-specific part of announcements
  148. $actions_array[] = array(
  149. 'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  150. 'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32)
  151. );
  152. }
  153. if ($current_group['wiki_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  154. // Link to the wiki area of this group
  155. $actions_array[] = array(
  156. 'url' => api_get_path(WEB_CODE_PATH).'wiki/index.php?'.api_get_cidreq().'&action=show&title=index&session_id='.api_get_session_id().'&group_id='.$current_group['id'],
  157. 'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
  158. );
  159. }
  160. if ($current_group['chat_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  161. // Link to the chat area of this group
  162. if (api_get_course_setting('allow_open_chat_window')) {
  163. $actions_array[] = array(
  164. 'url' => "javascript: void(0);",
  165. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32),
  166. 'url_attributes' => array(
  167. 'onclick' => " window.open('../chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id']."','window_chat_group_".api_get_course_id()."_".api_get_group_id()."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')"
  168. )
  169. );
  170. } else {
  171. $actions_array[] = array(
  172. 'url' => api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id'],
  173. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  174. );
  175. }
  176. }
  177. $enabled = api_get_plugin_setting('bbb', 'tool_enable');
  178. if ($enabled === 'true') {
  179. $bbb = new bbb();
  180. if ($bbb->hasGroupSupport()) {
  181. $actions_array[] = array(
  182. 'url' => api_get_path(WEB_PLUGIN_PATH)."bbb/start.php?".api_get_cidreq(),
  183. 'content' => Display::return_icon('bbb.png', get_lang('VideoConference'), array(), 32)
  184. );
  185. }
  186. }
  187. if (!empty($actions_array)) {
  188. echo Display::actions($actions_array);
  189. }
  190. } else {
  191. $actions_array = array();
  192. // Link to the forum of this group
  193. $forums_of_groups = get_forums_of_group($current_group['id']);
  194. if (is_array($forums_of_groups)) {
  195. if ( $current_group['forum_state'] == GroupManager::TOOL_PUBLIC) {
  196. foreach ($forums_of_groups as $key => $value) {
  197. if ($value['forum_group_public_private'] == 'public') {
  198. $actions_array[] = array(
  199. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?cidReq='.api_get_course_id().'&forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'&origin=group',
  200. 'content' => Display::return_icon('forum.png', get_lang('GroupForum'), array(), ICON_SIZE_MEDIUM)
  201. );
  202. }
  203. }
  204. }
  205. }
  206. if ($current_group['doc_state'] == GroupManager::TOOL_PUBLIC) {
  207. // Link to the documents area of this group
  208. $actions_array[] = array(
  209. 'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(),
  210. 'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_MEDIUM)
  211. );
  212. }
  213. if ($current_group['calendar_state'] == GroupManager::TOOL_PUBLIC) {
  214. // Link to a group-specific part of agenda
  215. $actions_array[] = array(
  216. 'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda.php?'.api_get_cidreq(),
  217. 'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_MEDIUM)
  218. );
  219. }
  220. if ($current_group['work_state'] == GroupManager::TOOL_PUBLIC) {
  221. // Link to the works area of this group
  222. $actions_array[] = array(
  223. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  224. 'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_MEDIUM)
  225. );
  226. }
  227. if ($current_group['announcements_state'] == GroupManager::TOOL_PUBLIC) {
  228. // Link to a group-specific part of announcements
  229. $actions_array[] = array(
  230. 'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  231. 'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_MEDIUM)
  232. );
  233. }
  234. if ($current_group['wiki_state'] == GroupManager::TOOL_PUBLIC) {
  235. // Link to the wiki area of this group
  236. $actions_array[] = array(
  237. 'url' => api_get_path(WEB_CODE_PATH).'wiki/index.php?'.api_get_cidreq().'&action=show&title=index&session_id='.api_get_session_id().'&group_id='.$current_group['id'],
  238. 'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
  239. );
  240. }
  241. if ($current_group['chat_state'] == GroupManager::TOOL_PUBLIC) {
  242. // Link to the chat area of this group
  243. if (api_get_course_setting('allow_open_chat_window')) {
  244. $actions_array[] = array(
  245. 'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id']."','window_chat_group_".api_get_course_id()."_".api_get_group_id()."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"",
  246. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  247. );
  248. } else {
  249. $actions_array[] = array(
  250. 'url' => api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id'],
  251. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  252. );
  253. }
  254. }
  255. if (!empty($actions_array)) {
  256. echo Display::actions($actions_array);
  257. }
  258. }
  259. /*
  260. * List all the tutors of the current group
  261. */
  262. $tutors = GroupManager::get_subscribed_tutors($current_group['id']);
  263. $tutor_info = '';
  264. if (count($tutors) == 0) {
  265. $tutor_info = get_lang('GroupNoneMasc');
  266. } else {
  267. isset($origin) ? $my_origin = $origin:$my_origin='';
  268. $tutor_info .= '<ul class="thumbnails">';
  269. foreach ($tutors as $index => $tutor) {
  270. $userInfo = api_get_user_info($tutor['user_id']);
  271. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userInfo['username']), ENT_QUOTES);
  272. $completeName = $userInfo['complete_name'];
  273. $photo = '<img src="'.$userInfo['avatar'].'" alt="'.$completeName.'" width="32" height="32" title="'.$completeName.'" />';
  274. $tutor_info .= '<li>';
  275. $tutor_info .= Display::url(
  276. $userInfo['complete_name'],
  277. $userInfo['profile_url']
  278. );
  279. $tutor_info .= '</li>';
  280. }
  281. $tutor_info .= '</ul>';
  282. }
  283. echo Display::page_subheader(get_lang('GroupTutors'));
  284. if (!empty($tutor_info)) {
  285. echo $tutor_info;
  286. }
  287. echo '<br />';
  288. /*
  289. * List all the members of the current group
  290. */
  291. echo Display::page_subheader(get_lang('GroupMembers'));
  292. $table = new SortableTable(
  293. 'group_users',
  294. 'get_number_of_group_users',
  295. 'get_group_user_data',
  296. (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1
  297. );
  298. $my_cidreq = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
  299. $my_origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  300. $my_gidreq = isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : '';
  301. $parameters = array('cidReq' => $my_cidreq, 'origin'=> $my_origin, 'gidReq' => $my_gidreq);
  302. $table->set_additional_parameters($parameters);
  303. $table->set_header(0, '');
  304. if (api_is_western_name_order()) {
  305. $table->set_header(1, get_lang('FirstName'));
  306. $table->set_header(2, get_lang('LastName'));
  307. } else {
  308. $table->set_header(1, get_lang('LastName'));
  309. $table->set_header(2, get_lang('FirstName'));
  310. }
  311. if (api_get_setting('show_email_addresses') == 'true') {
  312. $table->set_header(3, get_lang('Email'));
  313. $table->set_column_filter(3, 'email_filter');
  314. } else {
  315. if (api_is_allowed_to_edit() == 'true') {
  316. $table->set_header(3, get_lang('Email'));
  317. $table->set_column_filter(3, 'email_filter');
  318. }
  319. }
  320. //the order of these calls is important
  321. $table->set_column_filter(1, 'user_name_filter');
  322. $table->set_column_filter(2, 'user_name_filter');
  323. $table->set_column_filter(0, 'user_icon_filter');
  324. $table->display();
  325. /**
  326. * Get the number of subscribed users to the group
  327. *
  328. * @return integer
  329. *
  330. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  331. * @version April 2008
  332. */
  333. function get_number_of_group_users()
  334. {
  335. global $current_group;
  336. $course_id = api_get_course_int_id();
  337. // Database table definition
  338. $table = Database :: get_course_table(TABLE_GROUP_USER);
  339. // Query
  340. $sql = "SELECT count(iid) AS number_of_users
  341. FROM ".$table."
  342. WHERE c_id = $course_id AND group_id='".intval($current_group['id'])."'";
  343. $result = Database::query($sql);
  344. $return = Database::fetch_array($result, 'ASSOC');
  345. return $return['number_of_users'];
  346. }
  347. /**
  348. * Get the details of the users in a group
  349. *
  350. * @param integer $from starting row
  351. * @param integer $number_of_items number of items to be displayed
  352. * @param integer $column sorting colum
  353. * @param integer $direction sorting direction
  354. * @return array
  355. *
  356. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  357. * @version April 2008
  358. */
  359. function get_group_user_data($from, $number_of_items, $column, $direction)
  360. {
  361. global $current_group;
  362. // Database table definition
  363. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  364. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  365. $course_id = api_get_course_int_id();
  366. // Query
  367. if (api_get_setting('show_email_addresses') == 'true') {
  368. $sql = "SELECT user.id AS col0,
  369. ".(api_is_western_name_order() ?
  370. "user.firstname AS col1,
  371. user.lastname AS col2,"
  372. :
  373. "user.lastname AS col1,
  374. user.firstname AS col2,"
  375. )."
  376. user.email AS col3
  377. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  378. WHERE group_rel_user.c_id = $course_id AND group_rel_user.user_id = user.id
  379. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  380. $sql .= " ORDER BY col$column $direction ";
  381. $sql .= " LIMIT $from,$number_of_items";
  382. } else {
  383. if (api_is_allowed_to_edit()) {
  384. $sql = "SELECT DISTINCT
  385. u.id AS col0,
  386. ".(api_is_western_name_order() ?
  387. "u.firstname AS col1,
  388. u.lastname AS col2,"
  389. :
  390. "u.lastname AS col1,
  391. u.firstname AS col2,"
  392. )."
  393. u.email AS col3
  394. FROM ".$table_user." u INNER JOIN ".$table_group_user." gu ON (gu.user_id = u.id) AND gu.c_id = $course_id
  395. WHERE gu.group_id = '".Database::escape_string($current_group['id'])."'";
  396. $sql .= " ORDER BY col$column $direction ";
  397. $sql .= " LIMIT $from,$number_of_items";
  398. } else {
  399. $sql = "SELECT DISTINCT
  400. user.id AS col0,
  401. ". (api_is_western_name_order() ?
  402. "user.firstname AS col1,
  403. user.lastname AS col2 "
  404. :
  405. "user.lastname AS col1,
  406. user.firstname AS col2 "
  407. )."
  408. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  409. WHERE group_rel_user.c_id = $course_id AND group_rel_user.user_id = user.id
  410. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  411. $sql .= " ORDER BY col$column $direction ";
  412. $sql .= " LIMIT $from,$number_of_items";
  413. }
  414. }
  415. $return = array();
  416. $result = Database::query($sql);
  417. while ($row = Database::fetch_row($result)) {
  418. $return[] = $row;
  419. }
  420. return $return;
  421. }
  422. /**
  423. * Returns a mailto-link
  424. * @param string $email An email-address
  425. * @return string HTML-code with a mailto-link
  426. */
  427. function email_filter($email)
  428. {
  429. return Display :: encrypted_mailto_link($email, $email);
  430. }
  431. /**
  432. * Display a user icon that links to the user page
  433. *
  434. * @param integer $user_id the id of the user
  435. * @return string code
  436. *
  437. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  438. * @version April 2008
  439. */
  440. function user_icon_filter($user_id)
  441. {
  442. $userInfo = api_get_user_info($user_id);
  443. $photo = '<img src="'.$userInfo['avatar'].'" alt="'.$userInfo['complete_name'].'" width="22" height="22" title="'.$userInfo['complete_name'].'" />';
  444. return Display::url($photo, $userInfo['profile_url']);
  445. }
  446. /**
  447. * Return user profile link around the given user name.
  448. *
  449. * The parameters use a trick of the sorteable table, where the first param is
  450. * the original value of the column
  451. * @param string User name (value of the column at the time of calling)
  452. * @param string URL parameters
  453. * @param array Row of the "sortable table" as it is at the time of function call - we extract the user ID from there
  454. * @return string HTML link
  455. */
  456. function user_name_filter($name, $url_params, $row)
  457. {
  458. $userInfo = api_get_user_info($row[0]);
  459. return UserManager::getUserProfileLink($userInfo);
  460. }
  461. // Footer
  462. $orig = isset($origin) ? $origin : '';
  463. if ($orig != 'learnpath') {
  464. Display::display_footer();
  465. }