<?
session_start();

ini_set("display_errors", true);
error_reporting(E_ALL^E_NOTICE);

Header( 'P3P: CP="CAO PSA OUR"' ); // Prevents cookie blocking from external sites

$dbname="ProjectManagement";

include_once '../inc/report.php';
include_once '../inc/styles.php';

//include_once '../ProjectManagement/'.$_SESSION['PM_Mstyle'].'.inc';

//echo '<br>querystring: ',$_SERVER['QUERY_STRING'];

//echo "<br>index before request pid=",$_REQUEST['projectid']," session pid=",$_SESSION['ProjectId']," pm_pid=",$_SESSION['PM_PROJECTID'];

$ProjectId=$_REQUEST['projectid'];
if ($ProjectId<>'') 
  {
//echo "<br>pid=$ProjectId";
     $_SESSION['ProjectId']=$ProjectId;
     $_SESSION['PM_PROJECTID']=$ProjectId;
  }
//echo "<br>index after request pid=",$_REQUEST['projectid']," session pid=",$_SESSION['ProjectId']," pm_pid=",

$browser=$_SESSION['PM_BROWSER'];
if ($browser=='AN') echo '<head><meta id="meta" name="viewport" content="width=device-width; initial-scale=1.0" </head>>';

$LINENUMBERS=1;

$Instrument=$_REQUEST['Instrument'];
if ($Instrument=="")
	die("<h2>You must provide an Instrument in the url.</h2>");

$_SESSION['Instrument'] = $Instrument;

$Form=$_REQUEST['Form'];
if ($Form=="")
	die("<h2>You must provide a Form in the url.</h2>");

$_SESSION['Form'] = $Form;

$Question=$_REQUEST['Question'];
$_SESSION['Question'] = $Question;

deBug("Q index server URL=".$_SERVER['REQUEST_URI']);

$qprmid=$_REQUEST['qprmid'];
if($qprmid>'') $UserId=$qprmid;
elseif ($_SESSION['UserId']>"")
	$UserId=$_SESSION['UserId'];

//echo "<br>qprimid=$qprmid userid=$userid";

//echo '<br>request:',$_REQUEST['CaseId'],' session: ',$_SESSION['CaseId'];
$CaseId=$_REQUEST['CaseId'];
if ($CaseId=="")
	$CaseId=$_SESSION['CaseId'];
	if ($CaseId=="")
	    $CaseId="-1";
//		die("<h2>You must identify a subject to access this page</h2>");

$_SESSION['CaseId'] = $CaseId;

$Instance=$_REQUEST['Instance'];
if ($Instance=="")
	$Instance=$_SESSION['Instance'];
	if ($Instance=="")
	    $Instance=1;
//		die("<h2>You must specify an instance to access this page</h2>");

//echo "instance=$Instance";

$_SESSION['Instance'] = $Instance;

//echo "<br>caseid=$CaseId instance=$Instance";

$_SESSION['MsgTxt'] = $MsgTxt;

$exte=$_REQUEST["exte"];
//echo "<br>index exte=$exte";
if($exte=='') $exte=0;

$Ctmp=$_REQUEST['Ctmp'];
$_SESSION['Ctmp'] = $Ctmp;

$Ftmp=$_REQUEST['Ftmp'];
$_SESSION['Ftmp'] = $Ftmp;

$HFtmp=$_REQUEST['HFtmp'];
$_SESSION['HFtmp'] = $HFtmp;
if ($HFtmp=="null")
	{
		$hpcnt="0%";
		$cpcnt="100%";
		$fpcnt="0%";
	}
else
	{
		$hpcnt="24px";
		$cpcntn=78;
		if($_SESSION['PM_BROWSER']=='AN') null;
		elseif($exte==1) $cpcntn=89;
		else $cpcntn=$cpcntn - 3 * ($_SESSION['PM_hmnus']);
		$cpcnt=intval($cpcntn,0).'%';
		$fpcnt="38px";
	}

$BORDERS=$_REQUEST['Borders'];
$_SESSION['BORDERS'] = $BORDERS;

//echo "borders=$BORDERS";

$DE_MODE=$_REQUEST['DE_MODE'];
if ($DE_MODE=="")
	$DE_MODE=$_SESSION['DE_MODE'];
if ($DE_MODE=="") $DE_MODE="O";
$_SESSION['DE_MODE'] = $DE_MODE;

deBug("Q index UserId=$UserId");

