<?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");

if (!admin_login())
{            
    if(!headers_sent())
      setcookie("sid"," ",time()-3600);
    $objSession->Logout();
    header("Location: ".$adminURL."/login.php");
    die();
	//require_once($pathtoroot."admin/login.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");
require_once($pathtoroot.$admin."/listview/listview.php");

if(strlen($_GET["module"])==0)
{ 
    $module="In-Portal";
}
else
{
    $module=$_GET["module"];
}
if(strlen($_GET["section"])==0)
{
    $section="System";
}
else
{
    $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);
$envar = "module=$module&section=$section&env=" . BuildEnv();

//$title = prompt_language("la_Text_Editing")." ".prompt_language("la_Tab_Search");
$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');","document.configform.submit();","tool_select.gif");
$objCatToolBar->Add("img_cancel", "la_Cancel","#","swap('img_cancel','toolbar/tool_cancel_f2.gif');", "swap('img_cancel', 'toolbar/tool_cancel.gif');","history.back();","tool_cancel.gif");

$ParentSection = $sec->Get("parent");
$ParentSec = $objSections->GetSection($ParentSection);
$ParentUrl = $ParentSec->URL();
if($ParentSec->Get("parent"))
{
	$SubmitUrl = $ParentUrl;
}
else
  $SubmitUrl = $_SERVER['PHP_SELF']."?".$envar;
   
int_header($objCatToolBar,NULL,$title);
?>
<form name="configform" ID="configform" action="<?php echo $SubmitUrl; ?>" method=POST>
<table cellSpacing="0" cellPadding="2" width="100%" class="tableborder">
<tbody>
<?php
  $objSearchFields = new clsSearchConfigList($module);
  $headings = $objSearchFields->GetHeadingList();

  for($i=0;$i<=count($headings);$i++)
  {
    $h = $headings[$i];
    if(strlen($h))
    {
        int_subsection_title(prompt_language($h));
        $Items = $objSearchFields->GetHeadingItems($h);
        foreach($Items as $c)
        {
          print "<tr ".int_table_color_ret().">\n";          
          print "<TD>".prompt_language($c->Get("DisplayName"))."</TD>\n";
          $checked = "";
          if((int)$c->Get("SimpleSearch")==1)
              $checked = " CHECKED";
          print "<TD class=\"text\">";  
          print prompt_language("la_prompt_SimpleSearch");
          print "<INPUT TYPE=checkbox NAME=\"simple[".$c->Get("SearchConfigId")."]\" VALUE=\"1\"$checked>";
          print "&nbsp;&nbsp;".prompt_language("la_prompt_weight")."&nbsp;<input type=\"text\" size=3 NAME=\"pri[".$c->Get("SearchConfigId")."]\" VALUE=\"".(int)$c->Get("Priority")."\">";
          print "</TD>\n";
          $checked = "";
          if((int)$c->Get("AdvancedSearch")==1)
              $checked = " CHECKED";
          print "<TD class=\"text\"><INPUT TYPE=checkbox NAME=\"advanced[".$c->Get("SearchConfigId")."]\" VALUE=\"1\"$checked>";
          print prompt_language("la_prompt_AdvancedSearch")."</TD>\n";
          print "</TR>\n";
        }
        int_subsection_title(prompt_language($h)."&nbsp;".prompt_language("la_prompt_relevence_settings"));
        print "<tr ".int_table_color_ret().">\n";          
        print "<TD colspan=4>";
        print prompt_language("la_prompt_required_field_increase");
        $cfg_var = strtolower(prompt_language($h,1));
        $cfg = "SearchRel_Increase_".$cfg_var;
        $value = $objConfig->Get($cfg);
        
        if(!is_numeric($value))
            $value = (int)$objConfig->Get("SearchRel_DefaultIncrease");
            
        print "<input type=\"text\" size=3 name=\"req_increase[$cfg_var]\" VALUE=\"$value\">%";
        print "<input type=\"hidden\" name=\"cfg_var\" VALUE=\"$cfg_var\">%";
        print "</TD></TR>";
        print "<tr ".int_table_color_ret().">\n";          
        print "<TD colspan=4>";
        print prompt_language("la_prompt_relevence_percent");
        $cfg = "SearchRel_Keyword_".$cfg_var;
        $value = $objConfig->Get($cfg);
        if(!is_numeric($value))
            $value = (int)$objConfig->Get("SearchRel_DefaultKeyword");
        print " <input type=\"text\" size=3 name=\"rel_keyword[$cfg_var]\" VALUE=\"$value\">% ";
        print prompt_language("la_text_keyword")." ";
        $cfg = "SearchRel_Pop_".$cfg_var;
        $value = $objConfig->Get($cfg);
        if(!is_numeric($value))
            $value = (int)$objConfig->Get("SearchRel_DefaultPop");
        print "&nbsp;&nbsp;&nbsp;<input type=\"text\" size=3 name=\"rel_pop[$cfg_var]\" VALUE=\"$value\">% ";
        print prompt_language("la_text_popularity");
        $cfg = "SearchRel_Rating_".$cfg_var;
        $value = $objConfig->Get($cfg);
        if(!is_numeric($value))
            $value = (int)$objConfig->Get("SearchRel_DefaultRating");
        print "&nbsp;&nbsp;&nbsp;<input type=\"text\" size=3 name=\"rel_rating[$cfg_var]\" VALUE=\"$value\">% ";
        print prompt_language("la_prompt_Rating");
        
        if ($module != 'In-Portal') {
        	$cfg = "Search_ShowMultiple_".$cfg_var;        	
    	   	int_subsection_title(prompt_language($h)."&nbsp;".prompt_language("la_Text_MultipleShow"));
	        print "<tr ".int_table_color_ret().">\n";          
	        print "<TD>".prompt_language("la_prompt_MultipleShow")."</TD>\n";
	        $checked = "";
	        if((int)$objConfig->Get($cfg)==1)
	            $checked = " CHECKED";
	        print "<TD class=\"text\" colspan=\"2\">";  
	        print "<INPUT TYPE=checkbox NAME=\"multiple[$cfg_var]\" VALUE=\"1\"$checked>";
	        print "</TD>\n";
	        print "</TR>\n";        	
        }        	
    }
  }
  
  if ($module == 'In-Portal') {
	$cfg = "Search_MinKeyword_Length";    
    $value = $objConfig->Get($cfg);
    if(!is_numeric($value)) {
        $value = (int)$objConfig->Get("Search_MinKeyword_Length");
    }
	
   	int_subsection_title(prompt_language("la_Text_MinKeyWordLength"));
    print "<tr ".int_table_color_ret().">\n";          
    print "<TD>".prompt_language("la_prompt_MinKeyWordLength")."</TD>\n";
    print "<TD class=\"text\" colspan=\"2\">";  
    print "<INPUT TYPE=text NAME=\"minkeyword\" VALUE=\"$value\">";
    print "</TD>\n";
    print "</TR>\n";    	
  }  	
?>
  <tr <?php int_table_color(); ?>> 
    <td colspan="3"> 
      <input type="hidden" name="Action" value="m_SearchConfig_Edit">
      <INPUT TYPE="hidden" NAME="module" VALUE="<?php echo $module; ?>">
    </td>
  </tr>
</TBODY>
</TABLE>
</FORM>