Location: PHPKode > projects > Decider > decider/Kp_Quiz/addkpquestion.php
<html>

<head><link rel="stylesheet" type="text/css" href="../common/styles.css" />


<script language="javascript">
//Ajax stuff
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}
//select keyperson when changed the domain name
var select_domainkp_req = getXmlHttpRequestObject();
function select_kp(txt){
	//alert(txt);
	if (select_domainkp_req.readyState == 4 ||select_domainkp_req.readyState == 0) {
		var str = escape(txt);
						
		select_domainkp_req.open("GET",'select_domainkp.php?domain='+ str, true);
		select_domainkp_req.onreadystatechange =show_select_kp; 
		select_domainkp_req.send(null);
	}
	
}
	
function show_select_kp(){
	if (select_domainkp_req.readyState == 4) {
			str=select_domainkp_req.responseText.split("\n");
		//alert(str);
		 document.getElementById("kp").innerHTML=str;		 
	}

}
	
//End of select kp stuff
</script>
<script language="javascript">
//Ajax stuff
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}
//select available question for selected keyperson

var select_kpquestion_req=getXmlHttpRequestObject();

function select_question(txt){
//alert(txt);

	if (select_kpquestion_req.readyState == 4 ||select_kpquestion_req.readyState == 0) {
		var str = escape(txt);
						
		select_kpquestion_req.open("GET",'select_domainkp.php?kp='+ str, true);
		select_kpquestion_req.onreadystatechange =show_available_question; 
		select_kpquestion_req.send(null);
	}


}

function show_available_question(){
	if (select_kpquestion_req.readyState == 4) {
			str=select_kpquestion_req.responseText;
		//alert(str);
		document.getElementById("squestion").innerHTML=str;		 
	}

}

//End of question for selected key person

</script>
<script language="javascript">
<!--


//___________________________________________________________________

function getXmlHttpRequestObject() {
	
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		//alert("getxmlHttp");
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}

//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();


//check the current div tag element id by using txtsearch id

//Starts the AJAX request.
var id;
var txtname;
function searchSuggest(txt) {
//alert(txt.value);
		if (searchReq.readyState == 4 || searchReq.readyState == 0) {
		var str = escape(txt.value);
		id=txt.name;
		txtname=txt.id;		
		searchReq.open("GET",'searchsugestquestion.php?search=' + str, true);
		searchReq.onreadystatechange = handleSearchSuggest; 
		searchReq.send(null);
		
		//alert("hello"+id);
	}		
}

//Called when the AJAX response is returned.



function handleSearchSuggest() {
	if (searchReq.readyState == 4) {
		var ss = document.getElementById(id)
		ss.innerHTML = '';
		var str = searchReq.responseText.split("\n");
		for(i=0; i < str.length; i++) {
	
			//Build our element string.  This is cleaner using the DOM, but
			//IE doesn't support dynamically added attributes.
			var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
			suggest += 'onmouseout="javascript:suggestOut(this);" ';
			suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
			suggest += 'class="suggest_link">' + str[i] + '</div>';
			ss.innerHTML += suggest;
		}
	}
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}
//Click function
function setSearch(value) {
	//id.value=value;
	document.getElementById(txtname).value = value;
	document.getElementById(id).innerHTML = '';
}

//______________________________________________________________________


function suggestquestionload(obj){
	//alert(obj.value);
			document.getElementById("nquestion").value=obj.value;
			code = '<br>';
		var j=0;
		for(i=0;i<obj.selectedIndex;i++){
			txtsearch = "text"+i;
			divid="divid"+i;
			j++
			 code = code+'<tr><td class="label">'+(j)+'. Question </td><td><textarea cols="50" class="textboxarea"  id="'+txtsearch+'" name="'+divid+'" onkeyup="searchSuggest(this);" autocomplete="off" ></textarea ></td></tr><tr><td></td><td><span id="'+divid+'"></span></td></tr>'
			
		
		}
		code+='<tr><td></td><td><input type="submit"  value="Add" class="button" name="Add">&nbsp;&nbsp;&nbsp;<input type="button" value=" cancel " class="button"></td></tr>'
		document.getElementById("writehere").innerHTML = code;
	}
