group_space.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <?php //$Id: group_space.php 19369 2009-03-26 22:29:27Z 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. $image_path = UserManager::get_user_picture_path_by_id($tutor['user_id'],'web',false, true);
  261. $image_repository = $image_path['dir'];
  262. $existing_image = $image_path['file'];
  263. $photo= '<img src="'.$image_repository.$existing_image.'" align="absbottom" alt="'.$tutor['firstname'].' '.$tutor['lastname'].'" width="32" height="32" title="'.$tutor['firstname'].' '.$tutor['lastname'].'" />';
  264. $tutor_info .= "<div style='margin-bottom: 5px;'><a href='../user/userInfo.php?origin=".$my_origin."&amp;uInfo=".$tutor['user_id']."'>".$photo."&nbsp;".$tutor['firstname']." ".$tutor['lastname']."</a></div>";
  265. }
  266. }
  267. echo '<b>'.get_lang("GroupTutors").':</b>';
  268. if (!empty($tutor_info))
  269. {
  270. echo '<blockquote>'.$tutor_info.'</blockquote>';
  271. }
  272. /*
  273. * list all the members of the current group
  274. */
  275. echo '<b>'.get_lang("GroupMembers").':</b>';
  276. $table = new SortableTable('group_users', 'get_number_of_group_users', 'get_group_user_data',2);
  277. $my_cidreq=isset($_GET['cidReq']) ? $_GET['cidReq'] : '';
  278. $my_origin=isset($_GET['origin']) ? $_GET['origin'] : '';
  279. $my_gidreq=isset($_GET['gidReq']) ? $_GET['gidReq'] : '';
  280. $parameters = array('cidReq' => $my_cidreq, 'origin'=> $my_origin, 'gidReq' => $my_gidreq);
  281. $table->set_additional_parameters($parameters);
  282. $table->set_header(0, '');
  283. $table->set_header(1, get_lang('LastName'));
  284. $table->set_header(2, get_lang('FirstName'));
  285. if (api_get_setting("show_email_addresses") == "true")
  286. {
  287. $table->set_header(3, get_lang('Email'));
  288. $table->set_column_filter(3, 'email_filter');
  289. }
  290. else
  291. {
  292. if (api_is_allowed_to_edit()=="true")
  293. {
  294. $table->set_header(3, get_lang('Email'));
  295. $table->set_column_filter(3, 'email_filter');
  296. }
  297. }
  298. $table->set_column_filter(0, 'user_icon_filter');
  299. $table->display();
  300. /**
  301. * Get the number of subscribed users to the group
  302. *
  303. * @return integer
  304. *
  305. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  306. * @version April 2008
  307. */
  308. function get_number_of_group_users()
  309. {
  310. global $current_group;
  311. // Database table definition
  312. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  313. // query
  314. $sql = "SELECT count(id) AS number_of_users
  315. FROM ".$table_group_user."
  316. WHERE group_id='".Database::escape_string($current_group['id'])."'";
  317. $result = api_sql_query($sql,__FILE__,__LINE__);
  318. $return = Database::fetch_array($result,'ASSOC');
  319. return $return['number_of_users'];
  320. }
  321. /**
  322. * Get the details of the users in a group
  323. *
  324. * @param integer $from starting row
  325. * @param integer $number_of_items number of items to be displayed
  326. * @param integer $column sorting colum
  327. * @param integer $direction sorting direction
  328. * @return array
  329. *
  330. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  331. * @version April 2008
  332. */
  333. function get_group_user_data($from, $number_of_items, $column, $direction)
  334. {
  335. global $current_group;
  336. // Database table definition
  337. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  338. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  339. // query
  340. if (api_get_setting("show_email_addresses") == "true") {
  341. $sql = "SELECT
  342. user.user_id AS col0,
  343. user.lastname AS col1,
  344. user.firstname AS col2,
  345. user.email AS col3
  346. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  347. WHERE group_rel_user.user_id = user.user_id
  348. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  349. $sql .= " ORDER BY col$column $direction ";
  350. $sql .= " LIMIT $from,$number_of_items";
  351. }
  352. else
  353. {
  354. if (api_is_allowed_to_edit()=="true")
  355. {
  356. $sql = "SELECT
  357. user.user_id AS col0,
  358. user.lastname AS col1,
  359. user.firstname AS col2,
  360. user.email AS col3
  361. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  362. WHERE group_rel_user.user_id = user.user_id
  363. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  364. $sql .= " ORDER BY col$column $direction ";
  365. $sql .= " LIMIT $from,$number_of_items";
  366. }
  367. else
  368. {
  369. $sql = "SELECT
  370. user.user_id AS col0,
  371. user.lastname AS col1,
  372. user.firstname AS col2
  373. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  374. WHERE group_rel_user.user_id = user.user_id
  375. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  376. $sql .= " ORDER BY col$column $direction ";
  377. $sql .= " LIMIT $from,$number_of_items";
  378. }
  379. }
  380. $return = array ();
  381. $result = api_sql_query($sql,__FILE__,__LINE__);
  382. while ($row = Database::fetch_row($result))
  383. {
  384. $return[] = $row;
  385. }
  386. return $return;
  387. }
  388. /**
  389. * Returns a mailto-link
  390. * @param string $email An email-address
  391. * @return string HTML-code with a mailto-link
  392. */
  393. function email_filter($email)
  394. {
  395. return Display :: encrypted_mailto_link($email, $email);
  396. }
  397. /**
  398. * Display a user icon that links to the user page
  399. *
  400. * @param integer $user_id the id of the user
  401. * @return html code
  402. *
  403. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  404. * @version April 2008
  405. */
  406. function user_icon_filter($user_id)
  407. {
  408. global $origin;
  409. $userinfo=Database::get_user_info_from_id($user_id);
  410. $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false, true);
  411. $image_repository = $image_path['dir'];
  412. $existing_image = $image_path['file'];
  413. $photo= '<center><img src="'.$image_repository.$existing_image.'" alt="'.$userinfo['lastname'].' '.$userinfo['firstname'].'" width="22" height="22" title="'.$userinfo['lastname'].' '.$userinfo['firstname'].'" /></center>';
  414. return "<a href='../user/userInfo.php?origin=".$origin."&amp;uInfo=".$user_id."'>".$photo;
  415. }
  416. // footer
  417. isset($origin)?$orig=$origin:$orig='';
  418. if ($orig != 'learnpath')
  419. {
  420. Display::display_footer();
  421. }
  422. ?>