function eme_categories_table_layout($message = "")
{
    $categories = eme_get_categories();
    $destination = admin_url("admin.php?page=eme-categories");
    $table = "\n      <div class='wrap nosubsub'>\n\n         <div id='icon-edit' class='icon32'>\n            <br />\n         </div>\n         <h1>" . __('Categories', 'eme') . "</h1>\n ";
    if ($message != "") {
        $table .= "\n            <div id='message' class='updated fade below-h1' style='background-color: rgb(255, 251, 204);'>\n               <p>{$message}</p>\n            </div>";
    }
    $table .= "\n         <div id='col-container'>\n         \n            <?-- begin col-right -->\n            <div id='col-right'>\n             <div class='col-wrap'>\n                <form id='bookings-filter' method='post' action='" . $destination . "'>\n                  <input type='hidden' name='eme_admin_action' value='do_deletecategory' />";
    if (count($categories) > 0) {
        $table .= "<table class='widefat'>\n                        <thead>\n                           <tr>\n                              <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1' /></th>\n                              <th>" . __('ID', 'eme') . "</th>\n                              <th>" . __('Name', 'eme') . "</th>\n                           </tr>\n                        </thead>\n                        <tfoot>\n                           <tr>\n                              <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1' /></th>\n                              <th>" . __('ID', 'eme') . "</th>\n                              <th>" . __('Name', 'eme') . "</th>\n                           </tr>\n                        </tfoot>\n                        <tbody>";
        foreach ($categories as $this_category) {
            $table .= "    \n                           <tr>\n                           <td><input type='checkbox' class ='row-selector' value='" . $this_category['category_id'] . "' name='categories[]' /></td>\n                           <td><a href='" . admin_url("admin.php?page=eme-categories&amp;eme_admin_action=edit_category&amp;category_id=" . $this_category['category_id']) . "'>" . $this_category['category_id'] . "</a></td>\n                           <td><a href='" . admin_url("admin.php?page=eme-categories&amp;eme_admin_action=edit_category&amp;category_id=" . $this_category['category_id']) . "'>" . eme_trans_sanitize_html($this_category['category_name']) . "</a></td>\n                           </tr>\n                        ";
        }
        $delete_text = __("Are you sure you want to delete these categories?", "eme");
        $table .= <<<EOT
                        </tbody>
                     </table>
   
                     <div class='tablenav'>
                        <div class='alignleft actions'>
                        <input class='button-primary action' type='submit' name='doaction' value='Delete' onclick="return areyousure('{$delete_text}');" />
                        <br class='clear'/>
                        </div>
                        <br class='clear'/>
                     </div>
EOT;
    } else {
        $table .= "<p>" . __('No categories have been inserted yet!', 'eme');
    }
    $table .= "\n                  </form>\n               </div>\n            </div> \n            <?-- end col-right -->\n            \n            <?-- begin col-left -->\n            <div id='col-left'>\n            <div class='col-wrap'>\n                  <div class='form-wrap'>\n                     <div id='ajax-response'/>\n                  <h3>" . __('Add category', 'eme') . "</h3>\n                      <form name='add' id='add' method='post' action='" . $destination . "' class='add:the-list: validate'>\n                        <input type='hidden' name='eme_admin_action' value='do_addcategory' />\n                         <div class='form-field form-required'>\n                           <label for='category_name'>" . __('Category name', 'eme') . "</label>\n                           <input name='category_name' id='category_name' type='text' value='' size='40' />\n                            <p>" . __('The name of the category', 'eme') . ".</p>\n                            <label for='description'>" . __('Category description', 'eme') . "</label>\n                            <textarea name='description' id='description' rows='5' /></textarea>\n                         </div>\n                         <p class='submit'><input type='submit' class='button-primary' name='submit' value='" . __('Add category', 'eme') . "' /></p>\n                      </form>\n                 </div>\n               </div>\n            </div>\n            <?-- end col-left -->\n         </div>\n   </div>";
    echo $table;
}
 public function integrateWithVC()
 {
     // Check if Visual Composer is installed
     if (!defined('WPB_VC_VERSION')) {
         // Display notice that Visual Compser is required
         add_action('admin_notices', array($this, 'showVcVersionNotice'));
         return;
     }
     $categories = eme_get_categories();
     $option_categories = array();
     $option_categories['Select Category'] = '';
     foreach ($categories as $cat) {
         $option_categories[$cat['category_name']] = $cat['category_id'];
     }
     /*
     Add your Visual Composer logic here.
     Lets call vc_map function to "register" our custom shortcode within Visual Composer interface.
     
     More info: http://kb.wpbakery.com/index.php?title=Vc_map
     */
     vc_map(array('name' => __('EME Events Calendar', SCP_TEXT_DOMAIN), 'description' => __('', SCP_TEXT_DOMAIN), 'base' => 'scp_events_calendar', 'class' => '', 'controls' => 'full', 'icon' => plugins_url('assets/aislin-vc-icon.png', __FILE__), 'category' => __('Content', 'js_composer'), 'params' => array(array('type' => 'textfield', 'holder' => 'div', 'class' => '', 'heading' => __('Title', SCP_TEXT_DOMAIN), 'param_name' => 'title', 'value' => __('Calendar', SCP_TEXT_DOMAIN), 'description' => __('Widget title.', SCP_TEXT_DOMAIN)), array('type' => 'dropdown', 'holder' => '', 'class' => '', 'heading' => __('Title Tag', SCP_TEXT_DOMAIN), 'param_name' => 'title_tag', 'value' => array('h1' => 'h1', 'h2' => 'h2', 'h3' => 'h3', 'h4' => 'h4', 'h5' => 'h5', 'h6' => 'h6')), array('type' => 'dropdown', 'holder' => '', 'class' => '', 'heading' => __('Category', SCP_TEXT_DOMAIN), 'param_name' => 'category', 'value' => $option_categories, 'description' => __('If no category is selected all events will be shown.', SCP_TEXT_DOMAIN)), array('type' => 'textfield', 'heading' => __('Extra class name', $this->textdomain), 'param_name' => 'el_class', 'description' => __('If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.', $this->textdomain)))));
 }
