index.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Show specified user certificate.
  5. *
  6. * @package chamilo.certificate
  7. */
  8. require_once '../main/inc/global.inc.php';
  9. $action = isset($_GET['action']) ? $_GET['action'] : null;
  10. $userId = isset($_GET['user_id']) ? $_GET['user_id'] : 0;
  11. $certificateId = isset($_GET['id']) ? $_GET['id'] : 0;
  12. $certificate = new Certificate($certificateId, $userId);
  13. $certificateData = $certificate->get($certificateId);
  14. if (empty($certificateData)) {
  15. api_not_allowed(false, Display::return_message(get_lang('NoCertificateAvailable'), 'warning'));
  16. }
  17. $category = Category::findByCertificate($certificateId);
  18. // Check if the certificate should use the course language
  19. if (!empty($category) && !empty($category->get_course_code())) {
  20. $courseInfo = api_get_course_info($category->get_course_code());
  21. $language = $courseInfo['language'];
  22. $languageFilesToLoad = api_get_language_files_to_load($language);
  23. foreach ($languageFilesToLoad as $languageFile) {
  24. include $languageFile;
  25. }
  26. // Overwrite the interface language with the course language
  27. $language_interface = $language;
  28. $language_interface_initial_value = $language_interface;
  29. }
  30. CustomCertificatePlugin::redirectCheck($certificate, $certificateId, $userId);
  31. switch ($action) {
  32. case 'export':
  33. $hideExportLink = api_get_setting('hide_certificate_export_link');
  34. $hideExportLinkStudent = api_get_setting('hide_certificate_export_link_students');
  35. if ($hideExportLink === 'true' ||
  36. (api_is_student() && $hideExportLinkStudent === 'true')
  37. ) {
  38. api_not_allowed(true);
  39. }
  40. $certificate->generate(['hide_print_button' => true]);
  41. if ($certificate->isHtmlFileGenerated()) {
  42. $certificatePathList[] = $certificate->html_file;
  43. $pdfParams = [
  44. 'top' => 0,
  45. 'right' => 0,
  46. 'bottom' => 0,
  47. 'left' => 0,
  48. ];
  49. $orientation = api_get_configuration_value('certificate_pdf_orientation');
  50. $pdfParams['orientation'] = 'landscape';
  51. if (!empty($orientation)) {
  52. $pdfParams['orientation'] = $orientation;
  53. }
  54. $pageFormat = $pdfParams['orientation'] === 'landscape' ? 'A4-L' : 'A4';
  55. $userInfo = api_get_user_info($certificate->user_id);
  56. $pdfName = api_replace_dangerous_char(
  57. get_lang('Certificate').' '.$userInfo['username']
  58. );
  59. $pdf = new PDF($pageFormat, $pdfParams['orientation'], $pdfParams);
  60. $pdf->html_to_pdf(
  61. $certificatePathList,
  62. $pdfName,
  63. null,
  64. false,
  65. false
  66. );
  67. }
  68. break;
  69. default:
  70. // Special rules for anonymous users
  71. if (!$certificate->isVisible()) {
  72. api_not_allowed(false, Display::return_message(get_lang('CertificateExistsButNotPublic'), 'warning'));
  73. break;
  74. }
  75. if (!$certificate->isAvailable()) {
  76. api_not_allowed(false, Display::return_message(get_lang('NoCertificateAvailable'), 'warning'));
  77. break;
  78. }
  79. // Show certificate HTML
  80. $certificate->show();
  81. break;
  82. }