<?
/*
PHP AdminGen by Travis Pulley
Last Updated: 7/2/2003 5:22AM
Current version: 0.3.2
Generates an admin page from a table
Note that template delimiters are '{{' and '}}'
Changes:
- Can choose which fields show up in the listings
- Uses templates to serparate output php from real php (Life simply sucked beforehand)
- Now contructs sql using $fields array and foreach loop
- The checkbox for field inclusion is now functional
- Better structure
- Case for editing
TODO:
- add a pager
- key specification (currently assumes "id")
- display of response messages "opResult"
- Generate combined selects and management for times and dates (kinda started with "Date Selects" option)
- Generate selects with lookup tables
- Provide options for javascript validation on fields
- have enum types suggest "select" and produce options
*/
include('common.php');
if($action == "") {
$template->assign('HTTPS',$HTTPS);
$template->display('index.tpl');
}
else if($_POST['action'] == "login") {
mysql_pconnect("localhost", $_POST['login'], $_POST['pass']) or die( "Unable to connect to SQL server");
mysql_select_db($_POST['db']) or die( "Unable to select database");
$sql = "SELECT * FROM {$_POST['table']}";
$result = mysql_query($sql);
while ($i < mysql_num_fields ($result)) {
$fields[] = mysql_field_name ($result,$i);
$fieldtype[] = mysql_field_type ($result,$i);
$fieldlen[] = mysql_field_len($result,$i);
$i++;
}
mysql_free_result ($result);
?><form method="POST"><table border=1 cellspacing=0 cellpadding=5><?
for($i=0;$i<count($fields);++$i) {
?><tr>
<input type="hidden" name="fields[]" value="<?= $fields[$i] ?>">
<td><b><?= $fields[$i] ?></b></td><td><?= $fieldtype[$i] ?></td>
<td>
<select name="type[]">
<option value="text" <? if ($fieldtype[$i] == "string") echo "selected"; ?>>Text
<option value="hidden">hidden
<option value="password">Password
<option value="radio">Radio
<option value="checkbox"<?= $fieldtype[$i] == "int" && $fieldlen[$i] <= 4 ? " selected":'' ?>>Checkbox
<option value="select">Select
<option value="textarea" <? if ($fieldtype[$i] == "blob") echo "selected"; ?>>Textarea
<option value="dateSelects" <? if ($fieldtype[$i] == "date") echo "selected"; ?>>Date Selects
<option value="dateSelects" <? if ($fieldtype[$i] == "datetime") echo "selected"; ?>>DateTime Selects
</select></td>
<td><input type="checkbox" name="include<?= $i ?>" value="1" CHECKED> Make Editable</td>
<td><input type="checkbox" name="listing<?= $i ?>" value="1"> Show in Listing</td>
<td><input type="text" name="fielddesc[]" value="<?= ucfirst($fields[$i]) ?>"></td>
</tr>
<?
}
?>
</table>
<input type="hidden" name="table" value="<? echo $table; ?>"><br>
<input type="hidden" name="action" value="genform"><br>
<input type="submit" value="Generate Program!"><br>
</form>
<?
}
else if($_POST['action'] == "genform") {
// phpinfo(); die();
header('Content-type: text/plain');
header("Content-Disposition: inline; filename=stuff.txt");
$template->display('output.php');
}
?>