diff --git a/main/mySpace/access_details.php b/main/mySpace/access_details.php index a4e8c76941..561df08c78 100755 --- a/main/mySpace/access_details.php +++ b/main/mySpace/access_details.php @@ -24,6 +24,7 @@ require '../inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php'; +require_once 'myspace.lib.php'; // the section (for the tabs) $this_section = "session_my_space"; @@ -33,7 +34,7 @@ $this_section = "session_my_space"; $user_id = Security::remove_XSS($_REQUEST['student']); $course_code = Security::remove_XSS($_REQUEST['course']); -$connections = get_connections_to_course($user_id, $course_code); +$connections = MySpace::get_connections_to_course($user_id, $course_code); if (api_is_xml_http_request()) { $type = Security::remove_XSS($_GET['type']); $main_year = $main_month_year = $main_day = array(); @@ -218,89 +219,4 @@ foreach ($connections as $key => $data) { echo (""); */ -Display:: display_footer(); - - -/* ------------------------------------------------------------ - Functions ------------------------------------------------------------ -*/ - -/** - * Gets the connections to a course as an array of login and logout time - * - * @param unknown_type $user_id - * @param unknown_type $course_code - * @return unknown - */ -function get_connections_to_course($user_id, $course_code) { - // Database table definitions - $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); - $tbl_main = Database :: get_main_table(TABLE_MAIN_COURSE); - - $sql_query = 'SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database::escape_string($course_code).'";'; - $result = Database::query($sql_query); - $row_query = Database::fetch_array($result, 'ASSOC'); - $course_true = isset($row_query['course_code']) ? $row_query['course_code']: $course_code; - - $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . ' - WHERE user_id = ' . intval($user_id) . ' - AND course_code="' . Database::escape_string($course_true) . '" ORDER BY login_course_date ASC'; - - $rs = Database::query($sql); - $connections = array(); - - while ($row = Database::fetch_array($rs)) { - - $login_date = $row['login_course_date']; - $logout_date = $row['logout_course_date']; - - $login_date = api_get_local_time($login_date, null, null, date_default_timezone_get()); - $logout_date = api_get_local_time($logout_date, null, null, date_default_timezone_get()); - - $timestamp_login_date = strtotime($login_date); - $timestamp_logout_date = strtotime($logout_date); - - $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date); - } - return $connections; -} - -/** - * TODO: Not used, to b deleted? - * Enter description here... - * - * @param unknown_type $user_id - * @param unknown_type $course_code - * @param unknown_type $year - * @param unknown_type $month - * @param unknown_type $day - * @return unknown - */ -function get_connections_to_course_by_time($user_id, $course_code, $year = '', $month = '', $day = '') { - // Database table definitions - $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); - $tbl_main = Database :: get_main_table(TABLE_MAIN_COURSE); - - $sql_query = 'SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database :: escape_string($course_code).'";'; - $result = Database::query($sql_query); - $row_query = Database::fetch_array($result,'ASSOC'); - $course_true = isset($row_query['course_code']) ? $row_query['course_code']: $course_code; - - $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . ' - WHERE user_id = ' . intval($user_id) . ' - AND course_code="' . Database::escape_string($course_true) . '" - ORDER BY login_course_date DESC'; - - $rs = Database::query($sql); - $connections = array(); - while ($row = Database::fetch_array($rs)) { - $login_date = $row['login_course_date']; - $logout_date = $row['logout_course_date']; - $timestamp_login_date = strtotime($login_date); - $timestamp_logout_date = strtotime($logout_date); - $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date); - } - return $connections; -} +Display:: display_footer(); \ No newline at end of file diff --git a/main/mySpace/coaches.php b/main/mySpace/coaches.php index 5159b6ca86..376f7d0ddd 100755 --- a/main/mySpace/coaches.php +++ b/main/mySpace/coaches.php @@ -44,6 +44,8 @@ $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ FUNCTIONS =============================================================================== */ + +/*Posible Deprecated*/ function is_coach() { global $tbl_session_course; diff --git a/main/mySpace/index.php b/main/mySpace/index.php index 7ccc2082d9..9239d63674 100755 --- a/main/mySpace/index.php +++ b/main/mySpace/index.php @@ -17,6 +17,7 @@ require_once api_get_path(LIBRARY_PATH).'tracking.lib.php'; require_once api_get_path(LIBRARY_PATH).'course.lib.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php'; +require_once 'myspace.lib.php'; // the section (for the tabs) $this_section = 'session_my_space'; @@ -33,7 +34,7 @@ if (!$export_csv) { Display :: display_header($nameTools); } else { if ($_GET['view'] == 'admin' AND $_GET['display'] == 'useroverview') { - export_tracking_user_overview(); + MySpace::export_tracking_user_overview(); exit; } } @@ -453,7 +454,7 @@ echo '
 
'; if (api_is_allowed_to_create_course() && $view == 'teacher') { if ($nb_teacher_courses) { - $table = new SortableTable('courses', 'get_number_of_courses' ,'get_course_data'); + $table = new SortableTable('courses', 'get_number_of_courses' ,array('MySpace','get_course_data')); $parameters['view'] = 'teacher'; $parameters['class'] = 'data_table'; $table->set_additional_parameters($parameters); @@ -489,7 +490,7 @@ if ($is_platform_admin && $view == 'admin') { } echo '

