gradebook_edit_all.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2006-2008 Dokeos SPRL
  6. Copyright (c) 2006 Ghent University (UGent)
  7. Copyright (c) various contributors
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. $language_file= 'gradebook';
  20. $cidReset= true;
  21. require_once ('../inc/global.inc.php');
  22. $this_section = SECTION_MYGRADEBOOK;
  23. require_once ('lib/be.inc.php');
  24. require_once ('lib/scoredisplay.class.php');
  25. require_once ('lib/gradebook_functions.inc.php');
  26. require_once ('lib/fe/catform.class.php');
  27. require_once ('lib/fe/evalform.class.php');
  28. require_once ('lib/fe/linkform.class.php');
  29. require_once ('lib/gradebook_data_generator.class.php');
  30. require_once ('lib/fe/gradebooktable.class.php');
  31. require_once ('lib/fe/displaygradebook.php');
  32. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  33. api_block_anonymous_users();
  34. if (!api_is_allowed_to_create_course()) {
  35. header('Location: /index.php');
  36. }
  37. $my_selectcat=isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
  38. if (empty($my_selectcat)) {
  39. api_not_allowed();
  40. }
  41. // --------------------------------------------------------------------------------
  42. // - DISPLAY HEADERS AND MESSAGES -
  43. // --------------------------------------------------------------------------------
  44. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  45. if (isset ($_GET['studentoverview'])) {
  46. $interbreadcrumb[]= array (
  47. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  48. 'name' => get_lang('Gradebook')
  49. );
  50. Display :: display_header(get_lang('FlatView'));
  51. } elseif (isset ($_GET['search'])) {
  52. $interbreadcrumb[]= array (
  53. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  54. 'name' => get_lang('Gradebook')
  55. );
  56. Display :: display_header(get_lang('SearchResults'));
  57. } else {
  58. $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('Gradebook'));
  59. $interbreadcrumb[]= array (
  60. 'url' => $_SESSION['gradebook_dest'].'?&selectcat='.Security::remove_XSS($_GET['selectcat']),
  61. 'name' => get_lang('EditAllWeights'));
  62. Display :: display_header('');
  63. }
  64. }
  65. $table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  66. $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  67. //$table_forum_thread=Database::get_course_table(TABLE_FORUM_THREAD);
  68. $my_db_name=get_database_name_by_link_id($my_selectcat);
  69. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD,$my_db_name);
  70. $tbl_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION,$my_db_name);
  71. $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE,$my_db_name);
  72. /*
  73. if($_SERVER['REQUEST_METHOD']=='POST'):
  74. foreach($_POST['link'] as $key => $value){
  75. Database::query('UPDATE '.$table_link.' SET weight = '."'".$value."'".' WHERE id = '.$key);
  76. }
  77. foreach($_POST['evaluation'] as $key => $value){
  78. Database::query('UPDATE '.$table_evaluation.' SET weight = '."'".$value."'".' WHERE id = '.$key);
  79. }
  80. Display :: display_normal_message(get_lang('GradebookWeightUpdated')) . '<br /><br />';
  81. endif;*/
  82. /*
  83. define('LINK_EXERCISE',1);
  84. define('LINK_DROPBOX',2);
  85. define('LINK_STUDENTPUBLICATION',3);
  86. define('LINK_LEARNPATH',4);
  87. define('LINK_FORUM_THREAD',5);
  88. */
  89. $table_evaluated[1] = array(TABLE_QUIZ_TEST, 'title', 'id', get_lang('Exercise'));
  90. $table_evaluated[2] = array(TABLE_DROPBOX_FILE, 'name','id', get_lang('Dropbox'));
  91. $table_evaluated[3] = array(TABLE_STUDENT_PUBLICATION, 'url','id', get_lang('Student_publication'));
  92. $table_evaluated[4] = array(TABLE_LP_MAIN, 'name','id', get_lang('Learnpath'));
  93. $table_evaluated[5] = array(TABLE_FORUM_THREAD, 'thread_title_qualify', 'thread_id', get_lang('Forum'));
  94. $table_evaluated[7] = array(TABLE_ATTENDANCE, 'attendance_title_qualify', 'id', get_lang('Attendance'));
  95. $submitted=isset($_POST['submitted'])?$_POST['submitted']:'';
  96. if($submitted==1) {
  97. Display :: display_confirmation_message(get_lang('GradebookWeightUpdated')) . '<br /><br />';
  98. if (isset($_POST['evaluation'])) {
  99. require_once 'lib/be/evaluation.class.php';
  100. $eval_log = new Evaluation();
  101. }
  102. if(isset($_POST['link'])){
  103. require_once 'lib/be/abstractlink.class.php';
  104. //$eval_link_log = new AbstractLink();
  105. }
  106. }
  107. $category_id = (int)$_GET['selectcat'];
  108. $output='';
  109. $sql='SELECT * FROM '.$table_link.' WHERE category_id = '.$category_id;
  110. $result = Database::query($sql);
  111. while($row = Database ::fetch_array($result)) {
  112. //update only if value changed
  113. if(isset($_POST['link'][$row['id']]) && $_POST['link'][$row['id']] != $row['weight']) {
  114. AbstractLink::add_link_log($row['id']);
  115. Database::query('UPDATE '.$table_link.' SET weight = '."'".trim($_POST['link'][$row['id']])."'".' WHERE id = '.$row['id']);
  116. $row['weight'] = trim($_POST['link'][$row['id']]);
  117. //Update weight for attendance
  118. $sql = 'SELECT ref_id FROM '.$table_link.' WHERE id = '.intval($row['id']).' AND type='.LINK_ATTENDANCE;
  119. $rs_attendance = Database::query($sql);
  120. if (Database::num_rows($rs_attendance) > 0) {
  121. $row_attendance = Database::fetch_array($rs_attendance);
  122. $upd_attendance = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.floatval($_POST['link'][$row['id']]).' WHERE id = '.intval($row_attendance['ref_id']);
  123. Database::query($upd_attendance);
  124. }
  125. //Update weight into forum thread
  126. $sql_t='UPDATE '.$tbl_forum_thread.' SET thread_weight='.floatval($_POST['link'][$row['id']]).' WHERE thread_id= (SELECT ref_id FROM '.$table_link.' WHERE id='.intval($row['id']).' AND type='.LINK_FORUM_THREAD.');';
  127. Database::query($sql_t);
  128. //Update weight into student publication(work)
  129. $sql_t='UPDATE '.$tbl_work.' SET weight='.floatval($_POST['link'][$row['id']]).' WHERE id= (SELECT ref_id FROM '.$table_link.' WHERE id='.intval($row['id']).' AND type = '.LINK_STUDENTPUBLICATION.');';
  130. Database::query($sql_t);
  131. }
  132. $tempsql = Database::query('SELECT * FROM '.get_table_type_course($row['type'],$row['course_code']).' WHERE '.$table_evaluated[$row['type']][2].' = '.$row['ref_id']);
  133. $resource_name = Database ::fetch_array($tempsql);
  134. //var_dump($resource_name['lp_type']);
  135. if (isset($resource_name['lp_type'])) {
  136. $resource_name=$resource_name[2];
  137. } else {
  138. $resource_name=$resource_name[1];
  139. }
  140. $output.= '<tr><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>';
  141. }
  142. $sql = Database::query('SELECT * FROM '.$table_evaluation.' WHERE category_id = '.$category_id);
  143. while($row = Database ::fetch_array($sql)) {
  144. //update only if value changed
  145. if(isset($_POST['evaluation'][$row['id']]) && $_POST['evaluation'][$row['id']] != $row['weight']) {
  146. Evaluation::add_evaluation_log($row['id']);
  147. Database::query('UPDATE '.$table_evaluation.' SET weight = '."'".trim($_POST['evaluation'][$row['id']])."'".' WHERE id = '.$row['id']);
  148. $row['weight'] = trim($_POST['evaluation'][$row['id']]);
  149. }
  150. $type_evaluated = isset($row['type']) ? $table_evaluated[$type_evaluated][3] : null;
  151. $output.= '<tr><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>';
  152. }
  153. //by iflorespaz
  154. $my_category=array();
  155. $cat=new Category();
  156. $my_category = $cat->shows_all_information_an_category($my_selectcat);
  157. $my_api_cidreq = api_get_cidreq();
  158. if ($my_api_cidreq=='') {
  159. $my_api_cidreq='cidReq='.$my_category['course_code'];
  160. }
  161. ?>
  162. <div class="actions">
  163. <a href="<?php echo $_SESSION['gradebook_dest'].'?id_session='.$_SESSION['id_session'].'&amp;'.$my_api_cidreq ?>&selectcat=<?php echo $category_id ?>"> <?php echo Display::return_icon('back.png',get_lang('FolderView')) . get_lang('FolderView') ?></a>
  164. </div>
  165. <form method="post" action="gradebook_edit_all.php?id_session=<?php echo $_SESSION['id_session'].'&amp;'.$my_api_cidreq ?>&selectcat=<?php echo $category_id?>">
  166. <table class="data_table">
  167. <tr class="row_odd">
  168. <th><?php echo get_lang('Resource'); ?></th>
  169. <th><?php echo get_lang('Weight'); ?></th>
  170. </tr>
  171. <?php echo $output ?>
  172. </table>
  173. <input type="hidden" name="submitted" value="1" />
  174. <button class="save" type="submit" name="name" value="<?php echo get_lang('Save') ?>"><?php echo get_lang('SaveScoringRules') ?></button>
  175. </form>
  176. <?php
  177. Display :: display_footer();
  178. ?>