Fixing counter field update due the global chat see #4191

skala
Julio Montoya 13 years ago
parent 1f932c8b84
commit f89a25ff44
  1. 2
      main/inc/ajax/chat.ajax.php
  2. 3
      main/inc/lib/chat.lib.php
  3. 94
      main/inc/local.inc.php

@ -4,6 +4,8 @@
* Responses to AJAX calls * Responses to AJAX calls
*/ */
$_dont_save_user_course_access = true;
require_once '../global.inc.php'; require_once '../global.inc.php';
require_once api_get_path(LIBRARY_PATH).'chat.lib.php'; require_once api_get_path(LIBRARY_PATH).'chat.lib.php';

@ -191,8 +191,7 @@ class Chat extends Model {
function close() { function close() {
unset($_SESSION['openChatBoxes'][$_POST['chatbox']]); unset($_SESSION['openChatBoxes'][$_POST['chatbox']]);
unset($_SESSION['chatHistory'][$_POST['chatbox']]); unset($_SESSION['chatHistory'][$_POST['chatbox']]);
echo "1"; echo "1";
exit; exit;
} }

@ -790,54 +790,62 @@ if (isset($cidReset) && $cidReset) { // course session data refresh requested or
$rs = Database::query($sql); $rs = Database::query($sql);
list($_SESSION['session_name']) = Database::fetch_array($rs); list($_SESSION['session_name']) = Database::fetch_array($rs);
} }
if (!isset($_SESSION['login_as'])) { if (!isset($_SESSION['login_as'])) {
$save_course_access = true;
$course_tracking_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); //The value $_dont_save_user_course_access should be added before the call of global.inc.php see the main/inc/chat.ajax.php file
//Disables the updates in the TRACK_E_COURSE_ACCESS table
if (isset($_dont_save_user_course_access) && $_dont_save_user_course_access == true) {
$save_course_access = false;
}
/* if ($save_course_access) {
* When $_configuration['session_lifetime'] is too big 100 hours (in order to let users take exercises with no problems) $course_tracking_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
* the function Tracking::get_time_spent_on_the_course() returns big values (200h) due the condition:
* login_course_date > now() - INTERVAL $session_lifetime SECOND /*
* * When $_configuration['session_lifetime'] is too big 100 hours (in order to let users take exercises with no problems)
*/ * the function Tracking::get_time_spent_on_the_course() returns big values (200h) due the condition:
/* * login_course_date > now() - INTERVAL $session_lifetime SECOND
if (isset($_configuration['session_lifetime'])) { *
$session_lifetime = $_configuration['session_lifetime']; */
} else { /*
if (isset($_configuration['session_lifetime'])) {
$session_lifetime = $_configuration['session_lifetime'];
} else {
$session_lifetime = 3600; // 1 hour
}*/
$session_lifetime = 3600; // 1 hour $session_lifetime = 3600; // 1 hour
}*/
$session_lifetime = 3600; // 1 hour
$course_code = $_course['sysCode']; $course_code = $_course['sysCode'];
$time = api_get_datetime(); $time = api_get_datetime();
//We select the last record for the current course in the course tracking table //We select the last record for the current course in the course tracking table
// But only if the login date is < than now + max_life_time //But only if the login date is < than now + max_life_time
$sql = "SELECT course_access_id FROM $course_tracking_table
$sql = "SELECT course_access_id FROM $course_tracking_table WHERE user_id = ".intval($_user ['user_id'])." AND
WHERE user_id = ".intval($_user ['user_id'])." AND course_code = '$course_code' AND
course_code = '$course_code' AND session_id = ".api_get_session_id()." AND
session_id = ".api_get_session_id()." AND login_course_date > now() - INTERVAL $session_lifetime SECOND
login_course_date > now() - INTERVAL $session_lifetime SECOND ORDER BY login_course_date DESC LIMIT 0,1";
ORDER BY login_course_date DESC LIMIT 0,1"; $result = Database::query($sql);
$result = Database::query($sql);
//error_log($sql); if (Database::num_rows($result) > 0) {
if (Database::num_rows($result)>0) { $i_course_access_id = Database::result($result,0,0);
//We update the course tracking table
$i_course_access_id = Database::result($result,0,0); $sql="UPDATE $course_tracking_table SET logout_course_date = '$time', counter = counter+1 ".
//We update the course tracking table "WHERE course_access_id=".intval($i_course_access_id)." AND session_id = ".api_get_session_id();
$sql="UPDATE $course_tracking_table SET logout_course_date = '$time', counter = counter+1 ". //error_log($sql);
"WHERE course_access_id=".intval($i_course_access_id)." AND session_id = ".api_get_session_id(); Database::query($sql);
//error_log($sql); } else {
Database::query($sql); $sql="INSERT INTO $course_tracking_table (course_code, user_id, login_course_date, logout_course_date, counter, session_id)" .
} else { "VALUES('".$course_code."', '".$_user['user_id']."', '$time', '$time', '1','".api_get_session_id()."')";
$sql="INSERT INTO $course_tracking_table (course_code, user_id, login_course_date, logout_course_date, counter, session_id)" . //error_log($sql);
"VALUES('".$course_code."', '".$_user['user_id']."', '$time', '$time', '1','".api_get_session_id()."')"; Database::query($sql);
//error_log($sql); }
Database::query($sql);
} }
} }
} }
} }

Loading…
Cancel
Save