'; if ($_GET['display'] === 'useroverview') { - display_tracking_user_overview(); + MySpace::display_tracking_user_overview(); } else { if ($export_csv) { $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT); @@ -683,452 +684,6 @@ if ($export_csv) { if (!$export_csv) { Display::display_footer(); } - -/** - * This function exports the table that we see in display_tracking_user_overview() - * - * @author Patrick Cool , Ghent University, Belgium - * @version Dokeos 1.8.6 - * @since October 2008 - */ -function export_tracking_user_overview() { - // database table definitions - $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - - $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT); - $sort_by_first_name = api_sort_by_first_name(); - - // the values of the sortable table - if ($_GET['tracking_user_overview_page_nr']) { - $from = $_GET['tracking_user_overview_page_nr']; - } else { - $from = 0; - } - if ($_GET['tracking_user_overview_column']) { - $orderby = $_GET['tracking_user_overview_column']; - } else { - $orderby = 0; - } - if ($is_western_name_order != api_is_western_name_order() && ($orderby == 1 || $orderby == 2)) { - // Swapping the sorting column if name order for export is different than the common name order. - $orderby = 3 - $orderby; - } - if ($_GET['tracking_user_overview_direction']) { - $direction = $_GET['tracking_user_overview_direction']; - } else { - $direction = 'ASC'; - } - - $user_data = get_user_data_tracking_overview($from, 1000, $orderby, $direction); - - // the first line of the csv file with the column headers - $csv_row = array(); - $csv_row[] = get_lang('OfficialCode'); - if ($is_western_name_order) { - $csv_row[] = get_lang('FirstName', ''); - $csv_row[] = get_lang('LastName', ''); - } else { - $csv_row[] = get_lang('LastName', ''); - $csv_row[] = get_lang('FirstName', ''); - } - $csv_row[] = get_lang('LoginName'); - $csv_row[] = get_lang('CourseCode'); - // the additional user defined fields (only those that were selected to be exported) - require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php'); - $fields = UserManager::get_extra_fields(0, 50, 5, 'ASC'); - - if (is_array($_SESSION['additional_export_fields'])) { - foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) { - $csv_row[] = $fields[$extra_field_export][3]; - $field_names_to_be_exported[] = 'extra_'.$fields[$extra_field_export][1]; - } - } - $csv_row[] = get_lang('AvgTimeSpentInTheCourse', ''); - $csv_row[] = get_lang('AvgStudentsProgress', ''); - $csv_row[] = get_lang('AvgCourseScore', ''); - $csv_row[] = get_lang('AvgExercisesScore', ''); - $csv_row[] = get_lang('AvgMessages', ''); - $csv_row[] = get_lang('AvgAssignments', ''); - $csv_row[] = get_lang('TotalExercisesScoreObtained', ''); - $csv_row[] = get_lang('TotalExercisesScorePossible', ''); - $csv_row[] = get_lang('TotalExercisesAnswered', ''); - $csv_row[] = get_lang('TotalExercisesScorePercentage', ''); - $csv_row[] = get_lang('FirstLogin', ''); - $csv_row[] = get_lang('LatestLogin', ''); - $csv_content[] = $csv_row; - - // the other lines (the data) - foreach ($user_data as $key => $user) { - // getting all the courses of the user - $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user[4])."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." "; - $result = Database::query($sql); - while ($row = Database::fetch_row($result)) { - $csv_row = array(); - // user official code - $csv_row[] = $user[0]; - // user first|last name - $csv_row[] = $user[1]; - // user last|first name - $csv_row[] = $user[2]; - // user login name - $csv_row[] = $user[3]; - // course code - $csv_row[] = $row[0]; - // the additional defined user fields - $extra_fields = get_user_overview_export_extra_fields($user[4]); - - if (is_array($field_names_to_be_exported)) { - foreach ($field_names_to_be_exported as $key => $extra_field_export) { - $csv_row[] = $extra_fields[$extra_field_export]; - } - } - // time spent in the course - $csv_row[] = api_time_to_hms(Tracking :: get_time_spent_on_the_course ($user[4], $row[0])); - // student progress in course - $csv_row[] = round(Tracking :: get_avg_student_progress ($user[4], $row[0]), 2); - // student score - $csv_row[] = round(Tracking :: get_avg_student_score ($user[4], $row[0]), 2); - // student tes score - $csv_row[] = round(Tracking :: get_avg_student_exercise_score ($user[4], $row[0]), 2); - // student messages - $csv_row[] = Tracking :: count_student_messages ($user[4], $row[0]); - // student assignments - $csv_row[] = Tracking :: count_student_assignments ($user[4], $row[0]); - // student exercises results - $exercises_results = exercises_results($user[4], $row[0]); - $csv_row[] = $exercises_results['score_obtained']; - $csv_row[] = $exercises_results['score_possible']; - $csv_row[] = $exercises_results['questions_answered']; - $csv_row[] = $exercises_results['percentage']; - // first connection - $csv_row[] = Tracking :: get_first_connection_date_on_the_course ($user[4], $row[0]); - // last connection - $csv_row[] = strip_tags(Tracking :: get_last_connection_date_on_the_course ($user[4], $row[0])); - - $csv_content[] = $csv_row; - } - } - Export :: export_table_csv($csv_content, 'reporting_user_overview'); - exit; -} - -/** - * Display a sortable table that contains an overview off all the reporting progress of all users and all courses the user is subscribed to - * - * @author Patrick Cool , Ghent University, Belgium - * @version Dokeos 1.8.6 - * @since October 2008 - */ -function display_tracking_user_overview() { - display_user_overview_export_options(); - - $t_head .= ' '; - $t_head .= ' '; - $t_head .= ''; - $t_head .= ' '; - $t_head .= ' '; - $t_head .= ' '; - $t_head .= ' '; - //$t_head .= ' '; - $t_head .= ' '; - $t_head .= ' '; - $t_head .= ' '; - //$t_head .= ' '; - $t_head .= ' '; - //$t_head .= ' '; - //$t_head .= ' '; - $t_head .= ' '; - $t_head .= '
'.get_lang('CourseInformation').'
'.get_lang('Course').''.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).''.cut(get_lang('AvgStudentsProgress'), 6, true).''.cut(get_lang('AvgCourseScore'), 6, true).'
'.get_lang('AvgExercisesScore').'
'.cut(get_lang('AvgMessages'), 6, true).''.cut(get_lang('AvgAssignments'), 6, true).''.get_lang('TotalExercisesScoreObtained').'
'.get_lang('TotalExercisesScorePossible').'
'.cut(get_lang('TotalExercisesAnswered'), 6, true).'
'.get_lang('TotalExercisesScorePercentage').'
'.get_lang('FirstLogin').'
'.get_lang('LatestLogin').'
'; - - $addparams = array('view' => 'admin', 'display' => 'useroverview'); - - $table = new SortableTable('tracking_user_overview', 'get_number_of_users_tracking_overview', 'get_user_data_tracking_overview', 0); - $table->additional_parameters = $addparams; - - $table->set_header(0, get_lang('OfficialCode'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); - if (api_is_western_name_order()) { - $table->set_header(1, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); - $table->set_header(2, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); - } else { - $table->set_header(1, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); - $table->set_header(2, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); - } - $table->set_header(3, get_lang('LoginName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); - $table->set_header(4, $t_head, false, array('style' => 'width:90%;border:0;padding:0;font-size:7.5pt;'), array('style' => 'width:90%;padding:0;font-size:7.5pt;')); - $table->set_column_filter(4, 'course_info_tracking_filter'); - $table->display(); -} - -/** - * get the numer of users of the platform - * - * @return integer - * - * @author Patrick Cool , Ghent University, Belgium - * @version Dokeos 1.8.6 - * @since October 2008 - */ -function get_number_of_users_tracking_overview() { - // database table definition - $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); - - // query - $sql = 'SELECT user_id FROM '.$main_user_table; - $result = Database::query($sql); - - // return the number of results - return Database::num_rows($result); -} - -/** - * get all the data for the sortable table of the reporting progress of all users and all the courses the user is subscribed to. - * - * @author Patrick Cool , Ghent University, Belgium - * @version Dokeos 1.8.6 - * @since October 2008 - */ -function get_user_data_tracking_overview($from, $number_of_items, $column, $direction) { - // database table definition - $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); - global $export_csv; - if ($export_csv) { - $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT); - } else { - $is_western_name_order = api_is_western_name_order(); - } - $sql = "SELECT - official_code AS col0, - ".($is_western_name_order ? " - firstname AS col1, - lastname AS col2, - " : " - lastname AS col1, - firstname AS col2, - "). - "username AS col3, - user_id AS col4 - FROM - $main_user_table - "; - $sql .= " ORDER BY col$column $direction "; - $sql .= " LIMIT $from,$number_of_items"; - $result = Database::query($sql); - $return = array (); - while ($user = Database::fetch_row($result)) { - $return[] = $user; - } - return $return; -} - -/** - * Creates a small table in the last column of the table with the user overview - * - * @param integer $user_id the id of the user - * @param array $url_params additonal url parameters - * @param array $row the row information (the other columns) - * @return html code - * - * @author Patrick Cool , Ghent University, Belgium - * @version Dokeos 1.8.6 - * @since October 2008 - */ -function course_info_tracking_filter($user_id, $url_params, $row) { - // the table header - $return .= ''; - /*$return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' '; - $return .= ' ';*/ - - // database table definition - $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - - // getting all the courses of the user - $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user_id)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." "; - $result = Database::query($sql); - while ($row = Database::fetch_row($result)) { - $return .= ''; - // course code - $return .= ' '; - // time spent in the course - $return .= ' '; - // student progress in course - $return .= ' '; - // student score - $return .= ' '; - // student tes score - //$return .= ' '; - // student messages - $return .= ' '; - // student assignments - $return .= ' '; - // student exercises results (obtained score, maximum score, number of exercises answered, score percentage) - $exercises_results = exercises_results($user_id, $row[0]); - $return .= ' '; - //$return .= ' '; - $return .= ' '; - //$return .= ' '; - // first connection - //$return .= ' '; - // last connection - $return .= ' '; - $return .= ''; - } - $return .= '
'.get_lang('Course').''.get_lang('AvgTimeSpentInTheCourse').''.get_lang('AvgStudentsProgress').''.get_lang('AvgCourseScore').''.get_lang('AvgExercisesScore').''.get_lang('AvgMessages').''.get_lang('AvgAssignments').''.get_lang('TotalExercisesScoreObtained').''.get_lang('TotalExercisesScorePossible').''.get_lang('TotalExercisesAnswered').''.get_lang('TotalExercisesScorePercentage').''.get_lang('FirstLogin').''.get_lang('LatestLogin').'
'.cut($row[0], 20, true).'
'.api_time_to_hms(Tracking :: get_time_spent_on_the_course($user_id, $row[0])).'
'.round(Tracking :: get_avg_student_progress($user_id, $row[0]), 2).'
'.round(Tracking :: get_avg_student_score($user_id, $row[0]), 2).'
'.round(Tracking :: get_avg_student_exercise_score ($user_id, $row[0]),2).'%
'.Tracking :: count_student_messages($user_id, $row[0]).'
'.Tracking :: count_student_assignments($user_id, $row[0]).'
'.(is_null($exercises_results['percentage']) ? '' : $exercises_results['score_obtained'].'/'.$exercises_results['score_possible'].' ( '.$exercises_results['percentage'].'% )').'
'.$exercises_results['score_possible'].'
'.$exercises_results['questions_answered'].'
'.$exercises_results['percentage'].'%
'.Tracking :: get_first_connection_date_on_the_course ($user_id, $row[0]).'
'.Tracking :: get_last_connection_date_on_the_course ($user_id, $row[0]).'
'; - return $return; -} - -/** - * Get general information about the exercise performance of the user - * the total obtained score (all the score on all the questions) - * the maximum score that could be obtained - * the number of questions answered - * the success percentage - * - * @param integer $user_id the id of the user - * @param string $course_code the course code - * - * @author Patrick Cool , Ghent University, Belgium - * @version Dokeos 1.8.6 - * @since November 2008 - */ -function exercises_results($user_id, $course_code) { - $questions_answered = 0; - $sql = 'SELECT exe_result , exe_weighting - FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES)." - WHERE exe_cours_id = '".Database::escape_string($course_code)."' - AND exe_user_id = '".Database::escape_string($user_id)."'"; - $result = Database::query($sql); - $score_obtained = 0; - $score_possible = 0; - $questions_answered = 0; - while ($row = Database::fetch_array($result)) { - $score_obtained += $row['exe_result']; - $score_possible += $row['exe_weighting']; - $questions_answered ++; - } - - if ($score_possible != 0) { - $percentage = round(($score_obtained / $score_possible * 100), 2); - } else { - $percentage = null; - } - - return array('score_obtained' => $score_obtained, 'score_possible' => $score_possible, 'questions_answered' => $questions_answered, 'percentage' => $percentage); -} - -/** - * Displays a form with all the additionally defined user fields of the profile - * and give you the opportunity to include these in the CSV export - * - * @author Patrick Cool , Ghent University, Belgium - * @version Dokeos 1.8.6 - * @since November 2008 - */ -function display_user_overview_export_options() { - // include the user manager and formvalidator library - require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; - require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; - - if ($_GET['export'] == 'options') { - // get all the defined extra fields - $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC', false); - - // creating the form with all the defined extra fields - $form = new FormValidator('exportextrafields', 'post', api_get_self()."?view=".Security::remove_XSS($_GET['view']).'&display='.Security::remove_XSS($_GET['display']).'&export='.Security::remove_XSS($_GET['export'])); - - if (is_array($extrafields) && count($extrafields) > 0) { - foreach ($extrafields as $key => $extra) { - $form->addElement('checkbox', 'extra_export_field'.$extra[0], '', $extra[3]); - } - $form->addElement('style_submit_button','submit', get_lang('Ok'),'class="save"' ); - - // setting the default values for the form that contains all the extra fields - if (is_array($_SESSION['additional_export_fields'])) { - foreach ($_SESSION['additional_export_fields'] as $key => $value) { - $defaults['extra_export_field'.$value] = 1; - } - } - $form->setDefaults($defaults); - } else { - $form->addElement('html', Display::display_warning_message(get_lang('ThereAreNotExtrafieldsAvailable'))); - } - - if ($form->validate()) { - // exporting the form values - $values = $form->exportValues(); - - // re-initialising the session that contains the additional fields that need to be exported - $_SESSION['additional_export_fields'] = array(); - - // adding the fields that are checked to the session - $message = ''; - foreach ($values as $field_ids => $value) { - if ($value == 1 && strstr($field_ids,'extra_export_field')) { - $_SESSION['additional_export_fields'][] = str_replace('extra_export_field', '', $field_ids); - } - } - - // adding the fields that will be also exported to a message string - if (is_array($_SESSION['additional_export_fields'])) { - foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) { - $message .= '
  • '.$extrafields[$extra_field_export][3].'
  • '; - } - } - - // Displaying a feedback message - if (!empty($_SESSION['additional_export_fields'])) { - Display::display_confirmation_message(get_lang('FollowingFieldsWillAlsoBeExported').':
      '.$message.'
    ', false); - } else { - Display::display_confirmation_message(get_lang('NoAdditionalFieldsWillBeExported'), false); - } - $message = ''; - } else { - $form->display(); - } - - } else { - if (!empty($_SESSION['additional_export_fields'])) { - // get all the defined extra fields - $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC'); - - foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) { - $message .= '
  • '.$extrafields[$extra_field_export][3].'
  • '; - } - - Display::display_normal_message(get_lang('FollowingFieldsWillAlsoBeExported').':
      '.$message.'
    ', false); - $message = ''; - } - } -} - -/** - * Get all information that the user with user_id = $user_data has - * entered in the additionally defined profile fields - * - * @param integer $user_id the id of the user - * - * @author Patrick Cool , Ghent University, Belgium - * @version Dokeos 1.8.6 - * @since November 2008 - */ -function get_user_overview_export_extra_fields($user_id) { - // include the user manager - require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; - $extra_data = UserManager::get_extra_user_data($user_id, true); - return $extra_data; -} /** * Get number of courses for sortable with pagination * @return int @@ -1137,96 +692,3 @@ function get_number_of_courses() { global $courses; return count($courses); } -/** - * Get data for courses list in sortable with pagination - * @return array - */ -function get_course_data($from, $number_of_items, $column, $direction) { - - global $courses, $csv_content, $charset ; - global $tbl_course, $tbl_course_user, $tbl_track_cours_access, $tbl_session_course_user; - - $a_course_students = array(); - $course_data = array(); - $arr_course = $courses; - foreach ($arr_course as &$cours) { - $cours = "'{$cours[course_code]}'"; - } - - // get all courses with limit - $sql = "SELECT course.code as col1, course.title as col2 - FROM $tbl_course course - WHERE course.code IN (".implode(',',$arr_course).")"; - if (!in_array($direction, array('ASC','DESC'))) $direction = 'ASC'; - - $column = intval($column); - $from = intval($from); - $number_of_items = intval($number_of_items); - $sql .= " ORDER BY col$column $direction "; - $sql .= " LIMIT $from,$number_of_items"; - - $res = Database::query($sql); - while ($row_course = Database::fetch_row($res)) { - - $course_code = $row_course[0]; - $course_info = api_get_course_info($course_code); - $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0; - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']); - $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST, $course_info['dbName']); - $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $course_info['dbName']); - $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $course_info['dbName']); - - // students directly subscribed to the course - $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code' - UNION DISTINCT SELECT id_user as user_id FROM $tbl_session_course_user srcu WHERE srcu. course_code='$course_code'"; - $rs = Database::query($sql); - $users = array(); - while ($row = Database::fetch_array($rs)) { - $users[] = $row['user_id']; - } - if (count($users) > 0) { - $nb_students_in_course = count($users); - $avg_assignments_in_course = Tracking::count_student_assignments($users, $course_code); - $avg_messages_in_course = Tracking::count_student_messages($users, $course_code); - $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $course_code); - $avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code); - $avg_score_in_course = Tracking :: get_avg_student_score($users, $course_code); - $avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code); - - $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course); - $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2); - $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2); - $avg_score_in_exercise = round($avg_score_in_exercise / $nb_students_in_course, 2); - } else { - $avg_time_spent_in_course = null; - $avg_progress_in_course = null; - $avg_score_in_course = null; - $avg_score_in_exercise = null; - $avg_messages_in_course = null; - $avg_assignments_in_course = null; - } - $table_row = array(); - $table_row[] = $row_course[1]; - $table_row[] = $nb_students_in_course; - $table_row[] = $avg_time_spent_in_course; - $table_row[] = is_null($avg_progress_in_course) ? '' : $avg_progress_in_course.'%'; - $table_row[] = is_null($avg_score_in_course) ? '' : $avg_score_in_course.'%'; - $table_row[] = is_null($avg_score_in_exercise) ? '' : $avg_score_in_exercise.'%'; - $table_row[] = $avg_messages_in_course; - $table_row[] = $avg_assignments_in_course; - //set the "from" value to know if I access the Reporting by the Dokeos tab or the course link - $table_row[] = '
    '; - $csv_content[] = array( - api_html_entity_decode($row_course[1], ENT_QUOTES, $charset), - $nb_students_in_course, - $avg_time_spent_in_course, - is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%', - is_null($avg_score_in_course) ? null : $avg_score_in_course.'%', - is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%', - $avg_messages_in_course, - $avg_assignments_in_course, - ); - $course_data[] = $table_row; - } - return $course_data; -} \ No newline at end of file diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 9de277ce93..93f2f0834f 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -165,7 +165,8 @@ Display :: display_header($nameTools); * FUNCTIONS * ====================================================================================== */ - + +/* Possible Deprecated function is_teacher($course_code) { global $_user; $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); @@ -177,7 +178,7 @@ function is_teacher($course_code) { return false; } } - +*/ /* *=============================================================================== * MAIN CODE diff --git a/main/mySpace/myspace.lib.php b/main/mySpace/myspace.lib.php index 1bef6e4645..3d46dd6f22 100755 --- a/main/mySpace/myspace.lib.php +++ b/main/mySpace/myspace.lib.php @@ -1,41 +1,1123 @@ $timestamp_login_date, 'logout' => $timestamp_logout_date); + } + return $connections; + } + + /** + * TODO: Not used, to b deleted? + * Enter description here... + * @param int $user_id + * @param string $course_code + * @param date $year + * @param date $month + * @param date $day + * @return unknown + */ + function get_connections_to_course_by_time($user_id, $course_code, $year = '', $month = '', $day = '') { + // Database table definitions + $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + $tbl_main = Database :: get_main_table(TABLE_MAIN_COURSE); + + $sql_query = 'SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database :: escape_string($course_code).'";'; + $result = Database::query($sql_query); + $row_query = Database::fetch_array($result,'ASSOC'); + $course_true = isset($row_query['course_code']) ? $row_query['course_code']: $course_code; + + $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . ' + WHERE user_id = ' . intval($user_id) . ' + AND course_code="' . Database::escape_string($course_true) . '" + ORDER BY login_course_date DESC'; + + $rs = Database::query($sql); + $connections = array(); + while ($row = Database::fetch_array($rs)) { + $login_date = $row['login_course_date']; + $logout_date = $row['logout_course_date']; + $timestamp_login_date = strtotime($login_date); + $timestamp_logout_date = strtotime($logout_date); + $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date); + } + return $connections; + } + + /** + * Creates a small table in the last column of the table with the user overview + * + * @param integer $user_id the id of the user + * @param array $url_params additonal url parameters + * @param array $row the row information (the other columns) + * @return string html code + */ + function course_info_tracking_filter($user_id, $url_params, $row) { + // the table header + $return .= ''; + /*$return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' '; + $return .= ' ';*/ + + // database table definition + $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + + // getting all the courses of the user + $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user_id)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." "; + $result = Database::query($sql); + while ($row = Database::fetch_row($result)) { + $return .= ''; + // course code + $return .= ' '; + // time spent in the course + $return .= ' '; + // student progress in course + $return .= ' '; + // student score + $return .= ' '; + // student tes score + //$return .= ' '; + // student messages + $return .= ' '; + // student assignments + $return .= ' '; + // student exercises results (obtained score, maximum score, number of exercises answered, score percentage) + $exercises_results = MySpace::exercises_results($user_id, $row[0]); + $return .= ' '; + //$return .= ' '; + $return .= ' '; + //$return .= ' '; + // first connection + //$return .= ' '; + // last connection + $return .= ' '; + $return .= ''; + } + $return .= '
    '.get_lang('Course').''.get_lang('AvgTimeSpentInTheCourse').''.get_lang('AvgStudentsProgress').''.get_lang('AvgCourseScore').''.get_lang('AvgExercisesScore').''.get_lang('AvgMessages').''.get_lang('AvgAssignments').''.get_lang('TotalExercisesScoreObtained').''.get_lang('TotalExercisesScorePossible').''.get_lang('TotalExercisesAnswered').''.get_lang('TotalExercisesScorePercentage').''.get_lang('FirstLogin').''.get_lang('LatestLogin').'
    '.cut($row[0], 20, true).'
    '.api_time_to_hms(Tracking :: get_time_spent_on_the_course($user_id, $row[0])).'
    '.round(Tracking :: get_avg_student_progress($user_id, $row[0]), 2).'
    '.round(Tracking :: get_avg_student_score($user_id, $row[0]), 2).'
    '.round(Tracking :: get_avg_student_exercise_score ($user_id, $row[0]),2).'%
    '.Tracking :: count_student_messages($user_id, $row[0]).'
    '.Tracking :: count_student_assignments($user_id, $row[0]).'
    '.(is_null($exercises_results['percentage']) ? '' : $exercises_results['score_obtained'].'/'.$exercises_results['score_possible'].' ( '.$exercises_results['percentage'].'% )').'
    '.$exercises_results['score_possible'].'
    '.$exercises_results['questions_answered'].'
    '.$exercises_results['percentage'].'%
    '.Tracking :: get_first_connection_date_on_the_course ($user_id, $row[0]).'
    '.Tracking :: get_last_connection_date_on_the_course ($user_id, $row[0]).'
    '; + return $return; + } - if (!$open = fopen($archive_path.$file_name, 'w+')) { - $message = get_lang('noOpen'); - } else { - $info = ''; + /** + * Display a sortable table that contains an overview off all the reporting progress of all users and all courses the user is subscribed to + * @author Patrick Cool , Ghent University, Belgium + * @version Dokeos 1.8.6 + * @since October 2008 + */ + function display_tracking_user_overview() { + MySpace::display_user_overview_export_options(); + + $t_head .= ' '; + $t_head .= ' '; + $t_head .= ''; + $t_head .= ' '; + $t_head .= ' '; + $t_head .= ' '; + $t_head .= ' '; + //$t_head .= ' '; + $t_head .= ' '; + $t_head .= ' '; + $t_head .= ' '; + //$t_head .= ' '; + $t_head .= ' '; + //$t_head .= ' '; + //$t_head .= ' '; + $t_head .= ' '; + $t_head .= '
    '.get_lang('CourseInformation').'
    '.get_lang('Course').''.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).''.cut(get_lang('AvgStudentsProgress'), 6, true).''.cut(get_lang('AvgCourseScore'), 6, true).'
    '.get_lang('AvgExercisesScore').'
    '.cut(get_lang('AvgMessages'), 6, true).''.cut(get_lang('AvgAssignments'), 6, true).''.get_lang('TotalExercisesScoreObtained').'
    '.get_lang('TotalExercisesScorePossible').'
    '.cut(get_lang('TotalExercisesAnswered'), 6, true).'
    '.get_lang('TotalExercisesScorePercentage').'
    '.get_lang('FirstLogin').'
    '.get_lang('LatestLogin').'
    '; + + $addparams = array('view' => 'admin', 'display' => 'useroverview'); + + $table = new SortableTable('tracking_user_overview', array('MySpace','get_number_of_users_tracking_overview'), array('MySpace','get_user_data_tracking_overview'), 0); + $table->additional_parameters = $addparams; + + $table->set_header(0, get_lang('OfficialCode'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); + if (api_is_western_name_order()) { + $table->set_header(1, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); + $table->set_header(2, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); + } else { + $table->set_header(1, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); + $table->set_header(2, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); + } + $table->set_header(3, get_lang('LoginName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt')); + $table->set_header(4, $t_head, false, array('style' => 'width:90%;border:0;padding:0;font-size:7.5pt;'), array('style' => 'width:90%;padding:0;font-size:7.5pt;')); + $table->set_column_filter(4, array('MySpace','course_info_tracking_filter')); + $table->display(); + } + + /** + * Displays a form with all the additionally defined user fields of the profile + * and give you the opportunity to include these in the CSV export + * + * @author Patrick Cool , Ghent University, Belgium + * @version Dokeos 1.8.6 + * @since November 2008 + */ + function display_user_overview_export_options() { + // include the user manager and formvalidator library + require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; + require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; + + if ($_GET['export'] == 'options') { + // get all the defined extra fields + $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC', false); + + // creating the form with all the defined extra fields + $form = new FormValidator('exportextrafields', 'post', api_get_self()."?view=".Security::remove_XSS($_GET['view']).'&display='.Security::remove_XSS($_GET['display']).'&export='.Security::remove_XSS($_GET['export'])); + + if (is_array($extrafields) && count($extrafields) > 0) { + foreach ($extrafields as $key => $extra) { + $form->addElement('checkbox', 'extra_export_field'.$extra[0], '', $extra[3]); + } + $form->addElement('style_submit_button','submit', get_lang('Ok'),'class="save"' ); + + // setting the default values for the form that contains all the extra fields + if (is_array($_SESSION['additional_export_fields'])) { + foreach ($_SESSION['additional_export_fields'] as $key => $value) { + $defaults['extra_export_field'.$value] = 1; + } + } + $form->setDefaults($defaults); + } else { + $form->addElement('html', Display::display_warning_message(get_lang('ThereAreNotExtrafieldsAvailable'))); + } + + if ($form->validate()) { + // exporting the form values + $values = $form->exportValues(); + + // re-initialising the session that contains the additional fields that need to be exported + $_SESSION['additional_export_fields'] = array(); + + // adding the fields that are checked to the session + $message = ''; + foreach ($values as $field_ids => $value) { + if ($value == 1 && strstr($field_ids,'extra_export_field')) { + $_SESSION['additional_export_fields'][] = str_replace('extra_export_field', '', $field_ids); + } + } + + // adding the fields that will be also exported to a message string + if (is_array($_SESSION['additional_export_fields'])) { + foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) { + $message .= '
  • '.$extrafields[$extra_field_export][3].'
  • '; + } + } + + // Displaying a feedback message + if (!empty($_SESSION['additional_export_fields'])) { + Display::display_confirmation_message(get_lang('FollowingFieldsWillAlsoBeExported').':
      '.$message.'
    ', false); + } else { + Display::display_confirmation_message(get_lang('NoAdditionalFieldsWillBeExported'), false); + } + $message = ''; + } else { + $form->display(); + } + + } else { + if (!empty($_SESSION['additional_export_fields'])) { + // get all the defined extra fields + $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC'); + + foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) { + $message .= '
  • '.$extrafields[$extra_field_export][3].'
  • '; + } + + Display::display_normal_message(get_lang('FollowingFieldsWillAlsoBeExported').':
      '.$message.'
    ', false); + $message = ''; + } + } + } + + /** + * Get general information about the exercise performance of the user + * the total obtained score (all the score on all the questions) + * the maximum score that could be obtained + * the number of questions answered + * the success percentage + * @param integer $user_id the id of the user + * @param string $course_code the course code + * @return array + * @author Patrick Cool , Ghent University, Belgium + * @version Dokeos 1.8.6 + * @since November 2008 + */ + function exercises_results($user_id, $course_code) { + $questions_answered = 0; + $sql = 'SELECT exe_result , exe_weighting + FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES)." + WHERE exe_cours_id = '".Database::escape_string($course_code)."' + AND exe_user_id = '".Database::escape_string($user_id)."'"; + $result = Database::query($sql); + $score_obtained = 0; + $score_possible = 0; + $questions_answered = 0; + while ($row = Database::fetch_array($result)) { + $score_obtained += $row['exe_result']; + $score_possible += $row['exe_weighting']; + $questions_answered ++; + } + + if ($score_possible != 0) { + $percentage = round(($score_obtained / $score_possible * 100), 2); + } else { + $percentage = null; + } + + return array('score_obtained' => $score_obtained, 'score_possible' => $score_possible, 'questions_answered' => $questions_answered, 'percentage' => $percentage); + } - foreach ($header as $value) { - $info .= $value.';'; + /** + * This function exports the table that we see in display_tracking_user_overview() + * + * @author Patrick Cool , Ghent University, Belgium + * @version Dokeos 1.8.6 + * @since October 2008 + */ + function export_tracking_user_overview() { + // database table definitions + $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + + $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT); + $sort_by_first_name = api_sort_by_first_name(); + + // the values of the sortable table + if ($_GET['tracking_user_overview_page_nr']) { + $from = $_GET['tracking_user_overview_page_nr']; + } else { + $from = 0; + } + if ($_GET['tracking_user_overview_column']) { + $orderby = $_GET['tracking_user_overview_column']; + } else { + $orderby = 0; + } + if ($is_western_name_order != api_is_western_name_order() && ($orderby == 1 || $orderby == 2)) { + // Swapping the sorting column if name order for export is different than the common name order. + $orderby = 3 - $orderby; + } + if ($_GET['tracking_user_overview_direction']) { + $direction = $_GET['tracking_user_overview_direction']; + } else { + $direction = 'ASC'; + } + + $user_data = MySpace::get_user_data_tracking_overview($from, 1000, $orderby, $direction); + + // the first line of the csv file with the column headers + $csv_row = array(); + $csv_row[] = get_lang('OfficialCode'); + if ($is_western_name_order) { + $csv_row[] = get_lang('FirstName', ''); + $csv_row[] = get_lang('LastName', ''); + } else { + $csv_row[] = get_lang('LastName', ''); + $csv_row[] = get_lang('FirstName', ''); } - $info .= "\r\n"; + $csv_row[] = get_lang('LoginName'); + $csv_row[] = get_lang('CourseCode'); + // the additional user defined fields (only those that were selected to be exported) + require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php'); + $fields = UserManager::get_extra_fields(0, 50, 5, 'ASC'); + + if (is_array($_SESSION['additional_export_fields'])) { + foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) { + $csv_row[] = $fields[$extra_field_export][3]; + $field_names_to_be_exported[] = 'extra_'.$fields[$extra_field_export][1]; + } + } + $csv_row[] = get_lang('AvgTimeSpentInTheCourse', ''); + $csv_row[] = get_lang('AvgStudentsProgress', ''); + $csv_row[] = get_lang('AvgCourseScore', ''); + $csv_row[] = get_lang('AvgExercisesScore', ''); + $csv_row[] = get_lang('AvgMessages', ''); + $csv_row[] = get_lang('AvgAssignments', ''); + $csv_row[] = get_lang('TotalExercisesScoreObtained', ''); + $csv_row[] = get_lang('TotalExercisesScorePossible', ''); + $csv_row[] = get_lang('TotalExercisesAnswered', ''); + $csv_row[] = get_lang('TotalExercisesScorePercentage', ''); + $csv_row[] = get_lang('FirstLogin', ''); + $csv_row[] = get_lang('LatestLogin', ''); + $csv_content[] = $csv_row; + + // the other lines (the data) + foreach ($user_data as $key => $user) { + // getting all the courses of the user + $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user[4])."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." "; + $result = Database::query($sql); + while ($row = Database::fetch_row($result)) { + $csv_row = array(); + // user official code + $csv_row[] = $user[0]; + // user first|last name + $csv_row[] = $user[1]; + // user last|first name + $csv_row[] = $user[2]; + // user login name + $csv_row[] = $user[3]; + // course code + $csv_row[] = $row[0]; + // the additional defined user fields + $extra_fields = MySpace::get_user_overview_export_extra_fields($user[4]); + + if (is_array($field_names_to_be_exported)) { + foreach ($field_names_to_be_exported as $key => $extra_field_export) { + $csv_row[] = $extra_fields[$extra_field_export]; + } + } + // time spent in the course + $csv_row[] = api_time_to_hms(Tracking :: get_time_spent_on_the_course ($user[4], $row[0])); + // student progress in course + $csv_row[] = round(Tracking :: get_avg_student_progress ($user[4], $row[0]), 2); + // student score + $csv_row[] = round(Tracking :: get_avg_student_score ($user[4], $row[0]), 2); + // student tes score + $csv_row[] = round(Tracking :: get_avg_student_exercise_score ($user[4], $row[0]), 2); + // student messages + $csv_row[] = Tracking :: count_student_messages ($user[4], $row[0]); + // student assignments + $csv_row[] = Tracking :: count_student_assignments ($user[4], $row[0]); + // student exercises results + $exercises_results = MySpace::exercises_results($user[4], $row[0]); + $csv_row[] = $exercises_results['score_obtained']; + $csv_row[] = $exercises_results['score_possible']; + $csv_row[] = $exercises_results['questions_answered']; + $csv_row[] = $exercises_results['percentage']; + // first connection + $csv_row[] = Tracking :: get_first_connection_date_on_the_course ($user[4], $row[0]); + // last connection + $csv_row[] = strip_tags(Tracking :: get_last_connection_date_on_the_course ($user[4], $row[0])); + + $csv_content[] = $csv_row; + } + } + Export :: export_table_csv($csv_content, 'reporting_user_overview'); + exit; + } - foreach ($data as $row) { - foreach ($row as $value) { - $info .= $value.';'; + /** + * Get data for courses list in sortable with pagination + * @return array + */ + function get_course_data($from, $number_of_items, $column, $direction) { + + global $courses, $csv_content, $charset ; + global $tbl_course, $tbl_course_user, $tbl_track_cours_access, $tbl_session_course_user; + + $a_course_students = array(); + $course_data = array(); + $arr_course = $courses; + foreach ($arr_course as &$cours) { + $cours = "'{$cours[course_code]}'"; + } + + // get all courses with limit + $sql = "SELECT course.code as col1, course.title as col2 + FROM $tbl_course course + WHERE course.code IN (".implode(',',$arr_course).")"; + if (!in_array($direction, array('ASC','DESC'))) $direction = 'ASC'; + + $column = intval($column); + $from = intval($from); + $number_of_items = intval($number_of_items); + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + + $res = Database::query($sql); + while ($row_course = Database::fetch_row($res)) { + + $course_code = $row_course[0]; + $course_info = api_get_course_info($course_code); + $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0; + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']); + $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST, $course_info['dbName']); + $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $course_info['dbName']); + $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $course_info['dbName']); + + // students directly subscribed to the course + $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code' + UNION DISTINCT SELECT id_user as user_id FROM $tbl_session_course_user srcu WHERE srcu. course_code='$course_code'"; + $rs = Database::query($sql); + $users = array(); + while ($row = Database::fetch_array($rs)) { + $users[] = $row['user_id']; } - $info .= "\r\n"; + if (count($users) > 0) { + $nb_students_in_course = count($users); + $avg_assignments_in_course = Tracking::count_student_assignments($users, $course_code); + $avg_messages_in_course = Tracking::count_student_messages($users, $course_code); + $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $course_code); + $avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code); + $avg_score_in_course = Tracking :: get_avg_student_score($users, $course_code); + $avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code); + + $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course); + $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2); + $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2); + $avg_score_in_exercise = round($avg_score_in_exercise / $nb_students_in_course, 2); + } else { + $avg_time_spent_in_course = null; + $avg_progress_in_course = null; + $avg_score_in_course = null; + $avg_score_in_exercise = null; + $avg_messages_in_course = null; + $avg_assignments_in_course = null; + } + $table_row = array(); + $table_row[] = $row_course[1]; + $table_row[] = $nb_students_in_course; + $table_row[] = $avg_time_spent_in_course; + $table_row[] = is_null($avg_progress_in_course) ? '' : $avg_progress_in_course.'%'; + $table_row[] = is_null($avg_score_in_course) ? '' : $avg_score_in_course.'%'; + $table_row[] = is_null($avg_score_in_exercise) ? '' : $avg_score_in_exercise.'%'; + $table_row[] = $avg_messages_in_course; + $table_row[] = $avg_assignments_in_course; + //set the "from" value to know if I access the Reporting by the Dokeos tab or the course link + $table_row[] = '
    '; + $csv_content[] = array( + api_html_entity_decode($row_course[1], ENT_QUOTES, $charset), + $nb_students_in_course, + $avg_time_spent_in_course, + is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%', + is_null($avg_score_in_course) ? null : $avg_score_in_course.'%', + is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%', + $avg_messages_in_course, + $avg_assignments_in_course, + ); + $course_data[] = $table_row; + } + return $course_data; + } + + /** + * get the numer of users of the platform + * + * @return integer + * + * @author Patrick Cool , Ghent University, Belgium + * @version Dokeos 1.8.6 + * @since October 2008 + */ + function get_number_of_users_tracking_overview() { + // database table definition + $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); + + // query + $sql = 'SELECT user_id FROM '.$main_user_table; + $result = Database::query($sql); + + // return the number of results + return Database::num_rows($result); + } + + /** + * get all the data for the sortable table of the reporting progress of all users and all the courses the user is subscribed to. + * + * @author Patrick Cool , Ghent University, Belgium + * @version Dokeos 1.8.6 + * @since October 2008 + */ + function get_user_data_tracking_overview($from, $number_of_items, $column, $direction) { + // database table definition + $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); + global $export_csv; + if ($export_csv) { + $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT); + } else { + $is_western_name_order = api_is_western_name_order(); + } + $sql = "SELECT + official_code AS col0, + ".($is_western_name_order ? " + firstname AS col1, + lastname AS col2, + " : " + lastname AS col1, + firstname AS col2, + "). + "username AS col3, + user_id AS col4 + FROM + $main_user_table + "; + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + $result = Database::query($sql); + $return = array (); + while ($user = Database::fetch_row($result)) { + $return[] = $user; } + return $return; + } + + /** + * Get all information that the user with user_id = $user_data has + * entered in the additionally defined profile fields + * @param integer $user_id the id of the user + * @author Patrick Cool , Ghent University, Belgium + * @version Dokeos 1.8.6 + * @since November 2008 + */ + function get_user_overview_export_extra_fields($user_id) { + // include the user manager + require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; + $extra_data = UserManager::get_extra_user_data($user_id, true); + return $extra_data; + } + + + + + + + + + + + + + + + + + + + + + + + + - fwrite($open, $info); - fclose($open); - @chmod($file_name, api_get_permissions_for_new_files()); - header("Location:".$archive_url.$file_name); + + + + + + + + + + + + + + + + + + + + + + + + + /** + * Checks if a username exist in the DB otherwise it create a "double" + * i.e. if we look into for jmontoya but the user's name already exist we create the user jmontoya2 + * the return array will be array(username=>'jmontoya', sufix='2') + * @param string firstname + * @param string lastname + * @param string username + * @return array with the username, the sufix + * @author Julio Montoya Armas + */ + function make_username($firstname, $lastname, $username, $language = null, $encoding = null) { + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + // if username exist + if (!UserManager::is_username_available($username) || empty($username)) { + $i = 0; + while (1) { + if ($i == 0) { + $sufix = ''; + } else { + $sufix = $i; + } + $desired_username = UserManager::create_username($firstname, $lastname, $language, $encoding); + if (UserManager::is_username_available($desired_username.$sufix)) { + break; + } else { + $i++; + } + } + $username_array = array('username' => $desired_username , 'sufix' => $sufix); + return $username_array; + } else { + $username_array = array('username' => $username, 'sufix' => ''); + return $username_array; + } + } + + /** + * Checks if there are repeted users in a given array + * @param array $usernames list of the usernames in the uploaded file + * @param array $user_array['username'] and $user_array['sufix'] where sufix is the number part in a login i.e -> jmontoya2 + * @return array with the $usernames array and the $user_array array + * @author Julio Montoya Armas + */ + function check_user_in_array($usernames, $user_array) { + $user_list = array_keys($usernames); + $username = $user_array['username'].$user_array['sufix']; + + if (in_array($username, $user_list)) { + $user_array['sufix'] += $usernames[$username]; + $usernames[$username]++; + } else { + $usernames[$username] = 1; + } + $result_array = array($usernames, $user_array); + return $result_array; + } + + /** + * Checks whether a username has been already subscribed in a session. + * @param string a given username + * @param array the array with the course list codes + * @param the session id + * @return 0 if the user is not subscribed otherwise it returns the user_id of the given username + * @author Julio Montoya Armas + */ + function user_available_in_session($username, $course_list, $id_session) { + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + $id_session = intval($id_session); + $username = Database::escape_string($username); + foreach($course_list as $enreg_course) { + $sql_select = " SELECT u.user_id FROM $tbl_session_rel_course_rel_user rel INNER JOIN $table_user u + ON (rel.id_user=u.user_id) + WHERE rel.id_session='$id_session' AND u.status='5' AND u.username ='$username' AND rel.course_code='$enreg_course'"; + $rs = Database::query($sql_select); + if (Database::num_rows($rs) > 0) { + return Database::result($rs, 0, 0); + } else { + return 0; + } + } + } + + /** + This function checks whether some users in the uploaded file repeated and creates unique usernames if necesary. + A case: Within the file there is an user repeted twice (Julio Montoya / Julio Montoya) and the username fields are empty. + Then, this function would create unique usernames based on the first and the last name. Two users wiould be created - jmontoya and jmontoya2. + Of course, if in the database there is a user with the name jmontoya, the newly created two users registered would be jmontoya2 and jmontoya3. + @param $users list of users + @author Julio Montoya Armas + */ + function check_all_usernames($users, $course_list, $id_session) { + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $usernames = array(); + $new_users = array(); + foreach ($users as $index => $user) { + $desired_username = array(); + if (empty($user['UserName'])) { + $desired_username = MySpace::make_username($user['FirstName'], $user['LastName'], ''); + $pre_username = $desired_username['username'].$desired_username['sufix']; + $user['UserName'] = $pre_username; + $user['create'] = '1'; + } else { + if (UserManager::is_username_available($user['UserName'])) { + $desired_username = MySpace::make_username($user['FirstName'], $user['LastName'], $user['UserName']); + $user['UserName'] = $desired_username['username'].$desired_username['sufix']; + $user['create'] = '1'; + } else { + $is_session_avail = MySpace::user_available_in_session($user['UserName'], $course_list, $id_session); + if ($is_session_avail == 0) { + $user_name = $user['UserName']; + $sql_select = "SELECT user_id FROM $table_user WHERE username ='$user_name' "; + $rs = Database::query($sql_select); + $user['create'] = Database::result($rs, 0, 0); // This should be the ID because the user exists. + } else { + $user['create'] = $is_session_avail; + } + } + } + // Usernames is the current list of users in the file. + $result_array = MySpace::check_user_in_array($usernames, $desired_username); + $usernames = $result_array[0]; + $desired_username = $result_array[1]; + $user['UserName'] = $desired_username['username'].$desired_username['sufix']; + $new_users[] = $user; + } + return $new_users; + } + + /** + * This functions checks whether there are users that are already registered in the DB by different creator than the current coach. + * @param string a given username + * @param array the array with the course list codes + * @param the session id + * @author Julio Montoya Armas + */ + function get_user_creator($users, $course_list, $id_session) { + $errors = array(); + foreach ($users as $index => $user) { + // database table definition + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + $username = Database::escape_string($user['UserName']); + //echo "
    "; + $sql = "SELECT creator_id FROM $table_user WHERE username='$username' "; + + $rs = Database::query($sql); + $creator_id = Database::result($rs, 0, 0); + // check if we are the creators or not + if ($creator_id != '') { + if ($creator_id != api_get_user_id()) { + $user['error'] = get_lang('UserAlreadyRegisteredByOtherCreator'); + $errors[] = $user; + } + } + } + return $errors; + } + + /** + * Validates imported data. + * @param list of users + */ + function validate_data($users, $id_session = null) { + $errors = array(); + $usernames = array(); + $new_users = array(); + foreach ($users as $index => $user) { + // 1. Check whether mandatory fields are set. + $mandatory_fields = array('LastName', 'FirstName'); + if (api_get_setting('registration', 'email') == 'true') { + $mandatory_fields[] = 'Email'; + } + + foreach ($mandatory_fields as $key => $field) { + if (!isset ($user[$field]) || strlen($user[$field]) == 0) { + $user['error'] = get_lang($field.'Mandatory'); + $errors[] = $user; + } + } + // 2. Check whether the username is too long. + if (UserManager::is_username_too_long($user['UserName'])) { + $user['error'] = get_lang('UserNameTooLong'); + $errors[] = $user; + } + + $user['UserName'] = trim($user['UserName']); + + if (empty($user['UserName'])) { + $user['UserName'] = UserManager::create_username($user['FirstName'], $user['LastName']); + } + $new_users[] = $user; + } + $results = array('errors' => $errors, 'users' => $new_users); + return $results; + } + + /** + * Adds missing user-information (which isn't required, like password, etc). + */ + function complete_missing_data($user) { + // 1. Generate a password if it is necessary. + if (!isset ($user['Password']) || strlen($user['Password']) == 0) { + $user['Password'] = api_generate_password(); + } + return $user; + } + + /** + * Saves imported data. + */ + function save_data($users, $course_list, $id_session) { + $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); + $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); + $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); + + $id_session = intval($id_session); + $sendMail = $_POST['sendMail'] ? 1 : 0; + + // Adding users to the platform. + $new_users = array(); + foreach ($users as $index => $user) { + $user = MySpace::complete_missing_data($user); + // coach only will registered users + $default_status = '5'; + if ($user['create'] == '1') { + $user['id'] = UserManager :: create_user($user['FirstName'], $user['LastName'], $default_status, $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], ''); + $user['added_at_platform'] = 1; + } else { + $user['id'] = $user['create']; + $user['added_at_platform'] = 0; + } + $new_users[] = $user; + } + // Update user list. + $users = $new_users; + + // Inserting users. + $super_list = array(); + foreach ($course_list as $enreg_course) { + $nbr_users = 0; + $new_users = array(); + $enreg_course = Database::escape_string($enreg_course); + foreach ($users as $index => $user) { + $userid = intval($user['id']); + $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$userid')"; + $course_session = array('course' => $enreg_course, 'added' => 1); + //$user['added_at_session'] = $course_session; + Database::query($sql); + if (Database::affected_rows()) { + $nbr_users++; + } + $new_users[] = $user; + } + $super_list[] = $new_users; + + //update the nbr_users field + $sql_select = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='$enreg_course'"; + $rs = Database::query($sql_select); + list($nbr_users) = Database::fetch_array($rs); + $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$id_session' AND course_code='$enreg_course'"; + Database::query($sql_update); + + $sql_update = "UPDATE $tbl_session SET nbr_users= '$nbr_users' WHERE id='$id_session'"; + Database::query($sql_update); + } + // We don't delete the users (thoughts while dreaming) + //$sql_delete = "DELETE FROM $tbl_session_rel_user WHERE id_session = '$id_session'"; + //Database::query($sql_delete); + + $new_users = array(); + foreach ($users as $index => $user) { + $userid = $user['id']; + $sql_insert = "INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user) VALUES('$id_session','$userid')"; + Database::query($sql_insert); + $user['added_at_session'] = 1; + $new_users[] = $user; + } + + $users = $new_users; + $registered_users = get_lang('FileImported').'
    Import file results :
    '; + // Sending emails. + $addedto = ''; + if ($sendMail) { + $i = 0; + foreach ($users as $index => $user) { + $emailto = api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS).' <'.$user['Email'].'>'; + $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName'); + $emailbody = get_lang('Dear').' '.api_get_person_name($user['FirstName'], $user['LastName']).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : $user[UserName]\n".get_lang('Pass')." : $user[Password]\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".api_get_path('WEB_PATH')." \n\n".get_lang('Problem')."\n\n".get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n".get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator').""; + $emailheaders = 'From: '.api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS).' <'.api_get_setting('emailAdministrator').">\n"; + $emailheaders .= 'Reply-To: '.api_get_setting('emailAdministrator'); + @api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders); + + if (($user['added_at_platform'] == 1 && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) { + if ($user['added_at_platform'] == 1) { + $addedto = get_lang('UserCreatedPlatform'); + } else { + $addedto = ' '; + } + + if ($user['added_at_session'] == 1) { + $addedto .= get_lang('UserInSession'); + } + $registered_users .= "".api_get_person_name($user['FirstName'], $user['LastName'])." - ".$addedto.'
    '; + } else { + $addedto = get_lang('UserNotAdded'); + $registered_users .= "".api_get_person_name($user['FirstName'], $user['LastName'])." - ".$addedto.'
    '; + } + } + } else { + $i = 0; + foreach ($users as $index => $user) { + if (($user['added_at_platform'] == 1 && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) { + if ($user['added_at_platform'] == 1) { + $addedto = get_lang('UserCreatedPlatform'); + } else { + $addedto = ' '; + } + + if ($user['added_at_session'] == 1) { + $addedto .= ' '.get_lang('UserInSession'); + } + + $registered_users .= "".api_get_person_name($user['FirstName'], $user['LastName'])." - ".$addedto.'
    '; + } else { + $addedto = get_lang('UserNotAdded'); + $registered_users .= "".api_get_person_name($user['FirstName'], $user['LastName'])." - ".$addedto.'
    '; + } + } + } + + header('Location: course.php?id_session='.$id_session.'&action=show_message&message='.urlencode($registered_users)); + exit (); + + //header('Location: resume_session.php?id_session='.$id_session); + } + + /** + * Reads CSV-file. + * @param string $file Path to the CSV-file + * @return array All userinformation read from the file + */ + function parse_csv_data($file) { + $users = Import :: csv_to_array($file); + foreach ($users as $index => $user) { + if (isset ($user['Courses'])) { + $user['Courses'] = explode('|', trim($user['Courses'])); + } + $users[$index] = $user; + } + return $users; + } + + /** + * XML-parser: the handler at the beginning of element. + */ + function element_start($parser, $data) { + $data = api_utf8_decode($data); + global $user; + global $current_tag; + switch ($data) { + case 'Contact' : + $user = array (); + break; + default : + $current_tag = $data; + } + } + + /** + * XML-parser: the handler at the end of element. + */ + function element_end($parser, $data) { + $data = api_utf8_decode($data); + global $user; + global $users; + global $current_value; + global $purification_option_for_usernames; + $user[$data] = $current_value; + switch ($data) { + case 'Contact' : + $user['UserName'] = UserManager::purify_username($user['UserName'], $purification_option_for_usernames); + $users[] = $user; + break; + default : + $user[$data] = $current_value; + break; + } + } + + /** + * XML-parser: the handler for character data. + */ + function character_data($parser, $data) { + $data = trim(api_utf8_decode($data)); + global $current_value; + $current_value = $data; + } + + /** + * Reads XML-file. + * @param string $file Path to the XML-file + * @return array All userinformation read from the file + */ + function parse_xml_data($file) { + global $current_tag; + global $current_value; + global $user; + global $users; + $users = array (); + $parser = xml_parser_create('UTF-8'); + xml_set_element_handler($parser, array('MySpace','element_start'), array('MySpace','element_end')); + xml_set_character_data_handler($parser, "character_data"); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); + xml_parse($parser, api_utf8_encode_xml(file_get_contents($file))); + xml_parser_free($parser); + return $users; } - return $message; -} +} \ No newline at end of file diff --git a/main/mySpace/user_import.php b/main/mySpace/user_import.php index c52f12f2e1..984325292f 100755 --- a/main/mySpace/user_import.php +++ b/main/mySpace/user_import.php @@ -27,429 +27,6 @@ * Created on 26 julio 2008 by Julio Montoya gugli100@gmail.com ============================================================================== */ - -/** - * Checks if a username exist in the DB otherwise it create a "double" - * i.e. if we look into for jmontoya but the user's name already exist we create the user jmontoya2 - * the return array will be array(username=>'jmontoya', sufix='2') - * @param string firstname - * @param string lastname - * @param string username - * @return array with the username, the sufix - * @author Julio Montoya Armas - */ -function make_username($firstname, $lastname, $username, $language = null, $encoding = null) { - $table_user = Database::get_main_table(TABLE_MAIN_USER); - $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - // if username exist - if (!UserManager::is_username_available($username) || empty($username)) { - $i = 0; - while (1) { - if ($i == 0) { - $sufix = ''; - } else { - $sufix = $i; - } - $desired_username = UserManager::create_username($firstname, $lastname, $language, $encoding); - if (UserManager::is_username_available($desired_username.$sufix)) { - break; - } else { - $i++; - } - } - $username_array = array('username' => $desired_username , 'sufix' => $sufix); - return $username_array; - } else { - $username_array = array('username' => $username, 'sufix' => ''); - return $username_array; - } -} - -/** - * Checks if there are repeted users in a given array - * @param array $usernames list of the usernames in the uploaded file - * @param array $user_array['username'] and $user_array['sufix'] where sufix is the number part in a login i.e -> jmontoya2 - * @return array with the $usernames array and the $user_array array - * @author Julio Montoya Armas - */ -function check_user_in_array($usernames, $user_array) { - $user_list = array_keys($usernames); - $username = $user_array['username'].$user_array['sufix']; - - if (in_array($username, $user_list)) { - $user_array['sufix'] += $usernames[$username]; - $usernames[$username]++; - } else { - $usernames[$username] = 1; - } - $result_array = array($usernames, $user_array); - return $result_array; -} - -/** - * Checks whether a username has been already subscribed in a session. - * @param string a given username - * @param array the array with the course list codes - * @param the session id - * @return 0 if the user is not subscribed otherwise it returns the user_id of the given username - * @author Julio Montoya Armas - */ -function user_available_in_session($username, $course_list, $id_session) { - $table_user = Database::get_main_table(TABLE_MAIN_USER); - $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $id_session = intval($id_session); - $username = Database::escape_string($username); - foreach($course_list as $enreg_course) { - $sql_select = " SELECT u.user_id FROM $tbl_session_rel_course_rel_user rel INNER JOIN $table_user u - ON (rel.id_user=u.user_id) - WHERE rel.id_session='$id_session' AND u.status='5' AND u.username ='$username' AND rel.course_code='$enreg_course'"; - $rs = Database::query($sql_select); - if (Database::num_rows($rs) > 0) { - return Database::result($rs, 0, 0); - } else { - return 0; - } - } -} - -/** -This function checks whether some users in the uploaded file repeated and creates unique usernames if necesary. -A case: Within the file there is an user repeted twice (Julio Montoya / Julio Montoya) and the username fields are empty. -Then, this function would create unique usernames based on the first and the last name. Two users wiould be created - jmontoya and jmontoya2. -Of course, if in the database there is a user with the name jmontoya, the newly created two users registered would be jmontoya2 and jmontoya3. -@param $users list of users -@author Julio Montoya Armas -*/ -function check_all_usernames($users, $course_list, $id_session) { - $table_user = Database::get_main_table(TABLE_MAIN_USER); - $usernames = array(); - $new_users = array(); - foreach ($users as $index => $user) { - $desired_username = array(); - if (empty($user['UserName'])) { - $desired_username = make_username($user['FirstName'], $user['LastName'], ''); - $pre_username = $desired_username['username'].$desired_username['sufix']; - $user['UserName'] = $pre_username; - $user['create'] = '1'; - } else { - if (UserManager::is_username_available($user['UserName'])) { - $desired_username = make_username($user['FirstName'], $user['LastName'], $user['UserName']); - $user['UserName'] = $desired_username['username'].$desired_username['sufix']; - $user['create'] = '1'; - } else { - $is_session_avail = user_available_in_session($user['UserName'], $course_list, $id_session); - if ($is_session_avail == 0) { - $user_name = $user['UserName']; - $sql_select = "SELECT user_id FROM $table_user WHERE username ='$user_name' "; - $rs = Database::query($sql_select); - $user['create'] = Database::result($rs, 0, 0); // This should be the ID because the user exists. - } else { - $user['create'] = $is_session_avail; - } - } - } - // Usernames is the current list of users in the file. - $result_array = check_user_in_array($usernames, $desired_username); - $usernames = $result_array[0]; - $desired_username = $result_array[1]; - $user['UserName'] = $desired_username['username'].$desired_username['sufix']; - $new_users[] = $user; - } - return $new_users; -} - -/** - * This functions checks whether there are users that are already registered in the DB by different creator than the current coach. - * @param string a given username - * @param array the array with the course list codes - * @param the session id - * @author Julio Montoya Armas - */ -function get_user_creator($users, $course_list, $id_session) { - $errors = array(); - foreach ($users as $index => $user) { - // database table definition - $table_user = Database::get_main_table(TABLE_MAIN_USER); - $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $username = Database::escape_string($user['UserName']); - //echo "
    "; - $sql = "SELECT creator_id FROM $table_user WHERE username='$username' "; - - $rs = Database::query($sql); - $creator_id = Database::result($rs, 0, 0); - // check if we are the creators or not - if ($creator_id != '') { - if ($creator_id != api_get_user_id()) { - $user['error'] = get_lang('UserAlreadyRegisteredByOtherCreator'); - $errors[] = $user; - } - } - } - return $errors; -} - -/** - * Validates imported data. - * @param list of users - */ -function validate_data($users, $id_session = null) { - $errors = array(); - $usernames = array(); - $new_users = array(); - foreach ($users as $index => $user) { - // 1. Check whether mandatory fields are set. - $mandatory_fields = array('LastName', 'FirstName'); - if (api_get_setting('registration', 'email') == 'true') { - $mandatory_fields[] = 'Email'; - } - - foreach ($mandatory_fields as $key => $field) { - if (!isset ($user[$field]) || strlen($user[$field]) == 0) { - $user['error'] = get_lang($field.'Mandatory'); - $errors[] = $user; - } - } - // 2. Check whether the username is too long. - if (UserManager::is_username_too_long($user['UserName'])) { - $user['error'] = get_lang('UserNameTooLong'); - $errors[] = $user; - } - - $user['UserName'] = trim($user['UserName']); - - if (empty($user['UserName'])) { - $user['UserName'] = UserManager::create_username($user['FirstName'], $user['LastName']); - } - $new_users[] = $user; - } - $results = array('errors' => $errors, 'users' => $new_users); - return $results; -} - -/** - * Adds missing user-information (which isn't required, like password, etc). - */ -function complete_missing_data($user) { - // 1. Generate a password if it is necessary. - if (!isset ($user['Password']) || strlen($user['Password']) == 0) { - $user['Password'] = api_generate_password(); - } - return $user; -} - -/** - * Saves imported data. - */ -function save_data($users, $course_list, $id_session) { - $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); - $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); - $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); - - $id_session = intval($id_session); - $sendMail = $_POST['sendMail'] ? 1 : 0; - - // Adding users to the platform. - $new_users = array(); - foreach ($users as $index => $user) { - $user = complete_missing_data($user); - // coach only will registered users - $default_status = '5'; - if ($user['create'] == '1') { - $user['id'] = UserManager :: create_user($user['FirstName'], $user['LastName'], $default_status, $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], ''); - $user['added_at_platform'] = 1; - } else { - $user['id'] = $user['create']; - $user['added_at_platform'] = 0; - } - $new_users[] = $user; - } - // Update user list. - $users = $new_users; - - // Inserting users. - $super_list = array(); - foreach ($course_list as $enreg_course) { - $nbr_users = 0; - $new_users = array(); - $enreg_course = Database::escape_string($enreg_course); - foreach ($users as $index => $user) { - $userid = intval($user['id']); - $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$userid')"; - $course_session = array('course' => $enreg_course, 'added' => 1); - //$user['added_at_session'] = $course_session; - Database::query($sql); - if (Database::affected_rows()) { - $nbr_users++; - } - $new_users[] = $user; - } - $super_list[] = $new_users; - - //update the nbr_users field - $sql_select = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='$enreg_course'"; - $rs = Database::query($sql_select); - list($nbr_users) = Database::fetch_array($rs); - $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$id_session' AND course_code='$enreg_course'"; - Database::query($sql_update); - - $sql_update = "UPDATE $tbl_session SET nbr_users= '$nbr_users' WHERE id='$id_session'"; - Database::query($sql_update); - } - // We don't delete the users (thoughts while dreaming) - //$sql_delete = "DELETE FROM $tbl_session_rel_user WHERE id_session = '$id_session'"; - //Database::query($sql_delete); - - $new_users = array(); - foreach ($users as $index => $user) { - $userid = $user['id']; - $sql_insert = "INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user) VALUES('$id_session','$userid')"; - Database::query($sql_insert); - $user['added_at_session'] = 1; - $new_users[] = $user; - } - - $users = $new_users; - $registered_users = get_lang('FileImported').'
    Import file results :
    '; - // Sending emails. - $addedto = ''; - if ($sendMail) { - $i = 0; - foreach ($users as $index => $user) { - $emailto = api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS).' <'.$user['Email'].'>'; - $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName'); - $emailbody = get_lang('Dear').' '.api_get_person_name($user['FirstName'], $user['LastName']).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : $user[UserName]\n".get_lang('Pass')." : $user[Password]\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".api_get_path('WEB_PATH')." \n\n".get_lang('Problem')."\n\n".get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n".get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator').""; - $emailheaders = 'From: '.api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS).' <'.api_get_setting('emailAdministrator').">\n"; - $emailheaders .= 'Reply-To: '.api_get_setting('emailAdministrator'); - @api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders); - - if (($user['added_at_platform'] == 1 && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) { - if ($user['added_at_platform'] == 1) { - $addedto = get_lang('UserCreatedPlatform'); - } else { - $addedto = ' '; - } - - if ($user['added_at_session'] == 1) { - $addedto .= get_lang('UserInSession'); - } - $registered_users .= "".api_get_person_name($user['FirstName'], $user['LastName'])." - ".$addedto.'
    '; - } else { - $addedto = get_lang('UserNotAdded'); - $registered_users .= "".api_get_person_name($user['FirstName'], $user['LastName'])." - ".$addedto.'
    '; - } - } - } else { - $i = 0; - foreach ($users as $index => $user) { - if (($user['added_at_platform'] == 1 && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) { - if ($user['added_at_platform'] == 1) { - $addedto = get_lang('UserCreatedPlatform'); - } else { - $addedto = ' '; - } - - if ($user['added_at_session'] == 1) { - $addedto .= ' '.get_lang('UserInSession'); - } - - $registered_users .= "".api_get_person_name($user['FirstName'], $user['LastName'])." - ".$addedto.'
    '; - } else { - $addedto = get_lang('UserNotAdded'); - $registered_users .= "".api_get_person_name($user['FirstName'], $user['LastName'])." - ".$addedto.'
    '; - } - } - } - - header('Location: course.php?id_session='.$id_session.'&action=show_message&message='.urlencode($registered_users)); - exit (); - - //header('Location: resume_session.php?id_session='.$id_session); -} - -/** - * Reads CSV-file. - * @param string $file Path to the CSV-file - * @return array All userinformation read from the file - */ -function parse_csv_data($file) { - $users = Import :: csv_to_array($file); - foreach ($users as $index => $user) { - if (isset ($user['Courses'])) { - $user['Courses'] = explode('|', trim($user['Courses'])); - } - $users[$index] = $user; - } - return $users; -} - -/** - * XML-parser: the handler at the beginning of element. - */ -function element_start($parser, $data) { - $data = api_utf8_decode($data); - global $user; - global $current_tag; - switch ($data) { - case 'Contact' : - $user = array (); - break; - default : - $current_tag = $data; - } -} - -/** - * XML-parser: the handler at the end of element. - */ -function element_end($parser, $data) { - $data = api_utf8_decode($data); - global $user; - global $users; - global $current_value; - global $purification_option_for_usernames; - $user[$data] = $current_value; - switch ($data) { - case 'Contact' : - $user['UserName'] = UserManager::purify_username($user['UserName'], $purification_option_for_usernames); - $users[] = $user; - break; - default : - $user[$data] = $current_value; - break; - } -} - -/** - * XML-parser: the handler for character data. - */ -function character_data($parser, $data) { - $data = trim(api_utf8_decode($data)); - global $current_value; - $current_value = $data; -} - -/** - * Reads XML-file. - * @param string $file Path to the XML-file - * @return array All userinformation read from the file - */ -function parse_xml_data($file) { - global $current_tag; - global $current_value; - global $user; - global $users; - $users = array (); - $parser = xml_parser_create('UTF-8'); - xml_set_element_handler($parser, 'element_start', 'element_end'); - xml_set_character_data_handler($parser, "character_data"); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); - xml_parse($parser, api_utf8_encode_xml(file_get_contents($file))); - xml_parser_free($parser); - return $users; -} - - /* ============================================================================== Main script @@ -460,6 +37,7 @@ $language_file = array ('admin', 'registration', 'index', 'trad4all', 'tracking' $cidReset = true; require '../inc/global.inc.php'; +require_once 'myspace.lib.php'; $this_section = SECTION_PLATFORM_ADMIN; // TODO: Platform admin section? @@ -514,12 +92,12 @@ if ($_POST['formSent'] && $_FILES['import_file']['size'] !== 0) { $file_type = $_POST['file_type']; $id_session = intval($_POST['id_session']); if ($file_type == 'csv') { - $users = parse_csv_data($_FILES['import_file']['tmp_name']); + $users = MySpace::parse_csv_data($_FILES['import_file']['tmp_name']); } else { - $users = parse_xml_data($_FILES['import_file']['tmp_name']); + $users = MySpace::parse_xml_data($_FILES['import_file']['tmp_name']); } if (count($users) > 0) { - $results = validate_data($users); + $results = MySpace::validate_data($users); $errors = $results['errors']; $users = $results['users']; @@ -533,10 +111,10 @@ if ($_POST['formSent'] && $_FILES['import_file']['size'] !== 0) { while ($row = Database::fetch_array($result)) { $course_list[] = $row['course_code']; } - $errors = get_user_creator($users, $course_list, $id_session); - $users = check_all_usernames($users, $course_list, $id_session); + $errors = MySpace::get_user_creator($users, $course_list, $id_session); + $users = MySpace::check_all_usernames($users, $course_list, $id_session); if (count($errors) == 0) { - save_data($users, $course_list, $id_session); + MySpace::save_data($users, $course_list, $id_session); } } else { header('Location: course.php?id_session='.$id_session.'&action=error_message&message='.urlencode(get_lang('NoSessionId'))); diff --git a/tests/main/newscorm/openoffice_document.class.test.php b/tests/main/newscorm/openoffice_document.class.test.php new file mode 100644 index 0000000000..138c63ed61 --- /dev/null +++ b/tests/main/newscorm/openoffice_document.class.test.php @@ -0,0 +1,8 @@ + diff --git a/tests/main/newscorm/openoffice_presentation.class.test.php b/tests/main/newscorm/openoffice_presentation.class.test.php new file mode 100644 index 0000000000..be00609caa --- /dev/null +++ b/tests/main/newscorm/openoffice_presentation.class.test.php @@ -0,0 +1,38 @@ +assertTrue(is_numeric($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testAddCommandParameters() { + //ob_start(); + $res = OpenofficePresentation::add_command_parameters(); + $this->assertTrue(is_numeric($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testSetSlideSize() { + //ob_start(); + $res = OpenofficePresentation::set_slide_size($width = '400',$height = '500'); + $this->assertTrue(is_numeric($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testAddDocsToVisio() { + //ob_start(); + $res = OpenofficePresentation::add_docs_to_visio($files=array()); + $this->assertTrue(is_numeric($res)); + //ob_end_clean(); + //var_dump($res); + }*/ +} +?> diff --git a/tests/main/newscorm/openoffice_text.class.test.php b/tests/main/newscorm/openoffice_text.class.test.php new file mode 100644 index 0000000000..47e32a1b55 --- /dev/null +++ b/tests/main/newscorm/openoffice_text.class.test.php @@ -0,0 +1,50 @@ +assertTrue(is_bool($res)); + //ob_end_clean(); + //var_dump($res); + } +/* + public function testDealPerChapter() { + //ob_start(); + $obj = new OpenofficeText($split_steps=false, $course_code=null, $resource_id=null,$user_id=null); + $res = $obj->dealPerChapter($header = 'Header', $content = 'Content'); + $this->assertTrue(is_null($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testDalPerPage() { + //ob_start(); + $obj = new OpenofficeText($split_steps=false, $course_code=null, $resource_id=null,$user_id=null); + $res = $obj->dealPerPage($header = 'Header', $body= 'Body'); + $this->assertTrue(is_null($res)); + //ob_end_clean(); + //var_dump($res); + } +*/ + public function testAddCommandParameters() { + //ob_start(); + $res = OpenofficeText::add_command_parameters(); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testFormatPageContent() { + //ob_start(); + $res = OpenofficeText::format_page_content($header = 'Header', $content = 'Content'); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + } +} +?> \ No newline at end of file diff --git a/tests/main/newscorm/openoffice_text_document.class.test.php b/tests/main/newscorm/openoffice_text_document.class.test.php new file mode 100644 index 0000000000..b485fbc950 --- /dev/null +++ b/tests/main/newscorm/openoffice_text_document.class.test.php @@ -0,0 +1,47 @@ +make_lp($files=array()); + $this->assertTrue(is_bool($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testDealPerChapter() { + //ob_start(); + $res = OpenOfficeTextDocument::dealPerChapter($header = 'Header', $content = 'Content'); + $this->assertTrue(is_null($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testDealPerPage() { + //ob_start(); + $res = OpenOfficeTextDocument::dealPerPage($header = 'Header',$body = 'Content'); + $this->assertTrue(is_null($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testAddCommandParameters() { + //ob_start(); + $res = OpenOfficeTextDocument::add_command_parameters(); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + } + + public function testFormatPageContent() { + //ob_start(); + $res = OpenOfficeTextDocument::format_page_content($header = 'Header', $content = 'Content'); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + } */ +} +?> \ No newline at end of file diff --git a/tests/test_suite.php b/tests/test_suite.php index 52ad12e188..f525831649 100755 --- a/tests/test_suite.php +++ b/tests/test_suite.php @@ -48,112 +48,115 @@ require_once 'simpletest/autorun.php'; class TestsSuite extends TestSuite { function TestsSuite() { $this->TestSuite('All tests suite'); -/* $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/database.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/add_course.lib.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/course.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/banner.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/admin/calendar.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/surveymanager.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/session_handler.class.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/sessionmanager.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/classmanager.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/export.lib.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/legal.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/mail.lib.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/message.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/online.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/security.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/specific_fields_manager.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/social.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/sortabletable.class.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/statsUtils.lib.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/tablesort.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/text.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/tracking.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/blog.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/urlmanager.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/stats.lib.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/course_document.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/tool_navigation_menu.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/display.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/document.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/events.lib.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/fileDisplay.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/fileManage.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/geometry.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/admin/statistics/statistics.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/access_url_edit_courses_to_url_functions.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/access_url_edit_sessions_to_url_functions.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/access_url_edit_users_to_url_functions.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/add_courses_to_sessions_functions.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/add_many_session_to_category_functions.lib.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/admin/access_urls.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/admin/sub_language.class.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/add_courses_to_sessions_functions.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/auth/lost_password.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/auth/openid/xrds.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/chat/chat_functions.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/conference/get_translation.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/hotpotatoes.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/newscorm/scorm.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/survey/survey.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/user/userInfoLib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/webservices/user_import/import.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/work/work.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/glossary.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/notebook.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/permissions/permissions_functions.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/resourcelinker/resourcelinker.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/survey/survey.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/dropbox/dropbox_class.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/dropbox/dropbox_functions.inc.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/search/search_suggestions.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/export/qti2/qti2_classes.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/export/scorm/scorm_classes.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/usermanager.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/groupmanager.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/image.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/import.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/internationalization.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/system_announcements.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/fileUpload.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/main_api.lib.test.php');//this file delete the course - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests +/* $this->addTestFile(dirname(__FILE__).'/main/inc/lib/database.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/add_course.lib.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/course.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/banner.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/admin/calendar.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/surveymanager.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/session_handler.class.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/sessionmanager.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/classmanager.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/export.lib.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/legal.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/mail.lib.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/message.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/online.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/security.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/specific_fields_manager.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/social.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/sortabletable.class.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/statsUtils.lib.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/tablesort.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/text.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/tracking.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/blog.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/urlmanager.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/stats.lib.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/course_document.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/tool_navigation_menu.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/display.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/document.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/events.lib.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileDisplay.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileManage.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/geometry.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/admin/statistics/statistics.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/access_url_edit_courses_to_url_functions.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/access_url_edit_sessions_to_url_functions.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/access_url_edit_users_to_url_functions.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/add_courses_to_sessions_functions.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/add_many_session_to_category_functions.lib.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/admin/access_urls.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/admin/sub_language.class.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/add_courses_to_sessions_functions.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/auth/lost_password.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/auth/openid/xrds.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/chat/chat_functions.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/conference/get_translation.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/exercice/hotpotatoes.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/newscorm/scorm.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/survey/survey.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/user/userInfoLib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/webservices/user_import/import.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/work/work.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/glossary.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/notebook.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/permissions/permissions_functions.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/resourcelinker/resourcelinker.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/survey/survey.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/dropbox/dropbox_class.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/dropbox/dropbox_functions.inc.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/search/search_suggestions.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/exercice/export/qti2/qti2_classes.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/exercice/export/scorm/scorm_classes.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/usermanager.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/groupmanager.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/image.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/import.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/internationalization.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/system_announcements.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileUpload.lib.test.php'); + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course + $this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests */ /**This file was removed, now the functions was moved to install.lib*/ //require_once $maindir.'install/install_upgrade.lib.php'; - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/install/install_upgrade.lib.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/install/install_upgrade.lib.test.php'); /**This files has metadata*/ - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/xht.lib.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/xmd.lib.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/xht.lib.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/xmd.lib.test.php'); /**This files are not used and is not finished implement*/ - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/export/qti/qti_classes.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/export/qti2/qti2_export.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/export/exercise_import.inc.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/export/scorm/scorm_export.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/export/qti/qti_classes.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/export/qti2/qti2_export.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/export/exercise_import.inc.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/export/scorm/scorm_export.test.php'); /**EXERCISES**/ - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/answer.class.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/exercise_result.class.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/exercise_show_functions.lib.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/exercise.class.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/answer.class.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise_result.class.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/exercise_show_functions.lib.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise.class.test.php'); /**This files have problem with class and call objects*/ - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/exercise.lib.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/fill_blanks.class.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'/main/exercice/freeanswer.class.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise.lib.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/fill_blanks.class.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/exercice/freeanswer.class.test.php'); /**FORUM*/ - //$this->addFile(api_get_path(SYS_TEST_PATH).'main/forum/forumfunction.inc.test.php'); + //$this->addFile(dirname(__FILE__).'/main/forum/forumfunction.inc.test.php'); + // $this->addFile(api_get_path(SYS_TEST_PATH).'main/forum/forumfunction.inc.test.php'); - /**GRADEBOOK*/ - //$this->addFile(api_get_path(SYS_TEST_PATH).'main/gradebook/lib/be/attendancelink.class.test.php'); - //$this->addFile(api_get_path(SYS_TEST_PATH).'main/gradebook/lib/be/category.class.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php'); + + $this->addTestFile(dirname(__FILE__).'/main/newscorm/openoffice_presentation.class.test.php'); + } }