Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions bin/build-lang-cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env php
<?php


/***
* 1. Load en.xml from htdocs/Language
* 2. Load en_catalog.xml from htdocs/Language
* 3. Merge en.xml from local/langdata_127
* 4. Merge en_catalog.xml from local/langdata_127
*
*/


$locale = "en"; //$argv[1];
$lab_id = 12; //$argv[2];

$basepath = realpath(__DIR__ . "/../");
$baselocale = "$basepath/htdocs/Language";
$locallocale = "$basepath/local/langdata_$lab_id";

$basefile = "$baselocale/$locale.xml";

// $reference = load_locale_file($basefile);
// $base = load_locale_file($basefile);

// $default_base = load_locale_file("$baselocale/default.xml");
// $default_ov = load_locale_file("$locallocale/default.xml");
// $ov = load_locale_file("$locallocale/$locale.xml");

$reference = load_legacy_php_locale(__DIR__."/default_lang.php");
$base = load_legacy_php_locale(__DIR__."/default_lang.php");
$ov = load_legacy_php_locale(__DIR__."/en_lang.php");

if (!$base || !$ov) {
fwrite(STDERR, "Failed to load locales.\n");
exit(1);
}

// squash_locales($base, $default_base);
// squash_locales($base, $default_ov);
squash_locales($base, $ov);
$diff = find_overrides($reference, $base);

echo(json_encode($diff)."\n");
fwrite(STDOUT, json_encode($diff) . "\n");

function load_legacy_php_locale(string $filename): array | false {
if(!file_exists($filename)) {
fwrite(STDERR, "File $filename does not exist.\n");
return false;
}

$GLOBALS['LANG_ARRAY'] = null;

global $LANG_ARRAY;

include "$filename";

if (!$GLOBALS['LANG_ARRAY']) {
fwrite(STDERR, "Failed to load LANG_ARRAY from $filename\n");
return false;
}

return $GLOBALS['LANG_ARRAY'];
}

/**
* Returns a multilevel array keyed by page, then term
*/
function load_locale_file(string $filename) {
$file = simplexml_load_file($filename);

$locale = array();
foreach($file as $page)
{
$pagename = strval($page['id']);

$pageterms = array();
foreach($page->term as $term) {
$k = strval($term->key[0]);
$v = strval($term->value[0]);

$pageterms[$k] = $v;
}

$locale[$pagename] = $pageterms;
}

return $locale;
}

function squash_locales(array & $target, array $source) {
foreach($source as $pagename => $pageterms) {
if(!array_key_exists($pagename, $target)) {
$target[$pagename] = $pageterms;
} else {
foreach($pageterms as $term => $val) {
$target[$pagename][$term] = $val;
}
}
}
}

function find_overrides(array $base, array $overrides) {
$o = array();

foreach($overrides as $pagename => $pageterms) {
if(!array_key_exists($pagename, $base)) {
$o[$pagename] = $pageterms;
}
}

foreach($base as $pagename => $pageterms) {
if(!array_key_exists($pagename, $overrides)) {
continue;
}

foreach($pageterms as $term => $value) {
if(!array_key_exists($term, $overrides[$pagename])) {
continue;
}

if ($overrides[$pagename][$term] != $value) {
if (!array_key_exists($pagename, $o)) {
$o[$pagename] = array();
}
$o[$pagename][$term] = $overrides[$pagename][$term];
}
}
}

return $o;
}
11 changes: 6 additions & 5 deletions htdocs/includes/db_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ class ReportConfig
public $reportId;
public $testTypeId;
public $title;
public $name;

public $headerText;
public $titleText;
Expand Down Expand Up @@ -729,7 +730,7 @@ class ReportConfig