if ($UserId=="")
	{
		$UserId=$_SESSION['UserId'];
		if ($UserId=="")
		  {
//			die("<h2>You must log in to access this page</h2>");
			$_SESSION[Url] =  "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
			echo "<body onload='javascript: return popitup(\"../ProjectManagement/Login.php?winnam=UserLogin\",100,375,375,350);
'>";

	}
$_SESSION['UserId'] = $UserId;

//echo "Instrument=" , $Instrument , " Form=" , $Form , " CaseId=" , $CaseId , " UserId=" , $UserId ;

//echo "<font color=white>hpcnt=$hpcnt cpcnt=$cpcnt fpcnt=$fpcnt</font>";

?>
<title><?=$Instrument?></title>

<form name=index enctype="multipart/form-data" method=post>
<BODY id="Body" BOTTOMMARGIN="0" LEFTMARGIN="0" TOPMARGIN="0" RIGHTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<body style="background-color:transparent">
<table border=0 width=99% height=100%>
	<tr>
		<td width=100% height=100% valign=TOP>
			<IFRAME name="QHDIframe" scrolling=no frameborder="<?=$BORDERS?>"
				SRC= "header.php?Instrument=<?=$Instrument?>&Form=<?=$Form?>"
				WIDTH=100% HEIGHT=<?=$hpcnt?> >
	  		</IFRAME>

			<IFRAME name="QCOIframe" id="QCOIframe" scrolling=automatic frameborder="<?=$BORDERS?>"
				SRC= "content.php?Form=<?=$Form?>&Question=<?=$Question?>&BORDERS=<?=$BORDERS?>&Ctmp=<?=$Ctmp?>&Ftmp=<?=$Ftmp?>&exte=<?=$exte?>"
				WIDTH=100% HEIGHT=<?=$cpcnt?> allowtransparency=TRUE >
	  		</IFRAME>
			<IFRAME name="QFTIframe" scrolling=no frameborder="<?=$BORDERS?>"
				SRC= "footer.php?Form=<?=$Form?>&Instrument=<?=$Instrument?>"
				WIDTH=100% HEIGHT=<?=$fpcnt?> >
	  		</IFRAME>
	  	</td>
	</tr>
</table>
</form>
<script language=javascript>
function NewContent()
{
//	alert("in NewContent");
	frames['COIframe'].location.href='content.php';
}
function DoPostBack(act)
{
//alert('index DoPostBack');
	NewContent();
}

function SetInstrumentForm(instrument,form,fmt)
{
//	alert("in SetCase");
	window.document.index.action="index.php?Instrument="+instrument+"&Form="+form+fmt+"&exte=<?=$exte?>";
	window.document.index.submit(true);
}

function SetCase(caseid)
{
//	alert("index in SetCase");
	window.document.index.action="index.php?Instrument=<?=$_SESSION['Instrument']?>&Form=<?=$_SESSION['Form']?>&Question=<?=$_SESSION['Question']?>&CaseId="+caseid+"&iprmid=<?=$_SESSION['UserId']?>&Ctmp=<?=$Ctmp?>&Ftmp=<?=$Ftmp?>&HFtmp=<?=$HFtmp?>&BORDERS=<?=$BORDERS?>&exte=<?=$exte?>";
	window.document.index.submit(true);
}

function SetForm(form,fmt)
{
//	alert("in SetForm form="+form+" fmt="+fmt);
	window.document.index.action="index.php?Instrument=<?=$_SESSION['Instrument']?>&Form="+form+fmt+"&exte=<?=$exte?>";
	window.document.index.submit(true);
}

function SetCaseForm(caseid,form,fmt)
{
//	alert("in SetCaseForm "+caseid+" "+form+" "+fmt);
	window.document.index.action="index.php?Instrument=<?=$_SESSION['Instrument']?>&Form="+form+"&CaseId="+caseid+"&iprmid=<?=$_SESSION['UserId']?>"+fmt+"&exte=<?=$exte?>";
	window.document.index.submit(true);
}

function SetInstanceCaseForm(instance,caseid,form,fmt)
{
//alert("in SetInstanceCaseForm "+instance+" "+caseid+" "+form+" "+fmt);
	act="index.php?Instrument=<?=$_SESSION['Instrument']?>&Form="+form+"&CaseId="+caseid+"&Instance="+instance+"&iprmid=<?=$_SESSION['UserId']?>"+fmt+"&exte=<?=$exte?>";
//alert("act="+act);
	window.document.index.action=act;
	window.document.index.submit(true);
}

function NewCase(caseid)
{
//	alert("in SetCase");
	window.document.index.action="index.php?Instrument=<?=$_SESSION['Instrument']?>&Form=<?=$_SESSION['Form']?>&Question=<?=$_SESSION['Question']?>&CaseId=NEW&iprmid=<?=$_SESSION['UserId']?>&Ctmp=<?=$Ctmp?>&Ftmp=<?=$Ftmp?>&BORDERS=<?=$BORDERS?>&HFtmp=<?=$HFtmp?>&exte=<?=$exte?>";
	window.document.index.submit(true);
}

function EndIt()
{
//alert("in index EndIt");
//	parent.frames[1].EndIt();
//	window.opener.EndIt();
//	window.history.go(-1);
	window.close();
//	window.history.go(-1);
//	return false;
//	Content.EndIt();
//	index.close();
//alert("leaving index EndIt");
}

function SetTab(tabid,iprm)
{
//alert("index SetTab tabid=" + tabid + " iprm=" + iprm);

	window.parent.SetTab(tabid,iprm);
}

function PromptEnd(txt)
{
//alert("Starting PromptEnd txt="+txt);
	alert(txt);
	EndIt();
	return false;
}

//alert("index height:"+window.innerWidth, window.innerHeight);

function popitup(url,t,l,h,w)
{
//alert("URL="+url+" top="+t+" left="+l+" height="+h+" width="+w);
    ps="top=" + t + ",left=" + l + ",height=" + h + ",width=" + w + ",scrollbars=1";
    var d = new Date();
	var n = d.getSeconds();
    wnam="pop_"+n;
	newwindow=window.open(url,wnam,ps);
	newwindow.focus();
//	return false;
}


if(parent==top) document.body.style.backgroundImage = 'url("<?=$_SESSION['PM_CONTENT_BG']?>")';

</script>

