<?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', '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 ($pathtolocal."admin/include/navmenu.php"); 
require_once($pathtoroot.$admin."/toolbar.php");
require_once($pathtoroot.$admin."/listview/listview.php");

$FieldType = $_GET["DataType"];
$section = $_GET["section"];

$m = GetModuleArray();
foreach($m as $key=>$value)
{
    $path = $pathtoroot. $value."admin/include/parser.php";
    if(file_exists($path))
    {    
      include_once($path);
    }
}
unset($objEditItems);

$objBanList = new clsBanRuleList();

$envar = "section=$section&DataType=$FieldType&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","RuleChecks");
$objListToolBar->Set("CheckForm","configform");
  
$listImages = array();
                    //$img, $alt, $link, $onMouseOver, $onMouseOut, $onClick

$objListToolBar->Add("new_rule", "la_ToolTip_New_Rule",$adminURL."/users/addrule.php?$envar&new=1","swap('new_rule','toolbar/tool_new_rule_f2.gif');",
                    "swap('new_rule', 'toolbar/tool_new_rule.gif');","",$imagesURL."/toolbar/tool_new_rule.gif");

$objListToolBar->Add("apply_rules", "la_ToolTip_Apply_Rules",$adminURL."/users/banlist_apply.php?$envar","swap('apply_rules','toolbar/tool_apply_rules_f2.gif');",
                    "swap('apply_rules', 'toolbar/tool_apply_rules.gif');","",$imagesURL."/toolbar/tool_apply_rules.gif");

$objListToolBar->Add("rule_edit","la_ToolTip_Edit","#", "if (RuleChecks.itemChecked()) swap('rule_edit','toolbar/tool_edit_f2.gif');",
                    "if (RuleChecks.itemChecked()) swap('rule_edit', 'toolbar/tool_edit.gif');","if (RuleChecks.itemChecked()) RuleChecks.check_submit('../users/addrule', '');",
                    "tool_edit.gif", TRUE, TRUE);
$listImages[] = "RuleChecks.addImage('rule_edit','$imagesURL/toolbar/tool_edit.gif','$imagesURL/toolbar/tool_edit_f3.gif',1); ";

$objListToolBar->Add("rule_del","la_ToolTip_Delete","#", "if (RuleChecks.itemChecked()) swap('rule_del','toolbar/tool_delete_f2.gif');",
                    "if (RuleChecks.itemChecked()) swap('rule_del', 'toolbar/tool_delete.gif');","if (RuleChecks.itemChecked()) RuleChecks.check_submit('edit_banlist', 'm_rule_delete');",
                    "tool_delete.gif", FALSE, TRUE);
$listImages[] = "RuleChecks.addImage('rule_del','$imagesURL/toolbar/tool_delete.gif','$imagesURL/toolbar/tool_delete_f3.gif',1); ";

$objListToolBar->Add("divider");

$objListToolBar->Add("move_up","la_ToolTip_Move_Up","#", "if (RuleChecks.itemChecked()) swap('move_up','toolbar/tool_move_up_f2.gif');",
                    "if (RuleChecks.itemChecked()) swap('move_up', 'toolbar/tool_move_up.gif');","if (RuleChecks.itemChecked()) RuleChecks.check_submit('edit_banlist', 'm_rule_move_up');",
                    "tool_move_up.gif");
$listImages[] = "RuleChecks.addImage('move_up','$imagesURL/toolbar/tool_move_up.gif','$imagesURL/toolbar/tool_move_up_f3.gif',1); ";

$objListToolBar->Add("move_down","la_ToolTip_Move_Down","#", "if (RuleChecks.itemChecked()) swap('move_down','toolbar/tool_move_down_f2.gif');",
                    "if (RuleChecks.itemChecked()) swap('move_down', 'toolbar/tool_move_down.gif');","if (RuleChecks.itemChecked()) RuleChecks.check_submit('edit_banlist', 'm_rule_move_down');",
                    "tool_move_down.gif");
$listImages[] = "RuleChecks.addImage('move_down','$imagesURL/toolbar/tool_move_down.gif','$imagesURL/toolbar/tool_move_down_f3.gif',1); ";

$objListToolBar->AddToInitScript($listImages);
//$objListToolBar->AddToInitScript("fwLoadMenus(); \n");

$where = "ItemType = ".$FieldType;
$SearchWords = $objSession->GetVariable("RuleSearchWord");
if(strlen($SearchWords))
{
    $where .= " AND ".$objBanList->AdminSearchWhereClause($SearchWords);
}

$order = trim($objConfig->Get("BanRules_LV_Sortfield")." ".$objConfig->Get("BanRules_LV_Sortorder"));

