/**
     * Back-end widget form.
     *
     * @see WP_Widget::form()
     *
     * @param array $instance Previously saved values from database.
     */
    public function form($instance)
    {
        if (isset($instance['title'])) {
            $title = $instance['title'];
        } else {
            $title = __('New title', 'text_domain');
        }
        if (isset($instance['poll_id'])) {
            $poll_id = $instance['poll_id'];
        } else {
            $poll_id = -1;
        }
        if (isset($instance['chwidth'])) {
            $chwidth = intval($instance['chwidth']);
        } else {
            $chwidth = 270;
        }
        if (isset($instance['chheight'])) {
            $chheight = intval($instance['chheight']);
        } else {
            $chheight = 220;
        }
        if ($chwidth == 0) {
            $chwidth = 270;
        }
        if ($chheight == 0) {
            $chheight = 220;
        }
        if (isset($instance['chlegend'])) {
            $chlegend = $instance['chlegend'];
        } else {
            $chlegend = 'none';
        }
        $polls = GFontsDB::GetAllPolls();
        ?>
        <p>
            <label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', GFontsEngine::PLUGIN_SLUG);
        ?>
</label>
            <input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />
            <br/><br/>
            <label for="<?php 
        echo $this->get_field_id('poll_id');
        ?>
"><?php 
        _e('Select poll:', GFontsEngine::PLUGIN_SLUG);
        ?>
</label>
            <select class="widefat" id="<?php 
        echo $this->get_field_id('poll_id');
        ?>
" name="<?php 
        echo $this->get_field_name('poll_id');
        ?>
">
                <option value="-1"><?php 
        _e('-- select --', GFontsEngine::PLUGIN_SLUG);
        ?>
</option>
                <?php 
        foreach ($polls as $poll) {
            ?>
<option value="<?php 
            echo $poll->id;
            ?>
"<?php 
            if ($poll->id == $poll_id) {
                echo " selected";
            }
            ?>
><?php 
            echo $poll->name;
            ?>
</option><?php 
        }
        ?>
            </select>
            <br/>
            <br/>
            <label for="<?php 
        echo $this->get_field_id('chwidth');
        ?>
"><?php 
        _e('Chart width:', GFontsEngine::PLUGIN_SLUG);
        ?>
</label>
            <input class="widefat" id="<?php 
        echo $this->get_field_id('chwidth');
        ?>
" name="<?php 
        echo $this->get_field_name('chwidth');
        ?>
" type="text" value="<?php 
        echo esc_attr($chwidth);
        ?>
" />
            <br/>
            <br/>
            <label for="<?php 
        echo $this->get_field_id('chheight');
        ?>
"><?php 
        _e('Chart height:', GFontsEngine::PLUGIN_SLUG);
        ?>
</label>
            <input class="widefat" id="<?php 
        echo $this->get_field_id('chheight');
        ?>
" name="<?php 
        echo $this->get_field_name('chheight');
        ?>
" type="text" value="<?php 
        echo esc_attr($chheight);
        ?>
" />
            <br/>
            <br/>
            <label for="<?php 
        echo $this->get_field_id('chlegend');
        ?>
"><?php 
        _e('Chart legend (only for Pie and Donut):', GFontsEngine::PLUGIN_SLUG);
        ?>
</label>
            <select class="widefat" id="<?php 
        echo $this->get_field_id('chlegend');
        ?>
" name="<?php 
        echo $this->get_field_name('chlegend');
        ?>
">
                <option value="none"<?php 
        if ($chlegend == 'none') {
            echo ' selected';
        }
        ?>
><?php 
        _e('none', GFontsEngine::PLUGIN_SLUG);
        ?>
</option>
                <option value="left"<?php 
        if ($chlegend == 'left') {
            echo ' selected';
        }
        ?>
><?php 
        _e('left', GFontsEngine::PLUGIN_SLUG);
        ?>
</option>
                <option value="right"<?php 
        if ($chlegend == 'right') {
            echo ' selected';
        }
        ?>
><?php 
        _e('right', GFontsEngine::PLUGIN_SLUG);
        ?>
</option>
                <option value="top"<?php 
        if ($chlegend == 'top') {
            echo ' selected';
        }
        ?>
><?php 
        _e('top', GFontsEngine::PLUGIN_SLUG);
        ?>
</option>
                <option value="bottom"<?php 
        if ($chlegend == 'bottom') {
            echo ' selected';
        }
        ?>
><?php 
        _e('bottom', GFontsEngine::PLUGIN_SLUG);
        ?>
</option>
            </select>
        </p>
        <?php 
    }