function events_activate() { global $wpdb; $table_name1 = $wpdb->prefix . "events"; $table_name2 = $wpdb->prefix . "events_categories"; if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } } if (!events_mysql_table_exists($table_name1)) { // Add table if it's not there $add1 = "CREATE TABLE `" . $table_name1 . "` (\n\t \t\t`id` mediumint(8) unsigned NOT NULL auto_increment PRIMARY KEY,\n\t \t\t`title` longtext NOT NULL,\n\t \t\t`title_link` varchar(3) NOT NULL default 'N',\n\t \t\t`location` varchar(255) NOT NULL,\n\t \t\t`category` int(11) NOT NULL default '1',\n\t \t\t`pre_message` longtext NOT NULL,\n\t \t\t`post_message` longtext NOT NULL,\n\t \t\t`link` longtext NOT NULL,\n\t \t\t`allday` varchar(3) NOT NULL default 'N',\n\t \t\t`thetime` int(15) NOT NULL default '0',\n\t \t\t`theend` int(15) NOT NULL default '0',\n\t \t\t`author` varchar(60) NOT NULL default '',\n\t \t\t`priority` varchar(4) NOT NULL default 'no',\n\t \t\t`archive` varchar(4) NOT NULL default 'no'\n\t\t\t) " . $charset_collate; if (mysql_query($add1) !== true) { events_mysql_warning(); } } else { // Or send out epic fail! events_mysql_warning(); } if (!events_mysql_table_exists($table_name2)) { $add2 = "CREATE TABLE `" . $table_name2 . "` (\n\t\t\t`id` mediumint(8) unsigned NOT NULL auto_increment PRIMARY KEY,\n\t\t\t`name` varchar(255) NOT NULL\n\t\t\t) " . $charset_collate; if (mysql_query($add2) !== true) { events_mysql_warning(); } } else { // Or send out epic fail! events_mysql_warning(); } if (events_mysql_table_exists($table_name1)) { if (!($result = mysql_query("SHOW COLUMNS FROM `{$table_name1}`"))) { echo 'Could not run query: ' . mysql_error(); } $i = 0; while ($row = mysql_fetch_assoc($result)) { $field_array[] = mysql_field_name($row, $i); $i++; } if (in_array('review', $field_array)) { mysql_query("ALTER TABLE `{$table_name1}` DROP `review`;"); } } else { // Or send out epic fail! events_mysql_upgrade_error(); } }
function events_activate() { global $wpdb; if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } } if (!events_mysql_table_exists("{$wpdb->prefix}events")) { // Add table if it's not there $wpdb->query("CREATE TABLE `{$wpdb->prefix}events` (\n\t \t\t`id` mediumint(8) unsigned NOT NULL auto_increment PRIMARY KEY,\n\t \t\t`title` longtext NOT NULL,\n\t \t\t`title_link` varchar(3) NOT NULL default 'N',\n\t \t\t`location` varchar(255) NOT NULL,\n\t \t\t`category` int(11) unsigned NOT NULL default '1',\n\t \t\t`pre_message` longtext NOT NULL,\n\t \t\t`post_message` longtext NOT NULL,\n\t \t\t`link` longtext NOT NULL,\n\t \t\t`allday` varchar(3) NOT NULL default 'N',\n\t \t\t`thetime` int(15) unsigned NOT NULL default '0',\n\t \t\t`theend` int(15) unsigned NOT NULL default '0',\n\t \t\t`author` varchar(60) NOT NULL default '',\n\t \t\t`priority` varchar(4) NOT NULL default 'no',\n\t \t\t`archive` varchar(4) NOT NULL default 'no'\n\t\t\t) " . $charset_collate); } if (!events_mysql_table_exists("{$wpdb->prefix}events_categories")) { $wpdb->query("CREATE TABLE `{$wpdb->prefix}events_categories` (\n\t\t\t`id` mediumint(8) unsigned NOT NULL auto_increment PRIMARY KEY,\n\t\t\t`name` varchar(255) NOT NULL\n\t\t\t) " . $charset_collate); } }
function events_categories() { global $wpdb, $events_config; $action = $cat_edit_id = $catorder = ''; if (isset($_GET['action'])) { $action = esc_attr($_GET['action']); } if (isset($_GET['edit_cat'])) { $cat_edit_id = esc_attr($_GET['edit_cat']); } if (isset($_POST['catorder'])) { $catorder = esc_attr($_POST['catorder']); } else { $catorder = 'id ASC'; } ?> <div class="wrap"> <h2><?php _e('Categories', 'wpevents'); ?> </h2> <?php if ($action == 'delete-category') { ?> <div id="message" class="updated fade"><p><?php _e('Category <strong>deleted</strong>', 'wpevents'); ?> </p></div> <?php } else { if ($action == 'no_access') { ?> <div id="message" class="updated fade"><p><?php _e('Action prohibited', 'wpevents'); ?> </p></div> <?php } else { if ($action == 'category_new') { ?> <div id="message" class="updated fade"><p><?php _e('Category <strong>created</strong>', 'wpevents'); ?> . <a href="admin.php?page=wp-events-edit"><?php _e('Add events now', 'wpevents'); ?> </a></p></div> <?php } else { if ($action == 'category_edit') { ?> <div id="message" class="updated fade"><p><?php _e('Category <strong>updated</strong>', 'wpevents'); ?> </p></div> <?php } else { if ($action == 'category_field_error') { ?> <div id="message" class="updated fade"><p><?php _e('No category name filled in', 'wpevents'); ?> </p></div> <?php } } } } } ?> <?php if (!$cat_edit_id) { ?> <form name="groups" id="post" method="post" action="admin.php?page=wp-events-category"> <div class="tablenav"> <div class="alignleft actions"> <input onclick="return confirm('<?php _e('You are about to delete one or more categories! Make sure there are no events in those categories or they will not show on the website', 'wpevents'); ?> \n<?php _e('[OK] to continue, [Cancel] to stop.', 'wpevents'); ?> ')" type="submit" value="<?php _e('Delete category', 'wpevents'); ?> " name="delete_categories" class="button-secondary delete" /> <select name='catorder'> <option value="id ASC" <?php if ($catorder == "id ASC") { echo 'selected'; } ?> ><?php _e('in the order you made them', 'wpevents'); ?> (<?php _e('ascending', 'wpevents'); ?> )</option> <option value="id DESC" <?php if ($catorder == "id DESC") { echo 'selected'; } ?> ><?php _e('in the order you made them', 'wpevents'); ?> (<?php _e('descending', 'wpevents'); ?> )</option> <option value="name ASC" <?php if ($catorder == "name ASC") { echo 'selected'; } ?> ><?php _e('by name', 'wpevents'); ?> (A-Z)</option> <option value="name DESC" <?php if ($catorder == "name DESC") { echo 'selected'; } ?> ><?php _e('by name', 'wpevents'); ?> (Z-A)</option> </select> <input type="submit" id="post-query-submit" value="<?php _e('Sort', 'wpevents'); ?> " class="button-secondary" /> </div> </div> <table class="widefat" style="margin-top: .5em"> <thead> <tr> <th scope="col" class="check-column"> </th> <th scope="col" width="5%"><center><?php _e('ID', 'wpevents'); ?> </center></th> <th scope="col"><?php _e('Name', 'wpevents'); ?> </th> <th scope="col" width="10%"><center><?php _e('Events', 'wpevents'); ?> </center></th> </tr> </thead> <tbody> <?php if (events_mysql_table_exists("{$wpdb->prefix}events_categories")) { $categories = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}events_categories` ORDER BY {$catorder}"); if ($categories) { $class = ''; foreach ($categories as $category) { $count = $wpdb->get_var("SELECT COUNT(category) FROM `{$wpdb->prefix}events` WHERE `category` = '{$category->id}' GROUP BY `category`"); $class = 'alternate' != $class ? 'alternate' : ''; ?> <tr id='group-<?php echo $category->id; ?> ' class=' <?php echo $class; ?> '> <th scope="row" class="check-column"><input type="checkbox" name="categorycheck[]" value="<?php echo $category->id; ?> " /></th> <td><center><?php echo $category->id; ?> </center></td> <td><strong><a class="row-title" href="<?php echo get_option('siteurl') . '/wp-admin/admin.php?page=wp-events-category&edit_cat=' . $category->id; ?> " title="<?php _e('Edit', 'wpevents'); ?> "><?php echo $category->name; ?> </a></strong></td> <td><center><?php echo $count; ?> </center></td> </tr> <?php } ?> <?php } } else { ?> <tr id='no-id'><td scope="row" colspan="4"><span style="font-weight: bold; color: #f00;"><?php _e('There was an error locating the database table for the Events categories.', 'wpevents'); _e('Please deactivate and re-activate Events from the plugin page!!', 'wpevents'); ?> <br /><?php echo sprintf(__('If this does not solve the issue please seek support at <a href="%s">%s</a>.', 'wpevents'), 'http://meandmymac.net/contact-and-support/?pk_campaign=wpevents-categories&pk_kwd=databaseerror', 'http://meandmymac.net/support/'); ?> </a></span></td></tr> <?php } ?> <tr id='category-new'> <th scope="row" class="check-column"> </th> <td colspan="3"><input name="events_cat" type="text" class="search-input" size="40" maxlength="255" value="" /> <input type="submit" id="post-query-submit" name="events_category_submit" value="<?php _e('Add', 'wpevents'); ?> " class="button-secondary" /></td> </tr> </tbody> </table> </form> <br class="clear" /> <?php events_credits(); ?> <?php } else { ?> <?php $edit_cat = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}events_categories` WHERE `id` = '{$cat_edit_id}'"); $message = ''; if ($message == 'field_error') { ?> <div id="message" class="updated fade"><p><?php _e('Please fill in a name for your category!', 'wpevents'); ?> </p></div> <?php } if ($cat_edit_id > 0) { ?> <form method="post" action="admin.php?page=wp-events-category"> <input type="hidden" name="events_id" value="<?php echo $cat_edit_id; ?> " /> <table class="widefat" style="margin-top: .5em"> <thead> <tr valign="top"> <th colspan="2" bgcolor="#DDD"><?php _e('You can change the name of the category here. The ID stays the same!', 'wpevents'); ?> </th> </tr> </thead> <tbody> <tr> <th scope="row" width="25%"><?php _e('ID', 'wpevents'); ?> :</th> <td><?php echo $edit_cat->id; ?> </td> </tr> <tr> <th scope="row" width="25%"><?php _e('Name', 'wpevents'); ?> :</th> <td><input tabindex="1" name="events_cat" type="text" size="67" class="search-input" autocomplete="off" value="<?php echo $edit_cat->name; ?> " /></td> </tr> </tbody> </table> <p class="submit"> <input tabindex="2" type="submit" name="events_category_submit" class="button-primary" value="<?php _e('Save Category', 'wpevents'); ?> " /> <a href="admin.php?page=wp-events-category" class="button"><?php _e('Cancel', 'wpevents'); ?> </a> </p> </form> <?php } else { ?> <table class="widefat" style="margin-top: .5em"> <thead> <tr valign="top"> <th><?php _e('Error!', 'wpevents'); ?> </th> </tr> </thead> <tbody> <tr> <td><?php _e('No valid group ID specified!', 'wpevents'); ?> <a href="admin.php?page=wp-events-category"><?php _e('Continue', 'wpevents'); ?> </a>.</td> </tr> </tbody> </table> <?php } ?> <?php } ?> </div> <?php }