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', '
'.strtoupper(get_lang('StudentCourseInfo')).''); - $form->addElement('html', '
'); - $dir = '/'; - $courseInfo = api_get_course_info(); - $isAllowedToEdit = api_is_allowed_to_edit(null, true); - $editorConfig = [ - 'ToolbarSet' => ($isAllowedToEdit ? 'Documents' : 'DocumentsStudent'), - 'Width' => '100%', - 'Height' => '300', - 'cols-size' => [0, 12, 0], - 'FullPage' => true, - 'InDocument' => true, - 'CreateDocumentDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/', - 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/', - 'BaseHref' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$dir, - ]; - $form->addHtmlEditor( - 'content_course', - '', - false, - true, - $editorConfig, - true - ); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - $strInfo = '((user_firstname))
'; - $strInfo .= '((user_lastname))
'; - $strInfo .= '((gradebook_institution))
'; - $strInfo .= '((gradebook_sitename))
'; - $strInfo .= '((teacher_firstname))
'; - $strInfo .= '((teacher_lastname))
'; - $strInfo .= '((official_code))
'; - $strInfo .= '((date_certificate))
'; - $strInfo .= '((date_certificate_no_time))
'; - $strInfo .= '((course_code))
'; - $strInfo .= '((course_title))
'; - $strInfo .= '((gradebook_grade))
'; - $strInfo .= '((external_style))
'; - $strInfo .= '((start_date))
'; - $strInfo .= '((end_date))
'; - $strInfo .= '((date_expediction))'; - - $createCertificate = get_lang('CreateCertificateWithTags'); - $form->addElement( - 'html', - Display::return_message($createCertificate.':
'.$strInfo, 'normal', false) - ); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - - // Contents section - $form->addElement('html', '
'.strtoupper(get_lang('Contents')).''); - $extra = ''; - if (empty($infoCertificate['contents_type'])) { - $infoCertificate['contents_type'] = 0; - $extra = 'disabled'; + // Insert or Update + if ($infoCertificate['id'] > 0) { + $certificateId = $infoCertificate['id']; + Database::update($table, $params, ['id = ?' => $certificateId]); + } else { + $certificateId = Database::insert($table, $params); } - $group = []; - - $element = &$form->createElement( - 'radio', - 'contents_type', - '', - get_lang('ContentsCourseDescription'), - 0, - ['id' => 'contents_type_0', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();'] - ); - - $group[] = $element; - - $element = &$form->createElement( - 'radio', - 'contents_type', - '', - get_lang('ContentsIndexLearnpath'), - 1, - ['id' => 'contents_type_1', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();'] - ); - $group[] = $element; - - $element = &$form->createElement( - 'radio', - 'contents_type', - '', - get_lang('ContentsCustom'), - 2, - ['id' => 'contents_type_2', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();'] - ); - $group[] = $element; - - $form->addGroup( - $group, - 'contents_type', - get_lang('ContentsToShow'), - null, - false - ); - - $form->addElement('html', '
'); - $editorConfig = [ - 'ToolbarSet' => ($isAllowedToEdit ? 'Documents' : 'DocumentsStudent'), - 'Width' => '100%', - 'Height' => '200', - 'cols-size' => [2, 10, 0], - 'FullPage' => true, - 'InDocument' => true, - 'CreateDocumentDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/', - 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/', - 'BaseHref' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$dir, - 'id' => 'contents', - $extra, - ]; - $form->addHtmlEditor( - 'contents', - get_lang('Contents'), - false, - true, - $editorConfig, - true - ); - $form->addElement('html', '
'); - - // Dates section - $form->addElement('html', '
'.strtoupper(get_lang("Dates")).''); - - $group = []; - $option1 = &$form->createElement( - 'radio', - 'date_change', - '', - get_lang('UseDateSessionAccess'), - 0, - ['id' => 'contents_type_0', 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();'] - ); - $group[] = $option1; - - $option2 = &$form->createElement( - 'radio', - 'date_change', - '', - get_lang('None'), - 2, - ['id' => 'contents_type_2', 'onclick' => 'javascript: dateCertificateSwitchRadioButton2();'] - ); - $group[] = $option2; - - $option3 = &$form->createElement( - 'radio', - 'date_change', - '', - get_lang('Custom'), - 1, - ['id' => 'contents_type_1', 'onclick' => 'javascript: dateCertificateSwitchRadioButton1();'] - ); - $group[] = $option3; - - $form->addGroup( - $group, - 'date_change', - get_lang('CourseDeliveryDates'), - null, - false - ); - $form->addElement('html', '
- -
-
- '.get_lang('From').' - - '.get_lang('Until').' - -
-
-
'); - - $form->addText( - 'place', - get_lang('ExpectionPlace'), - false, - ['id' => 'place', 'cols-size' => [2, 5, 5], 'autofocus'] - ); - - $group = []; - $option1 = &$form->createElement( - 'radio', - 'type_date_expediction', - '', - get_lang('UseDateEndAccessSession'), - 0, - [ - 'id' => 'type_date_expediction_0', - 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();', - (($sessionId == 0) ? 'disabled' : ''), - ] - ); - $group[] = $option1; - - $option2 = &$form->createElement( - 'radio', - 'type_date_expediction', - '', - get_lang('UseDateDownloadCertificate'), - 1, - [ - 'id' => 'type_date_expediction_1', - 'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();', - ] - ); - $group[] = $option2; - - $option4 = &$form->createElement( - 'radio', - 'type_date_expediction', - '', - get_lang('None'), - 3, - [ - 'id' => 'type_date_expediction_3', - 'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();', - ] - ); - $group[] = $option4; - - $option3 = &$form->createElement( - 'radio', - 'type_date_expediction', - '', - get_lang('UseCustomDate'), - 2, - [ - 'id' => 'type_date_expediction_2', - 'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();', - ] - ); - $group[] = $option3; - - $form->addGroup( - $group, - 'type_date_expediction', - get_lang('DateExpediction'), - null, - false - ); - - $form->addElement('html', '
- -
-
- a - - de - - de - -
-
-
'); - $form->addElement('html', '
'); - - // Signature section - $base = api_get_path(WEB_UPLOAD_PATH); - $path = $base.'certificates/'; //.$infoCertificate['id'].'/'; - - $form->addElement('html', '
'.strtoupper(get_lang('LogosSeal')).''); - // Logo 1 - $form->addElement('html', '
'); - $form->addFile( - 'logo_left', - get_lang('LogoLeft'), - [ - 'id' => 'logo_left', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_scalable' => 'true', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['logo_left'])) { - $form->addElement('checkbox', 'remove_logo_left', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); - } - $allowedPictureTypes = api_get_supported_image_extensions(false); - $form->addRule( + // Image manager + $fieldList = [ 'logo_left', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - // Logo 2 - $form->addElement('html', '
'); - $form->addFile( 'logo_center', - get_lang('LogoCenter'), - [ - 'id' => 'logo_center', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_scalable' => 'true', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['logo_center'])) { - $form->addElement('checkbox', 'remove_logo_center', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); - } - $allowedPictureTypes = api_get_supported_image_extensions(false); - $form->addRule( - 'logo_center', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - // Logo 3 - $form->addElement('html', '
'); - $form->addFile( 'logo_right', - get_lang('LogoRight'), - [ - 'id' => 'logo_right', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_scalable' => 'true', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['logo_right'])) { - $form->addElement('checkbox', 'remove_logo_right', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); - } - $tblProperty = api_get_supported_image_extensions(false); - $form->addRule( - 'logo_right', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - $form->addFile( 'seal', - get_lang('Seal'), - [ - 'id' => 'seal', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_scalable' => 'true', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['seal'])) { - $form->addElement('checkbox', 'remove_seal', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); - } - $allowedPictureTypes = api_get_supported_image_extensions(false); - $form->addRule( - 'seal', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - $form->addElement('html', '
'.strtoupper(get_lang('Signatures')).''); - // signature 1 - $form->addElement('html', '
'); - $form->addText( - 'signature_text1', - get_lang('SignatureText1'), - false, - ['cols-size' => [2, 10, 0], 'autofocus'] - ); - $form->addFile( - 'signature1', - get_lang('Signature1'), - [ - 'id' => 'signature1', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_scalable' => 'true', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['signature1'])) { - $form->addElement('checkbox', 'remove_signature1', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); - } - $allowedPictureTypes = api_get_supported_image_extensions(false); - $form->addRule( 'signature1', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - // signature 2 - $form->addElement('html', '
'); - $form->addText( - 'signature_text2', - get_lang('SignatureText2'), - false, - ['cols-size' => [2, 10, 0], 'autofocus'] - ); - $form->addFile( 'signature2', - get_lang('Signature2'), - [ - 'id' => 'signature2', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_scalable' => 'true', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['signature2'])) { - $form->addElement('checkbox', 'remove_signature2', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); - } - $allowedPictureTypes = api_get_supported_image_extensions(false); - $form->addRule( - 'signature2', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - // signature 3 - $form->addElement('html', '
'); - $form->addText( - 'signature_text3', - get_lang('SignatureText3'), - false, - ['cols-size' => [2, 10, 0], 'autofocus'] - ); - $form->addFile( 'signature3', - get_lang('Signature3'), - [ - 'id' => 'signature3', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_scalable' => 'true', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['signature3'])) { - $form->addElement('checkbox', 'remove_signature3', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); - } - $allowedPictureTypes = api_get_supported_image_extensions(false); - $form->addRule( - 'signature3', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - // signature 4 - $form->addElement('html', '
'); - $form->addText( - 'signature_text4', - get_lang('SignatureText4'), - false, - ['cols-size' => [2, 10, 0], 'autofocus'] - ); - $form->addFile( - 'signature4', - get_lang('Signature4'), - [ - 'id' => 'signature4', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_scalable' => 'true', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['signature4'])) { - $form->addElement('checkbox', 'remove_signature4', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); - } - $allowedPictureTypes = api_get_supported_image_extensions(false); - $form->addRule( 'signature4', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - $form->addElement('html', '

'); - $form->addElement('html', '
'); - $form->addElement('html', '
'.strtoupper(get_lang('BackgroundCertificate')).''); - // background - $form->addFile( 'background', - get_lang('Background'), - [ - 'id' => 'background', - 'class' => 'picture-form', - 'crop_image' => true, - 'crop_ratio' => '297 / 210', - ] - ); - $form->addProgress(); - if (!empty($infoCertificate['background'])) { - $form->addElement('checkbox', 'remove_background', null, get_lang('DelImage')); - $form->addElement( - 'html', - ' - -

' - ); + ]; + + foreach ($fieldList as $field) { + $checkLogo[$field] = false; + if (!empty($formValues['remove_'.$field]) || $_FILES[$field]['size']) { + checkInstanceImage( + $certificateId, + $infoCertificate[$field], + $field + ); + } + + 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; + } + } } - $allowedPictureTypes = api_get_supported_image_extensions(false); - $form->addRule( - 'background', - get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', - 'filetype', - $allowedPictureTypes - ); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - $form->addElement('html', '
'.strtoupper(get_lang('OtherOptions')).''); - $marginOptions = []; - $i = 0; - while ($i < 298) { - $marginOptions[$i] = $i.' mm'; - $i++; + + // 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); + } + } + } } - $form->addElement( - 'select', - 'margin_left', - get_lang('MarginLeft'), - $marginOptions, - ['cols-size' => [4, 8, 0]] - ); - $form->addElement( - 'select', - 'margin_right', - get_lang('MarginRight'), - $marginOptions, - ['cols-size' => [4, 8, 0]] - ); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - $form->addElement('html', '
'); - - $form->addButton( - 'submit', - get_lang('SaveCertificate'), - 'check', - 'primary', - null, - null, - ['cols-size' => [5, 2, 5]], - false - ); - - $form->addElement('hidden', 'formSent'); - $infoCertificate['formSent'] = 1; - $form->setDefaults($infoCertificate); - $token = Security::get_token(); - $form->addElement('hidden', 'sec_token'); - $form->addElement('hidden', 'use_default'); - $form->addElement('hidden', 'default_certificate'); - $form->addElement('hidden', 'c_id'); - $form->addElement('hidden', 'session_id'); - $form->setConstants( - [ - 'sec_token' => $token, - 'use_default' => $useDefault, - 'default_certificate' => $defaultCertificate, - 'c_id' => $courseId, - 'session_id' => $sessionId, - ] - ); - echo '
'; - echo '
'; - echo '
'; - echo $form->returnForm(); - echo '
'; - echo '
'; - echo '
'; - Display::display_footer(); - } else { - $session = api_get_session_entity(api_get_session_id()); - $courseInfo = api_get_course_info(); - $webCoursePath = api_get_path(WEB_COURSE_PATH); - $url = $webCoursePath.$courseInfo['path'].'/index.php'.($session ? '?id_session='.$session->getId() : ''); - Display::addFlash( - Display::return_message($plugin->get_lang('OnlyAdminPlatformOrTeacher')) - ); + Display::addFlash(Display::return_message(get_lang('Saved'))); - header('Location: '.$url); + Security::clear_token(); + header('Location: '.api_get_self().$urlParams); exit; } -} else { - api_not_allowed(true, $plugin->get_lang('ToolDisabled')); } +if (empty($infoCertificate)) { + $infoCertificate = Database::select( + '*', + $table, + ['where' => ['access_url_id = ? AND certificate_default = ? ' => [$accessUrlId, 1]]], + 'first' + ); + + if (!is_array($infoCertificate)) { + $infoCertificate = []; + } + if (!empty($infoCertificate)) { + $useDefault = true; + } +} + +// 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'); +} + +// Student and course section +$form->addHtml('
'.strtoupper(get_lang('StudentCourseInfo')).''); +$form->addHtml('
'); +$dir = '/'; +$courseInfo = api_get_course_info(); +$isAllowedToEdit = api_is_allowed_to_edit(null, true); +$editorConfig = [ + 'ToolbarSet' => ($isAllowedToEdit ? 'Documents' : 'DocumentsStudent'), + 'Width' => '100%', + 'Height' => '300', + 'cols-size' => [0, 12, 0], + 'FullPage' => true, + 'InDocument' => true, + 'CreateDocumentDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/', + 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/', + 'BaseHref' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$dir, +]; +$form->addHtmlEditor( + 'content_course', + '', + false, + true, + $editorConfig, + true +); +$form->addHtml('
'); +$form->addHtml('
'); +$strInfo = '((user_firstname))
'; +$strInfo .= '((user_lastname))
'; +$strInfo .= '((gradebook_institution))
'; +$strInfo .= '((gradebook_sitename))
'; +$strInfo .= '((teacher_firstname))
'; +$strInfo .= '((teacher_lastname))
'; +$strInfo .= '((official_code))
'; +$strInfo .= '((date_certificate))
'; +$strInfo .= '((date_certificate_no_time))
'; +$strInfo .= '((course_code))
'; +$strInfo .= '((course_title))
'; +$strInfo .= '((gradebook_grade))
'; +$strInfo .= '((external_style))
'; +$strInfo .= '((start_date))
'; +$strInfo .= '((end_date))
'; +$strInfo .= '((date_expediction))'; + +$createCertificate = get_lang('CreateCertificateWithTags'); +$form->addElement( + 'html', + Display::return_message($createCertificate.':
'.$strInfo, 'normal', false) +); +$form->addHtml('
'); +$form->addHtml('
'); +$form->addHtml('
'); + +// Contents section +$form->addHtml('
'.strtoupper(get_lang('Contents')).''); +$extra = ''; +if (empty($infoCertificate['contents_type'])) { + $infoCertificate['contents_type'] = 0; + $extra = 'disabled'; +} + +$group = []; +$element = &$form->createElement( + 'radio', + 'contents_type', + '', + get_lang('ContentsCourseDescription'), + 0, + ['id' => 'contents_type_0', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();'] +); + +$group[] = $element; + +$element = &$form->createElement( + 'radio', + 'contents_type', + '', + get_lang('ContentsIndexLearnpath'), + 1, + ['id' => 'contents_type_1', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();'] +); +$group[] = $element; + +$element = &$form->createElement( + 'radio', + 'contents_type', + '', + get_lang('ContentsCustom'), + 2, + ['id' => 'contents_type_2', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();'] +); +$group[] = $element; + +$form->addGroup( + $group, + 'contents_type', + get_lang('ContentsToShow'), + null, + false +); + +$form->addHtml('
'); +$editorConfig = [ + 'ToolbarSet' => ($isAllowedToEdit ? 'Documents' : 'DocumentsStudent'), + 'Width' => '100%', + 'Height' => '200', + 'cols-size' => [2, 10, 0], + 'FullPage' => true, + 'InDocument' => true, + 'CreateDocumentDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/', + 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/', + 'BaseHref' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$dir, + 'id' => 'contents', + $extra, +]; +$form->addHtmlEditor( + 'contents', + get_lang('Contents'), + false, + true, + $editorConfig, + true +); +$form->addHtml('
'); + +// Dates section +$form->addHtml('
'.strtoupper(get_lang("Dates")).''); + +$group = []; +$option1 = &$form->createElement( + 'radio', + 'date_change', + '', + get_lang('UseDateSessionAccess'), + 0, + ['id' => 'contents_type_0', 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();'] +); +$group[] = $option1; + +$option2 = &$form->createElement( + 'radio', + 'date_change', + '', + get_lang('None'), + 2, + ['id' => 'contents_type_2', 'onclick' => 'javascript: dateCertificateSwitchRadioButton2();'] +); +$group[] = $option2; + +$option3 = &$form->createElement( + 'radio', + 'date_change', + '', + get_lang('Custom'), + 1, + ['id' => 'contents_type_1', 'onclick' => 'javascript: dateCertificateSwitchRadioButton1();'] +); +$group[] = $option3; + +$form->addGroup( + $group, + 'date_change', + get_lang('CourseDeliveryDates'), + null, + false +); +$form->addHtml('
+ +
+
+ '.get_lang('From').' + + '.get_lang('Until').' + +
+
+
'); + +$form->addText( + 'place', + get_lang('ExpectionPlace'), + false, + ['id' => 'place', 'cols-size' => [2, 5, 5], 'autofocus'] +); + +$group = []; +$option1 = &$form->createElement( + 'radio', + 'type_date_expediction', + '', + get_lang('UseDateEndAccessSession'), + 0, + [ + 'id' => 'type_date_expediction_0', + 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();', + (($sessionId == 0) ? 'disabled' : ''), + ] +); +$group[] = $option1; + +$option2 = &$form->createElement( + 'radio', + 'type_date_expediction', + '', + get_lang('UseDateDownloadCertificate'), + 1, + [ + 'id' => 'type_date_expediction_1', + 'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();', + ] +); +$group[] = $option2; + +$option4 = &$form->createElement( + 'radio', + 'type_date_expediction', + '', + get_lang('None'), + 3, + [ + 'id' => 'type_date_expediction_3', + 'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();', + ] +); +$group[] = $option4; + +$option3 = &$form->createElement( + 'radio', + 'type_date_expediction', + '', + get_lang('UseCustomDate'), + 2, + [ + 'id' => 'type_date_expediction_2', + 'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();', + ] +); +$group[] = $option3; + +$form->addGroup( + $group, + 'type_date_expediction', + get_lang('DateExpediction'), + null, + false +); + +$form->addHtml( + '
+ +
+
+ a + + de + + de + +
+
+
' +); +$form->addHtml('
'); + +// Signature section +$base = api_get_path(WEB_UPLOAD_PATH); +$path = $base.'certificates/'; +$form->addHtml('
'.strtoupper(get_lang('LogosSeal')).''); +// Logo 1 +$form->addHtml('
'); +$form->addFile( + 'logo_left', + get_lang('LogoLeft'), + [ + 'id' => 'logo_left', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_scalable' => 'true', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['logo_left'])) { + $form->addElement('checkbox', 'remove_logo_left', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$allowedPictureTypes = api_get_supported_image_extensions(false); +$form->addRule( + 'logo_left', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +// Logo 2 +$form->addHtml('
'); +$form->addFile( + 'logo_center', + get_lang('LogoCenter'), + [ + 'id' => 'logo_center', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_scalable' => 'true', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['logo_center'])) { + $form->addElement('checkbox', 'remove_logo_center', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$allowedPictureTypes = api_get_supported_image_extensions(false); +$form->addRule( + 'logo_center', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +// Logo 3 +$form->addHtml('
'); +$form->addFile( + 'logo_right', + get_lang('LogoRight'), + [ + 'id' => 'logo_right', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_scalable' => 'true', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['logo_right'])) { + $form->addElement('checkbox', 'remove_logo_right', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$tblProperty = api_get_supported_image_extensions(false); +$form->addRule( + 'logo_right', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +$form->addHtml('
'); +$form->addFile( + 'seal', + get_lang('Seal'), + [ + 'id' => 'seal', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_scalable' => 'true', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['seal'])) { + $form->addElement('checkbox', 'remove_seal', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$allowedPictureTypes = api_get_supported_image_extensions(false); +$form->addRule( + 'seal', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +$form->addHtml('
'); +$form->addHtml('
'.strtoupper(get_lang('Signatures')).''); +// signature 1 +$form->addHtml('
'); +$form->addText( + 'signature_text1', + get_lang('SignatureText1'), + false, + ['cols-size' => [2, 10, 0], 'autofocus'] +); +$form->addFile( + 'signature1', + get_lang('Signature1'), + [ + 'id' => 'signature1', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_scalable' => 'true', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['signature1'])) { + $form->addElement('checkbox', 'remove_signature1', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$allowedPictureTypes = api_get_supported_image_extensions(false); +$form->addRule( + 'signature1', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +// signature 2 +$form->addHtml('
'); +$form->addText( + 'signature_text2', + get_lang('SignatureText2'), + false, + ['cols-size' => [2, 10, 0], 'autofocus'] +); +$form->addFile( + 'signature2', + get_lang('Signature2'), + [ + 'id' => 'signature2', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_scalable' => 'true', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['signature2'])) { + $form->addElement('checkbox', 'remove_signature2', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$allowedPictureTypes = api_get_supported_image_extensions(false); +$form->addRule( + 'signature2', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +// signature 3 +$form->addHtml('
'); +$form->addText( + 'signature_text3', + get_lang('SignatureText3'), + false, + ['cols-size' => [2, 10, 0], 'autofocus'] +); +$form->addFile( + 'signature3', + get_lang('Signature3'), + [ + 'id' => 'signature3', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_scalable' => 'true', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['signature3'])) { + $form->addElement('checkbox', 'remove_signature3', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$allowedPictureTypes = api_get_supported_image_extensions(false); +$form->addRule( + 'signature3', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +// signature 4 +$form->addHtml('
'); +$form->addText( + 'signature_text4', + get_lang('SignatureText4'), + false, + ['cols-size' => [2, 10, 0], 'autofocus'] +); +$form->addFile( + 'signature4', + get_lang('Signature4'), + [ + 'id' => 'signature4', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_scalable' => 'true', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['signature4'])) { + $form->addElement('checkbox', 'remove_signature4', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$allowedPictureTypes = api_get_supported_image_extensions(false); +$form->addRule( + 'signature4', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +$form->addHtml('

'); +$form->addHtml('
'); +$form->addHtml('
'.strtoupper(get_lang('BackgroundCertificate')).''); +// background +$form->addFile( + 'background', + get_lang('Background'), + [ + 'id' => 'background', + 'class' => 'picture-form', + 'crop_image' => true, + 'crop_ratio' => '297 / 210', + ] +); +$form->addProgress(); +if (!empty($infoCertificate['background'])) { + $form->addElement('checkbox', 'remove_background', null, get_lang('DelImage')); + $form->addElement( + 'html', + ' + +

' + ); +} +$allowedPictureTypes = api_get_supported_image_extensions(false); +$form->addRule( + 'background', + get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')', + 'filetype', + $allowedPictureTypes +); +$form->addHtml('
'); +$form->addHtml('
'); +$form->addHtml('
'); +$form->addHtml('
'.strtoupper(get_lang('OtherOptions')).''); +$marginOptions = []; +$i = 0; +while ($i < 298) { + $marginOptions[$i] = $i.' mm'; + $i++; +} +$form->addElement( + 'select', + 'margin_left', + get_lang('MarginLeft'), + $marginOptions, + ['cols-size' => [4, 8, 0]] +); +$form->addElement( + 'select', + 'margin_right', + get_lang('MarginRight'), + $marginOptions, + ['cols-size' => [4, 8, 0]] +); +$form->addHtml('
'); +$form->addHtml('
'); +$form->addHtml('
'); + +$form->addButton( + 'submit', + get_lang('SaveCertificate'), + 'check', + 'primary', + null, + null, + ['cols-size' => [5, 2, 5]], + false +); + +$form->addElement('hidden', 'formSent'); +$infoCertificate['formSent'] = 1; +$form->setDefaults($infoCertificate); +$token = Security::get_token(); +$form->addElement('hidden', 'sec_token'); +$form->addElement('hidden', 'use_default'); +$form->addElement('hidden', 'default_certificate'); +$form->addElement('hidden', 'c_id'); +$form->addElement('hidden', 'session_id'); +$form->setConstants( + [ + 'sec_token' => $token, + 'use_default' => $useDefault, + 'default_certificate' => $defaultCertificate, + 'c_id' => $courseId, + 'session_id' => $sessionId, + ] +); +echo '
'; +echo '
'; +echo '
'; +echo $form->returnForm(); +echo '
'; +echo '
'; +echo '
'; +Display::display_footer(); + /** * Delete the file if there is only one instance. * @@ -927,6 +929,7 @@ function checkInstanceImage($certificateId, $imagePath, $field, $type = 'certifi { $table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE); $imagePath = Database::escape_string($imagePath); + $field = Database::escape_string($field); $sql = "SELECT * FROM $table WHERE $field = '$imagePath'"; $res = Database::query($sql); diff --git a/plugin/customcertificate/src/print_certificate.php b/plugin/customcertificate/src/print_certificate.php index 1a9ab880a4..b8357a34ad 100644 --- a/plugin/customcertificate/src/print_certificate.php +++ b/plugin/customcertificate/src/print_certificate.php @@ -45,10 +45,10 @@ if (empty($_GET['export_all'])) { } else { $certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $categoryTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = "SELECT cer.user_id AS user_id - FROM $certificateTable cer - INNER JOIN $categoryTable cat - ON (cer.cat_id = cat.id) + $sql = "SELECT cer.user_id AS user_id + FROM $certificateTable cer + INNER JOIN $categoryTable cat + ON (cer.cat_id = cat.id) WHERE cat.course_code = '$courseCode' AND cat.session_id = $sessionId"; $rs = Database::query($sql); while ($row = Database::fetch_assoc($rs)) { @@ -102,13 +102,13 @@ if (empty($infoCertificate)) { $workSpace = intval(297 - $infoCertificate['margin_left'] - $infoCertificate['margin_right']); $widthCell = intval($workSpace / 6); $htmlText = ''; -$htmlText .= ' - '; -$htmlText .= ' - '; $htmlText .= ''; foreach ($userList as $userInfo) { @@ -118,46 +118,46 @@ foreach ($userList as $userInfo) { $htmlText .= '
'; } else { $urlBackground = $path.$infoCertificate['background']; - $htmlText .= ' -
'; } if (!empty($infoCertificate['logo_left'])) { - $logoLeft = ' - '; } else { $logoLeft = ''; } if (!empty($infoCertificate['logo_center'])) { - $logoCenter = ' - '; } else { $logoCenter = ''; } if (!empty($infoCertificate['logo_right'])) { - $logoRight = ' - '; } else { $logoRight = ''; } - $htmlText .= ''; $htmlText .= ''; $htmlText .= ''; @@ -266,48 +266,48 @@ foreach ($userList as $userInfo) { $htmlText .= ''; $htmlText .= ' + ' + ' + ' - + '; $htmlText .= ''; $htmlText .= ''; $htmlText .= ' + ' + ' + ' + ''; @@ -359,11 +359,11 @@ foreach ($userList as $userInfo) { continue; } - $sql = "SELECT 1 - FROM $tblProperty - WHERE tool = 'learnpath_category' - AND ref = $categoryId - AND visibility = 0 + $sql = "SELECT 1 + FROM $tblProperty + WHERE tool = 'learnpath_category' + AND ref = $categoryId + AND visibility = 0 AND (session_id = $sessionId OR session_id IS NULL)"; $res = Database::query($sql); if (Database::num_rows($res) > 0) { @@ -393,10 +393,10 @@ foreach ($userList as $userInfo) { foreach ($flat_list as $learnpath) { $lpId = $learnpath['lp_old_id']; - $sql = "SELECT 1 - FROM $tblProperty - WHERE tool = 'learnpath' - AND ref = $lpId AND visibility = 0 + $sql = "SELECT 1 + FROM $tblProperty + WHERE tool = 'learnpath' + AND ref = $lpId AND visibility = 0 AND (session_id = $sessionId OR session_id IS NULL)"; $res = Database::query($sql); if (Database::num_rows($res) > 0) { @@ -464,11 +464,12 @@ 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); - + $text1 = ''; for ($x = 0; $x < 47; $x++) { $text1 .= $lines[$x].chr(13).chr(10); } + $text2 = ''; for ($x = 47; $x < 94; $x++) { $text2 .= $lines[$x].chr(13).chr(10); }
'. ((!empty($infoCertificate['signature_text1'])) ? $infoCertificate['signature_text1'] : ''). - ' '. ((!empty($infoCertificate['signature_text2'])) ? $infoCertificate['signature_text2'] : ''). - ' '. ((!empty($infoCertificate['signature_text3'])) ? $infoCertificate['signature_text3'] : ''). - ' '. ((!empty($infoCertificate['signature_text4'])) ? $infoCertificate['signature_text4'] : ''). - ' + ' '.((!empty($infoCertificate['seal'])) ? $plugin->get_lang('Seal') : ''). '
'. ((!empty($infoCertificate['signature1'])) - ? '' : ''). - ' '. ((!empty($infoCertificate['signature2'])) - ? '' : ''). - ' '. ((!empty($infoCertificate['signature3'])) - ? '' : ''). - ' '. ((!empty($infoCertificate['signature4'])) - ? '' : ''). - ' '. ((!empty($infoCertificate['seal'])) - ? '' : ''). '