group_space.php 19 KB

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