export_certificates.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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();