<?php 
##############################################################
##In-portal													##
##############################################################
##					      In-portal							##
##					Intechnic Corporation					##
##			   All Rights Reserved, 1998-2002				##
##															##
##	No portion of this code may be copied, reproduced or	##
##	   otherwise redistributed without proper written		##
##	  consent of Intechnic Corporation.  Violation will		##
##	   result in revocation of the license and support		##
##	 privileges along maximum prosecution allowed by law.	##
##############################################################

define('IS_POPUP', 1);

// new startup: begin
define('REL_PATH', 'admin/config');
$relation_level = count( explode('/', REL_PATH) );
define('FULL_PATH', realpath(dirname(__FILE__) . str_repeat('/..', $relation_level) ) );
require_once FULL_PATH.'/kernel/startup.php';
// new startup: end

require_once ($pathtoroot.$admin."/include/elements.php");
require_once ($pathtoroot."kernel/admin/include/navmenu.php");
require_once($pathtoroot.$admin."/toolbar.php");
require_once($pathtoroot.$admin."/listview/listview.php");

if(count($_POST)>0 && !$_GET['PhraseId'] && $add_error == '')
{
	echo "<SCRIPT language=\"JavaScript\">\n";
	echo "  if(window.opener) window.opener.location=window.opener.location;\n";
	echo "  window.close();";
	echo "</SCRIPT>";
	die();
}

$section = "in-portal:phrase_editor";
$ids = GetVar('PhraseId');

if(strlen($ids))
{
	$ids = str_replace("[","",$ids);
	$ids = str_replace("]","",$ids);
	$ids = str_replace("\"","",$ids);
	$ids = str_replace("\\","",$ids);
	$PhraseIds = explode(",",$ids);
	$LangId = 0;
}
else
{
	$LangId = GetVar('LanguageId');
	$PhraseIds = Array();
}

$EditDirect = (int)GetVar('direct');

if($EditDirect)
{
	$NewLabel = GetVar('label');
	if(!$LangId)
	{
		$LangId = $objSession->Get("Language");
	}
	SetVar( 'name', Array($NewLabel) );
}
else
{
	$NewLabel = '';	
}

unset($objEditItems);

if (count($PhraseIds) > 1) {
	$print_list = true;
}
else {
	$ado = &GetADODBConnection();
	$table=$EditDirect?GetTablePrefix().'Phrase':$objSession->GetEditTable("Phrase");
	$sql = "SELECT PhraseId FROM ".$table;

	if ($LangId) {
		$sql .= " WHERE LanguageId = $LangId";
	}

	$rs = $ado->Execute($sql);

	$selected_id = !GetVar('en') ? $PhraseIds[0] : $_GET['PhraseId'];

	$PhraseIdList = '';
	while ($rs && !$rs->EOF) {
		$PhraseIdList .= $rs->fields['PhraseId'].",";
		$rs->MoveNext();
	}

	$PhraseIdList = substr($PhraseIdList, 0, strlen($PhraseIdList));
	$PhraseIdArr = explode(",", $PhraseIdList);

	$print_list = false;
}

$envar = "env=".BuildEnv();
$formaction = $_SERVER["PHP_SELF"]."?".$envar;
$sec = $objSections->GetSection($section);

$objListToolBar = new clsToolBar();

$objListToolBar->Set("section",$section);
$objListToolBar->Set("load_menu_func","");
$objListToolBar->Set("CheckClass","ThemeChecks");

$objListToolBar->Add("select", "la_ToolTip_Select","#","swap('select','toolbar/tool_select_f2.gif');",
"swap('select', 'toolbar/tool_select.gif');",
"LangSubmit();",
"tool_select.gif");

$objListToolBar->Add("cancel", "la_ToolTip_Stop","#","swap('cancel','toolbar/tool_stop_f2.gif');",
"swap('cancel', 'toolbar/tool_stop.gif');","window.close();","tool_stop.gif");

if (!$print_list) {
	$x = -1;
	foreach ($PhraseIdArr as $key => $value) {
		if ($value == $selected_id) {
			$x = $key;
		}
	}

	if ($x <= 0) {
		$en_next = $PhraseIdArr[$x+1];
		$en_prev = false;
	}
	else if ($x >= count($PhraseIdArr) - 1) {
		$en_next = false;
		$en_prev = $PhraseIdArr[$x - 1];
	}
	else {
		$en_next = $PhraseIdArr[$x+1];
		$en_prev = $PhraseIdArr[$x-1];
	}


	$url = "edit_label.php?$envar&en=0";
	$form = "frmPhrase";
	MultiEditButtons($objListToolBar,$en_next,$en_prev,$form,1,$url, "LangSubmitMove");
}

$title = admin_language("la_Text_Editing")." ".admin_language("la_Text_Label");

// substitute charset to match the ones from phrase: begin
$tmp_id=GetVar('PhraseId');
if($tmp_id)
{
	$tmp_id=explode(',',$tmp_id);
	
	$db=&GetADODBConnection();
	$LangId=$db->GetOne('SELECT LanguageId FROM '.GetTablePrefix().'Phrase WHERE PhraseId='.$tmp_id[0]);
	
	$c = $objLanguages->GetItem($LangId);
	define('FORCE_CHARSET', $c->Get("Charset") );
}
// substitute charset to match the ones from phrase: end

int_header($objListToolBar,NULL,$title);
?>
<form name="frmPhrase" ID="frmPhrase" action="<?php echo $_SERVER["PHP_SELF"]."?".$envar;?>" method=POST>
<TABLE cellSpacing="0" cellPadding="2" width="100%" class="tableborder">
<?php
if( !isset($objPhraseList) || !is_object($objPhraseList) )
{
	$objPhraseList = new clsPhraseList();
}

