index.php 2.5 KB

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