group_space.php 19 KB

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