Example #1
0
function load_events_to_db()
{
    global $wpdb, $current_user;
    $csvfile = "../wp-content/uploads/events.csv";
    if (!function_exists('espresso_member_data')) {
        $current_user->ID = 1;
    }
    if (!file_exists($csvfile)) {
        echo "File not found. Make sure you specified the correct path.\n";
        exit;
    }
    $file_handle = fopen($csvfile, "r");
    if (!$file_handle) {
        echo "Error opening data file.\n";
        exit;
    }
    $file_size = filesize($csvfile);
    if (empty($file_size)) {
        echo "File is empty.\n";
        exit;
    }
    $num_of_imported_events = 0;
    while ($strings = fgetcsv($file_handle)) {
        $question_groups_rs = $wpdb->get_results("select * from " . EVENTS_QST_GROUP_TABLE . " where wp_user = "******" and system_group = 1");
        $question_groups_ar = array();
        foreach ($question_groups_rs as $question_group) {
            $question_groups_ar[] = $question_group->id;
        }
        $question_groups = serialize($question_groups_ar);
        //echo "valid is :'".$valid."'";
        if (array_key_exists('2', $strings)) {
            //echo "The  element is in the array";
            $skip = $strings[0];
            if ($skip >= "1") {
                ++$num_of_imported_events;
                // Event meta info -
                $event_meta = array();
                $event_meta['default_payment_status'] = "";
                $event_meta['venue_id'] = '';
                $event_meta['additional_attendee_reg_info'] = 1;
                $event_meta['add_attendee_question_groups'] = unserialize($question_groups);
                $event_meta['date_submitted'] = date("Y-m-d H:i:s");
                $event_meta = serialize($event_meta);
                $strings_sql_array = array('event_name' => sanitize_text_field($strings[1]), 'event_desc' => $strings[2], 'address' => sanitize_text_field($strings[3]), 'address2' => sanitize_text_field($strings[4]), 'city' => sanitize_text_field($strings[5]), 'state' => sanitize_text_field($strings[6]), 'country' => sanitize_text_field($strings[7]), 'zip' => sanitize_text_field($strings[8]), 'phone' => sanitize_text_field($strings[9]), 'display_desc' => sanitize_text_field($strings[10]), 'event_identifier' => sanitize_title_with_dashes($strings[11]), 'start_date' => date('Y-m-d', strtotime($strings[12])), 'end_date' => date('Y-m-d', strtotime($strings[13])), 'reg_limit' => sanitize_text_field($strings[16]), 'allow_multiple' => sanitize_text_field($strings[18]), 'additional_limit' => (int) $strings[19], 'send_mail' => sanitize_text_field($strings[20]), 'is_active' => sanitize_text_field($strings[21]), 'conf_mail' => $strings[22], 'registration_start' => date('Y-m-d', strtotime($strings[23])), 'registration_end' => date('Y-m-d', strtotime($strings[24])), 'question_groups' => $question_groups, 'event_meta' => $event_meta);
                $sql_format = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s');
                if ($wpdb->insert(EVENTS_DETAIL_TABLE, $strings_sql_array, $sql_format) === FALSE) {
                    print $wpdb->print_error();
                } else {
                    $last_event_id = $wpdb->insert_id;
                }
                //Add times data
                $times_sql = array('event_id' => $last_event_id, 'start_time' => date("h:i A", strtotime($strings[14])), 'end_time' => date("h:i A", strtotime($strings[15])));
                $times_sql_format = array('%d', '%s', '%s');
                //echo $times_sql;
                //$wpdb->query ( $wpdb->prepare( $times_sql ) );
                if ($wpdb->insert(EVENTS_START_END_TABLE, $times_sql, $times_sql_format) === false) {
                    print $wpdb->print_error();
                }
                //Add price data
                $prices_sql = array('event_id' => $last_event_id, 'event_cost' => (double) $strings[17]);
                $prices_sql_format = array('%d', '%f');
                //echo $prices_sql;
                // $wpdb->query ( $wpdb->prepare( $prices_sql ) );
                if ($wpdb->insert(EVENTS_PRICES_TABLE, $prices_sql, $prices_sql_format) === false) {
                    print $wpdb->print_error();
                }
                //Add category data
                $category_names = explode("|", $strings[25]);
                foreach ($category_names as $category_name) {
                    $category_name = trim($category_name);
                    $category_sql = "SELECT cd.id FROM " . EVENTS_CATEGORY_TABLE . " cd WHERE category_name='%s'";
                    $cat_id = $wpdb->get_var($wpdb->prepare($category_sql, $category_name));
                    if ($cat_id == false) {
                        //fool the admin code into thinking we're adding a category via a POSt
                        $old_REQUEST_action = $_REQUEST['action'];
                        $_REQUEST['action'] = 'add';
                        $_REQUEST['category_name'] = $category_name;
                        require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/category-management/add_cat_to_db.php';
                        add_cat_to_db();
                        $cat_id = $wpdb->get_var($wpdb->prepare($category_sql, $category_name));
                        //ok, now that we've fooled it and added teh category, revert the $_REQUEST params
                        $_REQUEST['action'] = $old_REQUEST_action;
                    }
                    $cat_sql_2 = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES (%d, %d)";
                    if ($wpdb->query($wpdb->prepare($cat_sql_2, $last_event_id, $cat_id)) === false) {
                        print $wpdb->print_error();
                    }
                }
            }
        }
    }
    unlink($csvfile);
    if (!file_exists($csvfile)) {
        echo "<br>\r\nUpload file has been deleted.<br>";
    }
    echo "Added a total of {$num_of_imported_events} events to the database.<br>";
    remove_query_arg("action");
}
Example #2
0
function event_espresso_categories_config_mnu()
{
    global $wpdb, $current_user;
    ?>
    <div class="wrap">
        <div id="icon-options-event" class="icon32"> </div>
        <h2><?php 
    _e('Manage Event Categories', 'event_espresso');
    ?>
            <?php 
    if (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'edit' && $_REQUEST['action'] != 'add_new_category') {
        echo '<a href="admin.php?page=event_categories&amp;action=add_new_category" class="button add-new-h2" style="margin-left: 20px;">' . __('Add New Category', 'event_espresso') . '</a>';
    }
    ?>
        </h2>

        <div id="poststuff" class="metabox-holder has-right-sidebar">
            <?php 
    event_espresso_display_right_column();
    ?>
            <div id="post-body">
                <div id="post-body-content">
                    <?php 
    if (!empty($_POST['delete_category']) || isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete_category') {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                //Delete category data
                $sql = "DELETE FROM " . EVENTS_CATEGORY_TABLE . " WHERE id='{$del_id}'";
                $wpdb->query($sql);
                $sql = "DELETE FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE cat_id='{$del_id}'";
                $wpdb->query($sql);
            }
        }
        if ($_REQUEST['action'] == 'delete_category') {
            //Delete discount data
            $sql = "DELETE FROM " . EVENTS_CATEGORY_TABLE . " WHERE id='" . $_REQUEST['id'] . "'";
            $wpdb->query($sql);
            $sql = "DELETE FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE cat_id='" . $_REQUEST['id'] . "'";
            $wpdb->query($sql);
        }
        ?>
                        <div id="message" class="updated fade">
                            <p><strong>
                                    <?php 
        _e('Categories have been successfully deleted from the event.', 'event_espresso');
        ?>
                                </strong></p>
                        </div>
                        <?php 
    }
    if (isset($_REQUEST['action'])) {
        switch ($_REQUEST['action']) {
            case 'update':
                update_event_category();
                break;
            case 'add':
                add_cat_to_db();
                break;
            case 'add_new_category':
                add_new_event_category();
                break;
            case 'edit':
                edit_event_category();
                break;
        }
    }
    ?>
                    <form id="form1" name="form1" method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

                        <table id="table" class="widefat manage-categories">
                            <thead>
                                <tr>
                                    <th class="manage-column column-cb check-column" id="cb" scope="col" style="width:2.5%;"><input type="checkbox"></th>
                                    <th class="manage-column column-comments num" id="id" style="padding-top:7px; width:2.5%;" scope="col" title="Click to Sort"><?php 
    _e('ID', 'event_espresso');
    ?>
