Esempio n. 1
0
function update_event_venue()
{
    global $wpdb;
    $wpdb->show_errors();
    $venue_updated = false;
    if (isset($_REQUEST['venue_id'])) {
        $venue_id = $_REQUEST['venue_id'];
        if (function_exists('espresso_user_has_venue_permission')) {
            if (!espresso_user_has_venue_permission($venue_id)) {
                echo '<h2>' . __('Sorry, you do not have permission to edit this Venue.', 'event_espresso') . '</h2>';
                return;
            }
        }
        //print_r($_REQUEST);
        $venue_meta['contact'] = isset($_REQUEST['contact']) ? $_REQUEST['contact'] : '';
        $venue_meta['phone'] = isset($_REQUEST['phone']) ? $_REQUEST['phone'] : '';
        $venue_meta['twitter'] = isset($_REQUEST['twitter']) ? $_REQUEST['twitter'] : '';
        $venue_meta['image'] = isset($_REQUEST['image']) ? $_REQUEST['image'] : '';
        $venue_meta['website'] = isset($_REQUEST['website']) ? $_REQUEST['website'] : '';
        $venue_meta['description'] = isset($_REQUEST['description']) ? esc_html($_REQUEST['description']) : '';
        $locale = isset($_REQUEST['locale']) ? $_REQUEST['locale'] : '';
        $meta = serialize($venue_meta);
        $sql = array('name' => isset($_REQUEST['name']) ? $_REQUEST['name'] : '', 'address' => isset($_REQUEST['address']) ? $_REQUEST['address'] : '', 'address2' => isset($_REQUEST['address2']) ? $_REQUEST['address2'] : '', 'city' => isset($_REQUEST['city']) ? $_REQUEST['city'] : '', 'state' => isset($_REQUEST['state']) ? $_REQUEST['state'] : '', 'zip' => isset($_REQUEST['zip']) ? $_REQUEST['zip'] : '', 'country' => isset($_REQUEST['country']) ? $_REQUEST['country'] : '', 'meta' => $meta);
        $update_id = array('id' => $venue_id);
        /*echo 'Debug: <br />';
          print_r($sql);
          print 'Number of vars: ' . count ($sql);
          echo '<br />';
          print 'Number of cols: ' . count($sql_data);*/
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');
        $wpdb->update(EVENTS_VENUE_TABLE, $sql, $update_id, $sql_data, array('%d'));
        #if ( $wpdb->rows_affected > 0 ) {
        $venue_updated = true;
        if (!empty($locale)) {
            $wpdb->query("DELETE FROM " . EVENTS_LOCALE_REL_TABLE . " WHERE venue_id='" . $venue_id . "'");
            $sql_locale = "INSERT INTO " . EVENTS_LOCALE_REL_TABLE . " ( venue_id, locale_id) VALUES ( '" . $venue_id . "', '" . $locale . "')";
            if (!$wpdb->query($sql_locale)) {
                $error = true;
            }
        }
        #}
    }
    if ($venue_updated) {
        ?>
	
	<div id="message" class="updated fade">
			<p><strong><?php 
        _e('The venue  has been updated.', 'event_espresso');
        ?>
</strong></p>
         </div>	
         
<?php 
    }
}
Esempio n. 2
0
function event_espresso_venue_config_mnu()
{
    global $wpdb, $current_user, $espresso_premium;
    $_REQUEST['action'] = isset($_REQUEST['action']) ? $_REQUEST['action'] : NULL;
    ?>

<div class="wrap">
	<div id="icon-options-event" class="icon32"> </div>
	<h2>
		<?php 
    _e('Manage Venues', 'event_espresso');
    ?>
		<?php 
    if ($_REQUEST['action'] != 'edit' && $_REQUEST['action'] != 'add_new_venue') {
        echo '<a href="admin.php?page=event_venues&amp;action=add_new_venue" class="button add-new-h2" style="margin-left: 20px;">' . __('Add New Venue', 'event_espresso') . '</a>';
    }
    ?>
	</h2>
	<?php 
    ob_start();
    if (isset($_POST['delete_venue']) || isset($_REQUEST['action']) && 'delete_venue' == $_REQUEST['action']) {
        $venue_deleted = 0;
        if (isset($_POST['checkbox']) && is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                $flag = true;
                if (function_exists('espresso_user_has_venue_permission')) {
                    $flag = espresso_user_has_venue_permission($del_id);
                }
                if ($flag) {
                    //Delete venue data
                    $sql = "DELETE FROM " . EVENTS_VENUE_TABLE . " WHERE id='{$del_id}'";
                    $wpdb->query($sql);
                    if ($wpdb->rows_affected > 0) {
                        $venue_deleted++;
                    }
                    $sql = "DELETE FROM " . EVENTS_VENUE_REL_TABLE . " WHERE venue_id='{$del_id}'";
                    $wpdb->query($sql);
                    $sql = "DELETE FROM " . EVENTS_LOCALE_REL_TABLE . " WHERE venue_id='{$del_id}'";
                    $wpdb->query($sql);
                }
            }
        }
        if (isset($_REQUEST['id']) && 'delete_venue' == $_REQUEST['action']) {
            $flag = true;
            $del_id = $_REQUEST['id'];
            if (function_exists('espresso_user_has_venue_permission')) {
                $flag = espresso_user_has_venue_permission($del_id);
            }
            if ($flag) {
                //Delete discount data
                $sql = "DELETE FROM " . EVENTS_VENUE_TABLE . " WHERE id='" . $del_id . "'";
                $wpdb->query($sql);
                if ($wpdb->rows_affected > 0) {
                    $venue_deleted++;
                }
                $sql = "DELETE FROM " . EVENTS_VENUE_REL_TABLE . " WHERE venue_id='" . $del_id . "'";
                $wpdb->query($sql);
                $sql = "DELETE FROM " . EVENTS_LOCALE_REL_TABLE . " WHERE venue_id='" . $del_id . "'";
                $wpdb->query($sql);
            }
        }
        if ($venue_deleted > 0) {
            ?>
            <div id="message" class="updated fade">
                <p><strong>
                    <?php 
            _e('Venues have been successfully deleted from the event.', 'event_espresso');
            ?>
                    </strong></p>
            </div>
<?php 
        }
    }
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'update') {
        require_once "update_venue.php";
        update_event_venue();
    }
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
        require_once "add_venue_to_db.php";
        add_venue_to_db();
    }
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add_new_venue') {
        require_once "add_new_venue.php";
        add_new_event_venue();
    }
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
        require_once "edit_venue.php";
        edit_event_venue();
    }
    ?>
				<form id="form1" name="form1" method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
					<table id="table" class="widefat manage-discounts">
						<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 && $espresso_premium == true) {
        ?>
								<th class="manage-column column-creator" id="creator" scope="col" title="Click to Sort" style="width:20%;"><?php 
        _e('Locale', 'event_espresso');
        ?>
</th>
								<?php 
    }
    ?>
								<?php 
    if (function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == true) {
        ?>
								<th class="manage-column column-creator" id="creator" scope="col" title="Click to Sort" style="width:20%;"><?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 
    global $espresso_manager;
    // If user is an event manager, then show only their venues
    $sql = "( SELECT v.* FROM " . EVENTS_VENUE_TABLE . " v ";
    if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_group_admin') {
        if ($espresso_manager['event_manager_venue'] == "Y") {
            //	show only venues inside their assigned locales.
            $group = get_user_meta(espresso_member_data('id'), "espresso_group", true);
            $sql .= " LEFT JOIN " . EVENTS_LOCALE_REL_TABLE . " l ON  l.venue_id = v.id ";
            $sql .= " WHERE l.locale_id IN (" . implode(",", $group) . ")";
            $sql .= ") UNION ( ";
            $sql .= "SELECT v.* FROM " . EVENTS_VENUE_TABLE . " v ";
        }
    }
    if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
        $sql .= "  WHERE v.wp_user = "******")";
    #echo $sql;
    #exit("TEST");
    $wpdb->query($sql);
    if ($wpdb->num_rows > 0) {
        $results = $wpdb->get_results($sql . " ORDER BY id ASC");
        foreach ($results as $result) {
            $venue_id = $result->id;
            $name = isset($result->name) ? stripslashes_deep($result->name) : '';
            $venue_desc = isset($result->venue_desc) ? stripslashes_deep($result->venue_desc) : '';
            $wp_user = isset($result->wp_user) ? $result->wp_user : '';
            ?>
							<tr>
								<td class="check-column" style="padding:7px 0 22px 5px; vertical-align:top;"><input name="checkbox[<?php 
            echo $venue_id;
            ?>
]" type="checkbox"  title="Delete <?php 
            echo stripslashes($name);
            ?>
"></td>
								<td class="column-comments" style="padding-top:3px;"><?php 
            echo $venue_id;
            ?>
</td>
								<td class="post-title page-title column-title"><strong><a href="admin.php?page=event_venues&action=edit&id=<?php 
            echo $venue_id;
            ?>
"><?php 
            echo $name;
            ?>
</a></strong>
									<div class="row-actions"> <span class="edit"><a href="admin.php?page=event_venues&action=edit&id=<?php 
            echo $venue_id;
            ?>
">
										<?php 
            _e('Edit', 'event_espresso');
            ?>
										</a> | </span> <span class="delete"><a onclick="return confirmDelete();" class="submitdelete" href="admin.php?page=event_venues&action=delete_venue&id=<?php 
            echo $venue_id;
            ?>
">
										<?php 
            _e('Delete', 'event_espresso');
            ?>
										</a></span> </div></td>
								<?php 
            if (function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == true) {
                ?>
								<td><?php 
                $last_locale_id = $wpdb->get_var("SELECT locale_id FROM " . EVENTS_LOCALE_REL_TABLE . " WHERE venue_id='" . $venue_id . "'");
                $locales = $wpdb->get_results("SELECT * FROM " . EVENTS_LOCALE_TABLE . " WHERE id = '" . $last_locale_id . "'");
                if (count($locales) > 0) {
                    foreach ($locales as $locale) {
                        $locale_id = $locale->id;
                        $name = stripslashes($locale->name);
                        echo $name;
                    }
                }
                ?>
</td>
								<?php 
            }
            ?>
								<?php 
            if (function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == 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>[ESPRESSO_VENUE id="<?php 
            echo $venue_id;
            ?>
"]</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_venue" type="submit" class="button-secondary" id="delete_venue" value="<?php 
    _e('Delete Venue', '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_venues&amp;action=add_new_venue">
							<?php 
    _e('Add New Venue', 'event_espresso');
    ?>
							</a> </p>
					</div>
				</form>
            <?php 
    $main_post_content = ob_get_clean();
    espresso_choose_layout($main_post_content, event_espresso_display_right_column());
    ?>
</div>
<?php 
    #### help dialogue box ####
    ?>
<div id="venue_locale" style="display:none">
	<div class="TB-ee-frame">
		<h2>
			<?php 
    _e('Venue Locale/Region', 'event_espresso');
    ?>
		</h2>
		<p>
			<?php 
    _e('This can be used to group venues together by locales/regions.', 'event_espresso');
    ?>
		</p>
		<p>
			<?php 
    _e('Once you have created a locale in the <a href="admin.php?page=event_locales"> Manage Locales/Regions</a> page it will be available to select on the \'Add a Venue\' page', 'event_espresso');
    ?>
		</p>
	</div>
</div>
<?php 
    #### end help ####
    ?>
<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,
							 <?php 
    echo function_exists('espresso_is_admin') && espresso_is_admin() == true ? 'null,' : '';
    ?>
							 null,
							 <?php 
    echo function_exists('espresso_is_admin') && espresso_is_admin() == true ? 'null,' : '';
    ?>
							 { "bSortable": false }
							
						]

	} );
	
} );		
// Add new venue form validation
	jQuery(function(){
		jQuery('#venues-form').validate({
		rules: {
		  name: "required"
		 },
		 messages: {
		  name: "please add a name for your venue"
			}
		
		});
		});
