Location: PHPKode > projects > Decider > decider/Analyst/analysttab.php
<?php

	require('../Login/authen.php');

?>
<?php
session_start();
	
	if($_SESSION['userid']!=1){
	
		include "../Login/normal.php";
	
		exit();	
	}
	
	
?>

<html>
<head>
<title>Decider - Information Gathering Assistant</title>
<link rel="stylesheet" type="text/css" href="../ajaxtabs/ajaxtabs.css" />
<link rel="stylesheet" type="text/css" href="../common/styles.css" />
<script type="text/javascript" src="../ajaxtabs/ajaxtabs.js">

</script>
<script type="text/javascript">

var xmlHttp

function showHint(str)
{
  if (str.length==0)
  { 
 	document.getElementById("suggest").innerHTML=""
	return
  }
  xmlHttp=GetXmlHttpObject()

  if (xmlHttp==null)
  {
	alert ("Browser does not support HTTP Request")
	return
  }
   
  var url="gethint.php"
  url=url+"?q="+str
  url=url+"&sid="+Math.random()
  xmlHttp.onreadystatechange=stateChanged 
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
} 

function stateChanged() 
{ 

  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  { 
	var str=xmlHttp.responseText;

	var length=str.length
	var arr=new Array();
	for(i=0;i<length;i++){
	//used letter 'x' instead of 'k'
	  arr[i]=str.substring(0,str.indexOf('x'))
	  str=str.substring(str.indexOf('x')+1)
	}

  document.getElementById("analyst_id").value=arr[0]
  document.getElementById("analyst_new_name").value=arr[1]
  document.getElementById("analyst_address").value=arr[2]
  document.getElementById("analyst_work_telno").value=arr[3]
  document.getElementById("analyst_home_telno").value=arr[4]
  document.getElementById("analyst_mobileno").value=arr[5]
  document.getElementById("analyst_email").value=arr[6]
  document.getElementById("analyst_username").value=arr[7]
  document.getElementById("analyst_password").value=arr[8]
  
  } 
} 

function GetXmlHttpObject()
{ 
  var objXMLHttp=null
  if (window.XMLHttpRequest)
  {
	objXMLHttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject)
  {
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  return objXMLHttp
} 
</script> 
<!-- help code-->
<script language="javascript">
var id;
var txtname;
function handleSearchSuggest(txt) {
var str;

			id=txt;
			txtname=txt;		
			var ss = document.getElementById("help");
			ss.innerHTML = '';
			if(id=="addanalysthelp"){
		    str = "This form is used to add new analyst details";
			}
			if(id=="editanalysthelp"){
			str = "This form is used to edit analyst details";
			}
			if(id=="deleteanalysthelp"){
			str = "This form is used to delete analyst details";
			}
			var suggest = '<div onmouseover="javascript:helpOver(this);" ';
			suggest += 'onmouseout="javascript:helpOut(this);" ';
			suggest += 'onclick="javascript:closeBox(this.innerHTML);" ';
			suggest += 'class="suggest_link">'+ str + '</div>';
			ss.innerHTML += suggest;
			}

//Mouse over function
function helpOver(div_value) {
	div_value.className = 'help_over';
}
//Mouse out function
function helpOut(div_value) {
	div_value.className = 'help_out';
}
//Click function
function closeBox(value) {
	document.getElementById("help").innerHTML = '';
}

</script>
</head>

<body>
<div id='maindiv' align="center" >
<table width="800px" height="115px"><tr><td align="left" valign="top"><?php require('../common/top.html'); ?></td>
	</tr></table>

<table background="../common/tableback.png" width="800px" height="800px">
<tr align="right"><td></td><td class="label" align="right">
	<?php 
	
echo $_SESSION['username'];
?></td></tr>
	<tr>
	
		<td width="200px" align="left" valign="top"><?php require('../common/menu.html'); ?></td>
		<td width="600px" align="left" valign="top"><?php require('analysttab.html'); ?></td>
	</tr>
</table>

<?php
//to add data to client table
if(isset($_POST['add'])){

	require("../common/database.php");
	
	//converting analyst password to md5 format
	$password = md5($_POST['analyst_password']);
	
	$q_string = "INSERT INTO analyst (Id, Name, Address,Work_Tel,Home_Tel,Mobile,Email,User_Name,Password)
	VALUES
	('$_POST[analyst_id]','$_POST[analyst_name]','$_POST[analyst_address]','$_POST[analyst_work_telno]','$_POST[analyst_home_telno]','$_POST[analyst_mobileno]','$_POST[analyst_email]','$_POST[analyst_username]','$password')";

	if (!mysql_query($q_string,$link))
	  {
	  die('Error: ' . mysql_error());
	  }
	echo "1 record added";
	
	mysql_close($link);
	
}
?>

<?php 
//to edit data in client table
if(isset($_POST['edit'])){
	require("../common/database.php");
	if (!$link)
  	{
  		die('Could not connect: ' . mysql_error());
  	}
	
	//converting analyst password to md5 format
	$password = md5($_POST['analyst_password']);

//concerned analyst 'Id' instead of anlyst 'Name'
$q_string="UPDATE analyst SET Name = '$_POST[analyst_new_name]',Address='$_POST[analyst_address]',Work_Tel='$_POST[analyst_work_telno]',Home_Tel='$_POST[analyst_home_telno]',Mobile='$_POST[analyst_mobileno]',Email='$_POST[analyst_email]',User_Name='$_POST[analyst_username]',Password='$password' WHERE Id = '$_POST[analyst_id]'";
//$q_string="UPDATE analyst SET Address='$_POST[analyst_address]',Work_Tel='$_POST[analyst_work_telno]',Home_Tel='$_POST[analyst_home_telno]',Mobile='$_POST[analyst_mobileno]',Email='$_POST[analyst_email]',User_Name='$_POST[analyst_username]',Password='$_POST[analyst_password]' WHERE Name = '$_POST[analyst_name]'";
		
if (!mysql_query($q_string,$link))
	  {
	  die('Error: ' . mysql_error());
	  }
	echo "1 record edited";
	
	mysql_close($link);
	
	
}
?>

<?php 
//to delete data from client table
if(isset($_POST['delete'])){

	require("../common/database.php");
	if (!$link)
  	{
  		die('Could not connect: ' . mysql_error());
  	}

//concerned analyst 'Name' instead of anlyst 'ID'
//$q_string="DELETE FROM analyst WHERE ID='$_POST[analyst_id]'";

$q_string="DELETE FROM analyst WHERE Name='$_POST[analyst_name]'";	
if (!mysql_query($q_string,$link))
	  {
	  die('Error: ' . mysql_error());
	  }
	echo "1 record deleted";
	
	mysql_close($link);
	
	
}
?>
</div >
</body>
</html>
Return current item: Decider