<?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(__FILE__));
  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"; 
//$pathtolocal = $pathtoroot."in-news/";
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");

unset($objEditItems);

$objEditItems = new clsBanRuleList();
$objEditItems->SourceTable = $objSession->GetEditTable("BanRules");
$objEditItems->EnablePaging = FALSE;

//Multiedit init
if ($_GET["new"] == 1)
{
	$c = new clsBanRule(NULL);
	$c->Set("ItemType", 6);
	$c->Set("Priority", 0);	
    $en = 0;
    $action = "m_add_rule";
    $objBanList->CreateEmptyEditTable("RuleId");
}
else
{
    $en = (int)$_GET["en"];
    if (isset($_POST["itemlist"]))
    {
        $objBanList->CopyToEditTable("RuleId",$_POST["itemlist"]);
    }
    $objEditItems->Query_Item("SELECT * FROM ".$objEditItems->SourceTable);

    $itemcount=$objEditItems->NumItems();
    $c = $objEditItems->GetItemByIndex($en);

    if($itemcount>1)
    {
	  if ($en+1 == $itemcount)
		$en_next = -1;
	  else
		$en_next = $en+1;

	  if ($en == 0)
		$en_prev = -1;
	  else
		$en_prev = $en-1;
    }
    $action = "m_edit_rule";
}

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

if (strlen($secvar = $_GET["section"]))
	$addSection = "&section=$secvar";
	
//echo "TEST: $secvar";

$section = 'in-portal:user_rule_edit';

$title = prompt_language("la_Text_Editing")." ".prompt_language("la_Text_Rule");
//echo $envar."<br>\n";

//Display header
$sec = $objSections->GetSection($section);
$objCatToolBar = new clsToolBar();
$objCatToolBar->Add("img_save", "la_Save","#","swap('img_save','toolbar/tool_select_f2.gif');", "swap('img_save', 'toolbar/tool_select.gif');","edit_submit('rule','RuleEditStatus','".$admin."/config/edit_banlist.php',1,'$addSection&DataType=6');","tool_select.gif");
$objCatToolBar->Add("img_cancel", "la_Cancel","#","swap('img_cancel','toolbar/tool_cancel_f2.gif');", "swap('img_cancel', 'toolbar/tool_cancel.gif');","edit_submit('rule','RuleEditStatus','".$admin."/config/edit_banlist.php',2,'$addSection&DataType=6');","tool_cancel.gif");
 
if ( isset($en_prev) || isset($en_next) )
{
  $url = $RootUrl.$admin."/users/addrule.php"; 
  $StatusField = "RuleEditStatus";
  $form = "rule";
  MultiEditButtons($objCatToolBar, $en_next, $en_prev, $form, $StatusField, $url, $sec->Get("OnClick"), $addSection);  
  $objCatToolBar->Add("divider");
}

  int_header($objCatToolBar,NULL,$title);
?>  	
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder">
<form ID="rule" name="rule" action="" method=POST>
<?php int_subsection_title(prompt_language("la_tab_Rule")); ?>

<tr <?php int_table_color(); ?>> 
    <td valign="top"><span ID="prompt_rule_type" class="text"><?php echo prompt_language("la_prompt_RuleType"); ?></span></td>
    <td>
      <SELECT name="rule_type" tabindex="4">
        <option value="0"<?php if($c->Get("RuleType")==0) echo " SELECTED"; ?>><?php echo admin_language("la_Text_Deny"); ?></OPTION>
        <option value="1"<?php if($c->Get("RuleType")==1) echo " SELECTED"; ?>><?php echo admin_language("la_Text_Allow"); ?></OPTION>
	  </SELECT>               
    </td>
    <td></td>
</tr>
 <tr <?php int_table_color(); ?>> 
    <td valign="top"><span class="text"><?php echo prompt_language("la_prompt_ItemField"); ?></span></td>
    <td> 
      <SELECT name="rule_field" tabindex="5">
        <option value="ip"<?php if($c->Get("ItemField")=="ip") echo " SELECTED"; ?>><?php echo admin_language("la_Text_IPAddress"); ?></OPTION>
        <option value="Login"<?php if($c->Get("ItemField")=="Login") echo " SELECTED"; ?>><?php echo admin_language("la_Text_Login"); ?></OPTION>
        <option value="Email"<?php if($c->Get("ItemField")=="Email") echo " SELECTED"; ?>><?php echo admin_language("la_Text_Email"); ?></OPTION>
        <option value="FirstName"<?php if($c->Get("ItemField")=="FirstName") echo " SELECTED"; ?>><?php echo admin_language("la_Text_FirstName"); ?></OPTION>
        <option value="LastName"<?php if($c->Get("ItemField")=="LastName") echo " SELECTED"; ?>><?php echo admin_language("la_Text_LastName"); ?></OPTION>
        <option value="Address"<?php if($c->Get("ItemField")=="Address") echo " SELECTED"; ?>><?php echo admin_language("la_Text_Address"); ?></OPTION>        
        <option value="City"<?php if($c->Get("ItemField")=="City") echo " SELECTED"; ?>><?php echo admin_language("la_Text_City"); ?></OPTION>
        <option value="State"<?php if($c->Get("ItemField")=="State") echo " SELECTED"; ?>><?php echo admin_language("la_Text_State"); ?></OPTION>
        <option value="Zip"<?php if($c->Get("ItemField")=="Zip") echo " SELECTED"; ?>><?php echo admin_language("la_Text_Zip"); ?></OPTION>
        <option value="Phone"<?php if($c->Get("ItemField")=="Phone") echo " SELECTED"; ?>><?php echo admin_language("la_Text_Phone"); ?></OPTION>
	  </SELECT>              
    </td>
    <td><span class="text">&nbsp;</span></td>
