gradebook_edit_all.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. * @author Julio Montoya - fixes in order to use gradebook models + some code cleaning
  7. */
  8. /**
  9. * Init
  10. */
  11. $language_file= 'gradebook';
  12. $cidReset= true;
  13. require_once '../inc/global.inc.php';
  14. $this_section = SECTION_COURSES;
  15. $current_course_tool = TOOL_GRADEBOOK;
  16. api_protect_course_script();
  17. require_once 'lib/be.inc.php';
  18. require_once 'lib/scoredisplay.class.php';
  19. require_once 'lib/gradebook_functions.inc.php';
  20. require_once 'lib/fe/catform.class.php';
  21. require_once 'lib/fe/evalform.class.php';
  22. require_once 'lib/fe/linkform.class.php';
  23. require_once 'lib/gradebook_data_generator.class.php';
  24. require_once 'lib/fe/gradebooktable.class.php';
  25. require_once 'lib/fe/displaygradebook.php';
  26. api_block_anonymous_users();
  27. if (!api_is_allowed_to_edit()) {
  28. header('Location: /index.php');
  29. exit;
  30. }
  31. $my_selectcat = isset($_GET['selectcat']) ? intval($_GET['selectcat']) : '';
  32. if (empty($my_selectcat)) {
  33. api_not_allowed();
  34. }
  35. // DISPLAY HEADERS AND MESSAGES
  36. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  37. if (isset ($_GET['studentoverview'])) {
  38. $interbreadcrumb[]= array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=' . $my_selectcat,'name' => get_lang('Gradebook'));
  39. Display :: display_header(get_lang('FlatView'));
  40. } elseif (isset ($_GET['search'])) {
  41. $interbreadcrumb[]= array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=' . $my_selectcat,'name' => get_lang('Gradebook'));
  42. Display :: display_header(get_lang('SearchResults'));
  43. } else {
  44. $interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=1', 'name' => get_lang('Gradebook'));
  45. $interbreadcrumb[] = array ('url' => '#','name' => get_lang('EditAllWeights'));
  46. Display :: display_header('');
  47. }
  48. }
  49. $course_id = get_course_id_by_link_id($my_selectcat);
  50. $table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  51. $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  52. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
  53. $tbl_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  54. $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  55. $table_evaluated[LINK_EXERCISE] = array(TABLE_QUIZ_TEST, 'title', 'id', get_lang('Exercise'));
  56. $table_evaluated[LINK_DROPBOX] = array(TABLE_DROPBOX_FILE, 'name','id', get_lang('Dropbox'));
  57. $table_evaluated[LINK_STUDENTPUBLICATION] = array(TABLE_STUDENT_PUBLICATION, 'url','id', get_lang('Student_publication'));
  58. $table_evaluated[LINK_LEARNPATH] = array(TABLE_LP_MAIN, 'name','id', get_lang('Learnpath'));
  59. $table_evaluated[LINK_FORUM_THREAD] = array(TABLE_FORUM_THREAD, 'thread_title_qualify', 'thread_id', get_lang('Forum'));
  60. $table_evaluated[LINK_ATTENDANCE] = array(TABLE_ATTENDANCE, 'attendance_title_qualify', 'id', get_lang('Attendance'));
  61. $table_evaluated[LINK_SURVEY] = array(TABLE_SURVEY, 'code', 'survey_id', get_lang('Survey'));
  62. $submitted = isset($_POST['submitted'])?$_POST['submitted']:'';
  63. if ($submitted==1) {
  64. Display :: display_confirmation_message(get_lang('GradebookWeightUpdated')) . '<br /><br />';
  65. if (isset($_POST['evaluation'])) {
  66. require_once 'lib/be/evaluation.class.php';
  67. $eval_log = new Evaluation();
  68. }
  69. if(isset($_POST['link'])){
  70. require_once 'lib/be/abstractlink.class.php';
  71. //$eval_link_log = new AbstractLink();
  72. }
  73. }
  74. $output='';
  75. $my_cat = Category::load($my_selectcat);
  76. $my_cat = $my_cat[0];
  77. $parent_id = $my_cat->get_parent_id();
  78. $parent_cat = Category::load($parent_id);
  79. $my_category = array();
  80. $cat = new Category();
  81. $my_category = $cat->shows_all_information_an_category($my_selectcat);
  82. $original_total = $my_category['weight'];
  83. $masked_total = $parent_cat[0]->get_weight(); //$my_category['weight'];
  84. $sql = 'SELECT * FROM '.$table_link.' WHERE category_id = '.$my_selectcat;
  85. $result = Database::query($sql);
  86. while ($row = Database ::fetch_array($result)) {
  87. $item_weight = $row['weight'];
  88. //$item_weight = $masked_total*$item_weight/$original_total;
  89. //update only if value changed
  90. if (isset($_POST['link'][$row['id']])) {
  91. //$new_weight = trim($_POST['link'][$row['id']]*$original_total/$masked_total);
  92. $new_weight = trim($_POST['link'][$row['id']]);
  93. AbstractLink::add_link_log($row['id']);
  94. Database::query('UPDATE '.$table_link.' SET weight = '."'".Database::escape_string($new_weight)."'".' WHERE id = '.$row['id']);
  95. $item_weight = trim($_POST['link'][$row['id']]);
  96. //Update weight for attendance
  97. $sql = 'SELECT ref_id FROM '.$table_link.' WHERE id = '.intval($row['id']).' AND type='.LINK_ATTENDANCE;
  98. $rs_attendance = Database::query($sql);
  99. if (Database::num_rows($rs_attendance) > 0) {
  100. $row_attendance = Database::fetch_array($rs_attendance);
  101. $upd_attendance = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.floatval($_POST['link'][$row['id']]).'
  102. WHERE c_id = '.$course_id.' AND id = '.intval($row_attendance['ref_id']);
  103. Database::query($upd_attendance);
  104. }
  105. //Update weight into forum thread
  106. $sql_t = 'UPDATE '.$tbl_forum_thread.' SET thread_weight='.floatval($_POST['link'][$row['id']]).'
  107. WHERE c_id = '.$course_id.' AND thread_id = (SELECT ref_id FROM '.$table_link.' WHERE id='.intval($row['id']).' AND type='.LINK_FORUM_THREAD.' ) ';
  108. Database::query($sql_t);
  109. //Update weight into student publication(work)
  110. $sql_t='UPDATE '.$tbl_work.' SET weight='.floatval($_POST['link'][$row['id']]).'
  111. WHERE c_id = '.$course_id.' AND id = (SELECT ref_id FROM '.$table_link.' WHERE id='.intval($row['id']).' AND type = '.LINK_STUDENTPUBLICATION.' ) ';
  112. Database::query($sql_t);
  113. }
  114. $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']);
  115. $resource_name = Database ::fetch_array($tempsql);
  116. if (isset($resource_name['lp_type'])) {
  117. $resource_name = $resource_name[2];
  118. } else {
  119. $resource_name = $resource_name[1];
  120. }
  121. $output.= '<tr><td>'.build_type_icon_tag($row['type']).'</td><td> '.$resource_name.' '.Display::label($table_evaluated[$row['type']][3],'info').' </td>';
  122. $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>';
  123. }
  124. $sql = Database::query('SELECT * FROM '.$table_evaluation.' WHERE category_id = '.$my_selectcat);
  125. while ($row = Database ::fetch_array($sql)) {
  126. $item_weight = $row['weight'];
  127. //$item_weight = $masked_total*$item_weight/$original_total;
  128. //update only if value changed
  129. if (isset($_POST['evaluation'][$row['id']])) {
  130. Evaluation::add_evaluation_log($row['id']);
  131. //$new_weight = trim($_POST['evaluation'][$row['id']]*$original_total/$masked_total);
  132. $new_weight = trim($_POST['evaluation'][$row['id']]);
  133. $update_sql = 'UPDATE '.$table_evaluation.' SET weight = '."'".Database::escape_string($new_weight)."'".' WHERE id = '.$row['id'];
  134. Database::query($update_sql);
  135. $item_weight = trim($_POST['evaluation'][$row['id']]);
  136. }
  137. $type_evaluated = isset($row['type']) ? $table_evaluated[$type_evaluated][3] : null;
  138. $output.= '<tr><td>'.build_type_icon_tag('evalnotempty').'</td><td>'.$row['name'].' '.Display::label(get_lang('Evaluation').$type_evaluated).'</td>';
  139. $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>';
  140. }
  141. //by iflorespaz
  142. $my_api_cidreq = api_get_cidreq();
  143. if ($my_api_cidreq=='') {
  144. $my_api_cidreq='cidReq='.$my_category['course_code'];
  145. }
  146. ?>
  147. <div class="actions">
  148. <a href="<?php echo Security::remove_XSS($_SESSION['gradebook_dest']).'?id_session='.api_get_session_id().'&amp;'.$my_api_cidreq ?>&selectcat=<?php echo $my_selectcat ?>">
  149. <?php echo Display::return_icon('back.png',get_lang('FolderView'),'',ICON_SIZE_MEDIUM); ?>
  150. </a>
  151. </div>
  152. <?php
  153. $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $masked_total);
  154. Display::display_normal_message($warning_message, false);
  155. ?>
  156. <form method="post" action="gradebook_edit_all.php?id_session=<?php echo $_SESSION['id_session'].'&amp;'.$my_api_cidreq ?>&selectcat=<?php echo $my_selectcat?>">
  157. <table class="data_table">
  158. <tr class="row_odd">
  159. <th style="width: 35px;"><?php echo get_lang('Type'); ?></th>
  160. <th><?php echo get_lang('Resource'); ?></th>
  161. <th><?php echo get_lang('Weight'); ?></th>
  162. </tr>
  163. <?php echo $output; ?>
  164. </table>
  165. <input type="hidden" name="submitted" value="1" />
  166. <br />
  167. <button class="save" type="submit" name="name" value="<?php echo get_lang('Save') ?>"><?php echo get_lang('SaveScoringRules') ?></button>
  168. </form>
  169. <?php
  170. Display :: display_footer();