index.php 2.5 KB

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