index.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $certificate = new Certificate($_GET['id']);
  11. CustomCertificatePlugin::redirectCheck($certificate, $_GET['id']);
  12. switch ($action) {
  13. case 'export':
  14. $hideExportLink = api_get_setting('hide_certificate_export_link');
  15. $hideExportLinkStudent = api_get_setting('hide_certificate_export_link_students');
  16. if ($hideExportLink === 'true' ||
  17. (api_is_student() && $hideExportLinkStudent === 'true')
  18. ) {
  19. api_not_allowed(true);
  20. }
  21. $certificate->generate(['hide_print_button' => true]);
  22. if ($certificate->isHtmlFileGenerated()) {
  23. $certificatePathList[] = $certificate->html_file;
  24. $pdfParams = [
  25. 'top' => 0,
  26. 'right' => 0,
  27. 'bottom' => 0,
  28. 'left' => 0,
  29. ];
  30. $orientation = api_get_configuration_value('certificate_pdf_orientation');
  31. $pdfParams['orientation'] = 'landscape';
  32. if (!empty($orientation)) {
  33. $pdfParams['orientation'] = $orientation;
  34. }
  35. $pageFormat = $pdfParams['orientation'] === 'landscape' ? 'A4-L' : 'A4';
  36. $userInfo = api_get_user_info($certificate->user_id);
  37. $pdfName = api_replace_dangerous_char(
  38. get_lang('Certificate').' '.$userInfo['username']
  39. );
  40. $pdf = new PDF($pageFormat, $pdfParams['orientation'], $pdfParams);
  41. $pdf->html_to_pdf(
  42. $certificatePathList,
  43. $pdfName,
  44. null,
  45. false,
  46. false
  47. );
  48. }
  49. break;
  50. default:
  51. // Special rules for anonymous users
  52. if (!$certificate->isVisible()) {
  53. Display::display_reduced_header();
  54. echo Display::return_message(
  55. get_lang('CertificateExistsButNotPublic'),
  56. 'warning'
  57. );
  58. Display::display_reduced_footer();
  59. break;
  60. }
  61. if (!$certificate->isAvailable()) {
  62. Display::display_reduced_header();
  63. echo Display::return_message(
  64. get_lang('NoCertificateAvailable'),
  65. 'error'
  66. );
  67. Display::display_reduced_footer();
  68. break;
  69. }
  70. // Show certificate HTML
  71. $certificate->show();
  72. break;
  73. }