<script type="text/javascript">

    $.ctrl('S', function () {
        return json_add('home_widgets-add', '', '1', 'popupform');
    });

</script>


<form action="" method="post" id="popupform" onsubmit="return json_add('home_widgets-add','','1','popupform');">


<div id="popupsave">

    <input type="submit" value="Save" class="save"/>

</div>

<h1>Customize Homepage Widgets</h1>


<div class="popupbody">


    <?php





    $homepage = new homepage_widgets($employee);

    $homepage->get_widgets();


    if ($employee['permissions']['admin'] == '1') {
        $where = "`hide`!='1'";
    } else {
        $where = "`hide`!='1' AND `perms`!='admin'";
    }


    $q1 = $db->run_query("

        SELECT *

        FROM `ppSD_homepage_widgets`

        WHERE $where

        ORDER BY `title` ASC

    ");

    while ($row = $q1->fetch()) {
        if (in_array($row['id'], $homepage->widgets)) {
            $active = '1';

        } else {
            $active = '0';

        }
        $data    = $homepage->get_widget($row['id']);
        $options = unserialize($data['options']);

        ?>

        <div class="popup_full_section">

            <div class="popup_h4_right"><input type="checkbox" name="<?php echo $row['id']; ?>[pin]"
                                               name="check-<?php echo $row['id']; ?>"
                                               onclick="return show_add('<?php echo $row['id']; ?>');"
                                               value="1" <?php if ($active == '1') {
                    echo "checked=\"checked\"";
                } ?> /> Add to Homepage
            </div>

            <h4><?php echo $row['title']; ?></h4>

            <div class="pad24" id="show-<?php echo $row['id']; ?>" style="display:

            <?php





            if ($active == '1') {
                echo "block";

            } else {
                echo "none";

            }

            ?>;">


                <?php





                if ($row['custom'] == '1') {

                } else {
                    ?>



                    <div class="field">

                        <label>Display</label>

                        <div class="field_entry">

                            <input type="text" name="<?php echo $row['id']; ?>[options][limit]"
                                   value="<?php echo $options['limit']; ?>" style="width:80px;"/>

                        </div>

                    </div>



                    <div class="field">

                        <label>Range</label>

                        <div class="field_entry">

                            <?php





                            $name = $row['id'] . "[options][timeframe]";

                            $timeframe = $admin->construct_timeframe($options['increments'], $options['unit']);

                            echo $admin->timeframe_field($name, $timeframe, '0');

                            ?>

                        </div>

                    </div>



                    <div class="field">

                        <label>Show</label>

                        <div class="field_entry">

                            <input type="checkbox" name="<?php echo $row['id']; ?>[options][graph]"
                                   value="1"<?php if ($options['graph'] == '1') {
                                echo " checked=\"checked\"";
                            } ?> /> Graph <input type="checkbox" name="<?php echo $row['id']; ?>[options][list]"
                                                 value="1"<?php if ($options['list'] == '1') {
                                echo " checked=\"checked\"";
                            } ?> /> List

                        </div>

                    </div>



                    <?php





                    if (!empty($options['fields'])) {
                        foreach ($options['fields'] as $opt) {
                            echo '<input type="hidden" name="' . $row['id'] . '[fields][' . $opt . ']" value="1" />';

                        }

                    }

                    ?>



                <?php

                }

                ?>


            </div>

        </div>

    <?php

    }



    ?>


</div>


</form>


<script type="text/javascript">

    function show_add(id) {
        $('#show-' + id).slideToggle();
    }

</script>