From d2d2ccde69010c26d9c48876bcde94d198c7d4a2 Mon Sep 17 00:00:00 2001 From: "TOMAHOST\\xes" Date: Thu, 10 Apr 2025 12:52:04 +0200 Subject: [PATCH] =?UTF-8?q?Actualizaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- certificates/index.php | 103 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 certificates/index.php diff --git a/certificates/index.php b/certificates/index.php new file mode 100644 index 000000000..67c08929c --- /dev/null +++ b/certificates/index.php @@ -0,0 +1,103 @@ +get_course_code())) { + $courseInfo = api_get_course_info($category->get_course_code()); + $language = $courseInfo['language']; + $languageFilesToLoad = api_get_language_files_to_load($language); + + foreach ($languageFilesToLoad as $languageFile) { + include $languageFile; + } + + // Overwrite the interface language with the course language + $language_interface = $language; + $language_interface_initial_value = $language_interface; +} + +$certificate = new Certificate($certificateId, $userId); +$certificateData = $certificate->get($certificateId); +if (empty($certificateData)) { + api_not_allowed(false, Display::return_message(get_lang('NoCertificateAvailable'), 'warning')); +} + +CustomCertificatePlugin::redirectCheck($certificate, $certificateId, $userId); + +switch ($action) { + case 'export': + $hideExportLink = api_get_setting('hide_certificate_export_link'); + $hideExportLinkStudent = api_get_setting('hide_certificate_export_link_students'); + if ($hideExportLink === 'true' || + (api_is_student() && $hideExportLinkStudent === 'true') + ) { + api_not_allowed(true); + } + + $certificate->generate(['hide_print_button' => true]); + + if ($certificate->isHtmlFileGenerated()) { + $certificatePathList[] = $certificate->html_file; + + $pdfParams = [ + 'top' => 0, + 'right' => 0, + 'bottom' => 0, + 'left' => 0, + ]; + + $orientation = api_get_configuration_value('certificate_pdf_orientation'); + $pdfParams['orientation'] = 'landscape'; + if (!empty($orientation)) { + $pdfParams['orientation'] = $orientation; + } + + $pageFormat = $pdfParams['orientation'] === 'landscape' ? 'A4-L' : 'A4'; + $userInfo = api_get_user_info($certificate->user_id); + $pdfName = api_replace_dangerous_char( + get_lang('Certificate').' '.$userInfo['username'] + ); + + $pdf = new PDF($pageFormat, $pdfParams['orientation'], $pdfParams); + + if (api_get_configuration_value('add_certificate_pdf_footer')) { + $pdf->setCertificateFooter(); + } + + $pdf->html_to_pdf( + $certificatePathList, + $pdfName, + null, + false, + false + ); + } + break; + default: + // Special rules for anonymous users + if (!$certificate->isVisible()) { + api_not_allowed(false, Display::return_message(get_lang('CertificateExistsButNotPublic'), 'warning')); + break; + } + + if (!$certificate->isAvailable()) { + api_not_allowed(false, Display::return_message(get_lang('NoCertificateAvailable'), 'warning')); + break; + } + + // Show certificate HTML + $certificate->show(); + break; +}