group_space.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. /* Libraries & config files */
  15. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  16. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  17. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  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. $current_group = GroupManager :: get_group_properties($_SESSION['_gid']);
  22. if (!is_array($current_group) ) {
  23. //display some error message
  24. }
  25. $this_section = SECTION_COURSES;
  26. $nameTools = get_lang('GroupSpace');
  27. $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
  28. /* Ensure all private groups // Juan Carlos Raña Trabado */
  29. $forums_of_groups = get_forums_of_group($current_group['id']);
  30. $forum_state_public = 0;
  31. if (is_array($forums_of_groups)) {
  32. foreach ($forums_of_groups as $key => $value) {
  33. if($value['forum_group_public_private'] == 'public') {
  34. $forum_state_public = 1;
  35. }
  36. }
  37. }
  38. if ($current_group['doc_state'] != 1 && $current_group['calendar_state'] != 1 && $current_group['work_state'] != 1 && $current_group['announcements_state'] != 1 && $current_group['wiki_state'] != 1 && $current_group['chat_state'] != 1 && $forum_state_public != 1) {
  39. if (!api_is_allowed_to_edit(null,true) && !GroupManager :: is_user_in_group($_user['user_id'], $current_group['id'])) {
  40. echo api_not_allowed($print_headers);
  41. }
  42. }
  43. /* Header */
  44. Display::display_header($nameTools.' '.stripslashes($current_group['name']), 'Group');
  45. /* Introduction section (editable by course admin) */
  46. Display::display_introduction_section(group_space_.$_SESSION['_gid']);
  47. /* Actions and Action links */
  48. /*
  49. * User wants to register in this group
  50. */
  51. if (!empty($_GET['selfReg']) && GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  52. GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $current_group['id']);
  53. Display :: display_normal_message(get_lang('GroupNowMember'));
  54. }
  55. /*
  56. * User wants to unregister from this group
  57. */
  58. if (!empty($_GET['selfUnReg']) && GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  59. GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $current_group['id']);
  60. Display::display_normal_message(get_lang('StudentDeletesHimself'));
  61. }
  62. echo '<div class="actions">';
  63. echo '<a href="group.php">'.Display::return_icon('back.png',get_lang('BackToGroupList')).get_lang('BackToGroupList').'</a>';
  64. /*
  65. * Edit the group
  66. */
  67. if (api_is_allowed_to_edit(false, true) or GroupManager :: is_tutor($_user['user_id'])) {
  68. $my_origin = isset($origin) ? $origin : '';
  69. echo Display::return_icon('edit.gif', get_lang('EditGroup')).'<a href="group_edit.php?origin=$my_origin">'.get_lang('EditGroup').'</a>';
  70. }
  71. /*
  72. * Register to group
  73. */
  74. if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  75. echo '<a 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;">'.Display::return_icon('groupadd.gif').get_lang("RegIntoGroup").'</a>';
  76. }
  77. /*
  78. * Unregister from group
  79. */
  80. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  81. echo '<a href="'.api_get_self().'?selfUnReg=1" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."'".')) return false;">'.Display::return_icon('group_delete.gif').get_lang("StudentUnsubscribe").'</a>';
  82. }
  83. echo '&nbsp;</div>';
  84. if (isset($_GET['action'])) {
  85. switch ($_GET['action']) {
  86. case 'show_msg':
  87. Display::display_normal_message(Security::remove_XSS($_GET['msg']));
  88. break;
  89. }
  90. }
  91. /* Main Display Area */
  92. $course_code = $_course['sysCode'];
  93. $is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course($_SESSION['_user']['user_id'], $course_code);
  94. /*
  95. * Group title and comment
  96. */
  97. //api_display_tool_title($nameTools.' '.stripslashes($current_group['name']));
  98. if (!empty($current_group['description'])) {
  99. echo '<blockquote>'.stripslashes($current_group['description']).'</blockquote>';
  100. }
  101. /*
  102. * Group Tools
  103. */
  104. // If the user is subscribed to the group or the user is a tutor of the group then
  105. if (api_is_allowed_to_edit(false, true) OR GroupManager :: is_user_in_group($_SESSION['_user']['user_id'], $current_group['id'])) {
  106. $tools = '';
  107. // Link to the forum of this group
  108. $forums_of_groups = get_forums_of_group($current_group['id']);
  109. if (is_array($forums_of_groups)) {
  110. if ($current_group['forum_state'] != TOOL_NOT_AVAILABLE ) {
  111. foreach ($forums_of_groups as $key => $value) {
  112. if ($value['forum_group_public_private'] == 'public' || (/*!empty($user_subscribe_to_current_group) && */ $value['forum_group_public_private'] == 'private') || !empty($user_is_tutor) || api_is_allowed_to_edit(false, true)) {
  113. $tools .= Display::return_icon('forum.gif', get_lang('GroupForum')) . ' <a href="../forum/viewforum.php?forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'">'.get_lang('Forum').': '.$value['forum_title'].'</a><br />';
  114. //$tools .= Display::return_icon('forum.gif', get_lang('Forum')) . ' <a href="../forum/viewforum.php?forum='.$value['forum_id'].'">'.get_lang('Forum').': '.$value['forum_title'].'</a><br />';
  115. }
  116. }
  117. }
  118. }
  119. if ($current_group['doc_state'] != TOOL_NOT_AVAILABLE ) {
  120. // Link to the documents area of this group
  121. $tools .= '<div style="margin-bottom: 5px;"><a href="../document/document.php?'.api_get_cidreq().'&amp;gidReq='.$current_group['id'].'">'.Display::return_icon('folder_document.gif', get_lang('GroupDocument')).'&nbsp;'.get_lang('GroupDocument').'</a></div>';
  122. }
  123. if ($current_group['calendar_state'] != TOOL_NOT_AVAILABLE) {
  124. // Link to a group-specific part of agenda
  125. $tools .= '<div style="margin-bottom: 5px;"><a href="../calendar/agenda.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'&amp;group='.$current_group['id'].'&amp;acces=0">'.Display::return_icon('agenda.gif', get_lang('GroupCalendar')).'&nbsp;'.get_lang('GroupCalendar').'</a></div>';
  126. }
  127. if ($current_group['work_state'] != TOOL_NOT_AVAILABLE) {
  128. // Link to the works area of this group
  129. $tools .= '<div style="margin-bottom: 5px;"><a href="../work/work.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'">'.Display::return_icon('works.gif', get_lang('GroupWork')).'&nbsp;'.get_lang('GroupWork').'</a></div>';
  130. }
  131. if ($current_group['announcements_state'] != TOOL_NOT_AVAILABLE) {
  132. // Link to a group-specific part of announcements
  133. $tools .= '<div style="margin-bottom: 5px;"><a href="../announcements/announcements.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'">'.Display::return_icon('valves.gif', get_lang('GroupAnnouncements')).'&nbsp;'.get_lang('GroupAnnouncements').'</a></div>';
  134. }
  135. if ($current_group['wiki_state'] != TOOL_NOT_AVAILABLE) {
  136. // Link to the wiki area of this group
  137. $tools .= '<div style="margin-bottom: 5px;"><a href="../wiki/index.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'">'.Display::return_icon('wiki.gif', get_lang('GroupWiki')).'&nbsp;'.get_lang('GroupWiki').'</a></div>';
  138. }
  139. if ($current_group['chat_state'] != TOOL_NOT_AVAILABLE) {
  140. // Link to the chat area of this group
  141. if (api_get_course_setting('allow_open_chat_window')) {
  142. $tools .= "<div style='margin-bottom: 5px;'><a href=\"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') \" >".Display::return_icon('chat.gif', get_lang('Chat'))."&nbsp;".get_lang('Chat')."</a></div>";
  143. } else {
  144. $tools .= "<div style='margin-bottom: 5px;'><a href=\"../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."\">".Display::return_icon('chat.gif', get_lang('Chat'))."&nbsp;".get_lang('Chat')."</a></div>";
  145. }
  146. }
  147. echo '<div class="actions-message" style="margin-bottom:4px;"><b>'.get_lang('Tools').':</b></div>';
  148. if (!empty($tools)) {
  149. echo '<div style="margin-left:5px;">'.$tools.'</div>';
  150. }
  151. } else {
  152. $tools = '';
  153. // Link to the forum of this group
  154. $forums_of_groups = get_forums_of_group($current_group['id']);
  155. if (is_array($forums_of_groups)) {
  156. if ( $current_group['forum_state'] == TOOL_PUBLIC ) {
  157. foreach ($forums_of_groups as $key => $value) {
  158. if ($value['forum_group_public_private'] == 'public' ) {
  159. $tools.= Display::return_icon('forum.gif', get_lang('GroupForum')) . ' <a href="../forum/viewforum.php?forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'">'.$value['forum_title'].'</a><br />';
  160. //$tools.= Display::return_icon('forum.gif', get_lang('Forum')) . ' <a href="../forum/viewforum.php?forum='.$value['forum_id'].'">'.get_lang("Forum").': '.$value['forum_title'].'</a><br />';
  161. }
  162. }
  163. }
  164. }
  165. if ($current_group['doc_state'] == TOOL_PUBLIC) {
  166. // Link to the documents area of this group
  167. $tools .= '<a href="../document/document.php?'.api_get_cidreq().'&amp;gidReq='.$current_group['id'].'&amp;origin='.$origin.'">'.Display::return_icon('folder_document.gif', get_lang('GroupDocument')).'&nbsp;'.get_lang('GroupDocument').'</a><br />';
  168. }
  169. if ($current_group['calendar_state'] == TOOL_PUBLIC) {
  170. // Link to a group-specific part of agenda
  171. $tools .= '<a href="../calendar/agenda.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'&amp;group='.$current_group['id'].'">'.Display::return_icon('agenda.gif', get_lang('GroupCalendar')).'&nbsp;'.get_lang('GroupCalendar').'</a><br />';
  172. }
  173. if ($current_group['work_state'] == TOOL_PUBLIC) {
  174. // Link to the works area of this group
  175. $tools .= '<a href="../work/work.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'">'.Display::return_icon('works.gif', get_lang('GroupWork')).'&nbsp;'.get_lang('GroupWork').'</a><br />';
  176. }
  177. if ($current_group['announcements_state'] == TOOL_PUBLIC) {
  178. // Link to a group-specific part of announcements
  179. $tools .= '<a href="../announcements/announcements.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'&amp;group='.$current_group['id'].'">'.Display::return_icon('valves.gif', get_lang('GroupAnnouncements')).'&nbsp;'.get_lang('GroupAnnouncements').'</a><br />';
  180. }
  181. if ($current_group['wiki_state'] == TOOL_PUBLIC) {
  182. // Link to the wiki area of this group
  183. $tools .= '<a href="../wiki/index.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'">'.Display::return_icon('wiki.gif', get_lang('GroupWiki')).'&nbsp;'.get_lang('GroupWiki').'</a><br />';
  184. }
  185. if ($current_group['chat_state'] == TOOL_PUBLIC ) {
  186. // Link to the chat area of this group
  187. if (api_get_course_setting('allow_open_chat_window')) {
  188. $tools .= "<div style='margin-bottom: 5px;'><a href=\"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') \" >".Display::return_icon('chat.gif', get_lang("Chat"))."&nbsp;".get_lang("Chat")."</a></div>";
  189. } else {
  190. $tools .= "<div style='margin-bottom: 5px;'><a href=\"../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."\">".Display::return_icon('chat.gif', get_lang("Chat"))."&nbsp;".get_lang("Chat")."</a></div>";
  191. }
  192. }
  193. echo '<br />';
  194. echo '<div class="actions-message" style="margin-bottom:4px;"><b>'.get_lang('Tools').':</b></div>';
  195. if (!empty($tools)) {
  196. echo '<div style="margin-left:5px;">'.$tools.'</div>';
  197. }
  198. }
  199. /*
  200. * List all the tutors of the current group
  201. */
  202. $tutors = GroupManager::get_subscribed_tutors($current_group['id']);
  203. $tutor_info = '';
  204. if (count($tutors) == 0) {
  205. $tutor_info = get_lang('GroupNoneMasc');
  206. } else {
  207. isset($origin)?$my_origin = $origin:$my_origin='';
  208. foreach($tutors as $index => $tutor) {
  209. $image_path = UserManager::get_user_picture_path_by_id($tutor['user_id'], 'web', false, true);
  210. $image_repository = $image_path['dir'];
  211. $existing_image = $image_path['file'];
  212. $photo= '<img src="'.$image_repository.$existing_image.'" align="absbottom" alt="'.api_get_person_name($tutor['firstname'], $tutor['lastname']).'" width="32" height="32" title="'.api_get_person_name($tutor['firstname'], $tutor['lastname']).'" />';
  213. $tutor_info .= '<div style="margin-bottom: 5px;"><a href="../user/userInfo.php?origin='.$my_origin.'&amp;uInfo='.$tutor['user_id'].'">'.$photo.'&nbsp;'.api_get_person_name($tutor['firstname'], $tutor['lastname']).'</a></div>';
  214. }
  215. }
  216. echo '<div class="actions-message" style="margin-bottom:4px;"><b>'.get_lang('GroupTutors').':</b></div>';
  217. if (!empty($tutor_info)) {
  218. echo '<div style="margin-left:5px;">'.$tutor_info.'</div>';
  219. }
  220. echo '<br />';
  221. /*
  222. * List all the members of the current group
  223. */
  224. echo '<b>'.get_lang("GroupMembers").':</b>';
  225. $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);
  226. $my_cidreq = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
  227. $my_origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  228. $my_gidreq = isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : '';
  229. $parameters = array('cidReq' => $my_cidreq, 'origin'=> $my_origin, 'gidReq' => $my_gidreq);
  230. $table->set_additional_parameters($parameters);
  231. $table->set_header(0, '');
  232. if (api_is_western_name_order()) {
  233. $table->set_header(1, get_lang('FirstName'));
  234. $table->set_header(2, get_lang('LastName'));
  235. } else {
  236. $table->set_header(1, get_lang('LastName'));
  237. $table->set_header(2, get_lang('FirstName'));
  238. }
  239. if (api_get_setting('show_email_addresses') == 'true') {
  240. $table->set_header(3, get_lang('Email'));
  241. $table->set_column_filter(3, 'email_filter');
  242. } else {
  243. if (api_is_allowed_to_edit() == 'true') {
  244. $table->set_header(3, get_lang('Email'));
  245. $table->set_column_filter(3, 'email_filter');
  246. }
  247. }
  248. $table->set_column_filter(0, 'user_icon_filter');
  249. $table->display();
  250. /**
  251. * Get the number of subscribed users to the group
  252. *
  253. * @return integer
  254. *
  255. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  256. * @version April 2008
  257. */
  258. function get_number_of_group_users() {
  259. global $current_group;
  260. // Database table definition
  261. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  262. // Query
  263. $sql = "SELECT count(id) AS number_of_users
  264. FROM ".$table_group_user."
  265. WHERE group_id='".Database::escape_string($current_group['id'])."'";
  266. $result = Database::query($sql);
  267. $return = Database::fetch_array($result,'ASSOC');
  268. return $return['number_of_users'];
  269. }
  270. /**
  271. * Get the details of the users in a group
  272. *
  273. * @param integer $from starting row
  274. * @param integer $number_of_items number of items to be displayed
  275. * @param integer $column sorting colum
  276. * @param integer $direction sorting direction
  277. * @return array
  278. *
  279. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  280. * @version April 2008
  281. */
  282. function get_group_user_data($from, $number_of_items, $column, $direction) {
  283. global $current_group;
  284. // Database table definition
  285. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  286. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  287. // Query
  288. if (api_get_setting('show_email_addresses') == 'true') {
  289. $sql = "SELECT
  290. user.user_id AS col0,
  291. ".(api_is_western_name_order() ?
  292. "user.firstname AS col1,
  293. user.lastname AS col2,"
  294. :
  295. "user.lastname AS col1,
  296. user.firstname AS col2,"
  297. )."
  298. user.email AS col3
  299. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  300. WHERE group_rel_user.user_id = user.user_id
  301. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  302. $sql .= " ORDER BY col$column $direction ";
  303. $sql .= " LIMIT $from,$number_of_items";
  304. } else {
  305. if (api_is_allowed_to_edit()) {
  306. $sql = "SELECT
  307. user.user_id AS col0,
  308. ".(api_is_western_name_order() ?
  309. "user.firstname AS col1,
  310. user.lastname AS col2,"
  311. :
  312. "user.lastname AS col1,
  313. user.firstname AS col2,"
  314. )."
  315. user.email AS col3
  316. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  317. WHERE group_rel_user.user_id = user.user_id
  318. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  319. $sql .= " ORDER BY col$column $direction ";
  320. $sql .= " LIMIT $from,$number_of_items";
  321. } else {
  322. $sql = "SELECT
  323. user.user_id AS col0,
  324. ". (api_is_western_name_order() ?
  325. "user.firstname AS col1,
  326. user.lastname AS col2 "
  327. :
  328. "user.lastname AS col1,
  329. user.firstname AS col2 "
  330. )."
  331. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  332. WHERE group_rel_user.user_id = user.user_id
  333. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  334. $sql .= " ORDER BY col$column $direction ";
  335. $sql .= " LIMIT $from,$number_of_items";
  336. }
  337. }
  338. $return = array();
  339. $result = Database::query($sql);
  340. while ($row = Database::fetch_row($result)) {
  341. $return[] = $row;
  342. }
  343. return $return;
  344. }
  345. /**
  346. * Returns a mailto-link
  347. * @param string $email An email-address
  348. * @return string HTML-code with a mailto-link
  349. */
  350. function email_filter($email) {
  351. return Display :: encrypted_mailto_link($email, $email);
  352. }
  353. /**
  354. * Display a user icon that links to the user page
  355. *
  356. * @param integer $user_id the id of the user
  357. * @return html code
  358. *
  359. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  360. * @version April 2008
  361. */
  362. function user_icon_filter($user_id) {
  363. global $origin;
  364. $userinfo = Database::get_user_info_from_id($user_id);
  365. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
  366. $image_repository = $image_path['dir'];
  367. $existing_image = $image_path['file'];
  368. $photo = '<center><img src="'.$image_repository.$existing_image.'" alt="'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'" width="22" height="22" title="'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'" /></center>';
  369. return '<a href="../user/userInfo.php?origin='.$origin.'&amp;uInfo='.$user_id.'">'.$photo;
  370. }
  371. // Footer
  372. $orig = isset($origin) ? $origin : '';
  373. if ($orig != 'learnpath') {
  374. Display::display_footer();
  375. }