This commit is contained in:
Xes
2025-08-14 22:39:38 +02:00
parent 3641e93527
commit 5403f346e3
3370 changed files with 327179 additions and 0 deletions

View File

@@ -0,0 +1,332 @@
<?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->setCourseToolDefaultVisibility(false);
$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');
}
}
/**
* 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;
}
}

View 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;
}

View 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;
}

View 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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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);
}

View 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;
}