gradebook_edit_all.php 8.6 KB

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