+ global $path_to_root, $installed_languages, $dflt_lang;
+
+ $installed_languages = array_natsort($installed_languages, 'code', 'code');
+ $msg = "<?php\n\n";
+
+ $msg .= "/* How to make new entries here for non-packaged languages:\n\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";
+ $msg .= "-- 'encoding' used in translation file\n";
+ $msg .= "-- 'version' always set to '' for manually installed languages.\n";
+ $msg .= "-- 'path' installation path related to FA root (e.g. 'lang/en_US').\n";
+ $msg .= "*/\n\n\n";
+
+ $msg .= "\$installed_languages = " . var_export($installed_languages, true);
+ $msg .= ";\n";
+ $msg .= "\n\$dflt_lang = '$dflt_lang';\n";
+
+ $path = $path_to_root . "/lang";
+ $filename = $path.'/installed_languages.inc';
+ // Check if directory exists and is writable first.
+ if (file_exists($path) && is_writable($path))
+ {
+ 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);
+ cache_invalidate($filename);
+ }
+ }
+ else
+ {
+ display_error(_("The language files folder ") . $path . _(" is not writable. Change its permissions so it is, then re-run the operation."));
+ return false;
+ }
+ return true;
+}
+/*
+ Database import:
+ $filename - sql file name
+ $connection - database connection
+ $force - ignore duplicate errors
+ $init - presume $filename is initialization file with '0_' prefix
+ $protect - protect users/roles
+ $return_errors - return errors instead of display them
+*/
+function db_import($filename, $connection, $force=true, $init=true, $protect=false, $return_errors=false)
+{
+ global $db, $SysPrefs;
+
+ $trail = $SysPrefs->sql_trail;
+ $SysPrefs->sql_trail = false;
+
+ $allowed_commands = array(
+ "create" => 'table_queries',
+ "delimiter" => 'table_queries',
+ "alter table" => 'table_queries',
+ "insert" => 'data_queries',
+ "update" => 'data_queries',
+ "set names" => 'set_names',
+ "drop table if exists" => 'drop_queries',
+ "drop function if exists" => 'drop_queries',
+ "drop trigger if exists" => 'drop_queries',
+ "select" => 'data_queries',
+ "delete" => 'data_queries',
+ );
+
+ $protected = array(
+ 'security_roles',
+ 'users'
+ );
+
+ $ignored_mysql_errors = array( //errors ignored in normal (non forced) mode
+ '1022', // duplicate key
+ '1050', // Table %s already exists
+ '1060', // duplicate column name
+ '1061', // duplicate key name
+ '1062', // duplicate key entry
+ '1091' // can't drop key/column check if exists
+ );
+
+ $set_names = array();