gradebook_display_certificate.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once __DIR__.'/../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. $userList = CourseManager::get_user_list_from_course_code(
  47. api_get_course_id(),
  48. api_get_session_id()
  49. );
  50. if (!empty($userList)) {
  51. foreach ($userList as $userInfo) {
  52. if ($userInfo['status'] == INVITEE) {
  53. continue;
  54. }
  55. Category::register_user_certificate($cat_id, $userInfo['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(
  65. 'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?',
  66. 'name' => get_lang('Gradebook'),
  67. );
  68. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('GradebookListOfStudentsCertificates'));
  69. $this_section = SECTION_COURSES;
  70. Display::display_header('');
  71. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  72. $check = Security::check_token('get');
  73. if ($check) {
  74. $certificate = new Certificate($_GET['certificate_id']);
  75. $result = $certificate->delete(true);
  76. Security::clear_token();
  77. if ($result == true) {
  78. echo Display::return_message(get_lang('CertificateRemoved'), 'confirmation');
  79. } else {
  80. echo Display::return_message(get_lang('CertificateNotRemoved'), 'error');
  81. }
  82. }
  83. }
  84. $token = Security::get_token();
  85. echo Display::page_header(get_lang('GradebookListOfStudentsCertificates'));
  86. //@todo replace all this code with something like get_total_weight()
  87. $cats = Category:: load($cat_id, null, null, null, null, null, false);
  88. if (!empty($cats)) {
  89. //with this fix the teacher only can view 1 gradebook
  90. if (api_is_platform_admin()) {
  91. $stud_id = (api_is_allowed_to_edit() ? null : api_get_user_id());
  92. } else {
  93. $stud_id = api_get_user_id();
  94. }
  95. $total_weight = $cats[0]->get_weight();
  96. $allcat = $cats[0]->get_subcategories(
  97. $stud_id,
  98. api_get_course_id(),
  99. api_get_session_id()
  100. );
  101. $alleval = $cats[0]->get_evaluations($stud_id);
  102. $alllink = $cats[0]->get_links($stud_id);
  103. $datagen = new GradebookDataGenerator($allcat, $alleval, $alllink);
  104. $total_resource_weight = 0;
  105. if (!empty($datagen)) {
  106. $data_array = $datagen->get_data(
  107. GradebookDataGenerator :: GDG_SORT_NAME,
  108. 0,
  109. null,
  110. true
  111. );
  112. if (!empty($data_array)) {
  113. $newarray = array();
  114. foreach ($data_array as $data) {
  115. $newarray[] = array_slice($data, 1);
  116. }
  117. foreach ($newarray as $item) {
  118. $total_resource_weight = $total_resource_weight + $item['2'];
  119. }
  120. }
  121. }
  122. if ($total_resource_weight != $total_weight) {
  123. echo Display::return_message(get_lang('SumOfActivitiesWeightMustBeEqualToTotalWeight'), 'warning');
  124. }
  125. }
  126. $filter = api_get_setting('certificate_filter_by_official_code');
  127. $userList = array();
  128. $filterForm = null;
  129. $certificate_list = array();
  130. if ($filter === 'true') {
  131. echo '<br />';
  132. $options = UserManager::getOfficialCodeGrouped();
  133. $options = array_merge(array('all' => get_lang('All')), $options);
  134. $form = new FormValidator(
  135. 'official_code_filter',
  136. 'POST',
  137. api_get_self().'?'.api_get_cidreq().'&cat_id='.$cat_id
  138. );
  139. $form->addElement('select', 'filter', get_lang('OfficialCode'), $options);
  140. $form->addButton('submit', get_lang('Submit'));
  141. $filterForm = '<br />'.$form->returnForm();
  142. if ($form->validate()) {
  143. $officialCode = $form->getSubmitValue('filter');
  144. if ($officialCode == 'all') {
  145. $certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
  146. } else {
  147. $userList = UserManager::getUsersByOfficialCode($officialCode);
  148. if (!empty($userList)) {
  149. $certificate_list = GradebookUtils::get_list_users_certificates(
  150. $cat_id,
  151. $userList
  152. );
  153. }
  154. }
  155. } else {
  156. $certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
  157. }
  158. } else {
  159. $certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
  160. }
  161. echo '<div class="btn-group">';
  162. $url = api_get_self().'?action=generate_all_certificates'.'&'.api_get_cidreq().'&cat_id='.$cat_id.'&filter='.$filterOfficialCode;
  163. echo Display::url(get_lang('GenerateCertificates'), $url, array('class' => 'btn btn-default'));
  164. $url = api_get_self().'?action=delete_all_certificates'.'&'.api_get_cidreq().'&cat_id='.$cat_id.'&filter='.$filterOfficialCode;
  165. echo Display::url(get_lang('DeleteAllCertificates'), $url, array('class' => 'btn btn-default'));
  166. $hideCertificateExport = api_get_setting('hide_certificate_export_link');
  167. if (count($certificate_list) > 0 && $hideCertificateExport !== 'true') {
  168. $url = api_get_self().'?action=export_all_certificates'.'&'.api_get_cidreq().'&cat_id='.$cat_id.'&filter='.$filterOfficialCode;
  169. echo Display::url(get_lang('ExportAllCertificatesToPDF'), $url, array('class' => 'btn btn-default'));
  170. }
  171. echo '</div>';
  172. echo $filterForm;
  173. if (count($certificate_list) == 0) {
  174. echo Display::return_message(get_lang('NoResultsAvailable'), 'warning');
  175. } else {
  176. echo '<br /><br /><table class="data_table">';
  177. foreach ($certificate_list as $index => $value) {
  178. echo '<tr>
  179. <td width="100%" class="actions">'.get_lang('Student').' : '.api_get_person_name($value['firstname'], $value['lastname']).' ('.$value['username'].')</td>';
  180. echo '</tr>';
  181. echo '<tr><td>
  182. <table class="data_table">';
  183. $list_certificate = GradebookUtils::get_list_gradebook_certificates_by_user_id($value['user_id'], $cat_id);
  184. foreach ($list_certificate as $value_certificate) {
  185. echo '<tr>';
  186. echo '<td width="50%">'.get_lang('Score').' : '.$value_certificate['score_certificate'].'</td>';
  187. echo '<td width="30%">'.get_lang('Date').' : '.api_convert_and_format_date($value_certificate['created_at']).'</td>';
  188. echo '<td width="20%">';
  189. $url = api_get_path(WEB_PATH).'certificates/index.php?id='.$value_certificate['id'];
  190. $certificates = Display::url(get_lang('Certificate'), $url, array('target'=>'_blank', 'class' => 'btn btn-default'));
  191. echo $certificates;
  192. 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'].'">
  193. '.Display::return_icon('delete.png', get_lang('Delete')).'
  194. </a>';
  195. echo '</td></tr>';
  196. }
  197. echo '</table>';
  198. echo '</td></tr>';
  199. }
  200. echo '</table>';
  201. }
  202. Display::display_footer();