group_space.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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 __DIR__.'/../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);
  29. if (!GroupManager::userHasAccessToBrowse($user_id, $current_group, api_get_session_id())) {
  30. api_not_allowed(true);
  31. }
  32. /* Actions and Action links */
  33. /*
  34. * User wants to register in this group
  35. */
  36. if (!empty($_GET['selfReg']) &&
  37. GroupManager :: is_self_registration_allowed($user_id, $current_group)
  38. ) {
  39. GroupManager :: subscribe_users($user_id, $current_group);
  40. Display::addFlash(Display::return_message(get_lang('GroupNowMember'), 'normal'));
  41. }
  42. /*
  43. * User wants to unregister from this group
  44. */
  45. if (!empty($_GET['selfUnReg']) &&
  46. GroupManager :: is_self_unregistration_allowed($user_id, $current_group)
  47. ) {
  48. GroupManager::unsubscribe_users($user_id, $current_group);
  49. Display::addFlash(
  50. Display::return_message(get_lang('StudentDeletesHimself'), 'normal')
  51. );
  52. }
  53. Display::display_header(
  54. $nameTools.' '.Security::remove_XSS($current_group['name']),
  55. 'Group'
  56. );
  57. /* Introduction section (editable by course admin) */
  58. Display::display_introduction_section(TOOL_GROUP);
  59. echo '<div class="actions">';
  60. echo '<a href="group.php">'.
  61. Display::return_icon('back.png', get_lang('BackToGroupList'), '', ICON_SIZE_MEDIUM).
  62. '</a>';
  63. /*
  64. * Register to group
  65. */
  66. $subscribe_group = '';
  67. if (GroupManager :: is_self_registration_allowed($user_id, $current_group)) {
  68. $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;">'.
  69. get_lang("RegIntoGroup").'</a>';
  70. }
  71. /*
  72. * Unregister from group
  73. */
  74. $unsubscribe_group = '';
  75. if (GroupManager :: is_self_unregistration_allowed($user_id, $current_group)) {
  76. $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;">'.
  77. get_lang("StudentUnsubscribe").'</a>';
  78. }
  79. echo '&nbsp;</div>';
  80. /* Main Display Area */
  81. $edit_url = '';
  82. if (api_is_allowed_to_edit(false, true) ||
  83. GroupManager::is_tutor_of_group(api_get_user_id(), $current_group)
  84. ) {
  85. $edit_url = '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?'.api_get_cidreq().'">'.
  86. Display::return_icon('edit.png', get_lang('EditGroup'), '', ICON_SIZE_SMALL).'</a>';
  87. }
  88. echo Display::page_header(
  89. Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group
  90. );
  91. if (!empty($current_group['description'])) {
  92. echo '<p>'.Security::remove_XSS($current_group['description']).'</p>';
  93. }
  94. /*
  95. * Group Tools
  96. */
  97. // If the user is subscribed to the group or the user is a tutor of the group then
  98. if (api_is_allowed_to_edit(false, true) ||
  99. GroupManager::is_user_in_group(api_get_user_id(), $current_group)
  100. ) {
  101. $actions_array = array();
  102. // Link to the forum of this group
  103. $forums_of_groups = get_forums_of_group($current_group);
  104. if (is_array($forums_of_groups)) {
  105. if ($current_group['forum_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  106. foreach ($forums_of_groups as $key => $value) {
  107. if ($value['forum_group_public_private'] == 'public' ||
  108. ($value['forum_group_public_private'] == 'private') ||
  109. !empty($user_is_tutor) ||
  110. api_is_allowed_to_edit(false, true)
  111. ) {
  112. $actions_array[] = array(
  113. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$value['forum_id'].'&'.api_get_cidreq().'&origin=group',
  114. 'content' => Display::return_icon(
  115. 'forum.png',
  116. get_lang('Forum').': '.$value['forum_title'],
  117. array(),
  118. 32
  119. ),
  120. );
  121. }
  122. }
  123. }
  124. }
  125. if ($current_group['doc_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  126. // Link to the documents area of this group
  127. $actions_array[] = array(
  128. 'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(),
  129. 'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32)
  130. );
  131. }
  132. if ($current_group['calendar_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  133. $groupFilter = null;
  134. if (!empty($group_id)) {
  135. $groupFilter = "&type=course&user_id=GROUP:$group_id";
  136. }
  137. // Link to a group-specific part of agenda
  138. $actions_array[] = array(
  139. 'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?'.api_get_cidreq().$groupFilter,
  140. 'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32)
  141. );
  142. }
  143. if ($current_group['work_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  144. // Link to the works area of this group
  145. $actions_array[] = array(
  146. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  147. 'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), 32)
  148. );
  149. }
  150. if ($current_group['announcements_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  151. // Link to a group-specific part of announcements
  152. $actions_array[] = array(
  153. 'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  154. 'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32)
  155. );
  156. }
  157. if ($current_group['wiki_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  158. // Link to the wiki area of this group
  159. $actions_array[] = array(
  160. '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'],
  161. 'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
  162. );
  163. }
  164. if ($current_group['chat_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  165. // Link to the chat area of this group
  166. if (api_get_course_setting('allow_open_chat_window')) {
  167. $actions_array[] = array(
  168. 'url' => "javascript: void(0);",
  169. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32),
  170. 'url_attributes' => array(
  171. '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')"
  172. )
  173. );
  174. } else {
  175. $actions_array[] = array(
  176. 'url' => api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id'],
  177. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  178. );
  179. }
  180. }
  181. $enabled = api_get_plugin_setting('bbb', 'tool_enable');
  182. if ($enabled === 'true') {
  183. $bbb = new bbb();
  184. if ($bbb->hasGroupSupport()) {
  185. $actions_array[] = array(
  186. 'url' => api_get_path(WEB_PLUGIN_PATH)."bbb/start.php?".api_get_cidreq(),
  187. 'content' => Display::return_icon('bbb.png', get_lang('VideoConference'), array(), 32)
  188. );
  189. }
  190. }
  191. if (!empty($actions_array)) {
  192. echo Display::actions($actions_array);
  193. }
  194. } else {
  195. $actions_array = array();
  196. // Link to the forum of this group
  197. $forums_of_groups = get_forums_of_group($current_group);
  198. if (is_array($forums_of_groups)) {
  199. if ($current_group['forum_state'] == GroupManager::TOOL_PUBLIC) {
  200. foreach ($forums_of_groups as $key => $value) {
  201. if ($value['forum_group_public_private'] == 'public') {
  202. $actions_array[] = array(
  203. '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',
  204. 'content' => Display::return_icon('forum.png', get_lang('GroupForum'), array(), ICON_SIZE_MEDIUM)
  205. );
  206. }
  207. }
  208. }
  209. }
  210. if ($current_group['doc_state'] == GroupManager::TOOL_PUBLIC) {
  211. // Link to the documents area of this group
  212. $actions_array[] = array(
  213. 'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(),
  214. 'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_MEDIUM)
  215. );
  216. }
  217. if ($current_group['calendar_state'] == GroupManager::TOOL_PUBLIC) {
  218. // Link to a group-specific part of agenda
  219. $actions_array[] = array(
  220. 'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda.php?'.api_get_cidreq(),
  221. 'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_MEDIUM)
  222. );
  223. }
  224. if ($current_group['work_state'] == GroupManager::TOOL_PUBLIC) {
  225. // Link to the works area of this group
  226. $actions_array[] = array(
  227. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  228. 'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_MEDIUM)
  229. );
  230. }
  231. if ($current_group['announcements_state'] == GroupManager::TOOL_PUBLIC) {
  232. // Link to a group-specific part of announcements
  233. $actions_array[] = array(
  234. 'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  235. 'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_MEDIUM)
  236. );
  237. }
  238. if ($current_group['wiki_state'] == GroupManager::TOOL_PUBLIC) {
  239. // Link to the wiki area of this group
  240. $actions_array[] = array(
  241. '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'],
  242. 'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
  243. );
  244. }
  245. if ($current_group['chat_state'] == GroupManager::TOOL_PUBLIC) {
  246. // Link to the chat area of this group
  247. if (api_get_course_setting('allow_open_chat_window')) {
  248. $actions_array[] = array(
  249. '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') \"",
  250. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  251. );
  252. } else {
  253. $actions_array[] = array(
  254. 'url' => api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id'],
  255. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  256. );
  257. }
  258. }
  259. if (!empty($actions_array)) {
  260. echo Display::actions($actions_array);
  261. }
  262. }
  263. /*
  264. * List all the tutors of the current group
  265. */
  266. $tutors = GroupManager::get_subscribed_tutors($current_group);
  267. $tutor_info = '';
  268. if (count($tutors) == 0) {
  269. $tutor_info = get_lang('GroupNoneMasc');
  270. } else {
  271. $tutor_info .= '<ul class="thumbnails">';
  272. foreach ($tutors as $index => $tutor) {
  273. $userInfo = api_get_user_info($tutor['user_id']);
  274. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userInfo['username']), ENT_QUOTES);
  275. $completeName = $userInfo['complete_name'];
  276. $photo = '<img src="'.$userInfo['avatar'].'" alt="'.$completeName.'" width="32" height="32" title="'.$completeName.'" />';
  277. $tutor_info .= '<li>';
  278. $tutor_info .= $userInfo['complete_name_with_message_link'];
  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. $origin = api_get_origin();
  299. $my_cidreq = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
  300. $my_gidreq = isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : '';
  301. $parameters = array('cidReq' => $my_cidreq, 'origin'=> $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. $groupInfo = GroupManager::get_group_properties(api_get_group_id());
  336. $course_id = api_get_course_int_id();
  337. if (empty($groupInfo) || empty($course_id)) {
  338. return 0;
  339. }
  340. // Database table definition
  341. $table = Database::get_course_table(TABLE_GROUP_USER);
  342. // Query
  343. $sql = "SELECT count(iid) AS number_of_users
  344. FROM $table
  345. WHERE
  346. c_id = $course_id AND
  347. group_id = '".intval($groupInfo['iid'])."'";
  348. $result = Database::query($sql);
  349. $return = Database::fetch_array($result, 'ASSOC');
  350. return $return['number_of_users'];
  351. }
  352. /**
  353. * Get the details of the users in a group
  354. *
  355. * @param integer $from starting row
  356. * @param integer $number_of_items number of items to be displayed
  357. * @param integer $column sorting colum
  358. * @param integer $direction sorting direction
  359. * @return array
  360. *
  361. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  362. * @version April 2008
  363. */
  364. function get_group_user_data($from, $number_of_items, $column, $direction)
  365. {
  366. $groupInfo = GroupManager::get_group_properties(api_get_group_id());
  367. $course_id = api_get_course_int_id();
  368. if (empty($groupInfo) || empty($course_id)) {
  369. return 0;
  370. }
  371. // Database table definition
  372. $table_group_user = Database::get_course_table(TABLE_GROUP_USER);
  373. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  374. $tableGroup = Database::get_course_table(TABLE_GROUP);
  375. // Query
  376. if (api_get_setting('show_email_addresses') === 'true') {
  377. $sql = "SELECT user.id AS col0,
  378. ".(api_is_western_name_order() ?
  379. "user.firstname AS col1,
  380. user.lastname AS col2,"
  381. :
  382. "user.lastname AS col1,
  383. user.firstname AS col2,"
  384. )."
  385. user.email AS col3
  386. FROM $table_user user INNER JOIN
  387. $table_group_user group_rel_user
  388. ON (group_rel_user.user_id = user.id)
  389. INNER JOIN $tableGroup g
  390. ON (group_rel_user.group_id = g.id)
  391. WHERE
  392. group_rel_user.c_id = $course_id AND
  393. g.iid = '".$groupInfo['iid']."'
  394. ORDER BY col$column $direction
  395. LIMIT $from, $number_of_items";
  396. } else {
  397. if (api_is_allowed_to_edit()) {
  398. $sql = "SELECT DISTINCT
  399. u.id AS col0,
  400. ".(api_is_western_name_order() ?
  401. "u.firstname AS col1,
  402. u.lastname AS col2,"
  403. :
  404. "u.lastname AS col1,
  405. u.firstname AS col2,")."
  406. u.email AS col3
  407. FROM $table_user u
  408. INNER JOIN $table_group_user gu
  409. ON (gu.user_id = u.id)
  410. INNER JOIN $tableGroup g
  411. ON (gu.group_id = g.id)
  412. WHERE
  413. g.iid = '".$groupInfo['iid']."' AND
  414. gu.c_id = $course_id
  415. ORDER BY col$column $direction
  416. LIMIT $from, $number_of_items";
  417. } else {
  418. $sql = "SELECT DISTINCT
  419. user.id AS col0,
  420. ". (api_is_western_name_order() ?
  421. "user.firstname AS col1,
  422. user.lastname AS col2 "
  423. :
  424. "user.lastname AS col1,
  425. user.firstname AS col2 "
  426. )."
  427. FROM $table_user user
  428. INNER JOIN $table_group_user group_rel_user
  429. ON (group_rel_user.user_id = user.id)
  430. INNER JOIN $tableGroup g
  431. ON (group_rel_user.group_id = g.id)
  432. WHERE
  433. g.iid = '".$groupInfo['iid']."' AND
  434. group_rel_user.c_id = $course_id AND
  435. group_rel_user.user_id = user.id AND
  436. g.iid = '".$groupInfo['iid']."'
  437. ORDER BY col$column $direction
  438. LIMIT $from, $number_of_items";
  439. }
  440. }
  441. $return = array();
  442. $result = Database::query($sql);
  443. while ($row = Database::fetch_row($result)) {
  444. $return[] = $row;
  445. }
  446. return $return;
  447. }
  448. /**
  449. * Returns a mailto-link
  450. * @param string $email An email-address
  451. * @return string HTML-code with a mailto-link
  452. */
  453. function email_filter($email)
  454. {
  455. return Display :: encrypted_mailto_link($email, $email);
  456. }
  457. /**
  458. * Display a user icon that links to the user page
  459. *
  460. * @param integer $user_id the id of the user
  461. * @return string code
  462. *
  463. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  464. * @version April 2008
  465. */
  466. function user_icon_filter($user_id)
  467. {
  468. $userInfo = api_get_user_info($user_id);
  469. $photo = '<img src="'.$userInfo['avatar'].'" alt="'.$userInfo['complete_name'].'" width="22" height="22" title="'.$userInfo['complete_name'].'" />';
  470. return Display::url($photo, $userInfo['profile_url']);
  471. }
  472. /**
  473. * Return user profile link around the given user name.
  474. *
  475. * The parameters use a trick of the sorteable table, where the first param is
  476. * the original value of the column
  477. * @param string User name (value of the column at the time of calling)
  478. * @param string URL parameters
  479. * @param array Row of the "sortable table" as it is at the time of function call - we extract the user ID from there
  480. * @return string HTML link
  481. */
  482. function user_name_filter($name, $url_params, $row)
  483. {
  484. $userInfo = api_get_user_info($row[0]);
  485. return UserManager::getUserProfileLink($userInfo);
  486. }
  487. if ($origin != 'learnpath') {
  488. Display::display_footer();
  489. }