<?php
	session_start();
	// include("/home/maarten/config.php");
	include("/home/ccbadmin/mirtargetlink_db/config.php");
	if (isset($_POST['Target_Gene'])){
		$type = "Target_Gene";
		$invType = "miRNA";
		$trType = "Gene";
		$list = explode("##", $_POST['Target_Gene']);
		$qval = $list[0];
		$rqtype = "microRNAs";
		$sessionkey = $list[1];
	}if (isset($_POST['miRNA'])){
		$type = "miRNA";
		$invType = "Target_Gene";
		$trType = "MicroRNA";
		$list = explode("##", $_POST['miRNA']);
		$qval = $list[0];
		$rqtype = "genes";
		$sessionkey = $list[1];
	}if (isset($_GET['qval'])){
		$qval = $_GET['qval'];
	}if (isset($_GET['type'])){
		$type = $_GET['type'];
		if($type == 'miRNA'){
			$trType = "MicroRNA";
			$rqtype = "genes";
			$invType = "Target_Gene";
		}else{
			$trType = "Gene";
			$rqtype = "microRNAs";
			$invType = "miRNA";
		}
	}

?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>miRTargetLink Human</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="css/mystyle.css">
		<script type="text/javascript" src="vis/4.9.0/package/dist/vis.js"></script>
    	<link href="vis/4.9.0/package/dist/vis.css" rel="stylesheet" type="text/css" />
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
		<?php include_once("include_head.html") ?>
	</head>
	<body>
	<script>
	// $(document).ready(function () {
	//     // Handler for .ready() called.
	//     $('html, body').animate({
	//         scrollTop: $('#start').offset().top
	//     }, 'slow');
	// });
	</script>
		<br/>
		<div class="container-fluid">
			<div class="row">
				<!-- <div class="col-md-1"></div> -->
				<div class="col-md-12">
					<div class="panel panel-primary">
						<div class="panel-heading">
							<h1 id="miRTargetLink" style="font-size: 4em;">
				            <a href="index.php" title="Home">
				              <img src="img/logo3.png" id="logo">
				            </a>miRTargetLink Human
				          </h1>
						</div>
					</div>
				</div>
				<!-- <div class="col-md-2"></div> -->
			</div>

			
			<div class="row">
				<div class="col-md-12">
					<div class="panel panel-primary">
						<div class="container" style="width:100%;padding:0;">
							<div class="alert alert-danger" role="alert" style="text-align:center;margin:0;">
								This site is deprecated and will soon no longer be available. Please use
								<a href="https://ccb-compute.cs.uni-saarland.de/mirtargetlink2">miRTargetLink 2</a> instead.
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="row">
				<!-- <div class="col-md-1"></div> -->
				<div class="col-md-9">
					<div class="panel panel-primary">
						<div class="panel-body">
							<?php
								$con = mysqli_connect($server, $username, $password, $database);
								// @mysql_select_db($database) or die( "Unable to select database");
								$result = NULL;
								if($type == 'miRNA'){
									$resultWeak = mysqli_query($con, "SELECT DISTINCT Target_Gene, miRTarBase_ID FROM miRTarBase WHERE miRNA = \"$qval\" AND Support_Type LIKE '%Weak%';");
									$resultStrong = mysqli_query($con, "SELECT DISTINCT Target_Gene, miRTarBase_ID FROM miRTarBase WHERE miRNA = \"$qval\" AND Support_Type NOT LIKE '%Weak%';");
									$resultMiranda = mysqli_query($con, "SELECT DISTINCT Target_Gene FROM miRanda WHERE miRNA = \"$qval\"");
								}else{
									$resultWeak = mysqli_query($con, "SELECT DISTINCT miRNA, miRTarBase_ID FROM miRTarBase WHERE Target_Gene = \"$qval\" AND Support_Type LIKE '%Weak%';");
									$resultStrong = mysqli_query($con, "SELECT DISTINCT miRNA, miRTarBase_ID FROM miRTarBase WHERE Target_Gene = \"$qval\" AND Support_Type NOT LIKE '%Weak%';");
									$resultMiranda = mysqli_query($con, "SELECT DISTINCT miRNA FROM miRanda WHERE Target_Gene = \"$qval\"");
								}
								if($type == 'miRNA'){
									$insert = 'genes that are targeted by ';
								}else{
									$insert = 'microRNAs that target';
								}



								function mysqli_result($res,$row=0,$col=0){
									$numrows = mysqli_num_rows($res);
									if ($numrows && $row <= ($numrows-1) && $row >=0){
										mysqli_data_seek($res,$row);
										$resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
										if (isset($resrow[$col])){
											return $resrow[$col];
										}
									}
									return false;
								}
								// making array of results
								$resultWeakArray = [];
								// while ($row = mysqli_fetch_assoc($resultWeak)) {
								// 	foreach($row as $field => $value) {
								// 		$resultWeakArray[] = $value;
								// 	}
								// }

								$mti =[];
								$i = 0;
								$j = mysqli_num_rows($resultWeak);
								while($i < $j){
									$result = mysqli_result($resultWeak, $i, $invType);
									$mti[$qval."##".$result] = mysqli_result($resultWeak, $i, "miRTarBase_ID");
									array_push($resultWeakArray, $result);
									$i++;
								}

								$resultStrongArray = [];
								// while ($row = mysqli_fetch_assoc($resultStrong)) {
								// 	foreach($row as $field => $value) {
								// 		$resultStrongArray[] = $value;
								// 	}
								// }
								$i = 0;
								$j = mysqli_num_rows($resultStrong);
								while($i < $j){
									$result = mysqli_result($resultStrong, $i, $invType);
									$mti[$qval."##".$result] = mysqli_result($resultStrong, $i, "miRTarBase_ID");
									array_push($resultStrongArray, $result);
									$i++;
								}

								$resultMirandaArray = [];
								// while ($row = mysqli_fetch_assoc($resultMiranda)) {
								// 	foreach($row as $field => $value) {
								// 		$resultMirandaArray[] = $value;
								// 	}
								// }
								$i = 0;
								$j = mysqli_num_rows($resultMiranda);
								while($i < $j){
									$result = mysqli_result($resultMiranda, $i, $invType);
									array_push($resultMirandaArray, $result);
									$i++;
								}

								function getConsensus($x, $y){
									$z = [];
									foreach($x as $a){
										if(in_array($a, $y)){
											array_push($z, $a);
										}
									}
									return $z;
								}

								function getDistinct($x, $y){
									$z = [];
									foreach($x as $a){
										if(!in_array($a, $y)){
											array_push($z, $a);
										}
									}
									return $z;
								}

								$weakDistinct =    getDistinct($resultWeakArray, $resultStrongArray);
								$miRandaDistinct = getDistinct($resultMirandaArray, $resultStrongArray);
								$miRandaDistinct = getDistinct($resultMirandaArray, $resultWeakArray);
								$resultSize =      sizeOf($weakDistinct)+sizeOf($resultStrongArray)+sizeOf($miRandaDistinct);


								if(sizeOf($resultStrongArray)+sizeOf($weakDistinct)+sizeOf($miRandaDistinct) > 0){								?>
								<h2 class="page-header" id="start">miRTargetLink found <?php echo (sizeOf($resultStrongArray)+sizeOf($weakDistinct)+sizeOf($miRandaDistinct)) ?> <?php echo $insert ?> <?php echo $qval ?></h2>
								<ul>
									<li><h4><strong><?php echo sizeOf($resultStrongArray) ?></strong> interactions with strong support</h4></li>
									<li><h4><strong><?php echo sizeOf($weakDistinct) ?></strong> interactions with weak support</h4></li>
									<li><h4><strong><?php echo sizeOf($miRandaDistinct) ?></strong> predicted interactions</h4></li>
								</ul>
								<?php

								$idsMiranda = [];
								$idsStrong =  [];
								$idsWeak =    [];

								$motherId = 1;
								$n =        $motherId;

								$clickInfo = "<li>Double click to generate interaction landscape<br/>(opens in new tab)</li>";
								$strong =    "<strong>strong experimental evidence</strong>";
								$weak =      "<strong>weaker experimental evidence</strong>";
								$miranda =   "<strong>prediction data</strong>";

								$qNode = ["id" =>    $motherId, "label" => $qval, "color" => "#6E3E0B", "font" =>  "16px arial white", "shape" => "box",
									"title" => "<strong>".$qval."</strong><ul>".$clickInfo."</ul>", "fixed" => true];
								$rNodes = [$qNode];
								$rEdges = [];

								for ($i = 0; $i < sizeOf($weakDistinct); $i++) {
									$n++;
									array_push($idsWeak, $n);
									array_push($rNodes, ["id" => $n, "label" => $weakDistinct[$i], "color" => "#346980", "font" => "16px arial white",
										"shape" => "box", "title" => "<strong>".$weakDistinct[$i]."</strong><ul><li>Interaction is backed up by ".$weak."</li>".$clickInfo."</ul>"]);
								}

								for ($i = 0; $i < sizeOf($resultStrongArray); $i++) {
									$n++;
									array_push($idsStrong, $n);
									array_push($rNodes, ["id" => $n, "label" => $resultStrongArray[$i], "color" => "#246327", "font" => "16px arial white",
										"shape" => "box", "title" => "<strong>".$resultStrongArray[$i]."</strong><ul><li>Interaction is backed up by ".$strong."</li>".$clickInfo."</ul>"]);
								}
								// print_r($rNodes);
								for ($i = 0; $i < sizeOf($miRandaDistinct); $i++) {
									$n++;
									array_push($idsMiranda, $n);
									array_push($rNodes, ["id" => $n, "label" => $miRandaDistinct[$i], "color" => "#FFDA00", "font" => "16px arial black",
										"shape" => "box", "title" => "<strong>".$miRandaDistinct[$i]."</strong><ul><li>Interaction is backed up by ".$miranda."</li>".$clickInfo."</ul>"]);
								}

								$fac = 0;
								if($resultSize > 500){$fac = 400;}
								if($resultSize > 1000){$fac = 800;}
								if($resultSize > 1300){$fac = 1100;}
								if($resultSize < 300){$fac = -150;}

								for ($i = 0; $i < sizeOf($idsStrong); $i++) {
									$l = 300+$fac;
									array_push($rEdges, ["from" => $motherId, "to" => $idsStrong[$i], "color" => "#246327", "length" => $l]);
								}

								for ($i = 0; $i < sizeOf($idsWeak); $i++) {
									$l = 600+$fac;
									array_push($rEdges, ["from" => $motherId, "to" => $idsWeak[$i], "color" => "#346980", "length" => $l]);
								}

								for ($i = 0; $i < sizeOf($idsMiranda); $i++) {
									$l = 1000+$fac;
									array_push($rEdges, ["from" => $motherId, "to" => $idsMiranda[$i], "color" => "#FF5E00", "length" => $l]);
								}

							?>
							<div class="panel panel-primary">
								<div class="panel-heading" style="text-align:center;">
									<h4>
									<a data-toggle="collapse" href="#collapseTips" title="Click to expand" style="color:white;">
									<span class="glyphicon glyphicon-th-list"></span> Network tips</a>
									</h4>
								</div>
								<div id="collapseTips" class="panel-collapse collapse">
									<div class="panel panel-body">
										<ul id="zzgraphTips">
											<li>Hover over any node or edge to see more info about the interaction.</li>
											<li>Double click on a gene or microRNA to open its interaction landscape in a new tab.</li>
											<li>Right click -> 'save image as...' to download network as png image.</li>
											<li>Click on microRNAs or genes in the table below to open a <a href="http://www.genecards.org/" target="_blank">genecards</a> or <a href="http://www.mirbase.org/" target="_blank">miRBase</a> link in a new tab.</li>
										</ul>
									</div>
								</div>
							</div>
							<div id="networkContainer">
								<div id="networkFrame"></div>
								<div id="loadingBar">
							        <div class="outerBorder">
							            <div id="text">Generating network please wait... 0%</div>
							            <div id="border">
							                <div id="bar"></div>
							            </div>
							        </div>
						    	</div>
							</div>


							<script type="text/javascript">
								var network =    null;
								var idsMiranda = <?php echo json_encode($idsMiranda);?>;
								var idsStrong =  <?php echo json_encode($idsStrong);?>;
								var idsWeak =    <?php echo json_encode($idsWeak);?>;
								var rNodes =     <?php echo json_encode($rNodes);?>;
								var rEdges =     <?php echo json_encode($rEdges);?>;
								var type =       <?php echo json_encode($type);?>;

								function draw(e, n){
									var qn =           1; // number of query values
									var motherId =     <?php echo $motherId;?>;
									var size =         <?php echo $resultSize; ?>;
									var nodes =        new vis.DataSet(n);
									var edges =        new vis.DataSet(e);
									var container =    document.getElementById('networkFrame');
									var data =         {nodes: nodes, edges: edges};
									var options =      {
														interaction:{
															dragNodes: true,
															hover: true,
															multiselect: true,
															navigationButtons: true,
															tooltipDelay: 100
														},
														nodes:{
															shadow: false,
														},
														groups:{
															useDefaultGroups: true,
															},

														edges:{
															physics:true,
															smooth:{
																enabled: false
															},
															hoverWidth:0,
					    									width: 0
														},
														physics:{
															// solver:'barnesHut',
															adaptiveTimestep:true,
															maxVelocity:50,
															stabilization: {
																enabled: true,
																iterations: 300,
																fit: true
															}
														},
														layout:{
															improvedLayout: true,
															hierarchical:{
																enabled: false
															}
														}
													};

									network = new vis.Network(container, data, options);
									network.on("stabilizationProgress", function(params) {
						                var maxWidth = 496;
						                var minWidth = 20;
						                var widthFactor = params.iterations/params.total;
						                var width = Math.max(minWidth,maxWidth * widthFactor);

						                document.getElementById('bar').style.width = width + 'px';
						                document.getElementById('text').innerHTML = 'Generating network please wait... '+Math.round(widthFactor*100) + '%';
						            });
						            network.once("stabilizationIterationsDone", function() {
						                document.getElementById('text').innerHTML = '100%';
						                document.getElementById('bar').style.width = '496px';
						                document.getElementById('loadingBar').style.opacity = 0;
						                // really clean the dom element
						                setTimeout(function () {document.getElementById('loadingBar').style.display = 'none';}, 500);
						                var postRenderOptions = {
											physics:{enabled:false}
										};
										network.setOptions(postRenderOptions);
						            });
									function openNetworkInTab(name, type) {
										// if(type == 'Target_Gene'){
										// 	window.open("http://www.genecards.org/cgi-bin/carddisp.pl?gene="+name);
										// }if(type == 'miRNA'){
										// 	window.open("http://www.mirbase.org/cgi-bin/mirna_entry.pl?acc="+name);
										// }
										window.open("network.php?type="+type+"&qval="+name);
									}
									network.on( 'doubleClick',
										function(properties) {
											if (type == 'Target_Gene' && properties.nodes <= qn){
												openNetworkInTab(rNodes[properties.nodes-1].label, 'Target_Gene')
											}
											if (type == 'Target_Gene' && properties.nodes > qn){
												openNetworkInTab(rNodes[properties.nodes-1].label, 'miRNA');
											}
											if (type == 'miRNA' && properties.nodes <= qn){
												openNetworkInTab(rNodes[properties.nodes-1].label, 'miRNA');
											}
											if (type == 'miRNA' && properties.nodes > qn){
												openNetworkInTab(rNodes[properties.nodes-1].label, 'Target_Gene');
											}
										}
									);
								}

								draw(rEdges, rNodes);
								// document.getElementById('loading').style.display='none';
								// document.getElementById('networkFrame').style.visibility='visible';

							</script>
							<script>
								$(document).ready(function(){
									$('[data-toggle="tooltip"]').tooltip();
								});
								$('[rel=tooltip]').tooltip({container: 'body'});
							</script>
							<h3>Edit network:
							<button type="button" onclick="filter('strong'); this.className='btn btn-default disabled';" class="btn btn-danger" id="strong" data-toggle="tooltip" title="Remove category from network" data-container="body" ><span class="glyphicon glyphicon-remove"></span> <strong>Strong evidence</strong></button>
							<button type="button" onclick="filter('weak'); this.className='btn btn-default disabled';" class="btn btn-danger" id="weak" data-toggle="tooltip" title="Remove category from network" data-container="body" ><span class="glyphicon glyphicon-remove"></span> <strong>Weaker evidence</strong></button>
							<button type="button" onclick="filter('pred'); this.className='btn btn-default disabled';" class="btn btn-danger" id="pred" data-toggle="tooltip" title="Remove category from network" data-container="body" ><span class="glyphicon glyphicon-remove"></span> <strong>Predicted interactions</strong></button>
							<!-- <button onclick="filter('sel');" class="btn btn-danger" data-toggle="tooltip" title="Remove selected nodes from network. Select multiple nodes by ctrl+clicking or long clicking them" data-container="body"><strong>Selection</strong></button> -->
							<button onclick="filter('reset');" class="btn btn-default disabled"  data-toggle="tooltip" title="Regenerate the original network" data-container="body" id="reset"><span class="glyphicon glyphicon-refresh"></span> <strong>Restore all categories</strong></button>
							</h3>
							<h3>Generate subnetwork for selection:
							<button class="btn btn-primary" onclick="getSelected('network', 'multigene')" data-toggle="tooltip" title="Select one or more genes in the network by crtl+clicking, or long clicking them" data-container="body"><span class="glyphicon glyphicon-cog"></span> <strong>Genes</strong></button>
							<button class="btn btn-primary" onclick="getSelected('network','multimir')" data-toggle="tooltip" title="Select one or more microRNAs in the network by crtl+clicking, or long clicking them" data-container="body"><span class="glyphicon glyphicon-cog"></span> <strong>MicroRNAs</strong></button>
							</h3>
							<script type="text/javascript">

							function filter(del){
								if(del=='pred'){
									document.getElementById("reset").className = "btn btn-warning";
									network.selectNodes(idsMiranda);
									network.deleteSelected();
								}if(del=='weak'){
									document.getElementById("reset").className = "btn btn-warning";
									network.selectNodes(idsWeak);
									network.deleteSelected();
								}if(del=='strong'){
									document.getElementById("reset").className = "btn btn-warning";
									network.selectNodes(idsStrong);
									network.deleteSelected();
								}if(del=='sel'){
									network.selectNodes(network.getSelectedNodes());
									network.deleteSelected();
								}if(del=='reset'){
									location.reload();
									// document.getElementById('pred').className='btn btn-danger';
									// document.getElementById('weak').className='btn btn-danger';
									// document.getElementById('strong').className='btn btn-danger';
									// draw(rEdges, rNodes);
								}
							}

							</script>
						<h2 class="page-header"></h2>
						<div class="panel panel-default">
							<div class="panel-heading">
								<h3>
								<a href="download.php?session=<?php echo $sessionkey; ?>" target="_blank" style="color:#347AB8;">
									<span class="glyphicon glyphicon-download"></span> <strong>Download interaction data</strong>
								</a>
								</h3>
							</div>
							<?php
							$tablecss = "height:500px;overflow-y:auto;";
							if($resultSize < 13){
								$tablecss = "height:auto;";
							}
							?>
							<div class="panel panel-body" style=<?php echo $tablecss; ?>>
								<table class="table table-striped">
									<?php
									$tarLink="http://www.genecards.org/cgi-bin/carddisp.pl?gene=";
									$tarTit="\"Go to genecards (opens in new tab)\"";
									$subjLink="http://www.mirbase.org/cgi-bin/mirna_entry.pl?acc=";
									$subjTit="\"Go to miRBase (opens in new tab)\"";
									if($type == 'Target_Gene'){
										$subjLink="http://www.genecards.org/cgi-bin/carddisp.pl?gene=";
										$tarTit="\"Go to miRBase (opens in new tab)\"";
										$tarLink="http://www.mirbase.org/cgi-bin/mirna_entry.pl?acc=";
										$subjTit="\"Go to genecards (opens in new tab)\"";
									}
									$target = 'MicroRNA';
									if($type == 'miRNA'){
										$target = 'Gene';
									}
									?>
									<thead>
										<tr>
											<th><?php echo $trType; ?></th>
											<th><?php echo $target; ?></th>
											<th>Evidence category</th>
											<th>miRTarBase ID</th>
										</tr>
									</thead>
									<tbody class="dikketabel">
									<?php
									if(sizeof($resultStrongArray) > 0){
										foreach($resultStrongArray as $s){
											?>
											<tr class='strong'>
												<td><a href=<?php echo $subjLink.$qval; ?> title=<?php echo $subjTit; ?> target="_blank"><?php echo $qval; ?></a></td>
												<td>
												<a title="open interaction landscape for <?php echo $s; ?> in a new tab" target="_blank" href="network.php?type=<?php echo $invType; ?>&qval=<?php echo $s; ?>"><span class="glyphicon glyphicon-expand"></span></a>
												<a href=<?php echo $tarLink.$s; ?> title=<?php echo $tarTit; ?> target="_blank"><?php echo $s; ?></a></td>
												<td style="cursor: help;" title="e.g. Reporter assay, Western blot, qPCR"><span rel="tooltip">Strong</span></td>
												<td><a href="http://mirtarbase.mbc.nctu.edu.tw/php/detail.php?mirtid=<?php echo $mti[$qval."##".$s]; ?>" target="_blank" title="open miRTarBase page for [<?php echo $qval.' : '.$s; ?>]"><?php echo $mti[$qval."##".$s]; ?></a></td>
											</tr>
											<?php
										}
									}
									if(sizeof($weakDistinct) > 0){
										foreach($weakDistinct as $w){
											?>
											<tr class='weak'>
												<td><a href=<?php echo $subjLink.$qval; ?> title=<?php echo $subjTit; ?> target="_blank"><?php echo $qval; ?></a></td>
												<td>
												<a title="open interaction landscape for <?php echo $w; ?> in a new tab" target="_blank" href="network.php?type=<?php echo $invType; ?>&qval=<?php echo $w; ?>"><span class="glyphicon glyphicon-expand"></span></a>
												<a href=<?php echo $tarLink.$w; ?> title=<?php echo $tarTit; ?> target="_blank"><?php echo $w; ?></a></td>
												<td style="cursor: help;" title="e.g. Microarray, NGS, pSILAC"><span rel="tooltip">Weak</span></td>
												<td><a href="http://mirtarbase.mbc.nctu.edu.tw/php/detail.php?mirtid=<?php echo $mti[$qval."##".$w]; ?>" target="_blank" title="open miRTarBase page for [<?php echo $qval.' : '.$w; ?>]"><?php echo $mti[$qval."##".$w]; ?></a></td>
											</tr>
											<?php
										}
									}
									if(sizeof($miRandaDistinct) > 0){
										foreach($miRandaDistinct as $p){
											?>
											<tr class='predicted'>
												<td><a href=<?php echo $subjLink.$qval; ?> title=<?php echo $subjTit; ?> target="_blank"><?php echo $qval; ?></a></td>
												<td>
												<a title="open interaction landscape for <?php echo $p; ?> in a new tab" target="_blank" href="network.php?type=<?php echo $invType; ?>&qval=<?php echo $p; ?>"><span class="glyphicon glyphicon-expand"></span></a>
												<a href=<?php echo $tarLink.$p; ?> title=<?php echo $tarTit; ?> target="_blank"><?php echo $p;?></a></td>
												<td style="cursor: help;" title="miRanda prediction"><span rel="tooltip">Prediction</span></td>
												<td style="cursor: help;" title="not available for predicted interactions">N/A</td>
											</tr>
											<?php
										}
									}
									?>
									</tbody>
								</table>
							</div>
						</div>
						<h3>Table filter:
						<button class="btn btn-info" id="showStrongButton">Strong only</button>
						<button class="btn btn-info" id="showWeakButton">Weak only</button>
						<button class="btn btn-info" id="showPredButton">Predicted only</button>
						<button class="btn btn-info" id="showAll">Show all</button>
						</h3>
						<script>
							var rows = $('tbody.dikketabel tr');
							$('#showStrongButton').click(function() {
							    var strong = rows.filter('.strong').show();
							    rows.not( strong ).hide();
							});

							$('#showWeakButton').click(function() {
							    var weak = rows.filter('.weak').show();
							    rows.not( weak ).hide();
							});

							$('#showPredButton').click(function() {
							    var pred = rows.filter('.predicted').show();
							    rows.not( pred ).hide();
							});

							$('#showAll').click(function() {
							    rows.show();
							});
						</script>
						<?php
						}else{
							?>
							<h2 class="page-header">Sorry, miRTargetLink found no interactions for the selected <?php echo $rtype;?>.</h2>
							<div class="col-md-12">
								<div class="panel panel-default">
									<div class="panel-heading">
										<h3 id="noResult">
										<span class="glyphicon glyphicon-home"></span> <a href="index.php" style="color:black;"> Back to main page</a>
										</h3>
									</div>
								</div>
							</div>
							<?php
						}
						?>
						</div>
					</div>
				</div>
				<div class="col-md-3">
					<div class="panel-group" id="fixed">
		                <div class="panel panel-primary">
		                  <div class="panel-head">
		                    <a href="https://www.ccb.uni-saarland.de/" title="CCB" target="_blank">
		                      <center><img src="img/ccb.png" id="CCB"></center>
		                    </a>
		                  </div>
		                </div>
						<div class="panel panel-primary">
							<div class="panel-heading">
								<h4>
								<span class="glyphicon glyphicon-search"></span> <a data-toggle="collapse" href="#collapse1" data-parent="#fixed" title="Click to expand" style="color:white;">Search by microRNA</a>
								</h4>
							</div>
							<div id="collapse1" class="panel-collapse collapse">
								<div class="panel-body">
									<form class="form-inline" role="form" method="post" action="result.php">
	                          			<p><strong>Interaction landscape for a single microRNA:</strong></p>
										<div class="form-group">
											<input class="form-control" name="miRNA" placeholder="Example: hsa-let">
										</div>
										<button type="submit" class="btn btn-info">
											<span class="glyphicon glyphicon-search"></span> <strong>Search</strong>
										</button>
									</form>
									<br/>
									<form class="form-inline" method="POST" action="multiresult.php" id="multimirform">
										<p><strong>Target-gene overlap between multiple microRNAs:</strong></p>
										<div class="form-group">
											<textarea placeholder="Example: let-7,hsa-miR-30,..." name="multimir" form="multimirform"></textarea>
										</div>
										<button type="submit" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> <strong>Search</strong></button>
									</form>
									<p style="color:#013ADF;">To view an example, leave fields empty and click search</p>

								</div>
							</div>
						</div>
						<div class="panel panel-primary">
							<div class="panel-heading">
								<h4>
									<span class="glyphicon glyphicon-search"></span> <a data-toggle="collapse" href="#collapse2" data-parent="#fixed" title="Click to expand" style="color:white;">Search by gene symbol</a>
								</h4>
							</div>
							<div id="collapse2" class="panel-collapse collapse">
								<div class="panel-body">
									<form class="form-inline" role="form" method="post" action="result.php">
	                          			<p><strong>Interaction landscape for a single gene symbol:</strong></p>
										<div class="form-group">
											<input class="form-control" name="Target_Gene" placeholder="Example: NOTCH">
										</div>
										<button type="submit" class="btn btn-info">
											<span class="glyphicon glyphicon-search"></span> <strong>Search</strong>
										</button>
									</form>
									<br/>
									<form class="form-inline" method="POST" action="multiresult.php" id="multigeneform">
										<p><strong>MicroRNA interaction overlap between multiple genes:</strong></p>
										<div class="form-group">
											<textarea placeholder="Example: NOTCH,DICER,..." name="multigene" from="multigeneform"></textarea>
										</div>
										<button type="submit" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> <strong>Search</strong></button>
									</form>
									<p style="color:#013ADF;">To view an example, leave fields empty and click search</p>
								</div>
							</div>
						</div>
						<div class="panel panel-primary">
							<div class="panel-heading">
								<h4>
									<span class="glyphicon glyphicon-play-circle"></span> <a data-toggle="collapse" href="#collapse4" data-parent="#fixed" title="Click to expand" style="color:white;">Over-representation analysis</a>
								</h4>
							</div>
							<div id="collapse4" class="panel-collapse collapse">
								<div class="panel-body">
									<p>Perform Over-representation analysis with <a href="https://genetrail2.bioinf.uni-sb.de/start.html" target="_blank">GeneTrail2</a>,
									a tool for statistical analysis of molecular signatures that was developed in the<a href="https://www.bioinf.uni-sb.de/home" target="_blank"> Chair for Bioinformatics</a>  at the University of Saarland.
									</p>
									<h4>Perform Over-representation analysis for:<h4/>
									<form action="waiting.php" method="POST" target="_blank">
										<?php

										$_SESSION['type'.$sessionkey] = $type;
										$_SESSION['qval'.$sessionkey] = $qval;

										if(sizeOf($resultStrongArray) > 0){
											$_SESSION['strong'.$sessionkey] = $resultStrongArray;
											$button2 = "Strong- and weaker support";
											$title2 = "Interactions with strong and/or weaker experimental support";
											$_SESSION['SWbool'.$sessionkey] = True;
											$_SESSION['SWval'.$sessionkey] = array_merge($resultStrongArray, $weakDistinct);
											?>
											<button type="submit" class="btn btn-info" name="strongE" data-toggle="tooltip" title="Interactions with strong experimental support" value=<?php echo $sessionkey; ?>><strong>Strong support</strong></button>
											<?php
										}else{
											$button2 = "Weaker support";
											$title2 = "Interactions with weaker experimental support";
											$_SESSION['SWbool'.$sessionkey] = False;
											$_SESSION['SWval'.$sessionkey] = $weakDistinct;
											?>
											<button type="button" class="btn btn-default disabled"> <span class="glyphicon glyphicon-ban-circle"></span> <strong>Strong support</strong></button>
											<?php
										}if(sizeOf($resultWeakArray) != 0){
											?>
											<button type="submit" class="btn btn-info" name="otherE" data-toggle="tooltip" title="<?php echo $title2; ?>" value=<?php echo $sessionkey; ?>><strong><?php echo $button2; ?></strong></button>
											<?php
										}else{
											?>
											<button type="button" class="btn btn-default disabled"> <span class="glyphicon glyphicon-ban-circle"></span><strong><?php echo $button2; ?></strong></button>
											<?php }

										session_write_close();
										?>
									</form>
									<br />
									<button style="width:100%;" class="btn btn-info" onclick="getSelected('cluster')" data-toggle="tooltip" title="Perform ORA on selected <?php echo $rqtype?>. Select one or more <?php echo $rqtype?> in the network by crtl+clicking, or long clicking them" data-container="body"><strong>Selected <?php echo $rqtype; ?></strong></button>
									<script type="text/javascript">
									function getSelected(what, who) {
									    if(what == 'cluster'){
									    	var sel = network.getSelectedNodes();
										    var type = '<?php echo $type; ?>';
									        var names = "";

									        for(i = 0; i < sel.length; i++){
									        	var name = rNodes[sel[i]-1].label;
									        	if((type == "Target_Gene" && name.substring(0,3) == 'hsa') || (type == 'miRNA' && name.substring(0,3) != 'hsa')){
									        		names = names+name+'#';
									        	}

									        }
									        // document.getElementById("demo").innerHTML = selectable.length;
								        	if(names != ""){
									    		var form = document.createElement("form");
									            form.setAttribute("method", "POST");
									            form.setAttribute("action", "waiting.php");
									            form.setAttribute("target", "_blank");
									            var selectedNodes = document.createElement('input');
									            selectedNodes.type = 'hidden';
									            selectedNodes.name = 'selNodes';
									            selectedNodes.value = names+'#'+"<?php echo $sessionkey;?>";
									            form.appendChild(selectedNodes);
									            document.body.appendChild(form);
									    		form.submit();
									    	}
									    }else{
									    	var sel = network.getSelectedNodes();
										    var type = '<?php echo $type; ?>';
									        var names = "";
									        // var varname = who;
									        // if(type =='miRNA'){varname = 'multigene';}
									        for(i = 0; i < sel.length; i++){
									        	var name = rNodes[sel[i]-1].label;
									        	if((who == 'multimir' && name.substring(0,3) == 'hsa') || (who == 'multigene' && name.substring(0,3) != 'hsa')){
									        		names = names+name+',';
									        	}

									        }
									        // document.getElementById("demo").innerHTML = selectable.length;
								        	if(names != ""){
									    		var form = document.createElement("form");
									            form.setAttribute("method", "POST");
									            form.setAttribute("action", "multiresult.php");
									            form.setAttribute("target", "_blank");
									            var selectedNodes = document.createElement('input');
									            selectedNodes.type = 'hidden';
									            selectedNodes.name = who;
									            selectedNodes.value = names;
									            form.appendChild(selectedNodes);
									            document.body.appendChild(form);
									    		form.submit();
									    	}
									    }
									}

									</script>
								</div>
								</div>
							</div>
						<div class="panel panel-primary">
							<div class="panel-heading">
								<h4>
									<span class="glyphicon glyphicon-info-sign"></span> <a data-toggle="collapse" href="#collapse3" data-parent="#fixed" title="Click to expand" style="color:white;">Network information</a>
								</h4>
							</div>
							<div id="collapse3" class="panel-collapse collapse">
								<div class="panel-body">
									<p>The length of the edges is an extra indicator for the type of evidence that supports the interaction. The center node <mark id="brown">(brown)</mark> depicts the query microRNA or gene, the
									 	nodes closest to the query node <mark id="green">(green)</mark> depict interactions that are backed up by strong experimental evidence such as Reporter Gene Assay. Second
									 	<mark id="blue">(blue)</mark> are the intereactions that are backed up by weaker experimental evidence such as Microarray. The outer most nodes
									 	<mark id="yellow">(yellow)</mark> depict intereactions are backed up only by prediction algorithms.
									</p>
								</div>
							</div>
						</div>

                <div class="panel panel-primary">
                  <div class="panel-heading">
                    <a href="manual.php" class="btn btn-default" target="_blank" id="download"><span class="glyphicon glyphicon-info-sign"></span> <strong>View the manual</strong> (opens in a new tab)</a>
                  </div>
                </div>
					</div>
				</div>
				<!-- <div class="col-md-1"></div> -->
			</div>
		</div>
	</body>
</html>
