Example #1
0
 /**
  * Delete column in CartoDB and save the settings
  *
  * AJAX handler for deleting custom field columns from the CartoDB table.
  *
  * @since 0.1.0
  * @return array $return Encoded json containing a user message, option_status boolean, cartodb status boolean
  */
 public static function cartopress_delete_column()
 {
     // checks the referer to ensure authorized access
     if (!isset($_POST['cartopress_delete_column_nonce']) || !wp_verify_nonce($_POST['cartopress_delete_column_nonce'], 'cartopress_delete_column_nonce')) {
         die('Unauthorized access denied.');
     }
     $apikey = $_POST['apikey'];
     $username = $_POST['username'];
     $tablename = $_POST['tablename'];
     $cartodb_column = $_POST['cartodb_column'];
     $custom_field = $_POST['custom_field'];
     $sql_delete_custom_col = "DO \$\$ BEGIN ALTER TABLE " . $tablename . " DROP COLUMN " . $cartodb_column . "; RAISE NOTICE 'Column Dropped'; END; \$\$";
     $result = cartopress_sync::update_cartodb($sql_delete_custom_col, $apikey, $username, true);
     $notice = $result->notices[0];
     if ($notice == "Column Dropped") {
         $message = "The CartoDB column " . $cartodb_column . " has been deleted";
         $option = cartopress_settings::update_customfield_settings(null, $cartodb_column, 'unset');
     } else {
         $message = "An error occurred and your column could not be deleted. Your settings have not been changed.";
     }
     $return = array('message' => $message, 'option_status' => $option);
     return print_r(json_encode($return));
     die;
 }