<?php
error_reporting(1);
set_time_limit(0);
session_start();
if(!$_SESSION['USER_NAME'])
{
	header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
	exit;
}
$basepath = explode('modules',getcwd());
require_once($basepath[0]."Basic.php");
require_once($basepath[0]."database.php");
$time = time();
$ais_pos =  strpos($_SERVER['HTTP_REFERER'],'ais')+ 3;
$redir_url =  substr($_SERVER['HTTP_REFERER'],0,$ais_pos);


if(isset($_REQUEST['form2_submit']) && !empty($_REQUEST['form2_submit'])) {
	//echo $Token;
	$Token=$_POST['token'];
	$Token = preg_replace("/\s+/", "", $Token);     // trim whitespace 
	$Url=$_POST['url'];
	$Name=$_POST['name'];
	$data = db_request(db_execute("select * from form2"));
	if(empty($data)){

  		$sql="INSERT INTO form2 (id,url,token,name) values(nextval('FORM_SEQ'),'$Url','$Token','$Name')";
	
	} else {
    
  		$id = $data[1]['ID'];
 	    $sql="update form2 set url='".$Url."', token='".$Token."' ,name='".$Name."' where id='".$id."' ";
	}

	db_request(db_execute($sql));
	echo "<script> window.location ='".$redir_url."' </script> ";
} 
?>

