group_space.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <?php //$Id: group_space.php 20455 2009-05-10 16:31:12Z ivantcholakov $
  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.' '.stripslashes($current_group['name']),"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. echo '<div class="actions">';
  114. echo '<a href="group.php">'.Display::return_icon('back.png',get_lang('BackToGroupList')).get_lang('BackToGroupList').'</a>';
  115. /*
  116. * Edit the group
  117. */
  118. if (api_is_allowed_to_edit(false,true) or GroupManager :: is_tutor($_user['user_id'])) {
  119. isset($origin)?$my_origin = $origin:$my_origin='';
  120. echo Display::return_icon('edit.gif', get_lang("EditGroup"))."<a href=\"group_edit.php?origin=$my_origin\">".get_lang("EditGroup")."</a>";
  121. }
  122. /*
  123. * Register to group
  124. */
  125. if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  126. 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,$charset))."'".')) return false;">'.Display::return_icon('groupadd.gif').get_lang("RegIntoGroup").'</a>';
  127. }
  128. /*
  129. * Unregister from group
  130. */
  131. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) {
  132. echo '<a href="'.api_get_self().'?selfUnReg=1" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.Display::return_icon('group_delete.gif').get_lang("StudentUnsubscribe").'</a>';
  133. }
  134. echo '&nbsp;</div>';
  135. if( isset($_GET['action'])) {
  136. switch( $_GET['action']) {
  137. case 'show_msg':
  138. Display::display_normal_message(Security::remove_XSS($_GET['msg']));
  139. break;
  140. }
  141. }
  142. /*
  143. -----------------------------------------------------------
  144. Main Display Area
  145. -----------------------------------------------------------
  146. */
  147. $course_code = $_course['sysCode'];
  148. $is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course($_SESSION['_user']['user_id'], $course_code);
  149. /*
  150. * Group title and comment
  151. */
  152. //api_display_tool_title($nameTools.' '.stripslashes($current_group['name']));
  153. if (!empty($current_group['description'])) {
  154. echo '<blockquote>'.stripslashes($current_group['description']).'</blockquote>';
  155. }
  156. /*
  157. * Group Tools
  158. */
  159. // If the user is subscribed to the group or the user is a tutor of the group then
  160. if (api_is_allowed_to_edit(false,true) OR GroupManager :: is_user_in_group($_SESSION['_user']['user_id'], $current_group['id'])) {
  161. $tools = '';
  162. // link to the forum of this group
  163. $forums_of_groups = get_forums_of_group($current_group['id']);
  164. if (is_array($forums_of_groups)) {
  165. if ( $current_group['forum_state'] != TOOL_NOT_AVAILABLE ) {
  166. foreach ($forums_of_groups as $key => $value) {
  167. 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)) {
  168. $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 />';
  169. //$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 />';
  170. }
  171. }
  172. }
  173. }
  174. if( $current_group['doc_state'] != TOOL_NOT_AVAILABLE )
  175. {
  176. // link to the documents area of this group
  177. $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>";
  178. }
  179. if ( $current_group['calendar_state'] != TOOL_NOT_AVAILABLE)
  180. {
  181. //link to a group-specific part of agenda
  182. $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>";
  183. }
  184. if ( $current_group['work_state'] != TOOL_NOT_AVAILABLE)
  185. {
  186. //link to the works area of this group
  187. $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>";
  188. }
  189. if ( $current_group['announcements_state'] != TOOL_NOT_AVAILABLE)
  190. {
  191. //link to a group-specific part of announcements
  192. $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>";
  193. }
  194. if ( $current_group['wiki_state'] != TOOL_NOT_AVAILABLE)
  195. {
  196. //link to the wiki area of this group
  197. $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>";
  198. }
  199. echo '<b>'.get_lang("Tools").':</b>';
  200. if (!empty($tools))
  201. {
  202. echo '<blockquote>'.$tools.'</blockquote>';
  203. }
  204. } else {
  205. $tools = '';
  206. // link to the forum of this group
  207. $forums_of_groups = get_forums_of_group($current_group['id']);
  208. if (is_array($forums_of_groups)) {
  209. if ( $current_group['forum_state'] == TOOL_PUBLIC ) {
  210. foreach ($forums_of_groups as $key => $value) {
  211. if ($value['forum_group_public_private'] == 'public' ) {
  212. $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 />';
  213. //$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 />';
  214. }
  215. }
  216. }
  217. }
  218. if( $current_group['doc_state'] == TOOL_PUBLIC )
  219. {
  220. // link to the documents area of this group
  221. $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/>";
  222. }
  223. if ( $current_group['calendar_state'] == TOOL_PUBLIC )
  224. {
  225. //link to a group-specific part of agenda
  226. $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/>";
  227. }
  228. if ( $current_group['work_state'] == TOOL_PUBLIC )
  229. {
  230. //link to the works area of this group
  231. $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/>";
  232. }
  233. if ( $current_group['announcements_state'] == TOOL_PUBLIC)
  234. {
  235. //link to a group-specific part of announcements
  236. $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/>";
  237. }
  238. if ( $current_group['wiki_state'] == TOOL_PUBLIC )
  239. {
  240. //link to the wiki area of this group
  241. $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/>";
  242. }
  243. echo '<b>'.get_lang("Tools").':</b>';
  244. if (!empty($tools))
  245. {
  246. echo '<blockquote>'.$tools.'</blockquote>';
  247. }
  248. }
  249. /*
  250. * list all the tutors of the current group
  251. */
  252. $tutors = GroupManager::get_subscribed_tutors($current_group['id']);
  253. $tutor_info = '';
  254. if (count($tutors) == 0)
  255. {
  256. $tutor_info = get_lang("GroupNoneMasc");
  257. }
  258. else
  259. {
  260. isset($origin)?$my_origin = $origin:$my_origin='';
  261. foreach($tutors as $index => $tutor)
  262. {
  263. $image_path = UserManager::get_user_picture_path_by_id($tutor['user_id'],'web',false, true);
  264. $image_repository = $image_path['dir'];
  265. $existing_image = $image_path['file'];
  266. $photo= '<img src="'.$image_repository.$existing_image.'" align="absbottom" alt="'.$tutor['firstname'].' '.$tutor['lastname'].'" width="32" height="32" title="'.$tutor['firstname'].' '.$tutor['lastname'].'" />';
  267. $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>";
  268. }
  269. }
  270. echo '<b>'.get_lang("GroupTutors").':</b>';
  271. if (!empty($tutor_info))
  272. {
  273. echo '<blockquote>'.$tutor_info.'</blockquote>';
  274. }
  275. /*
  276. * list all the members of the current group
  277. */
  278. echo '<b>'.get_lang("GroupMembers").':</b>';
  279. $table = new SortableTable('group_users', 'get_number_of_group_users', 'get_group_user_data',2);
  280. $my_cidreq=isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
  281. $my_origin=isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  282. $my_gidreq=isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : '';
  283. $parameters = array('cidReq' => $my_cidreq, 'origin'=> $my_origin, 'gidReq' => $my_gidreq);
  284. $table->set_additional_parameters($parameters);
  285. $table->set_header(0, '');
  286. $table->set_header(1, get_lang('LastName'));
  287. $table->set_header(2, get_lang('FirstName'));
  288. if (api_get_setting("show_email_addresses") == "true")
  289. {
  290. $table->set_header(3, get_lang('Email'));
  291. $table->set_column_filter(3, 'email_filter');
  292. }
  293. else
  294. {
  295. if (api_is_allowed_to_edit()=="true")
  296. {
  297. $table->set_header(3, get_lang('Email'));
  298. $table->set_column_filter(3, 'email_filter');
  299. }
  300. }
  301. $table->set_column_filter(0, 'user_icon_filter');
  302. $table->display();
  303. /**
  304. * Get the number of subscribed users to the group
  305. *
  306. * @return integer
  307. *
  308. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  309. * @version April 2008
  310. */
  311. function get_number_of_group_users()
  312. {
  313. global $current_group;
  314. // Database table definition
  315. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  316. // query
  317. $sql = "SELECT count(id) AS number_of_users
  318. FROM ".$table_group_user."
  319. WHERE group_id='".Database::escape_string($current_group['id'])."'";
  320. $result = api_sql_query($sql,__FILE__,__LINE__);
  321. $return = Database::fetch_array($result,'ASSOC');
  322. return $return['number_of_users'];
  323. }
  324. /**
  325. * Get the details of the users in a group
  326. *
  327. * @param integer $from starting row
  328. * @param integer $number_of_items number of items to be displayed
  329. * @param integer $column sorting colum
  330. * @param integer $direction sorting direction
  331. * @return array
  332. *
  333. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  334. * @version April 2008
  335. */
  336. function get_group_user_data($from, $number_of_items, $column, $direction)
  337. {
  338. global $current_group;
  339. // Database table definition
  340. $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
  341. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  342. // query
  343. if (api_get_setting("show_email_addresses") == "true") {
  344. $sql = "SELECT
  345. user.user_id AS col0,
  346. user.lastname AS col1,
  347. user.firstname AS col2,
  348. user.email AS col3
  349. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  350. WHERE group_rel_user.user_id = user.user_id
  351. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  352. $sql .= " ORDER BY col$column $direction ";
  353. $sql .= " LIMIT $from,$number_of_items";
  354. }
  355. else
  356. {
  357. if (api_is_allowed_to_edit()=="true")
  358. {
  359. $sql = "SELECT
  360. user.user_id AS col0,
  361. user.lastname AS col1,
  362. user.firstname AS col2,
  363. user.email AS col3
  364. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  365. WHERE group_rel_user.user_id = user.user_id
  366. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  367. $sql .= " ORDER BY col$column $direction ";
  368. $sql .= " LIMIT $from,$number_of_items";
  369. }
  370. else
  371. {
  372. $sql = "SELECT
  373. user.user_id AS col0,
  374. user.lastname AS col1,
  375. user.firstname AS col2
  376. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  377. WHERE group_rel_user.user_id = user.user_id
  378. AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
  379. $sql .= " ORDER BY col$column $direction ";
  380. $sql .= " LIMIT $from,$number_of_items";
  381. }
  382. }
  383. $return = array ();
  384. $result = api_sql_query($sql,__FILE__,__LINE__);
  385. while ($row = Database::fetch_row($result))
  386. {
  387. $return[] = $row;
  388. }
  389. return $return;
  390. }
  391. /**
  392. * Returns a mailto-link
  393. * @param string $email An email-address
  394. * @return string HTML-code with a mailto-link
  395. */
  396. function email_filter($email)
  397. {
  398. return Display :: encrypted_mailto_link($email, $email);
  399. }
  400. /**
  401. * Display a user icon that links to the user page
  402. *
  403. * @param integer $user_id the id of the user
  404. * @return html code
  405. *
  406. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  407. * @version April 2008
  408. */
  409. function user_icon_filter($user_id)
  410. {
  411. global $origin;
  412. $userinfo=Database::get_user_info_from_id($user_id);
  413. $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false, true);
  414. $image_repository = $image_path['dir'];
  415. $existing_image = $image_path['file'];
  416. $photo= '<center><img src="'.$image_repository.$existing_image.'" alt="'.$userinfo['lastname'].' '.$userinfo['firstname'].'" width="22" height="22" title="'.$userinfo['lastname'].' '.$userinfo['firstname'].'" /></center>';
  417. return "<a href='../user/userInfo.php?origin=".$origin."&amp;uInfo=".$user_id."'>".$photo;
  418. }
  419. // footer
  420. isset($origin)?$orig=$origin:$orig='';
  421. if ($orig != 'learnpath')
  422. {
  423. Display::display_footer();
  424. }
  425. ?>