Applied fixes from FlintCI and Codacy

pull/2525/head
Nosolored 8 years ago
parent 69545e0f74
commit c32cb1fa0f
  1. 2
      main/exercise/fill_blanks.class.php
  2. 4
      main/gradebook/gradebook_display_certificate.php
  3. 4
      main/gradebook/lib/fe/displaygradebook.php
  4. 24
      plugin/customcertificate/resources/css/certificate.css
  5. 12
      plugin/customcertificate/resources/css/form.css
  6. 90
      plugin/customcertificate/resources/js/certificate.js
  7. 7
      plugin/customcertificate/src/CustomCertificatePlugin.php
  8. 152
      plugin/customcertificate/src/index.php
  9. 188
      plugin/customcertificate/src/print_certificate.php

@ -559,7 +559,7 @@ class FillBlanks extends Question
[
'class' => 'selectpicker',
'data-width' => $width,
'id' => $labelId
'id' => $labelId,
],
false
);

@ -130,8 +130,8 @@ switch ($action) {
case 'export_all_certificates':
$courseCode = api_get_course_id();
if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') == 'true' &&
api_get_course_setting('customcertificate_course_enable', $courseCode) == 1 )
{
api_get_course_setting('customcertificate_course_enable', $courseCode) == 1
) {
$url = api_get_path(WEB_PLUGIN_PATH).'customcertificate/src/print_certificate.php?export_all=1';
} else {
if (api_is_student_boss()) {

@ -465,8 +465,8 @@ class DisplayGradebook
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>';
$courseCode = api_get_course_id();
if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') == 'true' &&
api_get_course_setting('customcertificate_course_enable', $courseCode) == 1 )
{
api_get_course_setting('customcertificate_course_enable', $courseCode) == 1
) {
$actionsRight .= '<a href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/src/index.php?'.$my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM).'</a>';
} else {

@ -1,17 +1,17 @@
body {background-repeat:no-repeat !important; margin:0; padding: 0;}
body {background-repeat:no-repeat; margin:0; padding: 0;}
td { font-family:arial, sans-serif; font-size:18px; }
td.logo { height: 150px; vertical-align: middle; }
td.content-table { height: 480px; padding: 10px 25px; vertical-align:middle;}
td.content-student { text-align:center; /*padding: 10px 0;*/ }
td.course { text-align:center; /*height: 200px;*/ vertical-align: middle; padding-top: 10px;}
td.modality { text-align:center; }
td.course-date { text-align:center; }
td.expediction { text-align:right; font-size: 18px; padding: 20px 0;}
td.seals { text-align:center; font-size: 16px;}
td.logo-seals { text-align:center; height: 100px; vertical-align: middle;}
@page caraA { margin:0; padding:0; page-break-before:always; height: 210mm;}
.logo { height: 150px; vertical-align: middle; }
.content-table { height: 480px; padding: 10px 25px; vertical-align:middle;}
.content-student { text-align:center;}
.course { padding-top: 10px; text-align:center; vertical-align: middle;}
.modality { text-align:center; }
.course-date { text-align:center; }
.expediction { font-size: 18px; padding: 20px 0; text-align:right;}
.seals { font-size: 16px; text-align:center;}
.logo-seals { height: 100px; text-align:center; vertical-align: middle;}
@page caraA { height: 210mm; margin:0; padding:0; page-break-before:always;}
.caraA {box-decoration-break: slice; page: caraA}
@page caraB { background:#FFFFFF; }
.caraB {box-decoration-break: slice; page: caraB}
.contents-learnpath td {font-size: 12px; background: #FFFFFF; padding: 10px; height: 160mm; vertical-align: top;}
.contents-learnpath td {background: #FFFFFF; font-size: 12px; height: 160mm; padding: 10px; vertical-align: top;}
ol {margin: 0; padding:0;}

@ -1,17 +1,13 @@
.form-control-cert {
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
color: #555;
font-size: 14px;
line-height: 1.42857143;
padding: 6px 12px;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
.certificado-text-label {

@ -1,70 +1,66 @@
function date_certificate_switch_radio_button_2(){
var input_date_start = document.getElementById("date_start");
var input_date_end = document.getElementById("date_end");
input_date_start.value = "";
input_date_end.value = "";
input_date_start.setAttribute("disabled","disabled");
input_date_end.setAttribute("disabled","disabled");
function dateCertificateSwitchRadioButton2(){
var inputDateStart = document.getElementById("date_start");
var inputDateEnd = document.getElementById("date_end");
inputDateStart.value = "";
inputDateEnd.value = "";
inputDateStart.setAttribute("disabled","disabled");
inputDateEnd.setAttribute("disabled","disabled");
}
function date_certificate_switch_radio_button_1(){
var input_date_start = document.getElementById("date_start");
var input_date_end = document.getElementById("date_end");
input_date_start.removeAttribute("disabled");
input_date_end.removeAttribute("disabled");
function dateCertificateSwitchRadioButton1(){
var inputDateStart = document.getElementById("date_start");
var inputDateEnd = document.getElementById("date_end");
inputDateStart.removeAttribute("disabled");
inputDateEnd.removeAttribute("disabled");
}
function date_certificate_switch_radio_button_0(){
var input_date_start = document.getElementById("date_start");
var input_date_end = document.getElementById("date_end");
input_date_start.value = "";
input_date_end.value = "";
input_date_start.setAttribute("disabled","disabled");
input_date_end.setAttribute("disabled","disabled");
function dateCertificateSwitchRadioButton0(){
var inputDateStart = document.getElementById("date_start");
var inputDateEnd = document.getElementById("date_end");
inputDateStart.value = "";
inputDateEnd.value = "";
inputDateStart.setAttribute("disabled","disabled");
inputDateEnd.setAttribute("disabled","disabled");
}
function type_date_expediction_switch_radio_button(){
var input_type = document.getElementsByName("type_date_expediction");
function typeDateExpedictionSwitchRadioButton(){
var inputType = document.getElementsByName("type_date_expediction");
var type;
for (var i=0;i<input_type.length;i++){
if ( input_type[i].checked ) {
type = input_type[i].value;
for (var i=0;i<inputType.length;i++){
if ( inputType[i].checked ) {
type = parseInt(inputType[i].value);
}
}
var input_day = document.getElementById("day");
var input_month = document.getElementById("month");
var input_year = document.getElementById("year");
if (type == 2) {
input_day.removeAttribute("disabled");
input_month.removeAttribute("disabled");
input_year.removeAttribute("disabled");
var inputDay = document.getElementById("day");
var inputMonth = document.getElementById("month");
var inputYear = document.getElementById("year");
if (type === 2) {
inputDay.removeAttribute("disabled");
inputMonth.removeAttribute("disabled");
inputYear.removeAttribute("disabled");
} else {
input_day.setAttribute("disabled","disabled");
input_month.setAttribute("disabled","disabled");
input_year.setAttribute("disabled","disabled");
inputDay.setAttribute("disabled","disabled");
inputMonth.setAttribute("disabled","disabled");
inputYear.setAttribute("disabled","disabled");
}
}
function contents_type_switch_radio_button(){
var input_type = document.getElementsByName("contents_type");
function contentsTypeSwitchRadioButton(){
var inputType = document.getElementsByName("contents_type");
var type;
for (var i=0;i<input_type.length;i++){
if ( input_type[i].checked ) {
type = input_type[i].value;
for (var i=0;i<inputType.length;i++){
if ( inputType[i].checked ) {
type = parseInt(inputType[i].value);
}
}
var input_contents = document.getElementById("contents");
if (type == 2) {
input_contents.removeAttribute("disabled");
var inputContents = document.getElementById("contents");
if (type === 2) {
inputContents.removeAttribute("disabled");
} else {
input_contents.setAttribute("disabled","disabled");
inputContents.setAttribute("disabled","disabled");
}
}
$(document).ready(function() {
CKEDITOR.on("instanceReady", function (e) {
showTemplates();
});
$( ".datepicker" ).datepicker();
});

@ -22,7 +22,7 @@ class CustomCertificatePlugin extends Plugin
[
'name' => 'use_certificate_default',
'type' => 'checkbox',
]
],
];
protected function __construct()
@ -195,7 +195,7 @@ class CustomCertificatePlugin extends Plugin
$sql = "DROP TABLE IF EXISTS $oldCertificateTable";
Database::query($sql);
echo $this->get_lang('MessageUpdate');
echo get_lang('MessageUpdate');
}
}
@ -212,7 +212,7 @@ class CustomCertificatePlugin extends Plugin
return false;
}
$certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$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, cat.session_id AS session_id, cat.course_code AS course_code
FROM $certificateTable cer
@ -233,6 +233,7 @@ class CustomCertificatePlugin extends Plugin
];
}
}
return [];
}
}

@ -1,8 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
if (intval($_GET['default']) == 1) {
$cidReset = true;
}
@ -62,7 +60,7 @@ 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)) {
@ -74,9 +72,9 @@ if ($enable) {
'post',
api_get_self().$urlParams,
null,
array('class' => 'form-vertical')
['class' => 'form-vertical']
);
if (isset($_POST['formSent']) && $_POST['formSent'] == 1 && $form->validate()) {
if ($form->validate()) {
$formValues = $form->getSubmitValues();
if (empty($formValues['contents'])) {
$contents = '';
@ -86,8 +84,8 @@ if ($enable) {
$check = Security::check_token('post');
if ($check) {
$date_start = str_replace('/', '-', $_POST['date_start']);
$date_end = str_replace('/', '-', $_POST['date_end']);
$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'],
@ -100,19 +98,19 @@ if ($enable) {
'date_end' => date("Y-m-d", strtotime($date_end)),
'place' => $formValues['place'],
'type_date_expediction' => intval($formValues['type_date_expediction']),
'day' => Database::escape_string($_POST['day']),
'month' => Database::escape_string($_POST['month']),
'year' => Database::escape_string($_POST['year']),
'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
'certificate_default' => 0,
];
if (intval($_POST['default_certificate'] == 1)) {
if (intval($formValues['default_certificate'] == 1)) {
$params['certificate_default'] = 1;
}
@ -320,13 +318,13 @@ if ($enable) {
}
// Certificate Default
if (intval($_POST['use_default'] == 1)) {
if (intval($formValues['use_default'] == 1)) {
$base = api_get_path(SYS_UPLOAD_PATH);
$infoCertificateDefault = Database::select(
'*',
$table,
['where'=> ['certificate_default = ? ' => 1]],
['where' => ['certificate_default = ? ' => 1]],
'first'
);
@ -447,12 +445,12 @@ if ($enable) {
$infoCertificate = Database::select(
'*',
$table,
['where'=> ['access_url_id = ? AND certificate_default = ? ' => [$accessUrlId, 1]]],
['where' => ['access_url_id = ? AND certificate_default = ? ' => [$accessUrlId, 1]]],
'first'
);
if (!is_array($infoCertificate)) {
$infoCertificate = array();
$infoCertificate = [];
}
if (!empty($infoCertificate)) {
$useDefault = true;
@ -467,7 +465,7 @@ if ($enable) {
);
echo Display::toolbarAction(
'toolbar-document',
array($actionsLeft)
[$actionsLeft]
);
if ($useDefault && $courseId > 0) {
@ -543,7 +541,7 @@ if ($enable) {
'',
get_lang('ContentsCourseDescription'),
0,
['id' => 'contents_type_0', 'onclick' => 'javascript: contents_type_switch_radio_button();']
['id' => 'contents_type_0', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();']
);
$group[] = $element;
@ -554,7 +552,7 @@ if ($enable) {
'',
get_lang('ContentsIndexLearnpath'),
1,
['id' => 'contents_type_1', 'onclick' => 'javascript: contents_type_switch_radio_button();']
['id' => 'contents_type_1', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();']
);
$group[] = $element;
@ -564,7 +562,7 @@ if ($enable) {
'',
get_lang('ContentsCustom'),
2,
['id' => 'contents_type_2', 'onclick' => 'javascript: contents_type_switch_radio_button();']
['id' => 'contents_type_2', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();']
);
$group[] = $element;
@ -610,7 +608,7 @@ if ($enable) {
'',
get_lang('UseDateSessionAccess'),
0,
['id' => 'contents_type_0', 'onclick' => 'javascript: date_certificate_switch_radio_button_0();']
['id' => 'contents_type_0', 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();']
);
$group[] = $option1;
@ -620,7 +618,7 @@ if ($enable) {
'',
get_lang('None'),
2,
['id' => 'contents_type_2', 'onclick' => 'javascript: date_certificate_switch_radio_button_2();']
['id' => 'contents_type_2', 'onclick' => 'javascript: dateCertificateSwitchRadioButton2();']
);
$group[] = $option2;
@ -630,7 +628,7 @@ if ($enable) {
'',
get_lang('Custom'),
1,
['id' => 'contents_type_1', 'onclick' => 'javascript: date_certificate_switch_radio_button_1();']
['id' => 'contents_type_1', 'onclick' => 'javascript: dateCertificateSwitchRadioButton1();']
);
$group[] = $option3;
@ -678,7 +676,7 @@ if ($enable) {
'place',
get_lang('ExpectionPlace'),
false,
array('id' => 'place', 'cols-size' => [2, 5, 5], 'autofocus')
['id' => 'place', 'cols-size' => [2, 5, 5], 'autofocus']
);
$group = [];
@ -690,8 +688,8 @@ if ($enable) {
0,
[
'id' => 'type_date_expediction_0',
'onclick' => 'javascript: date_certificate_switch_radio_button_0();',
(($sessionId == 0) ? 'disabled' : '')
'onclick' => 'javascript: dateCertificateSwitchRadioButton0();',
(($sessionId == 0) ? 'disabled' : ''),
]
);
$group[] = $option1;
@ -704,7 +702,7 @@ if ($enable) {
1,
[
'id' => 'type_date_expediction_1',
'onclick' => 'javascript: type_date_expediction_switch_radio_button();',
'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
]
);
$group[] = $option2;
@ -717,7 +715,7 @@ if ($enable) {
3,
[
'id' => 'type_date_expediction_3',
'onclick' => 'javascript: type_date_expediction_switch_radio_button();',
'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
]
);
$group[] = $option4;
@ -730,7 +728,7 @@ if ($enable) {
2,
[
'id' => 'type_date_expediction_2',
'onclick' => 'javascript: type_date_expediction_switch_radio_button();',
'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
]
);
$group[] = $option3;
@ -795,12 +793,12 @@ if ($enable) {
$form->addFile(
'logo_left',
get_lang('LogoLeft'),
array(
[
'id' => 'logo_left',
'class' => 'picture-form',
'crop_image' => true,
'crop_scalable' => 'true'
)
'crop_scalable' => 'true',
]
);
$form->addProgress();
if (!empty($infoCertificate['logo_left'])) {
@ -825,12 +823,12 @@ if ($enable) {
$form->addFile(
'logo_center',
get_lang('LogoCenter'),
array(
[
'id' => 'logo_center',
'class' => 'picture-form',
'crop_image' => true,
'crop_scalable' => 'true'
)
'crop_scalable' => 'true',
]
);
$form->addProgress();
if (!empty($infoCertificate['logo_center'])) {
@ -855,12 +853,12 @@ if ($enable) {
$form->addFile(
'logo_right',
get_lang('LogoRight'),
array(
[
'id' => 'logo_right',
'class' => 'picture-form',
'crop_image' => true,
'crop_scalable' => 'true'
)
'crop_scalable' => 'true',
]
);
$form->addProgress();
if (!empty($infoCertificate['logo_right'])) {
@ -884,12 +882,12 @@ if ($enable) {
$form->addFile(
'seal',
get_lang('Seal'),
array(
[
'id' => 'seal',
'class' => 'picture-form',
'crop_image' => true,
'crop_scalable' => 'true'
)
'crop_scalable' => 'true',
]
);
$form->addProgress();
if (!empty($infoCertificate['seal'])) {
@ -917,17 +915,17 @@ if ($enable) {
'signature_text1',
get_lang('SignatureText1'),
false,
array('cols-size' => [2, 10, 0], 'autofocus')
['cols-size' => [2, 10, 0], 'autofocus']
);
$form->addFile(
'signature1',
get_lang('Signature1'),
array(
[
'id' => 'signature1',
'class' => 'picture-form',
'crop_image' => true,
'crop_scalable' => 'true'
)
'crop_scalable' => 'true',
]
);
$form->addProgress();
if (!empty($infoCertificate['signature1'])) {
@ -953,17 +951,17 @@ if ($enable) {
'signature_text2',
get_lang('SignatureText2'),
false,
array('cols-size' => [2, 10, 0], 'autofocus')
['cols-size' => [2, 10, 0], 'autofocus']
);
$form->addFile(
'signature2',
get_lang('Signature2'),
array(
[
'id' => 'signature2',
'class' => 'picture-form',
'crop_image' => true,
'crop_scalable' => 'true'
)
'crop_scalable' => 'true',
]
);
$form->addProgress();
if (!empty($infoCertificate['signature2'])) {
@ -989,17 +987,17 @@ if ($enable) {
'signature_text3',
get_lang('SignatureText3'),
false,
array('cols-size' => [2, 10, 0], 'autofocus')
['cols-size' => [2, 10, 0], 'autofocus']
);
$form->addFile(
'signature3',
get_lang('Signature3'),
array(
[
'id' => 'signature3',
'class' => 'picture-form',
'crop_image' => true,
'crop_scalable' => 'true'
)
'crop_scalable' => 'true',
]
);
$form->addProgress();
if (!empty($infoCertificate['signature3'])) {
@ -1025,17 +1023,17 @@ if ($enable) {
'signature_text4',
get_lang('SignatureText4'),
false,
array('cols-size' => [2, 10, 0], 'autofocus')
['cols-size' => [2, 10, 0], 'autofocus']
);
$form->addFile(
'signature4',
get_lang('Signature4'),
array(
[
'id' => 'signature4',
'class' => 'picture-form',
'crop_image' => true,
'crop_scalable' => 'true'
)
'crop_scalable' => 'true',
]
);
$form->addProgress();
if (!empty($infoCertificate['signature4'])) {
@ -1062,12 +1060,12 @@ if ($enable) {
$form->addFile(
'background',
get_lang('Background'),
array(
[
'id' => 'background',
'class' => 'picture-form',
'crop_image' => true,
'crop_ratio' => '297 / 210'
)
'crop_ratio' => '297 / 210',
]
);
$form->addProgress();
if (!empty($infoCertificate['background'])) {
@ -1101,14 +1099,14 @@ if ($enable) {
'margin_left',
get_lang('MarginLeft'),
$marginOptions,
array('cols-size' => [4, 8, 0])
['cols-size' => [4, 8, 0]]
);
$form->addElement(
'select',
'margin_right',
get_lang('MarginRight'),
$marginOptions,
array('cols-size' => [4, 8, 0])
['cols-size' => [4, 8, 0]]
);
$form->addElement('html', '</fieldset>');
$form->addElement('html', '</div>');
@ -1143,13 +1141,13 @@ if ($enable) {
'session_id' => $sessionId,
]
);
echo '<div class="page-create">
<div class="row" style="overflow:hidden">
<div id="doc_form" class="col-md-12">
'.$form->returnForm().'
</div>
</div>
</div>';
echo '<div class="page-create">';
echo '<div class="row" style="overflow:hidden">';
echo '<div id="doc_form" class="col-md-12">';
echo $form->returnForm();
echo '</div>';
echo '</div>';
echo '</div>';
Display::display_footer();
} else {
$session = api_get_session_entity(api_get_session_id());
@ -1171,20 +1169,23 @@ if ($enable) {
function uploadImageCertificate(
$certId,
$file = null,
$source_file = null,
$sourceFile = null,
$cropParameters = '',
$default = false
) {
if (empty($certId)) {
return false;
}
$delete = empty($file);
if (empty($source_file)) {
$source_file = $file;
if (empty($sourceFile)) {
$sourceFile = $file;
}
$base = api_get_path(SYS_UPLOAD_PATH);
$path = $base.'certificates/'.$certId.'/';
if ($default) {
$path = $base.'certificates/default/';
}
@ -1193,14 +1194,17 @@ function uploadImageCertificate(
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;
}
@ -1210,10 +1214,10 @@ function uploadImageCertificate(
$filename = $certId.'_'.$filename;
//Crop the image to adjust 1:1 ratio
$image = new Image($source_file);
$image = new Image($sourceFile);
$image->crop($cropParameters);
$origin = new Image($source_file); // This is the original picture.
$origin = new Image($sourceFile); // This is the original picture.
$origin->send_image($path.$filename);
$result = $origin;

@ -2,7 +2,6 @@
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CLpCategory;
use ChamiloSession as Session;
if (intval($_GET['default']) == 1) {
$cidReset = true;
@ -35,7 +34,7 @@ if (intval($_GET['default']) == 1) {
}
$accessUrlId = api_get_current_access_url_id();
$userList = array();
$userList = [];
if (empty($_GET['export_all'])) {
if (!isset($_GET['student_id'])) {
$studentId = api_get_user_id();
@ -44,7 +43,7 @@ if (empty($_GET['export_all'])) {
}
$userList[] = api_get_user_info($studentId);
} else {
$certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$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
@ -70,24 +69,24 @@ $base = api_get_path(WEB_UPLOAD_PATH).'certificates/';
$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)) {
$infoCertificate = array();
$infoCertificate = [];
}
if (empty($infoCertificate)) {
$infoCertificate = Database::select(
'*',
Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE),
['where'=> ['access_url_id = ? AND certificate_default = ? ' => [$accessUrlId, 1]]],
['where' => ['access_url_id = ? AND certificate_default = ? ' => [$accessUrlId, 1]]],
'first'
);
if (!is_array($infoCertificate)) {
$infoCertificate = array();
$infoCertificate = [];
}
if (empty($infoCertificate)) {
@ -104,7 +103,7 @@ if (empty($infoCertificate)) {
}
$workSpace = intval(297 - $infoCertificate['margin_left'] - $infoCertificate['margin_right']);
$widthCell = intval($workSpace / 6);
$widthCell = intval($workSpace / 6);
$htmlText = '';
$htmlText .= '<link rel="stylesheet"
type="text/css"
@ -165,9 +164,9 @@ foreach ($userList as $userInfo) {
border="0"
>';
$htmlText .= '<tr>';
$htmlText .= '<td colspan="4" class="logo">'.$logoLeft.'</td>';
$htmlText .= '<td colspan="4" class="logo" style="text-align:center;">'.$logoCenter.'</td>';
$htmlText .= '<td colspan="4" class="logo" style="text-align:right;">'.$logoRight.'</td>';
$htmlText .= '<td colspan="4" class="logo">'.$logoLeft.'</td>';
$htmlText .= '<td colspan="4" class="logo" style="text-align:center;">'.$logoCenter.'</td>';
$htmlText .= '<td colspan="4" class="logo" style="text-align:right;">'.$logoRight.'</td>';
$htmlText .= '</tr>';
$all_user_info = DocumentManager::get_all_info_to_certificate(
@ -177,7 +176,7 @@ foreach ($userList as $userInfo) {
);
$myContentHtml = $infoCertificate['content_course'];
$myContentHtml = str_replace(chr(13).chr(10).chr(13).chr(10),chr(13).chr(10), $myContentHtml);
$myContentHtml = str_replace(chr(13).chr(10).chr(13).chr(10), chr(13).chr(10), $myContentHtml);
$info_to_be_replaced_in_content_html = $all_user_info[0];
$info_to_replace_in_content_html = $all_user_info[1];
$myContentHtml = str_replace(
@ -257,71 +256,70 @@ foreach ($userList as $userInfo) {
'<p><b><strong><table><tr><td><th><tbody><span><i><li><ol><ul><dd><dt><dl><br><hr><img><a><div>'
);
$htmlText .= '<tr>';
$htmlText .= '<td colspan="12" class="content-table">';
$htmlText .= '<table width="100%">';
$htmlText .= '<tr>';
$htmlText .= '<td colspan="12" class="content-student">';
$htmlText .= $myContentHtml;
$htmlText .= '</td>';
$htmlText .= '</tr>';
$htmlText .= '</table>';
$htmlText .= '</td>';
$htmlText .= '<td colspan="12" class="content-table">';
$htmlText .= '<table width="100%">';
$htmlText .= '<tr>';
$htmlText .= '<td colspan="12" class="content-student">';
$htmlText .= $myContentHtml;
$htmlText .= '</td>';
$htmlText .= '</tr>';
$htmlText .= '</table>';
$htmlText .= '</td>';
$htmlText .= '</tr>';
$htmlText .= '<tr>';
$htmlText .= '<td colspan="2" class="seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature_text1'])) ? $infoCertificate['signature_text1'] : '').
'</td>
<td colspan="2" class="seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature_text2'])) ? $infoCertificate['signature_text2'] : '').
'</td>
<td colspan="2" class="seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature_text3'])) ? $infoCertificate['signature_text3'] : '').
'</td>
<td colspan="2" class="seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature_text4'])) ? $infoCertificate['signature_text4'] : '').
'</td>
<td colspan="4" class="seals" style="width:'.(2 * $widthCell).'mm">
'.((!empty($infoCertificate['seal'])) ? $plugin->get_lang('Seal') : '').
'</td>';
$htmlText .= '<td colspan="2" class="seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature_text1'])) ? $infoCertificate['signature_text1'] : '').
'</td>
<td colspan="2" class="seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature_text2'])) ? $infoCertificate['signature_text2'] : '').
'</td>
<td colspan="2" class="seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature_text3'])) ? $infoCertificate['signature_text3'] : '').
'</td>
<td colspan="2" class="seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature_text4'])) ? $infoCertificate['signature_text4'] : '').
'</td>
<td colspan="4" class="seals" style="width:'.(2 * $widthCell).'mm">
'.((!empty($infoCertificate['seal'])) ? $plugin->get_lang('Seal') : '').
'</td>';
$htmlText .= '</tr>';
$htmlText .= '<tr>';
$htmlText .= '<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature1']))
? '<img style="max-height: 100px; max-width: '.$widthCell.'mm;"
src="'.$path.$infoCertificate['signature1'].'"
/>'
: '').
'</td>
<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature2']))
? '<img style="max-height: 100px; '.$widthCell.'mm;"
src="'.$path.$infoCertificate['signature2'].'"
/>'
: '').
'</td>
<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature3']))
? '<img style="max-height: 100px; '.$widthCell.'mm;"
src="'.$path.$infoCertificate['signature3'].'"
/>'
: '').
'</td>
<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature4']))
? '<img style="max-height: 100px; '.$widthCell.'mm;"
src="'.$path.$infoCertificate['signature4'].'"
/>'
: '').
'</td>
<td colspan="4" class="logo-seals" style="width:'.(2 * $widthCell).'mm">
'.((!empty($infoCertificate['seal']))
? '<img style="max-height: 100px; '.(2 * $widthCell).'mm;"
src="'.$path.$infoCertificate['seal'].'"
/>'
: '').
'</td>';
$htmlText .= '<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature1']))
? '<img style="max-height: 100px; max-width: '.$widthCell.'mm;"
src="'.$path.$infoCertificate['signature1'].'"
/>'
: '').
'</td>
<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature2']))
? '<img style="max-height: 100px; '.$widthCell.'mm;"
src="'.$path.$infoCertificate['signature2'].'"
/>'
: '').
'</td>
<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature3']))
? '<img style="max-height: 100px; '.$widthCell.'mm;"
src="'.$path.$infoCertificate['signature3'].'"
/>'
: '').
'</td>
<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">
'.((!empty($infoCertificate['signature4']))
? '<img style="max-height: 100px; '.$widthCell.'mm;"
src="'.$path.$infoCertificate['signature4'].'"
/>'
: '').
'</td>
<td colspan="4" class="logo-seals" style="width:'.(2 * $widthCell).'mm">
'.((!empty($infoCertificate['seal']))
? '<img style="max-height: 100px; '.(2 * $widthCell).'mm;"
src="'.$path.$infoCertificate['seal'].'"
/>'
: '').
'</td>';
$htmlText .= '</tr>';
$htmlText .= '</table>';
$htmlText .= '</div>';
@ -330,7 +328,6 @@ foreach ($userList as $userInfo) {
$htmlText .= '<div class="caraB" style="page-break-before:always;" margin:0; padding:0;>';
if ($infoCertificate['contents_type'] == 0) {
$contentsDescription = CourseDescription::get_data_by_description_type(3, $courseId, 0);
$domd = new DOMDocument();
@ -340,12 +337,12 @@ foreach ($userList as $userInfo) {
$domx = new DOMXPath($domd);
$items = $domx->query("//li[@style]");
foreach($items as $item) {
foreach ($items as $item) {
$item->removeAttribute("style");
}
$items = $domx->query("//span[@style]");
foreach($items as $item) {
foreach ($items as $item) {
$item->removeAttribute("style");
}
@ -355,15 +352,15 @@ foreach ($userList as $userInfo) {
}
if ($infoCertificate['contents_type'] == 1) {
$items = array();
$items = [];
$categoriesTempList = learnpath::getCategories($courseId);
$categoryTest = new CLpCategory();
$categoryTest->setId(0);
$categoryTest->setName($plugin->get_lang('WithOutCategory'));
$categoryTest->setPosition(0);
$categories = array(
$categoryTest
);
$categories = [
$categoryTest
];
if (!empty($categoriesTempList)) {
$categories = array_merge($categories, $categoriesTempList);
}
@ -420,7 +417,7 @@ foreach ($userList as $userInfo) {
continue;
}
$lpName = $learnpath['lp_name'];
$items[] = $lpName.'<br>';
$items[] = $lpName.'<br>';
}
$items[] = '<br>';
}
@ -462,30 +459,30 @@ foreach ($userList as $userInfo) {
}
$htmlText .= '</body>';
$fileName = 'certificate_'.date("Ymd_His");
$params = array(
'filename' => $fileName,
'pdf_title' => "Certificate",
'pdf_description' => '',
'format' => 'A4-L',
'orientation' => 'L',
'left' => 15,
'top' => 15,
'bottom' => 0,
);
$params = [
'filename' => $fileName,
'pdf_title' => "Certificate",
'pdf_description' => '',
'format' => 'A4-L',
'orientation' => 'L',
'left' => 15,
'top' => 15,
'bottom' => 0,
];
$pdf = new PDF($params['format'], $params['orientation'], $params);
$pdf->content_to_pdf($htmlText, '', $fileName, null, 'I', false, null, false, true, false);
function getIndexFiltered($indice){
function getIndexFiltered($indice) {
$txt = strip_tags($indice, "<b><strong><i>");
$txt = str_replace(chr(13).chr(10).chr(13).chr(10),chr(13).chr(10), $txt);
$txt = str_replace(chr(13).chr(10).chr(13).chr(10), chr(13).chr(10), $txt);
$lines = explode(chr(13).chr(10), $txt);
$n = count($lines);
for ($x=0; $x<47; $x++) {
for ($x = 0; $x < 47; $x++) {
$text1 .= $lines[$x].chr(13).chr(10);
}
for ($x=47; $x<94; $x++) {
for ($x = 47; $x < 94; $x++) {
$text2 .= $lines[$x].chr(13).chr(10);
}
@ -500,4 +497,3 @@ function getIndexFiltered($indice){
return $result;
}
Loading…
Cancel
Save