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(_($help_context = "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"));
47 //---------------------------------------------------------------------------------------------
49 function handle_submit()
51 global $path_to_root, $installed_languages, $dflt_lang;
59 $dflt_lang = $_POST['code'];
62 $installed_languages[$id]['code'] = $_POST['code'];
63 $installed_languages[$id]['name'] = $_POST['name'];
64 $installed_languages[$id]['encoding'] = $_POST['encoding'];
65 $installed_languages[$id]['rtl'] = (bool)$_POST['rtl'];
68 $directory = $path_to_root . "/lang/" . $_POST['code'];
69 if (!file_exists($directory))
72 mkdir($directory . "/LC_MESSAGES");
74 if (is_uploaded_file($_FILES['uploadfile']['tmp_name']))
76 $file1 = $_FILES['uploadfile']['tmp_name'];
77 $file2 = $directory . "/LC_MESSAGES/".$_POST['code'].".po";
78 if (file_exists($file2))
80 move_uploaded_file($file1, $file2);
82 if (is_uploaded_file($_FILES['uploadfile2']['tmp_name']))
84 $file1 = $_FILES['uploadfile2']['tmp_name'];
85 $file2 = $directory . "/LC_MESSAGES/".$_POST['code'].".mo";
86 if (file_exists($file2))
88 move_uploaded_file($file1, $file2);
93 //---------------------------------------------------------------------------------------------
95 function handle_delete()
97 global $path_to_root, $installed_languages, $dflt_lang;
101 $lang = $installed_languages[$id]['code'];
102 $filename = "$path_to_root/lang/$lang/LC_MESSAGES";
104 if ($lang == $dflt_lang ) {
105 // on delete set default to current.
106 $dflt_lang = $_SESSION['language']->code;
109 unset($installed_languages[$id]);
110 $installed_languages = array_values($installed_languages);
115 $filename = "$path_to_root/lang/$lang";
116 flush_dir($filename);
119 meta_forward($_SERVER['PHP_SELF']);
122 //---------------------------------------------------------------------------------------------
124 function display_languages()
126 global $installed_languages, $dflt_lang;
128 $lang = $_SESSION["language"]->code;
131 <script language='javascript'>
132 function deleteLanguage(id) {
133 if (!confirm('" . _("Are you sure you want to delete language no. ") . "'+id))
135 document.location.replace('inst_lang.php?c=df&id='+id)
138 start_table(TABLESTYLE);
139 $th = array(_("Language"), _("Name"), _("Encoding"), _("Right To Left"), _("Default"), "", "");
143 $conn = $installed_languages;
145 for ($i = 0; $i < $n; $i++)
147 if ($conn[$i]['code'] == $lang)
148 start_row("class='stockmankobg'");
150 alt_table_row_color($k);
152 label_cell($conn[$i]['code']);
153 label_cell($conn[$i]['name']);
154 label_cell($conn[$i]['encoding']);
155 if (isset($conn[$i]['rtl']) && $conn[$i]['rtl'])
160 label_cell($dflt_lang == $conn[$i]['code'] ? _("Yes") :_("No"));
162 $delete = _("Delete");
163 if (user_graphic_links())
165 $edit = set_icon(ICON_EDIT, $edit);
166 $delete = set_icon(ICON_DELETE, $delete);
168 label_cell("<a href='" . $_SERVER['PHP_SELF']. "?selected_id=$i'>$edit</a>");
169 label_cell($conn[$i]['code'] == $lang ? '' :
170 "<a href='javascript:deleteLanguage(" . $i . ")'>$delete</a>");
175 display_note(_("The marked language is the current language which cannot be deleted."), 0, 0, "class='currentfg'");
178 //---------------------------------------------------------------------------------------------
180 function display_language_edit($selected_id)
182 global $installed_languages, $dflt_lang;
184 if ($selected_id != -1)
187 $n = count($installed_languages);
192 <script language='javascript'>
193 function updateLanguage() {
194 document.forms[0].action='inst_lang.php?c=u&id=" . $n . "'
195 document.forms[0].submit()
199 start_table(TABLESTYLE2);
201 if ($selected_id != -1)
203 $conn = $installed_languages[$selected_id];
204 $_POST['code'] = $conn['code'];
205 $_POST['name'] = $conn['name'];
206 $_POST['encoding'] = $conn['encoding'];
207 if (isset($conn['rtl']))
208 $_POST['rtl'] = $conn['rtl'];
210 $_POST['rtl'] = false;
211 $_POST['dflt'] = $dflt_lang == $conn['code'];
212 hidden('selected_id', $selected_id);
214 text_row_ex(_("Language Code"), 'code', 20);
215 text_row_ex(_("Language Name"), 'name', 20);
216 text_row_ex(_("Encoding"), 'encoding', 20);
218 yesno_list_row(_("Right To Left"), 'rtl', null, "", "", false);
219 yesno_list_row(_("Default Language"), 'dflt', null, "", "", false);
221 file_row(_("Language File") . " (PO)", 'uploadfile');
222 file_row(_("Language File") . " (MO)", 'uploadfile2');
225 display_note(_("Select your language files from your local harddisk."), 0, 1);
226 echo "<center><input onclick='javascript:updateLanguage()' type='button' style='width:150px' value='". _("Save"). "'></center>";
233 //---------------------------------------------------------------------------------------------
235 if (isset($_GET['c']))
237 if ($_GET['c'] == 'df')
242 if ($_GET['c'] == 'u')
246 //meta_forward($_SERVER['PHP_SELF']);
251 //---------------------------------------------------------------------------------------------
255 hyperlink_no_params($_SERVER['PHP_SELF'], _("Create a new language"));
257 display_language_edit($selected_id);
259 //---------------------------------------------------------------------------------------------