Get("Site_Path");
$admin = $objConfig->Get("AdminDirectory");
if(!strlen($admin))
$admin = "admin";
$localURL=$rootURL."kernel/";
$adminURL = $rootURL.$admin;
$imagesURL = $adminURL."/images";
// $pathtolocal = $pathtoroot."in-link/";
require_once ($pathtoroot.$admin."/include/elements.php");
require_once ($pathtoroot."kernel/admin/include/navmenu.php");
//require_once ($pathtolocal."admin/include/navmenu.php");
require_once($pathtoroot.$admin."/toolbar.php");
require_once($pathtoroot.$admin."/listview/listview.php");
include_once($pathtoroot."kernel/include/xml.php");
$section = "in-portal:lang_import";
$ado = &GetADODBConnection();
$MaxInserts = 200;
$PhraseTable = "ses_".$objSession->GetSessionKey()."_".GetTablePrefix()."ImportPhrases";
$EventTable = "ses_".$objSession->GetSessionKey()."_".GetTablePrefix()."ImportEvents";
$OverWrite = $_POST['overwrite'];
if(count($_POST)>0)
{
$Offset = 0;
$CurrentLang=0;
$file = $_FILES["lang_file"];
if(is_array($file))
{
if((int)$file["size"]>0)
{
move_uploaded_file($file["tmp_name"],$pathtoroot.$admin."/export/".$file["name"]);
$filename = $pathtoroot.$admin."/export/".$file["name"];
if(file_exists($filename))
{
/* parse xml file */
$fp = @fopen($filename,"r");
$xml = @fread($fp,filesize($filename));
@fclose($fp);
$objInXML = new xml_doc($xml);
$objInXML->parse();
$sql = "CREATE TABLE $PhraseTable SELECT Phrase,Translation,PhraseType,LanguageId FROM ".GetTablePrefix()."Phrase WHERE PhraseId=-1";
$ado->Execute($sql);
$sql = "CREATE TABLE $EventTable SELECT Template,MessageType,EventId,LanguageId FROM ".GetTablePrefix()."EmailMessage WHERE EmailMessageId=-1";
$ado->Execute($sql);
//$sql = "ALTER TABLE $EventTable ADD `Type` INT(11) default 0";
//$ado->Execute($sql);
$sql = "SELECT EventId,Event,Type FROM ".GetTablePrefix()."Events";
$rs = $ado->Execute($sql);
$Events = array();
while($rs && !$rs->EOF)
{
$Events[$rs->fields["Event"]."_".$rs->fields["Type"]] = $rs->fields["EventId"];
$rs->MoveNext();
}
$objInXML->getTag(0,$name,$attribs,$contents,$tags);
if(is_array($tags))
{
foreach($tags as $t)
{
$LangRoot =& $objInXML->getTagByID($t);
$PackName = $LangRoot->attributes["PACKNAME"];
$l = $objLanguages->GetItemByField("PackName",$PackName);
if(is_object($l))
{
$LangId = $l->Get("LanguageId");
}
else
{
$l = new clsLanguage();
$l->Create();
$NewLang = TRUE;
$LangId = $l->Get("LanguageId");
}
foreach($LangRoot->children as $tag)
{
switch($tag->name)
{
case "PHRASES":
foreach($tag->children as $PhraseTag)
{
$Phrase = $ado->qstr($PhraseTag->attributes["LABEL"]);
$Translation = $ado->qstr(base64_decode($PhraseTag->contents));
$PhraseType = $PhraseTag->attributes["TYPE"];
$psql = "INSERT INTO $PhraseTable (Phrase,Translation,PhraseType,LanguageId) VALUES ($Phrase,$Translation,$PhraseType,$LangId)";
$ado->Execute($psql);
//echo "$psql
\n";
}
break;
case "DATEFORMAT":
$DateFormat = $tag->contents;
break;
case "TIMEFORMAT":
$TimeFormat = $tag->contents;
break;
case "DECIMAL":
$Decimal = $tag->contents;
break;
case "THOUSANDS":
$Thousands = $tag->contents;
break;
case "EVENTS":
foreach($tag->children as $EventTag)
{
$event = $EventTag->attributes["EVENT"];
$MsgType = strtolower($EventTag->attributes["MESSAGETYPE"]);
$template = base64_decode($EventTag->contents);
$Type = $EventTag->attributes["TYPE"];
$EventId = $Events[$event."_".$Type];
$esql = "INSERT INTO $EventTable (Template,MessageType,EventId,LanguageId) VALUES ('$template','$MsgType',$EventId,$LangId)";
$ado->Execute($esql);
//echo htmlentities($esql)."
\n";
}
break;
}
if($NewLang)
{
$l->Set("PackName",$PackName);
$l->Set("LocalName",$PackName);
$l->Set("DateFormat",$DateFormat);
$l->Set("TimeFormat",$TimeFormat);
$l->Set("DecimalPoint",$Decimal);
$l->Set("ThousandSep",$Thousands);
$l->Update();
}
}
}
$Types = implode(",",$_POST["langtypes"]);
$objSession->SetVariable("lang_types",$Types);
$objSession->SetVariable("lang_overwrite",(int)$_POST["overwrite"]);
$Total = TableCount($PhraseTable,"PhraseType IN ($Types)",0);
$objSession->SetVariable("phrase_total",$Total);
$Total = TableCount($EventTable,"",0);
$objSession->SetVariable("event_total",$Total);
$Offset = 0;
$Status = 0;
//unlink($filename);
}
}
}
}
}
else
{
$Offset = (int)$_GET["Offset"];
$Status = (int)$_GET["Status"];
$OverWrite = $objSession->GetVariable("lang_overwrite");
$Types = $objSession->GetVariable("lang_types");
if($Status==0)
{
$Total = $objSession->GetVariable("phrase_total");
}
else
$Total = $objSession->GetVariable("event_total");
}
//echo $Total;
if ($Total == "") {
$url = $adminURL."/config/importlang.php?env=".BuildEnv()."&importerror=1";
Header("Location: $url");
//reload($url);
}
$title = admin_language("la_Text_LangImport")." - ".admin_language("la_Step")." 2";
int_header(NULL,NULL, $title);
?>
"; $o .= "
"; echo $o."\n"; echo " |