diff --git a/certificates/index.php b/certificates/index.php index 6c9c42309a..790c37650e 100755 --- a/certificates/index.php +++ b/certificates/index.php @@ -10,7 +10,7 @@ require_once '../main/inc/global.inc.php'; $action = isset($_GET['action']) ? $_GET['action'] : null; $certificate = new Certificate($_GET['id']); -CustomCertificatePlugin::redirectCheck($certificate, intval($_GET['id'])); +CustomCertificatePlugin::redirectCheck($certificate, $_GET['id']); switch ($action) { case 'export': diff --git a/plugin/customcertificate/src/CustomCertificatePlugin.php b/plugin/customcertificate/src/CustomCertificatePlugin.php index 8d3175f9aa..6f009842d4 100644 --- a/plugin/customcertificate/src/CustomCertificatePlugin.php +++ b/plugin/customcertificate/src/CustomCertificatePlugin.php @@ -15,16 +15,19 @@ class CustomCertificatePlugin extends Plugin // When creating a new course this settings are added to the course public $course_settings = [ - [ - 'name' => 'customcertificate_course_enable', - 'type' => 'checkbox', - ], - [ - 'name' => 'use_certificate_default', - 'type' => 'checkbox', - ], + [ + 'name' => 'customcertificate_course_enable', + 'type' => 'checkbox', + ], + [ + 'name' => 'use_certificate_default', + 'type' => 'checkbox', + ], ]; + /** + * Constructor. + */ protected function __construct() { parent::__construct( @@ -39,6 +42,10 @@ class CustomCertificatePlugin extends Plugin } /** + * Instance the plugin. + * + * @staticvar null $result + * * @return CustomCertificatePlugin */ public static function create() @@ -190,7 +197,7 @@ class CustomCertificatePlugin extends Plugin /** * Get certificate data. * - * @param Certificate $id The certificate + * @param int $id The certificate * * @return array */ diff --git a/plugin/customcertificate/src/index.php b/plugin/customcertificate/src/index.php index 7db298f002..1b7d837493 100644 --- a/plugin/customcertificate/src/index.php +++ b/plugin/customcertificate/src/index.php @@ -125,9 +125,6 @@ if ($enable) { } // Image manager - $base = api_get_path(SYS_UPLOAD_PATH); - $pathCertificates = $base.'certificates'; - $fieldList = [ 'logo_left', 'logo_center', @@ -146,8 +143,7 @@ if ($enable) { checkInstanceImage( $certificateId, $infoCertificate[$field], - $field, - $pathCertificates + $field ); } @@ -170,8 +166,6 @@ if ($enable) { // Certificate Default if (intval($formValues['use_default'] == 1)) { - $base = api_get_path(SYS_UPLOAD_PATH); - $infoCertificateDefault = Database::select( '*', $table, @@ -921,14 +915,25 @@ if ($enable) { api_not_allowed(true, $plugin->get_lang('ToolDisabled')); } -function checkInstanceImage($certificateId, $imagePath, $field, $path) +/** + * Delete the file if there is only one instance. + * + * @param int $certificateId + * @param string $imagePath + * @param string $field + * @param string $type + */ +function checkInstanceImage($certificateId, $imagePath, $field, $type = 'certificates') { $table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE); + $imagePath = Database::escape_string($imagePath); + $sql = "SELECT * FROM $table WHERE $field = '$imagePath'"; $res = Database::query($sql); if (Database::num_rows($res) == 1) { - @unlink($path.$imagePath); + api_remove_uploaded_file($type, $imagePath); } + $sql = "UPDATE $table SET $field = '' WHERE id = $certificateId"; Database::query($sql); }