checkInstanceImage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 4
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
$useDefault = false;
5
$isDefault = isset($_GET['default']) ? (int) $_GET['default'] : null;
6
7
if ($isDefault === 1) {
8
    $cidReset = true;
9
}
10
11
$course_plugin = 'customcertificate';
12
require_once __DIR__.'/../config.php';
13
14
$_setting['student_view_enabled'] = 'false';
15
16
$userId = api_get_user_id();
17
$plugin = CustomCertificatePlugin::create();
18
$nameTools = $plugin->get_lang('CertificateSetting');
19
$enable = $plugin->get('enable_plugin_customcertificate') == 'true';
20
$accessUrlId = api_get_current_access_url_id();
21
$course_info = api_get_course_info();
22
23
if ($isDefault === 1) {
24
    $courseId = 0;
25
    $courseCode = '';
26
    $sessionId = 0;
27
    $enableCourse = false;
28
    $useDefault = true;
29
    $defaultCertificate = 1;
30
    $nameTools = $plugin->get_lang('CertificateSettingDefault');
31
    $urlParams = '?default=1';
32
} else {
33
    $courseId = api_get_course_int_id();
34
    $courseCode = api_get_course_id();
35
    $sessionId = api_get_session_id();
36
    $enableCourse = api_get_course_setting('customcertificate_course_enable', $course_info) == 1 ? true : false;
37
    $useDefault = api_get_course_setting('use_certificate_default', $course_info) == 1 ? true : false;
38
    $defaultCertificate = 0;
39
    $urlParams = '?'.api_get_cidreq();
40
}
41
42
if (!$enable) {
43
    api_not_allowed(true, $plugin->get_lang('ToolDisabled'));
44
}
45
46
if (!$enableCourse && !$useDefault) {
47
    api_not_allowed(true, $plugin->get_lang('ToolDisabledCourse'));
48
}
49
50
if ($enableCourse && $useDefault) {
51
    api_not_allowed(true, $plugin->get_lang('ToolUseDefaultSettingCourse'));
52
}
53
54
$allow = api_is_platform_admin() || api_is_teacher();
55
if (!$allow) {
56
    api_not_allowed(true);
57
}
58
59
$table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE);
60
$htmlHeadXtra[] = api_get_js_simple(
61
    api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/js/certificate.js'
62
);
63
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
64
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
65
$htmlHeadXtra[] = api_get_css(
66
    api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/form.css'
67
);
68
$htmlHeadXtra[] = '<script>
69
    $(function () {
70
        $("#delete_certificate").click(function (e) {
71
            e.preventDefault();
72
            e.stopPropagation();
73
74
            if (confirm("'.$plugin->get_lang("QuestionDelete").'")) {
75
                var courseId = '.$courseId.';
76
                var sessionId = '.$sessionId.';
77
                var accessUrlId = '.$accessUrlId.';
78
                var plugin_path = "'.api_get_path(WEB_PLUGIN_PATH).'";
79
                var ajax_path = plugin_path + "customcertificate/src/customcertificate.ajax.php?a=delete_certificate";
80
                $.ajax({
81
                    data: {courseId: courseId, sessionId: sessionId, accessUrlId: accessUrlId},
82
                    url: ajax_path,
83
                    type: "POST",
84
                    success: function (response) {
85
                        window.location.reload();
86
                    }
87
                }); 
88
            }
89
        });
90
91
    });
