gradebook_display_certificate.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $cat_id = isset($_GET['cat_id']) ? (int)$_GET['cat_id'] : null;
  32. $action = isset($_GET['action']) && $_GET['action'] ? $_GET['action'] : null;
  33. switch ($action) {
  34. case 'export_all_certificates':
  35. $params['orientation'] = 'landscape';
  36. $page_format = $params['orientation'] == 'landscape' ? 'A4-L' : 'A4';
  37. $pdf = new PDF($page_format, $params['orientation'], $params);
  38. $certificate_list = get_list_users_certificates($cat_id);
  39. $certificate_path_list = array();
  40. if (!empty($certificate_list)) {
  41. foreach ($certificate_list as $index=>$value) {
  42. $list_certificate = get_list_gradebook_certificates_by_user_id($value['user_id'], $cat_id);
  43. foreach ($list_certificate as $value_certificate) {
  44. $certificate_obj = new Certificate($value_certificate['id']);
  45. $certificate_obj->generate(array('hide_print_button' => true));
  46. if ($certificate_obj->html_file_is_generated()) {
  47. $certificate_path_list[]= $certificate_obj->html_file;
  48. }
  49. }
  50. }
  51. }
  52. if (!empty($certificate_path_list)) {
  53. // Print certificates (without the common header/footer/watermark
  54. // stuff) and return as one multiple-pages PDF
  55. $pdf->html_to_pdf($certificate_path_list, get_lang('Certificates'), null, false, false);
  56. }
  57. break;
  58. case 'generate_all_certificates':
  59. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id());
  60. if (!empty($user_list)) {
  61. foreach ($user_list as $user_info) {
  62. Category::register_user_certificate($cat_id, $user_info['user_id']);
  63. }
  64. }
  65. break;
  66. case 'delete_all_certificates':
  67. $certificate_list = get_list_users_certificates($cat_id);
  68. if (!empty($certificate_list)) {
  69. foreach ($certificate_list as $index=>$value) {
  70. $list_certificate = get_list_gradebook_certificates_by_user_id($value['user_id'], $cat_id);
  71. foreach ($list_certificate as $value_certificate) {
  72. $certificate_obj = new Certificate($value_certificate['id']);
  73. $certificate_obj->delete(true);
  74. }
  75. }
  76. }
  77. break;
  78. }
  79. $course_code = api_get_course_id();
  80. $interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?', 'name' => get_lang('Gradebook'));
  81. $interbreadcrumb[] = array ('url' => '#','name' => get_lang('GradebookListOfStudentsCertificates'));
  82. $this_section = SECTION_COURSES;
  83. Display::display_header('');
  84. if ($_GET['action'] == 'delete') {
  85. $check = Security::check_token('get');
  86. if ($check) {
  87. $certificate = new Certificate($_GET['certificate_id']);
  88. $result = $certificate->delete(true);
  89. Security::clear_token();
  90. if ($result ==true) {
  91. Display::display_confirmation_message(get_lang('CertificateRemoved'));
  92. } else {
  93. Display::display_error_message(get_lang('CertificateNotRemoved'));
  94. }
  95. }
  96. }
  97. $token = Security::get_token();
  98. echo Display::page_header(get_lang('GradebookListOfStudentsCertificates'));
  99. $cat_id = isset($_GET['cat_id']) ? (int)$_GET['cat_id'] : null;
  100. //@todo replace all this code with something like get_total_weight()
  101. $cats = Category :: load ($cat_id, null, null, null, null, null, false);
  102. if (!empty($cats)) {
  103. //with this fix the teacher only can view 1 gradebook
  104. if (api_is_platform_admin()) {
  105. $stud_id= (api_is_allowed_to_edit() ? null : api_get_user_id());
  106. } else {
  107. $stud_id= api_get_user_id();
  108. }
  109. $total_weight = $cats[0]->get_weight();
  110. $allcat = $cats[0]->get_subcategories($stud_id, api_get_course_id(), api_get_session_id());
  111. $alleval = $cats[0]->get_evaluations($stud_id);
  112. $alllink = $cats[0]->get_links($stud_id);
  113. $datagen = new GradebookDataGenerator($allcat,$alleval, $alllink);
  114. $total_resource_weight = 0;
  115. if (!empty($datagen)) {
  116. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  117. if (!empty($data_array)) {
  118. $newarray = array();
  119. foreach ($data_array as $data) {
  120. $newarray[] = array_slice($data, 1);
  121. }
  122. foreach($newarray as $item) {
  123. $total_resource_weight = $total_resource_weight + $item['2'];
  124. }
  125. }
  126. }
  127. if ($total_resource_weight != $total_weight) {
  128. Display::display_warning_message(get_lang('SumOfActivitiesWeightMustBeEqualToTotalWeight'));
  129. }
  130. }
  131. $certificate_list = get_list_users_certificates($cat_id);
  132. echo '<div class="btn-group">';
  133. $url = api_get_self().'?action=generate_all_certificates'.'&'.api_get_cidReq().'&cat_id='.$cat_id;
  134. echo Display::url(get_lang('GenerateCertificates'), $url, array('class' => 'btn'));
  135. $url = api_get_self().'?action=delete_all_certificates'.'&'.api_get_cidReq().'&cat_id='.$cat_id;
  136. echo Display::url(get_lang('DeleteAllCertificates'), $url, array('class' => 'btn'));
  137. if (count($certificate_list) > 0) {
  138. $url = api_get_self().'?action=export_all_certificates'.'&'.api_get_cidReq().'&cat_id='.$cat_id;
  139. echo Display::url(get_lang('ExportAllCertificatesToPDF'), $url, array('class' => 'btn'));
  140. }
  141. echo '</div>';
  142. if (count($certificate_list)==0) {
  143. echo Display::display_warning_message(get_lang('NoResultsAvailable'));
  144. } else {
  145. echo '<br /><br /><table class="data_table">';
  146. foreach ($certificate_list as $index=>$value) {
  147. echo '<tr>
  148. <td width="100%" class="actions">'.get_lang('Student').' : '.api_get_person_name($value['firstname'], $value['lastname']).' ( '.$value['username'].')</td>';
  149. echo '</tr>';
  150. echo '<tr><td>
  151. <table class="data_table">';
  152. $list_certificate = get_list_gradebook_certificates_by_user_id($value['user_id'], $cat_id);
  153. foreach ($list_certificate as $value_certificate) {
  154. echo '<tr>';
  155. echo '<td width="50%">'.get_lang('Score').' : '.$value_certificate['score_certificate'].'</td>';
  156. echo '<td width="30%">'.get_lang('Date').' : '.api_convert_and_format_date($value_certificate['created_at']).'</td>';
  157. echo '<td width="20%">';
  158. $url = Certificate::getCertificatePublicURL($value_certificate['id']);
  159. $certificates = Display::url(get_lang('Certificate'), $url, array('target'=>'_blank', 'class' => 'btn'));
  160. echo $certificates;
  161. 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'].'">
  162. '.Display::return_icon('delete.png',get_lang('Delete')).'
  163. </a>';
  164. echo '</td></tr>';
  165. }
  166. echo '</table>';
  167. echo '</td></tr>';
  168. }
  169. echo '</table>';
  170. }
  171. Display::display_footer();