gradebook_display_certificate.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. $current_course_tool = TOOL_GRADEBOOK;
  8. if (!api_is_student_boss()) {
  9. api_protect_course_script(true);
  10. }
  11. set_time_limit(0);
  12. ini_set('max_execution_time', 0);
  13. //extra javascript functions for in html head:
  14. $htmlHeadXtra[] ="<script>
  15. function confirmation() {
  16. if (confirm(\" " . trim(get_lang('AreYouSureToDelete')) . " ?\")) {
  17. return true;
  18. } else {
  19. return false;
  20. }
  21. }
  22. </script>";
  23. api_block_anonymous_users();
  24. if (!api_is_allowed_to_edit() && !api_is_student_boss()) {
  25. api_not_allowed(true);
  26. }
  27. $cat_id = isset($_GET['cat_id']) ? (int)$_GET['cat_id'] : null;
  28. $action = isset($_GET['action']) && $_GET['action'] ? $_GET['action'] : null;
  29. $filterOfficialCode = isset($_POST['filter']) ? Security::remove_XSS($_POST['filter']) : null;
  30. $filterOfficialCodeGet = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
  31. switch ($action) {
  32. case 'export_all_certificates':
  33. if (api_is_student_boss()) {
  34. $userGroup = new UserGroup();
  35. $userList = $userGroup->getGroupUsersByUser(api_get_user_id());
  36. } else {
  37. $userList = array();
  38. if (!empty($filterOfficialCodeGet)) {
  39. $userList = UserManager::getUsersByOfficialCode($filterOfficialCodeGet);
  40. }
  41. }
  42. Category::exportAllCertificates($cat_id, $userList);
  43. break;
  44. case 'generate_all_certificates':
  45. $user_list = CourseManager::get_user_list_from_course_code(
  46. api_get_course_id(),
  47. api_get_session_id()
  48. );
  49. if (!empty($user_list)) {
  50. foreach ($user_list as $user_info) {
  51. if ($user_info['status'] == INVITEE) {
  52. continue;
  53. }
  54. Category::register_user_certificate($cat_id, $user_info['user_id']);
  55. }
  56. }
  57. break;
  58. case 'delete_all_certificates':
  59. Category::deleteAllCertificates($cat_id);
  60. break;
  61. }
  62. $course_code = api_get_course_id();
  63. $interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?', 'name' => get_lang('Gradebook'));
  64. $interbreadcrumb[] = array('url' => '#','name' => get_lang('GradebookListOfStudentsCertificates'));
  65. $this_section = SECTION_COURSES;
  66. Display::display_header('');
  67. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  68. $check = Security::check_token('get');
  69. if ($check) {
  70. $certificate = new Certificate($_GET['certificate_id']);
  71. $result = $certificate->delete(true);
  72. Security::clear_token();
  73. if ($result ==true) {
  74. Display::display_confirmation_message(get_lang('CertificateRemoved'));
  75. } else {
  76. Display::display_error_message(get_lang('CertificateNotRemoved'));
  77. }
  78. }
  79. }
  80. $token = Security::get_token();
  81. echo Display::page_header(get_lang('GradebookListOfStudentsCertificates'));
  82. //@todo replace all this code with something like get_total_weight()
  83. $cats = Category :: load($cat_id, null, null, null, null, null, false);
  84. if (!empty($cats)) {
  85. //with this fix the teacher only can view 1 gradebook
  86. if (api_is_platform_admin()) {
  87. $stud_id= (api_is_allowed_to_edit() ? null : api_get_user_id());
  88. } else {
  89. $stud_id= api_get_user_id();
  90. }
  91. $total_weight = $cats[0]->get_weight();
  92. $allcat = $cats[0]->get_subcategories($stud_id, api_get_course_id(), api_get_session_id());
  93. $alleval = $cats[0]->get_evaluations($stud_id);
  94. $alllink = $cats[0]->get_links($stud_id);
  95. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  96. $total_resource_weight = 0;
  97. if (!empty($datagen)) {
  98. $data_array = $datagen->get_data(
  99. GradebookDataGenerator :: GDG_SORT_NAME,
  100. 0,
  101. null,
  102. true
  103. );
  104. if (!empty($data_array)) {
  105. $newarray = array();
  106. foreach ($data_array as $data) {
  107. $newarray[] = array_slice($data, 1);
  108. }
  109. foreach($newarray as $item) {
  110. $total_resource_weight = $total_resource_weight + $item['2'];
  111. }
  112. }
  113. }
  114. if ($total_resource_weight != $total_weight) {
  115. Display::display_warning_message(get_lang('SumOfActivitiesWeightMustBeEqualToTotalWeight'));
  116. }
  117. }
  118. $filter = api_get_setting('certificate_filter_by_official_code');
  119. $userList = array();
  120. $filterForm = null;
  121. $certificate_list = array();
  122. if ($filter === 'true') {
  123. echo '<br />';
  124. $options = UserManager::getOfficialCodeGrouped();
  125. $options =array_merge(array('all' => get_lang('All')), $options);
  126. $form = new FormValidator(
  127. 'official_code_filter',
  128. 'POST',
  129. api_get_self().'?'.api_get_cidreq().'&cat_id='.$cat_id
  130. );
  131. $form->addElement('select', 'filter', get_lang('OfficialCode'), $options);
  132. $form->addButton('submit', get_lang('Submit'));
  133. $filterForm = '<br />'.$form->return_form();
  134. if ($form->validate()) {
  135. $officialCode = $form->getSubmitValue('filter');
  136. if ($officialCode == 'all') {
  137. $certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
  138. } else {
  139. $userList = UserManager::getUsersByOfficialCode($officialCode);
  140. if (!empty($userList)) {
  141. $certificate_list = GradebookUtils::get_list_users_certificates(
  142. $cat_id,
  143. $userList
  144. );
  145. }
  146. }
  147. } else {
  148. $certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
  149. }
  150. } else {
  151. $certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
  152. }
  153. echo '<div class="btn-group">';
  154. $url = api_get_self().'?action=generate_all_certificates'.'&'.api_get_cidreq().'&cat_id='.$cat_id.'&filter='.$filterOfficialCode;
  155. echo Display::url(get_lang('GenerateCertificates'), $url, array('class' => 'btn btn-default'));
  156. $url = api_get_self().'?action=delete_all_certificates'.'&'.api_get_cidreq().'&cat_id='.$cat_id.'&filter='.$filterOfficialCode;
  157. echo Display::url(get_lang('DeleteAllCertificates'), $url, array('class' => 'btn btn-default'));
  158. $hideCertificateExport = api_get_setting('hide_certificate_export_link');
  159. if (count($certificate_list) > 0 && $hideCertificateExport !== 'true') {
  160. $url = api_get_self().'?action=export_all_certificates'.'&'.api_get_cidreq().'&cat_id='.$cat_id.'&filter='.$filterOfficialCode;
  161. echo Display::url(get_lang('ExportAllCertificatesToPDF'), $url, array('class' => 'btn btn-default'));
  162. }
  163. echo '</div>';
  164. echo $filterForm;
  165. if (count($certificate_list) == 0 ) {
  166. echo Display::display_warning_message(get_lang('NoResultsAvailable'));
  167. } else {
  168. echo '<br /><br /><table class="data_table">';
  169. foreach ($certificate_list as $index=>$value) {
  170. echo '<tr>
  171. <td width="100%" class="actions">'.get_lang('Student').' : '.api_get_person_name($value['firstname'], $value['lastname']).' ('.$value['username'].')</td>';
  172. echo '</tr>';
  173. echo '<tr><td>
  174. <table class="data_table">';
  175. $list_certificate = GradebookUtils::get_list_gradebook_certificates_by_user_id($value['user_id'], $cat_id);
  176. foreach ($list_certificate as $value_certificate) {
  177. echo '<tr>';
  178. echo '<td width="50%">'.get_lang('Score').' : '.$value_certificate['score_certificate'].'</td>';
  179. echo '<td width="30%">'.get_lang('Date').' : '.api_convert_and_format_date($value_certificate['created_at']).'</td>';
  180. echo '<td width="20%">';
  181. $url = api_get_path(WEB_PATH).'certificates/index.php?id='.$value_certificate['id'];
  182. $certificates = Display::url(get_lang('Certificate'), $url, array('target'=>'_blank', 'class' => 'btn btn-default'));
  183. echo $certificates;
  184. echo '<a onclick="return confirmation();" href="gradebook_display_certificate.php?sec_token='.$token.'&'.api_get_cidreq().'&action=delete&cat_id='.$cat_id.'&certificate_id='.$value_certificate['id'].'">
  185. '.Display::return_icon('delete.png',get_lang('Delete')).'
  186. </a>';
  187. echo '</td></tr>';
  188. }
  189. echo '</table>';
  190. echo '</td></tr>';
  191. }
  192. echo '</table>';
  193. }
  194. Display::display_footer();