/**
  *			@Export data for ALL events
  *		  @access public
  *			@return void
  */
 function export_categories()
 {
     // are any Event IDs set?
     $query_params = array();
     if (isset($this->_req_data['EVT_CAT_ID'])) {
         // do we have an array of IDs ?
         if (is_array($this->_req_data['EVT_CAT_ID'])) {
             // generate an "IN (CSV)" where clause
             $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']);
             $filename = 'event-categories';
             $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs);
         } else {
             // generate regular where = clause
             $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']);
             $filename = 'event-category#' . $EVT_CAT_ID;
             $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID;
         }
     } else {
         // no IDs means we will d/l the entire table
         $filename = 'all-categories';
     }
     $tables_to_export = array('Term_Taxonomy' => $query_params);
     $table_data = $this->_get_export_data_for_models($tables_to_export);
     $filename = $this->generate_filename($filename);
     if (!$this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) {
         EE_Error::add_error(__('An error occurred and the Category details could not be exported from the database.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
     }
 }
 /**
  *		@ singleton method used to instantiate class object
  *		@ access public
  *		@return EE_CSV
  */
 public static function instance()
 {
     // check if class object is instantiated
     if (self::$_instance === NULL or !is_object(self::$_instance) or !self::$_instance instanceof EE_CSV) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  *	@Import Event Espresso data - some code "borrowed" from event espresso csv_import.php
  *	@access public
  *	@return boolean success
  */
 public function import()
 {
     require_once EE_CLASSES . 'EE_CSV.class.php';
     $this->EE_CSV = EE_CSV::instance();
     if (isset($_REQUEST['import'])) {
         if (isset($_POST['csv_submitted'])) {
             switch ($_FILES['file']['error'][0]) {
                 case UPLOAD_ERR_OK:
                     $error_msg = FALSE;
                     break;
                 case UPLOAD_ERR_INI_SIZE:
                     $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso");
                     break;
                 case UPLOAD_ERR_FORM_SIZE:
                     $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso");
                     break;
                 case UPLOAD_ERR_PARTIAL:
                     $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
                     break;
                 case UPLOAD_ERR_NO_FILE:
                     $error_msg = __('No file was uploaded.', "event_espresso");
                     break;
                 case UPLOAD_ERR_NO_TMP_DIR:
                     $error_msg = __('Missing a temporary folder.', "event_espresso");
                     break;
                 case UPLOAD_ERR_CANT_WRITE:
                     $error_msg = __('Failed to write file to disk.', "event_espresso");
                     break;
                 case UPLOAD_ERR_EXTENSION:
                     $error_msg = __('File upload stopped by extension.', "event_espresso");
                     break;
                 default:
                     $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso");
                     break;
             }
             if (!$error_msg) {
                 $filename = $_FILES['file']['name'][0];
                 $file_ext = substr(strrchr($filename, '.'), 1);
                 $file_type = $_FILES['file']['type'][0];
                 $temp_file = $_FILES['file']['tmp_name'][0];
                 $filesize = $_FILES['file']['size'][0] / 1024;
                 //convert from bytes to KB
                 if ($file_ext == 'csv') {
                     $max_upload = $this->EE_CSV->get_max_upload_size();
                     //max upload size in KB
                     if ($filesize < $max_upload || true) {
                         $wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir());
                         $path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename;
                         if (move_uploaded_file($temp_file, $path_to_file)) {
                             // convert csv to array
                             $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file);
                             // was data successfully stored in an array?
                             if (is_array($this->csv_array)) {
                                 $import_what = str_replace('csv_import_', '', $_REQUEST['action']);
                                 $import_what = str_replace('_', ' ', ucwords($import_what));
                                 $processed_data = $this->csv_array;
                                 $this->columns_to_save = FALSE;
                                 // if any imports require funcky processing, we'll catch them in the switch
                                 switch ($_REQUEST['action']) {
                                     case "import_events":
                                     case "event_list":
                                         $import_what = 'Event Details';
                                         break;
                                     case 'groupon_import_csv':
                                         $import_what = 'Groupon Codes';
                                         $processed_data = $this->process_groupon_codes();
                                         break;
                                 }
                                 // save processed codes to db
                                 if ($this->EE_CSV->save_csv_to_db($processed_data, $this->columns_to_save)) {
                                     return TRUE;
                                 }
                             } else {
                                 // no array? must be an error
                                 EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__);
                                 return FALSE;
                             }
                         } else {
                             EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__);
                             return FALSE;
                         }
                     } else {
                         EE_Error::add_error(sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"), $filename, $max_upload), __FILE__, __FUNCTION__, __LINE__);
                         return FALSE;
                     }
                 } else {
                     EE_Error::add_error(sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__);
                     return FALSE;
                 }
             } else {
                 EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
                 return FALSE;
             }
         }
     }
     return;
 }