if(!$EditDirect)
{
	$objPhraseList->SourceTable = $objSession->GetEditTable("Phrase");
}
$count_ids = 1;

if ($print_list) {
	$count_ids = count($PhraseIds);
}
else {
	foreach($PhraseIdArr as $key => $value) {
		if ($value == $selected_id) {
			$PhraseIds[0] = $value;
		}
	}
}

for($x=0;$x<$count_ids;$x++)
{
	$p = $objPhraseList->GetItem($PhraseIds[$x]);

	//echo "<pre>"; print_r($p); echo "</pre>";

	if(!$LangId)
	$LangId = $p->Get("LanguageId");
	if(is_object($p) && ($selected_id != '' || $count_ids > 1))
	{
		echo int_subsection_title_ret(admin_language("la_tab_General")." :: ".GetPrimaryTranslation($p->Get("Phrase")));
		echo "<TR ".int_table_color_ret()." >\n";
		echo "  <TD>".admin_language("la_prompt_PhraseId")."</TD>\n";
		echo "  <TD>".$p->Get("PhraseId")."</TD>\n";
		echo "  <TD></TD>\n";
		echo "</TR>\n";

		echo "<TR ".int_table_color_ret()." >\n";
		echo "  <TD>".admin_language("la_prompt_Label")."</TD>\n";
		echo "  <TD><input size=60 type=text  tabindex=\"1\" ValidationType=\"exists\" NAME=\"name[".$p->Get("PhraseId")."]\" VALUE=\"".inp_htmlize($p->Get("Phrase"))."\"></TD>\n";
		echo "  <TD></TD>\n";
		echo "</TR>\n";

		echo "<TR ".int_table_color_ret()." >\n";
		echo "  <TD>".admin_language("la_prompt_Value")."</TD>\n";
		echo "  <TD><input size=60 type=text  tabindex=\"2\" ValidationType=\"exists\" NAME=\"translation[".$p->Get("PhraseId")."]\" VALUE=\"".inp_htmlize($p->Get("Translation"))."\"></TD>\n";
		echo "  <TD></TD>\n";
		echo "</TR>\n";

		echo "<TR ".int_table_color_ret()." >\n";
		echo "  <TD>".admin_language("la_prompt_PhraseType")."</TD>\n";
		echo "  <TD COLSPAN=2>\n";
		echo "    <input type=radio tabindex=\"3\" NAME=\"phrasetype[".$p->Get("PhraseId")."]\" VALUE=\"0\"";
		if($p->Get("PhraseType")==0)
		echo "CHECKED";
		echo ">";
		echo admin_language("la_Text_Front");
		echo "  <input type=radio tabindex=\"3\" NAME=\"phrasetype[".$p->Get("PhraseId")."]\" VALUE=\"1\"";
		if($p->Get("PhraseType")==1)
		echo "CHECKED";
		echo ">";
		echo admin_language("la_Text_Admin");
		echo "  <input type=radio tabindex=\"3\" NAME=\"phrasetype[".$p->Get("PhraseId")."]\" VALUE=\"2\"";
		if($p->Get("PhraseType")==2)
		echo "CHECKED";
		echo ">";
		echo admin_language("la_Text_Both");
		echo "  </TD>\n";
		echo "</TR>\n";
		unset($p);
	}
}
?>
<?php
if(strlen($NewLabel)>0)
{
	"::".$PriTrans = GetPrimaryTranslation($NewLabel);
}
else
{
	$PriTrans = '';	
}

?> 
<?php if ( !GetVar('PhraseId') ) { ?> 
<?php int_subsection_title(admin_language("la_tab_General")." :: New Phrase ".$PriTrans); ?> 

<TR <?php int_table_color(); ?> >
  <td><?php echo admin_language("la_prompt_Label"); ?></td>
  <td><input type=text size=60   tabindex="4" NAME="name[0]" VALUE="<?php $names = GetVar('name'); if($names !== false) echo $names[0]; ?>"></td>
  <td></td>
</tr>

<TR <?php int_table_color(); ?> >
  <td><?php echo admin_language("la_prompt_Value"); ?></td>
  <td><input type=text size=60 tabindex="5"  NAME="translation[0]" VALUE="<?php $traslations = GetVar('translation'); if($traslations !== false) echo $traslations[0]; ?>"></td>
  <td></td>  
</tr>                                                       

<TR <?php int_table_color(); ?> >
  	<TD><?php echo admin_language("la_prompt_PhraseType"); ?></TD>
	<TD COLSPAN=2>
    <input type="radio" tabindex="6" name="phrasetype[0]" id="phrasetype_0" value="0">
    <label for="phrasetype_0"><?php echo admin_language("la_Text_Front"); ?></label>
    <input type="radio" tabindex="7" name="phrasetype[0]" id="phrasetype_1" value="1"<?php if($EditDirect) echo ' checked'; ?>>
    <label for="phrasetype_1"><?php echo admin_language("la_Text_Admin"); ?></label>
    <input type="radio" tabindex="8" name="phrasetype[0]" id="phrasetype_2" value="2">
    <label for="phrasetype_2"><?php echo admin_language("la_Text_Both"); ?></label>
    </TD>
</tr> 
<tr>        
	<td colspan="3" align="center"><font color="#FF0000"><?php if( isset($add_error) ) echo $add_error; ?></font></td>
</tr>
<INPUT type=hidden name="Action1" VALUE="new">
<?php } ?>                                   
<INPUT TYPE=HIDDEN NAME="LanguageId" VALUE="<?php echo $LangId; ?>">
<INPUT type=hidden name="Action" VALUE="m_phrase_edit">
<input type=hidden name="direct" VALUE="<?php echo $EditDirect; ?>">
</FORM>
</TABLE>
<?php int_footer(); ?>