Dokeos PHP Cross Reference Learning Management Systems

Source: /main/mySpace/student.php - 283 lines - 10375 bytes - Summary - Text - Print

   1  <?php
   2  /* For licensing terms, see /dokeos_license.txt */
   3  /*
   4   * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
   5   */
   6  
   7   // name of the language file that needs to be included
   8  $language_file = array ('registration', 'index', 'tracking');
   9  $cidReset = true;
  10  
  11  require  '../inc/global.inc.php';
  12  require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  13  require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  14  require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  15  require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  16  
  17  
  18  $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  19  if ($export_csv) {
  20      ob_start();
  21  }
  22  $csv_content = array();
  23  
  24  if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  25      $nameTools = get_lang("CoachStudents");
  26      $sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(TABLE_MAIN_USER).' WHERE user_id='.intval($_GET['id_coach']);
  27      $rs = Database::query($sql, __FILE__, __LINE__);
  28      $coach_name = api_get_person_name(Database::result($rs, 0, 1), Database::result($rs, 0, 0));
  29      $title = get_lang('Probationers').' - '.$coach_name;
  30  } else {
  31      $nameTools = get_lang("Students");
  32      $title = get_lang('Probationers');
  33  }
  34  
  35  $this_section = "session_my_space";
  36  
  37  api_block_anonymous_users();
  38  
  39  $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  40  
  41  if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  42      $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  43  }
  44  
  45  if (isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  46       $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  47  }
  48  
  49  $isCoach = api_is_coach();
  50  
  51  Display :: display_header($nameTools);
  52  
  53  // Database Table Definitions
  54  $tbl_course                 = Database :: get_main_table(TABLE_MAIN_COURSE);
  55  $tbl_user                     = Database :: get_main_table(TABLE_MAIN_USER);
  56  $tbl_course_user             = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  57  $tbl_session                 = Database :: get_main_table(TABLE_MAIN_SESSION);
  58  $tbl_session_course         = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  59  $tbl_session_course_user     = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  60  $tbl_session_rel_user         = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  61  
  62  /*
  63   ===============================================================================
  64       FUNCTION
  65   ===============================================================================
  66   */
  67  
  68  function count_student_coached() {
  69      global $students;
  70      return count($students);
  71  }
  72  
  73  function sort_users($a, $b) {
  74      global $tracking_column;
  75      if ($a[$tracking_column] > $b[$tracking_column]) {
  76          return 1;
  77      } else {
  78          return -1;
  79      }
  80  }
  81  
  82  function rsort_users($a, $b)
  83  {
  84      global $tracking_column;
  85      if ($b[$tracking_column] > $a[$tracking_column]) {
  86          return 1;
  87      } else {
  88          return -1;
  89      }
  90  }
  91  
  92  /*
  93   ===============================================================================
  94       MAIN CODE
  95   ===============================================================================
  96   */
  97  
  98  if ($isCoach || api_is_platform_admin() || $_user['status'] == DRH) {
  99  
 100      if ($export_csv) {
 101          $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
 102      } else {
 103          $is_western_name_order = api_is_western_name_order();
 104      }
 105      $sort_by_first_name = api_sort_by_first_name();
 106  
 107      echo '
 108            <div class="actions" align="right">
 109              <a href="javascript: void(0);" onclick="javascript: window.print();">'.Display::return_icon('pixel.gif',get_lang('Print'), array('class' => 'toolactionplaceholdericon toolactionprint32')).'&nbsp;'.get_lang('Print').'</a>
 110              <a href="'.api_get_self().'?export=csv">'.Display::return_icon('pixel.gif',get_lang('ExportAsXLS'), array('class' => 'toolactionplaceholdericon toolactionexportcourse')).'&nbsp;'.get_lang('ExportAsCSV').'</a>
 111            </div><div id="content"><div align="left" ><h4>'.$title.'</h4></div><div class="clear"></div>';
 112  
 113      if (isset($_GET['id_coach'])) {
 114          $coach_id = intval($_GET['id_coach']);
 115      } else {
 116          $coach_id = $_user['user_id'];
 117      }
 118  
 119      if (!isset($_GET['id_session'])) {
 120          if ($isCoach) {
 121              $courses = Tracking :: get_courses_followed_by_coach($coach_id);
 122              $students = Tracking :: get_student_followed_by_coach($coach_id);
 123          }
 124          elseif ($_user['status'] == DRH) {
 125              $students = Tracking :: get_student_followed_by_drh($_user['user_id']);
 126              $courses_of_the_platform = CourseManager :: get_real_course_list();
 127              foreach ($courses_of_the_platform as $course) {
 128                  $courses[$course['code']] = $course['code'];
 129              }
 130          }
 131      } else {
 132          $students = Tracking :: get_student_followed_by_coach_in_a_session($_GET['id_session'], $coach_id);
 133      }
 134  
 135      $tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
 136      $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : DESC;
 137  
 138      if (count($students) > 0) {
 139          $table = new SortableTable('tracking', 'count_student_coached', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
 140          if ($is_western_name_order) {
 141              $table -> set_header(0, get_lang('FirstName'), true, 'align="center');
 142              $table -> set_header(1, get_lang('LastName'), true, 'align="center');
 143          } else {
 144              $table -> set_header(0, get_lang('LastName'), true, 'align="center');
 145              $table -> set_header(1, get_lang('FirstName'), true, 'align="center');
 146          }
 147          $table -> set_header(2, get_lang('Time'), false);
 148          $table -> set_header(3, get_lang('Progress'), false);
 149          $table -> set_header(4, get_lang('Score'), false);
 150          $table -> set_header(5, get_lang('Student_publication'), false);
 151          $table -> set_header(6, get_lang('Messages'), false);
 152          $table -> set_header(7, get_lang('FirstLogin'), false);
 153          $table -> set_header(8, get_lang('LatestLogin'), false);
 154          $table -> set_header(9, get_lang('Details'), false);
 155  
 156          if ($export_csv) {
 157              if ($is_western_name_order) {
 158                  $csv_header[] = array (
 159                      get_lang('FirstName', ''),
 160                      get_lang('LastName', ''),
 161                      get_lang('Time', ''),
 162                      get_lang('Progress', ''),
 163                      get_lang('Score', ''),
 164                      get_lang('Student_publication', ''),
 165                      get_lang('Messages', ''),
 166                      get_lang('FirstLogin', ''),
 167                      get_lang('LatestLogin', '')
 168                  );
 169              } else {
 170                  $csv_header[] = array (
 171                      get_lang('LastName', ''),
 172                      get_lang('FirstName', ''),
 173                      get_lang('Time', ''),
 174                      get_lang('Progress', ''),
 175                      get_lang('Score', ''),
 176                      get_lang('Student_publication', ''),
 177                      get_lang('Messages', ''),
 178                      get_lang('FirstLogin', ''),
 179                      get_lang('LatestLogin', '')
 180                  );
 181              }
 182          }
 183  
 184          $all_datas = array();
 185          foreach ($students as $student_id) {
 186              $student_data = UserManager :: get_user_info_by_id($student_id);
 187              if(isset($_GET['id_session'])) {
 188                  $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
 189              }
 190  
 191              $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
 192              $nb_courses_student = 0;
 193              foreach ($courses as $course_code) {
 194                  if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
 195                      $avg_time_spent += Tracking :: get_time_spent_on_the_platform($student_id, $course_code);
 196                      $avg_student_score += Tracking :: get_avg_student_score($student_id, $course_code);
 197                      $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
 198                      $total_assignments += Tracking :: count_student_assignments($student_id, $course_code);
 199                      $total_messages += Tracking :: count_student_messages($student_id, $course_code);
 200                      $nb_courses_student++;
 201                  }
 202              }
 203  
 204              if ($nb_courses_student > 0) {
 205                  $avg_time_spent = $avg_time_spent / $nb_courses_student;
 206                  $avg_student_score = $avg_student_score / $nb_courses_student;
 207                  $avg_student_progress = $avg_student_progress / $nb_courses_student;
 208              } else {
 209                  $avg_time_spent = null;
 210                  $avg_student_score = null;
 211                  $avg_student_progress = null;
 212              }
 213  
 214              $row = array();
 215              if ($is_western_name_order) {
 216                  $row[] = $student_data['firstname'];
 217                  $row[] = $student_data['lastname'];
 218              } else {
 219                  $row[] = $student_data['lastname'];
 220                  $row[] = $student_data['firstname'];
 221              }
 222              $row[] = api_time_to_hms($avg_time_spent);
 223              $row[] = is_null($avg_student_progress) ? null : round($avg_student_progress, 2).'%';
 224              $row[] = is_null($avg_student_score) ? null : round($avg_student_score, 2).'%';
 225              $row[] = $total_assignments;
 226              $row[] = $total_messages;
 227  
 228              $string_date = Tracking :: get_last_connection_date($student_id, true);
 229              $first_date = Tracking :: get_first_connection_date($student_id);
 230              $row[] = $first_date;
 231              $row[] = $string_date;
 232  
 233              if ($export_csv) {
 234                  $csv_content[] = $row;
 235              }
 236  
 237              if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
 238                  $row[] = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.Security::remove_XSS($_GET['id_session']).'">'.Display::return_icon('pixel.gif','',array('class'=>'actionplaceholdericon actionstatisticsdetails')).'</a>';
 239              } else {
 240                  $row[] = '<a href="myStudents.php?student='.$student_id.'">'.Display::return_icon('pixel.gif','',array('class'=>'actionplaceholdericon actionstatisticsdetails')).'</a>';
 241              }
 242  
 243              $all_datas[] = $row;
 244          }
 245  
 246          if ($tracking_direction == 'ASC') {
 247              usort($all_datas, 'rsort_users');
 248          } else {
 249              usort($all_datas, 'sort_users');
 250          }
 251  
 252          if ($export_csv) {
 253              usort($csv_content, 'sort_users');
 254              $csv_content = array_merge($csv_header, $csv_content);
 255          }
 256  
 257          foreach ($all_datas as $row) {
 258              $table -> addRow($row, 'align="right"');
 259          }
 260          $table -> updateColAttributes(0, array('align' => 'left'));
 261          $table -> updateColAttributes(1, array('align' => 'left'));
 262          $table -> updateColAttributes(7, array('align' => 'left'));
 263          $table -> updateColAttributes(8, array('align' => 'left'));
 264          $table -> setColAttributes(9, array('align' => 'center'));
 265          $table -> display();
 266      } else {
 267          echo get_lang('NoStudent');
 268      }
 269  
 270      // send the csv file if asked
 271      if ($export_csv) {
 272          ob_end_clean();
 273          Export :: export_table_csv($csv_content, 'reporting_student_list');
 274      }
 275  }
 276  
 277  /*
 278  ==============================================================================
 279          FOOTER
 280  ==============================================================================
 281  */
 282  echo '</div>';
 283  Display :: display_footer();

title

Description

title

Description

title

Description

title

title

Body