group_space.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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['iid']);
  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['iid'])
  41. ) {
  42. GroupManager :: subscribe_users($user_id, $current_group['iid']);
  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['iid'])
  50. ) {
  51. GroupManager::unsubscribe_users($user_id, $current_group['iid']);
  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['iid'])) {
  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['iid'])) {
  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(), $current_group['iid'])
  79. ) {
  80. $edit_url = '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?'.api_get_cidreq().'">'.
  81. Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
  82. }
  83. echo Display::page_header(
  84. Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group
  85. );
  86. if (!empty($current_group['description'])) {
  87. echo '<p>'.Security::remove_XSS($current_group['description']).'</p>';
  88. }
  89. /*
  90. * Group Tools
  91. */
  92. // If the user is subscribed to the group or the user is a tutor of the group then
  93. if (api_is_allowed_to_edit(false, true) ||
  94. GroupManager::is_user_in_group(api_get_user_id(), $current_group['iid'])
  95. ) {
  96. $actions_array = array();
  97. // Link to the forum of this group
  98. $forums_of_groups = get_forums_of_group($current_group['iid']);
  99. if (is_array($forums_of_groups)) {
  100. if ($current_group['forum_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  101. foreach ($forums_of_groups as $key => $value) {
  102. if ($value['forum_group_public_private'] == 'public' ||
  103. ($value['forum_group_public_private'] == 'private') ||
  104. !empty($user_is_tutor) ||
  105. api_is_allowed_to_edit(false, true)
  106. ) {
  107. $actions_array[] = array(
  108. 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$value['forum_id'].'&'.api_get_cidreq().'&origin=group',
  109. 'content' => Display::return_icon(
  110. 'forum.png',
  111. get_lang('Forum').': '.$value['forum_title'],
  112. array(),
  113. 32
  114. ),
  115. );
  116. }
  117. }
  118. }
  119. }
  120. if ($current_group['doc_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  121. // Link to the documents area of this group
  122. $actions_array[] = array(
  123. 'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(),
  124. 'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32)
  125. );
  126. }
  127. if ($current_group['calendar_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  128. $groupFilter = null;
  129. if (!empty($group_id)) {
  130. $groupFilter = "&type=course&user_id=GROUP:$group_id";
  131. }
  132. // Link to a group-specific part of agenda
  133. $actions_array[] = array(
  134. 'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?'.api_get_cidreq().$groupFilter,
  135. 'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32)
  136. );
  137. }
  138. if ($current_group['work_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  139. // Link to the works area of this group
  140. $actions_array[] = array(
  141. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  142. 'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), 32)
  143. );
  144. }
  145. if ($current_group['announcements_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  146. // Link to a group-specific part of announcements
  147. $actions_array[] = array(
  148. 'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  149. 'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32)
  150. );
  151. }
  152. if ($current_group['wiki_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  153. // Link to the wiki area of this group
  154. $actions_array[] = array(
  155. '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'],
  156. 'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
  157. );
  158. }
  159. if ($current_group['chat_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
  160. // Link to the chat area of this group
  161. if (api_get_course_setting('allow_open_chat_window')) {
  162. $actions_array[] = array(
  163. 'url' => "javascript: void(0);",
  164. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32),
  165. 'url_attributes' => array(
  166. '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')"
  167. )
  168. );
  169. } else {
  170. $actions_array[] = array(
  171. 'url' => api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id'],
  172. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  173. );
  174. }
  175. }
  176. $enabled = api_get_plugin_setting('bbb', 'tool_enable');
  177. if ($enabled === 'true') {
  178. $bbb = new bbb();
  179. if ($bbb->hasGroupSupport()) {
  180. $actions_array[] = array(
  181. 'url' => api_get_path(WEB_PLUGIN_PATH)."bbb/start.php?".api_get_cidreq(),
  182. 'content' => Display::return_icon('bbb.png', get_lang('VideoConference'), array(), 32)
  183. );
  184. }
  185. }
  186. if (!empty($actions_array)) {
  187. echo Display::actions($actions_array);
  188. }
  189. } else {
  190. $actions_array = array();
  191. // Link to the forum of this group
  192. $forums_of_groups = get_forums_of_group($current_group['iid']);
  193. if (is_array($forums_of_groups)) {
  194. if ($current_group['forum_state'] == GroupManager::TOOL_PUBLIC) {
  195. foreach ($forums_of_groups as $key => $value) {
  196. if ($value['forum_group_public_private'] == 'public') {
  197. $actions_array[] = array(
  198. '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',
  199. 'content' => Display::return_icon('forum.png', get_lang('GroupForum'), array(), ICON_SIZE_MEDIUM)
  200. );
  201. }
  202. }
  203. }
  204. }
  205. if ($current_group['doc_state'] == GroupManager::TOOL_PUBLIC) {
  206. // Link to the documents area of this group
  207. $actions_array[] = array(
  208. 'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(),
  209. 'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_MEDIUM)
  210. );
  211. }
  212. if ($current_group['calendar_state'] == GroupManager::TOOL_PUBLIC) {
  213. // Link to a group-specific part of agenda
  214. $actions_array[] = array(
  215. 'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda.php?'.api_get_cidreq(),
  216. 'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_MEDIUM)
  217. );
  218. }
  219. if ($current_group['work_state'] == GroupManager::TOOL_PUBLIC) {
  220. // Link to the works area of this group
  221. $actions_array[] = array(
  222. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  223. 'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_MEDIUM)
  224. );
  225. }
  226. if ($current_group['announcements_state'] == GroupManager::TOOL_PUBLIC) {
  227. // Link to a group-specific part of announcements
  228. $actions_array[] = array(
  229. 'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  230. 'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_MEDIUM)
  231. );
  232. }
  233. if ($current_group['wiki_state'] == GroupManager::TOOL_PUBLIC) {
  234. // Link to the wiki area of this group
  235. $actions_array[] = array(
  236. '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'],
  237. 'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
  238. );
  239. }
  240. if ($current_group['chat_state'] == GroupManager::TOOL_PUBLIC) {
  241. // Link to the chat area of this group
  242. if (api_get_course_setting('allow_open_chat_window')) {
  243. $actions_array[] = array(
  244. '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') \"",
  245. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  246. );
  247. } else {
  248. $actions_array[] = array(
  249. 'url' => api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id'],
  250. 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
  251. );
  252. }
  253. }
  254. if (!empty($actions_array)) {
  255. echo Display::actions($actions_array);
  256. }
  257. }
  258. /*
  259. * List all the tutors of the current group
  260. */
  261. $tutors = GroupManager::get_subscribed_tutors($current_group['iid']);
  262. $tutor_info = '';
  263. if (count($tutors) == 0) {
  264. $tutor_info = get_lang('GroupNoneMasc');
  265. } else {
  266. $tutor_info .= '<ul class="thumbnails">';
  267. foreach ($tutors as $index => $tutor) {
  268. $userInfo = api_get_user_info($tutor['user_id']);
  269. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userInfo['username']), ENT_QUOTES);
  270. $completeName = $userInfo['complete_name'];
  271. $photo = '<img src="'.$userInfo['avatar'].'" alt="'.$completeName.'" width="32" height="32" title="'.$completeName.'" />';
  272. $tutor_info .= '<li>';
  273. $tutor_info .= Display::url(
  274. $userInfo['complete_name'],
  275. $userInfo['profile_url']
  276. );
  277. $tutor_info .= '</li>';
  278. }
  279. $tutor_info .= '</ul>';
  280. }
  281. echo Display::page_subheader(get_lang('GroupTutors'));
  282. if (!empty($tutor_info)) {
  283. echo $tutor_info;
  284. }
  285. echo '<br />';
  286. /*
  287. * List all the members of the current group
  288. */
  289. echo Display::page_subheader(get_lang('GroupMembers'));
  290. $table = new SortableTable(
  291. 'group_users',
  292. 'get_number_of_group_users',
  293. 'get_group_user_data',
  294. (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1
  295. );
  296. $my_cidreq = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
  297. $my_origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  298. $my_gidreq = isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : '';
  299. $parameters = array('cidReq' => $my_cidreq, 'origin'=> $my_origin, 'gidReq' => $my_gidreq);
  300. $table->set_additional_parameters($parameters);
  301. $table->set_header(0, '');
  302. if (api_is_western_name_order()) {
  303. $table->set_header(1, get_lang('FirstName'));
  304. $table->set_header(2, get_lang('LastName'));
  305. } else {
  306. $table->set_header(1, get_lang('LastName'));
  307. $table->set_header(2, get_lang('FirstName'));
  308. }
  309. if (api_get_setting('show_email_addresses') == 'true') {
  310. $table->set_header(3, get_lang('Email'));
  311. $table->set_column_filter(3, 'email_filter');
  312. } else {
  313. if (api_is_allowed_to_edit() == 'true') {
  314. $table->set_header(3, get_lang('Email'));
  315. $table->set_column_filter(3, 'email_filter');
  316. }
  317. }
  318. //the order of these calls is important
  319. //$table->set_column_filter(1, 'user_name_filter');
  320. //$table->set_column_filter(2, 'user_name_filter');
  321. $table->set_column_filter(0, 'user_icon_filter');
  322. $table->display();
  323. /**
  324. * Get the number of subscribed users to the group
  325. *
  326. * @return integer
  327. *
  328. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  329. * @version April 2008
  330. */
  331. function get_number_of_group_users()
  332. {
  333. $groupInfo = GroupManager::get_group_properties(api_get_group_id());
  334. $course_id = api_get_course_int_id();
  335. if (empty($groupInfo) || empty($course_id)) {
  336. return 0;
  337. }
  338. // Database table definition
  339. $table = Database :: get_course_table(TABLE_GROUP_USER);
  340. // Query
  341. $sql = "SELECT count(iid) AS number_of_users
  342. FROM $table
  343. WHERE
  344. c_id = $course_id AND
  345. group_id = '".intval($groupInfo['iid'])."'";
  346. $result = Database::query($sql);
  347. $return = Database::fetch_array($result, 'ASSOC');
  348. return $return['number_of_users'];
  349. }
  350. /**
  351. * Get the details of the users in a group
  352. *
  353. * @param integer $from starting row
  354. * @param integer $number_of_items number of items to be displayed
  355. * @param integer $column sorting colum
  356. * @param integer $direction sorting direction
  357. * @return array
  358. *
  359. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  360. * @version April 2008
  361. */
  362. function get_group_user_data($from, $number_of_items, $column, $direction)
  363. {
  364. $groupInfo = GroupManager::get_group_properties(api_get_group_id());
  365. $course_id = api_get_course_int_id();
  366. if (empty($groupInfo) || empty($course_id)) {
  367. return 0;
  368. }
  369. // Database table definition
  370. $table_group_user = Database:: get_course_table(TABLE_GROUP_USER);
  371. $table_user = Database:: get_main_table(TABLE_MAIN_USER);
  372. // Query
  373. if (api_get_setting('show_email_addresses') === 'true') {
  374. $sql = "SELECT user.id AS col0,
  375. ".(api_is_western_name_order() ?
  376. "user.firstname AS col1,
  377. user.lastname AS col2,"
  378. :
  379. "user.lastname AS col1,
  380. user.firstname AS col2,"
  381. )."
  382. user.email AS col3
  383. FROM $table_user user,
  384. $table_group_user group_rel_user
  385. WHERE
  386. group_rel_user.c_id = $course_id AND
  387. group_rel_user.user_id = user.id AND
  388. group_rel_user.group_id = '".$groupInfo['iid']."'
  389. ORDER BY col$column $direction
  390. LIMIT $from, $number_of_items";
  391. } else {
  392. if (api_is_allowed_to_edit()) {
  393. $sql = "SELECT DISTINCT
  394. u.id AS col0,
  395. ".(api_is_western_name_order() ?
  396. "u.firstname AS col1,
  397. u.lastname AS col2,"
  398. :
  399. "u.lastname AS col1,
  400. u.firstname AS col2,")."
  401. u.email AS col3
  402. FROM $table_user u
  403. INNER JOIN $table_group_user gu
  404. ON (gu.user_id = u.id) AND gu.c_id = $course_id
  405. WHERE gu.group_id = '".$groupInfo['iid']."'
  406. ORDER BY col$column $direction
  407. LIMIT $from, $number_of_items";
  408. } else {
  409. $sql = "SELECT DISTINCT
  410. user.id AS col0,
  411. ". (api_is_western_name_order() ?
  412. "user.firstname AS col1,
  413. user.lastname AS col2 "
  414. :
  415. "user.lastname AS col1,
  416. user.firstname AS col2 "
  417. )."
  418. FROM $table_user user, $table_group_user group_rel_user
  419. WHERE
  420. group_rel_user.c_id = $course_id AND
  421. group_rel_user.user_id = user.id AND
  422. group_rel_user.group_id = '".$groupInfo['iid']."'
  423. ORDER BY col$column $direction
  424. LIMIT $from, $number_of_items";
  425. }
  426. }
  427. $return = array();
  428. $result = Database::query($sql);
  429. while ($row = Database::fetch_row($result)) {
  430. $return[] = $row;
  431. }
  432. return $return;
  433. }
  434. /**
  435. * Returns a mailto-link
  436. * @param string $email An email-address
  437. * @return string HTML-code with a mailto-link
  438. */
  439. function email_filter($email)
  440. {
  441. return Display :: encrypted_mailto_link($email, $email);
  442. }
  443. /**
  444. * Display a user icon that links to the user page
  445. *
  446. * @param integer $user_id the id of the user
  447. * @return string code
  448. *
  449. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  450. * @version April 2008
  451. */
  452. function user_icon_filter($user_id)
  453. {
  454. $userInfo = api_get_user_info($user_id);
  455. $photo = '<img src="'.$userInfo['avatar'].'" alt="'.$userInfo['complete_name'].'" width="22" height="22" title="'.$userInfo['complete_name'].'" />';
  456. return Display::url($photo, $userInfo['profile_url']);
  457. }
  458. /**
  459. * Return user profile link around the given user name.
  460. *
  461. * The parameters use a trick of the sorteable table, where the first param is
  462. * the original value of the column
  463. * @param string User name (value of the column at the time of calling)
  464. * @param string URL parameters
  465. * @param array Row of the "sortable table" as it is at the time of function call - we extract the user ID from there
  466. * @return string HTML link
  467. */
  468. function user_name_filter($name, $url_params, $row)
  469. {
  470. $userInfo = api_get_user_info($row[0]);
  471. return UserManager::getUserProfileLink($userInfo);
  472. }
  473. // Footer
  474. $orig = isset($origin) ? $origin : '';
  475. if ($orig != 'learnpath') {
  476. Display::display_footer();
  477. }