<?php
if( !(isset($pathtoroot) && $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( !(isset($pathtoroot) && $pathtoroot) )
      $pathtoroot = ".".$pathchar;
  }
  else
  {
    $pathtoroot = ".".$pathchar;
  }
}

$sub = substr($pathtoroot,strlen($pathchar)*-1);
if($sub!=$pathchar)
{
  $pathtoroot = $pathtoroot.$pathchar;
}
require_once($pathtoroot."kernel/startup.php");

if (!admin_login())
{            
    if(!headers_sent())
      setcookie("sid"," ",time()-3600);
    $objSession->Logout();
    header("Location: ".$adminURL."/index.php?logout=1");
    die();
	//require_once($pathtoroot."admin/login.php");
}

$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";

//admin only util

$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."/toolbar.php");

$m = GetModuleArray();
foreach($m as $key=>$value)
{
    $path = $pathtoroot.$value."admin/include/parser.php";
    if(file_exists($path))
    {
      //echo "<!-- $path -->";
      @include_once($path);
    }
}

//Set Section
$section = $_GET["section"];
$module = $_GET["module"];
//echo  $module." - ".$section."<br>\n";
//Set Environment Variable
$envar = "env=" . BuildEnv()."&section=$section&module=$module";
 $objCatToolBar = new clsToolBar();
 $objCatToolBar->Add("img_save", "la_Save","#","swap('img_save','toolbar/tool_select_f2.gif');", "swap('img_save', 'toolbar/tool_select.gif');","if(SubmitFunc) { config_submit('edit_config'); } else document.edit_config.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");


$sec = $objSections->GetSection($section);
$ParentSection = $sec->Get("parent");
$ParentSec = $objSections->GetSection($ParentSection);
$ParentUrl = $ParentSec->URL();
if($ParentSec->Get("parent"))
{
	//$SubmitUrl = $ParentUrl."&section=$section&module=$module";
	$SubmitUrl = $ParentUrl;
	//echo "Submitting Parent ($ParentUrl) to: $SubmitUrl <br>\n";
}
else
  $SubmitUrl = $_SERVER['PHP_SELF']."?".$envar;



int_header($objCatToolBar,NULL,$title);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder">
<form name="edit_config" ID="edit_config" action="<?php echo $SubmitUrl; ?>" method=POST>	
<?php
$objAdmin = new clsConfigAdmin($module,$section);
$objAdmin->Clear();
$objAdmin->LoadItems(TRUE);

$headings = $objAdmin->GetHeadingList();

for($i=0;$i<=count($headings);$i++)
{
    $h = $headings[$i];
    if(strlen($h))
    {
        int_subsection_title(prompt_language($h));
        $Items = $objAdmin->GetHeadingItems($h);
        foreach($Items as $c)
        {
            print "<tr ".int_table_color_ret().">\n"; 
            print "  <td width=\"60%\" valign=\"top\"><span class=\"text\">".$c->GetPrompt()."</span></td>\n";
            print "  <td nowrap>".$c->ItemFormElement()."</TD>";       
            if(is_object($c->NextItem))
            {
                $n = $c->NextItem;
                print "  <td>".$n->ItemFormElement()."</TD>";       
            }
            else
              print "  <td><span class=\"text\">&nbsp;</span></td>\n";
            print "</tr>\n";
        }
    }
}
?>
  <tr <?php int_table_color(); ?>> 
    <td colspan="4"> 
      <input type="hidden" name="Action" value="m_config_edit">
      <input type="hidden" name="module" value="<?php echo $module; ?>">
      <input type="hidden" name="section" value="<?php echo $section; ?>">
	</td>
  </tr>
</FORM></TABLE>
<?php
int_footer();
?>