92
</script>';
93
94
// Get info certificate
95
$infoCertificate = CustomCertificatePlugin::getInfoCertificate($courseId, $sessionId, $accessUrlId);
96
97
$form = new FormValidator(
98
    'formEdit',
99
    'post',
100
    api_get_self().$urlParams,
101
    null,
102
    ['class' => 'form-vertical']
103
);
104
105
if ($form->validate()) {
106
    $formValues = $form->getSubmitValues();
107
    if (empty($formValues['contents'])) {
108
        $contents = '';
109
    } else {
110
        $contents = $formValues['contents'];
111
    }
112
    $check = Security::check_token('post');
113
    if ($check) {
114
        $date_start = str_replace('/', '-', $formValues['date_start']);
115
        $date_end = str_replace('/', '-', $formValues['date_end']);
116
        $params = [
117
            'access_url_id' => api_get_current_access_url_id(),
118
            'c_id' => $formValues['c_id'],
119
            'session_id' => $formValues['session_id'],
120
            'content_course' => $formValues['content_course'],
121
            'contents_type' => (int) $formValues['contents_type'],
122
            'contents' => $contents,
123
            'date_change' => intval($formValues['date_change']),
124
            'date_start' => date("Y-m-d", strtotime($date_start)),
125
            'date_end' => date("Y-m-d", strtotime($date_end)),
126
            'place' => $formValues['place'],
127
            'type_date_expediction' => (int) $formValues['type_date_expediction'],
128
            'day' => $formValues['day'],
129
            'month' => $formValues['month'],
130
            'year' => $formValues['year'],
131
            'signature_text1' => $formValues['signature_text1'],
132
            'signature_text2' => $formValues['signature_text2'],
133
            'signature_text3' => $formValues['signature_text3'],
134
            'signature_text4' => $formValues['signature_text4'],
135
            'margin_left' => (int) $formValues['margin_left'],
136
            'margin_right' => (int) $formValues['margin_right'],
137
            'certificate_default' => 0,
138
        ];
139
140
        if (intval($formValues['default_certificate'] == 1)) {
141
            $params['certificate_default'] = 1;
142
        }
143
144
        // Insert or Update
145
        if ($infoCertificate['id'] > 0) {
146
            $certificateId = $infoCertificate['id'];
147
            Database::update($table, $params, ['id = ?' => $certificateId]);
148
        } else {
149
            $certificateId = Database::insert($table, $params);
150
        }
151
152
        // Image manager
153
        $fieldList = [
154
            'logo_left',
155
            'logo_center',
156
            'logo_right',
157
            'seal',
158
            'signature1',
159
            'signature2',
160
            'signature3',
161
            'signature4',
162
            'background',
163
        ];
164
165
        foreach ($fieldList as $field) {
166
            $checkLogo[$field] = false;
167
            if (!empty($formValues['remove_'.$field]) || $_FILES[$field]['size']) {
168
                checkInstanceImage(
169
                    $certificateId,
170
                    $infoCertificate[$field],
171
                    $field
172
                );
173
            }
174
175
            if ($_FILES[$field]['size']) {
176
                $newPicture = api_upload_file(
177
                    'certificates',
178
                    $_FILES[$field],
179
                    $certificateId,
180
                    $formValues[$field.'_crop_result']
181
                );
182
                if ($newPicture) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $newPicture of type array<string,string> is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
183
                    $sql = "UPDATE $table
184
                            SET $field = '".$newPicture['path_to_save']."'
185
                            WHERE id = $certificateId";
186
                    Database::query($sql);
187
                    $checkLogo[$field] = true;
188
                }
189
            }
190
        }
191
192
        // Certificate Default
193
        if (intval($formValues['use_default'] == 1)) {
194
            $infoCertificateDefault = CustomCertificatePlugin::getInfoCertificateDefault($accessUrlId);
195
            if (!empty($infoCertificateDefault)) {
196
                foreach ($fieldList as $field) {
197
                    if (!empty($infoCertificateDefault[$field]) && !$checkLogo[$field]) {
198
                        $sql = "UPDATE $table
199
                                SET $field = '".$infoCertificateDefault[$field]."'
200
                                WHERE id = $certificateId";
201
                        Database::query($sql);
202
                    }
203
                }
204
            }
205
        }
206
207
        Display::addFlash(Display::return_message(get_lang('Saved')));
208
209
        Security::clear_token();
210
        header('Location: '.api_get_self().$urlParams);
211
        exit;
212
    }
