function export_xml($type, $args = array())
 {
     global $wpdb, $frmdb, $frmprodb;
     if (!is_array($type)) {
         $table = $type == 'items' ? $frmdb->entries : ($type == 'displays' ? $frmprodb->{$type} : $frmdb->{$type});
     }
     $defaults = array('is_template' => false, 'ids' => false);
     $args = wp_parse_args($args, $defaults);
     $where = $join = '';
     if (function_exists('sanitize_key')) {
         $sitename = sanitize_key(get_bloginfo('name'));
     } else {
         $sitename = sanitize_title_with_dashes(get_bloginfo('name'));
     }
     if (!empty($sitename)) {
         $sitename .= '.';
     }
     $filename = $sitename . 'formidable.' . date('Y-m-d') . '.xml';
     header('Content-Description: File Transfer');
     header('Content-Disposition: attachment; filename=' . $filename);
     header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
     if ($type == 'forms') {
         $where .= $wpdb->prepare("{$table}.is_template = %d AND {$table}.status != 'draft'", $args['is_template']);
     } else {
         if ($type == 'entries') {
             //$join = "INNER JOIN {$frmdb->entry_metas} ON ({$frmdb->entries}.id = {$frmdb->entry_metas}.item_id)";
         } else {
             if ($type == 'displays') {
             }
         }
     }
     if (is_array($args['ids'])) {
         $args['ids'] = implode(',', $args['ids']);
     }
     if (isset($table) and $args['ids']) {
         if (!empty($where)) {
             $where .= " AND ";
         }
         //$ids = array_fill( 0, count($args['ids']), '%s' );
         $where .= "{$table}.id IN (" . $args['ids'] . ")";
     }
     $xml = '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '" ?>' . "\n";
     $xml .= "<formidable>\n";
     if (is_array($type)) {
         foreach ($type as $tb_type) {
             $table = $tb_type == 'items' ? $frmdb->entries : ($tb_type == 'displays' ? $frmprodb->{$tb_type} : $frmdb->{$tb_type});
             $where = '';
             if ($tb_type == 'forms') {
                 //add forms
                 $where = $wpdb->prepare("{$table}.is_template = %d AND {$table}.status != 'draft'", $args['is_template']);
                 if ($args['ids']) {
                     $where .= " AND {$table}.id IN (" . $args['ids'] . ")";
                 }
             } else {
                 if (($tb_type == 'items' or $tb_type == 'displays') and $args['ids']) {
                     $where = "{$table}.form_id IN (" . $args['ids'] . ")";
                 }
             }
             if (!empty($where)) {
                 $where = " WHERE " . $where;
             }
             $records = $wpdb->get_results("SELECT * FROM {$table}{$where}");
             $xml .= FrmProAppHelper::get_xml_for_type($tb_type, $records);
         }
     } else {
         $records = $wpdb->get_results("SELECT * FROM {$table} {$join} WHERE {$where}");
         $xml .= FrmProAppHelper::get_xml_for_type($type, $records);
     }
     $xml .= "</formidable>\n";
     return $xml;
 }