<?php
include "../login/A-header.php";
include "../login/authheader.php";
if($block != true)
{
?>
<html>
<?php
?>
<br>
<table align=center border=0 bgcolor=#efefef width=90%>
<form name=fun method=POST action='edit.php'>
<?php
$id1=$_SESSION["UserId"];
$name1=$_SESSION["UserName"];
$sub=$_POST['sub'];
$subb=$_GET['subb'];
$cnt=$_POST['nam'];
$cntid1=$_GET['cntid'];
$sub=$_GET['sub'];
$cntid=$_POST['cntid'];
$updat=$_POST['updat'];
$summary=$_POST['summary'];
$select1=$_POST['select1'];
$select2=$_POST['select2'];
$select3=$_POST['select3'];
$select4=$_POST['select4'];
$check=$_POST['mybox'];
$id=$_GET['id'];
$ct=count($cnt);
$usrid=$_POST['usrid'];
//$cnt=count($check);
$frm='true';
$sel="";
echo"<script language='javascript'>";
echo "id1=$id1;";
echo "cntidd=$cntid1;";
echo"</script>";
if($select1==0)
{
}else if($select2 ==0)
{
$tid=$select1;
}else if($select3==0)
{
$tid=$select2;
}else if($select4==0)
{
$tid=$select3;
}else
{
$tid=$select4;
}
if($sub=='yes')
{
$qry="select * from cnt where cntid=$cntid1";
$result=mysql_query($qry);
if($line = @mysql_fetch_array($result, MYSQL_ASSOC))
{
$contents=$line['contents'];
$cntid=$line['cntid'];
$tid=$line['tid'];
$usrid=$line['usrid'];
$arr=split('####',$contents);
}
}
if($subb=="yes"){
$qryy="select mandatory from cntfields where catid=$tid";
$res=mysql_query($qryy);
$k=0;
$i=0;
$stt="";
while($ros = @mysql_fetch_array($res, MYSQL_ASSOC))
{
$val=$ros['mandatory'];
if($val==1)
{
$stt[$i]=$k;
$i=$i+1;
}
$k=$k+1;
}
for($i=0;$i<$ct;$i=$i+1)
{
$st=$st.$cnt[$i]."####";
}
$process="update";
for($i=0;$i<count($stt);$i=$i+1){
$vval=$stt[$i];
if($cnt[$vval]=="")
{
$process="noupdate";
}
}
if($process=="update" )
{
$qry="update cnt set contents='$st',upddate=sysdate(),status='TBR' where cntid=$cntid";
$result=mysql_query($qry);
if($result)
{
$block=true;
echo"<div align=center style='color:green;'>Your resource titled <font color=red>$nam[0]</font> will be updated in the database after admin review</div>";
}
}else
{
echo"<div align=center style='color:red;'>Enter proper values for mandatory fields</div>" ;
}
}
?>
<?php
echo"<SCRIPT LANGUAGE='JavaScript'>";
echo"var cat = new Array();";
$query="select * from type";
$result=mysql_query($query);
$j=0;
while($line = @mysql_fetch_array($result, MYSQL_ASSOC))
{
$id=$line['id'];
$parentid=$line['parentid'];
$name=$line['name'];
//echo"---$id--$parentid--$name";
echo"cat[$j] = new Array($id, $parentid, '$name');";
$j=$j+1;
}
echo"</script>";
?>
<SCRIPT LANGUAGE="JavaScript">
var check = true;
var val ="<?php echo($tid);?>";
var arr = new Array;
var jj=0;
while(check)
{
for(var ff=0; ff<cat.length; ff++)
{
if(cat[ff][0]==val)
{
val = cat[ff][1];
tthis = cat[ff][2];
arr[jj]=cat[ff][0];
jj=jj+1;
//alert("THis -"+tthis+"-- Parent-- "+val);
}
}
if(val == 0)
check = false;
}
var dispid=0;
function change(tid)
{
dispid=tid;
}
//alert(dispid);
var browser = navigator.appName;
function createRequestObject(){
var request_o; //declare the variable to hold the object.
if(browser == "Microsoft Internet Explorer"){
/* Create the object using MSIE's method */
request_o = new ActiveXObject("Microsoft.XMLHTTP");
}else{
/* Create the object using other browser's method */
request_o = new XMLHttpRequest();
}
return request_o; //return the object
}
var httpa;
function testAjax(tid,id1,cntidd)
{
httpa = createRequestObject();
var str="editcnt.php?tid="+tid+"&id="+id1+"&cntidd="+cntidd;
httpa.open('get', str);
httpa.onreadystatechange = handleResponse;
/* Send the data. We use something other than null when we are sending using the POST
method. */
httpa.send(null);
}
function handleResponse() {
if(httpa.readyState == 4){
var response = httpa.responseText;
//alert(response);
var xx=document.getElementById("tt");
xx.innerHTML=response;
}
}
function second(now,next)
{
var tt=0;
var from = eval("document.fun.select"+now);
var dd = from.selectedIndex;
var res = from[dd].value;
var ss = eval("document.fun.select"+(next));
var ss1 = eval("document.fun.select"+(next+1));
var ss2 = eval("document.fun.select"+(next+2));
if(now==1)
{
ss1.style.visibility="hidden";
ss2.style.visibility="hidden";
}
for(var ff=0; ff<cat.length; ff++)
{
if(cat[ff][1]==res)
{
ss.style.visibility="visible";
var tt=1;
}
}
if(tt==0)
{
document.fun.select1.disabled = true ;
document.fun.select2.disabled = true;
document.fun.select3.disabled = true;
document.fun.select4.disabled = true;
document.fun.select5.disabled = true;
var tmp=eval("document.fun.select"+(now));
dispid=tmp.value;
ss.style.visibility="hidden";
}
ss.options.length = 0;
var cc = gg = 0;
for(var ff=0; ff<cat.length; ff++)
{
var val = cat[ff];
if(val[1] == res)
{
var tobeadded = val[2];
var tobeadded2 = val[0];
ss.options[gg] = new Option(tobeadded,tobeadded2);
gg = gg+1;
}
}
}
</script>
<?php
if($frm=='true')
{
echo"<tr><td width=15%>Title </td><td ><input type=text name=title value=\"$arr[0]\"></input></td></tr>
<tr><td width=15% >Category</td><td width=200 >
<select name=select1 size=10 onclick=\"second(1,2)\">
<script language=javascript>
for(var d=0; d<cat.length; d++)
{
if(cat[d][1] == 0)
document.write(\"<option value=\"+cat[d][0]+\">\"+cat[d][2]+\"</option>\");
}
</script>
</select>
<select style='visibility: hidden;' name=select2 size=10 onclick=\"second(2,3)\">
</select>
<select style='visibility: hidden;' name=select3 size=10 onclick=\"second(3,4)\">
</select>
<select style='visibility: hidden;' name=select4 size=10 onclick=\"second(4,5)\">
</select>
<select style='visibility: hidden;' name=select5 size=10 onclick=\"second(5,6)\">
</select>
<input type=hidden name=usrid value=$id>
<input type=hidden name=updat value='updat'></input>
<input type=hidden name=cntid value=$cntidd></input>
</td></tr><tr><td align=center colspan=2 ><input type=button value=Edit onclick='testAjax(dispid,id1,cntidd);'></input></td></tr>
<tr><td height=20></td></tr><tr><td colspan=2>
<div id=tt></div></td></tr>";
echo"</table>
</form>";
}
?>
<script language=javascript>
var coun=1;
for(i=arr.length-1;i>=0;i--)
{
var xx = eval("document.fun.select"+coun);
var dd = xx.options.length;
for(var fg=0; fg<dd; fg++){
if(xx[fg].value == arr[i])
xx[fg].selected = true;
}
second(coun,(coun+1));
coun=coun+1;
}
</script>
</html>
<?php
include "../login/A-footer.php";
}
?>