<?php

// if (isset($_POST['submit'])) {
//     // // ============== Send a record to the database ==============
//     $dbhost = 'localhost';
//     $dbuser = 'root';
//     $dbpass = 'VsQ$vxK3';
//     $dbname = 'feedback';
//
//     // Create connection
//     $conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
//     mysqli_select_db($conn, $dbname) or die("Could not open the db '$dbname'");
//     // Check connection
//     if ($conn->connect_error) {
//         die("Connection failed: " . $conn->connect_error);
//     }
//
//     // $sql = "INSERT INTO wth1 (url, helpful, comment) VALUES ('https://documentation', 'true', 'john@example.com')";
//
//     // $url      = $conn->real_escape_string($_POST['url']);
//     // $helpful  = $conn->real_escape_string($_POST['helpful']);
//     // $comment  = $conn->real_escape_string($_POST['comment']);
//     // $sql      = "INSERT into wth1 (url,helpful,comment)
//     //                 VALUES('" . $url . "','" . $helpful . "','" . $comment . "')";
//     //
//     // if ($conn->query($sql) === TRUE) {
//     //     echo "New record created successfully";
//     // } else {
//     //     echo "Error: " . $sql . "<br>" . $conn->error;
//     // }
//
//     $conn->close();
//     // // ============== End Send a record to the database ==============
//
//
//     // console.log("Submit button pushed");
//     // $con = mysqli_connect('localhost','root','VsQ$vxK3','feedback_application');
//     // if(!$con)
//     // {
//     //  echo 'Not Connected To Server';
//     // }
//     // else {
//     //   console.log('Connected');
//     // }
//     //
//     // $url      = $conn->real_escape_string($_POST['url']);
//     // $helpful  = $conn->real_escape_string($_POST['helpful']);
//     // $comment  = $conn->real_escape_string($_POST['comment']);
//     //
//     //
//     // $sql = "insert into wth1 (url,helpful,comment) values ('$url','$helpful','$comment')";
//     //
//     // if (!mysqli_query($con,$sql))
//     // {
//     //  echo 'Not Inserted';
//     // }
//     //
//     // else
//     // {
//     //  echo 'Inserted Successfully';
//     // }
// }
?>

<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="author" content="" />
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />

    <title>Was This Helpful Feedback</title>

    <link rel="shortcut icon" href="/resources/img/favicon.ico" />

    <!-- Stylesheets -->
    <link rel="stylesheet" href="/resources/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/resources/font-awesome/css/font-awesome.min.css"/>
    <!--<link rel="stylesheet" href="https://cdn.wolterskluwer.io/wk.css/0.13.x/with-bootstrap.min.css" type="text/css"/>-->
    <style>
		body {
			background-color: #555;
		}
		#wth-title {
			margin-left: 15px;
		}
		h1 {
			color: #fff;
			font-size: 18px;
		}
		#wth-closebutton {
			float:right;
			padding: 10px 10px 0px 0px;
		}
		.fa-close {
			color: #fff;
		}
		.submitbtn {
			font-family: 'Roboto', sans-serif;
		}
	</style>
    <!-- Javascript -->
</head>


<body id="mainBody">
		<!-- ===== Header ===== -->
    <div class="container-fluid">
		<div class="row">
			<div id="wth-title">
				<div style="display:inline-block"><h1 id="greeting"></h1></div>
				<div style="display:inline-block" id="wth-closebutton"><a href="#" onclick="parent.hideIframe();"><i class="fa fa-close fa-lg"></i></a></div>
			</div>
		</div>


		<form name="contactform" method="post" action="thankyou.php?">
			<input type="hidden" class="form-control" id="url" name="url" />
			<input type="hidden" class="form-control" id="helpful" name="helpful" />

			<div class="form-group">
				<div class="input-group">
					<textarea rows="5" cols="45" class="form-control" id="comment" name="comment" value=url placeholder="Optional: Please let us know how we can improve this page."></textarea>
				</div>
			</div>

			<button type="submit"
					id="feedbackSubmit"
					class="btn btn-success btn-lg"
					data-loading-text="Sending..."
					style="display: block; margin-top: 10px; text-align:right" onclick="parent.hideIframe();parent.hideHelpfulPodShowThankyou();">
				<i class="fa fa-send-o pull-left">&nbsp;<span class="submitbtn">&nbsp;Submit</span></i>
			</button>

		</form>

		<!-- ===== Contact Form ===== -->

<script>
	document.getElementById("url").value = document.referrer;
	var wthValue = getParamValue('wth');
	document.getElementById("helpful").value = wthValue;
	if (wthValue == "true") {
		document.getElementById("greeting").innerHTML = "Glad we could help!";
	} else {
		document.getElementById("greeting").innerHTML = "Sorry you didnt find what you need.";
	}
	console.log(wthValue);

	function getParamValue(paramName)
	{
		var url = window.location.search.substring(1); //get rid of "?" in querystring
		var qArray = url.split('&'); //get key-value pairs
		for (var i = 0; i < qArray.length; i++)
		{
			var pArr = qArray[i].split('='); //split key and value
			if (pArr[0] == paramName)
				return pArr[1]; //return value
		}
	}
</script>
</body>

</html>
