Location: PHPKode > scripts > Create Your Own Directory > cms/admin/contentfield.php
<?php
include "authheader.php";
if($block != true)
{
$frm='false';
?>
<!-- Welcome to the scripts database of HIOX INDIA      -->
<!-- This tool is developed and a copyright             -->
<!-- product of HIOX INDIA.				        -->
<!-- For more information visit http://www.hscripts.com -->
<html>
<head>
</head>
<body style="margin: 0px;">
<?php include "heade.php" ?>
<br>
<table align=center border=0 bgcolor=#f8f8ff  width=80%>

<tr><td align=center>
<tr height=95%><td class=maintext valign=top>
<html>
<br>
<table align=center border=0 bgcolor=#f8f8ff  width=100%>

<SCRIPT LANGUAGE=JavaScript>


function addvalue()
{
document.fun.hidval.value="insert";
}

function editvalue()
{
document.fun.hidval.value="edit";
}
function updatevalue()
{
document.fun.sub.value="update";
}
function deletevalue()
{
document.fun.sub.value="delete";
}


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,i,opr,oldval)
{
	
var tmp=eval("document.val"+i+".fname"+i);
var tmp1=eval("document.val"+i+".ftyp"+i);
var tmp2=eval("document.val"+i+".inptyp"+i);
var tmp3=eval("document.val"+i+".defval"+i);
var tmp4=eval("document.val"+i+".dispcnt"+i);
var tmp5=eval("document.val"+i+".manfld"+i);

var vaal=tmp.value;
var vaal1=tmp1.value;
var vaal2=tmp2.value;
var vaal3=tmp3.value;
var vaal4=tmp4.value;
var vaal5=tmp5.value;



	httpa = createRequestObject(); 
	var str="editcntfield.php?oldval="+oldval+"&catid="+tid+"&opr="+opr+"&fname="+vaal+"&ftype="+vaal1+"&inputtype="+vaal2+"&defaultval="+ vaal3+"&contentpg="+vaal4+"&mandatory="+vaal5+"&sno="+i;
	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;
            var res=response.split("----")
		var xx=eval("document.getElementById('divv"+res[0]+"')");
		xx.innerHTML=res[1];
	}
}

</script>

<?php


$fname=$_POST['fname'];
$typsel=$_POST['typsel'];
$dtsel=$_POST['dtsel'];
$defval=$_POST['defval'];
$dispcnt=$_POST['dispcnt'];
$name=$_POST['catname'];
$manfld=$_POST['manfld'];
$hidval=$_POST['hidval'];
$update=$_POST['update'];
$fname=$_POST['fname'];
$id=$_POST['id'];
$sub=$_POST['sub'];
$typsel=$_POST['typsel'];
$select1=$_POST['select1'];
$select2=$_POST['select2'];
$select3=$_POST['select3'];
$select4=$_POST['select4'];
$sel="";
$frm=true;
if($select1==0)
{

  $edit=0;
}
else if($select2 ==0)
{
	$edit=$select1;
	$parentid=$select1;
      $idd=$select1;

}else if($select3==0)
{
	$edit=$select2;
	$parentid=$select2;
      $idd=$select2;

}else if($select4==0)
{
  	$edit=$select3;
	$parentid=$select3;
      $idd=$select3;

}else if($select4 !=0)
{
  	$edit=$select4;
	$parentid=$select3;
      $idd=$select4;

}


$qqry="select distinct ftype from cntfields";
$i=0;
$ftyparr =array();
$ree=mysql_query($qqry,$link);
	while($line = @mysql_fetch_array($ree,MYSQL_ASSOC))
	{
	$ftyparr[$i]=$line['ftype'];
      $i++;
	}

$qqry="select distinct inputtype from cntfields";
$j=0;
$inparr =array();

$ree=mysql_query($qqry,$link);
	while($line = @mysql_fetch_array($ree,MYSQL_ASSOC))
	{
	$inparr[$j]=$line['inputtype'];
      $j++;
	}

