function mc_mass_delete_locations()
{
    global $wpdb;
    $mcdb = $wpdb;
    // mass delete locations
    if (!empty($_POST['mass_edit']) && isset($_POST['mass_delete'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        $locations = $_POST['mass_edit'];
        $i = $total = 0;
        $deleted = $ids = array();
        foreach ($locations as $value) {
            $total = count($locations);
            $ids[] = (int) $value;
            $deleted[] = $value;
            $i++;
        }
        $statement = implode(',', $ids);
        $sql = 'DELETE FROM ' . my_calendar_locations_table() . " WHERE location_id IN ({$statement})";
        $result = $mcdb->query($sql);
        if ($result !== 0 && $result !== false) {
            mc_delete_cache();
            // argument: array of event IDs
            do_action('mc_mass_delete_locations', $deleted);
            $message = "<div class='updated'><p>" . sprintf(__('%1$d locations deleted successfully out of %2$d selected', 'my-calendar'), $i, $total) . "</p></div>";
        } else {
            $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Your locations have not been deleted. Please investigate.', 'my-calendar') . "</p></div>";
        }
        echo $message;
    }
}
function my_calendar_save_group($action, $output, $event_id = false)
{
    global $wpdb, $event_author;
    $mcdb = $wpdb;
    $proceed = $output[0];
    $message = '';
    if ($action == 'edit' && $proceed == true) {
        $event_author = (int) $_POST['event_author'];
        if (mc_can_edit_event($event_author)) {
            $update = $output[2];
            $update = apply_filters('mc_update_group_data', $update, $event_author, $action, $event_id);
            $formats = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%f', '%f');
            //$mcdb->show_errors();
            $result = $mcdb->update(my_calendar_table(), $update, array('event_id' => $event_id), $formats, '%d');
            //$mcdb->print_error();
            $url = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? ' ' . sprintf(__('View <a href="%s">your calendar</a>.', 'my-calendar'), get_option('mc_uri')) : '';
            do_action('mc_save_event', 'edit', $update, $event_id, $result);
            // same as action on basic save
            do_action('mc_save_grouped_events', $result, $event_id, $update);
            if ($result === false) {
                $message = "<div class='error'><p><strong>#{$event_id}; " . __('Error', 'my-calendar') . ":</strong>" . __('Your event was not updated.', 'my-calendar') . "{$url}</p></div>";
            } else {
                if ($result === 0) {
                    $message = "<div class='updated'><p>#{$event_id}: " . __('Nothing was changed in that update.', 'my-calendar') . "{$url}</p></div>";
                } else {
                    $message = "<div class='updated'><p>#{$event_id}: " . __('Event updated successfully', 'my-calendar') . ".{$url}</p></div>";
                    mc_delete_cache();
                }
            }
        } else {
            $message = "<div class='error'><p><strong>#{$event_id}: " . __('You do not have sufficient permissions to edit that event.', 'my-calendar') . "</strong></p></div>";
        }
    }
    $message = $message . "\n" . $output[3];
    return $message;
}
Пример #3
0
function check_my_calendar()
{
    global $wpdb, $initial_listjs, $initial_caljs, $initial_minijs, $initial_ajaxjs, $mc_version, $grid_template, $rss_template, $list_template, $mini_template, $single_template, $defaults;
    $mcdb = $wpdb;
    mc_if_needs_permissions();
    $current_version = get_option('mc_version') == '' ? get_option('my_calendar_version') : get_option('mc_version');
    // If current version matches, don't bother running this.
    if ($current_version == $mc_version) {
        return true;
    }
    // Lets see if this is first run and create a table if it is!
    // Assume this is not a new install until we prove otherwise
    $new_install = false;
    $my_calendar_exists = false;
    $upgrade_path = array();
    // Determine the calendar version
    $tables = $mcdb->get_results("show tables;");
    foreach ($tables as $table) {
        foreach ($table as $value) {
            if ($value == MY_CALENDAR_TABLE) {
                $my_calendar_exists = true;
                // check whether installed version matches most recent version, establish upgrade process.
            }
        }
    }
    if ($my_calendar_exists == true && $current_version == '') {
        // If the table exists, but I don't know what version it is, I have to run the full cycle of upgrades.
        $current_version = '1.5.9';
    }
    if ($my_calendar_exists == false) {
        $new_install = true;
    } else {
        // for each release requiring an upgrade path, add a version compare.
        // Loop will run every relevant upgrade cycle.
        if (version_compare($current_version, "1.8.0", "<")) {
            $upgrade_path[] = "1.8.0";
        }
        if (version_compare($current_version, "1.9.0", "<")) {
            $upgrade_path[] = "1.9.0";
        }
        if (version_compare($current_version, "1.9.1", "<")) {
            $upgrade_path[] = "1.9.1";
        }
        if (version_compare($current_version, "1.9.3", "<")) {
            $upgrade_path[] = "1.9.3";
        }
        if (version_compare($current_version, "1.10.0", "<")) {
            $upgrade_path[] = "1.10.0";
        }
        if (version_compare($current_version, "1.10.7", "<")) {
            $upgrade_path[] = "1.10.7";
        }
        if (version_compare($current_version, "1.11.0", "<")) {
            $upgrade_path[] = "1.11.0";
        }
        if (version_compare($current_version, "1.11.1", "<")) {
            $upgrade_path[] = "1.11.1";
        }
        if (version_compare($current_version, "2.0.0", "<")) {
            $upgrade_path[] = "2.0.0";
        }
        if (version_compare($current_version, "2.0.4", "<")) {
            $upgrade_path[] = "2.0.4";
        }
        if (version_compare($current_version, "2.1.0", "<")) {
            $upgrade_path[] = "2.1.0";
        }
        if (version_compare($current_version, "2.2.0", "<")) {
            $upgrade_path[] = "2.2.0";
        }
        if (version_compare($current_version, "2.2.6", "<")) {
            $upgrade_path[] = "2.2.6";
        }
        if (version_compare($current_version, "2.2.10", "<")) {
            $upgrade_path[] = "2.2.10";
        }
        if (version_compare($current_version, "2.3.0", "<")) {
            $upgrade_path[] = "2.3.0";
        }
    }
    // having determined upgrade path, assign new version number
    update_option('mc_version', $mc_version);
    // Now we've determined what the current install is or isn't
    if ($new_install == true) {
        //add default settings
        mc_default_settings();
        $sql = "INSERT INTO " . MY_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_color='#ffffcc', category_icon='event.png'";
        $mcdb->query($sql);
    } else {
        // clear cache so updates are immediately available
        mc_delete_cache();
    }
    // switch for different upgrade paths
    foreach ($upgrade_path as $upgrade) {
        switch ($upgrade) {
            // only upgrade db on most recent version
            case '2.3.0':
                delete_option('mc_location_control');
                $user_data = get_option('mc_user_settings');
                $loc_type = get_option('mc_location_type') == '' ? 'event_state' : get_option('mc_location_type');
                $locations[$loc_type] = $user_data['my_calendar_location_default']['values'];
                add_option('mc_use_permalinks', false);
                delete_option('mc_modified_feeds');
                add_option('mc_location_controls', $locations);
                add_option('mc_location_access', array('1' => __('Accessible Entrance', 'my-calendar'), '2' => __('Accessible Parking Designated', 'my-calendar'), '3' => __('Accessible Restrooms', 'my-calendar'), '4' => __('Accessible Seating', 'my-calendar'), '5' => __('Accessible Transportation Available', 'my-calendar'), '6' => __('Wheelchair Accessible', 'my-calendar'), '7' => __('Courtesy Wheelchairs', 'my-calendar'), '8' => __('Bariatric Seating Available', 'my-calendar'), '9' => __('Elevator to all public areas', 'my-calendar'), '10' => __('Braille Signage', 'my-calendar'), '11' => __('Fragrance-Free Policy', 'my-calendar'), '12' => __('Other', 'my-calendar')));
                add_option('mc_event_access', array('1' => __('Audio Description', 'my-calendar'), '2' => __('ASL Interpretation', 'my-calendar'), '3' => __('ASL Interpretation with voicing', 'my-calendar'), '4' => __('Deaf-Blind ASL', 'my-calendar'), '5' => __('Real-time Captioning', 'my-calendar'), '6' => __('Scripted Captioning', 'my-calendar'), '7' => __('Assisted Listening Devices', 'my-calendar'), '8' => __('Tactile/Touch Tour', 'my-calendar'), '9' => __('Braille Playbill', 'my-calendar'), '10' => __('Large Print Playbill', 'my-calendar'), '11' => __('Sensory Friendly', 'my-calendar'), '12' => __('Other', 'my-calendar')));
                $mc_input_options = get_option('mc_input_options');
                $mc_input_options['event_access'] = 'on';
                update_option('mc_input_options', $mc_input_options);
                mc_upgrade_db();
                mc_transition_db();
                break;
            case '2.2.10':
                delete_option('mc_show_print');
                delete_option('mc_show_ical');
                delete_option('mc_show_rss');
                break;
            case '2.2.8':
                delete_option('mc_draggable');
                break;
            case '2.2.6':
                delete_option('mc_caching_enabled');
                // remove caching support via options. Filter only.
                break;
            case '2.2.0':
                add_option('mc_inverse_color', 'true');
                break;
            case '2.1.0':
                $templates = get_option('mc_templates');
                global $rss_template;
                $templates['rss'] = $rss_template;
                update_option('mc_templates', $templates);
                break;
            case '2.0.4':
                update_option('mc_ical_utc', 'true');
                break;
            case '2.0.0':
                mc_migrate_db();
                update_option('mc_db_version', '2.0.0');
                $mc_input = get_option('mc_input_options');
                if (!isset($mc_input['event_specials'])) {
                    $mc_input['event_specials'] = 'on';
                    update_option('mc_input_options', $mc_input);
                }
                break;
            case '1.11.1':
                add_option('mc_event_link', 'true');
                break;
            case '1.11.0':
                add_option('mc_convert', 'true');
                add_option('mc_process_shortcodes', 'false');
                $add = get_option('mc_can_manage_events');
                // yes, this is correct.
                $manage = get_option('mc_event_edit_perms');
                $approve = get_option('mc_event_approve_perms');
                mc_add_roles($add, $manage, $approve);
                delete_option('mc_can_manage_events');
                delete_option('mc_event_edit_perms');
                delete_option('mc_event_approve_perms');
                break;
            case '1.10.7':
                update_option('mc_multisite_show', 0);
                break;
            case '1.10.0':
                update_option('mc_week_caption', "The week's events");
                break;
            case '1.9.1':
                update_option('mc_widget_defaults', $defaults);
                break;
            case '1.9.0':
                delete_option('mc_show_heading');
                add_option('mc_time_format', get_option('time_format'));
                add_option('mc_display_jump', get_option('display_jump'));
                add_option('mc_display_author', get_option('display_author'));
                if (get_option('can_manage_events') != '') {
                    add_option('mc_can_manage_events', get_option('can_manage_events'));
                } else {
                    add_option('mc_can_manage_events', 'manage_options');
                }
                add_option('mc_ajaxjs', get_option('my_calendar_ajaxjs'));
                add_option('mc_caljs', get_option('my_calendar_caljs'));
                add_option('mc_css_file', get_option('my_calendar_css_file'));
                add_option('mc_date_format', get_option('my_calendar_date_format'));
                add_option('mc_hide_icons', get_option('my_calendar_hide_icons'));
                add_option('mc_listjs', get_option('my_calendar_listjs'));
                add_option('mc_minijs', get_option('my_calendar_minijs'));
                add_option('mc_notime_text', get_option('my_calendar_notime_text'));
                add_option('mc_show_address', get_option('my_calendar_show_address'));
                add_option('mc_show_css', get_option('my_caledar_show_css'));
                add_option('mc_show_heading', get_option('my_calendar_show_heading'));
                add_option('mc_show_js', get_option('my_calendar_show_js'));
                add_option('mc_show_map', get_option('my_calendar_show_map'));
                add_option('mc_show_months', get_option('my_calendar_show_months'));
                add_option('mc_templates', get_option('my_calendar_templates'));
                add_option('mc_use_styles', get_option('my_calendar_use_styles'));
                add_option('mc_version', get_option('my_calendar_version'));
                add_option('mc_widget_defaults', get_option('my_calendar_widget_defaults'));
                add_option('mc_week_format', "M j, 'y");
                add_option('mc_calendar_javascript', get_option('calendar_javascript'));
                add_option('mc_list_javascript', get_option('list_javascript'));
                add_option('mc_mini_javascript', get_option('mini_javascript'));
                add_option('mc_ajax_javascript', get_option('ajax_javascript'));
                delete_option('ajax_javascript');
                delete_option('mini_javascript');
                delete_option('calendar_javascript');
                delete_option('list_javascript');
                delete_option('display_jump');
                delete_option('display_author');
                delete_option('can_manage_events');
                delete_option('my_calendar_week_format');
                delete_option('my_calendar_ajaxjs');
                delete_option('my_calendar_caljs');
                delete_option('my_calendar_css_file');
                delete_option('my_calendar_date_format');
                delete_option('my_calendar_hide_icons');
                delete_option('my_calendar_listjs');
                delete_option('my_calendar_minijs');
                delete_option('my_calendar_notime_text');
                delete_option('my_calendar_show_address');
                delete_option('my_calendar_show_css');
                delete_option('my_calendar_show_heading');
                delete_option('my_calendar_show_js');
                delete_option('my_calendar_show_map');
                delete_option('my_calendar_show_months');
                delete_option('my_calendar_templates');
                delete_option('my_calendar_use_styles');
                delete_option('my_calendar_version');
                delete_option('my_calendar_widget_defaults');
                add_option('mc_location_control', '');
                add_site_option('mc_multisite', '0');
                add_option('mc_templates', array('title' => '{title}', 'link' => '{title}', 'label' => '{title}', 'mini' => $mini_template, 'grid' => $grid_template, 'list' => $list_template, 'details' => $single_template));
                $mc_input = get_option('mc_input_options');
                $mc_input['event_image'] = 'on';
                update_option('mc_input_options', $mc_input);
                mc_upgrade_db();
                update_option('mc_db_version', '1.9.0');
            case '1.8.0':
                $mc_input = get_option('mc_input_options');
                add_option('mc_show_weekends', 'true');
                add_option('mc_uri', '');
                delete_option('my_calendar_stored_styles');
                break;
            default:
                break;
        }
    }
    /* 
    if the user has fully uninstalled the plugin but kept the database of events, this will restore default 
    settings and upgrade db if needed.
    */
    if (get_option('mc_uninstalled') == 'true') {
        mc_default_settings();
        update_option('mc_db_version', $mc_version);
        delete_option('mc_uninstalled');
    }
}
Пример #4
0
function edit_my_calendar_config()
{
    global $wpdb;
    $mcdb = $wpdb;
    check_my_calendar();
    if (!empty($_POST)) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        if (isset($_POST['remigrate'])) {
            echo "<div class='updated fade'><ol>";
            echo "<li>" . __('Dropping occurrences database table', 'my-calendar') . "</li>";
            mc_drop_table('my_calendar_event_table');
            sleep(1);
            echo "<li>" . __('Reinstalling occurrences database table.', 'my-calendar') . "</li>";
            mc_upgrade_db();
            sleep(1);
            echo "<li>" . __('Generating event occurrences.', 'my-calendar') . "</li>";
            mc_migrate_db();
            echo "<li>" . __('Event generation completed.', 'my-calendar') . "</li>";
            echo "</ol></div>";
        }
    }
    if (isset($_POST['mc_manage'])) {
        // management
        $clear = '';
        $mc_event_approve = !empty($_POST['mc_event_approve']) && $_POST['mc_event_approve'] == 'on' ? 'true' : 'false';
        $mc_api_enabled = !empty($_POST['mc_api_enabled']) && $_POST['mc_api_enabled'] == 'on' ? 'true' : 'false';
        $mc_remote = !empty($_POST['mc_remote']) && $_POST['mc_remote'] == 'on' ? 'true' : 'false';
        if (isset($_POST['mc_clear_cache']) && $_POST['mc_clear_cache'] == 'clear') {
            mc_delete_cache();
            $clear = __('My Calendar Cache cleared', 'my-calendar');
        }
        update_option('mc_event_approve', $mc_event_approve);
        update_option('mc_api_enabled', $mc_api_enabled);
        update_option('mc_remote', $mc_remote);
        update_option('mc_default_sort', $_POST['mc_default_sort']);
        if (get_site_option('mc_multisite') == 2) {
            $mc_current_table = (int) $_POST['mc_current_table'];
            update_option('mc_current_table', $mc_current_table);
        }
        echo "<div class='updated'><p><strong>" . __('My Calendar Management Settings saved', 'my-calendar') . ". {$clear}</strong></p></div>";
    }
    if (isset($_POST['mc_permissions'])) {
        $perms = $_POST['mc_caps'];
        $caps = array('mc_add_events' => __('Add Events', 'my-calendar'), 'mc_approve_events' => __('Approve Events', 'my-calendar'), 'mc_manage_events' => __('Manage Events', 'my-calendar'), 'mc_edit_cats' => __('Edit Categories', 'my-calendar'), 'mc_edit_locations' => __('Edit Locations', 'my-calendar'), 'mc_edit_styles' => __('Edit Styles', 'my-calendar'), 'mc_edit_behaviors' => __('Edit Behaviors', 'my-calendar'), 'mc_edit_templates' => __('Edit Templates', 'my-calendar'), 'mc_edit_settings' => __('Edit Settings', 'my-calendar'), 'mc_view_help' => __('View Help', 'my-calendar'));
        foreach ($perms as $key => $value) {
            $role = get_role($key);
            if (is_object($role)) {
                foreach ($caps as $k => $v) {
                    if (isset($value[$k])) {
                        $role->add_cap($k);
                    } else {
                        $role->remove_cap($k);
                    }
                }
            }
        }
        echo "<div class='updated'><p><strong>" . __('My Calendar Permissions Updated', 'my-calendar') . "</strong></p></div>";
    }
    // output
    if (isset($_POST['mc_show_months'])) {
        $mc_open_day_uri = !empty($_POST['mc_open_day_uri']) ? $_POST['mc_open_day_uri'] : '';
        update_option('mc_uri', $_POST['mc_uri']);
        update_option('mc_use_permalinks', !empty($_POST['mc_use_permalinks']) ? 'true' : 'false');
        update_option('mc_open_uri', !empty($_POST['mc_open_uri']) && $_POST['mc_open_uri'] == 'on' && get_option('mc_uri') != '' ? 'true' : 'false');
        update_option('mc_mini_uri', $_POST['mc_mini_uri']);
        update_option('mc_open_day_uri', $mc_open_day_uri);
        update_option('mc_skip_holidays', !empty($_POST['mc_skip_holidays']) && $_POST['mc_skip_holidays'] == 'on' ? 'true' : 'false');
        update_option('mc_display_author', !empty($_POST['mc_display_author']) && $_POST['mc_display_author'] == 'on' ? 'true' : 'false');
        update_option('mc_show_event_vcal', !empty($_POST['mc_show_event_vcal']) && $_POST['mc_show_event_vcal'] == 'on' ? 'true' : 'false');
        update_option('mc_show_gcal', !empty($_POST['mc_show_gcal']) && $_POST['mc_show_gcal'] == 'on' ? 'true' : 'false');
        update_option('mc_display_jump', !empty($_POST['mc_display_jump']) && $_POST['mc_display_jump'] == 'on' ? 'true' : 'false');
        update_option('mc_show_list_info', !empty($_POST['mc_show_list_info']) && $_POST['mc_show_list_info'] == 'on' ? 'true' : 'false');
        update_option('mc_show_months', (int) $_POST['mc_show_months']);
        // calculate sequence for navigation elements
        $top = $bottom = array();
        $nav = $_POST['mc_nav'];
        $set = 'top';
        foreach ($nav as $n) {
            if ($n == 'calendar') {
                $set = 'bottom';
            } else {
                if ($set == 'top') {
                    $top[] = $n;
                } else {
                    $bottom[] = $n;
                }
            }
            if ($n == 'stop') {
                break;
            }
        }
        update_option('mc_bottomnav', implode(',', $bottom));
        update_option('mc_topnav', implode(',', $top));
        update_option('mc_show_map', !empty($_POST['mc_show_map']) && $_POST['mc_show_map'] == 'on' ? 'true' : 'false');
        update_option('mc_gmap', !empty($_POST['mc_gmap']) && $_POST['mc_gmap'] == 'on' ? 'true' : 'false');
        update_option('mc_show_address', !empty($_POST['mc_show_address']) && $_POST['mc_show_address'] == 'on' ? 'true' : 'false');
        update_option('mc_hide_icons', !empty($_POST['mc_hide_icons']) && $_POST['mc_hide_icons'] == 'on' ? 'true' : 'false');
        update_option('mc_event_link_expires', !empty($_POST['mc_event_link_expires']) && $_POST['mc_event_link_expires'] == 'on' ? 'true' : 'false');
        update_option('mc_apply_color', $_POST['mc_apply_color']);
        update_option('mc_event_registration', !empty($_POST['mc_event_registration']) && $_POST['mc_event_registration'] == 'on' ? 'true' : 'false');
        update_option('mc_inverse_color', !empty($_POST['mc_inverse_color']) && $_POST['mc_inverse_color'] == 'on' ? 'true' : 'false');
        update_option('mc_short', !empty($_POST['mc_short']) && $_POST['mc_short'] == 'on' ? 'true' : 'false');
        update_option('mc_desc', !empty($_POST['mc_desc']) && $_POST['mc_desc'] == 'on' ? 'true' : 'false');
        update_option('mc_process_shortcodes', !empty($_POST['mc_process_shortcodes']) && $_POST['mc_process_shortcodes'] == 'on' ? 'true' : 'false');
        update_option('mc_details', !empty($_POST['mc_details']) && $_POST['mc_details'] == 'on' ? 'true' : 'false');
        update_option('mc_event_link', !empty($_POST['mc_event_link']) && $_POST['mc_event_link'] == 'on' ? 'true' : 'false');
        update_option('mc_show_weekends', !empty($_POST['mc_show_weekends']) && $_POST['mc_show_weekends'] == 'on' ? 'true' : 'false');
        update_option('mc_convert', !empty($_POST['mc_convert']) && $_POST['mc_convert'] == 'on' ? 'true' : 'false');
        update_option('mc_no_fifth_week', !empty($_POST['mc_no_fifth_week']) && $_POST['mc_no_fifth_week'] == 'on' ? 'true' : 'false');
        echo "<div class=\"updated\"><p><strong>" . __('Output Settings saved', 'my-calendar') . "</strong></p></div>";
    }
    // input
    if (isset($_POST['mc_dates'])) {
        update_option('mc_date_format', stripslashes($_POST['mc_date_format']));
        update_option('mc_week_format', stripslashes($_POST['mc_week_format']));
        update_option('mc_time_format', stripslashes($_POST['mc_time_format']));
        update_option('mc_month_format', stripslashes($_POST['mc_month_format']));
        $mc_ical_utc = !empty($_POST['mc_ical_utc']) && $_POST['mc_ical_utc'] == 'on' ? 'true' : 'false';
        update_option('mc_ical_utc', $mc_ical_utc);
        echo "<div class=\"updated\"><p><strong>" . __('Date/Time Format Settings saved', 'my-calendar') . "</strong></p></div>";
    }
    if (isset($_POST['mc_input'])) {
        $mc_input_options_administrators = !empty($_POST['mc_input_options_administrators']) && $_POST['mc_input_options_administrators'] == 'on' ? 'true' : 'false';
        $mc_input_options = array('event_short' => !empty($_POST['mci_event_short']) && $_POST['mci_event_short'] ? 'on' : '', 'event_desc' => !empty($_POST['mci_event_desc']) && $_POST['mci_event_desc'] ? 'on' : '', 'event_category' => !empty($_POST['mci_event_category']) && $_POST['mci_event_category'] ? 'on' : '', 'event_image' => !empty($_POST['mci_event_image']) && $_POST['mci_event_image'] ? 'on' : '', 'event_link' => !empty($_POST['mci_event_link']) && $_POST['mci_event_link'] ? 'on' : '', 'event_recurs' => !empty($_POST['mci_event_recurs']) && $_POST['mci_event_recurs'] ? 'on' : '', 'event_open' => !empty($_POST['mci_event_open']) && $_POST['mci_event_open'] ? 'on' : '', 'event_location' => !empty($_POST['mci_event_location']) && $_POST['mci_event_location'] ? 'on' : '', 'event_location_dropdown' => !empty($_POST['mci_event_location_dropdown']) && $_POST['mci_event_location_dropdown'] ? 'on' : '', 'event_specials' => !empty($_POST['mci_event_specials']) && $_POST['mci_event_specials'] ? 'on' : '', 'event_access' => !empty($_POST['mci_event_access']) && $_POST['mci_event_access'] ? 'on' : '');
        update_option('mc_input_options', $mc_input_options);
        update_option('mc_input_options_administrators', $mc_input_options_administrators);
        echo "<div class=\"updated\"><p><strong>" . __('Input Settings saved', 'my-calendar') . ".</strong></p></div>";
    }
    if (current_user_can('manage_network')) {
        if (isset($_POST['mc_network'])) {
            $mc_multisite = (int) $_POST['mc_multisite'];
            update_site_option('mc_multisite', $mc_multisite);
            $mc_multisite_show = (int) $_POST['mc_multisite_show'];
            update_site_option('mc_multisite_show', $mc_multisite_show);
            echo "<div class=\"updated\"><p><strong>" . __('Multisite settings saved', 'my-calendar') . ".</strong></p></div>";
        }
    }
    // custom text
    if (isset($_POST['mc_previous_events'])) {
        $mc_title_template = $_POST['mc_title_template'];
        $mc_details_label = $_POST['mc_details_label'];
        $mc_link_label = $_POST['mc_link_label'];
        $mc_event_title_template = $_POST['mc_event_title_template'];
        $mc_notime_text = $_POST['mc_notime_text'];
        $mc_previous_events = $_POST['mc_previous_events'];
        $mc_next_events = $_POST['mc_next_events'];
        $mc_event_open = $_POST['mc_event_open'];
        $mc_event_closed = $_POST['mc_event_closed'];
        $mc_week_caption = $_POST['mc_week_caption'];
        $mc_caption = $_POST['mc_caption'];
        $templates = get_option('mc_templates');
        $templates['title'] = $mc_title_template;
        $templates['label'] = $mc_details_label;
        $templates['link'] = $mc_link_label;
        update_option('mc_templates', $templates);
        update_option('mc_event_title_template', $mc_event_title_template);
        update_option('mc_notime_text', $mc_notime_text);
        update_option('mc_week_caption', $mc_week_caption);
        update_option('mc_next_events', $mc_next_events);
        update_option('mc_previous_events', $mc_previous_events);
        update_option('mc_caption', $mc_caption);
        update_option('mc_event_open', $mc_event_open);
        update_option('mc_event_closed', $mc_event_closed);
        echo "<div class=\"updated\"><p><strong>" . __('Custom text settings saved', 'my-calendar') . ".</strong></p></div>";
    }
    // Mail function by Roland
    if (isset($_POST['mc_email'])) {
        $mc_event_mail = !empty($_POST['mc_event_mail']) && $_POST['mc_event_mail'] == 'on' ? 'true' : 'false';
        $mc_html_email = !empty($_POST['mc_html_email']) && $_POST['mc_html_email'] == 'on' ? 'true' : 'false';
        $mc_event_mail_to = $_POST['mc_event_mail_to'];
        $mc_event_mail_from = $_POST['mc_event_mail_from'];
        $mc_event_mail_subject = $_POST['mc_event_mail_subject'];
        $mc_event_mail_message = $_POST['mc_event_mail_message'];
        update_option('mc_event_mail_to', $mc_event_mail_to);
        update_option('mc_event_mail_from', $mc_event_mail_from);
        update_option('mc_event_mail_subject', $mc_event_mail_subject);
        update_option('mc_event_mail_message', $mc_event_mail_message);
        update_option('mc_event_mail', $mc_event_mail);
        update_option('mc_html_email', $mc_html_email);
        echo "<div class=\"updated\"><p><strong>" . __('Email notice settings saved', 'my-calendar') . ".</strong></p></div>";
    }
    // Custom User Settings
    apply_filters('mc_save_settings', '', $_POST);
    // pull templates for passing into functions.
    $templates = get_option('mc_templates');
    $mc_title_template = esc_attr(stripslashes($templates['title']));
    $mc_details_label = esc_attr(stripslashes($templates['label']));
    $mc_link_label = esc_attr(stripslashes($templates['link']));
    ?>
 

<div class="wrap jd-my-calendar mc-settings-page" id="mc_settings">
<?php 
    my_calendar_check_db();
    ?>
    <div id="icon-options-general" class="icon32"><br /></div>
	<h2><?php 
    _e('My Calendar Options', 'my-calendar');
    ?>
</h2>
<div class="postbox-container jcd-wide">
<div class="metabox-holder">
  <?php 
    //update_option( 'ko_calendar_imported','false' ); // for testing importing.
    if (isset($_POST['import']) && $_POST['import'] == 'true') {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        my_calendar_import();
    }
    if (get_option('ko_calendar_imported') != 'true') {
        if (function_exists('check_calendar')) {
            ?>
	<div class='import upgrade-db'>
	<p>
	<?php 
            _e('My Calendar has identified that you have the Calendar plugin by Kieran O\'Shea installed. You can import those events and categories into the My Calendar database. Would you like to import these events?', 'my-calendar');
            ?>
	</p>
		<form method="post" action="<?php 
            echo admin_url("admin.php?page=my-calendar-config");
            ?>
">
		<div><input type="hidden" name="_wpnonce" value="<?php 
            echo wp_create_nonce('my-calendar-nonce');
            ?>
" /></div>		
		<div>
		<input type="hidden" name="import" value="true" />
		<input type="submit" value="<?php 
            _e('Import from Calendar', 'my-calendar');
            ?>
" name="import-calendar" class="button-primary" />
		</div>
		</form>
	</div>
<?php 
        }
    }
    ?>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox">
	<h3><?php 
    _e('My Calendar Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	<ul class="mc-settings checkboxes">
		<li><a href="#my-calendar-manage"><?php 
    _e('Management', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-text"><?php 
    _e('Customizable Text', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-output"><?php 
    _e('Output', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-time"><?php 
    _e('Date/Time', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-input"><?php 
    _e('Input', 'my-calendar');
    ?>
</a></li>
		<?php 
    if (current_user_can('manage_network')) {
        ?>
		<li><a href="#my-calendar-multisite"><?php 
        _e('Multi-site', 'my-calendar');
        ?>
</a></li>		
		<?php 
    }
    ?>
		<li><a href="#my-calendar-permissions"><?php 
    _e('Permissions', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-email"><?php 
    _e('Email Notifications', 'my-calendar');
    ?>
</a></li>
		<?php 
    echo apply_filters('mc_settings_section_links', '');
    ?>
	</ul>
	</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-manage">
	<h3><?php 
    _e('My Calendar Management', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	<?php 
    if (current_user_can('administrator')) {
        ?>
    <form method="post" action="<?php 
        echo admin_url("admin.php?page=my-calendar-config");
        ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
" /></div> 	
	<fieldset>
    <legend><?php 
        _e('Management', 'my-calendar');
        ?>
</legend>
    <ul>
	<li><?php 
        mc_settings_field('mc_remote', __('Get data (events, categories and locations) from a remote database.', 'my-calendar'), '', '', array(), 'checkbox-single');
        ?>
</li>
	<?php 
        if (get_option('mc_remote') == 'true') {
            ?>
	<li><?php 
            _e('Add this code to your theme\'s <code>functions.php</code> file:', 'my-calendar');
            ?>
<pre>function mc_remote_db() {
	$mcdb = new wpdb('DB_USER','DB_PASSWORD','DB_NAME','DB_ADDRESS');
	return $mcdb;
}</pre>
		<?php 
            _e('You will need to allow remote connections from this site to the site hosting your My Calendar events. Replace the above placeholders with the host-site information. The two sites must have the same WP table prefix. While this option is enabled, you may not enter or edit events through this installation.', 'my-calendar');
            ?>
	</li>	
	<?php 
        }
        ?>
	<li><?php 
        mc_settings_field('mc_event_approve', __('Enable approval options.', 'my-calendar'), '', '', array(), 'checkbox-single');
        ?>
</li>
	<li><?php 
        mc_settings_field('mc_api_enabled', __('Enable external API.', 'my-calendar'), '', '', array(), 'checkbox-single');
        ?>
</li>	
	<?php 
        if (apply_filters('mc_caching_clear', false)) {
            ?>
	<li><?php 
            mc_settings_field('mc_clear_cache', __('Clear current cache. (Necessary if you edit shortcodes to change displayed categories, for example.)', 'my-calendar'), '', '', array(), 'checkbox-single');
            ?>
</li>	
	<?php 
        }
        ?>
	<li><?php 
        mc_settings_field('mc_default_sort', __('Default Sort order for Admin Events List', 'my-calendar'), array('1' => __('Event ID', 'my-calendar'), '2' => __('Title', 'my-calendar'), '3' => __('Description', 'my-calendar'), '4' => __('Start Date', 'my-calendar'), '5' => __('Author', 'my-calendar'), '6' => __('Category', 'my-calendar'), '7' => __('Location Name', 'my-calendar')), '', array(), 'select');
        ?>
</li>
	<?php 
        if (get_site_option('mc_multisite') == 2 && MY_CALENDAR_TABLE != MY_CALENDAR_GLOBAL_TABLE) {
            mc_settings_field('mc_current_table', array('0' => __('Currently editing my local calendar', 'my-calendar'), '1' => __('Currently editing the network calendar', 'my-calendar')), '0', '', array(), 'radio');
        } else {
            if (get_option('mc_remote') != 'true' && current_user_can('manage_network')) {
                ?>
			<li><?php 
                _e('You are currently working in the primary site for this network; your local calendar is also the global table.', 'my-calendar');
                ?>
</li><?php 
            }
        }
        ?>
	<li><?php 
        mc_settings_field('remigrate', __('Re-generate event occurrences table.', 'my-calendar'), '', '', array(), 'checkbox-single');
        ?>
</li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="mc_manage" class="button-primary" value="<?php 
        _e('Save Management Settings', 'my-calendar');
        ?>
" />
		</p>
	</form>
	<?php 
    } else {
        ?>
		<?php 
        _e('My Calendar management settings are only available to administrators.', 'my-calendar');
        ?>
	<?php 
    }
    ?>
	</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-text">
	<h3><?php 
    _e('Text Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	    <form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>		
<fieldset>
	<legend><?php 
    _e('Customize Text Fields', 'my-calendar');
    ?>
</legend>
	<ul>
	<li><?php 
    mc_settings_field('mc_notime_text', __('Label for all-day events', 'my-calendar'), 'N/A');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_previous_events', __('Previous events link', 'my-calendar'), __('Previous', 'my-calendar'), __('Use <code>{date}</code> to display date in navigation.', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_next_events', __('Next events link', 'my-calendar'), __('Next', 'my-calendar'), __('Use <code>{date}</code> to display date in navigation.', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_open', __('If events are open', 'my-calendar'), __('Registration is open', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_closed', __('If events are closed', 'my-calendar'), __('Registration is closed', 'my-calendar'));
    ?>
</li>	
	<li><?php 
    mc_settings_field('mc_week_caption', __('Week view caption:', 'my-calendar'), '', __('Available tag: <code>{date format=""}</code>', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_caption', __('Extended caption:', 'my-calendar'), '', __('Follows month/year in list views.', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_title_template', __('Event title template', 'my-calendar'), $mc_title_template, "<a href='" . admin_url("admin.php?page=my-calendar-help#templates") . "'>" . __("Templating Help", 'my-calendar') . '</a>');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_details_label', __('Event details link text', 'my-calendar'), $mc_details_label, __('Tags: <code>{title}</code>, <code>{location}</code>, <code>{color}</code>, <code>{icon}</code>, <code>{date}</code>, <code>{time}</code>.', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_link_label', __('Event URL link text', 'my-calendar'), $mc_link_label, "<a href='" . admin_url("admin.php?page=my-calendar-help#templates") . "'>" . __("Templating Help", 'my-calendar') . '</a>');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_title_template', __('Title element template', 'my-calendar'), '{title} &raquo; {date}', __('Current: %s', 'my-calendar'));
    ?>
</li>		
	</ul>
	</fieldset>	
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Custom Text Settings', 'my-calendar');
    ?>
" />
	</p>
	</form>
</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-output">
	<h3><?php 
    _e('Output Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>
	<fieldset>
	<legend><?php 
    _e('Calendar Link Targets', 'my-calendar');
    ?>
</legend>
	<ul>
	<?php 
    /* <li><?php mc_settings_field( 'mc_use_permalinks', __( 'Use Pretty Permalinks for Events','my-calendar' ), '', '', array(), 'checkbox-single' ); ?></li> This just isn't ready; add in a point release. */
    ?>
	<?php 
    $guess = mc_guess_calendar();
    ?>
	<li><?php 
    mc_settings_field('mc_uri', __('Where is your main calendar page?', 'my-calendar'), '', "<br /><small>" . __('Can be any Page or Post which includes the <code>[my_calendar]</code> shortcode.', 'my-calendar') . " {$guess}</small>", array('size' => '60'), 'url');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_mini_uri', __('Target <abbr title="Uniform resource locator">URL</abbr> for mini calendar date links:', 'my-calendar'), '', "<br /><small>" . __('Can be any Page or Post which includes the <code>[my_calendar]</code> shortcode.', 'my-calendar') . "</small>", array('size' => '60'), 'url');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_open_uri', __('Open calendar links to event details URL', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	<?php 
    $disabled = !get_option('mc_uri') && !get_option('mc_mini_uri') ? array('disabled' => 'disabled') : array();
    ?>
	<li><?php 
    mc_settings_field('mc_open_day_uri', __('Mini calendar widget date links to:', 'my-calendar'), array('false' => __('jQuery pop-up view', 'my-calendar'), 'true' => __('daily view page (above)', 'my-calendar'), 'listanchor' => __('in-page anchor on main calendar page (list)', 'my-calendar'), 'calendaranchor' => __('in-page anchor on main calendar page (grid)', 'my-calendar')), '', $disabled, 'select');
    ?>
</li>
	</ul>
	<?php 
    // End General Options //
    ?>
	</fieldset>
	
	<fieldset> 
	<legend><?php 
    _e('Set Default Navigation Element Order (can be overridden in shortcodes)', 'my-calendar');
    ?>
</legend>
	<?php 
    $topnav = explode(',', get_option('mc_topnav'));
    $calendar = array('calendar');
    $botnav = explode(',', get_option('mc_bottomnav'));
    $order = array_merge($topnav, $calendar, $botnav);
    $nav_elements = array('nav' => '<div class="dashicons dashicons-arrow-left-alt2"></div> <div class="dashicons dashicons-arrow-right-alt2"></div> ' . __('Primary Previous/Next Buttons', 'my-calendar'), 'toggle' => '<div class="dashicons dashicons-list-view"></div> <div class="dashicons dashicons-calendar"></div> ' . __('Switch between list and grid views', 'my-calendar'), 'jump' => '<div class="dashicons dashicons-redo"></div> ' . __('Jump to any other month/year', 'my-calendar'), 'print' => '<div class="dashicons dashicons-list-view"></div> ' . __('Link to printable view', 'my-calendar'), 'timeframe' => '<div class="dashicons dashicons-clock"></div> ' . __('Toggle between day, week, and month view', 'my-calendar'), 'calendar' => '<div class="dashicons dashicons-calendar"></div> ' . __('The calendar', 'my-calendar'), 'key' => '<div class="dashicons dashicons-admin-network"></div> ' . __('Categories', 'my-calendar'), 'feeds' => '<div class="dashicons dashicons-rss"></div> ' . __('Links to RSS and iCal output', 'my-calendar'), 'stop' => '<div class="dashicons dashicons-no"></div> ' . __('Elements below here will be hidden.'));
    echo "<div id='mc-sortable-update' aria-live='polite'></div>";
    echo "<ul id='mc-sortable'>";
    foreach ($order as $k) {
        $k = trim($k);
        $v = isset($nav_elements[$k]) ? $nav_elements[$k] : false;
        if ($v !== false) {
            $inserted[$k] = $v;
            echo "<li class='ui-state-default mc-{$k}'><button class='up'><i class='dashicons dashicons-arrow-up'></i><span class='screen-reader-text'>Up</span></button> <button class='down'><i class='dashicons dashicons-arrow-down'></i><span class='screen-reader-text'>Down</span></button> <code>{$k}</code> {$v} <input type='hidden' name='mc_nav[]' value='{$k}' /></li>";
        }
    }
    $missed = array_diff($nav_elements, $inserted);
    foreach ($missed as $k => $v) {
        echo "<li class='ui-state-default mc-{$k}'><button class='up'><i class='dashicons dashicons-arrow-up'></i><span class='screen-reader-text'>Up</span></button> <button class='down'><i class='dashicons dashicons-arrow-down'></i><span class='screen-reader-text'>Down</span></button> <code>{$k}</code> {$v} <input type='hidden' name='mc_nav[]' value='{$k}' /></li>";
    }
    echo "</ul>";
    ?>
	</fieldset>	
	
	<fieldset>
	<legend><?php 
    _e('Grid Layout Options', 'my-calendar');
    ?>
</legend>
	<ul>
	<li><?php 
    mc_settings_field('mc_show_weekends', __('Show Weekends on Calendar', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_convert', __('Switch to list view on mobile devices', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>	
	</ul>	
	<?php 
    // End Grid Options //
    ?>
	</fieldset>	
	
	<fieldset>
	<legend><?php 
    _e('List Layout Options', 'my-calendar');
    ?>
</legend>
	<ul>
	<li><?php 
    mc_settings_field('mc_show_months', __('How many months of events to show at a time:', 'my-calendar'), '', '', array('size' => '3'), 'text');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_show_list_info', __('Show the first event\'s title and the number of events that day next to the date.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>	
	</ul>	
	<?php 
    // End List Options //
    ?>
	</fieldset>	

	<fieldset>
	<legend><?php 
    _e('Event Details Pop-up', 'my-calendar');
    ?>
</legend>
		<p><?php 
    _e('The checked items will be shown in your event details view. Does not apply if you are using a custom template', 'my-calendar');
    ?>
		<ul class="checkboxes">
			<li><?php 
    mc_settings_field('mc_display_author', __('Author\'s name', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_show_event_vcal', __('Link to single event iCal download', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_show_gcal', __('Link to submit event to Google Calendar', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>		
			<li><?php 
    mc_settings_field('mc_hide_icons', __('Hide Category icons', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_show_map', __('Link to Google Map', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_gmap', __('Google Map (single event view only)', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>			
			<li><?php 
    mc_settings_field('mc_show_address', __('Event Address', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_short', __('Short description', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_desc', __('Full description', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_process_shortcodes', __('Process WordPress shortcodes in descriptions', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>	
			<li><?php 
    mc_settings_field('mc_details', __('Link to event details (requires <a href=\'#mc_uri\'>URL</a>)', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_event_link', __('External link', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_event_registration', __('Registration info', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
		</ul>
	</fieldset>
	<fieldset>
	<legend><?php 
    _e('Event Category Display', 'my-calendar');
    ?>
</legend>
		<ul class='checkboxes'>
			<?php 
    mc_settings_field('mc_apply_color', array('default' => __('No category colors with titles.', 'my-calendar'), 'font' => __('Titles are in category colors.', 'my-calendar'), 'background' => __('Titles have category color as background.', 'my-calendar')), 'default', '', array(), 'radio');
    ?>
			<li><?php 
    mc_settings_field('mc_inverse_color', __('Optimize contrast for category colors.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
		</ul>	
	<?php 
    // End Event Options //
    ?>
	</fieldset>
	<fieldset>
	<legend><?php 
    _e('Event Scheduling Defaults', 'my-calendar');
    ?>
</legend>
		<ul>
			<li><?php 
    mc_settings_field('mc_event_link_expires', __('Event links expire after event passes.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>	
			<li><?php 
    mc_settings_field('mc_no_fifth_week', __('If a recurring event falls on a date that doesn\'t exist (like the 5th Wednesday in February), move it back one week.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_skip_holidays', __('If an event coincides with an event in the designated "Holiday" category, do not show the event.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
		</ul>	
	<?php 
    // End Scheduling Options //
    ?>
	</fieldset>
	<p><input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Output Settings', 'my-calendar');
    ?>
" /></p>
</form>
</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">
<div class="postbox" id="my-calendar-time">
	<h3><?php 
    _e('Calendar Time Formats', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>
	<fieldset>
	<legend><?php 
    _e('Set default date/time formats', 'my-calendar');
    ?>
</legend>
	<div><input type='hidden' name='mc_dates' value='true' /></div>
	<ul>	
	<?php 
    $month_format = get_option('mc_month_format') == '' ? date_i18n('F Y') : date_i18n(get_option('mc_month_format'));
    $time_format = get_option('mc_time_format') == '' ? date_i18n(get_option('time_format')) : date_i18n(get_option('mc_time_format'));
    $week_format = get_option('mc_week_format') == '' ? date_i18n('M j, \'y') : date_i18n(get_option('mc_week_format'));
    $date_format = get_option('mc_date_format') == '' ? date_i18n(get_option('date_format')) : date_i18n(get_option('mc_date_format'));
    ?>
	<li><?php 
    mc_settings_field('mc_month_format', __('Month format (calendar headings)', 'my-calendar'), '', $month_format);
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_time_format', __('Time format', 'my-calendar'), '', $time_format);
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_week_format', __('Date in grid mode, week view', 'my-calendar'), '', $week_format);
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_date_format', __('Date Format in other views', 'my-calendar'), '', $date_format);
    ?>
</li>
	<li>
	<?php 
    _e('Date formats use syntax from the <a href="http://php.net/date">PHP <code>date()</code> function</a>. Save to update sample output.', 'my-calendar');
    ?>
	</li>
	<li><?php 
    mc_settings_field('mc_ical_utc', __('iCal times are UTC', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Date/Time Settings', 'my-calendar');
    ?>
" />
		</p>
	</form>	
	</div>
</div>
</div>


<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-input">
	<h3><?php 
    _e('Calendar Input Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>
	<fieldset>
	<legend><?php 
    _e('Select which input fields will be available when adding or editing events.', 'my-calendar');
    ?>
</legend>
	<div><input type='hidden' name='mc_input' value='true' /></div>
	<ul class="checkboxes">
	<?php 
    $input_options = get_option('mc_input_options');
    $input_labels = array('event_location_dropdown' => __('Event Location Dropdown Menu', 'my-calendar'), 'event_short' => __('Event Short Description field', 'my-calendar'), 'event_desc' => __('Event Description Field', 'my-calendar'), 'event_category' => __('Event Category field', 'my-calendar'), 'event_image' => __('Event Image field', 'my-calendar'), 'event_link' => __('Event Link field', 'my-calendar'), 'event_recurs' => __('Event Recurrence Options', 'my-calendar'), 'event_open' => __('Event Registration options', 'my-calendar'), 'event_location' => __('Event Location fields', 'my-calendar'), 'event_specials' => __('Set Special Scheduling options', 'my-calendar'), 'event_access' => __("Event Accessibility", 'my-calendar'));
    $output = '';
    // if input options isn't an array, we'll assume that this plugin wasn't upgraded properly, and reset them to the default.
    if (!is_array($input_options)) {
        update_option('mc_input_options', array('event_short' => 'on', 'event_desc' => 'on', 'event_category' => 'on', 'event_image' => 'on', 'event_link' => 'on', 'event_recurs' => 'on', 'event_open' => 'on', 'event_location' => 'on', 'event_location_dropdown' => 'on', 'event_specials' => 'on', 'event_access' => 'on'));
    }
    foreach ($input_options as $key => $value) {
        $checked = $value == 'on' ? "checked='checked'" : '';
        if (isset($input_labels[$key])) {
            $output .= "<li><input type=\"checkbox\" id=\"mci_{$key}\" name=\"mci_{$key}\" {$checked} /> <label for=\"mci_{$key}\">{$input_labels[$key]}</label></li>";
        }
    }
    echo $output;
    ?>
	<li><?php 
    mc_settings_field('mc_input_options_administrators', __('Administrators see all input options', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Input Settings', 'my-calendar');
    ?>
" />
		</p>
</form>
</div>
</div>
</div>

<?php 
    if (current_user_can('manage_network')) {
        ?>
<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-multisite">
	<h3><?php 
        _e('Multisite Settings (Network Administrators only)', 'my-calendar');
        ?>
</h3>
	<div class="inside">
	<form method="post" action="<?php 
        echo admin_url("admin.php?page=my-calendar-config");
        ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
" /></div>	
	<div><input type='hidden' name='mc_network' value='true' /></div>	
	<fieldset>
	<legend><?php 
        _e('WP MultiSite configurations', 'my-calendar');
        ?>
</legend>
	<p><?php 
        _e('The central calendar is the calendar associated with the primary site in your WordPress Multisite network.', 'my-calendar');
        ?>
</p>	
	<ul>
	<li><input type="radio" value="0" id="ms0" name="mc_multisite"<?php 
        echo jd_option_selected(get_site_option('mc_multisite'), '0');
        ?>
 /> <label for="ms0"><?php 
        _e('Site owners may only post to their local calendar', 'my-calendar');
        ?>
</label></li>
	<li><input type="radio" value="1" id="ms1" name="mc_multisite"<?php 
        echo jd_option_selected(get_site_option('mc_multisite'), '1');
        ?>
 /> <label for="ms1"><?php 
        _e('Site owners may only post to the central calendar', 'my-calendar');
        ?>
</label></li>
	<li><input type="radio" value="2" id="ms2" name="mc_multisite"<?php 
        echo jd_option_selected(get_site_option('mc_multisite'), 2);
        ?>
 /> <label for="ms2"><?php 
        _e('Site owners may manage either calendar', 'my-calendar');
        ?>
</label></li>
	</ul>
	<p class="notice"><strong>*</strong> <?php 
        _e('Changes only effect input permissions. Public-facing calendars will be unchanged.', 'my-calendar');
        ?>
</p>
	<ul>
	<li><input type="radio" value="0" id="mss0" name="mc_multisite_show"<?php 
        echo jd_option_selected(get_site_option('mc_multisite_show'), '0');
        ?>
 /> <label for="mss0"><?php 
        _e('Sub-site calendars show events from their local calendar.', 'my-calendar');
        ?>
</label></li>
	<li><input type="radio" value="1" id="mss1" name="mc_multisite_show"<?php 
        echo jd_option_selected(get_site_option('mc_multisite_show'), '1');
        ?>
 /> <label for="mss1"><?php 
        _e('Sub-site calendars show events from the central calendar.', 'my-calendar');
        ?>
</label></li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
        _e('Save Multisite Settings', 'my-calendar');
        ?>
" />
		</p>
</form>	
	</div>
</div>
</div>
<?php 
    }
    ?>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-permissions">
	<h3><?php 
    _e('My Calendar Permissions', 'my-calendar');
    ?>
</h3>
	<div class="inside mc-tabs">	
	<?php 
    if (current_user_can('administrator')) {
        ?>

    <form method="post" action="<?php 
        echo admin_url("admin.php?page=my-calendar-config");
        ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
" /></div> 	
	<?php 
        function mc_check_caps($role, $cap)
        {
            $role = get_role($role);
            if ($role->has_cap($cap)) {
                return " checked='checked'";
            }
        }
        function mc_cap_checkbox($role, $cap, $name)
        {
            return "<li><input type='checkbox' id='mc_caps_{$role}_{$cap}' name='mc_caps[{$role}][{$cap}]' value='on'" . mc_check_caps($role, $cap) . " /> <label for='mc_caps_{$role}_{$cap}'>{$name}</label></li>";
        }
        global $wp_roles;
        $roles = $wp_roles->get_names();
        $caps = array('mc_add_events' => __('Add Events', 'my-calendar'), 'mc_approve_events' => __('Approve Events', 'my-calendar'), 'mc_manage_events' => __('Manage Events', 'my-calendar'), 'mc_edit_cats' => __('Edit Categories', 'my-calendar'), 'mc_edit_locations' => __('Edit Locations', 'my-calendar'), 'mc_edit_styles' => __('Edit Styles', 'my-calendar'), 'mc_edit_behaviors' => __('Edit Behaviors', 'my-calendar'), 'mc_edit_templates' => __('Edit Templates', 'my-calendar'), 'mc_edit_settings' => __('Edit Settings', 'my-calendar'), 'mc_view_help' => __('View Help', 'my-calendar'));
        $role_tabs = $role_container = '';
        foreach ($roles as $role => $rolename) {
            if ($role == 'administrator') {
                continue;
            }
            $role_tabs .= "<li><a href='#mc_{$role}'>{$rolename}</a></li>\n";
            $role_container .= "<div class='wptab mc_{$role}' id='mc_{$role}' aria-live='polite'><fieldset id='mc_{$role}' class='roles'><legend>{$rolename}</legend>";
            $role_container .= "<input type='hidden' value='none' name='mc_caps[" . $role . "][none]' />\n\t\t\t<ul class='mc-settings checkboxes'>";
            foreach ($caps as $cap => $name) {
                $role_container .= mc_cap_checkbox($role, $cap, $name);
            }
            $role_container .= "\n\t\t\t</ul></fieldset></div>\n";
        }
        echo "\n\t\t<ul class='tabs'>\n\t\t\t{$role_tabs}\n\t\t</ul>\n\t\t{$role_container}";
        ?>
	
		<p>
		<input type="submit" name="mc_permissions" class="button-primary" value="<?php 
        _e('Save Permissions', 'my-calendar');
        ?>
" />
		</p>
	</form>
	<?php 
    } else {
        ?>
		<?php 
        _e('My Calendar permission settings are only available to administrators.', 'my-calendar');
        ?>
	<?php 
    }
    ?>
	
	</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-email">
	<h3><?php 
    _e('Calendar Email Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>
	<fieldset>
	<legend><?php 
    _e('Email Notifications', 'my-calendar');
    ?>
</legend>
	<div><input type='hidden' name='mc_email' value='true' /></div>
	<ul>
	<li><?php 
    mc_settings_field('mc_event_mail', __('Send Email Notifications when new events are scheduled or reserved.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_mail_to', __('Notification messages are sent to:', 'my-calendar'), get_bloginfo('admin_email'));
    ?>
</li>	
	<li><?php 
    mc_settings_field('mc_event_mail_from', __('Notification messages are sent from:', 'my-calendar'), get_bloginfo('admin_email'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_mail_subject', __('Email subject', 'my-calendar'), get_bloginfo('name') . ': ' . __('New event added', 'my-calendar'), '', array('size' => 60));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_mail_message', __('Message Body', 'my-calendar'), __('New Event:', 'my-calendar') . "\n{title}: {date}, {time} - {event_status}", "<br /><a href='" . admin_url("admin.php?page=my-calendar-help#templates") . "'>" . __("Templating Help", 'my-calendar') . '</a>', array('cols' => 60, 'rows' => 6), 'textarea');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_html_email', __('Send HTML email', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Email Settings', 'my-calendar');
    ?>
" />
		</p>
</form>
</div>
</div>
</div>

<?php 
    echo apply_filters('mc_after_settings', '');
    ?>

</div>
</div>

	<?php 
    mc_show_sidebar();
    ?>

</div>
<?php 
}
function mc_delete_event($event_id)
{
    global $wpdb;
    $mcdb = $wpdb;
    // Deal with deleting an event from the database
    if (empty($event_id)) {
        $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __("You can't delete an event if you haven't submitted an event id", 'my-calendar') . "</p></div>";
    } else {
        $post_id = mc_get_data('event_post', $event_id);
        if (empty($_POST['event_instance'])) {
            $sql = "DELETE FROM " . my_calendar_table() . " WHERE event_id='" . (int) $event_id . "'";
            $delete_occurrences = "DELETE FROM " . my_calendar_event_table() . " WHERE occur_event_id = " . (int) $event_id;
            $mcdb->query($delete_occurrences);
            $mcdb->query($sql);
            $sql = "SELECT event_id FROM " . my_calendar_table() . " WHERE event_id='" . (int) $event_id . "'";
            $result = $mcdb->get_results($sql);
        } else {
            $delete = "DELETE FROM " . my_calendar_event_table() . " WHERE occur_id = " . (int) $_POST['event_instance'];
            $result = $mcdb->get_results($delete);
        }
        if (empty($result) || empty($result[0]->event_id)) {
            mc_delete_cache();
            // do an action using the event_id
            do_action('mc_delete_event', $event_id, $post_id);
            $message = "<div class='updated'><p>" . __('Event deleted successfully', 'my-calendar') . "</p></div>";
        } else {
            $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Despite issuing a request to delete, the event still remains in the database. Please investigate.', 'my-calendar') . "</p></div>";
        }
    }
    return $message;
}
Пример #6
0
function check_my_calendar()
{
    global $wpdb, $mc_version;
    $mcdb = $wpdb;
    mc_if_needs_permissions();
    $current_version = get_option('mc_version') == '' ? get_option('my_calendar_version') : get_option('mc_version');
    if (version_compare($current_version, '2.3.12', '>=')) {
        // if current is a version higher than 2.3.11, they've already seen this notice and handled it.
        update_option('mc_update_notice', 1);
    }
    // If current version matches, don't bother running this.
    if ($current_version == $mc_version) {
        return true;
    }
    // Assume this is not a new install until we prove otherwise
    $new_install = false;
    $upgrade_path = array();
    if (my_calendar_exists() && $current_version == '') {
        // If the table exists, but I don't know what version it is, I have to run the full cycle of upgrades.
        $current_version = '1.10.7';
    }
    if (!my_calendar_exists()) {
        $new_install = true;
    } else {
        // for each release requiring an upgrade path, add a version compare.
        // Loop will run every relevant upgrade cycle.
        $valid_upgrades = array('1.11.0', '1.11.1', '2.0.0', '2.0.4', '2.1.0', '2.2.0', '2.2.6', '2.2.10', '2.3.0', '2.3.11', '2.3.15', '2.4.4');
        foreach ($valid_upgrades as $upgrade) {
            if (version_compare($current_version, $upgrade, "<")) {
                $upgrade_path[] = $upgrade;
            }
        }
    }
    // having determined upgrade path, assign new version number
    update_option('mc_version', $mc_version);
    // Now we've determined what the current install is or isn't
    if ($new_install == true) {
        //add default settings
        mc_default_settings();
        $sql = "INSERT INTO " . MY_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_color='#ffffcc', category_icon='event.png'";
        $mcdb->query($sql);
    } else {
        // clear cache so updates are immediately available
        mc_delete_cache();
    }
    mc_do_upgrades($upgrade_path);
    /*
    if the user has fully uninstalled the plugin but kept the database of events, this will restore default 
    settings and upgrade db if needed.
    */
    if (get_option('mc_uninstalled') == 'true') {
        mc_default_settings();
        update_option('mc_db_version', $mc_version);
        delete_option('mc_uninstalled');
    }
}
function my_calendar_manage_categories()
{
    global $wpdb;
    $mcdb = $wpdb;
    $formats = array('%s', '%s', '%s');
    ?>
	<div class="wrap jd-my-calendar">
		<?php 
    my_calendar_check_db();
    // We do some checking to see what we're doing
    if (!empty($_POST)) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
    }
    if (isset($_POST['mode']) && $_POST['mode'] == 'add') {
        $term = wp_insert_term($_POST['category_name'], 'mc-event-category');
        if (!is_wp_error($term)) {
            $term = $term['term_id'];
        } else {
            $term = false;
        }
        $add = array('category_name' => $_POST['category_name'], 'category_color' => $_POST['category_color'], 'category_icon' => $_POST['category_icon'], 'category_private' => isset($_POST['category_private']) ? 1 : 0, 'category_term' => $term);
        // actions and filters
        $add = apply_filters('mc_pre_add_category', $add, $_POST);
        $results = $mcdb->insert(my_calendar_categories_table(), $add, $formats);
        do_action('mc_post_add_category', $add, $results, $_POST);
        $cat_ID = $mcdb->insert_id;
        if (isset($_POST['mc_default_category'])) {
            update_option('mc_default_category', $cat_ID);
            $append = __('Default category changed.', 'my-calendar');
        } else {
            $append = '';
        }
        if (isset($_POST['mc_skip_holidays_category'])) {
            update_option('mc_skip_holidays_category', $cat_ID);
            $append .= __('Holiday category changed.', 'my-calendar');
        }
        if ($results) {
            echo "<div class=\"updated\"><p><strong>" . __('Category added successfully', 'my-calendar') . ". {$append}</strong></p></div>";
        } else {
            echo "<div class=\"updated error\"><p><strong>" . __('Category addition failed.', 'my-calendar') . "</strong></p></div>";
        }
    } else {
        if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'delete') {
            $cat_ID = (int) $_GET['category_id'];
            $sql = "DELETE FROM " . my_calendar_categories_table() . " WHERE category_id={$cat_ID}";
            $results = $mcdb->query($sql);
            if ($results) {
                $sql = "UPDATE " . my_calendar_table() . " SET event_category=1 WHERE event_category={$cat_ID}";
                $cal_results = $mcdb->query($sql);
                mc_delete_cache();
            } else {
                $cal_results = false;
            }
            if (get_option('mc_default_category') == $cat_ID) {
                update_option('mc_default_category', 1);
            }
            if ($results && $cal_results) {
                echo "<div class=\"updated\"><p><strong>" . __('Category deleted successfully. Categories in calendar updated.', 'my-calendar') . "</strong></p></div>";
            } else {
                if ($results && !$cal_results) {
                    echo "<div class=\"updated\"><p><strong>" . __('Category deleted successfully. Categories in calendar not updated.', 'my-calendar') . "</strong></p></div>";
                } else {
                    if (!$results && $cal_results) {
                        echo "<div class=\"updated error\"><p><strong>" . __('Category not deleted. Categories in calendar updated.', 'my-calendar') . "</strong></p></div>";
                    }
                }
            }
        } else {
            if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'edit' && !isset($_POST['mode'])) {
                $cur_cat = (int) $_GET['category_id'];
                mc_edit_category_form('edit', $cur_cat);
            } else {
                if (isset($_POST['mode']) && isset($_POST['category_id']) && isset($_POST['category_name']) && isset($_POST['category_color']) && $_POST['mode'] == 'edit') {
                    $update = array('category_name' => $_POST['category_name'], 'category_color' => $_POST['category_color'], 'category_icon' => $_POST['category_icon'], 'category_private' => isset($_POST['category_private']) ? 1 : 0);
                    $where = array('category_id' => (int) $_POST['category_id']);
                    $append = '';
                    if (isset($_POST['mc_default_category'])) {
                        update_option('mc_default_category', (int) $_POST['category_id']);
                        $append .= __('Default category changed.', 'my-calendar');
                    } else {
                        if (get_option('mc_default_category') == (int) $_POST['category_id']) {
                            delete_option('mc_default_category');
                        }
                    }
                    if (isset($_POST['mc_skip_holidays_category'])) {
                        update_option('mc_skip_holidays_category', (int) $_POST['category_id']);
                        $append .= __('Holiday category changed.', 'my-calendar');
                    } else {
                        if (get_option('mc_skip_holidays_category') == (int) $_POST['category_id']) {
                            delete_option('mc_skip_holidays_category');
                        }
                    }
                    $results = $mcdb->update(my_calendar_categories_table(), $update, $where, $formats, '%d');
                    mc_delete_cache();
                    if ($results) {
                        echo "<div class=\"updated\"><p><strong>" . __('Category edited successfully.', 'my-calendar') . " {$append}</strong></p></div>";
                    } else {
                        echo "<div class=\"updated error\"><p><strong>" . __('Category was not edited.', 'my-calendar') . " {$append}</strong></p></div>";
                    }
                    $cur_cat = (int) $_POST['category_id'];
                    mc_edit_category_form('edit', $cur_cat);
                }
            }
        }
    }
    if (isset($_GET['mode']) && $_GET['mode'] != 'edit' || isset($_POST['mode']) && $_POST['mode'] != 'edit' || !isset($_GET['mode']) && !isset($_POST['mode'])) {
        mc_edit_category_form('add');
    }
    ?>
</div>
<?php 
}
function my_calendar_save($action, $output, $event_id = false)
{
    global $wpdb, $event_author;
    $mcdb = $wpdb;
    $proceed = $output[0];
    $message = '';
    $formats = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%f', '%f');
    if (($action == 'add' || $action == 'copy') && $proceed == true) {
        $add = $output[2];
        // add format here
        $add = apply_filters('mc_before_save_insert', $add);
        $result = $mcdb->insert(my_calendar_table(), $add, $formats);
        $event_id = $mcdb->insert_id;
        mc_increment_event($event_id);
        if (!$result) {
            $message = "<div class='error notice'><p><strong>" . __('Error', 'my-calendar') . ":</strong> " . __('I\'m sorry! I couldn\'t add that event to the database.', 'my-calendar') . "</p></div>";
        } else {
            // do an action using the $action and processed event data
            $data = $add;
            do_action('mc_save_event', $action, $data, $event_id, $result);
            // Call mail function
            if (get_option('mc_event_mail') == 'true') {
                $event = mc_get_first_event($event_id);
                // insert_id is last occurrence inserted in the db
                my_calendar_send_email($event);
            }
            if ($add['event_approved'] == 0) {
                $message = "<div class='updated notice'><p>" . __('Event saved. An administrator will review and approve your event.', 'my-calendar') . "</p></div>";
            } else {
                if (function_exists('jd_doTwitterAPIPost') && isset($_POST['mc_twitter']) && trim($_POST['mc_twitter']) != '') {
                    jd_doTwitterAPIPost(stripslashes($_POST['mc_twitter']));
                }
                if (get_option('mc_uri') != '') {
                    $event_ids = mc_get_occurrences($event_id);
                    $event_link = mc_build_url(array('mc_id' => $event_ids[0]->occur_id), array('page'), get_option('mc_uri'));
                } else {
                    $event_link = false;
                }
                $message = "<div class='updated notice'><p>" . __('Event added. It will now show on the calendar.', 'my-calendar');
                if ($event_link !== false) {
                    $message .= sprintf(__(' <a href="%s">View Event</a>', 'my-calendar'), $event_link);
                }
                $message .= "</p></div>";
            }
            mc_delete_cache();
        }
    }
    if ($action == 'edit' && $proceed == true) {
        $result = true;
        $url = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? '' . sprintf(__('View <a href="%s">your calendar</a>.', 'my-calendar'), get_option('mc_uri')) : '';
        $event_author = (int) $_POST['event_author'];
        if (mc_can_edit_event($event_author)) {
            $update = $output[2];
            $update = apply_filters('mc_before_save_update', $update, $event_id);
            $date_changed = $update['event_begin'] != $_POST['prev_event_begin'] || date("H:i:00", strtotime($update['event_time'])) != $_POST['prev_event_time'] || $update['event_end'] != $_POST['prev_event_end'] || date("H:i:00", strtotime($update['event_endtime'])) != $_POST['prev_event_endtime'] && ($_POST['prev_event_endtime'] != '' && date("H:i:00", strtotime($update['event_endtime'])) != '00:00:00') ? true : false;
            if (isset($_POST['event_instance'])) {
                $is_changed = mc_compare($update, $event_id);
                // compares the information sent to the information saved for a given event.
                $event_instance = (int) $_POST['event_instance'];
                if ($is_changed) {
                    // if changed, create new event, match group id, update instance to reflect event connection, same group id.
                    // if group ID == 0, need to add group ID to both records.
                    if ($update['event_group_id'] == 0) {
                        $update['event_group_id'] = $event_id;
                        mc_update_data($event_id, 'event_group_id', $event_id);
                    }
                    $mcdb->insert(my_calendar_table(), $update, $formats);
                    $new_event = $mcdb->insert_id;
                    // need to get this variable into URL for form submit
                    $result = mc_update_instance($event_instance, $new_event, $update);
                    mc_delete_cache();
                } else {
                    if ($update['event_begin'][0] == $_POST['prev_event_begin'] && $update['event_end'][0] == $_POST['prev_event_end']) {
                        // There were no changes at all.
                    } else {
                        $result = mc_update_instance($event_instance, $event_id, $update);
                        // Only dates were changed
                        $message = "<div class='updated notice'><p>" . __('Date/time information for this event has been updated.', 'my-calendar') . "{$url}</p></div>";
                        mc_delete_cache();
                    }
                }
            } else {
                $result = $mcdb->update(my_calendar_table(), $update, array('event_id' => $event_id), $formats, '%d');
                $recur_changed = $update['event_repeats'] != $_POST['prev_event_repeats'] || $update['event_recur'] != $_POST['prev_event_recur'] ? true : false;
                if ($date_changed || $recur_changed) {
                    mc_delete_instances($event_id);
                    mc_increment_event($event_id);
                    mc_delete_cache();
                }
            }
            $data = $update;
            do_action('mc_save_event', $action, $data, $event_id, $result);
            if ($result === false) {
                $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Your event was not updated.', 'my-calendar') . "{$url}</p></div>";
            } else {
                // do an action using the $action and processed event data
                do_action('mc_transition_event', (int) $_POST['prev_event_status'], (int) $_POST['event_approved']);
                $message = "<div class='updated'><p>" . __('Event updated successfully', 'my-calendar') . ".{$url}</p></div>";
                mc_delete_cache();
            }
        } else {
            $message = "<div class='error'><p><strong>" . __('You do not have sufficient permissions to edit that event.', 'my-calendar') . "</strong></p></div>";
        }
    }
    if ($action == 'delete') {
        // Deal with deleting an event from the database
        if (empty($event_id)) {
            $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __("You can't delete an event if you haven't submitted an event id", 'my-calendar') . "</p></div>";
        } else {
            $post_id = mc_get_data('event_post', $event_id);
            if (empty($_POST['event_instance'])) {
                $sql = "DELETE FROM " . my_calendar_table() . " WHERE event_id='" . (int) $event_id . "'";
                $delete_occurrences = "DELETE FROM " . my_calendar_event_table() . " WHERE occur_event_id = " . (int) $event_id;
                $mcdb->query($delete_occurrences);
                $mcdb->query($sql);
                $sql = "SELECT event_id FROM " . my_calendar_table() . " WHERE event_id='" . (int) $event_id . "'";
                $result = $mcdb->get_results($sql);
            } else {
                $delete = "DELETE FROM " . my_calendar_event_table() . " WHERE occur_id = " . (int) $_POST['event_instance'];
                $result = $mcdb->get_results($delete);
            }
            if (empty($result) || empty($result[0]->event_id)) {
                mc_delete_cache();
                // do an action using the event_id
                do_action('mc_delete_event', $event_id, $post_id);
                $message = "<div class='updated'><p>" . __('Event deleted successfully', 'my-calendar') . "</p></div>";
            } else {
                $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Despite issuing a request to delete, the event still remains in the database. Please investigate.', 'my-calendar') . "</p></div>";
            }
        }
    }
    $message = $message . "\n" . $output[3];
    return array('event_id' => $event_id, 'message' => $message);
}