export_certificates.php 1.6 KB

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