<?php
if(!isset($id)){
    $id = NULL;
}
?>
<iframe id="upload_target" name="upload_target" src="blank_iframe.html" style="width:0;height:0;border:0px solid #fff;"></iframe>
<form action="<?php echo pageLink('actions/upload.php'); ?>" method="post" id="generateForm" class="form" enctype="multipart/form-data" target="upload_target"  onsubmit="startUpload();">
    <h1 class="title"><?php echo printTableName($tableName) ; ?>
        <?php if($table->isCrudEnabled()) : ?><a href="<?php echo pageLink('generate.php?table='.$tableName); ?>" >[ + ]</a><?php endif; ?>
    </h1>
    <hr />
    <h3><?php echo empty($id) ? 'Create a new entry' : 'Update Entry'; ?> <span id="result" style='color:#6e6;font-weight: bold;'></span></h3><br /><br />


    <?php
        //Loop through the current table's fields and output the corresponding form
        foreach($table->returnFieldsNamesTypes() as $fieldName => $fieldTypeLength){
            if($fieldName == 'id' || $fieldName == 'pos'){
                continue;
            }

            echo'<div class="field"><label class="input-control text"><div class="label '. ($table->isRequired($fieldName) ? 'required' : '' ) .'">';

            $tooltip = $table->getTooltip($fieldName);

            echo printTableName($fieldName);
            echo'</div>';
            echo $table->getFormElement($fieldName,$id); //Displays the corresponding form element to the following field
            if(!empty($tooltip))
                echo '<span title="'.$tooltip.'" class="tooltipMessage"></span>';

            echo '</label></div>';
            echo '<br />';

        }
    ?>
    <br style="clear: both;" />
    <div style="float: left; margin-top: 20px;">
        <?php if ($table->isPhotoGallery() && empty($_GET['id'])) : ?>
            <input class="submit round drop_shadow triggerFineUploader" type="button" value="Save" style="float:left" />
            <?php else : ?>
            <input class="submit round drop_shadow" id="save" type="submit" value="Save" style="float:left" />
            <?php endif; ?>


        <input class="submit round drop_shadow"  type="reset" value="Reset" style="float:left;margin-left:4px;">
    </div>
    <input type="hidden" name="id" value="<?php echo $id; ?>" />
    <input type="hidden" name="table" value="<?php echo $tableName; ?>" />
    <div class="clear"></div><br />
    <?php if(!in_array($tableName,$oneRowTables)) :  ?>
        <a href="<?php echo pageLink('list.php?table='.$tableName); ?>" style="display:block;clear:both;" class="listAllRecordsLink">List all records</a>
        <?php endif; ?>
</form>