213
}
214
215
if (empty($infoCertificate)) {
216
    $infoCertificate = CustomCertificatePlugin::getInfoCertificateDefault($accessUrlId);
217
218
    if (empty($infoCertificate)) {
219
        $infoCertificate = [
220
            'type_date_expediction' => '',
221
            'year' => '',
222
            'month' => '',
223
            'day' => '',
224
            'date_change' => '',
225
        ];
226
    }
227
    $useDefault = true;
228
}
229
230
// Display the header
231
Display::display_header($nameTools);
232
$actionsLeft = Display::url(
233
    Display::return_icon('certificate.png', get_lang('Certificate'), '', ICON_SIZE_MEDIUM),
234
    'print_certificate.php'.$urlParams
235
);
236
if (!empty($courseId) && !$useDefault) {
237
    $actionsLeft .= Display::url(
238
        Display::return_icon('delete.png', $plugin->get_lang('DeleteCertificate'), '', ICON_SIZE_MEDIUM),
239
        'delete_certificate.php'.$urlParams,
240
        ['id' => 'delete_certificate']
241
    );
242
}
243
244
echo Display::toolbarAction(
245
    'toolbar-document',
246
    [$actionsLeft]
247
);
248
249
if ($useDefault && $courseId > 0) {
250
    echo Display::return_message(get_lang('InfoFromDefaultCertificate'), 'info');
251
}
252
253
// Student and course section
254
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('StudentCourseInfo')).'</legend>');
255
$form->addHtml('<div class="col-sm-8">');
256
$dir = '/';
257
$courseInfo = api_get_course_info();
258
$isAllowedToEdit = api_is_allowed_to_edit(null, true);
259
$editorConfig = [
260
    'ToolbarSet' => $isAllowedToEdit ? 'Documents' : 'DocumentsStudent',
261
    'Width' => '100%',
262
    'Height' => '300',
263
    'cols-size' => [0, 12, 0],
264
    'FullPage' => true,
265
    'InDocument' => true,
266
    'CreateDocumentDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/',
267
    'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/',
268
    'BaseHref' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$dir,
269
];
270
$form->addHtmlEditor(
271
    'content_course',
272
    '',
273
    false,
274
    true,
275
    $editorConfig,
276
    true
277
);
278
$form->addHtml('</div>');
279
$form->addHtml('<div class="col-sm-4">');
280
$strInfo = '((user_firstname))<br />';
281
$strInfo .= '((user_lastname))<br />';
282
$strInfo .= '((gradebook_institution))<br />';
283
$strInfo .= '((gradebook_sitename))<br />';
284
$strInfo .= '((teacher_firstname))<br />';
285
$strInfo .= '((teacher_lastname))<br />';
286
$strInfo .= '((official_code))<br />';
287
$strInfo .= '((date_certificate))<br />';
288
$strInfo .= '((date_certificate_no_time))<br />';
289
$strInfo .= '((date_simple_certificate))<br />';
290
$strInfo .= '((course_code))<br />';
291
$strInfo .= '((course_title))<br />';
292
$strInfo .= '((gradebook_grade))<br />';
293
$strInfo .= '((external_style))<br />';
294
$strInfo .= '((start_date))<br />';
295
$strInfo .= '((end_date))<br />';
296
$strInfo .= '((date_expediction))';
297
298
$createCertificate = get_lang('CreateCertificateWithTags');
299
$form->addElement(
300
    'html',
301
    Display::return_message($createCertificate.': <br />'.$strInfo, 'normal', false)
302
);
303
$form->addHtml('</div>');
304
$form->addHtml('</fieldset>');
305
$form->addHtml('<div class="clearfix"></div>');
306
307
// Contents section
308
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('Contents')).'</legend>');
309
$extra = '';
310
if (empty($infoCertificate['contents_type'])) {
311
    $infoCertificate['contents_type'] = 0;
312
    $extra = 'disabled';
313
}
314
315
$group = [];
316
$element = &$form->createElement(
317
    'radio',
318
    'contents_type',
319
    '',
320
    get_lang('ContentsCourseDescription'),
321
    0,
322
    ['id' => 'contents_type_0', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();']
323
);
324
325
$group[] = $element;
326
327
$element = &$form->createElement(
328
    'radio',
329
    'contents_type',
330
    '',
331
    get_lang('ContentsIndexLearnpath'),
332
    1,
333
    ['id' => 'contents_type_1', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();']
334
);
335
$group[] = $element;
336
337
$element = &$form->createElement(
338
    'radio',
339
    'contents_type',
340
    '',
341
    get_lang('ContentsHide'),
342
    3,
343
    ['id' => 'contents_type_3', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();']
344
);
345
$group[] = $element;
346
347
$element = &$form->createElement(
348
    'radio',
349
    'contents_type',
350
    '',
351
    get_lang('ContentsCustom'),
352
    2,
353
    ['id' => 'contents_type_2', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();']
354
);
355
$group[] = $element;
356
357
$form->addGroup(
358
    $group,
359
    'contents_type',
360
    get_lang('ContentsToShow'),
361
    null,
362
    false
363
);
364
365
$form->addHtml('<div id="contents-section">');
366
$editorConfig = [
367
    'ToolbarSet' => ($isAllowedToEdit ? 'Documents' : 'DocumentsStudent'),
368
    'Width' => '100%',
369
    'Height' => '200',
370
    'cols-size' => [2, 10, 0],
371
    'FullPage' => true,
372
    'InDocument' => true,
373
    'CreateDocumentDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/',
374
    'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/',
375
    'BaseHref' => api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$dir,
376
    'id' => 'contents',
377
    $extra,
378
];
379
$form->addHtmlEditor(
380
    'contents',
381
    get_lang('Contents'),
382
    false,
383
    true,
384
    $editorConfig,
385
    true
386
);
387
$form->addHtml('</div>');
388
389
// Dates section
390
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang("Dates")).'</legend>');
391
392
$group = [];
393
$option1 = &$form->createElement(
394
    'radio',
395
    'date_change',
396
    '',
397
    get_lang('UseDateSessionAccess'),
398
    0,
399
    ['id' => 'date_change_0', 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();']
400
);
401
$group[] = $option1;
402
403
$option2 = &$form->createElement(
404
    'radio',
405
    'date_change',
406
    '',
407
    get_lang('None'),
408
    2,
409
    ['id' => 'date_change_2', 'onclick' => 'javascript: dateCertificateSwitchRadioButton2();']
410
);
411
$group[] = $option2;
412
413
$option3 = &$form->createElement(
414
    'radio',
415
    'date_change',
416
    '',
417
    get_lang('Custom'),
418
    1,
419
    ['id' => 'date_change_1', 'onclick' => 'javascript: dateCertificateSwitchRadioButton1();']
420
);
421
$group[] = $option3;
422
423
$form->addGroup(
424
    $group,
425
    'date_change',
426
    get_lang('CourseDeliveryDates'),
427
    null,
428
    false
429
);
430
$form->addHtml('<div class="form-group" style="padding-top: 10px;">
431
        <label for="date_certificate" class="col-sm-2 control-label">&nbsp;</label>
432
        <div class="col-sm-10">
433
        <div class="radio" style="margin-top: -25px;">
434
            <span style="margin: 0 10px; font-style: italic;">'.get_lang('From').'</span>
435
            <input 
436
                size="20"
437
                autofocus="autofocus"
438
                class="form-control-cert text-center datepicker"
439
                name="date_start"
440
                id="date_start"
441
                type="text"
442
                value="'.(($infoCertificate['date_change'] == '1')
443
                        ? date("d/m/Y", strtotime($infoCertificate['date_start']))
444
                        : '').'"
445
                '.(($infoCertificate['date_change'] == '') ? 'disabled' : '').'
446
            >
447
            <span style="margin: 0 10px; font-style: italic;">'.get_lang('Until').'</span>
448
            <input
449
                size="20"
450
                class="form-control-cert text-center datepicker"
451
                name="date_end"
452
                id="date_end"
453
                type="text"
454
                value="'.(($infoCertificate['date_change'] == '1')
455
                        ? date("d/m/Y", strtotime($infoCertificate['date_end']))
456
                        : '').'"
457
                '.(($infoCertificate['date_change'] == "0") ? 'disabled' : '').'
458
            >
459
        </div>
460
        </div>
461
    </div>');
462
463
$form->addText(
464
    'place',
465
    get_lang('ExpectionPlace'),
466
    false,
467
    ['id' => 'place', 'cols-size' => [2, 5, 5], 'autofocus']
468
);
469
470
$group = [];
471
$option = &$form->createElement(
472
    'radio',
473
    'type_date_expediction',
474
    '',
475
    get_lang('UseDateEndAccessSession'),
476
    0,
477
    [
478
        'id' => 'type_date_expediction_0',
479
        'onclick' => 'javascript: dateCertificateSwitchRadioButton0();',
480
        (($sessionId == 0) ? 'disabled' : ''),
481
    ]
482
);
483
$group[] = $option;
484
485
$option = &$form->createElement(
486
    'radio',
487
    'type_date_expediction',
488
    '',
489
    get_lang('UseDateDownloadCertificate'),
490
    1,
491
    [
492
        'id' => 'type_date_expediction_1',
493
        'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
494
    ]
495
);
496
$group[] = $option;
497
498
$option = &$form->createElement(
499
    'radio',
500
    'type_date_expediction',
501
    '',
502
    get_lang('UseDateGenerationCertificate'),
503
    4,
504
    [
505
        'id' => 'type_date_expediction_4',
506
        'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
507
    ]
508
);
509
$group[] = $option;
510
511
$option = &$form->createElement(
512
    'radio',
513
    'type_date_expediction',
514
    '',
515
    get_lang('None'),
516
    3,
517
    [
518
        'id' => 'type_date_expediction_3',
519
        'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
520
    ]
521
);
522
$group[] = $option;
523
524
$option = &$form->createElement(
525
    'radio',
526
    'type_date_expediction',
527
    '',
528
    get_lang('UseCustomDate'),
529
    2,
530
    [
531
        'id' => 'type_date_expediction_2',
532
        'onclick' => 'javascript: typeDateExpedictionSwitchRadioButton();',
533
    ]
534
);
535
$group[] = $option;
536
537
$form->addGroup(
538
    $group,
539
    'type_date_expediction',
540
    get_lang('DateExpediction'),
541
    null,
542
    false
543
);
544
545
$form->addHtml(
546
    '<div class="form-group" style="padding-top: 10px;">
547
        <label for="date_certificate" class="col-sm-2 control-label">&nbsp;</label>
548
        <div class="col-sm-10">
549
        <div class="radio" style="margin-top: -25px;">
550
            <span class="certificado-text-label">a</span>
551
            <input
552
                size="4"
553
                autofocus="autofocus"
554
                class="form-control-cert text-center"
555
                name="day"
556
                id="day"
557
                type="text"
558
                value="'.$infoCertificate['day'].'"
559
                '.(($infoCertificate['type_date_expediction'] != '2') ? 'disabled' : '').'
560
            >
561
            <span class="certificado-text-label">de</span>
562
            <input
563
                size="10"
564
                autofocus="autofocus"
565
                class="form-control-cert text-center"
566
                name="month"
567
                id="month"
568
                type="text"
569
                value="'.$infoCertificate['month'].'"
570
                '.(($infoCertificate['type_date_expediction'] != '2') ? 'disabled' : '').'
571
            >
572
            <span class="certificado-text-label">de</span>
573
            <input
574
                size="4"
575
                autofocus="autofocus"
576
                class="form-control-cert text-center"
577
                name="year"
578
                id="year"
579
                type="text"
580
                value="'.$infoCertificate['year'].'"
581
                '.(($infoCertificate['type_date_expediction'] != '2') ? 'disabled' : '').'
582
            >
583
        </div>
584
        </div>
585
    </div>'
586
);
587
$form->addHtml('</fieldset>');
588
589
// Signature section
590
$base = api_get_path(WEB_UPLOAD_PATH);
591
$path = $base.'certificates/';
592
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('LogosSeal')).'</legend>');
593
// Logo 1
594
$form->addHtml('<div class="col-sm-6">');
595
$form->addFile(
596
    'logo_left',
597
    get_lang('LogoLeft'),
598
    [
599
        'id' => 'logo_left',
600
        'class' => 'picture-form',
601
        'crop_image' => true,
602
        'crop_scalable' => 'true',
603
    ]
604
);
605
$form->addProgress();
606
if (!empty($infoCertificate['logo_left'])) {
607
    $form->addElement('checkbox', 'remove_logo_left', null, get_lang('DelImage'));
608
    $form->addElement(
609
        'html',
610
        '<label class="col-sm-2">&nbsp;</label>
611
        <img src="'.$path.$infoCertificate['logo_left'].'" width="100"  />
612
        <br><br>'
613
    );
614
}
615
$allowedPictureTypes = api_get_supported_image_extensions(false);
616
$form->addRule(
617
    'logo_left',
618
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
619
    'filetype',
620
    $allowedPictureTypes
621
);
622
$form->addHtml('</div>');
623
// Logo 2
624
$form->addHtml('<div class="col-sm-6">');
625
$form->addFile(
626
    'logo_center',
627
    get_lang('LogoCenter'),
628
    [
629
        'id' => 'logo_center',
630
        'class' => 'picture-form',
631
        'crop_image' => true,
632
        'crop_scalable' => 'true',
633
    ]
634
);
635
$form->addProgress();
636
if (!empty($infoCertificate['logo_center'])) {
637
    $form->addElement('checkbox', 'remove_logo_center', null, get_lang('DelImage'));
638
    $form->addElement(
639
        'html',
640
        '<label class="col-sm-2">&nbsp;</label>
641
        <img src="'.$path.$infoCertificate['logo_center'].'" width="100"  />
642
        <br><br>'
643
    );
644
}
645
$allowedPictureTypes = api_get_supported_image_extensions(false);
646
$form->addRule(
647
    'logo_center',
648
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
649
    'filetype',
650
    $allowedPictureTypes
651
);
652
$form->addHtml('</div><div class="clearfix"></div>');
653
// Logo 3
654
$form->addHtml('<div class="col-sm-6">');
655
$form->addFile(
656
    'logo_right',
657
    get_lang('LogoRight'),
658
    [
659
        'id' => 'logo_right',
660
        'class' => 'picture-form',
661
        'crop_image' => true,
662
        'crop_scalable' => 'true',
663
    ]
664
);
665
$form->addProgress();
666
if (!empty($infoCertificate['logo_right'])) {
667
    $form->addElement('checkbox', 'remove_logo_right', null, get_lang('DelImage'));
668
    $form->addElement(
669
        'html',
670
        '<label class="col-sm-2">&nbsp;</label>
671
        <img src="'.$path.$infoCertificate['logo_right'].'" width="100"  />
672
        <br><br>'
673
    );
674
}
675
$tblProperty = api_get_supported_image_extensions(false);
676
$form->addRule(
677
    'logo_right',
678
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
679
    'filetype',
680
    $allowedPictureTypes
681
);
682
$form->addHtml('</div>');
683
$form->addHtml('<div class="col-sm-6">');
684
$form->addFile(
685
    'seal',
686
    get_lang('Seal'),
687
    [
688
        'id' => 'seal',
689
        'class' => 'picture-form',
690
        'crop_image' => true,
691
        'crop_scalable' => 'true',
692
    ]
693
);
694
$form->addProgress();
695
if (!empty($infoCertificate['seal'])) {
696
    $form->addElement('checkbox', 'remove_seal', null, get_lang('DelImage'));
697
    $form->addElement(
698
        'html',
699
        '<label class="col-sm-2">&nbsp;</label>
700
        <img src="'.$path.$infoCertificate['seal'].'" width="100"  />
701
        <br><br>'
702
    );
703
}
704
$allowedPictureTypes = api_get_supported_image_extensions(false);
705
$form->addRule(
706
    'seal',
707
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
708
    'filetype',
709
    $allowedPictureTypes
710
);
711
$form->addHtml('</div><div class="clearfix"></div>');
712
$form->addHtml('</fieldset>');
713
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('Signatures')).'</legend>');
714
// signature 1
715
$form->addHtml('<div class="col-sm-6">');
716
$form->addText(
717
    'signature_text1',
718
    get_lang('SignatureText1'),
719
    false,
720
    ['cols-size' => [2, 10, 0], 'autofocus']
721
);
722
$form->addFile(
723
    'signature1',
724
    get_lang('Signature1'),
725
    [
726
        'id' => 'signature1',
727
        'class' => 'picture-form',
728
        'crop_image' => true,
729
        'crop_scalable' => 'true',
730
    ]
731
);
732
$form->addProgress();
733
if (!empty($infoCertificate['signature1'])) {
734
    $form->addElement('checkbox', 'remove_signature1', null, get_lang('DelImage'));
735
    $form->addElement(
736
        'html',
737
        '<label class="col-sm-2">&nbsp;</label>
738
        <img src="'.$path.$infoCertificate['signature1'].'" width="100"  />
739
        <br><br>'
740
    );
741
}
742
$allowedPictureTypes = api_get_supported_image_extensions(false);
743
$form->addRule(
744
    'signature1',
745
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
746
    'filetype',
747
    $allowedPictureTypes
748
);
749
$form->addHtml('</div>');
750
// signature 2
751
$form->addHtml('<div class="col-sm-6">');
752
$form->addText(
753
    'signature_text2',
754
    get_lang('SignatureText2'),
755
    false,
756
    ['cols-size' => [2, 10, 0], 'autofocus']
757
);
758
$form->addFile(
759
    'signature2',
760
    get_lang('Signature2'),
761
    [
762
        'id' => 'signature2',
763
        'class' => 'picture-form',
764
        'crop_image' => true,
765
        'crop_scalable' => 'true',
766
    ]
767
);
768
$form->addProgress();
769
if (!empty($infoCertificate['signature2'])) {
770
    $form->addElement('checkbox', 'remove_signature2', null, get_lang('DelImage'));
771
    $form->addElement(
772
        'html',
773
        '<label class="col-sm-2">&nbsp;</label>
774
        <img src="'.$path.$infoCertificate['signature2'].'" width="100"  />
775
        <br><br>'
776
    );
777
}
778
$allowedPictureTypes = api_get_supported_image_extensions(false);
779
$form->addRule(
780
    'signature2',
781
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
782
    'filetype',
783
    $allowedPictureTypes
784
);
785
$form->addHtml('</div><div class="clearfix"></div>');
786
// signature 3
787
$form->addHtml('<div class="col-sm-6">');
788
$form->addText(
789
    'signature_text3',
790
    get_lang('SignatureText3'),
791
    false,
792
    ['cols-size' => [2, 10, 0], 'autofocus']
793
);
794
$form->addFile(
795
    'signature3',
796
    get_lang('Signature3'),
797
    [
798
        'id' => 'signature3',
799
        'class' => 'picture-form',
800
        'crop_image' => true,
801
        'crop_scalable' => 'true',
802
    ]
803
);
804
$form->addProgress();
805
if (!empty($infoCertificate['signature3'])) {
806
    $form->addElement('checkbox', 'remove_signature3', null, get_lang('DelImage'));
807
    $form->addElement(
808
        'html',
809
        '<label class="col-sm-2">&nbsp;</label>
810
        <img src="'.$path.$infoCertificate['signature3'].'" width="100" />
811
        <br><br>'
812
    );
813
}
814
$allowedPictureTypes = api_get_supported_image_extensions(false);
815
$form->addRule(
816
    'signature3',
817
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
818
    'filetype',
819
    $allowedPictureTypes
820
);
821
$form->addHtml('</div>');
822
// signature 4
823
$form->addHtml('<div class="col-sm-6">');
824
$form->addText(
825
    'signature_text4',
826
    get_lang('SignatureText4'),
827
    false,
828
    ['cols-size' => [2, 10, 0], 'autofocus']
829
);
830
$form->addFile(
831
    'signature4',
832
    get_lang('Signature4'),
833
    [
834
        'id' => 'signature4',
835
        'class' => 'picture-form',
836
        'crop_image' => true,
837
        'crop_scalable' => 'true',
838
    ]
839
);
840
$form->addProgress();
841
if (!empty($infoCertificate['signature4'])) {
842
    $form->addElement('checkbox', 'remove_signature4', null, get_lang('DelImage'));
843
    $form->addElement(
844
        'html',
845
        '<label class="col-sm-2">&nbsp;</label>
846
        <img src="'.$path.$infoCertificate['signature4'].'" width="100"  />
847
        <br><br>'
848
    );
849
}
850
$allowedPictureTypes = api_get_supported_image_extensions(false);
851
$form->addRule(
852
    'signature4',
853
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
854
    'filetype',
855
    $allowedPictureTypes
856
);
857
$form->addHtml('</div><div class="clearfix"></div>');
858
$form->addHtml('</fieldset><br>');
859
$form->addHtml('<div class="col-sm-6">');
860
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('BackgroundCertificate')).'</legend>');
861
// background
862
$form->addFile(
863
    'background',
864
    get_lang('Background'),
865
    [
866
        'id' => 'background',
867
        'class' => 'picture-form',
868
        'crop_image' => true,
869
        'crop_ratio' => '297 / 210',
870
    ]
871
);
872
$form->addProgress();
873
if (!empty($infoCertificate['background'])) {
874
    $form->addElement('checkbox', 'remove_background', null, get_lang('DelImage'));
875
    $form->addElement(
876
        'html',
877
        '<label class="col-sm-2">&nbsp;</label>
878
        <img src="'.$path.$infoCertificate['background'].'" width="100"  />
879
        <br><br>'
880
    );
881
}
882
$allowedPictureTypes = api_get_supported_image_extensions(false);
883
$form->addRule(
884
    'background',
885
    get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowedPictureTypes).')',
