Skip to content

Commit

Permalink
Update Event::addEvent() and corresponding calls to use course ID ins…
Browse files Browse the repository at this point in the history
…tead of course code ~ refs #7202
  • Loading branch information
ywarnier committed Apr 2, 2015
1 parent fb7b9a2 commit 7977580
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 55 deletions.
8 changes: 7 additions & 1 deletion index.php
Expand Up @@ -50,7 +50,13 @@
*/
if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
$i = api_get_anonymous_id();
Event::addEvent(LOG_ATTEMPTED_FORCED_LOGIN, 'tried_hacking_get', $_SERVER['REMOTE_ADDR'].(empty($_POST['login'])?'':'/'.$_POST['login']),null,$i);
Event::addEvent(
LOG_ATTEMPTED_FORCED_LOGIN,
'tried_hacking_get',
$_SERVER['REMOTE_ADDR'].(empty($_POST['login'])?'':'/'.$_POST['login']),
null,
$i
);
echo 'Attempted breakin - sysadmins notified.';
session_destroy();
die();
Expand Down
16 changes: 14 additions & 2 deletions main/admin/configure_homepage.php
Expand Up @@ -323,7 +323,13 @@ function home_tabs($file_logged_in)
fputs($fp, "<b>$notice_title</b><br />\n$notice_text");
fclose($fp);
}
Event::addEvent(LOG_HOMEPAGE_CHANGED, 'edit_notice', cut(strip_tags($notice_title), 254), api_get_utc_datetime(), api_get_user_id());
Event::addEvent(
LOG_HOMEPAGE_CHANGED,
'edit_notice',
cut(strip_tags($notice_title), 254),
api_get_utc_datetime(),
api_get_user_id()
);
break;
case 'edit_news':
//Filter
Expand Down Expand Up @@ -365,7 +371,13 @@ function home_tabs($file_logged_in)
}
}
}
Event::addEvent(LOG_HOMEPAGE_CHANGED, 'edit_news', strip_tags(cut($home_news, 254)), api_get_utc_datetime(), api_get_user_id());
Event::addEvent(
LOG_HOMEPAGE_CHANGED,
'edit_news',
strip_tags(cut($home_news, 254)),
api_get_utc_datetime(),
api_get_user_id()
);
break;
case 'insert_tabs':
case 'edit_tabs':
Expand Down
16 changes: 14 additions & 2 deletions main/admin/settings.lib.php
Expand Up @@ -765,15 +765,27 @@ function handle_templates() {
// Add event to the system log.
$user_id = api_get_user_id();
$category = $_GET['category'];
Event::addEvent(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
Event::addEvent(
LOG_CONFIGURATION_SETTINGS_CHANGE,
LOG_CONFIGURATION_SETTINGS_CATEGORY,
$category,
api_get_utc_datetime(),
$user_id
);
} else {
if ($action == 'delete' && is_numeric($_GET['id'])) {
delete_template($_GET['id']);

// Add event to the system log
$user_id = api_get_user_id();
$category = $_GET['category'];
Event::addEvent(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
Event::addEvent(
LOG_CONFIGURATION_SETTINGS_CHANGE,
LOG_CONFIGURATION_SETTINGS_CATEGORY,
$category,
api_get_utc_datetime(),
$user_id
);
}
display_templates();
}
Expand Down
2 changes: 1 addition & 1 deletion main/exercice/exercise.class.php
Expand Up @@ -1621,7 +1621,7 @@ public function clean_results($cleanLpTests = false, $cleanResultBeforeDate = nu
$this->id,
null,
null,
api_get_course_id(),
api_get_course_int_id(),
$session_id
);

Expand Down
16 changes: 14 additions & 2 deletions main/inc/lib/career.lib.php
Expand Up @@ -213,7 +213,13 @@ public function save($params, $show_query = false)
{
$id = parent::save($params);
if (!empty($id)) {
Event::addEvent(LOG_CAREER_CREATE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id());
Event::addEvent(
LOG_CAREER_CREATE,
LOG_CAREER_ID,
$id,
api_get_utc_datetime(),
api_get_user_id()
);
}

return $id;
Expand All @@ -226,6 +232,12 @@ public function save($params, $show_query = false)
public function delete($id)
{
parent::delete($id);
Event::addEvent(LOG_CAREER_DELETE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id());
Event::addEvent(
LOG_CAREER_DELETE,
LOG_CAREER_ID,
$id,
api_get_utc_datetime(),
api_get_user_id()
);
}
}
2 changes: 1 addition & 1 deletion main/inc/lib/course.lib.php
Expand Up @@ -2261,7 +2261,7 @@ public static function delete_course($code)
$code,
api_get_utc_datetime(),
$user_id,
$code
$courseId
);
}
}
Expand Down
68 changes: 35 additions & 33 deletions main/inc/lib/events.lib.inc.php
Expand Up @@ -629,12 +629,14 @@ public static function saveExerciseAttemptHotspot($exe_id, $question_id, $answer
/**
* Records information for common (or admin) events (in the track_e_default table)
* @author Yannick Warnier <yannick.warnier@beeznest.com>
* @param string Type of event
* @param string Type of value
* @param string Value
* @param string Timestamp (defaults to null)
* @param integer User ID (defaults to null)
* @param string Course code (defaults to null)
* @param string $event_type Type of event
* @param string $event_value_type Type of value
* @param string $event_value Value
* @param string $datetime Datetime (UTC) (defaults to null)
* @param int $user_id User ID (defaults to null)
* @param int $course_id Course ID (defaults to null)
* @param int $sessionId Session ID
* @return bool
* @assert ('','','') === false
*/
public static function addEvent(
Expand All @@ -643,7 +645,7 @@ public static function addEvent(
$event_value,
$datetime = null,
$user_id = null,
$course_code = null,
$course_id = null,
$sessionId = 0
) {
$TABLETRACK_DEFAULT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
Expand All @@ -653,6 +655,16 @@ public static function addEvent(
}
$event_type = Database::escape_string($event_type);
$event_value_type = Database::escape_string($event_value_type);
if (empty($course_id)) {
$course_id = intval($course_id);
} else {
$course_id = api_get_course_int_id();
}
if (empty($sessionId)) {
$sessionId = intval($sessionId);
} else {
$sessionId = api_get_session_id();
}

//Clean the user_info
if ($event_value_type == LOG_USER_OBJECT) {
Expand All @@ -673,16 +685,8 @@ public static function addEvent(
}

$event_value = Database::escape_string($event_value);
$course_info = api_get_course_info($course_code);
$sessionId = empty($sessionId) ? api_get_session_id() : intval($sessionId);

if (!empty($course_info)) {
$course_id = $course_info['real_id'];
} else {
$course_id = null;
$course_code = null;
}

if (!isset($datetime)) {
$datetime = api_get_utc_datetime();
}
Expand Down Expand Up @@ -1060,22 +1064,16 @@ public static function delete_student_lp_events($user_id, $lp_id, $course, $sess
}

if (!empty($exe_list) && is_array($exe_list) && count($exe_list) > 0) {
$sql = "DELETE FROM $track_e_exercises WHERE exe_id IN (" . implode(
',',
$exe_list
) . ")";
$sql = "DELETE FROM $track_e_exercises
WHERE exe_id IN (" . implode(',', $exe_list) . ")";
Database::query($sql);

$sql = "DELETE FROM $track_attempts WHERE exe_id IN (" . implode(
',',
$exe_list
) . ")";
$sql = "DELETE FROM $track_attempts
WHERE exe_id IN (" . implode(',', $exe_list) . ")";
Database::query($sql);

$sql = "DELETE FROM $recording_table WHERE exe_id IN (" . implode(
',',
$exe_list
) . ")";
$sql = "DELETE FROM $recording_table
WHERE exe_id IN (" . implode(',', $exe_list) . ")";
Database::query($sql);
}

Expand All @@ -1085,7 +1083,7 @@ public static function delete_student_lp_events($user_id, $lp_id, $course, $sess
$lp_id,
null,
null,
$course['code'],
$course_id,
$session_id
);
}
Expand Down Expand Up @@ -1120,7 +1118,7 @@ public static function delete_all_incomplete_attempts($user_id, $exercise_id, $c
$exercise_id . '-' . $user_id,
null,
null,
$course_code,
$course_id,
$session_id
);
}
Expand Down Expand Up @@ -1684,7 +1682,7 @@ public static function delete_attempt($exe_id, $user_id, $courseId, $session_id,
$exe_id . '-' . $question_id,
null,
null,
$courseInfo['code'],
$courseId,
$session_id
);
}
Expand All @@ -1694,15 +1692,19 @@ public static function delete_attempt($exe_id, $user_id, $courseId, $session_id,
* @param $user_id
* @param int $courseId
* @param $question_id
* @param int $sessionId
*/
public static function delete_attempt_hotspot($exe_id, $user_id, $courseId, $question_id)
public static function delete_attempt_hotspot($exe_id, $user_id, $courseId, $question_id, $sessionId = null)
{
$table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);

$exe_id = intval($exe_id);
$user_id = intval($user_id);
$courseId = intval($courseId);
$question_id = intval($question_id);
if (!isset($sessionId)) {
$sessionId = api_get_session_id();
}

$sql = "DELETE FROM $table_track_attempt
WHERE hotspot_exe_id = $exe_id AND
Expand All @@ -1716,8 +1718,8 @@ public static function delete_attempt_hotspot($exe_id, $user_id, $courseId, $que
$exe_id . '-' . $question_id,
null,
null,
$course_code,
$session_id
$courseId,
$sessionId
);
}

Expand Down
24 changes: 21 additions & 3 deletions main/inc/lib/sessionmanager.lib.php
Expand Up @@ -228,7 +228,13 @@ public static function create_session(

// add event to system log
$user_id = api_get_user_id();
Event::addEvent(LOG_SESSION_CREATE, LOG_SESSION_ID, $session_id, api_get_utc_datetime(), $user_id);
Event::addEvent(
LOG_SESSION_CREATE,
LOG_SESSION_ID,
$session_id,
api_get_utc_datetime(),
$user_id
);
}
return $session_id;
}
Expand Down Expand Up @@ -1499,7 +1505,13 @@ public static function delete_session($id_checked, $from_ws = false)
Database::query($sql_delete_sfv);

