export_certificates.php 1.7 KB

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