Fixing - queries due the new changes in the DB (single database) #3910

skala
Julio Montoya 13 years ago
parent 544eff50f5
commit 4aa191ec3b
  1. 3
      main/exercice/exercise.class.php
  2. 1
      main/inc/lib/database.lib.php
  3. 254
      main/inc/lib/tracking.lib.php
  4. 2
      main/mySpace/myStudents.php
  5. 36
      main/newscorm/learnpath.class.php
  6. 34
      main/newscorm/lp_stats.php
  7. 159
      main/tracking/courseLog.php

@ -102,6 +102,9 @@ class Exercise {
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$id = intval($id);
if (empty($this->course_id)) {
return false;
}
$sql = "SELECT * FROM $TBL_EXERCICES WHERE c_id = ".$this->course_id." AND id = ".$id;
$result = Database::query($sql);

@ -703,6 +703,7 @@ class Database {
if (strpos($query, 'c_')) {
//Check if the table contains inner joins
if (
strpos($query, 'down_doc_path') === false &&
strpos($query, 'INNER JOIN') === false &&
strpos($query, 'inner join') === false &&
strpos($query, 'left join') === false &&

@ -1493,8 +1493,7 @@ class Tracking {
* @return int Count of messages
*/
function count_student_messages($student_id, $course_code, $session_id = null) {
require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
// protect datas
$student_id = intval($student_id);
$course_code = addslashes($course_code);
@ -1524,13 +1523,10 @@ class Tracking {
}
$sql = "SELECT 1 FROM $tbl_forum_post post INNER JOIN $tbl_forum forum
ON forum.forum_id = post.forum_id
ON forum.forum_id = post.forum_id
WHERE post.c_id = $course_id AND
forum.c_id = $course_id
$condition_user $condition_session
";
$condition_user $condition_session ";
$rs = Database::query($sql);
return Database::num_rows($rs);
} else {
@ -1584,22 +1580,27 @@ class Tracking {
* @return int The number of threads by course
*/
public static function count_number_of_threads_by_course($course_code, $session_id = null) {
//protect data
$course_code = Database::escape_string($course_code);
// get the informations of the course
$a_course = CourseManager :: get_course_information($course_code);
$course_info = api_get_course_info($course_code);
if (empty($course_info)) {
return null;
}
$course_id = $course_info['real_id'];
$count = 0;
if (!empty($a_course['db_name'])) {
$tbl_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $a_course['db_name']);
$tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']);
$condition_session = '';
if (isset($session_id)) {
$session_id = intval($session_id);
$condition_session = ' WHERE f.session_id = '. $session_id;
}
$sql = "SELECT count(*) FROM $tbl_threads t INNER JOIN $tbl_forums f ON f.forum_id = t.forum_id $condition_session ";
$result = Database::query($sql);
$row = Database::fetch_row($result);
$tbl_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$tbl_forums = Database :: get_course_table(TABLE_FORUM);
$condition_session = '';
if (isset($session_id)) {
$session_id = intval($session_id);
$condition_session = ' AND f.session_id = '. $session_id;
}
$sql = "SELECT count(*) FROM $tbl_threads t INNER JOIN $tbl_forums f ON f.forum_id = t.forum_id
WHERE t.c_id = $course_id AND f.c_id = $course_id $condition_session ";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_row($result);
$count = $row[0];
return $count;
} else {
@ -1614,22 +1615,22 @@ class Tracking {
* @return int The number of forums by course
*/
public static function count_number_of_forums_by_course($course_code, $session_id = null) {
//protect data
$course_code = addslashes($course_code);
// get the informations of the course
$a_course = CourseManager :: get_course_information($course_code);
$count = 0;
if (!empty($a_course['db_name'])) {
$course_info = api_get_course_info($course_code);
if (empty($course_info)) {
return null;
}
$course_id = $course_info['real_id'];
$condition_session = '';
if (isset($session_id)) {
$session_id = intval($session_id);
$condition_session = ' WHERE session_id = '. $session_id;
}
$condition_session = '';
if (isset($session_id)) {
$session_id = intval($session_id);
$condition_session = ' session_id = '. $session_id;
}
$tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']);
$sql = "SELECT count(*) FROM $tbl_forums $condition_session";
$result = Database::query($sql);
$tbl_forums = Database :: get_course_table(TABLE_FORUM);
$sql = "SELECT count(*) FROM $tbl_forums WHERE c_id = $course_id AND $condition_session";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_row($result);
$count = $row[0];
return $count;
@ -1645,20 +1646,26 @@ class Tracking {
* @param int Session id (optional)
* @return int Chat last connections by course in x days
*/
public static function chat_connections_during_last_x_days_by_course($course_code,$last_days, $session_id = 0) {
public static function chat_connections_during_last_x_days_by_course($course_code,$last_days, $session_id = 0) {
$course_info = api_get_course_info($course_code);
if (empty($course_info)) {
return null;
}
$course_id = $course_info['real_id'];
//protect data
$last_days = intval($last_days);
$course_code = Database::escape_string($course_code);
$session_id = intval($session_id);
// get the informations of the course
$a_course = CourseManager :: get_course_information($course_code);
$count = 0;
if (!empty($a_course['db_name'])) {
$tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']);
$tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$sql = "SELECT count(*) FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date
$sql = "SELECT count(*) FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date
AND access_cours_code = '$course_code' AND access_tool='".TOOL_CHAT."' AND access_session_id='$session_id' ";
$result = Database::query($sql);
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_row($result);
$count = $row[0];
return $count;
@ -1773,9 +1780,9 @@ class Tracking {
* @return array Inactives users
*/
public static function get_inactives_students_in_course($course_code, $since = 'never', $session_id=0) {
$tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$table_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$table_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$inner = '';
if($session_id!=0)
{
@ -1821,9 +1828,9 @@ class Tracking {
$tbl_course_rel_user = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$sql = 'SELECT '.$student_id.'
FROM ' . $tbl_course_rel_user . '
WHERE access_user_id=' . $student_id . '
AND access_cours_code="' . $course_code . '" AND access_session_id = "'.$session_id.'" ';
FROM ' . $tbl_course_rel_user . '
WHERE access_user_id=' . $student_id . '
AND access_cours_code="' . $course_code . '" AND access_session_id = "'.$session_id.'" ';
$rs = Database::query($sql);
$nb_login = Database::num_rows($rs);
@ -1840,10 +1847,10 @@ class Tracking {
public static function get_student_followed_by_drh($hr_dept_id) {
$hr_dept_id = intval($hr_dept_id);
$a_students = array ();
$a_students = array();
$tbl_organism = Database :: get_main_table(TABLE_MAIN_ORGANISM);
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$sql = 'SELECT DISTINCT user_id FROM '.$tbl_user.' as user
WHERE hr_dept_id='.$hr_dept_id;
@ -1865,30 +1872,38 @@ class Tracking {
* @author isaac flores paz
* @deprecated get_avg_student_score should be use
*/
public static function get_average_test_scorm_and_lp ($user_id,$course_id) {
public static function get_average_test_scorm_and_lp ($user_id, $course_id) {
//the score inside the Reporting table
$course_info = api_get_course_info($course_id);
$lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']);
$lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course_info['dbName']);
$lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course_info['dbName']);
$lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course_info['dbName']);
$sql_type='SELECT id, lp_type FROM '.$lp_table;
$course_info = api_get_course_info($course_id);
$course_id = $course_info['real_id'];
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
$lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
$lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
$sql_type = "SELECT id, lp_type FROM $lp_table WHERE c_id = $course_id";
$rs_type=Database::query($sql_type);
$average_data=0;
$count_loop=0;
$lp_list = array();
while ($row_type=Database::fetch_array($rs_type)) {
while ($row_type = Database::fetch_array($rs_type)) {
$lp_list[] = $row_type['id'];
if ($row_type['lp_type']==1) {
//lp chamilo
$sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
$sql = "SELECT id FROM $lp_view_table WHERE c_id = $course_id AND user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
$rs_last_lp_view_id = Database::query($sql);
$lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
$sql_list_view='SELECT li.max_score,lv.user_id,liw.score,(liw.score/li.max_score) as sum_data FROM '.$lp_item_table.' li INNER JOIN '.$lp_view_table.' lv
ON li.lp_id=lv.lp_id INNER JOIN '.$lp_item_view_table.' liw ON liw.lp_item_id=li.id WHERE lv.user_id="'.$user_id.'" AND li.item_type="quiz" AND liw.lp_view_id="'.$lp_view_id.'"';
$sql_list_view="SELECT li.max_score,lv.user_id,liw.score,(liw.score/li.max_score) as sum_data
FROM $lp_item_table li INNER JOIN $lp_view_table lv
ON li.lp_id=lv.lp_id INNER JOIN $lp_item_view_table liw ON liw.lp_item_id=li.id
WHERE li.c_id = $course_id AND
liw.c_id = $course_id AND
lv.c_id = $course_id AND
lv.user_id= $user_id AND li.item_type = 'quiz' AND liw.lp_view_id= $lp_view_id";
$sum=0;
$tot=0;
$rs_list_view1=Database::query($sql_list_view);
@ -1906,12 +1921,17 @@ class Tracking {
} elseif ($row_type['lp_type']==2) {
//lp scorm
$sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
$sql = "SELECT id FROM $lp_view_table WHERE c_id = $course_id AND user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
$rs_last_lp_view_id = Database::query($sql);
$lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
$sql_list_view='SELECT li.max_score,lv.user_id,liw.score,((liw.score/li.max_score)*100) as sum_data FROM '.$lp_item_table.' li INNER JOIN '.$lp_view_table.' lv
ON li.lp_id=lv.lp_id INNER JOIN '.$lp_item_view_table.' liw ON liw.lp_item_id=li.id WHERE lv.user_id="'.$user_id.'" AND (li.item_type="sco" OR li.item_type="quiz") AND liw.lp_view_id="'.$lp_view_id.'"';
$sql_list_view = "SELECT li.max_score,lv.user_id,liw.score,((liw.score/li.max_score)*100) as sum_data
FROM $lp_item_table li INNER JOIN $lp_view_table lv
ON li.lp_id=lv.lp_id INNER JOIN $lp_item_view_table liw ON liw.lp_item_id=li.id
WHERE li.c_id = $course_id AND
liw.c_id = $course_id AND
lv.c_id = $course_id AND
lv.user_id= $user_id AND (li.item_type = 'sco' OR li.item_type='quiz') AND liw.lp_view_id = $lp_view_id";
$tot=0;
$sum=0;
@ -1936,8 +1956,8 @@ class Tracking {
foreach($lp_list as $lp_id) {
//check if LP have a score
$sql = "SELECT count(id) as count FROM $lp_item_table
WHERE item_type = 'quiz' AND lp_id = ".$lp_id." ";
$sql = "SELECT count(id) as count FROM $lp_item_table
WHERE c_id = $course_id AND item_type = 'quiz' AND lp_id = ".$lp_id." ";
$result_have_quiz = Database::query($sql);
if (Database::num_rows($result_have_quiz) > 0 ) {
@ -2005,12 +2025,12 @@ class Tracking {
$condition_session = ' AND down_session_id = '. $session_id;
}
$sql = "SELECT down_doc_path, COUNT(DISTINCT down_user_id), COUNT(down_doc_path) as count_down
FROM $TABLETRACK_DOWNLOADS
WHERE down_cours_id = '$course_code'
$condition_session
GROUP BY down_doc_path
ORDER BY count_down DESC
LIMIT 0, $limit";
FROM $TABLETRACK_DOWNLOADS
WHERE down_cours_id = '$course_code'
$condition_session
GROUP BY down_doc_path
ORDER BY count_down DESC
LIMIT 0, $limit";
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
@ -2032,10 +2052,13 @@ class Tracking {
//protect data
$course_code = Database::escape_string($course_code);
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$data = array();
$TABLETRACK_LINKS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
$TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK, $course_info['dbName']);
$TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
$condition_session = '';
if (isset($session_id)) {
@ -2045,9 +2068,10 @@ class Tracking {
$sql = "SELECT cl.title, cl.url,count(DISTINCT sl.links_user_id), count(cl.title) as count_visits
FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
WHERE sl.links_link_id = cl.id
AND sl.links_cours_id = '$course_code'
$condition_session
WHERE cl.c_id = $course_id AND
sl.links_link_id = cl.id
AND sl.links_cours_id = '$course_code'
$condition_session
GROUP BY cl.title, cl.url
ORDER BY count_visits DESC
LIMIT 0, 3";
@ -2065,8 +2089,7 @@ class Tracking {
* @param int user id
* @return string html code
*/
function show_user_progress($user_id, $session_id = 0, $extra_params = '', $show_courses = true) {
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
function show_user_progress($user_id, $session_id = 0, $extra_params = '', $show_courses = true) {
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
global $_configuration;
@ -2368,7 +2391,6 @@ class Tracking {
//$html .= Display::tag('td', $all_done_exercise);
$html .= Display::tag('td', convert_to_percentage($all_average));
if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) {
$icon = Display::url(Display::return_icon('2rightarrow_na.gif', get_lang('Details')), '?session_id='.$my_session_id);
@ -2525,16 +2547,16 @@ class Tracking {
$session_id = intval($session_id);
$course = Database::escape_string($course_code);
$course_info = CourseManager::get_course_information($course);
$course_id = $course_info['real_id'];
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $course_info['db_name']);
$tbl_course_lp_view_item = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_info['db_name']);
$tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $course_info['db_name']);
$tbl_course_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_info['db_name']);
$tbl_course_quiz = Database :: get_course_table(TABLE_QUIZ_TEST, $course_info['db_name']);
$tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN);
$tbl_course_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
$session_name = api_get_session_name($session_id);
$html .= Display::tag('h2', $course_info['title']);
@ -2559,9 +2581,9 @@ class Tracking {
</tr>';
if (empty($session_id)) {
$sql_exercices = "SELECT quiz.title,id, results_disabled FROM ".$tbl_course_quiz." AS quiz WHERE active='1' AND session_id = 0";
$sql_exercices = "SELECT quiz.title,id, results_disabled FROM ".$tbl_course_quiz." AS quiz WHERE c_id = $course_id AND active='1' AND session_id = 0";
} else {
$sql_exercices = "SELECT quiz.title,id, results_disabled FROM ".$tbl_course_quiz." AS quiz WHERE active='1'";
$sql_exercices = "SELECT quiz.title,id, results_disabled FROM ".$tbl_course_quiz." AS quiz WHERE c_id = $course_id AND active='1'";
}
$result_exercices = Database::query($sql_exercices);
$to_graph_exercise_result = array();
@ -2571,8 +2593,7 @@ class Tracking {
$user_list = UserManager::get_user_list();
} else {
$user_list = SessionManager::get_users_by_session($session_id);
}
}
if (Database::num_rows($result_exercices) > 0) {
$score = $weighting = $exe_id = 0;
@ -2665,9 +2686,9 @@ class Tracking {
$html .= '</tr>';
if (empty($session_id)) {
$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp WHERE session_id = 0 ORDER BY lp.display_order";
$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp WHERE c_id = $course_id AND session_id = 0 ORDER BY lp.display_order";
} else {
$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp ORDER BY lp.display_order";
$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp WHERE c_id = $course_id ORDER BY lp.display_order";
}
$result_learnpath = Database::query($sql_learnpath);
@ -2710,8 +2731,6 @@ class Tracking {
</tr>';
}
$html .='</table>';
}
if (!empty($html)) {
$html = Display::div($html, array('class'=>'rounded_div', 'style'=>'position:relative; float:none; width:95%'));
@ -3067,7 +3086,6 @@ class Tracking {
//$main_graph->drawStackedBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE);
$main_graph->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100);
// Finish the graph
$main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
$main_graph->drawLegend($main_width - 120,$main_height -100,$data_set->GetDataDescription(),255,255,255);
@ -3097,12 +3115,13 @@ class TrackingCourseLog {
function count_item_resources() {
global $session_id;
$course_id = api_get_course_int_id();
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$sql = "SELECT count(tool) AS total_number_of_items FROM $table_item_property track_resource, $table_user user" .
" WHERE track_resource.insert_user_id = user.user_id AND id_session = $session_id ";
" WHERE track_resource.c_id = $course_id AND track_resource.insert_user_id = user.user_id AND id_session = $session_id ";
if (isset($_GET['keyword'])) {
$keyword = Database::escape_string(trim($_GET['keyword']));
@ -3117,20 +3136,25 @@ class TrackingCourseLog {
function get_item_resources_data($from, $number_of_items, $column, $direction) {
global $dateTimeFormatLong, $session_id;
$course_id = api_get_course_int_id();
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$session_id = intval($session_id);
$sql = "SELECT
tool as col0,
tool as col0,
lastedit_type as col1,
ref as ref,
user.username as col3,
insert_date as col5,
visibility as col6
FROM $table_item_property track_resource, $table_user user
WHERE track_resource.insert_user_id = user.user_id AND id_session = $session_id ";
WHERE track_resource.c_id = $course_id AND
track_resource.insert_user_id = user.user_id AND
id_session = $session_id ";
if (isset($_GET['keyword'])) {
$keyword = Database::escape_string(trim($_GET['keyword']));
@ -3144,10 +3168,10 @@ class TrackingCourseLog {
}
if ($column != '' && $direction != '') {
if ($column != 2 && $column != 4) {
$sql .= " ORDER BY col$column $direction";
$sql .= " ORDER BY col$column $direction";
}
} else {
$sql .= " ORDER BY col5 DESC ";
$sql .= " ORDER BY col5 DESC ";
}
$sql .= " LIMIT $from, $number_of_items ";
@ -3165,26 +3189,25 @@ class TrackingCourseLog {
if (in_array($row['col0'], array('thematic_plan', 'thematic_advance'))) {
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$sql = "SELECT thematic_id FROM $table_tool WHERE id = $ref";
$sql = "SELECT thematic_id FROM $table_tool WHERE c_id = $course_id AND id = $ref";
$rs_thematic = Database::query($sql);
if (Database::num_rows($rs_thematic)) {
$row_thematic = Database::fetch_array($rs_thematic);
$thematic_id = $row_thematic['thematic_id'];
$query = "SELECT session.id, session.name, user.username FROM $tbl_thematic t, $table_session session, $table_user user" .
" WHERE t.session_id = session.id AND session.id_coach = user.user_id AND t.id = $thematic_id";
" WHERE t.c_id = $course_id AND t.session_id = session.id AND session.id_coach = user.user_id AND t.id = $thematic_id";
$recorset = Database::query($query);
}
} else {
$query = "SELECT session.id, session.name, user.username FROM $table_tool tool, $table_session session, $table_user user" .
" WHERE tool.session_id = session.id AND session.id_coach = user.user_id AND tool.$id = $ref";
$query = "SELECT session.id, session.name, user.username FROM $table_tool tool, $table_session session, $table_user user
WHERE tool.c_id = $course_id AND tool.session_id = session.id AND session.id_coach = user.user_id AND tool.$id = $ref";
$recorset = Database::query($query);
}
if (!empty($recorset)) {
$obj = Database::fetch_object($recorset);
$name_session = '';
$coach_name = '';
if (!empty($obj)) {
@ -3220,65 +3243,60 @@ class TrackingCourseLog {
//@todo Improve this code please
switch ($table_name['table_name']) {
case 'document' :
$query_document = "SELECT tool.title as title FROM $table_tool tool WHERE id = $ref";
$query_document = "SELECT tool.title as title FROM $table_tool tool WHERE c_id = $course_id AND id = $ref";
$rs_document = Database::query($query_document);
$obj_document = Database::fetch_object($rs_document);
$row[4] = $obj_document->title;
break;
case 'announcement':
$query_document = "SELECT title FROM $table_tool " .
" WHERE id = $ref";
$query_document = "SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref";
$rs_document = Database::query($query_document);
$obj_document = Database::fetch_object($rs_document);
$row[4] = $obj_document->title;
break;
case 'glossary':
$query_document = "SELECT name FROM $table_tool " .
" WHERE glossary_id = $ref";
$query_document = "SELECT name FROM $table_tool WHERE c_id = $course_id AND glossary_id = $ref";
$rs_document = Database::query($query_document);
$obj_document = Database::fetch_object($rs_document);
$row[4] = $obj_document->name;
break;
case 'lp':
$query_document = "SELECT name FROM $table_tool " .
" WHERE id = $ref";
$query_document = "SELECT name FROM $table_tool WHERE c_id = $course_id AND id = $ref";
$rs_document = Database::query($query_document);
$obj_document = Database::fetch_object($rs_document);
$row[4] = $obj_document->name;
break;
case 'quiz':
$query_document = "SELECT title FROM $table_tool " .
" WHERE id = $ref";
$query_document = "SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref";
$rs_document = Database::query($query_document);
$obj_document = Database::fetch_object($rs_document);
$row[4] = $obj_document->title;
break;
case 'course_description':
$query_document = "SELECT title FROM $table_tool " .
" WHERE id = $ref";
$query_document = "SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref";
$rs_document = Database::query($query_document);
$obj_document = Database::fetch_object($rs_document);
$row[4] = $obj_document->title;
break;
case 'thematic':
$rs = Database::query("SELECT title FROM $table_tool WHERE id = $ref");
$rs = Database::query("SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref");
if (Database::num_rows($rs) > 0) {
$obj = Database::fetch_object($rs);
$row[4] = $obj->title;
}
break;
case 'thematic_advance':
$rs = Database::query("SELECT content FROM $table_tool WHERE id = $ref");
$rs = Database::query("SELECT content FROM $table_tool WHERE c_id = $course_id AND id = $ref");
if (Database::num_rows($rs) > 0) {
$obj = Database::fetch_object($rs);
$row[4] = $obj->content;
}
break;
case 'thematic_plan':
$rs = Database::query("SELECT title FROM $table_tool WHERE id = $ref");
$rs = Database::query("SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref");
if (Database::num_rows($rs) > 0) {
$obj = Database::fetch_object($rs);
$row[4] = $obj->title;

@ -905,7 +905,7 @@ if (empty($_GET['details'])) {
echo '</td>';
echo '<td align="center">';
$all_attempt_url = "../exercice/exercice.php?show=result&exerciseId=$exercise_id&cidReq=$course_code&filter_by_user=$student_id&id_session=$session_id";
$all_attempt_url = "../exercice/exercise_report.php?exerciseId=$exercise_id&cidReq=$course_code&filter_by_user=$student_id&id_session=$session_id";
echo Display::url(Display::return_icon('test_results.png', get_lang('AllAttempts'), array(), 22), $all_attempt_url );
echo '</td></tr>';

@ -2451,19 +2451,21 @@ class learnpath {
* Return the number of interactions for the given learnpath Item View ID.
* This method can be used as static.
* @param integer Item View ID
* @param integer course id
* @return integer Number of interactions
*/
public function get_interactions_count_from_db($lp_iv_id = 0, $course_code = null) {
if (empty ($lp_iv_id)) {
return -1;
}
$course_info = api_get_course_info($course_code);
$table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
$course_id = $course_info['real_id'];
public function get_interactions_count_from_db($lp_iv_id, $course_id) {
$table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
$lp_iv_id = intval($lp_iv_id);
$course_id = intval($course_id);
$sql = "SELECT count(*) FROM $table WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
$res = Database::query($sql);
$row = Database::fetch_array($res);
$num = $row[0];
$res = 0;
if (Database::num_rows($res)) {
$row = Database::fetch_array($res);
$num = $row[0];
}
return $num;
}
@ -2515,17 +2517,17 @@ class learnpath {
* @param integer Item View ID
* @return integer Number of objectives
*/
public function get_objectives_count_from_db($lp_iv_id = 0, $course_code = null) {
if (empty ($lp_iv_id)) {
return -1;
}
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
public function get_objectives_count_from_db($lp_iv_id, $course_id) {
$table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
$course_id = intval($course_id);
$lp_iv_id = intval($lp_iv_id);
$sql = "SELECT count(*) FROM $table WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
$res = Database::query($sql);
$row = Database :: fetch_array($res);
$num = $row[0];
$res = 0;
if (Database::num_rows($res)) {
$row = Database :: fetch_array($res);
$num = $row[0];
}
return $num;
}

@ -91,7 +91,7 @@ $TBL_QUIZ = Database :: get_course_table(TABLE_QUIZ_TEST);
$tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$tbl_stats_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$sql = "SELECT max(view_count) FROM $TBL_LP_VIEW WHERE lp_id = $lp_id AND user_id = '" . $user_id . "' $session_condition";
$sql = "SELECT max(view_count) FROM $TBL_LP_VIEW WHERE c_id = $course_id AND lp_id = $lp_id AND user_id = '" . $user_id . "' $session_condition";
$res = Database::query($sql);
$view = '';
$num = 0;
@ -121,7 +121,7 @@ if (isset($_GET['lp_id']) && isset($_GET['my_lp_id'])) {
$clean_lp_item_id = Database::escape_string($_GET['my_lp_id']);
$clean_lp_id = Database::escape_string($_GET['lp_id']);
$clean_course_code = Database :: escape_string($course_code);
$sql_path = "SELECT path FROM $TBL_LP_ITEM WHERE id = '$clean_lp_item_id' AND lp_id = '$clean_lp_id'";
$sql_path = "SELECT path FROM $TBL_LP_ITEM WHERE c_id = $course_id AND id = '$clean_lp_item_id' AND lp_id = '$clean_lp_id'";
$res_path = Database::query($sql_path);
$row_path = Database::fetch_array($res_path);
@ -176,12 +176,11 @@ if (is_array($list) && count($list) > 0) {
" i.item_type as item_type, iv.view_count as iv_view_count, " .
" iv.id as iv_id, path as path " .
" FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v " .
" WHERE i.id = iv.lp_item_id
" WHERE i.id = iv.lp_item_id AND
i.c_id = $course_id AND
iv.c_id = $course_id AND
v.c_id = $course_id AND
" .
" AND i.id = $my_item_id " .
v.c_id = $course_id AND
i.id = $my_item_id " .
" AND iv.lp_view_id = v.id " .
" AND i.lp_id = $lp_id " .
" AND v.user_id = " . $user_id . " " .
@ -202,7 +201,7 @@ if (is_array($list) && count($list) > 0) {
// Check results_disabled in quiz table.
$my_path = Database::escape_string($row['path']);
$sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE id ='".(int)$my_path."'";
$sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE c_id = $course_id AND id ='".(int)$my_path."'";
$res_result_disabled = Database::query($sql);
$row_result_disabled = Database::fetch_row($res_result_disabled);
@ -240,7 +239,7 @@ if (is_array($list) && count($list) > 0) {
// Check if there are interactions below.
$extend_attempt_link = '';
$extend_this_attempt = 0;
if ((learnpath :: get_interactions_count_from_db($row['iv_id']) > 0 || learnpath :: get_objectives_count_from_db($row['iv_id']) > 0) && !$extend_all) {
if ((learnpath :: get_interactions_count_from_db($row['iv_id'], $course_id) > 0 || learnpath :: get_objectives_count_from_db($row['iv_id'], $course_id) > 0) && !$extend_all) {
if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
// The extend button for this attempt has been clicked.
$extend_this_attempt = 1;
@ -388,7 +387,7 @@ if (is_array($list) && count($list) > 0) {
// Check results_disabled in quiz table.
$my_path = Database::escape_string($my_path);
$sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE id ='".(int)$my_path."'";
$sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE c_id = $course_id AND id ='".(int)$my_path."'";
$res_result_disabled = Database::query($sql);
$row_result_disabled = Database::fetch_row($res_result_disabled);
@ -400,8 +399,9 @@ if (is_array($list) && count($list) > 0) {
// Check if there are interactions below.
$extend_attempt_link = '';
$extend_this_attempt = 0;
$inter_num = learnpath::get_interactions_count_from_db($row['iv_id']);
$objec_num = learnpath::get_objectives_count_from_db($row['iv_id']);
$inter_num = learnpath::get_interactions_count_from_db($row['iv_id'], $course_id);
$objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id);
if (($inter_num > 0 || $objec_num > 0) && !$extend_all) {
if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
// The extend button for this attempt has been clicked.
@ -466,12 +466,14 @@ if (is_array($list) && count($list) > 0) {
} else {
if ($row['item_type'] == 'quiz') {
// Get score and total time from last attempt of a exercise en lp.
$sql = "SELECT score FROM $TBL_LP_ITEM_VIEW WHERE lp_item_id = '".(int)$my_id."' and lp_view_id = '".(int)$my_lp_view_id."'
$sql = "SELECT score FROM $TBL_LP_ITEM_VIEW
WHERE c_id = $course_id AND lp_item_id = '".(int)$my_id."' and lp_view_id = '".(int)$my_lp_view_id."'
ORDER BY view_count DESC limit 1";
$res_score = Database::query($sql);
$row_score = Database::fetch_array($res_score);
$sql = "SELECT SUM(total_time) as total_time FROM $TBL_LP_ITEM_VIEW WHERE lp_item_id = '".(int)$my_id."' and lp_view_id = '".(int)$my_lp_view_id."'";
$sql = "SELECT SUM(total_time) as total_time FROM $TBL_LP_ITEM_VIEW
WHERE c_id = $course_id AND lp_item_id = '".(int)$my_id."' and lp_view_id = '".(int)$my_lp_view_id."'";
$res_time = Database::query($sql);
$row_time = Database::fetch_array($res_time);
@ -486,8 +488,8 @@ if (is_array($list) && count($list) > 0) {
//$time = learnpathItem :: get_scorm_time('js', $subtotal_time);
// Selecting the max score from an attempt.
$sql = "SELECT SUM(t.ponderation) as maxscore FROM (
SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at INNER JOIN $tbl_quiz_questions as q
ON(q.id = at.question_id)
SELECT distinct question_id, marks, ponderation FROM $tbl_stats_attempts as at INNER JOIN $tbl_quiz_questions as q
ON (q.id = at.question_id AND q.c_id = $course_id )
WHERE exe_id ='$id_last_attempt' ) as t";
$result = Database::query($sql);
@ -687,7 +689,7 @@ if (is_array($list) && count($list) > 0) {
if (!$is_allowed_to_edit && $result_disabled_ext_all ) {
$output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="'.get_lang('ShowAndQualifyAttempt').'" title="'.get_lang('ShowAndQualifyAttempt').'"></td>';
} else {
$output .= '<td><a href="../exercice/exercise_show.php?origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="'.get_lang('ShowAndQualifyAttempt').'" title="'.get_lang('ShowAndQualifyAttempt').'"></a></td>';
$output .= '<td><a href="../exercice/exercise_show.php?cidReq=' . $course_code.'&origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="'.get_lang('ShowAndQualifyAttempt').'" title="'.get_lang('ShowAndQualifyAttempt').'"></a></td>';
}
}
$output .= '</tr>';

@ -124,6 +124,7 @@ echo '<div class="actions" style="height:32px">';
if (empty($_GET['studentlist'])) {
$_GET['studentlist'] = 'true';
}
switch($_GET['studentlist']) {
case 'true':
echo Display::return_icon('user_na.png', get_lang('StudentsTracking'), array(), 32);
@ -166,10 +167,9 @@ echo '</span>';
echo '</div>';
//Actions
if ($_GET['studentlist'] == '' || $_GET['studentlist'] == 'true') {
echo '<div class="actions">';
// Create a search-box.
$form_search = new FormValidator('search_simple', 'get', api_get_path(WEB_CODE_PATH).'tracking/courseLog.php?'.api_get_cidreq().'&studentlist=true', '', 'width=200px', false);
$renderer =& $form_search->defaultRenderer();
@ -188,22 +188,23 @@ if ($_GET['studentlist'] == 'false') {
echo'<br /><br />';
// learning path tracking
echo '<div class="report_section">
<h2>'.Display::return_icon('scorms.gif',get_lang('AverageProgressInLearnpath')).get_lang('AverageProgressInLearnpath').'</h2>
<table class="data_table">';
$list = new LearnpathList('', $course_code, $session_id);
if (count($flat_list) > 0) {
// learning path tracking
echo '<div class="report_section">
<h2>'.Display::return_icon('scorms.gif',get_lang('AverageProgressInLearnpath')).get_lang('AverageProgressInLearnpath').'</h2>
<table class="data_table">';
$flat_list = $list->get_flat_list();
if ($export_csv) {
$temp = array(get_lang('AverageProgressInLearnpath', ''), '');
$csv_content[] = array('', '');
$csv_content[] = $temp;
}
$list = new LearnpathList('', $course_code, $session_id);
$flat_list = $list->get_flat_list();
if ($export_csv) {
$temp = array(get_lang('AverageProgressInLearnpath', ''), '');
$csv_content[] = array('', '');
$csv_content[] = $temp;
}
if (count($flat_list) > 0) {
foreach ($flat_list as $lp_id => $lp) {
$lp_avg_progress = 0;
foreach ($a_students as $student_id => $student) {
@ -227,18 +228,20 @@ if ($_GET['studentlist'] == 'false') {
$csv_content[] = $temp;
}
}
echo '</table></div>';
} else {
echo '<tr><td>'.get_lang('NoLearningPath').'</td></tr>';
//echo '<tr><td>'.get_lang('NoLearningPath').'</td></tr>';
if ($export_csv) {
$temp = array(get_lang('NoLearningPath', ''), '');
$csv_content[] = $temp;
}
}
echo '</table></div>';
echo '<div class="clear"></div>';
//hiding detail for exercises
// Exercices tracking.
echo '<div class="report_section">
// Exercices tracking.
echo '<div class="report_section">
<h2>'.Display::return_icon('quiz.gif',get_lang('AverageResultsToTheExercices')).get_lang('AverageResultsToTheExercices').'</h2>
<table class="data_table">';
@ -430,63 +433,65 @@ if ($_GET['studentlist'] == 'false') {
}
} elseif ($_GET['studentlist'] == 'true' or $_GET['studentlist'] == '') {
// BEGIN : form to remind inactives susers
$form = new FormValidator('reminder_form', 'get', api_get_path(REL_CODE_PATH).'announcements/announcements.php');
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<span>{label} {element}</span>&nbsp;<button class="save" type="submit">'.get_lang('SendNotification').'</button>','since');
$options = array (
2 => '2 '.get_lang('Days'),
3 => '3 '.get_lang('Days'),
4 => '4 '.get_lang('Days'),
5 => '5 '.get_lang('Days'),
6 => '6 '.get_lang('Days'),
7 => '7 '.get_lang('Days'),
15 => '15 '.get_lang('Days'),
30 => '30 '.get_lang('Days'),
'never' => get_lang('Never')
);
$el = $form -> addElement('select', 'since', '<img width="22" align="middle" src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" border="0" />'.get_lang('RemindInactivesLearnersSince'), $options);
$el -> setSelected(7);
$form -> addElement('hidden', 'action', 'add');
$form -> addElement('hidden', 'remindallinactives', 'true');
if (count($a_students) > 0) {
$form = new FormValidator('reminder_form', 'get', api_get_path(REL_CODE_PATH).'announcements/announcements.php');
$course_info = api_get_course_info(api_get_course_id());
$course_name = get_lang('Course').' '.$course_info['name'];
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<span>{label} {element}</span>&nbsp;<button class="save" type="submit">'.get_lang('SendNotification').'</button>','since');
if ($session_id) {
echo '<h2>'.Display::return_icon('session.png', get_lang('Session'), array(), 22).' '.api_get_session_name($session_id).' '.
Display::return_icon('course.png', get_lang('Course'), array(), 22).' '.$course_name.'</h2>';
} else {
echo '<h2>'.Display::return_icon('course.png', get_lang('Course'), array(), 22).' '.$course_info['name'].'</h2>';
}
$options = array (
2 => '2 '.get_lang('Days'),
3 => '3 '.get_lang('Days'),
4 => '4 '.get_lang('Days'),
5 => '5 '.get_lang('Days'),
6 => '6 '.get_lang('Days'),
7 => '7 '.get_lang('Days'),
15 => '15 '.get_lang('Days'),
30 => '30 '.get_lang('Days'),
'never' => get_lang('Never')
);
$extra_field_select = TrackingCourseLog::display_additional_profile_fields();
$el = $form -> addElement('select', 'since', '<img width="22" align="middle" src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" border="0" />'.get_lang('RemindInactivesLearnersSince'), $options);
$el -> setSelected(7);
$form -> addElement('hidden', 'action', 'add');
$form -> addElement('hidden', 'remindallinactives', 'true');
$course_info = api_get_course_info(api_get_course_id());
$course_name = get_lang('Course').' '.$course_info['name'];
if ($session_id) {
echo '<h2>'.Display::return_icon('session.png', get_lang('Session'), array(), 22).' '.api_get_session_name($session_id).' '.
Display::return_icon('course.png', get_lang('Course'), array(), 22).' '.$course_name.'</h2>';
} else {
echo '<h2>'.Display::return_icon('course.png', get_lang('Course'), array(), 22).' '.$course_info['name'].'</h2>';
}
$extra_field_select = TrackingCourseLog::display_additional_profile_fields();
if (!empty($extra_field_select)) {
echo $extra_field_select;
}
$form->display();
if (!empty($extra_field_select)) {
echo $extra_field_select;
}
$form->display();
// END : form to remind inactives susers
if ($export_csv) {
$is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
} else {
// END : form to remind inactives susers
/*
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();
}*/
//PERSON_NAME_DATA_EXPORT is buggy
$is_western_name_order = api_is_western_name_order();
}
//PERSON_NAME_DATA_EXPORT is buggy
$is_western_name_order = api_is_western_name_order();
//$sort_by_first_name = api_sort_by_first_name();
$sort_by_first_name = api_sort_by_first_name();
$tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : 0;
$tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : 'DESC';
if (count($a_students) > 0) {
//$tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : 0;
//$tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : 'DESC';
if ($export_csv) {
$csv_content = array();
@ -535,12 +540,10 @@ if ($_GET['studentlist'] == 'false') {
$table->set_header(10, get_lang('LatestLogin'), false, 'align="center"');
$table->set_header(11, get_lang('AdditionalProfileField'), false);
$table->set_header(12, get_lang('Details'), false);
}
}
$table->display();
} else {
echo get_lang('NoUsersInCourseTracking');
echo Display::display_warning_message(get_lang('NoUsersInCourse'));
}
// Send the csv file if asked.
@ -605,9 +608,9 @@ if ($_GET['studentlist'] == 'false') {
$table->set_header(0, get_lang('Tool'));
$table->set_header(1, get_lang('EventType'));
$table->set_header(2, get_lang('Session'), false);
$table->set_header(3, get_lang('UserName'));
$table->set_header(3, get_lang('UserName'), true, 'width=65px');
$table->set_header(4, get_lang('Document'), false);
$table->set_header(5, get_lang('Date'), true, 'width=160px');
$table->set_header(5, get_lang('Date'), true, 'width=190px');
$table->display();
}

Loading…
Cancel
Save