$sql = "SELECT ELT(r.Status+1,'".admin_language("la_Text_Disabled")." ','".admin_language("la_Text_Enabled")." ') as Status, ";
$sql .= "ELT(r.RuleType+1,'".admin_language("la_Text_Deny")." ','".admin_language("la_Text_Allow")." ') as RuleType, ";
$sql .= "ELT(r.ItemVerb+1,'".admin_language("la_Text_Any")." ','".admin_language("la_Text_Is")." ','".admin_language("la_Text_IsNot")." ','".admin_language("la_text_Contains");
$sql .=   " ','".admin_language("la_Text_NotContains")." ','".admin_language("la_Text_GreaterThan")." ','".admin_language("la_Text_LessThan");
$sql .=   " ','".admin_language("la_Text_Exists")." ','".admin_language("la_Text_Unique")."') as ItemVerb, r.RuleId as RuleId, ";
$sql .= "r.ItemValue as ItemValue, r.ItemField as ItemField, r.Priority as Priority FROM ".$objBanList->SourceTable." as r ";
$sql .= "WHERE $where ORDER BY Priority DESC";

if(strlen($order))
  $sql .= ", ".$order;

 // echo $sql;
  
$objBanList->Query_Item($sql);

$objListView = new clsListView($objListToolBar,$objBanList);
$objListView->IdField = "RuleId";

$order = $objConfig->Get("BanRules_LV_Sortfield");
$objListView->ColumnHeaders->Add("RuleType",admin_language("la_ColHeader_RuleType"),1,0,$order,"width=\"30%\"","BanRules_LV_Sortfield","BanRules_LV_Sortorder","RuleType");
$objListView->ColumnHeaders->Add("ItemField",admin_language("la_ColHeader_ItemField"),1,0,$order,"width=\"30%\"","BanRules_LV_Sortfield","BanRules_LV_Sortorder","ItemField");
$objListView->ColumnHeaders->Add("ItemVerb",admin_language("la_ColHeader_ItemVerb"),1,0,$order,"width=\"30%\"","BanRules_LV_Sortfield","BanRules_LV_Sortorder","ItemVerb");
$objListView->ColumnHeaders->Add("ItemValue",admin_language("la_ColHeader_ItemValue"),1,0,$order,"width=\"30%\"","BanRules_LV_Sortfield","BanRules_LV_Sortorder","ItemValue");
$objListView->ColumnHeaders->Add("Status",admin_language("la_ColHeader_Status"),1,0,$order,"width=\"30%\"","BanRules_LV_Sortfield","BanRules_LV_Sortorder","Status");

$objListView->ColumnHeaders->SetSort($objConfig->Get("BanRules_LV_Sortfield"), $objConfig->Get("BanRules_LV_Sortorder"));

$objListView->PrintToolBar = FALSE;
$objListView->checkboxes = TRUE;
$objListView->SearchBar=TRUE;
$objListView->SearchAction = "m_rule_search";

$objListView->CurrentPageVar = "Page_BanRules";
$objListView->PerPageVar = "Perpage_BanRules";
$objListView->CheckboxName = "itemlist[]"; 
$objListView->extra_env = "section=$section&DataType=$FieldType";

//$objListView->ConfigureViewMenu($SortFieldVar,$SortOrderVar,$DefaultSortField,"","",0);

// $title = prompt_language("la_Text_Editing")." ".prompt_language("la_Text_BanRules");

$objSession->SetVariable("HasChanges", 0);

$filter = false; // always initialize variables before use
if($objSession->GetVariable("RuleSearchWord") != '') {
	$filter = true;
} 

$h = "\n\n<SCRIPT Language=\"JavaScript1.2\">\n".$objListView->GetViewMenu($imagesURL)."\n</SCRIPT>\n";
if( !isset($title) ) $title = '';
int_header($objListToolBar,NULL, $title,NULL,$h);

if ($filter) { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="toolbar">
  <tr>
    <td valign="top">
      <?php int_hint_red(admin_language("la_Warning_Filter")); ?>
    </td>
  </tr>
</table>
<?php } ?>
<form name="configform" ID="configform" action="<?php echo $_SERVER["PHP_SELF"]."?".$envar;?>" method=POST>
<table cellSpacing="0" cellPadding="2" width="100%" class="tableborder">
<tbody>
<?php
  $objListView->PageLinks = $objListView->PrintPageLinks(); /* call this before we slice! */
  $objListView->SliceItems();
  print $objListView->PrintList();
  
?>
    <input TYPE="hidden" NAME="DataType" VALUE="<?php echo $FieldType; ?>">
    <input type="hidden" NAME="section" VALUE="<?php echo $section; ?>">
    <input type="hidden" name="Action" value="m_config_custom">
</FORM>
<!-- CODE FOR VIEW MENU -->
<form ID="viewmenu" 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>
<FORM ID="ListSearchForm" NAME="ListSearchForm" method="POST" action="<?php echo $_SERVER["PHP_SELF"]."?env=".BuildEnv()."&section=$section&DataType=6"; ?>">
   <INPUT TYPE="HIDDEN" NAME="Action" VALUE="">
   <INPUT TYPE="HIDDEN" NAME="list_search">
</FORM>


<script src="<?php echo $adminURL; ?>/listview/listview.js"></script>
<script>
initSelectiorContainers();
<?php echo $objListToolBar->Get("CheckClass").".setImages();"; ?>
</script>
<?php int_footer(); ?>