|
|
|
@ -16,6 +16,7 @@ api_block_anonymous_users(); |
|
|
|
$plugin = CustomCertificatePlugin::create(); |
|
|
|
$plugin = CustomCertificatePlugin::create(); |
|
|
|
$enable = $plugin->get('enable_plugin_customcertificate') == 'true'; |
|
|
|
$enable = $plugin->get('enable_plugin_customcertificate') == 'true'; |
|
|
|
$tblProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
|
|
$tblProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
|
|
|
|
|
|
$categoryId = isset($_GET['cat_id']) ? (int) $_GET['cat_id'] : 0; |
|
|
|
|
|
|
|
|
|
|
|
if (!$enable) { |
|
|
|
if (!$enable) { |
|
|
|
api_not_allowed(true, $plugin->get_lang('ToolDisabled')); |
|
|
|
api_not_allowed(true, $plugin->get_lang('ToolDisabled')); |
|
|
|
@ -52,7 +53,9 @@ if (empty($sessionId)) { |
|
|
|
$accessUrlId = api_get_current_access_url_id(); |
|
|
|
$accessUrlId = api_get_current_access_url_id(); |
|
|
|
|
|
|
|
|
|
|
|
$userList = []; |
|
|
|
$userList = []; |
|
|
|
if (empty($_GET['export_all'])) { |
|
|
|
$exportZip = false; |
|
|
|
|
|
|
|
$exportAllInOne = false; |
|
|
|
|
|
|
|
if (empty($_GET['export_all']) && empty($_GET['export_all_in_one'])) { |
|
|
|
if (!isset($_GET['student_id'])) { |
|
|
|
if (!isset($_GET['student_id'])) { |
|
|
|
$studentId = api_get_user_id(); |
|
|
|
$studentId = api_get_user_id(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -60,16 +63,15 @@ if (empty($_GET['export_all'])) { |
|
|
|
} |
|
|
|
} |
|
|
|
$userList[] = api_get_user_info($studentId); |
|
|
|
$userList[] = api_get_user_info($studentId); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); |
|
|
|
if (!empty($_GET['export_all'])) { |
|
|
|
$categoryTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); |
|
|
|
$exportZip = true; |
|
|
|
$sql = "SELECT cer.user_id AS user_id |
|
|
|
} |
|
|
|
FROM $certificateTable cer |
|
|
|
if (!empty($_GET['export_all_in_one'])) { |
|
|
|
INNER JOIN $categoryTable cat |
|
|
|
$exportAllInOne = true; |
|
|
|
ON (cer.cat_id = cat.id) |
|
|
|
} |
|
|
|
WHERE cat.course_code = '$courseCode' AND cat.session_id = $sessionId"; |
|
|
|
$certificate_list = GradebookUtils::get_list_users_certificates($categoryId); |
|
|
|
$rs = Database::query($sql); |
|
|
|
foreach ($certificate_list as $index => $value) { |
|
|
|
while ($row = Database::fetch_assoc($rs)) { |
|
|
|
$userList[] = api_get_user_info($value['user_id']); |
|
|
|
$userList[] = api_get_user_info($row['user_id']); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -80,7 +82,7 @@ if ($sessionId > 0) { |
|
|
|
|
|
|
|
|
|
|
|
$table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE); |
|
|
|
$table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE); |
|
|
|
$useDefault = false; |
|
|
|
$useDefault = false; |
|
|
|
$path = api_get_path(SYS_UPLOAD_PATH).'certificates/'; |
|
|
|
$path = api_get_path(WEB_UPLOAD_PATH).'certificates/'; |
|
|
|
|
|
|
|
|
|
|
|
// Get info certificate |
|
|
|
// Get info certificate |
|
|
|
$infoCertificate = CustomCertificatePlugin::getInfoCertificate($courseId, $sessionId, $accessUrlId); |
|
|
|
$infoCertificate = CustomCertificatePlugin::getInfoCertificate($courseId, $sessionId, $accessUrlId); |
|
|
|
@ -109,16 +111,19 @@ $htmlList = []; |
|
|
|
$currentLocalTime = api_get_local_time(); |
|
|
|
$currentLocalTime = api_get_local_time(); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($userList as $userInfo) { |
|
|
|
foreach ($userList as $userInfo) { |
|
|
|
$htmlText = '<html>'; |
|
|
|
$htmlText = ''; |
|
|
|
$htmlText .= ' |
|
|
|
if (!$exportAllInOne) { |
|
|
|
<link rel="stylesheet" |
|
|
|
$htmlText = '<html>'; |
|
|
|
type="text/css" |
|
|
|
$htmlText .= ' |
|
|
|
href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">'; |
|
|
|
<link rel="stylesheet" |
|
|
|
$htmlText .= ' |
|
|
|
type="text/css" |
|
|
|
<link rel="stylesheet" |
|
|
|
href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">'; |
|
|
|
type="text/css" |
|
|
|
$htmlText .= ' |
|
|
|
href="'.api_get_path(WEB_CSS_PATH).'document.css">'; |
|
|
|
<link rel="stylesheet" |
|
|
|
$htmlText .= '<body>'; |
|
|
|
type="text/css" |
|
|
|
|
|
|
|
href="'.api_get_path(WEB_CSS_PATH).'document.css">'; |
|
|
|
|
|
|
|
$htmlText .= '<body>'; |
|
|
|
|
|
|
|
} |
|
|
|
$studentId = $userInfo['user_id']; |
|
|
|
$studentId = $userInfo['user_id']; |
|
|
|
|
|
|
|
|
|
|
|
if (empty($infoCertificate['background'])) { |
|
|
|
if (empty($infoCertificate['background'])) { |
|
|
|
@ -126,8 +131,9 @@ foreach ($userList as $userInfo) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$urlBackground = $path.$infoCertificate['background']; |
|
|
|
$urlBackground = $path.$infoCertificate['background']; |
|
|
|
$htmlText .= ' <div |
|
|
|
$htmlText .= ' <div |
|
|
|
class = "caraA" |
|
|
|
class="caraA" |
|
|
|
style = "background-image:url('.$urlBackground.') no-repeat; background-image-resize:6; margin:0px; padding:0px;">'; |
|
|
|
style="background-image:url('.$urlBackground.') no-repeat; |
|
|
|
|
|
|
|
background-image-resize:6; margin:0px; padding:0px;">'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($infoCertificate['logo_left'])) { |
|
|
|
if (!empty($infoCertificate['logo_left'])) { |
|
|
|
@ -164,7 +170,9 @@ foreach ($userList as $userInfo) { |
|
|
|
border="0">'; |
|
|
|
border="0">'; |
|
|
|
$htmlText .= '<tr>'; |
|
|
|
$htmlText .= '<tr>'; |
|
|
|
$htmlText .= '<td style="width:'.intval($workSpace / 3).'mm" class="logo">'.$logoLeft.'</td>'; |
|
|
|
$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">'.$logoCenter.'</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 .= '<td style="width:'.intval($workSpace / 3).'mm; text-align:right;" class="logo">'.$logoRight.'</td>'; |
|
|
|
$htmlText .= '</tr>'; |
|
|
|
$htmlText .= '</tr>'; |
|
|
|
$htmlText .= '</table>'; |
|
|
|
$htmlText .= '</table>'; |
|
|
|
@ -461,7 +469,10 @@ foreach ($userList as $userInfo) { |
|
|
|
} |
|
|
|
} |
|
|
|
$htmlText .= '</div>'; |
|
|
|
$htmlText .= '</div>'; |
|
|
|
} |
|
|
|
} |
|
|
|
$htmlText .= '</body></html>'; |
|
|
|
|
|
|
|
|
|
|
|
if (!$exportAllInOne) { |
|
|
|
|
|
|
|
$htmlText .= '</body></html>'; |
|
|
|
|
|
|
|
} |
|
|
|
$fileName = 'certificate_'.$courseInfo['code'].'_'.$userInfo['complete_name'].'_'.$currentLocalTime; |
|
|
|
$fileName = 'certificate_'.$courseInfo['code'].'_'.$userInfo['complete_name'].'_'.$currentLocalTime; |
|
|
|
$htmlList[$fileName] = $htmlText; |
|
|
|
$htmlList[$fileName] = $htmlText; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -472,10 +483,8 @@ if (!is_dir($archivePath)) { |
|
|
|
mkdir($archivePath, api_get_permissions_for_new_directories()); |
|
|
|
mkdir($archivePath, api_get_permissions_for_new_directories()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach ($htmlList as $fileName => $content) { |
|
|
|
if ($exportAllInOne) { |
|
|
|
$fileName = api_replace_dangerous_char($fileName); |
|
|
|
|
|
|
|
$params = [ |
|
|
|
$params = [ |
|
|
|
'filename' => $fileName, |
|
|
|
|
|
|
|
'pdf_title' => 'Certificate', |
|
|
|
'pdf_title' => 'Certificate', |
|
|
|
'pdf_description' => '', |
|
|
|
'pdf_description' => '', |
|
|
|
'format' => 'A4-L', |
|
|
|
'format' => 'A4-L', |
|
|
|
@ -485,25 +494,72 @@ foreach ($htmlList as $fileName => $content) { |
|
|
|
'bottom' => 0, |
|
|
|
'bottom' => 0, |
|
|
|
]; |
|
|
|
]; |
|
|
|
$pdf = new PDF($params['format'], $params['orientation'], $params); |
|
|
|
$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); |
|
|
|
$contentAllCertificate = ''; |
|
|
|
exit; |
|
|
|
foreach ($htmlList as $fileName => $content) { |
|
|
|
} else { |
|
|
|
$contentAllCertificate .= $content; |
|
|
|
$filePath = $archivePath.$fileName.'.pdf'; |
|
|
|
|
|
|
|
$pdf->content_to_pdf($content, '', $fileName, null, 'F', true, $filePath, false, false, false); |
|
|
|
|
|
|
|
$fileList[] = $filePath; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($fileList)) { |
|
|
|
if (!empty($contentAllCertificate)) { |
|
|
|
$zipFile = $archivePath.'certificates_'.api_get_unique_id().'.zip'; |
|
|
|
$certificateContent = '<html>'; |
|
|
|
$zipFolder = new PclZip($zipFile); |
|
|
|
$certificateContent .= ' |
|
|
|
foreach ($fileList as $file) { |
|
|
|
<link rel="stylesheet" |
|
|
|
$zipFolder->add($file, PCLZIP_OPT_REMOVE_ALL_PATH); |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
$name = 'certificates_'.$courseInfo['code'].'_'.$currentLocalTime.'.zip'; |
|
|
|
|
|
|
|
DocumentManager::file_send_for_download($zipFile, true, $name); |
|
|
|
|
|
|
|
exit; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getIndexFiltered($index) |
|
|
|
function getIndexFiltered($index) |
|
|
|
|