|
@@ -3,6 +3,7 @@
|
|
|
/**
|
|
|
* Script
|
|
|
* @package chamilo.gradebook
|
|
|
+ * @author Julio Montoya - fixes in order to use gradebook models + some code cleaning
|
|
|
*/
|
|
|
/**
|
|
|
* Init
|
|
@@ -25,28 +26,27 @@ require_once 'lib/fe/linkform.class.php';
|
|
|
require_once 'lib/gradebook_data_generator.class.php';
|
|
|
require_once 'lib/fe/gradebooktable.class.php';
|
|
|
require_once 'lib/fe/displaygradebook.php';
|
|
|
-require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
|
|
|
|
|
|
api_block_anonymous_users();
|
|
|
+
|
|
|
if (!api_is_allowed_to_edit()) {
|
|
|
header('Location: /index.php');
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
-$my_selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
|
|
|
+$my_selectcat = isset($_GET['selectcat']) ? intval($_GET['selectcat']) : '';
|
|
|
|
|
|
if (empty($my_selectcat)) {
|
|
|
api_not_allowed();
|
|
|
}
|
|
|
|
|
|
-// DISPLAY HEADERS AND MESSAGES -
|
|
|
-
|
|
|
+// DISPLAY HEADERS AND MESSAGES
|
|
|
if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
|
|
|
if (isset ($_GET['studentoverview'])) {
|
|
|
- $interbreadcrumb[]= array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Gradebook'));
|
|
|
+ $interbreadcrumb[]= array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=' . $my_selectcat,'name' => get_lang('Gradebook'));
|
|
|
Display :: display_header(get_lang('FlatView'));
|
|
|
} elseif (isset ($_GET['search'])) {
|
|
|
- $interbreadcrumb[]= array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Gradebook'));
|
|
|
+ $interbreadcrumb[]= array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=' . $my_selectcat,'name' => get_lang('Gradebook'));
|
|
|
Display :: display_header(get_lang('SearchResults'));
|
|
|
} else {
|
|
|
$interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=1', 'name' => get_lang('Gradebook'));
|
|
@@ -59,6 +59,7 @@ $course_id = get_course_id_by_link_id($my_selectcat);
|
|
|
|
|
|
$table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
|
|
|
$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
|
|
|
+
|
|
|
$tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
|
|
|
$tbl_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
|
|
|
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
|
|
@@ -71,8 +72,8 @@ $table_evaluated[LINK_FORUM_THREAD] = array(TABLE_FORUM_THREAD, 'thread_ti
|
|
|
$table_evaluated[LINK_ATTENDANCE] = array(TABLE_ATTENDANCE, 'attendance_title_qualify', 'id', get_lang('Attendance'));
|
|
|
$table_evaluated[LINK_SURVEY] = array(TABLE_SURVEY, 'code', 'survey_id', get_lang('Survey'));
|
|
|
|
|
|
-$submitted=isset($_POST['submitted'])?$_POST['submitted']:'';
|
|
|
-if($submitted==1) {
|
|
|
+$submitted = isset($_POST['submitted'])?$_POST['submitted']:'';
|
|
|
+if ($submitted==1) {
|
|
|
Display :: display_confirmation_message(get_lang('GradebookWeightUpdated')) . '<br /><br />';
|
|
|
if (isset($_POST['evaluation'])) {
|
|
|
require_once 'lib/be/evaluation.class.php';
|
|
@@ -84,78 +85,99 @@ if($submitted==1) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-$category_id = (int)$_GET['selectcat'];
|
|
|
$output='';
|
|
|
-$sql = 'SELECT * FROM '.$table_link.' WHERE category_id = '.$category_id;
|
|
|
+$my_cat = Category::load($my_selectcat);
|
|
|
+$my_cat = $my_cat[0];
|
|
|
+
|
|
|
+$parent_id = $my_cat->get_parent_id();
|
|
|
+$parent_cat = Category::load($parent_id);
|
|
|
+
|
|
|
+$my_category = array();
|
|
|
+$cat = new Category();
|
|
|
+$my_category = $cat->shows_all_information_an_category($my_selectcat);
|
|
|
+
|
|
|
+$original_total = $my_category['weight'];
|
|
|
+$masked_total = $parent_cat[0]->get_weight(); //$my_category['weight'];
|
|
|
+
|
|
|
+$sql = 'SELECT * FROM '.$table_link.' WHERE category_id = '.$my_selectcat;
|
|
|
$result = Database::query($sql);
|
|
|
- while($row = Database ::fetch_array($result)) {
|
|
|
- //update only if value changed
|
|
|
- if(isset($_POST['link'][$row['id']]) && $_POST['link'][$row['id']] != $row['weight']) {
|
|
|
-
|
|
|
- AbstractLink::add_link_log($row['id']);
|
|
|
- Database::query('UPDATE '.$table_link.' SET weight = '."'".Database::escape_string(trim($_POST['link'][$row['id']]))."'".' WHERE c_id = '.$course_id.' AND id = '.$row['id']);
|
|
|
- $row['weight'] = trim($_POST['link'][$row['id']]);
|
|
|
-
|
|
|
- //Update weight for attendance
|
|
|
- $sql = 'SELECT ref_id FROM '.$table_link.' WHERE c_id = '.$course_id.' AND id = '.intval($row['id']).' AND type='.LINK_ATTENDANCE;
|
|
|
- $rs_attendance = Database::query($sql);
|
|
|
- if (Database::num_rows($rs_attendance) > 0) {
|
|
|
- $row_attendance = Database::fetch_array($rs_attendance);
|
|
|
- $upd_attendance = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.floatval($_POST['link'][$row['id']]).'
|
|
|
- WHERE c_id = '.$course_id.' AND id = '.intval($row_attendance['ref_id']);
|
|
|
- Database::query($upd_attendance);
|
|
|
- }
|
|
|
- //Update weight into forum thread
|
|
|
- $sql_t = 'UPDATE '.$tbl_forum_thread.' SET thread_weight='.floatval($_POST['link'][$row['id']]).'
|
|
|
- WHERE c_id = '.$course_id.' AND thread_id = (SELECT ref_id FROM '.$table_link.' WHERE id='.intval($row['id']).' AND type='.LINK_FORUM_THREAD.' AND c_id = '.$course_id.') ';
|
|
|
- Database::query($sql_t);
|
|
|
- //Update weight into student publication(work)
|
|
|
- $sql_t='UPDATE '.$tbl_work.' SET weight='.floatval($_POST['link'][$row['id']]).'
|
|
|
- WHERE c_id = '.$course_id.' AND id = (SELECT ref_id FROM '.$table_link.' WHERE id='.intval($row['id']).' AND type = '.LINK_STUDENTPUBLICATION.' AND c_id = '.$course_id.' ) ';
|
|
|
- Database::query($sql_t);
|
|
|
- }
|
|
|
-
|
|
|
- $tempsql = Database::query('SELECT * FROM '.get_table_type_course($row['type']).' WHERE c_id = '.$course_id.' AND '.$table_evaluated[$row['type']][2].' = '.$row['ref_id']);
|
|
|
- $resource_name = Database ::fetch_array($tempsql);
|
|
|
- //var_dump($resource_name['lp_type']);
|
|
|
- if (isset($resource_name['lp_type'])) {
|
|
|
- $resource_name=$resource_name[2];
|
|
|
- } else {
|
|
|
- $resource_name=$resource_name[1];
|
|
|
- }
|
|
|
- $output.= '<tr><td>'.build_type_icon_tag($row['type']).'</td><td> [ '.$table_evaluated[$row['type']][3].' ] '.$resource_name.'</td><td><input type="hidden" name="link_'.$row['id'].'" value="'.$resource_name.'" /><input size="10" type="text" name="link['.$row['id'].']" value="'.$row['weight'].'"/></td></tr>';
|
|
|
- }
|
|
|
|
|
|
- $sql = Database::query('SELECT * FROM '.$table_evaluation.' WHERE category_id = '.$category_id);
|
|
|
- while($row = Database ::fetch_array($sql)) {
|
|
|
- //update only if value changed
|
|
|
- if(isset($_POST['evaluation'][$row['id']]) && $_POST['evaluation'][$row['id']] != $row['weight']) {
|
|
|
- Evaluation::add_evaluation_log($row['id']);
|
|
|
- Database::query('UPDATE '.$table_evaluation.' SET weight = '."'".Database::escape_string(trim($_POST['evaluation'][$row['id']]))."'".' WHERE id = '.$row['id']);
|
|
|
- $row['weight'] = trim($_POST['evaluation'][$row['id']]);
|
|
|
- }
|
|
|
- $type_evaluated = isset($row['type']) ? $table_evaluated[$type_evaluated][3] : null;
|
|
|
- $output.= '<tr><td>'.build_type_icon_tag('evalnotempty').'</td><td> [ '.get_lang('Evaluation').$type_evaluated.' ] '.$row['name'].'</td><td><input type="hidden" name="eval_'.$row['id'].'" value="'.$row['name'].'" /><input type="text" size="10" name="evaluation['.$row['id'].']" value="'.$row['weight'].'"/></td></tr>';
|
|
|
+while ($row = Database ::fetch_array($result)) {
|
|
|
+ $item_weight = $row['weight'];
|
|
|
+ $item_weight = $masked_total*$item_weight/$original_total;
|
|
|
+
|
|
|
+ //update only if value changed
|
|
|
+ if (isset($_POST['link'][$row['id']])) {
|
|
|
+ $new_weight = trim($_POST['link'][$row['id']]*$original_total/$masked_total);
|
|
|
+ AbstractLink::add_link_log($row['id']);
|
|
|
+ Database::query('UPDATE '.$table_link.' SET weight = '."'".Database::escape_string($new_weight)."'".' WHERE id = '.$row['id']);
|
|
|
+ $item_weight = trim($_POST['link'][$row['id']]);
|
|
|
+
|
|
|
+ //Update weight for attendance
|
|
|
+ $sql = 'SELECT ref_id FROM '.$table_link.' WHERE id = '.intval($row['id']).' AND type='.LINK_ATTENDANCE;
|
|
|
+ $rs_attendance = Database::query($sql);
|
|
|
+ if (Database::num_rows($rs_attendance) > 0) {
|
|
|
+ $row_attendance = Database::fetch_array($rs_attendance);
|
|
|
+ $upd_attendance = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.floatval($_POST['link'][$row['id']]).'
|
|
|
+ WHERE c_id = '.$course_id.' AND id = '.intval($row_attendance['ref_id']);
|
|
|
+ Database::query($upd_attendance);
|
|
|
+ }
|
|
|
+ //Update weight into forum thread
|
|
|
+ $sql_t = 'UPDATE '.$tbl_forum_thread.' SET thread_weight='.floatval($_POST['link'][$row['id']]).'
|
|
|
+ WHERE c_id = '.$course_id.' AND thread_id = (SELECT ref_id FROM '.$table_link.' WHERE id='.intval($row['id']).' AND type='.LINK_FORUM_THREAD.' ) ';
|
|
|
+ Database::query($sql_t);
|
|
|
+ //Update weight into student publication(work)
|
|
|
+ $sql_t='UPDATE '.$tbl_work.' SET weight='.floatval($_POST['link'][$row['id']]).'
|
|
|
+ WHERE c_id = '.$course_id.' AND id = (SELECT ref_id FROM '.$table_link.' WHERE id='.intval($row['id']).' AND type = '.LINK_STUDENTPUBLICATION.' ) ';
|
|
|
+ Database::query($sql_t);
|
|
|
+ }
|
|
|
+
|
|
|
+ $tempsql = Database::query('SELECT * FROM '.get_table_type_course($row['type']).' WHERE c_id = '.$course_id.' AND '.$table_evaluated[$row['type']][2].' = '.$row['ref_id']);
|
|
|
+ $resource_name = Database ::fetch_array($tempsql);
|
|
|
+
|
|
|
+ if (isset($resource_name['lp_type'])) {
|
|
|
+ $resource_name = $resource_name[2];
|
|
|
+ } else {
|
|
|
+ $resource_name = $resource_name[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ $output.= '<tr><td>'.build_type_icon_tag($row['type']).'</td><td> '.$resource_name.' '.Display::label($table_evaluated[$row['type']][3],'info').' </td>';
|
|
|
+ $output.= '<td><input type="hidden" name="link_'.$row['id'].'" value="'.$resource_name.'" /><input size="10" type="text" name="link['.$row['id'].']" value="'.$item_weight.'"/></td></tr>';
|
|
|
+}
|
|
|
+
|
|
|
+$sql = Database::query('SELECT * FROM '.$table_evaluation.' WHERE category_id = '.$my_selectcat);
|
|
|
+while ($row = Database ::fetch_array($sql)) {
|
|
|
+ $item_weight = $row['weight'];
|
|
|
+ $item_weight = $masked_total*$item_weight/$original_total;
|
|
|
+
|
|
|
+ //update only if value changed
|
|
|
+ if (isset($_POST['evaluation'][$row['id']])) {
|
|
|
+ Evaluation::add_evaluation_log($row['id']);
|
|
|
+ $new_weight = trim($_POST['evaluation'][$row['id']]*$original_total/$masked_total);
|
|
|
+ $update_sql = 'UPDATE '.$table_evaluation.' SET weight = '."'".Database::escape_string($new_weight)."'".' WHERE id = '.$row['id'];
|
|
|
+ Database::query($update_sql);
|
|
|
+ $item_weight = trim($_POST['evaluation'][$row['id']]);
|
|
|
+ }
|
|
|
+ $type_evaluated = isset($row['type']) ? $table_evaluated[$type_evaluated][3] : null;
|
|
|
+ $output.= '<tr><td>'.build_type_icon_tag('evalnotempty').'</td><td>'.$row['name'].' '.Display::label(get_lang('Evaluation').$type_evaluated).'</td>';
|
|
|
+ $output.= '<td><input type="hidden" name="eval_'.$row['id'].'" value="'.$row['name'].'" /><input type="text" size="10" name="evaluation['.$row['id'].']" value="'.$item_weight.'"/></td></tr>';
|
|
|
}
|
|
|
//by iflorespaz
|
|
|
-$my_category=array();
|
|
|
-$cat=new Category();
|
|
|
-$my_category = $cat->shows_all_information_an_category($my_selectcat);
|
|
|
$my_api_cidreq = api_get_cidreq();
|
|
|
if ($my_api_cidreq=='') {
|
|
|
$my_api_cidreq='cidReq='.$my_category['course_code'];
|
|
|
}
|
|
|
?>
|
|
|
<div class="actions">
|
|
|
-<a href="<?php echo Security::remove_XSS($_SESSION['gradebook_dest']).'?id_session='.api_get_session_id().'&'.$my_api_cidreq ?>&selectcat=<?php echo $category_id ?>">
|
|
|
+<a href="<?php echo Security::remove_XSS($_SESSION['gradebook_dest']).'?id_session='.api_get_session_id().'&'.$my_api_cidreq ?>&selectcat=<?php echo $my_selectcat ?>">
|
|
|
<?php echo Display::return_icon('back.png',get_lang('FolderView'),'',ICON_SIZE_MEDIUM); ?>
|
|
|
</a>
|
|
|
</div>
|
|
|
<?php
|
|
|
-$warning_message = sprintf(get_lang('TotalWeightMustBeX'), $my_category['weight']);
|
|
|
-Display::display_normal_message($warning_message,false);
|
|
|
+$warning_message = sprintf(get_lang('TotalWeightMustBeX'), $masked_total);
|
|
|
+Display::display_normal_message($warning_message, false);
|
|
|
?>
|
|
|
-<form method="post" action="gradebook_edit_all.php?id_session=<?php echo $_SESSION['id_session'].'&'.$my_api_cidreq ?>&selectcat=<?php echo $category_id?>">
|
|
|
+<form method="post" action="gradebook_edit_all.php?id_session=<?php echo $_SESSION['id_session'].'&'.$my_api_cidreq ?>&selectcat=<?php echo $my_selectcat?>">
|
|
|
<table class="data_table">
|
|
|
<tr class="row_odd">
|
|
|
<th style="width: 35px;"><?php echo get_lang('Type'); ?></th>
|