Actualización
This commit is contained in:
26
plugin/customcertificate/README.md
Normal file
26
plugin/customcertificate/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
CustomCertificate plugin
|
||||
===============
|
||||
Este plugin da la posibilidad al administrador de disponer de una herramienta de certificados alternativa
|
||||
a la que tiene por defecto la plataforma Chamilo.
|
||||
|
||||
**Instrucciones de puesta en funcionamiento**
|
||||
|
||||
- Habilitar el plugin en la administración de Chamilo.
|
||||
- Indicar 'menu_administrator' en la configuración de la región del plugin.
|
||||
|
||||
**accesos a la herramienta**
|
||||
|
||||
- Desde la pantalla de Administración para configurar el certificado por defecto.
|
||||
- Desde las herramientas del curso, para la configuración del diploma especifico.
|
||||
|
||||
**Importante a tener en cuenta**
|
||||
|
||||
Por defecto los certificados utilizados serán los de la plataforma chamilo. Para habilitar el certificado alternativo
|
||||
en un curso se debe entrar en la configuración del curso y habilitar en la pestaña de "certificados personalizado" la
|
||||
casilla de verificación de "Habilitar en el curso el certificado alternativo".
|
||||
Si se desea usar el certificado por defecto se deberá mostrar la segunda casilla de verificación.
|
||||
|
||||
|
||||
Credits
|
||||
-------
|
||||
Contributed by [Nosolored](https://www.nosolored.com/).
|
||||
11
plugin/customcertificate/config.php
Normal file
11
plugin/customcertificate/config.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Config the plugin.
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*
|
||||
* @author Jose Angel Ruiz <desarrollo@nosolored.com>
|
||||
*/
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php';
|
||||
68
plugin/customcertificate/database.php
Normal file
68
plugin/customcertificate/database.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
/**
|
||||
* Plugin database installation script. Can only be executed if included
|
||||
* inside another script loading global.inc.php.
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*/
|
||||
/**
|
||||
* Check if script can be called.
|
||||
*/
|
||||
if (!function_exists('api_get_path')) {
|
||||
exit('This script must be loaded through the Chamilo plugin installer sequence');
|
||||
}
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
$pluginSchema = new \Doctrine\DBAL\Schema\Schema();
|
||||
$connection = $entityManager->getConnection();
|
||||
$platform = $connection->getDatabasePlatform();
|
||||
|
||||
if ($pluginSchema->hasTable(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Create tables
|
||||
$certificateTable = $pluginSchema->createTable(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE);
|
||||
$certificateTable->addColumn('id', Type::INTEGER, ['autoincrement' => true, 'unsigned' => true]);
|
||||
$certificateTable->addColumn('access_url_id', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addColumn('c_id', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addColumn('session_id', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addColumn('content_course', Type::TEXT);
|
||||
$certificateTable->addColumn('contents_type', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addColumn('contents', Type::TEXT);
|
||||
$certificateTable->addColumn('date_change', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addColumn('date_start', Type::DATETIME);
|
||||
$certificateTable->addColumn('date_end', Type::DATETIME);
|
||||
$certificateTable->addColumn('type_date_expediction', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addColumn('place', Type::STRING);
|
||||
$certificateTable->addColumn('day', Type::STRING, ['notnull' => false]);
|
||||
$certificateTable->addColumn('month', Type::STRING, ['notnull' => false]);
|
||||
$certificateTable->addColumn('year', Type::STRING, ['notnull' => false]);
|
||||
$certificateTable->addColumn('logo_left', Type::STRING);
|
||||
$certificateTable->addColumn('logo_center', Type::STRING);
|
||||
$certificateTable->addColumn('logo_right', Type::STRING);
|
||||
$certificateTable->addColumn('seal', Type::STRING);
|
||||
$certificateTable->addColumn('signature1', Type::STRING);
|
||||
$certificateTable->addColumn('signature2', Type::STRING);
|
||||
$certificateTable->addColumn('signature3', Type::STRING);
|
||||
$certificateTable->addColumn('signature4', Type::STRING);
|
||||
$certificateTable->addColumn('signature_text1', Type::STRING);
|
||||
$certificateTable->addColumn('signature_text2', Type::STRING);
|
||||
$certificateTable->addColumn('signature_text3', Type::STRING);
|
||||
$certificateTable->addColumn('signature_text4', Type::STRING);
|
||||
$certificateTable->addColumn('background', Type::STRING);
|
||||
$certificateTable->addColumn('margin_left', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addColumn('margin_right', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addColumn('certificate_default', Type::INTEGER, ['unsigned' => true]);
|
||||
$certificateTable->addIndex(['c_id', 'session_id']);
|
||||
$certificateTable->setPrimaryKey(['id']);
|
||||
|
||||
$queries = $pluginSchema->toSql($platform);
|
||||
|
||||
foreach ($queries as $query) {
|
||||
Database::query($query);
|
||||
}
|
||||
3
plugin/customcertificate/index.php
Normal file
3
plugin/customcertificate/index.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
require_once 'config.php';
|
||||
15
plugin/customcertificate/install.php
Normal file
15
plugin/customcertificate/install.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* This script is included by main/admin/settings.lib.php and generally
|
||||
* includes things to execute in the main database (settings_current table).
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*/
|
||||
require_once __DIR__.'/config.php';
|
||||
|
||||
if (!api_is_platform_admin()) {
|
||||
exit('You must have admin permissions to install plugins');
|
||||
}
|
||||
|
||||
CustomCertificatePlugin::create()->install();
|
||||
77
plugin/customcertificate/lang/english.php
Normal file
77
plugin/customcertificate/lang/english.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
$strings['plugin_title'] = "Custom certificate";
|
||||
$strings['plugin_comment'] = "This plugin allows you to create custom certificates for each course.";
|
||||
$strings['enable_plugin_customcertificate'] = "Enable plugin";
|
||||
$strings['customcertificate_course_enable'] = "Custom certificate enable in course";
|
||||
$strings['use_certificate_default'] = "Use default custom certificate";
|
||||
$strings['ToolDisabled'] = "The tool is disabled from the administration";
|
||||
$strings['OnlyAdminPlatform'] = "Tool only for administrators";
|
||||
$strings['OnlyAdminPlatformOrTeacher'] = "Tool only for administrators and teachers";
|
||||
$strings['TrainingEntity'] = "Training entity";
|
||||
$strings['DescriptionFront'] = "Description front";
|
||||
$strings['DescriptionRear'] = "Description rear";
|
||||
$strings['Certify'] = "Certify";
|
||||
$strings['CertificateType'] = "Certificate type";
|
||||
$strings['CertifyThat'] = "CERTIFY THAT";
|
||||
$strings['StudentCourseInfo'] = 'Student and Course data';
|
||||
$strings['StudentData'] = "Student data";
|
||||
$strings['CourseData'] = "Course data";
|
||||
$strings['Modality'] = "Modality";
|
||||
$strings['Contents'] = "Contents";
|
||||
$strings['ContentsToShow'] = "Contents to show";
|
||||
$strings['ContentsCourseDescription'] = 'Use section "Course description"> "Contents"';
|
||||
$strings['ContentsIndexLearnpath'] = "Use learnpath index";
|
||||
$strings['ContentsCustom'] = "Use custom content";
|
||||
$strings['ContentsHide'] = "No show contents";
|
||||
$strings['Dates'] = "Dates";
|
||||
$strings['CourseDeliveryDates'] = "Course delivery dates";
|
||||
$strings['Custom'] = "Custom";
|
||||
$strings['UseDateSessionAccess'] = "Use access dates to the session";
|
||||
$strings['ExpectionPlace'] = "Expection place";
|
||||
$strings['DateExpediction'] = "Expediction date";
|
||||
$strings['UseDateEndAccessSession'] = "Use end date of session access";
|
||||
$strings['UseDateDownloadCertificate'] = "Use certificate download date";
|
||||
$strings['UseDateGenerationCertificate'] = "Use certificate generation date";
|
||||
$strings['UseCustomDate'] = "Use custom date";
|
||||
$strings['LogosSeal'] = "Logos / Seals";
|
||||
$strings['LogoLeft'] = "Logo left";
|
||||
$strings['LogoCenter'] = "Logo center";
|
||||
$strings['LogoRight'] = "Logo right";
|
||||
$strings['Seal'] = "Seal";
|
||||
$strings['Signature1'] = "Signature 1";
|
||||
$strings['Signature2'] = "Signature 2";
|
||||
$strings['Signature3'] = "Signature 3";
|
||||
$strings['Signature4'] = "Signature 4";
|
||||
$strings['SignatureText1'] = "Signature text 1";
|
||||
$strings['SignatureText2'] = "Signature text 2";
|
||||
$strings['SignatureText3'] = "Signature text 3";
|
||||
$strings['SignatureText4'] = "Signature text 4";
|
||||
$strings['OtherOptions'] = "Others options";
|
||||
$strings['MarginRight'] = "Margin right";
|
||||
$strings['MarginLeft'] = "Margin left";
|
||||
$strings['SetDefaultTemplate'] = "Set template by default";
|
||||
$strings['MessageDefaultTemplate'] = "Save this default customization for courses and sessions without
|
||||
defined certificates";
|
||||
$strings['None'] = "None";
|
||||
$strings['ErrorTemplateCertificate'] = "There is no template defined for the certificate.
|
||||
There is no template by default.";
|
||||
$strings['DateStartEnd'] = "With Start date and End date: ";
|
||||
$strings['ExpedictionIn'] = "Expediction in";
|
||||
$strings['Signatures'] = "Signatures";
|
||||
$strings['BackgroundCertificate'] = "Background image of the certificate";
|
||||
$strings['Background'] = "Background";
|
||||
$strings['CertificateSetting'] = "Certificate setting";
|
||||
$strings['ToolDisabledCourse'] = "Tool disabled in course setting";
|
||||
$strings['ToolUseDefaultSettingCourse'] = "Tool configured to use the default certificate. <br>
|
||||
You can edit it from the Administration screen -> Plugins -> Custom Certificate. <br>
|
||||
Or if you want you can disable the option to use certificate by default in the plugin configuration in the course";
|
||||
$strings['CertificateSettingDefault'] = "Default certificate settings";
|
||||
$strings['InfoFromDefaultCertificate'] = "The content of the certificate is based on the default certificate.
|
||||
The modifications you make will not affect the default certificate.";
|
||||
$strings['to'] = " to ";
|
||||
$strings['formatDownloadDate'] = " to %sth %s, %s";
|
||||
$strings['PrintCertificate'] = "Print certificate";
|
||||
$strings['QuestionDelete'] = "Do you want to delete the specific diploma and use the default certificate?";
|
||||
$strings['SuccessDelete'] = "Successfully deleted";
|
||||
$strings['ProblemDelete'] = "Problem deleting the certificate";
|
||||
$strings['OnlyCustomCertificates'] = "Only courses with a personalized certificate are exported";
|
||||
79
plugin/customcertificate/lang/spanish.php
Normal file
79
plugin/customcertificate/lang/spanish.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
$strings['plugin_title'] = "Certificado personalizado";
|
||||
$strings['plugin_comment'] = "Este plugin permite crear certificados personalizados por curso.";
|
||||
$strings['enable_plugin_customcertificate'] = "Activar plugin";
|
||||
$strings['customcertificate_course_enable'] = "Habilitar en el curso el certificado alternativo";
|
||||
$strings['use_certificate_default'] = "Usar el certificado personalizado por defecto";
|
||||
$strings['ToolDisabled'] = "La herramienta está deshabilitada desde la administración";
|
||||
$strings['OnlyAdminPlatform'] = "Herramienta exclusiva para administradores";
|
||||
$strings['OnlyAdminPlatformOrTeacher'] = "Herramienta para administradores y profesores";
|
||||
$strings['TrainingEntity'] = "Entidad formadora";
|
||||
$strings['DescriptionFront'] = "Descripción principal";
|
||||
$strings['DescriptionRear'] = "Descripción trasera";
|
||||
$strings['Certify'] = "Certifica";
|
||||
$strings['CertificateType'] = "Tipo certificado";
|
||||
$strings['CertifyThat'] = "CERTIFICA QUE";
|
||||
$strings['StudentCourseInfo'] = 'Datos del alumno y curso';
|
||||
$strings['StudentData'] = "Datos estudiante";
|
||||
$strings['CourseData'] = "Datos curso";
|
||||
$strings['Modality'] = "Modalidad";
|
||||
$strings['Contents'] = "Contenidos";
|
||||
$strings['ContentsToShow'] = "Contenidos a mostrar";
|
||||
$strings['ContentsCourseDescription'] = 'Usar apartado "Descripcion del curso" > "Contenidos"';
|
||||
$strings['ContentsIndexLearnpath'] = "Usar indice de lecciones";
|
||||
$strings['ContentsCustom'] = "Usar contenido personalizado";
|
||||
$strings['ContentsHide'] = "No mostrar contenidos";
|
||||
$strings['Dates'] = "Fechas";
|
||||
$strings['CourseDeliveryDates'] = "Fechas de impartición del curso";
|
||||
$strings['Custom'] = "Personalizado";
|
||||
$strings['UseDateSessionAccess'] = "Usar fechas de acceso a la sesión";
|
||||
$strings['ExpectionPlace'] = "Lugar expedición";
|
||||
$strings['DateExpediction'] = "Fecha expedición";
|
||||
$strings['UseDateEndAccessSession'] = "Usar fecha fin de acceso de la sesión";
|
||||
$strings['UseDateDownloadCertificate'] = "Usar fecha de descarga del certificado";
|
||||
$strings['UseDateGenerationCertificate'] = "Usar fecha de generación del certificado";
|
||||
$strings['UseCustomDate'] = "Usar fechas personalizadas";
|
||||
$strings['LogosSeal'] = "Logos / Sellos";
|
||||
$strings['LogoLeft'] = "Logo izquierda";
|
||||
$strings['LogoCenter'] = "Logo central";
|
||||
$strings['LogoRight'] = "Logo derecha";
|
||||
$strings['Seal'] = "Sello";
|
||||
$strings['Signature1'] = "Firma 1";
|
||||
$strings['Signature2'] = "Firma 2";
|
||||
$strings['Signature3'] = "Firma 3";
|
||||
$strings['Signature4'] = "Firma 4";
|
||||
$strings['SignatureText1'] = "Texto firma 1";
|
||||
$strings['SignatureText2'] = "Texto firma 2";
|
||||
$strings['SignatureText3'] = "Texto firma 3";
|
||||
$strings['SignatureText4'] = "Texto firma 4";
|
||||
$strings['OtherOptions'] = "Otras opciones";
|
||||
$strings['MarginRight'] = "Margen derecho";
|
||||
$strings['MarginLeft'] = "Margen izquierdo";
|
||||
$strings['SetDefaultTemplate'] = "Establecer plantilla por defecto";
|
||||
$strings['MessageDefaultTemplate'] = "Guardar esta personalización por defecto para cursos y
|
||||
sesiones sin certificados definidos";
|
||||
$strings['None'] = "Ninguno";
|
||||
$strings['ErrorTemplateCertificate'] = "No hay una plantilla definida para el certificado.
|
||||
No existe plantilla por defecto.";
|
||||
$strings['DateStartEnd'] = "Con Fecha de inicio y Fecha fin: ";
|
||||
$strings['ExpedictionIn'] = "Expedido en";
|
||||
$strings['Signatures'] = "Firmas";
|
||||
$strings['BackgroundCertificate'] = "Imagen de fondo del certificado";
|
||||
$strings['Background'] = "Fondo";
|
||||
$strings['CertificateSetting'] = "Configuración Certificado";
|
||||
$strings['ToolDisabledCourse'] = "Herramienta desabilitada en el curso";
|
||||
$strings['ToolUseDefaultSettingCourse'] = "Herramienta configurada para usar el certificado por defecto.<br>
|
||||
Podrá editarlo desde la pantalla de Administración -> Plugins -> Certificado personalizado.<br>
|
||||
O si lo desea puede desactivar la opción de usar certificado por defecto en la configuración del
|
||||
plugin en el curso";
|
||||
$strings['CertificateSettingDefault'] = "Configuración del certificado por defecto";
|
||||
$strings['InfoFromDefaultCertificate'] = "El contenido del certificado está basado en el certificado por defecto.
|
||||
Las modificaciones que realice no afectará al certificado por defecto.";
|
||||
$strings['to'] = " a ";
|
||||
$strings['formatDownloadDate'] = " a %s de %s de %s";
|
||||
$strings['MessageUpdate'] = "El proceso de actualización ha terminado";
|
||||
$strings['PrintCertificate'] = "Imprimir certificado";
|
||||
$strings['QuestionDelete'] = "¿Desea eliminar el diploma específico y volver a usar el certificado por defecto?";
|
||||
$strings['SuccessDelete'] = "Borrado con éxito";
|
||||
$strings['ProblemDelete'] = "Hubo un problema al borrar el certificado";
|
||||
$strings['OnlyCustomCertificates'] = "Solo se exportan los diplomas de cursos con certificado personalizado";
|
||||
16
plugin/customcertificate/plugin.php
Normal file
16
plugin/customcertificate/plugin.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This script is a configuration file for the date plugin.
|
||||
* You can use it as a master for other platform plugins (course plugins are slightly different).
|
||||
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins).
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugin details (must be present).
|
||||
*/
|
||||
require_once __DIR__.'/config.php';
|
||||
$plugin_info = CustomCertificatePlugin::create()->get_info();
|
||||
11
plugin/customcertificate/resources/css/certificate.css
Normal file
11
plugin/customcertificate/resources/css/certificate.css
Normal file
@@ -0,0 +1,11 @@
|
||||
body {background-repeat:no-repeat; margin:0; padding: 0;}
|
||||
td { font-family:arial, sans-serif; font-size:18px; }
|
||||
.logo {height: 150px; vertical-align: middle; }
|
||||
.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 {background: #FFFFFF; font-size: 12px; height: 160mm; vertical-align: top;}
|
||||
ol {margin: 0; padding:0;}
|
||||
18
plugin/customcertificate/resources/css/form.css
Normal file
18
plugin/customcertificate/resources/css/form.css
Normal file
@@ -0,0 +1,18 @@
|
||||
.form-control-cert {
|
||||
background-color: #fff;
|
||||
background-image: none;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
|
||||
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 {
|
||||
font-weight: 700;
|
||||
margin: 0 10px 0 10px;
|
||||
}
|
||||
input:disabled { background: #eee; }
|
||||
label { font-size: 13px; }
|
||||
BIN
plugin/customcertificate/resources/img/22/customcertificate.png
Normal file
BIN
plugin/customcertificate/resources/img/22/customcertificate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 843 B |
BIN
plugin/customcertificate/resources/img/64/customcertificate.png
Normal file
BIN
plugin/customcertificate/resources/img/64/customcertificate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
38
plugin/customcertificate/resources/js/certificate.js
Normal file
38
plugin/customcertificate/resources/js/certificate.js
Normal file
@@ -0,0 +1,38 @@
|
||||
function dateCertificateSwitchRadioButton2(){
|
||||
$("#date_start").prop("disabled", true).val("");
|
||||
$("#date_end").prop("disabled", true).val("");
|
||||
}
|
||||
|
||||
function dateCertificateSwitchRadioButton1(){
|
||||
$("#date_start").prop("disabled", false);
|
||||
$("#date_end").prop("disabled", false);
|
||||
}
|
||||
|
||||
function dateCertificateSwitchRadioButton0(){
|
||||
$("#date_start").prop("disabled", true).val("");
|
||||
$("#date_end").prop("disabled", true).val("");
|
||||
}
|
||||
|
||||
function typeDateExpedictionSwitchRadioButton(){
|
||||
$("[name=\"type_date_expediction\"]").each(function( index ) {
|
||||
if ( $(this).is(":checked") && $(this).val() === "2") {
|
||||
$("#day, #month, #year").prop("disabled", false);
|
||||
} else {
|
||||
$("#day, #month, #year").prop("disabled", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function contentsTypeSwitchRadioButton(){
|
||||
$("[name=\"contents_type\"]").each(function( index ) {
|
||||
if ( $(this).is(":checked") && $(this).val() === "2") {
|
||||
$("#contents").prop("disabled", false);
|
||||
} else {
|
||||
$("#contents").prop("disabled", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$( ".datepicker" ).datepicker();
|
||||
});
|
||||
341
plugin/customcertificate/src/CustomCertificatePlugin.php
Normal file
341
plugin/customcertificate/src/CustomCertificatePlugin.php
Normal file
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Plugin class for the CustomCertificate plugin.
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*
|
||||
* @author Jose Angel Ruiz <desarrollo@nosolored.com>
|
||||
*/
|
||||
class CustomCertificatePlugin extends Plugin
|
||||
{
|
||||
public const TABLE_CUSTOMCERTIFICATE = 'plugin_customcertificate';
|
||||
public $isCoursePlugin = true;
|
||||
|
||||
// When creating a new course this settings are added to the course
|
||||
public $course_settings = [
|
||||
[
|
||||
'name' => 'customcertificate_course_enable',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => 'use_certificate_default',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'1.0',
|
||||
'Jose Angel Ruiz - NoSoloRed (original author), Julio Montoya',
|
||||
[
|
||||
'enable_plugin_customcertificate' => 'boolean',
|
||||
]
|
||||
);
|
||||
|
||||
$this->isAdminPlugin = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance the plugin.
|
||||
*
|
||||
* @staticvar null $result
|
||||
*
|
||||
* @return CustomCertificatePlugin
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
static $result = null;
|
||||
|
||||
return $result ? $result : $result = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates the tables required to this plugin.
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
//Installing course settings
|
||||
$this->install_course_fields_in_all_courses();
|
||||
|
||||
$tablesToBeCompared = [self::TABLE_CUSTOMCERTIFICATE];
|
||||
$em = Database::getManager();
|
||||
$cn = $em->getConnection();
|
||||
$sm = $cn->getSchemaManager();
|
||||
$tables = $sm->tablesExist($tablesToBeCompared);
|
||||
|
||||
if ($tables) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once api_get_path(SYS_PLUGIN_PATH).'customcertificate/database.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* This method drops the plugin tables.
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
// Deleting course settings.
|
||||
$this->uninstall_course_fields_in_all_courses();
|
||||
|
||||
$tablesToBeDeleted = [self::TABLE_CUSTOMCERTIFICATE];
|
||||
foreach ($tablesToBeDeleted as $tableToBeDeleted) {
|
||||
$table = Database::get_main_table($tableToBeDeleted);
|
||||
$sql = "DROP TABLE IF EXISTS $table";
|
||||
Database::query($sql);
|
||||
}
|
||||
$this->manageTab(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method update the previous plugin tables.
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$oldCertificateTable = 'gradebook_certificate_alternative';
|
||||
$base = api_get_path(WEB_UPLOAD_PATH);
|
||||
if (Database::num_rows(Database::query("SHOW TABLES LIKE '$oldCertificateTable'")) == 1) {
|
||||
$sql = "SELECT * FROM $oldCertificateTable";
|
||||
$res = Database::query($sql);
|
||||
while ($row = Database::fetch_assoc($res)) {
|
||||
$pathOrigin = $base.'certificates/'.$row['id'].'/';
|
||||
$params = [
|
||||
'access_url_id' => api_get_current_access_url_id(),
|
||||
'c_id' => $row['c_id'],
|
||||
'session_id' => $row['session_id'],
|
||||
'content_course' => $row['content_course'],
|
||||
'contents_type' => intval($row['contents_type']),
|
||||
'contents' => $row['contents'],
|
||||
'date_change' => intval($row['date_change']),
|
||||
'date_start' => $row['date_start'],
|
||||
'date_end' => $row['date_end'],
|
||||
'place' => $row['place'],
|
||||
'type_date_expediction' => intval($row['type_date_expediction']),
|
||||
'day' => $row['day'],
|
||||
'month' => $row['month'],
|
||||
'year' => $row['year'],
|
||||
'logo_left' => $row['logo_left'],
|
||||
'logo_center' => $row['logo_center'],
|
||||
'logo_right' => $row['logo_right'],
|
||||
'seal' => $row['seal'],
|
||||
'signature1' => $row['signature1'],
|
||||
'signature2' => $row['signature2'],
|
||||
'signature3' => $row['signature3'],
|
||||
'signature4' => $row['signature4'],
|
||||
'signature_text1' => $row['signature_text1'],
|
||||
'signature_text2' => $row['signature_text2'],
|
||||
'signature_text3' => $row['signature_text3'],
|
||||
'signature_text4' => $row['signature_text4'],
|
||||
'background' => $row['background'],
|
||||
'margin_left' => intval($row['margin']),
|
||||
'margin_right' => 0,
|
||||
'certificate_default' => 0,
|
||||
];
|
||||
|
||||
$certificateId = Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params);
|
||||
|
||||
// Image manager
|
||||
$pathDestiny = $base.'certificates/'.$certificateId.'/';
|
||||
|
||||
if (!file_exists($pathDestiny)) {
|
||||
mkdir($pathDestiny, api_get_permissions_for_new_directories(), true);
|
||||
}
|
||||
|
||||
$imgList = [
|
||||
'logo_left',
|
||||
'logo_center',
|
||||
'logo_right',
|
||||
'seal',
|
||||
'signature1',
|
||||
'signature2',
|
||||
'signature3',
|
||||
'signature4',
|
||||
'background',
|
||||
];
|
||||
foreach ($imgList as $value) {
|
||||
if (!empty($row[$value])) {
|
||||
copy(
|
||||
$pathOrigin.$row[$value],
|
||||
$pathDestiny.$row[$value]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($row['certificate_default'] == 1) {
|
||||
$params['c_id'] = 0;
|
||||
$params['session_id'] = 0;
|
||||
$params['certificate_default'] = 1;
|
||||
$certificateId = Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params);
|
||||
$pathOrigin = $base.'certificates/default/';
|
||||
$pathDestiny = $base.'certificates/'.$certificateId.'/';
|
||||
foreach ($imgList as $value) {
|
||||
if (!empty($row[$value])) {
|
||||
copy(
|
||||
$pathOrigin.$row[$value],
|
||||
$pathDestiny.$row[$value]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "DROP TABLE IF EXISTS $oldCertificateTable";
|
||||
Database::query($sql);
|
||||
|
||||
echo get_lang('MessageUpdate');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* By default new icon is invisible.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isIconVisibleByDefault()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get certificate data.
|
||||
*
|
||||
* @param int $id The certificate
|
||||
* @param int $userId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCertificateData($id, $userId)
|
||||
{
|
||||
$id = (int) $id;
|
||||
$userId = (int) $userId;
|
||||
|
||||
if (empty($id) || empty($userId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$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
|
||||
INNER JOIN $categoryTable cat
|
||||
ON (cer.cat_id = cat.id AND cer.user_id = $userId)
|
||||
WHERE cer.id = $id";
|
||||
|
||||
$rs = Database::query($sql);
|
||||
if (Database::num_rows($rs) > 0) {
|
||||
$row = Database::fetch_assoc($rs);
|
||||
$courseCode = $row['course_code'];
|
||||
$sessionId = $row['session_id'];
|
||||
$userId = $row['user_id'];
|
||||
if (api_get_course_setting('customcertificate_course_enable', api_get_course_info($courseCode)) == 1) {
|
||||
return [
|
||||
'course_code' => $courseCode,
|
||||
'session_id' => $sessionId,
|
||||
'user_id' => $userId,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it redirects.
|
||||
*
|
||||
* @param certificate $certificate
|
||||
* @param int $certId
|
||||
* @param int $userId
|
||||
*/
|
||||
public static function redirectCheck($certificate, $certId, $userId)
|
||||
{
|
||||
$certId = (int) $certId;
|
||||
$userId = !empty($userId) ? $userId : api_get_user_id();
|
||||
|
||||
if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') === 'true') {
|
||||
$infoCertificate = self::getCertificateData($certId, $userId);
|
||||
if (!empty($infoCertificate)) {
|
||||
if ($certificate->user_id == api_get_user_id() && !empty($certificate->certificate_data)) {
|
||||
$certificateId = $certificate->certificate_data['id'];
|
||||
$extraFieldValue = new ExtraFieldValue('user_certificate');
|
||||
$value = $extraFieldValue->get_values_by_handler_and_field_variable(
|
||||
$certificateId,
|
||||
'downloaded_at'
|
||||
);
|
||||
if (empty($value)) {
|
||||
$params = [
|
||||
'item_id' => $certificate->certificate_data['id'],
|
||||
'extra_downloaded_at' => api_get_utc_datetime(),
|
||||
];
|
||||
$extraFieldValue->saveFieldValues($params);
|
||||
}
|
||||
}
|
||||
|
||||
$url = api_get_path(WEB_PLUGIN_PATH).'customcertificate/src/print_certificate.php'.
|
||||
'?student_id='.$infoCertificate['user_id'].
|
||||
'&course_code='.$infoCertificate['course_code'].
|
||||
'&session_id='.$infoCertificate['session_id'];
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get certificate info.
|
||||
*
|
||||
* @param int $courseId
|
||||
* @param int $sessionId
|
||||
* @param int $accessUrlId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getInfoCertificate($courseId, $sessionId, $accessUrlId)
|
||||
{
|
||||
$courseId = (int) $courseId;
|
||||
$sessionId = (int) $sessionId;
|
||||
$accessUrlId = !empty($accessUrlId) ? (int) $accessUrlId : 1;
|
||||
|
||||
$table = Database::get_main_table(self::TABLE_CUSTOMCERTIFICATE);
|
||||
$sql = "SELECT * FROM $table
|
||||
WHERE
|
||||
c_id = $courseId AND
|
||||
session_id = $sessionId AND
|
||||
access_url_id = $accessUrlId";
|
||||
$result = Database::query($sql);
|
||||
$resultArray = [];
|
||||
if (Database::num_rows($result) > 0) {
|
||||
$resultArray = Database::fetch_array($result);
|
||||
}
|
||||
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default certificate info.
|
||||
*
|
||||
* @param int $accessUrlId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getInfoCertificateDefault($accessUrlId)
|
||||
{
|
||||
$accessUrlId = !empty($accessUrlId) ? (int) $accessUrlId : 1;
|
||||
|
||||
$table = Database::get_main_table(self::TABLE_CUSTOMCERTIFICATE);
|
||||
$sql = "SELECT * FROM $table
|
||||
WHERE certificate_default = 1 AND access_url_id = $accessUrlId";
|
||||
$result = Database::query($sql);
|
||||
$resultArray = [];
|
||||
if (Database::num_rows($result) > 0) {
|
||||
$resultArray = Database::fetch_array($result);
|
||||
}
|
||||
|
||||
return $resultArray;
|
||||
}
|
||||
}
|
||||
51
plugin/customcertificate/src/customcertificate.ajax.php
Normal file
51
plugin/customcertificate/src/customcertificate.ajax.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Responses to AJAX calls.
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
api_block_anonymous_users();
|
||||
|
||||
$plugin = CustomCertificatePlugin::create();
|
||||
$enable = $plugin->get('enable_plugin_customcertificate') == 'true';
|
||||
|
||||
if ($enable === false) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$action = isset($_GET['a']) ? $_GET['a'] : null;
|
||||
|
||||
switch ($action) {
|
||||
case 'delete_certificate':
|
||||
$table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE);
|
||||
$courseId = isset($_POST['courseId']) ? (int) $_POST['courseId'] : 0;
|
||||
$sessionId = isset($_POST['sessionId']) ? (int) $_POST['sessionId'] : 0;
|
||||
$accessUrlId = isset($_POST['accessUrlId']) ? (int) $_POST['accessUrlId'] : 1;
|
||||
|
||||
if (!empty($courseId)) {
|
||||
$sql = "DELETE FROM $table
|
||||
WHERE
|
||||
c_id = $courseId AND
|
||||
session_id = $sessionId AND
|
||||
access_url_id = $accessUrlId";
|
||||
Database::query($sql);
|
||||
echo Display::return_message(
|
||||
get_plugin_lang('SuccessDelete', 'CustomCertificatePlugin'),
|
||||
'success'
|
||||
);
|
||||
} else {
|
||||
echo Display::return_message(
|
||||
get_plugin_lang('ProblemDelete', 'CustomCertificatePlugin'),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
708
plugin/customcertificate/src/export_pdf_all_in_one.php
Normal file
708
plugin/customcertificate/src/export_pdf_all_in_one.php
Normal file
@@ -0,0 +1,708 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CourseBundle\Entity\CLpCategory;
|
||||
|
||||
$course_plugin = 'customcertificate';
|
||||
require_once __DIR__.'/../config.php';
|
||||
|
||||
api_block_anonymous_users();
|
||||
$plugin = CustomCertificatePlugin::create();
|
||||
$enable = $plugin->get('enable_plugin_customcertificate') === 'true';
|
||||
$tblProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
|
||||
$tblCourse = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tblSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
$tblSessionRelAccessUrl = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
|
||||
|
||||
define('NO_DATE_FILTER', 0);
|
||||
define('DATE_BEGIN_FILTER', 1);
|
||||
define('DATE_END_FILTER', 2);
|
||||
define('ALL_DATE_FILTER', 3);
|
||||
|
||||
if (!$enable) {
|
||||
api_not_allowed(true, $plugin->get_lang('ToolDisabled'));
|
||||
}
|
||||
|
||||
$currentLocalTime = api_get_local_time();
|
||||
$accessUrlId = api_get_current_access_url_id();
|
||||
|
||||
$sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : null;
|
||||
$dateBegin = isset($_GET['date_begin']) ? strtotime($_GET['date_begin']) : null;
|
||||
$dateEnd = isset($_GET['date_end']) ? strtotime($_GET['date_end'].' 23:59:59') : null;
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
if ($accessUrlId != -1) {
|
||||
$result = Database::select(
|
||||
'*',
|
||||
"$tblSessionRelAccessUrl",
|
||||
[
|
||||
'where' => [
|
||||
"access_url_id = ? AND session_id = ?" => [$accessUrlId, $sessionId],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
if (empty($result)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$exportAllInOne = isset($_GET['export_pdf']) ? (int) $_GET['export_pdf'] : false;
|
||||
$exportZip = isset($_GET['export_zip']) ? (int) $_GET['export_zip'] : false;
|
||||
|
||||
$filterDate = 0;
|
||||
if (!empty($dateBegin)) {
|
||||
$filterDate += DATE_BEGIN_FILTER;
|
||||
}
|
||||
if (!empty($dateEnd)) {
|
||||
$filterDate += DATE_END_FILTER;
|
||||
}
|
||||
|
||||
$filterCheckList = [];
|
||||
$extraField = new ExtraField('user');
|
||||
$extraFieldsAll = $extraField->get_all(['filter = ?' => 1], 'option_order');
|
||||
foreach ($extraFieldsAll as $field) {
|
||||
if (!empty($_GET['extra_'.$field['variable']])) {
|
||||
$filterCheckList[$field['id']] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::select(
|
||||
'c.id, c.code',
|
||||
"$tblCourse c INNER JOIN $tblSessionRelCourse r ON c.id = r.c_id",
|
||||
[
|
||||
'where' => [
|
||||
"r.session_id = ? " => [$sessionId],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
foreach ($result as $value) {
|
||||
$courseId = $value['id'];
|
||||
$courseCode = $value['code'];
|
||||
|
||||
$cats = Category::load(
|
||||
null,
|
||||
null,
|
||||
$courseCode,
|
||||
null,
|
||||
null,
|
||||
$sessionId,
|
||||
'ORDER BY id'
|
||||
);
|
||||
|
||||
if (empty($cats)) {
|
||||
// first time
|
||||
$cats = Category::load(
|
||||
0,
|
||||
null,
|
||||
$courseCode,
|
||||
null,
|
||||
null,
|
||||
$sessionId,
|
||||
'ORDER BY id'
|
||||
);
|
||||
}
|
||||
|
||||
$selectCat = (int) $cats[0]->get_id();
|
||||
$certificateList = [];
|
||||
$certificateListAux = GradebookUtils::get_list_users_certificates($selectCat);
|
||||
|
||||
foreach ($certificateListAux as $value) {
|
||||
$created_at = strtotime(api_get_local_time($value['created_at']));
|
||||
$value['category_id'] = $selectCat;
|
||||
$value['c_id'] = $courseId;
|
||||
$value['course_code'] = $courseCode;
|
||||
switch ($filterDate) {
|
||||
case NO_DATE_FILTER:
|
||||
$certificateList[] = $value;
|
||||
break;
|
||||
case DATE_BEGIN_FILTER:
|
||||
if ($created_at >= $dateBegin) {
|
||||
$certificateList[] = $value;
|
||||
}
|
||||
break;
|
||||
case DATE_END_FILTER:
|
||||
if ($created_at <= $dateEnd) {
|
||||
$certificateList[] = $value;
|
||||
}
|
||||
break;
|
||||
case ALL_DATE_FILTER:
|
||||
if ($created_at >= $dateBegin && $created_at <= $dateEnd) {
|
||||
$certificateList[] = $value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter extra field
|
||||
foreach ($certificateList as $key => $value) {
|
||||
foreach ($filterCheckList as $fieldId => $field) {
|
||||
$extraFieldValue = new ExtraFieldValue('user');
|
||||
$extraFieldValueData = $extraFieldValue->get_values_by_handler_and_field_id(
|
||||
$value['user_id'],
|
||||
$fieldId
|
||||
);
|
||||
|
||||
if (empty($extraFieldValueData)) {
|
||||
unset($certificateList[$key]);
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($field['field_type']) {
|
||||
case ExtraField::FIELD_TYPE_TEXT:
|
||||
case ExtraField::FIELD_TYPE_ALPHANUMERIC:
|
||||
$pos = stripos($extraFieldValueData['value'], $_GET['extra_'.$field['variable']]);
|
||||
if ($pos === false) {
|
||||
unset($certificateList[$key]);
|
||||
}
|
||||
break;
|
||||
case ExtraField::FIELD_TYPE_RADIO:
|
||||
$valueRadio = $_GET['extra_'.$field['variable']]['extra_'.$field['variable']];
|
||||
if ($extraFieldValueData['value'] != $valueRadio) {
|
||||
unset($certificateList[$key]);
|
||||
}
|
||||
break;
|
||||
case ExtraField::FIELD_TYPE_SELECT:
|
||||
if ($extraFieldValueData['value'] != $_GET['extra_'.$field['variable']]) {
|
||||
unset($certificateList[$key]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$userList = [];
|
||||
foreach ($certificateList as $index => $value) {
|
||||
$infoUser = api_get_user_info($value['user_id']);
|
||||
$infoUser['category_id'] = $value['category_id'];
|
||||
$infoUser['c_id'] = $value['c_id'];
|
||||
$infoUser['course_code'] = $value['course_code'];
|
||||
$userList[] = $infoUser;
|
||||
}
|
||||
|
||||
$sessionInfo = [];
|
||||
if ($sessionId > 0) {
|
||||
$sessionInfo = SessionManager::fetch($sessionId);
|
||||
}
|
||||
|
||||
$path = api_get_path(WEB_UPLOAD_PATH).'certificates/';
|
||||
$htmlList = [];
|
||||
|
||||
foreach ($userList as $userInfo) {
|
||||
$courseId = $userInfo['c_id'];
|
||||
$courseCode = $userInfo['course_code'];
|
||||
$studentId = $userInfo['user_id'];
|
||||
|
||||
$courseInfo = api_get_course_info($courseCode);
|
||||
$allowCustomCertificate = api_get_course_setting('customcertificate_course_enable', $courseInfo);
|
||||
if (!$allowCustomCertificate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get info certificate
|
||||
$infoCertificate = CustomCertificatePlugin::getInfoCertificate($courseId, $sessionId, $accessUrlId);
|
||||
|
||||
if (!is_array($infoCertificate)) {
|
||||
$infoCertificate = [];
|
||||
}
|
||||
|
||||
if (empty($infoCertificate)) {
|
||||
$infoCertificate = CustomCertificatePlugin::getInfoCertificateDefault($accessUrlId);
|
||||
|
||||
if (empty($infoCertificate)) {
|
||||
Display::display_header($plugin->get_lang('PrintCertificate'));
|
||||
echo Display::return_message($plugin->get_lang('ErrorTemplateCertificate'), 'error');
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$workSpace = intval(297 - $infoCertificate['margin_left'] - $infoCertificate['margin_right']);
|
||||
$widthCell = intval($workSpace / 6);
|
||||
|
||||
$htmlText = '';
|
||||
if (!$exportAllInOne) {
|
||||
$htmlText = '<html>';
|
||||
$htmlText .= '
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">';
|
||||
$htmlText .= '
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="'.api_get_path(WEB_CSS_PATH).'document.css">';
|
||||
$htmlText .= '<body>';
|
||||
}
|
||||
$studentId = $userInfo['user_id'];
|
||||
|
||||
if (empty($infoCertificate['background'])) {
|
||||
$htmlText .= '<div class="caraA" style="page-break-before:always; margin:0px; padding:0px;">';
|
||||
} else {
|
||||
$urlBackground = $path.$infoCertificate['background'];
|
||||
$htmlText .= ' <div
|
||||
class="caraA"
|
||||
style="background-image:url('.$urlBackground.') no-repeat;
|
||||
background-image-resize:6; margin:0px; padding:0px;">';
|
||||
}
|
||||
|
||||
if (!empty($infoCertificate['logo_left'])) {
|
||||
$logoLeft = '
|
||||
<img
|
||||
style="max-height: 150px; max-width: '.(2 * $widthCell).'mm;"
|
||||
src="'.$path.$infoCertificate['logo_left'].'" />';
|
||||
} else {
|
||||
$logoLeft = '';
|
||||
}
|
||||
|
||||
$logoCenter = '';
|
||||
if (!empty($infoCertificate['logo_center'])) {
|
||||
$logoCenter = '
|
||||
<img
|
||||
style="max-height: 150px; max-width: '.intval($workSpace - (2 * $widthCell)).'mm;"
|
||||
src="'.$path.$infoCertificate['logo_center'].'" />';
|
||||
}
|
||||
|
||||
$logoRight = '';
|
||||
if (!empty($infoCertificate['logo_right'])) {
|
||||
$logoRight = '
|
||||
<img
|
||||
style="max-height: 150px; max-width: '.(2 * $widthCell).'mm;"
|
||||
src="'.$path.$infoCertificate['logo_right'].'" />';
|
||||
}
|
||||
|
||||
$htmlText .= '<table
|
||||
width="'.$workSpace.'mm"
|
||||
style="
|
||||
margin-left:'.$infoCertificate['margin_left'].'mm;
|
||||
margin-right:'.$infoCertificate['margin_right'].'mm;
|
||||
"
|
||||
border="0">';
|
||||
$htmlText .= '<tr>';
|
||||
$htmlText .= '<td style="width:'.intval($workSpace / 3).'mm" class="logo">'.$logoLeft.'</td>';
|
||||
$htmlText .= '<td style="width:'.intval($workSpace / 3).'mm; text-align:center;" class="logo">';
|
||||
$htmlText .= $logoCenter;
|
||||
$htmlText .= '</td>';
|
||||
$htmlText .= '<td style="width:'.intval($workSpace / 3).'mm; text-align:right;" class="logo">'.$logoRight.'</td>';
|
||||
$htmlText .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
|
||||
$allUserInfo = DocumentManager::get_all_info_to_certificate(
|
||||
$studentId,
|
||||
$courseCode,
|
||||
$sessionId,
|
||||
false
|
||||
);
|
||||
|
||||
$myContentHtml = $infoCertificate['content_course'];
|
||||
$myContentHtml = str_replace(chr(13).chr(10).chr(13).chr(10), chr(13).chr(10), $myContentHtml);
|
||||
$infoToBeReplacedInContentHtml = $allUserInfo[0];
|
||||
$infoToReplaceInContentHtml = $allUserInfo[1];
|
||||
$myContentHtml = str_replace(
|
||||
$infoToBeReplacedInContentHtml,
|
||||
$infoToReplaceInContentHtml,
|
||||
$myContentHtml
|
||||
);
|
||||
|
||||
$startDate = '';
|
||||
$endDate = '';
|
||||
switch ($infoCertificate['date_change']) {
|
||||
case 0:
|
||||
if (!empty($sessionInfo['access_start_date'])) {
|
||||
$startDate = date("d/m/Y", strtotime(api_get_local_time($sessionInfo['access_start_date'])));
|
||||
}
|
||||
if (!empty($sessionInfo['access_end_date'])) {
|
||||
$endDate = date("d/m/Y", strtotime(api_get_local_time($sessionInfo['access_end_date'])));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$startDate = date("d/m/Y", strtotime($infoCertificate['date_start']));
|
||||
$endDate = date("d/m/Y", strtotime($infoCertificate['date_end']));
|
||||
break;
|
||||
}
|
||||
|
||||
$myContentHtml = str_replace(
|
||||
'((start_date))',
|
||||
$startDate,
|
||||
$myContentHtml
|
||||
);
|
||||
|
||||
$myContentHtml = str_replace(
|
||||
'((end_date))',
|
||||
$endDate,
|
||||
$myContentHtml
|
||||
);
|
||||
|
||||
$dateExpediction = '';
|
||||
if ($infoCertificate['type_date_expediction'] != 3) {
|
||||
$dateExpediction .= $plugin->get_lang('ExpedictionIn').' '.$infoCertificate['place'];
|
||||
if ($infoCertificate['type_date_expediction'] == 1) {
|
||||
$dateExpediction .= $plugin->get_lang('to').api_format_date(time(), DATE_FORMAT_LONG);
|
||||
} elseif ($infoCertificate['type_date_expediction'] == 2) {
|
||||
$dateFormat = $plugin->get_lang('formatDownloadDate');
|
||||
if (!empty($infoCertificate['day']) &&
|
||||
!empty($infoCertificate['month']) &&
|
||||
!empty($infoCertificate['year'])
|
||||
) {
|
||||
$dateExpediction .= sprintf(
|
||||
$dateFormat,
|
||||
$infoCertificate['day'],
|
||||
$infoCertificate['month'],
|
||||
$infoCertificate['year']
|
||||
);
|
||||
} else {
|
||||
$dateExpediction .= sprintf(
|
||||
$dateFormat,
|
||||
'......',
|
||||
'....................',
|
||||
'............'
|
||||
);
|
||||
}
|
||||
} elseif ($infoCertificate['type_date_expediction'] == 4) {
|
||||
$dateExpediction .= $plugin->get_lang('to').$infoToReplaceInContentHtml[9]; //date_certificate_no_time
|
||||
} else {
|
||||
if (!empty($sessionInfo)) {
|
||||
$dateInfo = api_get_local_time($sessionInfo['access_end_date']);
|
||||
$dateExpediction .= $plugin->get_lang('to').api_format_date($dateInfo, DATE_FORMAT_LONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$myContentHtml = str_replace(
|
||||
'((date_expediction))',
|
||||
$dateExpediction,
|
||||
$myContentHtml
|
||||
);
|
||||
|
||||
$myContentHtml = strip_tags(
|
||||
$myContentHtml,
|
||||
'<p><b><strong><table><tr><td><th><tbody><span><i><li><ol><ul>
|
||||
<dd><dt><dl><br><hr><img><a><div><h1><h2><h3><h4><h5><h6>'
|
||||
);
|
||||
|
||||
$htmlText .= '<div style="
|
||||
height: 480px;
|
||||
width:'.$workSpace.'mm;
|
||||
margin-left:'.$infoCertificate['margin_left'].'mm;
|
||||
margin-right:'.$infoCertificate['margin_right'].'mm;
|
||||
">';
|
||||
$htmlText .= $myContentHtml;
|
||||
$htmlText .= '</div>';
|
||||
|
||||
$htmlText .= '<table
|
||||
width="'.$workSpace.'mm"
|
||||
style="
|
||||
margin-left:'.$infoCertificate['margin_left'].'mm;
|
||||
margin-right:'.$infoCertificate['margin_right'].'mm;
|
||||
"
|
||||
border="0">';
|
||||
|
||||
$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 .= '</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 .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
$htmlText .= '</div>';
|
||||
|
||||
// Rear certificate
|
||||
if ($infoCertificate['contents_type'] != 3) {
|
||||
$htmlText .= '<div class="caraB" style="page-break-before:always; margin:0px; padding:0px;">';
|
||||
if ($infoCertificate['contents_type'] == 0) {
|
||||
$courseDescription = new CourseDescription();
|
||||
$contentDescription = $courseDescription->get_data_by_description_type(3, $courseId, 0);
|
||||
$domd = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
if (isset($contentDescription['description_content'])) {
|
||||
$domd->loadHTML($contentDescription['description_content']);
|
||||
}
|
||||
libxml_use_internal_errors(false);
|
||||
$domx = new DOMXPath($domd);
|
||||
$items = $domx->query("//li[@style]");
|
||||
foreach ($items as $item) {
|
||||
$item->removeAttribute("style");
|
||||
}
|
||||
|
||||
$items = $domx->query("//span[@style]");
|
||||
foreach ($items as $item) {
|
||||
$item->removeAttribute("style");
|
||||
}
|
||||
|
||||
$output = $domd->saveHTML();
|
||||
$htmlText .= getIndexFiltered($output);
|
||||
}
|
||||
|
||||
if ($infoCertificate['contents_type'] == 1) {
|
||||
$items = [];
|
||||
$categoriesTempList = learnpath::getCategories($courseId);
|
||||
$categoryTest = new CLpCategory();
|
||||
$categoryTest->setId(0);
|
||||
$categoryTest->setName($plugin->get_lang('WithOutCategory'));
|
||||
$categoryTest->setPosition(0);
|
||||
$categories = [$categoryTest];
|
||||
|
||||
if (!empty($categoriesTempList)) {
|
||||
$categories = array_merge($categories, $categoriesTempList);
|
||||
}
|
||||
|
||||
foreach ($categories as $item) {
|
||||
$categoryId = $item->getId();
|
||||
|
||||
if (!learnpath::categoryIsVisibleForStudent($item, api_get_user_entity($studentId))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list = new LearnpathList(
|
||||
$studentId,
|
||||
$courseCode,
|
||||
$sessionId,
|
||||
null,
|
||||
false,
|
||||
$categoryId
|
||||
);
|
||||
|
||||
$flat_list = $list->get_flat_list();
|
||||
|
||||
if (empty($flat_list)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (count($categories) > 1 && count($flat_list) > 0) {
|
||||
if ($item->getName() != $plugin->get_lang('WithOutCategory')) {
|
||||
$items[] = '<h4 style="margin:0">'.$item->getName().'</h4>';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($flat_list as $learnpath) {
|
||||
$lpId = $learnpath['lp_old_id'];
|
||||
$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) {
|
||||
continue;
|
||||
}
|
||||
$lpName = $learnpath['lp_name'];
|
||||
$items[] = $lpName.'<br>';
|
||||
}
|
||||
$items[] = '<br />';
|
||||
}
|
||||
|
||||
if (count($items) > 0) {
|
||||
$htmlText .= '<table width="100%" class="contents-learnpath">';
|
||||
$htmlText .= '<tr>';
|
||||
$htmlText .= '<td>';
|
||||
$i = 0;
|
||||
foreach ($items as $value) {
|
||||
if ($i == 50) {
|
||||
$htmlText .= '</td><td>';
|
||||
}
|
||||
$htmlText .= $value;
|
||||
$i++;
|
||||
}
|
||||
$htmlText .= '</td>';
|
||||
$htmlText .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
}
|
||||
$htmlText .= '</td></table>';
|
||||
}
|
||||
|
||||
if ($infoCertificate['contents_type'] == 2) {
|
||||
$htmlText .= '<table width="100%" class="contents-learnpath">';
|
||||
$htmlText .= '<tr>';
|
||||
$htmlText .= '<td>';
|
||||
$myContentHtml = strip_tags(
|
||||
$infoCertificate['contents'],
|
||||
'<p><b><strong><table><tr><td><th><span><i><li><ol><ul>'.
|
||||
'<dd><dt><dl><br><hr><img><a><div><h1><h2><h3><h4><h5><h6>'
|
||||
);
|
||||
$htmlText .= $myContentHtml;
|
||||
$htmlText .= '</td>';
|
||||
$htmlText .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
}
|
||||
$htmlText .= '</div>';
|
||||
}
|
||||
|
||||
if (!$exportAllInOne) {
|
||||
$htmlText .= '</body></html>';
|
||||
}
|
||||
$fileName = 'certificate_'.$userInfo['course_code'].'_'.$userInfo['complete_name'].'_'.$currentLocalTime;
|
||||
$htmlList[$fileName] = $htmlText;
|
||||
}
|
||||
|
||||
$fileList = [];
|
||||
$archivePath = api_get_path(SYS_ARCHIVE_PATH).'certificates/';
|
||||
if (!is_dir($archivePath)) {
|
||||
mkdir($archivePath, api_get_permissions_for_new_directories());
|
||||
}
|
||||
|
||||
if ($exportAllInOne) {
|
||||
$params = [
|
||||
'pdf_title' => 'Certificate',
|
||||
'pdf_description' => '',
|
||||
'format' => 'A4-L',
|
||||
'orientation' => 'L',
|
||||
'left' => 15,
|
||||
'top' => 15,
|
||||
'bottom' => 0,
|
||||
];
|
||||
$pdf = new PDF($params['format'], $params['orientation'], $params);
|
||||
|
||||
$contentAllCertificate = '';
|
||||
foreach ($htmlList as $fileName => $content) {
|
||||
$contentAllCertificate .= $content;
|
||||
}
|
||||
|
||||
if (!empty($contentAllCertificate)) {
|
||||
$certificateContent = '<html>';
|
||||
$certificateContent .= '
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">';
|
||||
$certificateContent .= '
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="'.api_get_path(WEB_CSS_PATH).'document.css">';
|
||||
$certificateContent .= '<body>';
|
||||
$certificateContent .= $contentAllCertificate;
|
||||
$certificateContent .= '</body></html>';
|
||||
|
||||
$pdf->content_to_pdf(
|
||||
$certificateContent,
|
||||
'',
|
||||
'certificate'.date('Y_m_d_His'),
|
||||
null,
|
||||
'D',
|
||||
false,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
} else {
|
||||
foreach ($htmlList as $fileName => $content) {
|
||||
$fileName = api_replace_dangerous_char($fileName);
|
||||
$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);
|
||||
if ($exportZip) {
|
||||
$filePath = $archivePath.$fileName.'.pdf';
|
||||
$pdf->content_to_pdf($content, '', $fileName, null, 'F', true, $filePath, false, false, false);
|
||||
$fileList[] = $filePath;
|
||||
} else {
|
||||
$pdf->content_to_pdf($content, '', $fileName, null, 'D', false, null, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($fileList)) {
|
||||
$zipFile = $archivePath.'certificates_'.api_get_unique_id().'.zip';
|
||||
$zipFolder = new PclZip($zipFile);
|
||||
foreach ($fileList as $file) {
|
||||
$zipFolder->add($file, PCLZIP_OPT_REMOVE_ALL_PATH);
|
||||
}
|
||||
$name = 'certificates_'.$currentLocalTime.'.zip';
|
||||
DocumentManager::file_send_for_download($zipFile, true, $name);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function getIndexFiltered($index)
|
||||
{
|
||||
$txt = strip_tags($index, "<b><strong><i>");
|
||||
$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++) {
|
||||
if (isset($lines[$x])) {
|
||||
$text1 .= $lines[$x].chr(13).chr(10);
|
||||
}
|
||||
}
|
||||
|
||||
$text2 = '';
|
||||
for ($x = 47; $x < 94; $x++) {
|
||||
if (isset($lines[$x])) {
|
||||
$text2 .= $lines[$x].chr(13).chr(10);
|
||||
}
|
||||
}
|
||||
|
||||
$showLeft = str_replace(chr(13).chr(10), "<br/>", $text1);
|
||||
$showRight = str_replace(chr(13).chr(10), "<br/>", $text2);
|
||||
$result = '<table width="100%">';
|
||||
$result .= '<tr>';
|
||||
$result .= '<td style="width:50%;vertical-align:top;padding-left:15px; font-size:12px;">'.$showLeft.'</td>';
|
||||
$result .= '<td style="vertical-align:top; font-size:12px;">'.$showRight.'</td>';
|
||||
$result .= '<tr>';
|
||||
$result .= '</table>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
978
plugin/customcertificate/src/index.php
Normal file
978
plugin/customcertificate/src/index.php
Normal file
@@ -0,0 +1,978 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$useDefault = false;
|
||||
$isDefault = isset($_GET['default']) ? (int) $_GET['default'] : null;
|
||||
|
||||
if ($isDefault === 1) {
|
||||
$cidReset = true;
|
||||
}
|
||||
|
||||
$course_plugin = 'customcertificate';
|
||||
require_once __DIR__.'/../config.php';
|
||||
|
||||
$_setting['student_view_enabled'] = 'false';
|
||||
|
||||
$userId = api_get_user_id();
|
||||
$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 ($isDefault === 1) {
|
||||
$courseId = 0;
|
||||
$courseCode = '';
|
||||
$sessionId = 0;
|
||||
$enableCourse = false;
|
||||
$useDefault = true;
|
||||
$defaultCertificate = 1;
|
||||
$nameTools = $plugin->get_lang('CertificateSettingDefault');
|
||||
$urlParams = '?default=1';
|
||||
} else {
|
||||
$courseId = api_get_course_int_id();
|
||||
$courseCode = api_get_course_id();
|
||||
$sessionId = api_get_session_id();
|
||||
$enableCourse = api_get_course_setting('customcertificate_course_enable', $course_info) == 1 ? true : false;
|
||||
$useDefault = api_get_course_setting('use_certificate_default', $course_info) == 1 ? true : false;
|
||||
$defaultCertificate = 0;
|
||||
$urlParams = '?'.api_get_cidreq();
|
||||
}
|
||||
|
||||
if (!$enable) {
|
||||
api_not_allowed(true, $plugin->get_lang('ToolDisabled'));
|
||||
}
|
||||
|
||||
if (!$enableCourse && !$useDefault) {
|
||||
api_not_allowed(true, $plugin->get_lang('ToolDisabledCourse'));
|
||||
}
|
||||
|
||||
if ($enableCourse && $useDefault) {
|
||||
api_not_allowed(true, $plugin->get_lang('ToolUseDefaultSettingCourse'));
|
||||
}
|
||||
|
||||
$allow = api_is_platform_admin() || api_is_teacher();
|
||||
if (!$allow) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$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'
|
||||
);
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function () {
|
||||
$("#delete_certificate").click(function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if (confirm("'.$plugin->get_lang("QuestionDelete").'")) {
|
||||
var courseId = '.$courseId.';
|
||||
var sessionId = '.$sessionId.';
|
||||
var accessUrlId = '.$accessUrlId.';
|
||||
var plugin_path = "'.api_get_path(WEB_PLUGIN_PATH).'";
|
||||
var ajax_path = plugin_path + "customcertificate/src/customcertificate.ajax.php?a=delete_certificate";
|
||||
$.ajax({
|
||||
data: {courseId: courseId, sessionId: sessionId, accessUrlId: accessUrlId},
|
||||
url: ajax_path,
|
||||
type: "POST",
|
||||
success: function (response) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>';
|
||||
|
||||
// Get info certificate
|
||||
$infoCertificate = CustomCertificatePlugin::getInfoCertificate($courseId, $sessionId, $accessUrlId);
|
||||
|
||||
$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' => (int) $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' => (int) $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' => (int) $formValues['margin_left'],
|
||||
'margin_right' => (int) $formValues['margin_right'],
|
||||
'certificate_default' => 0,
|
||||
];
|
||||
|
||||
if (intval($formValues['default_certificate'] == 1)) {
|
||||
$params['certificate_default'] = 1;
|
||||
}
|
||||
|
||||
// Insert or Update
|
||||
if ($infoCertificate['id'] > 0) {
|
||||
$certificateId = $infoCertificate['id'];
|
||||
Database::update($table, $params, ['id = ?' => $certificateId]);
|
||||
} else {
|
||||
$certificateId = Database::insert($table, $params);
|
||||
}
|
||||
|
||||
// Image manager
|
||||
$fieldList = [
|
||||
'logo_left',
|
||||
'logo_center',
|
||||
'logo_right',
|
||||
'seal',
|
||||
'signature1',
|
||||
'signature2',
|
||||
'signature3',
|
||||
'signature4',
|
||||
'background',
|
||||
];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Certificate Default
|
||||
if (intval($formValues['use_default'] == 1)) {
|
||||
$infoCertificateDefault = CustomCertificatePlugin::getInfoCertificateDefault($accessUrlId);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Saved')));
|
||||
|
||||
Security::clear_token();
|
||||
header('Location: '.api_get_self().$urlParams);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($infoCertificate)) {
|
||||
$infoCertificate = CustomCertificatePlugin::getInfoCertificateDefault($accessUrlId);
|
||||
|
||||
if (empty($infoCertificate)) {
|
||||
$infoCertificate = [
|
||||
'type_date_expediction' => '',
|
||||
'year' => '',
|
||||
'month' => '',
|
||||
'day' => '',
|
||||
'date_change' => '',
|
||||
];
|
||||
}
|
||||
$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
|
||||
);
|
||||
if (!empty($courseId) && !$useDefault) {
|
||||
$actionsLeft .= Display::url(
|
||||
Display::return_icon('delete.png', $plugin->get_lang('DeleteCertificate'), '', ICON_SIZE_MEDIUM),
|
||||
'delete_certificate.php'.$urlParams,
|
||||
['id' => 'delete_certificate']
|
||||
);
|
||||
}
|
||||
|
||||
echo Display::toolbarAction(
|
||||
'toolbar-document',
|
||||
[$actionsLeft]
|
||||
);
|
||||
|
||||
if ($useDefault && $courseId > 0) {
|
||||
echo Display::return_message(get_lang('InfoFromDefaultCertificate'), 'info');
|
||||
}
|
||||
|
||||
// Student and course section
|
||||
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('StudentCourseInfo')).'</legend>');
|
||||
$form->addHtml('<div class="col-sm-8">');
|
||||
$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('</div>');
|
||||
$form->addHtml('<div class="col-sm-4">');
|
||||
$strInfo = '((user_firstname))<br />';
|
||||
$strInfo .= '((user_lastname))<br />';
|
||||
$strInfo .= '((gradebook_institution))<br />';
|
||||
$strInfo .= '((gradebook_sitename))<br />';
|
||||
$strInfo .= '((teacher_firstname))<br />';
|
||||
$strInfo .= '((teacher_lastname))<br />';
|
||||
$strInfo .= '((official_code))<br />';
|
||||
$strInfo .= '((date_certificate))<br />';
|
||||
$strInfo .= '((date_certificate_no_time))<br />';
|
||||
$strInfo .= '((date_simple_certificate))<br />';
|
||||
$strInfo .= '((course_code))<br />';
|
||||
$strInfo .= '((course_title))<br />';
|
||||
$strInfo .= '((gradebook_grade))<br />';
|
||||
$strInfo .= '((external_style))<br />';
|
||||
$strInfo .= '((start_date))<br />';
|
||||
$strInfo .= '((end_date))<br />';
|
||||
$strInfo .= '((date_expediction))';
|
||||
|
||||
$createCertificate = get_lang('CreateCertificateWithTags');
|
||||
$form->addElement(
|
||||
'html',
|
||||
Display::return_message($createCertificate.': <br />'.$strInfo, 'normal', false)
|
||||
);
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('</fieldset>');
|
||||
$form->addHtml('<div class="clearfix"></div>');
|
||||
|
||||
// Contents section
|
||||
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('Contents')).'</legend>');
|
||||
$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('ContentsHide'),
|
||||
3,
|
||||
['id' => 'contents_type_3', '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('<div id="contents-section">');
|
||||
$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('</div>');
|
||||
|
||||
// Dates section
|
||||
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang("Dates")).'</legend>');
|
||||
|
||||
$group = [];
|
||||
$option1 = &$form->createElement(
|
||||
'radio',
|
||||
'date_change',
|
||||
'',
|
||||
get_lang('UseDateSessionAccess'),
|
||||
0,
|
||||
['id' => 'date_change_0', 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();']
|
||||
);
|
||||
$group[] = $option1;
|
||||
|
||||
$option2 = &$form->createElement(
|
||||
'radio',
|
||||
'date_change',
|
||||
'',
|
||||
get_lang('None'),
|
||||
2,
|
||||
['id' => 'date_change_2', 'onclick' => 'javascript: dateCertificateSwitchRadioButton2();']
|
||||
);
|
||||
$group[] = $option2;
|
||||
|
||||
$option3 = &$form->createElement(
|
||||
'radio',
|
||||
'date_change',
|
||||
'',
|
||||
get_lang('Custom'),
|
||||
1,
|
||||
['id' => 'date_change_1', 'onclick' => 'javascript: dateCertificateSwitchRadioButton1();']
|
||||
);
|
||||
$group[] = $option3;
|
||||
|
||||
$form->addGroup(
|
||||
$group,
|
||||
'date_change',
|
||||
get_lang('CourseDeliveryDates'),
|
||||
null,
|
||||
false
|
||||
);
|
||||
$form->addHtml('<div class="form-group" style="padding-top: 10px;">
|
||||
<label for="date_certificate" class="col-sm-2 control-label"> </label>
|
||||
<div class="col-sm-10">
|
||||
<div class="radio" style="margin-top: -25px;">
|
||||
<span style="margin: 0 10px; font-style: italic;">'.get_lang('From').'</span>
|
||||
<input
|
||||
size="20"
|
||||
autofocus="autofocus"
|
||||
class="form-control-cert text-center datepicker"
|
||||
name="date_start"
|
||||
id="date_start"
|
||||
type="text"
|
||||
value="'.(($infoCertificate['date_change'] == '1')
|
||||
? date("d/m/Y", strtotime($infoCertificate['date_start']))
|
||||
: '').'"
|
||||
'.(($infoCertificate['date_change'] == '') ? 'disabled' : '').'
|
||||
>
|
||||
<span style="margin: 0 10px; font-style: italic;">'.get_lang('Until').'</span>
|
||||
<input
|
||||
size="20"
|
||||
class="form-control-cert text-center datepicker"
|
||||
name="date_end"
|
||||
id="date_end"
|
||||
type="text"
|
||||
value="'.(($infoCertificate['date_change'] == '1')
|
||||
? date("d/m/Y", strtotime($infoCertificate['date_end']))
|
||||
: '').'"
|
||||
'.(($infoCertificate['date_change'] == "0") ? 'disabled' : '').'
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>');
|
||||
|
||||
$form->addText(
|
||||
'place',
|
||||
get_lang('ExpectionPlace'),
|
||||
false,
|
||||
['id' => 'place', 'cols-size' => [2, 5, 5], 'autofocus']
|
||||
);
|
||||
|
||||
$group = [];
|
||||
$option = &$form->createElement(
|
||||
'radio',
|
||||
'type_date_expediction',
|
||||
'',
|
||||
get_lang('UseDateEndAccessSession'),
|
||||
0,
|
||||
[
|
||||
'id' => 'type_date_expediction_0',
|
||||
'onclick' => 'javascript: dateCertificateSwitchRadioButton0();',
|
||||
(($sessionId == 0) ? 'disabled' : ''),
|
||||
]
|
||||
);
|
||||
$group[] = $option;
|
||||
|
||||
$option = &$form->createElement(
|
||||
'radio',
|
||||
'type_date_expediction',
|
||||
'',
|
||||
get_lang('UseDateDownloadCertificate'),
|
||||
1,
|
||||
[
|
||||
'id' => 'type_date_expediction_1',
|
||||
'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
|
||||
]
|
||||
);
|
||||
$group[] = $option;
|
||||
|
||||
$option = &$form->createElement(
|
||||
'radio',
|
||||
'type_date_expediction',
|
||||
'',
|
||||
get_lang('UseDateGenerationCertificate'),
|
||||
4,
|
||||
[
|
||||
'id' => 'type_date_expediction_4',
|
||||
'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
|
||||
]
|
||||
);
|
||||
$group[] = $option;
|
||||
|
||||
$option = &$form->createElement(
|
||||
'radio',
|
||||
'type_date_expediction',
|
||||
'',
|
||||
get_lang('None'),
|
||||
3,
|
||||
[
|
||||
'id' => 'type_date_expediction_3',
|
||||
'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
|
||||
]
|
||||
);
|
||||
$group[] = $option;
|
||||
|
||||
$option = &$form->createElement(
|
||||
'radio',
|
||||
'type_date_expediction',
|
||||
'',
|
||||
get_lang('UseCustomDate'),
|
||||
2,
|
||||
[
|
||||
'id' => 'type_date_expediction_2',
|
||||
'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
|
||||
]
|
||||
);
|
||||
$group[] = $option;
|
||||
|
||||
$form->addGroup(
|
||||
$group,
|
||||
'type_date_expediction',
|
||||
get_lang('DateExpediction'),
|
||||
null,
|
||||
false
|
||||
);
|
||||
|
||||
$form->addHtml(
|
||||
'<div class="form-group" style="padding-top: 10px;">
|
||||
<label for="date_certificate" class="col-sm-2 control-label"> </label>
|
||||
<div class="col-sm-10">
|
||||
<div class="radio" style="margin-top: -25px;">
|
||||
<span class="certificado-text-label">a</span>
|
||||
<input
|
||||
size="4"
|
||||
autofocus="autofocus"
|
||||
class="form-control-cert text-center"
|
||||
name="day"
|
||||
id="day"
|
||||
type="text"
|
||||
value="'.$infoCertificate['day'].'"
|
||||
'.(($infoCertificate['type_date_expediction'] != '2') ? 'disabled' : '').'
|
||||
>
|
||||
<span class="certificado-text-label">de</span>
|
||||
<input
|
||||
size="10"
|
||||
autofocus="autofocus"
|
||||
class="form-control-cert text-center"
|
||||
name="month"
|
||||
id="month"
|
||||
type="text"
|
||||
value="'.$infoCertificate['month'].'"
|
||||
'.(($infoCertificate['type_date_expediction'] != '2') ? 'disabled' : '').'
|
||||
>
|
||||
<span class="certificado-text-label">de</span>
|
||||
<input
|
||||
size="4"
|
||||
autofocus="autofocus"
|
||||
class="form-control-cert text-center"
|
||||
name="year"
|
||||
id="year"
|
||||
type="text"
|
||||
value="'.$infoCertificate['year'].'"
|
||||
'.(($infoCertificate['type_date_expediction'] != '2') ? 'disabled' : '').'
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>'
|
||||
);
|
||||
$form->addHtml('</fieldset>');
|
||||
|
||||
// Signature section
|
||||
$base = api_get_path(WEB_UPLOAD_PATH);
|
||||
$path = $base.'certificates/';
|
||||
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('LogosSeal')).'</legend>');
|
||||
// Logo 1
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['logo_left'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$allowedPictureTypes = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'logo_left',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</div>');
|
||||
// Logo 2
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['logo_center'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$allowedPictureTypes = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'logo_center',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</div><div class="clearfix"></div>');
|
||||
// Logo 3
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['logo_right'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$tblProperty = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'logo_right',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['seal'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$allowedPictureTypes = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'seal',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</div><div class="clearfix"></div>');
|
||||
$form->addHtml('</fieldset>');
|
||||
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('Signatures')).'</legend>');
|
||||
// signature 1
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['signature1'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$allowedPictureTypes = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'signature1',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</div>');
|
||||
// signature 2
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['signature2'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$allowedPictureTypes = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'signature2',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</div><div class="clearfix"></div>');
|
||||
// signature 3
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['signature3'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$allowedPictureTypes = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'signature3',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</div>');
|
||||
// signature 4
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['signature4'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$allowedPictureTypes = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'signature4',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</div><div class="clearfix"></div>');
|
||||
$form->addHtml('</fieldset><br>');
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('BackgroundCertificate')).'</legend>');
|
||||
// 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',
|
||||
'<label class="col-sm-2"> </label>
|
||||
<img src="'.$path.$infoCertificate['background'].'" width="100" />
|
||||
<br><br>'
|
||||
);
|
||||
}
|
||||
$allowedPictureTypes = api_get_supported_image_extensions(false);
|
||||
$form->addRule(
|
||||
'background',
|
||||
get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
|
||||
'filetype',
|
||||
$allowedPictureTypes
|
||||
);
|
||||
$form->addHtml('</fieldset>');
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div class="col-sm-6">');
|
||||
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('OtherOptions')).'</legend>');
|
||||
$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('</fieldset>');
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div class="clearfix"></div>');
|
||||
|
||||
$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 '<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();
|
||||
|
||||
/**
|
||||
* Delete the file if there is only one instance.
|
||||
*
|
||||
* @param int $certificateId
|
||||
* @param string $imagePath
|
||||
* @param string $field
|
||||
* @param string $type
|
||||
*/
|
||||
function checkInstanceImage($certificateId, $imagePath, $field, $type = 'certificates')
|
||||
{
|
||||
$table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE);
|
||||
$imagePath = Database::escape_string($imagePath);
|
||||
$field = Database::escape_string($field);
|
||||
$certificateId = (int) $certificateId;
|
||||
|
||||
$sql = "SELECT * FROM $table WHERE $field = '$imagePath'";
|
||||
$res = Database::query($sql);
|
||||
if (Database::num_rows($res) == 1) {
|
||||
api_remove_uploaded_file($type, $imagePath);
|
||||
}
|
||||
|
||||
$sql = "UPDATE $table SET $field = '' WHERE id = $certificateId";
|
||||
Database::query($sql);
|
||||
}
|
||||
598
plugin/customcertificate/src/print_certificate.php
Normal file
598
plugin/customcertificate/src/print_certificate.php
Normal file
@@ -0,0 +1,598 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CourseBundle\Entity\CLpCategory;
|
||||
|
||||
$default = isset($_GET['default']) ? (int) $_GET['default'] : null;
|
||||
|
||||
if ($default === 1) {
|
||||
$cidReset = true;
|
||||
}
|
||||
|
||||
$course_plugin = 'customcertificate';
|
||||
require_once __DIR__.'/../config.php';
|
||||
|
||||
api_block_anonymous_users();
|
||||
$plugin = CustomCertificatePlugin::create();
|
||||
$enable = $plugin->get('enable_plugin_customcertificate') == 'true';
|
||||
$tblProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
|
||||
$categoryId = isset($_GET['cat_id']) ? (int) $_GET['cat_id'] : 0;
|
||||
|
||||
if (!$enable) {
|
||||
api_not_allowed(true, $plugin->get_lang('ToolDisabled'));
|
||||
}
|
||||
|
||||
if ($default == 1) {
|
||||
$courseId = 0;
|
||||
$courseCode = '';
|
||||
$sessionId = 0;
|
||||
$enableCourse = false;
|
||||
$useDefault = true;
|
||||
} else {
|
||||
$courseId = api_get_course_int_id();
|
||||
$courseCode = api_get_course_id();
|
||||
$sessionId = api_get_session_id();
|
||||
$enableCourse = api_get_course_setting('customcertificate_course_enable') == 1 ? true : false;
|
||||
$useDefault = api_get_course_setting('use_certificate_default') == 1 ? true : false;
|
||||
}
|
||||
|
||||
if (empty($courseCode)) {
|
||||
$courseCode = isset($_REQUEST['course_code']) ? Database::escape_string($_REQUEST['course_code']) : '';
|
||||
$courseInfo = api_get_course_info($courseCode);
|
||||
if (!empty($courseInfo)) {
|
||||
$courseId = $courseInfo['real_id'];
|
||||
}
|
||||
} else {
|
||||
$courseInfo = api_get_course_info($courseCode);
|
||||
}
|
||||
|
||||
if (empty($sessionId)) {
|
||||
$sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0;
|
||||
}
|
||||
|
||||
$accessUrlId = api_get_current_access_url_id();
|
||||
|
||||
$userList = [];
|
||||
$exportZip = false;
|
||||
$exportAllInOne = false;
|
||||
if (empty($_GET['export_all']) && empty($_GET['export_all_in_one'])) {
|
||||
if (!isset($_GET['student_id'])) {
|
||||
$studentId = api_get_user_id();
|
||||
} else {
|
||||
$studentId = intval($_GET['student_id']);
|
||||
}
|
||||
$userList[] = api_get_user_info($studentId);
|
||||
} else {
|
||||
if (!empty($_GET['export_all'])) {
|
||||
$exportZip = true;
|
||||
}
|
||||
if (!empty($_GET['export_all_in_one'])) {
|
||||
$exportAllInOne = true;
|
||||
}
|
||||
$certificate_list = GradebookUtils::get_list_users_certificates($categoryId);
|
||||
foreach ($certificate_list as $index => $value) {
|
||||
$userList[] = api_get_user_info($value['user_id']);
|
||||
}
|
||||
}
|
||||
|
||||
$sessionInfo = [];
|
||||
if ($sessionId > 0) {
|
||||
$sessionInfo = SessionManager::fetch($sessionId);
|
||||
}
|
||||
|
||||
$table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE);
|
||||
$useDefault = false;
|
||||
$path = api_get_path(WEB_UPLOAD_PATH).'certificates/';
|
||||
|
||||
// Get info certificate
|
||||
$infoCertificate = CustomCertificatePlugin::getInfoCertificate($courseId, $sessionId, $accessUrlId);
|
||||
|
||||
if (!is_array($infoCertificate)) {
|
||||
$infoCertificate = [];
|
||||
}
|
||||
|
||||
if (empty($infoCertificate)) {
|
||||
$infoCertificate = CustomCertificatePlugin::getInfoCertificateDefault($accessUrlId);
|
||||
|
||||
if (empty($infoCertificate)) {
|
||||
Display::display_header($plugin->get_lang('PrintCertificate'));
|
||||
echo Display::return_message($plugin->get_lang('ErrorTemplateCertificate'), 'error');
|
||||
Display::display_footer();
|
||||
exit;
|
||||
} else {
|
||||
$useDefault = true;
|
||||
}
|
||||
}
|
||||
|
||||
$workSpace = intval(297 - $infoCertificate['margin_left'] - $infoCertificate['margin_right']);
|
||||
$widthCell = intval($workSpace / 6);
|
||||
$htmlList = [];
|
||||
|
||||
$currentLocalTime = api_get_local_time();
|
||||
|
||||
foreach ($userList as $userInfo) {
|
||||
$htmlText = '';
|
||||
if (!$exportAllInOne) {
|
||||
$htmlText = '<html>';
|
||||
$htmlText .= '
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">';
|
||||
$htmlText .= '
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="'.api_get_path(WEB_CSS_PATH).'document.css">';
|
||||
$htmlText .= '<body>';
|
||||
}
|
||||
$studentId = $userInfo['user_id'];
|
||||
|
||||
if (empty($infoCertificate['background'])) {
|
||||
$htmlText .= '<div class="caraA" style="page-break-before:always; margin:0px; padding:0px;">';
|
||||
} else {
|
||||
$urlBackground = $path.$infoCertificate['background'];
|
||||
$htmlText .= ' <div
|
||||
class="caraA"
|
||||
style="background-image:url('.$urlBackground.') no-repeat;
|
||||
background-image-resize:6; margin:0px; padding:0px;">';
|
||||
}
|
||||
|
||||
if (!empty($infoCertificate['logo_left'])) {
|
||||
$logoLeft = '
|
||||
<img
|
||||
style="max-height: 150px; max-width: '.(2 * $widthCell).'mm;"
|
||||
src="'.$path.$infoCertificate['logo_left'].'" />';
|
||||
} else {
|
||||
$logoLeft = '';
|
||||
}
|
||||
|
||||
$logoCenter = '';
|
||||
if (!empty($infoCertificate['logo_center'])) {
|
||||
$logoCenter = '
|
||||
<img
|
||||
style="max-height: 150px; max-width: '.intval($workSpace - (2 * $widthCell)).'mm;"
|
||||
src="'.$path.$infoCertificate['logo_center'].'" />';
|
||||
}
|
||||
|
||||
$logoRight = '';
|
||||
if (!empty($infoCertificate['logo_right'])) {
|
||||
$logoRight = '
|
||||
<img
|
||||
style="max-height: 150px; max-width: '.(2 * $widthCell).'mm;"
|
||||
src="'.$path.$infoCertificate['logo_right'].'" />';
|
||||
}
|
||||
|
||||
$htmlText .= '<table
|
||||
width="'.$workSpace.'mm"
|
||||
style="
|
||||
margin-left:'.$infoCertificate['margin_left'].'mm;
|
||||
margin-right:'.$infoCertificate['margin_right'].'mm;
|
||||
"
|
||||
border="0">';
|
||||
$htmlText .= '<tr>';
|
||||
$htmlText .= '<td style="width:'.intval($workSpace / 3).'mm" class="logo">'.$logoLeft.'</td>';
|
||||
$htmlText .= '<td style="width:'.intval($workSpace / 3).'mm; text-align:center;" class="logo">';
|
||||
$htmlText .= $logoCenter;
|
||||
$htmlText .= '</td>';
|
||||
$htmlText .= '<td style="width:'.intval($workSpace / 3).'mm; text-align:right;" class="logo">'.$logoRight.'</td>';
|
||||
$htmlText .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
|
||||
$myContentHtml = $infoCertificate['content_course'];
|
||||
$myContentHtml = str_replace(chr(13).chr(10).chr(13).chr(10), chr(13).chr(10), $myContentHtml);
|
||||
|
||||
if (!empty($courseCode)) {
|
||||
$allUserInfo = DocumentManager::get_all_info_to_certificate(
|
||||
$studentId,
|
||||
$courseCode,
|
||||
$sessionId,
|
||||
false
|
||||
);
|
||||
|
||||
$infoToBeReplacedInContentHtml = $allUserInfo[0];
|
||||
$infoToReplaceInContentHtml = $allUserInfo[1];
|
||||
$myContentHtml = str_replace(
|
||||
$infoToBeReplacedInContentHtml,
|
||||
$infoToReplaceInContentHtml,
|
||||
$myContentHtml
|
||||
);
|
||||
}
|
||||
|
||||
$startDate = '';
|
||||
$endDate = '';
|
||||
switch ($infoCertificate['date_change']) {
|
||||
case 0:
|
||||
if (!empty($sessionInfo['access_start_date'])) {
|
||||
$startDate = date("d/m/Y", strtotime(api_get_local_time($sessionInfo['access_start_date'])));
|
||||
}
|
||||
if (!empty($sessionInfo['access_end_date'])) {
|
||||
$endDate = date("d/m/Y", strtotime(api_get_local_time($sessionInfo['access_end_date'])));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$startDate = date("d/m/Y", strtotime($infoCertificate['date_start']));
|
||||
$endDate = date("d/m/Y", strtotime($infoCertificate['date_end']));
|
||||
break;
|
||||
}
|
||||
|
||||
$myContentHtml = str_replace(
|
||||
'((start_date))',
|
||||
$startDate,
|
||||
$myContentHtml
|
||||
);
|
||||
|
||||
$myContentHtml = str_replace(
|
||||
'((end_date))',
|
||||
$endDate,
|
||||
$myContentHtml
|
||||
);
|
||||
|
||||
$dateExpediction = '';
|
||||
if ($infoCertificate['type_date_expediction'] != 3) {
|
||||
$dateExpediction .= $plugin->get_lang('ExpedictionIn').' '.$infoCertificate['place'];
|
||||
if ($infoCertificate['type_date_expediction'] == 1) {
|
||||
$dateExpediction .= $plugin->get_lang('to').api_format_date(time(), DATE_FORMAT_LONG);
|
||||
} elseif ($infoCertificate['type_date_expediction'] == 2) {
|
||||
$dateFormat = $plugin->get_lang('formatDownloadDate');
|
||||
if (!empty($infoCertificate['day']) &&
|
||||
!empty($infoCertificate['month']) &&
|
||||
!empty($infoCertificate['year'])
|
||||
) {
|
||||
$dateExpediction .= sprintf(
|
||||
$dateFormat,
|
||||
$infoCertificate['day'],
|
||||
$infoCertificate['month'],
|
||||
$infoCertificate['year']
|
||||
);
|
||||
} else {
|
||||
$dateExpediction .= sprintf(
|
||||
$dateFormat,
|
||||
'......',
|
||||
'....................',
|
||||
'............'
|
||||
);
|
||||
}
|
||||
} elseif ($infoCertificate['type_date_expediction'] == 4) {
|
||||
$dateExpediction .= $plugin->get_lang('to').$infoToReplaceInContentHtml[9]; //date_certificate_no_time
|
||||
} else {
|
||||
if (!empty($sessionInfo)) {
|
||||
$dateInfo = api_get_local_time($sessionInfo['access_end_date']);
|
||||
$dateExpediction .= $plugin->get_lang('to').api_format_date($dateInfo, DATE_FORMAT_LONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$myContentHtml = str_replace(
|
||||
'((date_expediction))',
|
||||
$dateExpediction,
|
||||
$myContentHtml
|
||||
);
|
||||
|
||||
$myContentHtml = strip_tags(
|
||||
$myContentHtml,
|
||||
'<p><b><strong><table><tr><td><th><tbody><span><i><li><ol><ul>
|
||||
<dd><dt><dl><br><hr><img><a><div><h1><h2><h3><h4><h5><h6>'
|
||||
);
|
||||
|
||||
$htmlText .= '<div style="
|
||||
height: 480px;
|
||||
width:'.$workSpace.'mm;
|
||||
margin-left:'.$infoCertificate['margin_left'].'mm;
|
||||
margin-right:'.$infoCertificate['margin_right'].'mm;
|
||||
">';
|
||||
$htmlText .= $myContentHtml;
|
||||
$htmlText .= '</div>';
|
||||
|
||||
$htmlText .= '<table
|
||||
width="'.$workSpace.'mm"
|
||||
style="
|
||||
margin-left:'.$infoCertificate['margin_left'].'mm;
|
||||
margin-right:'.$infoCertificate['margin_right'].'mm;
|
||||
"
|
||||
border="0">';
|
||||
|
||||
$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 .= '</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 .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
$htmlText .= '</div>';
|
||||
|
||||
// Rear certificate
|
||||
if ($infoCertificate['contents_type'] != 3) {
|
||||
$htmlText .= '<div class="caraB" style="page-break-before:always; margin:0px; padding:0px;">';
|
||||
if ($infoCertificate['contents_type'] == 0) {
|
||||
$courseDescription = new CourseDescription();
|
||||
$contentDescription = $courseDescription->get_data_by_description_type(3, $courseId, 0);
|
||||
$domd = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
if (isset($contentDescription['description_content'])) {
|
||||
$domd->loadHTML($contentDescription['description_content']);
|
||||
}
|
||||
libxml_use_internal_errors(false);
|
||||
$domx = new DOMXPath($domd);
|
||||
$items = $domx->query("//li[@style]");
|
||||
foreach ($items as $item) {
|
||||
$item->removeAttribute("style");
|
||||
}
|
||||
|
||||
$items = $domx->query("//span[@style]");
|
||||
foreach ($items as $item) {
|
||||
$item->removeAttribute("style");
|
||||
}
|
||||
|
||||
$output = $domd->saveHTML();
|
||||
$htmlText .= getIndexFiltered($output);
|
||||
}
|
||||
|
||||
if ($infoCertificate['contents_type'] == 1) {
|
||||
$items = [];
|
||||
$categoriesTempList = learnpath::getCategories($courseId);
|
||||
$categoryTest = new CLpCategory();
|
||||
$categoryTest->setId(0);
|
||||
$categoryTest->setName($plugin->get_lang('WithOutCategory'));
|
||||
$categoryTest->setPosition(0);
|
||||
$categories = [$categoryTest];
|
||||
|
||||
if (!empty($categoriesTempList)) {
|
||||
$categories = array_merge($categories, $categoriesTempList);
|
||||
}
|
||||
|
||||
foreach ($categories as $item) {
|
||||
$categoryId = $item->getId();
|
||||
|
||||
if (!learnpath::categoryIsVisibleForStudent($item, api_get_user_entity($studentId))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list = new LearnpathList(
|
||||
$studentId,
|
||||
$courseInfo,
|
||||
$sessionId,
|
||||
null,
|
||||
false,
|
||||
$categoryId
|
||||
);
|
||||
|
||||
$flat_list = $list->get_flat_list();
|
||||
|
||||
if (empty($flat_list)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (count($categories) > 1 && count($flat_list) > 0) {
|
||||
if ($item->getName() != $plugin->get_lang('WithOutCategory')) {
|
||||
$items[] = '<h4 style="margin:0">'.$item->getName().'</h4>';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($flat_list as $learnpath) {
|
||||
$lpId = $learnpath['lp_old_id'];
|
||||
$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) {
|
||||
continue;
|
||||
}
|
||||
$lpName = $learnpath['lp_name'];
|
||||
$items[] = $lpName.'<br>';
|
||||
}
|
||||
$items[] = '<br>';
|
||||
}
|
||||
|
||||
if (count($items) > 0) {
|
||||
$htmlText .= '<table width="100%" class="contents-learnpath">';
|
||||
$htmlText .= '<tr>';
|
||||
$htmlText .= '<td>';
|
||||
$i = 0;
|
||||
foreach ($items as $value) {
|
||||
if ($i == 50) {
|
||||
$htmlText .= '</td><td>';
|
||||
}
|
||||
$htmlText .= $value;
|
||||
$i++;
|
||||
}
|
||||
$htmlText .= '</td>';
|
||||
$htmlText .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
}
|
||||
$htmlText .= '</td></table>';
|
||||
}
|
||||
|
||||
if ($infoCertificate['contents_type'] == 2) {
|
||||
$htmlText .= '<table width="100%" class="contents-learnpath">';
|
||||
$htmlText .= '<tr>';
|
||||
$htmlText .= '<td>';
|
||||
$myContentHtml = strip_tags(
|
||||
$infoCertificate['contents'],
|
||||
'<p><b><strong><table><tr><td><th><span><i><li><ol><ul>'.
|
||||
'<dd><dt><dl><br><hr><img><a><div><h1><h2><h3><h4><h5><h6>'
|
||||
);
|
||||
$htmlText .= $myContentHtml;
|
||||
$htmlText .= '</td>';
|
||||
$htmlText .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
}
|
||||
$htmlText .= '</div>';
|
||||
}
|
||||
|
||||
if (!$exportAllInOne) {
|
||||
$htmlText .= '</body></html>';
|
||||
}
|
||||
$fileName = 'certificate_'.$courseInfo['code'].'_'.$userInfo['complete_name'].'_'.$currentLocalTime;
|
||||
$htmlList[$fileName] = $htmlText;
|
||||
}
|
||||
|
||||
$fileList = [];
|
||||
$archivePath = api_get_path(SYS_ARCHIVE_PATH).'certificates/';
|
||||
if (!is_dir($archivePath)) {
|
||||
mkdir($archivePath, api_get_permissions_for_new_directories());
|
||||
}
|
||||
|
||||
if ($exportAllInOne) {
|
||||
$params = [
|
||||
'pdf_title' => 'Certificate',
|
||||
'pdf_description' => '',
|
||||
'format' => 'A4-L',
|
||||
'orientation' => 'L',
|
||||
'left' => 15,
|
||||
'top' => 15,
|
||||
'bottom' => 0,
|
||||
];
|
||||
$pdf = new PDF($params['format'], $params['orientation'], $params);
|
||||
|
||||
$contentAllCertificate = '';
|
||||
foreach ($htmlList as $fileName => $content) {
|
||||
$contentAllCertificate .= $content;
|
||||
}
|
||||
|
||||
if (!empty($contentAllCertificate)) {
|
||||
$certificateContent = '<html>';
|
||||
$certificateContent .= '
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">';
|
||||
$certificateContent .= '
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="'.api_get_path(WEB_CSS_PATH).'document.css">';
|
||||
$certificateContent .= '<body>';
|
||||
$certificateContent .= $contentAllCertificate;
|
||||
$certificateContent .= '</body></html>';
|
||||
|
||||
$pdf->content_to_pdf(
|
||||
$certificateContent,
|
||||
'',
|
||||
'certificate'.date("Y_m_d_His"),
|
||||
null,
|
||||
'D',
|
||||
false,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
} else {
|
||||
foreach ($htmlList as $fileName => $content) {
|
||||
$fileName = api_replace_dangerous_char($fileName);
|
||||
$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);
|
||||
if ($exportZip) {
|
||||
$filePath = $archivePath.$fileName.'.pdf';
|
||||
$pdf->content_to_pdf($content, '', $fileName, null, 'F', true, $filePath, false, false, false);
|
||||
$fileList[] = $filePath;
|
||||
} else {
|
||||
$pdf->content_to_pdf($content, '', $fileName, null, 'D', false, null, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($fileList)) {
|
||||
$zipFile = $archivePath.'certificates_'.api_get_unique_id().'.zip';
|
||||
$zipFolder = new PclZip($zipFile);
|
||||
foreach ($fileList as $file) {
|
||||
$zipFolder->add($file, PCLZIP_OPT_REMOVE_ALL_PATH);
|
||||
}
|
||||
$name = 'certificates_'.$courseInfo['code'].'_'.$currentLocalTime.'.zip';
|
||||
DocumentManager::file_send_for_download($zipFile, true, $name);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function getIndexFiltered($index)
|
||||
{
|
||||
$txt = strip_tags($index, "<b><strong><i>");
|
||||
$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++) {
|
||||
if (isset($lines[$x])) {
|
||||
$text1 .= $lines[$x].chr(13).chr(10);
|
||||
}
|
||||
}
|
||||
|
||||
$text2 = '';
|
||||
for ($x = 47; $x < 94; $x++) {
|
||||
if (isset($lines[$x])) {
|
||||
$text2 .= $lines[$x].chr(13).chr(10);
|
||||
}
|
||||
}
|
||||
|
||||
$showLeft = str_replace(chr(13).chr(10), "<br/>", $text1);
|
||||
$showRight = str_replace(chr(13).chr(10), "<br/>", $text2);
|
||||
$result = '<table width="100%">';
|
||||
$result .= '<tr>';
|
||||
$result .= '<td style="width:50%;vertical-align:top;padding-left:15px; font-size:12px;">'.$showLeft.'</td>';
|
||||
$result .= '<td style="vertical-align:top; font-size:12px;">'.$showRight.'</td>';
|
||||
$result .= '<tr>';
|
||||
$result .= '</table>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
34
plugin/customcertificate/start.php
Normal file
34
plugin/customcertificate/start.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* This script initiates a customcertificate plugin.
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*/
|
||||
$course_plugin = 'customcertificate';
|
||||
require_once __DIR__.'/config.php';
|
||||
|
||||
$plugin = CustomCertificatePlugin::create();
|
||||
$enable = $plugin->get('enable_plugin_customcertificate') == 'true';
|
||||
|
||||
if ($enable) {
|
||||
if (api_is_platform_admin() || api_is_teacher()) {
|
||||
$url = 'src/index.php?';
|
||||
$url .= (isset($_GET['cidReq']) ? api_get_cidreq() : 'default=1');
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
} else {
|
||||
$session = api_get_session_entity(api_get_session_id());
|
||||
$_course = api_get_course_info();
|
||||
$webCoursePath = api_get_path(WEB_COURSE_PATH);
|
||||
$url = $webCoursePath.$_course['path'].'/index.php'.($session ? '?id_session='.$session->getId() : '');
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('OnlyAdminPlatform'))
|
||||
);
|
||||
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
api_not_allowed(true, $plugin->get_lang('ToolDisabled'));
|
||||
}
|
||||
12
plugin/customcertificate/uninstall.php
Normal file
12
plugin/customcertificate/uninstall.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This script is included by main/admin/settings.lib.php when unselecting a plugin
|
||||
* and is meant to remove things installed by the install.php script in both
|
||||
* the global database and the courses tables.
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*/
|
||||
require_once __DIR__.'/config.php';
|
||||
CustomCertificatePlugin::create()->uninstall();
|
||||
14
plugin/customcertificate/update.php
Normal file
14
plugin/customcertificate/update.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* This script is meant to update previous version the plugin.
|
||||
*
|
||||
* @package chamilo.plugin.customcertificate
|
||||
*/
|
||||
require_once __DIR__.'/config.php';
|
||||
|
||||
if (!api_is_platform_admin()) {
|
||||
exit('You must have admin permissions to install plugins');
|
||||
}
|
||||
|
||||
CustomCertificatePlugin::create()->update();
|
||||
Reference in New Issue
Block a user