public static function getObject($record, $lab_config_id)
{
global $LANG_ARRAY, $LOCAL_PATH;
global $LOCAL_PATH;

if($record == null)
return null;
Expand All @@ -752,16 +753,16 @@ public static function getObject($record, $lab_config_id)
switch($report_config->reportId)
{
case 1:
$report_config->name = $LANG_ARRAY["reports"]["MENU_PATIENT"];
$report_config->name = LangUtil::$pageTerms->getTerm("reports", "MENU_PATIENT");
break;
case 2:
$report_config->name = $LANG_ARRAY["reports"]["MENU_SPECIMEN"];
$report_config->name = LangUtil::$pageTerms->getTerm("reports", "MENU_SPECIMEN");
break;
case 3:
$report_config->name = $LANG_ARRAY["reports"]["MENU_TESTRECORDS"];
$report_config->name = LangUtil::$pageTerms->getTerm("reports", "MENU_TESTRECORDS");
break;
case 4:
$report_config->name = $LANG_ARRAY["reports"]["MENU_DAILYLOGS"];
$report_config->name = LangUtil::$pageTerms->getTerm("reports", "MENU_DAILYLOGS");
break;
}

Expand Down
15 changes: 7 additions & 8 deletions htdocs/includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
require_once(__DIR__."/page_elems.php");
require_once(__DIR__."/script_elems.php");
include_once(__DIR__."/../lang/lang_util.php");
LangUtil::setPageId("header");
require_once(__DIR__."/perms_check.php");

$script_elems = new ScriptElems();
Expand Down Expand Up @@ -76,21 +75,21 @@
<?php
if (isset($_SESSION['username'])) {
?>
<?php echo LangUtil::getPageTerm("LOGGEDINAS"); ?>: <?php echo $_SESSION['username']; ?> |
<a href='/edit_profile.php' class="black"><?php echo LangUtil::$pageTerms['EDITPROFILE']; ?></a> |
<?php echo LangUtil::getTerm("header", "LOGGEDINAS"); ?>: <?php echo $_SESSION['username']; ?> |
<a href='/edit_profile.php' class="black"><?php echo LangUtil::getTerm("header", 'EDITPROFILE'); ?></a> |
<?php
//echo "test".$_SESSION['admin_as_tech'];
if (isset($_SESSION['admin_as_tech']) && $_SESSION['admin_as_tech'] === true) {
?>
<a href='/switchto_admin.php' class="black"><?php echo LangUtil::getPageTerm("SWITCH_TOMGR"); ?></a> |
<a href='/switchto_admin.php' class="black"><?php echo LangUtil::getTerm("header", "SWITCH_TOMGR"); ?></a> |
<?php
} elseif (isset($_SESSION['dir_as_tech']) && $_SESSION['dir_as_tech'] === true) {
?>
<a href='/switchto_admin.php' class="black"><?php echo LangUtil::getPageTerm("SWITCH_TODIR"); ?></a> |
<a href='/switchto_admin.php' class="black"><?php echo LangUtil::getTerm("header", "SWITCH_TODIR"); ?></a> |
<?php
} elseif (User::onlyOneLabConfig($_SESSION['user_id'], $_SESSION['user_level'])) {
$lab_config_list = get_lab_configs($_SESSION['user_id']); ?>
<a href='/switchto_tech.php?id=<?php echo $lab_config_list[0]->id; ?>' class="black"><?php echo LangUtil::getPageTerm("SWITCH_TOTECH"); ?></a> |
<a href='/switchto_tech.php?id=<?php echo $lab_config_list[0]->id; ?>' class="black"><?php echo LangUtil::getTerm("header", "SWITCH_TOTECH"); ?></a> |
<?php
}
}
Expand All @@ -102,7 +101,7 @@
<?php
}
?>
<a rel='facebox' href='/user_rating.php' class="black"><?php echo LangUtil::getPageTerm("LOGOUT"); ?></a>
<a rel='facebox' href='/user_rating.php' class="black"><?php echo LangUtil::getTerm("header", "LOGOUT"); ?></a>
</div>
<table cellspacing="10px">
<tr>
Expand Down Expand Up @@ -137,7 +136,7 @@
# Highlight current page tab
echo " class='here' ";
}
if (strpos($key, LangUtil::$pageTerms['MENU_BACKUP']) !== false) {
if (strpos($key, LangUtil::getTerm("header", 'MENU_BACKUP')) !== false) {
// echo " target='_blank' ";
}
if (strpos($_SERVER['PHP_SELF'], "_home.php") !== false && strpos($value, "lab_configs.php") !== false) {
Expand Down
Loading