Adding support to sessions in the thematic tool

skala
Julio Montoya 14 years ago
parent f9b52b328f
commit 26d0cf7017
  1. 54
      main/attendance/attendance_calendar.php
  2. 29
      main/attendance/attendance_controller.php
  3. 4
      main/course_progress/index.php
  4. 184
      main/course_progress/thematic.php
  5. 406
      main/course_progress/thematic_controller.php
  6. 103
      main/course_progress/thematic_plan.php
  7. 40
      main/inc/ajax/thematic.ajax.php
  8. 264
      main/inc/lib/attendance.lib.php
  9. 71
      main/inc/lib/main_api.lib.php
  10. 282
      main/inc/lib/thematic.lib.php

@ -14,15 +14,18 @@ $param_gradebook = '';
if (isset($_SESSION['gradebook'])) {
$param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
}
echo '<div class="actions" style="margin-bottom:30px">';
echo '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('attendance_list.png',get_lang('AttendanceSheet'),'','32').'</a>';
if ($action == 'calendar_add') {
echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'','32').'</a>';
} else {
echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('add_calendar_event.png',get_lang('AddDateAndTime'),'','32').'</a>';
echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDeleteAllDates').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=calendar_all_delete&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('clean_calendar.png',get_lang('CleanCalendar'),'','32').'</a>';
if (!$is_locked_attendance || api_is_platform_admin()) {
echo '<div class="actions" style="margin-bottom:30px">';
echo '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('attendance_list.png',get_lang('AttendanceSheet'),'','32').'</a>';
if ($action == 'calendar_add') {
echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'','32').'</a>';
} else {
echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('add_calendar_event.png',get_lang('AddDateAndTime'),'','32').'</a>';
echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDeleteAllDates').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=calendar_all_delete&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('clean_calendar.png',get_lang('CleanCalendar'),'','32').'</a>';
}
echo '</div>';
}
echo '</div>';
$message_information = get_lang('AttendanceCalendarDescription');
@ -70,8 +73,8 @@ if (isset($action) && $action == 'calendar_add') {
$defaults['end_date_time'] = date('Y-m-d 12:00:00');
$form->addElement('html', '</td></tr>');
$form->addElement('html', '</table>');
$form->addElement('html', '</div>');
$form->addElement('html', '</div>');
$form->addElement('html','<br /><br />');
@ -85,32 +88,33 @@ if (isset($action) && $action == 'calendar_add') {
// calendar list
echo '<div class="attendance-calendar-list">';
echo '<h4>'.get_lang('CalendarList').'</h4>';
if (!empty($attendance_calendar)) {
foreach ($attendance_calendar as $calendar) {
echo '<div class="attendance-calendar-row">';
if (!empty($attendance_calendar)) {
foreach ($attendance_calendar as $calendar) {
echo '<div class="attendance-calendar-row">';
if ((isset($action) && $action == 'calendar_edit') && (isset($calendar_id) && $calendar_id == $calendar['id'])) {
// calendar edit form
echo '<div class="attendance-calendar-edit">';
$form = new FormValidator('attendance_calendar_edit','POST','index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq().$param_gradebook,'');
// calendar edit form
echo '<div class="attendance-calendar-edit">';
$form = new FormValidator('attendance_calendar_edit','POST','index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq().$param_gradebook,'');
$form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_edit'), 5);
$defaults['date_time'] = $calendar['date_time'];
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
$form->addElement('style_submit_button', 'cancel', get_lang('Cancel'), 'class="cancel"');
$form->setDefaults($defaults);
$form->display();
echo '</div>';
echo '</div>';
} else {
echo Display::return_icon('lp_calendar_event.png',get_lang('DateTime')).' '.$calendar['date_time'].'&nbsp;';
echo '<span style="margin-left:20px;">';
echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style'=>'vertical-align:middle')).'</a>&nbsp;';
echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().$param_gradebook.'&action=calendar_delete&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.Display::return_icon('delete.gif', get_lang('Delete'), array('style'=>'vertical-align:middle')).'</a>';
echo '</span>';
}
if (!$is_locked_attendance || api_is_platform_admin()) {
echo '<span style="margin-left:20px;">';
echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style'=>'vertical-align:middle')).'</a>&nbsp;';
echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().$param_gradebook.'&action=calendar_delete&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.Display::return_icon('delete.gif', get_lang('Delete'), array('style'=>'vertical-align:middle')).'</a>';
echo '</span>';
}
}
echo '</div>';
}
} else {
echo '<div style="padding:5px;">'.get_lang('ThereAreNoRegisteredDatetimeYet').'</div>';
}
echo '</div>';
}
?>
echo '</div>';
}

@ -172,7 +172,29 @@
}
$this->attendance_list();
}
/**
* Lock or unlock an attendance
* render to attendance_list view
* @param string action (lock_attendance or unlock_attendance)
* @param int attendance id
* render to attendance_list view
*/
public function lock_attendance($action, $attendance_id) {
$attendance = new Attendance();
$attendance_id = intval($attendance_id);
if ($action == 'lock_attendance') {
$result = $attendance->lock_attendance($attendance_id);
} else {
$result = $attendance->lock_attendance($attendance_id, false);
}
if ($affected_rows) {
$message['message_locked_attendance'] = true;
}
$this->attendance_list();
}
/**
* It's used for controlling attendace sheet (list, add),
* render to attendance_sheet view
@ -226,7 +248,7 @@
} else {
$data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id,$filter_type);
}
$data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id);
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('attendance_sheet');
@ -318,7 +340,8 @@
}
$data['action'] = $action;
$data['attendance_calendar'] = $attendance->get_attendance_calendar($attendance_id);
$data['attendance_calendar'] = $attendance->get_attendance_calendar($attendance_id);
$data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id);
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');

@ -89,7 +89,7 @@ $htmlHeadXtra[] = '<script language="javascript">
beforeSend: function(objeto) {},
type: "POST",
url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=get_datetime_by_attendance",
data: "attendance_id="+selected_value,
data: "attendance_id="+selected_value+"&thematic_advance_id='.$thematic_id.'",
success: function(datos) {
$("#div_datetime_attendance").html(datos);
}
@ -190,6 +190,8 @@ if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
$interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('NewThematicAdvance'));
}
// distpacher actions to controller
switch ($action) {
case 'thematic_add' :

@ -86,76 +86,104 @@ if ($action == 'thematic_list') {
echo '<table width="100%" class="data_table">';
echo '<tr><th width="33%">'.get_lang('Thematic').'</th><th>'.get_lang('ThematicPlan').'</th><th width="33%">'.get_lang('ThematicAdvance').'</th></tr>';
foreach ($thematic_data as $thematic) {
echo '<tr>';
// display thematic data
echo '<td><div id="titlethematic" ><strong>'.Security::remove_XSS($thematic['title'], STUDENT).'</strong></div><div>'.Security::remove_XSS($thematic['content'], STUDENT).'</div></td>';
// display thematic plan data
echo '<td>';
if (api_is_allowed_to_edit(null, true)) {
echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&origin=thematic_details&action=thematic_plan_list&thematic_id='.$thematic['id'].'">'.Display::return_icon('edit.png',get_lang('EditThematicPlan'),array('style'=>'vertical-align:middle'),22).'</a></div><br />';
foreach ($thematic_data as $thematic) {
echo '<tr>';
// display thematic title
echo '<td><div id="titlethematic" ><strong>'.Security::remove_XSS($thematic['title'], STUDENT).'</strong></div><div>'.Security::remove_XSS($thematic['content'], STUDENT).'</div></td>';
// display thematic plan data
echo '<td>';
if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&origin=thematic_details&action=thematic_plan_list&thematic_id='.$thematic['id'].'">'.Display::return_icon('lp_quiz.png',get_lang('EditThematicPlan'),array('style'=>'vertical-align:middle')).'</a></div><br />';
}
$new_thematic_plan_data = array();
if (!empty($thematic_plan_data[$thematic['id']]))
foreach($thematic_plan_data[$thematic['id']] 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;
if (!empty($thematic_simple_list))
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'];
}
}
if (!empty($default_thematic_plan_title)) {
foreach ($default_thematic_plan_title as $id=>$title) {
//avoid others
if ($title == 'Others' && empty($thematic_plan_data[$thematic['id']][$id]['description'])) { continue;}
if(isset($thematic_plan_data[$thematic['id']][$id]['title'])) {
echo '<div id="titlethematic" ><strong>'.Security::remove_XSS($thematic_plan_data[$thematic['id']][$id]['title'], STUDENT).'</strong></div><div>'.Security::remove_XSS($thematic_plan_data[$thematic['id']][$id]['description'], STUDENT).'</div>';
} else {
echo '<div id="titlethematic" ><strong>'.$title.'</strong></div><br />';
}
}
} else {
echo '<div><em>'.get_lang('StillDoNotHaveAThematicPlan').'</em></div>';
}
echo '</td>';
// display thematic advance data
echo '<td>';
if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&origin=thematic_details&action=thematic_advance_list&thematic_id='.$thematic['id'].'">'.Display::return_icon('lp_quiz.png',get_lang('EditThematicAdvance'),array('style'=>'vertical-align:middle')).'</a></div><br />';
}
echo '<table width="100%">';
//if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
if (!empty($thematic_advance_data[$thematic['id']])) {
foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
$thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']);
$thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG);
echo '<tr>';
echo '<td width="90%">';
echo '<div><strong>'.$thematic_advance['start_date'].'</strong></div>';
echo '<div>'.Security::remove_XSS($thematic_advance['content'], STUDENT).'</div>';
echo '<div>'.get_lang('DurationInHours').' : '.$thematic_advance['duration'].'</div>';
echo '</td>';
if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
if (empty($thematic_id)) {
$checked = '';
if ($last_done_thematic_advance == $thematic_advance['id']) {
$checked = 'checked';
}
$style = '';
if ($thematic_advance['done_advance'] == 1) {
$style = ' style="background-color:#E5EDF9" ';
} else {
$style = ' style="background-color:#fff" ';
}
echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center><input type="radio" id="done_thematic_'.$thematic_advance['id'].'" name="done_thematic" value="'.$thematic_advance['id'].'" '.$checked.' onclick="update_done_thematic_advance(this.value)"></center></td>';
} else {
if ($thematic_advance['done_advance'] == 1) {
echo '<td><center>'.get_lang('Done').'</center></td>';
} else {
echo '<td><center>-</center></td>';
}
}
}
if (!empty($thematic_plan_data[$thematic['id']])) {
foreach ($thematic_plan_data[$thematic['id']] as $thematic_plan) {
echo '<div id="titlethematic" ><strong>'.Security::remove_XSS($thematic_plan['title'], STUDENT).'</strong></div><div>'.Security::remove_XSS($thematic_plan['description'], STUDENT).'</div>';
}
} else {
echo '<div><em>'.get_lang('StillDoNotHaveAThematicPlan').'</em></div>';
}
echo '</td>';
// display thematic advance data
echo '<td>';
if (api_is_allowed_to_edit(null, true)) {
echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&origin=thematic_details&action=thematic_advance_list&thematic_id='.$thematic['id'].'">'.Display::return_icon('edit.png',get_lang('EditThematicAdvance'),array('style'=>'vertical-align:middle'),22).'</a></div><br />';
}
echo '<table width="100%">';
if (!empty($thematic_advance_data[$thematic['id']])) {
foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
$thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']);
$thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG);
echo '<tr>';
echo '<td width="90%">';
echo '<div><strong>'.$thematic_advance['start_date'].'</strong></div>';
echo '<div>'.Security::remove_XSS($thematic_advance['content'], STUDENT).'</div>';
echo '<div>'.get_lang('DurationInHours').' : '.$thematic_advance['duration'].'</div>';
echo '</td>';
if (empty($thematic_id) && api_is_allowed_to_edit(null, true)) {
$checked = '';
if ($last_done_thematic_advance == $thematic_advance['id']) {
$checked = 'checked';
}
$style = '';
if ($thematic_advance['done_advance'] == 1) {
$style = ' style="background-color:#E5EDF9" ';
} else {
$style = ' style="background-color:#fff" ';
}
echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center><input type="radio" id="done_thematic_'.$thematic_advance['id'].'" name="done_thematic" value="'.$thematic_advance['id'].'" '.$checked.' onclick="update_done_thematic_advance(this.value)"></center></td>';
} else {
if ($thematic_advance['done_advance'] == 1) {
echo '<td><center>'.get_lang('Done').'</center></td>';
} else {
echo '<td><center>-</center></td>';
}
}
echo '</tr>';
}
} else {
echo '<tr><td width="90%"><div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div></td><td>&nbsp;</td>';
}
echo '</table>';
echo '</td>';
echo '</tr>';
}
echo '</table>';
} else {
echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
}
echo '</tr>';
}
} else {
echo '<tr><td width="90%"><div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div></td><td>&nbsp;</td>';
}
echo '</table>';
echo '</td>';
echo '</tr>';
} //End for
echo '</table>';
} else {
echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
}
} else if ($action == 'thematic_add' || $action == 'thematic_edit') {
if (!$error) {
@ -164,7 +192,7 @@ if ($action == 'thematic_list') {
}
// display form
$form = new FormValidator('thematic_add','POST','index.php?action=thematic_details&'.api_get_cidreq(),'','style="width: 100%;"');
$form = new FormValidator('thematic_add','POST','index.php?action=thematic_details&'.api_get_cidreq(),'style="width: 100%;"');
if ($action == 'thematic_edit') {
$form->addElement('header', '', get_lang('EditThematicSection'));
@ -182,7 +210,16 @@ if ($action == 'thematic_list') {
$form->addElement('html','<div class="clear" style="margin-top:50px;"></div>');
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
$show_form = true;
if (!empty($thematic_data)) {
if (api_get_session_id()) {
if ($thematic_data['session_id'] != api_get_session_id()) {
$show_form = false;
Display::display_error_message(get_lang('NotAllowedClickBack'),false);
}
}
// set default values
$default['title'] = $thematic_data['title'];
$default['content'] = $thematic_data['content'];
@ -193,7 +230,6 @@ if ($action == 'thematic_list') {
if ($error) {
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
}
$form->display();
}
?>
if ($show_form)
$form->display();
}

@ -39,24 +39,26 @@ class ThematicController
$msg_add = false;
// insert or update a thematic
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (isset($_POST['action']) && ($_POST['action'] == 'thematic_add' || $_POST['action'] == 'thematic_edit')) {
if (trim($_POST['title']) !== '') {
if ($_POST['thematic_token'] == $_SESSION['thematic_token']) {
$id = $_POST['thematic_id'];
$title = $_POST['title'];
$content = $_POST['content'];
$session_id = api_get_session_id();
$thematic->set_thematic_attributes($id, $title, $content, $session_id);
$last_id = $thematic->thematic_save();
if ($_POST['action'] == 'thematic_add') {
$action = 'thematic_details';
if ($last_id) {
$data['last_id'] = $last_id;
}
} else {
$action = 'thematic_list';
}
if ($_POST['thematic_token'] == $_SESSION['thematic_token']) {
if (api_is_allowed_to_edit(null, true)) {
$id = $_POST['thematic_id'];
$title = $_POST['title'];
$content = $_POST['content'];
$session_id = api_get_session_id();
$thematic->set_thematic_attributes($id, $title, $content, $session_id);
$last_id = $thematic->thematic_save();
if ($_POST['action'] == 'thematic_add') {
$action = 'thematic_details';
if ($last_id) {
$data['last_id'] = $last_id;
}
} else {
$action = 'thematic_list';
}
}
unset($_SESSION['thematic_token']);
}
} else {
@ -75,19 +77,24 @@ class ThematicController
// delete many thematics
if ($action == 'thematic_delete_select') {
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
$thematic_ids = $_POST['id'];
$affected_rows = $thematic->thematic_destroy($thematic_ids);
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (api_is_allowed_to_edit(null, true)) {
$thematic_ids = $_POST['id'];
$affected_rows = $thematic->thematic_destroy($thematic_ids);
}
$action = 'thematic_list';
}
}
$thematic_id = isset($_GET['thematic_id'])?intval($_GET['thematic_id']):null;
if (isset($thematic_id)) {
// delete a thematic
if ($action == 'thematic_delete') {
$affected_rows = $thematic->thematic_destroy($thematic_id);
if (api_is_allowed_to_edit(null, true)) {
$affected_rows = $thematic->thematic_destroy($thematic_id);
}
$action = 'thematic_list';
}
// move thematic
@ -99,26 +106,34 @@ class ThematicController
$action = 'thematic_list';
}
$data['thematic_data'] = $thematic->get_thematic_list($thematic_id);
$data['thematic_id'] = $thematic_id;
$data['thematic_id'] = $thematic_id;
}
if ($action == 'thematic_details') {
if (isset($thematic_id)) {
$thematic_data[$thematic_id] = $thematic->get_thematic_list($thematic_id);
$data['total_average_of_advances'] = $thematic->get_average_of_advances_by_thematic($thematic_id);
$thematic_data[$thematic_id] = $thematic->get_thematic_list($thematic_id);
$data['total_average_of_advances'] = $thematic->get_average_of_advances_by_thematic($thematic_id);
} else {
$thematic_data = $thematic->get_thematic_list();
$data['last_done_thematic_advance'] = $thematic->get_last_done_thematic_advance();
$data['total_average_of_advances'] = $thematic->get_total_average_of_thematic_advances();
$thematic_data = $thematic->get_thematic_list(null, api_get_course_id(), api_get_session_id());
$data['last_done_thematic_advance'] = $thematic->get_last_done_thematic_advance();
$data['total_average_of_advances'] = $thematic->get_total_average_of_thematic_advances();
}
$thematic_plan_data = $thematic->get_thematic_plan_data();
$thematic_advance_data = $thematic->get_thematic_advance_list();
$data['thematic_plan_data'] = $thematic_plan_data;
$data['thematic_advance_data'] = $thematic_advance_data;
$data['thematic_data'] = $thematic_data;
//Second column
$thematic_plan_data = $thematic->get_thematic_plan_data();
//Third column
$thematic_advance_data = $thematic->get_thematic_advance_list();
$data['thematic_plan_data'] = $thematic_plan_data;
$data['thematic_advance_data'] = $thematic_advance_data;
$data['thematic_data'] = $thematic_data;
}
$data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['action'] = $action;
// render to the view
@ -134,163 +149,192 @@ class ThematicController
* render to thematic_plan.php
*/
public function thematic_plan($action) {
$thematic= new Thematic();
$thematic= new Thematic();
$data = array();
$error = false;
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (isset($_POST['action']) && ($_POST['action'] == 'thematic_plan_add' || $_POST['action'] == 'thematic_plan_edit')) {
if (trim($_POST['title']) !== '') {
if ($_POST['thematic_plan_token'] == $_SESSION['thematic_plan_token']) {
$thematic_id = $_POST['thematic_id'];
$title = $_POST['title'];
$description = $_POST['description'];
$description_type = $_POST['description_type'];
$thematic->set_thematic_plan_attributes($thematic_id, $title, $description, $description_type);
$affected_rows = $thematic->thematic_plan_save();
unset($_SESSION['thematic_plan_token']);
$action = 'thematic_plan_list';
}
} else {
$error = true;
$action = $_POST['action'];
$data['error'] = $error;
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($_POST['thematic_id'], $_POST['description_type']);
$data['thematic_id'] = $_POST['thematic_id'];
$data['description_type'] = $_POST['description_type'];
$data['action'] = $action;
$data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon();
$data['default_thematic_plan_question'] = $thematic->get_default_question();
$data['next_description_type'] = $thematic->get_next_description_type($_POST['thematic_id']);
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic_plan');
$this->view->render();
}
}
}
if ($action == 'thematic_plan_list') {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
}
$thematic_id = intval($_GET['thematic_id']);
$description_type = intval($_GET['description_type']);
if (!empty($thematic_id) && !empty($description_type)) {
if ($action == 'thematic_plan_delete') {
$affected_rows = $thematic->thematic_plan_destroy($thematic_id, $description_type);
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
$action = 'thematic_plan_list';
} else {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id, $description_type);
}
$data['thematic_id'] = $thematic_id;
$data['description_type'] = $description_type;
} else if (!empty($thematic_id) && $action == 'thematic_plan_list') {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
$data['thematic_id'] = $thematic_id;
}
$data['thematic_id'] = $thematic_id;
$data['action'] = $action;
$data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon();
$data['next_description_type'] = $thematic->get_next_description_type($thematic_id);
$data['default_thematic_plan_question'] = $thematic->get_default_question();
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic_plan');
$this->view->render();
}
/**
* This method is used for thematic advance control (update, insert or listing)
* @param string Action
* render to thematic_advance.php
*/
public function thematic_advance($action) {
$thematic= new Thematic();
$attendance = new Attendance();
$data = array();
// get data for attendance input select
$attendance_list = $attendance->get_attendances_list();
$attendance_select = array();
$attendance_select[0] = get_lang('SelectAnAttendance');
foreach ($attendance_list as $attendance_id => $attendance_data) {
$attendance_select[$attendance_id] = $attendance_data['name'];
}
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (isset($_POST['action']) && ($_POST['action'] == 'thematic_advance_add' || $_POST['action'] == 'thematic_advance_edit')) {
if (($_POST['start_date_type'] == 1 && empty($_POST['start_date_by_attendance'])) || (!empty($_POST['duration_in_hours']) && !is_numeric($_POST['duration_in_hours'])) ) {
if ($_POST['start_date_type'] == 1 && empty($_POST['start_date_by_attendance'])) {
$start_date_error = true;
$data['start_date_error'] = $start_date_error;
}
if (!empty($_POST['duration_in_hours']) && !is_numeric($_POST['duration_in_hours'])) {
$duration_error = true;
$data['duration_error'] = $duration_error;
}
$data['action'] = $_POST['action'];
$data['thematic_id'] = $_POST['thematic_id'];
$data['attendance_select'] = $attendance_select;
if (isset($_POST['thematic_advance_id'])) {
$data['thematic_advance_id'] = $_POST['thematic_advance_id'];
$thematic_advance_data = $thematic->get_thematic_advance_list($_POST['thematic_advance_id']);
$data['thematic_advance_data'] = $thematic_advance_data;
}
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (isset($_POST['action']) && ($_POST['action'] == 'thematic_plan_add' || $_POST['action'] == 'thematic_plan_edit')) {
if (trim($_POST['title']) !== '') {
if ($_POST['thematic_plan_token'] == $_SESSION['thematic_plan_token']) {
if (api_is_allowed_to_edit(null, true)) {
$thematic_id = $_POST['thematic_id'];
$title = $_POST['title'];
$description = $_POST['description'];
$description_type = $_POST['description_type'];
$thematic->set_thematic_plan_attributes($thematic_id, $title, $description, $description_type);
$affected_rows = $thematic->thematic_plan_save();
unset($_SESSION['thematic_plan_token']);
$data['message'] = 'ok';
}
$data['action'] = 'thematic_plan_list';
}
} else {
$error = true;
$action = $_POST['action'];
$data['error'] = $error;
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($_POST['thematic_id'], $_POST['description_type']);
$data['thematic_id'] = $_POST['thematic_id'];
$data['description_type'] = $_POST['description_type'];
$data['action'] = $action;
$data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon();
$data['default_thematic_plan_question'] = $thematic->get_default_question();
$data['next_description_type'] = $thematic->get_next_description_type($_POST['thematic_id']);
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic_advance');
$this->view->render();
} else {
if ($_POST['thematic_advance_token'] == $_SESSION['thematic_advance_token']) {
$thematic_advance_id = $_POST['thematic_advance_id'];
$thematic_id = $_POST['thematic_id'];
$content = $_POST['content'];
$duration = $_POST['duration_in_hours'];
if (isset($_POST['start_date_type']) && $_POST['start_date_type'] == 2) {
$start_date = $thematic->build_datetime_from_array($_POST['custom_start_date']);
$attendance_id = 0;
} else {
$start_date = $_POST['start_date_by_attendance'];
$attendance_id = $_POST['attendance_select'];
}
$thematic->set_thematic_advance_attributes($thematic_advance_id, $thematic_id, $attendance_id, $content, $start_date, $duration);
$affected_rows = $thematic->thematic_advance_save();
if ($affected_rows) {
// get last done thematic advance before move thematic list
$last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
// update done advances with de current thematic list
if (!empty($last_done_thematic_advance)) {
$update_done_advances = $thematic->update_done_thematic_advances($last_done_thematic_advance);
}
}
unset($_SESSION['thematic_advance_token']);
$action = 'thematic_advance_list';
}
}
}
}
$this->view->set_template('thematic_plan');
$this->view->render();
}
} else if($_POST['action'] == 'thematic_plan_list') {
$title_list = $_POST['title'];
$description_list = $_POST['description'];
$description_type = $_POST['description_type'];
if (api_is_allowed_to_edit(null, true)) {
for($i=1;$i<count($title_list)+1; $i++) {
//if (!empty($description_list[$i])) {
$thematic->set_thematic_plan_attributes($_POST['thematic_id'], $title_list[$i], $description_list[$i], $description_type[$i]);
$affected_rows = $thematic->thematic_plan_save();
//}
}
$data['message'] = 'ok';
}
}
}
if ($action == 'thematic_plan_list') {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
}
$thematic_id = intval($_GET['thematic_id']);
$description_type = intval($_GET['description_type']);
if (!empty($thematic_id) && !empty($description_type)) {
if ($action == 'thematic_plan_delete') {
if (api_is_allowed_to_edit(null, true)) {
$affected_rows = $thematic->thematic_plan_destroy($thematic_id, $description_type);
}
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
$action = 'thematic_plan_list';
} else {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id, $description_type);
}
$data['thematic_id'] = $thematic_id;
$data['description_type'] = $description_type;
} else if (!empty($thematic_id) && $action == 'thematic_plan_list') {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
$data['thematic_id'] = $thematic_id;
}
$data['thematic_id'] = $thematic_id;
$data['action'] = $action;
$data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon();
$data['next_description_type'] = $thematic->get_next_description_type($thematic_id);
$data['default_thematic_plan_question'] = $thematic->get_default_question();
$data['thematic_data'] = $thematic->get_thematic_list($thematic_id);
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic_plan');
$this->view->render();
exit;
}
/**
* This method is used for thematic advance control (update, insert or listing)
* @param string Action
* render to thematic_advance.php
*/
public function thematic_advance($action) {
$thematic= new Thematic();
$attendance = new Attendance();
$data = array();
// get data for attendance input select
$attendance_list = $attendance->get_attendances_list();
$attendance_select = array();
$attendance_select[0] = get_lang('SelectAnAttendance');
foreach ($attendance_list as $attendance_id => $attendance_data) {
$attendance_select[$attendance_id] = $attendance_data['name'];
}
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (isset($_POST['action']) && ($_POST['action'] == 'thematic_advance_add' || $_POST['action'] == 'thematic_advance_edit')) {
if (($_POST['start_date_type'] == 1 && empty($_POST['start_date_by_attendance'])) || (!empty($_POST['duration_in_hours']) && !is_numeric($_POST['duration_in_hours'])) ) {
if ($_POST['start_date_type'] == 1 && empty($_POST['start_date_by_attendance'])) {
$start_date_error = true;
$data['start_date_error'] = $start_date_error;
}
if (!empty($_POST['duration_in_hours']) && !is_numeric($_POST['duration_in_hours'])) {
$duration_error = true;
$data['duration_error'] = $duration_error;
}
$data['action'] = $_POST['action'];
$data['thematic_id'] = $_POST['thematic_id'];
$data['attendance_select'] = $attendance_select;
if (isset($_POST['thematic_advance_id'])) {
$data['thematic_advance_id'] = $_POST['thematic_advance_id'];
$thematic_advance_data = $thematic->get_thematic_advance_list($_POST['thematic_advance_id']);
$data['thematic_advance_data'] = $thematic_advance_data;
}
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic_advance');
$this->view->render();
} else {
if ($_POST['thematic_advance_token'] == $_SESSION['thematic_advance_token'] && api_is_allowed_to_edit(null, true)) {
$thematic_advance_id = $_POST['thematic_advance_id'];
$thematic_id = $_POST['thematic_id'];
$content = $_POST['content'];
$duration = $_POST['duration_in_hours'];
if (isset($_POST['start_date_type']) && $_POST['start_date_type'] == 2) {
$start_date = $thematic->build_datetime_from_array($_POST['custom_start_date']);
$attendance_id = 0;
} else {
$start_date = $_POST['start_date_by_attendance'];
$attendance_id = $_POST['attendance_select'];
}
$thematic->set_thematic_advance_attributes($thematic_advance_id, $thematic_id, $attendance_id, $content, $start_date, $duration);
$affected_rows = $thematic->thematic_advance_save();
if ($affected_rows) {
// get last done thematic advance before move thematic list
$last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
// update done advances with de current thematic list
if (!empty($last_done_thematic_advance)) {
$update_done_advances = $thematic->update_done_thematic_advances($last_done_thematic_advance);
}
}
unset($_SESSION['thematic_advance_token']);
$action = 'thematic_advance_list';
}
}
}
}
$thematic_id = intval($_GET['thematic_id']);
$thematic_advance_id = intval($_GET['thematic_advance_id']);
$thematic_advance_data = array();
if (!empty($thematic_advance_id)) {
if ($action == 'thematic_advance_delete') {
$affected_rows = $thematic->thematic_advance_destroy($thematic_advance_id);
if (api_is_allowed_to_edit(null, true)) {
$affected_rows = $thematic->thematic_advance_destroy($thematic_advance_id);
}
$action = 'thematic_advance_list';
} else {
$thematic_advance_data = $thematic->get_thematic_advance_list($thematic_advance_id);
@ -321,10 +365,6 @@ class ThematicController
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic_advance');
$this->view->render();
$this->view->render();
}
}
?>
}

