diff --git a/certificates/index.php b/certificates/index.php index 0d7117f327..6c9c42309a 100755 --- a/certificates/index.php +++ b/certificates/index.php @@ -10,33 +10,7 @@ require_once '../main/inc/global.inc.php'; $action = isset($_GET['action']) ? $_GET['action'] : null; $certificate = new Certificate($_GET['id']); -if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') == 'true') { - $infoCertificate = CustomCertificatePlugin::getCertificateData(intval($_GET['id'])); - if (!empty($infoCertificate)) { - if ($certificate->user_id == api_get_user_id() && !empty($certificate->certificate_data)) { - $certificateId = $certificate->certificate_data['id']; - $extraFieldValue = new ExtraFieldValue('user_certificate'); - $value = $extraFieldValue->get_values_by_handler_and_field_variable( - $certificateId, - 'downloaded_at' - ); - if (empty($value)) { - $params = [ - 'item_id' => $certificate->certificate_data['id'], - 'extra_downloaded_at' => api_get_utc_datetime(), - ]; - $extraFieldValue->saveFieldValues($params); - } - } - - $url = api_get_path(WEB_PLUGIN_PATH).'customcertificate/src/print_certificate.php'. - '?student_id='.$infoCertificate['user_id']. - '&course_code='.$infoCertificate['course_code']. - '&session_id='.$infoCertificate['session_id']; - header('Location: '.$url); - exit; - } -} +CustomCertificatePlugin::redirectCheck($certificate, intval($_GET['id'])); switch ($action) { case 'export': diff --git a/main/gradebook/lib/fe/displaygradebook.php b/main/gradebook/lib/fe/displaygradebook.php index 1b5399a1aa..e6ffecd1fd 100755 --- a/main/gradebook/lib/fe/displaygradebook.php +++ b/main/gradebook/lib/fe/displaygradebook.php @@ -471,7 +471,7 @@ class DisplayGradebook $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'. Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM).''; } else { - $actionsRight .= 'get_id().'">'. Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM).''; } diff --git a/plugin/customcertificate/README.md b/plugin/customcertificate/README.md index c308c87be5..4775337951 100644 --- a/plugin/customcertificate/README.md +++ b/plugin/customcertificate/README.md @@ -5,7 +5,6 @@ Este plugin da la posibilidad al administrador de disponer de una herramienta de **Instrucciones de puesta en funcionamiento** -- Subir la carpeta **customcertificate** a la carpeta plugin de chamilo. - Habilitar el plugin en la administración de Chamilo. - Indicar 'menu_administrator' en la configuración de la región del plugin. @@ -21,12 +20,6 @@ en un curso se debe entrar en la configuración del curso y habilitar en la pest casilla de verificación de "Habilitar en el curso el certificado alternativo". Si se desea usar el certificado por defecto se deberá mostrar la segunda casilla de verificación. -**Problema visualización icono de herramienta** - -El icono de la herramienta aparecerá en pantalla de los cursos con el resto de herramientas -Si no se visualiza el icono en el cursos correctamente y sale el icono de plugin genérico: -- Copiar los iconos de la carpeta resources/img/64 dentro de /main/img/icons/64 -- Copiar el icono de la carpeta resources/img/22 dentro de /main/img Credits ------- diff --git a/plugin/customcertificate/database.php b/plugin/customcertificate/database.php index a431e60dbf..b99273a795 100644 --- a/plugin/customcertificate/database.php +++ b/plugin/customcertificate/database.php @@ -1,6 +1,8 @@ hasTable(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE)) { //Create tables $certificateTable = $pluginSchema->createTable(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE); -$certificateTable->addColumn('id', \Doctrine\DBAL\Types\Type::INTEGER, ['autoincrement' => true, 'unsigned' => true]); -$certificateTable->addColumn('access_url_id', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); -$certificateTable->addColumn('c_id', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); -$certificateTable->addColumn('session_id', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); -$certificateTable->addColumn('content_course', \Doctrine\DBAL\Types\Type::TEXT); -$certificateTable->addColumn('contents_type', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); -$certificateTable->addColumn('contents', \Doctrine\DBAL\Types\Type::TEXT); -$certificateTable->addColumn('date_change', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); -$certificateTable->addColumn('date_start', \Doctrine\DBAL\Types\Type::DATETIME); -$certificateTable->addColumn('date_end', \Doctrine\DBAL\Types\Type::DATETIME); -$certificateTable->addColumn('type_date_expediction', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); -$certificateTable->addColumn('place', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('day', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('month', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('year', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('logo_left', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('logo_center', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('logo_right', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('seal', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('signature1', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('signature2', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('signature3', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('signature4', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('signature_text1', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('signature_text2', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('signature_text3', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('signature_text4', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('background', \Doctrine\DBAL\Types\Type::STRING); -$certificateTable->addColumn('margin_left', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); -$certificateTable->addColumn('margin_right', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); -$certificateTable->addColumn('certificate_default', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('id', Type::INTEGER, ['autoincrement' => true, 'unsigned' => true]); +$certificateTable->addColumn('access_url_id', Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('c_id', Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('session_id', Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('content_course', Type::TEXT); +$certificateTable->addColumn('contents_type', Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('contents', Type::TEXT); +$certificateTable->addColumn('date_change', Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('date_start', Type::DATETIME); +$certificateTable->addColumn('date_end', Type::DATETIME); +$certificateTable->addColumn('type_date_expediction', Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('place', Type::STRING); +$certificateTable->addColumn('day', Type::STRING, ['notnull' => false]); +$certificateTable->addColumn('month', Type::STRING, ['notnull' => false]); +$certificateTable->addColumn('year', Type::STRING, ['notnull' => false]); +$certificateTable->addColumn('logo_left', Type::STRING); +$certificateTable->addColumn('logo_center', Type::STRING); +$certificateTable->addColumn('logo_right', Type::STRING); +$certificateTable->addColumn('seal', Type::STRING); +$certificateTable->addColumn('signature1', Type::STRING); +$certificateTable->addColumn('signature2', Type::STRING); +$certificateTable->addColumn('signature3', Type::STRING); +$certificateTable->addColumn('signature4', Type::STRING); +$certificateTable->addColumn('signature_text1', Type::STRING); +$certificateTable->addColumn('signature_text2', Type::STRING); +$certificateTable->addColumn('signature_text3', Type::STRING); +$certificateTable->addColumn('signature_text4', Type::STRING); +$certificateTable->addColumn('background', Type::STRING); +$certificateTable->addColumn('margin_left', Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('margin_right', Type::INTEGER, ['unsigned' => true]); +$certificateTable->addColumn('certificate_default', Type::INTEGER, ['unsigned' => true]); $certificateTable->addIndex(['c_id', 'session_id']); $certificateTable->setPrimaryKey(['id']); diff --git a/plugin/customcertificate/src/CustomCertificatePlugin.php b/plugin/customcertificate/src/CustomCertificatePlugin.php index e71d9db098..9598932262 100644 --- a/plugin/customcertificate/src/CustomCertificatePlugin.php +++ b/plugin/customcertificate/src/CustomCertificatePlugin.php @@ -66,18 +66,6 @@ class CustomCertificatePlugin extends Plugin return false; } - $srcfile1 = __DIR__.'/../resources/img/64/customcertificate.png'; - $srcfile2 = __DIR__.'/../resources/img/64/customcertificate_na.png'; - $srcfile3 = __DIR__.'/../resources/img/22/customcertificate.png'; - $dstfile1 = __DIR__.'/../../../main/img/icons/64/customcertificate.png'; - $dstfile2 = __DIR__.'/../../../main/img/icons/64/customcertificate_na.png'; - $dstfile3 = __DIR__.'/../../../main/img/customcertificate.png'; - $dstfile4 = __DIR__.'/../../../main/img/icons/22/customcertificate.png'; - copy($srcfile1, $dstfile1); - copy($srcfile2, $dstfile2); - copy($srcfile3, $dstfile3); - copy($srcfile3, $dstfile4); - require_once api_get_path(SYS_PLUGIN_PATH).'customcertificate/database.php'; } @@ -208,6 +196,7 @@ class CustomCertificatePlugin extends Plugin */ public function getCertificateData($id) { + $id = (int) $id; if (empty($id)) { return false; } @@ -236,4 +225,36 @@ class CustomCertificatePlugin extends Plugin return []; } + + public function redirectCheck($certificate, $certId) + { + $certId = (int) $certId; + if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') == 'true') { + $infoCertificate = CustomCertificatePlugin::getCertificateData($certId); + if (!empty($infoCertificate)) { + if ($certificate->user_id == api_get_user_id() && !empty($certificate->certificate_data)) { + $certificateId = $certificate->certificate_data['id']; + $extraFieldValue = new ExtraFieldValue('user_certificate'); + $value = $extraFieldValue->get_values_by_handler_and_field_variable( + $certificateId, + 'downloaded_at' + ); + if (empty($value)) { + $params = [ + 'item_id' => $certificate->certificate_data['id'], + 'extra_downloaded_at' => api_get_utc_datetime(), + ]; + $extraFieldValue->saveFieldValues($params); + } + } + + $url = api_get_path(WEB_PLUGIN_PATH).'customcertificate/src/print_certificate.php'. + '?student_id='.$infoCertificate['user_id']. + '&course_code='.$infoCertificate['course_code']. + '&session_id='.$infoCertificate['session_id']; + header('Location: '.$url); + exit; + } + } + } } diff --git a/plugin/customcertificate/src/index.php b/plugin/customcertificate/src/index.php index f4815a9b33..cee2b089a6 100644 --- a/plugin/customcertificate/src/index.php +++ b/plugin/customcertificate/src/index.php @@ -60,7 +60,9 @@ if ($enable) { $infoCertificate = Database::select( '*', $table, - ['where' => ['access_url_id = ? AND c_id = ? AND session_id = ?' => [$accessUrlId, $courseId, $sessionId]]], + ['where' => [ + 'access_url_id = ? AND c_id = ? AND session_id = ?' => [$accessUrlId, $courseId, $sessionId]] + ], 'first' ); if (!is_array($infoCertificate)) { @@ -81,7 +83,6 @@ if ($enable) { } else { $contents = $formValues['contents']; } - $check = Security::check_token('post'); if ($check) { $date_start = str_replace('/', '-', $formValues['date_start']); @@ -125,198 +126,48 @@ if ($enable) { // Image manager $base = api_get_path(SYS_UPLOAD_PATH); - $pathCertificates = $base.'certificates/'.$certificateId.'/'; - - if (!empty($formValues['remove_logo_left']) || $_FILES['logo_left']['size']) { - @unlink($pathCertificates.$infoCertificate['logo_left']); - $sql = "UPDATE $table SET logo_left = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - if (!empty($formValues['remove_logo_center']) || $_FILES['logo_center']['size']) { - @unlink($pathCertificates.$infoCertificate['logo_center']); - $sql = "UPDATE $table SET logo_center = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - if (!empty($formValues['remove_logo_right']) || $_FILES['logo_right']['size']) { - @unlink($pathCertificates.$infoCertificate['logo_right']); - $sql = "UPDATE $table SET logo_right = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - if (!empty($formValues['remove_seal']) || $_FILES['seal']['size']) { - @unlink($pathCertificates.$infoCertificate['seal']); - $sql = "UPDATE $table SET seal = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - if (!empty($formValues['remove_signature1']) || $_FILES['signature1']['size']) { - @unlink($pathCertificates.$infoCertificate['signature1']); - $sql = "UPDATE $table SET signature1 = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - if (!empty($formValues['remove_signature2']) || $_FILES['signature2']['size']) { - @unlink($pathCertificates.$infoCertificate['signature2']); - $sql = "UPDATE $table SET signature2 = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - if (!empty($formValues['remove_signature3']) || $_FILES['signature3']['size']) { - @unlink($pathCertificates.$infoCertificate['signature3']); - $sql = "UPDATE $table SET signature3 = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - if (!empty($formValues['remove_signature4']) || $_FILES['signature4']['size']) { - @unlink($pathCertificates.$infoCertificate['signature4']); - $sql = "UPDATE $table SET signature4 = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - if (!empty($formValues['remove_background']) || $_FILES['background']['size']) { - @unlink($pathCertificates.$infoCertificate['background']); - $sql = "UPDATE $table SET background = '' WHERE id = $certificateId"; - $rs = Database::query($sql); - } - - $logoLeft = false; - $logoCenter = false; - $logoRight = false; - $seal = false; - $signature1 = false; - $signature2 = false; - $signature3 = false; - $signature4 = false; - $background = false; - - if ($_FILES['logo_left']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['logo_left']['name'], - $_FILES['logo_left']['tmp_name'], - $formValues['logo_left_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET logo_left = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $logoLeft = true; - } - } - - if ($_FILES['logo_center']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['logo_center']['name'], - $_FILES['logo_center']['tmp_name'], - $formValues['logo_center_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET logo_center = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $logoCenter = true; - } - } - - if ($_FILES['logo_right']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['logo_right']['name'], - $_FILES['logo_right']['tmp_name'], - $formValues['logo_right_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET logo_right = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $logoRight = true; - } - } - - if ($_FILES['seal']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['seal']['name'], - $_FILES['seal']['tmp_name'], - $formValues['seal_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET seal = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $seal = true; - } - } - - if ($_FILES['signature1']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['signature1']['name'], - $_FILES['signature1']['tmp_name'], - $formValues['signature1_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET signature1 = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $signature1 = true; - } - } - - if ($_FILES['signature2']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['signature2']['name'], - $_FILES['signature2']['tmp_name'], - $formValues['signature2_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET signature2 = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $signature2 = true; - } - } - - if ($_FILES['signature3']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['signature3']['name'], - $_FILES['signature3']['tmp_name'], - $formValues['signature3_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET signature3 = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $signature3 = true; - } - } - - if ($_FILES['signature4']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['signature4']['name'], - $_FILES['signature4']['tmp_name'], - $formValues['signature4_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET signature4 = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $signature4 = true; + $pathCertificates = $base.'certificates'; + + $fieldList = [ + 'logo_left', + 'logo_center', + 'logo_right', + 'seal', + 'signature1', + 'signature2', + 'signature3', + 'signature4', + 'background', + ]; + + foreach ($fieldList as $field) { + $checkLogo[$field] = false; + if (!empty($formValues['remove_'.$field]) || $_FILES[$field]['size']) { + checkInstanceImage( + $certificateId, + $infoCertificate[$field], + $field, + $pathCertificates + ); } - } - - if ($_FILES['background']['size']) { - $newPicture = uploadImageCertificate( - $certificateId, - $_FILES['background']['name'], - $_FILES['background']['tmp_name'], - $formValues['background_crop_result'] - ); - if ($newPicture) { - $sql = "UPDATE $table SET background = '".$newPicture."' WHERE id = $certificateId"; - Database::query($sql); - $background = true; + + if ($_FILES[$field]['size']) { + $newPicture = api_upload_file( + 'certificates', + $_FILES[$field], + $certificateId, + $formValues[$field.'_crop_result'] + ); + if ($newPicture) { + $sql = "UPDATE $table + SET $field = '".$newPicture['path_to_save']."' + WHERE id = $certificateId"; + Database::query($sql); + $checkLogo[$field] = true; + } } } - + // Certificate Default if (intval($formValues['use_default'] == 1)) { $base = api_get_path(SYS_UPLOAD_PATH); @@ -329,109 +180,13 @@ if ($enable) { ); if (!empty($infoCertificateDefault)) { - $pathCertificatesDefault = $base.'certificates/'.$infoCertificateDefault['id'].'/'; - - if (!file_exists($pathCertificates)) { - mkdir($pathCertificates, api_get_permissions_for_new_directories(), true); - } - - if (!empty($infoCertificateDefault['logo_left']) && !$logoLeft) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['logo_left'], - $pathCertificates.$infoCertificateDefault['logo_left'] - ); - $sql = "UPDATE $table - SET logo_left = '".$infoCertificateDefault['logo_left']."' - WHERE id = $certificateId"; - Database::query($sql); - } - - if (!empty($infoCertificateDefault['logo_center']) && !$logoCenter) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['logo_center'], - $pathCertificates.$infoCertificateDefault['logo_center'] - ); - $sql = "UPDATE $table - SET logo_center = '".$infoCertificateDefault['logo_center']."' - WHERE id = $certificateId"; - Database::query($sql); - } - - if (!empty($infoCertificateDefault['logo_right']) && !$logoRight) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['logo_right'], - $pathCertificates.$infoCertificateDefault['logo_right'] - ); - $sql = "UPDATE $table - SET logo_right = '".$infoCertificateDefault['logo_right']."' - WHERE id = $certificateId"; - Database::query($sql); - } - - if (!empty($infoCertificateDefault['seal']) && !$seal) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['seal'], - $pathCertificates.$infoCertificateDefault['seal'] - ); - $sql = "UPDATE $table - SET seal = '".$infoCertificateDefault['seal']."' - WHERE id = $certificateId"; - Database::query($sql); - } - - if (!empty($infoCertificateDefault['signature1']) && !$signature1) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['signature1'], - $pathCertificates.$infoCertificateDefault['signature1'] - ); - $sql = "UPDATE $table - SET signature1 = '".$infoCertificateDefault['signature1']."' - WHERE id = $certificateId"; - Database::query($sql); - } - - if (!empty($infoCertificateDefault['signature2']) && !$signature2) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['signature2'], - $pathCertificates.$infoCertificateDefault['signature2'] - ); - $sql = "UPDATE $table - SET signature2 = '".$infoCertificateDefault['signature2']."' - WHERE id = $certificateId"; - Database::query($sql); - } - - if (!empty($infoCertificateDefault['signature3']) && !$signature3) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['signature3'], - $pathCertificates.$infoCertificateDefault['signature3'] - ); - $sql = "UPDATE $table - SET signature3 = '".$infoCertificateDefault['signature3']."' - WHERE id = $certificateId"; - Database::query($sql); - } - - if (!empty($infoCertificateDefault['signature4']) && !$signature4) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['signature4'], - $pathCertificates.$infoCertificateDefault['signature4'] - ); - $sql = "UPDATE $table - SET signature4 = '".$infoCertificateDefault['signature4']."' - WHERE id = $certificateId"; - Database::query($sql); - } - - if (!empty($infoCertificateDefault['background']) && !$background) { - copy( - $pathCertificatesDefault.$infoCertificateDefault['background'], - $pathCertificates.$infoCertificateDefault['background'] - ); - $sql = "UPDATE $table - SET background = '".$infoCertificateDefault['background']."' - WHERE id = $certificateId"; - Database::query($sql); + foreach ($fieldList as $field) { + if (!empty($infoCertificateDefault[$field]) && !$checkLogo[$field]) { + $sql = "UPDATE $table + SET $field = '".$infoCertificateDefault[$field]."' + WHERE id = $certificateId"; + Database::query($sql); + } } } } @@ -499,8 +254,8 @@ if ($enable) { ); $form->addElement('html', ''); $form->addElement('html', '
'); - - $strInfo = '((user_lastname))
'; + $strInfo = '((user_firstname))
'; + $strInfo .= '((user_lastname))
'; $strInfo .= '((gradebook_institution))
'; $strInfo .= '((gradebook_sitename))
'; $strInfo .= '((teacher_firstname))
'; @@ -519,7 +274,7 @@ if ($enable) { $createCertificate = get_lang('CreateCertificateWithTags'); $form->addElement( 'html', - Display::return_message($createCertificate.':

'.$strInfo, 'normal', false) + Display::return_message($createCertificate.':
'.$strInfo, 'normal', false) ); $form->addElement('html', '
'); $form->addElement('html', ''); @@ -785,7 +540,7 @@ if ($enable) { // Signature section $base = api_get_path(WEB_UPLOAD_PATH); - $path = $base.'certificates/'.$infoCertificate['id'].'/'; + $path = $base.'certificates/'; //.$infoCertificate['id'].'/'; $form->addElement('html', '
'.strtoupper(get_lang('LogosSeal')).''); // Logo 1 @@ -1166,61 +921,13 @@ if ($enable) { api_not_allowed(true, $plugin->get_lang('ToolDisabled')); } -function uploadImageCertificate( - $certId, - $file = null, - $sourceFile = null, - $cropParameters = '', - $default = false -) { - if (empty($certId)) { - return false; +function checkInstanceImage($certificateId, $imagePath, $field, $path) { + $table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE); + $sql = "SELECT * FROM $table WHERE $field = '$imagePath'"; + $res = Database::query($sql); + if (Database::num_rows($res) == 1) { + @unlink($path.$imagePath); } - - $delete = empty($file); - - if (empty($sourceFile)) { - $sourceFile = $file; - } - - $base = api_get_path(SYS_UPLOAD_PATH); - $path = $base.'certificates/'.$certId.'/'; - - if ($default) { - $path = $base.'certificates/default/'; - } - - // If this directory does not exist - we create it. - if (!file_exists($path)) { - mkdir($path, api_get_permissions_for_new_directories(), true); - } - - // Exit if only deletion has been requested. Return an empty picture name. - if ($delete) { - return ''; - } - - $allowedTypes = api_get_supported_image_extensions(); - $file = str_replace('\\', '/', $file); - $filename = (($pos = strrpos($file, '/')) !== false) ? substr($file, $pos + 1) : $file; - $extension = strtolower(substr(strrchr($filename, '.'), 1)); - - if (!in_array($extension, $allowedTypes)) { - return false; - } - - $filename = api_replace_dangerous_char($filename); - $filename = uniqid('').'_'.$filename; - $filename = $certId.'_'.$filename; - - //Crop the image to adjust 1:1 ratio - $image = new Image($sourceFile); - $image->crop($cropParameters); - - $origin = new Image($sourceFile); // This is the original picture. - $origin->send_image($path.$filename); - - $result = $origin; - - return $result ? $filename : false; -} + $sql = "UPDATE $table SET $field = '' WHERE id = $certificateId"; + $rs = Database::query($sql); + } diff --git a/plugin/customcertificate/src/print_certificate.php b/plugin/customcertificate/src/print_certificate.php index 8db8f9e40c..5f04b0128d 100644 --- a/plugin/customcertificate/src/print_certificate.php +++ b/plugin/customcertificate/src/print_certificate.php @@ -63,7 +63,7 @@ if ($sessionId > 0) { $table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE); $useDefault = false; -$base = api_get_path(WEB_UPLOAD_PATH).'certificates/'; +$path = api_get_path(WEB_UPLOAD_PATH).'certificates/'; // Get info certificate $infoCertificate = Database::select( @@ -96,10 +96,7 @@ if (empty($infoCertificate)) { exit; } else { $useDefault = true; - $path = $base.$infoCertificate['id'].'/'; } -} else { - $path = $base.$infoCertificate['id'].'/'; } $workSpace = intval(297 - $infoCertificate['margin_left'] - $infoCertificate['margin_right']); @@ -396,7 +393,6 @@ foreach ($userList as $userInfo) { foreach ($flat_list as $learnpath) { $lpId = $learnpath['lp_old_id']; - //echo $lpId."
"; $sql = "SELECT 1 FROM $tblProperty WHERE tool = 'learnpath' @@ -463,8 +459,8 @@ $params = [ $pdf = new PDF($params['format'], $params['orientation'], $params); $pdf->content_to_pdf($htmlText, '', $fileName, null, 'I', false, null, false, true, false); -function getIndexFiltered($indice) { - $txt = strip_tags($indice, ""); +function getIndexFiltered($index) { + $txt = strip_tags($index, ""); $txt = str_replace(chr(13).chr(10).chr(13).chr(10), chr(13).chr(10), $txt); $lines = explode(chr(13).chr(10), $txt);