/**
  * Update an existing db entry
  * 
  * @param array $entry
  */
 function editEntry($entry)
 {
     global $wpdb;
     $ad = new Advertisment($entry['advertisment_id']);
     $ad->setName($wpdb->escape($entry['advertisment_name']));
     $ad->setVendor($wpdb->escape($entry['advertisment_vendor']));
     $ad->setHtml($entry['advertisment_code']);
     $ad->setWeight($entry['advertisment_weight']);
     $ad->setSize($entry['advertisment_size']);
     $ad->setActive(isset($entry['advertisment_active']) ? true : false);
     $ad->updateDatabase();
 }
/**
 * Install the plugin
 * 
 * This function runs when the plugin is activated. Checks if database table exists and creates it.
 * 
 * @since 0.1
 */
function was_install()
{
    global $wpdb;
    add_option('was_show_per_page', '10');
    $was_db_version = '0.1';
    $table_name = $wpdb->prefix . 'was_data';
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) {
        $sql = "CREATE TABLE `" . $table_name . "` (\n\t\t\t`advertisment_id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`advertisment_active` int(11) DEFAULT '1' NOT NULL,\n\t\t\t`advertisment_vendor` varchar(200) DEFAULT '' NOT NULL,\n\t\t\t`advertisment_name` varchar(200) DEFAULT '' NOT NULL,\n\t\t\t`advertisment_code` text NOT NULL,\n\t\t\t`advertisment_weight` int(11) DEFAULT '1' NOT NULL,\n\t\t\t`advertisment_size` varchar(20) DEFAULT '125x125' NOT NULL,\n\t\t\tPRIMARY KEY  (`advertisment_id`)\n\t\t\t);";
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($sql);
        add_option('was_db_version', $was_db_version);
    }
    $ad = new Advertisment();
    $ad->setName('Wordpress Trac');
    $ad->setHtml('http://core.trac.wordpress.org/timeline');
    $ad->updateDatabase();
}