diff --git a/documentation/changelog.html b/documentation/changelog.html
index b62098d534..9e88c8102f 100644
--- a/documentation/changelog.html
+++ b/documentation/changelog.html
@@ -131,6 +131,7 @@ calendar_event table, instead this value is 0.
Improvements to the User profile
Improvements to the Learning path display view (no more frames)
Added HTML Purifier
+ Added tracking/logging of admin activity FS#842
Debugging
diff --git a/main/admin/settings.php b/main/admin/settings.php
index 016c95332c..58c9e0a233 100644
--- a/main/admin/settings.php
+++ b/main/admin/settings.php
@@ -1,4 +1,4 @@
-getElement('new_stylesheet');
$picture = $picture_element->getValue();
upload_stylesheet($values, $picture);
+
+ // add event to system log
+ $time = time();
+ $user_id = api_get_user_id();
+ $category = $_GET['category'];
+ event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, $time, $user_id);
+
Display::display_confirmation_message(get_lang('StylesheetAdded'));
}
else
@@ -874,9 +894,22 @@ function handle_templates()
if ($_GET['action'] == 'add' OR ( $_GET['action'] == 'edit' AND is_numeric($_GET['id']))) {
add_edit_template();
+
+ // add event to system log
+ $time = time();
+ $user_id = api_get_user_id();
+ $category = $_GET['category'];
+ event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, $time, $user_id);
+
} else {
if ($_GET['action'] == 'delete' and is_numeric($_GET['id'])) {
delete_template($_GET['id']);
+
+ // add event to system log
+ $time = time();
+ $user_id = api_get_user_id();
+ $category = $_GET['category'];
+ event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, $time, $user_id);
}
display_templates();
}
diff --git a/main/admin/statistics/index.php b/main/admin/statistics/index.php
index 9a30ed03e8..327e926453 100644
--- a/main/admin/statistics/index.php
+++ b/main/admin/statistics/index.php
@@ -49,6 +49,7 @@ require_once ('statistics.lib.php');
$strCourse = get_lang('Courses');
$strUsers = get_lang('Users');
+$strSystem = get_lang('System');
$tools[$strCourse]['action=courses'] = get_lang('CountCours');
@@ -64,6 +65,7 @@ $tools[$strUsers]['action=logins&type=day'] = get_lang('Logins').' ('.get_la
$tools[$strUsers]['action=logins&type=hour'] = get_lang('Logins').' ('.get_lang('PeriodHour').')';
$tools[$strUsers]['action=pictures'] = get_lang('CountUsers').' ('.get_lang('UserPicture').')';
+$tools[$strSystem]['action=activities'] = get_lang('ImportantActivities');
echo '';
@@ -133,6 +135,9 @@ switch($_GET['action'])
case 'pictures':
statistics::print_user_pictures_stats();
break;
+ case 'activities':
+ statistics::print_activities_stats();
+ break;
}
Display::display_footer();
diff --git a/main/admin/statistics/statistics.lib.php b/main/admin/statistics/statistics.lib.php
index 523c13c895..d5eb320e00 100644
--- a/main/admin/statistics/statistics.lib.php
+++ b/main/admin/statistics/statistics.lib.php
@@ -80,6 +80,62 @@ class Statistics
$obj = Database::fetch_object($res);
return $obj->number;
}
+
+ /**
+ * Count activities from track_e_default_table
+ * @return int Number of activities counted
+ */
+ function get_number_of_activities()
+ {
+ // Database table definitions
+ $track_e_default = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
+
+ $sql = "SELECT count(default_id) AS total_number_of_items FROM $track_e_default ";
+ $res = api_sql_query($sql, __FILE__, __LINE__);
+ $obj = Database::fetch_object($res);
+ return $obj->total_number_of_items;
+ }
+
+ /**
+ * Get activities data to display
+ */
+ function get_activities_data($from, $number_of_items, $column, $direction)
+ {
+ global $dateTimeFormatLong;
+ $track_e_default = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
+ $table_user = Database::get_main_table(TABLE_MAIN_USER);
+ $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
+
+ $sql = "SELECT
+ default_event_type as col0,
+ default_value_type as col1,
+ default_value as col2,
+ user.username as col3,
+ default_date as col4
+ FROM $track_e_default track_default, $table_user user
+ WHERE track_default.default_user_id = user.user_id ";
+
+ if (isset($_GET['keyword'])) {
+ $keyword = Database::escape_string($_GET['keyword']);
+ $sql .= " AND (user.username LIKE '%".$keyword."%' OR default_event_type LIKE '%".$keyword."%' OR default_value_type LIKE '%".$keyword."%' OR default_value LIKE '%".$keyword."%') ";
+ }
+
+ if (!empty($column) && !empty($direction)) {
+ $sql .= " ORDER BY col$column $direction";
+ } else {
+ $sql .= " ORDER BY col4 DESC ";
+ }
+ $sql .= " LIMIT $from,$number_of_items ";
+
+ $res = api_sql_query($sql, __FILE__, __LINE__);
+ $activities = array ();
+ while ($row = Database::fetch_row($res)) {
+ $row[4] = api_ucfirst(format_locale_date($dateTimeFormatLong,strtotime($row[4])));
+ $activities[] = $row;
+ }
+ return $activities;
+ }
+
/**
* Get all course categories
* @return array All course categories (code => name)
@@ -159,7 +215,7 @@ class Statistics
| '.$number_label.' | ';
if($show_total)
{
- echo ' '.number_format(100*$number/$total, 1, ',', '.').'% | ';
+ echo ' '.($total>0?number_format(100*$number/$total, 1, ',', '.'):'0').'% | ';
}
echo '
';
$i ++;
@@ -274,6 +330,43 @@ class Statistics
$result[get_lang('Yes')] = $count2->n; // #users with picture
Statistics::print_stats(get_lang('CountUsers').' ('.get_lang('UserPicture').')',$result,true);
}
+
+ function print_activities_stats() {
+
+ echo ''.get_lang('ImportantActivities').'
';
+
+ // Create a search-box
+ $form = new FormValidator('search_simple','get',api_get_path(WEB_CODE_PATH).'admin/statistics/index.php?action=activities','','width=200px',false);
+ $renderer =& $form->defaultRenderer();
+ $renderer->setElementTemplate('{element} ');
+ $form->addElement('hidden','action','activities');
+ $form->addElement('hidden','activities_direction','DESC');
+ $form->addElement('hidden','activities_column','4');
+ $form->addElement('text','keyword',get_lang('keyword'));
+ $form->addElement('style_submit_button', 'submit', get_lang('SearchActivities'),'class="search"');
+ echo '';
+ $form->display();
+ echo '
';
+
+
+ $table = new SortableTable('activities', array('Statistics','get_number_of_activities'), array('Statistics','get_activities_data'),4,50,'DESC');
+ $parameters = array();
+
+ $parameters['action'] = 'activities';
+ if (isset($_GET['keyword'])) {
+ $parameters['keyword'] = Security::remove_XSS($_GET['keyword']);
+ }
+
+ $table->set_additional_parameters($parameters);
+ $table->set_header(0, get_lang('EventType'));
+ $table->set_header(1, get_lang('DataType'));
+ $table->set_header(2, get_lang('Value'));
+ $table->set_header(3, get_lang('Username'));
+ $table->set_header(4, get_lang('Date'));
+ $table->display();
+
+ }
+
/**
* Shows statistics about the time of last visit to each course.
*/
diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php
index 79be6d4c76..2546fa5828 100644
--- a/main/inc/lib/add_course.lib.inc.php
+++ b/main/inc/lib/add_course.lib.inc.php
@@ -2381,6 +2381,13 @@ function register_course($courseSysCode, $courseScreenCode, $courseRepository, $
} else {
UrlManager::add_course_to_url($courseSysCode,1);
}
+
+ // add event to system log
+ $time = time();
+ $user_id = api_get_user_id();
+ event_system(LOG_COURSE_CREATE, LOG_COURSE_CODE, $courseSysCode, $time, $user_id, $courseSysCode);
+
+
}
return 0;
}
diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php
index 1efd33b180..84b5ae59d8 100644
--- a/main/inc/lib/course.lib.php
+++ b/main/inc/lib/course.lib.php
@@ -79,7 +79,7 @@
Configuration files
-----------------------------------------------------------
*/
-include_once (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
+require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
/*
-----------------------------------------------------------
@@ -88,8 +88,8 @@ include_once (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
-----------------------------------------------------------
*/
-include_once (api_get_path(LIBRARY_PATH).'database.lib.php');
-include_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
+require_once api_get_path(LIBRARY_PATH).'database.lib.php';
+require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
/*
-----------------------------------------------------------
@@ -317,6 +317,12 @@ class CourseManager {
} else {
$sql = "DELETE FROM $table_course_user WHERE user_id IN (".$user_ids.") AND course_code = '".$course_code."'";
api_sql_query($sql, __FILE__, __LINE__);
+
+ // add event to system log
+ $time = time();
+ $user_id = api_get_user_id();
+ event_system(LOG_UNSUBSCRIBE_USER_FROM_COURSE, LOG_COURSE_CODE, $course_code, $time, $user_id);
+
}
}
@@ -411,6 +417,12 @@ class CourseManager {
status = '".$status."',
sort = '". ($course_sort)."'";
$result = @api_sql_query($add_course_user_entry_sql, __FILE__, __LINE__);
+
+
+ // add event to system log
+ $time = time();
+ $user_id = api_get_user_id();
+ event_system(LOG_SUBSCRIBE_USER_TO_COURSE, LOG_COURSE_CODE, $course_code, $time, $user_id);
}
if ($result) {
return true;
@@ -1661,6 +1673,12 @@ class CourseManager {
}
}
}
+
+ // add event to system log
+ $time = time();
+ $user_id = api_get_user_id();
+ event_system(LOG_COURSE_DELETE, LOG_COURSE_CODE, $code, $time, $user_id, $code);
+
}
/**
diff --git a/main/inc/lib/events.lib.inc.php b/main/inc/lib/events.lib.inc.php
index c1e4fa06f5..698194b400 100644
--- a/main/inc/lib/events.lib.inc.php
+++ b/main/inc/lib/events.lib.inc.php
@@ -1,4 +1,4 @@
-