Fixing user expiration date see #5846

skala
Julio Montoya 12 years ago
parent a308a976d3
commit b34d576a9c
  1. 2
      main/admin/user_add.php
  2. 11
      main/admin/user_edit.php
  3. 228
      main/inc/lib/attendance.lib.php
  4. 42
      main/inc/lib/text.lib.php
  5. 396
      main/inc/lib/thematic.lib.php

@ -270,7 +270,7 @@ if( $form->validate()) {
}
if ($user['radio_expiration_date'] == '1') {
$expiration_date = $user['expiration_date'];
$expiration_date = $user['expiration_date'];
} else {
$expiration_date = '0000-00-00 00:00:00';
}

@ -294,16 +294,20 @@ if ($expiration_date == '0000-00-00 00:00:00') {
$user_data['expiration_date']['Y'] = date('Y');
} else {
$user_data['radio_expiration_date'] = 1;
$user_data['expiration_date'] = array();
$user_data['expiration_date']['d'] = substr($expiration_date, 8, 2);
$user_data['expiration_date']['F'] = substr($expiration_date, 5, 2);
$user_data['expiration_date']['Y'] = substr($expiration_date, 0, 4);
$user_data['expiration_date']['H'] = substr($expiration_date, 11, 2);
$user_data['expiration_date']['i'] = substr($expiration_date, 14, 2);
}
$form->setDefaults($user_data);
$error_drh = false;
// Validate form
if ( $form->validate()) {
if ($form->validate()) {
$user = $form->getSubmitValues();
$is_user_subscribed_in_course = CourseManager::is_user_subscribed_in_course($user['user_id']);
@ -337,10 +341,11 @@ if ( $form->validate()) {
$hr_dept_id = intval($user['hr_dept_id']);
$language = $user['language'];
if ($user['radio_expiration_date'] == '1' && !$user_data['platform_admin']) {
$expiration_date=$user['expiration_date'];
$expiration_date = return_datetime_from_array($user['expiration_date']);
} else {
$expiration_date='0000-00-00 00:00:00';
$expiration_date = '0000-00-00 00:00:00';
}
$active = $user_data['platform_admin'] ? 1 : intval($user['active']);
//If the user is set to admin the status will be overwrite by COURSEMANAGER = 1

@ -37,11 +37,11 @@ class Attendance
*/
static function get_number_of_attendances() {
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$course_id = api_get_course_int_id();
$sql = "SELECT COUNT(att.id) AS total_number_of_items FROM $tbl_attendance att
$sql = "SELECT COUNT(att.id) AS total_number_of_items FROM $tbl_attendance att
WHERE c_id = $course_id AND att.active = 1 $condition_session ";
$res = Database::query($sql);
$res = Database::query($sql);
@ -71,7 +71,7 @@ class Attendance
$condition_session = api_get_session_condition($session_id);
// Get attendance data
$sql = "SELECT id, name, attendance_qualify_max FROM $tbl_attendance
$sql = "SELECT id, name, attendance_qualify_max FROM $tbl_attendance
WHERE c_id = $course_id AND active = 1 $condition_session ";
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
@ -98,17 +98,17 @@ class Attendance
$column = intval($column);
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'ASC';
}
$active_plus = 'att.active = 1';
if (api_is_platform_admin()) {
if (api_is_platform_admin()) {
$active_plus = ' 1 = 1 ';
}
$sql = "SELECT
att.id AS col0,
att.name AS col1,
@ -119,8 +119,8 @@ class Attendance
att.session_id
FROM $tbl_attendance att
WHERE c_id = $course_id AND $active_plus $condition_session
ORDER BY col$column $direction LIMIT $from,$number_of_items ";
ORDER BY col$column $direction LIMIT $from,$number_of_items ";
$res = Database::query($sql);
$attendances = array ();
@ -130,14 +130,14 @@ class Attendance
}
$user_info = api_get_user_info();
while ($attendance = Database::fetch_row($res)) {
$student_param = '';
if (api_is_drh() && ($_GET['student_id'])) {
$student_param = '&student_id='.Security::remove_XSS($_GET['student_id']);
}
$session_star = '';
if (api_get_session_id() == $attendance[6]) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
}
@ -149,7 +149,7 @@ class Attendance
//Link to view
$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$param_gradebook.$student_param.'">'.$attendance[1].'</a>'.$session_star;
}
} else {
$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$param_gradebook.$student_param.'"><del>'.$attendance[1].'</del></a>'.$session_star;
}
@ -189,14 +189,14 @@ class Attendance
$message_alert = get_lang('UnlockMessageInformation');
}
$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('unlock.png',get_lang('LockAttendance')).'</a>';
} else {
} else {
if (api_is_platform_admin()) {
$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('locked.png',get_lang('UnlockAttendance')).'</a>';
} else {
$actions .= '&nbsp;'.Display::return_icon('locked_na.png',get_lang('LockedAttendance'));
}
}
}
}
$actions .= '</center>';
$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);
@ -239,13 +239,13 @@ class Attendance
$table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$session_id = api_get_session_id();
$user_id = api_get_user_id();
$course_code = api_get_course_id();
$course_id = api_get_course_int_id();
$course_code = api_get_course_id();
$course_id = api_get_course_int_id();
$title_gradebook= Database::escape_string($this->attendance_qualify_title);
$value_calification = 0;
$weight_calification = floatval($this->attendance_weight);
$sql = "INSERT INTO $tbl_attendance SET
c_id = $course_id,
c_id = $course_id,
name ='".Database::escape_string($this->name)."',
description = '".Database::escape_string($this->description)."',
attendance_qualify_title = '$title_gradebook',
@ -291,9 +291,9 @@ class Attendance
$title_gradebook = Database::escape_string($this->attendance_qualify_title);
$value_calification = 0;
$weight_calification= floatval($this->attendance_weight);
if (!empty($attendance_id)) {
$sql = "UPDATE $tbl_attendance
SET name ='".Database::escape_string($this->name)."',
description = '".Database::escape_string($this->description)."',
@ -302,7 +302,7 @@ class Attendance
WHERE c_id = $course_id AND id = '$attendance_id'";
Database::query($sql);
api_item_property_update($_course, TOOL_ATTENDANCE, $attendance_id,"AttendanceUpdated", $user_id);
api_item_property_update($_course, TOOL_ATTENDANCE, $attendance_id,"AttendanceUpdated", $user_id);
// add link to gradebook
if ($link_to_gradebook && !empty($this->category_id)) {
@ -313,10 +313,10 @@ class Attendance
} else {
Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
}
}
}
return $attendance_id;
}
return null;
return null;
}
/**
@ -417,7 +417,7 @@ class Attendance
* @return array users data
*/
public function get_users_rel_course($attendance_id = 0) {
$current_session_id = api_get_session_id();
$current_course_id = api_get_course_id();
if (!empty($current_session_id)) {
@ -428,15 +428,15 @@ class Attendance
// get registered users inside current course
$a_users = array();
foreach ($a_course_users as $key =>$user_data) {
$value = array();
$value = array();
$uid = $user_data['user_id'];
$status = $user_data['status'];
$user_status_in_session = null;
$user_status_in_course = null;
if (api_get_session_id()) {
$user_status_in_session = SessionManager::get_user_status_in_course_session($uid, $current_course_id, $current_session_id);
$user_status_in_session = SessionManager::get_user_status_in_course_session($uid, $current_course_id, $current_session_id);
} else {
$user_status_in_course = CourseManager::get_user_in_course_status($uid, $current_course_id);
}
@ -490,7 +490,7 @@ class Attendance
$attendance_id = intval($attendance_id);
$users = $this->get_users_rel_course();
$course_id = api_get_course_int_id();
$user_ids = array_keys($users);
$users_absent = array_diff($user_ids,$users_present);
$affected_rows = 0;
@ -507,12 +507,12 @@ class Attendance
$uid = intval($user_present);
// check if user already was registered with the $calendar_id
$sql = "SELECT user_id FROM $tbl_attendance_sheet WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'";
$rs = Database::query($sql);
$rs = Database::query($sql);
if (Database::num_rows($rs) == 0) {
$sql = "INSERT INTO $tbl_attendance_sheet SET
c_id = $course_id,
user_id = '$uid',
attendance_calendar_id = '$calendar_id',
$sql = "INSERT INTO $tbl_attendance_sheet SET
c_id = $course_id,
user_id = '$uid',
attendance_calendar_id = '$calendar_id',
presence = 1";
Database::query($sql);
$affected_rows += Database::affected_rows();
@ -531,9 +531,9 @@ class Attendance
$rs = Database::query($sql);
if (Database::num_rows($rs) == 0) {
$sql = "INSERT INTO $tbl_attendance_sheet SET
c_id = $course_id,
user_id ='$uid',
attendance_calendar_id = '$calendar_id',
c_id = $course_id,
user_id ='$uid',
attendance_calendar_id = '$calendar_id',
presence = 0";
Database::query($sql);
$affected_rows += Database::affected_rows();
@ -553,8 +553,8 @@ class Attendance
if ($affected_rows) {
//save attendance sheet log
$lastedit_date = Date('Y-m-d H:i:s');
$lastedit_user_id = api_get_user_id();
$lastedit_date = Date('Y-m-d H:i:s');
$lastedit_user_id = api_get_user_id();
$calendar_date_value = $calendar_data['date_time'];
$save_attendance_log = $this->save_attendance_sheet_log($attendance_id, $lastedit_date, $lastedit_type, $lastedit_user_id, $calendar_date_value);
}
@ -574,7 +574,7 @@ class Attendance
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$course_id = api_get_course_int_id();
$attendance_id = intval($attendance_id);
// fill results about presence of students
$attendance_calendar = $this->get_attendance_calendar($attendance_id);
@ -589,7 +589,7 @@ class Attendance
foreach ($user_ids as $uid) {
$count_presences = 0;
if (count($calendar_ids) > 0) {
$sql = "SELECT count(presence) as count_presences FROM $tbl_attendance_sheet
$sql = "SELECT count(presence) as count_presences FROM $tbl_attendance_sheet
WHERE c_id = $course_id AND user_id = '$uid' AND attendance_calendar_id IN(".implode(',',$calendar_ids).") AND presence = 1";
$rs_count = Database::query($sql);
$row_count = Database::fetch_array($rs_count);
@ -600,16 +600,16 @@ class Attendance
$rs_check_result = Database::query($sql);
if (Database::num_rows($rs_check_result) > 0) {
// update result
$sql = "UPDATE $tbl_attendance_result SET
score='$count_presences'
$sql = "UPDATE $tbl_attendance_result SET
score='$count_presences'
WHERE c_id = $course_id AND user_id='$uid' AND attendance_id='$attendance_id'";
Database::query($sql);
} else {
// insert new result
$sql = "INSERT INTO $tbl_attendance_result SET
c_id = $course_id ,
user_id = '$uid',
attendance_id = '$attendance_id',
c_id = $course_id ,
user_id = '$uid',
attendance_id = '$attendance_id',
score = '$count_presences'";
Database::query($sql);
}
@ -655,7 +655,7 @@ class Attendance
Database::query($ins);
return Database::affected_rows();
return Database::affected_rows();
}
/**
@ -667,8 +667,8 @@ class Attendance
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendance_id = intval($attendance_id);
$course_id = api_get_course_int_id();
$sql = "SELECT count(done_attendance) as count
FROM $tbl_attendance_calendar
$sql = "SELECT count(done_attendance) as count
FROM $tbl_attendance_calendar
WHERE c_id = $course_id AND attendance_id = '$attendance_id' AND done_attendance=1";
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
@ -690,19 +690,19 @@ class Attendance
$attendance_id = intval($attendance_id);
$results = array();
$attendance_data = $this->get_attendance_by_id($attendance_id);
$calendar_count = self::get_number_of_attendance_calendar($attendance_id);
$total_done_attendance = $attendance_data['attendance_qualify_max'];
$attendance_user_score = $this->get_user_score($user_id, $attendance_id);
//This is the main change of the BT#1381
//$total_done_attendance = $calendar_count;
// calculate results
$faults = $total_done_attendance - $attendance_user_score;
$faults = $total_done_attendance - $attendance_user_score;
$faults = $faults > 0 ? $faults:0;
$faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
$results['faults'] = $faults;
@ -802,7 +802,7 @@ class Attendance
$results['faults'] = $total_faults;
$results['total'] = $total_weight;
$results['porcent'] = $porcent;
return $results;
return $results;
}
/**
@ -811,7 +811,7 @@ class Attendance
* @param int user id for showing data for only one user (optional)
* @return array users attendance sheet data
*/
public function get_users_attendance_sheet($attendance_id, $user_id = 0) {
public function get_users_attendance_sheet($attendance_id, $user_id = 0) {
$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
@ -821,7 +821,7 @@ class Attendance
foreach ($attendance_calendar as $cal) {
$calendar_ids[] = $cal['id'];
}
$course_id = api_get_course_int_id();
$data = array();
@ -831,8 +831,8 @@ class Attendance
$user_ids = array_keys($users);
if (count($calendar_ids) > 0 && count($user_ids) > 0) {
foreach ($user_ids as $uid) {
$sql = "SELECT * FROM $tbl_attendance_sheet
WHERE c_id = $course_id AND user_id = '$uid' AND attendance_calendar_id IN(".implode(',',$calendar_ids).") ";
$sql = "SELECT * FROM $tbl_attendance_sheet
WHERE c_id = $course_id AND user_id = '$uid' AND attendance_calendar_id IN(".implode(',',$calendar_ids).") ";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
while ($row = Database::fetch_array($res)) {
@ -845,14 +845,14 @@ class Attendance
// Get attendance for current user
$user_id = intval($user_id);
if (count($calendar_ids) > 0) {
$sql = "SELECT cal.date_time, att.presence
FROM $tbl_attendance_sheet att
INNER JOIN $tbl_attendance_calendar cal
ON cal.id = att.attendance_calendar_id
$sql = "SELECT cal.date_time, att.presence
FROM $tbl_attendance_sheet att
INNER JOIN $tbl_attendance_calendar cal
ON cal.id = att.attendance_calendar_id
WHERE att.c_id = $course_id AND
cal.c_id = $course_id AND
att.user_id = '$user_id' AND
att.attendance_calendar_id IN(".implode(',',$calendar_ids).")
att.user_id = '$user_id' AND
att.attendance_calendar_id IN(".implode(',',$calendar_ids).")
ORDER BY date_time";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
@ -875,8 +875,8 @@ class Attendance
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendance_id = intval($attendance_id);
$course_id = api_get_course_int_id();
$sql = "SELECT id FROM $tbl_attendance_calendar
$sql = "SELECT id FROM $tbl_attendance_calendar
WHERE c_id = $course_id AND attendance_id = '$attendance_id' AND done_attendance = 0 ORDER BY date_time limit 1";
$rs = Database::query($sql);
$next_calendar_id = 0;
@ -946,8 +946,8 @@ class Attendance
}
}
return $data;
}
}
/**
* Get all attendance calendar data inside current attendance
* @param int attendance id
@ -956,34 +956,34 @@ class Attendance
public function get_attendance_calendar($attendance_id, $type = 'all', $calendar_id = null) {
global $dateFormatShort, $timeNoSecFormat;
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendance_id = intval($attendance_id);
$attendance_id = intval($attendance_id);
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM $tbl_attendance_calendar WHERE c_id = $course_id AND attendance_id = '$attendance_id' ";
$sql = "SELECT * FROM $tbl_attendance_calendar WHERE c_id = $course_id AND attendance_id = '$attendance_id' ";
if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) {
$type = 'all';
}
}
switch ($type) {
case 'calendar_id':
$calendar_id = intval($calendar_id);
$calendar_id = intval($calendar_id);
if (!empty($calendar_id)) {
$sql.= " AND id = $calendar_id";
}
break;
case 'today':
//$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )';
break;
break;
case 'all_done':
$sql .= " AND done_attendance = 1 ";
break;
case 'all_not_done':
$sql .= " AND done_attendance = 0 ";
break;
case 'all':
default:
break;
}
$sql .= " ORDER BY date_time ";
case 'all':
default:
break;
}
$sql .= " ORDER BY date_time ";
$rs = Database::query($sql);
$data = array();
if (Database::num_rows($rs) > 0) {
@ -991,10 +991,10 @@ class Attendance
$row['db_date_time'] = $row['date_time'];
$row['date_time'] = api_get_local_time($row['date_time']);
$row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT);
$row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT);
if ($type == 'today') {
$row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT);
if ($type == 'today') {
if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) {
$data[] = $row;
$data[] = $row;
}
} else {
$data[] = $row;
@ -1003,7 +1003,7 @@ class Attendance
}
return $data;
}
/**
* Get number of attendance calendar inside current attendance
@ -1014,7 +1014,7 @@ class Attendance
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendance_id = intval($attendance_id);
$course_id = api_get_course_int_id();
$sql = "SELECT count(id) FROM $tbl_attendance_calendar
$sql = "SELECT count(id) FROM $tbl_attendance_calendar
WHERE c_id = $course_id AND attendance_id = '$attendance_id'";
$rs = Database::query($sql);
$row = Database::fetch_row($rs);
@ -1031,7 +1031,7 @@ class Attendance
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendance_id = intval($attendance_id);
$course_id = api_get_course_int_id();
$sql = "SELECT count(id) FROM $tbl_attendance_calendar
$sql = "SELECT count(id) FROM $tbl_attendance_calendar
WHERE c_id = $course_id AND attendance_id = '$attendance_id'";
$rs = Database::query($sql);
$count = 0;
@ -1068,9 +1068,9 @@ class Attendance
*/
public static function is_locked_attendance($attendance_id) {
//use gradebook lock
$result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE);
return $result;
}
$result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE);
return $result;
}
/**
* Add new datetime inside attendance calendar table
@ -1083,13 +1083,13 @@ class Attendance
$attendance_id = intval($attendance_id);
$course_id = api_get_course_int_id();
// check if datetime already exists inside the table
$sql = "SELECT id FROM $tbl_attendance_calendar
$sql = "SELECT id FROM $tbl_attendance_calendar
WHERE c_id = $course_id AND date_time='".Database::escape_string($this->date_time)."' AND attendance_id = '$attendance_id'";
$rs = Database::query($sql);
if (Database::num_rows($rs) == 0) {
$sql = "INSERT INTO $tbl_attendance_calendar SET
c_id = $course_id,
date_time = '".Database::escape_string($this->date_time)."',
c_id = $course_id,
date_time = '".Database::escape_string($this->date_time)."',
attendance_id = '$attendance_id'";
Database::query($sql);
$affected_rows = Database::affected_rows();
@ -1127,7 +1127,7 @@ class Attendance
case 'daily':
$j = 1;
for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) {
//$datetimezone = api_get_utc_date_add(api_get_utc_datetime($start_date), 0 , 0, $j); //to support europe timezones
//$datetimezone = api_get_utc_date_add(api_get_utc_datetime($start_date), 0 , 0, $j); //to support europe timezones
$datetimezone = api_get_utc_datetime($i);
$this->set_date_time($datetimezone);
$res = $this->attendance_calendar_add($attendance_id);
@ -1137,7 +1137,7 @@ class Attendance
exit;
case 'weekly':
$j = 1;
for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) {
for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) {
$datetimezone = api_get_utc_datetime($i);
//$datetimezone = api_get_utc_date_add(api_get_utc_datetime($start_date), 0 , 0, $j*7); //to support europe timezones
$this->set_date_time($datetimezone);
@ -1148,13 +1148,13 @@ class Attendance
case 'monthlyByDate':
$j = 1;
//@todo fix bug with february
for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) {
for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) {
$datetimezone = api_get_utc_datetime($i);
//$datetimezone = api_get_utc_date_add(api_get_utc_datetime($start_date), 0 , $j); //to support europe timezones
$this->set_date_time($datetimezone);
$res = $this->attendance_calendar_add($attendance_id);
$j++;
}
}
break;
}
}
@ -1167,8 +1167,8 @@ class Attendance
*/
private function add_month($timestamp, $num=1) {
$values = api_get_utc_datetime($timestamp);
$values = str_replace(array(':','-',' '), '/', $values);
list($y, $m, $d, $h, $n, $s) = split('/',$values);
$values = str_replace(array(':','-',' '), '/', $values);
list($y, $m, $d, $h, $n, $s) = split('/',$values);
if($m+$num>12) {
$y += floor($num/12);
$m += $num%12;
@ -1176,8 +1176,8 @@ class Attendance
$m += $num;
}
//date_default_timezone_set('UTC');
// return mktime($h, $n, $s, $m, $d, $y);
$result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC');
// return mktime($h, $n, $s, $m, $d, $y);
$result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC');
if (!empty($result)) {
return $result;
}
@ -1196,7 +1196,7 @@ class Attendance
$attendance_id = intval($attendance_id);
$course_id = api_get_course_int_id();
// check if datetime already exists inside the table
$sql = "SELECT id FROM $tbl_attendance_calendar
$sql = "SELECT id FROM $tbl_attendance_calendar
WHERE c_id = $course_id AND date_time = '".Database::escape_string($this->date_time)."' AND attendance_id = '$attendance_id'";
$rs = Database::query($sql);
if (Database::num_rows($rs) == 0) {
@ -1212,7 +1212,7 @@ class Attendance
} else {
$unlock = self::lock_attendance($attendance_id);
}
return $affected_rows;
}
@ -1258,7 +1258,7 @@ class Attendance
$affected_rows = Database::affected_rows();
// update users' results
$this->update_users_results($user_ids, $attendance_id);
$this->update_users_results($user_ids, $attendance_id);
return $affected_rows;
}
@ -1269,23 +1269,7 @@ class Attendance
* @return string date and time e.g: '2010-02-10 12:30:00'
*/
public function build_datetime_from_array($array) {
$year = '0000';
$month = $day = $hours = $minutes = $seconds = '00';
if (isset($array['Y']) && (isset($array['F']) || isset($array['M'])) && isset($array['d']) && isset($array['H']) && isset($array['i'])) {
$year = $array['Y'];
$month = isset($array['F'])?$array['F']:$array['M'];
if (intval($month) < 10 ) $month = '0'.$month;
$day = $array['d'];
if (intval($day) < 10 ) $day = '0'.$day;
$hours = $array['H'];
if (intval($hours) < 10 ) $hours = '0'.$hours;
$minutes = $array['i'];
if (intval($minutes) < 10 ) $minutes = '0'.$minutes;
}
if (checkdate($month,$day,$year)) {
$datetime = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.':'.$seconds;
}
return $datetime;
return return_datetime_from_array($array);
}
/** Setters for fields of attendances tables **/

@ -576,17 +576,17 @@ function cut($text, $maxchar, $embed = false) {
* @return mixed An integer or a float depends on the parameter
*/
function float_format($number, $flag = 1) {
if (is_numeric($number)) {
if (is_numeric($number)) {
if (!$number) {
$result = ($flag == 2 ? '0.'.str_repeat('0', EXERCISE_NUMBER_OF_DECIMALS) : '0');
} else {
if (floor($number) == $number) {
$result = number_format($number, ($flag == 2 ? EXERCISE_NUMBER_OF_DECIMALS : 0));
} else {
$result = number_format(round($number, 2), ($flag == 0 ? 0 : EXERCISE_NUMBER_OF_DECIMALS));
}
}
}
return $result;
}
}
@ -673,12 +673,12 @@ function _text_parse_texexplorer($textext) {
}
/**
* This function splits the string into words and then joins them back together again one by one.
* Example: "Test example of a long string"
* substrwords(5) = Test ... *
* @param string
* This function splits the string into words and then joins them back together again one by one.
* Example: "Test example of a long string"
* substrwords(5) = Test ... *
* @param string
* @param int the max number of character
* @param string how the string will be end
* @param string how the string will be end
* @return a reduce string
*/
@ -711,7 +711,7 @@ function substrwords($text,$maxchar,$end='...')
return $output.$end;
}
function implode_with_key($glue, $array) {
function implode_with_key($glue, $array) {
if (!empty($array)) {
$string = '';
foreach($array as $key => $value) {
@ -722,7 +722,7 @@ function implode_with_key($glue, $array) {
}
return $string;
}
return '';
return '';
}
@ -744,4 +744,26 @@ function format_file_size($file_size) {
$file_size = $file_size . 'B';
}
return $file_size;
}
function return_datetime_from_array($array) {
$year = '0000';
$month = $day = $hours = $minutes = $seconds = '00';
var_dump($array);
if (isset($array['Y']) && (isset($array['F']) || isset($array['M'])) && isset($array['d']) && isset($array['H']) && isset($array['i'])) {
$year = $array['Y'];
$month = isset($array['F'])?$array['F']:$array['M'];
if (intval($month) < 10 ) $month = '0'.$month;
$day = $array['d'];
if (intval($day) < 10 ) $day = '0'.$day;
$hours = $array['H'];
if (intval($hours) < 10 ) $hours = '0'.$hours;
$minutes = $array['i'];
if (intval($minutes) < 10 ) $minutes = '0'.$minutes;
}
if (checkdate($month,$day,$year)) {
$datetime = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.':'.$seconds;
}
return $datetime;
}

@ -5,11 +5,11 @@
* This file contains class used like library, provides functions for thematic option inside attendance tool. It's also used like model to thematic_controller (MVC pattern)
* Thematic class can be used to instanciate objects or as a library for thematic control
* @author Christian Fasanando <christian1827@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> SQL fixes
* @author Julio Montoya <gugli100@gmail.com> SQL fixes
* @package chamilo.course_progress
*/
class Thematic
{
{
private $session_id;
private $thematic_id;
private $thematic_title;
@ -17,7 +17,7 @@ class Thematic
private $thematic_plan_id;
private $thematic_plan_title;
private $thematic_plan_description;
private $thematic_plan_description_type;
private $thematic_plan_description_type;
private $thematic_advance_id;
private $attendance_id;
private $thematic_advance_content;
@ -27,8 +27,8 @@ class Thematic
public function __construct() {
$this->course_int_id = api_get_course_int_id();
}
}
/**
* Get the total number of thematic inside current course and current session
* @see SortableTable#get_total_number_of_items()
@ -41,7 +41,7 @@ class Thematic
}
$course_id = api_get_course_int_id();
$sql = "SELECT COUNT(id) AS total_number_of_items FROM $tbl_thematic WHERE c_id = $course_id AND active = 1 $condition_session ";
$res = Database::query($sql);
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->total_number_of_items;
}
@ -57,24 +57,24 @@ class Thematic
public function get_thematic_data($from, $number_of_items, $column, $direction) {
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$condition_session = '';
if (!api_get_session_id()) {
if (!api_get_session_id()) {
$condition_session = api_get_session_condition(0);
}
}
$column = intval($column);
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'ASC';
}
$course_id = api_get_course_int_id();
$sql = "SELECT id AS col0, title AS col1, display_order AS col2, session_id FROM $tbl_thematic
WHERE c_id = $course_id AND active = 1 $condition_session
ORDER BY col2 LIMIT $from,$number_of_items ";
$res = Database::query($sql);
$thematics = array ();
$param_gradebook = '';
@ -82,34 +82,34 @@ class Thematic
$param_gradebook = '&gradebook='.$_SESSION['gradebook'];
}
$user_info = api_get_user_info(api_get_user_id());
while ($thematic = Database::fetch_row($res)) {
$session_star = '';
if (api_get_session_id() == $thematic[3]) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
}
$thematic[1] = '<a href="index.php?'.api_get_cidreq().'&action=thematic_details&thematic_id='.$thematic[0].$param_gradebook.'">'.Security::remove_XSS($thematic[1], STUDENT).$session_star.'</a>';
}
$thematic[1] = '<a href="index.php?'.api_get_cidreq().'&action=thematic_details&thematic_id='.$thematic[0].$param_gradebook.'">'.Security::remove_XSS($thematic[1], STUDENT).$session_star.'</a>';
if (api_is_allowed_to_edit(null, true)) {
$actions = '';
if (api_get_session_id()) {
if (api_get_session_id()) {
if (api_get_session_id() == $thematic[3]) {
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('lesson_plan.png',get_lang('ThematicPlan'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('lesson_plan_calendar.png',get_lang('ThematicAdvance'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a>';
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a>';
} else {
$actions .= Display::return_icon('lesson_plan_na.png',get_lang('ThematicPlan'),'',22).'&nbsp;';
$actions .= Display::return_icon('lesson_plan_calendar_na.png',get_lang('ThematicAdvance'),'',22).'&nbsp;';
$actions .= Display::return_icon('edit_na.png',get_lang('Edit'),'',22);
$actions .= Display::return_icon('delete_na.png',get_lang('Delete'),'',22).'&nbsp;';
$actions .= Display::url(Display::return_icon('cd.gif', get_lang('Copy')), 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$thematic[0].$param_gradebook);
}
} else {
$actions .= Display::url(Display::return_icon('cd.gif', get_lang('Copy')), 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$thematic[0].$param_gradebook);
}
} else {
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('lesson_plan.png',get_lang('ThematicPlan'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('lesson_plan_calendar.png',get_lang('ThematicAdvance'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
if ($thematic[2] > 1) {
$actions .= '<a href="'.api_get_self().'?action=moveup&'.api_get_cidreq().'&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('up.png', get_lang('Up'),'',22).'</a>';
} else {
@ -121,7 +121,7 @@ class Thematic
$actions .= Display::return_icon('down_na.png','&nbsp;','',22);
}
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a>';
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a>';
}
$thematics[] = array($thematic[0], $thematic[1], $actions);
}
@ -141,10 +141,10 @@ class Thematic
$condition_session = api_get_session_condition($session_id);
} else {
$condition_session = '';
}
}
$course_id = api_get_course_int_id();
$sql = "SELECT MAX(display_order) FROM $tbl_thematic WHERE c_id = $course_id AND active = 1 $condition_session";
$rs = Database::query($sql);
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
return $row[0];
}
@ -218,9 +218,9 @@ class Thematic
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
if (isset($session_id)) {
$session_id = intval($session_id);
$session_id = intval($session_id);
} else {
$session_id = api_get_session_id();
}
@ -238,7 +238,7 @@ class Thematic
$condition = " WHERE active = 1 $condition_session ";
}
$sql = "SELECT * FROM $tbl_thematic $condition AND c_id = $course_id ORDER BY display_order ";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
if (!empty($thematic_id)) {
@ -270,10 +270,10 @@ class Thematic
// get the maximum display order of all the glossary items
$max_thematic_item = $this->get_max_thematic_item(false);
if (empty($id)) {
// insert
$sql = "INSERT INTO $tbl_thematic (c_id, title, content, active, display_order, session_id)
$sql = "INSERT INTO $tbl_thematic (c_id, title, content, active, display_order, session_id)
VALUES ($this->course_int_id, '$title', '$content', 1, ".(intval($max_thematic_item)+1).", $session_id) ";
Database::query($sql);
$last_id = Database::insert_id();
@ -306,7 +306,7 @@ class Thematic
$affected_rows = 0;
$user_id = api_get_user_id();
$course_id = api_get_course_int_id();
if (is_array($thematic_id)) {
foreach ($thematic_id as $id) {
$id = intval($id);
@ -332,31 +332,31 @@ class Thematic
}
return $affected_rows;
}
public function copy($thematic_id) {
$thematic = self::get_thematic_list($thematic_id, api_get_course_id(), 0);
$thematic = self::get_thematic_list($thematic_id, api_get_course_id(), 0);
$thematic_copy = new Thematic();
$thematic_copy->set_thematic_attributes('', $thematic['title'].' - '.get_lang('Copy'), $thematic['content'], api_get_session_id());
$new_thematic_id = $thematic_copy->thematic_save();
if (!empty($new_thematic_id)) {
$thematic_advanced = self::get_thematic_advance_by_thematic_id($thematic_id);
if(!empty($thematic_advanced)) {
foreach($thematic_advanced as $item) {
$thematic = new Thematic();
$thematic->set_thematic_advance_attributes(0, $new_thematic_id, 0, $item['content'], $item['start_date'], $item['duration']);
$thematic->thematic_advance_save();
foreach($thematic_advanced as $item) {
$thematic = new Thematic();
$thematic->set_thematic_advance_attributes(0, $new_thematic_id, 0, $item['content'], $item['start_date'], $item['duration']);
$thematic->thematic_advance_save();
}
}
$thematic_plan = self::get_thematic_plan_data($thematic_id);
$thematic_plan = self::get_thematic_plan_data($thematic_id);
if (!empty($thematic_plan)) {
foreach ($thematic_plan as $item) {
$thematic = new Thematic();
$thematic->set_thematic_plan_attributes($new_thematic_id, $item['title'], $item['description'], $item['description_type']);
$thematic->thematic_plan_save();
foreach ($thematic_plan as $item) {
$thematic = new Thematic();
$thematic->set_thematic_plan_attributes($new_thematic_id, $item['title'], $item['description'], $item['description_type']);
$thematic->thematic_plan_save();
}
}
}
}
}
/**
@ -367,7 +367,7 @@ class Thematic
global $thematic_id;
$tbl_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
$course_id = api_get_course_int_id();
$sql = "SELECT COUNT(id) AS total_number_of_items FROM $tbl_thematic_advance WHERE c_id = $course_id AND thematic_id = $thematic_id ";
$res = Database::query($sql);
$res = Database::query($sql);
@ -395,33 +395,33 @@ class Thematic
$direction = 'ASC';
}
$data = array();
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
if (api_is_allowed_to_edit(null, true)) {
$sql = "SELECT id AS col0, start_date AS col1, duration AS col2, content AS col3 FROM $tbl_thematic_advance
WHERE c_id = $course_id AND thematic_id = $thematic_id
ORDER BY col$column $direction LIMIT $from,$number_of_items ";
$list = api_get_item_property_by_tool('thematic_advance', api_get_course_id(), api_get_session_id());
$elements = array();
foreach ($list as $value) {
$elements[] = $value['ref'];
}
$res = Database::query($sql);
}
$res = Database::query($sql);
$i = 1;
while ($thematic_advance = Database::fetch_row($res)) {
if(in_array($thematic_advance[0], $elements)) {
$thematic_advance[1] = api_get_local_time($thematic_advance[1]);
$thematic_advance[1] = api_format_date($thematic_advance[1], DATE_TIME_FORMAT_LONG);
$thematic_advance[1] = api_format_date($thematic_advance[1], DATE_TIME_FORMAT_LONG);
$actions = '';
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_edit&thematic_id='.$thematic_id.'&thematic_advance_id='.$thematic_advance[0].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_advance_delete&thematic_id='.$thematic_id.'&thematic_advance_id='.$thematic_advance[0].'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a></center>';
$data[] = array($i, $thematic_advance[1], $thematic_advance[2], $thematic_advance[3], $actions);
$data[] = array($i, $thematic_advance[1], $thematic_advance[2], $thematic_advance[3], $actions);
$i++;
}
}
@ -436,23 +436,23 @@ class Thematic
* @return array data
*/
public function get_thematic_advance_by_thematic_id($thematic_id, $course_code = null) {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
// set current course
$tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$thematic_id = intval($thematic_id);
$data = array();
$data = array();
$sql = "SELECT * FROM $tbl_thematic_advance WHERE c_id = $course_id AND thematic_id = $thematic_id ";
$elements = array();
$list = api_get_item_property_by_tool('thematic_advance', $course_info['code'], api_get_session_id());
foreach($list as $value) {
$elements[] = $value['ref'];
}
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
while ($row = Database::fetch_array($res, 'ASSOC')) {
@ -463,15 +463,15 @@ class Thematic
}
return $data;
}
public function get_thematic_advance_div($data) {
public function get_thematic_advance_div($data) {
$return_array = array();
$uinfo = api_get_user_info();
foreach ($data as $thematic_id => $thematic_advance_data) {
foreach ($thematic_advance_data as $key => $thematic_advance) {
$session_star = '';
if (api_is_allowed_to_edit(null, true)) {
if ($thematic_advance['session_id'] !=0) {
@ -485,41 +485,41 @@ class Thematic
$thematic_advance_item .= '<div>'.Security::remove_XSS($thematic_advance['content'], STUDENT).'</div>';
$return_array[$thematic_id][$thematic_advance['id']] = $thematic_advance_item;
}
}
}
return $return_array;
}
public function get_thematic_plan_div($data) {
$final_return = array();
$uinfo = api_get_user_info();
foreach ($data as $thematic_id => $thematic_plan_data) {
$new_thematic_plan_data = array();
foreach($thematic_plan_data as $thematic_item) {
$thematic_simple_list[] = $thematic_item['description_type'];
$new_thematic_plan_data[$thematic_item['description_type']] = $thematic_item;
}
$new_id = ADD_THEMATIC_PLAN;
}
$new_id = ADD_THEMATIC_PLAN;
if (!empty($thematic_simple_list)) {
foreach($thematic_simple_list as $item) {
foreach($thematic_simple_list as $item) {
//if ($item >= ADD_THEMATIC_PLAN) {
//$new_id = $item + 1;
$default_thematic_plan_title[$item] = $new_thematic_plan_data[$item]['title'];
//}
}
}
$no_data = true;
$session_star = '';
$session_star = '';
$return = '<div id="thematic_plan_'.$thematic_id.'">';
if (!empty($default_thematic_plan_title)) {
foreach ($default_thematic_plan_title as $id=>$title) {
$thematic_plan_data_item = '';
//avoid others
if ($title == 'Others' && empty($data[$thematic_id][$id]['description'])) {
continue;
}
continue;
}
if (!empty($data[$thematic_id][$id]['title']) && !empty($data[$thematic_id][$id]['description'])) {
if (api_is_allowed_to_edit(null, true)) {
if ($data[$thematic_id][$id]['session_id'] !=0) {
@ -531,7 +531,7 @@ class Thematic
$no_data = false;
}
}
}
}
if ($no_data) {
$return .= '<div><em>'.get_lang('StillDoNotHaveAThematicPlan').'</em></div>';
}
@ -540,7 +540,7 @@ class Thematic
}
return $final_return;
}
/**
* get thematic advance list
* @param int Thematic advance id (optional), get data by thematic advance list
@ -549,10 +549,10 @@ class Thematic
*/
public function get_thematic_advance_list($thematic_advance_id = null, $course_code = null, $force_session_id = false) { // set current course
$course_info = api_get_course_info($course_code);
$tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
$data = array();
$condition = '';
@ -560,47 +560,47 @@ class Thematic
$thematic_advance_id = intval($thematic_advance_id);
$condition = " AND a.id = $thematic_advance_id ";
}
$course_id = $course_info['real_id'];
/*if ($force_session_id) {
$sql = "SELECT a.* FROM $tbl_thematic_advance a INNER JOIN $tbl_thematic t ON t.id = a.thematic_id WHERE 1 $condition AND t.session_id = ".api_get_session_id()." ORDER BY start_date ";
} else {
} else {
$sql = "SELECT * FROM $tbl_thematic_advance a WHERE 1 $condition ORDER BY start_date ";
}*/
$sql = "SELECT * FROM $tbl_thematic_advance a WHERE c_id = $course_id $condition ORDER BY start_date ";
$elements = array();
if ($force_session_id) {
if ($force_session_id) {
$list = api_get_item_property_by_tool('thematic_advance', $course_info['code'], api_get_session_id());
foreach($list as $value) {
$elements[$value['ref']]= $value;
$elements[$value['ref']]= $value;
}
}
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
if (!empty($thematic_advance_id)) {
if (Database::num_rows($res) > 0) {
if (!empty($thematic_advance_id)) {
$data = Database::fetch_array($res);
} else {
// group all data group by thematic id
$tmp = array();
while ($row = Database::fetch_array($res, 'ASSOC')) {
while ($row = Database::fetch_array($res, 'ASSOC')) {
$tmp[] = $row['thematic_id'];
if (in_array($row['thematic_id'], $tmp)) {
if ($force_session_id) {
if (in_array($row['id'], array_keys($elements))) {
$row['session_id'] = $elements[$row['id']]['id_session'];
$data[$row['thematic_id']][$row['id']] = $row;
$data[$row['thematic_id']][$row['id']] = $row;
}
} else {
$data[$row['thematic_id']][$row['id']] = $row;
}
}
}
}
}
@ -627,9 +627,9 @@ class Thematic
$duration = intval($this->duration);
$user_id = api_get_user_id();
if (empty($id)) {
if (empty($id)) {
// Insert
$sql = "INSERT INTO $tbl_thematic_advance (c_id, thematic_id, attendance_id, content, start_date, duration)
$sql = "INSERT INTO $tbl_thematic_advance (c_id, thematic_id, attendance_id, content, start_date, duration)
VALUES ($this->course_int_id, $tematic_id, $attendance_id, '$content', '".api_get_utc_datetime($start_date)."', '$duration') ";
Database::query($sql);
$last_id = Database::insert_id();
@ -638,9 +638,9 @@ class Thematic
}
} else {
// update
$sql = "UPDATE $tbl_thematic_advance SET thematic_id = '$tematic_id', attendance_id = '$attendance_id', content = '$content', start_date = '".api_get_utc_datetime($start_date)."', duration = '$duration'
$sql = "UPDATE $tbl_thematic_advance SET thematic_id = '$tematic_id', attendance_id = '$attendance_id', content = '$content', start_date = '".api_get_utc_datetime($start_date)."', duration = '$duration'
WHERE c_id = {$this->course_int_id} AND id = $id ";
Database::query($sql);
Database::query($sql);
if (Database::affected_rows()) {
api_item_property_update($_course, 'thematic_advance', $id, "ThematicAdvanceUpdated", $user_id);
}
@ -685,9 +685,9 @@ class Thematic
// definition database table
$tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
$course_id = api_get_course_int_id();
$data = array();
$condition = '';
if (isset($thematic_id)) {
@ -698,53 +698,53 @@ class Thematic
$description_type = intval($description_type);
$condition .= " AND description_type = $description_type ";
}
$items_from_course = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), 0);
$items_from_course = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), 0);
$items_from_session = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
$thematic_plan_complete_list = array();
$thematic_plan_id_list = array();
if (!empty($items_from_course)) {
foreach($items_from_course as $item) {
foreach($items_from_course as $item) {
$thematic_plan_id_list[] = $item['ref'];
$thematic_plan_complete_list[$item['ref']] = $item;
}
}
if (!empty($items_from_session)) {
foreach($items_from_session as $item) {
foreach($items_from_session as $item) {
$thematic_plan_id_list[] = $item['ref'];
$thematic_plan_complete_list[$item['ref']] = $item;
}
}
if (!empty($thematic_plan_id_list)) {
if (!empty($thematic_plan_id_list)) {
$sql = "SELECT tp.id, thematic_id, tp.title, description, description_type, t.session_id
FROM $tbl_thematic_plan tp INNER JOIN $tbl_thematic t ON (t.id=tp.thematic_id)
FROM $tbl_thematic_plan tp INNER JOIN $tbl_thematic t ON (t.id=tp.thematic_id)
WHERE t.c_id = $course_id AND tp.c_id = $course_id $condition AND tp.id IN (".implode(', ', $thematic_plan_id_list).") ";
$rs = Database::query($sql);
if (Database::num_rows($rs)) {
if (!isset($thematic_id) && !isset($description_type)) {
if (!isset($thematic_id) && !isset($description_type)) {
// group all data group by thematic id
$tmp = array();
while ($row = Database::fetch_array($rs,'ASSOC')) {
$tmp = array();
while ($row = Database::fetch_array($rs,'ASSOC')) {
$tmp[] = $row['thematic_id'];
if (in_array($row['thematic_id'], $tmp)) {
$row['session_id'] = $thematic_plan_complete_list[$row['id']];
if (in_array($row['thematic_id'], $tmp)) {
$row['session_id'] = $thematic_plan_complete_list[$row['id']];
$data[$row['thematic_id']][$row['description_type']] = $row;
}
}
} else {
}
}
} else {
while ($row = Database::fetch_array($rs,'ASSOC')) {
$row['session_id'] = $thematic_plan_complete_list[$row['id']];
$row['session_id'] = $thematic_plan_complete_list[$row['id']];
$data[] = $row;
}
}
}
}
}
}
}
return $data;
}
@ -754,19 +754,19 @@ class Thematic
*/
public function thematic_plan_save() {
global $_course;
// definition database table
// definition database table
$tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
// protect data
$thematic_id = intval($this->thematic_id);
$title = Database::escape_string($this->thematic_plan_title);
$description = Database::escape_string($this->thematic_plan_description);
$description_type = intval($this->thematic_plan_description_type);
$user_id = api_get_user_id();
$description_type = intval($this->thematic_plan_description_type);
$user_id = api_get_user_id();
$course_id = api_get_course_int_id();
$list = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
$elements_to_show = array();
foreach($list as $value) {
$elements_to_show[]= $value['ref'];
@ -776,23 +776,23 @@ class Thematic
$condition = "AND id IN (".implode(',', $elements_to_show).") ";
}
// check thematic plan type already exists
$sql = "SELECT id FROM $tbl_thematic_plan WHERE c_id = $course_id AND thematic_id = $thematic_id AND description_type = '$description_type'";
$sql = "SELECT id FROM $tbl_thematic_plan WHERE c_id = $course_id AND thematic_id = $thematic_id AND description_type = '$description_type'";
$rs = Database::query($sql);
$affected_rows = 0;
if (Database::num_rows($rs) > 0) {
//if (!empty($thematic_plan_data)) {
$row_thematic_plan = Database::fetch_array($rs);
$thematic_plan_id = $row_thematic_plan['id'];
//Checking the session
$thematic_plan_data = api_get_item_property_info(api_get_course_int_id(), 'thematic_plan', $thematic_plan_id);
$update = false;
$update = false;
if (in_array($thematic_plan_id, $elements_to_show)) {
$update = true;
}
}
if ($update) {
// update
$upd = "UPDATE $tbl_thematic_plan SET title = '$title', description = '$description' WHERE c_id = $course_id AND id = $thematic_plan_id";
@ -800,22 +800,22 @@ class Thematic
$affected_rows = Database::affected_rows();
if ($affected_rows) {
api_item_property_update($_course, 'thematic_plan', $thematic_plan_id, "ThematicPlanUpdated", $user_id);
}
} else {
}
} else {
// insert
$ins = "INSERT INTO $tbl_thematic_plan (c_id, thematic_id, title, description, description_type)
VALUES ($this->course_int_id, $thematic_id, '$title', '$description', $description_type) ";
$ins = "INSERT INTO $tbl_thematic_plan (c_id, thematic_id, title, description, description_type)
VALUES ($this->course_int_id, $thematic_id, '$title', '$description', $description_type) ";
Database::query($ins);
$last_id = Database::insert_id();
$affected_rows = Database::affected_rows();
if ($affected_rows) {
api_item_property_update($_course, 'thematic_plan', $last_id,"ThematicPlanAdded", $user_id);
}
}
} else {
}
}
} else {
// insert
$ins = "INSERT INTO $tbl_thematic_plan (c_id, thematic_id, title, description, description_type)
VALUES($this->course_int_id, $thematic_id, '$title', '$description', $description_type) ";
$ins = "INSERT INTO $tbl_thematic_plan (c_id, thematic_id, title, description, description_type)
VALUES($this->course_int_id, $thematic_id, '$title', '$description', $description_type) ";
Database::query($ins);
$last_id = Database::insert_id();
$affected_rows = Database::affected_rows();
@ -841,7 +841,7 @@ class Thematic
$thematic_id = intval($thematic_id);
$description_type = intval($description_type);
$user_id = api_get_user_id();
$course_id = $course_info['real_id'];
$course_id = $course_info['real_id'];
// get thematic plan id
$thematic_plan_data = $this->get_thematic_plan_data($thematic_id, $description_type);
@ -871,10 +871,10 @@ class Thematic
$thematic_id = intval($thematic_id);
$description_type = intval($description_type);
$next_description_type = 0;
$course_id = api_get_course_int_id();
$sql = "SELECT MAX(description_type) as max FROM $tbl_thematic_plan
$sql = "SELECT MAX(description_type) as max FROM $tbl_thematic_plan
WHERE c_id = $course_id AND thematic_id = $thematic_id AND description_type >= ".ADD_THEMATIC_PLAN." ";
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
@ -903,8 +903,8 @@ class Thematic
$affected_rows = 0;
$user_id = api_get_user_id();
$all = array();
$all = array();
if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) {
$thematic_id = $thematic['id'];
@ -914,29 +914,29 @@ class Thematic
}
}
}
}
$error = null;
}
$error = null;
$a_thematic_advance_ids = array();
$course_id = api_get_course_int_id();
if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) {
$my_affected_rows = 0;
$thematic_id = $thematic['id'];
if (!empty($thematic_advance_data[$thematic['id']])) {
foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
$item_info = api_get_item_property_info(api_get_course_int_id(), 'thematic_advance', $thematic_advance['id']);
if ($item_info['id_session'] == api_get_session_id()) {
$a_thematic_advance_ids[] = $thematic_advance['id'];
// update done thematic for previous advances ((done_advance = 1))
$upd = "UPDATE $tbl_thematic_advance SET done_advance = 1 WHERE c_id = $course_id AND id = ".$thematic_advance['id']." ";
Database::query($upd);
$my_affected_rows = Database::affected_rows();
$my_affected_rows = Database::affected_rows();
$affected_rows += $my_affected_rows;
//if ($my_affected_rows) {
api_item_property_update($_course, 'thematic_advance', $thematic_advance['id'], "ThematicAdvanceDone", $user_id);
@ -949,22 +949,22 @@ class Thematic
}
}
}
// Update done thematic for others advances (done_advance = 0)
if (!empty($a_thematic_advance_ids) && count($a_thematic_advance_ids) > 0) {
$diff = array_diff($all, $a_thematic_advance_ids);
if (!empty($diff)) {
$diff = array_diff($all, $a_thematic_advance_ids);
if (!empty($diff)) {
$upd = "UPDATE $tbl_thematic_advance SET done_advance = 0 WHERE c_id = $course_id AND id IN(".implode(',',$diff).") ";
Database::query($upd);
}
// update item_property
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$session_id = api_get_session_id();
// get all thematic advance done
$rs_thematic_done = Database::query("SELECT ref FROM $tbl_item_property
$rs_thematic_done = Database::query("SELECT ref FROM $tbl_item_property
WHERE c_id = $course_id AND tool='thematic_advance' AND lastedit_type='ThematicAdvanceDone' AND id_session = $session_id ");
if (Database::num_rows($rs_thematic_done) > 0) {
while ($row_thematic_done = Database::fetch_array($rs_thematic_done)) {
@ -975,7 +975,7 @@ class Thematic
}
}
}
return $affected_rows;
return $affected_rows;
}
/**
@ -983,10 +983,10 @@ class Thematic
* @return int Last done thematic advance id
*/
public function get_last_done_thematic_advance() {
$thematic_data = $this->get_thematic_list();
$thematic_data = $this->get_thematic_list();
$thematic_advance_data = $this->get_thematic_advance_list(null, api_get_course_id(), true);
$a_thematic_advance_ids = array();
$last_done_advance_id = 0;
if (!empty($thematic_data)) {
@ -1004,7 +1004,7 @@ class Thematic
if (!empty($a_thematic_advance_ids)) {
$last_done_advance_id = array_pop($a_thematic_advance_ids);
$last_done_advance_id = intval($last_done_advance_id);
}
}
return $last_done_advance_id;
}
@ -1052,16 +1052,16 @@ class Thematic
if (api_get_session_id()) {
$thematic_data = $this->get_thematic_list(null, $course_code );
} else {
$thematic_data = $this->get_thematic_list(null, $course_code, 0);
}
$thematic_data = $this->get_thematic_list(null, $course_code, 0);
}
$new_thematic_data = array();
if (!empty($thematic_data)) {
foreach ($thematic_data as $item) {
$new_thematic_data[] = $item;
foreach ($thematic_data as $item) {
$new_thematic_data[] = $item;
}
$thematic_data = $new_thematic_data;
}
$thematic_advance_data = $this->get_thematic_advance_list(null, $course_code, true);
$a_average_of_advances_by_thematic = array();
$total_average = 0;
@ -1077,7 +1077,7 @@ class Thematic
$count_tematics = count($thematic_data);
$score = array_sum($a_average_of_advances_by_thematic);
$total_average = round(($score*100)/($count_tematics*100));
}
}
return $total_average;
}
@ -1096,16 +1096,16 @@ class Thematic
// get all done advances by thematic
$advances = array();
$count_done_advances = 0;
$average = 0;
$average = 0;
foreach ($thematic_advance_data as $thematic_advance) {
if ($thematic_advance['done_advance'] == 1) {
$count_done_advances++;
$count_done_advances++;
}
$advances[] = $thematic_advance['done_advance'];
}
// calculate average by thematic
$count_total_advances = count($advances);
$average = round(($count_done_advances*100)/$count_total_advances);
$count_total_advances = count($advances);
$average = round(($count_done_advances*100)/$count_total_advances);
}
return $average;
@ -1187,7 +1187,7 @@ class Thematic
$default_thematic_plan_titles[1]= get_lang('Objectives');
$default_thematic_plan_titles[2]= get_lang('SkillToAcquire');
$default_thematic_plan_titles[3]= get_lang('Methodology');
$default_thematic_plan_titles[4]= get_lang('Infrastructure');
$default_thematic_plan_titles[4]= get_lang('Infrastructure');
$default_thematic_plan_titles[5]= get_lang('Assessment');
$default_thematic_plan_titles[6]= get_lang('Others');
return $default_thematic_plan_titles;
@ -1228,22 +1228,6 @@ class Thematic
* @return string date and time e.g: '2010-02-10 12:30:00'
*/
public function build_datetime_from_array($array) {
$year = '0000';
$month = $day = $hours = $minutes = $seconds = '00';
if (isset($array['Y']) && isset($array['F']) && isset($array['d']) && isset($array['H']) && isset($array['i'])) {
$year = $array['Y'];
$month = $array['F'];
if (intval($month) < 10 ) $month = '0'.$month;
$day = $array['d'];
if (intval($day) < 10 ) $day = '0'.$day;
$hours = $array['H'];
if (intval($hours) < 10 ) $hours = '0'.$hours;
$minutes = $array['i'];
if (intval($minutes) < 10 ) $minutes = '0'.$minutes;
}
if (checkdate($month,$day,$year)) {
$datetime = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.':'.$seconds;
}
return $datetime;
return return_datetime_from_array($array);
}
}
Loading…
Cancel
Save