1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | use Chamilo\CourseBundle\Entity\CLpCategory; |
||
6 | |||
7 | $course_plugin = 'customcertificate'; |
||
8 | require_once __DIR__.'/../config.php'; |
||
9 | |||
10 | api_block_anonymous_users(); |
||
11 | $plugin = CustomCertificatePlugin::create(); |
||
12 | $enable = $plugin->get('enable_plugin_customcertificate') === 'true'; |
||
13 | $tblProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||
14 | $tblCourse = Database::get_main_table(TABLE_MAIN_COURSE); |
||
15 | $tblSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
||
16 | $tblSessionRelAccessUrl = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
||
17 | |||
18 | define('NO_DATE_FILTER', 0); |
||
19 | define('DATE_BEGIN_FILTER', 1); |
||
20 | define('DATE_END_FILTER', 2); |
||
21 | define('ALL_DATE_FILTER', 3); |
||
22 | |||
23 | if (!$enable) { |
||
24 | api_not_allowed(true, $plugin->get_lang('ToolDisabled')); |
||
25 | } |
||
26 | |||
27 | $currentLocalTime = api_get_local_time(); |
||
28 | $accessUrlId = api_get_current_access_url_id(); |
||
29 | |||
30 | $sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : null; |
||
31 | $dateBegin = isset($_GET['date_begin']) ? strtotime($_GET['date_begin']) : null; |
||
32 | $dateEnd = isset($_GET['date_end']) ? strtotime($_GET['date_end'].' 23:59:59') : null; |
||
33 | |||
34 | if (api_is_multiple_url_enabled()) { |
||
35 | if ($accessUrlId != -1) { |
||
36 | $result = Database::select( |
||
37 | '*', |
||
38 | "$tblSessionRelAccessUrl", |
||
39 | [ |
||
40 | 'where' => [ |
||
41 | "access_url_id = ? AND session_id = ?" => [$accessUrlId, $sessionId], |
||
42 | ], |
||
43 | ] |
||
44 | ); |
||
45 | |||
46 | if (empty($result)) { |
||
47 | api_not_allowed(); |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | |||
52 | $exportAllInOne = isset($_GET['export_pdf']) ? (int) $_GET['export_pdf'] : false; |
||
53 | $exportZip = isset($_GET['export_zip']) ? (int) $_GET['export_zip'] : false; |
||
54 | |||
55 | $filterDate = 0; |
||
56 | if (!empty($dateBegin)) { |
||
57 | $filterDate += DATE_BEGIN_FILTER; |
||
58 | } |
||
59 | if (!empty($dateEnd)) { |
||
60 | $filterDate += DATE_END_FILTER; |
||
61 | } |
||
62 | |||
63 | $filterCheckList = []; |
||
64 | $extraField = new ExtraField('user'); |
||
65 | $extraFieldsAll = $extraField->get_all(['filter = ?' => 1], 'option_order'); |
||
66 | foreach ($extraFieldsAll as $field) { |
||
67 | if (!empty($_GET['extra_'.$field['variable']])) { |
||
68 | $filterCheckList[$field['id']] = $field; |
||
69 | } |
||
70 | } |
||
71 | |||
72 | $result = Database::select( |
||
73 | 'c.id, c.code', |
||
74 | "$tblCourse c INNER JOIN $tblSessionRelCourse r ON c.id = r.c_id", |
||
75 | [ |
||
76 | 'where' => [ |
||
77 | "r.session_id = ? " => [$sessionId], |
||
78 | ], |
||
79 | ] |
||
80 | ); |
||
81 | |||
82 | foreach ($result as $value) { |
||
83 | $courseId = $value['id']; |
||
84 | $courseCode = $value['code']; |
||
85 | |||
86 | $cats = Category::load( |
||
87 | null, |
||
88 | null, |
||
89 | $courseCode, |
||
90 | null, |
||
91 | null, |
||
92 | $sessionId, |
||
93 | 'ORDER BY id' |
||
94 | ); |
||
95 | |||
96 | if (empty($cats)) { |
||
97 | // first time |
||
98 | $cats = Category::load( |
||
99 | 0, |
||
100 | null, |
||
101 | $courseCode, |
||
102 | null, |
||
103 | null, |
||
104 | $sessionId, |
||
105 | 'ORDER BY id' |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | $selectCat = (int) $cats[0]->get_id(); |
||
110 | $certificateList = []; |
||
111 | $certificateListAux = GradebookUtils::get_list_users_certificates($selectCat); |
||
112 | |||
113 | foreach ($certificateListAux as $value) { |
||
0 ignored issues
–
show
Comprehensibility
Bug
introduced
by
Loading history...
|
|||
114 | $created_at = strtotime(api_get_local_time($value['created_at'])); |
||
115 | $value['category_id'] = $selectCat; |
||
116 | $value['c_id'] = $courseId; |
||
117 | $value['course_code'] = $courseCode; |
||
118 | switch ($filterDate) { |
||
119 | case NO_DATE_FILTER: |
||
120 | $certificateList[] = $value; |
||
121 | break; |
||
122 | case DATE_BEGIN_FILTER: |
||
123 | if ($created_at >= $dateBegin) { |
||
124 | $certificateList[] = $value; |
||
125 | } |
||
126 | break; |
||
127 | case DATE_END_FILTER: |
||
128 | if ($created_at <= $dateEnd) { |
||
129 | $certificateList[] = $value; |
||
130 | } |
||
131 | break; |
||
132 | case ALL_DATE_FILTER: |
||
133 | if ($created_at >= $dateBegin && $created_at <= $dateEnd) { |
||
134 | $certificateList[] = $value; |
||
135 | } |
||
136 | break; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | // Filter extra field |
||
141 | foreach ($certificateList as $key => $value) { |
||
142 | foreach ($filterCheckList as $fieldId => $field) { |
||
143 | $extraFieldValue = new ExtraFieldValue('user'); |
||
144 | $extraFieldValueData = $extraFieldValue->get_values_by_handler_and_field_id( |
||
145 | $value['user_id'], |
||
146 | $fieldId |
||
147 | ); |
||
148 | |||
149 | if (empty($extraFieldValueData)) { |
||
150 | unset($certificateList[$key]); |
||
151 | break; |
||
152 | } |
||
153 | |||
154 | switch ($field['field_type']) { |
||
155 | case ExtraField::FIELD_TYPE_TEXT: |
||
156 | case ExtraField::FIELD_TYPE_ALPHANUMERIC: |
||
157 | $pos = stripos($extraFieldValueData['value'], $_GET['extra_'.$field['variable']]); |
||
158 | if ($pos === false) { |
||
159 | unset($certificateList[$key]); |
||
160 | } |
||
161 | break; |
||
162 | case ExtraField::FIELD_TYPE_RADIO: |
||
163 | $valueRadio = $_GET['extra_'.$field['variable']]['extra_'.$field['variable']]; |
||
164 | if ($extraFieldValueData['value'] != $valueRadio) { |
||
165 | unset($certificateList[$key]); |
||
166 | } |
||
167 | break; |
||
168 | case ExtraField::FIELD_TYPE_SELECT: |
||
169 | if ($extraFieldValueData['value'] != $_GET['extra_'.$field['variable']]) { |
||
170 | unset($certificateList[$key]); |
||
171 | } |
||
172 | break; |
||
173 | } |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | |||
178 | $userList = []; |
||
179 | foreach ($certificateList as $index => $value) { |
||
180 | $infoUser = api_get_user_info($value['user_id']); |
||
181 | $infoUser['category_id'] = $value['category_id']; |
||
182 | $infoUser['c_id'] = $value['c_id']; |
||
183 | $infoUser['course_code'] = $value['course_code']; |
||
184 | $userList[] = $infoUser; |
||
185 | } |
||
186 | |||
187 | $sessionInfo = []; |
||
188 | if ($sessionId > 0) { |
||
189 | $sessionInfo = SessionManager::fetch($sessionId); |
||
190 | } |
||
191 | |||
192 | $path = api_get_path(WEB_UPLOAD_PATH).'certificates/'; |
||
193 | $htmlList = []; |
||
194 | |||
195 | foreach ($userList as $userInfo) { |
||
196 | $courseId = $userInfo['c_id']; |
||
197 | $courseCode = $userInfo['course_code']; |
||
198 | $studentId = $userInfo['user_id']; |
||
199 | |||
200 | $courseInfo = api_get_course_info($courseCode); |
||
201 | $allowCustomCertificate = api_get_course_setting('customcertificate_course_enable', $courseInfo); |
||
202 | if (!$allowCustomCertificate) { |
||
203 | continue; |
||
204 | } |
||
205 | |||
206 | // Get info certificate |
||
207 | $infoCertificate = CustomCertificatePlugin::getInfoCertificate($courseId, $sessionId, $accessUrlId); |
||
208 | |||
209 | if (!is_array($infoCertificate)) { |
||
210 | $infoCertificate = []; |
||
211 | } |
||
212 | |||
213 | if (empty($infoCertificate)) { |
||
214 | $infoCertificate = CustomCertificatePlugin::getInfoCertificateDefault($accessUrlId); |
||
215 | |||
216 | if (empty($infoCertificate)) { |
||
217 | Display::display_header($plugin->get_lang('PrintCertificate')); |
||
218 | echo Display::return_message($plugin->get_lang('ErrorTemplateCertificate'), 'error'); |
||
219 | Display::display_footer(); |
||
220 | exit; |
||
221 | } |
||
222 | } |
||
223 | |||
224 | $workSpace = intval(297 - $infoCertificate['margin_left'] - $infoCertificate['margin_right']); |
||
225 | $widthCell = intval($workSpace / 6); |
||
226 | |||
227 | $htmlText = ''; |
||
228 | if (!$exportAllInOne) { |
||
229 | $htmlText = '<html>'; |
||
230 | $htmlText .= ' |
||
231 | <link rel="stylesheet" |
||
232 | type="text/css" |
||
233 | href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">'; |
||
234 | $htmlText .= ' |
||
235 | <link rel="stylesheet" |
||
236 | type="text/css" |
||
237 | href="'.api_get_path(WEB_CSS_PATH).'document.css">'; |
||
238 | $htmlText .= '<body>'; |
||
239 | } |
||
240 | $studentId = $userInfo['user_id']; |
||
241 | |||
242 | if (empty($infoCertificate['background'])) { |
||
243 | $htmlText .= '<div class="caraA" style="page-break-before:always; margin:0px; padding:0px;">'; |
||
244 | } else { |
||
245 | $urlBackground = $path.$infoCertificate['background']; |
||
246 | $htmlText .= ' <div |
||
247 | class="caraA" |
||
248 | style="background-image:url('.$urlBackground.') no-repeat; |
||
249 | background-image-resize:6; margin:0px; padding:0px;">'; |
||
250 | } |
||
251 | |||
252 | if (!empty($infoCertificate['logo_left'])) { |
||
253 | $logoLeft = ' |
||
254 | <img |
||
255 | style="max-height: 150px; max-width: '.(2 * $widthCell).'mm;" |
||
256 | src="'.$path.$infoCertificate['logo_left'].'" />'; |
||
257 | } else { |
||
258 | $logoLeft = ''; |
||
259 | } |
||
260 | |||
261 | $logoCenter = ''; |
||
262 | if (!empty($infoCertificate['logo_center'])) { |
||
263 | $logoCenter = ' |
||
264 | <img |
||
265 | style="max-height: 150px; max-width: '.intval($workSpace - (2 * $widthCell)).'mm;" |
||
266 | src="'.$path.$infoCertificate['logo_center'].'" />'; |
||
267 | } |
||
268 | |||
269 | $logoRight = ''; |
||
270 | if (!empty($infoCertificate['logo_right'])) { |
||
271 | $logoRight = ' |
||
272 | <img |
||
273 | style="max-height: 150px; max-width: '.(2 * $widthCell).'mm;" |
||
274 | src="'.$path.$infoCertificate['logo_right'].'" />'; |
||
275 | } |
||
276 | |||
277 | $htmlText .= '<table |
||
278 | width="'.$workSpace.'mm" |
||
279 | style=" |
||
280 | margin-left:'.$infoCertificate['margin_left'].'mm; |
||
281 | margin-right:'.$infoCertificate['margin_right'].'mm; |
||
282 | " |
||
283 | border="0">'; |
||
284 | $htmlText .= '<tr>'; |
||
285 | $htmlText .= '<td style="width:'.intval($workSpace / 3).'mm" class="logo">'.$logoLeft.'</td>'; |
||
286 | $htmlText .= '<td style="width:'.intval($workSpace / 3).'mm; text-align:center;" class="logo">'; |
||
287 | $htmlText .= $logoCenter; |
||
288 | $htmlText .= '</td>'; |
||
289 | $htmlText .= '<td style="width:'.intval($workSpace / 3).'mm; text-align:right;" class="logo">'.$logoRight.'</td>'; |
||
290 | $htmlText .= '</tr>'; |
||
291 | $htmlText .= '</table>'; |
||
292 | |||
293 | $allUserInfo = DocumentManager::get_all_info_to_certificate( |
||
294 | $studentId, |
||
295 | $courseCode, |
||
296 | $sessionId, |
||
297 | false |
||
298 | ); |
||
299 | |||
300 | $myContentHtml = $infoCertificate['content_course']; |
||
301 | $myContentHtml = str_replace(chr(13).chr(10).chr(13).chr(10), chr(13).chr(10), $myContentHtml); |
||
302 | $infoToBeReplacedInContentHtml = $allUserInfo[0]; |
||
303 | $infoToReplaceInContentHtml = $allUserInfo[1]; |
||
304 | $myContentHtml = str_replace( |
||
305 | $infoToBeReplacedInContentHtml, |
||
306 | $infoToReplaceInContentHtml, |
||
307 | $myContentHtml |
||
308 | ); |
||
309 | |||
310 | $startDate = ''; |
||
311 | $endDate = ''; |
||
312 | switch ($infoCertificate['date_change']) { |
||
313 | case 0: |
||
314 | if (!empty($sessionInfo['access_start_date'])) { |
||
315 | $startDate = date("d/m/Y", strtotime(api_get_local_time($sessionInfo['access_start_date']))); |
||
316 | } |
||
317 | if (!empty($sessionInfo['access_end_date'])) { |
||
318 | $endDate = date("d/m/Y", strtotime(api_get_local_time($sessionInfo['access_end_date']))); |
||
319 | } |
||
320 | break; |
||
321 | case 1: |
||
322 | $startDate = date("d/m/Y", strtotime($infoCertificate['date_start'])); |
||
323 | $endDate = date("d/m/Y", strtotime($infoCertificate['date_end'])); |
||
324 | break; |
||
325 | } |
||
326 | |||
327 | $myContentHtml = str_replace( |
||
328 | '((start_date))', |
||
329 | $startDate, |
||
330 | $myContentHtml |
||
331 | ); |
||
332 | |||
333 | $myContentHtml = str_replace( |
||
334 | '((end_date))', |
||
335 | $endDate, |
||
336 | $myContentHtml |
||
337 | ); |
||
338 | |||
339 | $dateExpediction = ''; |
||
340 | if ($infoCertificate['type_date_expediction'] != 3) { |
||
341 | $dateExpediction .= $plugin->get_lang('ExpedictionIn').' '.$infoCertificate['place']; |
||
342 | if ($infoCertificate['type_date_expediction'] == 1) { |
||
343 | $dateExpediction .= $plugin->get_lang('to').api_format_date(time(), DATE_FORMAT_LONG); |
||
344 | } elseif ($infoCertificate['type_date_expediction'] == 2) { |
||
345 | $dateFormat = $plugin->get_lang('formatDownloadDate'); |
||
346 | if (!empty($infoCertificate['day']) && |
||
347 | !empty($infoCertificate['month']) && |
||
348 | !empty($infoCertificate['year']) |
||
349 | ) { |
||
350 | $dateExpediction .= sprintf( |
||
351 | $dateFormat, |
||
352 | $infoCertificate['day'], |
||
353 | $infoCertificate['month'], |
||
354 | $infoCertificate['year'] |
||
355 | ); |
||
356 | } else { |
||
357 | $dateExpediction .= sprintf( |
||
358 | $dateFormat, |
||
359 | '......', |
||
360 | '....................', |
||
361 | '............' |
||
362 | ); |
||
363 | } |
||
364 | } elseif ($infoCertificate['type_date_expediction'] == 4) { |
||
365 | $dateExpediction .= $plugin->get_lang('to').$infoToReplaceInContentHtml[9]; //date_certificate_no_time |
||
366 | } else { |
||
367 | if (!empty($sessionInfo)) { |
||
368 | $dateInfo = api_get_local_time($sessionInfo['access_end_date']); |
||
369 | $dateExpediction .= $plugin->get_lang('to').api_format_date($dateInfo, DATE_FORMAT_LONG); |
||
370 | } |
||
371 | } |
||
372 | } |
||
373 | |||
374 | $myContentHtml = str_replace( |
||
375 | '((date_expediction))', |
||
376 | $dateExpediction, |
||
377 | $myContentHtml |
||
378 | ); |
||
379 | |||
380 | $myContentHtml = strip_tags( |
||
381 | $myContentHtml, |
||
382 | '<p><b><strong><table><tr><td><th><tbody><span><i><li><ol><ul> |
||
383 | <dd><dt><dl><br><hr><img><a><div><h1><h2><h3><h4><h5><h6>' |
||
384 | ); |
||
385 | |||
386 | $htmlText .= '<div style=" |
||
387 | height: 480px; |
||
388 | width:'.$workSpace.'mm; |
||
389 | margin-left:'.$infoCertificate['margin_left'].'mm; |
||
390 | margin-right:'.$infoCertificate['margin_right'].'mm; |
||
391 | ">'; |
||
392 | $htmlText .= $myContentHtml; |
||
393 | $htmlText .= '</div>'; |
||
394 | |||
395 | $htmlText .= '<table |
||
396 | width="'.$workSpace.'mm" |
||
397 | style=" |
||
398 | margin-left:'.$infoCertificate['margin_left'].'mm; |
||
399 | margin-right:'.$infoCertificate['margin_right'].'mm; |
||
400 | " |
||
401 | border="0">'; |
||
402 | |||
403 | $htmlText .= '<tr>'; |
||
404 | $htmlText .= '<td colspan="2" class="seals" style="width:'.$widthCell.'mm">'. |
||
405 | ((!empty($infoCertificate['signature_text1'])) ? $infoCertificate['signature_text1'] : ''). |
||
406 | '</td> |
||
407 | <td colspan="2" class="seals" style="width:'.$widthCell.'mm">'. |
||
408 | ((!empty($infoCertificate['signature_text2'])) ? $infoCertificate['signature_text2'] : ''). |
||
409 | '</td> |
||
410 | <td colspan="2" class="seals" style="width:'.$widthCell.'mm">'. |
||
411 | ((!empty($infoCertificate['signature_text3'])) ? $infoCertificate['signature_text3'] : ''). |
||
412 | '</td> |
||
413 | <td colspan="2" class="seals" style="width:'.$widthCell.'mm">'. |
||
414 | ((!empty($infoCertificate['signature_text4'])) ? $infoCertificate['signature_text4'] : ''). |
||
415 | '</td> |
||
416 | <td colspan="4" class="seals" style="width:'.(2 * $widthCell).'mm"> |
||
417 | '.((!empty($infoCertificate['seal'])) ? $plugin->get_lang('Seal') : ''). |
||
418 | '</td>'; |
||
419 | $htmlText .= '</tr>'; |
||
420 | $htmlText .= '<tr>'; |
||
421 | $htmlText .= '<td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">'. |
||
422 | ((!empty($infoCertificate['signature1'])) |
||
423 | ? '<img style="max-height: 100px; max-width: '.$widthCell.'mm;" |
||
424 | src="'.$path.$infoCertificate['signature1'].'" />' |
||
425 | : ''). |
||
426 | '</td> |
||
427 | <td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">'. |
||
428 | ((!empty($infoCertificate['signature2'])) |
||
429 | ? '<img style="max-height: 100px; '.$widthCell.'mm;" |
||
430 | src="'.$path.$infoCertificate['signature2'].'" />' |
||
431 | : ''). |
||
432 | '</td> |
||
433 | <td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">'. |
||
434 | ((!empty($infoCertificate['signature3'])) |
||
435 | ? '<img style="max-height: 100px; '.$widthCell.'mm;" |
||
436 | src="'.$path.$infoCertificate['signature3'].'" />' |
||
437 | : ''). |
||
438 | '</td> |
||
439 | <td colspan="2" class="logo-seals" style="width:'.$widthCell.'mm">'. |
||
440 | ((!empty($infoCertificate['signature4'])) |
||
441 | ? '<img style="max-height: 100px; '.$widthCell.'mm;" |
||
442 | src="'.$path.$infoCertificate['signature4'].'" />' |
||
443 | : ''). |
||
444 | '</td> |
||
445 | <td colspan="4" class="logo-seals" style="width:'.(2 * $widthCell).'mm">'. |
||
446 | ((!empty($infoCertificate['seal'])) |
||
447 | ? '<img style="max-height: 100px; '.(2 * $widthCell).'mm;" |
||
448 | src="'.$path.$infoCertificate['seal'].'" />' |
||
449 | : ''). |
||
450 | '</td>'; |
||
451 | $htmlText .= '</tr>'; |
||
452 | $htmlText .= '</table>'; |
||
453 | $htmlText .= '</div>'; |
||
454 | |||
455 | // Rear certificate |
||
456 | if ($infoCertificate['contents_type'] != 3) { |
||
457 | $htmlText .= '<div class="caraB" style="page-break-before:always; margin:0px; padding:0px;">'; |
||
458 | if ($infoCertificate['contents_type'] == 0) { |
||
459 | $courseDescription = new CourseDescription(); |
||
460 | $contentDescription = $courseDescription->get_data_by_description_type(3, $courseId, 0); |
||
461 | $domd = new DOMDocument(); |
||
462 | libxml_use_internal_errors(true); |
||
463 | if (isset($contentDescription['description_content'])) { |
||
464 | $domd->loadHTML($contentDescription['description_content']); |
||
465 | } |
||
466 | libxml_use_internal_errors(false); |
||
467 | $domx = new DOMXPath($domd); |
||
468 | $items = $domx->query("//li[@style]"); |
||
469 | foreach ($items as $item) { |
||
470 | $item->removeAttribute("style"); |
||
471 | } |
||
472 | |||
473 | $items = $domx->query("//span[@style]"); |
||
474 | foreach ($items as $item) { |
||
475 | $item->removeAttribute("style"); |
||
476 | } |
||
477 | |||
478 | $output = $domd->saveHTML(); |
||
479 | $htmlText .= getIndexFiltered($output); |
||
480 | } |
||
481 | |||
482 | if ($infoCertificate['contents_type'] == 1) { |
||
483 | $items = []; |
||
484 | $categoriesTempList = learnpath::getCategories($courseId); |
||
485 | $categoryTest = new CLpCategory(); |
||
486 | $categoryTest->setId(0); |
||
487 | $categoryTest->setName($plugin->get_lang('WithOutCategory')); |
||
488 | $categoryTest->setPosition(0); |
||
489 | $categories = [$categoryTest]; |
||
490 | |||
491 | if (!empty($categoriesTempList)) { |
||
492 | $categories = array_merge($categories, $categoriesTempList); |
||
493 | } |
||
494 | |||
495 | foreach ($categories as $item) { |
||
496 | $categoryId = $item->getId(); |
||
497 | |||
498 | if (!learnpath::categoryIsVisibleForStudent($item, api_get_user_entity($studentId))) { |
||
499 | continue; |
||
500 | } |
||
501 | |||
502 | $sql = "SELECT 1 |
||
503 | FROM $tblProperty |
||
504 | WHERE tool = 'learnpath_category' |
||
505 | AND ref = $categoryId |
||
506 | AND visibility = 0 |
||
507 | AND (session_id = $sessionId OR session_id IS NULL)"; |
||
508 | $res = Database::query($sql); |
||
509 | if (Database::num_rows($res) > 0) { |
||
510 | continue; |
||
511 | } |
||
512 | |||
513 | $list = new LearnpathList( |
||
514 | $studentId, |
||
515 | $courseCode, |
||
516 | $sessionId, |
||
517 | null, |
||
518 | false, |
||
519 | $categoryId |
||
520 | ); |
||
521 | |||
522 | $flat_list = $list->get_flat_list(); |
||
523 | |||
524 | if (empty($flat_list)) { |
||
525 | continue; |
||
526 | } |
||
527 | |||
528 | if (count($categories) > 1 && count($flat_list) > 0) { |
||
529 | if ($item->getName() != $plugin->get_lang('WithOutCategory')) { |
||
530 | $items[] = '<h4 style="margin:0">'.$item->getName().'</h4>'; |
||
531 | } |
||
532 | } |
||
533 | |||
534 | foreach ($flat_list as $learnpath) { |
||
535 | $lpId = $learnpath['lp_old_id']; |
||
536 | $sql = "SELECT 1 |
||
537 | FROM $tblProperty |
||
538 | WHERE tool = 'learnpath' |
||
539 | AND ref = $lpId AND visibility = 0 |
||
540 | AND (session_id = $sessionId OR session_id IS NULL)"; |
||
541 | $res = Database::query($sql); |
||
542 | if (Database::num_rows($res) > 0) { |
||
543 | continue; |
||
544 | } |
||
545 | $lpName = $learnpath['lp_name']; |
||
546 | $items[] = $lpName.'<br>'; |
||
547 | } |
||
548 | $items[] = '<br />'; |
||
549 | } |
||
550 | |||
551 | if (count($items) > 0) { |
||
552 | $htmlText .= '<table width="100%" class="contents-learnpath">'; |
||
553 | $htmlText .= '<tr>'; |
||
554 | $htmlText .= '<td>'; |
||
555 | $i = 0; |
||
556 | foreach ($items as $value) { |
||
557 | if ($i == 50) { |
||
558 | $htmlText .= '</td><td>'; |
||
559 | } |
||
560 | $htmlText .= $value; |
||
561 | $i++; |
||
562 | } |
||
563 | $htmlText .= '</td>'; |
||
564 | $htmlText .= '</tr>'; |
||
565 | $htmlText .= '</table>'; |
||
566 | } |
||
567 | $htmlText .= '</td></table>'; |
||
568 | } |
||
569 | |||
570 | if ($infoCertificate['contents_type'] == 2) { |
||
571 | $htmlText .= '<table width="100%" class="contents-learnpath">'; |
||
572 | $htmlText .= '<tr>'; |
||
573 | $htmlText .= '<td>'; |
||
574 | $myContentHtml = strip_tags( |
||
575 | $infoCertificate['contents'], |
||
576 | '<p><b><strong><table><tr><td><th><span><i><li><ol><ul>'. |
||
577 | '<dd><dt><dl><br><hr><img><a><div><h1><h2><h3><h4><h5><h6>' |
||
578 | ); |
||
579 | $htmlText .= $myContentHtml; |
||
580 | $htmlText .= '</td>'; |
||
581 | $htmlText .= '</tr>'; |
||
582 | $htmlText .= '</table>'; |
||
583 | } |
||
584 | $htmlText .= '</div>'; |
||
585 | } |
||
586 | |||
587 | if (!$exportAllInOne) { |
||
588 | $htmlText .= '</body></html>'; |
||
589 | } |
||
590 | $fileName = 'certificate_'.$userInfo['course_code'].'_'.$userInfo['complete_name'].'_'.$currentLocalTime; |
||
591 | $htmlList[$fileName] = $htmlText; |
||
592 | } |
||
593 | |||
594 | $fileList = []; |
||
595 | $archivePath = api_get_path(SYS_ARCHIVE_PATH).'certificates/'; |
||
596 | if (!is_dir($archivePath)) { |
||
597 | mkdir($archivePath, api_get_permissions_for_new_directories()); |
||
598 | } |
||
599 | |||
600 | if ($exportAllInOne) { |
||
601 | $params = [ |
||
602 | 'pdf_title' => 'Certificate', |
||
603 | 'pdf_description' => '', |
||
604 | 'format' => 'A4-L', |
||
605 | 'orientation' => 'L', |
||
606 | 'left' => 15, |
||
607 | 'top' => 15, |
||
608 | 'bottom' => 0, |
||
609 | ]; |
||
610 | $pdf = new PDF($params['format'], $params['orientation'], $params); |
||
611 | |||
612 | $contentAllCertificate = ''; |
||
613 | foreach ($htmlList as $fileName => $content) { |
||
614 | $contentAllCertificate .= $content; |
||
615 | } |
||
616 | |||
617 | if (!empty($contentAllCertificate)) { |
||
618 | $certificateContent = '<html>'; |
||
619 | $certificateContent .= ' |
||
620 | <link rel="stylesheet" |
||
621 | type="text/css" |
||
622 | href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">'; |
||
623 | $certificateContent .= ' |
||
624 | <link rel="stylesheet" |
||
625 | type="text/css" |
||
626 | href="'.api_get_path(WEB_CSS_PATH).'document.css">'; |
||
627 | $certificateContent .= '<body>'; |
||
628 | $certificateContent .= $contentAllCertificate; |
||
629 | $certificateContent .= '</body></html>'; |
||
630 | |||
631 | $pdf->content_to_pdf( |
||
632 | $certificateContent, |
||
633 | '', |
||
634 | 'certificate'.date('Y_m_d_His'), |
||
635 | null, |
||
636 | 'D', |
||
637 | false, |
||
638 | null, |
||
639 | false, |
||
640 | false, |
||
641 | false |
||
642 | ); |
||
643 | } |
||
644 | } else { |
||
645 | foreach ($htmlList as $fileName => $content) { |
||
646 | $fileName = api_replace_dangerous_char($fileName); |
||
647 | $params = [ |
||
648 | 'filename' => $fileName, |
||
649 | 'pdf_title' => 'Certificate', |
||
650 | 'pdf_description' => '', |
||
651 | 'format' => 'A4-L', |
||
652 | 'orientation' => 'L', |
||
653 | 'left' => 15, |
||
654 | 'top' => 15, |
||
655 | 'bottom' => 0, |
||
656 | ]; |
||
657 | $pdf = new PDF($params['format'], $params['orientation'], $params); |
||
658 | if ($exportZip) { |
||
659 | $filePath = $archivePath.$fileName.'.pdf'; |
||
660 | $pdf->content_to_pdf($content, '', $fileName, null, 'F', true, $filePath, false, false, false); |
||
661 | $fileList[] = $filePath; |
||
662 | } else { |
||
663 | $pdf->content_to_pdf($content, '', $fileName, null, 'D', false, null, false, false, false); |
||
664 | } |
||
665 | } |
||
666 | |||
667 | if (!empty($fileList)) { |
||
668 | $zipFile = $archivePath.'certificates_'.api_get_unique_id().'.zip'; |
||
669 | $zipFolder = new PclZip($zipFile); |
||
670 | foreach ($fileList as $file) { |
||
671 | $zipFolder->add($file, PCLZIP_OPT_REMOVE_ALL_PATH); |
||
0 ignored issues
–
show
|
|||
672 | } |
||
673 | $name = 'certificates_'.$currentLocalTime.'.zip'; |
||
674 | DocumentManager::file_send_for_download($zipFile, true, $name); |
||
675 | exit; |
||
676 | } |
||
677 | } |
||
678 | |||
679 | function getIndexFiltered($index) |
||
680 | { |
||
681 | $txt = strip_tags($index, "<b><strong><i>"); |
||
682 | $txt = str_replace(chr(13).chr(10).chr(13).chr(10), chr(13).chr(10), $txt); |
||
683 | $lines = explode(chr(13).chr(10), $txt); |
||
684 | $text1 = ''; |
||
685 | for ($x = 0; $x < 47; $x++) { |
||
686 | if (isset($lines[$x])) { |
||
687 | $text1 .= $lines[$x].chr(13).chr(10); |
||
688 | } |
||
689 | } |
||
690 | |||
691 | $text2 = ''; |
||
692 | for ($x = 47; $x < 94; $x++) { |
||
693 | if (isset($lines[$x])) { |
||
694 | $text2 .= $lines[$x].chr(13).chr(10); |
||
695 | } |
||
696 | } |
||
697 | |||
698 | $showLeft = str_replace(chr(13).chr(10), "<br/>", $text1); |
||
699 | $showRight = str_replace(chr(13).chr(10), "<br/>", $text2); |
||
700 | $result = '<table width="100%">'; |
||
701 | $result .= '<tr>'; |
||
702 | $result .= '<td style="width:50%;vertical-align:top;padding-left:15px; font-size:12px;">'.$showLeft.'</td>'; |
||
703 | $result .= '<td style="vertical-align:top; font-size:12px;">'.$showRight.'</td>'; |
||
704 | $result .= '<tr>'; |
||
705 | $result .= '</table>'; |
||
706 | |||
707 | return $result; |
||
708 | } |
||
709 |