group_space.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <?php //$Id: group_space.php 18319 2009-02-07 00:03:42Z herodoto $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. Copyright (c) Bart Mollet
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * This script shows the group space for one specific group, possibly displaying
  23. * a list of users in the group, subscribe or unsubscribe option, tutors...
  24. *
  25. * @package dokeos.group
  26. * @todo Display error message if no group ID specified
  27. ==============================================================================
  28. */
  29. /*
  30. ==============================================================================
  31. INIT SECTION
  32. ==============================================================================
  33. */
  34. // name of the language file that needs to be included
  35. $language_file = "group";
  36. include ('../inc/global.inc.php');
  37. /*
  38. -----------------------------------------------------------
  39. Libraries & config files
  40. -----------------------------------------------------------
  41. */
  42. include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  43. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  44. include_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  45. require_once (api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php');
  46. require_once (api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php');
  47. /*
  48. ==============================================================================
  49. MAIN CODE
  50. ==============================================================================
  51. */
  52. $current_group = GroupManager :: get_group_properties($_SESSION['_gid']);
  53. if(!is_array($current_group) ) {
  54. //display some error message
  55. }
  56. $nameTools = get_lang("GroupSpace");
  57. $interbreadcrumb[] = array ("url" => "group.php", "name" => get_lang("Groups"));
  58. /*
  59. -----------------------------------------------------------
  60. Ensure all private groups // Juan Carlos Raña Trabado
  61. -----------------------------------------------------------
  62. */
  63. $forums_of_groups = get_forums_of_group($current_group['id']);
  64. $forum_state_public=0;
  65. if (is_array($forums_of_groups)) {
  66. foreach ($forums_of_groups as $key => $value) {
  67. if($value['forum_group_public_private'] == 'public') {
  68. $forum_state_public=1;
  69. }
  70. }
  71. }
  72. if ($current_group['doc_state']!=1 and $current_group['calendar_state']!=1 and $current_group['work_state']!=1 and $current_group['announcements_state']!=1 and $current_group['wiki_state']!=1 and $forum_state_public!=1) {
  73. if (!api_is_allowed_to_edit() and !GroupManager :: is_user_in_group($_user['user_id'], $current_group['id'])) {
  74. echo api_not_allowed($print_headers);
  75. }
  76. }
  77. /*
  78. -----------------------------------------------------------
  79. Header
  80. -----------------------------------------------------------
  81. */
  82. Display::display_header($nameTools,"Group");
  83. /*
  84. -----------------------------------------------------------
  85. Introduction section
  86. (editable by course admin)
  87. -----------------------------------------------------------
  88. */
  89. $fck_attribute['Width'] = '100%';
  90. $fck_attribute['Height'] = '300';
  91. $fck_attribute['ToolbarSet'] = 'Introduction';
  92. Display::display_introduction_section(group_space_.$_SESSION['_gid']);
  93. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  94. /*
  95. -----------------------------------------------------------
  96. Actions and Action links
  97. -----------------------------------------------------------
  98. */
  99. /*
  100. * User wants to register in this group
  101. */
  102. if (!empty($_GET['selfReg']) && GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  103. GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $current_group['id']);
  104. Display :: display_normal_message(get_lang('GroupNowMember'));
  105. }
  106. /*
  107. * User wants to unregister from this group
  108. */
  109. if (!empty($_GET['selfUnReg']) && GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  110. GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $current_group['id']);
  111. Display::display_normal_message(get_lang('StudentDeletesHimself'));
  112. }
  113. /*
  114. * Edit the group
  115. */
  116. if (api_is_allowed_to_edit(false,true) or GroupManager :: is_tutor($_user['user_id'])) {
  117. isset($origin)?$my_origin = $origin:$my_origin='';
  118. echo Display::return_icon('settings.gif', get_lang("EditGroup"))."<a href=\"group_edit.php?origin=$my_origin\">".get_lang("EditGroup")."</a><br/><br/>";
  119. }
  120. /*
  121. * Register to group
  122. */
  123. if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  124. echo '<p align="right"><a href="'.api_get_self().'?selfReg=1&amp;group_id='.$current_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.get_lang("RegIntoGroup").'</a></p>';
  125. }
  126. /*
  127. * Unregister from group
  128. */
  129. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  130. echo '<p align="right"><a href="'.api_get_self().'?selfUnReg=1" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.get_lang("StudentUnsubscribe").'</a></p>';
  131. }
  132. if( isset($_GET['action'])) {
  133. switch( $_GET['action']) {
  134. case 'show_msg':
  135. Display::display_normal_message($_GET['msg']);
  136. break;
  137. }
  138. }
  139. /*
  140. -----------------------------------------------------------
  141. Main Display Area
  142. -----------------------------------------------------------
  143. */
  144. $course_code = $_course['sysCode'];
  145. $is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course($_SESSION['_user']['user_id'], $course_code);
  146. /*
  147. * Group title and comment
  148. */
  149. api_display_tool_title($nameTools.' '.stripslashes($current_group['name']));
  150. if (!empty($current_group['description'])) {
  151. echo '<blockquote>'.stripslashes($current_group['description']).'</blockquote>';
  152. }
  153. /*
  154. * Group Tools
  155. */
  156. // If the user is subscribed to the group or the user is a tutor of the group then
  157. if (api_is_allowed_to_edit(false,true) OR GroupManager :: is_user_in_group($_SESSION['_user']['user_id'], $current_group['id'])) {
  158. $tools = '';
  159. // link to the forum of this group
  160. $forums_of_groups = get_forums_of_group($current_group['id']);
  161. if (is_array($forums_of_groups)) {
  162. if ( $current_group['forum_state'] != TOOL_NOT_AVAILABLE ) {
  163. foreach ($forums_of_groups as $key => $value) {
  164. 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)) {
  165. $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").'</a><br />';
  166. //$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 />';
  167. }
  168. }
  169. }
  170. }
  171. if( $current_group['doc_state'] != TOOL_NOT_AVAILABLE )
  172. {
  173. // link to the documents area of this group
  174. $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>";
  175. }
  176. if ( $current_group['calendar_state'] != TOOL_NOT_AVAILABLE)
  177. {
  178. //link to a group-specific part of agenda
  179. $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>";
  180. }
  181. if ( $current_group['work_state'] != TOOL_NOT_AVAILABLE)
  182. {
  183. //link to the works area of this group
  184. $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>";
  185. }
  186. if ( $current_group['announcements_state'] != TOOL_NOT_AVAILABLE)
  187. {
  188. //link to a group-specific part of announcements
  189. $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>";
  190. }
  191. if ( $current_group['wiki_state'] != TOOL_NOT_AVAILABLE)
  192. {
  193. //link to the wiki area of this group
  194. $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>";
  195. }
  196. echo '<b>'.get_lang("Tools").':</b>';
  197. if (!empty($tools))
  198. {
  199. echo '<blockquote>'.$tools.'</blockquote>';
  200. }
  201. } else {
  202. $tools = '';
  203. // link to the forum of this group
  204. $forums_of_groups = get_forums_of_group($current_group['id']);
  205. if (is_array($forums_of_groups)) {
  206. if ( $current_group['forum_state'] == TOOL_PUBLIC ) {
  207. foreach ($forums_of_groups as $key => $value) {
  208. if ($value['forum_group_public_private'] == 'public' ) {
  209. $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 />';
  210. //$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 />';
  211. }
  212. }
  213. }
  214. }
  215. if( $current_group['doc_state'] == TOOL_PUBLIC )
  216. {
  217. // link to the documents area of this group
  218. $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/>";
  219. }
  220. if ( $current_group['calendar_state'] == TOOL_PUBLIC )
  221. {
  222. //link to a group-specific part of agenda
  223. $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/>";
  224. }
  225. if ( $current_group['work_state'] == TOOL_PUBLIC )
  226. {
  227. //link to the works area of this group
  228. $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/>";
  229. }
  230. if ( $current_group['announcements_state'] == TOOL_PUBLIC)
  231. {
  232. //link to a group-specific part of announcements
  233. $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/>";
  234. }
  235. if ( $current_group['wiki_state'] == TOOL_PUBLIC )
  236. {
  237. //link to the wiki area of this group
  238. $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/>";
  239. }
  240. echo '<b>'.get_lang("Tools").':</b>';
  241. if (!empty($tools))
  242. {
  243. echo '<blockquote>'.$tools.'</blockquote>';
  244. }
  245. }
  246. /*
  247. * list all the tutors of the current group
  248. */
  249. $tutors = GroupManager::get_subscribed_tutors($current_group['id']);
  250. $tutor_info = '';
  251. if (count($tutors) == 0)
  252. {
  253. $tutor_info = get_lang("GroupNoneMasc");
  254. }
  255. else
  256. {
  257. isset($origin)?$my_origin = $origin:$my_origin='';
  258. foreach($tutors as $index => $tutor)
  259. {
  260. $tutor_info .= "<div style='margin-bottom: 5px;'><a href='../user/userInfo.php?origin=".$my_origin."&amp;uInfo=".$tutor['user_id']."'><img src='../img/coachs.gif' align='absbottom'>&nbsp;".$tutor['firstname']." ".$tutor['lastname']."</a></div>";
  261. }
  262. }
  263. echo '<b>'.get_lang("GroupTutors").':</b>';
  264. if (!empty($tutor_info))
  265. {
  266. echo '<blockquote>'.$tutor_info.'</blockquote>';
  267. }
  268. /*
  269. * list all the members of the current group
  270. */
  271. echo '<b>'.get_lang("GroupMembers").':</b>';
  272. $table = new SortableTable('group_users', 'get_number_of_group_users', 'get_group_user_data',2);
  273. $my_cidreq=isset($_GET['cidReq']) ? $_GET['cidReq'] : '';
  274. $my_origin=isset($_GET['origin']) ? $_GET['origin'] : '';
  275. $my_gidreq=isset($_GET['gidReq']) ? $_GET['gidReq'] : '';
  276. $parameters = array('cidReq' => $my_cidreq, 'origin'=> $my_origin, 'gidReq' => $my_gidreq);
  277. $table->set_additional_parameters($parameters);
  278. $table->set_header(0, '');
  279. $table->set_header(1, get_lang('LastName'));
  280. $table->set_header(2, get_lang('FirstName'));
  281. if (api_get_setting("show_email_addresses") == "true")
  282. {
  283. $table->set_header(3, get_lang('Email'));
  284. $table->set_column_filter(3, 'email_filter');
  285. }
  286. else
  287. {
  288. if (api_is_allowed_to_edit()=="true")
  289. {
  290. $table->set_header(3, get_lang('Email'));
  291. $table->set_column_filter(3, 'email_filter');
  292. }
  293. }
  294. $table->set_column_filter(0, 'user_icon_filter');
  295. $table->display();
  296. /**
  297. * Get the number of subscribed users to the group
  298. *
  299. * @return integer
  300. *
  301. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  302. * @version April 2008
  303. */
  304. function get_number_of_group_users()
  305. {
  306. global $current_group;
  307. // Database table definition
  308. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  309. // query
  310. $sql = "SELECT count(id) AS number_of_users
  311. FROM ".$table_group_user."
  312. WHERE group_id='".Database::escape_string($current_group['id'])."'";
  313. $result = api_sql_query($sql,__FILE__,__LINE__);
  314. $return = Database::fetch_array($result,'ASSOC');
  315. return $return['number_of_users'];
  316. }
  317. /**
  318. * Get the details of the users in a group
  319. *
  320. * @param integer $from starting row
  321. * @param integer $number_of_items number of items to be displayed
  322. * @param integer $column sorting colum
  323. * @param integer $direction sorting direction
  324. * @return array
  325. *
  326. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  327. * @version April 2008
  328. */
  329. function get_group_user_data($from, $number_of_items, $column, $direction)
  330. {
  331. global $current_group;
  332. // Database table definition
  333. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  334. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  335. // query
  336. if (api_get_setting("show_email_addresses") == "true") {
  337. $sql = "SELECT
  338. user.user_id AS col0,
  339. user.lastname AS col1,
  340. user.firstname AS col2,
  341. user.email AS col3
  342. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  343. WHERE group_rel_user.user_id = user.user_id
  344. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  345. $sql .= " ORDER BY col$column $direction ";
  346. $sql .= " LIMIT $from,$number_of_items";
  347. }
  348. else
  349. {
  350. if (api_is_allowed_to_edit()=="true")
  351. {
  352. $sql = "SELECT
  353. user.user_id AS col0,
  354. user.lastname AS col1,
  355. user.firstname AS col2,
  356. user.email AS col3
  357. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  358. WHERE group_rel_user.user_id = user.user_id
  359. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  360. $sql .= " ORDER BY col$column $direction ";
  361. $sql .= " LIMIT $from,$number_of_items";
  362. }
  363. else
  364. {
  365. $sql = "SELECT
  366. user.user_id AS col0,
  367. user.lastname AS col1,
  368. user.firstname AS col2
  369. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  370. WHERE group_rel_user.user_id = user.user_id
  371. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  372. $sql .= " ORDER BY col$column $direction ";
  373. $sql .= " LIMIT $from,$number_of_items";
  374. }
  375. }
  376. $return = array ();
  377. $result = api_sql_query($sql,__FILE__,__LINE__);
  378. while ($row = Database::fetch_row($result))
  379. {
  380. $return[] = $row;
  381. }
  382. return $return;
  383. }
  384. /**
  385. * Returns a mailto-link
  386. * @param string $email An email-address
  387. * @return string HTML-code with a mailto-link
  388. */
  389. function email_filter($email)
  390. {
  391. return Display :: encrypted_mailto_link($email, $email);
  392. }
  393. /**
  394. * Display a user icon that links to the user page
  395. *
  396. * @param integer $user_id the id of the user
  397. * @return html code
  398. *
  399. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  400. * @version April 2008
  401. */
  402. function user_icon_filter($user_id)
  403. {
  404. global $origin;
  405. return "<a href='../user/userInfo.php?origin=".$origin."&amp;uInfo=".$user_id."'><img src='../img/members.gif' >";
  406. }
  407. // footer
  408. isset($origin)?$orig=$origin:$orig='';
  409. if ($orig != 'learnpath')
  410. {
  411. Display::display_footer();
  412. }
  413. ?>