group_space.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This script shows the group space for one specific group, possibly displaying
  6. * a list of users in the group, subscribe or unsubscribe option, tutors...
  7. *
  8. * @package chamilo.group
  9. * @todo Display error message if no group ID specified
  10. */
  11. //require_once '../inc/global.inc.php';
  12. $current_course_tool = TOOL_GROUP;
  13. // Notice for unauthorized people.
  14. api_protect_course_script(true);
  15. /* Libraries & config files */
  16. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  17. require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php';
  18. /* MAIN CODE */
  19. $group_id = api_get_group_id();
  20. $user_id = api_get_user_id();
  21. $current_group = GroupManager::get_group_properties($group_id);
  22. if (empty($current_group)) {
  23. api_not_allowed(true);
  24. }
  25. $this_section = SECTION_COURSES;
  26. $nameTools = get_lang('GroupSpace');
  27. $interbreadcrumb[] = array('url' => 'group.php?'.api_get_cidReq(), 'name' => get_lang('Groups'));
  28. /* Ensure all private groups // Juan Carlos Raña Trabado */
  29. $forums_of_groups = get_forums_of_group($current_group['iid']);
  30. if (!GroupManager::userHasAccessToBrowse($user_id, $current_group, api_get_session_id())) {
  31. api_not_allowed(true);
  32. }
  33. Display::display_header($nameTools.' '.Security::remove_XSS($current_group['name']), 'Group');
  34. /* Introduction section (editable by course admin) */
  35. Display::display_introduction_section(TOOL_GROUP);
  36. /* Actions and Action links */
  37. /*
  38. * User wants to register in this group
  39. */
  40. if (!empty($_GET['selfReg']) &&
  41. GroupManager :: is_self_registration_allowed($user_id, $current_group['iid'])
  42. ) {
  43. GroupManager :: subscribe_users($user_id, $current_group['iid']);
  44. Display :: display_normal_message(get_lang('GroupNowMember'));
  45. }
  46. /*
  47. * User wants to unregister from this group
  48. */
  49. if (!empty($_GET['selfUnReg']) &&
  50. GroupManager :: is_self_unregistration_allowed($user_id, $current_group['iid'])
  51. ) {
  52. GroupManager::unsubscribe_users($user_id, $current_group['iid']);
  53. Display::display_normal_message(get_lang('StudentDeletesHimself'));
  54. }
  55. echo '<div class="actions">';
  56. echo '<a href="group.php">'.
  57. Display::return_icon('back.png',get_lang('BackToGroupList'),'',ICON_SIZE_MEDIUM).
  58. '</a>';
  59. /*
  60. * Register to group
  61. */
  62. $subscribe_group = '';
  63. if (GroupManager :: is_self_registration_allowed($user_id, $current_group['iid'])) {
  64. $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;">'.
  65. get_lang("RegIntoGroup").'</a>';
  66. }
  67. /*
  68. * Unregister from group
  69. */
  70. $unsubscribe_group = '';
  71. if (GroupManager :: is_self_unregistration_allowed($user_id, $current_group['iid'])) {
  72. $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;">'.
  73. get_lang("StudentUnsubscribe").'</a>';
  74. }
  75. echo '&nbsp;</div>';
  76. /* Main Display Area */
  77. $edit_url = '';
  78. if (api_is_allowed_to_edit(false, true) ||
  79. GroupManager::is_tutor_of_group(api_get_user_id(), $current_group['iid'])
  80. ) {
  81. $edit_url = '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?'.api_get_cidreq().'">'.
  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['iid'])
  96. ) {
  97. $actions_array = array();
  98. // Link to the forum of this group
  99. $forums_of_groups = get_forums_of_group($current_group['iid']);
  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['iid']);
  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['iid']);
  263. $tutor_info = '';
  264. if (count($tutors) == 0) {
  265. $tutor_info = get_lang('GroupNoneMasc');
  266. } else {
  267. $tutor_info .= '<ul class="thumbnails">';
  268. foreach ($tutors as $index => $tutor) {
  269. $userInfo = api_get_user_info($tutor['user_id']);
  270. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userInfo['username']), ENT_QUOTES);
  271. $completeName = $userInfo['complete_name'];
  272. $photo = '<img src="'.$userInfo['avatar'].'" alt="'.$completeName.'" width="32" height="32" title="'.$completeName.'" />';
  273. $tutor_info .= '<li>';
  274. $tutor_info .= Display::url(
  275. $userInfo['complete_name'],
  276. $userInfo['profile_url']
  277. );
  278. $tutor_info .= '</li>';
  279. }
  280. $tutor_info .= '</ul>';
  281. }
  282. echo Display::page_subheader(get_lang('GroupTutors'));
  283. if (!empty($tutor_info)) {
  284. echo $tutor_info;
  285. }
  286. echo '<br />';
  287. /*
  288. * List all the members of the current group
  289. */
  290. echo Display::page_subheader(get_lang('GroupMembers'));
  291. $table = new SortableTable(
  292. 'group_users',
  293. 'get_number_of_group_users',
  294. 'get_group_user_data',
  295. (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1
  296. );
  297. $my_cidreq = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
  298. $my_origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  299. $my_gidreq = isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : '';
  300. $parameters = array('cidReq' => $my_cidreq, 'origin'=> $my_origin, 'gidReq' => $my_gidreq);
  301. $table->set_additional_parameters($parameters);
  302. $table->set_header(0, '');
  303. if (api_is_western_name_order()) {
  304. $table->set_header(1, get_lang('FirstName'));
  305. $table->set_header(2, get_lang('LastName'));
  306. } else {
  307. $table->set_header(1, get_lang('LastName'));
  308. $table->set_header(2, get_lang('FirstName'));
  309. }
  310. if (api_get_setting('display.show_email_addresses') == 'true') {
  311. $table->set_header(3, get_lang('Email'));
  312. $table->set_column_filter(3, 'email_filter');
  313. } else {
  314. if (api_is_allowed_to_edit() == 'true') {
  315. $table->set_header(3, get_lang('Email'));
  316. $table->set_column_filter(3, 'email_filter');
  317. }
  318. }
  319. //the order of these calls is important
  320. //$table->set_column_filter(1, 'user_name_filter');
  321. //$table->set_column_filter(2, 'user_name_filter');
  322. $table->set_column_filter(0, 'user_icon_filter');
  323. $table->display();
  324. /**
  325. * Get the number of subscribed users to the group
  326. *
  327. * @return integer
  328. *
  329. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  330. * @version April 2008
  331. */
  332. function get_number_of_group_users()
  333. {
  334. $groupInfo = GroupManager::get_group_properties(api_get_group_id());
  335. $course_id = api_get_course_int_id();
  336. if (empty($groupInfo) || empty($course_id)) {
  337. return 0;
  338. }
  339. // Database table definition
  340. $table = Database :: get_course_table(TABLE_GROUP_USER);
  341. // Query
  342. $sql = "SELECT count(iid) AS number_of_users
  343. FROM $table
  344. WHERE
  345. c_id = $course_id AND
  346. group_id = '".intval($groupInfo['iid'])."'";
  347. $result = Database::query($sql);
  348. $return = Database::fetch_array($result, 'ASSOC');
  349. return $return['number_of_users'];
  350. }
  351. /**
  352. * Get the details of the users in a group
  353. *
  354. * @param integer $from starting row
  355. * @param integer $number_of_items number of items to be displayed
  356. * @param integer $column sorting colum
  357. * @param integer $direction sorting direction
  358. * @return array
  359. *
  360. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  361. * @version April 2008
  362. */
  363. function get_group_user_data($from, $number_of_items, $column, $direction)
  364. {
  365. $groupInfo = GroupManager::get_group_properties(api_get_group_id());
  366. $course_id = api_get_course_int_id();
  367. if (empty($groupInfo) || empty($course_id)) {
  368. return 0;
  369. }
  370. // Database table definition
  371. $table_group_user = Database:: get_course_table(TABLE_GROUP_USER);
  372. $table_user = Database:: get_main_table(TABLE_MAIN_USER);
  373. // Query
  374. if (api_get_setting('display.show_email_addresses') == 'true') {
  375. $sql = "SELECT user.user_id AS col0,
  376. ".(api_is_western_name_order() ?
  377. "user.firstname AS col1,
  378. user.lastname AS col2,"
  379. :
  380. "user.lastname AS col1,
  381. user.firstname AS col2,"
  382. )."
  383. user.email AS col3
  384. FROM $table_user user,
  385. $table_group_user group_rel_user
  386. WHERE
  387. group_rel_user.c_id = $course_id AND
  388. group_rel_user.user_id = user.id AND
  389. group_rel_user.group_id = '".$groupInfo['iid']."'
  390. ORDER BY col$column $direction
  391. LIMIT $from, $number_of_items";
  392. } else {
  393. if (api_is_allowed_to_edit()) {
  394. $sql = "SELECT DISTINCT
  395. u.id AS col0,
  396. ".(api_is_western_name_order() ?
  397. "u.firstname AS col1,
  398. u.lastname AS col2,"
  399. :
  400. "u.lastname AS col1,
  401. u.firstname AS col2,")."
  402. u.email AS col3
  403. FROM $table_user u
  404. INNER JOIN $table_group_user gu
  405. ON (gu.user_id = u.id) AND gu.c_id = $course_id
  406. WHERE gu.group_id = '".$groupInfo['iid']."'
  407. ORDER BY col$column $direction
  408. LIMIT $from, $number_of_items";
  409. } else {
  410. $sql = "SELECT DISTINCT
  411. user.id AS col0,
  412. ". (api_is_western_name_order() ?
  413. "user.firstname AS col1,
  414. user.lastname AS col2 "
  415. :
  416. "user.lastname AS col1,
  417. user.firstname AS col2 "
  418. )."
  419. FROM $table_user user, $table_group_user group_rel_user
  420. WHERE
  421. group_rel_user.c_id = $course_id AND
  422. group_rel_user.user_id = user.id AND
  423. group_rel_user.group_id = '".$groupInfo['iid']."'
  424. ORDER BY col$column $direction
  425. LIMIT $from, $number_of_items";
  426. }
  427. }
  428. $return = array();
  429. $result = Database::query($sql);
  430. while ($row = Database::fetch_row($result)) {
  431. $return[] = $row;
  432. }
  433. return $return;
  434. }
  435. /**
  436. * Returns a mailto-link
  437. * @param string $email An email-address
  438. * @return string HTML-code with a mailto-link
  439. */
  440. function email_filter($email)
  441. {
  442. return Display :: encrypted_mailto_link($email, $email);
  443. }
  444. /**
  445. * Display a user icon that links to the user page
  446. *
  447. * @param integer $user_id the id of the user
  448. * @return string code
  449. *
  450. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  451. * @version April 2008
  452. */
  453. function user_icon_filter($user_id)
  454. {
  455. $userInfo = api_get_user_info($user_id);
  456. $photo = '<img src="'.$userInfo['avatar'].'" alt="'.$userInfo['complete_name'].'" width="22" height="22" title="'.$userInfo['complete_name'].'" />';
  457. return Display::url($photo, $userInfo['profile_url']);
  458. }
  459. /**
  460. * Return user profile link around the given user name.
  461. *
  462. * The parameters use a trick of the sorteable table, where the first param is
  463. * the original value of the column
  464. * @param string User name (value of the column at the time of calling)
  465. * @param string URL parameters
  466. * @param array Row of the "sortable table" as it is at the time of function call - we extract the user ID from there
  467. * @return string HTML link
  468. */
  469. function user_name_filter($name, $url_params, $row)
  470. {
  471. $userInfo = api_get_user_info($row[0]);
  472. return UserManager::getUserProfileLink($userInfo);
  473. }
  474. // Footer
  475. $orig = isset($origin) ? $origin : '';
  476. if ($orig != 'learnpath') {
  477. Display::display_footer();
  478. }