2nd attempt to support sessions in Course progress see BT#2662

skala
Julio Montoya 15 years ago
parent 55bdcabdf6
commit a4d67f9c61
  1. 1
      main/attendance/index.php
  2. 31
      main/course_progress/index.php
  3. 114
      main/course_progress/thematic.php
  4. 10
      main/course_progress/thematic_advance.php
  5. 190
      main/course_progress/thematic_controller.php
  6. 7
      main/course_progress/thematic_plan.php
  7. 123
      main/inc/ajax/thematic.ajax.php
  8. 9
      main/inc/lib/main_api.lib.php
  9. 11
      main/inc/lib/security.lib.php
  10. 322
      main/inc/lib/thematic.lib.php

@ -4,7 +4,6 @@
/**
* Template (front controller in MVC pattern) used for distpaching to the controllers depend on the current action
* @author Christian Fasanando <christian1827@gmail.com>
* @author Carlos Vargas (link to attendance tool )<litox84@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> Bug fixing, sql improvements
*
* @package chamilo.attendance

@ -4,6 +4,7 @@
/**
* Template (front controller in MVC pattern) used for distpaching to the controllers depend on the current action
* @author Christian Fasanando <christian1827@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> Bugfixes session support
* @package chamilo.course_progress
*/
@ -15,7 +16,6 @@ require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'attendance.lib.php';
require_once api_get_path(LIBRARY_PATH).'thematic.lib.php';
require_once api_get_path(LIBRARY_PATH).'app_view.php';
//require_once 'attendance_controller.php';
require_once 'thematic_controller.php';
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'course.lib.php';
@ -29,7 +29,6 @@ $this_section = SECTION_COURSES;
// protect a course script
api_protect_course_script(true);
// defining constants
define('ADD_THEMATIC_PLAN', 6);
@ -101,10 +100,10 @@ function update_done_thematic_advance(selected_value) {
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {},
type: "GET",
url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=update_done_thematic_advance&thematic_advance_id="+selected_value,
url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=update_done_thematic_advance",
data: "thematic_advance_id="+selected_value,
success: function(datos) {
$("#div_result").html(datos);
success: function(data) {
$("#div_result").html(data);
}
});
@ -147,12 +146,6 @@ function check_per_custom_date(obj) {
</script>';
// interbreadcrumbs
//$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=thematic_details'.$param_gradebook.$student_param, 'name' => get_lang('ToolAttendance'));
//if ($action == 'attendance_add') {
//$interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('CreateANewAttendance'));
//}
if ($action == 'thematic_list') {
$interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('ThematicControl'));
}
@ -169,11 +162,11 @@ if ($action == 'thematic_details') {
}
if ($action == 'thematic_plan_list' || $action == 'thematic_plan_delete') {
$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action='.$_SESSION['thematic_control'], 'name' => get_lang('ThematicControl'));
$interbreadcrumb[] = array ('url' => '#', 'name' => $thematic_data['title'].':'.get_lang('ThematicPlan'));
$interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('ThematicPlan').' ('.$thematic_data['title'].') ');
}
if ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action='.$_SESSION['thematic_control'], 'name' => get_lang('ThematicControl'));
$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$thematic_id, 'name' => $thematic_data['title'].':'.get_lang('ThematicPlan'));
$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$thematic_id, 'name' => get_lang('ThematicPlan').' ('.$thematic_data['title'].')');
if ($description_type >= ADD_THEMATIC_PLAN) {
$interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('NewBloc'));
} else {
@ -182,17 +175,16 @@ if ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
}
if ($action == 'thematic_advance_list' || $action == 'thematic_advance_delete') {
$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action='.$_SESSION['thematic_control'], 'name' => get_lang('ThematicControl'));
$interbreadcrumb[] = array ('url' => '#', 'name' => $thematic_data['title'].':'.get_lang('ThematicAdvance'));
$interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('ThematicAdvance').' ('.$thematic_data['title'].')');
}
if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action='.$_SESSION['thematic_control'], 'name' => get_lang('ThematicControl'));
$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$thematic_id, 'name' => $thematic_data['title'].':'.get_lang('ThematicAdvance'));
$interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$thematic_id, 'name' => get_lang('ThematicAdvance').' ('.$thematic_data['title'].')');
$interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('NewThematicAdvance'));
}
// distpacher actions to controller
// Distpacher actions to controller
switch ($action) {
case 'thematic_add' :
case 'thematic_edit' :
@ -200,8 +192,7 @@ switch ($action) {
case 'thematic_delete_select' :
case 'thematic_copy' :
case 'moveup' :
case 'movedown' :
case 'movedown' :
if (!api_is_allowed_to_edit(null,true)) {
api_not_allowed();
}

@ -11,6 +11,9 @@
// protect a course script
api_protect_course_script(true);
$token = Security::get_token();
$url_token = "&sec_token=".$token;
if (api_is_allowed_to_edit(null, true)) {
echo '<div class="actions" style="margin-bottom:30px">';
@ -21,19 +24,19 @@ if (api_is_allowed_to_edit(null, true)) {
//echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_list">'.Display::return_icon('view_list.gif',get_lang('ThematicList')).' '.get_lang('ThematicList').'</a>';//TODO:delete, no need
break;
case 'thematic_list' :
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_details">'.Display::return_icon('view_detailed.png',get_lang('ThematicDetails'),'','32').'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
//echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_details">'.Display::return_icon('view_detailed.png',get_lang('ThematicDetails'),'','32').'</a>';
//echo '<strong>'.Display::return_icon('view_list.gif',get_lang('ThematicList')).' '.get_lang('ThematicList').'</strong>&nbsp;&nbsp;';//TODO:delete, no need
break;
case 'thematic_details' :
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
//echo '<strong>'.Display::return_icon('view_table.gif',get_lang('ThematicDetails')).' '.get_lang('ThematicDetails').'</strong>&nbsp;&nbsp;';////TODO:delete, no need
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_list">'.Display::return_icon('view_text.png',get_lang('ThematicList'),'','32').'</a>';
//echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_list">'.Display::return_icon('view_text.png',get_lang('ThematicList'),'','32').'</a>';
break;
default :
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_details">'.Display::return_icon('view_detailed.png',get_lang('ThematicDetails'),'','32').'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_list">'.Display::return_icon('view_text.png',get_lang('ThematicList'),'','32').'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
//echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_details">'.Display::return_icon('back.png',get_lang('ThematicDetails'),'','32').'</a>';
//echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_list">'.Display::return_icon('view_text.png',get_lang('ThematicList'),'','32').'</a>';
}
echo '</div>';
}
@ -54,7 +57,7 @@ if ($action == 'thematic_list') {
//echo '<div><strong>'.get_lang('ThematicList').'</strong></div><br />';
$table->display();
} else if ($action == 'thematic_details') {
} elseif ($action == 'thematic_details') {
if ($last_id) {
$link_to_thematic_plan = '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$last_id.'">'.Display::return_icon('lesson_plan.png', get_lang('ThematicPlan'), array('style'=>'vertical-align:middle'),22).'</a>';
@ -64,9 +67,7 @@ if ($action == 'thematic_list') {
// display title
if (!empty($thematic_id)) {
//echo '<div><strong>'.Security::remove_XSS($thematic_data[$thematic_id]['title'], STUDENT).': '.get_lang('Details').'</strong></div><br />';
} else {
//echo '<div><strong>'.get_lang('ThematicDetails').'</strong></div><br />';
} else {
// display information
$message = '<strong>'.get_lang('Information').'</strong><br />';
$message .= get_lang('ThematicDetailsDescription');
@ -74,7 +75,8 @@ if ($action == 'thematic_list') {
echo '<br />';
}
// display thematic data
// display thematic data
if (!empty($thematic_data)) {
// display progress
@ -84,21 +86,53 @@ if ($action == 'thematic_list') {
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) {
$my_thematic_id = $thematic['id'];
$session_star = '';
if (api_is_allowed_to_edit(null, true)) {
if (api_get_session_id() == $thematic['session_id']) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
}
}
//@todo add a validation in order to load or not course thematics in the session thematic
/*
if (api_get_session_id() == $thematic['session_id']) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
} else {
continue;
}
} */
echo '<tr>';
// display thematic title
echo '<td><h2>'.Security::remove_XSS($thematic['title'], STUDENT).$session_star.'</h2><div>'.Security::remove_XSS($thematic['content'], STUDENT).'</div></td>';
$actions_first_col = '';
if (api_is_allowed_to_edit(null, true)) {
// Thematic title
$actions_first_col = Display::url(Display::return_icon('cd.gif', get_lang('Copy')), 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$my_thematic_id.$param_gradebook.$url_token);
if (api_get_session_id() == 0 ) {
if ($thematic['display_order'] > 1) {
$actions_first_col .= ' <a href="'.api_get_self().'?action=moveup&'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('up.png', get_lang('Up'),'',22).'</a>';
} else {
$actions_first_col .= ' '.Display::return_icon('up_na.png','&nbsp;','',22);
}
if ($thematic['display_order'] < $thematic['max_thematic_item']) {
$actions_first_col .= ' <a href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('down.png',get_lang('Down'),'',22).'</a>';
} else {
$actions_first_col .= ' '.Display::return_icon('down_na.png','&nbsp;','',22);
}
}
if (api_get_session_id() == $thematic['session_id']) {
$actions_first_col .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
$actions_first_col .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a>';
}
}
echo Display::tag('td', Display::tag('h2', Security::remove_XSS($thematic['title'], STUDENT).$session_star).Security::remove_XSS($thematic['content'], STUDENT).$actions_first_col);
// display thematic plan data
echo '<td>';
if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
//if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
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 />';
}
@ -118,12 +152,18 @@ if ($action == 'thematic_list') {
}
}
$no_data = true;
$session_star = '';
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 (!empty($thematic_plan_data[$thematic['id']][$id]['title']) && !empty($thematic_plan_data[$thematic['id']][$id]['description'])) {
echo '<h3>'.Security::remove_XSS($thematic_plan_data[$thematic['id']][$id]['title'], STUDENT).'</h3><div>';
if (!empty($thematic_plan_data[$thematic['id']][$id]['title']) && !empty($thematic_plan_data[$thematic['id']][$id]['description'])) {
if (api_is_allowed_to_edit(null, true)) {
if ($thematic_plan_data[$thematic['id']][$id]['session_id'] !=0) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
}
}
echo Display::tag('h3', Security::remove_XSS($thematic_plan_data[$thematic['id']][$id]['title'], STUDENT).$session_star);
echo Security::remove_XSS($thematic_plan_data[$thematic['id']][$id]['description'], STUDENT).'</div>';
$no_data = false;
} else {
@ -138,8 +178,9 @@ if ($action == 'thematic_list') {
echo '</td>';
// display thematic advance data
echo '<td>';
if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
echo '<td>';
//if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
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 />';
}
@ -151,25 +192,38 @@ if ($action == 'thematic_list') {
$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>';
$session_star = '';
if (api_is_allowed_to_edit(null, true)) {
if ($thematic_advance['session_id'] !=0) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
}
}
echo '<div><strong>'.$thematic_advance['start_date'].$session_star.'</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 (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
if (api_is_allowed_to_edit(null, true)) {
if (empty($thematic_id)) {
$checked = '';
if ($last_done_thematic_advance == $thematic_advance['id']) {
$checked = 'checked';
}
$style = '';
if ($thematic_advance['done_advance'] == 1) {
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>';
echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center>';
echo '<input type="radio" id="done_thematic_'.$thematic_advance['id'].'" name="done_thematic" value="'.$thematic_advance['id'].'" '.$checked.' onclick="update_done_thematic_advance(this.value)">';
echo '</center></td>';
} else {
if ($thematic_advance['done_advance'] == 1) {
echo '<td><center>'.get_lang('Done').'</center></td>';
} else {
@ -191,12 +245,6 @@ if ($action == 'thematic_list') {
echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
}
} else if ($action == 'thematic_add' || $action == 'thematic_edit') {
if (!$error) {
//@todo why the heck you create your token? use Security::get_token()! jm
$token = md5(uniqid(rand(),TRUE));
$_SESSION['thematic_token'] = $token;
}
// Display form
$form = new FormValidator('thematic_add','POST','index.php?action=thematic_add&'.api_get_cidreq());
@ -205,7 +253,7 @@ if ($action == 'thematic_list') {
$form->addElement('header', '', get_lang('EditThematicSection'));
}
$form->addElement('hidden', 'thematic_token',$token);
$form->addElement('hidden', 'sec_token', $token);
$form->addElement('hidden', 'action', $action);
if (!empty($thematic_id)) {

@ -4,13 +4,14 @@
/**
* View (MVC patter) for thematic advance
* @author Christian Fasanando <christian1827@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2011 Bug fixing
* @package chamilo.course_progress
*/
// protect a course script
api_protect_course_script(true);
if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
$header_form = get_lang('NewThematicAdvance');
if ($action == 'thematic_advance_edit') {
@ -129,9 +130,6 @@ if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
if (api_is_allowed_to_edit(null, true)) {
$table->set_header(4, get_lang('Actions'), false,array('style'=>'text-align:center'));
}
}
$table->display();
}
?>
}

@ -7,6 +7,7 @@
* !!! WARNING !!! : ALL DATES IN THIS MODULE ARE STORED IN UTC ! DO NOT CONVERT DURING THE TRANSITION FROM CHAMILO 1.8.x TO 2.0
*
* @author Christian Fasanando <christian1827@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> token support improving UI
* @package chamilo.course_progress
*/
@ -33,95 +34,111 @@ class ThematicController
* render to thematic.php
*/
public function thematic($action) {
$thematic= new Thematic();
$data = array();
$error = false;
$msg_add = false;
$thematic = new Thematic();
$data = array();
$error = false;
$msg_add = false;
// insert or update a thematic
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']) {
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 {
$error = true;
$data['error'] = $error;
$data['action'] = $_POST['action'];
$data['thematic_id'] = $_POST['thematic_id'];
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic');
$this->view->render();
}
}
}
$check = Security::check_token('request');
$thematic_id = isset($_REQUEST['thematic_id'])?intval($_REQUEST['thematic_id']):null;
//Copy a thematic to a session
if ($action == 'thematic_copy') {
$thematic->copy($_REQUEST['thematic_id']);
$action = 'thematic_list';
}
// delete many thematics
if ($action == 'thematic_delete_select') {
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';
}
if ($check) {
switch ($action) {
case 'thematic_add':
case 'thematic_edit':
// insert or update a thematic
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (trim($_POST['title']) !== '') {
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';
$thematic_id = null;
if ($last_id) {
$data['last_id'] = $last_id;
}
} else {
$action = 'thematic_details';
$thematic_id = null;
}
}
} else {
$error = true;
$data['error'] = $error;
$data['action'] = $_POST['action'];
$data['thematic_id'] = $_POST['thematic_id'];
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic');
$this->view->render();
}
}
break;
case 'thematic_copy':
//Copy a thematic to a session
$thematic->copy($thematic_id);
$thematic_id = null;
$action = 'thematic_details';
break;
case 'thematic_delete_select':
//Delete many thematics
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_details';
}
break;
case 'thematic_delete':
// Delete a thematic
if (isset($thematic_id)) {
if (api_is_allowed_to_edit(null, true)) {
$affected_rows = $thematic->thematic_destroy($thematic_id);
}
$thematic_id = null;
$action = 'thematic_details';
}
break;
case 'moveup':
$thematic->move_thematic('up', $thematic_id);
$action = 'thematic_details';
$thematic_id = null;
break;
case 'movedown':
$thematic->move_thematic('down', $thematic_id);
$action = 'thematic_details';
$thematic_id = null;
break;
}
Security::clear_token();
} else {
$action = 'thematic_details';
$thematic_id = null;
}
$thematic_id = isset($_GET['thematic_id'])?intval($_GET['thematic_id']):null;
if (isset($thematic_id)) {
// delete a thematic
if ($action == 'thematic_delete') {
if (api_is_allowed_to_edit(null, true)) {
$affected_rows = $thematic->thematic_destroy($thematic_id);
}
$action = 'thematic_list';
}
// move thematic
if ($action == 'moveup') {
$thematic->move_thematic('up', $thematic_id);
$action = 'thematic_list';
} else if ($action == 'movedown') {
$thematic->move_thematic('down', $thematic_id);
$action = 'thematic_list';
}
if (isset($thematic_id)) {
$data['thematic_data'] = $thematic->get_thematic_list($thematic_id);
$data['thematic_id'] = $thematic_id;
}
if ($action == 'thematic_details') {
if ($action == 'thematic_details') {
if (isset($thematic_id)) {
$thematic_data[$thematic_id] = $thematic->get_thematic_list($thematic_id);
$thematic_data_result = $thematic->get_thematic_list($thematic_id);
if (!empty($thematic_data_result)) {
$thematic_data[$thematic_id] = $thematic_data_result;
}
$data['total_average_of_advances'] = $thematic->get_average_of_advances_by_thematic($thematic_id);
} else {
$thematic_data = $thematic->get_thematic_list(null, api_get_course_id(), api_get_session_id());
$thematic_data = $thematic->get_thematic_list(null, api_get_course_id(), api_get_session_id());
$data['max_thematic_item'] = $thematic->get_max_thematic_item();
$data['last_done_thematic_advance'] = $thematic->get_last_done_thematic_advance();
$data['total_average_of_advances'] = $thematic->get_total_average_of_thematic_advances();
@ -131,15 +148,14 @@ class ThematicController
$thematic_plan_data = $thematic->get_thematic_plan_data();
//Third column
$thematic_advance_data = $thematic->get_thematic_advance_list();
$thematic_advance_data = $thematic->get_thematic_advance_list(null, null, true);
$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['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['action'] = $action;
// render to the view
@ -360,12 +376,12 @@ class ThematicController
}
}
$data['action'] = $action;
$data['thematic_id'] = $thematic_id;
$data['thematic_advance_id'] = $thematic_advance_id;
$data['attendance_select'] = $attendance_select;
$data['action'] = $action;
$data['thematic_id'] = $thematic_id;
$data['thematic_advance_id'] = $thematic_advance_id;
$data['attendance_select'] = $attendance_select;
$data['thematic_advance_data'] = $thematic_advance_data;
$data['calendar_select'] = $calendar_select;
$data['calendar_select'] = $calendar_select;
// render to the view
$this->view->set_data($data);

@ -130,9 +130,6 @@ if ($action == 'thematic_plan_list') {
// error messages
if ($error) {
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
}
}
$form->display();
}
?>
}

@ -14,71 +14,74 @@ $action = $_GET['a'];
switch ($action) {
case 'get_datetime_by_attendance':
$attendance_id = intval($_POST['attendance_id']);
$attendance_id = intval($_POST['attendance_id']);
$thematic_advance_id = intval($_POST['thematic_advance_id']);
$label = '';
$input_select = '';
if (!empty($attendance_id)) {
$attendance = new Attendance();
$thematic = new Thematic();
$thematic_list = $thematic->get_thematic_list();
$thematic_advance_id = intval($_POST['thematic_advance_id']);
$label = '';
$input_select = '';
if (!empty($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']);
$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) {
$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;
}
}
}
$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) {
$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>';
}
if ($insert == true) {
$input_select .= '<option value="'.$calendar['date_time'].'">'.$calendar['date_time'].'</option>';
}
$input_select .= '</select>';
} else {
$input_select .= '<em>'.get_lang('ThereAreNoRegisteredDatetimeYet').'</em>';
}
}
?>
<div class="row">
<div class="label"><?php echo $label ?></div>
<div class="formw"><?php echo $input_select ?></div>
</div>
<?php
break;
case 'update_done_thematic_advance':
$thematic_advance_id = intval($_GET['thematic_advance_id']);
$total_avererage = 0;
if (!empty($thematic_advance_id)) {
$thematic = new Thematic();
$affected_rows = $thematic->update_done_thematic_advances($thematic_advance_id);
$total_avererage = $thematic->get_total_average_of_thematic_advances(api_get_course_id(), api_get_session_id());
$input_select .= '</select>';
} else {
$input_select .= '<em>'.get_lang('ThereAreNoRegisteredDatetimeYet').'</em>';
}
echo $total_avererage;
break;
}
?>
<div class="row">
<div class="label"><?php echo $label ?></div>
<div class="formw"><?php echo $input_select ?></div>
</div>
<?php
break;
case 'update_done_thematic_advance':
$thematic_advance_id = intval($_GET['thematic_advance_id']);
$total_average = 0;
if (!empty($thematic_advance_id)) {
$thematic = new Thematic();
$affected_rows = $thematic->update_done_thematic_advances($thematic_advance_id);
//if ($affected_rows) {
$total_average = $thematic->get_total_average_of_thematic_advances(api_get_course_id(), api_get_session_id());
//}
}
echo $total_average;
break;
default:
echo '';
}

@ -2615,9 +2615,8 @@ function api_get_item_property_by_tool($tool, $course_code, $session_id = null)
$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;
}
$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 = '';
@ -2640,11 +2639,11 @@ function api_get_item_property_id($course_code, $tool, $ref) {
$course_info = api_get_course_info($course_code);
$tool = Database::escape_string($tool);
$ref = intval($ref);
$ref = intval($ref);
// Definition of tables.
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
$sql = "SELECT id FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = '$ref' ";
$sql = "SELECT id FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = '$ref'";
$rs = Database::query($sql);
$item_property_id = '';
if (Database::num_rows($rs) > 0) {

@ -104,8 +104,13 @@ class Security {
* @param string The array in which to get the token ('get' or 'post')
* @return bool True if it's the right token, false otherwise
*/
public static function check_token($array = 'post') {
switch ($array) {
public static function check_token($request_type = 'post') {
switch ($request_type) {
case 'request':
if (isset($_SESSION['sec_token']) && isset($_REQUEST['sec_token']) && $_SESSION['sec_token'] === $_REQUEST['sec_token']) {
return true;
}
return false;
case 'get':
if (isset($_SESSION['sec_token']) && isset($_GET['sec_token']) && $_SESSION['sec_token'] === $_GET['sec_token']) {
return true;
@ -117,7 +122,7 @@ class Security {
}
return false;
default:
if (isset($_SESSION['sec_token']) && isset($array) && $_SESSION['sec_token'] === $array) {
if (isset($_SESSION['sec_token']) && isset($request_type) && $_SESSION['sec_token'] === $request_type) {
return true;
}
return false;

@ -95,7 +95,7 @@ class Thematic
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'),'','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;';
@ -138,14 +138,17 @@ class Thematic
* Get the maximum display order of the thematic item
* @return int Maximum display order
*/
public function get_max_thematic_item() {
public function get_max_thematic_item($use_session = true) {
// Database table definition
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$session_id = api_get_session_id();
if ($use_session) {
$condition_session = api_get_session_condition($session_id);
} else {
$condition_session = '';
}
$sql = "SELECT MAX(display_order) FROM $tbl_thematic WHERE active = 1 $condition_session";
$rs = Database::query($sql);
$dsp=0;
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
return $row[0];
}
@ -224,7 +227,7 @@ class Thematic
}
if (isset($session_id)) {
$session_id = intval($session_id);
$session_id = intval($session_id);
} else {
$session_id = api_get_session_id();
}
@ -233,7 +236,7 @@ class Thematic
$condition = '';
if (isset($thematic_id)) {
$thematic_id = intval($thematic_id);
$condition = " WHERE id = $thematic_id ";
$condition = " WHERE id = $thematic_id AND active = 1 ";
} else {
$condition_session = '';
if (empty($session_id)) {
@ -242,6 +245,7 @@ class Thematic
$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)) {
@ -253,7 +257,6 @@ class Thematic
}
}
return $data;
}
/**
@ -273,8 +276,8 @@ class Thematic
$user_id = api_get_user_id();
// get the maximum display order of all the glossary items
$max_thematic_item = $this->get_max_thematic_item();
$max_thematic_item = $this->get_max_thematic_item(false);
if (empty($id)) {
// insert
$sql = "INSERT INTO $tbl_thematic(title, content, active, display_order, session_id) VALUES ('$title', '$content', 1, ".(intval($max_thematic_item)+1).", $session_id) ";
@ -393,23 +396,35 @@ class Thematic
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
WHERE thematic_id = $thematic_id
ORDER BY col$column $direction LIMIT $from,$number_of_items ";
$res = Database::query($sql);
$data = array ();
$i = 1;
while ($thematic_advance = Database::fetch_row($res)) {
$thematic_advance[1] = api_get_local_time($thematic_advance[1]);
$thematic_advance[1] = api_format_date($thematic_advance[1], DATE_TIME_FORMAT_LONG);
if (api_is_allowed_to_edit(null, true)) {
$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);
}
$i++;
$data = array();
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 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);
$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);
$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);
$i++;
}
}
}
return $data;
}
@ -433,10 +448,19 @@ class Thematic
$thematic_id = intval($thematic_id);
$data = array();
$sql = "SELECT * FROM $tbl_thematic_advance WHERE 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)) {
$data[] = $row;
while ($row = Database::fetch_array($res, 'ASSOC')) {
if (in_array($row['id'], $elements)) {
$data[] = $row;
}
}
}
return $data;
@ -449,8 +473,8 @@ class Thematic
* @return array data
*/
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);
$course_info = api_get_course_info($course_code);
if (isset($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 {
@ -465,11 +489,23 @@ class Thematic
$thematic_advance_id = intval($thematic_advance_id);
$condition = " AND a.id = $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 ";
/*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 {
$sql = "SELECT * FROM $tbl_thematic_advance a WHERE 1 $condition ORDER BY start_date ";
}
}*/
$sql = "SELECT * FROM $tbl_thematic_advance a WHERE 1 $condition ORDER BY start_date ";
$elements = array();
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;
}
}
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
if (!empty($thematic_advance_id)) {
@ -477,11 +513,20 @@ class Thematic
} else {
// group all data group by thematic id
$tmp = array();
while ($row = Database::fetch_array($res)) {
while ($row = Database::fetch_array($res, 'ASSOC')) {
$tmp[] = $row['thematic_id'];
if (in_array($row['thematic_id'], $tmp)) {
$data[$row['thematic_id']][$row['id']] = $row;
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;
}
} else {
$data[$row['thematic_id']][$row['id']] = $row;
}
}
}
}
}
@ -583,24 +628,42 @@ class Thematic
$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 ";
$items = $elements_to_show = $elements_to_show_values = array();
$items = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
$elements_to_show = array();
foreach($items as $value) {
$elements_to_show[$value['ref']] = $value;
}
$elements_to_show_values = array_keys($elements_to_show);
$rs = Database::query($sql);
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,'ASSOC')) {
while ($row = Database::fetch_array($rs,'ASSOC')) {
if (!in_array($row['id'], $elements_to_show_values) && !api_get_session_id()) {
continue;
}
$tmp[] = $row['thematic_id'];
if (in_array($row['thematic_id'], $tmp)) {
if (in_array($row['thematic_id'], $tmp)) {
$row['session_id'] =isset($elements_to_show[$row['id']]) ? $elements_to_show[$row['id']]['id_session']: 0;
$data[$row['thematic_id']][$row['description_type']] = $row;
}
}
} else {
while ($row = Database::fetch_array($rs,'ASSOC')) {
if (!in_array($row['id'], $elements_to_show_values) && !api_get_session_id()) {
continue;
}
$row['session_id'] =isset($elements_to_show[$row['id']]) ? $elements_to_show[$row['id']]['id_session']: 0;
$data[] = $row;
}
}
}
return $data;
}
@ -618,35 +681,68 @@ class Thematic
$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();
$session_id = api_get_session_id();
$user_id = api_get_user_id();
$session_id = api_get_session_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'];
}
$condition = '';
if (!empty($elements_to_show)) {
$condition = "AND id IN (".implode(',', $elements_to_show).") ";
}
// check thematic plan type already exists
$sql = "SELECT id FROM $tbl_thematic_plan WHERE 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'];
// update
$upd = "UPDATE $tbl_thematic_plan SET title = '$title', description = '$description' WHERE thematic_id = $thematic_id AND description_type = $description_type ";
Database::query($upd);
$affected_rows = Database::affected_rows();
if ($affected_rows) {
api_item_property_update($_course, 'thematic_plan', $thematic_plan_id,"ThematicPlanUpdated", $user_id);
}
} else {
//Checking the session
$thematic_plan_data = api_get_item_property_info(api_get_course_id(), 'thematic_plan', $thematic_plan_id);
$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 id = $thematic_plan_id";
Database::query($upd);
$affected_rows = Database::affected_rows();
if ($affected_rows) {
api_item_property_update($_course, 'thematic_plan', $thematic_plan_id, "ThematicPlanUpdated", $user_id);
}
} else {
// insert
$ins = "INSERT INTO $tbl_thematic_plan(thematic_id, title, description, description_type) VALUES($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 {
// insert
$ins = "INSERT INTO $tbl_thematic_plan(thematic_id, title, description, description_type) VALUES($thematic_id, '$title', '$description', $description_type) ";
$ins = "INSERT INTO $tbl_thematic_plan(thematic_id, title, description, description_type) VALUES($thematic_id, '$title', '$description', $description_type) ";
Database::query($ins);
$last_id = Database::insert_id();
$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);
}
if ($affected_rows) {
api_item_property_update($_course, 'thematic_plan', $last_id,"ThematicPlanAdded", $user_id);
}
}
return $affected_rows;
}
@ -720,15 +816,15 @@ class Thematic
*/
public function update_done_thematic_advances($thematic_advance_id) {
global $_course;
$thematic_data = $this->get_thematic_list();
$thematic_data = $this->get_thematic_list(null, api_get_course_id());
$thematic_advance_data = $this->get_thematic_advance_list(null, api_get_course_id(), true);
$tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$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();
//var_dump($thematic_advance_data);
if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) {
$thematic_id = $thematic['id'];
@ -739,29 +835,41 @@ class Thematic
}
}
}
$error = null;
$a_thematic_advance_ids = array();
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) {
$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 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 ($thematic_advance['id'] == $thematic_advance_id) {
break 2;
$item_info = api_get_item_property_info(api_get_course_id(), 'thematic_advance', $thematic_advance['id']);
//var_dump($item_info );
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 id = ".$thematic_advance['id']." ";
Database::query($upd);
$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);
//}
if ($thematic_advance['id'] == $thematic_advance_id) {
break 2;
}
}
}
}
}
}
// 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);
@ -769,21 +877,23 @@ class Thematic
$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);
$session_id = api_get_session_id();
// get all thematic advance done
$rs_thematic_done = Database::query("SELECT ref FROM $tbl_item_property WHERE tool='thematic_advance' AND lastedit_type='ThematicAdvanceDone'");
$rs_thematic_done = Database::query("SELECT ref FROM $tbl_item_property WHERE 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)) {
$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='".api_get_utc_datetime()."', lastedit_type='ThematicAdvanceUpdated', lastedit_user_id = $user_id WHERE tool='thematic_advance' AND ref=$ref");
Database::query("UPDATE $tbl_item_property SET lastedit_date='".api_get_utc_datetime()."', lastedit_type='ThematicAdvanceUpdated', lastedit_user_id = $user_id WHERE tool='thematic_advance' AND ref=$ref AND id_session = $session_id ");
}
}
}
return $affected_rows;
}
return $affected_rows;
}
/**
@ -791,9 +901,10 @@ class Thematic
* @return int Last done thematic advance id
*/
public function get_last_done_thematic_advance() {
$thematic_data = $this->get_thematic_list();
$thematic_advance_data = $this->get_thematic_advance_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)) {
@ -808,12 +919,10 @@ 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;
}
@ -855,19 +964,21 @@ class Thematic
* @return float Average of thematic advances
*/
public function get_total_average_of_thematic_advances($course_code = null, $session_id = null) {
$thematic_data = $this->get_thematic_list(null, $course_code, $session_id);
if (api_get_session_id()) {
$thematic_data = $this->get_thematic_list(null, api_get_course_id());
} else {
$thematic_data = $this->get_thematic_list(null, api_get_course_id(), 0);
}
$new_thematic_data = array();
if (!empty($thematic_data)) {
foreach ($thematic_data as $item) {
if ($item['session_id'] == api_get_session_id()) {
$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);
$thematic_advance_data = $this->get_thematic_advance_list(null, $course_code, true);
$a_average_of_advances_by_thematic = array();
$total_average = 0;
if (!empty($thematic_data)) {
@ -880,9 +991,9 @@ class Thematic
// calculate total average
if (!empty($a_average_of_advances_by_thematic)) {
$count_tematics = count($thematic_data);
$score = array_sum($a_average_of_advances_by_thematic);
$total_average = round(($score*100)/($count_tematics*100));
}
$score = array_sum($a_average_of_advances_by_thematic);
$total_average = round(($score*100)/($count_tematics*100));
}
return $total_average;
}
@ -901,16 +1012,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;
@ -926,10 +1037,10 @@ class Thematic
* @return void
*/
public function set_thematic_attributes($id = null, $title = '', $content = '', $session_id = 0) {
$this->thematic_id = $id;
$this->thematic_title = $title;
$this->thematic_content = $content;
$this->session_id = $session_id;
$this->thematic_id = $id;
$this->thematic_title = $title;
$this->thematic_content = $content;
$this->session_id = $session_id;
}
/**
@ -1052,5 +1163,4 @@ class Thematic
return $datetime;
}
}
?>
}
Loading…
Cancel
Save