2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_CREATELANGUAGE';
14 include_once($path_to_root . "/includes/session.inc");
16 page(_("Install/Update Languages"));
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/admin/db/company_db.inc");
20 include_once($path_to_root . "/admin/db/maintenance_db.inc");
21 include_once($path_to_root . "/includes/ui.inc");
23 //---------------------------------------------------------------------------------------------
25 if (isset($_GET['selected_id']))
27 $selected_id = $_GET['selected_id'];
29 elseif (isset($_POST['selected_id']))
31 $selected_id = $_POST['selected_id'];
36 //---------------------------------------------------------------------------------------------
40 if ($_POST['code'] == "" || $_POST['name'] == "" || $_POST['encoding'] == "") {
41 display_error(_("Language name, code nor encoding cannot be empty"));
49 global $path_to_root, $installed_languages, $dflt_lang;
50 include_once($path_to_root . "/lang/installed_languages.inc");
52 $conn = array_natsort($installed_languages, 'code', 'code');
53 $installed_languages = $conn;
54 //reset($installed_languages);
55 $n = count($installed_languages);
58 $msg .= "/* How to make new entries here\n\n";
59 $msg .= "-- if adding languages at the beginning of the list, make sure it's index is set to 0 (it has ' 0 => ')\n";
60 $msg .= "-- 'code' should match the name of the directory for the language under \\lang\n";
61 $msg .= "-- 'name' is the name that will be displayed in the language selection list (in Users and Display Setup)\n";
62 $msg .= "-- 'rtl' only needs to be set for right-to-left languages like Arabic and Hebrew\n\n";
65 $msg .= "\$installed_languages = array (\n";
68 for ($i = 0; $i < $n; $i++)
74 $msg .= "('code' => '" . $installed_languages[$i]['code'] . "', ";
75 $msg .= "'name' => '" . $installed_languages[$i]['name'] . "', ";
76 $msg .= "'encoding' => '" . $installed_languages[$i]['encoding'] . "'";
77 if (isset($installed_languages[$i]['rtl']) && $installed_languages[$i]['rtl'])
78 $msg .= ", 'rtl' => true),\n";
84 $msg .= "\n\$dflt_lang = '$dflt_lang';\n?>\n";
86 $filename = $path_to_root . "/lang/installed_languages.inc";
87 // Check if the file exists and is writable first.
88 if (file_exists($filename) && is_writable($filename))
90 if (!$zp = fopen($filename, 'w'))
92 display_error(_("Cannot open the languages file - ") . $filename);
97 if (!fwrite($zp, $msg))
99 display_error(_("Cannot write to the language file - ") . $filename);
109 display_error(_("The language file ") . $filename . _(" is not writable. Change its permissions so it is, then re-run the operation."));
115 //---------------------------------------------------------------------------------------------
117 function handle_submit()
119 global $path_to_root, $installed_languages, $dflt_lang;
126 if ($_POST['dflt']) {
127 $dflt_lang = $_POST['code'];
130 $installed_languages[$id]['code'] = $_POST['code'];
131 $installed_languages[$id]['name'] = $_POST['name'];
132 $installed_languages[$id]['encoding'] = $_POST['encoding'];
133 $installed_languages[$id]['rtl'] = (bool)$_POST['rtl'];
136 $directory = $path_to_root . "/lang/" . $_POST['code'];
137 if (!file_exists($directory))
140 mkdir($directory . "/LC_MESSAGES");
142 if (is_uploaded_file($_FILES['uploadfile']['tmp_name']))
144 $file1 = $_FILES['uploadfile']['tmp_name'];
145 $file2 = $directory . "/LC_MESSAGES/".$_POST['code'].".po";
146 if (file_exists($file2))
148 move_uploaded_file($file1, $file2);
150 if (is_uploaded_file($_FILES['uploadfile2']['tmp_name']))
152 $file1 = $_FILES['uploadfile2']['tmp_name'];
153 $file2 = $directory . "/LC_MESSAGES/".$_POST['code'].".mo";
154 if (file_exists($file2))
156 move_uploaded_file($file1, $file2);
161 //---------------------------------------------------------------------------------------------
163 function handle_delete()
165 global $path_to_root, $installed_languages, $dflt_lang;
169 $lang = $installed_languages[$id]['code'];
170 $filename = "$path_to_root/lang/$lang/LC_MESSAGES";
172 if ($lang == $dflt_lang ) {
173 // on delete set default to current.
174 $dflt_lang = $_SESSION['language']->code;
177 unset($installed_languages[$id]);
178 $installed_languages = array_values($installed_languages);
183 $filename = "$path_to_root/lang/$lang";
184 flush_dir($filename);
187 meta_forward($_SERVER['PHP_SELF']);
190 //---------------------------------------------------------------------------------------------
192 function display_languages()
194 global $table_style, $installed_languages, $dflt_lang;
196 $lang = $_SESSION["language"]->code;
199 <script language='javascript'>
200 function deleteLanguage(id) {
201 if (!confirm('" . _("Are you sure you want to delete language no. ") . "'+id))
203 document.location.replace('inst_lang.php?c=df&id='+id)
206 start_table($table_style);
207 $th = array(_("Language"), _("Name"), _("Encoding"), _("Right To Left"), _("Default"), "", "");
211 $conn = $installed_languages;
213 for ($i = 0; $i < $n; $i++)
215 if ($conn[$i]['code'] == $lang)
216 start_row("class='stockmankobg'");
218 alt_table_row_color($k);
220 label_cell($conn[$i]['code']);
221 label_cell($conn[$i]['name']);
222 label_cell($conn[$i]['encoding']);
223 if (isset($conn[$i]['rtl']) && $conn[$i]['rtl'])
228 label_cell($dflt_lang == $conn[$i]['code'] ? _("Yes") :_("No"));
230 $delete = _("Delete");
231 if (user_graphic_links())
233 $edit = set_icon(ICON_EDIT, $edit);
234 $delete = set_icon(ICON_DELETE, $delete);
236 label_cell("<a href='" . $_SERVER['PHP_SELF']. "?selected_id=$i'>$edit</a>");
237 label_cell($conn[$i]['code'] == $lang ? '' :
238 "<a href='javascript:deleteLanguage(" . $i . ")'>$delete</a>");
243 display_note(_("The marked language is the current language which cannot be deleted."), 0, 0, "class='currentfg'");
246 //---------------------------------------------------------------------------------------------
248 function display_language_edit($selected_id)
250 global $installed_languages, $table_style2, $dflt_lang;
252 if ($selected_id != -1)
255 $n = count($installed_languages);
260 <script language='javascript'>
261 function updateLanguage() {
262 document.forms[0].action='inst_lang.php?c=u&id=" . $n . "'
263 document.forms[0].submit()
267 start_table($table_style2);
269 if ($selected_id != -1)
271 $conn = $installed_languages[$selected_id];
272 $_POST['code'] = $conn['code'];
273 $_POST['name'] = $conn['name'];
274 $_POST['encoding'] = $conn['encoding'];
275 if (isset($conn['rtl']))
276 $_POST['rtl'] = $conn['rtl'];
278 $_POST['rtl'] = false;
279 $_POST['dflt'] = $dflt_lang == $conn['code'];
280 hidden('selected_id', $selected_id);
282 text_row_ex(_("Language Code"), 'code', 20);
283 text_row_ex(_("Language Name"), 'name', 20);
284 text_row_ex(_("Encoding"), 'encoding', 20);
286 yesno_list_row(_("Right To Left"), 'rtl', null, "", "", false);
287 yesno_list_row(_("Default Language"), 'dflt', null, "", "", false);
289 label_row(_("Language File") . " (PO)", "<input name='uploadfile' type='file'>");
290 label_row(_("Language File") . " (MO)", "<input name='uploadfile2' type='file'>");
293 display_note(_("Select your language files from your local harddisk."), 0, 1);
294 echo "<center><input onclick='javascript:updateLanguage()' type='button' style='width:150px' value='". _("Save"). "'></center>";
301 //---------------------------------------------------------------------------------------------
303 if (isset($_GET['c']))
305 if ($_GET['c'] == 'df')
310 if ($_GET['c'] == 'u')
314 //meta_forward($_SERVER['PHP_SELF']);
319 //---------------------------------------------------------------------------------------------
323 hyperlink_no_params($_SERVER['PHP_SELF'], _("Create a new language"));
325 display_language_edit($selected_id);
327 //---------------------------------------------------------------------------------------------