</th>
                                    <th class="manage-column column-title" id="name" scope="col" title="Click to Sort" style="width:20%;"><?php 
    _e('Name', 'event_espresso');
    ?>
</th>
                                    <?php 
    if (function_exists('espresso_is_admin') && espresso_is_admin() == true) {
        ?>
                                        <th class="manage-column column-creator" id="creator" scope="col" title="Click to Sort" style="width:10%;"><?php 
        _e('Creator', 'event_espresso');
        ?>
</th>
                                    <?php 
    }
    ?>

                                    <th class="manage-column column-author" id="start" scope="col" title="Click to Sort" style="width:20%;"><?php 
    _e('Shortcode', 'event_espresso');
    ?>
</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php 
    $sql = "SELECT * FROM " . EVENTS_CATEGORY_TABLE . " c";
    if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
        $sql .= " JOIN {$wpdb->users} u on u.ID = c.wp_user WHERE c.wp_user = "******" ORDER BY c.id ASC");
        foreach ($results as $result) {
            $category_id = $result->id;
            $category_name = stripslashes($result->category_name);
            $category_identifier = stripslashes($result->category_identifier);
            $category_desc = stripslashes($result->category_desc);
            $display_category_desc = stripslashes($result->display_desc);
            $wp_user = $result->wp_user;
            ?>
                                        <tr>
                                            <td class="check-column" style="padding:7px 0 22px 5px; vertical-align:top;"><input name="checkbox[<?php 
            echo $category_id;
            ?>
]" type="checkbox"  title="Delete <?php 
            echo stripslashes($category_name);
            ?>