if($hidval=='insert')
{
if(  $fname!="" && $typsel != "" && $dtsel != "" )
{

	$present1="no";
	$query="select fname from cntfields where fname='$fname' and catid=$idd";
	//echo"$query";
	$result1=mysql_query($query,$link);
	while($line = @mysql_fetch_array($result1, MYSQL_ASSOC))
	{
	$present1=$line['name'];
	}
	if($present1=='no')
	{
		if($idd !=0)
		{
			$query="insert into cntfields values('$idd','$fname','$dtsel','$typsel','$defval','$dispcnt','$manfld')";
			$result1=mysql_query($query,$link);
                  if($result1)
                       echo"<div align=center><font color=green>Content field for selected category is added</font></div>";
                  else
                      echo"<div align=center><font color=red>Enter proper values for mandatory fields</font></div>";



		
		}else{
			echo"<div align=center><font color=red>select category before adding content fields</font></div>";
		}

	}else{
			echo"<div align=center><font color=red>Added field already present for select category</font></div>";
		}

	
}
}


if($hidval=='edit')
{
	if($id != 0)
	$edit=$id;
	$parent="no";
		$query="select name from type  where parentid=$edit";
		$result1=mysql_query($query,$link);
		while($line = @mysql_fetch_array($result1, MYSQL_ASSOC))
		{
			$parent=$line['name'];
		}
	if($parent =="no")
	{
		$frm='false';
 
		$query="select * from cntfields where catid=$edit"; 
    		//$query="update type set name='$name' , des='$des' where id=$id";
 		$result1=mysql_query($query,$link);
 		if($result1)
 		{
			$i=1;
			while($line = @mysql_fetch_array($result1, MYSQL_ASSOC))
 			{    
				$id=$line['catid'];
				$fname=$line['fname'];
				$ftype=$line['ftype'];
 				$inputtype=$line['inputtype'];
				$defaultval=$line['defaultval'];
				$contentpg=$line['contentpg'];
				$mandatory=$line['mandatory'];
 	 			echo"<form name='val"."$i' method=get action=$php_self><tr><td colspan=2><div align=center id=divv$i style='color:green;'></div><table border=0 align=center with=100%><tr><td >Category Id</td>
				<td  ><input type=text name=id$i value='$id' readonly></td></tr>
				<tr><td width=30% >Field Name</td>
				<td><input type=text name=fname$i value='$fname'></td></tr>
				<tr><td width=30% > Field Type</td>
				<td><select name=ftyp$i >";
				for($j=0;$j<count($ftyparr);$j++)
                        {
                        if($ftyparr[$j]==$ftype)
	                        echo"<option value=$ftyparr[$j] selected>$ftyparr[$j]</option>";
   				else
	                        echo"<option value=$ftyparr[$j]>$ftyparr[$j]</option>";

                        }
     				echo"</select></td></tr>
                        <tr><td width=30% > Field Input Type</td>
				<td><select name=inptyp$i  >";
				for($j=0;$j<count($inparr);$j++)
                        {
                        if($inparr[$j]==$inputtype)
	                        echo"<option value=$inparr[$j] selected>$inparr[$j]</option>";
   				else
	                        echo"<option value=$inparr[$j]>$inparr[$j]</option>";
                        }

      			echo"</select></td></tr>
				<tr><td width=30% > Default Value</td>
				<td><input type=text name=defval$i value='$defaultval'>
				<tr><td  width=30%  >Display in content page</td>";
                        if($contentpg==1){
                                 $sel2="selected";
                                  $sel1="";
                        }else{
                                $sel1="selected";
                                $sel2="";

                        }
				echo"<td> <select name='dispcnt$i' >
                                           
      			<option value=1 $sel2>1</option>
      			<option value=0 $sel1>0</option>
      			</select>
				</td></tr>";
                        if($mandatory==1){
     	                       $sel12="selected";
                             $sel11="";
                        }else{
                             $sel11="selected";
                             $sel12="";
                        }
				echo"<tr><td width=30% >Mandatory Field</td>
				<td><select name='manfld$i' >
      			<option value=0 $sel11>0</option>
      			<option value=1 $sel12>1</option>
      			</select>
				</td></tr>
				<tr><td colspan=2 align= center>
				<input type=button value=Edit  name='update".$i."' onclick=\"testAjax($id,$i,'update','$fname')\">
				<input type=button value=Delete name='delete".$i."' onclick=\"testAjax($id,$i,'delete','$fname')\">
				<input type=hidden name=hid$i value=$fname >
				<input type=hidden name=sub ><div align=right><img src=$home/image/get.gif style='display:none;' id=donimg$i></div>";
    				echo"</td></tr></table></form>";
				
				
				$i=$i+1;


				
 			}
 		}else
 		{
      		echo"<div align=center style=\"color:red\";>Select atleast one category</div>";
 		}
	}else{
    		echo"<div align=center style=\"color:red\";>Select Leaf node to edit content fields</div>";

	}
}
?>
<?php
	echo"<SCRIPT LANGUAGE='JavaScript'>";
   	echo"var cat = new Array();";
	$query="select * from type";

	$result=mysql_query($query,$link);
	$j=0;
	while($line = @mysql_fetch_array($result, MYSQL_ASSOC))
	{
		$id=$line['id'];
		$parentid=$line['parentid'];
		$name=$line['name'];
		echo" cat[$j] = new Array($id, $parentid, '$name');";
		$j=$j+1;
	}
	echo"</script>";