@ -8,49 +8,78 @@
*/
// actions menu
$categories = array ();
foreach ($default_thematic_plan_title as $id => $title) {
$categories[$id] = $title;
$new_thematic_plan_data = array();
if (!empty($thematic_plan_data))
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;
if (!empty($thematic_simple_list))
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'];
}
}
$categories[ADD_THEMATIC_PLAN] = get_lang('NewBloc');
$i=1;
echo '<h2>'.$thematic_data['title'].'</h2>';
echo $thematic_data['content'];
echo '<div class="actions" style="margin-bottom:30px">';
ksort($categories);
foreach ($categories as $id => $title) {
if ($i == ADD_THEMATIC_PLAN) {
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_add&thematic_id='.$thematic_id.'&description_type='.$next_description_type.'">'.Display::return_icon($default_thematic_plan_icon[$id], $title,'','32').'</a>';
break;
} else {
echo '<a href="index.php?action=thematic_plan_edit&'.api_get_cidreq().'&description_type='.$id.'&thematic_id='.$thematic_id.'">'.Display::return_icon($default_thematic_plan_icon[$id], $title,'','32').'</a>';
$i++;
}
if ($action == 'thematic_plan_edit') {
echo '<a href="index.php?action=thematic_plan_list&'.api_get_cidreq().'&thematic_id='.$thematic_id.'">'.Display::return_icon('back.png', get_lang('Back'), array(), 32).'</a>&nbsp;&nbsp;';
} else {
echo '<a href="index.php?action=thematic_plan_list&'.api_get_cidreq().'&action=thematic_details&'.api_get_cidreq().'">'.Display::return_icon('back.png', $title, array('height'=>'32')).'</a>&nbsp;&nbsp;';
echo '<a href="index.php?action=thematic_plan_edit&'.api_get_cidreq().'&description_type='.$new_id.'&thematic_id='.$thematic_id.'">'.Display::return_icon('new_document.png', get_lang('NewBloc'), array(), 32).'</a>';
}
echo '</div>';
if ($action == 'thematic_plan_list') {
if ($message == 'ok') {
Display::display_normal_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull'));
}
if ($action == 'thematic_plan_list') {
$form = new FormValidator('thematic_plan_add','POST','index.php?action=thematic_plan_list&thematic_id='.$thematic_id.'&'.api_get_cidreq().$param_gradebook,'','style="width: 100%;"');
$form->addElement('hidden', 'action', $action);
$form->addElement('hidden', 'thematic_plan_token', $token);
$form->addElement('hidden', 'thematic_id', $thematic_id);
//var_dump($default_thematic_plan_title);
//var_dump($thematic_simple_list);
foreach ($default_thematic_plan_title as $id => $title) {
//foreach ($thematic_simple_list as $id) {
//$title = $default_thematic_plan_title[$id];
$form->addElement('hidden', 'description_type['.$id.']', $id);
$form->add_textfield('title['.$id.']', get_lang('Title'), true, array('size'=>'50'));
$form->add_html_editor('description['.$id.']', get_lang('Description'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200'));
$form->addElement('html','<div class="clear" style="margin-top:50px;"></div>');
if (!empty($thematic_simple_list) && in_array($id, $thematic_simple_list)) {
$thematic_plan = $new_thematic_plan_data[$id];
// set default values
$default['title['.$id.']'] = $thematic_plan['title'];
$default['description['.$id.']'] = $thematic_plan['description'];
$thematic_plan = null;
if (isset($thematic_plan_data) && count($thematic_plan_data) > 0) {
foreach ($thematic_plan_data as $thematic_plan) {
echo '<div class="sectiontitle" >';
//delete
echo '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&thematic_id='.$thematic_plan['thematic_id'].'&action=thematic_plan_delete&description_type='.$thematic_plan['description_type'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">';
echo Display::return_icon('delete.png', get_lang('Delete'), array('style' => 'vertical-align:middle;float:right;'),22);
echo '</a> ';
//edit
echo '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&thematic_id='.$thematic_plan['thematic_id'].'&action=thematic_plan_edit&description_type='.$thematic_plan['description_type'].'">';
echo Display::return_icon('edit.png', get_lang('Edit'), array('style' => 'vertical-align:middle;float:right; padding-right:4px;'),22);
echo '</a> ';
echo Security::remove_XSS($thematic_plan['title'], STUDENT);
echo '</div>';
echo '<div class="sectioncomment">';
echo text_filter($thematic_plan['description']);
echo '</div>';
}
} else {
echo '<em>'.get_lang('ThisCourseDescriptionIsEmpty').'</em>';
}
} else {
$thematic_plan = null;
$default['title['.$id.']'] = $title;
$default['description['.$id.']']= '';
}
$form->setDefaults($default);
}
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
$form->display();
} else if ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
if ($description_type >= ADD_THEMATIC_PLAN) {
@ -64,8 +93,8 @@ if ($action == 'thematic_plan_list') {
}
// display form
$form = new FormValidator('thematic_plan_add','POST','index.php?action=thematic_plan_list&thematic_id='.$thematic_id.'&'.api_get_cidreq().$param_gradebook,'','style="width: 100%;"');
$form->addElement('header', '', $header_form);
$form = new FormValidator('thematic_plan_add','POST','index.php?action=thematic_plan_edit&thematic_id='.$thematic_id.'&'.api_get_cidreq().$param_gradebook,'','style="width: 100%;"');
//$form->addElement('header', '', $header_form);
$form->addElement('hidden', 'action', $action);
$form->addElement('hidden', 'thematic_plan_token', $token);

@ -13,17 +13,47 @@ $action = $_GET['a'];
switch ($action) {
case 'get_datetime_by_attendance':
$attendance_id = intval($_POST['attendance_id']);
$thematic_advance_id = intval($_POST['thematic_advance_id']);
$label = '';
$input_select = '';
if (!empty($attendance_id)) {
$attendance = new Attendance();
$attendance_calendar = $attendance->get_attendance_calendar($attendance_id);
$attendance = new Attendance();
$thematic = new Thematic();
$thematic_list = $thematic->get_thematic_list();
$my_list = $thematic_list_temp = array();
foreach($thematic_list as $item) {
$my_list = $thematic->get_thematic_advance_by_thematic_id($item['id']);
$thematic_list_temp = array_merge($my_list, $thematic_list_temp);
}
$new_thematic_list = array();
foreach($thematic_list_temp as $item) {
if (!empty($item['attendance_id']) ) {
$new_thematic_list[$item['id']] = array('attendance_id' =>$item['attendance_id'], 'start_date'=>$item['start_date']);
}
}
$attendance_calendar = $attendance->get_attendance_calendar($attendance_id);
$calendar_select = array();
$label = get_lang('StartDate');
if (!empty($attendance_calendar)) {
$input_select .= '<select name="start_date_by_attendance" UNIQUE size="5">';
foreach ($attendance_calendar as $calendar) {
$input_select .= '<option value="'.$calendar['date_time'].'">'.$calendar['date_time'].'</option>';
$insert = true;
//checking if was already taken
foreach($new_thematic_list as $thematic_item) {
//if ($calendar['db_date_time'] == $thematic_item['start_date'] && $calendar['attendance_id'] == $thematic_item['attendance_id'] ) {
if ($calendar['db_date_time'] == $thematic_item['start_date'] ) {
$insert = false;
break;
}
}
if ($insert == true) {
$input_select .= '<option value="'.$calendar['date_time'].'">'.$calendar['date_time'].'</option>';
}
}
$input_select .= '</select>';
} else {
@ -50,6 +80,4 @@ switch ($action) {
default:
echo '';
}
exit;
?>
exit;

@ -22,6 +22,10 @@ class Attendance
private $attendance_qualify_title;
private $attendance_weight;
// constants
const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet';
CONST UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet';
const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet';
public function __construct() {}
@ -79,20 +83,21 @@ class Attendance
* @see SortableTable#get_table_data($from)
*/
function get_attendance_data($from, $number_of_items, $column, $direction) {
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$column = intval($column);
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'ASC';
}
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$column = intval($column);
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'ASC';
}
$sql = "SELECT
att.id AS col0,
att.name AS col1,
att.description AS col2,
att.attendance_qualify_max AS col3
att.attendance_qualify_max AS col3,
att.locked AS col4
FROM $tbl_attendance att
WHERE att.active = 1 $condition_session
ORDER BY col$column $direction LIMIT $from,$number_of_items ";
@ -115,8 +120,44 @@ class Attendance
$attendance[3] = '<center>'.$attendance[3].'</center>';
if (api_is_allowed_to_edit(null, true)) {
$actions = '';
$actions .= '<center><a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[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=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a></center>';
$actions .= '<center>';
if (api_is_platform_admin()) {
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('edit.gif',get_lang('Edit')).'</a>&nbsp;';
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a>';
} else {
$is_locked_attendance = self::is_locked_attendance($attendance[0]);
if ($is_locked_attendance) {
$actions .= Display::return_icon('edit_na.gif',get_lang('Edit')).'&nbsp;';
$actions .= Display::return_icon('delete_na.gif',get_lang('Delete'));
} else {
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('edit.gif',get_lang('Edit')).'</a>&nbsp;';
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a>';
}
}
// display lock/unlock icon
$is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
if ($is_done_all_calendar) {
$locked = $attendance[4];
if ($locked == 0) {
if (api_is_platform_admin()) {
$message_alert = get_lang('AreYouSureToLockTheAttendance');
} else {
$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 {
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);
} else {
$attendance[0] = '&nbsp;';
@ -267,6 +308,28 @@ class Attendance
return $affected_rows;
}
/**
* Lock or unlock an attendance
* @param int attendance id
* @param bool True to lock or false otherwise
*/
public function lock_attendance($attendance_id, $lock = true) {
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$attendance_id = intval($attendance_id);
$locked = ($lock)?1:0;
$upd = "UPDATE $tbl_attendance SET locked = $locked WHERE id = $attendance_id";
Database::query($upd);
$affected_rows = Database::affected_rows();
if ($affected_rows && $lock) {
//save attendance sheet log
$lastedit_date = Date('Y-m-d H:i:s');
$lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE;
$lastedit_user_id = api_get_user_id();
$save_attendance_log = $this->save_attendance_sheet_log($attendance_id, $lastedit_date, $lastedit_type, $lastedit_user_id);
}
return $affected_rows;
}
/**
* Get registered users inside current course
* @param int attendance id for showing attendance result field (optional)
@ -339,6 +402,13 @@ class Attendance
$users_absent = array_diff($user_ids,$users_present);
$affected_rows = 0;
// get last edit type
$calendar_data = $this->get_attendance_calendar_by_id($calendar_id);
$lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE;
if ($calendar_data['done_attendance']) {
$lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE;
}
// save users present in class
foreach ($users_present as $user_present) {
$uid = intval($user_present);
@ -348,11 +418,11 @@ class Attendance
if (Database::num_rows($rs) == 0) {
$sql = "INSERT INTO $tbl_attendance_sheet SET user_id ='$uid', attendance_calendar_id = '$calendar_id', presence = 1";
Database::query($sql);
$affected_rows = Database::affected_rows();
$affected_rows += Database::affected_rows();
} else {
$sql = "UPDATE $tbl_attendance_sheet SET presence = 1 WHERE user_id ='$uid' AND attendance_calendar_id = '$calendar_id'";
Database::query($sql);
$affected_rows = Database::affected_rows();
$affected_rows += Database::affected_rows();
}
}
@ -365,11 +435,11 @@ class Attendance
if (Database::num_rows($rs) == 0) {
$sql = "INSERT INTO $tbl_attendance_sheet SET user_id ='$uid', attendance_calendar_id = '$calendar_id', presence = 0";
Database::query($sql);
$affected_rows = Database::affected_rows();
$affected_rows += Database::affected_rows();
} else {
$sql = "UPDATE $tbl_attendance_sheet SET presence = 0 WHERE user_id ='$uid' AND attendance_calendar_id = '$calendar_id'";
Database::query($sql);
$affected_rows = Database::affected_rows();
$affected_rows += Database::affected_rows();
}
}
@ -380,6 +450,14 @@ class Attendance
// save users' results
$this->update_users_results($user_ids, $attendance_id);
if ($affected_rows) {
//save attendance sheet log
$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);
}
return $affected_rows;
}
@ -433,6 +511,44 @@ class Attendance
Database::query($sql);
}
/**
* update attendance_sheet_log table, is used as history of an attendance sheet
* @param int Attendance id
* @param string Last edit datetime
* @param string Event type ('locked_attendance', 'done_attendance_sheet' ...)
* @param int Last edit user id
* @param string Calendar datetime value (optional, when event type is 'done_attendance_sheet')
* @return int Affected rows
*/
public function save_attendance_sheet_log($attendance_id, $lastedit_date, $lastedit_type, $lastedit_user_id, $calendar_date_value = null) {
// define table
$tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG);
// protect data
$attendance_id = intval($attendance_id);
$lastedit_date = Database::escape_string($lastedit_date);
$lastedit_type = Database::escape_string($lastedit_type);
$lastedit_user_id = intval($lastedit_user_id);
if (isset($calendar_date_value)) {
$calendar_date_value = Database::escape_string($calendar_date_value);
} else {
$calendar_date_value = '';
}
// save data
$ins = "INSERT INTO $tbl_attendance_sheet_log(attendance_id, lastedit_date, lastedit_type, lastedit_user_id, calendar_date_value)
VALUES($attendance_id, '$lastedit_date', '$lastedit_type', $lastedit_user_id, '$calendar_date_value')";
Database::query($ins);
return Database::affected_rows();
}
/**
* Get number of done attendances inside current sheet
* @param int attendance id
@ -461,16 +577,25 @@ class Attendance
$user_id = intval($user_id);
$attendance_id = intval($attendance_id);
$results = array();
$attendance_data = $this->get_attendance_by_id($attendance_id);
$attendance_data = $this->get_attendance_by_id($attendance_id);
$calendar_count = $this->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 = $total_done_attendance > 0 ?round(($faults*100)/$total_done_attendance,0):0;
$faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
$results['faults'] = $faults;
$results['total'] = $total_done_attendance;
$results['total'] = $calendar_count;
$results['faults_porcent'] = $faults_porcent;
$color_bar = '';
@ -746,6 +871,84 @@ class Attendance
}
return $data;
}
/**
* Get number of attendance calendar inside current attendance
* @param int attendance id
* @return int number of dates in attendance calendar
*/
public function get_number_of_attendance_calendar($attendance_id) {
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendance_id = intval($attendance_id);
$sql = "SELECT count(id) FROM $tbl_attendance_calendar WHERE attendance_id = '$attendance_id'";
$rs = Database::query($sql);
$row = Database::fetch_row($rs);
$count = $row[0];
return $count;
}
/**
* Get count dates inside attendance calendar by attendance id
* @param int attendance id
* @return int count of dates
*/
public function get_count_dates_inside_attendance_calendar($attendance_id) {
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendance_id = intval($attendance_id);
$sql = "SELECT count(id) FROM $tbl_attendance_calendar WHERE attendance_id = '$attendance_id'";
$rs = Database::query($sql);
$count = 0;
if (Database::num_rows($rs) > 0) {
$row = Database::fetch_row($rs);
$count = $row[0];
}
return $count;
}
/**
* check if all calendar of an attendance is done
* @param int attendance id
* @return bool True if all calendar is done, otherwise false
*/
public function is_all_attendance_calendar_done($attendance_id) {
$attendance_id = intval($attendance_id);
$done_calendar = self::get_done_attendance_calendar($attendance_id);
$count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id);
$number_of_dates = self::get_number_of_attendance_calendar($attendance_id);
$result = false;
if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) {
$result = true;
}
return $result;
}
/**
* check if an attendance is locked
* @param int attendance id
* @param bool
*/
public function is_locked_attendance($attendance_id) {
$attendance_id = intval($attendance_id);
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$sql = "SELECT id FROM $tbl_attendance WHERE id = $attendance_id AND locked = 1";
$rs = Database::query($sql);
$result = false;
if (Database::num_rows($rs) > 0) {
$result = true;
}
return $result;
}
/**
* Add new datetime inside attendance calendar table
@ -764,6 +967,15 @@ class Attendance
Database::query($sql);
$affected_rows = Database::affected_rows();
}
// update locked attendance
$is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
if (!$is_all_calendar_done) {
$unlock = self::lock_attendance($attendance_id, false);
} else {
$unlock = self::lock_attendance($attendance_id);
}
return $affected_rows;
}
@ -881,6 +1093,15 @@ class Attendance
Database::query($sql);
$affected_rows = Database::affected_rows();
}
// update locked attendance
$is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
if (!$is_all_calendar_done) {
$unlock = self::lock_attendance($attendance_id, false);
} else {
$unlock = self::lock_attendance($attendance_id);
}
return $affected_rows;
}
@ -925,7 +1146,8 @@ 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;
}

@ -2561,6 +2561,37 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
return true;
}
/**
* Gets item property by tool
* @param string course code
* @param string tool name, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!)
* @param int id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool
*/
function api_get_item_property_by_tool($tool, $course_code, $session_id = null) {
$course_info = api_get_course_info($course_code);
$tool = Database::escape_string($tool);
$ref = intval($ref);
// Definition of tables.
$item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
$session_condition = '';
$session_id = intval($session_id);
if (!empty($session_id)) {
$session_condition = ' AND id_session = '.$session_id;
}
$sql = "SELECT * FROM $item_property_table WHERE tool = '$tool' $session_condition ";
$rs = Database::query($sql);
$item_property_id = '';
$list = array();
if (Database::num_rows($rs) > 0) {
while ($row = Database::fetch_array($rs, 'ASSOC')) {
$list[] = $row;
}
}
return $list;
}
/**
* Gets item property id from tool of a course
* @param string course code
@ -2585,6 +2616,46 @@ function api_get_item_property_id($course_code, $tool, $ref) {
return $item_property_id;
}
/**
*
* Inserts a record in the track_e_item_property table (No update)
*
*/
function api_track_item_property_update($tool, $ref, $title, $content, $progress) {
$tbl_stats_item_property = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
$course_id = api_get_real_course_id(); //numeric
$course_code = api_get_course_id(); //alphanumeric
$item_property_id = api_get_item_property_id($course_code, $tool, $ref);
if (!empty($item_property_id)) {
$sql = "INSERT IGNORE INTO $tbl_stats_item_property SET
course_id = '$course_id',
item_property_id = '$item_property_id',
title = '".Database::escape_string($title)."',
content = '".Database::escape_string($content)."',
progress = '".intval($progress)."',
lastedit_date = '".api_get_utc_datetime()."',
lastedit_user_id = '".api_get_user_id()."',
session_id = '".api_get_session_id()."'";
Database::query($sql);
$affected_rows = Database::affected_rows();
return $affected_rows;
}
return false;
}
function api_get_track_item_property_history($tool, $ref) {
$tbl_stats_item_property = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
$course_id = api_get_real_course_id(); //numeric
$course_code = api_get_course_id(); //alphanumeric
$item_property_id = api_get_item_property_id($course_code, $tool, $ref);
$sql = "SELECT * FROM $tbl_stats_item_property WHERE item_property_id = $item_property_id AND course_id = $course_id ORDER BY lastedit_date DESC";
$result = Database::query($sql);
$result = Database::store_result($result,'ASSOC');
return $result;
}
/**
* Gets item property data from tool of a course id
* @param int course id

@ -13,7 +13,7 @@
* @package chamilo.course_progress
*/
class Thematic
{
{
private $session_id;
private $thematic_id;
private $thematic_title;
@ -21,7 +21,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;
@ -29,16 +29,18 @@ class Thematic
private $duration;
public function __construct() {}
/**
* Get the total number of thematic inside current course and current session
* @see SortableTable#get_total_number_of_items()
*/
public function get_number_of_thematics() {
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$condition_session = '';
if (!api_get_session_id()) {
$condition_session = api_get_session_condition(0);
}
$sql = "SELECT COUNT(id) AS total_number_of_items FROM $tbl_thematic WHERE active = 1 $condition_session ";
$res = Database::query($sql);
$res = Database::query($sql);
@ -57,51 +59,61 @@ class Thematic
*/
public function get_thematic_data($from, $number_of_items, $column, $direction) {
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$condition_session = '';
if (!api_get_session_id()) {
$condition_session = api_get_session_condition(0);
}
$column = intval($column);
$from = intval($from);
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'ASC';
}
$sql = "SELECT
id AS col0,
title AS col1,
display_order AS col2
FROM $tbl_thematic
$sql = "SELECT id AS col0, title AS col1, display_order AS col2, session_id FROM $tbl_thematic
WHERE active = 1 $condition_session
ORDER BY col2 LIMIT $from,$number_of_items ";
$res = Database::query($sql);
$thematics = array ();
$param_gradebook = '';
if (isset($_SESSION['gradebook'])) {
$param_gradebook = '&gradebook='.$_SESSION['gradebook'];
}
$user_info = api_get_user_info(api_get_user_id());
while ($thematic = Database::fetch_row($res)) {
$thematic[1] = '<a href="index.php?'.api_get_cidreq().'&action=thematic_details&thematic_id='.$thematic[0].$param_gradebook.'">'.Security::remove_XSS($thematic[1], STUDENT).'</a>';
$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>';
if (api_is_allowed_to_edit(null, true)) {
$actions = '';
$actions .= '<center><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'),'','22').'</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'),'','22').'</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 {
$actions .= Display::return_icon('up_na.png','&nbsp;','',22);
}
if ($thematic[2] < self::get_max_thematic_item()) {
$actions .= '<a href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('down.png',get_lang('Down'),'',22).'</a>';
} else {
$actions .= Display::return_icon('down_na.png','&nbsp;','',22);
if (api_get_session_id()) {
if (api_get_session_id() == $thematic[3]) {
$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></center>';
}
} else {
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 {
$actions .= Display::return_icon('up_na.png','&nbsp;','',22);
}
if ($thematic[2] < self::get_max_thematic_item()) {
$actions .= '<a href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('down.png',get_lang('Down'),'',22).'</a>';
} else {
$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></center>';
}
$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></center>';
$thematics[] = array($thematic[0], $thematic[1], $actions);
}
}
@ -196,7 +208,7 @@ class Thematic
} else {
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
}
if (isset($session_id)) {
$session_id = intval($session_id);
} else {
@ -209,16 +221,19 @@ class Thematic
$thematic_id = intval($thematic_id);
$condition = " WHERE id = $thematic_id ";
} else {
$condition_session = api_get_session_condition($session_id);
$condition_session = '';
if (empty($session_id)) {
$condition_session = api_get_session_condition(0);
}
$condition = " WHERE active = 1 $condition_session ";
}
$sql = "SELECT * FROM $tbl_thematic $condition ORDER BY display_order ";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
if (!empty($thematic_id)) {
$data = Database::fetch_array($res);
$data = Database::fetch_array($res,'ASSOC');
} else {
while ($row = Database::fetch_array($res)) {
while ($row = Database::fetch_array($res,'ASSOC')) {
$data[$row['id']] = $row;
}
}
@ -311,7 +326,7 @@ class Thematic
*/
public function get_number_of_thematic_advances() {
global $thematic_id;
$tbl_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
$tbl_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
$sql = "SELECT COUNT(id) AS total_number_of_items FROM $tbl_thematic_advance WHERE thematic_id = $thematic_id ";
$res = Database::query($sql);
$res = Database::query($sql);
@ -333,17 +348,13 @@ class Thematic
$tbl_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
$thematic_data = self::get_thematic_list($thematic_id);
$column = intval($column);
$from = intval($from);
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'ASC';
}
$sql = "SELECT
id AS col0,
start_date AS col1,
duration AS col2,
content AS col3
FROM $tbl_thematic_advance
$sql = "SELECT id AS col0, start_date AS col1, duration AS col2, content AS col3 FROM $tbl_thematic_advance
WHERE thematic_id = $thematic_id
ORDER BY col$column $direction LIMIT $from,$number_of_items ";
$res = Database::query($sql);
@ -380,7 +391,7 @@ class Thematic
}
$thematic_id = intval($thematic_id);
$data = array();
$data = array();
$sql = "SELECT * FROM $tbl_thematic_advance WHERE thematic_id = $thematic_id ";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
@ -397,13 +408,14 @@ class Thematic
* @param string Course code (optional)
* @return array data
*/
public function get_thematic_advance_list($thematic_advance_id = null, $course_code = null) {
// set current course
public function get_thematic_advance_list($thematic_advance_id = null, $course_code = null, $force_session_id = false) { // set current course
if (isset($course_code)) {
$course_info = api_get_course_info($course_code);
$tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE, $course_info['dbName']);
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC,$course_info['dbName']);
} else {
$tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
}
$data = array();
@ -411,13 +423,16 @@ class Thematic
$condition = '';
if (isset($thematic_advance_id)) {
$thematic_advance_id = intval($thematic_advance_id);
$condition = " WHERE id = $thematic_advance_id ";
$condition = " AND a.id = $thematic_advance_id ";
}
$sql = "SELECT * FROM $tbl_thematic_advance $condition ORDER BY start_date ";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
if (!empty($thematic_advance_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 session_id = ".api_get_session_id()." ORDER BY start_date ";
} else {
$sql = "SELECT * FROM $tbl_thematic_advance a WHERE 1 $condition ORDER BY start_date ";
}
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
if (!empty($thematic_advance_id)) {
$data = Database::fetch_array($res);
} else {
// group all data group by thematic id
@ -430,51 +445,46 @@ class Thematic
}
}
}
return $data;
}
/**
* insert or update a thematic advance
* @todo problem
* @return int last thematic advance id
*/
public function thematic_advance_save() {
global $_course;
global $_course;
// definition database table
$tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
// protect data
$id = intval($this->thematic_advance_id);
$tematic_id = intval($this->thematic_id);
$attendance_id = intval($this->attendance_id);
$content = Database::escape_string($this->thematic_advance_content);
$start_date = Database::escape_string($this->start_date);
$duration = intval($this->duration);
$user_id = api_get_user_id();
if (empty($id)) {
// insert
$sql = "INSERT INTO $tbl_thematic_advance (thematic_id, attendance_id, content, start_date, duration) VALUES ($tematic_id, $attendance_id, '$content', '".api_get_utc_datetime($start_date)."', $duration) ";
$id = intval($this->thematic_advance_id);
$tematic_id = intval($this->thematic_id);
$attendance_id = intval($this->attendance_id);
$content = Database::escape_string($this->thematic_advance_content);
$start_date = Database::escape_string($this->start_date);
$duration = intval($this->duration);
$user_id = api_get_user_id();
if (empty($id)) {
// Insert
$sql = "INSERT INTO $tbl_thematic_advance (thematic_id, attendance_id, content, start_date, duration) VALUES ($tematic_id, $attendance_id, '$content', '".api_get_utc_datetime($start_date)."', '$duration') ";
Database::query($sql);
$last_id = Database::insert_id();
if (Database::affected_rows()) {
api_item_property_update($_course, 'thematic_advance', $last_id,"ThematicAdvanceAdded", $user_id);
}
if (Database::affected_rows()) {
api_item_property_update($_course, 'thematic_advance', $last_id,"ThematicAdvanceAdded", $user_id);
}
} 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 WHERE id = $id ";
Database::query($sql);
$last_id = $id;
if (Database::affected_rows()) {
api_item_property_update($_course, 'thematic_advance', $last_id,"ThematicAdvanceUpdated", $user_id);
}
$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 id = $id ";
Database::query($sql);
if (Database::affected_rows()) {
api_item_property_update($_course, 'thematic_advance', $id, "ThematicAdvanceUpdated", $user_id);
}
}
return $last_id;
}
/**
@ -495,9 +505,9 @@ class Thematic
$sql = "DELETE FROM $tbl_thematic_advance WHERE id = $thematic_advance_id ";
Database::query($sql);
$affected_rows = Database::affected_rows();
if ($affected_rows) {
api_item_property_update($_course, 'thematic_advance', $thematic_advance_id,"ThematicAdvanceDeleted", $user_id);
}
if ($affected_rows) {
api_item_property_update($_course, 'thematic_advance', $thematic_advance_id,"ThematicAdvanceDeleted", $user_id);
}
return $affected_rows;
}
@ -512,6 +522,8 @@ class Thematic
// definition database table
$tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
$data = array();
$condition = '';
if (isset($thematic_id)) {
@ -522,23 +534,31 @@ class Thematic
$description_type = intval($description_type);
$condition .= " AND description_type = $description_type ";
}
$sql = "SELECT * FROM $tbl_thematic_plan WHERE 1 $condition";
$session_condition = '';
if (!api_get_session_id()) {
$session_condition .= ' AND t.session_id = 0';
}
$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)
WHERE 1 $condition $session_condition ";
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if (!isset($thematic_id) && !isset($description_type)) {
if (Database::num_rows($rs) > 0) {
if (!isset($thematic_id) && !isset($description_type)) {
// group all data group by thematic id
$tmp = array();
while ($row = Database::fetch_array($rs)) {
$tmp[] = $row['thematic_id'];
if (in_array($row['thematic_id'], $tmp)) {
$data[$row['thematic_id']][$row['id']] = $row;
}
}
} else {
while ($row = Database::fetch_array($rs)) {
while ($row = Database::fetch_array($rs,'ASSOC')) {
$tmp[] = $row['thematic_id'];
if (in_array($row['thematic_id'], $tmp)) {
$data[$row['thematic_id']][$row['description_type']] = $row;
}
}
} else {
while ($row = Database::fetch_array($rs,'ASSOC')) {
$data[] = $row;
}
}
}
}
return $data;
@ -549,18 +569,17 @@ class Thematic
* @return int affected rows
*/
public function thematic_plan_save() {
global $_course;
// definition database table
global $_course;
// 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();
$session_id = api_get_session_id();
// check thematic plan type already exists
$sql = "SELECT id FROM $tbl_thematic_plan WHERE thematic_id = $thematic_id AND description_type = $description_type ";
@ -568,8 +587,8 @@ class Thematic
$affected_rows = 0;
if (Database::num_rows($rs) > 0) {
$row_thematic_plan = Database::fetch_array($rs);
$thematic_plan_id = $row_thematic_plan['id'];
$row_thematic_plan = Database::fetch_array($rs);
$thematic_plan_id = $row_thematic_plan['id'];
// update
$upd = "UPDATE $tbl_thematic_plan SET title = '$title', description = '$description' WHERE thematic_id = $thematic_id AND description_type = $description_type ";
Database::query($upd);
@ -659,15 +678,29 @@ class Thematic
* @param int Thematic id
* @return int Affected rows
*/
public function update_done_thematic_advances ($thematic_advance_id) {
public function update_done_thematic_advances($thematic_advance_id) {
global $_course;
$thematic_data = $this->get_thematic_list();
$thematic_advance_data = $this->get_thematic_advance_list();
$thematic_advance_data = $this->get_thematic_advance_list(null, api_get_course_id(), true);
$tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$affected_rows = 0;
$user_id = api_get_user_id();
$user_id = api_get_user_id();
$all = array();
if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) {
$thematic_id = $thematic['id'];
if (!empty($thematic_advance_data[$thematic['id']])) {
foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
$all[] = $thematic_advance['id'];
}
}
}
}
$a_thematic_advance_ids = array();
if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) {
@ -679,9 +712,9 @@ class Thematic
$upd = "UPDATE $tbl_thematic_advance set done_advance = 1 WHERE id = ".$thematic_advance['id']." ";
Database::query($upd);
$affected_rows += Database::affected_rows();
if (Database::affected_rows()) {
api_item_property_update($_course, 'thematic_advance', $thematic_advance['id'],"ThematicAdvanceDone", $user_id);
}
if (Database::affected_rows()) {
api_item_property_update($_course, 'thematic_advance', $thematic_advance['id'],"ThematicAdvanceDone", $user_id);
}
if ($thematic_advance['id'] == $thematic_advance_id) {
break 2;
}
@ -692,20 +725,23 @@ class Thematic
// Update done thematic for others advances (done_advance = 0)
if (!empty($a_thematic_advance_ids) && count($a_thematic_advance_ids) > 0) {
$upd = "UPDATE $tbl_thematic_advance set done_advance = 0 WHERE id NOT IN(".implode(',',$a_thematic_advance_ids).") ";
Database::query($upd);
// update item_property
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
// get all thematic advance done
$rs_thematic_done = Database::query("SELECT ref FROM $tbl_item_property WHERE tool='thematic_advance' AND lastedit_type='ThematicAdvanceDone'");
if (Database::num_rows($rs_thematic_done) > 0) {
while ($row_thematic_done = Database::fetch_array($rs_thematic_done)) {
$ref = $row_thematic_done['ref'];
if (in_array($ref, $a_thematic_advance_ids)) { continue; }
// update items
Database::query("UPDATE $tbl_item_property SET lastedit_date='".date('Y-m-d H:i:s', time())."', lastedit_type='ThematicAdvanceUpdated', lastedit_user_id = $user_id WHERE tool='thematic_advance' AND ref=$ref");
}
}
$diff = array_diff($all, $a_thematic_advance_ids);
if (!empty($diff)) {
$upd = "UPDATE $tbl_thematic_advance set done_advance = 0 WHERE id IN(".implode(',',$diff).") ";
Database::query($upd);
}
// update item_property
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
// get all thematic advance done
$rs_thematic_done = Database::query("SELECT ref FROM $tbl_item_property WHERE tool='thematic_advance' AND lastedit_type='ThematicAdvanceDone'");
if (Database::num_rows($rs_thematic_done) > 0) {
while ($row_thematic_done = Database::fetch_array($rs_thematic_done)) {
$ref = $row_thematic_done['ref'];
if (in_array($ref, $a_thematic_advance_ids)) { continue; }
// update items
Database::query("UPDATE $tbl_item_property SET lastedit_date='".date('Y-m-d H:i:s', time())."', lastedit_type='ThematicAdvanceUpdated', lastedit_user_id = $user_id WHERE tool='thematic_advance' AND ref=$ref");
}
}
}
return $affected_rows;

Loading…
Cancel
Save