<?php
putenv("ORACLE_HOME=/opt/app/psoft/oracle/client");
putenv("LD_LIBRARY_PATH=/opt/app/psoft/pt853/elm92/bin:/opt/app/psoft/oracle/client/lib:/opt/app/psoft/pt853/elm92/jre/lib/amd64/server:/opt/app/psoft/pt853/elm92/jre/lib/amd64:/opt/app/psoft/pt853/elm92/bin/interfacedrivers:/opt/app/psoft/pt853/elm92/bin/sqr/ORA/bin:/opt/app/psoft/oracle/tuxedo11gR1/lib:/usr/bin");
ob_start(); 

	//Retrieve passed id for website
        $id = $_REQUEST['id'];
        if($id == NULL) {
          $id = "12345";
        }

	//Connect to Oracle Server
         $db_conn['host'] = "(DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = tdclpbj3vd-scan.verizon.com)(PORT = 1521))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = VZLMPRB)))";


	$db_conn['user'] = "PSSURVEY";
	$db_conn['pass'] = "PSSURVEY";
	$db_conn['library'] = "OCI";
	
	$conn = oci_connect($db_conn['user'], $db_conn['pass'], $db_conn['host']);
	
	$query = "SELECT DBMS_LOB.substr(B_LM_URL_DEST) as B_LM_URL_DEST FROM SYSADM.PS_B_URL_REDIRECT WHERE B_LM_URL_ID = ".$id."";
	$query_active = "SELECT LM_ACTIVE FROM SYSADM.PS_B_URL_REDIRECT WHERE B_LM_URL_ID = ".$id."";
	
	//Execute Query
	$statement = oci_parse($conn, $query);
	oci_execute($statement);
	$result = array();
//	while(oci_fetch_assoc($statement, $tmp, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS)) {
//		array_push($result, $tmp);
//	}

while ($tmp = oci_fetch_array($statement,  OCI_BOTH | OCI_RETURN_NULLS)) {
             array_push($result, $tmp);
     }	
//Execute Query 2 (Active or not active)
	$statement1 = oci_parse($conn, $query_active);
	oci_execute($statement1);
	$active_result = array();
//	while(oci_fetch_assoc($statement1, $tmp, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS)) {
        while ($tmp1 = oci_fetch_array($statement1,  OCI_BOTH | OCI_RETURN_NULLS)) {
		array_push($active_result, $tmp1);
	}
	
	
	$active_bool = $active_result[0]["LM_ACTIVE"];
	
	
	//Redirect to correct website.
	$url = $result[0]["B_LM_URL_DEST"];
       // $url=$tmp["B_LM_URL_DEST"];
        $urlannon1 = str_replace("learn.verizon.com","learnapi.verizon.com",$url);
        $urlannon = str_replace("_newwin","",$urlannon1);
	
	if (!empty($url) && $active_bool == 'Y'){
                if ( strpos($url,'B_SRV_LANDING_PG') == false &&  strpos($url,'B_SRV_LC_LANDING') == false &&  strpos($url,'B_SURVEY') == false ) {
                  header("Location: ".$url."");
                } else {?>
<script type="text/javascript">
  function doSubmit(form) {
    var urls = form['url'];
    var i = urls && urls.length;
    while (i--) {
      if (urls[i].checked) {
        window.location = urls[i].value;
      }
    }
    return false;
  }
  </script>
  <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<LINK rel="stylesheet" type="text/css" href="/vzlearn/style.css">

<META name="GENERATOR" content="MSHTML 9.00.8112.16540"></HEAD>
<BODY>
<DIV class="container">
<DIV class="red_ribben"></DIV>
<DIV class="main"><HEADER>
<DIV class="header">
<DIV class="logo">
<IMG alt="" src="/lm_vzcontent/vz_images/Verizon_logo_new.gif" >
</DIV>
</DIV>
</HEADER>

<DIV class="content">
<H1>Login to complete Survey</H1>

<form>
<DIV class="options">
<DIV class="option">
<a href='javascript:window.location = "<?php echo $url;?>"'><img src="/vzlearn/images/have.jpg" /></a>
<BR>
</DIV>
<DIV class="option2">
<a href='javascript:window.location = "<?php echo $urlannon;?>"'><img src="/vzlearn/images/donothave.jpg" /></a>
<BR>
</DIV>
</DIV>
</DIV>
<DIV class="clear">
</DIV>
</form>
   <?php                }
	} else if (empty($url)) {
		echo "The link you are trying to reach is not valid. Please try again or contact the person who sent you the link.";
	} else	{
		echo "The link you are trying to reach is no longer active.";
	
	}
	oci_close($conn);

ob_flush(); 
?>