?>
<?php
	echo"<SCRIPT LANGUAGE=JavaScript>";
	echo"var cat = new Array();";
	$query="select * from type";
	$result=mysql_query($query,$link);
	$j=0;
	while($line = @mysql_fetch_array($result, MYSQL_ASSOC))
	{
	$id=$line['id'];
	$parentid=$line['parentid'];
	$name=$line['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;
}
function second(now,next)
{	

var ds=document.getElementById("dispp");
ds.style.display='none';

	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 ds=document.getElementById("dispp");
ds.style.display='block';

	    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;
     		}
	}
//document.fun.addparent.style.visibility="hidden";
}
</script>
<?php
if($frm=="true"){
	echo"<form name=fun method=POST action=$php_self>
	<tr><td  width=30% style='padding-left:20px; padding -top:20px;'>Category</td>
	<td style='padding -top:20px;'><select name=select1 size=8 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=8 onclick=\"second(2,3)\">
	</select>
   	<select style='visibility: hidden;' name=select3 size=8 onclick=\"second(3,4)\">
	</select>
	<select style='visibility: hidden;' name=select4 size=8 onclick=\"second(4,5)\">
	</select>
	<select style='visibility: hidden;' name=select5 size=8 onclick=\"second(5,6)\">
	</select>
	</td></tr><tr><td colspan=2><div id='dispp'><table width=100%> ";
	
	echo"	<tr><td height=20 width=30% colspan=2></td></tr>
	<tr><td width=30%  style='padding-left:20px;'>Enter Field Name</td>
	<td><input type=text name='fname'></td></tr>
	<tr><td  style='padding-left:20px;'>Enter Input Type</td>          
	<td>          
	<select name='typsel'>
      <option value=textbox>textbox</option>
      <option value=textarea>textarea</option>
      <option value=selectbox>selectbox</option>
 	</select>
	</td></tr>
	<tr><td width=30%  style='padding-left:20px;'>Field Data Type</td>
	<td><select name='dtsel' >
      <option value=int>int</option>
      <option value=longint>longint</option>
      <option value=varchar>varchar</option>
	<option value=text>text</option>
      <option value=blob>blob</option>
 	</select>
	</td></tr>
      <tr><td  width=30% height=50 style='padding-left:20px;'>Enter Default Values<br><font color=green>(seperate values by comma)</font></td>
	<td valign=top><input type=text name='defval'></td></tr>
	<tr><td width=30%  style='padding-left:20px;'>Display in content page</td>
	<td><select name='dispcnt' >
      <option value=0>0</option>
      <option value=1 selected>1</option>
      </select>
	</td></tr>
	<tr><td width=30%  style='padding-left:20px;'>Mandatory Field</td>
	<td><select name='manfld' >
      <option value=0>0</option>
      <option value=1 selected>1</option>
      </select>
	</td></tr>
	<tr><td width=30%  colspan=2>
	<input type=hidden name=hidval >
	<div align=center><input type=submit name=update value='Add Field' onclick=\"addvalue()\">
	<input type=submit name=Edit value='Edit Field' onclick=\"editvalue()\"></input></div>
	
	</td></tr>
	<tr><td height=20 colspan=2></td></tr></table></div></form>
      </td></tr>";

}
	
?>
</table>
<script language=javascript>

var ds=document.getElementById("dispp");
ds.style.display='none';

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>
</td></tr>
</table>
<tr><td height=20 bgcolor=white>
</td></tr></table>

</body>
</html>
<!-- Welcome to the scripts database of HIOX INDIA      -->
<!-- This tool is developed and a copyright             -->
<!-- product of HIOX INDIA.				        -->
<!-- For more information visit http://www.hscripts.com -->
<?php
}
?>




 
Return current item: Create Your Own Directory