export_certificates.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // Language files that need to be included.
  7. $language_file = array('admin');
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be.inc.php';
  11. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  12. Display::display_header(null);
  13. $form = new FormValidator('export_certificate');
  14. $courses = CourseManager::get_courses_list(0, 0, 'title');
  15. $options = array();
  16. foreach ($courses as $course) {
  17. $options[$course['id']] = $course['title'];
  18. }
  19. $form->addElement('select', 'course', get_lang('Course'), $options);
  20. $form->addElement('file', 'file', get_lang('File'));
  21. $form->add_button('submit', get_lang('Submit'));
  22. $form->display();
  23. if ($form->validate()) {
  24. $values = $form->getSubmitValues();
  25. if (isset($_FILES['file']['tmp_name']) &&
  26. !empty($_FILES['file']['tmp_name'])
  27. ) {
  28. $users = Import::csv_reader($_FILES['file']['tmp_name']);
  29. $courseId = $values['course'];
  30. $courseInfo = api_get_course_info_by_id($courseId);
  31. $courseCode = $courseInfo['code'];
  32. $cats = Category:: load(
  33. null,
  34. null,
  35. $courseCode,
  36. null,
  37. null,
  38. 0,
  39. false
  40. );
  41. if (isset($cats[0])) {
  42. /** @var Category $cat */
  43. $userList = array();
  44. foreach ($users as $user) {
  45. $userInfo = api_get_user_info_from_official_code(
  46. $user['official_code']
  47. );
  48. if (!empty($userInfo)) {
  49. $userList[] = $userInfo;
  50. }
  51. }
  52. Category::exportAllCertificates(
  53. $cat->get_id(),
  54. $userList
  55. );
  56. }
  57. }
  58. }
  59. Display :: display_footer();