|
29 | 29 | //Ajax request |
30 | 30 | if (isset($_POST['sent_http_request'])) { |
31 | 31 | if (isset($_POST['visibility']) && |
32 | | - $_POST['visibility'] == strval(intval($_POST['visibility'])) && 0 == $_POST['visibility']) { |
| 32 | + $_POST['visibility'] == strval(intval($_POST['visibility'])) && 0 == $_POST['visibility'] |
| 33 | + ) { |
33 | 34 | if (isset($_POST['id']) && $_POST['id'] == strval(intval($_POST['id']))) { |
34 | 35 | if (false == SubLanguageManager::check_if_language_is_used($_POST['id'])) { |
35 | 36 | SubLanguageManager::make_unavailable_language($_POST['id']); |
|
51 | 52 | } |
52 | 53 |
|
53 | 54 | $msgLang = isset($_SESSION['disabled_languages']) ? 1 : 0; |
54 | | -$disabledLang = isset($_SESSION['disabled_languages']) ? $_SESSION['disabled_languages'] : null; |
55 | | - |
56 | | -$htmlHeadXtra[] = '<script> |
57 | | - $(function () { |
58 | | - var msgLang = '.$msgLang.'; |
59 | | - var disabledLang = "'.$disabledLang.'" |
60 | | -
|
61 | | - if (msgLang == 1) { |
62 | | - $("#id_content_message").html("<div class=\"warning-message alert alert-warning\">'.addslashes(get_lang('There are users currently using the following language. Please disable manually.')).' <br /> " + disabledLang + "</div"); |
63 | | - } |
64 | | -
|
65 | | - $("#disable_all_except_default").click(function () { |
66 | | - if(confirm("'.addslashes(get_lang('Please confirm your choice')).'")) { |
67 | | - $.ajax({ |
68 | | - contentType: "application/x-www-form-urlencoded", |
69 | | - beforeSend: function(myObject) { |
70 | | - $("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.addslashes(get_lang('Loading')).'</div>"); |
71 | | - }, |
72 | | - type: "GET", |
73 | | - url: "../admin/languages.php", |
74 | | - data: "action=disable_all_except_default", |
75 | | - success: function(datos) { |
76 | | - window.location.href = "'.api_get_self().'"; |
77 | | - } |
78 | | - }); |
79 | | - } |
80 | | -
|
81 | | - return false; |
82 | | - }); |
83 | | -
|
84 | | - $(".make_visible_and_invisible").click(function(e) { |
85 | | - e.preventDefault(); |
86 | | -
|
87 | | - var id_link_tool = $(this).attr("id"); |
88 | | - var link_id = id_link_tool.split("linktool_")[1]; |
89 | | - var currentIcon = $("#imglinktool_" + link_id); |
90 | | -
|
91 | | - $.ajax({ |
92 | | - type: "POST", |
93 | | - url: "../admin/languages.php", |
94 | | - data: { id: link_id, visibility: currentIcon.hasClass("mdi-toggle-switch") ? 0 : 1, sent_http_request: 1 }, |
95 | | - beforeSend: function() { |
96 | | - $("#id_content_message").html("<div class=\'warning-message alert alert-warning\'><em class=\'fa fa-refresh fa-spin\'></em>'.addslashes(get_lang('Loading')). '...</div>"); |
97 | | - }, |
98 | | - success: function(response) { |
99 | | - if (response === "set_visible" || response === "set_hidden") { |
100 | | - var newIconClass = (response === "set_visible") ? "mdi-toggle-switch" : "mdi-toggle-switch-off"; |
101 | | - var oldIconClass = (response === "set_visible") ? "mdi-toggle-switch-off" : "mdi-toggle-switch"; |
102 | | -
|
103 | | - currentIcon.removeClass(oldIconClass).addClass(newIconClass); |
104 | | - } |
105 | | - } |
106 | | - }); |
107 | | - }); |
108 | | -
|
109 | | - }); |
110 | | -</script>'; |
111 | | - |
112 | | -// unset the msg session variable |
| 55 | +$disabledLang = $msgLang ? (string) $_SESSION['disabled_languages'] : ''; |
113 | 56 | unset($_SESSION['disabled_languages']); |
114 | 57 |
|
115 | | -// setting the table that is needed for the styles management (there is a check if it exists later in this code) |
116 | 58 | $tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE); |
117 | 59 | $tbl_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS); |
118 | 60 |
|
119 | 61 | $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; |
120 | 62 | $url = api_get_self(); |
121 | 63 |
|
122 | | -// we change the availability |
123 | 64 | switch ($action) { |
124 | 65 | case 'makeunavailable': |
125 | 66 | if (!empty($id)) { |
|
128 | 69 | } |
129 | 70 | header("Location: $url"); |
130 | 71 | exit; |
131 | | - break; |
132 | 72 | case 'makeavailable': |
133 | 73 | if (!empty($id)) { |
134 | 74 | SubLanguageManager::make_available_language($id); |
|
148 | 88 | $failedDisabledLanguages = ''; |
149 | 89 | $checkFailed = false; |
150 | 90 | foreach ($allLanguages as $language) { |
151 | | - if (false == SubLanguageManager::check_if_language_is_used($language['id'])) { |
152 | | - SubLanguageManager::make_unavailable_language($language['id']); |
| 91 | + if (false == SubLanguageManager::check_if_language_is_used((int) $language['id'])) { |
| 92 | + SubLanguageManager::make_unavailable_language((int) $language['id']); |
153 | 93 | } else { |
154 | | - if (intval(SubLanguageManager::get_platform_language_id()) !== intval($language['id'])) { |
| 94 | + if ((int) SubLanguageManager::get_platform_language_id() !== (int) $language['id']) { |
155 | 95 | $failedDisabledLanguages .= ' - '.$language['english_name'].'<br />'; |
156 | 96 | $checkFailed = true; |
157 | 97 | } |
|
164 | 104 | Display::addFlash(Display::return_message(get_lang('Update successful'), 'success')); |
165 | 105 | header("Location: $url"); |
166 | 106 | exit; |
167 | | - break; |
168 | 107 | case 'make_unavailable_confirmed': |
169 | 108 | $language_info = SubLanguageManager::get_all_information_of_language($id); |
170 | | - if (1 == $language_info['available']) { |
| 109 | + if ($language_info && 1 == (int) $language_info['available']) { |
171 | 110 | SubLanguageManager::make_unavailable_language($id); |
172 | 111 | $platform_language = api_get_setting('platformLanguage'); |
173 | 112 | UserManager::update_all_user_languages($language_info['english_name'], $platform_language); |
174 | | - Display::addFlash(Display::return_message(get_lang('The language has been hidden. It will not be possible to use it until it becomes visible again.'), 'confirm')); |
| 113 | + Display::addFlash( |
| 114 | + Display::return_message( |
| 115 | + get_lang('The language has been hidden. It will not be possible to use it until it becomes visible again.'), |
| 116 | + 'confirm' |
| 117 | + ) |
| 118 | + ); |
175 | 119 | header("Location: $url"); |
176 | 120 | exit; |
177 | 121 | } |
178 | 122 | break; |
179 | 123 | } |
180 | 124 |
|
181 | 125 | if (isset($_POST['Submit']) && $_POST['Submit']) { |
182 | | - // changing the name |
183 | 126 | $name = html_filter($_POST['txt_name']); |
184 | 127 | $postId = (int) $_POST['edit_id']; |
185 | 128 | Database::update( |
186 | 129 | $tbl_admin_languages, |
187 | 130 | ['original_name' => $name], |
188 | 131 | ['id = ?' => $postId] |
189 | 132 | ); |
190 | | - // changing the Platform language |
191 | 133 | if (isset($_POST['platformlanguage']) && '' != $_POST['platformlanguage']) { |
192 | 134 | api_set_setting('platformLanguage', $_POST['platformlanguage'], null, null, api_get_current_access_url_id()); |
193 | 135 | header("Location: $url"); |
|
196 | 138 | } elseif (isset($_POST['action'])) { |
197 | 139 | switch ($_POST['action']) { |
198 | 140 | case 'makeavailable': |
199 | | - if (count($_POST['id']) > 0) { |
200 | | - $ids = []; |
201 | | - foreach ($_POST['id'] as $index => $id) { |
202 | | - $ids[] = intval($id); |
| 141 | + if (!empty($_POST['id'])) { |
| 142 | + $ids = array_map('intval', (array) $_POST['id']); |
| 143 | + if ($ids) { |
| 144 | + $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('".implode("','", $ids)."')"; |
| 145 | + Database::query($sql); |
203 | 146 | } |
204 | | - $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('".implode("','", $ids)."')"; |
205 | | - Database::query($sql); |
206 | 147 | header("Location: $url"); |
207 | 148 | exit; |
208 | 149 | } |
209 | 150 | break; |
210 | 151 | case 'makeunavailable': |
211 | | - if (count($_POST['id']) > 0) { |
212 | | - $ids = []; |
213 | | - foreach ($_POST['id'] as $index => $id) { |
214 | | - $ids[] = intval($id); |
| 152 | + if (!empty($_POST['id'])) { |
| 153 | + $ids = array_map('intval', (array) $_POST['id']); |
| 154 | + if ($ids) { |
| 155 | + $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')"; |
| 156 | + Database::query($sql); |
215 | 157 | } |
216 | | - $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')"; |
217 | | - Database::query($sql); |
218 | 158 | header("Location: $url"); |
219 | 159 | exit; |
220 | 160 | } |
221 | 161 | break; |
222 | 162 | } |
223 | 163 | } |
224 | 164 |
|
225 | | -// setting the name of the tool |
226 | 165 | $tool_name = get_lang('Chamilo Portal Languages'); |
227 | 166 |
|
228 | | -// setting breadcrumbs |
229 | 167 | $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')]; |
230 | 168 |
|
231 | | -// displaying the explanation for this tool |
232 | | -Display::addFlash(Display::return_message(get_lang('This tool manages the language selection menu on the login page. As a platform administrator you can decide which languages should be available for your users.'), 'normal')); |
| 169 | +Display::addFlash( |
| 170 | + Display::return_message( |
| 171 | + get_lang('This tool manages the language selection menu on the login page. As a platform administrator you can decide which languages should be available for your users.') |
| 172 | + ) |
| 173 | +); |
| 174 | + |
| 175 | +$htmlHeadXtra[] = '<script> |
| 176 | +$(function () { |
| 177 | + var msgLang = '. $msgLang .'; |
| 178 | + var disabledLang = "'.addslashes($disabledLang).'"; |
| 179 | +
|
| 180 | + if (msgLang === 1) { |
| 181 | + $("#id_content_message").html("<div class=\"warning-message alert alert-warning\">'.addslashes(get_lang('There are users currently using the following language. Please disable manually.')).'<br />" + disabledLang + "</div>"); |
| 182 | + } |
| 183 | +
|
| 184 | + $("#disable_all_except_default").on("click", function () { |
| 185 | + if (confirm("'.addslashes(get_lang('Please confirm your choice')).'")) { |
| 186 | + $.ajax({ |
| 187 | + contentType: "application/x-www-form-urlencoded", |
| 188 | + beforeSend: function() { |
| 189 | + $("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.addslashes(get_lang('Loading')).'</div>"); |
| 190 | + }, |
| 191 | + type: "GET", |
| 192 | + url: "'.api_get_self().'", |
| 193 | + data: { action: "disable_all_except_default" }, |
| 194 | + success: function() { |
| 195 | + window.location.href = "'.api_get_self().'"; |
| 196 | + } |
| 197 | + }); |
| 198 | + } |
| 199 | + return false; |
| 200 | + }); |
| 201 | +
|
| 202 | + $(".make_visible_and_invisible").on("click", function (e) { |
| 203 | + e.preventDefault(); |
| 204 | + var $link = $(this); |
| 205 | + var id = parseInt($link.data("id"), 10); |
| 206 | + var available = parseInt($link.data("available"), 10); |
| 207 | + var nextVisibility = available ? 0 : 1; |
| 208 | + var $icon = $("#imglinktool_" + id); |
| 209 | +
|
| 210 | + $.ajax({ |
| 211 | + type: "POST", |
| 212 | + url: "../admin/languages.php", |
| 213 | + data: { id: id, visibility: nextVisibility, sent_http_request: 1 }, |
| 214 | + beforeSend: function () { |
| 215 | + $("#id_content_message").html("<div class=\'warning-message alert alert-warning\'><em class=\'fa fa-refresh fa-spin\'></em> '.addslashes(get_lang('Loading')).'...</div>"); |
| 216 | + }, |
| 217 | + success: function (response) { |
| 218 | + if (response === "set_visible" || response === "set_hidden") { |
| 219 | + var nowAvailable = response === "set_visible" ? 1 : 0; |
| 220 | + $link.data("available", nowAvailable); |
| 221 | +
|
| 222 | + if (nowAvailable === 1) { |
| 223 | + $icon.removeClass("ch-tool-icon-disabled"); |
| 224 | + } else { |
| 225 | + $icon.addClass("ch-tool-icon-disabled"); |
| 226 | + } |
| 227 | +
|
| 228 | + $("#id_content_message").html("<div class=\'alert alert-success\'>'.addslashes(get_lang('Update successful')).'</div>"); |
| 229 | + } else if (typeof response === "string" && response.indexOf("confirm:") === 0) { |
| 230 | + window.location.href = "'.api_get_self().'?action=make_unavailable_confirmed&id=" + id; |
| 231 | + } |
| 232 | + } |
| 233 | + }); |
| 234 | + }); |
| 235 | +}); |
| 236 | +</script>'; |
233 | 237 |
|
234 | | -// including the header file (which includes the banner itself) |
235 | 238 | Display::display_header($tool_name); |
236 | 239 |
|
237 | 240 | echo '<a id="disable_all_except_default" href="javascript:void(0)" class="btn btn--primary"> |
238 | 241 | <em class="fa fa-eye"></em> '.get_lang('Disable all languages except the platform default').'</a><br /><br />'; |
239 | 242 |
|
240 | | -// selecting all the languages |
241 | 243 | $sql_select = "SELECT * FROM $tbl_admin_languages"; |
242 | 244 | $result_select = Database::query($sql_select); |
243 | 245 | $currentLanguage = api_get_setting('language.platform_language'); |
244 | 246 |
|
245 | | -// the table data |
246 | 247 | $language_data = []; |
247 | 248 | while ($row = Database::fetch_array($result_select)) { |
248 | 249 | $row_td = []; |
249 | 250 | $row_td[] = $row['id']; |
250 | 251 | $checked = ''; |
251 | | - // the first column is the original name of the language OR a form containing the original name |
| 252 | + |
252 | 253 | if ('edit' == $action && $row['id'] == $id) { |
253 | 254 | if ($row['english_name'] == api_get_setting('platformLanguage')) { |
254 | 255 | $checked = ' checked="checked" '; |
|
257 | 258 | $row_td[] = ' |
258 | 259 | <input type="hidden" name="edit_id" value="'.$id.'" /> |
259 | 260 | <input type="text" name="txt_name" value="'.$row['original_name'].'" /> |
260 | | - <input type="checkbox" '.$checked.'name="platformlanguage" id="platformlanguage" value="'.$row['english_name'].'" /> |
| 261 | + <input type="checkbox" '.$checked.' name="platformlanguage" id="platformlanguage" value="'.$row['english_name'].'" /> |
261 | 262 | <label for="platformlanguage">'.$row['original_name'].' '.get_lang('as platformlanguage').'</label> |
262 | 263 | <input type="submit" name="Submit" value="'.get_lang('Validate').'" /> |
263 | 264 | <a name="value" />'; |
264 | 265 | } else { |
265 | 266 | $row_td[] = $row['original_name']; |
266 | 267 | } |
267 | 268 |
|
268 | | - // the second column |
269 | 269 | $row_td[] = $row['english_name'].' ('.$row['isocode'].')'; |
270 | 270 |
|
271 | 271 | if ($row['isocode'] == $currentLanguage) { |
272 | | - $setplatformlanguage = Display::getMdiIcon(ToolIcon::TRANSLATION, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Current portal\'s language')); |
| 272 | + $setplatformlanguage = Display::getMdiIcon( |
| 273 | + ToolIcon::TRANSLATION, |
| 274 | + 'ch-tool-icon', |
| 275 | + null, |
| 276 | + ICON_SIZE_SMALL, |
| 277 | + get_lang('Current portal\'s language') |
| 278 | + ); |
273 | 279 | } else { |
| 280 | + $confirmSet = addslashes(get_lang('Are you sure you want to set this language as the portal\'s default?')); |
274 | 281 | $setplatformlanguage = |
275 | | - "<a href=\"javascript:if (confirm('".addslashes(get_lang('Are you sure you want to set this language as the portal\'s default?'))."')) { location.href='".api_get_self()."?action=setplatformlanguage&id=".$row['id']."'; }\">". |
| 282 | + "<a href=\"javascript:if (confirm('".$confirmSet."')) { location.href='".api_get_self()."?action=setplatformlanguage&id=".$row['id']."'; }\">". |
276 | 283 | Display::getMdiIcon(ToolIcon::TRANSLATION, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Set language as default'))."</a>"; |
277 | 284 | } |
278 | 285 |
|
|
303 | 310 | $row_td[] = Display::getMdiIcon(StateIcon::ACTIVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Visible')). |
304 | 311 | "<a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>". |
305 | 312 | Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit'))."</a> |
306 | | - ".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language; |
| 313 | + ".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language; |
307 | 314 | } else { |
308 | | - $action = ($row['available'] == 1) ? 'makeunavailable' : 'makeavailable'; |
309 | 315 | $icon = ($row['available'] == 1) ? StateIcon::ACTIVE : StateIcon::INACTIVE; |
310 | 316 | $tooltip = ($row['available'] == 1) ? get_lang('Make unavailable') : get_lang('Make available'); |
311 | 317 |
|
312 | | - $row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=$action&id=".$row['id']."'>". |
| 318 | + $row_td[] = "<a class=\"make_visible_and_invisible\" |
| 319 | + id=\"linktool_".$row['id']."\" |
| 320 | + href=\"".api_get_self()."?action=".(($row['available']==1)?'makeunavailable':'makeavailable')."&id=".$row['id']."\" |
| 321 | + data-id=\"".$row['id']."\" |
| 322 | + data-available=\"".$row['available']."\">". |
313 | 323 | Display::getMdiIcon($icon, 'ch-tool-icon', null, ICON_SIZE_SMALL, $tooltip, ['id' => 'imglinktool_'.$row['id']])."</a> |
314 | 324 | <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit'))."</a> |
315 | 325 | ".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language; |
|
0 commit comments