index.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. 'top' => 0,
  22. 'right' => 0,
  23. 'bottom' => 0,
  24. 'left' => 0
  25. );
  26. $orientation = api_get_configuration_value('certificate_pdf_orientation');
  27. $pdfParams['orientation'] = 'landscape';
  28. if (!empty($orientation)) {
  29. $pdfParams['orientation'] = $orientation;
  30. }
  31. $pageFormat = $pdfParams['orientation'] === 'landscape' ? 'A4-L' : 'A4';
  32. $userInfo = api_get_user_info($certificate->user_id);
  33. $pdfName = api_replace_dangerous_char(get_lang('Certificate').' '.$userInfo['username']);
  34. $pdf = new PDF($pageFormat, $pdfParams['orientation'], $pdfParams);
  35. $pdf->html_to_pdf(
  36. $certificatePathList,
  37. $pdfName,
  38. null,
  39. false,
  40. false
  41. );
  42. }
  43. break;
  44. default:
  45. // Special rules for anonymous users
  46. if (!$certificate->isVisible()) {
  47. Display::display_reduced_header();
  48. echo Display::return_message(get_lang('CertificateExistsButNotPublic'), 'warning');
  49. Display::display_reduced_footer();
  50. break;
  51. }
  52. if (!$certificate->isAvailable()) {
  53. Display::display_reduced_header();
  54. echo Display::return_message(get_lang('NoCertificateAvailable'), 'error');
  55. Display::display_reduced_footer();
  56. break;
  57. }
  58. // Show certificate HTML
  59. $certificate->show();
  60. break;
  61. }