<?php 

if(!strlen($pathtoroot))
{
  $path=dirname(realpath($_SERVER['SCRIPT_FILENAME']));
  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;
//echo $pathtoroot;
require_once($pathtoroot."kernel/startup.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");
	
	//Set Section
	$section = "in-portal:main_import";
	
	//Set Environment Variable
	$envar = "env=" . BuildEnv();
	
	$sec = $objSections->GetSection($section);
	$objCatToolBar = new clsToolBar();

	//check if the previous input is correct
	if( $_POST["Action"] == 'checkconn')
	{
	    // save supplied connection info
	    $objSession->SetVariable("import_sql_type",	$_POST["db_sql_type"]);
	    $objSession->SetVariable("import_server",	$_POST["db_server"]);
	    $objSession->SetVariable("import_db",		$_POST["db_db"]);
	    $objSession->SetVariable("import_user",		$_POST["db_user"]);
	    $objSession->SetVariable("import_pass",		$_POST["db_pass"]);
	    $objSession->SetVariable("error_importing", '');
		
	    // get them for using here
	    $db_sql_type	=	$objSession->GetVariable("import_sql_type");
	    $db_server		=	$objSession->GetVariable("import_server");
	    $db_db			=	$objSession->GetVariable("import_db");
	    $db_user		=	$objSession->GetVariable("import_user");
	    $db_pass		=	$objSession->GetVariable("import_pass");
		
		// check supplied connection
	   	$linkconn = ADONewConnection($db_sql_type);
	    if( !$linkconn->PConnect($db_server, $db_user, $db_pass, $db_db) || !$db_server || !$db_db )
	    {
	        $objSession->SetVariable("error_importing","Error: The connection to the DB failed please check your settings");
	        header('Location: step3.php?'.$envar);
	   	}
	    unset($linkconn);
	}
	
	$import_script = GetImportScript( $objSession->GetVariable('ImportScriptID') );
		
	$var = "?env=".BuildEnv();
    
    // Previous Button
    $MouseOver = "swap('moveleft','toolbar/tool_prev_f2.gif');";
    $MouseOut = "swap('moveleft', 'toolbar/tool_prev.gif');";
    $link = $adminURL."/import/step3.php".$var;
    $objCatToolBar->Add("moveleft",admin_language("la_ToolTip_Previous")." ".admin_language("la_Text_Step"),$link,$MouseOver,$MouseOut,"","tool_prev.gif");
   
	// Next Button  
    $MouseOver = "swap('moveright','toolbar/tool_next_f2.gif');";
    $MouseOut = "swap('moveright', 'toolbar/tool_next.gif');";
    
    $formaction = $rootURL.$import_script['module'].'/'.$admin.'/import/'.$import_script['url'].'.php?'.$envar;
    
    $onClick = "if( !CheckFinalForm('import_form') ) alert('Please fill in all of the fields'); else import_submit('import_form','$formaction',''); ";
    $objCatToolBar->Add("moveright",admin_language("la_ToolTip_Next")." ".admin_language("la_Text_Step"),'#',$MouseOver,$MouseOut,$onClick,"tool_next.gif");
  
  	// Header
  	$title = admin_language("la_performing_import")." - ".admin_language("la_Step")." 4";
  	int_header($objCatToolBar,NULL,$title);

?>
         
<form id="import_form" name="import_form" method="post" action="<?php echo $_SERVER["PHP_SELF"]."?".$envar; ?>">
	<input type="hidden" name="Action" value="m_save_import_config">  
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder">
	<?php int_subsection_title("Matching Fields - Intechnic In-Portal ");  ?>
<!-- script common fields: begin -->
<?php
if( $import_script['id'] == 'in-link' )
{
?>	
	<tr <?php echo int_table_color(); ?>> 
		<td width="60%" valign="top"><span class="text"><?php echo admin_language("la_prompt_AdminId"); ?></span></td>
		<td> 
			<b><?php echo $objSession->GetVariable("user_admin_names"); ?></b>
			<input type="hidden" name="user_admin" size="15" class="text" value="<?php echo $objSession->GetVariable("user_admin_values"); ?>">
			<input type="hidden" name="grouplist1" value="<?php echo $objSession->GetVariable('grouplist1'); ?>">
			<a href="#"><img src="../images/icon_users_sm.gif" style="cursor:hand;" border="0" onclick="OpenGroupSelector('<?php echo $envar; ?>&en=0&destform=import_form&destfield=grouplist1&Selector=radio');"></a>
		</td>
	</tr>
<?php
}
?>
	<tr <?php echo int_table_color(); ?>> 
		<td width="60%" valign="top"><span class="text"><?php echo admin_language("la_prompt_RegUserId"); ?></span></td>
		<td>
			<b><?php echo $objSession->GetVariable("user_regular_names"); ?></b>
			<input type="hidden" name="user_regular" size="15" class="text" value="<?php echo $objSession->GetVariable("user_regular_values"); ?>">
 		    <input type="hidden" name="grouplist2" value="<?php echo $objSession->GetVariable('grouplist2'); ?>">
 		    <a href="#"><img src="../images/icon_users_sm.gif" style="cursor:hand;" border="0" onclick="OpenGroupSelector('<?php echo $envar; ?>&en=0&destform=import_form&destfield=grouplist2&Selector=radio');"></a>
		</td>
	</tr>
	<tr <?php echo int_table_color(); ?>> 
		<td width="60%" valign="top"><span class="text"><?php 
			echo admin_language("la_prompt_InitImportCat");                         
            $catid = $objSession->GetVariable('categoryid');
			$path = prompt_language($objConfig->Get("Root_Name"));
			if($catid > 0)
			{
				$c = $objCatList->GetItemByField('ResourceId', $catid);
				$path .= "&gt;".$c->GetCachedNavBar();
			}          
             ?>
		</td>
		<td> 
			<b><?php echo $path; ?></b>
			<input type="hidden" name="init_cat" size="15" class="text" value="<?php echo $objSession->GetVariable("categoryid"); ?>">
			<a href="#"><img src="<?php echo $imagesURL; ?>/folder.gif" style="cursor:hand;" border="0" ONCLICK="OpenCatSelector('<?php echo $envar; ?>&source=inlinkimport4&continue_sess=1&destform=import_form&destfield=categorylist&Selector=radio');"></a>
			<input type="hidden" name="categorylist" value="<?php echo $objSession->GetVariable('categorylist'); ?>">
		</td>
	</tr>         
<!-- script common fields: end -->	
<!-- script spefific fields: begin -->	
<?php
	if( $import_script['id'] == 'in-link' )
	{
		if( GetVar('link_image') ) $objSession->SetVariable('link_image', GetVar('link_image') );
?>	
	<tr <?php echo int_table_color(); ?>> 
		<td width="60%" valign="top"><span class="text"><?php echo admin_language("la_prompt_Import_ImageName"); ?></span></td>
		<td> 
			<input type="text" name="link_image" class="text" size="30" value="<?php echo $objSession->GetVariable('link_image'); ?>">
		</td>
	</tr>
<?php
	}
	
	if( $import_script['module'] == 'in-bulletin' )
	{
		if( GetVar('bb_prefix') ) $objSession->SetVariable('import_table_prefix', GetVar('bb_prefix') );
?>
	<tr <?php echo int_table_color(); ?>> 
		<td width="60%" valign="top"><span class="text"><?php echo admin_language("la_prompt_Import_Prefix"); ?></span></td>
		<td> 
			<input type="text" name="bb_prefix" class="text" size="30" value="<?php echo $objSession->GetVariable('import_table_prefix'); ?>">
		</td>
	</tr>
<?php
	}
?>
<!-- script spefific fields: end -->
</table>
</form>
<?php
int_footer();
?>