index.php 2.7 KB

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