group_space.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php //$Id: group_space.php 14826 2008-04-10 08:10:19Z pcool $
  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("GroupManagement"));
  58. /*
  59. -----------------------------------------------------------
  60. Header
  61. -----------------------------------------------------------
  62. */
  63. Display::display_header($nameTools,"Group");
  64. /*
  65. -----------------------------------------------------------
  66. Actions and Action links
  67. -----------------------------------------------------------
  68. */
  69. /*
  70. * User wants to register in this group
  71. */
  72. if ($_GET['selfReg'] && GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id']))
  73. {
  74. GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $current_group['id']);
  75. Display :: display_normal_message(get_lang('GroupNowMember'));
  76. }
  77. /*
  78. * User wants to unregister from this group
  79. */
  80. if ($_GET['selfUnReg'] && GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id']))
  81. {
  82. GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $current_group['id']);
  83. Display::display_normal_message(get_lang('StudentDeletesHimself'));
  84. }
  85. /*
  86. * Edit the group
  87. */
  88. if (api_is_allowed_to_edit() or GroupManager :: is_tutor($_user['user_id']))
  89. {
  90. echo "<a href=\"group_edit.php?origin=$origin\">".get_lang("EditGroup")."</a><br/><br/>";
  91. }
  92. /*
  93. * Register to group
  94. */
  95. if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id']))
  96. {
  97. 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>';
  98. }
  99. /*
  100. * Unregister from group
  101. */
  102. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id']))
  103. {
  104. 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>';
  105. }
  106. if( isset($_GET['action']))
  107. {
  108. switch( $_GET['action'])
  109. {
  110. case 'show_msg':
  111. Display::display_normal_message($_GET['msg']);
  112. break;
  113. }
  114. }
  115. /*
  116. -----------------------------------------------------------
  117. Main Display Area
  118. -----------------------------------------------------------
  119. */
  120. $course_code = $_course['sysCode'];
  121. $is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course($_SESSION['_user']['user_id'], $course_code);
  122. /*
  123. * Group title and comment
  124. */
  125. api_display_tool_title($nameTools.' '.stripslashes($current_group['name']));
  126. if (!empty($current_group['description']))
  127. {
  128. echo '<blockquote>'.stripslashes($current_group['description']).'</blockquote>';
  129. }
  130. /*
  131. * Group Tools
  132. */
  133. // If the user is subscribed to the group or the user is a tutor of the group then
  134. if (api_is_allowed_to_edit() OR GroupManager :: is_user_in_group($_SESSION['_user']['user_id'], $current_group['id']))
  135. {
  136. $tools = '';
  137. $forums_of_groups = get_forums_of_group($current_group['id']);
  138. if (is_array($forums_of_groups))
  139. {
  140. foreach ($forums_of_groups as $key => $value)
  141. {
  142. if($value['forum_group_public_private'] == 'public' || ($user_subscribe_to_current_group && $value['forum_group_public_private'] == 'private') || $user_is_tutor || api_is_allowed_to_edit())
  143. {
  144. $tools.= Display::return_icon('forum.gif') . ' <a href="../forum/viewforum.php?forum='.$value['forum_id'].'">'.$value['forum_title'].'</a><br />';
  145. }
  146. }
  147. }
  148. if( $current_group['doc_state'] != TOOL_NOT_AVAILABLE )
  149. {
  150. // link to the documents area of this group
  151. $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')."&nbsp;".get_lang("GroupDocument")."</a></div>";
  152. }
  153. if ( $current_group['calendar_state'] != TOOL_NOT_AVAILABLE)
  154. {
  155. //link to a group-specific part of agenda
  156. $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')."&nbsp;".get_lang("GroupCalendar")."</a></div>";
  157. }
  158. if ( $current_group['work_state'] != TOOL_NOT_AVAILABLE)
  159. {
  160. //link to the works area of this group
  161. $tools .= "<div style='margin-bottom: 5px;'><a href=\"../work/work.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."\">".Display::return_icon('works.gif')."&nbsp;".get_lang("GroupWork")."</a></div>";
  162. }
  163. if ( $current_group['announcements_state'] != TOOL_NOT_AVAILABLE)
  164. {
  165. //link to a group-specific part of announcements
  166. $tools .= "<div style='margin-bottom: 5px;'><a href=\"../announcements/announcements.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."\">".Display::return_icon('valves.gif')."&nbsp;".get_lang("GroupAnnouncements")."</a></div>";
  167. }
  168. echo '<b>'.get_lang("Tools").':</b>';
  169. if (!empty($tools))
  170. {
  171. echo '<blockquote>'.$tools.'</blockquote>';
  172. }
  173. }
  174. else
  175. {
  176. $tools = '';
  177. $forums_of_groups = get_forums_of_group($current_group['id']);
  178. if (is_array($forums_of_groups))
  179. {
  180. foreach ($forums_of_groups as $key => $value)
  181. {
  182. if($value['forum_group_public_private'] == 'public' )
  183. {
  184. $tools.= Display::return_icon('forum.gif') . ' <a href="../forum/viewforum.php?forum='.$value['forum_id'].'">'.$value['forum_title'].'</a><br />';
  185. }
  186. }
  187. }
  188. if( $current_group['doc_state'] == TOOL_PUBLIC )
  189. {
  190. // link to the documents area of this group
  191. $tools .= "<a href=\"../document/document.php?".api_get_cidreq()."&amp;gidReq=".$current_group['id']."&amp;origin=$origin\">".Display::return_icon('folder_document.gif')."&nbsp;".get_lang("GroupDocument")."</a><br/>";
  192. }
  193. if ( $current_group['calendar_state'] == TOOL_PUBLIC )
  194. {
  195. //link to a group-specific part of agenda
  196. $tools .= "<a href=\"../calendar/agenda.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."&amp;group=".$current_group['id']."\">".Display::return_icon('agenda.gif')."&nbsp;".get_lang("GroupCalendar")."</a><br/>";
  197. }
  198. if ( $current_group['work_state'] == TOOL_PUBLIC )
  199. {
  200. //link to the works area of this group
  201. $tools .= "<a href=\"../work/work.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."\">".Display::return_icon('works.gif')."&nbsp;".get_lang("GroupWork")."</a><br/>";
  202. }
  203. if ( $current_group['announcements_state'] == TOOL_PUBLIC)
  204. {
  205. //link to a group-specific part of announcements
  206. $tools .= "<a href=\"../announcements/announcements.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."&amp;group=".$current_group['id']."\">".Display::return_icon('valves.gif')."&nbsp;".get_lang("GroupAnnouncements")."</a><br/>";
  207. }
  208. echo '<b>'.get_lang("Tools").':</b>';
  209. if (!empty($tools))
  210. {
  211. echo '<blockquote>'.$tools.'</blockquote>';
  212. }
  213. }
  214. /*
  215. * list all the tutors of the current group
  216. */
  217. $tutors = GroupManager::get_subscribed_tutors($current_group['id']);
  218. if (count($tutors) == 0)
  219. {
  220. $tutor_info = get_lang("GroupNoneMasc");
  221. }
  222. else
  223. {
  224. foreach($tutors as $index => $tutor)
  225. {
  226. $tutor_info .= "<div style='margin-bottom: 5px;'><a href='../user/userInfo.php?origin=".$origin."&amp;uInfo=".$tutor['user_id']."'><img src='../img/coachs.gif' align='absbottom'>&nbsp;".$tutor['firstname']." ".$tutor['lastname']."</a></div>";
  227. }
  228. }
  229. echo '<b>'.get_lang("GroupTutors").':</b>';
  230. if (!empty($tutor_info))
  231. {
  232. echo '<blockquote>'.$tutor_info.'</blockquote>';
  233. }
  234. /*
  235. * list all the members of the current group
  236. */
  237. echo '<b>'.get_lang("GroupMembers").':</b>';
  238. $table = new SortableTable('group_users', 'get_number_of_group_users', 'get_group_user_data',2);
  239. $parameters = array('cidReq' => $_GET['cidReq'], 'origin'=> $_GET['origin'], 'gidReq' => $_GET['gidReq']);
  240. $table->set_additional_parameters($parameters);
  241. $table->set_header(0, '');
  242. $table->set_header(1, get_lang('LastName'));
  243. $table->set_header(2, get_lang('FirstName'));
  244. $table->set_header(3, get_lang('Email'));
  245. $table->set_column_filter(3, 'email_filter');
  246. $table->set_column_filter(0, 'user_icon_filter');
  247. $table->display();
  248. /**
  249. * Get the number of subscribed users to the group
  250. *
  251. * @return integer
  252. *
  253. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  254. * @version April 2008
  255. */
  256. function get_number_of_group_users()
  257. {
  258. global $current_group;
  259. // Database table definition
  260. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  261. // query
  262. $sql = "SELECT count(id) AS number_of_users
  263. FROM ".$table_group_user."
  264. WHERE group_id='".Database::escape_string($current_group['id'])."'";
  265. $result = api_sql_query($sql,__FILE__,__LINE__);
  266. $return = Database::fetch_array($result,'ASSOC');
  267. return $return['number_of_users'];
  268. }
  269. /**
  270. * Get the details of the users in a group
  271. *
  272. * @param integer $from starting row
  273. * @param integer $number_of_items number of items to be displayed
  274. * @param integer $column sorting colum
  275. * @param integer $direction sorting direction
  276. * @return array
  277. *
  278. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  279. * @version April 2008
  280. */
  281. function get_group_user_data($from, $number_of_items, $column, $direction)
  282. {
  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. $sql = "SELECT
  289. user.user_id AS col0,
  290. user.lastname AS col1,
  291. user.firstname AS col2,
  292. user.email AS col3
  293. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  294. WHERE group_rel_user.user_id = user.user_id
  295. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  296. $sql .= " ORDER BY col$column $direction ";
  297. $sql .= " LIMIT $from,$number_of_items";
  298. $return = array ();
  299. $result = api_sql_query($sql,__FILE__,__LINE__);
  300. while ($row = Database::fetch_row($result))
  301. {
  302. $return[] = $row;
  303. }
  304. return $return;
  305. }
  306. /**
  307. * Returns a mailto-link
  308. * @param string $email An email-address
  309. * @return string HTML-code with a mailto-link
  310. */
  311. function email_filter($email)
  312. {
  313. return Display :: encrypted_mailto_link($email, $email);
  314. }
  315. /**
  316. * Display a user icon that links to the user page
  317. *
  318. * @param integer $user_id the id of the user
  319. * @return html code
  320. *
  321. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  322. * @version April 2008
  323. */
  324. function user_icon_filter($user_id)
  325. {
  326. global $origin;
  327. return "<a href='../user/userInfo.php?origin=".$origin."&amp;uInfo=".$user_id."'><img src='../img/members.gif' >";
  328. }
  329. // footer
  330. if ($origin != 'learnpath')
  331. {
  332. Display::display_footer();
  333. }
  334. ?>