Exemple #3
0
function eme_replace_filter_form_placeholders($format, $multiple, $multisize, $scope_count, $fields, $category, $notcategory)
{
    if ($fields == "all") {
        $fields = "categories,locations,towns,weeks,months";
    }
    preg_match_all("/#_[A-Za-z0-9_]+/", $format, $placeholders);
    usort($placeholders[0], 'sort_stringlenth');
    // if one of these changes, also the eme_events.php needs changing for the "Next page" part
    $cat_post_name = "eme_cat_filter";
    $loc_post_name = "eme_loc_filter";
    $town_post_name = "eme_town_filter";
    $scope_post_name = "eme_scope_filter";
    $localised_scope_post_name = "eme_localised_scope_filter";
    $selected_scope = isset($_REQUEST[$scope_post_name]) ? eme_sanitize_request($_REQUEST[$scope_post_name]) : '';
    $selected_location = isset($_REQUEST[$loc_post_name]) ? eme_sanitize_request($_REQUEST[$loc_post_name]) : '';
    $selected_town = isset($_REQUEST[$town_post_name]) ? eme_sanitize_request($_REQUEST[$town_post_name]) : '';
    $selected_category = isset($_REQUEST[$cat_post_name]) ? eme_sanitize_request($_REQUEST[$cat_post_name]) : '';
    $extra_conditions_arr = array();
    if ($category != '') {
        $extra_conditions_arr[] = "(category_id IN ({$category}))";
    }
    if ($notcategory != '') {
        $extra_conditions_arr[] = "(category_id NOT IN ({$notcategory}))";
    }
    $extra_conditions = implode(' AND ', $extra_conditions_arr);
    $scope_fieldcount = 0;
    foreach ($placeholders[0] as $result) {
        $replacement = "";
        $eventful = 0;
        $found = 1;
        $orig_result = $result;
        if (preg_match('/#_(EVENTFUL_)?FILTER_CATS/', $result) && get_option('eme_categories_enabled')) {
            if (strstr($result, '#_EVENTFUL')) {
                $eventful = 1;
            }
            $categories = eme_get_categories($eventful, "future", $extra_conditions);
            if ($categories && (empty($fields) || strstr($fields, 'categories'))) {
                $cat_list = array();
                foreach ($categories as $this_category) {
                    $id = $this_category['category_id'];
                    $cat_list[$id] = eme_translate($this_category['category_name']);
                }
                asort($cat_list);
                if ($multiple) {
                    $cat_list = array(0 => __('Select one or more categories', 'eme')) + $cat_list;
                    $replacement = eme_ui_multiselect($selected_category, $cat_post_name, $cat_list, $multisize);
                } else {
                    $cat_list = array(0 => __('Select a category', 'eme')) + $cat_list;
                    $replacement = eme_ui_select($selected_category, $cat_post_name, $cat_list);
                }
            }
        } elseif (preg_match('/#_(EVENTFUL_)?FILTER_LOCS/', $result)) {
            if (strstr($result, '#_EVENTFUL')) {
                $eventful = 1;
            }
            $locations = eme_get_locations($eventful, "future");
            if ($locations && (empty($fields) || strstr($fields, 'locations'))) {
                $loc_list = array();
                foreach ($locations as $this_location) {
                    $id = $this_location['location_id'];
                    $loc_list[$id] = eme_translate($this_location['location_name']);
                }
                asort($loc_list);
                if ($multiple) {
                    $loc_list = array(0 => __('Select one or more locations', 'eme')) + $loc_list;
                    $replacement = eme_ui_multiselect($selected_location, $loc_post_name, $loc_list, $multisize);
                } else {
                    $loc_list = array(0 => __('Select a location', 'eme')) + $loc_list;
                    $replacement = eme_ui_select($selected_location, $loc_post_name, $loc_list);
                }
            }
        } elseif (preg_match('/#_(EVENTFUL_)?FILTER_TOWNS/', $result)) {
            if (strstr($result, '#_EVENTFUL')) {
                $eventful = 1;
            }
            $towns = eme_get_locations($eventful, "future");
            if ($towns && (empty($fields) || strstr($fields, 'towns'))) {
                $town_list = array();
                foreach ($towns as $this_town) {
                    $id = eme_translate($this_town['location_town']);
                    $town_list[$id] = $id;
                }
                asort($town_list);
                if ($multiple) {
                    $town_list = array(0 => __('Select one or more towns', 'eme')) + $town_list;
                    $replacement = eme_ui_multiselect($selected_town, $town_post_name, $town_list, $multisize);
                } else {
                    $town_list = array(0 => __('Select a town', 'eme')) + $town_list;
                    $replacement = eme_ui_select($selected_town, $town_post_name, $town_list);
                }
            }
        } elseif (preg_match('/#_FILTER_WEEKS/', $result)) {
            if ($scope_fieldcount == 0 && (empty($fields) || strstr($fields, 'weeks'))) {
                $replacement = eme_ui_select($selected_scope, $scope_post_name, eme_create_week_scope($scope_count));
                $scope_fieldcount++;
            }
        } elseif (preg_match('/#_FILTER_MONTHS/', $result)) {
            if ($scope_fieldcount == 0 && (empty($fields) || strstr($fields, 'months'))) {
                $replacement = eme_ui_select($selected_scope, $scope_post_name, eme_create_month_scope($scope_count));
                $scope_fieldcount++;
            }
        } elseif (preg_match('/#_FILTER_MONTHRANGE/', $result)) {
            if ($scope_fieldcount == 0 && (empty($fields) || strstr($fields, 'monthrange'))) {
                $replacement = "<input type='text' id='{$localised_scope_post_name}' name='{$localised_scope_post_name}' readonly='readonly' >";
                $replacement .= "<input type='hidden' id='{$scope_post_name}' name='{$scope_post_name}' value='" . eme_sanitize_html($selected_scope) . "'>";
                wp_enqueue_script('eme-jquery-datepick');
                wp_enqueue_style('eme-jquery-datepick', EME_PLUGIN_URL . "js/jquery-datepick/jquery.datepick.css");
                // jquery ui locales are with dashes, not underscores
                $locale_code = get_locale();
                $locale_code = preg_replace("/_/", "-", $locale_code);
                $locale_file = EME_PLUGIN_DIR . "js/jquery-datepick/jquery.datepick-{$locale_code}.js";
                $locale_file_url = EME_PLUGIN_URL . "js/jquery-datepick/jquery.datepick-{$locale_code}.js";
                // for english, no translation code is needed)
                if ($locale_code != "en-US") {
                    if (!file_exists($locale_file)) {
                        $locale_code = substr($locale_code, 0, 2);
                        $locale_file = EME_PLUGIN_DIR . "js/jquery-datepick/jquery.datepick-{$locale_code}.js";
                        $locale_file_url = EME_PLUGIN_URL . "js/jquery-datepick/jquery.datepick-{$locale_code}.js";
                    }
                    if (file_exists($locale_file)) {
                        wp_enqueue_script('eme-jquery-datepick-locale', $locale_file_url);
                    }
                }
                ob_start();
                ?>
            <script type="text/javascript">
            var locale_code = '<?php 
                echo $locale_code;
                ?>
';
            var firstDayOfWeek = <?php 
                echo get_option('start_of_week');
                ?>
;
            </script>
            <?php 
                $replacement .= ob_get_clean();
                $replacement .= "<script type='text/javascript' src='" . EME_PLUGIN_URL . "js/eme_filters.js'></script>";
            }
        } elseif (preg_match('/#_FILTER_YEARS/', $result)) {
            if ($scope_fieldcount == 0 && (empty($fields) || strstr($fields, 'years'))) {
                $replacement = eme_ui_select($selected_scope, $scope_post_name, eme_create_year_scope($scope_count));
                $scope_fieldcount++;
            }
        } else {
            $found = 0;
        }
        if ($found) {
            $replacement = apply_filters('eme_general', $replacement);
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    return do_shortcode($format);
}
 /**
  *  Wrapper function to get categories form eme
  *
  */
 function getCategories()
 {
     return eme_get_categories();
 }
    public function form($instance)
    {
        //Defaults
        $instance = wp_parse_args((array) $instance, array('long_events' => 0));
        $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
        $category = empty($instance['category']) ? '' : eme_sanitize_html($instance['category']);
        $notcategory = empty($instance['notcategory']) ? '' : eme_sanitize_html($instance['notcategory']);
        $long_events = isset($instance['long_events']) ? eme_sanitize_html($instance['long_events']) : false;
        $authorid = isset($instance['authorid']) ? eme_sanitize_html($instance['authorid']) : '';
        $categories = eme_get_categories();
        $option_categories = array();
        foreach ($categories as $cat) {
            $id = $cat['category_id'];
            $option_categories[$id] = $cat['category_name'];
        }
        ?>
  <p>
   <label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:');
        ?>
</label>
   <input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />
  </p>      
  <p>
    <label for="<?php 
        echo $this->get_field_id('long_events');
        ?>
"><?php 
        _e('Show Long Events?', 'eme');
        ?>
:</label>
    <input type="checkbox" id="<?php 
        echo $this->get_field_id('long_events');
        ?>
" name="<?php 
        echo $this->get_field_name('long_events');
        ?>
" value="1" <?php 
        echo $long_events ? 'checked="checked"' : '';
        ?>
 />
  </p>
  <?php 
        if (get_option('eme_categories_enabled')) {
            ?>
  <p>
    <label for="<?php 
            echo $this->get_field_id('category');
            ?>
"><?php 
            _e('Category', 'eme');
            ?>
:</label><br />
   <select id="<?php 
            echo $this->get_field_id('category');
            ?>
" name="<?php 
            echo $this->get_field_name('category');
            ?>
[]" multiple="multiple">
      <?php 
            eme_option_items($option_categories, $category);
            ?>
   </select>
  </p>
  <p>
    <label for="<?php 
            echo $this->get_field_id('notcategory');
            ?>
"><?php 
            _e('Exclude Category', 'eme');
            ?>
:</label><br />
   <select id="<?php 
            echo $this->get_field_id('notcategory');
            ?>
" name="<?php 
            echo $this->get_field_name('notcategory');
            ?>
[]" multiple="multiple">
      <?php 
            eme_option_items($option_categories, $notcategory);
            ?>
   </select>
  </p>
<?php 
        }
        ?>
  <p>
    <label for="<?php 
        echo $this->get_field_id('authorid');
        ?>
"><?php 
        _e('Author', 'eme');
        ?>
:</label><br />
<?php 
        wp_dropdown_users(array('id' => $this->get_field_id('authorid'), 'name' => $this->get_field_name('authorid'), 'show_option_none' => __("Select...", 'eme'), 'selected' => $authorid));
        ?>
  </p>
<?php 
    }
Exemple #6
0
function eme_locations_edit_layout($location, $message = "")
{
    if (!isset($location['location_id'])) {
        $action = "add";
    } else {
        $action = "edit";
    }
    ?>
   <div class="wrap">
      <div id="poststuff">
         <div id="icon-edit" class="icon32">
            <br />
         </div>
            
         <h2><?php 
    if ($action == "add") {
        _e('Add location', 'eme');
    } else {
        _e('Edit location', 'eme');
    }
    ?>
</h2>
             <?php 
    admin_show_warnings();
    ?>
         
         <?php 
    if ($message != "") {
        ?>
            <div id="message" class="updated fade below-h2" style="background-color: rgb(255, 251, 204);">
               <p><?php 
        echo $message;
        ?>
</p>
            </div>
         <?php 
    }
    ?>
         <div id="ajax-response"></div>
   
         <form enctype="multipart/form-data" name="editloc" id="editloc" method="post" action="<?php 
    echo admin_url("admin.php?page=eme-locations");
    ?>
" class="validate">
         <?php 
    if ($action == "add") {
        ?>
         <input type="hidden" name="eme_admin_action" value="do_addlocation" />
         <?php 
    } else {
        ?>
         <input type="hidden" name="eme_admin_action" value="do_editlocation" />
         <input type="hidden" name="location_id" value="<?php 
        echo $location['location_id'];
        ?>
" />
         <?php 
    }
    ?>
         
         <!-- we need titlediv and title for qtranslate as ID -->
         <div id="titlediv" class="postbox">
            <h3>
               <?php 
    _e('Location name', 'eme');
    ?>
            </h3>
            <div class="inside">
           <input name="location_name" id="title" type="text" required="required" value="<?php 
    echo eme_sanitize_html($location['location_name']);
    ?>
" size="40" />
           <?php 
    if ($action == "edit") {
        _e('Permalink: ', 'eme');
        echo trailingslashit(home_url()) . eme_permalink_convert(get_option('eme_permalink_locations_prefix')) . $location['location_id'] . "/";
        $slug = $location['location_slug'] ? $location['location_slug'] : $location['location_name'];
        $slug = untrailingslashit(eme_permalink_convert($slug));
        ?>
                    <input type="text" id="slug" name="location_slug" value="<?php 
        echo $slug;
        ?>
" /><?php 
        echo user_trailingslashit("");
        ?>
           <?php 
    }
    ?>
           </div>
         </div>
         <div class="postbox">
            <h3>
               <?php 
    _e('Location address', 'eme');
    ?>
            </h3>
            <div class="inside">
            <input id="location_address" name="location_address" type="text" value="<?php 
    echo eme_trans_sanitize_html($location['location_address']);
    ?>
" size="40" />
            </div>
         </div>
 
         <div class="postbox">
            <h3>
               <?php 
    _e('Location town', 'eme');
    ?>
            </h3>
            <div class="inside">
            <input name="location_town" id="location_town" type="text" value="<?php 
    echo eme_trans_sanitize_html($location['location_town']);
    ?>
" size="40" />
            </div>
         </div>
                        
         <div class="postbox">
            <h3>
               <?php 
    _e('Location latitude/longitude', 'eme');
    ?>
            </h3>
            <div class="inside">
            <table><tr>
            <td><label for="location_latitude"><?php 
    _e('Latitude', 'eme');
    ?>
</label></td>
            <td><input id="location_latitude" name="location_latitude" type="text" value="<?php 
    echo eme_sanitize_html($location['location_latitude']);
    ?>
" size="40" /></td>
            </tr>
            <tr>
            <td><label for="location_longitude"><?php 
    _e('Longitude', 'eme');
    ?>
</label></td>
            <td><input id="location_longitude" name="location_longitude" type="text" value="<?php 
    echo eme_sanitize_html($location['location_longitude']);
    ?>
" size="40" /></td>
            </tr></table>
            </div>
         </div>

         <div class="postbox">
            <h3>
               <?php 
    _e('Location image', 'eme');
    ?>
            </h3>
            <div class="inside">
             <?php 
    if (isset($location['location_image_url']) && !empty($location['location_image_url'])) {
        echo "<img id='eme_location_image_example' src='" . $location['location_image_url'] . "' width='200' />";
        echo "<input type='hidden' name='location_image_url' id='location_image_url' value='" . $location['location_image_url'] . "' />";
    } else {
        echo "<img id='eme_location_image_example' src='' alt='' width='200' />";
        echo "<input type='hidden' name='location_image_url' id='location_image_url' />";
    }
    if (isset($location['location_image_id']) && !empty($location['location_image_id'])) {
        echo "<input type='hidden' name='location_image_id' id='location_image_id' value='" . $location['location_image_id'] . "' />";
    } else {
        echo "<input type='hidden' name='location_image_id' id='location_image_id' />";
    }
    // based on code found at http://codestag.com/how-to-use-wordpress-3-5-media-uploader-in-theme-options/
    ?>

                <input type="button" name="location_image_button" id="location_image_button" value="<?php 
    _e('Set a featured image', 'eme');
    ?>
" />
                <input type="button" id="eme_remove_old_image" name="eme_remove_old_image" value=" <?php 
    _e('Unset featured image', 'eme');
    ?>
" />
            </div>
<script>
jQuery(document).ready(function($){

  $('#eme_remove_old_image').click(function(e) {
        $('#location_image_url').val('');
        $('#location_image_id').val('');
        $('#eme_location_image_example' ).attr("src",'');
  });
  $('#location_image_button').click(function(e) {
    e.preventDefault();

    var custom_uploader = wp.media({
        title: '<?php 
    _e('Select the image to be used as featured image', 'eme');
    ?>
',
        button: {
            text: '<?php 
    _e('Set featured image', 'eme');
    ?>
'
        },
        // Tell the modal to show only images.
        library: {
                type: 'image'
        },  
        multiple: false  // Set this to true to allow multiple files to be selected
    })
    .on('select', function() {
        var attachment = custom_uploader.state().get('selection').first().toJSON();
        $('#location_image_url').val(attachment.url);
        $('#location_image_id').val(attachment.id);
        $('#eme_location_image_example' ).attr("src",attachment.url);
    })
    .open();
  });
});
</script>
        </div>
 
        <?php 
    if (get_option('eme_categories_enabled')) {
        ?>
        <div class="postbox">
            <h3>
               <?php 
        _e('Category', 'eme');
        ?>
            </h3>
            <div class="inside">
           <?php 
        $categories = eme_get_categories();
        foreach ($categories as $category) {
            if ($location['location_category_ids'] && in_array($category['category_id'], explode(",", $location['location_category_ids']))) {
                $selected = "checked='checked'";
            } else {
                $selected = "";
            }
            ?>
              <input type="checkbox" name="location_category_ids[]" value="<?php 
            echo $category['category_id'];
            ?>
" <?php 
            echo $selected;
            ?>
 /><?php 
            echo eme_trans_sanitize_html($category['category_name']);
            ?>
<br />
           <?php 
        }
        ?>
            </div>
        </div>
        <?php 
    }
    ?>

         <?php 
    $gmap_is_active = get_option('eme_gmap_is_active');
    if ($gmap_is_active) {
        ?>
   
         <div class="postbox"><?php 
        if (function_exists('qtrans_getLanguage') || function_exists('ppqtrans_getLanguage') || defined('ICL_LANGUAGE_CODE')) {
            _e("Because qtranslate or a derivate is active, the title of the location might not update automatically in the balloon, so don't panic there.");
        }
        ?>
         </div>
         <div class="postbox" id="eme-admin-map-not-found"><p><?php 
        _e('Map not found', 'eme');
        ?>
</p></div>
         <div class="postbox" id="eme-admin-location-map"></div>
         <br style="clear:both;" />
         <?php 
    }
    ?>
         <div class="postbox" id="loc_description">
            <h3>
               <?php 
    _e('Location description', 'eme');
    ?>
            </h3>
            <div class="inside">
               <div id="<?php 
    echo user_can_richedit() ? 'postdivrich' : 'postdiv';
    ?>
" class="postarea">
                  <!-- we need content for qtranslate as ID -->
                  <?php 
    wp_editor($location['location_description'], "content");
    ?>
               </div>
               <?php 
    _e('A description of the Location. You may include any kind of info here.', 'eme');
    ?>
            </div>
         </div>
     	 <?php 
    if (get_option('eme_attributes_enabled')) {
        ?>
         <div class="postbox">
            <h3>
               <?php 
        _e('Attributes', 'eme');
        ?>
            </h3>
               <?php 
        eme_attributes_form($location);
        ?>
         </div>
       <?php 
    }
    ?>
         <div class="postbox">
            <h3>
               <?php 
    _e('External link', 'eme');
    ?>
            </h3>
            <div class="inside">
            <input name="location_url" id="location_url" type="text" value="<?php 
    echo eme_sanitize_html($location['location_url']);
    ?>
" size="40" />
            <p><?php 
    _e('If this is filled in, the single location URL will point to this url instead of the standard location page.', 'eme');
    ?>
</p>
            </div>
         </div>
         <p class="submit"><input type="submit" class="button-primary" name="submit" value="<?php 
    if ($action == "add") {
        _e('Add location', 'eme');
    } else {
        _e('Update location', 'eme');
    }
    ?>
" /></p>
      </div>
      </form>
   </div>
   <?php 
}
function eme_event_form($event, $title, $element)
{
    admin_show_warnings();
    global $plugin_page, $eme_timezone;
    $event_status_array = eme_status_array();
    $saved_bydays = array();
    $currency_array = eme_currency_array();
    // let's determine if it is a new event, handy
    // or, in case of validation errors, $event can already contain info, but no $element (=event id)
    // so we create a new event and copy over the info into $event for the elements that do not exist
    if (!$element) {
        $is_new_event = 1;
        $new_event = eme_new_event();
        $event = array_replace_recursive($new_event, $event);
    } else {
        $is_new_event = 0;
    }
    $show_recurrent_form = 0;
    if (isset($_GET['eme_admin_action']) && $_GET['eme_admin_action'] == "edit_recurrence") {
        $pref = "recurrence";
        $form_destination = "admin.php?page=events-manager&amp;eme_admin_action=update_recurrence&amp;recurrence_id=" . $element;
        $saved_bydays = explode(",", $event['recurrence_byday']);
        $show_recurrent_form = 1;
    } else {
        $pref = "event";
        // even for new events, after the 'save' button is clicked, we want to go to the list of events
        // so we use page=events-manager too, not page=eme-new_event
        if ($is_new_event) {
            $form_destination = "admin.php?page=events-manager&amp;eme_admin_action=insert_event";
        } else {
            $form_destination = "admin.php?page=events-manager&amp;eme_admin_action=update_event&amp;event_id=" . $element;
        }
        if (isset($event['recurrence_id']) && $event['recurrence_id']) {
            # editing a single event of an recurrence: don't show the recurrence form
            $show_recurrent_form = 0;
        } else {
            # for single non-recurrent events: we show the form, so we can make it recurrent if we want to
            # but for that, we need to set the recurrence fields, otherwise we get warnings
            $show_recurrent_form = 1;
            $event['recurrence_id'] = 0;
            $event['recurrence_freq'] = '';
            $event['recurrence_start_date'] = $event['event_start_date'];
            $event['recurrence_end_date'] = $event['event_end_date'];
            $event['recurrence_interval'] = '';
            $event['recurrence_byweekno'] = '';
            $event['recurrence_byday'] = '';
            $event['recurrence_specific_days'] = '';
        }
    }
    if (!isset($event['recurrence_start_date'])) {
        $event['recurrence_start_date'] = $event['event_start_date'];
    }
    if (!isset($event['recurrence_end_date'])) {
        $event['recurrence_end_date'] = $event['event_end_date'];
    }
    $freq_options = array("daily" => __('Daily', 'eme'), "weekly" => __('Weekly', 'eme'), "monthly" => __('Monthly', 'eme'), "specific" => __('Specific days', 'eme'));
    $days_names = array(1 => __('Mon'), 2 => __('Tue'), 3 => __('Wed'), 4 => __('Thu'), 5 => __('Fri'), 6 => __('Sat'), 7 => __('Sun'));
    $weekno_options = array("1" => __('first', 'eme'), '2' => __('second', 'eme'), '3' => __('third', 'eme'), '4' => __('fourth', 'eme'), '5' => __('fifth', 'eme'), '-1' => __('last', 'eme'), "0" => __('Start day'));
    $event_RSVP_checked = $event['event_rsvp'] ? "checked='checked'" : "";
    $event_number_spaces = $event['event_seats'];
    $registration_wp_users_only = $event['registration_wp_users_only'] ? "checked='checked'" : "";
    $registration_requires_approval = $event['registration_requires_approval'] ? "checked='checked'" : "";
    $use_paypal_checked = $event['use_paypal'] ? "checked='checked'" : "";
    $use_2co_checked = $event['use_2co'] ? "checked='checked'" : "";
    $use_webmoney_checked = $event['use_webmoney'] ? "checked='checked'" : "";
    $use_fdgg_checked = $event['use_fdgg'] ? "checked='checked'" : "";
    $use_mollie_checked = $event['use_mollie'] ? "checked='checked'" : "";
    $use_sagepay_checked = $event['use_sagepay'] ? "checked='checked'" : "";
    // all properties
    $eme_prop_auto_approve_checked = $event['event_properties']['auto_approve'] ? "checked='checked'" : "";
    $eme_prop_ignore_pending_checked = $event['event_properties']['ignore_pending'] ? "checked='checked'" : "";
    $eme_prop_take_attendance = $event['event_properties']['take_attendance'] ? "checked='checked'" : "";
    $eme_prop_all_day_checked = $event['event_properties']['all_day'] ? "checked='checked'" : "";
    $eme_prop_use_worldpay = $event['event_properties']['use_worldpay'] ? "checked='checked'" : "";
    $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
    // the next javascript will fill in the values for localised-start-date, ... form fields and jquery datepick will fill in also to "to_submit" form fields
    ?>

<script type="text/javascript">
   jQuery(document).ready( function() {
   var dateFormat = jQuery("#localised-start-date").datepick( "option", "dateFormat" );

   var loc_start_date = jQuery.datepick.newDate(<?php 
    echo $eme_date_obj->setTimestampFromString($event['event_start_date'] . " " . $eme_timezone)->format('Y,n,j');
    ?>
);
   jQuery("#localised-start-date").datepick("setDate", jQuery.datepick.formatDate(dateFormat, loc_start_date));

   var loc_end_date = jQuery.datepick.newDate(<?php 
    echo $eme_date_obj->setTimestampFromString($event['event_end_date'] . " " . $eme_timezone)->format('Y,n,j');
    ?>
);
   jQuery("#localised-end-date").datepick("setDate", jQuery.datepick.formatDate(dateFormat, loc_end_date));
   <?php 
    if ($pref == "recurrence" && $event['recurrence_freq'] == 'specific') {
        ?>
      var mydates = [];
      <?php 
        foreach (explode(',', $event['recurrence_specific_days']) as $specific_day) {
            ?>
	      mydates.push(jQuery.datepick.newDate(<?php 
            echo $eme_date_obj->setTimestampFromString($specific_day)->format('Y,n,j');
            ?>
));
      <?php 
        }
        ?>
      jQuery("#localised-rec-start-date").datepick("setDate", mydates);
   <?php 
    } else {
        ?>
      var rec_start_date = jQuery.datepick.newDate(<?php 
        echo $eme_date_obj->setTimestampFromString($event['recurrence_start_date'] . " " . $eme_timezone)->format('Y,n,j');
        ?>
);
      jQuery("#localised-rec-start-date").datepick("setDate", jQuery.datepick.formatDate(dateFormat, rec_start_date));
   <?php 
    }
    ?>
      var rec_end_date = jQuery.datepick.newDate(<?php 
    echo $eme_date_obj->setTimestampFromString($event['recurrence_end_date'] . " " . $eme_timezone)->format('Y,n,j');
    ?>
);
   jQuery("#localised-rec-end-date").datepick("setDate", jQuery.datepick.formatDate(dateFormat, rec_end_date));
 });
</script>

   <form id="eventForm" name="eventForm" method="post" enctype="multipart/form-data" action="<?php 
    echo $form_destination;
    ?>
">
      <div class="wrap">
         <div id="icon-events" class="icon32"><br /></div>
         <h1><?php 
    echo eme_trans_sanitize_html($title);
    ?>
</h1>
         <?php 
    if ($event['recurrence_id']) {
        ?>
         <p id='recurrence_warning'>
            <?php 
        if (isset($_GET['eme_admin_action']) && $_GET['eme_admin_action'] == 'edit_recurrence') {
            _e('WARNING: This is a recurrence.', 'eme');
            ?>
            <br />
            <?php 
            _e('Modifying these data all the events linked to this recurrence will be rescheduled', 'eme');
        } else {
            _e('WARNING: This is a recurring event.', 'eme');
            _e('If you change these data and save, this will become an independent event.', 'eme');
        }
        ?>
         </p>
         <?php 
    }
    ?>
         <div id="poststuff" class="metabox-holder has-right-sidebar">
            <!-- SIDEBAR -->
            <div id="side-info-column" class='inner-sidebar'>
               <div id='side-sortables' class="meta-box-sortables">
                  <?php 
    if (current_user_can(get_option('eme_cap_author_event'))) {
        ?>
                  <!-- status postbox -->
                  <div class="postbox ">
                     <div class="handlediv" title="Click to toggle."><br />
                     </div>
                     <h3 class='hndle'><span>
                        <?php 
        _e('Event Status', 'eme');
        ?>
                        </span></h3>
                     <div class="inside">
                        <p><?php 
        _e('Status', 'eme');
        ?>
                        <select id="event_status" name="event_status">
                        <?php 
        foreach ($event_status_array as $key => $value) {
            if ($event['event_status'] && $event['event_status'] == $key) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }
            echo "<option value='{$key}' {$selected}>{$value}</option>";
        }
        ?>
                        </select><br />
                        <?php 
        _e('Private events are only visible for logged in users, draft events are not visible from the front end.', 'eme');
        ?>
                        </p>
                     </div>
                  </div>
                  <?php 
    }
    ?>
                  <?php 
    if (get_option('eme_recurrence_enabled') && $show_recurrent_form) {
        ?>
                  <!-- recurrence postbox -->
                  <div class="postbox ">
                     <div class="handlediv" title="Click to toggle."><br />
                     </div>
                     <h3 class='hndle'><span>
                        <?php 
        _e("Recurrence", 'eme');
        ?>
                        </span></h3>
                     <div class="inside">
                        <?php 
        $recurrence_YES = "";
        if ($event['recurrence_id']) {
            $recurrence_YES = "checked='checked' disabled='disabled'";
        }
        ?>
                        <p>
                           <input id="event-recurrence" type="checkbox" name="repeated_event"
                              value="1" <?php 
        echo $recurrence_YES;
        ?>
 />
                        </p>
                        <div id="event_recurrence_pattern">
                           <p>Frequency:
                              <select id="recurrence-frequency" name="recurrence_freq">
                                 <?php 
        eme_option_items($freq_options, $event['recurrence_freq']);
        ?>
                              </select>
                           </p>
			   <div id="recurrence-intervals">
                           <p>
                              <?php 
        _e('Every', 'eme');
        ?>
                              <input id="recurrence-interval" name='recurrence_interval'
                                size='2' value='<?php 
        if (isset($event['recurrence_interval'])) {
            echo $event['recurrence_interval'];
        }
        ?>
' />
                              <span class='interval-desc' id="interval-daily-singular">
                              <?php 
        _e('day', 'eme');
        ?>
                              </span> <span class='interval-desc' id="interval-daily-plural">
                              <?php 
        _e('days', 'eme');
        ?>
                              </span> <span class='interval-desc' id="interval-weekly-singular">
                              <?php 
        _e('week', 'eme');
        ?>
                              </span> <span class='interval-desc' id="interval-weekly-plural">
                              <?php 
        _e('weeks', 'eme');
        ?>
                              </span> <span class='interval-desc' id="interval-monthly-singular">
                              <?php 
        _e('month', 'eme');
        ?>
                              </span> <span class='interval-desc' id="interval-monthly-plural">
                              <?php 
        _e('months', 'eme');
        ?>
                              </span> </p>
                           <p class="alternate-selector" id="weekly-selector">
                              <?php 
        eme_checkbox_items('recurrence_bydays[]', $days_names, $saved_bydays);
        ?>
                              <br />
                              <?php 
        _e('If you leave this empty, the recurrence start date will be used as a reference.', 'eme');
        ?>
                           </p>
                           <p class="alternate-selector" id="monthly-selector">
                              <?php 
        _e('Every', 'eme');
        ?>
                              <select id="monthly-modifier" name="recurrence_byweekno">
                                 <?php 
        eme_option_items($weekno_options, $event['recurrence_byweekno']);
        ?>
                              </select>
                              <select id="recurrence-weekday" name="recurrence_byday">
                                 <?php 
        eme_option_items($days_names, $event['recurrence_byday']);
        ?>
                              </select>
                              <?php 
        _e('Day of month', 'eme');
        ?>
                              <br />
                              <?php 
        _e('If you use "Start day" as day of the month, the recurrence start date will be used as a reference.', 'eme');
        ?>
                              &nbsp;
                           </p>
                           </div>
                        </div>
                        <p id="recurrence-tip">
                           <?php 
        _e('Check if your event happens more than once.', 'eme');
        ?>
                        </p>
                        <p id="recurrence-tip-2">
                           <?php 
        _e('The event start and end date only define the duration of an event in case of a recurrence.', 'eme');
        ?>
                        </p>
                     </div>
                  </div>
                  <?php 
    }
    ?>

                  <?php 
    if ($event['event_author']) {
        ?>
                  <!-- owner postbox -->
                  <div class="postbox ">
                     <div class="handlediv" title="Click to toggle."><br />
                     </div>
                     <h3 class='hndle'><span>
                        <?php 
        _e('Author', 'eme');
        ?>
                        </span></h3>
                     <div class="inside">
                        <p><?php 
        _e('Author of this event: ', 'eme');
        ?>
                           <?php 
        $owner_user_info = get_userdata($event['event_author']);
        echo eme_sanitize_html($owner_user_info->display_name);
        ?>
                        </p>
                     </div>
                  </div>
                  <?php 
    }
    ?>
                  <div class="postbox ">
                     <div class="handlediv" title="Click to toggle."><br />
                     </div>
                     <h3 class='hndle'><span>
                        <?php 
    _e('Contact Person', 'eme');
    ?>
                        </span></h3>
                     <div class="inside">
                        <p><?php 
    _e('Contact', 'eme');
    ?>
                           <?php 
    wp_dropdown_users(array('name' => 'event_contactperson_id', 'show_option_none' => __("Event author", 'eme'), 'selected' => $event['event_contactperson_id']));
    // if it is not a new event and there's no contact person defined, then the event author becomes contact person
    // So let's display a warning what this means if there's no author (like when submitting via the frontend submission form)
    if (!$is_new_event && $event['event_contactperson_id'] < 1 && $event['event_author'] < 1) {
        print "<br />" . __('Since the author is undefined for this event, any reference to the contact person (like when using #_CONTACTPERSON when sending mails), will use the admin user info.', 'eme');
    }
    ?>
                        </p>
                     </div>
                  </div>
                  <?php 
    if (get_option('eme_rsvp_enabled')) {
        ?>
                  <div class="postbox ">
                     <div class="handlediv" title="Click to toggle."><br />
                     </div>
                     <h3 class='hndle'><span><?php 
        _e('RSVP', 'eme');
        ?>
</span></h3>
                     <div class="inside">
                        <p>
                           <input id="rsvp-checkbox" name='event_rsvp' value='1' type='checkbox' <?php 
        echo $event_RSVP_checked;
        ?>
 />
                           <?php 
        _e('Enable registration for this event', 'eme');
        ?>
                        </p>
                        <div id='rsvp-data'>
                           <p>
                              <input id="approval_required-checkbox" name='registration_requires_approval' value='1' type='checkbox' <?php 
        echo $registration_requires_approval;
        ?>
 />
                              <?php 
        _e('Require approval for registration', 'eme');
        ?>
                           <br />
                              <input id="eme_prop_auto_approve" name='eme_prop_auto_approve' value='1' type='checkbox' <?php 
        echo $eme_prop_auto_approve_checked;
        ?>
 />
                              <?php 
        _e('Auto-approve registration upon payment', 'eme');
        ?>
                           <br />
                              <input id="eme_prop_ignore_pending" name='eme_prop_ignore_pending' value='1' type='checkbox' <?php 
        echo $eme_prop_ignore_pending_checked;
        ?>
 />
                              <?php 
        _e('Consider pending registrations as available seats for new bookings', 'eme');
        ?>
                           <br />
                              <input id="wp_member_required-checkbox" name='registration_wp_users_only' value='1' type='checkbox' <?php 
        echo $registration_wp_users_only;
        ?>
 />
                              <?php 
        _e('Require WP membership for registration', 'eme');
        ?>
                           <br />
                              <input id="eme_prop_take_attendance" name='eme_prop_take_attendance' value='1' type='checkbox' <?php 
        echo $eme_prop_take_attendance;
        ?>
 />
                              <?php 
        _e('Only take attendance (0 or 1 seat) for this event', 'eme');
        ?>
                           <br /><table>
                              <tr>
                              <td><?php 
        _e('Spaces', 'eme');
        ?>
 :</td>
                              <td><input id="seats-input" type="text" name="event_seats" maxlength='125' title="<?php 
        _e('For multiseat events, seperate the values by \'||\'', 'eme');
        ?>
" value="<?php 
        echo $event_number_spaces;
        ?>
" /></td>
                              </tr>
                              <tr>
                              <td><?php 
        _e('Price: ', 'eme');
        ?>
</td>
                              <td><input id="price" type="text" name="price" maxlength='125' title="<?php 
        _e('For multiprice events, seperate the values by \'||\'', 'eme');
        ?>
" value="<?php 
        echo $event['price'];
        ?>
" /></td>
                              </tr>
                              <tr>
                              <td><?php 
        _e('Currency: ', 'eme');
        ?>
</td>
                              <td><select id="currency" name="currency">
                              <?php 
        foreach ($currency_array as $key => $value) {
            if ($event['currency'] && $event['currency'] == $key) {
                $selected = "selected='selected'";
            } elseif (!$event['currency'] && $key == get_option('eme_default_currency')) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }
            echo "<option value='{$key}' {$selected}>{$value}</option>";
        }
        ?>
                              </select></td>
                              </tr>
                              <tr>
                              <td><?php 
        _e('Max number of spaces to book', 'eme');
        ?>
</td>
                              <td><input id="eme_prop_max_allowed" type="text" name="eme_prop_max_allowed" maxlength='125' title="<?php 
        echo __('The maximum number of spaces a person can book in one go.', 'eme') . ' ' . __('(is multi-compatible)', 'eme');
        ?>
" value="<?php 
        echo $event['event_properties']['max_allowed'];
        ?>
" /></td>
                              </tr>
                              <tr>
                              <td><?php 
        _e('Min number of spaces to book', 'eme');
        ?>
</td>
                              <td><input id="eme_prop_min_allowed" type="text" name="eme_prop_min_allowed" maxlength='125' title="<?php 
        echo __('The minimum number of spaces a person can book in one go (it can be 0, for e.g. just an attendee list).', 'eme') . ' ' . __('(is multi-compatible)', 'eme');
        ?>
" value="<?php 
        echo $event['event_properties']['min_allowed'];
        ?>
" /></td>
                              </tr></table>
                           <br />
                              <?php 
        _e('Allow RSVP until ', 'eme');
        ?>
                           <br />
                              <input id="rsvp_number_days" type="text" name="rsvp_number_days" maxlength='2' size='2' value="<?php 
        echo $event['rsvp_number_days'];
        ?>
" />
                              <?php 
        _e('days', 'eme');
        ?>
                              <input id="rsvp_number_hours" type="text" name="rsvp_number_hours" maxlength='2' size='2' value="<?php 
        echo $event['rsvp_number_hours'];
        ?>
" />
                              <?php 
        _e('hours', 'eme');
        ?>
                           <br />
                              <?php 
        _e('before the event ', 'eme');
        $eme_rsvp_end_target_list = array('start' => __('starts', 'eme'), 'end' => __('ends', 'eme'));
        echo eme_ui_select($event['event_properties']['rsvp_end_target'], 'eme_prop_rsvp_end_target', $eme_rsvp_end_target_list);
        ?>
                           <br />
                           <br />
                              <?php 
        _e('Payment methods', 'eme');
        ?>
<br />
                              <input id="paypal-checkbox" name='use_paypal' value='1' type='checkbox' <?php 
        echo $use_paypal_checked;
        ?>
 /><?php 
        _e('Paypal', 'eme');
        ?>
<br />
                              <input id="2co-checkbox" name='use_2co' value='1' type='checkbox' <?php 
        echo $use_2co_checked;
        ?>
 /><?php 
        _e('2Checkout', 'eme');
        ?>
<br />
                              <input id="webmoney-checkbox" name='use_webmoney' value='1' type='checkbox' <?php 
        echo $use_webmoney_checked;
        ?>
 /><?php 
        _e('Webmoney', 'eme');
        ?>
<br />
                              <input id="fdgg-checkbox" name='use_fdgg' value='1' type='checkbox' <?php 
        echo $use_fdgg_checked;
        ?>
 /><?php 
        _e('First Data', 'eme');
        ?>
<br />
                              <input id="mollie-checkbox" name='use_mollie' value='1' type='checkbox' <?php 
        echo $use_mollie_checked;
        ?>
 /><?php 
        _e('Mollie', 'eme');
        ?>
<br />
                              <input id="sagepay-checkbox" name='use_sagepay' value='1' type='checkbox' <?php 
        echo $use_sagepay_checked;
        ?>
 /><?php 
        _e('Sage Pay', 'eme');
        ?>
<br />
                              <input id="eme_prop_use_worldpay" name='eme_prop_use_worldpay' value='1' type='checkbox' <?php 
        echo $eme_prop_use_worldpay;
        ?>
 /><?php 
        _e('Worldpay', 'eme');
        ?>
<br />
                           </p>
                           <?php 
        if ($event['event_rsvp'] && $pref != "recurrence") {
            // show the compact bookings table only when not editing a recurrence
            eme_bookings_compact_table($event['event_id']);
        }
        ?>
                        </div>
                     </div>
                  </div>
                  <?php 
    }
    ?>
                  <?php 
    if (get_option('eme_categories_enabled')) {
        ?>
                  <div class="postbox ">
                     <div class="handlediv" title="Click to toggle."><br />
                     </div>
                     <h3 class='hndle'><span>
                        <?php 
        _e('Category', 'eme');
        ?>
                        </span></h3>
                     <div class="inside">
                     <?php 
        $categories = eme_get_categories();
        foreach ($categories as $category) {
            if ($event['event_category_ids'] && in_array($category['category_id'], explode(",", $event['event_category_ids']))) {
                $selected = "checked='checked'";
            } else {
                $selected = "";
            }
            ?>
            <input type="checkbox" name="event_category_ids[]" value="<?php 
            echo $category['category_id'];
            ?>
" <?php 
            echo $selected;
            ?>
 /><?php 
            echo eme_trans_sanitize_html($category['category_name']);
            ?>
<br />
                     <?php 
        }
        ?>
                     </div>
                  </div> 
                  <?php 
    }
    ?>
               </div>
            </div>
            <!-- END OF SIDEBAR -->
            <div id="post-body">
               <div id="post-body-content" class="meta-box-sortables">
               <?php 
    if ($plugin_page === 'eme-new_event' && get_option("eme_fb_app_id")) {
        ?>
                  <div id="fb-root"></div>
                  <script>
                    window.fbAsyncInit = function() {
                      // init the FB JS SDK
                      FB.init({
                        appId      : '<?php 
        echo get_option("eme_fb_app_id");
        ?>
',// App ID from the app dashboard
                        channelUrl : '<?php 
        echo plugins_url("eme_fb_channel.php", __FILE__);
        ?>
', // Channel file for x-domain comms
                        status     : true,  // Check Facebook Login status
                        xfbml      : true   // Look for social plugins on the page
                      });

                      // Additional initialization code such as adding Event Listeners goes here
                     FB.Event.subscribe('auth.authResponseChange', function(response) {
                        if (response.status === 'connected') {
                           jQuery('#fb-import-box').show();
                         } else if (response.status === 'not_authorized') {
                           jQuery('#fb-import-box').hide();
                         } else {
                           jQuery('#fb-import-box').hide();
                         }
                        });
                     };


                     // Load the SDK asynchronously
                     (function(d, s, id){
                       var js, fjs = d.getElementsByTagName(s)[0];
                       if (d.getElementById(id)) {return;}
                       js = d.createElement(s); js.id = id;
                       js.src = "//connect.facebook.net/en_US/all.js";
                       fjs.parentNode.insertBefore(js, fjs);
                     }(document, 'script', 'facebook-jssdk'));

                  </script>
                  <fb:login-button id="fb-login-button" width="200" autologoutlink="true" scope="user_events" max-rows="1"></fb:login-button>
                  <br />
                  <br />
                  <div id='fb-import-box' style='display:none'>
                     Facebook event url : <input type='text' id='fb-event-url' class='widefat' /> 
                     <br />
                     <br />
                     <input type='button' class='button' value='Import' id='import-fb-event-btn' />
                     <br />
                     <br />
                  </div>
               <?php 
    }
    ?>

               <?php 
    $screens = array('events_page_eme-new_event', 'toplevel_page_events-manager');
    foreach ($screens as $screen) {
        if ($event['event_page_title_format'] == "" && $event['event_properties']['event_page_title_format_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_page_title_format', 'eme_closed');
        }
        if ($event['event_single_event_format'] == "" && $event['event_properties']['event_single_event_format_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_single_event_format', 'eme_closed');
        }
        if ($event['event_contactperson_email_body'] == "" && $event['event_properties']['event_contactperson_email_body_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_contactperson_email_body', 'eme_closed');
        }
        if ($event['event_registration_recorded_ok_html'] == "" && $event['event_properties']['event_registration_recorded_ok_html_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_registration_recorded_ok_html', 'eme_closed');
        }
        if ($event['event_respondent_email_body'] == "" && $event['event_properties']['event_respondent_email_body_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_respondent_email_body', 'eme_closed');
        }
        if ($event['event_registration_pending_email_body'] == "" && $event['event_properties']['event_registration_pending_email_body_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_registration_pending_email_body', 'eme_closed');
        }
        if ($event['event_registration_updated_email_body'] == "" && $event['event_properties']['event_registration_updated_email_body_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_registration_updated_email_body', 'eme_closed');
        }
        if ($event['event_registration_cancelled_email_body'] == "" && $event['event_properties']['event_registration_cancelled_email_body_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_registration_cancelled_email_body', 'eme_closed');
        }
        if ($event['event_registration_denied_email_body'] == "" && $event['event_properties']['event_registration_denied_email_body_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_registration_denied_email_body', 'eme_closed');
        }
        if ($event['event_registration_form_format'] == "" && $event['event_properties']['event_registration_form_format_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_registration_form_format', 'eme_closed');
        }
        if ($event['event_cancel_form_format'] == "" && $event['event_properties']['event_cancel_form_format_tpl'] == 0) {
            add_filter('postbox_classes_' . $screen . '_div_event_cancel_form_format', 'eme_closed');
        }
    }
    // we can only give one parameter to do_meta_boxes, but we don't want to list the templates each time
    // so temporary we store the array in the $event var and unset it afterwards
    $templates_array = eme_get_templates_array_by_id();
    // the first element is something empty or a "no templates" string, but we need to keep the array indexes
    // so we concatenate using "+", not array_merge
    if (is_array($templates_array) && count($templates_array) > 0) {
        $templates_array = array(0 => '') + $templates_array;
    } else {
        $templates_array = array(0 => __('No templates defined yet!', 'eme'));
    }
    $event['templates_array'] = $templates_array;
    if ($is_new_event) {
        // we add the meta boxes only on the page we're currently at, so for duplicate event it is the same as for edit event
        // see the eme_admin_event_boxes function
        if (isset($_GET['eme_admin_action']) && $_GET['eme_admin_action'] == 'duplicate_event') {
            do_meta_boxes('toplevel_page_events-manager', "post", $event);
        } else {
            do_meta_boxes('events_page_eme-new_event', "post", $event);
        }
    } else {
        do_meta_boxes('toplevel_page_events-manager', "post", $event);
    }
    unset($event['templates_array']);
    ?>
               </div>
               <p class="submit">
                  <?php 
    if ($is_new_event) {
        ?>
                     <input type="submit" class="button-primary" id="event_update_button" name="event_update_button" value="<?php 
        _e('Save');
        ?>
 &raquo;" />
                  <?php 
    } else {
        $delete_button_text = __('Are you sure you want to delete this event?', 'eme');
        $deleteRecurrence_button_text = __('Are you sure you want to delete this recurrence?', 'eme');
        ?>
                     <?php 
        if ($pref == "recurrence") {
            ?>
                     <input type="submit" class="button-primary" id="event_update_button" name="event_update_button" value="<?php 
            _e('Update');
            ?>
 &raquo;" />
                     <?php 
        } else {
            ?>
                     <input type="submit" class="button-primary" id="event_update_button" name="event_update_button" value="<?php 
            _e('Update');
            ?>
 &raquo;" />
                     <?php 
        }
        ?>
                     <input type="submit" class="button-primary" id="event_delete_button" name="event_delete_button" value="<?php 
        _e('Delete Event', 'eme');
        ?>
 &raquo;" onclick="return areyousure('<?php 
        echo $delete_button_text;
        ?>
');" />
                     <?php 
        if ($event['recurrence_id']) {
            ?>
                     <input type="submit" class="button-primary" id="event_deleteRecurrence_button" name="event_deleteRecurrence_button" value="<?php 
            _e('Delete Recurrence', 'eme');
            ?>
 &raquo;" onclick="return areyousure('<?php 
            echo $deleteRecurrence_button_text;
            ?>
');" />
                     <?php 
        }
        ?>
 
                  <?php 
    }
    ?>
               </p>
            </div>
         </div>
      </div>
      <?php 
    wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
    ?>
      <?php 
    wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
    ?>
   </form>
<?php 
}