group_space.php 19 KB

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