diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php
index 8a517dd0b7..ea0c2f548f 100755
--- a/main/inc/lib/message.lib.php
+++ b/main/inc/lib/message.lib.php
@@ -292,6 +292,7 @@ class MessageManager
";
$result = Database::query($sql);
+
return Database::num_rows($result) > 0;
}
diff --git a/plugin/customcertificate/src/CustomCertificatePlugin.php b/plugin/customcertificate/src/CustomCertificatePlugin.php
index 6f009842d4..c1d28e799f 100644
--- a/plugin/customcertificate/src/CustomCertificatePlugin.php
+++ b/plugin/customcertificate/src/CustomCertificatePlugin.php
@@ -32,7 +32,7 @@ class CustomCertificatePlugin extends Plugin
{
parent::__construct(
'1.0',
- 'Jose Angel Ruiz - NoSoloRed (original author)',
+ 'Jose Angel Ruiz - NoSoloRed (original author), Julio Montoya',
[
'enable_plugin_customcertificate' => 'boolean',
]
@@ -82,7 +82,7 @@ class CustomCertificatePlugin extends Plugin
public function uninstall()
{
// Deleting course settings.
- $this->uninstall_course_fields_in_all_courses($this->course_settings);
+ $this->uninstall_course_fields_in_all_courses();
$tablesToBeDeleted = [self::TABLE_CUSTOMCERTIFICATE];
foreach ($tablesToBeDeleted as $tableToBeDeleted) {
@@ -138,10 +138,9 @@ class CustomCertificatePlugin extends Plugin
'certificate_default' => 0,
];
- Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params);
- $certificateId = Database::insert_id();
+ $certificateId = Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params);
- //Image manager
+ // Image manager
$pathDestiny = $base.'certificates/'.$certificateId.'/';
if (!file_exists($pathDestiny)) {
@@ -172,8 +171,7 @@ class CustomCertificatePlugin extends Plugin
$params['c_id'] = 0;
$params['session_id'] = 0;
$params['certificate_default'] = 1;
- Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params);
- $certificateId = Database::insert_id();
+ $certificateId = Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params);
$pathOrigin = $base.'certificates/default/';
$pathDestiny = $base.'certificates/'.$certificateId.'/';
foreach ($imgList as $value) {
@@ -205,7 +203,7 @@ class CustomCertificatePlugin extends Plugin
{
$id = (int) $id;
if (empty($id)) {
- return false;
+ return [];
}
$certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
@@ -237,9 +235,8 @@ class CustomCertificatePlugin extends Plugin
* Check if it redirects.
*
* @param certificate $certificate
- * @param int $id
+ * @param int $certId
*
- * @return array
*/
public function redirectCheck($certificate, $certId)
{
@@ -268,6 +265,7 @@ class CustomCertificatePlugin extends Plugin
'&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 1b7d837493..1b1560b5ec 100644
--- a/plugin/customcertificate/src/index.php
+++ b/plugin/customcertificate/src/index.php
@@ -15,8 +15,8 @@ $plugin = CustomCertificatePlugin::create();
$nameTools = $plugin->get_lang('CertificateSetting');
$enable = $plugin->get('enable_plugin_customcertificate') == 'true';
$accessUrlId = api_get_current_access_url_id();
-
$course_info = api_get_course_info();
+
if (intval($_GET['default']) == 1) {
$courseId = 0;
$courseCode = '';
@@ -36,885 +36,887 @@ if (intval($_GET['default']) == 1) {
$urlParams = '?'.api_get_cidreq();
}
-if ($enable) {
- if (!$enableCourse && !$useDefault) {
- api_not_allowed(true, $plugin->get_lang('ToolDisabledCourse'));
- }
-
- if ($enableCourse && $useDefault) {
- api_not_allowed(true, $plugin->get_lang('ToolUseDefaultSettingCourse'));
- }
-
- if (api_is_platform_admin() || api_is_teacher()) {
- $table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE);
- $htmlHeadXtra[] = api_get_js_simple(
- api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/js/certificate.js'
- );
- $htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
- $htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
- $htmlHeadXtra[] = api_get_css(
- api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/form.css'
- );
-
- // Get info certificate
- $infoCertificate = Database::select(
- '*',
- $table,
- ['where' => [
- 'access_url_id = ? AND c_id = ? AND session_id = ?' => [$accessUrlId, $courseId, $sessionId], ],
- ],
- 'first'
- );
- if (!is_array($infoCertificate)) {
- $infoCertificate = [];
- }
-
- $form = new FormValidator(
- 'formEdit',
- 'post',
- api_get_self().$urlParams,
- null,
- ['class' => 'form-vertical']
- );
- if ($form->validate()) {
- $formValues = $form->getSubmitValues();
- if (empty($formValues['contents'])) {
- $contents = '';
- } else {
- $contents = $formValues['contents'];
- }
- $check = Security::check_token('post');
- if ($check) {
- $date_start = str_replace('/', '-', $formValues['date_start']);
- $date_end = str_replace('/', '-', $formValues['date_end']);
- $params = [
- 'access_url_id' => api_get_current_access_url_id(),
- 'c_id' => $formValues['c_id'],
- 'session_id' => $formValues['session_id'],
- 'content_course' => $formValues['content_course'],
- 'contents_type' => intval($formValues['contents_type']),
- 'contents' => $contents,
- 'date_change' => intval($formValues['date_change']),
- 'date_start' => date("Y-m-d", strtotime($date_start)),
- 'date_end' => date("Y-m-d", strtotime($date_end)),
- 'place' => $formValues['place'],
- 'type_date_expediction' => intval($formValues['type_date_expediction']),
- 'day' => $formValues['day'],
- 'month' => $formValues['month'],
- 'year' => $formValues['year'],
- 'signature_text1' => $formValues['signature_text1'],
- 'signature_text2' => $formValues['signature_text2'],
- 'signature_text3' => $formValues['signature_text3'],
- 'signature_text4' => $formValues['signature_text4'],
- 'margin_left' => intval($formValues['margin_left']),
- 'margin_right' => intval($formValues['margin_right']),
- 'certificate_default' => 0,
- ];
-
- if (intval($formValues['default_certificate'] == 1)) {
- $params['certificate_default'] = 1;
- }
+if (!$enable) {
+ api_not_allowed(true, $plugin->get_lang('ToolDisabled'));
+}
- // Insert or Update
- if ($infoCertificate['id'] > 0) {
- $certificateId = $infoCertificate['id'];
- Database::update($table, $params, ['id = ?' => $certificateId]);
- } else {
- Database::insert($table, $params);
- $certificateId = Database::insert_id();
- }
+if (!$enableCourse && !$useDefault) {
+ api_not_allowed(true, $plugin->get_lang('ToolDisabledCourse'));
+}
- // Image manager
- $fieldList = [
- 'logo_left',
- 'logo_center',
- 'logo_right',
- 'seal',
- 'signature1',
- 'signature2',
- 'signature3',
- 'signature4',
- 'background',
- ];
+if ($enableCourse && $useDefault) {
+ api_not_allowed(true, $plugin->get_lang('ToolUseDefaultSettingCourse'));
+}
- foreach ($fieldList as $field) {
- $checkLogo[$field] = false;
- if (!empty($formValues['remove_'.$field]) || $_FILES[$field]['size']) {
- checkInstanceImage(
- $certificateId,
- $infoCertificate[$field],
- $field
- );
- }
+$allow = api_is_platform_admin() || api_is_teacher();
+if (!$allow) {
+ api_not_allowed(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)) {
- $infoCertificateDefault = Database::select(
- '*',
- $table,
- ['where' => ['certificate_default = ? ' => 1]],
- 'first'
- );
-
- if (!empty($infoCertificateDefault)) {
- foreach ($fieldList as $field) {
- if (!empty($infoCertificateDefault[$field]) && !$checkLogo[$field]) {
- $sql = "UPDATE $table
- SET $field = '".$infoCertificateDefault[$field]."'
- WHERE id = $certificateId";
- Database::query($sql);
- }
- }
- }
- }
+$table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE);
+$htmlHeadXtra[] = api_get_js_simple(
+ api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/js/certificate.js'
+);
+$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
+$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
+$htmlHeadXtra[] = api_get_css(
+ api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/form.css'
+);
+
+// Get info certificate
+$infoCertificate = Database::select(
+ '*',
+ $table,
+ ['where' => [
+ 'access_url_id = ? AND c_id = ? AND session_id = ?' => [$accessUrlId, $courseId, $sessionId], ],
+ ],
+ 'first'
+);
+if (!is_array($infoCertificate)) {
+ $infoCertificate = [
+ 'type_date_expediction' => '',
+ 'year' => '',
+ 'month' => '',
+ 'day' => '',
+ 'date_change' => '',
+ ];
+}
- Security::clear_token();
- header('Location: '.api_get_self().$urlParams);
- exit;
- }
- }
- if (empty($infoCertificate)) {
- $infoCertificate = Database::select(
- '*',
- $table,
- ['where' => ['access_url_id = ? AND certificate_default = ? ' => [$accessUrlId, 1]]],
- 'first'
- );
+$form = new FormValidator(
+ 'formEdit',
+ 'post',
+ api_get_self().$urlParams,
+ null,
+ ['class' => 'form-vertical']
+);
+
+if ($form->validate()) {
+ $formValues = $form->getSubmitValues();
+ if (empty($formValues['contents'])) {
+ $contents = '';
+ } else {
+ $contents = $formValues['contents'];
+ }
+ $check = Security::check_token('post');
+ if ($check) {
+ $date_start = str_replace('/', '-', $formValues['date_start']);
+ $date_end = str_replace('/', '-', $formValues['date_end']);
+ $params = [
+ 'access_url_id' => api_get_current_access_url_id(),
+ 'c_id' => $formValues['c_id'],
+ 'session_id' => $formValues['session_id'],
+ 'content_course' => $formValues['content_course'],
+ 'contents_type' => intval($formValues['contents_type']),
+ 'contents' => $contents,
+ 'date_change' => intval($formValues['date_change']),
+ 'date_start' => date("Y-m-d", strtotime($date_start)),
+ 'date_end' => date("Y-m-d", strtotime($date_end)),
+ 'place' => $formValues['place'],
+ 'type_date_expediction' => intval($formValues['type_date_expediction']),
+ 'day' => $formValues['day'],
+ 'month' => $formValues['month'],
+ 'year' => $formValues['year'],
+ 'signature_text1' => $formValues['signature_text1'],
+ 'signature_text2' => $formValues['signature_text2'],
+ 'signature_text3' => $formValues['signature_text3'],
+ 'signature_text4' => $formValues['signature_text4'],
+ 'margin_left' => intval($formValues['margin_left']),
+ 'margin_right' => intval($formValues['margin_right']),
+ 'certificate_default' => 0,
+ ];
- if (!is_array($infoCertificate)) {
- $infoCertificate = [];
- }
- if (!empty($infoCertificate)) {
- $useDefault = true;
- }
- }
- /* Display user interface */
- // Display the header
- Display::display_header($nameTools);
- $actionsLeft .= Display::url(
- Display::return_icon('certificate.png', get_lang('Certificate'), '', ICON_SIZE_MEDIUM),
- 'print_certificate.php'.$urlParams
- );
- echo Display::toolbarAction(
- 'toolbar-document',
- [$actionsLeft]
- );
-
- if ($useDefault && $courseId > 0) {
- echo Display::return_message(get_lang('InfoFromDefaultCertificate'), 'info');
+ if (intval($formValues['default_certificate'] == 1)) {
+ $params['certificate_default'] = 1;
}
- // Student and course section
- $form->addElement('html', '
');
- $form->addElement('html', '');
-
- // Contents section
- $form->addElement('html', '