<?php
    require_once('common/header.php');


    if(!empty($_GET['table'])){
        $tableName = $_GET['table'];
    }else{
        die("Please select a table!");
    }


    $table = new Table($tableName);
    $id = !empty($_GET['id']) ? $_GET['id'] : 0;
    //oneRowTables have only one default row and users cannot add to it
    if(!$table->isCrudEnabled() && empty($id)){
        redirect_to("dashboard.php");
    }
?>
<div class="round drop_shadow">
    <?php include(ADMIN_PATH.DS."common/generateForm.php"); ?>
</div>
<!-- TinyMCE -->


<script type="text/javascript" src="<?php echo ADMIN_PATH_HTML;?>/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<script type="text/javascript" src="<?php echo ADMIN_PATH_HTML;?>/js/qtip/qtip.js"></script>
<link rel="stylesheet" href="<?php echo ADMIN_PATH_HTML;?>/js/qtip/qtip.css" type="text/css" />
<script type="text/javascript">
    // Create the tooltips only on document load
    $(document).ready(function()
        {
            // By suppling no content attribute, the library uses each elements title attribute by default
            $('.tooltipMessage[title]').qtip({

            });

            // NOTE: You can even omit all options and simply replace the regular title tooltips like so:
            // $('#content a[href]').qtip();
    });
</script>

<script src="<?php echo ADMIN_PATH_HTML;?>/js/jquery.Jcrop.min.js"></script>
<link rel="stylesheet" href="<?php echo ADMIN_PATH_HTML;?>/css/jquery.Jcrop.css" type="text/css" />


<script type="text/javascript">
    // initialize editors
    initMCE();
    
    $(document).ready(function(){
        if ($('input[name=slug]')) {
            if ($('input[name=title]')) {
                $('input[name=title]').keyup(function(){
                    $('input[name=slug]').val(string_to_slug($(this).val()));
                });
            }
        }
    });
    function string_to_slug(str) {
        str = str.replace(/^\s+|\s+$/g, ''); // trim
        str = str.toLowerCase();

        // remove accents, swap ñ for n, etc
        var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
        var to   = "aaaaeeeeiiiioooouuuunc------";
        for (var i=0, l=from.length ; i<l ; i++) {
            str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
        }

        str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
        .replace(/\s+/g, '-') // collapse whitespace and replace by -
        .replace(/-+/g, '-'); // collapse dashes

        return str;
    }
</script>
<!-- /TinyMCE -->

<?php require_once('common/footer.php'); ?>