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', 'class' => 'selectpicker',
'data-width' => $width, 'data-width' => $width,
'id' => $labelId 'id' => $labelId,
], ],
false false
); );

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

@ -465,8 +465,8 @@ class DisplayGradebook
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>';
$courseCode = api_get_course_id(); $courseCode = api_get_course_id();
if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') == 'true' && 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().'">'. $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>'; Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM).'</a>';
} else { } 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 { font-family:arial, sans-serif; font-size:18px; }
td.logo { height: 150px; vertical-align: middle; } .logo { height: 150px; vertical-align: middle; }
td.content-table { height: 480px; padding: 10px 25px; vertical-align:middle;} .content-table { height: 480px; padding: 10px 25px; vertical-align:middle;}
td.content-student { text-align:center; /*padding: 10px 0;*/ } .content-student { text-align:center;}
td.course { text-align:center; /*height: 200px;*/ vertical-align: middle; padding-top: 10px;} .course { padding-top: 10px; text-align:center; vertical-align: middle;}
td.modality { text-align:center; } .modality { text-align:center; }
td.course-date { text-align:center; } .course-date { text-align:center; }
td.expediction { text-align:right; font-size: 18px; padding: 20px 0;} .expediction { font-size: 18px; padding: 20px 0; text-align:right;}
td.seals { text-align:center; font-size: 16px;} .seals { font-size: 16px; text-align:center;}
td.logo-seals { text-align:center; height: 100px; vertical-align: middle;} .logo-seals { height: 100px; text-align:center; vertical-align: middle;}
@page caraA { margin:0; padding:0; page-break-before:always; height: 210mm;} @page caraA { height: 210mm; margin:0; padding:0; page-break-before:always;}
.caraA {box-decoration-break: slice; page: caraA} .caraA {box-decoration-break: slice; page: caraA}
@page caraB { background:#FFFFFF; } @page caraB { background:#FFFFFF; }
.caraB {box-decoration-break: slice; page: caraB} .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;} ol {margin: 0; padding:0;}

@ -1,17 +1,13 @@
.form-control-cert { .form-control-cert {
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff; background-color: #fff;
background-image: none; background-image: none;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 4px; 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); 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; color: #555;
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s; font-size: 14px;
line-height: 1.42857143;
padding: 6px 12px;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
} }
.certificado-text-label { .certificado-text-label {

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

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

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

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