function wpmt_update_posts($post_data)
{
    $performance_genres = array('Alternative Content', 'Comedy', 'Concert', 'Dance', 'Family', 'Live Show', 'Live Sports Broadcast', 'Musical');
    $post_data_as_array = wpmt_object_to_array($post_data);
    for ($i = 0; $i < count($post_data_as_array); $i++) {
        // do not import festival films
        if ($post_data_as_array[$i]["Genre"] != "Festival") {
            // if the format is 'not a film' and is a performance genre, then make it a performance
            if ($post_data_as_array[$i]["Format"] == "Not a Film" && in_array($post_data_as_array[$i]["Genre"], $performance_genres)) {
                $performance = new WPMT_Performance();
                $performance->assign_values($post_data_as_array, $i);
                if ($performance->status == "Inactive" || $performance->status == "Deleted") {
                    $inactive_performances = get_posts(array('posts_per_page' => -1, 'post_type' => 'wpmt_performance', 'meta_key' => 'wpmt_performance_id', 'meta_value' => $performance->id));
                    foreach ($inactive_performances as $my_post) {
                        wp_delete_post($my_post->ID, true);
                        // Set to False if you want to send them to Trash.
                    }
                } elseif (null == get_posts(array('posts_per_page' => -1, 'post_type' => 'wpmt_performance', 'meta_key' => 'wpmt_performance_id', 'meta_value' => $performance->id))) {
                    $post_id = wpmt_add_post($performance->title, 'wpmt_performance');
                    $performance->update_fields($post_id);
                } elseif (null != get_posts(array('posts_per_page' => -1, 'post_type' => 'wpmt_performance', 'meta_key' => 'wpmt_performance_id', 'meta_value' => $performance->id)) && esc_attr(get_option('wpmt_overwrite_format')) != "No") {
                    $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'wpmt_performance', 'meta_key' => 'wpmt_performance_id', 'meta_value' => $performance->id));
                    foreach ($posts as $post) {
                        $performance->update_performance_format($post->ID);
                    }
                }
                // if the format or genre is anything else, make a film
            } else {
                $film = new WPMT_Film();
                $tmdb = new WPMT_Tmdb();
                $film->assign_values($post_data_as_array, $i);
                if ($film->status == "Inactive" || $film->status == "Deleted") {
                    $inactive_films = get_posts(array('posts_per_page' => -1, 'post_type' => 'wpmt_film', 'meta_key' => 'wpmt_film_id', 'meta_value' => $film->id));
                    foreach ($inactive_films as $my_post) {
                        wp_delete_post($my_post->ID, true);
                        // Set to False if you want to send them to Trash.
                    }
                } elseif (null == get_posts(array('posts_per_page' => -1, 'post_type' => 'wpmt_film', 'meta_key' => 'wpmt_film_id', 'meta_value' => $film->id))) {
                    $post_id = wpmt_add_post($film->title, 'wpmt_film');
                    $film->update_fields($post_id);
                    $tmdb->update_fields($post_id);
                } elseif (null != get_posts(array('posts_per_page' => -1, 'post_type' => 'wpmt_film', 'meta_key' => 'wpmt_film_id', 'meta_value' => $film->id)) && esc_attr(get_option('wpmt_overwrite_format')) != "No") {
                    $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'wpmt_film', 'meta_key' => 'wpmt_film_id', 'meta_value' => $film->id));
                    foreach ($posts as $post) {
                        $film->update_film_format($post->ID);
                    }
                }
            }
            //end else
        }
        //end if
    }
    //end $post_data_as_array for loop
}
function wpmt_do_option_updates()
{
    //need to add a verification of user priviledges in here
    if (isset($_POST['wpmt_manual_update'])) {
        //$wpmt_updates = get_option('wpmt_manual_updates_checkbox');
        $wpmt_updates = $_POST['wpmt_manual_updates_checkbox'];
    }
    for ($i = 0; $i < count($wpmt_updates); $i++) {
        if ($wpmt_updates[$i] == 'force delete all films') {
            wpmt_delete_all_posts('WPMT_Film');
        }
        if ($wpmt_updates[$i] == 'force delete all performances') {
            wpmt_delete_all_posts('WPMT_Performance');
        }
        if ($wpmt_updates[$i] == 'force delete all sessions') {
            wpmt_delete_all_posts('WPMT_Session');
        }
        if ($wpmt_updates[$i] == 'add new films and performances') {
            $my_token = esc_attr(get_option('wpmt_veezi_token'));
            $veezi_access_token = 'VeeziAccessToken: ' . $my_token;
            $film_and_performance_data = call_service('https://api.us.veezi.com/v1/film', $veezi_access_token);
            wpmt_update_posts($film_and_performance_data);
        }
        if ($wpmt_updates[$i] == 'add new sessions') {
            $my_token = esc_attr(get_option('wpmt_veezi_token'));
            $veezi_access_token = 'VeeziAccessToken: ' . $my_token;
            $session_data = call_service('https://api.us.veezi.com/v1/websession', $veezi_access_token);
            //1. delete all sessions
            wpmt_delete_all_posts('WPMT_Session');
            if (NULL == get_posts(array('post_type' => 'WPMT_Session'))) {
                wpmt_add_sessions($session_data);
            }
        }
        if ($wpmt_updates[$i] == 'update film formats' || $wpmt_updates[$i] == 'update performance formats') {
            $my_token = esc_attr(get_option('wpmt_veezi_token'));
            $veezi_access_token = 'VeeziAccessToken: ' . $my_token;
            $film_and_performance_data = call_service('https://api.us.veezi.com/v1/film', $veezi_access_token);
            $post_data_as_array = wpmt_object_to_array($film_and_performance_data);
            for ($c = 0; $c < count($post_data_as_array); $c++) {
                if ($post_data_as_array[$c]["Genre"] != "Festival") {
                    // if the format is 'not a film' and it's not a documentary, then make a performance
                    if ($post_data_as_array[$c]["Format"] == "Not a Film" && $post_data_as_array[$c]["Genre"] != "Documentary") {
                        if ($wpmt_updates[$i] == 'update performance formats') {
                            $performance = new WPMT_Performance();
                            $performance->assign_values($post_data_as_array, $c);
                            if (NULL != get_posts(array('posts_per_page' => -1, 'post_type' => 'WPMT_Performance', 'meta_key' => 'wpmt_performance_id', 'meta_value' => $performance->id))) {
                                $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'WPMT_Performance', 'meta_key' => 'wpmt_performance_id', 'meta_value' => $performance->id));
                                foreach ($posts as $post) {
                                    $performance->update_performance_format($post->ID);
                                }
                            }
                        }
                    } elseif ($wpmt_updates[$i] == 'update film formats') {
                        $film = new WPMT_Film();
                        $film->assign_values($post_data_as_array, $c);
                        if (NULL != get_posts(array('posts_per_page' => -1, 'post_type' => 'WPMT_Film', 'meta_key' => 'wpmt_film_id', 'meta_value' => $film->id))) {
                            $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'WPMT_Film', 'meta_key' => 'wpmt_film_id', 'meta_value' => $film->id));
                            foreach ($posts as $post) {
                                $film->update_film_format($post->ID);
                            }
                        }
                    }
                }
            }
            // end for loop
        }
    }
}