gradebook_display_certificate.php 8.2 KB

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