get('enable_plugin_customcertificate') == 'true'; $tblProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); 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'] : ''; } $accessUrlId = api_get_current_access_url_id(); $userList = []; if (empty($_GET['export_all'])) { if (!isset($_GET['student_id'])) { $studentId = api_get_user_id(); } else { $studentId = intval($_GET['student_id']); } $userList[] = api_get_user_info($studentId); } else { $certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $categoryTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $sql = "SELECT cer.user_id AS user_id FROM $certificateTable cer INNER JOIN $categoryTable cat ON (cer.cat_id = cat.id) WHERE cat.course_code = '$courseCode' AND cat.session_id = $sessionId"; $rs = Database::query($sql); while ($row = Database::fetch_assoc($rs)) { $userList[] = api_get_user_info($row['user_id']); } } $sessionInfo = []; if ($sessionId > 0) { $sessionInfo = SessionManager::fetch($sessionId); } $table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE); $useDefault = false; $path = api_get_path(SYS_UPLOAD_PATH).'certificates/'; // Get info certificate $infoCertificate = Database::select( '*', $table, ['where' => ['access_url_id = ? AND c_id = ? AND session_id = ?' => [$accessUrlId, $courseId, $sessionId]]], 'first' ); if (!is_array($infoCertificate)) { $infoCertificate = []; } if (empty($infoCertificate)) { $infoCertificate = Database::select( '*', Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE), ['where' => ['access_url_id = ? AND certificate_default = ? ' => [$accessUrlId, 1]]], 'first' ); if (!is_array($infoCertificate)) { $infoCertificate = []; } 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 = ''; $htmlText .= ' '; $htmlText .= ' '; $htmlText .= '
'; $studentId = $userInfo['user_id']; if (empty($infoCertificate['background'])) { $htmlText .= '| '.$logoLeft.' | '; $htmlText .= ''.$logoCenter.' | '; $htmlText .= ''.$logoRight.' | '; $htmlText .= '
';
}
if ($infoCertificate['contents_type'] == 2) {
$htmlText .= '';
$htmlText .= '
';
$htmlText .= ' ';
$myContentHtml = strip_tags(
$infoCertificate['contents'],
'
';
}
$htmlText .= '';
}
$htmlText .= '';
$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());
}
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 (count($htmlList) == 1) {
$pdf->content_to_pdf($content, '', $fileName, null, 'D', false, null, false, false, false);
exit;
} else {
$filePath = $archivePath.$fileName.'.pdf';
$pdf->content_to_pdf($content, '', $fileName, null, 'F', true, $filePath, false, false, false);
$fileList[] = $filePath;
}
}
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, "");
$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), " ';
$htmlText .= '
", $text1);
$showRight = str_replace(chr(13).chr(10), "
", $text2);
$result = '';
$result .= '
';
return $result;
}
';
$result .= ' '.$showLeft.' ';
$result .= ''.$showRight.' ';
$result .= '';
$result .= '