index.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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('CertificateExistsButNotPublic'),
  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('NoCertificateAvailable'),
  66. 'error'
  67. );
  68. Display::display_reduced_footer();
  69. break;
  70. }
  71. // Show certificate HTML
  72. $certificate->show();
  73. break;
  74. }