1 | <?php |
||
2 | /* For license terms, see /license.txt */ |
||
3 | |||
4 | /** |
||
5 | * Create new Services for the Buy Courses plugin. |
||
6 | * |
||
7 | * @package chamilo.plugin.buycourses |
||
8 | */ |
||
9 | $cidReset = true; |
||
10 | |||
11 | require_once '../../../main/inc/global.inc.php'; |
||
12 | |||
13 | $serviceId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null; |
||
14 | |||
15 | if (!$serviceId) { |
||
0 ignored issues
–
show
|
|||
16 | header('Location: list.php'); |
||
17 | exit; |
||
18 | } |
||
19 | |||
20 | $plugin = BuyCoursesPlugin::create(); |
||
21 | $currency = $plugin->getSelectedCurrency(); |
||
22 | $users = UserManager::getRepository()->findAll(); |
||
23 | $userOptions = []; |
||
24 | if (!empty($users)) { |
||
25 | foreach ($users as $user) { |
||
26 | $userOptions[$user->getId()] = $user->getCompleteNameWithUsername(); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | api_protect_admin_script(true); |
||
31 | $htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css'); |
||
32 | $htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js'); |
||
33 | |||
34 | //view |
||
35 | $interbreadcrumb[] = [ |
||
36 | 'url' => 'list.php', |
||
37 | 'name' => $plugin->get_lang('Configuration'), |
||
38 | ]; |
||
39 | |||
40 | $globalSettingsParams = $plugin->getGlobalParameters(); |
||
41 | $service = $plugin->getService($serviceId); |
||
42 | |||
43 | $formDefaultValues = [ |
||
44 | 'name' => $service['name'], |
||
45 | 'description' => $service['description'], |
||
46 | 'price' => $service['price'], |
||
47 | 'tax_perc' => $service['tax_perc'], |
||
48 | 'duration_days' => $service['duration_days'], |
||
49 | 'owner_id' => intval($service['owner_id']), |
||
50 | 'applies_to' => intval($service['applies_to']), |
||
51 | 'visibility' => ($service['visibility'] == 1) ? true : false, |
||
52 | 'image' => is_file(api_get_path(SYS_PLUGIN_PATH).'buycourses/uploads/services/images/simg-'.$serviceId.'.png') |
||
53 | ? api_get_path(WEB_PLUGIN_PATH).'buycourses/uploads/services/images/simg-'.$serviceId.'.png' |
||
54 | : api_get_path(WEB_CODE_PATH).'img/session_default.png', |
||
55 | 'video_url' => $service['video_url'], |
||
56 | 'service_information' => $service['service_information'], |
||
57 | ]; |
||
58 | |||
59 | $form = new FormValidator('Services'); |
||
60 | $form->addText('name', $plugin->get_lang('ServiceName')); |
||
61 | $form->addHtmlEditor('description', $plugin->get_lang('Description')); |
||
62 | $form->addElement( |
||
63 | 'number', |
||
64 | 'price', |
||
65 | [$plugin->get_lang('Price'), null, $currency['iso_code']], |
||
66 | ['step' => 0.01] |
||
67 | ); |
||
68 | $form->addElement( |
||
69 | 'number', |
||
70 | 'tax_perc', |
||
71 | [$plugin->get_lang('TaxPerc'), $plugin->get_lang('TaxPercDescription'), '%'], |
||
72 | ['step' => 1, 'placeholder' => $globalSettingsParams['global_tax_perc'].'% '.$plugin->get_lang('ByDefault')] |
||
73 | ); |
||
74 | $form->addElement( |
||
75 | 'number', |
||
76 | 'duration_days', |
||
77 | [$plugin->get_lang('Duration'), null, get_lang('Days')], |
||
78 | ['step' => 1] |
||
79 | ); |
||
80 | $form->addElement( |
||
81 | 'radio', |
||
82 | 'applies_to', |
||
83 | $plugin->get_lang('AppliesTo'), |
||
84 | get_lang('None'), |
||
85 | 0 |
||
86 | ); |
||
87 | $form->addElement( |
||
88 | 'radio', |
||
89 | 'applies_to', |
||
90 | null, |
||
91 | get_lang('User'), |
||
92 | 1 |
||
93 | ); |
||
94 | $form->addElement( |
||
95 | 'radio', |
||
96 | 'applies_to', |
||
97 | null, |
||
98 | get_lang('Course'), |
||
99 | 2 |
||
100 | ); |
||
101 | $form->addElement( |
||
102 | 'radio', |
||
103 | 'applies_to', |
||
104 | null, |
||
105 | get_lang('Session'), |
||
106 | 3 |
||
107 | ); |
||
108 | $form->addElement( |
||
109 | 'radio', |
||
110 | 'applies_to', |
||
111 | null, |
||
112 | get_lang('TemplateTitleCertificate'), |
||
113 | 4 |
||
114 | ); |
||
115 | $form->addSelect( |
||
116 | 'owner_id', |
||
117 | get_lang('Owner'), |
||
118 | $userOptions |
||
119 | ); |
||
120 | $form->addCheckBox('visibility', $plugin->get_lang('VisibleInCatalog')); |
||
121 | $form->addFile( |
||
122 | 'picture', |
||
123 | $formDefaultValues['image'] != '' ? get_lang('UpdateImage') : get_lang('AddImage'), |
||
124 | ['id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '16 / 9'] |
||
125 | ); |
||
126 | $form->addText('video_url', get_lang('VideoUrl'), false); |
||
127 | $form->addHtmlEditor('service_information', $plugin->get_lang('ServiceInformation'), false); |
||
128 | $form->addHidden('id', $serviceId); |
||
129 | $form->addButtonSave(get_lang('Edit')); |
||
130 | $form->addHtml('<br /><br /><br /><br />'); |
||
131 | $form->addButtonDelete($plugin->get_lang('DeleteThisService'), 'delete_service'); |
||
132 | $form->setDefaults($formDefaultValues); |
||
133 | if ($form->validate()) { |
||
134 | $values = $form->getSubmitValues(); |
||
135 | |||
136 | if (isset($values['delete_service'])) { |
||
137 | $plugin->deleteService($serviceId); |
||
138 | Display::addFlash( |
||
139 | Display::return_message($plugin->get_lang('ServiceDeleted'), 'error') |
||
140 | ); |
||
141 | } else { |
||
142 | $plugin->updateService($values, $serviceId); |
||
143 | Display::addFlash( |
||
144 | Display::return_message($plugin->get_lang('ServiceEdited'), 'success') |
||
145 | ); |
||
146 | } |
||
147 | header('Location: list.php'); |
||
148 | exit; |
||
149 | } |
||
150 | |||
151 | $templateName = $plugin->get_lang('EditService'); |
||
152 | $tpl = new Template($templateName); |
||
153 | |||
154 | $tpl->assign('header', $templateName); |
||
155 | $tpl->assign('content', $form->returnForm()); |
||
156 | $tpl->display_one_col_template(); |
||
157 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: