<?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.	##
##############################################################

// new startup: begin
define('REL_PATH', 'in-news/admin');
$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

$pathtolocal = $pathtoroot."kernel/";
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."/browse/toolbar.php");
require_once($pathtoroot.$admin."/listview/listview.php");

unset($objEditCat);

$objEditCat = new clsNewsList();
$objEditCat->SourceTable = $objSession->GetEditTable("News");
$objEditCat->EnablePaging = FALSE;
//Multiedit init
$en = (int)$_GET["en"];
$objEditCat->Query_Item("SELECT * FROM ".$objEditCat->SourceTable);
$itemcount=$objEditCat->NumItems();
$c = $objEditCat->GetItemByIndex($en);

unset($objEditItems);

$objEditItems = new clsRelationshipList();
$objEditItems->SourceTable = $objSession->GetEditTable("Relationship");

if(isset($_POST["itemlist"]))
{
  if(is_array($_POST["itemlist"]))
  {
    $RelationId = $_POST["itemlist"][0];
  }
  else
  { 
    $RelationId = $_POST["itemlist"];
  }
  //  $Rel = $objEditItems->GetItem($RelationId);
  $Rel = new clsRelationship();
  $Rel->tablename = $objEditItems->SourceTable;
  $Rel->LoadFromDatabase($RelationId);
  //$Rel->LoadExpanded($RelationId);
  $action = "m_edit_relation";
}
else
{
  $Rel = new clsRelationship();
  $Rel->Set("SourceType","2");
  $Rel->Set("SourceId",$c->Get("ResourceId"));
  $Rel->Set("TargetId",$_POST["TargetId"]);
  $Rel->Set("TargetType",$_POST["TargetType"]);
  $Rel->Set("Type","0");
  $Rel->Set("Enabled","1");
  $action = "m_add_relation";
}

$item = $Rel->GetTargetItemData();

$envar = "env=" . BuildEnv() . "&en=$en";

$section = 'in-news:editarticle_relation'; 

$ado = &GetADODBConnection();

/* page header */
$charset = GetRegionalOption('Charset');
print <<<END
<html>
<head>
  <title>In-portal</title>
  <meta http-equiv="content-type" content="text/html;charset=$charset">
  <meta http-equiv="Pragma" content="no-cache">
  <script language="JavaScript">
    imagesPath='$imagesURL'+'/';
  </script>
  <script src="$browseURL/common.js"></script>
  <script src="$browseURL/toolbar.js"></script>
  <script src="$browseURL/utility.js"></script>
  <script src="$browseURL/checkboxes.js"></script>
  <script language="JavaScript1.2" src="$browseURL/fw_menu.js"></script>
  <link rel="stylesheet" type="text/css" href="$browseURL/checkboxes.css">
  <link rel="stylesheet" type="text/css" href="$cssURL/style.css">
  <link rel="stylesheet" type="text/css" href="$browseURL/toolbar.css">
END;


$title = prompt_language("la_Text_Editing")." ".prompt_language("la_Text_Article")." '".$c->Get("Title")."' - ".prompt_language("la_tab_Relations");
$title .= " ".prompt_language("la_Text_to")." ".$item[$item["TitleField"]];

$objListToolBar = new clsToolBar();
$objListToolBar->Add("img_save", "la_Save","#","swap('img_save','toolbar/tool_select_f2.gif');", "swap('img_save', 'toolbar/tool_select.gif');","do_edit_save('article','NewsEditStatus','in-news/admin/addarticle_relations.php',0);",$imagesURL."/toolbar/tool_select.gif");
$objListToolBar->Add("img_cancel", "la_Cancel","#","swap('img_cancel','toolbar/tool_cancel_f2.gif');", "swap('img_cancel', 'toolbar/tool_cancel.gif');","do_edit_save('article','NewsEditStatus','in-news/admin/addarticle_relations.php',-1);",$imagesURL."/toolbar/tool_cancel.gif");

int_header($objListToolBar,NULL,$title);
if ($objSession->GetVariable("HasChanges") == 1) {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="toolbar">
  <tr>
    <td valign="top">
      <?php int_hint_red(admin_language("la_Warning_Save_Item")); ?>
    </td>
  </tr>
</table>
<?php } ?>
<TABLE cellSpacing="0" cellPadding="2" width="100%" class="tableborder">
<FORM ID="article" NAME="article" method="POST" ACTION="">
<?php int_subsection_title("Relation"); ?>
 <TR <?php int_table_color(); ?> >
  <TD>
    <span class="text"><?php echo prompt_language("la_prompt_RelationId"). ":</span></TD><TD>".$Rel->Get("RelationshipId"); ?>
  </TD>
  <TD>&nbsp;</TD>
</TR>

<TR <?php int_table_color(); ?> >
  <TD><span class="text"><?php echo prompt_language("la_prompt_Item"); ?></SPAN></TD>
   <TD>
     <IMG src="<?php echo $Rel->Admin_Icon(); ?>" align="absmiddle"><SPAN id="TargetName"><?php echo $item[$item["TitleField"]]; ?></SPAN> <SPAN ID="TargetTypeName">(<?php echo prompt_language("la_Text_".$item["SourceTable"]); ?>)</SPAN>
  </TD>
  <TD>&nbsp;</TD>
</TR>
<TR <?php int_table_color(); ?> >
    <TD><span class="text"><?php echo prompt_language("la_prompt_Type"); ?></SPAN></TD>
  <TD>

<?php
  $Recip = "";   
  $OneWay = "";   
  if($Rel->Get("Type")=="1")
  {
      $Recip = " CHECKED";
  }
  else
    $OneWay = " CHECKED";
?>
    <input type="radio" tabindex="1" name="RelType" VALUE=1 <?php echo $Recip; ?>><?php echo prompt_language("la_Text_Reciprocal"); ?>
    <input type="radio" tabindex="1" name="RelType" VALUE=0 <?php echo $OneWay; ?>><?php echo prompt_language("la_Text_OneWay"); ?>
  </TD>
    <TD>&nbsp;</TD>
</TR>

    <TR <?php int_table_color(); ?> >
    <TD><span class="text"><?php echo prompt_language("la_prompt_Enabled"); ?></SPAN></TD>
  <TD>
     <?php
        $checked = "";
        if($Rel->Get("Enabled")=="1")
        {        
            $checked = " CHECKED";         
        }
     ?>
     <input type="checkbox" tabindex="2" VALUE="1" name="Enabled" <?php echo $checked; ?>>
  </TD>
  <TD>&nbsp;</TD>
</TR>
<TR <?php int_table_color(); ?> >
  <TD><span class="text"><?php echo prompt_language("la_prompt_Priority"); ?></SPAN></TD>
  <TD>
     <INPUT TYPE="TEXT" tabindex="3" SIZE="5" NAME="priority" VALUE="<?php echo $Rel->Get("Priority"); ?>"> 
  </TD> 
  <TD>&nbsp;</TD>
</TR>
    <input type="hidden" name="TargetId" value ="<?php echo $Rel->Get("TargetId"); ?>">
    <input type="hidden" name="TargetType" value ="<?php echo $Rel->Get("TargetType"); ?>">
    <input type="hidden" name="SourceType" value ="<?php echo $Rel->Get("SourceType"); ?>">
    <input type="hidden" name="SourceId" value ="<?php echo $c->Get("ResourceId"); ?>">
    <INPUT TYPE="hidden" NAME="RelationshipId" VALUE="<?php echo $Rel->Get("RelationshipId"); ?>">
    <input type="hidden" name="Action" value="<?php echo $action; ?>">
    <input type="hidden" name="NewsEditStatus" VALUE="0">
</FORM>
</TABLE>

<FORM NAME="save_edit_buttons" ID="save_edit_buttons" method="POST" ACTION="">
  <tr <?php int_table_color(); ?>>
    <td colspan="3">
    <input type=hidden NAME="Action" VALUE="save_cat_edit">
    <input type="hidden" name="NewsEditStatus" VALUE="0">
    </td>
  </tr>
</FORM>


<!-- CODE FOR VIEW MENU -->
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]."?".$envar; ?>" name="viewmenu">
<input type="hidden" name="fieldname" value="">
<input type="hidden" name="varvalue" value="">
<input type="hidden" name="varvalue2" value="">
<input type="hidden" name="Action" value="">
</form>
<!-- END CODE-->

<?php int_footer(); ?>