5 include_once($path_to_root . "/includes/session.inc");
7 page(_("Install/Update Languages"));
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/admin/db/company_db.inc");
11 include_once($path_to_root . "/admin/db/maintenance_db.inc");
12 include_once($path_to_root . "/includes/ui.inc");
14 //---------------------------------------------------------------------------------------------
16 if (isset($_GET['selected_id']))
18 $selected_id = $_GET['selected_id'];
20 elseif (isset($_POST['selected_id']))
22 $selected_id = $_POST['selected_id'];
27 //---------------------------------------------------------------------------------------------
35 * @return Returns the array sorted as required
36 * @param $aryData Array containing data to sort
37 * @param $strIndex name of column to use as an index
38 * @param $strSortBy Column to sort the array by
39 * @param $strSortType String containing either asc or desc [default to asc]
40 * @desc Naturally sorts an array using by the column $strSortBy
42 function array_natsort($aryData, $strIndex, $strSortBy, $strSortType=false)
44 // if the parameters are invalid
45 if (!is_array($aryData) || !$strIndex || !$strSortBy)
49 // create our temporary arrays
50 $arySort = $aryResult = array();
52 // loop through the array
53 foreach ($aryData as $aryRow)
54 // set up the value in the array
55 $arySort[$aryRow[$strIndex]] = $aryRow[$strSortBy];
57 // apply the natural sort
60 // if the sort type is descending
61 if ($strSortType=="desc")
65 // loop through the sorted and original data
66 foreach ($arySort as $arySortKey => $arySorted)
67 foreach ($aryData as $aryOriginal)
69 if ($aryOriginal[$strIndex]==$arySortKey)
70 // add it to the output array
71 array_push($aryResult, $aryOriginal);
79 global $path_to_root, $installed_languages;
80 include_once($path_to_root . "/lang/installed_languages.inc");
82 $conn = array_natsort($installed_languages, 'code', 'code');
83 $installed_languages = $conn;
84 //reset($installed_languages);
85 $n = count($installed_languages);
88 $msg .= "/* How to make new entries here\n\n";
89 $msg .= "-- if adding languages at the beginning of the list, make sure it's index is set to 0 (it has ' 0 => ')\n";
90 $msg .= "-- 'code' should match the name of the directory for the language under \\lang\n";
91 $msg .= "-- 'name' is the name that will be displayed in the language selection list (in Users and Display Setup)\n";
92 $msg .= "-- 'rtl' only needs to be set for right-to-left languages like Arabic and Hebrew\n\n";
95 $msg .= "\$installed_languages = array (\n";
97 for ($i = 0; $i < $n; $i++)
100 $msg .= "\t\tarray ";
103 $msg .= "('code' => '" . $installed_languages[$i]['code'] . "', ";
104 $msg .= "'name' => '" . $installed_languages[$i]['name'] . "', ";
105 $msg .= "'encoding' => '" . $installed_languages[$i]['encoding'] . "'";
106 if (isset($installed_languages[$i]['rtl']) && $installed_languages[$i]['rtl'])
107 $msg .= ", 'rtl' => true),\n";
113 $filename = $path_to_root . "/lang/installed_languages.inc";
114 // Check if the file exists and is writable first.
115 if (file_exists($filename) && is_writable($filename))
117 if (!$zp = fopen($filename, 'w'))
119 display_error(_("Cannot open the languages file - ") . $filename);
124 if (!fwrite($zp, $msg))
126 display_error(_("Cannot write to the language file - ") . $filename);
136 display_error(_("The language file ") . $filename . _(" is not writable. Change its permissions so it is, then re-run the operation."));
142 //---------------------------------------------------------------------------------------------
144 function handle_submit()
146 global $path_to_root, $installed_languages;
153 $installed_languages[$id]['code'] = $_POST['code'];
154 $installed_languages[$id]['name'] = $_POST['name'];
155 $installed_languages[$id]['encoding'] = $_POST['encoding'];
156 $installed_languages[$id]['rtl'] = (bool)$_POST['rtl'];
159 $directory = $path_to_root . "/lang/" . $_POST['code'];
160 if (!file_exists($directory))
163 mkdir($directory . "/LC_MESSAGES");
165 if (is_uploaded_file($_FILES['uploadfile']['tmp_name']))
167 $file1 = $_FILES['uploadfile']['tmp_name'];
168 $file2 = $directory . "/LC_MESSAGES/".$_POST['code'].".po";
169 if (file_exists($file2))
171 move_uploaded_file($file1, $file2);
173 if (is_uploaded_file($_FILES['uploadfile2']['tmp_name']))
175 $file1 = $_FILES['uploadfile2']['tmp_name'];
176 $file2 = $directory . "/LC_MESSAGES/".$_POST['code'].".mo";
177 if (file_exists($file2))
179 move_uploaded_file($file1, $file2);
184 //---------------------------------------------------------------------------------------------
186 function handle_delete()
188 global $path_to_root, $installed_languages;
192 $lang = $installed_languages[$id]['code'];
193 $filename = "$path_to_root/lang/$lang/LC_MESSAGES";
194 if ($h = opendir($filename))
196 while (($file = readdir($h)) !== false)
198 if (is_file("$filename/$file"))
199 unlink("$filename/$file");
204 $filename = "$path_to_root/lang/$lang";
205 if ($h = opendir($filename))
207 while (($file = readdir($h)) !== false)
209 if (is_file("$filename/$file"))
210 unlink("$filename/$file");
216 unset($installed_languages[$id]);
217 $conn = array_values($installed_languages);
218 $installed_languages = $conn;
220 //$$db_connections = array_values($db_connections);
224 meta_forward($_SERVER['PHP_SELF']);
227 //---------------------------------------------------------------------------------------------
229 function display_languages()
231 global $table_style, $installed_languages;
233 $lang = $_SESSION["language"]->code;
236 <script language='javascript'>
237 function deleteLanguage(id) {
238 if (!confirm('" . _("Are you sure you want to delete language no. ") . "'+id))
240 document.location.replace('inst_lang.php?c=df&id='+id)
243 start_table($table_style);
244 $th = array(_("Language"), _("Name"), _("Encoding"), _("Right To Left"), "", "");
248 $conn = $installed_languages;
250 for ($i = 0; $i < $n; $i++)
252 if ($conn[$i]['code'] == $lang)
253 start_row("class='stockmankobg'");
255 alt_table_row_color($k);
257 label_cell($conn[$i]['code']);
258 label_cell($conn[$i]['name']);
259 label_cell($conn[$i]['encoding']);
260 if (isset($conn[$i]['rtl']) && $conn[$i]['rtl'])
265 edit_link_cell("selected_id=" . $i);
266 if ($conn[$i]['code'] != $lang)
267 label_cell("<a href='javascript:deleteLanguage(" . $i . ")'>" . _("Delete") . "</a>");
272 display_note(_("The marked language is the current language which cannot be deleted."), 0, 0, "class='currentfg'");
275 //---------------------------------------------------------------------------------------------
277 function display_language_edit($selected_id)
279 global $installed_languages, $table_style2;
281 if ($selected_id != -1)
284 $n = count($installed_languages);
286 start_form(true, true);
289 <script language='javascript'>
290 function updateLanguage() {
291 document.forms[0].action='inst_lang.php?c=u&id=" . $n . "'
292 document.forms[0].submit()
296 start_table($table_style2);
298 if ($selected_id != -1)
300 $conn = $installed_languages[$selected_id];
301 $_POST['code'] = $conn['code'];
302 $_POST['name'] = $conn['name'];
303 $_POST['encoding'] = $conn['encoding'];
304 if (isset($conn['rtl']))
305 $_POST['rtl'] = $conn['rtl'];
307 $_POST['rtl'] = false;
308 hidden('selected_id', $selected_id);
310 text_row_ex(_("Language"), 'code', 20);
311 text_row_ex(_("Name"), 'name', 20);
312 text_row_ex(_("Encoding"), 'encoding', 20);
314 yesno_list_row(_("Right To Left"), 'rtl', null, "", "", false);
316 label_row(_("Language File") . " (PO)", "<input name='uploadfile' type='file'>");
317 label_row(_("Language File") . " (MO)", "<input name='uploadfile2' type='file'>");
320 display_note(_("Select your language files from your local harddisk."), 0, 1);
321 echo "<center><input onclick='javascript:updateLanguage()' type='button' style='width:150' value='". _("Save"). "'>";
328 //---------------------------------------------------------------------------------------------
330 if (isset($_GET['c']))
332 if ($_GET['c'] == 'df')
337 if ($_GET['c'] == 'u')
341 //meta_forward($_SERVER['PHP_SELF']);
346 //---------------------------------------------------------------------------------------------
350 hyperlink_no_params($_SERVER['PHP_SELF'], _("Create a new language"));
352 display_language_edit($selected_id);
354 //---------------------------------------------------------------------------------------------