Location: PHPKode > projects > PhpCodeBuilder > phpcb/codeform.php

<? 
/*
PHP Code Builder
Copyright (C) 2007  Revmakx

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
$db=$_REQUEST['db'];
$table=$_REQUEST['table'];
$btn=$_REQUEST['btn'];
$empty_row=$_REQUEST['empty_row'];
$cap_first=$_REQUEST['cap_first'];
$cap=$_REQUEST['cap'];
include('header.php');
heading('Code For Forms');

//echo '<br> DB='.$db.'<br> Table='.$table.'<br>Empty_row='.$empty_row;//coment 
include('connect.php'); ?>
<? 
if($btn=='Generate Form')
{
function auto_form($btn,$db,$table,$empty_row,$cap_first)
{	 $blank_row='';
	 if($empty_row==1) $blank_row='<tr><td>&nbsp;</td><td>&nbsp;</td></tr>';
	 echo '<center><h3>'.$table.' Form</h3></center>';
	 echo '<table align="center"  border="0">';
	 $q3='describe '.$table;
	 $q3e=mysql_query($q3);
	 if(!$q3e) echo 'error q3e';
	 $n3=mysql_num_rows($q3e);
	 if($n3==0) echo'No Fileds is saved';
	 else
	 {  
	    for($i=0;$i<$n3;$i++)
		{
			$a3=mysql_fetch_array($q3e);
			if($a3[3]!='PRI')
			{	
				$aa3=$a3[0];
				if($cap_first==1){$aa3=ucfirst($a3[0]);}
				if($cap_first==2){$aa3=strtoupper($a3[0]);}
				$hi[$i]=' <tr><td>'.$aa3.':</td><td><input type="text" name="'.$a3[0].'"></td></tr> '.$blank_row;
				echo $hi[$i];
				
			}
			//echo $a3[0].'<br>'.$a3[1].'<br>'.$a3[2].'<br>'.$a3[3].'<br>'.$a3[4].'<br>'.$a3[5].'<br>'.$a3[6].'<br>'.$a3[7];
		}
		echo '<tr><td colspan="2">Code for the Form</td></tr><tr><td colspan="2">
		<textarea name="textarea" cols="50" rows="10">
<form method="post" action="">
<table align="center"  border="0"> ';
		 for($i=0;$i<$n3;$i++)
		{
		echo $hi[$i];
		}
		echo'
</table>
</form></textarea></td></tr></table>';
	}
}
}//if btn ?>

  
<? ////////////////////// function q_db_table($db,$table)
//{
?>
<style type="text/css">
<!--
.style1 {
	font-size: 12px;
	font-family: Arial;
	color: #447C9F;
}
-->
</style>

<form name="form1" method="post" action="?">
    <p>    </p>
    <p>&nbsp;</p>
    <p align="center" class="style1"><strong>Coder's Friend</strong></p>
    <p align="center" class="style1">&nbsp;</p>
  <table width="427" border="0" align="center">
  <tr>
    <th width="261"  align="center" class="style1" scope="row">Select DB</th>
    <td colspan="2" class="style1"><select name="db" onChange="MM_jumpMenu('parent',this,0)">
	 <? $q1e=mysql_query('show databases'); 
	 	if(!$q1e)
		echo 'error q1';
		else
		echo 'succes';
		$n1=mysql_num_rows($q1e);
		if($n1==0)
		echo '<option>No Database is saved </option>';
		else
		{
			for($i=0;$i<$n1;$i++)
			{
				$a1=mysql_fetch_array($q1e);
			
				if($df_db=='')
					$df_db=$a1[0];
				if($db==$a1[0])
					{
						echo '<option selected value=?&db='.$a1[0].'>'.$a1[0].'</option>';
					}
					else
					{
						echo '<option value=?&db='.$a1[0].'>'.$a1[0].'</option>';
					}
			}
		}
		
		
	  ?>

    </select></td>
  </tr>
  <? if($db==NULL)
  {
  	$db=$df_db;
	 include('connect.php');
	}
	else include('connect.php');
	//echo 'DB='.$db.' Table='.$table.' btn_var='.$btn_var.' table='.$table;//coment

  ?>
  <tr>
    <th height="23" align="center" class="style1" scope="row">Tables</th>
    <td colspan="2" class="style1"><select name="table" onChange="MM_jumpMenu('parent',this,0)">
	<?
	
	$q2e=mysql_query('show tables');
	if(!$q2e)
		echo 'error q2';
		$n2=mysql_num_rows($q2e);
		if($n2==0)
		echo '<option>No Tables is saved </option>';
		else
		{
			$select2='selected';
			for($i=0;$i<$n2;$i++)
			{
						$a2=mysql_fetch_array($q2e);
						if($df_table=='')
					$df_table=$a2[0];
				if($table==$a2[0])
					{
						echo '<option selected value=?&db='.$db.'&table='.$a2[0].'>'.$a2[0].'</option>';
					}
					else
					{
						echo '<option value=?&db='.$db.'&table='.$a2[0].'>'.$a2[0].'</option>';
					}
			}
		
	?>
        </select></td>
  </tr>
  <?   if($table==NULL)
  {
  	$table=$df_table;
	 //include('connect.php');
	}
	}//end else if no tables saved.
	
	//return $n2;
//////////////}//funtion ends here

//////////////////////$n2=q_db_table($db,$table);
  ?>
  <tr>
    <th height="23" class="style1" scope="row">&nbsp;</th>
    <td colspan="2" class="style1">&nbsp;</td>
  </tr>
  <? if($n2!=0){ ?>
   <tr>
     <th height="23" align="left" class="style1" scope="row"><label><input name="empty_row" type="checkbox" id="empty_row" value="1" <? if($empty_row==1) echo 'checked="checked"'; ?> />
Empty Row Between Data</label></th>
     <td colspan="2" class="style1">&nbsp;</td>
   </tr>
   <tr>
     <th height="23" align="left" class="style1" scope="row">
	 <fieldset>
     
     <label><input type="checkbox" name="cap" value="1" <? if($cap==1) echo 'checked="checked"'; ?>  onClick="return document.forms.form1.submit();" >
     Choose Case </label>
    
     <p>
<label>
<input name="cap_first" type="radio" <? if($cap!=1){ echo 'disabled';} ?> value="1" <? if($cap_first==1) echo 'checked="checked"'; elseif($cap_first!=1 && $cap_first!=2)echo 'checked="checked"'; ?> >
Title Case 
</label>
     </p>
     <p>
       <label>
       <input name="cap_first" type="radio" <? if($cap!=1){ echo 'disabled';} ?>  value="2" <? if($cap_first==2) echo 'checked="checked"'; ?> >
       Upper Case </label>
     </p>
     </fieldset></th>
     <td colspan="2" class="style1">&nbsp;</td>
   </tr>
   <tr>
    <th height="23" align="left" class="style1" scope="row"><label></label></th>
    <td colspan="2" class="style1">&nbsp;</td>
  </tr>
  <tr>
    <th height="23" colspan="3" class="style1" scope="row"><input name="btn" type="submit" id="btn" value="Generate Form" /></th>
    </tr> 
	<? } ?>
  </table>
  <? if($btn=='Generate Form')
	{
	//echo '<br>table='.$table;
	auto_form($btn,$db,$table,$empty_row,$cap_first);
	}
	 //echo 'n2='.$n2.'<br> DB='.$db.'<br> Table='.$table;//coment ?>
	<input type="hidden" name="db" value="<? echo $db; ?>">
<input type="hidden" name="table" value="<? echo $table; ?>">
</form>
<? require_once('footer.php');?>

Return current item: PhpCodeBuilder