// Add event to system log
Event::addEvent(LOG_SESSION_DELETE, LOG_SESSION_ID, $id_checked, api_get_utc_datetime(), $userId);
Event::addEvent(
LOG_SESSION_DELETE,
LOG_SESSION_ID,
$id_checked,
api_get_utc_datetime(),
$userId
);
}

/**
Expand Down Expand Up @@ -2336,7 +2348,13 @@ public static function create_category_session($sname, $syear_start, $smonth_sta
$id_session = Database::insert_id();
// Add event to system log
$user_id = api_get_user_id();
Event::addEvent(LOG_SESSION_CATEGORY_CREATE, LOG_SESSION_CATEGORY_ID, $id_session, api_get_utc_datetime(), $user_id);
Event::addEvent(
LOG_SESSION_CATEGORY_CREATE,
LOG_SESSION_CATEGORY_ID,
$id_session,
api_get_utc_datetime(),
$user_id
);
return $id_session;
}

Expand Down
6 changes: 5 additions & 1 deletion main/inc/lib/sub_language.class.php
Expand Up @@ -355,7 +355,11 @@ public static function set_platform_language($language_id)
$lang = Database::fetch_array($result);
$sql_update_2 = "UPDATE " . $tbl_settings_current . " SET selected_value='" . $lang['english_name'] . "' WHERE variable='platformLanguage'";
$result_2 = Database::query($sql_update_2);
Event::addEvent(LOG_PLATFORM_LANGUAGE_CHANGE, LOG_PLATFORM_LANGUAGE, $lang['english_name']);
Event::addEvent(
LOG_PLATFORM_LANGUAGE_CHANGE,
LOG_PLATFORM_LANGUAGE,
$lang['english_name']
);

return $result_2 !== false;
}
Expand Down

0 comments on commit 7977580

Please sign in to comment.