$arySorted) foreach ($aryData as $aryOriginal) // if the key matches if ($aryOriginal[$strIndex]==$arySortKey) // add it to the output array array_push($aryResult, $aryOriginal); // return the return return $aryResult; } function write_lang() { global $path_to_root, $installed_languages; include_once($path_to_root . "/lang/installed_languages.inc"); $conn = array_natsort($installed_languages, 'code', 'code'); $installed_languages = $conn; //reset($installed_languages); $n = count($installed_languages); $msg = " ')\n"; $msg .= "-- 'code' should match the name of the directory for the language under \\lang\n"; $msg .= "-- 'name' is the name that will be displayed in the language selection list (in Users and Display Setup)\n"; $msg .= "-- 'rtl' only needs to be set for right-to-left languages like Arabic and Hebrew\n\n"; $msg .= "*/\n\n\n"; $msg .= "\$installed_languages = array (\n"; $msg .= "\t0 => "; for ($i = 0; $i < $n; $i++) { if ($i > 0) $msg .= "\t\tarray "; else $msg .= "array "; $msg .= "('code' => '" . $installed_languages[$i]['code'] . "', "; $msg .= "'name' => '" . $installed_languages[$i]['name'] . "', "; $msg .= "'encoding' => '" . $installed_languages[$i]['encoding'] . "'"; if (isset($installed_languages[$i]['rtl']) && $installed_languages[$i]['rtl']) $msg .= ", 'rtl' => true),\n"; else $msg .= "),\n"; } $msg .= "\t);\n?>"; $filename = $path_to_root . "/lang/installed_languages.inc"; // Check if the file exists and is writable first. if (file_exists($filename) && is_writable($filename)) { if (!$zp = fopen($filename, 'w')) { display_error(_("Cannot open the languages file - ") . $filename); return false; } else { if (!fwrite($zp, $msg)) { display_error(_("Cannot write to the language file - ") . $filename); fclose($zp); return false; } // Close file fclose($zp); } } else { display_error(_("The language file ") . $filename . _(" is not writable. Change its permissions so it is, then re-run the operation.")); return false; } return true; } //--------------------------------------------------------------------------------------------- function handle_submit() { global $path_to_root, $installed_languages; if (!check_data()) return false; $id = $_GET['id']; $installed_languages[$id]['code'] = $_POST['code']; $installed_languages[$id]['name'] = $_POST['name']; $installed_languages[$id]['encoding'] = $_POST['encoding']; $installed_languages[$id]['rtl'] = (bool)$_POST['rtl']; if (!write_lang()) return false; $directory = $path_to_root . "/lang/" . $_POST['code']; if (!file_exists($directory)) { mkdir($directory); mkdir($directory . "/LC_MESSAGES"); } if (is_uploaded_file($_FILES['uploadfile']['tmp_name'])) { $file1 = $_FILES['uploadfile']['tmp_name']; $file2 = $directory . "/LC_MESSAGES/".$_POST['code'].".mo"; if (file_exists($file2)) unlink($file2); move_uploaded_file($file1, $file2); } return true; } //--------------------------------------------------------------------------------------------- function handle_delete() { global $path_to_root, $installed_languages; $id = $_GET['id']; $lang = $installed_languages[$id]['code']; $filename = "$path_to_root/lang/$lang/LC_MESSAGES"; if ($h = opendir($filename)) { while (($file = readdir($h)) !== false) { if (is_file("$filename/$file")) unlink("$filename/$file"); } closedir($h); } rmdir($filename); $filename = "$path_to_root/lang/$lang"; if ($h = opendir($filename)) { while (($file = readdir($h)) !== false) { if (is_file("$filename/$file")) unlink("$filename/$file"); } closedir($h); } rmdir($filename); unset($installed_languages[$id]); $conn = array_values($installed_languages); $installed_languages = $conn; //$$db_connections = array_values($db_connections); if (!write_lang()) return; meta_forward($_SERVER['PHP_SELF']); } //--------------------------------------------------------------------------------------------- function display_languages() { global $table_style, $installed_languages; $lang = $_SESSION["language"]->code; echo " "; start_table($table_style); $th = array(_("Language"), _("Name"), _("Encoding"), _("Right To Left"), "", ""); table_header($th); $k = 0; $conn = $installed_languages; $n = count($conn); for ($i = 0; $i < $n; $i++) { if ($conn[$i]['code'] == $lang) start_row("class='stockmankobg'"); else alt_table_row_color($k); label_cell($conn[$i]['code']); label_cell($conn[$i]['name']); label_cell($conn[$i]['encoding']); if (isset($conn[$i]['rtl']) && $conn[$i]['rtl']) $rtl = _("Yes"); else $rtl = _("No"); label_cell($rtl); edit_link_cell("selected_id=" . $i); if ($conn[$i]['code'] != $lang) label_cell("" . _("Delete") . ""); end_row(); } end_table(); display_note(_("The marked language is the current language which cannot be deleted."), 0, 0, "class='currentfg'"); } //--------------------------------------------------------------------------------------------- function display_language_edit($selected_id) { global $installed_languages, $table_style2; if ($selected_id != -1) $n = $selected_id; else $n = count($installed_languages); start_form(true, true); echo " "; start_table($table_style2); if ($selected_id != -1) { $conn = $installed_languages[$selected_id]; $_POST['code'] = $conn['code']; $_POST['name'] = $conn['name']; $_POST['encoding'] = $conn['encoding']; if (isset($conn['rtl'])) $_POST['rtl'] = $conn['rtl']; else $_POST['rtl'] = false; hidden('selected_id', $selected_id); } text_row_ex(_("Language"), 'code', 20); text_row_ex(_("Name"), 'name', 20); text_row_ex(_("Encoding"), 'encoding', 20); yesno_list_row(_("Right To Left"), 'rtl', null, "", "", false); label_row(_("Language File"), ""); end_table(0); display_note(_("Select your language MO file from your local harddisk."), 0, 1); echo "
"; end_form(); } //--------------------------------------------------------------------------------------------- if (isset($_GET['c'])) { if ($_GET['c'] == 'df') { handle_delete(); } if ($_GET['c'] == 'u') { if (handle_submit()) { //meta_forward($_SERVER['PHP_SELF']); } } } //--------------------------------------------------------------------------------------------- display_languages(); hyperlink_no_params($_SERVER['PHP_SELF'], _("Create a new language")); display_language_edit($selected_id); //--------------------------------------------------------------------------------------------- end_page(); ?>