//-->
</script>
<!-- help code-->
<script language="javascript">
var id;
var txtname;
function handlehelp(txt) {
var str;

			id=txt;
			txtname=txt;		
			var ss = document.getElementById("help");
			ss.innerHTML = '';
			if(id=="addkeypersonquizhelp"){
		    str = "This form is used to add new key person's questions";
			}
			
			var suggest = '<div onmouseover="javascript:helpOver(this);" ';
			suggest += 'onmouseout="javascript:helpOut(this);" ';
			suggest += 'onclick="javascript:closeBox(this.innerHTML);" ';
			suggest += 'class="suggest_lin">'+ 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>

<style type="text/css" media="screen">
			body1 {
				font: 11px arial;
			}
			.suggest_link {
				background-color: #EAEAEA;
				padding: 2px 6px 2px 6px;
				font-weight:bold;
			font-size:12px;
			color:#666666;
			}
			.suggest_link_over {
				background-color: #AAAAAA;
				padding: 2px 6px 2px 6px;
				cursor:pointer;
				font-weight:bold;
			font-size:12px;
			color:#666666;
				
			}
			#divid0 {
				 
				position:absolute; 
				background-color: #CCCCCC; 
				color:#000000;
				text-align: left; 
				border: 1px solid #000000;			
			}	
			#divid1 {
				position:absolute; 
				background-color: #CCCCCC;
				color:#000000; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid2 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid3 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid4 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid5 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid6 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid7 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}	
			#divid8 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid9 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid10 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid11 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid12{
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid13 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid14{
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid15 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid16 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid17{
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid18 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid19 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid20 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid21 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid22 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}		
			#divid23 {
				 
				position:absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;			
			}				
		</style>
	

</head>


<body>

<div class="topic">Add Key Person Question</div>
<form  id="addkpquestion" action="" method="post">

<table>
<?php
		require("../common/database.php");
		 $result = mysql_query( "SELECT * FROM domain");
		 	$i=0;?>
			 <tr><td class="label">Domain Name</td><td>
			 <select id="domain" name="domain" onChange="javascript:select_kp(this.value);" class="select">
			 <option >-select domain-</option>
			<?php $result = mysql_query( "SELECT * FROM domain");
			 while($row=mysql_fetch_array($result)){
			 	?>
				<option value="<?php echo $row['Name']?>"><?php echo $row['Name']?></option>
				
				<?php
			 }
			 
			?>
	</select></td>
	<td><img src="../common/HelpIcon.gif" height="30" width="30" type="" name="Submit"  id="addkeypersonquizhelp" onClick="handlehelp(this.id)" class="pointer"><div id="help" class="length" >
 </div>
</td>
	</tr>
				<tr><td class="label">Key Person Name</td><td><select  id="kp" name="kp" onChange="javascript:select_question(this.value);" class="select">
				
	</select></td></tr><tr><td>&nbsp;</td></tr>
	</table>
	
	<div class="topic">Available Questions</div>
	<br />
				<table id="squestion" class="label"></table>
				<br />
			<div class="topic">Add New Questions </div>
			<table>
			<tr><td class="label">No Of questions </td><td>   <select  name="no_of_kp" onChange="javascript:suggestquestionload(this);" id="no_of_question" class="select">
			<option selected value=0 >-select-</option>
        <option value=1 >1</option>
        <option  value=2 >2</option>
        <option value=3 >3</option>
        <option value=4 >4</option>
        <option value=5 >5</option>
        <option value=6 >6</option>
        <option value=7 >7</option>
        <option value=8 >8</option>
        <option value=9 >9</option>
        <option value=10 >10</option>
        <option value=11 >11</option>
        <option value=12 >12</option>
        <option value=13 >13</option>
        <option value=14 >14</option>
        <option value=15 >15</option>
        <option value=16 >16</option>
        <option value=17 >17</option>
        <option value=18 >18</option>
        <option value=19 >19</option>
        <option value=20 >20</option>
        <option value=21 >21</option>
        <option value=22 >22</option>
        <option value=23 >23</option>
        <option value=24 >24</option>
        <option value=25 >25</option>
       
    </select>
</td></tr><br><br>
<input type="hidden" id="nquestion" value="">
</table>
<table id="writehere"><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td ><input type="submit" value="Ok" class="button" name=""></td><td><input type="reset" value=" cancel " class="button"></td></tr></table>

<br><br>

</form>

</body>

</html>

<?php
//require("../common/database.php");
		 
if(isset($_POST['Add'])){
$i=0;
$gg="";
	//$result = mysql_query( "SELECT * FROM domain");
	$i = $_POST['no_of_kp'];
	echo $i;
	//print_r($_POST);
	for($j=0;$j<$i+1;$j++){
		$gg="divid".$j;
		$result=mysql_query("SELECT Id FROM quiz WHERE Question='".$_POST[$gg]."'");
		$num_rows = mysql_num_rows($result);
		//echo "rows available".$num_rows;
		if($num_rows==0){
		//echo "new question";
			mysql_query("INSERT INTO quiz(Question) VALUES('".$_POST[$gg]."')");
			dbinsert($_POST[$gg]);
		}else{
		//echo "old question";
			dbinsert($_POST[$gg]);
		}
		 
		
	}

}
function dbinsert($value){
//echo "call my fucntion";
$result=mysql_query("SELECT Id FROM quiz WHERE Question='".$value."'");
	while($row1=mysql_fetch_array($result)){
		 		
				$q_string="INSERT INTO kid_qid(K_Id,Q_Id) VALUES('".$_POST['kp']."','".$row1['Id']."')";
				if (!mysql_query($q_string)){
	  				die('Error: ' . mysql_error());
	 		 	}
	 			
				
			
		 }
} 

?>
Return current item: Decider