</tr>
 <tr <?php int_table_color(); ?>> 
    <td valign="top"><span class="text"><?php echo prompt_language("la_prompt_ItemVerb"); ?></span></td>
    <td> 
      <SELECT name="rule_verb"  tabindex="6">
        <option value="0"<?php if($c->Get("ItemVerb")==0) echo " SELECTED"; ?>><?php echo admin_language("la_Text_Any"); ?></OPTION>
        <option value="1"<?php if($c->Get("ItemVerb")==1) echo " SELECTED"; ?>><?php echo admin_language("la_Text_Is"); ?></OPTION>
        <option value="2"<?php if($c->Get("ItemVerb")==2) echo " SELECTED"; ?>><?php echo admin_language("la_Text_IsNot"); ?></OPTION>
        <option value="3"<?php if($c->Get("ItemVerb")==3) echo " SELECTED"; ?>><?php echo admin_language("la_Text_Contains"); ?></OPTION>
        <option value="4"<?php if($c->Get("ItemVerb")==4) echo " SELECTED"; ?>><?php echo admin_language("la_Text_NotContains"); ?></OPTION>
        <option value="5"<?php if($c->Get("ItemVerb")==5) echo " SELECTED"; ?>><?php echo admin_language("la_Text_GreaterThan"); ?></OPTION>        
        <option value="6"<?php if($c->Get("ItemVerb")==6) echo " SELECTED"; ?>><?php echo admin_language("la_Text_LessThan"); ?></OPTION>
        <option value="7"<?php if($c->Get("ItemVerb")==7) echo " SELECTED"; ?>><?php echo admin_language("la_Text_Exists"); ?></OPTION>
        <option value="8"<?php if($c->Get("ItemVerb")==8) echo " SELECTED"; ?>><?php echo admin_language("la_Text_Unique"); ?></OPTION>        
	  </SELECT>              
    </td>
    <td><span class="text">&nbsp;</span></td>
</tr>

 <tr <?php int_table_color(); ?>> 
    <td valign="top"><span id="prompt_rule_value" class="text"><?php echo prompt_language("la_prompt_ItemValue"); ?></span></td>
    <td> 
	  <input type="text" ValidationType="exists" tabindex="7" name="rule_value" class="text" size="20" value="<?php echo $c->Get("ItemValue"); ?>">
	</td>
	<td></td>
</tr>
 <tr <?php int_table_color(); ?>> 
    <td valign="top"><span class="text"><?php echo prompt_language("la_prompt_ErrorTag"); ?></span></td>
    <td> 
	  <input type="text" name="rule_error" tabindex="8" class="text" size="20" value="<?php echo $c->Get("ErrorTag"); ?>">
	  <?php if(strlen($c->Get("ErrorTag"))) echo prompt_language($c->Get("ErrorTag")); ?>
	</td>
	<td></td>
</tr>
<TR <?php int_table_color(); ?> >
  <TD><?php echo prompt_language("la_prompt_Priority"); ?></TD>
  <TD><input type=text SIZE="5" NAME="rule_priority" tabindex="9" VALUE="<?php echo $c->Get("Priority"); ?>"></TD>
  <TD></TD>
</TR>		  
<TR <?php int_table_color(); ?> >
  <TD><?php echo prompt_language("la_prompt_Status"); ?></TD>
  <TD>
    <input type="RADIO" NAME="rule_status" tabindex="10" <?php if($c->Get("Status")==1) echo "CHECKED"; ?> VALUE="1"><?php echo prompt_language("la_Text_Enabled"); ?>
    <input type="RADIO" NAME="rule_status" tabindex="10" <?php if($c->Get("Status")==0) echo "CHECKED"; ?> VALUE="0"><?php echo prompt_language("la_Text_Disabled"); ?>   
  </TD>
  <TD></TD>  
</TR>	  

  <tr <?php int_table_color(); ?>> 
    <td colspan="3"> 
	  <input type="hidden" name="Action" value="<?php echo $action; ?>">
	  <input type="hidden" name="rule_id" value="<?php echo $c->Get("RuleId"); ?>">
      <input type="hidden" name="RuleEditStatus" VALUE="0">
      <input type="hidden" name="rule_itemtype" VALUE=6>
    </td>
  </tr>
  </FORM>
</table>

<SCRIPT language="JavaScript">   
    MarkAsRequired(document.getElementById("rule"));
</SCRIPT>  

<?php int_footer(); ?>