diff --git a/main/inc/lib/text.lib.php b/main/inc/lib/text.lib.php
index eea32b92f5..d53bb2a968 100755
--- a/main/inc/lib/text.lib.php
+++ b/main/inc/lib/text.lib.php
@@ -432,4 +432,25 @@ function float_format($number, $flag = 1)
}
}
+/**
+ * Function to obtain last week timestamps
+ * @return array times for every day inside week
+ */
+function get_last_week() {
+ $week = date('W');
+ $year = date('Y');
+
+ $lastweek=$week-1;
+ if ($lastweek==0){
+ $week = 52;
+ $year--;
+ }
+
+ $lastweek=sprintf("%02d", $lastweek);
+ for ($i=1;$i<=7;$i++){
+ $arrdays[] = strtotime("$year". "W$lastweek"."$i");
+ }
+ return $arrdays;
+}
+
?>
diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php
index c05a6c72e2..9b4a754a8a 100755
--- a/main/inc/lib/tracking.lib.php
+++ b/main/inc/lib/tracking.lib.php
@@ -15,14 +15,23 @@ class Tracking {
/**
* Calculates the time spent on the platform by a user
* @param integer $user_id the user id
+ * @param bool optionally show time spent last week
* @return timestamp $nb_seconds
*/
- public static function get_time_spent_on_the_platform($user_id) {
+ public static function get_time_spent_on_the_platform($user_id, $last_week = false) {
$tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
+ $cond_last_week = '';
+ if ($last_week) {
+ $a_last_week = get_last_week();
+ $fday_last_week = date('Y-m-d H:i:s',$a_last_week[0]);
+ $lday_last_week = date('Y-m-d H:i:s',$a_last_week[6]);
+ $cond_last_week = ' AND (login_date >= "'.$fday_last_week.'" AND login_date <= "'.$lday_last_week.'") ';
+ }
+
$sql = 'SELECT login_date, logout_date FROM ' . $tbl_track_login . '
- WHERE login_user_id = ' . intval($user_id);
+ WHERE login_user_id = ' . intval($user_id).$cond_last_week;
$rs = Database::query($sql);
diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php
index e3bcfb2cee..18f15c6a53 100644
--- a/main/inc/lib/usermanager.lib.php
+++ b/main/inc/lib/usermanager.lib.php
@@ -2905,11 +2905,11 @@ class UserManager
$hr_dept_id = intval($hr_dept_id);
$assigned_users_to_hrm = array();
-
+
$condition_status = '';
- if (!empty($status)) {
+ if (!empty($user_status)) {
$status = intval($status);
- $condition_status = ' WHERE u.status = '.$status;
+ $condition_status = ' AND u.status = '.$user_status;
}
$sql = "SELECT u.user_id, u.username, u.lastname, u.firstname FROM $tbl_user u
diff --git a/main/mySpace/teachers.php b/main/mySpace/teachers.php
index f5cb50a3dc..0d891b2722 100755
--- a/main/mySpace/teachers.php
+++ b/main/mySpace/teachers.php
@@ -13,6 +13,7 @@ $cidReset = true;
require_once '../inc/global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'mySpace/myspace.lib.php';
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
+require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
$this_section = "session_my_space";
@@ -95,20 +96,25 @@ if (!api_is_drh()) {
}
}
+$a_last_week = get_last_week();
+$last_week = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
+
if ($is_western_name_order) {
- echo '
| '.get_lang('FirstName').' | '.get_lang('LastName').' | '.get_lang('Email').' | '.get_lang('AdminCourses').' | '.get_lang('Students').' |
';
+ echo '| '.get_lang('FirstName').' | '.get_lang('LastName').' | '.get_lang('TimeSpentLastWeek').' '.$last_week.' | '.get_lang('Email').' | '.get_lang('AdminCourses').' | '.get_lang('Students').' |
';
} else {
- echo '| '.get_lang('LastName').' | '.get_lang('FirstName').' | '.get_lang('Email').' | '.get_lang('AdminCourses').' | '.get_lang('Students').' |
';
+ echo '| '.get_lang('LastName').' | '.get_lang('FirstName').' | '.get_lang('TimeSpentLastWeek').' '.$last_week.' | '.get_lang('Email').' | '.get_lang('AdminCourses').' | '.get_lang('Students').' |
';
}
if ($is_western_name_order) {
- $header[] = get_lang('FirstName', '');
- $header[] = get_lang('LastName', '');
+ $header[] = get_lang('FirstName');
+ $header[] = get_lang('LastName');
} else {
- $header[] = get_lang('LastName', '');
- $header[] = get_lang('FirstName', '');
+ $header[] = get_lang('LastName');
+ $header[] = get_lang('FirstName');
}
-$header[] = get_lang('Email', '');
+
+$header[] = get_lang('TimeSpentLastWeek');
+$header[] = get_lang('Email');
$data = array();
@@ -144,12 +150,15 @@ if (count($formateurs) > 0) {
$data[$user_id]["lastname"] = $lastname;
$data[$user_id]["firstname"] = $firstname;
}
+
+ $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($user_id,true));
+ $data[$user_id]["timespentlastweek"] = $time_on_platform;
$data[$user_id]["email"] = $email;
if ($is_western_name_order) {
- echo '| '.$firstname.' | '.$lastname.' | '.$email.' | .'2rightarrow.gif) | .'2rightarrow.gif) |
';
+ echo '| '.$firstname.' | '.$lastname.' | '.$time_on_platform.' | '.$email.' | .'2rightarrow.gif) | .'2rightarrow.gif) |
';
} else {
- echo '| '.$lastname.' | '.$firstname.' | '.$email.' | .'2rightarrow.gif) | .'2rightarrow.gif) |
';
+ echo '| '.$lastname.' | '.$firstname.' | '.$time_on_platform.' | '.$email.' | .'2rightarrow.gif) | .'2rightarrow.gif) |
';
}
}
} else {
diff --git a/plugin/dashboard/block_course/block_course.class.php b/plugin/dashboard/block_course/block_course.class.php
index 01dfcf84c1..5f6be75aa0 100755
--- a/plugin/dashboard/block_course/block_course.class.php
+++ b/plugin/dashboard/block_course/block_course.class.php
@@ -144,7 +144,7 @@ class BlockCourse extends Block {
}
if (count($users) > 0) {
$nb_students_in_course = count($users);
- $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $course_code);
+ $avg_time_spent_in_course = api_time_to_hms(Tracking::get_time_spent_on_the_course($users, $course_code));
} else {
$avg_time_spent_in_course = null;
}
diff --git a/plugin/dashboard/block_student/block_student.class.php b/plugin/dashboard/block_student/block_student.class.php
index c603c5c308..57a4842dd0 100755
--- a/plugin/dashboard/block_student/block_student.class.php
+++ b/plugin/dashboard/block_student/block_student.class.php
@@ -133,7 +133,7 @@ class BlockStudent extends Block {
$content .= $students_table;
if (count($students) > 0) {
- $content .= '';
+ $content .= '';
}
$content .= '';
@@ -193,7 +193,7 @@ class BlockStudent extends Block {
$content .= $students_table;
if (count($students) > 0) {
- $content .= '';
+ $content .= '';
}
$content .= '';
return $content;
diff --git a/plugin/dashboard/block_teacher/block_teacher.class.php b/plugin/dashboard/block_teacher/block_teacher.class.php
index 80f03be9c7..035ae478cc 100755
--- a/plugin/dashboard/block_teacher/block_teacher.class.php
+++ b/plugin/dashboard/block_teacher/block_teacher.class.php
@@ -127,7 +127,7 @@ class BlockTeacher extends Block {
$content .= $teachers_table;
if (count($teachers) > 0) {
- $content .= '';
+ $content .= '';
}
$content .= '';
@@ -141,16 +141,18 @@ class BlockTeacher extends Block {
$teachers = $this->teachers;
$content = '';
$content = '';
- $content .= '
'.get_lang('YourTeachers').'
';
-
- if (count($teachers) > 0) {
+ $content .= '
'.get_lang('YourTeachers').'
';
+
+ if (count($teachers) > 0) {
+ $a_last_week = get_last_week();
+ $last_week = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
+
$teachers_table = '
';
$teachers_table .= '
| '.get_lang('FirtName').' |
'.get_lang('LastName').' |
- '.get_lang('Time').' |
- '.get_lang('Email').' |
+ '.get_lang('TimeSpentLastWeek').' '.$last_week.' |
';
@@ -160,16 +162,15 @@ class BlockTeacher extends Block {
$teacher_id = $teacher['user_id'];
$firstname = $teacher['firstname'];
$lastname = $teacher['lastname'];
- $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id));
- $email = $teacher['email'];
-
+
+ $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id,true));
+
if ($i%2 == 0) $class_tr = 'row_odd';
else $class_tr = 'row_even';
$teachers_table .= '
| '.$firstname.' |
'.$lastname.' |
- '.$time_on_platform.' |
- '.$email.' |
+ '.$time_on_platform.' |
';
$i++;
@@ -182,7 +183,7 @@ class BlockTeacher extends Block {
$content .= $teachers_table;
if (count($teachers) > 0) {
- $content .= '';
+ $content .= '';
}
$content .= '';