Location: PHPKode > scripts > Create Your Own Directory > cms/HRAS/users/addcontent.php
<?php
include "../login/A-header.php";
include "../login/authheader.php";
if($block != true)
{
?>

<html>
<?php
$name1=$_SESSION["UserName"]; 
$id1=$_SESSION["UserId"]; 
$tabid=$_POST['tabid'];
$cnt=$_POST['nam'];
$sub=$_POST['sub'];
?>
<script language=javascript>
var sub="no";
var id1=0;
</script>
<table align=center border=0 bgcolor=#efefef width=90% height=40%>
<form name=fun method=POST action='addcontent.php?name=<?php echo($name1); ?>&id=<?php echo($id1);?>' >
<?php
$ip = $_SERVER['REMOTE_ADDR'];
if($sub=="")
{
$sub="no";
}
echo"<script language='javascript'>";
echo "var name1;";
echo "id1=$id1;";
echo "name1='$name1';";

echo"</script>";
$ct=count($cnt);
$select1=$_POST['select1'];
$select2=$_POST['select2'];
$select3=$_POST['select3'];
$select4=$_POST['select4'];
$view=0;
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')
{
		
		for($i=0;$i<$ct;$i=$i+1)
		{
			$st=$st.$cnt[$i]."####";
			
				
		}

  $str="select * from cnt where contents like '$cnt[0]%'";
  $res=mysql_query($str);



$qryy="select mandatory from cntfields where catid=$tabid";
//echo"$qryy";
  $ress=mysql_query($qryy);
$k=0;
$i=0;
$stt="";
     while($ros = @mysql_fetch_array($ress, MYSQL_ASSOC))
    {
             $val=$ros['mandatory'];
             if($val==1)
              {
               $stt[$i]=$k;
			$i=$i+1;
              }
        	$k=$k+1;
        	
              
    }



	
      $process="insert";
	for($i=0;$i<count($stt);$i=$i+1){
              $vval=$stt[$i];

              if($cnt[$vval]=="")
                   {
                     $process="noinsert";
                    }

       }



  if(!($roww=mysql_fetch_array($res,MYSQL_ASSOC)))
  { 


    if($process=="insert" )
    {
      $qry="insert into cnt values('',$tabid,'$st',$id1,'TBR','$ip',sysdate(),sysdate(),$view)";
      $result=mysql_query($qry);
	if($result)
	{
       $block=true;
	echo"<div align=center style='color:green;'>Your resource titled <font color=red>$cnt[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>" ;
    }
  }else{
     echo"<div align=center style='color:red;'>The Resource with the title <font color=green> $cnt[0] </font> already exist</div>";
  }
}
?>
<tr><td align=center bgcolor=#efefef><br><b>CATEGORY*</b><br>
	<?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))
	{
	$idd=$line['id'];
	$parentid=$line['parentid'];
	$name=$line['name'];
	echo"cat[$j] = new Array($idd, $parentid, '$name');";
	$j=$j+1;
	}
	echo"</script>";
?>
<SCRIPT LANGUAGE="JavaScript">

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,name1)
{
	
	httpa = createRequestObject(); 
	var str="getcnt.php?tid="+tid+"&id="+id1+"&username="+name1;
	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)
	{
	var tmp=eval("document.fun.select"+(now));
      dispid=tmp.value;
	testAjax(dispid,id1,name1);
	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>
	<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>
</td></tr></table>

 <table style="margin-top:50px;" width=50% align=center><tr><td><div id=tt></div></td></tr></table>
</html>
<?php
include "../login/A-footer.php";
}
?>

Return current item: Create Your Own Directory