Passed
Push — master ( b6788e...7c4243 )
by Julito
08:34
created

card_settings_open()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 16
c 0
b 0
f 0
nc 4
nop 5
dl 0
loc 20
rs 9.7333
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Framework\Container;
6
use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8
/**
9
 * Code to display the course settings form (for the course admin)
10
 * and activate the changes.
11
 *
12
 * See ./inc/conf/course_info.conf.php for settings
13
 *
14
 * @todo    Take those config settings into account in this script
15
 *
16
 * @author  Patrick Cool <[email protected]>
17
 * @author  Roan Embrechts, refactoring and improved course visibility|subscribe|unsubscribe options
18
 * @author  Julio Montoya <[email protected]> Jquery support + lots of fixes
19
 */
20
require_once __DIR__.'/../inc/global.inc.php';
21
$current_course_tool = TOOL_COURSE_SETTING;
22
$this_section = SECTION_COURSES;
23
$nameTools = get_lang('Settings');
24
api_protect_course_script(true);
25
api_block_anonymous_users();
26
27
$urlId = api_get_current_access_url_id();
28
$_course = api_get_course_info();
29
$courseEntity = api_get_course_entity();
30
$isAllowToEdit = api_is_course_admin() || api_is_platform_admin();
31
$course_code = api_get_course_id();
32
$courseId = api_get_course_int_id();
33
$repo = Container::getCourseRepository();
34
$courseCategoryRepo = Container::getCourseCategoryRepository();
35
$illustrationRepo = Container::getIllustrationRepository();
36
$em = Database::getManager();
37
$isEditable = true;
38
39
if (!$isAllowToEdit) {
40
    api_not_allowed(true);
41
}
42
43
$router = Container::getRouter();
44
$translator = Container::getTranslator();
45
46
$show_delete_watermark_text_message = false;
47
if ('true' === api_get_setting('pdf_export_watermark_by_course')) {
48
    if (isset($_GET['delete_watermark'])) {
49
        PDF::delete_watermark($course_code);
50
        $show_delete_watermark_text_message = true;
51
    }
52
}
53
54
$categories = $courseCategoryRepo->getCategoriesByCourseIdAndAccessUrlId($courseId, $urlId);
55
56
$formOptionsArray = [];
57
58
// Build the form
59
$form = new FormValidator(
60
    'update_course',
61
    'post',
62
    api_get_self().'?'.api_get_cidreq()
63
);
64
65
$image = '';
66
$illustrationUrl = $illustrationRepo->getIllustrationUrl($courseEntity, 'course_picture_medium');
67
68
if (!empty($illustrationUrl)) {
69
    $image = '<div class="row">
70
                <label class="col-md-2 control-label">'.get_lang('Image').'</label>
71
                <div class="col-md-8">
72
                    <img class="img-thumbnail" src="'.$illustrationUrl.'" />
73
                </div>
74
            </div>';
75
}
76
77
$form->addText('title', get_lang('Title'), true);
78
$form->applyFilter('title', 'html_filter');
79
$form->applyFilter('title', 'trim');
80
81
/*$form->addElement(
82
    'select',
83
    'category_id',
84
    get_lang('Category'),
85
    $categories,
86
    ['style' => 'width:350px', 'id' => 'category_id']
87
);*/
88
$form->addSelectLanguage(
89
    'course_language',
90
    [get_lang('Language'), get_lang('This language will be valid for every visitor of your courses portal')]
91
);
92
93
$group = [
94
    $form->createElement('radio', 'show_course_in_user_language', null, get_lang('Yes'), 1),
95
    $form->createElement('radio', 'show_course_in_user_language', null, get_lang('No'), 2),
96
];
97
98
$form->addGroup($group, '', [get_lang('Show course in user\'s language')]);
99
100
$form->addText('department_name', get_lang('Department'), false);
101
$form->applyFilter('department_name', 'html_filter');
102
$form->applyFilter('department_name', 'trim');
103
104
$form->addText('department_url', get_lang('Department URL'), false);
105
$form->applyFilter('department_url', 'html_filter');
106
107
// Extra fields
108
$extra_field = new ExtraField('course');
109
$extraFieldAdminPermissions = false;
110
$showOnlyTheseFields = ['tags', 'video_url', 'course_hours_duration', 'max_subscribed_students'];
111
$extra = $extra_field->addElements(
112
    $form,
113
    $courseId,
114
    [],
115
    false,
116
    false,
117
    $showOnlyTheseFields
118
);
119
120
//Tags ExtraField
121
$htmlHeadXtra[] = '
122
<script>
123
$(function() {
124
    '.$extra['jquery_ready_content'].'
125
});
126
</script>';
127
128
// Picture
129
$form->addFile(
130
    'picture',
131
    get_lang('Add a picture'),
132
    ['id' => 'picture', 'class' => 'picture-form', 'crop_image' => true]
133
);
134
135
$allowed_picture_types = api_get_supported_image_extensions(false);
136
137
$form->addHtml($image);
138
139
$form->addRule(
140
    'picture',
141
    get_lang('Only PNG, JPG or GIF images allowed').' ('.implode(',', $allowed_picture_types).')',
142
    'filetype',
143
    $allowed_picture_types
144
);
145
$form->addElement('checkbox', 'delete_picture', null, get_lang('Delete picture'));
146
147
if ('true' === api_get_setting('pdf_export_watermark_by_course')) {
148
    $url = PDF::get_watermark($course_code);
149
    $form->addText('pdf_export_watermark_text', get_lang('PDF watermark text'), false, ['size' => '60']);
150
    $form->addElement('file', 'pdf_export_watermark_path', get_lang('Upload a watermark image'));
151
    if (false != $url) {
152
        $delete_url = '<a href="?delete_watermark">'.Display::return_icon('delete.png', get_lang('Remove picture')).'</a>';
153
        $form->addElement(
154
            'html',
155
            '<div class="row"><div class="form"><a href="'.$url.'">'.$url.' '.$delete_url.'</a></div></div>'
156
        );
157
    }
158
    $form->addRule(
159
        'pdf_export_watermark_path',
160
        get_lang('Only PNG, JPG or GIF images allowed').' ('.implode(',', $allowed_picture_types).')',
161
        'filetype',
162
        $allowed_picture_types
163
    );
164
}
165
166
if ('true' === api_get_setting('allow_course_theme')) {
167
    $group = [];
168
    $group[] = $form->createElement(
169
        'SelectTheme',
170
        'course_theme',
171
        null,
172
        ['id' => 'course_theme_id']
173
    );
174
    $form->addGroup($group, '', [get_lang('Style sheets')]);
175
}
176
177
$form->addElement('label', get_lang('Space Available'), format_file_size(DocumentManager::get_course_quota()));
178
179
/*$scoreModels = ExerciseLib::getScoreModels();
180
if (!empty($scoreModels)) {
181
    $options = ['' => get_lang('none')];
182
    foreach ($scoreModels['models'] as $item) {
183
        $options[$item['id']] = get_lang($item['name']);
184
    }
185
    $form->addSelect('score_model_id', get_lang('Score model'), $options);
186
}
187
*/
188
189
190
$form->addButtonSave(get_lang('Save settings'), 'submit_save');
191
192
193
CourseManager::addVisibilityOptions($form);
194
195
$url = api_get_path(WEB_CODE_PATH)."auth/inscription.php?c=$course_code&e=1";
196
$url = Display::url($url, $url);
197
$label = $form->addLabel(
198
    get_lang('Direct link'),
199
    sprintf(
200
        get_lang(
201
            'If your course is public or open, you can use the direct link below to send an invitation to new users, so after registration, they will be sent directly to the course. Also, you can add the e=1 parameter to the URL, replacing \"1\" by an exercise ID to send them directly to a specific exam. The exercise ID can be discovered in the URL when clicking on an exercise to open it.<br/>%s'
202
        ),
203
        $url
204
    ),
205
    true
206
);
207
208
$group2 = [];
209
$group2[] = $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
210
$group2[] = $form->createElement(
211
    'radio',
212
    'subscribe',
213
    null,
214
    get_lang('This function is only available to trainers'),
215
    0
216
);
217
218
$myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
219
220
$group3[] = $form->createElement(
221
    'radio',
222
    'unsubscribe',
223
    get_lang('Unsubscribe'),
224
    get_lang('Users are allowed to unsubscribe from this course'),
225
    1
226
);
227
$group3[] = $form->createElement(
228
    'radio',
229
    'unsubscribe',
230
    null,
231
    get_lang('Users are not allowed to unsubscribe from this course'),
232
    0
233
);
234
235
$text = $form->createElement(
236
    'text',
237
    'course_registration_password',
238
    get_lang('Course registration password'),
239
    false,
240
    ['size' => '60']
241
);
242
243
$checkBoxActiveLegal = $form->createElement(
244
    'checkbox',
245
    'activate_legal',
246
    [null, get_lang('Show a legal notice when entering the course')],
247
    get_lang('Enable legal terms')
248
);
249
$textAreaLegal = $form->createElement('textarea', 'legal', get_lang('Legal agreement for this course'), ['rows' => 8]);
250
251
$elements = [
252
    //$groupElement,
253
    $label,
254
    get_lang('Subscription') => $group2,
255
    get_lang('Unsubscribe') => $group3,
256
    $text,
257
    $checkBoxActiveLegal,
258
    $textAreaLegal,
259
    $myButton,
260
];
261
262
$form->addPanelOption(
263
    'course_access',
264
    get_lang('Course access'),
265
    $elements,
266
    'course.png',
267
    false,
268
    'accordionSettings'
269
);
270
/*
271
/*
272
// Documents
273
$globalGroup = [];
274
if ('true' === api_get_setting('documents_default_visibility_defined_in_course')) {
275
    $group = [
276
        $form->createElement('radio', 'documents_default_visibility', null, get_lang('Visible'), 'visible'),
277
        $form->createElement('radio', 'documents_default_visibility', null, get_lang('invisible'), 'invisible'),
278
    ];
279
    $globalGroup[get_lang('Default visibility of new documents')] = $group;
280
}
281
282
if ('true' == api_get_setting('show_default_folders')) {
283
    $group = [
284
        $form->createElement('radio', 'show_system_folders', null, get_lang('Yes'), 1),
285
        $form->createElement('radio', 'show_system_folders', null, get_lang('No'), 2),
286
    ];
287
288
    $globalGroup[get_lang('Show system folders.')] = $group;
289
290
    $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
291
}
292
293
$group = [];
294
$group[] = $form->createElement(
295
    'radio',
296
    'enable_document_auto_launch',
297
    get_lang('Auto-launch for documents'),
298
    get_lang('Redirect to the document list'),
299
    1
300
);
301
$group[] = $form->createElement('radio', 'enable_document_auto_launch', null, get_lang('Deactivate'), 0);
302
$globalGroup[get_lang('Auto-launch for documents')] = $group;
303
304
$globalGroup[] = $myButton;
305
306
$form->addPanelOption(
307
    'documents',
308
    get_lang('Documents'),
309
    $globalGroup,
310
    'folder.png',
311
    false,
312
    'accordionSettings'
313
);
314
315
$globalGroup = [];
316
$group = [];
317
$group[] = $form->createElement(
318
    'radio',
319
    'email_alert_to_teacher_on_new_user_in_course',
320
    get_lang('E-mail teacher when a new user auto-subscribes'),
321
    get_lang('E-mail teacher when a new user auto-subscribesEnable'),
322
    1
323
);
324
$group[] = $form->createElement(
325
    'radio',
326
    'email_alert_to_teacher_on_new_user_in_course',
327
    null,
328
    get_lang('E-mail teacher when a new user auto-subscribesToTeacharAndTutor'),
329
    2
330
);
331
$group[] = $form->createElement(
332
    'radio',
333
    'email_alert_to_teacher_on_new_user_in_course',
334
    null,
335
    get_lang('E-mail teacher when a new user auto-subscribesDisable'),
336
    0
337
);
338
$globalGroup[get_lang('E-mail teacher when a new user auto-subscribes')] = $group;
339
340
$group = [];
341
$group[] = $form->createElement(
342
    'radio',
343
    'email_alert_students_on_new_homework',
344
    get_lang('E-mail students on assignment creation'),
345
    get_lang('E-mail students on assignment creationEnable'),
346
    1
347
);
348
$group[] = $form->createElement(
349
    'radio',
350
    'email_alert_students_on_new_homework',
351
    null,
352
    get_lang('E-mail students on assignment creationToHrmEnable'),
353
    2
354
);
355
$group[] = $form->createElement(
356
    'radio',
357
    'email_alert_students_on_new_homework',
358
    null,
359
    get_lang('E-mail students on assignment creationDisable'),
360
    0
361
);
362
$globalGroup[get_lang('E-mail students on assignment creation')] = $group;
363
364
$group = [];
365
$group[] = $form->createElement(
366
    'radio',
367
    'email_alert_manager_on_new_doc',
368
    get_lang('E-mail on assignments submission by students'),
369
    get_lang('E-mail on assignments submission by studentsActivate'),
370
    1
371
);
372
$group[] = $form->createElement(
373
    'radio',
374
    'email_alert_manager_on_new_doc',
375
    null,
376
    get_lang('E-mail on assignments submission by studentsActivateOnlyForTeachers'),
377
    3
378
);
379
$group[] = $form->createElement(
380
    'radio',
381
    'email_alert_manager_on_new_doc',
382
    null,
383
    get_lang('E-mail on assignments submission by studentsActivateOnlyForStudents'),
384
    2
385
);
386
$group[] = $form->createElement(
387
    'radio',
388
    'email_alert_manager_on_new_doc',
389
    null,
390
    get_lang('E-mail on assignments submission by studentsDeactivate'),
391
    0
392
);
393
394
$globalGroup[get_lang('E-mail on assignments submission by students')] = $group;
395
396
$group = [];
397
$group[] = $form->createElement(
398
    'radio',
399
    'email_alert_on_new_doc_dropbox',
400
    get_lang('E-mail users on dropbox file reception'),
401
    get_lang('E-mail users on dropbox file receptionActivate'),
402
    1
403
);
404
$group[] = $form->createElement(
405
    'radio',
406
    'email_alert_on_new_doc_dropbox',
407
    null,
408
    get_lang('E-mail users on dropbox file receptionDeactivate'),
409
    0
410
);
411
412
$globalGroup[get_lang('E-mail users on dropbox file reception')] = $group;
413
414
// Exercises notifications
415
$emailAlerts = ExerciseLib::getNotificationSettings();
416
$group = [];
417
foreach ($emailAlerts as $itemId => $label) {
418
    $group[] = $form->createElement(
419
        'checkbox',
420
        'email_alert_manager_on_new_quiz[]',
421
        null,
422
        $label,
423
        ['value' => $itemId]
424
    );
425
}
426
427
$globalGroup[get_lang('Tests')] = $group;
428
429
$group = [];
430
$group[] = $form->createElement(
431
    'radio',
432
    'email_to_teachers_on_new_work_feedback',
433
    get_lang('E-mail to teachers on new user\'s student publication feedback.'),
434
    get_lang('Yes'),
435
    1
436
);
437
$group[] = $form->createElement(
438
    'radio',
439
    'email_to_teachers_on_new_work_feedback',
440
    null,
441
    get_lang('No'),
442
    2
443
);
444
445
$globalGroup[get_lang('E-mail to teachers on new user\'s student publication feedback.')] = $group;
446
447
$myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
448
$globalGroup[] = $myButton;
449
450
$form->addPanelOption(
451
    'email-notifications',
452
    get_lang('E-mail notifications'),
453
    $globalGroup,
454
    'mail.png',
455
    false,
456
    'accordionSettings'
457
);
458
459
$group = [];
460
$group[] = $form->createElement(
461
    'radio',
462
    'allow_user_edit_agenda',
463
    get_lang('Allow learners to edit the agenda'),
464
    get_lang('Allow learners to edit the agendaActivate'),
465
    1
466
);
467
$group[] = $form->createElement(
468
    'radio',
469
    'allow_user_edit_agenda',
470
    null,
471
    get_lang('Allow learners to edit the agendaDeactivate'),
472
    0
473
);
474
475
$group2 = [];
476
$group2[] = $form->createElement(
477
    'radio',
478
    'allow_user_edit_announcement',
479
    get_lang('Allow learners to edit announcements'),
480
    get_lang('Allow learners to edit announcementsActivate'),
481
    1
482
);
483
$group2[] = $form->createElement(
484
    'radio',
485
    'allow_user_edit_announcement',
486
    null,
487
    get_lang('Allow learners to edit announcementsDeactivate'),
488
    0
489
);
490
491
$group3 = [];
492
$group3[] = $form->createElement(
493
    'radio',
494
    'allow_user_image_forum',
495
    get_lang('User picture in forum'),
496
    get_lang('User picture in forumActivate'),
497
    1
498
);
499
$group3[] = $form->createElement(
500
    'radio',
501
    'allow_user_image_forum',
502
    null,
503
    get_lang('User picture in forumDeactivate'),
504
    0
505
);
506
507
$group4 = [];
508
$group4[] = $form->createElement(
509
    'radio',
510
    'allow_user_view_user_list',
511
    get_lang('Allow user view user list'),
512
    get_lang('Allow user view user listActivate'),
513
    1
514
);
515
$group4[] = $form->createElement(
516
    'radio',
517
    'allow_user_view_user_list',
518
    null,
519
    get_lang('Allow user view user listDeactivate'),
520
    0
521
);
522
$myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
523
524
$globalGroup = [
525
    get_lang('Allow learners to edit the agenda') => $group,
526
    get_lang('Allow learners to edit announcements') => $group2,
527
    get_lang('User picture in forum') => $group3,
528
    get_lang('Allow user view user list') => $group4,
529
    '' => $myButton,
530
];
531
532
$form->addPanelOption(
533
    'users',
534
    get_lang('User rights'),
535
    $globalGroup,
536
    'user.png',
537
    false,
538
    'accordionSettings'
539
);
540
541
// CHAT SETTINGS
542
$group = [];
543
$group[] = $form->createElement(
544
    'radio',
545
    'allow_open_chat_window',
546
    get_lang('Open chat in a new Window'),
547
    get_lang('Activate open the chat in a new window'),
548
    1
549
);
550
$group[] = $form->createElement(
551
    'radio',
552
    'allow_open_chat_window',
553
    null,
554
    get_lang('Deactivate open the chat in a new window'),
555
    0
556
);
557
$myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
558
559
$globalGroup = [
560
    get_lang('Open chat in a new Window') => $group,
561
    '' => $myButton,
562
];
563
564
$form->addPanelOption(
565
    'chat',
566
    get_lang('Chat settings'),
567
    $globalGroup,
568
    'chat.png',
569
    false,
570
    'accordionSettings'
571
);
572
573
$globalGroup = [];
574
$group = [];
575
$group[] = $form->createElement(
576
    'radio',
577
    'enable_lp_auto_launch',
578
    get_lang('Enable learning path auto-launch'),
579
    get_lang('Redirect to a selected learning path'),
580
    1
581
);
582
$group[] = $form->createElement(
583
    'radio',
584
    'enable_lp_auto_launch',
585
    get_lang('Enable learning path auto-launch'),
586
    get_lang('Redirect to the learning paths list'),
587
    2
588
);
589
$group[] = $form->createElement('radio', 'enable_lp_auto_launch', null, get_lang('Deactivate'), 0);
590
591
$globalGroup[get_lang('Enable learning path auto-launch')] = $group;
592
593
if ('true' === api_get_setting('allow_course_theme')) {
594
    // Allow theme into Learning path
595
    $group = [];
596
    $group[] = $form->createElement(
597
        'radio',
598
        'allow_learning_path_theme',
599
        get_lang('Enable course themes'),
600
        get_lang('Enable course themesAllow'),
601
        1
602
    );
603
    $group[] = $form->createElement(
604
        'radio',
605
        'allow_learning_path_theme',
606
        null,
607
        get_lang('Enable course themesDisallow'),
608
        0
609
    );
610
611
    $globalGroup[get_lang("Enable course themes")] = $group;
612
}
613
614
$allowLPReturnLink = api_get_setting('allow_lp_return_link');
615
if ('true' === $allowLPReturnLink) {
616
    $group = [
617
        $form->createElement(
618
            'radio',
619
            'lp_return_link',
620
            get_lang('Learning path return link'),
621
            get_lang('Redirect to the learning paths list'),
622
            1
623
        ),
624
        $form->createElement(
625
            'radio',
626
            'lp_return_link',
627
            null,
628
            get_lang('Redirect to Course home'),
629
            0
630
        ),
631
        $form->createElement(
632
            'radio',
633
            'lp_return_link',
634
            null,
635
            get_lang('My courses'),
636
            2
637
        ),
638
        $form->createElement(
639
            'radio',
640
            'lp_return_link',
641
            null,
642
            get_lang('RedirectToPortalHome'),
643
            3
644
        ),
645
    ];
646
    $globalGroup[get_lang("Learning path return link")] = $group;
647
}
648
649
$exerciseInvisible = api_get_setting('exercise_invisible_in_session');
650
$configureExerciseVisibility = api_get_setting('configure_exercise_visibility_in_course');
651
652
if ('true' === $exerciseInvisible &&
653
    'true' === $configureExerciseVisibility
654
) {
655
    $group = [
656
        $form->createElement(
657
            'radio',
658
            'exercise_invisible_in_session',
659
            get_lang('TestinvisibleInSession'),
660
            get_lang('Yes'),
661
            1
662
        ),
663
        $form->createElement(
664
            'radio',
665
            'exercise_invisible_in_session',
666
            null,
667
            get_lang('No'),
668
            0
669
        ),
670
    ];
671
672
    $globalGroup[get_lang("TestinvisibleInSession")] = $group;
673
}
674
675
if ($isEditable) {
676
    $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
677
    $globalGroup[] = $myButton;
678
} else {
679
    // Is it allowed to edit the course settings?
680
    if (!$isEditable) {
681
        $disabled_output = "disabled";
682
    }
683
    $form->freeze();
684
}
685
686
$form->addPanelOption(
687
    'config_lp',
688
    get_lang('Learning path settings'),
689
    $globalGroup,
690
    'scorms.png',
691
    false,
692
    'accordionSettings'
693
);
694
695
if (api_get_configuration_value('allow_exercise_auto_launch')) {
696
    $globalGroup = [];
697
698
    // Auto launch exercise
699
    $group = [];
700
    $group[] = $form->createElement(
701
        'radio',
702
        'enable_exercise_auto_launch',
703
        get_lang('Auto-launch for exercises'),
704
        get_lang('Redirect to the selected exercise'),
705
        1
706
    );
707
    $group[] = $form->createElement(
708
        'radio',
709
        'enable_exercise_auto_launch',
710
        get_lang('Auto-launch for exercises'),
711
        get_lang('Redirect to the exercises list'),
712
        2
713
    );
714
    $group[] = $form->createElement('radio', 'enable_exercise_auto_launch', null, get_lang('Deactivate'), 0);
715
716
    $globalGroup[get_lang("Auto-launch for exercises")] = $group;
717
718
    if ($isEditable) {
719
        $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
720
        $globalGroup[] = $myButton;
721
    } else {
722
        // Is it allowed to edit the course settings?
723
        if (!$isEditable) {
724
            $disabled_output = "disabled";
725
        }
726
        $form->freeze();
727
    }
728
729
    $form->addPanelOption(
730
        'config_exercise',
731
        get_lang('Test'),
732
        $globalGroup,
733
        'quiz.png',
734
        false,
735
        'accordionSettings'
736
    );
737
}
738
739
// START THEMATIC
740
$group = [];
741
$group[] = $form->createElement(
742
    'radio',
743
    'display_info_advance_inside_homecourse',
744
    get_lang('Information on thematic advance on course homepage'),
745
    get_lang('Display information about the last completed topic'),
746
    1
747
);
748
$group[] = $form->createElement(
749
    'radio',
750
    'display_info_advance_inside_homecourse',
751
    null,
752
    get_lang('Display information about the next uncompleted topic'),
753
    2
754
);
755
$group[] = $form->createElement(
756
    'radio',
757
    'display_info_advance_inside_homecourse',
758
    null,
759
    get_lang('Display information about the next uncompleted topicAndLastDoneAdvance'),
760
    3
761
);
762
$group[] = $form->createElement(
763
    'radio',
764
    'display_info_advance_inside_homecourse',
765
    null,
766
    get_lang('Do not display progress'),
767
    0
768
);
769
$myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
770
771
$globalGroup = [
772
    get_lang('Information on thematic advance on course homepage') => $group,
773
    '' => $myButton,
774
];
775
776
$form->addPanelOption(
777
    'thematic',
778
    get_lang('Thematic advance configuration'),
779
    $globalGroup,
780
    'course_progress.png',
781
    false,
782
    'accordionSettings'
783
);
784
785
if ('true' === api_get_setting('allow_public_certificates')) {
786
    $group = [];
787
    $group[] = $form->createElement(
788
        'radio',
789
        'allow_public_certificates',
790
        get_lang('Learner certificates are public'),
791
        get_lang('Yes'),
792
        1
793
    );
794
    $group[] = $form->createElement('radio', 'allow_public_certificates', null, get_lang('No'), 0);
795
    $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
796
797
    $globalGroup = [
798
        get_lang('Learner certificates are public') => $group,
799
        '' => $myButton,
800
    ];
801
802
    $form->addPanelOption(
803
        'certificate',
804
        get_lang('Certificates'),
805
        $globalGroup,
806
        null,
807
        false,
808
        'accordionSettings'
809
    );
810
}
811
812
// Forum settings
813
$group = [
814
    $form->createElement('radio', 'enable_forum_auto_launch', null, get_lang('Redirect to forums list'), 1),
815
    $form->createElement('radio', 'enable_forum_auto_launch', null, get_lang('Disabled'), 2),
816
];
817
$myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
818
819
// Forum settings
820
$groupNotification = [
821
    $form->createElement('radio', 'hide_forum_notifications', null, get_lang('Yes'), 1),
822
    $form->createElement('radio', 'hide_forum_notifications', null, get_lang('No'), 2),
823
];
824
825
$addUsers = [
826
    $form->createElement('radio', 'subscribe_users_to_forum_notifications', null, get_lang('Yes'), 1),
827
    $form->createElement('radio', 'subscribe_users_to_forum_notifications', null, get_lang('No'), 2),
828
];
829
830
$globalGroup = [
831
    get_lang('Enable forum auto-launch') => $group,
832
    get_lang('Hide forum notifications') => $groupNotification,
833
    get_lang('Subscribe automatically all users to all forum notifications') => $addUsers,
834
    '' => $myButton,
835
];
836
837
$form->addPanelOption(
838
    'forum',
839
    get_lang('Forum'),
840
    $globalGroup,
841
    'forum.png',
842
    false,
843
    'accordionSettings'
844
);
845
846
// Student publication
847
$group = [
848
    $form->createElement('radio', 'show_score', null, get_lang('New documents are visible for all users'), 0),
849
    $form->createElement('radio', 'show_score', null, get_lang('New documents are only visible for the teacher(s)'), 1),
850
];
851
$group2 = [
852
    $form->createElement('radio', 'student_delete_own_publication', null, get_lang('Yes'), 1),
853
    $form->createElement('radio', 'student_delete_own_publication', null, get_lang('No'), 0),
854
];
855
$myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
856
857
$globalGroup = [
858
    get_lang('Default setting for the visibility of newly posted files') => $group,
859
    get_lang('Allow learners to delete their own publications') => $group2,
860
    '' => $myButton,
861
];
862
863
$form->addPanelOption(
864
    'student-publication',
865
    get_lang('Assignments'),
866
    $globalGroup,
867
    'work.png',
868
    false,
869
    'accordionSettings'
870
);
871
872
$button = Display::toolbarButton(
873
    get_lang('Configure external tools'),
874
    $router->generate('chamilo_lti_configure', ['cid' => $courseId]).'?'.api_get_cidreq(),
875
    'cog',
876
    'primary'
877
);
878
$html = [
879
    $form->createElement('html', '<p>'.get_lang('LTI intro tool').'</p>'.$button),
880
];
881
882
$form->addPanelOption(
883
    'lti_tool',
884
    $translator->trans('External tools'),
885
    $html,
886
    'plugin.png',
887
    false,
888
    'accordionSettings'
889
);*/
890
891
// Plugin course settings
892
//$appPlugin = new AppPlugin();
893
//$appPlugin->add_course_settings_form($form);
894
895
//$form->addHtml('</div>');
896
897
// Set the default values of the form
898
$values = [];
899
$values['title'] = $_course['name'];
900
//$values['category_id'] = $_course['category_id'];
901
$values['course_language'] = $_course['language'];
902
$values['department_name'] = $_course['extLink']['name'];
903
$values['department_url'] = $_course['extLink']['url'];
904
$values['visibility'] = $_course['visibility'];
905
$values['subscribe'] = $_course['subscribe'];
906
$values['unsubscribe'] = $_course['unsubscribe'];
907
$values['course_registration_password'] = $_course['registration_code'];
908
$values['legal'] = $_course['legal'];
909
$values['activate_legal'] = $_course['activate_legal'];
910
$values['show_score'] = $_course['show_score'];
911
912
/*$courseSettings = CourseManager::getCourseSettingVariables($appPlugin);
913
foreach ($courseSettings as $setting) {
914
    $result = api_get_course_setting($setting);
915
    if ('-1' != $result) {
916
        $values[$setting] = $result;
917
    }
918
}*/
919
// make sure new settings have a clear default value
920
if (!isset($values['student_delete_own_publication'])) {
921
    $values['student_delete_own_publication'] = 0;
922
}
923
$form->setDefaults($values);
924
925
// Validate form
926
if ($form->validate()) {
927
    $updateValues = $form->getSubmitValues();
928
929
    $request = Container::getRequest();
930
    /** @var UploadedFile $uploadFile */
931
    $uploadFile = $request->files->get('picture');
932
933
    if (null !== $uploadFile) {
934
        $file = $illustrationRepo->addIllustration(
935
            $courseEntity,
936
            api_get_user_entity(api_get_user_id()),
937
            $uploadFile
938
        );
939
940
        if ($file) {
941
            $file->setCrop($updateValues['picture_crop_result']);
942
            $em->persist($file);
943
            $em->flush();
944
            Event::addEvent(
945
                LOG_COURSE_SETTINGS_CHANGED,
946
                'course_picture',
947
                $uploadFile->getFilename()
948
            );
949
        }
950
    }
951
952
    $visibility = $updateValues['visibility'] ?? '';
953
    $deletePicture = $updateValues['delete_picture'] ?? '';
954
955
    if ($deletePicture) {
956
        $illustrationRepo->deleteIllustration($courseEntity);
957
    }
958
959
    $limitCourses = api_get_configuration_value('hosting_limit_active_courses');
960
    if ($limitCourses > 0) {
961
        $courseInfo = api_get_course_info_by_id($courseId);
962
963
        // Check if
964
        if (COURSE_VISIBILITY_HIDDEN == $courseInfo['visibility'] &&
965
            $visibility != $courseInfo['visibility']
966
        ) {
967
            $num = CourseManager::countActiveCourses($urlId);
968
            if ($num >= $limitCourses) {
969
                api_warn_hosting_contact('hosting_limit_active_courses');
970
971
                Display::addFlash(
972
                    Display::return_message(
973
                        get_lang(
974
                            'Sorry, this installation has an active courses limit, which has now been reached. You can still create new courses, but only if you hide/disable at least one existing active course. To do this, edit a course from the administration courses list, and change the visibility to \'hidden\', then try creating this course again. To increase the maximum number of active courses allowed on this Chamilo installation, please contact your hosting provider or, if available, upgrade to a superior hosting plan.'
975
                        )
976
                    )
977
                );
978
979
                $url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?'.api_get_cidreq();
980
                header("Location: $url");
981
                exit;
982
            }
983
        }
984
    }
985
986
    $pdf_export_watermark_path = isset($_FILES['pdf_export_watermark_path'])
987
        ? $_FILES['pdf_export_watermark_path']
988
        : null;
989
990
    if (!empty($pdf_export_watermark_path['name'])) {
991
        PDF::upload_watermark(
992
            $pdf_export_watermark_path['name'],
993
            $pdf_export_watermark_path['tmp_name'],
994
            $course_code
995
        );
996
        unset($updateValues['pdf_export_watermark_path']);
997
    }
998
999
    $activeLegal = $updateValues['activate_legal'] ?? 0;
1000
1001
    /*$category = null;
1002
    if (!empty($updateValues['category_id'])) {
1003
        $category = $courseCategoryRepo->find($updateValues['category_id']);
1004
    }*/
1005
1006
    $courseEntity
1007
        ->setTitle($updateValues['title'])
1008
        ->setCourseLanguage($updateValues['course_language'])
1009
        //->setCategory($category)
1010
        ->setDepartmentName($updateValues['department_name'])
1011
        ->setDepartmentUrl($updateValues['department_url'])
1012
        ->setVisibility($updateValues['visibility'])
1013
        ->setSubscribe($updateValues['subscribe'])
1014
        ->setUnsubscribe($updateValues['unsubscribe'])
1015
        ->setLegal($updateValues['legal'])
1016
        ->setActivateLegal($activeLegal)
1017
        ->setRegistrationCode($updateValues['course_registration_password'])
1018
    //    ->setShowScore($updateValues['show_score'])
1019
    ;
1020
1021
    $em->persist($courseEntity);
1022
    $em->flush();
1023
1024
    // Insert/Updates course_settings table
1025
    /*foreach ($courseSettings as $setting) {
1026
        $value = isset($updateValues[$setting]) ? $updateValues[$setting] : null;
1027
        CourseManager::saveCourseConfigurationSetting(
1028
            $appPlugin,
1029
            $setting,
1030
            $value,
1031
            api_get_course_int_id()
1032
        );
1033
    }*/
1034
    // update the extra fields
1035
    $courseFieldValue = new ExtraFieldValue('course');
1036
    $courseFieldValue->saveFieldValues($updateValues, true);
1037
1038
    //$appPlugin->saveCourseSettingsHook($updateValues);
1039
    $courseParams = api_get_cidreq();
1040
    $cidReset = true;
1041
    $cidReq = $course_code;
1042
    Display::addFlash(Display::return_message(get_lang('Update successful')));
1043
    $url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?'.$courseParams;
1044
    header("Location: $url");
1045
    exit;
1046
}
1047
1048
if ($show_delete_watermark_text_message) {
1049
    Display::addFlash(
1050
        Display::return_message(get_lang('File deleted'), 'normal')
1051
    );
1052
}
1053
1054
//Template Course Info
1055
$tpl = new Template($nameTools);
1056
1057
Display::display_header($nameTools, 'Settings');
1058
$tpl->assign('course_settings', $form->returnForm());
1059
$courseInfoLayout = $tpl->get_template("course_info/index.html.twig");
1060
$content = $tpl->fetch($courseInfoLayout);
1061
echo $content;
1062
1063
Display::display_footer();
1064