</script>
<?php 
}
function edit_event_venue()
{
    global $wpdb;
    $id = $_REQUEST['id'];
    if (function_exists('espresso_user_has_venue_permission')) {
        if (!espresso_user_has_venue_permission($id)) {
            echo '<h2>' . __('Sorry, you do not have permission to edit this Venue.', 'event_espresso') . '</h2>';
            return;
        }
    }
    $sql = "SELECT * FROM " . EVENTS_VENUE_TABLE . " v WHERE v.id ='" . $id . "' ";
    /*
        if ( function_exists( 'espresso_member_data' ) ) {
       if ( 'espresso_event_manager' == espresso_member_data( 'role' ) ) {
           $sql .= " AND v.wp_user = '******'id') . "' ";
       } elseif ( 'espresso_group_admin' == espresso_member_data( ( 'role' ) ) ) {
           if(	"y" == strtolower( $espresso_manager['event_manager_venue'] )  ){
               $sql .= " AND ( v.wp_user = '******'id') . "' ";
               //OR v.id IN ( )";
           } else {
               $sql .= " AND v.wp_user = '******'id') . "' ";
           }
       }
    	}
    * 
    */
    // echo $sql;
    $result = $wpdb->get_row($sql);
    if ($result == NULL) {
        echo '<h2>' . __('Sorry, no venue was found.', 'event_espresso') . '</h2>';
        return;
    }
    $venue_id = $result->id;
    $name = stripslashes_deep($result->name);
    $address = stripslashes_deep($result->address);
    $address2 = stripslashes_deep($result->address2);
    $city = stripslashes_deep($result->city);
    $state = stripslashes_deep($result->state);
    $zip = stripslashes_deep($result->zip);
    $country = stripslashes_deep($result->country);
    $meta = unserialize($result->meta);
    $last_locale_id = $wpdb->get_var("SELECT locale_id FROM " . EVENTS_LOCALE_REL_TABLE . " WHERE venue_id = '" . $id . "'");
    ?>
<!--Add event display-->

<div id="add-edit-venue" class="metabox-holder">
	<div class="postbox">
		<h3>
			<?php 
    _e('Edit Venue:', 'event_espresso');
    ?>
			<?php 
    echo stripslashes($name);
    ?>
</h3>
		<div class="inside">
			<form method="post" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
">
				<input type="hidden" name="venue_id" value="<?php 
    echo $venue_id;
    ?>
">
				<input type="hidden" name="action" value="update">
				<table width="100%" border="0">
					<tr>
						<td align="left" valign="top"><ul>
								<li>
									<label for="name">
										<?php 
    _e('Name', 'event_espresso');
    ?>
									</label>
									<input type="text" id="name" name="name" size="25" value="<?php 
    echo $name;
    ?>
">
								</li>
								<li>
									<label for="address">
										<?php 
    _e('Address', 'event_espresso');
    ?>
									</label>
									<input type="text" id="address" name="address" size="25" value="<?php 
    echo $address;
    ?>
">
								</li>
								<li>
									<label for="address2">
										<?php 
    _e('Address 2', 'event_espresso');
    ?>
									</label>
									<input type="text" id="address2" name="address2" size="25" value="<?php 
    echo $address2;
    ?>
">
								</li>
								<li>
									<label for="city">
										<?php 
    _e('City', 'event_espresso');
    ?>
									</label>
									<input type="text" id="city" name="city" size="25" value="<?php 
    echo $city;
    ?>
">
								</li>
								<li>
									<label for="state">
										<?php 
    _e('State', 'event_espresso');
    ?>
									</label>
									<input type="text" id="state" name="state" size="25" value="<?php 
    echo $state;
    ?>
">
								</li>
								<li>
									<label for="zip">
										<?php 
    _e('Zip', 'event_espresso');
    ?>
									</label>
									<input type="text" id="zip" name="zip" size="25" value="<?php 
    echo $zip;
    ?>
">
								</li>
								<li>
									<label for="country">
										<?php 
    _e('Country', 'event_espresso');
    ?>
									</label>
									<input type="text" id="country" name="country" size="25" value="<?php 
    echo $country;
    ?>
">
								</li>
<?php 
    //
    if (function_exists('espresso_manager_pro_version')) {
        ?>
								<li>
									<label for="locale">
										<?php 
        _e('Locale/Region ', 'event_espresso');
        ?>
										<a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=venue_locale"><img src="<?php 
        echo EVENT_ESPRESSO_PLUGINFULLURL;
        ?>
images/question-frame.png" width="16" height="16" /></a> </label>
									<?php 
        $sql = "SELECT * FROM " . EVENTS_LOCALE_TABLE . " ORDER BY name ASC";
        $results = $wpdb->get_results($sql);
        if ($wpdb->num_rows > 0) {
            ?>
									<select name="locale" id="local">
<?php 
            foreach ($results as $result) {
                $locale_id = $result->id;
                $name = stripslashes($result->name);
                $sel = "";
                if ($last_locale_id == $locale_id) {
                    $sel = " SELECTED ";
                }
                ?>
										<option value="<?php 
                echo $locale_id;
                ?>
" <?php 
                echo $sel;
                ?>
><?php 
                echo $name;
                ?>
</option>
<?php 
            }
            ?>
									</select>
<?php 
        } else {
            ?>
						<p><?php 
            _e('You have not created any locales yet. To create Locales please visit', 'event_espresso');
            ?>
 <a href="admin.php?page=event_locales"> <?php 
            _e('Manage Locales/Regions', 'event_espresso');
            ?>
</a> <?php 
            _e('page.', 'event_espresso');
            ?>
</p>
<?php 
        }
        ?>
								</li>
<?php 
    }
    // end if function_exists('espresso_member_data'
    ?>
							</ul></td>
						<td align="left" valign="top" class="b"><ul>
								<li>
									<label for="contact">
										<?php 
    _e('Contact', 'event_espresso');
    ?>
									</label>
									<input type="text" id="contact" name="contact" size="25" value="<?php 
    echo stripslashes_deep($meta['contact']);
    ?>
">
								</li>
								<li>
									<label for="phone">
										<?php 
    _e('Phone', 'event_espresso');
    ?>
									</label>
									<input type="text" id="phone" name="phone" size="25" value="<?php 
    echo stripslashes_deep($meta['phone']);
    ?>
">
								</li>
								<li>
									<label for="twitter">
										<?php 
    _e('Twitter', 'event_espresso');
    ?>
									</label>
									<input type="text" id="twitter" name="twitter" size="25" value="<?php 
    echo stripslashes_deep($meta['twitter']);
    ?>
">
								</li>
								<li>
									<label for="website">
										<?php 
    _e('Website', 'event_espresso');
    ?>
									</label>
									<input type="text" id="website" name="website" size="25" value="<?php 
    echo stripslashes_deep($meta['website']);
    ?>
">
								</li>
								<li>
									<label for="image">
										<?php 
    _e('Image/Logo URL', 'event_espresso');
    ?>
									</label>
									<input type="text" id="image" name="image" size="25" value="<?php 
    echo stripslashes_deep($meta['image']);
    ?>
">
								</li>
							</ul></td>
					</tr>
				</table>
				<div id="descriptiondivrich" class="postarea">
					<label for="description" class="section-heading">
						<?php 
    _e('Description', 'event_espresso');
    ?>
					</label>
					<div class="postbox">
						<?php 
    if (function_exists('wp_editor')) {
        $args = array("textarea_rows" => 5, "textarea_name" => "description", "editor_class" => "my_editor_custom");
        wp_editor(espresso_admin_format_content($meta['description']), "description", $args);
    } else {
        the_editor(espresso_admin_format_content($meta['description']), $id = 'event_desc', $prev_id = 'title', $media_buttons = true, $tab_index = 3);
    }
    //the_editor(espresso_admin_format_content($meta['description']), $id = 'description', $prev_id = 'title', $media_buttons = true, $tab_index = 3);
    ?>
						<table id="venue-descr-add-form"  cellspacing="0">
							<tbody>
								<tr>
									<td class="aer-word-count"></td>
									<td class="autosave-info"><span>
										<p></p>
										</span></td>
								</tr>
							</tbody>
						</table>
					</div>
					<!-- /.postbox -->
					<p>
						<input class="button-primary" type="submit" name="Submit" value="<?php 
    _e('Update Venue');
    ?>
" id="update_venue" />
					</p>
				</div>
				<!-- /#descriptiondivrich -->
			</form>
		</div>
		<!-- /.inside --> 
	</div>
	<!-- /.postbox --> 
</div>
<!-- /.metabox-holder -->

<?php 
    //espresso_tiny_mce();
}