Source

webcircos / delFiles.php

Full commit
<?php
error_reporting(0);
//	echo "<pre>" . print_r($_POST, true) . "</pre>";
	$delFiles = $_POST['delList'];
	$delImages = $_POST['delimgList'];
//	echo "<pre>" . print_r($delImages, true) . "</pre>";
	echo "<script>";
	foreach($delFiles as $file) {
		$classArray = explode("/", $file);
		$myClassArray = explode('.', $classArray[2]);
		$myClass = $myClassArray[0];
		echo "$(\".$myClass\").html('');";
		unlink($file);
		$relations = file_get_contents('temp/' . $classArray[1] . '/relations.txt');
		$relationsArray=explode("'$myClass'", $relations);
//		echo "<pre>" . print_r($relationsArray, true) . "</pre>";
		$f = fopen('temp/' . $classArray[1] ."/relations.txt", 'w');
		foreach($relationsArray as $rel) {
			if(substr($rel, -1) !== ';'){
				if(substr($rel, -1) == '~') {
				} else {
					$rel = substr($rel,0, -1);
				}
			}
		fwrite($f, $rel);
		}
	}
	foreach($delImages as $image) {
		$classArray = explode("/", $image);
		$myClassArray = explode('.', $classArray[3]);
		$myClass = $myClassArray[0];
		echo "$(\".$myClass\").html('');";
		unlink($image);
		$relations = file_get_contents('temp/' . $classArray[1] . '/relations.txt');
		$relationsArray = explode("~", $relations);
		$f = fopen('temp/' . $classArray[1] . "/relations.txt", 'w' );
		array_pop($relationsArray);
		foreach($relationsArray as $rel) {
			if(strpos($rel ,$myClass) === false) {
				fwrite($f, $rel);
				fwrite($f, "~");
			}
		}
	}
	if (is_file('temp/' . $classArray[1] . '/relations.txt') == true) {
		$relations = file_get_contents('temp/' . $classArray[1] . '/relations.txt');
		$relationsArray=explode("~", $relations);
		array_pop($relationsArray);
		echo "var colorArray = new Array('rgba(20,83,154, .6)', 'rgba(154,110,9, .6)', 'rgba(29,142,17, .6)', 'rgba(100,20,162, .6)', 'rgba(0,0,0, .6)', 'rgba(153,0,0, .6)', 'rgba(168,168,8, .6)');
		var c = -1;
		var canvas = document.getElementById('relationsCanvas');
		var context = canvas.getContext('2d');
		context.clearRect(0,0,canvas.width,canvas.height);";
		foreach ($relationsArray as $relation) {
			echo $relation;
			echo "
				c++;
				if(c == 7) {
					c=0;	
				}
				var figPos = $('.' + jq(relArray[0])).offset();
				var len = relArray.length;
				var title = relArray[0] + ': ';
				for (var i= 1; i < len; i++) {
					if(i !== 1){
						title = title + ', '
					}
					title = title + relArray[i];
					var filei = $('#' + jq(relArray[i]));
					var pos1 = filei.offset();
					DrawLine(pos1.left + filei.width(), pos1.top + filei.height()/2, figPos.left, figPos.top, colorArray[c]);
				}
				$('.' + jq(relArray[0])).prop('title', title);
				";
		}
	}
	echo " </script>";
?>