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;
 }
Example #2
0
				<?php 
do_settings_fields('cartopress-settings', 'cartopress_collect_info');
?>
	        	<h4>Data Sync Options</h4>
				<p>CartoPress will automatically sync the Post Title, Summary Description, Permalink, Post Date, and all Geo Data to your CartoDB account. You may also select from the following additional options. Checking these boxes will add these features to sync so they can be featured and styled in the CartoDB infobox.</p>
				<p><em>Note: Unchecking will not remove existing data from your CartoDB table. Any new data, however, will not sync.</em> </p> 
				<?php 
do_settings_fields('cartopress-settings', 'cartopress_sync_info');
?>
	        	<div id="cpdb-customfields-select">
					<h5>Custom Field Selection</h5>
					<p>Please select a custom field from the drop down menu and press the Add Custom Field button to start syncing that custom field to CartoDB. Unchecking the box under the &ldquo;Syncing&rdquo; heading will stop syncing to for that field. Clicking &ldquo;Remove&rdquo; will remove the column (and all of its data) from CartoDB.</p>
					<select id="cpdb-customfield-select-menu">
						<option value="" disabled selected id="placeholder">Select a Custom Field</option>
						<?php 
cartopress_settings::get_metakey_menu();
?>
					</select>
					<input type="button" class="button" id="add_column" name="add_column" value="Add Custom Field" />
					<div id="cpdb-customfield-display">
						<table>
							<thead>
								<tr>
									<td align="center">Syncing</td>
									<td>Custom Field Name</td>
									<td>CartoDB Column</td>
									<td align="center">Remove</td>
								</tr>
							</thead>
							<tbody><?php 
do_settings_sections('cartopress-customfields-group');
Example #3
0
        /**
         * Generates option tags for the custom field select menu
         * 
         * @since 0.1.0
         */
        public static function get_metakey_menu()
        {
            $meta_keys = cartopress_settings::generate_metakeys();
            if ($meta_keys == null) {
                echo '<option value="" disabled>You have no custom fields</option>';
            } else {
                foreach ($meta_keys as $value) {
                    $column = cartopress_settings::create_column_name($value);
                    echo '<option value="cp_post_customfield_' . $column . '" id="cp_post_customfield_' . $column . '">' . $value . '</option>
					';
                }
            }
            // end if else
        }