function cpabc_appointments_export_csv()
{
    if (!is_admin()) {
        return;
    }
    global $wpdb;
    if (!defined('CP_CALENDAR_ID')) {
        define('CP_CALENDAR_ID', intval($_GET["cal"]));
    }
    $form_data = json_decode(cpabc_appointment_cleanJSON(cpabc_get_option('form_structure', CPABC_APPOINTMENTS_DEFAULT_form_structure)));
    if (@$_GET["cancelled_by"] != '') {
        $cond = '';
    } else {
        $cond = " AND ((is_cancelled<>'1') OR is_cancelled is null)";
    }
    if ($_GET["search"] != '') {
        $cond .= " AND (buffered_date like '%" . esc_sql($_GET["search"]) . "%')";
    }
    if ($_GET["dfrom"] != '') {
        $cond .= " AND (`booked_time_unformatted` >= '" . esc_sql($_GET["dfrom"]) . "')";
    }
    if ($_GET["dto"] != '') {
        $cond .= " AND (`booked_time_unformatted` <= '" . esc_sql($_GET["dto"]) . " 23:59:59')";
    }
    if (@$_GET["added_by"] != '') {
        $cond .= " AND (who_added >= '" . esc_sql($_GET["added_by"]) . "')";
    }
    if (@$_GET["edited_by"] != '') {
        $cond .= " AND (who_edited >= '" . esc_sql($_GET["edited_by"]) . "')";
    }
    if (@$_GET["cancelled_by"] != '') {
        $cond .= " AND (is_cancelled='1' AND who_cancelled >= '" . esc_sql($_GET["cancelled_by"]) . "')";
    }
    if (CP_CALENDAR_ID != 0) {
        $cond .= " AND appointment_calendar_id=" . CP_CALENDAR_ID;
    }
    $events = $wpdb->get_results("SELECT * FROM " . CPABC_TDEAPP_CALENDAR_DATA_TABLE . " INNER JOIN " . CPABC_APPOINTMENTS_CONFIG_TABLE_NAME . " ON " . CPABC_TDEAPP_CALENDAR_DATA_TABLE . ".appointment_calendar_id=" . CPABC_APPOINTMENTS_CONFIG_TABLE_NAME . ".id LEFT JOIN " . CPABC_APPOINTMENTS_TABLE_NAME . " ON " . CPABC_TDEAPP_CALENDAR_DATA_TABLE . ".reference=" . CPABC_APPOINTMENTS_TABLE_NAME . ".id  WHERE 1=1 " . $cond);
    $fields = array("Calendar ID", "Calendar", "Time");
    $values = array();
    foreach ($events as $item) {
        $value = array($item->appointment_calendar_id, $item->uname, $item->datatime);
        $data = array();
        $data = unserialize($item->buffered_date);
        if (!is_array($data)) {
            $data = array('title' => $item->title, 'description' => $item->description);
        }
        $end = count($fields);
        for ($i = 3; $i < $end; $i++) {
            if (isset($data[$fields[$i]])) {
                $value[$i] = $data[$fields[$i]];
                unset($data[$fields[$i]]);
            } else {
                $value[$i] = '';
            }
        }
        foreach ($data as $k => $d) {
            $fields[] = $k;
            $value[] = $d;
        }
        $values[] = $value;
    }
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=bookings.csv");
    $end = count($fields);
    for ($i = 0; $i < $end; $i++) {
        echo '"' . str_replace('"', '""', cpabc_appointments_get_field_name($fields[$i], @$form_data[0])) . '",';
    }
    echo "\n";
    foreach ($values as $item) {
        for ($i = 0; $i < $end; $i++) {
            if (!isset($item[$i])) {
                $item[$i] = '';
            }
            if (is_array($item[$i])) {
                $item[$i] = implode($item[$i], ',');
            }
            echo '"' . str_replace('"', '""', $item[$i]) . '",';
        }
        echo "\n";
    }
    exit;
}
    }
    ?>
>Plain Text (default)</option>
           <option value="html"<?php 
    if ($option == 'html') {
        echo ' selected';
    }
    ?>
>HTML (use html in the textarea below)</option>
          </select>
        </td>
        </tr>          
        <tr valign="top">
        <th scope="row">Remainder email message</th>
        <td><textarea cols="70" rows="3"  disabled readonly name="reminder_content"><?php 
    echo cpabc_get_option('reminder_content', CPABC_APPOINTMENTS_DEFAULT_REMINDER_CONTENT);
    ?>
</textarea></td>
        </tr>                                                
     </table>
  </div>
</div>  

 
 <div id="metabox_basic_settings" class="postbox" >
  <h3 class='hndle' style="padding:5px;"><span>Custom Settings - Available only in Pro version</span></h3>
  <div class="inside">
     <table class="form-table">    
        <tr valign="top">
        <th scope="row">Options (drop-down select, one item per line with format: <span style="color:#ff0000">price | title</span>)<br />                
        <ul>Sample Format:</ul>
?>
"><br />
<?php 
_e('Comments/Questions', 'cpabc');
?>
:<br />
<textarea name="question" style="width:100%"></textarea><br />
<?php 
if (cpabc_get_option('dexcv_enable_captcha', CPABC_TDEAPP_DEFAULT_dexcv_enable_captcha) != 'false') {
    ?>
  <?php 
    _e('Please enter the security code:', 'cpabc');
    ?>
<br />
  <img src="<?php 
    echo cpabc_appointment_get_site_url() . '/?cpabc_app=captcha&inAdmin=1&width=' . cpabc_get_option('dexcv_width', CPABC_TDEAPP_DEFAULT_dexcv_width) . '&height=' . cpabc_get_option('dexcv_height', CPABC_TDEAPP_DEFAULT_dexcv_height) . '&letter_count=' . cpabc_get_option('dexcv_chars', CPABC_TDEAPP_DEFAULT_dexcv_chars) . '&min_size=' . cpabc_get_option('dexcv_min_font_size', CPABC_TDEAPP_DEFAULT_dexcv_min_font_size) . '&max_size=' . cpabc_get_option('dexcv_max_font_size', CPABC_TDEAPP_DEFAULT_dexcv_max_font_size) . '&noise=' . cpabc_get_option('dexcv_noise', CPABC_TDEAPP_DEFAULT_dexcv_noise) . '&noiselength=' . cpabc_get_option('dexcv_noise_length', CPABC_TDEAPP_DEFAULT_dexcv_noise_length) . '&bcolor=' . cpabc_get_option('dexcv_background', CPABC_TDEAPP_DEFAULT_dexcv_background) . '&border=' . cpabc_get_option('dexcv_border', CPABC_TDEAPP_DEFAULT_dexcv_border) . '&font=' . cpabc_get_option('dexcv_font', CPABC_TDEAPP_DEFAULT_dexcv_font);
    ?>
"  id="captchaimg" alt="security code" border="0"  />
  <br />
  <?php 
    _e('Security Code (lowercase letters):', 'cpabc');
    ?>
<br />
  <div class="dfield">
  <input type="text" size="20" name="hdcaptcha" id="hdcaptcha" value="" />
  <div class="error message" id="hdcaptcha_error" generated="true" style="display:none;position: absolute; left: 0px; top: 25px;"></div>
  </div>
  <br />
<?php 
}
?>