<?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.	##
##############################################################
if(!strlen($pathtoroot))
{
  $path=dirname(realpath($_SERVER['SCRIPT_FILENAME']));
  if(strlen($path))
  {
    /* determine the OS type for path parsing */
    $pos = strpos($path,":");
    if ($pos === false)
    {
      $gOS_TYPE="unix";
      $pathchar = "/";
    }
    else
    {
      $gOS_TYPE="win";
      $pathchar="\\";
    }
    $p = $path.$pathchar;
    /*Start looking for the root flag file */
    while(!strlen($pathtoroot) && strlen($p))
    {
      $sub = substr($p,strlen($pathchar)*-1);
      if($sub==$pathchar)
      {
        $filename = $p."root.flg";
      }
      else
        $filename = $p.$pathchar."root.flg";
      if(file_exists($filename))
      {
        $pathtoroot = $p;
      }
      else
      {
        $parent = realpath($p.$pathchar."..".$pathchar);
	if($parent!=$p)
	{
	  $p = $parent;
	}
	else
	  $p = "";
      }
    }
    if(!strlen($pathtoroot))
      $pathtoroot = ".".$pathchar;
  }
  else
  {
    $pathtoroot = ".".$pathchar;
  }
}


$sub = substr($pathtoroot,strlen($pathchar)*-1);
if($sub!=$pathchar)
{
  $pathtoroot = $pathtoroot.$pathchar;
}
//echo $pathtoroot;

require_once($pathtoroot."kernel/startup.php");
//admin only util
$rootURL="http://".ThisDomain().$objConfig->Get("Site_Path");
$admin = $objConfig->Get("AdminDirectory");
if(!strlen($admin))
    $admin = "admin";
$localURL=$rootURL."kernel/";
$adminURL = $rootURL.$admin;
$imagesURL = $adminURL."/images"; 

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) )
{
  // useless code: begin
  $ids = str_replace("[","",$ids);
  $ids = str_replace("]","",$ids);
  $ids = str_replace("\"","",$ids);
  $ids = str_replace("\\","",$ids);
  // useless code: end
  $PhraseIds = explode(",",$ids);
}
else
{
  $LangId = $_GET["LanguageId"];	
}

$EditDirect = GetVar('direct');

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

unset($objEditItems);

if ( isset($PhraseIds) && count($PhraseIds) > 1) {
	$print_list = true;
}
else {
	$ado = GetADODBConnection();
	$sql = "SELECT PhraseId FROM ".$objSession->GetEditTable("Phrase");
	
	if ( isset($LangId) && $LangId > 0 ) {
		$sql .= " WHERE LanguageId = $LangId";
	}
	
	$rs = $ado->Execute($sql);
	
	if ( GetVar('en') === false ) {
		$selected_id = $PhraseIds[0];
	}
	else {
		$selected_id = GetVar('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");

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) ) $objPhraseList = new clsPhraseList();

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

if ($print_list) {
	$count_ids = count($PhraseIds);
	$selected_id = $PhraseIds[0];
}
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]);
  
  if( !isset($LangId) ) $LangId = $p->Get("LanguageId");
  if(is_object($p) && isset($selected_id) )
  {
  	echo int_subsection_title_ret(admin_language("la_tab_General").": ".GetPrimaryTranslation($p->Get("Phrase")));
  	if($p->Get('PhraseId') > 0)
  	{
  		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=\"".$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=\"".$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);                                                   
  }
}
$PriTrans = isset($NewLabel) ? GetPrimaryTranslation($NewLabel) : '';
?>

<?php if (GetVar('PhraseId') === false) { ?> 
<?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 echo $_POST['name'][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 echo $_POST['translation'][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]" VALUE="0">
    <?php echo admin_language("la_Text_Front"); ?>
    <input type=radio tabindex="6" NAME="phrasetype[0]" VALUE="1">
    <?php echo admin_language("la_Text_Admin"); ?>
    <input type=radio tabindex="6" NAME="phrasetype[0]" VALUE="2">
    <?php echo admin_language("la_Text_Both"); ?>
    </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(); ?>