index.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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' || (api_is_student() && $hideExportLinkStudent === 'true')) {
  15. api_not_allowed(true);
  16. }
  17. $certificate->generate(array('hide_print_button' => true));
  18. if ($certificate->html_file_is_generated()) {
  19. $certificatePathList[] = $certificate->html_file;
  20. $pdfParams = array(
  21. 'orientation' => 'landscape',
  22. 'top' => 0,
  23. 'right' => 0,
  24. 'bottom' => 0,
  25. 'left' => 0
  26. );
  27. $pdfParams['orientation'] = 'landscape';
  28. $pageFormat = $pdfParams['orientation'] === 'landscape' ? 'A4-L' : 'A4';
  29. $userInfo = api_get_user_info($certificate->user_id);
  30. $pdfName = api_replace_dangerous_char(get_lang('Certificate') . ' ' . $userInfo['username']);
  31. $pdf = new PDF($pageFormat, $pdfParams['orientation'], $pdfParams);
  32. $pdf->html_to_pdf($certificatePathList, $pdfName, null, false, false);
  33. }
  34. break;
  35. default:
  36. // Special rules for anonymous users
  37. if (!$certificate->isVisible()) {
  38. Display::display_reduced_header();
  39. echo Display::return_message(get_lang('CertificateExistsButNotPublic'), 'warning');
  40. Display::display_reduced_footer();
  41. break;
  42. }
  43. if (!$certificate->isAvailable()) {
  44. Display::display_reduced_header();
  45. echo Display::return_message(get_lang('NoCertificateAvailable'), 'error');
  46. Display::display_reduced_footer();
  47. break;
  48. }
  49. // Show certificate HTML
  50. $certificate->show();
  51. break;
  52. }