Location: PHPKode > projects > WaveWatcher > wavewatcher3/html/editnetwork.php
<?
	require_once("../classes/user.php");
	require_once("../classes/network.php");
    
  session_start();

	//User have entered a name that already exists in the database.
	$exists		= false;

	//Look if the page have been posted
	if ($HTTP_POST_VARS)
	{		
		$edit_network = $HTTP_POST_VARS["newName"];	
		$sel_network = $HTTP_POST_VARS["selNetwork"];	
	
		if(!empty($edit_network) && !empty($sel_network))
		{
			$exists		= false;
			$user			= new User();
			$networks	= new Network();
			$dbcn			= new DBConnection();

			$pos = strpos($sel_network, " ");			
			$number = substr($sel_network, 0, $pos);
			$name = substr($sel_network, $pos+1);			
				
			$network_result = $networks->GetNetworks(0, "yes");
			while( List($network_id, $network_name) = $dbcn->FetchRow($network_result) )
			{			
				if($network_name == $edit_network)
				{
					$exists = true;
				}
			}					
			if(!$exists && !FindSqlSyntax($edit_network))
			{
				$networks->SetNetworkDetails($number, $edit_network);
			}
			else
			{
				$exists = true;
			}
		}
	}		
	
	//Creates a user object
	$user = new User();

  //If we haven't logged in as a admin we should redirect to another page.
  if (!$user->IsLoggedIn() || !$user->IsAdmin())
  {	
		header("Location: index.php");		
  }

	function createOption()
	{
		$user			= new User();
		$networks	= new Network();
		$dbcn			= new DBConnection();
				
		//
		//  THIS CODE GENERATES THE EXISTING NETWORK LIST.
		//
		$network_result = $networks->GetNetworks(0, "yes");
		while( List($network_id, $network_name) = $dbcn->FetchRow($network_result) )
		{			
				print "<option value=\"$network_id $network_name\">$network_name</option>\n";
		}			
		//
		// END OF EXISTING NETWORK
		//
	}

	// check so that no unwanted SQL querys are inside the strings
  function FindSqlSyntax($str)
  {				
		$str = strtoupper($str);
		     
    if (strpos($str,"SELECT") === FALSE && strpos($str,"UPDATE") === FALSE && strpos($str,"INSERT") === FALSE && strpos($str,"DELETE") === FALSE)
			return FALSE;
		else
			return TRUE;	
	}

	
?>

<html>
	<head>
		<title>Wavewatcher New Network</title>
		<link href="css/style1.css" rel="styleSheet" type="text/css">
		<script language="Javascript">			
		function AskConfirm()
		{			
			var bQuestion = confirm("Are you sure you want to change the name of this network?");			
			if(bQuestion)
			{
				document.create_network.submit();
			}
		}	
	</script>
	</head>
	
	<body bgcolor="#ffffff">
	<table width = "100%" height=20 align="center" border=0 cellpadding="0" cellspacing="0">
		<tr>
			<td><font face="Verdana, Arial, Helvetica, sans-serif" size=1 color="#000000"><b>Wavewatcher</b></font></td>
			<td align=right>
				<a href="home.php">home</a> | 
				<a href="monitor.php">monitor network</a> | 
				<a href="profile.php">profile</a> |
				 <? if ($user->IsAdmin())
                                     print "<a href=\"procsetup.php\">process setup</a> | ";
                          ?> 
				<? if ($user->IsAdmin()) 
				     print "<a href=\"sconfig.php\">configure server</a> | ";
				?>
				<a href="help.html" target="_blank">help</a> | 
				<a href="logout.php">logout</a>
			</td>
		</tr>
	</table>



	<form name="create_network" method="post">
	
	<table width = "50%" height="80%" align="center" border="0">
		<tr>
			<td>
				<!-- background table -->
				<table width="350" align="center" border="0" cellspacing="1" cellpadding="0" bgcolor="#000000">
					<tr>
						<td>
							<!-- gui table -->
							<table width="350" border="0" cellspacing="1" cellpadding="2">
								
								<!-- title row -->
								<tr>
									<td bgcolor="#515173">
										<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">
										<b>Edit Network</b>
										</font>
									</td>
								</tr>

								<!-- message row -->
								<? 
								if (!$exists)
								{ 
								?>
																
								<!-- message row -->
								<tr>
									<td bgcolor="#c0c0c0">
										<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
											Select a network you want to change name on.											
										</font>
									</td>
								</tr>

								<?	
								}
								else
								{
								?>

								<tr>
									<td bgcolor="#FC4848">
										<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
											You have chosen a name that already exists in the database or it's invalid, please select a different name.
										</font>
									</td>
								</tr>

								<?
								}
								?>
								
								<!-- edit network -->
								<tr bgcolor="#fcfcfc">
									<td>
										<table width="100%" border="0" cellspacing="0" cellpadding="2">
											<tr>
												<td align="left">
													<select style="WIDTH: 100%" name="selNetwork">
													<? createOption() ?>
													</select>
												</td>
											</tr>
										</table>
									</td>
								</tr>

								<!-- message row -->
								<tr>
									<td bgcolor="#c0c0c0">
										<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
											Enter the new name of the network you selected.											
										</font>
									</td>
								</tr>

								<!-- new network -->
								<tr bgcolor="#fcfcfc">
									<td>
										<table width="100%" border="0" cellspacing="0" cellpadding="2">
											<tr>
												<td align="center">
													<input size="30" name="newName">
												</td>
												<td align="right">
													<input onClick="javascript:AskConfirm()" type="button" name="editBtn" value="Change name">
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
				<br>				
			</td>
		</tr>
	</table>
	</form>
	</body>
<html>






Return current item: WaveWatcher