function edit() { global $wpdb; extract($_POST); // save if (isset($save_coupon)) { // response $response = array('status' => 'error', 'message' => __('Coupon update failed, Unknown error!', 'mgm')); // check duplicate if (mgm_is_duplicate(TBL_MGM_COUPON, array('name'), "id <> '{$id}'")) { $response['message'] = sprintf(__('Error while updating coupon: %s, same code exists!', 'mgm'), $name); } else { // fields $fields = array('name', 'value', 'description', 'use_limit', 'used_count', 'product', 'expire_dt'); // colums $column_data = $column_null_data = array(); // create value $value = $this->_set_value(); // use limit if (isset($use_limit) && is_numeric($use_limit)) { $use_limit = (int) $use_limit; } else { $use_limit = NULL; } // product if (isset($product)) { $product = json_encode($product); } else { $product = NULL; } // expire dt format if (isset($expire_dt) && !empty($expire_dt)) { $expire_dt = date('Y-m-d H:i:s', strtotime(mgm_format_inputdate_to_mysql($expire_dt, mgm_get_date_format('date_format_short')))); } else { $expire_dt = NULL; } // loop foreach ($fields as $field) { // check if (isset(${$field}) && !is_null(${$field})) { $column_data[$field] = trim(${$field}); } else { $column_null_data[$field] = 'NULL'; // need string to track } } // affected $affected = 0; // update if ($wpdb->update(TBL_MGM_COUPON, $column_data, array('id' => $id))) { $affected++; } // null if (!empty($column_null_data)) { // column_data2 $column_data2_a = mgm_implode_a(',', array_keys($column_null_data), array_values($column_null_data)); // update if ($wpdb->query("UPDATE `" . TBL_MGM_COUPON . "` SET {$column_data2_a} WHERE id='{$id}' ")) { $affected++; } } // save if ($affected) { $response = array('status' => 'success', 'message' => sprintf(__('Successfully updated coupon: "%s"', 'mgm'), $name)); } else { $response = array('status' => 'error', 'message' => sprintf(__('Error while updating coupon: "%s"', 'mgm'), $name)); } } // return response echo json_encode($response); exit; } // data $data = array(); // coupon $data['coupon'] = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . TBL_MGM_COUPON . "` WHERE id=%d", $id)); // parse $data['value_is'] = $this->_get_value($data['coupon']->value); // currency $data['currency'] = mgm_get_class('system')->setting['currency']; // load template view $this->load->template('coupons/edit', array('data' => $data)); }
function edit() { global $wpdb; extract($_POST); // save if (isset($save_addon)) { // response $response = array('status' => 'error', 'message' => __('Addon update failed, Unknown error!', 'mgm')); // check duplicate if (mgm_is_duplicate(TBL_MGM_ADDON, array('name'), "id <> '{$id}'")) { $response['message'] = sprintf(__('Error while updating addon: %s, same code exists!', 'mgm'), $name); } else { // fields $fields = array('name', 'description', 'expire_dt'); // colums $column_data = $column_null_data = array(); // expire dt format if (isset($expire_dt) && !empty($expire_dt)) { $expire_dt = date('Y-m-d H:i:s', strtotime(mgm_format_inputdate_to_mysql($expire_dt, mgm_get_date_format('date_format_short')))); } else { $expire_dt = NULL; } // loop foreach ($fields as $field) { // check if (isset(${$field}) && !is_null(${$field})) { $column_data[$field] = trim(${$field}); } else { $column_null_data[$field] = 'NULL'; // need string to track } } // affected $affected = 0; // update if ($wpdb->update(TBL_MGM_ADDON, $column_data, array('id' => $id))) { $affected++; } // null if (!empty($column_null_data)) { // column_data2 $column_data2_a = mgm_implode_a(',', array_keys($column_null_data), array_values($column_null_data)); // update if ($wpdb->query("UPDATE `" . TBL_MGM_ADDON . "` SET {$column_data2_a} WHERE `id`='{$id}' ")) { $affected++; } } // check if (!isset($addon_options)) { $addon_options = array(); } // save options if ($this->_save_addon_options($id, $addon_options, 'update')) { $affected++; } // save if ($affected) { // response $response = array('status' => 'success', 'message' => sprintf(__('Successfully updated addon: "%s"', 'mgm'), $name)); } else { $response = array('status' => 'error', 'message' => sprintf(__('Error while updating addon: "%s"', 'mgm'), $name)); } } // return response echo json_encode($response); exit; } // data $data = array(); // addon $data['addon'] = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . TBL_MGM_ADDON . "` WHERE `id`=%d", $id)); $data['addon_options'] = $wpdb->get_results($wpdb->prepare("SELECT `option`,`price` FROM `" . TBL_MGM_ADDON_OPTION . "` WHERE `addon_id`=%d", $id), ARRAY_A); // empty if (empty($data['addon_options'])) { $data['addon_options'] = array(array('option' => '', 'price' => '')); } // load template view $this->load->template('addons/edit', array('data' => $data)); }