886
    'filetype',
887
    $allowedPictureTypes
888
);
889
$form->addHtml('</fieldset>');
890
$form->addHtml('</div>');
891
$form->addHtml('<div class="col-sm-6">');
892
$form->addHtml('<fieldset><legend>'.strtoupper(get_lang('OtherOptions')).'</legend>');
893
$marginOptions = [];
894
$i = 0;
895
while ($i < 298) {
896
    $marginOptions[$i] = $i.' mm';
897
    $i++;
898
}
899
$form->addElement(
900
    'select',
901
    'margin_left',
902
    get_lang('MarginLeft'),
903
    $marginOptions,
904
    ['cols-size' => [4, 8, 0]]
905
);
906
$form->addElement(
907
    'select',
908
    'margin_right',
909
    get_lang('MarginRight'),
910
    $marginOptions,
911
    ['cols-size' => [4, 8, 0]]
912
);
913
$form->addHtml('</fieldset>');
914
$form->addHtml('</div>');
915
$form->addHtml('<div class="clearfix"></div>');
916
917
$form->addButton(
918
    'submit',
919
    get_lang('SaveCertificate'),
920
    'check',
921
    'primary',
922
    null,
923
    null,
924
    ['cols-size' => [5, 2, 5]],
925
    false
926
);
927
928
$form->addElement('hidden', 'formSent');
929
$infoCertificate['formSent'] = 1;
930
$form->setDefaults($infoCertificate);
931
$token = Security::get_token();
932
$form->addElement('hidden', 'sec_token');
933
$form->addElement('hidden', 'use_default');
934
$form->addElement('hidden', 'default_certificate');
935
$form->addElement('hidden', 'c_id');
936
$form->addElement('hidden', 'session_id');
937
$form->setConstants(
938
    [
939
        'sec_token' => $token,
940
        'use_default' => $useDefault,
941
        'default_certificate' => $defaultCertificate,
942
        'c_id' => $courseId,
943
        'session_id' => $sessionId,
944
    ]
945
);
946
echo '<div class="page-create">';
947
echo '<div class="row" style="overflow:hidden">';
948
echo '<div id="doc_form" class="col-md-12">';
949
echo $form->returnForm();
950
echo '</div>';
951
echo '</div>';
952
echo '</div>';
953
Display::display_footer();
954
955
/**
956
 * Delete the file if there is only one instance.
957
 *
958
 * @param int    $certificateId
959
 * @param string $imagePath
960
 * @param string $field
961
 * @param string $type
962
 */
963
function checkInstanceImage($certificateId, $imagePath, $field, $type = 'certificates')
964
{
965
    $table = Database::get_main_table(CustomCertificatePlugin::TABLE_CUSTOMCERTIFICATE);
966
    $imagePath = Database::escape_string($imagePath);
967
    $field = Database::escape_string($field);
968
    $certificateId = (int) $certificateId;
969
970
    $sql = "SELECT * FROM $table WHERE $field = '$imagePath'";
971
    $res = Database::query($sql);
972
    if (Database::num_rows($res) == 1) {
973
        api_remove_uploaded_file($type, $imagePath);
974
    }
975
976
    $sql = "UPDATE $table SET $field = '' WHERE id = $certificateId";
977
    Database::query($sql);
978
}
979