/**
 * Function to read options from the database and add any new ones.
 *
 * @return array Options from the database
 */
function hiilite_read_options()
{
    $hiilite_settings_changed = false;
    $defaults = hiilite_default_options();
    $hiilite_settings = array_map('stripslashes', (array) get_option('hiilite_settings'));
    unset($hiilite_settings[0]);
    // produced by the (array) casting when there's nothing in the DB
    // If there are any new options added to the Default Options array, let's add them
    foreach ($defaults as $k => $v) {
        if (!isset($hiilite_settings[$k])) {
            $hiilite_settings[$k] = $v;
        }
        $hiilite_settings_changed = true;
    }
    if (true == $hiilite_settings_changed) {
        update_option('hiilite_settings', $hiilite_settings);
    }
    return apply_filters('hiilite_read_options', $hiilite_settings);
}
/**
 * Add to Footer options.
 */
function hiilite_options()
{
    global $wpdb;
    $poststable = $wpdb->posts;
    $hiilite_settings = hiilite_read_options();
    if (isset($_POST['hiilite_save']) && check_admin_referer('hiilite-admin-options')) {
        $hiilite_settings['enable_plugin'] = isset($_POST['enable_plugin']) ? true : false;
        $hiilite_settings['disable_notice'] = isset($_POST['disable_notice']) ? true : false;
        $hiilite_settings['hiilite_other'] = $_POST['hiilite_other'];
        update_option('hiilite_settings', $hiilite_settings);
        $str = '<div id="message" class="updated fade"><p>' . __('Options saved successfully.', 'hiilite-admin') . '</p></div>';
        echo $str;
    }
    if (isset($_POST['hiilite_default']) && check_admin_referer('hiilite-admin-options')) {
        delete_option('hiilite_settings');
        $hiilite_settings = hiilite_default_options();
        update_option('hiilite_settings', $hiilite_settings);
        $str = '<div id="message" class="updated fade"><p>' . __('Options set to Default.', 'hiilite-admin') . '</p></div>';
        echo $str;
    }
    ?>

<div class="wrap">
	<h2><?php 
    _e("Hiilite Admin", 'hiilite-admin');
    ?>
</h2>
	<div id="poststuff">
	<div id="post-body" class="metabox-holder columns-2">
	<div id="post-body-content">
	  <form method="post" id="hiilite_options" name="hiilite_options" onsubmit="return checkForm()">
	    <div id="genopdiv" class="postbox"><div class="handlediv" title="<?php 
    _e('Click to toggle', 'hiilite-admin');
    ?>
"><br /></div>
	      <h3 class='hndle'><span><?php 
    _e('General options', 'hiilite-admin');
    ?>
</span></h3>
	      <div class="inside">
			<table class="form-table">
				<tr><th scope="row" style="background:#<?php 
    if ($hiilite_settings['enable_plugin']) {
        echo 'cfc';
    } else {
        echo 'fcc';
    }
    ?>
"><label for="enable_plugin">&nbsp;<?php 
    _e('Enable Footer Code:', 'hiilite-admin');
    ?>
</label></th>
					<td style="background:#<?php 
    if ($hiilite_settings['enable_plugin']) {
        echo 'cfc';
    } else {
        echo 'fcc';
    }
    ?>
"><input type="checkbox" name="enable_plugin" id="enable_plugin" <?php 
    if ($hiilite_settings['enable_plugin']) {
        echo 'checked="checked"';
    }
    ?>
 /></td>
				</tr>
				
				<tr><th scope="row" colspan="2"><?php 
    _e('HTML (no PHP) to add to <code>wp_footer</code>:', 'hiilite-admin');
    ?>
</th>
				</tr>
				<tr><td scope="row" colspan="2"><textarea name="hiilite_other" id="hiilite_other" rows="15" cols="80"><?php 
    echo stripslashes($hiilite_settings['hiilite_other']);
    ?>
</textarea></td>
				</tr>
			</table>
	      </div>
	    </div>
		<p>
		  <input type="submit" name="hiilite_save" id="hiilite_save" value="<?php 
    _e('Save Options', 'hiilite-admin');
    ?>
" class="button button-primary" />
		  <input type="submit" name="hiilite_default" id="hiilite_default" value="<?php 
    _e('Default Options', 'hiilite-admin');
    ?>
" class="button button-secondary" onclick="if ( ! confirm( '<?php 
    _e("Do you want to set options to Default?", 'hiilite-admin');
    ?>
' ) ) return false;" />
		</p>
		<?php 
    wp_nonce_field('hiilite-admin-options');
    ?>
	  </form>

	</div><!-- /post-body-content -->
	<div id="postbox-container-1" class="postbox-container">
	  <div id="side-sortables" class="meta-box-sortables ui-sortable">
		  <?php 
    hiilite_admin_side();
    ?>
	  </div><!-- /side-sortables -->
	</div><!-- /postbox-container-1 -->
	</div><!-- /post-body -->
	<br class="clear" />
	</div><!-- /poststuff -->
</div><!-- /wrap -->

<?php 
}