Dokeos PHP Cross Reference Learning Management Systems

Source: /main/group/group_ori.php - 433 lines - 15378 bytes - Summary - Text - Print

Description: Main page for the group module.

   1  <?php
   2  
   3  /* For licensing terms, see /dokeos_license.txt */
   4  
   5  /**
   6  ==============================================================================
   7  *    Main page for the group module.
   8  *    @package dokeos.group
   9  ==============================================================================
  10  */
  11  
  12  // settings (temporarily added here)
  13  $_setting['group_overview'] = 'true';
  14  $_setting['group_export_csv'] = 'true';
  15  $_setting['group_export_xls'] = 'true';
  16  
  17  // name of the language file that needs to be included
  18  $language_file = 'group';
  19  
  20  // including the global Dokeos file
  21  require_once  ('../inc/global.inc.php');
  22  
  23  // including additional libraries
  24  require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  25  require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  26  require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  27  
  28  // the section (for the tabs)
  29  $this_section = SECTION_COURSES;
  30  
  31  // access control
  32  api_protect_course_script(true);
  33  
  34  // tracking
  35  event_access_tool(TOOL_GROUP);
  36  
  37  // name of the tool
  38  $nameTools = get_lang('Groups');
  39  
  40  // display the header
  41  Display::display_header(get_lang('Groups'));
  42  
  43  // Tool introduction
  44  Display::display_introduction_section(TOOL_GROUP);
  45  
  46  // unsetting some local $_SESSION variables
  47  unset($_SESSION['groupmembers'.api_get_course_id()]);
  48  unset($_SESSION['groupmembership'.api_get_course_id()]);
  49  unset($_SESSION['grouplist'.api_get_course_id()]);
  50  
  51  // display the tool title
  52  //api_display_tool_title(get_lang('Groups'));
  53  
  54  // action links
  55  display_actions();
  56  
  57  //start the content div
  58  echo '<div id="content">';
  59  
  60  // cleaning up session variables that have been used so that we always get 'fresh' information
  61  $_SESSION['groupmembers'.api_get_course_id()] = null;
  62  $_SESSION['coaches'.api_get_course_id()] = null;
  63  $_SESSION['group_info'.api_get_course_id()] = null;
  64  
  65  // action handling
  66  group_actions();
  67  
  68  // display the groups
  69  display_groups();
  70  
  71  // close the content div
  72  echo '</div>';
  73  
  74  // secondary action links
  75  display_secondary_actions();
  76  
  77  // Display the footer
  78  Display::display_footer();
  79  exit;
  80  
  81  
  82  function display_groups(){
  83      $table = new SortableTable('groups', 'get_number_of_groups', 'get_groups_data');
  84  
  85      // table headers
  86      $table->set_header(0, '', false);
  87      $table->set_header(1, get_lang('GroupName'));    
  88      $table->set_header(2, get_lang('Tutor'));
  89      $table->set_header(3, get_lang('GroupCategory'));
  90      $table->set_header(4, get_lang('GroupAvailablePlaces'));
  91      $table->set_header(5, get_lang('GroupMembers'));
  92      if (api_is_allowed_to_edit(false,true)){
  93          $table->set_header(6, get_lang('Empty'));
  94          $table->set_header(7, get_lang('Fill'));
  95          $table->set_header(8, get_lang('Edit'));
  96          //$table->set_header(9, get_lang('Delete'));
  97      } else {
  98          $table->set_header(6,get_lang('GroupMembership'));
  99      }
 100  
 101      // table data filters
 102      $table->set_column_filter(1, 'group_name_filter');
 103      $table->set_column_filter(2, 'tutor_filter');
 104      $table->set_column_filter(5, 'group_members_filter');
 105      if (api_is_allowed_to_edit(false,true)){
 106          $table->set_column_filter(6, 'empty_filter');
 107          $table->set_column_filter(7, 'fill_filter');
 108          $table->set_column_filter(8, 'edit_filter');
 109          //$table->set_column_filter(9, 'delete_filter');
 110      } else {
 111          $table->set_column_filter(6, 'groupmembership_filter');
 112      }
 113  
 114      // table form actions (actions on selected items)
 115      if (api_is_allowed_to_edit(false,true)){
 116          $table->set_form_actions(array ('delete' => get_lang('DeleteGroup')));
 117      } else {
 118          $table->set_form_actions(array ('join' => get_lang('JoinGroup')));
 119      }
 120      $table->display();
 121  }
 122  
 123  function get_number_of_groups(){
 124      // Database table definition
 125      $table_group =    Database::get_course_table(TABLE_GROUP);
 126  
 127      $sql = "SELECT count(id) AS total_number_of_items FROM $table_group";
 128      $res = Database::query($sql, __FILE__, __LINE__);
 129      $obj = Database::fetch_object($res);
 130      return $obj->total_number_of_items;
 131  }
 132  
 133  function get_groups_data($from, $number_of_items, $column, $direction){
 134      // Database table definition
 135      $table_group         = Database::get_course_table(TABLE_GROUP);
 136      $table_group_category     = Database :: get_course_table(TABLE_GROUP_CATEGORY);
 137  
 138      if (api_is_allowed_to_edit(false,true)){
 139          $sql = "SELECT 
 140                  groupinfo.id         AS col0,
 141                  groupinfo.name         AS col1,
 142                  groupinfo.session_id    AS col2,
 143                  group_category.title    AS col3,
 144                  groupinfo.max_student    AS col4,
 145                  groupinfo.id        AS col5,
 146                  groupinfo.id        AS col6,
 147                  groupinfo.id        AS col7,
 148                  groupinfo.id         AS col8
 149              FROM $table_group groupinfo
 150              LEFT JOIN $table_group_category group_category
 151              ON groupinfo.category_id = group_category.id
 152              ";
 153          $sql .= " ORDER BY col$column $direction ";
 154          $sql .= " LIMIT $from,$number_of_items";
 155      } else {
 156          $sql = "SELECT 
 157                  groupinfo.id         AS col0,
 158                  groupinfo.name         AS col1,
 159                  groupinfo.session_id    AS col2,
 160                  group_category.title    AS col3,
 161                  groupinfo.max_student    AS col4,
 162                  groupinfo.id        AS col5,
 163                  groupinfo.id        AS col6
 164              FROM $table_group groupinfo
 165              LEFT JOIN $table_group_category group_category
 166              ON groupinfo.category_id = group_category.id
 167              ";
 168          $sql .= " ORDER BY col$column $direction ";
 169          $sql .= " LIMIT $from,$number_of_items";
 170      }
 171      $res = Database::query($sql, __FILE__, __LINE__);
 172      while ($group = Database::fetch_row($res)) {
 173          $return[] = $group;
 174      }
 175      return $return;
 176  }
 177  
 178  function group_name_filter($group_name,$url_params,$row){
 179      return '<a href="group_space.php?'.api_get_cidreq().'&amp;gidReq='.$row[0].'&amp;group_id='.$row[0].'">'.$group_name.'</a>';
 180  }
 181  
 182  function tutor_filter($session_id,$url_params,$row){
 183      // here we have to check if the sessions are enabled
 184      // if this is the case we need to display the session coach
 185      // if it is not enabled we display the tutors (for backwards compatibility)
 186      $_SESSION['coaches'] = array();
 187      if (api_get_setting('use_session_mode') == 'true'){
 188          if (!array_key_exists($session_id, $_SESSION['coaches'])){
 189              $_SESSION['coaches'.api_get_course_id()][$session_id] = api_get_coachs_from_course($session_id);
 190          }
 191  
 192          // according to the code (api_get_coachs_from_course) there can be multiple session coaches
 193          foreach ($_SESSION['coaches'.api_get_course_id()][$session_id] as $key=>$session_coach){
 194              $return .= $session_coach['firstname'].' '.$session_coach['lastname'];
 195          }
 196          return $return;
 197      } else {
 198          // code to write
 199      }
 200  
 201  }
 202  
 203  function group_members_filter($group_id, $url_params, $row){
 204      global $_course;
 205  
 206      // Database table definition
 207      $table_group       = Database::get_course_table(TABLE_GROUP);
 208      $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
 209  
 210      // count the number of members in the group if none is set
 211      if (!is_array($_SESSION['groupmembers'.api_get_course_id()])){
 212          $sql = "SELECT group_id, count(id) as number_of_users FROM ".$table_group_user." group by group_id";
 213          $result = Database::query($sql,__FILE__,__LINE__);
 214          while ($row = Database::fetch_array($result)) {
 215              $_SESSION['groupmembers'.api_get_course_id()][$row['group_id']] = $row['number_of_users'];
 216          }
 217      }
 218      return $_SESSION['groupmembers'.api_get_course_id()][$group_id];
 219  }
 220  
 221  function empty_filter($group_id, $url_params, $row){
 222      return '<div align="center"><a href="group.php?action=empty_one&group_id='.$group_id.'">'.Display::return_icon('empty.png',get_lang('EmptyGroup')).'</a></div>';
 223  }
 224  
 225  function fill_filter($group_id, $url_params, $row){
 226      return '<div align="center"><a href="group.php?action=fill_one&group_id='.$group_id.'">'.Display::return_icon('filter.png',get_lang('FillGroup')).'</a></div>';
 227  }
 228  
 229  function edit_filter($group_id, $url_params, $row){
 230      return '<div align="center"><a href="group_edit.php?gidReq='.$group_id.'&amp;group_id='.$group_id.'">'.Display::return_icon('edit.png',get_lang('EditGroup')).'</a></div>';
 231  }
 232  
 233  function delete_filter($group_id, $url_params, $row){
 234      return '<a href="group.php?action=delete_one&group_id='.$group_id.'">'.Display::return_icon('delete.png',get_lang('DeleteGroup')).'</a>';
 235  }
 236  
 237  function groupmembership_filter($group_id, $url_params, $row){
 238      global $_user;
 239  
 240      // count the number of members in the group if none is set
 241      if (!is_array($_SESSION['groupmembers'.api_get_course_id()])){
 242          $sql = "SELECT group_id, count(id) as number_of_users FROM ".$table_group_user." group by group_id";
 243          $result = Database::query($sql,__FILE__,__LINE__);
 244          while ($row = Database::fetch_array($result)) {
 245              $_SESSION['groupmembers'.api_get_course_id()][$row['group_id']] = $row['number_of_users'];
 246          }
 247      }
 248  
 249      // get all the group information (and cache it)
 250      if (!is_array($_SESSION['grouplist'.api_get_course_id()])){
 251          $groups_unsorted = GroupManager::get_group_list();
 252          foreach ($groups_unsorted as $key=>$group){
 253              $group_list[$group['id']] = $group;
 254          }
 255          $_SESSION['grouplist'.api_get_course_id()] = $group_list;
 256      }
 257  
 258      // get all the group the user is subscribed to
 259      if (!is_array($_SESSION['groupmembership'.api_get_course_id()])){
 260          $_SESSION['groupmembership'.api_get_course_id()] = GroupManager::get_group_ids(null,$_user['user_id']);
 261      }
 262  
 263      // display link to register to the group if
 264      // 1. the number of places is higher than the number of students already registerend AND 
 265      // 2. registration is allowed AND
 266      // 3. the user is not in the group yet
 267      if ($_SESSION['groupmembers'.api_get_course_id()][$group_id] < $_SESSION['grouplist'.api_get_course_id()][$group_id]['maximum_number_of_members']
 268          AND $_SESSION['grouplist'.api_get_course_id()][$group_id]['self_registration_allowed'] == 1 
 269          AND !in_array($group_id, $_SESSION['groupmembership'.api_get_course_id()])){
 270          return '<a href="group.php?action=self_reg&amp;group_id='.$group_id.'">register</a>';
 271      }
 272      
 273      // display the link to unregister if
 274      // 1. the user is registered AND
 275      // 2. unregistration is allowed
 276      if ( in_array($group_id, $_SESSION['groupmembership'.api_get_course_id()]) AND $_SESSION['grouplist'.api_get_course_id()][$group_id]['self_unregistration_allowed'] == 1){
 277          return '<a href="group.php?action=self_unreg&amp;group_id='.$group_id.'">unregister</a>';
 278      }
 279  
 280      // display 'group full' if 
 281      // 1. the number of places is equal than the number of students already registerend AND 
 282      // 2. the user is not in the group yet
 283      if ($_SESSION['groupmembers'.api_get_course_id()][$group_id] == $_SESSION['grouplist'.api_get_course_id()][$group_id]['maximum_number_of_members']
 284          AND !in_array($group_id, $_SESSION['groupmembership'.api_get_course_id()])){
 285          return 'group full';
 286      }
 287  }
 288  
 289  
 290  function display_secondary_actions(){
 291      echo '<div class="actions">';
 292      if (api_is_allowed_to_edit(false,true)){
 293          // group overview
 294          if (api_get_setting('group_overview') == 'true'){
 295              if( Database::count_rows(Database::get_course_table(TABLE_GROUP)) > 0) {
 296                  echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group.gif', get_lang('GroupOverview')).' '.get_lang('GroupOverview').'</a>';
 297              } else {
 298                  echo '<a href="#" class="invisible">'.Display::return_icon('group.gif', get_lang('GroupOverview')).' '.get_lang('GroupOverview').'</a>';
 299              }
 300          }
 301  
 302          // export
 303          if (api_is_allowed_to_edit(false,true)){
 304              if (api_get_setting('group_export_csv') == 'true') {
 305                  echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=csv">'.Display::return_icon('csv.gif', get_lang('ExportAsCSV')).' '.get_lang('ExportAsCSV').'</a> ';
 306                  }
 307              if (api_get_setting('group_export_xls') == 'true') {
 308                  echo ' <a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.Display::return_icon('excel.gif', get_lang('ExportAsXLS')).' '.get_lang('ExportAsXLS').'</a>';
 309              }
 310          }
 311          echo '</div>';
 312      }
 313      echo '</div>';
 314  }
 315  
 316  
 317  
 318  
 319  function display_actions(){
 320  
 321      if (api_is_allowed_to_edit(false,true))
 322      {
 323          echo '<div class="actions">';
 324          // link to add a group
 325          echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('groupadd.png', get_lang('NewGroupCreate'), array('style'=>'height: 32px;')).' '.get_lang('NewGroupCreate').'</a>';
 326          if (api_get_setting('allow_group_categories') == 'true') {
 327              echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.Display::return_icon('folder_new.gif', get_lang('AddCategory')).' '.get_lang('AddCategory').'</a>&nbsp;';
 328          } else {
 329              echo '<a href="group_category.php?'.api_get_cidreq().'">'.Display::return_icon('dokeos_scenario.png', get_lang('Scenario')).' '.get_lang('Scenario').'</a>';
 330          }
 331          echo '</div>';
 332      }
 333  }
 334  
 335  
 336  
 337  
 338  function group_actions(){
 339      global $_user;
 340  
 341      // actions that a student can do
 342      if (isset ($_GET['action']))
 343      {
 344          switch ($_GET['action'])
 345          {
 346              case 'self_reg' :
 347                  if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], Security::remove_XSS($_GET['group_id']))) {
 348                      GroupManager :: subscribe_users($_SESSION['_user']['user_id'],Security::remove_XSS($_GET['group_id']));
 349                      Display :: display_confirmation_message(get_lang('GroupNowMember'));
 350                  }
 351                  break;
 352              case 'self_unreg' :
 353                  if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], Security::remove_XSS($_GET['group_id']))) {
 354                      GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'],Security::remove_XSS($_GET['group_id']));
 355                      Display :: display_confirmation_message(get_lang('StudentDeletesHimself'));
 356                  }
 357                  break;
 358              case 'show_msg' :
 359                  Display :: display_confirmation_message(Security::remove_XSS($_GET['msg']));
 360                  break;
 361          }
 362      }
 363  
 364      // actions that a student can do
 365      if (isset ($_POST['action']))
 366      {
 367          switch ($_POST['action']){
 368              case 'join': 
 369              foreach ($_POST['id'] as $key=>$group_id){
 370                      GroupManager :: subscribe_users ($_user['user_id'], $group_id);
 371                  }
 372                  break;
 373          }
 374      }
 375  
 376      // actions that a teacher can do
 377      if (api_is_allowed_to_edit(false,true))
 378      {
 379          // Post-actions
 380          if (isset ($_POST['action']))
 381          {
 382              switch ($_POST['action'])
 383              {
 384                  case 'delete' :
 385                      if( is_array($_POST['id'])) {
 386                          GroupManager :: delete_groups($_POST['id']);
 387                          Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted'));
 388                      }
 389                      break;
 390                  case 'empty_selected' :
 391                      if( is_array($_POST['id']))    {
 392                          GroupManager :: unsubscribe_all_users($_POST['group']);
 393                          Display :: display_confirmation_message(get_lang('SelectedGroupsEmptied'));
 394                      }
 395                      break;
 396                  case 'fill_selected' :
 397                      if( is_array($_POST['id']))    {
 398                          GroupManager :: fill_groups($_POST['group']);
 399                          Display :: display_confirmation_message(get_lang('SelectedGroupsFilled'));
 400                      }
 401                      break;
 402              }
 403          }
 404          // Get-actions
 405          if (isset ($_GET['action']))
 406          {
 407              switch ($_GET['action'])
 408              {
 409                  case 'swap_cat_order' :
 410                      GroupManager :: swap_category_order(Security::remove_XSS($_GET['id1']),Security::remove_XSS($_GET['id2']));
 411                      Display :: display_confirmation_message(get_lang('CategoryOrderChanged'));
 412                      break;
 413                  case 'delete_one' :
 414                      GroupManager :: delete_groups(Security::remove_XSS($_GET['group_id']));
 415                      Display :: display_confirmation_message(get_lang('GroupDel'));
 416                      break;
 417                  case 'empty_one' :
 418                      GroupManager :: unsubscribe_all_users(Security::remove_XSS($_GET['group_id']));
 419                      Display :: display_confirmation_message(get_lang('GroupEmptied'));
 420                      break;
 421                  case 'fill_one' :
 422                      GroupManager :: fill_groups(Security::remove_XSS($_GET['group_id']));
 423                      Display :: display_confirmation_message(get_lang('GroupFilledGroups'));
 424                      break;
 425                  case 'delete_category' :
 426                      GroupManager :: delete_category(Security::remove_XSS($_GET['group_id']));
 427                      Display :: display_confirmation_message(get_lang('CategoryDeleted'));
 428                      break;
 429              }
 430          }
 431      }
 432  }
 433  ?>

title

Description

title

Description

title

Description

title

title

Body