Location: PHPKode > projects > NetVis Module > netvis/survey_modify.php
<?php
// modify social network when selected from survey.php

	include("config.php");
	include($baseDir . "common/_func.php");

	//if user is not logged in, redirect to homepage
		if(!isset($uID)){header("Location: http://www.netvis.org");exit;}

	//if user is logged in as demo, redirect to homepage
		demoRedirect($username);

	//file deletion
		deleteFiles($uID,$username,$net,$serverRoot);

	if($username=="demo"){
		header("Location: socialnetworks.php");
	}

	if(!isset($process)){
		$process=FALSE;
	}

	if($process==7){

		$sql="SELECT * FROM networks WHERE netname=\"$net\" AND uID=$uID";
		$result=mysql_query($sql) or die(sqlError($sql));
		$row=mysql_fetch_array($result);
		$rawmatrix=$row['rawmatrix'];
		$peoples=$row['netnum'];
		if($split_change!=$row['split']){
			$sql="UPDATE networks SET split=$split_change WHERE netname=\"$net\" AND uID=$uID";
			mysql_query($sql) or die(sqlError($sql));
		}

		//networks.matrix computing
		$sql = "SELECT * FROM networks WHERE uID=$uID AND netname=\"$network\"";
		$result = mysql_query($sql) or die(sqlError($sql));
		$row = mysql_fetch_array($result);

		$com_array = split(",",$row['commatrix']);
		$clo_array = split(",",$row['clomatrix']);
		$other_array = split(",",$row['othermatrix']);

		if($com_array){
			$count_array=count($com_array);
		}elseif($clo_array){
			$count_array=count($clo_array);
		}elseif($other_array){
			$count_array=count($other_array);
		}

		$matrix="";
		for($c=1; $c <= ($count_array-1); $c++){
			if(!isset($com_array[$c])){
				$com_array[$c]=FALSE;
			}
			if(!isset($clo_array[$c])){
				$clo_array[$c]=FALSE;
			}
			if(!isset($other_array[$c])){
				$other_array[$c]=FALSE;
			}
			$matrix.=($com_array[$c] + $clo_array[$c] + $other_array[$c]).",";
		}

		//networks rawmatrix and fullmatrix computing
		$fullmatrix_array = split(",", $matrix);

		$rawmatrix="";
		$fullmatrix="";
		$c=0;
		$inner_count=0;
		$last=count($fullmatrix_array)-2;
		while($num>=0){
		//adds one onto diagonals, reverse values after, creating square
			if($num==$inner_count){
				$rawmatrix.="0,";
				$fullmatrix.="0,";
				$inner_count=0;
				$more=$row['netnum']-$num;
					for($d=$more; $d>0; $d--){
						$rawmatrix.=$fullmatrix_array[$last].",";
						$fullmatrix.=$fullmatrix_array[$last].",";
						$last--;
					}
			$num--;
			}else{
			if(!isset($fullmatrix_array[$c])){
				$fullmatrix_array[$c]=FALSE;
			}
			$rawmatrix.=$fullmatrix_array[$c].",";
			$fullmatrix.=$fullmatrix_array[$c].",";
			$c++;
			$inner_count++;
			}
		}

		//networks.squarematrix computing
		$squarematrix_array = split(",",$rawmatrix);
		$squarematrix="";
		for($c=0; $c<(count($squarematrix_array)-1); $c++){
			if($squarematrix_array[$c]>=$row['split']){
				$squarematrix.="1,";
			}else{
				$squarematrix.="0,";
			}
		}
			$sql="UPDATE networks SET ".
			"matrix=\"$matrix\", tempmatrix=\"$matrix\", ".
			"fullmatrix=\"$fullmatrix\", tempfullmatrix=\"$fullmatrix\", ".
			"squarematrix=\"$squarematrix\", tempsquarematrix=\"$squarematrix\", ".
			"rawmatrix=\"$fullmatrix\" ".
			"WHERE uID=$uID AND netname=\"$network\"";
			mysql_query($sql) or die(sqlError($sql));

		$error_array=array();
		$error=0;

		if(!isset($action)){
			$action=FALSE;
		}
		switch ($action){
			case "change_net_name":
				$sql="UPDATE networks SET netname=\"$new_net_name\" WHERE netname=\"$net\" AND uID=$uID";
				mysql_query($sql) or die(sqlError($sql));
				$sql="UPDATE people SET network=\"$new_net_name\" WHERE uID=$uID AND network=\"$net\"";
				mysql_query($sql) or die(sqlError($sql));
				header("Location: socialnetworks.php");
				exit;
			case "add_person":
				session_register("add_name");
				$add_name=$add;
				header("Location: survey_add.php"); //address matrix issue
				exit;
			case "change_comm":
				header("Location: data2.php");
				session_register("start_matrix");
				$start_matrix=1;
				session_register("display_matrix");
				$display_matrix=1;
				session_register("network");
				$network=$net;
				session_register("num");
				$num=$peoples+1;
				session_register("error");
				$error=0;
				exit;
			case "change_clo":
				header("Location: data2.php");
				session_register("start_matrix");
				$start_matrix=2;
				session_register("display_matrix");
				$display_matrix=2;
				session_register("network");
				$network=$net;
				session_register("num");
				$num=$peoples+1;
				session_register("error");
				$error=0;
				exit;
			case "change_other":
				header("Location: data2.php");
				session_register("start_matrix");
				$start_matrix=3;
				session_register("display_matrix");
				$display_matrix=3;
				session_register("network");
				$network=$net;
				session_register("num");
				$num=$peoples+1;
				session_register("error");
				$error=0;
				exit;
			default:
				$pos=strpos($action,"_");

				if(substr($action,0,$pos)=="del"){ //address matrix issue
					$sql="DELETE FROM people WHERE uID=$uID AND network=\"$net\" AND name=\"".
						substr($action,$pos+1,strlen($action)-$pos)."\"";
					mysql_query($sql) or die(sqlError($sql));

					$sql="SELECT * FROM networks WHERE uID=$uID AND netname=\"$net\"";
					$result=mysql_query($sql) or die(sqlError($sql));
					$row=mysql_fetch_array($result);
					$name_edit=str_replace(substr($action,$pos+1,strlen($action)-$pos).",","",$row['names']);
					$sql="UPDATE networks SET netnum=".($row['netnum']-1).", names=\"$name_edit\" WHERE uID=$uID AND netname=\"$net\"";
					mysql_query($sql) or die(sqlError($sql));
					header("Location: survey_modify.php");
					exit;
				}else{
					session_register("person");
					$person=substr($action,$pos+1,strlen($action)-$pos);
					header("Location: survey_person.php"); //needs to be fixed
				}
		}
	}else{
	session_register("peoples");
	include($baseDir . "common/_javascript.php");
	include($baseDir . "common/_header.php");
?>

<center>
<table width=700 border=0 cellspacing=0 cellpadding=1>
<tr bgcolor=#CCCCCC align=center>
 <td nowrap bgcolor=#FFFFFF height='16'>
	<div align='left'><a href='logout.php'><font color=#006699>Home</font></a>
	 &gt; <a href="socialnetworks.php"><font color=#006699>Social
	 Networks</font></a> &gt; Modify</div>
 </td>
 <td nowrap bgcolor=#FFFFFF height='16' colspan=2>
	 <div align='right'>
<?php
	include($baseDir . "/common/_options.php");
?>
	 </div>
 </td>
</tr>
</table>
</center>

<?php
	$sql="SELECT * FROM networks WHERE uID=$uID and netname=\"$net\"";
	$result=mysql_query($sql) or die(sqlError($sql));
	$row=mysql_fetch_array($result);
	echo "<h2><center>Modify $net Social Network</center></h2>";
	echo "<form action=\"survey_modify.php\" method=\"post\" name=\"form\">";
	echo "<center>";
	echo "<table><tr bgcolor=#006699><td colspan=3><font color=#FFFFFF><center>Social Network</center></font></td></tr>";
	echo "<tr><td bgcolor=#006699><font color=#FFFFFF>Change name</font></td><td bgcolor=#CCCCCC><input type=radio name=action value=\"change_net_name\">".
	 "Type new name:<br><input type=textbox size=20 name=new_net_name></td></tr>";
	echo "<tr><td bgcolor=#006699><font color=#FFFFFF>Change communication matrix</font></td><td bgcolor=#CCCCCC><input type=radio name=action value=\"change_comm\"></td></tr>";
	echo "<tr><td bgcolor=#006699><font color=#FFFFFF>Change closeness matrix</font></td><td bgcolor=#CCCCCC><input type=radio name=action value=\"change_clo\"></td></tr>";
	echo "<tr><td bgcolor=#006699><font color=#FFFFFF>Change other matrix</font></td><td bgcolor=#CCCCCC><input type=radio name=action value=\"change_other\"></td></tr>";
	echo "<tr><td bgcolor=#006699><font color=#FFFFFF>Change median split value</font></td><td bgcolor=#CCCCCC>".
	"<input type=textbox size=4 name=\"split_change\" value=".$row['split']."></td></tr>";
	echo "</table><br>";

	echo "<table><tr bgcolor=#006699><td colspan=2><font color=#FFFFFF><center>Relationships<center></font></td></tr>";

	$sql="SELECT * FROM people WHERE uID=$uID AND network=\"$net\" ORDER BY ID";
	$result=mysql_query($sql) or die(sqlError($sql));

	echo"<td bgcolor=#006699><font color=#FFFFFF>".
		"<center><input maxlength=64 size=10 name=add></center></td>".
		"<td bgcolor=#CCCCCC><font color=#000000>".
		"<input type=radio name=action value=\"add_person\">Add".
			"</td></tr>";
	$sql="SELECT * FROM networks WHERE uID=$uID AND netname=\"$net\"";
	$temp_result=mysql_query($sql);
	$temp_row=mysql_fetch_array($temp_result);

	if($temp_row['upload']==0 || is_null($temp_row['upload'])){
		$row=mysql_fetch_array($result);
	}
	while($row=mysql_fetch_array($result)){
		echo "<tr><td bgcolor=#006699><font color=#FFFFFF>".
			$row['name']."</font></td><td bgcolor=#CCCCCC><input type=radio name=action value=\"mod_".
			$row['name']."\">Modify<br><input type=radio name=action value=\"del_".$row['name']."\">Delete</td></tr>";
	}
	echo "</table>";
	echo "</center>";
	echo "<input type=hidden name=process value=7>";
?>

 <center>
 <br>
 <table width=700 border=0 cellspacing=0 cellpadding=1>
 <tr>
	<td align=center>
	 <a class=smalltext onClick='document.forms[0].jsenabled.value = "T";document.forms[0].submit(); return false;' href="survey_modify.php"><img alt="Submit" src="<?php echo $url . "/img/submit.gif"; ?>" border=0 width="59" height="17"></a>
	</td>
 </tr>
 <input type=hidden value=F name=jsenabled>
 </table>
 </center>
 </form>

<?php
	include("./common/_actions.php");
	include("./common/_disclaimer.php");
	include("./common/_footer.php");
	}
?>
Return current item: NetVis Module