"></td>
                                            <td class="column-comments" style="padding-top:3px;"><?php 
            echo $category_id;
            ?>
</td>
                                            <td class="post-title page-title column-title"><strong><a href="admin.php?page=event_categories&action=edit&id=<?php 
            echo $category_id;
            ?>
"><?php 
            echo $category_name;
            ?>
</a></strong>
                                               <div class="row-actions">
																								  <span class="edit"><a href="admin.php?page=event_categories&action=edit&id=<?php 
            echo $category_id;
            ?>
"><?php 
            _e('Edit', 'event_espresso');
            ?>
</a> | </span>
																									<span class="delete"><a onclick="return confirmDelete();" class="submitdelete" href="admin.php?page=event_categories&action=delete_category&id=<?php 
            echo $category_id;
            ?>
"><?php 
            _e('Delete', 'event_espresso');
            ?>
</a></span></div>
                                            </td>
                                            <?php 
            if (function_exists('espresso_is_admin') && espresso_is_admin() == true) {
                ?>
                                                <td><?php 
                echo espresso_user_meta($wp_user, 'user_firstname') != '' ? espresso_user_meta($wp_user, 'user_firstname') . ' ' . espresso_user_meta($wp_user, 'user_lastname') : espresso_user_meta($wp_user, 'display_name');
                ?>
</td>
                                            <?php 
            }
            ?>
                                            <td>[EVENT_ESPRESSO_CATEGORY event_category_id="<?php 
            echo $category_identifier;
            ?>
"]</td>

                                        </tr>
                                    <?php 
        }
    }
    ?>
                            </tbody>
                        </table>
                        <div style="clear:both">
                            <p>
                                <input type="checkbox" name="sAll" onclick="selectAll(this)" />
                                <strong>
                                    <?php 
    _e('Check All', 'event_espresso');
    ?>
                                </strong>
                                <input name="delete_category" type="submit" class="button-secondary" id="delete_category" value="<?php 
    _e('Delete Category', 'event_espresso');
    ?>
" style="margin-left:10px 0 0 10px;" onclick="return confirmDelete();">
                                <a  style="margin-left:5px"class="button-primary" href="admin.php?page=event_categories&amp;action=add_new_category"><?php 
    _e('Add New Category', 'event_espresso');
    ?>
</a>
                            </p>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div id="unique_id_info" style="display:none">
        <h2><?php 
    _e('Unique Category Identifier', 'event_espresso');
    ?>
</h2>
        <p><?php 
    _e('This should be a unique identifier for the category. Example: "category1" (without qoutes.)', 'event_espresso');
    ?>
</p>
        <p>The<?php 
    _e(' unique ID can also be used in individual pages using the', 'event_espresso');
    ?>
  	[EVENT_ESPRESSO_CATEGORY event_category_id="category_identifier"] <?php 
    _e('shortcode', 'event_espresso');
    ?>
.</p>
    </div>
    <script>
        jQuery(document).ready(function($) {

            /* show the table data */
            var mytable = $('#table').dataTable( {
                "bStateSave": true,
                "sPaginationType": "full_numbers",

                "oLanguage": {	"sSearch": "<strong><?php 
    _e('Live Search Filter', 'event_espresso');
    ?>
:</strong>",
                    "sZeroRecords": "<?php 
    _e('No Records Found!', 'event_espresso');
    ?>
" },
                "aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
    <?php 
    echo function_exists('espresso_is_admin') && espresso_is_admin() == true ? 'null,' : '';
    ?>
                    { "bSortable": false }

                ]

            } );

        } );
// Add new category form validation
	jQuery(function(){
	jQuery("#add-new-cat").validate({
	rules: {
	category_name: "required"
	},
	messages: {
	 category_name: "please add a category name"
		}
	
 });		
	});
</script>					


    <?php 
}