<?php
//language
require_once("includes/config.inc.php");
require_once("DB.php");
require_once("includes/translation.class.php");
class lang extends base
{
protected $db = null;
protected $tr = null;
function onInit($param)
{
parent::onInit($param);
//var
$lang = "en";
//connect to the database
$this->db = &DB::connect($this->Application->getUserParameter('APPL_DSN'), false);
if (DB::isError($this->db))
$this->onError("Error connecting to the database." . $this->db->getMessage());
else
{
$this->db->autoCommit(false);
//initiates the language
if ($this->User->isAuthenticated())
$lang = $this->User->getUserLang();
else if (isset($_GET['lang']))
$lang = $_GET['lang'];
try
{
if ($this->getID() === "login")
$this->tr = new trans($this->getID(), $lang, $this->db);
else
$this->tr = new trans(array($this->getID(), 'phpwdmanager'), $lang, $this->db);
}
catch (Exception $e)
{
if ($this->getID() === "profile" && isset($_GET['sign']))
$this->onError($e->getMessage(), array("sign" => ""));
else
$this->onError($e->getMessage());
}
}
}
function onUnload($param)
{
parent::onUnload($param);
if (is_object($this->db))
{
if (substr(get_class($this->db), 0, 2) === "DB")
$this->db->disconnect();
}
unset($this->db);
}
protected function setLanguage($object, $strings)
{
$objs = null;
$obj = null;
$item = null;
if ($object->hasChildren())
{
$objs = $object->getChildren();
foreach ($objs as $obj)
{
if ((isset($strings['phpwdmanager'][$obj->ID])))
$this->setLanguage($obj, $strings['phpwdmanager']);
else if (isset($strings[$object->ID][$obj->ID]))
$this->setLanguage($obj, $strings[$object->ID]);
}
}
else if (!is_subclass_of($object, "TListControl"))
{
if (isset($strings[$object->ID]))
$object->setText(ucwords($strings[$object->ID]));
}
else if (isset($strings[$object->ID]))//it's subclass of TListControl
{
$objs = $object->getItems();
foreach ($objs as $item)
{
if (isset($strings[$object->ID][$item->Value]))
$item->setText(ucwords($strings[$object->ID][$item->Value]));
}
}
}
}
?>