gradebook_display_certificate.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. /**
  8. * Init
  9. */
  10. $language_file = 'gradebook';
  11. require_once '../inc/global.inc.php';
  12. $current_course_tool = TOOL_GRADEBOOK;
  13. api_protect_course_script();
  14. require_once 'lib/gradebook_functions.inc.php';
  15. require_once 'lib/be.inc.php';
  16. require_once 'lib/gradebook_data_generator.class.php';
  17. //extra javascript functions for in html head:
  18. $htmlHeadXtra[] =
  19. "<script>
  20. function confirmation() {
  21. if (confirm(\" ".trim(get_lang('AreYouSureToDelete'))." ?\"))
  22. {return true;}
  23. else
  24. {return false;}
  25. }
  26. </script>";
  27. api_block_anonymous_users();
  28. if (!api_is_allowed_to_edit()) {
  29. api_not_allowed(true);
  30. }
  31. $course_code = api_get_course_id();
  32. $interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?', 'name' => get_lang('Gradebook'));
  33. $interbreadcrumb[] = array ('url' => '#','name' => get_lang('GradebookListOfStudentsCertificates'));
  34. $this_section = SECTION_COURSES;
  35. Display::display_header('');
  36. if ($_GET['action'] == 'delete') {
  37. $check = Security::check_token('get');
  38. if ($check) {
  39. $certificate = new Certificate($_GET['certificate_id']);
  40. $result = $certificate->delete();
  41. Security::clear_token();
  42. if ($result ==true) {
  43. Display::display_confirmation_message(get_lang('CertificateRemoved'));
  44. } else {
  45. Display::display_error_message(get_lang('CertificateNotRemoved'));
  46. }
  47. }
  48. }
  49. $token = Security::get_token();
  50. echo Display::page_header(get_lang('GradebookListOfStudentsCertificates'));
  51. $cat_id = isset($_GET['cat_id']) ? (int)$_GET['cat_id'] : null;
  52. //@todo replace all this code with something like get_total_weight()
  53. $cats = Category :: load ($cat_id, null, null, null, null, null, false);
  54. if (!empty($cats)) {
  55. //with this fix the teacher only can view 1 gradebook
  56. if (api_is_platform_admin()) {
  57. $stud_id= (api_is_allowed_to_edit() ? null : api_get_user_id());
  58. } else {
  59. $stud_id= api_get_user_id();
  60. }
  61. $total_weight = $cats[0]->get_weight();
  62. $allcat = $cats[0]->get_subcategories($stud_id, api_get_course_id(), api_get_session_id());
  63. $alleval = $cats[0]->get_evaluations($stud_id);
  64. $alllink = $cats[0]->get_links($stud_id);
  65. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  66. $total_resource_weight = 0;
  67. if (!empty($datagen)) {
  68. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  69. if (!empty($data_array)) {
  70. $newarray = array();
  71. foreach ($data_array as $data) {
  72. $newarray[] = array_slice($data, 1);
  73. }
  74. foreach($newarray as $item) {
  75. $total_resource_weight = $total_resource_weight + $item['2'];
  76. }
  77. }
  78. }
  79. if ($total_resource_weight != $total_weight) {
  80. Display::display_warning_message(get_lang('SumOfActivitiesWeightMustBeEqualToTotalWeight'));
  81. }
  82. }
  83. $certificate_list = get_list_users_certificates($cat_id);
  84. if (count($certificate_list)==0) {
  85. echo Display::display_warning_message(get_lang('NoResultsAvailable'));
  86. } else {
  87. echo '<table class="data_table">';
  88. foreach ($certificate_list as $index=>$value) {
  89. echo '<tr>
  90. <td width="100%" class="actions">'.get_lang('Student').' : '.api_get_person_name($value['firstname'], $value['lastname']).' ( '.$value['username'].')</td>';
  91. echo '</tr>';
  92. echo '<tr><td>
  93. <table class="data_table">';
  94. $list_certificate = get_list_gradebook_certificates_by_user_id ($value['user_id'], $cat_id);
  95. foreach ($list_certificate as $value_certificate) {
  96. echo '<tr>';
  97. echo '<td width="50%">'.get_lang('Score').' : '.$value_certificate['score_certificate'].'</td>';
  98. echo '<td width="30%">'.get_lang('Date').' : '.api_convert_and_format_date($value_certificate['created_at']).'</td>';
  99. echo '<td width="20%">';
  100. //$url = "index.php?export_certificate=yes&cat_id=".$cat_id."&user=".$value['user_id'];
  101. $url = api_get_path(WEB_PATH).'certificates/index.php?id='.$value_certificate['id'];
  102. $certificates = Display::url(get_lang('Certificate'), $url, array('target'=>'_blank', 'class' => 'btn'));
  103. echo $certificates;
  104. echo '<a onclick="return confirmation();" href="gradebook_display_certificate.php?sec_token='.$token.'&cidReq='.$course_code.'&action=delete&cat_id='.$cat_id.'&certificate_id='.$value_certificate['id'].'">
  105. '.Display::return_icon('delete.png',get_lang('Delete')).'
  106. </a>';
  107. echo '</td></tr>';
  108. }
  109. echo '</table>';
  110. echo '</td></tr>';
  111. }
  112. echo '</table>';
  113. }
  114. Display::display_footer();