| [21] | 1 | <?php |
|---|
| 2 | |
|---|
| 3 | // Parse the parameters from the Ajax.Request |
|---|
| 4 | |
|---|
| 5 | //if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { |
|---|
| 6 | require( dirname(__FILE__) . '/../../../../wp-config.php' ); |
|---|
| 7 | if (!(is_user_logged_in() && current_user_can('edit_posts'))) |
|---|
| 8 | die("Athentication failed!"); |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | global $wpdb, $canvas; |
|---|
| 12 | $parent = $_GET['parent']; |
|---|
| 13 | $template_name = $_GET['template_name']; |
|---|
| 14 | $template_size = $_GET['template_size']; |
|---|
| 15 | $listitems = array(); |
|---|
| 16 | |
|---|
| 17 | $wpdb->query("UPDATE ".$canvas->main." |
|---|
| 18 | SET template_name='$template_name', |
|---|
| 19 | template_size='$template_size' |
|---|
| 20 | WHERE block_id='$parent'"); |
|---|
| 21 | |
|---|
| 22 | // Save the new values to the database |
|---|
| 23 | foreach ($_GET as $key => $value) { |
|---|
| 24 | $key = trim(urldecode($key)); |
|---|
| 25 | $value = trim(urldecode($value)); |
|---|
| 26 | |
|---|
| 27 | if (($key != "_")&&($key != "parent")&&($key != "checked")) { |
|---|
| 28 | if(strstr($key, 'canvaslist')) { |
|---|
| 29 | $key = preg_replace('/^([0-9]*)canvaslist_/','',$key); |
|---|
| 30 | if(!in_array($key, $listitems)) $listitems[] = $key; |
|---|
| 31 | $$key .= $value."|"; |
|---|
| 32 | continue; |
|---|
| 33 | } |
|---|
| 34 | if($var_id = $wpdb->get_var("SELECT variable_id FROM ".$canvas->variables." WHERE variable_name = '$key' AND parent='$parent'")) { |
|---|
| 35 | $wpdb->query("UPDATE ".$canvas->variables." SET value='$value' WHERE variable_name='$key' AND parent='$parent'"); |
|---|
| 36 | $updated_vars[] = $var_id; |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | // Handle list items |
|---|
| 42 | if($listitems) { |
|---|
| 43 | foreach($listitems as $item) { |
|---|
| 44 | $new_value = preg_replace('/(\|*)$/', '', $$item); |
|---|
| 45 | $wpdb->query("UPDATE ".$canvas->variables." SET value='$new_value' WHERE variable_name='$item' AND parent='$parent'"); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | // Save any values that weren't passed in the GET string, eg. empty checkboxes |
|---|
| 50 | $variables = $wpdb->get_results("SELECT variable_id,type FROM ".$canvas->variables." WHERE parent='$parent' AND variable_id NOT IN ('".implode("','", $updated_vars)."')"); |
|---|
| 51 | |
|---|
| 52 | if (!empty($variables)) { |
|---|
| 53 | foreach ($variables as $variable) { |
|---|
| 54 | // Here's where we define what the default "false" value is for each variable type |
|---|
| 55 | switch ($variable->type) { |
|---|
| 56 | case "Boolean": |
|---|
| 57 | $wpdb->query("UPDATE ".$canvas->variables." SET value='0' WHERE variable_id='$variable->variable_id'"); |
|---|
| 58 | break; |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | //} |
|---|
| 63 | ?> |
|---|