| 1 |
<?php |
| 2 |
function usces_get_post_meta_by_metaid( $meta_id ) { |
| 3 |
global $wpdb; |
| 4 |
$res = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id), ARRAY_A); |
| 5 |
return $res; |
| 6 |
} |
| 7 |
function usces_get_post_meta( $post_id, $key ) { |
| 8 |
global $wpdb; |
| 9 |
$res = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $key), ARRAY_A); |
| 10 |
return $res; |
| 11 |
} |
| 12 |
function usces_sort_post_meta( $post_id, $metastr ) { |
| 13 |
global $wpdb; |
| 14 |
$meta_ids = explode(',', $metastr); |
| 15 |
if( !empty($meta_ids) ){ |
| 16 |
$i = 0; |
| 17 |
foreach( $meta_ids as $meta_id ){ |
| 18 |
|
| 19 |
$rows = usces_get_post_meta_by_metaid( $meta_id ); |
| 20 |
$values = unserialize($rows['meta_value']); |
| 21 |
$values['sort'] = $i; |
| 22 |
$serialized_values = serialize($values); |
| 23 |
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $rows['meta_id']) ); |
| 24 |
$i++; |
| 25 |
} |
| 26 |
} |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* item option |
| 32 |
*/ |
| 33 |
//function has_item_option_meta( $postid ) { |
| 34 |
function usces_get_opts( $post_id, $keyflag = 'sort' ) { |
| 35 |
$opts = array(); |
| 36 |
$metas = usces_get_post_meta($post_id, '_iopt_'); |
| 37 |
|
| 38 |
if( empty($metas) ) return $opts; |
| 39 |
|
| 40 |
foreach( $metas as $rows ){ |
| 41 |
$values = unserialize($rows['meta_value']); |
| 42 |
$key = isset($values[$keyflag]) ? $values[$keyflag] : $values['sort']; |
| 43 |
$opts[$key] = array( |
| 44 |
'meta_id' => $rows['meta_id'], |
| 45 |
'name' => $values['name'], |
| 46 |
'means' => $values['means'], |
| 47 |
'essential' => $values['essential'], |
| 48 |
'value' => $values['value'], |
| 49 |
'sort' => $values['sort'] |
| 50 |
); |
| 51 |
} |
| 52 |
ksort($opts); |
| 53 |
|
| 54 |
return $opts; |
| 55 |
} |
| 56 |
function usces_add_opt( $post_id, $newvalue, $check = true ) { |
| 57 |
global $wpdb, $usces; |
| 58 |
if( $check ){ |
| 59 |
$metas = usces_get_post_meta($post_id, '_iopt_'); |
| 60 |
if( !empty($metas) ){ |
| 61 |
$meta_num = count($metas); |
| 62 |
$unique = true; |
| 63 |
$sortnull = true; |
| 64 |
foreach( $metas as $meta ){ |
| 65 |
$values = unserialize($meta['meta_value']); |
| 66 |
if( $values['name'] == $newvalue['name'] ) |
| 67 |
$unique = false; |
| 68 |
if( !isset($values['sort']) ) |
| 69 |
$sortnull = false; |
| 70 |
$sort[] = $values['sort']; |
| 71 |
} |
| 72 |
if( !$unique ) |
| 73 |
return -1; |
| 74 |
|
| 75 |
rsort($sort); |
| 76 |
$next_number = reset($sort) + 1; |
| 77 |
$unique_sort = array_unique($sort); |
| 78 |
if( $meta_num !== count($unique_sort) || $meta_num !== $next_number || !$sortnull){ |
| 79 |
//To repair the sort data |
| 80 |
$i = 0; |
| 81 |
foreach( $metas as $rows ){ |
| 82 |
$values = unserialize($rows['meta_value']); |
| 83 |
$values['sort'] = $i; |
| 84 |
$serialized_values = serialize($values); |
| 85 |
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $rows['meta_id']) ); |
| 86 |
$i++; |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
$newvalue['sort'] = !empty($meta_num) ? $meta_num : 0; |
| 91 |
} |
| 92 |
$serialized_newvalue = serialize($newvalue); |
| 93 |
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value ) VALUES (%d, '_iopt_', %s)", $post_id, $serialized_newvalue) ); |
| 94 |
$id = $wpdb->insert_id; |
| 95 |
return $id; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* item sku |
| 100 |
*/ |
| 101 |
function usces_add_sku( $post_id, $newvalue, $check = true ) { |
| 102 |
global $wpdb, $usces; |
| 103 |
if( $check ){ |
| 104 |
$metas = usces_get_post_meta($post_id, '_isku_'); |
| 105 |
if( !empty($metas) ){ |
| 106 |
$meta_num = count($metas); |
| 107 |
$unique = true; |
| 108 |
$sortnull = true; |
| 109 |
foreach( $metas as $rows ){ |
| 110 |
$values = unserialize($rows['meta_value']); |
| 111 |
if( $values['code'] == $newvalue['code'] ) |
| 112 |
$unique = false; |
| 113 |
if( !isset($values['sort']) ) |
| 114 |
$sortnull = false; |
| 115 |
$sort[] = $values['sort']; |
| 116 |
} |
| 117 |
if( !$unique ) |
| 118 |
return -1; |
| 119 |
|
| 120 |
rsort($sort); |
| 121 |
$next_number = $sort[0] + 1; |
| 122 |
$unique_sort = array_unique($sort); |
| 123 |
if( $meta_num != count($unique_sort) || $meta_num != $next_number || !$sortnull){ |
| 124 |
//To repair the sort data |
| 125 |
$i = 0; |
| 126 |
foreach( $metas as $rows ){ |
| 127 |
$values = unserialize($rows['meta_value']); |
| 128 |
$values['sort'] = $i; |
| 129 |
$serialized_values = serialize($values); |
| 130 |
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $rows['meta_id']) ); |
| 131 |
$i++; |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
$newvalue['sort'] = !empty($meta_num) ? $meta_num : 0; |
| 136 |
} |
| 137 |
$newvalue = $usces->stripslashes_deep_post($newvalue); |
| 138 |
$serialized_newvalue = serialize($newvalue); |
| 139 |
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value ) VALUES (%d, '_isku_', %s)", $post_id, $serialized_newvalue) ); |
| 140 |
$id = $wpdb->insert_id; |
| 141 |
return $id; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
/** |
| 146 |
* list_item_option |
| 147 |
*/ |
| 148 |
function list_item_option_meta( $opts ) { |
| 149 |
// Exit if no meta |
| 150 |
if ( ! $opts ) { |
| 151 |
?> |
| 152 |
<table id="optlist-table" class="list" style="display: none;"> |
| 153 |
<thead> |
| 154 |
<tr> |
| 155 |
<th class="hanldh"> </th> |
| 156 |
<th class="item-opt-key"><?php _e('option name','usces') ?></th> |
| 157 |
<th class="item-opt-value"><?php _e('selected amount','usces') ?></th> |
| 158 |
</tr> |
| 159 |
</thead> |
| 160 |
<tbody id="item-opt-list"> |
| 161 |
<tr><td></td></tr> |
| 162 |
</tbody> |
| 163 |
</table> |
| 164 |
<?php |
| 165 |
}else{ |
| 166 |
?> |
| 167 |
<table id="optlist-table" class="list"> |
| 168 |
<thead> |
| 169 |
<tr> |
| 170 |
<th class="hanldh"> </th> |
| 171 |
<th class="item-opt-key"><?php _e('option name','usces') ?></th> |
| 172 |
<th class="item-opt-value"><?php _e('selected amount','usces') ?></th> |
| 173 |
</tr> |
| 174 |
</thead> |
| 175 |
<tbody id="item-opt-list"> |
| 176 |
<?php |
| 177 |
foreach ( $opts as $opt ) |
| 178 |
echo _list_item_option_meta_row( $opt ); |
| 179 |
?> |
| 180 |
</tbody> |
| 181 |
</table> |
| 182 |
<?php |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* list_item_sku |
| 188 |
*/ |
| 189 |
function list_item_sku_meta( $skus ) { |
| 190 |
// Exit if no meta |
| 191 |
if ( empty( $skus ) ) { |
| 192 |
?> |
| 193 |
<table id="skulist-table" class="list" style="display: none;"> |
| 194 |
<thead> |
| 195 |
<tr> |
| 196 |
<th class="hanldh" rowspan="2"> </th> |
| 197 |
<th><?php _e('SKU code','usces'); ?></th> |
| 198 |
<th><?php echo apply_filters('usces_filter_listprice_label', __('normal price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> |
| 199 |
<th><?php echo apply_filters('usces_filter_sellingprice_label', __('Sale price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> |
| 200 |
<th><?php _e('stock','usces'); ?></th> |
| 201 |
<th><?php _e('stock status', 'usces'); ?></th> |
| 202 |
</tr> |
| 203 |
</thead> |
| 204 |
<tbody id="item-sku-list"> |
| 205 |
<tr><td></td><td></td><td></td><td></td><td></td></tr> |
| 206 |
</tbody> |
| 207 |
</table> |
| 208 |
<?php |
| 209 |
}else{ |
| 210 |
?> |
| 211 |
<table id="skulist-table" class="list"> |
| 212 |
<thead> |
| 213 |
<tr> |
| 214 |
<th class="hanldh" rowspan="2"> </th> |
| 215 |
<th class="item-sku-key"><?php _e('SKU code','usces'); ?></th> |
| 216 |
<th class="item-sku-cprice"><?php echo apply_filters('usces_filter_listprice_label', __('normal price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> |
| 217 |
<th class="item-sku-price"><?php echo apply_filters('usces_filter_sellingprice_label', __('Sale price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> |
| 218 |
<th class="item-sku-zaikonum"><?php _e('stock','usces'); ?></th> |
| 219 |
<th class="item-sku-zaiko"><?php _e('stock status','usces'); ?></th> |
| 220 |
</tr> |
| 221 |
<tr> |
| 222 |
<th><?php _e('SKU display name ','usces'); ?></th> |
| 223 |
<th><?php _e('unit','usces'); ?></th> |
| 224 |
<?php |
| 225 |
$advance_title = '<th colspan="2"> </th>'; |
| 226 |
echo apply_filters('usces_filter_sku_meta_form_advance_title', $advance_title); |
| 227 |
?> |
| 228 |
<th><?php _e('Apply business package','usces'); ?></th> |
| 229 |
</tr> |
| 230 |
</thead> |
| 231 |
<tbody id="item-sku-list"> |
| 232 |
<?php |
| 233 |
foreach ( $skus as $sku ) |
| 234 |
echo _list_item_sku_meta_row( $sku ); |
| 235 |
?> |
| 236 |
</tbody> |
| 237 |
</table> |
| 238 |
<?php |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
/** |
| 245 |
* option meta row |
| 246 |
*/ |
| 247 |
function _list_item_option_meta_row( $opt ) { |
| 248 |
$r = ''; |
| 249 |
$style = ''; |
| 250 |
$means = get_option('usces_item_option_select'); |
| 251 |
|
| 252 |
// $opt['meta_value'] = unserialize( $opt['meta_value'] ); |
| 253 |
|
| 254 |
$name = esc_attr($opt['name']); |
| 255 |
$meansoption = ''; |
| 256 |
foreach($means as $meankey => $meanvalue){ |
| 257 |
if($meankey == $opt['means']) { |
| 258 |
$selected = ' selected="selected"'; |
| 259 |
}else{ |
| 260 |
$selected = ''; |
| 261 |
} |
| 262 |
$meansoption .= '<option value="' . esc_attr($meankey) . '"' . $selected . '>' . esc_html($meanvalue) . "</option>\n"; |
| 263 |
} |
| 264 |
$essential = $opt['essential'] == 1 ? " checked='checked'" : ""; |
| 265 |
$value = ''; |
| 266 |
if(is_array($opt['value'])){ |
| 267 |
foreach($opt['value'] as $k => $v){ |
| 268 |
$value .= $v . "\n"; |
| 269 |
} |
| 270 |
}else{ |
| 271 |
//$value = esc_attr(trim($opt['value'])); |
| 272 |
$value = $opt['value']; |
| 273 |
} |
| 274 |
$value = trim($value); |
| 275 |
$id = (int) $opt['meta_id']; |
| 276 |
$sort = (int) $opt['sort']; |
| 277 |
|
| 278 |
ob_start(); |
| 279 |
?> |
| 280 |
<tr class="metastuffrow"><td colspan="3"> |
| 281 |
<table id="itemopt-<?php echo $id; ?>" class="metastufftable"> |
| 282 |
<tr> |
| 283 |
<th class='handlb' rowspan='2'> </th> |
| 284 |
<td class='item-opt-key'> |
| 285 |
<div><input name='itemopt[<?php echo $id; ?>][name]' id='itemopt[<?php echo $id; ?>][name]' class='metaboxfield' type='text' size='20' value='<?php echo $name; ?>' /></div> |
| 286 |
<div class='optcheck'> |
| 287 |
<select name='itemopt[<?php echo $id; ?>][means]' id='itemopt[<?php echo $id; ?>][means]'><?php echo $meansoption; ?></select> |
| 288 |
<label for='itemopt[<?php echo $id; ?>][essential]'><input name='itemopt[<?php echo $id; ?>][essential]' id='itemopt[<?php echo $id; ?>][essential]' type='checkbox' value='1'<?php echo $essential; ?> class='metaboxcheckfield' /><?php _e('Required','usces'); ?></label> |
| 289 |
</div> |
| 290 |
</td> |
| 291 |
<td class='item-opt-value'> |
| 292 |
<textarea name='itemopt[<?php echo $id; ?>][value]' id='itemopt[<?php echo $id; ?>][value]' class='metaboxfield'><?php echo esc_html($value); ?></textarea> |
| 293 |
</td> |
| 294 |
</tr> |
| 295 |
<tr> |
| 296 |
<td colspan='2' class='submittd'> |
| 297 |
<div id='itemoptsubmit-<?php echo $id; ?>' class='submit'> |
| 298 |
<input name='deleteitemopt[<?php echo $id; ?>]' id='deleteitemopt[<?php echo $id; ?>]' type='button' value='<?php esc_attr_e(__( 'Delete' )); ?>' onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('deleteitemopt', <?php echo $id; ?>);" /> |
| 299 |
<input name='updateitemopt[<?php echo $id; ?>]' id='updateitemopt[<?php echo $id; ?>]' type='button' value='<?php esc_attr_e(__( 'Update' )); ?>' onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('updateitemopt', <?php echo $id; ?>);" /> |
| 300 |
<input name='itemopt[<?php echo $id; ?>][sort]' id='itemopt[<?php echo $id; ?>][sort]' type='hidden' value='<?php echo $sort; ?>' /> |
| 301 |
</div> |
| 302 |
<div id='itemopt_loading-<?php echo $id; ?>' class='meta_submit_loading'></div> |
| 303 |
</td> |
| 304 |
</tr> |
| 305 |
</table> |
| 306 |
</td></tr> |
| 307 |
<?php |
| 308 |
$r = ob_get_contents(); |
| 309 |
ob_end_clean(); |
| 310 |
return $r; |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* sku meta row |
| 315 |
*/ |
| 316 |
function _list_item_sku_meta_row( $sku ) { |
| 317 |
$r = ''; |
| 318 |
$style = ''; |
| 319 |
|
| 320 |
$key = esc_attr($sku['code']); |
| 321 |
$cprice = $sku['cprice']; |
| 322 |
$price = $sku['price']; |
| 323 |
$zaikonum = $sku['stocknum']; |
| 324 |
$zaiko = $sku['stock']; |
| 325 |
$skudisp = esc_attr($sku['name']); |
| 326 |
$skuunit = esc_attr($sku['unit']); |
| 327 |
$skugptekiyo = $sku['gp']; |
| 328 |
//$charging_type = $sku['meta_value']['charging_type']; |
| 329 |
$id = (int)$sku['meta_id']; |
| 330 |
$zaikoselectarray = get_option('usces_zaiko_status'); |
| 331 |
$sort = (int) $sku['sort']; |
| 332 |
|
| 333 |
ob_start(); |
| 334 |
?> |
| 335 |
<tr class='metastuffrow'><td colspan='6'> |
| 336 |
<table id='itemsku-<?php echo $id; ?>' class='metastufftable'> |
| 337 |
<tr> |
| 338 |
<th class='handlb' rowspan='<?php echo apply_filters( 'usces_filter_sku_meta_rowspan', '3' ); ?>'> </th> |
| 339 |
<td class='item-sku-key'><input name='itemsku[<?php echo $id; ?>][key]' id='itemsku[<?php echo $id; ?>][key]' class='skuname metaboxfield' type='text' value='<?php echo $key; ?>' /></td> |
| 340 |
<td class='item-sku-cprice'><input name='itemsku[<?php echo $id; ?>][cprice]' id='itemsku[<?php echo $id; ?>][cprice]' class='skuprice metaboxfield' type='text' value='<?php echo $cprice; ?>' /></td> |
| 341 |
<td class='item-sku-price'><input name='itemsku[<?php echo $id; ?>][price]' id='itemsku[<?php echo $id; ?>][price]' class='skuprice metaboxfield' type='text' value='<?php echo $price; ?>' /></td> |
| 342 |
<td class='item-sku-zaikonum'><input name='itemsku[<?php echo $id; ?>][zaikonum]' id='itemsku[<?php echo $id; ?>][zaikonum]' class='skuzaikonum metaboxfield' type='text' value='<?php echo $zaikonum; ?>' /></td> |
| 343 |
<td class='item-sku-zaiko'> |
| 344 |
<select id='itemsku[<?php echo $id; ?>][zaiko]' name='itemsku[<?php echo $id; ?>][zaiko]' class='skuzaiko metaboxfield'> |
| 345 |
<?php |
| 346 |
for ( $i=0; $i<count($zaikoselectarray); $i++ ) { |
| 347 |
$selected = ( $i == $zaiko ) ? " selected='selected'" : ''; |
| 348 |
?> |
| 349 |
<option value='<?php echo $i; ?>'<?php echo $selected; ?>><?php echo $zaikoselectarray[$i]; ?></option> |
| 350 |
<?php |
| 351 |
} |
| 352 |
?> |
| 353 |
</select> |
| 354 |
</td> |
| 355 |
</tr> |
| 356 |
<tr> |
| 357 |
<td class='item-sku-key'><input name='itemsku[<?php echo $id; ?>][skudisp]' id='itemsku[<?php echo $id; ?>][skudisp]' class='skudisp metaboxfield' type='text' value='<?php echo $skudisp; ?>' /> |
| 358 |
</td> |
| 359 |
<td class='item-sku-cprice'><input name='itemsku[<?php echo $id; ?>][skuunit]' id='itemsku[<?php echo $id; ?>][skuunit]' class='skuunit metaboxfield' type='text' value='<?php echo $skuunit; ?>' /></td> |
| 360 |
<?php |
| 361 |
$default_field = "\n\t\t<td colspan='2'> </td>"; |
| 362 |
echo apply_filters('usces_filter_sku_meta_row_advance', $default_field, $sku); |
| 363 |
?> |
| 364 |
<td class='item-sku-zaiko'> |
| 365 |
<select id='itemsku[<?php echo $id; ?>][skugptekiyo]' name='itemsku[<?php echo $id; ?>][skugptekiyo]' class='skugptekiyo metaboxfield'> |
| 366 |
<option value='0' <?php echo ($skugptekiyo == 0 ? " selected='selected'" : ""); ?>><?php _e('Not apply','usces'); ?></option> |
| 367 |
<option value='1' <?php echo ($skugptekiyo == 1 ? " selected='selected'" : ""); ?>><?php _e('Apply','usces'); ?></option> |
| 368 |
</select> |
| 369 |
</td> |
| 370 |
</tr> |
| 371 |
<?php echo apply_filters( 'usces_filter_sku_meta_row', '', $sku ); ?> |
| 372 |
<tr> |
| 373 |
<td colspan='5' class='submittd'> |
| 374 |
<div id='skusubmit-<?php echo $id; ?>' class='submit'> |
| 375 |
<input name='deleteitemsku[<?php echo $id; ?>]' id='deleteitemsku[<?php echo $id; ?>]' type='button' value='<?php esc_attr_e(__( 'Delete' )) ?>' onclick="if( jQuery('#post_ID').val() < 0 ) return; itemSku.post('deleteitemsku', <?php echo $id; ?>);" /> |
| 376 |
<input name='updateitemsku[<?php echo $id; ?>]' id='updateitemsku[<?php echo $style; ?>]' type='button' value='<?php esc_attr_e(__( 'Update' )); ?>' onclick="if( jQuery('#post_ID').val() < 0 ) return; itemSku.post('updateitemsku', <?php echo $id; ?>);" /> |
| 377 |
<input name='itemsku[<?php echo $id; ?>][sort]' id='itemsku[<?php echo $id; ?>][sort]' type='hidden' value='<?php echo $sort; ?>' /> |
| 378 |
</div> |
| 379 |
<div id='itemsku_loading-<?php echo $id; ?>' class='meta_submit_loading'></div> |
| 380 |
</td> |
| 381 |
</tr> |
| 382 |
</table> |
| 383 |
</td></tr> |
| 384 |
<?php |
| 385 |
$r = ob_get_contents(); |
| 386 |
ob_end_clean(); |
| 387 |
return $r; |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
/** |
| 392 |
* common_option_meta_form |
| 393 |
*/ |
| 394 |
function common_option_meta_form() { |
| 395 |
$means = get_option('usces_item_option_select'); |
| 396 |
$meansoption = ''; |
| 397 |
foreach($means as $meankey => $meanvalue){ |
| 398 |
$meansoption .= '<option value="' . esc_attr($meankey) . '">' . esc_html($meanvalue) . "</option>\n"; |
| 399 |
} |
| 400 |
?> |
| 401 |
<div id="itemopt_ajax-response"></div> |
| 402 |
<p><strong><?php _e('Add a new option','usces') ?> : </strong></p> |
| 403 |
<table id="newmeta2"> |
| 404 |
<thead> |
| 405 |
<tr> |
| 406 |
<th class="left"><label for="metakeyselect"><?php _e('option name','usces') ?></label></th> |
| 407 |
<th><label for="metavalue"><?php _e('selected amount','usces') ?></label></th> |
| 408 |
</tr> |
| 409 |
</thead> |
| 410 |
|
| 411 |
<tbody> |
| 412 |
<tr> |
| 413 |
<td class='item-opt-key'> |
| 414 |
<input type="text" id="newoptname" name="newoptname" class="metaboxfield" tabindex="7" value="" /> |
| 415 |
<div class="optcheck"> |
| 416 |
<select name='newoptmeans' id='newoptmeans' class="metaboxfield long"><?php echo $meansoption; ?></select> |
| 417 |
<label for='newoptessential'><input name="newoptessential" type="checkbox" id="newoptessential" class="metaboxcheckfield" /><?php _e('Required','usces') ?></label> |
| 418 |
</div> |
| 419 |
</td> |
| 420 |
<td class='item-opt-value'><textarea id="newoptvalue" name="newoptvalue" class='metaboxfield'></textarea></td> |
| 421 |
</tr> |
| 422 |
|
| 423 |
<tr> |
| 424 |
<td colspan="2" class="submittd"> |
| 425 |
<div id='newcomoptsubmit' class='submit'> |
| 426 |
<input name="add_comopt" type="button" id="add_comopt" tabindex="9" value="<?php _e('Add common options','usces') ?>" onclick="itemOpt.post('addcommonopt', 0);" /> |
| 427 |
</div> |
| 428 |
<div id="newcomopt_loading" class="meta_submit_loading"></div> |
| 429 |
</td> |
| 430 |
</tr> |
| 431 |
</tbody> |
| 432 |
</table> |
| 433 |
<?php |
| 434 |
} |
| 435 |
|
| 436 |
/** |
| 437 |
* item_option_meta_form |
| 438 |
*/ |
| 439 |
function item_option_meta_form() { |
| 440 |
global $wpdb; |
| 441 |
$usces_options = get_option('usces'); |
| 442 |
$limit = (int) apply_filters( 'postmeta_form_limit', 30 ); |
| 443 |
$cart_number = (int)get_option('usces_cart_number'); |
| 444 |
$opts = usces_get_opts($cart_number); |
| 445 |
$means = get_option('usces_item_option_select'); |
| 446 |
$meansoption = ''; |
| 447 |
foreach($means as $meankey => $meanvalue){ |
| 448 |
$meansoption .= '<option value="' . esc_attr($meankey) . '">' . esc_html($meanvalue) . "</option>\n"; |
| 449 |
} |
| 450 |
?> |
| 451 |
<div id="itemopt_ajax-response"></div> |
| 452 |
<p><strong><?php _e('Applicable product options','usces') ?> : </strong></p> |
| 453 |
<table id="newmeta2"> |
| 454 |
<thead> |
| 455 |
<tr> |
| 456 |
<th class="item-opt-key"><label for="metakeyselect"><?php _e('option name','usces') ?></label></th> |
| 457 |
<th class="item-opt-value"><label for="metavalue"><?php _e('selected amount','usces') ?></label></th> |
| 458 |
</tr> |
| 459 |
</thead> |
| 460 |
|
| 461 |
<tbody> |
| 462 |
<tr> |
| 463 |
<td class='item-opt-key'> |
| 464 |
<?php if ( !empty($opts) ) { ?> |
| 465 |
<select id="optkeyselect" name="optkeyselect" class="optkeyselect metaboxfield" tabindex="7" onchange="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('keyselect', this.value);"> |
| 466 |
<option value="#NONE#"><?php _e( '-- Select --','usces' ); ?></option> |
| 467 |
<?php foreach ( $opts as $opt ){ ?> |
| 468 |
<option value='<?php echo $opt['meta_id']; ?>'><?php esc_attr_e($opt['name']); ?></option> |
| 469 |
<?php } ?> |
| 470 |
</select> |
| 471 |
<input type="hidden" id="newoptname" name="newoptname" class="metaboxfield" /> |
| 472 |
<div class="optcheck"> |
| 473 |
<select name='newoptmeans' id='newoptmeans'><?php echo $meansoption; ?></select> |
| 474 |
<label for='newoptessential'><input name="newoptessential" type="checkbox" id="newoptessential" class="metaboxcheckfield" /><?php _e('Required','usces') ?></label> |
| 475 |
</div> |
| 476 |
<?php } else { ?> |
| 477 |
<p><?php _e('Please create a common option.','usces') ?></p> |
| 478 |
<?php } ?> |
| 479 |
</td> |
| 480 |
<td class='item-opt-value'><textarea id="newoptvalue" name="newoptvalue" class='metaboxfield'></textarea></td> |
| 481 |
</tr> |
| 482 |
|
| 483 |
<tr> |
| 484 |
<td colspan="2" class="submittd"> |
| 485 |
<?php if( is_array($opts) ) { ?> |
| 486 |
<div id='newitemoptsubmit' class='submit'> |
| 487 |
<input name="add_itemopt" type="button" id="add_itemopt" tabindex="9" value="<?php _e('Apply an option','usces') ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('additemopt', 0);" /> |
| 488 |
</div> |
| 489 |
<div id="newitemopt_loading" class="meta_submit_loading"></div> |
| 490 |
<?php } ?> |
| 491 |
</td> |
| 492 |
</tr> |
| 493 |
</tbody> |
| 494 |
</table> |
| 495 |
<?php |
| 496 |
} |
| 497 |
|
| 498 |
/** |
| 499 |
* item_sku_meta_form |
| 500 |
*/ |
| 501 |
function item_sku_meta_form() { |
| 502 |
?> |
| 503 |
<div id="sku_ajax-response"></div> |
| 504 |
<p><strong><?php _e('Add new SKU','usces') ?> : </strong></p> |
| 505 |
<table id="newsku"> |
| 506 |
<thead> |
| 507 |
<tr> |
| 508 |
<th class="left"><?php _e('SKU code','usces') ?></th> |
| 509 |
<th><?php echo apply_filters('usces_filter_listprice_label', __('normal price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> |
| 510 |
<th><?php echo apply_filters('usces_filter_sellingprice_label', __('Sale price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> |
| 511 |
<th><?php _e('stock','usces') ?></th> |
| 512 |
<th><?php _e('stock status','usces') ?></th> |
| 513 |
</tr> |
| 514 |
<tr> |
| 515 |
<th><?php _e('SKU display name ','usces') ?></th> |
| 516 |
<th><?php _e('unit','usces') ?></th> |
| 517 |
<?php |
| 518 |
$advance_title = '<th colspan="2"> </th>'; |
| 519 |
echo apply_filters('usces_filter_sku_meta_form_advance_title', $advance_title); |
| 520 |
?> |
| 521 |
<th><?php _e('Apply business package','usces') ?></th> |
| 522 |
</tr> |
| 523 |
</thead> |
| 524 |
|
| 525 |
<tbody> |
| 526 |
<tr> |
| 527 |
<td id="newskuleft" class='item-sku-key'><input type="text" id="newskuname" name="newskuname" class="newskuname metaboxfield"value="" /></td> |
| 528 |
<td class='item-sku-cprice'><input type="text" id="newskucprice" name="newskucprice" class='newskuprice metaboxfield' /></td> |
| 529 |
<td class='item-sku-price'><input type="text" id="newskuprice" name="newskuprice" class='newskuprice metaboxfield' /></td> |
| 530 |
<td class='item-sku-zaikonum'><input type="text" id="newskuzaikonum" name="newskuzaikonum" class='newskuzaikonum metaboxfield' /></td> |
| 531 |
<td class='item-sku-zaiko'> |
| 532 |
<select id="newskuzaikoselect" name="newskuzaikoselect" class="newskuzaikoselect metaboxfield"> |
| 533 |
<?php |
| 534 |
$zaikoselectarray = get_option('usces_zaiko_status'); |
| 535 |
foreach ( $zaikoselectarray as $v => $l ) { |
| 536 |
echo "\n<option value='" . esc_attr($v) . "'>" . esc_html($l) . "</option>"; |
| 537 |
} |
| 538 |
?> |
| 539 |
</select> |
| 540 |
</td> |
| 541 |
</tr> |
| 542 |
<tr> |
| 543 |
<td class='item-sku-key'><input type="text" id="newskudisp" name="newskudisp" class="newskudisp metaboxfield" /></td> |
| 544 |
<td class='item-sku-cprice'><input type="text" id="newskuunit" name="newskuunit" class='newskuunit metaboxfield' /></td> |
| 545 |
<?php |
| 546 |
$advance_field = '<td class="item-sku-price"> </td><td class="item-sku-zaikonum"> </td>'; |
| 547 |
echo apply_filters('usces_filter_sku_meta_form_advance_field', $advance_field ); |
| 548 |
?> |
| 549 |
<td class='item-sku-zaiko'> |
| 550 |
<select id="newskugptekiyo" name="newskugptekiyo" class="newskugptekiyo metaboxfield"> |
| 551 |
<option value="0"><?php _e('Not apply','usces') ?></option> |
| 552 |
<option value="1"><?php _e('Apply','usces') ?></option> |
| 553 |
</select> |
| 554 |
</td> |
| 555 |
</tr> |
| 556 |
<?php echo apply_filters( 'usces_filter_newsku_meta_row', '' ); ?> |
| 557 |
<tr> |
| 558 |
<td colspan="5" class="submittd"> |
| 559 |
<div id='newskusubmit' class='submit'><input name="add_itemsku" type="button" id="add_itemsku" tabindex="9" value="<?php _e('Add SKU','usces') ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemSku.post('additemsku', 0);" /></div> |
| 560 |
<div id="newitemsku_loading" class="meta_submit_loading"></div> |
| 561 |
</td> |
| 562 |
</tr> |
| 563 |
</tbody> |
| 564 |
</table> |
| 565 |
<?php |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
// |
| 570 |
// Post Meta |
| 571 |
// |
| 572 |
|
| 573 |
/** |
| 574 |
* add_item_option_meta |
| 575 |
*/ |
| 576 |
function add_item_option_meta( $post_ID ) { |
| 577 |
global $usces; |
| 578 |
|
| 579 |
$post_ID = (int) $post_ID; |
| 580 |
$value = array(); |
| 581 |
$opts = array(); |
| 582 |
$protected = array( '#NONE#', '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); |
| 583 |
|
| 584 |
$newoptname = isset($_POST['newoptname']) ? trim( $_POST['newoptname'] ) : ''; |
| 585 |
$newoptmeans = isset($_POST['newoptmeans']) ? (int)$_POST['newoptmeans']: 0; |
| 586 |
$newoptessential = isset($_POST['newoptessential']) ? $_POST['newoptessential']: 0; |
| 587 |
$newoptvalue = isset($_POST['newoptvalue']) ? trim($_POST['newoptvalue']) : ''; |
| 588 |
|
| 589 |
if ( ($newoptmeans >= 2 || WCUtils::is_zero($newoptvalue) || !empty ( $newoptvalue )) && !empty ( $newoptname) ) { |
| 590 |
|
| 591 |
if ( $newoptname ) |
| 592 |
$metakey = $newoptname; // default |
| 593 |
|
| 594 |
if ( in_array($metakey, $protected) ) |
| 595 |
return false; |
| 596 |
|
| 597 |
wp_cache_delete($post_ID, 'post_meta'); |
| 598 |
|
| 599 |
$value['name'] = str_replace("\\",'',$newoptname); |
| 600 |
$value['means'] = $newoptmeans; |
| 601 |
$value['essential'] = $newoptessential; |
| 602 |
$value['value'] = str_replace("\\",'',$newoptvalue); |
| 603 |
$value = $usces->stripslashes_deep_post($value); |
| 604 |
|
| 605 |
$id = usces_add_opt($post_ID, $value); |
| 606 |
|
| 607 |
return $id; |
| 608 |
} |
| 609 |
return false; |
| 610 |
} // add_meta |
| 611 |
|
| 612 |
/** |
| 613 |
* add_item_sku_meta |
| 614 |
*/ |
| 615 |
function add_item_sku_meta( $post_ID ) { |
| 616 |
global $usces; |
| 617 |
|
| 618 |
$post_ID = (int) $post_ID; |
| 619 |
$value = array(); |
| 620 |
$skus = array(); |
| 621 |
$protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); |
| 622 |
|
| 623 |
$newskuname = isset($_POST['newskuname']) ? trim( $_POST['newskuname'] ) : ''; |
| 624 |
$newskucprice = isset($_POST['newskucprice']) ? $_POST['newskucprice']: ''; |
| 625 |
$newskuprice = isset($_POST['newskuprice']) ? $_POST['newskuprice']: ''; |
| 626 |
$newskuzaikonum = isset($_POST['newskuzaikonum']) ? $_POST['newskuzaikonum']: ''; |
| 627 |
$newskuzaikoselect = isset($_POST['newskuzaikoselect']) ? $_POST['newskuzaikoselect'] : ''; |
| 628 |
$newskudisp = isset($_POST['newskudisp']) ? trim( $_POST['newskudisp'] ) : ''; |
| 629 |
$newskuunit = isset($_POST['newskuunit']) ? trim( $_POST['newskuunit'] ) : ''; |
| 630 |
$newskugptekiyo = isset($_POST['newskugptekiyo']) ? $_POST['newskugptekiyo'] : ''; |
| 631 |
|
| 632 |
if ( !WCUtils::is_blank($newskuname) && !WCUtils::is_blank($newskuprice) && !WCUtils::is_blank($newskuzaikoselect) ) { |
| 633 |
|
| 634 |
if ( in_array($newskuname, $protected) ) |
| 635 |
return false; |
| 636 |
|
| 637 |
wp_cache_delete($post_ID, 'post_meta'); |
| 638 |
|
| 639 |
$value['code'] = $newskuname; |
| 640 |
$value['name'] = $newskudisp; |
| 641 |
$value['cprice'] = $newskucprice; |
| 642 |
$value['price'] = $newskuprice; |
| 643 |
$value['unit'] = $newskuunit; |
| 644 |
$value['stocknum'] = $newskuzaikonum; |
| 645 |
$value['stock'] = $newskuzaikoselect; |
| 646 |
$value['gp'] = $newskugptekiyo; |
| 647 |
$value = apply_filters('usces_filter_add_item_sku_meta_value', $value); |
| 648 |
|
| 649 |
$id = usces_add_sku($post_ID, $value); |
| 650 |
return $id; |
| 651 |
} |
| 652 |
return false; |
| 653 |
} // add_meta |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
/** |
| 658 |
* up_item_option_meta |
| 659 |
*/ |
| 660 |
function up_item_option_meta( $post_ID ) { |
| 661 |
global $wpdb, $usces; |
| 662 |
|
| 663 |
$post_ID = (int) $post_ID; |
| 664 |
$value = array(); |
| 665 |
|
| 666 |
$optmetaid = isset($_POST['optmetaid']) ? (int)$_POST['optmetaid'] : ''; |
| 667 |
$optname = isset($_POST['optname']) ? $_POST['optname'] : ''; |
| 668 |
$optmeans = isset($_POST['optmeans']) ? (int)$_POST['optmeans']: 0; |
| 669 |
$optessential = isset($_POST['optessential']) ? $_POST['optessential']: 0; |
| 670 |
$optsort = isset($_POST['sort']) ? $_POST['sort']: 0; |
| 671 |
$optvalue = isset($_POST['optvalue']) ? trim($_POST['optvalue']) : ''; |
| 672 |
|
| 673 |
$metakey = '_iopt_'; |
| 674 |
$value['name'] = str_replace("\\",'',$optname); |
| 675 |
$value['means'] = $optmeans; |
| 676 |
$value['essential'] = $optessential; |
| 677 |
$value['value'] = str_replace("\\",'',$optvalue); |
| 678 |
$value['sort'] = $optsort; |
| 679 |
$value = $usces->stripslashes_deep_post($value); |
| 680 |
$valueserialized = serialize($value); |
| 681 |
|
| 682 |
wp_cache_delete($post_ID, 'post_meta'); |
| 683 |
|
| 684 |
$res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $valueserialized, $optmetaid) ); |
| 685 |
return $res; |
| 686 |
} // update_meta |
| 687 |
|
| 688 |
/** |
| 689 |
* up_item_sku_meta |
| 690 |
*/ |
| 691 |
function up_item_sku_meta( $post_ID ) { |
| 692 |
global $wpdb, $usces; |
| 693 |
|
| 694 |
$post_ID = (int) $post_ID; |
| 695 |
$value = array(); |
| 696 |
|
| 697 |
$skuname = isset($_POST['skuname']) ? trim( $_POST['skuname'] ) : ''; |
| 698 |
$skumetaid = isset($_POST['skumetaid']) ? (int)$_POST['skumetaid'] : ''; |
| 699 |
$skucprice = isset($_POST['skucprice']) ? trim( $_POST['skucprice'] ): 0; |
| 700 |
$skuprice = isset($_POST['skuprice']) ? trim( $_POST['skuprice'] ): 0; |
| 701 |
$skuzaikonum = isset($_POST['skuzaikonum']) ? trim( $_POST['skuzaikonum'] ): 0; |
| 702 |
$skuzaiko = isset($_POST['skuzaiko']) ? (int)$_POST['skuzaiko'] : ''; |
| 703 |
$skudisp = isset($_POST['skudisp']) ? trim( $_POST['skudisp'] ): ''; |
| 704 |
$skuunit = isset($_POST['skuunit']) ? trim( $_POST['skuunit'] ): ''; |
| 705 |
$skugptekiyo = isset($_POST['skugptekiyo']) ? (int)$_POST['skugptekiyo'] : 0; |
| 706 |
$skusort = isset($_POST['sort']) ? $_POST['sort']: 0; |
| 707 |
|
| 708 |
$value['code'] = $skuname; |
| 709 |
$value['name'] = $skudisp; |
| 710 |
$value['cprice'] = $skucprice; |
| 711 |
$value['price'] = $skuprice; |
| 712 |
$value['unit'] = $skuunit; |
| 713 |
$value['stocknum'] = $skuzaikonum; |
| 714 |
$value['stock'] = $skuzaiko; |
| 715 |
$value['gp'] = $skugptekiyo; |
| 716 |
$value['sort'] = $skusort; |
| 717 |
$value = $usces->stripslashes_deep_post($value); |
| 718 |
|
| 719 |
$skus = $usces->get_skus($post_ID); |
| 720 |
foreach( $skus as $sku ){ |
| 721 |
if( $sku['code'] == $skuname && $sku['meta_id'] != $skumetaid){ |
| 722 |
return -1; |
| 723 |
break; |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
$value = apply_filters('usces_filter_up_item_sku_meta_value', $value); |
| 728 |
|
| 729 |
$valueserialized = serialize($value); |
| 730 |
|
| 731 |
if ( !WCUtils::is_blank($skumetaid) && !WCUtils::is_blank($skuname) && !WCUtils::is_blank($skuprice) ) { |
| 732 |
|
| 733 |
wp_cache_delete($post_ID, 'post_meta'); |
| 734 |
|
| 735 |
$res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $valueserialized, $skumetaid) ); |
| 736 |
return $res; |
| 737 |
} |
| 738 |
return false; |
| 739 |
} // update_meta |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
/** |
| 744 |
* del_item_option_meta |
| 745 |
*/ |
| 746 |
function del_item_option_meta( $post_ID ) { |
| 747 |
global $wpdb; |
| 748 |
|
| 749 |
$post_ID = (int) $post_ID; |
| 750 |
$optmetaid = isset($_POST['optmetaid']) ? (int)$_POST['optmetaid'] : ''; |
| 751 |
|
| 752 |
wp_cache_delete($post_ID, 'post_meta'); |
| 753 |
|
| 754 |
$res = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $optmetaid) ); |
| 755 |
|
| 756 |
$opts = usces_get_opts($post_ID); |
| 757 |
if( !empty($opts) ){ |
| 758 |
$i = 0; |
| 759 |
foreach( $opts as $opt ){ |
| 760 |
$opt['sort'] = $i; |
| 761 |
$meta_id = $opt['meta_id']; |
| 762 |
unset($opt['meta_id']); |
| 763 |
$serialized_values = serialize($opt); |
| 764 |
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $meta_id) ); |
| 765 |
$i++; |
| 766 |
} |
| 767 |
} |
| 768 |
return ; |
| 769 |
} // delete_meta |
| 770 |
|
| 771 |
/** |
| 772 |
* del_item_sku_meta |
| 773 |
*/ |
| 774 |
function del_item_sku_meta( $post_ID ) { |
| 775 |
global $wpdb, $usces; |
| 776 |
|
| 777 |
$post_ID = (int) $post_ID; |
| 778 |
$skumetaid = isset($_POST['skumetaid']) ? (int)$_POST['skumetaid'] : ''; |
| 779 |
|
| 780 |
wp_cache_delete($post_ID, 'post_meta'); |
| 781 |
|
| 782 |
$res = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $skumetaid) ); |
| 783 |
|
| 784 |
$skus = $usces->get_skus($post_ID); |
| 785 |
if( !empty($skus) ){ |
| 786 |
$i = 0; |
| 787 |
foreach( $skus as $sku ){ |
| 788 |
$sku['sort'] = $i; |
| 789 |
$meta_id = $sku['meta_id']; |
| 790 |
unset($sku['meta_id']); |
| 791 |
$serialized_values = serialize($sku); |
| 792 |
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $meta_id) ); |
| 793 |
$i++; |
| 794 |
} |
| 795 |
} |
| 796 |
return ; |
| 797 |
} // delete_meta |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
function select_common_option( $post_ID ) { |
| 802 |
global $wpdb; |
| 803 |
|
| 804 |
$meta_id = isset($_POST['meta_id']) ? $_POST['meta_id'] : ''; |
| 805 |
if(!$meta_id) return ; |
| 806 |
|
| 807 |
$meta_value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE meta_id = %d ", $meta_id) ); |
| 808 |
$array_val = unserialize( $meta_value ); |
| 809 |
|
| 810 |
$means = $array_val['means']; |
| 811 |
$essential = $array_val['essential']; |
| 812 |
$value = $array_val['value']; |
| 813 |
$res = $means . '#usces#' . $essential . '#usces#' . $value; |
| 814 |
return $res; |
| 815 |
} // select_common_option |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
function order_item2cart_ajax(){ |
| 821 |
global $usces; |
| 822 |
|
| 823 |
if( $_POST['action'] != 'order_item2cart_ajax' ) die(0); |
| 824 |
|
| 825 |
$_POST = $usces->stripslashes_deep_post($_POST); |
| 826 |
$order_id = usces_add_ordercartdata(); |
| 827 |
if( !$order_id ) |
| 828 |
die( 0 ); |
| 829 |
|
| 830 |
$cart = usces_get_ordercartdata( $order_id ); |
| 831 |
$return = usces_get_ordercart_row( $order_id, $cart ); |
| 832 |
/* |
| 833 |
REGEX BUG: but it'll return info |
| 834 |
Compose JavaScript for return |
| 835 |
*/ |
| 836 |
die( $return ); |
| 837 |
} |
| 838 |
|
| 839 |
function order_item_ajax(){ |
| 840 |
global $usces; |
| 841 |
|
| 842 |
if( $_POST['action'] != 'order_item_ajax' ) die(0); |
| 843 |
|
| 844 |
$res = false; |
| 845 |
$_POST = $usces->stripslashes_deep_post($_POST); |
| 846 |
|
| 847 |
switch ( $_POST['mode'] ) { |
| 848 |
case 'completionMail': |
| 849 |
case 'orderConfirmMail': |
| 850 |
case 'changeConfirmMail': |
| 851 |
case 'receiptConfirmMail': |
| 852 |
case 'mitumoriConfirmMail': |
| 853 |
case 'cancelConfirmMail': |
| 854 |
case 'otherConfirmMail': |
| 855 |
$res = usces_order_confirm_message( $_POST['order_id'] ); |
| 856 |
break; |
| 857 |
case 'sendmail': |
| 858 |
$res = usces_ajax_send_mail(); |
| 859 |
break; |
| 860 |
case 'get_order_item': |
| 861 |
$res = get_order_item( $_POST['itemcode'] ); |
| 862 |
break; |
| 863 |
case 'get_item_select_option': |
| 864 |
$res = usces_get_item_select_option( $_POST['cat_id'] ); |
| 865 |
break; |
| 866 |
case 'ordercheckpost': |
| 867 |
$res = usces_update_ordercheck(); |
| 868 |
break; |
| 869 |
case 'getmember': |
| 870 |
$res = usces_get_member_neworder(); |
| 871 |
break; |
| 872 |
case 'recalculation': |
| 873 |
$res = usces_order_recalculation( $_POST['order_id'], $_POST['mem_id'], $_POST['post_ids'], $_POST['skus'], $_POST['prices'], $_POST['quants'], $_POST['use_point'], $_POST['shipping_charge'], $_POST['cod_fee'] ); |
| 874 |
break; |
| 875 |
} |
| 876 |
|
| 877 |
$res = apply_filters( 'usces_filter_order_item_ajax', $res ); |
| 878 |
|
| 879 |
if( $res === false ) die(0); |
| 880 |
|
| 881 |
//REGEX BUG: but it'll return info |
| 882 |
// Compose JavaScript for return |
| 883 |
die( $res ); |
| 884 |
} |
| 885 |
|
| 886 |
function usces_get_item_select_option( $cat_id ){ |
| 887 |
global $usces; |
| 888 |
$number = apply_filters( 'usces_filter_item_select_numberposts', 50, $cat_id ); |
| 889 |
$args = array( 'category' => $cat_id, 'numberposts' => $number ); |
| 890 |
$items = get_posts( $args ); |
| 891 |
$option = '<option value="-1">商品を選択して下さい</option>' . "\n"; |
| 892 |
foreach( $items as $item ){ |
| 893 |
$ItemName = get_post_meta($item->ID, '_itemName', true); |
| 894 |
$ItemCode = get_post_meta($item->ID, '_itemCode', true); |
| 895 |
$option .= '<option value="' . urlencode($ItemCode) . '">' . $ItemName . '(' . $ItemCode . ')' . '</option>' . "\n"; |
| 896 |
} |
| 897 |
return $option; |
| 898 |
} |
| 899 |
|
| 900 |
/** |
| 901 |
* order Item html |
| 902 |
*/ |
| 903 |
function usces_get_member_neworder() { |
| 904 |
global $wpdb; |
| 905 |
$wpdb->show_errors(); |
| 906 |
$res = ''; |
| 907 |
$member_table = $wpdb->prefix . "usces_member"; |
| 908 |
$query = $wpdb->prepare("SELECT * FROM $member_table WHERE mem_email = %s", trim($_POST['email'])); |
| 909 |
$value = $wpdb->get_row( $query, ARRAY_A ); |
| 910 |
if( !$value ){ |
| 911 |
die( 'none#usces#1' ); |
| 912 |
}else{ |
| 913 |
$res .= 'ok#usces#member_id=' . $value['ID']; |
| 914 |
$res .= '#usces#customer[name1]=' . $value['mem_name1']; |
| 915 |
$res .= '#usces#customer[name2]=' . $value['mem_name2']; |
| 916 |
$res .= '#usces#customer[name3]=' . $value['mem_name3']; |
| 917 |
$res .= '#usces#customer[name4]=' . $value['mem_name4']; |
| 918 |
$res .= '#usces#customer[zipcode]=' . $value['mem_zip']; |
| 919 |
$res .= '#usces#customer[pref]=' . $value['mem_pref']; |
| 920 |
$res .= '#usces#customer[address1]=' . $value['mem_address1']; |
| 921 |
$res .= '#usces#customer[address2]=' . $value['mem_address2']; |
| 922 |
$res .= '#usces#customer[address3]=' . $value['mem_address3']; |
| 923 |
$res .= '#usces#customer[tel]=' . $value['mem_tel']; |
| 924 |
$res .= '#usces#customer[fax]=' . $value['mem_fax']; |
| 925 |
$res .= '#usces#delivery[name1]=' . $value['mem_name1']; |
| 926 |
$res .= '#usces#delivery[name2]=' . $value['mem_name2']; |
| 927 |
$res .= '#usces#delivery[name3]=' . $value['mem_name3']; |
| 928 |
$res .= '#usces#delivery[name4]=' . $value['mem_name4']; |
| 929 |
$res .= '#usces#delivery[zipcode]=' . $value['mem_zip']; |
| 930 |
$res .= '#usces#delivery[pref]=' . $value['mem_pref']; |
| 931 |
$res .= '#usces#delivery[address1]=' . $value['mem_address1']; |
| 932 |
$res .= '#usces#delivery[address2]=' . $value['mem_address2']; |
| 933 |
$res .= '#usces#delivery[address3]=' . $value['mem_address3']; |
| 934 |
$res .= '#usces#delivery[tel]=' . $value['mem_tel']; |
| 935 |
$res .= '#usces#delivery[fax]=' . $value['mem_fax']; |
| 936 |
|
| 937 |
$member_metetable = $wpdb->prefix . "usces_member_meta"; |
| 938 |
$query = $wpdb->prepare("SELECT * FROM $member_metetable WHERE meta_key LIKE %s AND member_id = %d", 'csmb_%', $value['ID']); |
| 939 |
$customs = $wpdb->get_results( $query, ARRAY_A ); |
| 940 |
if( !empty($customs) ){ |
| 941 |
foreach( $customs as $cusv ){ |
| 942 |
$res .= '#usces#custom_customer[' . substr($cusv['meta_key'], 5) . ']=' . $cusv['meta_value']; |
| 943 |
$res .= '#usces#custom_delivery[' . substr($cusv['meta_key'], 5) . ']=' . $cusv['meta_value']; |
| 944 |
} |
| 945 |
} |
| 946 |
//die( urlencode($res) ); |
| 947 |
} |
| 948 |
|
| 949 |
die( $res ); |
| 950 |
} |
| 951 |
|
| 952 |
//function order_item2cart() { |
| 953 |
// global $usces; |
| 954 |
// |
| 955 |
// if( $_POST['action'] != 'order_item2cart_ajax' ) die(0); |
| 956 |
// |
| 957 |
// usces_add_ordercartdata(); |
| 958 |
// //$res = usces_update_ordercart(); |
| 959 |
////20120613ysk start 0000500 |
| 960 |
// //if( $res === false ) die(0); |
| 961 |
// //if( $res === 0 ) die('nodata'); |
| 962 |
// |
| 963 |
// //die( $res ); |
| 964 |
// return $res; |
| 965 |
////20120613ysk end |
| 966 |
//} |
| 967 |
|
| 968 |
function usces_add_ordercartdata(){ |
| 969 |
global $usces, $wpdb; |
| 970 |
$res = 0; |
| 971 |
|
| 972 |
$order_id = (int)$_POST['order_id']; |
| 973 |
if( !$order_id ) |
| 974 |
return $res; |
| 975 |
|
| 976 |
$post_id = (int)$_POST['post_id']; |
| 977 |
$sku_code = urldecode($_POST['sku']); |
| 978 |
$quantity = 1; |
| 979 |
|
| 980 |
$current_cart = usces_get_ordercartdata( $order_id ); |
| 981 |
$temp_arr = array(); |
| 982 |
foreach( $current_cart as $cv ){ |
| 983 |
$temp_arr[] = $cv['row_index']; |
| 984 |
} |
| 985 |
$row_index = ( 0 < count($temp_arr) ) ? max($temp_arr) + 1 : 0; |
| 986 |
|
| 987 |
$cart_table = $wpdb->prefix . "usces_ordercart"; |
| 988 |
$cart_meta_table = $wpdb->prefix . "usces_ordercart_meta"; |
| 989 |
|
| 990 |
$item_code = get_post_meta( $post_id, '_itemCode', true); |
| 991 |
$item_name = get_post_meta( $post_id, '_itemName', true); |
| 992 |
$skus = $usces->get_skus($post_id, 'code'); |
| 993 |
$sku = $skus[$sku_code]; |
| 994 |
if( empty($usces->option['tax_rate']) ){ |
| 995 |
$tax = 0; |
| 996 |
|
| 997 |
}else{ |
| 998 |
$tax = ($sku['price'] * $quantity) * $usces->options['tax_rate'] / 100; |
| 999 |
$cr = $usces->options['system']['currency']; |
| 1000 |
$decimal = $usces_settings['currency'][$cr][1]; |
| 1001 |
$decipad = (int)str_pad( '1', $decimal+1, '0', STR_PAD_RIGHT ); |
| 1002 |
switch( $usces->options['tax_method'] ){ |
| 1003 |
case 'cutting': |
| 1004 |
$tax = floor($tax*$decipad)/$decipad; |
| 1005 |
break; |
| 1006 |
case 'bring': |
| 1007 |
$tax = ceil($tax*$decipad)/$decipad; |
| 1008 |
break; |
| 1009 |
case 'rounding': |
| 1010 |
if( 0 < $decimal ){ |
| 1011 |
$tax = round($tax, (int)$decimal); |
| 1012 |
}else{ |
| 1013 |
$tax = round($tax); |
| 1014 |
} |
| 1015 |
break; |
| 1016 |
} |
| 1017 |
} |
| 1018 |
$query = $wpdb->prepare("INSERT INTO $cart_table |
| 1019 |
( |
| 1020 |
order_id, row_index, post_id, item_code, item_name, |
| 1021 |
sku_code, sku_name, cprice, price, quantity, |
| 1022 |
unit, tax, destination_id, cart_serial |
| 1023 |
) VALUES ( |
| 1024 |
%d, %d, %d, %s, %s, |
| 1025 |
%s, %s, %f, %f, %d, |
| 1026 |
%s, %d, %d, %s |
| 1027 |
)", |
| 1028 |
$order_id, $row_index, $post_id, $item_code, $item_name, |
| 1029 |
$sku_code, $sku['name'], $sku['cprice'], $sku['price'], $quantity, |
| 1030 |
$sku['unit'], $tax, NULL, NULL |
| 1031 |
); |
| 1032 |
$res = $wpdb->query($query); |
| 1033 |
|
| 1034 |
$cart_id = NULL; |
| 1035 |
if( false !== $res ){ |
| 1036 |
$cart_id = $wpdb->insert_id ; |
| 1037 |
if( isset($_POST['itemOption']) ){ |
| 1038 |
foreach((array)$_POST['itemOption'] as $okey => $ovalue){ |
| 1039 |
$okey = urldecode($okey); |
| 1040 |
if(is_array($ovalue)) { |
| 1041 |
$temp = array(); |
| 1042 |
foreach( $ovalue as $k => $v ){ |
| 1043 |
$temp[urlencode($k)] = $v; |
| 1044 |
} |
| 1045 |
$ovalue = serialize($temp); |
| 1046 |
} else { |
| 1047 |
$ovalue = urldecode($ovalue); |
| 1048 |
} |
| 1049 |
$aquery = $wpdb->prepare("INSERT INTO $cart_meta_table |
| 1050 |
( cart_id, meta_type, meta_key, meta_value ) VALUES (%d, %s, %s, %s)", |
| 1051 |
$cart_id, 'option', $okey, $ovalue |
| 1052 |
); |
| 1053 |
$wpdb->query($aquery); |
| 1054 |
} |
| 1055 |
} |
| 1056 |
} |
| 1057 |
|
| 1058 |
$res = apply_filters( 'usces_filter_add_ordercart', $res, $order_id, $cart_id ); |
| 1059 |
|
| 1060 |
if( $res ) |
| 1061 |
return $order_id; |
| 1062 |
else |
| 1063 |
return $res; |
| 1064 |
} |
| 1065 |
|
| 1066 |
function get_order_item( $item_code ) { |
| 1067 |
global $usces, $post; |
| 1068 |
|
| 1069 |
$post_id = $usces->get_postIDbyCode( $item_code ); |
| 1070 |
if( $post_id == NULL ) return false; |
| 1071 |
$post = get_post($post_id); |
| 1072 |
|
| 1073 |
$pict_id = $usces->get_mainpictid( $item_code ); |
| 1074 |
$pict_link = wp_get_attachment_image($pict_id, array(150, 150), true); |
| 1075 |
preg_match("/^\<a .+\>(\<img .+\/\>)\<\/a\>$/", $pict_link, $match); |
| 1076 |
$pict = isset($match[1]) ? $match[1] : ''; |
| 1077 |
$skus = $usces->get_skus( $post_id ); |
| 1078 |
$optkeys = $usces->get_itemOptionKey( $post_id ); |
| 1079 |
$itemName = esc_html($usces->getItemName($post_id)); |
| 1080 |
|
| 1081 |
$r = ''; |
| 1082 |
$r .= $pict_link . "\n"; |
| 1083 |
$r .= "<h3>" . $itemName . "</h3>\n"; |
| 1084 |
$r .= "<div class='skuform'>\n"; |
| 1085 |
|
| 1086 |
$r .= "<table class='skumulti'>\n"; |
| 1087 |
$r .= "<thead>\n"; |
| 1088 |
$r .= "<tr>\n"; |
| 1089 |
$r .= "<th>" . __('SKU code','usces') . "</th>\n"; |
| 1090 |
$r .= "<th>" . __('SKU display name ','usces') . "</th>\n"; |
| 1091 |
$usces_listprice = __('List price', 'usces') . usces_guid_tax('return'); |
| 1092 |
$r .= "<th>" . apply_filters('usces_filter_listprice_label', $usces_listprice, __('List price', 'usces'), usces_guid_tax('return')) . "</th>\n"; |
| 1093 |
$usces_sellingprice = __('Sale price','usces') . usces_guid_tax('return'); |
| 1094 |
$r .= "<th>" . apply_filters('usces_filter_sellingprice_label', $usces_sellingprice, __('Sale price', 'usces'), usces_guid_tax('return')) . "</th>\n"; |
| 1095 |
$r .= "<th>" . __('stock status','usces') . "</th>\n"; |
| 1096 |
$r .= "<th>" . __('stock','usces') . "</th>\n"; |
| 1097 |
$r .= "<th>" . __('unit','usces') . "</th>\n"; |
| 1098 |
$r .= "<th> </th>\n"; |
| 1099 |
$r .= "</tr>\n"; |
| 1100 |
$r .= "</thead>\n"; |
| 1101 |
$r .= "<tbody>\n"; |
| 1102 |
//for ($i=0; $i<count($skus['code']); $i++) : |
| 1103 |
// $sku = esc_attr($skus['code'][$i]); |
| 1104 |
// $cprice = esc_attr($skus['cprice'][$i]); |
| 1105 |
// $price = esc_attr($skus['price'][$i]); |
| 1106 |
// $zaiko = esc_attr($usces->zaiko_status[$skus['stock'][$i]]); |
| 1107 |
// $zaikonum = esc_attr($skus['stocknum'][$i]); |
| 1108 |
// $disp = esc_attr($skus['name'][$i]); |
| 1109 |
// $unit = esc_attr($skus['unit'][$i]); |
| 1110 |
// $gptekiyo = $skus['gp'][$i]; |
| 1111 |
foreach($skus as $sku) : |
| 1112 |
$key = urlencode($sku['code']); |
| 1113 |
$cprice = esc_attr($sku['cprice']); |
| 1114 |
$price = esc_attr($sku['price']); |
| 1115 |
$zaiko = esc_attr($usces->zaiko_status[$sku['stock']]); |
| 1116 |
$zaikonum = esc_attr($sku['stocknum']); |
| 1117 |
$disp = esc_attr($sku['name']); |
| 1118 |
$unit = esc_attr($sku['unit']); |
| 1119 |
$gptekiyo = $sku['gp']; |
| 1120 |
$sort = (int)$sku['sort']; |
| 1121 |
$r .= "<tr>\n"; |
| 1122 |
$r .= "<td rowspan='2'>" . $key . "</td>\n"; |
| 1123 |
$r .= "<td>" . $disp . "</td>\n"; |
| 1124 |
$r .= "<td><span class='cprice'>" . ( ( !empty($cprice) ) ? usces_crform( $cprice, true, false, 'return' ) : '' ) . "</span></td>\n"; |
| 1125 |
$r .= "<td><span class='price'>" . usces_crform( $price, true, false, 'return' ) . "</span></td>\n"; |
| 1126 |
$r .= "<td>" . $zaiko . "</td>\n"; |
| 1127 |
$r .= "<td>" . $zaikonum . "</td>\n"; |
| 1128 |
// $r .= "<td>" . usces_the_itemQuant() . "</td>\n"; |
| 1129 |
$r .= "<td>" . $unit . "</td>\n"; |
| 1130 |
$r .= "<td>\n"; |
| 1131 |
$r .= "<input name=\"itemNEWName[{$post_id}][{$key}]\" type=\"hidden\" id=\"itemNEWName[{$post_id}][{$key}]\" value=\"{$itemName}\" />\n"; |
| 1132 |
$r .= "<input name=\"itemNEWCode[{$post_id}][{$key}]\" type=\"hidden\" id=\"itemNEWCode[{$post_id}][{$key}]\" value=\"{$item_code}\" />\n"; |
| 1133 |
$r .= "<input name=\"skuNEWName[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWName[{$post_id}][{$key}]\" value=\"{$key}\" />\n"; |
| 1134 |
$r .= "<input name=\"skuNEWCprice[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWCprice[{$post_id}][{$key}]\" value=\"{$cprice}\" />\n"; |
| 1135 |
$r .= "<input name=\"skuNEWDisp[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWDisp[{$post_id}][{$key}]\" value=\"{$disp}\" />\n"; |
| 1136 |
$r .= "<input name=\"zaikoNEWnum[{$post_id}][{$key}]\" type=\"hidden\" id=\"zaikoNEWnum[{$post_id}][{$key}]\" value=\"{$zaikonum}\" />\n"; |
| 1137 |
$r .= "<input name=\"zaiNEWko[{$post_id}][{$key}]\" type=\"hidden\" id=\"zaiNEWko[{$post_id}][{$key}]\" value=\"{$zaiko}\" />\n"; |
| 1138 |
$r .= "<input name=\"uniNEWt[{$post_id}][{$key}]\" type=\"hidden\" id=\"uniNEWt[{$post_id}][{$key}]\" value=\"{$unit}\" />\n"; |
| 1139 |
$r .= "<input name=\"gpNEWtekiyo[{$post_id}][{$key}]\" type=\"hidden\" id=\"gpNEWtekiyo[{$post_id}][{$key}]\" value=\"{$gptekiyo}\" />\n"; |
| 1140 |
$r .= "<input name=\"skuNEWPrice[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWPrice[{$post_id}][{$key}]\" value=\"{$price}\" />\n"; |
| 1141 |
$r .= "<input name=\"inNEWCart[{$post_id}][{$key}]\" type=\"button\" id=\"inNEWCart[{$post_id}][{$key}]\" class=\"skubutton\" value=\"" . __('Add to Whish List','usces') . "\" onclick=\"orderItem.add2cart('{$post_id}', '{$key}');\" />"; |
| 1142 |
$r .= "</td>\n"; |
| 1143 |
$r .= "</tr>\n"; |
| 1144 |
$r .= "<tr>\n"; |
| 1145 |
if($optkeys) : |
| 1146 |
$r .= "<td colspan='7'>\n"; |
| 1147 |
foreach($optkeys as $optkey => $optvalue) : |
| 1148 |
$r .= "<div>\n"; |
| 1149 |
$name = esc_attr($optvalue); |
| 1150 |
$optcode = urlencode($name); |
| 1151 |
$opts = usces_get_opts($post_id, 'name'); |
| 1152 |
$opt = $opts[$optvalue]; |
| 1153 |
//20110715ysk start 0000202 |
| 1154 |
$means = (int)$opt['means']; |
| 1155 |
$essential = (int)$opt['essential']; |
| 1156 |
$r .= "\n<label for='itemNEWOption[{$post_id}][{$key}][{$optcode}]' class='iopt_label'>{$name}</label>\n"; |
| 1157 |
switch($means) { |
| 1158 |
case 0://Single-select |
| 1159 |
case 1://Multi-select |
| 1160 |
$selects = explode("\n", $opt['value']); |
| 1161 |
$multiple = ($means === 0) ? '' : ' multiple'; |
| 1162 |
$multiple_array = ($means === 0) ? '' : '_multiple'; |
| 1163 |
|
| 1164 |
$r .= "\n<select name='itemNEWOption[{$post_id}][{$key}][{$optcode}]' id='itemNEWOption[{$post_id}][{$key}][{$optcode}]' class='iopt_select{$multiple_array}'{$multiple}>\n"; |
| 1165 |
if($essential == 1) |
| 1166 |
$r .= "\t<option value='#NONE#' selected='selected'>" . __('Choose','usces') . "</option>\n"; |
| 1167 |
$s=0; |
| 1168 |
foreach($selects as $v) { |
| 1169 |
$v = trim($v); |
| 1170 |
//$optvalue = urlencode($v); |
| 1171 |
if($s == 0 && $essential == 0) |
| 1172 |
$selected = ' selected="selected"'; |
| 1173 |
else |
| 1174 |
$selected = ''; |
| 1175 |
$r .= "\t<option value='{$v}'{$selected}>{$v}</option>\n"; |
| 1176 |
$s++; |
| 1177 |
} |
| 1178 |
$r .= "</select>\n"; |
| 1179 |
break; |
| 1180 |
case 2://Text |
| 1181 |
$r .= "\n<input name='itemNEWOption[{$post_id}][{$key}][{$optcode}]' type='text' id='itemNEWOption[{$post_id}][{$key}][{$optcode}]' class='iopt_text' onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"\" />\n"; |
| 1182 |
break; |
| 1183 |
case 5://Text-area |
| 1184 |
$r .= "\n<textarea name='itemNEWOption[{$post_id}][{$key}][{$optcode}]' id='itemNEWOption[{$post_id}][{$key}][{$optcode}]' class='iopt_textarea'></textarea>\n"; |
| 1185 |
break; |
| 1186 |
} |
| 1187 |
//20110715ysk end |
| 1188 |
$r .= "<input name=\"optNEWCode[{$post_id}][{$key}][{$optcode}]\" type=\"hidden\" id=\"optNEWCode[{$post_id}][{$key}][{$optcode}]\" value=\"{$optcode}\" />\n"; |
| 1189 |
$r .= "<input name=\"optNEWEssential[{$post_id}][{$key}][{$optcode}]\" type=\"hidden\" id=\"optNEWEssential[{$post_id}][{$key}][{$optcode}]\" value=\"{$essential}\" />\n"; |
| 1190 |
$r .= "</div>\n"; |
| 1191 |
endforeach; |
| 1192 |
$r .= "</td>\n"; |
| 1193 |
endif; |
| 1194 |
$r .= "</tr>\n"; |
| 1195 |
//endfor; |
| 1196 |
endforeach; |
| 1197 |
$r .= "</tbody>\n"; |
| 1198 |
$r .= "</table>\n"; |
| 1199 |
|
| 1200 |
|
| 1201 |
$r .= "</div>\n"; |
| 1202 |
|
| 1203 |
return $r; |
| 1204 |
} |
| 1205 |
|
| 1206 |
function item_option_ajax() |
| 1207 |
{ |
| 1208 |
|
| 1209 |
if( $_POST['action'] != 'item_option_ajax' ) die(0); |
| 1210 |
|
| 1211 |
if(isset($_POST['update'])){ |
| 1212 |
$id = up_item_option_meta( $_POST['ID'] ); |
| 1213 |
|
| 1214 |
}else if(isset($_POST['delete'])){ |
| 1215 |
$id = del_item_option_meta( $_POST['ID'] ); |
| 1216 |
|
| 1217 |
}else if(isset($_POST['select'])){ |
| 1218 |
$res = select_common_option( $_POST['ID'] ); |
| 1219 |
die( $res ); |
| 1220 |
|
| 1221 |
}else if(isset($_POST['sort'])){ |
| 1222 |
$id = usces_sort_post_meta( $_POST['ID'], $_POST['meta'] ); |
| 1223 |
//die( $res ); |
| 1224 |
|
| 1225 |
}else{ |
| 1226 |
$id = add_item_option_meta( $_POST['ID'] ); |
| 1227 |
|
| 1228 |
} |
| 1229 |
|
| 1230 |
$opts = usces_get_opts( $_POST['ID'] ); |
| 1231 |
|
| 1232 |
$r = ''; |
| 1233 |
foreach ( $opts as $opt ) |
| 1234 |
$r .= _list_item_option_meta_row( $opt ); |
| 1235 |
|
| 1236 |
$res = $r . '#usces#' . $id; |
| 1237 |
//REGEX BUG: but it'll return info |
| 1238 |
// Compose JavaScript for return |
| 1239 |
die( $res ); |
| 1240 |
} |
| 1241 |
|
| 1242 |
function item_sku_ajax(){ |
| 1243 |
global $usces; |
| 1244 |
|
| 1245 |
$id = ''; |
| 1246 |
if( $_POST['action'] != 'item_sku_ajax' ) die(0); |
| 1247 |
|
| 1248 |
if(isset($_POST['update'])){ |
| 1249 |
$id = up_item_sku_meta( $_POST['ID'] ); |
| 1250 |
|
| 1251 |
}else if(isset($_POST['delete'])){ |
| 1252 |
$id = del_item_sku_meta( $_POST['ID'] ); |
| 1253 |
|
| 1254 |
}else if(isset($_POST['select'])){ |
| 1255 |
$res = select_item_sku( $_POST['ID'] ); |
| 1256 |
die( $res ); |
| 1257 |
|
| 1258 |
}else if(isset($_POST['sort'])){ |
| 1259 |
$id = usces_sort_post_meta( $_POST['ID'], $_POST['meta'] ); |
| 1260 |
//die( $res ); |
| 1261 |
|
| 1262 |
}else{ |
| 1263 |
$id = add_item_sku_meta( $_POST['ID'] ); |
| 1264 |
|
| 1265 |
} |
| 1266 |
|
| 1267 |
$skus = $usces->get_skus( $_POST['ID'] ); |
| 1268 |
|
| 1269 |
$r = ''; |
| 1270 |
|
| 1271 |
foreach ( (array)$skus as $sku ) |
| 1272 |
$r .= _list_item_sku_meta_row( $sku ); |
| 1273 |
|
| 1274 |
//$list = has_item_sku_list(); |
| 1275 |
|
| 1276 |
$res = $r . '#usces#' . $id; |
| 1277 |
|
| 1278 |
die( $res ); |
| 1279 |
} |
| 1280 |
|
| 1281 |
function item_save_metadata( $post_id, $post ) { |
| 1282 |
global $usces, $wpdb; |
| 1283 |
|
| 1284 |
$message = ''; |
| 1285 |
|
| 1286 |
// usces_log('item_save_metadata : '.print_r($post_id,true), 'acting_transaction.log'); |
| 1287 |
// usces_log('item_save_metadata : '.print_r($_POST['post_ID'],true), 'acting_transaction.log'); |
| 1288 |
// パーミッションチェック |
| 1289 |
if ( isset($_POST['page']) && 'usces_itemedit' == $_POST['page']) { |
| 1290 |
if ( !current_user_can( 'edit_post', $post_id ) ){ |
| 1291 |
$usces->set_action_status('error', 'ERROR : '.__('Sorry, you do not have the right to edit this post.')); |
| 1292 |
return $post_id; |
| 1293 |
} |
| 1294 |
} else { |
| 1295 |
return $post_id; |
| 1296 |
} |
| 1297 |
|
| 1298 |
if ( !wp_verify_nonce( $_POST['usces_nonce'], 'usc-e-shop' )) { |
| 1299 |
return $post_id; |
| 1300 |
} |
| 1301 |
|
| 1302 |
// $post_id = $_POST['post_ID']; |
| 1303 |
// if( $post_id < 0 ){ |
| 1304 |
// return $post_id; |
| 1305 |
// } |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
// 自動保存ルーチンかどうかチェック。そうだった場合はフォームを送信しない(何もしない) |
| 1310 |
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) |
| 1311 |
return $post_id; |
| 1312 |
|
| 1313 |
$usces->set_item_mime($post_id, 'item'); |
| 1314 |
|
| 1315 |
$itemCode = trim($_POST['itemCode' ]); |
| 1316 |
if( preg_match('/[^0-9a-zA-Z\-_]/', $itemCode) ){ |
| 1317 |
// $itemCode = ''; |
| 1318 |
// $usces->action_message = '商品コードは半角英数(-_を含む)で� |
| 1319 |
�力して下さい。' . "<br />"; |
| 1320 |
} |
| 1321 |
if( empty($itemCode) ){ |
| 1322 |
$itemCode = ''; |
| 1323 |
$message .= __('Product code has not been entered.', 'usces') . "<br />"; |
| 1324 |
}elseif( $res = usces_is_same_itemcode($post->ID, $itemCode)) { |
| 1325 |
$message .= 'post_ID '; |
| 1326 |
foreach( $res as $postid ) |
| 1327 |
$message .= $postid . ', '; |
| 1328 |
$message .= 'Same product code is registered here.' . "<br />"; |
| 1329 |
$usces->set_action_status('error', 'ERROR : '.$message); |
| 1330 |
} |
| 1331 |
update_post_meta($post_id, '_itemCode', $itemCode); |
| 1332 |
|
| 1333 |
|
| 1334 |
if(isset($_POST['itemName'])){ |
| 1335 |
$itemName = trim($_POST['itemName']); |
| 1336 |
update_post_meta($post_id, '_itemName', $itemName); |
| 1337 |
} |
| 1338 |
// if(isset($_POST['itemCode'])){ |
| 1339 |
// $itemCode = trim($_POST['itemCode']); |
| 1340 |
// update_post_meta($post_id, '_itemCode', $itemCode); |
| 1341 |
// } |
| 1342 |
if(isset($_POST['itemRestriction'])){ |
| 1343 |
$itemRestriction = trim($_POST['itemRestriction']); |
| 1344 |
update_post_meta($post_id, '_itemRestriction', $itemRestriction); |
| 1345 |
} |
| 1346 |
if(isset($_POST['itemPointrate'])){ |
| 1347 |
$itemPointrate = (int)$_POST['itemPointrate']; |
| 1348 |
update_post_meta($post_id, '_itemPointrate', $itemPointrate); |
| 1349 |
} |
| 1350 |
if(isset($_POST['itemGpNum1'])){ |
| 1351 |
$itemGpNum1 = (int)$_POST['itemGpNum1']; |
| 1352 |
update_post_meta($post_id, '_itemGpNum1', $itemGpNum1); |
| 1353 |
} |
| 1354 |
if(isset($_POST['itemGpNum2'])){ |
| 1355 |
$itemGpNum2 = (int)$_POST['itemGpNum2']; |
| 1356 |
update_post_meta($post_id, '_itemGpNum2', $itemGpNum2); |
| 1357 |
} |
| 1358 |
if(isset($_POST['itemGpNum3'])){ |
| 1359 |
$itemGpNum3 = (int)$_POST['itemGpNum3']; |
| 1360 |
update_post_meta($post_id, '_itemGpNum3', $itemGpNum3); |
| 1361 |
} |
| 1362 |
if(isset($_POST['itemGpDis1'])){ |
| 1363 |
$itemGpDis1 = (int)$_POST['itemGpDis1']; |
| 1364 |
update_post_meta($post_id, '_itemGpDis1', $itemGpDis1); |
| 1365 |
} |
| 1366 |
if(isset($_POST['itemGpDis2'])){ |
| 1367 |
$itemGpDis2 = (int)$_POST['itemGpDis2']; |
| 1368 |
update_post_meta($post_id, '_itemGpDis2', $itemGpDis2); |
| 1369 |
} |
| 1370 |
if(isset($_POST['itemGpDis3'])){ |
| 1371 |
$itemGpDis3 = (int)$_POST['itemGpDis3']; |
| 1372 |
update_post_meta($post_id, '_itemGpDis3', $itemGpDis3); |
| 1373 |
} |
| 1374 |
|
| 1375 |
if(isset($_POST['itemShipping'])){ |
| 1376 |
$itemShipping = (int)$_POST['itemShipping']; |
| 1377 |
update_post_meta($post_id, '_itemShipping', $itemShipping); |
| 1378 |
} |
| 1379 |
if(isset($_POST['itemDeliveryMethod'])){ |
| 1380 |
$itemDeliveryMethod = array(); |
| 1381 |
foreach( (array)$_POST["itemDeliveryMethod"] as $dmid){ |
| 1382 |
$itemDeliveryMethod[] = $dmid; |
| 1383 |
} |
| 1384 |
update_post_meta($post_id, '_itemDeliveryMethod', $itemDeliveryMethod); |
| 1385 |
} |
| 1386 |
if(isset($_POST['itemShippingCharge'])){ |
| 1387 |
$itemShippingCharge = (int)$_POST['itemShippingCharge']; |
| 1388 |
update_post_meta($post_id, '_itemShippingCharge', $itemShippingCharge); |
| 1389 |
} |
| 1390 |
$itemIndividualSCharge = isset($_POST['itemIndividualSCharge']) ? 1 : 0; |
| 1391 |
update_post_meta($post_id, '_itemIndividualSCharge', $itemIndividualSCharge); |
| 1392 |
|
| 1393 |
if(isset($_POST['wcexp'])){ |
| 1394 |
$wcexp = serialize($_POST['wcexp']); |
| 1395 |
update_post_meta($post_id, '_wcexp', $wcexp); |
| 1396 |
} |
| 1397 |
|
| 1398 |
//SKU |
| 1399 |
if( isset($_POST['itemsku']) ){ |
| 1400 |
$meta_ids = array(); |
| 1401 |
$codes = array(); |
| 1402 |
$uniq_code = false; |
| 1403 |
$irreg_code = false; |
| 1404 |
$irreg_price = false; |
| 1405 |
|
| 1406 |
foreach($_POST['itemsku'] as $mid => $temp){ |
| 1407 |
$meta_ids[] = $mid; |
| 1408 |
} |
| 1409 |
$meta_ids = array_unique($meta_ids); |
| 1410 |
foreach( $meta_ids as $meta_id ){ |
| 1411 |
|
| 1412 |
$skucode = isset($_POST['itemsku'][$meta_id]['key']) ? trim( $_POST['itemsku'][$meta_id]['key'] ) : ''; |
| 1413 |
$skucprice = isset($_POST['itemsku'][$meta_id]['cprice']) ? trim( $_POST['itemsku'][$meta_id]['cprice'] ): 0; |
| 1414 |
$skuprice = isset($_POST['itemsku'][$meta_id]['price']) ? trim( $_POST['itemsku'][$meta_id]['price'] ): 0; |
| 1415 |
$skustocknum = isset($_POST['itemsku'][$meta_id]['zaikonum']) ? trim( $_POST['itemsku'][$meta_id]['zaikonum'] ): 0; |
| 1416 |
$skustock = isset($_POST['itemsku'][$meta_id]['zaiko']) ? (int)$_POST['itemsku'][$meta_id]['zaiko'] : ''; |
| 1417 |
$skuname = isset($_POST['itemsku'][$meta_id]['skudisp']) ? trim( $_POST['itemsku'][$meta_id]['skudisp'] ): ''; |
| 1418 |
$skuunit = isset($_POST['itemsku'][$meta_id]['skuunit']) ? trim( $_POST['itemsku'][$meta_id]['skuunit'] ): ''; |
| 1419 |
$skugp = isset($_POST['itemsku'][$meta_id]['skugptekiyo']) ? (int)$_POST['itemsku'][$meta_id]['skugptekiyo'] : 0; |
| 1420 |
$skusort = isset($_POST['itemsku'][$meta_id]['sort']) ? $_POST['itemsku'][$meta_id]['sort']: 0; |
| 1421 |
|
| 1422 |
$skus['code'] = $skucode; |
| 1423 |
$skus['name'] = $skuname; |
| 1424 |
$skus['cprice'] = $skucprice; |
| 1425 |
$skus['price'] = $skuprice; |
| 1426 |
$skus['unit'] = $skuunit; |
| 1427 |
$skus['stocknum'] = $skustocknum; |
| 1428 |
$skus['stock'] = $skustock; |
| 1429 |
$skus['gp'] = $skugp; |
| 1430 |
$skus['sort'] = $skusort; |
| 1431 |
$skus = $usces->stripslashes_deep_post($skus); |
| 1432 |
$skus = apply_filters( 'usces_filter_item_save_sku_metadata', $skus, $meta_id ); |
| 1433 |
|
| 1434 |
$valueserialized = serialize($skus); |
| 1435 |
$res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $valueserialized, $meta_id) ); |
| 1436 |
|
| 1437 |
if( in_array( $skucode, $codes ) ) |
| 1438 |
$uniq_code = true; |
| 1439 |
|
| 1440 |
if( WCUtils::is_blank($skucode) ) |
| 1441 |
$irreg_code = true; |
| 1442 |
|
| 1443 |
if( WCUtils::is_blank($skuprice) || preg_match('/[^0-9.]/', $skuprice) || 1 < substr_count($skuprice, '.' ) ) |
| 1444 |
$irreg_price = true; |
| 1445 |
|
| 1446 |
$codes[] = $skucode; |
| 1447 |
} |
| 1448 |
|
| 1449 |
if( $uniq_code ){ |
| 1450 |
$message .= __('SKU code is duplicated.','usces') . "<br />"; |
| 1451 |
} |
| 1452 |
if( $irreg_code ){ |
| 1453 |
$message .= __('SKU code is invalid.','usces') . "<br />"; |
| 1454 |
} |
| 1455 |
if( $irreg_price ){ |
| 1456 |
$message .= __('SKU of invalid selling price exists.','usces') . "<br />"; |
| 1457 |
} |
| 1458 |
} |
| 1459 |
//OPT |
| 1460 |
if( isset($_POST['itemopt']) ){ |
| 1461 |
$meta_ids = array(); |
| 1462 |
$names = array(); |
| 1463 |
$uniq_name = false; |
| 1464 |
$irreg_name = false; |
| 1465 |
$irreg_value = false; |
| 1466 |
|
| 1467 |
foreach($_POST['itemopt'] as $mid => $temp){ |
| 1468 |
$meta_ids[] = $mid; |
| 1469 |
} |
| 1470 |
$meta_ids = array_unique($meta_ids); |
| 1471 |
foreach( $meta_ids as $meta_id ){ |
| 1472 |
|
| 1473 |
$optname = isset($_POST['itemopt'][$meta_id]['name']) ? $_POST['itemopt'][$meta_id]['name'] : ''; |
| 1474 |
$optmeans = isset($_POST['itemopt'][$meta_id]['means']) ? (int)$_POST['itemopt'][$meta_id]['means']: 0; |
| 1475 |
$optessential = isset($_POST['itemopt'][$meta_id]['essential']) ? $_POST['itemopt'][$meta_id]['essential']: 0; |
| 1476 |
$optsort = isset($_POST['itemopt'][$meta_id]['sort']) ? $_POST['itemopt'][$meta_id]['sort']: 0; |
| 1477 |
$optvalue = isset($_POST['itemopt'][$meta_id]['value']) ? trim($_POST['itemopt'][$meta_id]['value']) : ''; |
| 1478 |
|
| 1479 |
$opts['name'] = str_replace("\\",'',$optname); |
| 1480 |
$opts['value'] = str_replace("\\",'',$optvalue); |
| 1481 |
$opts['means'] = $optmeans; |
| 1482 |
$opts['essential'] = $optessential; |
| 1483 |
$opts['sort'] = $optsort; |
| 1484 |
$opts = $usces->stripslashes_deep_post($opts); |
| 1485 |
|
| 1486 |
$valueserialized = serialize($opts); |
| 1487 |
$res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $valueserialized, $meta_id) ); |
| 1488 |
|
| 1489 |
if( in_array( $optname, $names ) ) |
| 1490 |
$uniq_name = true; |
| 1491 |
|
| 1492 |
if( WCUtils::is_blank($optname) ) |
| 1493 |
$irreg_name = true; |
| 1494 |
|
| 1495 |
if( WCUtils::is_blank($optvalue) && 1 >= $optmeans ) |
| 1496 |
$irreg_value = true; |
| 1497 |
|
| 1498 |
$names[] = $optname; |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
if( $uniq_name ){ |
| 1503 |
$message .= __("Commodity option option name duplicates exist.", "usces") . "<br />"; |
| 1504 |
} |
| 1505 |
if( $irreg_name ){ |
| 1506 |
$message .= __("Commodity option not entered there is the option name.", "usces") . "<br />"; |
| 1507 |
} |
| 1508 |
if( $irreg_value ){ |
| 1509 |
$message .= __("If you select 'single select' and 'multi-select' the trade option, please enter the select value.", "usces") . "<br />"; |
| 1510 |
} |
| 1511 |
} |
| 1512 |
|
| 1513 |
do_action('usces_action_save_product', $post_id, $post); |
| 1514 |
$message = apply_filters( 'usces_filter_save_product_message', $message, $post_id ); |
| 1515 |
|
| 1516 |
// $usces->action_status = 'none'; |
| 1517 |
// $usces->action_message = ''; |
| 1518 |
if( $message ){ |
| 1519 |
$usces->set_action_status('error', 'ERROR : '.$message); |
| 1520 |
}else{ |
| 1521 |
$usces->set_action_status('success', __('Registration of the product is complete.','usces')); |
| 1522 |
} |
| 1523 |
|
| 1524 |
wp_cache_delete($post_id, 'post_meta'); |
| 1525 |
} |
| 1526 |
|
| 1527 |
function usces_link_replace($para) { |
| 1528 |
//$str = 'admin.php?page=' . USCES_PLUGIN_BASENAME . '&'; |
| 1529 |
$str = 'admin.php?page=usces_itemedit&'; |
| 1530 |
$url = preg_replace('|post\.php\?|i', $str, $para); |
| 1531 |
return $url; |
| 1532 |
|
| 1533 |
} |
| 1534 |
|
| 1535 |
function usces_count_posts( $type = 'post', $perm = '' ) { |
| 1536 |
global $wpdb; |
| 1537 |
|
| 1538 |
$user = wp_get_current_user(); |
| 1539 |
|
| 1540 |
$cache_key = $type; |
| 1541 |
|
| 1542 |
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND post_mime_type = 'item'"; |
| 1543 |
//$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; |
| 1544 |
if ( 'readable' == $perm && is_user_logged_in() ) { |
| 1545 |
if ( !current_user_can("read_private_{$type}s") ) { |
| 1546 |
$cache_key .= '_' . $perm . '_' . $user->ID; |
| 1547 |
$query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))"; |
| 1548 |
} |
| 1549 |
} |
| 1550 |
$query .= ' GROUP BY post_status'; |
| 1551 |
|
| 1552 |
$count = wp_cache_get($cache_key, 'counts'); |
| 1553 |
if ( false !== $count ) |
| 1554 |
// return $count; |
| 1555 |
|
| 1556 |
$count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); |
| 1557 |
|
| 1558 |
$stats = array( ); |
| 1559 |
foreach( (array) $count as $row_num => $row ) { |
| 1560 |
$stats[$row['post_status']] = $row['num_posts']; |
| 1561 |
} |
| 1562 |
|
| 1563 |
$stats = (object) $stats; |
| 1564 |
wp_cache_set($cache_key, $stats, 'counts'); |
| 1565 |
|
| 1566 |
return $stats; |
| 1567 |
} |
| 1568 |
|
| 1569 |
//20100809ysk start |
| 1570 |
/** |
| 1571 |
* custom order meta row |
| 1572 |
*/ |
| 1573 |
function _list_custom_order_meta_row($key, $entry) { |
| 1574 |
$r = ''; |
| 1575 |
$style = ''; |
| 1576 |
$key = esc_attr($key); |
| 1577 |
|
| 1578 |
$name = esc_attr($entry['name']); |
| 1579 |
$means = get_option('usces_custom_order_select'); |
| 1580 |
$meansoption = ''; |
| 1581 |
foreach($means as $meankey => $meanvalue) { |
| 1582 |
if($meankey == $entry['means']) { |
| 1583 |
$selected = ' selected="selected"'; |
| 1584 |
} else { |
| 1585 |
$selected = ''; |
| 1586 |
} |
| 1587 |
$meansoption .= '<option value="'.esc_attr($meankey).'"'.$selected.'>'.esc_html($meanvalue)."</option>\n"; |
| 1588 |
} |
| 1589 |
$essential = $entry['essential'] == 1 ? " checked='checked'" : ""; |
| 1590 |
$value = ''; |
| 1591 |
if(is_array($entry['value'])) { |
| 1592 |
foreach($entry['value'] as $k => $v) { |
| 1593 |
$value .= $v."\n"; |
| 1594 |
} |
| 1595 |
} |
| 1596 |
$value = esc_attr(trim($value)); |
| 1597 |
|
| 1598 |
$r .= "\n\t<tr id='csod-{$key}' class='{$style}'>"; |
| 1599 |
$r .= "\n\t\t<td class='left'><div><input type='text' name='csod[{$key}][key]' id='csod[{$key}][key]' class='optname' size='20' value='{$key}' readonly /></div>"; |
| 1600 |
$r .= "\n\t\t<div><input type='text' name='csod[{$key}][name]' id='csod[{$key}][name]' class='optname' size='20' value='{$name}' /></div>"; |
| 1601 |
$r .= "\n\t\t<div class='optcheck'><select name='csod[{$key}][means]' id='csod[{$key}][means]'>".$meansoption."</select>\n"; |
| 1602 |
$r .= "<input type='checkbox' name='csod[{$key}][essential]' id='csod[{$key}][essential]' value='1'{$essential} /><label for='csod[{$key}][essential]'>".__('Required','usces')."</label></div>"; |
| 1603 |
//20100818ysk start |
| 1604 |
//$r .= "\n\t\t<div class='submit'><input type='button' name='deletecsod[{$key}]' id='deletecsod[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customOrder.del(\"{$key}\");' />"; |
| 1605 |
//$r .= "\n\t\t<input type='button' name='updatecsod' id='updatecsod[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customOrder.upd(\"{$key}\");' /></div>"; |
| 1606 |
$r .= "\n\t\t<div class='submit'><input type='button' name='del_csod[{$key}]' id='del_csod[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customField.delOrder(\"{$key}\");' />"; |
| 1607 |
$r .= "\n\t\t<input type='button' name='upd_csod[{$key}]' id='upd_csod[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customField.updOrder(\"{$key}\");' /></div>"; |
| 1608 |
//20100818ysk end |
| 1609 |
$r .= "\n\t\t<div id='csod_loading-{$key}' class='meta_submit_loading'></div>"; |
| 1610 |
$r .= "</td>"; |
| 1611 |
$r .= "\n\t\t<td class='item-opt-value'><textarea name='csod[{$key}][value]' id='csod[{$key}][value]' class='optvalue'>{$value}</textarea></td>\n\t</tr>"; |
| 1612 |
return $r; |
| 1613 |
} |
| 1614 |
//20100809ysk end |
| 1615 |
|
| 1616 |
//20100818ysk start |
| 1617 |
/** |
| 1618 |
* has custom field meta |
| 1619 |
*/ |
| 1620 |
function usces_has_custom_field_meta($fieldname) { |
| 1621 |
switch($fieldname) { |
| 1622 |
case 'order': |
| 1623 |
$field = 'usces_custom_order_field'; |
| 1624 |
break; |
| 1625 |
case 'customer': |
| 1626 |
$field = 'usces_custom_customer_field'; |
| 1627 |
break; |
| 1628 |
case 'delivery': |
| 1629 |
$field = 'usces_custom_delivery_field'; |
| 1630 |
break; |
| 1631 |
case 'member': |
| 1632 |
$field = 'usces_custom_member_field'; |
| 1633 |
break; |
| 1634 |
default: |
| 1635 |
return array(); |
| 1636 |
} |
| 1637 |
$fields = get_option($field); |
| 1638 |
if( empty($fields) ){ |
| 1639 |
$meta = array(); |
| 1640 |
}elseif( is_array($fields) ){ |
| 1641 |
$meta = $fields; |
| 1642 |
}else{ |
| 1643 |
$meta = unserialize($fields); |
| 1644 |
} |
| 1645 |
return $meta; |
| 1646 |
} |
| 1647 |
|
| 1648 |
function usces_getinfo_ajax(){ |
| 1649 |
global $wp_version; |
| 1650 |
$wcex_str = ''; |
| 1651 |
$res = ''; |
| 1652 |
$wcex = usces_get_wcex(); |
| 1653 |
foreach ( (array)$wcex as $key => $values ) { |
| 1654 |
$wcex_str .= $key . "-" . $values['version'] . ","; |
| 1655 |
} |
| 1656 |
$wcex_str = rtrim($wcex_str, ','); |
| 1657 |
if ( version_compare($wp_version, '3.4', '>=') ){ |
| 1658 |
$theme_ob = wp_get_theme(); |
| 1659 |
$themedata['Name'] = $theme_ob->get('Name'); |
| 1660 |
$themedata['Version'] = $theme_ob->get('Version'); |
| 1661 |
}else{ |
| 1662 |
$themedata = get_theme_data( get_stylesheet_directory().'/style.css' ); |
| 1663 |
} |
| 1664 |
|
| 1665 |
|
| 1666 |
$v = urlencode(USCES_VERSION); |
| 1667 |
$wcid = urlencode(get_option('usces_wcid')); |
| 1668 |
$locale = urlencode(get_locale()); |
| 1669 |
$theme = urlencode($themedata['Name'] . '-' . $themedata['Version']); |
| 1670 |
$wcex = urlencode($wcex_str); |
| 1671 |
$interface_url = 'http://www.welcart.com/util/welcart_information2.php'; |
| 1672 |
$wcurl = urlencode(get_home_url()); |
| 1673 |
$interface = parse_url($interface_url); |
| 1674 |
|
| 1675 |
$vars ="v=$v&wcid=$wcid&locale=$locale&theme=$theme&wcex=$wcex&wcurl=$wcurl"; |
| 1676 |
$header = "POST " . $interface_url . " HTTP/1.1\r\n"; |
| 1677 |
$header .= "Host: " . $_SERVER['HTTP_HOST'] . "\r\n"; |
| 1678 |
$header .= "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n"; |
| 1679 |
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
| 1680 |
$header .= "Content-Length: " . strlen($vars) . "\r\n"; |
| 1681 |
$header .= "Connection: close\r\n\r\n"; |
| 1682 |
$header .= $vars; |
| 1683 |
$fp = fsockopen($interface['host'],80,$errno,$errstr,30); |
| 1684 |
if( $fp ){ |
| 1685 |
fwrite($fp, $header); |
| 1686 |
$i=0; |
| 1687 |
while ( !feof($fp) ) { |
| 1688 |
$scr = fgets($fp, 10240); |
| 1689 |
preg_match("/<(title|data)>(.*)<(\/title|\/data)>$/", $scr, $match); |
| 1690 |
|
| 1691 |
if(!empty($match[2])){ |
| 1692 |
switch( $match[1] ){ |
| 1693 |
case'title': |
| 1694 |
$res .= '<div style="text-align: center;border-bottom: 1px dotted #CCCCCC;width: 80%;margin-bottom: 10px;padding-bottom: 3px; margin-right: auto; margin-left: auto;"><stlong>' . $match[2] . '</strong></div><ul>'; |
| 1695 |
break; |
| 1696 |
case 'data': |
| 1697 |
$res .= '<li>' . $match[2] . '</li>'; |
| 1698 |
break; |
| 1699 |
} |
| 1700 |
} |
| 1701 |
$i++; |
| 1702 |
if($i>50) { |
| 1703 |
$res = 'ERROR'; |
| 1704 |
break; |
| 1705 |
} |
| 1706 |
} |
| 1707 |
|
| 1708 |
$res .= '</ul>'; |
| 1709 |
fclose($fp); |
| 1710 |
|
| 1711 |
}else{ |
| 1712 |
$res = 'ERROR'; |
| 1713 |
} |
| 1714 |
die($res); |
| 1715 |
} |
| 1716 |
|
| 1717 |
/** |
| 1718 |
* custom field ajax |
| 1719 |
*/ |
| 1720 |
function custom_field_ajax() { |
| 1721 |
global $usces; |
| 1722 |
$_POST = $usces->stripslashes_deep_post($_POST); |
| 1723 |
|
| 1724 |
if($_POST['action'] != 'custom_field_ajax') die(0); |
| 1725 |
switch($_POST['field']) { |
| 1726 |
case 'order': |
| 1727 |
$field = 'usces_custom_order_field'; |
| 1728 |
break; |
| 1729 |
case 'customer': |
| 1730 |
$field = 'usces_custom_customer_field'; |
| 1731 |
break; |
| 1732 |
case 'delivery': |
| 1733 |
$field = 'usces_custom_delivery_field'; |
| 1734 |
break; |
| 1735 |
case 'member': |
| 1736 |
$field = 'usces_custom_member_field'; |
| 1737 |
break; |
| 1738 |
default: |
| 1739 |
die(0); |
| 1740 |
} |
| 1741 |
|
| 1742 |
$meta = usces_has_custom_field_meta($_POST['field']); |
| 1743 |
$dupkey = 0; |
| 1744 |
|
| 1745 |
if(isset($_POST['add'])) { |
| 1746 |
$newkey = isset($_POST['newkey']) ? trim($_POST['newkey']) : ''; |
| 1747 |
$newname = isset($_POST['newname']) ? trim($_POST['newname']) : ''; |
| 1748 |
$newmeans = isset($_POST['newmeans']) ? $_POST['newmeans'] : 0; |
| 1749 |
$newessential = isset($_POST['newessential']) ? $_POST['newessential'] : 0; |
| 1750 |
$newposition = isset($_POST['newposition']) ? trim($_POST['newposition']) : ''; |
| 1751 |
|
| 1752 |
if($newmeans == 2) {//Text |
| 1753 |
$newvalue = isset($_POST['newvalue']) ? trim($_POST['newvalue']) : ''; |
| 1754 |
$nv = $newvalue; |
| 1755 |
|
| 1756 |
} else { |
| 1757 |
$newvalue = isset($_POST['newvalue']) ? explode('\n', trim($_POST['newvalue'])) : ''; |
| 1758 |
foreach((array)$newvalue as $v) { |
| 1759 |
if( !WCUtils::is_blank($v) ) |
| 1760 |
$nv[] = trim($v); |
| 1761 |
} |
| 1762 |
} |
| 1763 |
|
| 1764 |
if(!array_key_exists($newkey, $meta)) { |
| 1765 |
if((!empty($newvalue)) && !empty($newkey) && !empty($newname)) { |
| 1766 |
$meta[$newkey]['name'] = $newname; |
| 1767 |
$meta[$newkey]['means'] = $newmeans; |
| 1768 |
$meta[$newkey]['essential'] = $newessential; |
| 1769 |
$meta[$newkey]['value'] = $nv; |
| 1770 |
if( !WCUtils::is_blank($newposition) ) $meta[$newkey]['position'] = $newposition; |
| 1771 |
update_option($field, $meta); |
| 1772 |
} |
| 1773 |
} else { |
| 1774 |
$dupkey = 1; |
| 1775 |
} |
| 1776 |
|
| 1777 |
} elseif(isset($_POST['update'])) { |
| 1778 |
$key = isset($_POST['key']) ? trim($_POST['key']) : ''; |
| 1779 |
$name = isset($_POST['name']) ? trim($_POST['name']) : ''; |
| 1780 |
$means = isset($_POST['means']) ? $_POST['means'] : 0; |
| 1781 |
$essential = isset($_POST['essential']) ? $_POST['essential'] : 0; |
| 1782 |
$position = isset($_POST['position']) ? trim($_POST['position']) : ''; |
| 1783 |
|
| 1784 |
if($means == 2) {//Text |
| 1785 |
$value = isset($_POST['value']) ? trim($_POST['value']) : ''; |
| 1786 |
$nv = $value; |
| 1787 |
|
| 1788 |
} else { |
| 1789 |
$value = isset($_POST['value']) ? explode('\n', trim($_POST['value'])) : ''; |
| 1790 |
foreach((array)$value as $v) { |
| 1791 |
if( !WCUtils::is_blank($v) ) |
| 1792 |
$nv[] = trim($v); |
| 1793 |
} |
| 1794 |
} |
| 1795 |
|
| 1796 |
if( !empty($value) && !empty($key) && !empty($name) ) { |
| 1797 |
$meta[$key]['name'] = $name; |
| 1798 |
$meta[$key]['means'] = $means; |
| 1799 |
$meta[$key]['essential'] = $essential; |
| 1800 |
$meta[$key]['value'] = $nv; |
| 1801 |
if( !WCUtils::is_blank($position) ) $meta[$key]['position'] = $position; |
| 1802 |
update_option($field, $meta); |
| 1803 |
} |
| 1804 |
|
| 1805 |
} elseif(isset($_POST['delete'])) { |
| 1806 |
$key = isset($_POST['key']) ? trim($_POST['key']) : ''; |
| 1807 |
unset($meta[$key]); |
| 1808 |
update_option($field, $meta); |
| 1809 |
} |
| 1810 |
|
| 1811 |
$r = ''; |
| 1812 |
switch($_POST['field']) { |
| 1813 |
case 'order': |
| 1814 |
foreach($meta as $key => $entry) |
| 1815 |
$r .= _list_custom_order_meta_row($key, $entry); |
| 1816 |
break; |
| 1817 |
case 'customer': |
| 1818 |
foreach($meta as $key => $entry) |
| 1819 |
$r .= _list_custom_customer_meta_row($key, $entry); |
| 1820 |
break; |
| 1821 |
case 'delivery': |
| 1822 |
foreach($meta as $key => $entry) |
| 1823 |
$r .= _list_custom_delivery_meta_row($key, $entry); |
| 1824 |
break; |
| 1825 |
case 'member': |
| 1826 |
foreach($meta as $key => $entry) |
| 1827 |
$r .= _list_custom_member_meta_row($key, $entry); |
| 1828 |
break; |
| 1829 |
} |
| 1830 |
|
| 1831 |
$res = $r . '#usces#' . $dupkey; |
| 1832 |
//REGEX BUG: but it'll return info |
| 1833 |
// Compose JavaScript for return |
| 1834 |
die($res); |
| 1835 |
} |
| 1836 |
|
| 1837 |
/** |
| 1838 |
* list custom customer meta row |
| 1839 |
*/ |
| 1840 |
function _list_custom_customer_meta_row($key, $entry) { |
| 1841 |
$r = ''; |
| 1842 |
$style = ''; |
| 1843 |
$key = esc_attr($key); |
| 1844 |
|
| 1845 |
$name = esc_attr($entry['name']); |
| 1846 |
$means = get_option('usces_custom_customer_select'); |
| 1847 |
$meansoption = ''; |
| 1848 |
foreach($means as $meankey => $meanvalue) { |
| 1849 |
$selected = ($meankey == $entry['means']) ? " selected='selected'" : ""; |
| 1850 |
$meansoption .= "<option value='".esc_attr($meankey)."'".$selected.">".esc_html($meanvalue)."</option>\n"; |
| 1851 |
} |
| 1852 |
$essential = $entry['essential'] == 1 ? " checked='checked'" : ""; |
| 1853 |
$value = ''; |
| 1854 |
if(is_array($entry['value'])) { |
| 1855 |
foreach($entry['value'] as $k => $v) { |
| 1856 |
$value .= $v."\n"; |
| 1857 |
} |
| 1858 |
} |
| 1859 |
$value = esc_attr(trim($value)); |
| 1860 |
$positions = get_option('usces_custom_field_position_select'); |
| 1861 |
$positionsoption = ''; |
| 1862 |
foreach($positions as $poskey => $posvalue) { |
| 1863 |
$selected = ($poskey == $entry['position']) ? " selected='selected'" : ""; |
| 1864 |
$positionsoption .= "<option value='".esc_attr($poskey)."'".$selected.">".esc_html($posvalue)."</option>\n"; |
| 1865 |
} |
| 1866 |
|
| 1867 |
$r .= "\n\t<tr id='cscs-{$key}' class='{$style}'>"; |
| 1868 |
$r .= "\n\t\t<td class='left'><div><input type='text' name='cscs[{$key}][key]' id='cscs[{$key}][key]' class='optname' size='20' value='{$key}' readonly /></div>"; |
| 1869 |
$r .= "\n\t\t<div><input type='text' name='cscs[{$key}][name]' id='cscs[{$key}][name]' class='optname' size='20' value='{$name}' /></div>"; |
| 1870 |
$r .= "\n\t\t<div class='optcheck'><select name='cscs[{$key}][means]' id='cscs[{$key}][means]'>".$meansoption."</select>\n"; |
| 1871 |
$r .= "<input type='checkbox' name='cscs[{$key}][essential]' id='cscs[{$key}][essential]' value='1'{$essential} /><label for='cscs[{$key}][essential]'>".__('Required','usces')."</label>\n"; |
| 1872 |
$r .= "<select name='cscs[{$key}][position]' id='cscs[{$key}][position]'>".$positionsoption."</select></div>"; |
| 1873 |
$r .= "\n\t\t<div class='submit'><input type='button' name='del_cscs[{$key}]' id='del_cscs[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customField.delCustomer(\"{$key}\");' />"; |
| 1874 |
$r .= "\n\t\t<input type='button' name='upd_cscs[{$key}]' id='upd_cscs[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customField.updCustomer(\"{$key}\");' /></div>"; |
| 1875 |
$r .= "\n\t\t<div id='cscs_loading-{$key}' class='meta_submit_loading'></div>"; |
| 1876 |
$r .= "</td>"; |
| 1877 |
$r .= "\n\t\t<td class='item-opt-value'><textarea name='cscs[{$key}][value]' id='cscs[{$key}][value]' class='optvalue'>{$value}</textarea></td>\n\t</tr>"; |
| 1878 |
return $r; |
| 1879 |
} |
| 1880 |
|
| 1881 |
/** |
| 1882 |
* list custom delivery meta row |
| 1883 |
*/ |
| 1884 |
function _list_custom_delivery_meta_row($key, $entry) { |
| 1885 |
$r = ''; |
| 1886 |
$style = ''; |
| 1887 |
$key = esc_attr($key); |
| 1888 |
|
| 1889 |
$name = esc_attr($entry['name']); |
| 1890 |
$means = get_option('usces_custom_delivery_select'); |
| 1891 |
$meansoption = ''; |
| 1892 |
foreach($means as $meankey => $meanvalue) { |
| 1893 |
$selected = ($meankey == $entry['means']) ? " selected='selected'" : ""; |
| 1894 |
$meansoption .= "<option value='".esc_attr($meankey)."'".$selected.">".esc_html($meanvalue)."</option>\n"; |
| 1895 |
} |
| 1896 |
$essential = $entry['essential'] == 1 ? " checked='checked'" : ""; |
| 1897 |
$value = ''; |
| 1898 |
if(is_array($entry['value'])) { |
| 1899 |
foreach($entry['value'] as $k => $v) { |
| 1900 |
$value .= $v."\n"; |
| 1901 |
} |
| 1902 |
} |
| 1903 |
$value = esc_attr(trim($value)); |
| 1904 |
$positions = get_option('usces_custom_field_position_select'); |
| 1905 |
$positionsoption = ''; |
| 1906 |
foreach($positions as $poskey => $posvalue) { |
| 1907 |
$selected = ($poskey == $entry['position']) ? " selected='selected'" : ""; |
| 1908 |
$positionsoption .= "<option value='".esc_attr($poskey)."'".$selected.">".esc_html($posvalue)."</option>\n"; |
| 1909 |
} |
| 1910 |
|
| 1911 |
$r .= "\n\t<tr id='csde-{$key}' class='{$style}'>"; |
| 1912 |
$r .= "\n\t\t<td class='left'><div><input type='text' name='csde[{$key}][key]' id='csde[{$key}][key]' class='optname' size='20' value='{$key}' readonly /></div>"; |
| 1913 |
$r .= "\n\t\t<div><input type='text' name='csde[{$key}][name]' id='csde[{$key}][name]' class='optname' size='20' value='{$name}' /></div>"; |
| 1914 |
$r .= "\n\t\t<div class='optcheck'><select name='csde[{$key}][means]' id='csde[{$key}][means]'>".$meansoption."</select>\n"; |
| 1915 |
$r .= "<input type='checkbox' name='csde[{$key}][essential]' id='csde[{$key}][essential]' value='1'{$essential} /><label for='csde[{$key}][essential]'>".__('Required','usces')."</label>\n"; |
| 1916 |
$r .= "<select name='csde[{$key}][position]' id='csde[{$key}][position]'>".$positionsoption."</select></div>"; |
| 1917 |
$r .= "\n\t\t<div class='submit'><input type='button' name='del_csde[{$key}]' id='del_csde[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customField.delDelivery(\"{$key}\");' />"; |
| 1918 |
$r .= "\n\t\t<input type='button' name='upd_csde[{$key}]' id='upd_csde[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customField.updDelivery(\"{$key}\");' /></div>"; |
| 1919 |
$r .= "\n\t\t<div id='csde_loading-{$key}' class='meta_submit_loading'></div>"; |
| 1920 |
$r .= "</td>"; |
| 1921 |
$r .= "\n\t\t<td class='item-opt-value'><textarea name='csde[{$key}][value]' id='csde[{$key}][value]' class='optvalue'>{$value}</textarea></td>\n\t</tr>"; |
| 1922 |
return $r; |
| 1923 |
} |
| 1924 |
|
| 1925 |
/** |
| 1926 |
* list custom member meta row |
| 1927 |
*/ |
| 1928 |
function _list_custom_member_meta_row($key, $entry) { |
| 1929 |
$r = ''; |
| 1930 |
$style = ''; |
| 1931 |
$key = esc_attr($key); |
| 1932 |
|
| 1933 |
$name = esc_attr($entry['name']); |
| 1934 |
$means = get_option('usces_custom_member_select'); |
| 1935 |
$meansoption = ''; |
| 1936 |
foreach($means as $meankey => $meanvalue) { |
| 1937 |
$selected = ($meankey == $entry['means']) ? " selected='selected'" : ""; |
| 1938 |
$meansoption .= "<option value='".esc_attr($meankey)."'".$selected.">".esc_html($meanvalue)."</option>\n"; |
| 1939 |
} |
| 1940 |
$essential = $entry['essential'] == 1 ? " checked='checked'" : ""; |
| 1941 |
$value = ''; |
| 1942 |
if(is_array($entry['value'])) { |
| 1943 |
foreach($entry['value'] as $k => $v) { |
| 1944 |
$value .= $v."\n"; |
| 1945 |
} |
| 1946 |
} |
| 1947 |
$value = esc_attr(trim($value)); |
| 1948 |
$positions = get_option('usces_custom_field_position_select'); |
| 1949 |
$positionsoption = ''; |
| 1950 |
foreach($positions as $poskey => $posvalue) { |
| 1951 |
$selected = ($poskey == $entry['position']) ? " selected='selected'" : ""; |
| 1952 |
$positionsoption .= "<option value='".esc_attr($poskey)."'".$selected.">".esc_attr($posvalue)."</option>\n"; |
| 1953 |
} |
| 1954 |
$r .= "\n\t<tr id='csmb-{$key}' class='{$style}'>"; |
| 1955 |
$r .= "\n\t\t<td class='left'><div><input type='text' name='csmb[{$key}][key]' id='csmb[{$key}][key]' class='optname' size='20' value='{$key}' readonly /></div>"; |
| 1956 |
$r .= "\n\t\t<div><input type='text' name='csmb[{$key}][name]' id='csmb[{$key}][name]' class='optname' size='20' value='{$name}' /></div>"; |
| 1957 |
$r .= "\n\t\t<div class='optcheck'><select name='csmb[{$key}][means]' id='csmb[{$key}][means]'>".$meansoption."</select>\n"; |
| 1958 |
$r .= "<input type='checkbox' name='csmb[{$key}][essential]' id='csmb[{$key}][essential]' value='1'{$essential} /><label for='csmb[{$key}][essential]'>".__('Required','usces')."</label>\n"; |
| 1959 |
$r .= "<select name='csmb[{$key}][position]' id='csmb[{$key}][position]'>".$positionsoption."</select></div>"; |
| 1960 |
$r .= "\n\t\t<div class='submit'><input type='button' name='del_csmb[{$key}]' id='del_csmb[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customField.delMember(\"{$key}\");' />"; |
| 1961 |
$r .= "\n\t\t<input type='button' name='upd_csmb[{$key}]' id='upd_csmb[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customField.updMember(\"{$key}\");' /></div>"; |
| 1962 |
$r .= "\n\t\t<div id='csmb_loading-{$key}' class='meta_submit_loading'></div>"; |
| 1963 |
$r .= "</td>"; |
| 1964 |
$r .= "\n\t\t<td class='item-opt-value'><textarea name='csmb[{$key}][value]' id='csmb[{$key}][value]' class='optvalue'>{$value}</textarea></td>\n\t</tr>"; |
| 1965 |
return $r; |
| 1966 |
} |
| 1967 |
//20100818ysk end |
| 1968 |
|
| 1969 |
function change_states_ajax(){ |
| 1970 |
global $usces, $usces_states; |
| 1971 |
$_POST = $usces->stripslashes_deep_post($_POST); |
| 1972 |
|
| 1973 |
$c = $_POST['country']; |
| 1974 |
$res = ''; |
| 1975 |
//20110331ysk start |
| 1976 |
/* if( !isset($usces_states[$c]) || empty($usces_states[$c]) ) |
| 1977 |
die('error'); |
| 1978 |
|
| 1979 |
foreach( (array)$usces_states[$c] as $state ){ |
| 1980 |
$res .= '<option value="' . $state . '">' . $state . '</option>'; |
| 1981 |
}*/ |
| 1982 |
$prefs = get_usces_states($c); |
| 1983 |
if(is_array($prefs) and 0 < count($prefs)) { |
| 1984 |
foreach((array)$prefs as $state) { |
| 1985 |
$res .= '<option value="' . $state . '">' . $state . '</option>'; |
| 1986 |
} |
| 1987 |
} else { |
| 1988 |
die('error'); |
| 1989 |
} |
| 1990 |
//20110331ysk end |
| 1991 |
die($res); |
| 1992 |
} |
| 1993 |
|
| 1994 |
//20110331ysk start |
| 1995 |
function get_usces_states($country) { |
| 1996 |
global $usces, $usces_states; |
| 1997 |
|
| 1998 |
$states = array(); |
| 1999 |
$prefs = maybe_unserialize($usces->options['province']); |
| 2000 |
if( !isset($prefs[$country]) || empty($prefs[$country]) ) { |
| 2001 |
if($country == $usces->options['system']['base_country']) { |
| 2002 |
foreach((array)$prefs as $state) { |
| 2003 |
if(!is_array($state)) |
| 2004 |
array_push($states, $state); |
| 2005 |
} |
| 2006 |
if(count($states) == 0) { |
| 2007 |
if( !empty($usces_states[$country]) ) { |
| 2008 |
$prefs = $usces_states[$country]; |
| 2009 |
if(is_array($prefs)) { |
| 2010 |
$states = $prefs; |
| 2011 |
} |
| 2012 |
} |
| 2013 |
} |
| 2014 |
} else { |
| 2015 |
if( !empty($usces_states[$country]) ) { |
| 2016 |
$prefs = $usces_states[$country]; |
| 2017 |
if(is_array($prefs)) { |
| 2018 |
$states = $prefs; |
| 2019 |
} |
| 2020 |
} |
| 2021 |
} |
| 2022 |
} else { |
| 2023 |
$states = $prefs[$country]; |
| 2024 |
} |
| 2025 |
return $states; |
| 2026 |
} |
| 2027 |
|
| 2028 |
function target_market_ajax() { |
| 2029 |
global $usces; |
| 2030 |
$_POST = $usces->stripslashes_deep_post($_POST); |
| 2031 |
$res = ""; |
| 2032 |
$target = explode(",", $_POST['target']); |
| 2033 |
foreach((array)$target as $country) { |
| 2034 |
$prefs = get_usces_states($country); |
| 2035 |
if(is_array($prefs) and 0 < count($prefs)) { |
| 2036 |
$pos = strpos($prefs[0], '--'); |
| 2037 |
if($pos !== false) array_shift($prefs); |
| 2038 |
$res .= $country.","; |
| 2039 |
foreach((array)$prefs as $state) { |
| 2040 |
$res .= $state."\n"; |
| 2041 |
} |
| 2042 |
$res = rtrim($res, "\n")."#usces#"; |
| 2043 |
//20110430ysk start |
| 2044 |
} else { |
| 2045 |
$res .= $country.",#usces#"; |
| 2046 |
//20110430ysk end |
| 2047 |
} |
| 2048 |
} |
| 2049 |
$res = rtrim($res, "#usces#"); |
| 2050 |
die($res); |
| 2051 |
} |
| 2052 |
//20110331ysk end |
| 2053 |
//20120309ysk start 0000430 |
| 2054 |
function usces_admin_ajax() { |
| 2055 |
switch($_POST['mode']) { |
| 2056 |
case 'options_backup': |
| 2057 |
$options = get_option('usces'); |
| 2058 |
$res = true; |
| 2059 |
if( is_array($options) ) { |
| 2060 |
$usces_backup_date = current_time('mysql'); |
| 2061 |
update_option('usces_backup', $options); |
| 2062 |
update_option('usces_backup_date', $usces_backup_date); |
| 2063 |
$res = $usces_backup_date; |
| 2064 |
} else { |
| 2065 |
$res = false; |
| 2066 |
} |
| 2067 |
die($res); |
| 2068 |
break; |
| 2069 |
case 'options_restore': |
| 2070 |
$options = get_option('usces_backup'); |
| 2071 |
$res = true; |
| 2072 |
if( is_array($options) ) { |
| 2073 |
update_option('usces', $options); |
| 2074 |
} else { |
| 2075 |
$res = false; |
| 2076 |
} |
| 2077 |
die($res); |
| 2078 |
break; |
| 2079 |
} |
| 2080 |
do_action('usces_action_admin_ajax'); |
| 2081 |
} |
| 2082 |
//20120309ysk end |
| 2083 |
function usces_order_recalculation( $order_id, $mem_id, $post_ids, $skus, $prices, $quants, $use_point, $shipping_charge, $cod_fee ) { |
| 2084 |
global $usces; |
| 2085 |
|
| 2086 |
$res = 'ok'; |
| 2087 |
if( !empty($order_id) ) { |
| 2088 |
$data = $usces->get_order_data( $order_id, 'direct' ); |
| 2089 |
$condition = unserialize( $data['order_condition'] ); |
| 2090 |
} else { |
| 2091 |
$condition = $usces->get_condition(); |
| 2092 |
} |
| 2093 |
//usces_log('condition : '.print_r($condition,true), 'acting_transaction.log'); |
| 2094 |
|
| 2095 |
$post_id = explode("#usces#", $post_ids); |
| 2096 |
//$sku = explode("#usces#", $skus); |
| 2097 |
$price = explode("#usces#", $prices); |
| 2098 |
$quant = explode("#usces#", $quants); |
| 2099 |
$cart = array(); |
| 2100 |
for( $i = 0; $i < count($post_id); $i++ ) { |
| 2101 |
if( $post_id[$i] ) |
| 2102 |
//$cart[] = array( "post_id"=>$post_id[$i], "sku"=>$sku[$i], "price"=>$price[$i], "quantity"=>$quant[$i] ); |
| 2103 |
$cart[] = array( "post_id"=>$post_id[$i], "price"=>$price[$i], "quantity"=>$quant[$i] ); |
| 2104 |
} |
| 2105 |
|
| 2106 |
$total_items_price = 0; |
| 2107 |
foreach( $cart as $cart_row ) { |
| 2108 |
$total_items_price += $cart_row['price'] * $cart_row['quantity']; |
| 2109 |
} |
| 2110 |
$meminfo = $usces->get_member_info( $mem_id ); |
| 2111 |
|
| 2112 |
$discount = 0; |
| 2113 |
if( $condition['display_mode'] == 'Promotionsale' ) { |
| 2114 |
if( $condition['campaign_privilege'] == 'discount' ) { |
| 2115 |
if ( 0 === (int)$condition['campaign_category'] ) { |
| 2116 |
$discount = $total_items_price * $condition['privilege_discount'] / 100; |
| 2117 |
} else { |
| 2118 |
foreach( $cart as $cart_row ) { |
| 2119 |
if( in_category( (int)$condition['campaign_category'], $cart_row['post_id']) ) { |
| 2120 |
$discount += $cart_row['price'] * $cart_row['quantity'] * $condition['privilege_discount'] / 100; |
| 2121 |
} |
| 2122 |
} |
| 2123 |
} |
| 2124 |
} |
| 2125 |
} |
| 2126 |
if( 0 < $discount ) $discount = ceil($discount * -1); |
| 2127 |
|
| 2128 |
$point = 0; |
| 2129 |
if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($meminfo['ID']) ) { |
| 2130 |
if( $condition['display_mode'] == 'Promotionsale' ) { |
| 2131 |
if( $condition['campaign_privilege'] == 'discount' ) { |
| 2132 |
foreach( $cart as $cart_row ) { |
| 2133 |
$cats = $usces->get_post_term_ids( $cart_row['post_id'], 'category' ); |
| 2134 |
if( !in_array( $condition['campaign_category'], $cats ) ) { |
| 2135 |
$rate = get_post_meta( $cart_row['post_id'], '_itemPointrate', true ); |
| 2136 |
$price = $cart_row['price'] * $cart_row['quantity']; |
| 2137 |
$point += $price * $rate / 100; |
| 2138 |
} |
| 2139 |
} |
| 2140 |
} elseif( $condition['campaign_privilege'] == 'point' ) { |
| 2141 |
foreach( $cart as $cart_row ) { |
| 2142 |
$rate = get_post_meta( $cart_row['post_id'], '_itemPointrate', true ); |
| 2143 |
$price = $cart_row['price'] * $cart_row['quantity']; |
| 2144 |
$cats = $usces->get_post_term_ids( $cart_row['post_id'], 'category' ); |
| 2145 |
if( in_array( $condition['campaign_category'], $cats ) ) { |
| 2146 |
$point += $price * $rate / 100 * $condition['privilege_point']; |
| 2147 |
} else { |
| 2148 |
$point += $price * $rate / 100; |
| 2149 |
} |
| 2150 |
} |
| 2151 |
} |
| 2152 |
} else { |
| 2153 |
foreach( $cart as $cart_row ) { |
| 2154 |
$rate = get_post_meta( $cart_row['post_id'], '_itemPointrate', true ); |
| 2155 |
$price = $cart_row['price'] * $cart_row['quantity']; |
| 2156 |
$point += $price * $rate / 100; |
| 2157 |
} |
| 2158 |
} |
| 2159 |
} |
| 2160 |
|
| 2161 |
if( 0 < $point ) $point = ceil($point); |
| 2162 |
//20130425ysk start 0000699 |
| 2163 |
if( 0 < $use_point ) { |
| 2164 |
$point = ceil( $point - ( $point * $use_point / $total_items_price ) ); |
| 2165 |
if( 0 > $point ) |
| 2166 |
$point = 0; |
| 2167 |
} |
| 2168 |
//20130425ysk end |
| 2169 |
$point = apply_filters( 'usces_filter_set_point_recalculation', $point, $condition, $cart, $meminfo, $use_point ); |
| 2170 |
$total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee; |
| 2171 |
$total_price = apply_filters('usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee); |
| 2172 |
$materials = compact( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point', 'discount' ); |
| 2173 |
$tax = $usces->getTax( $total_price, $materials ); |
| 2174 |
$total_full_price = $total_price + $tax; |
| 2175 |
$total_full_price = apply_filters('usces_filter_set_cart_fees_total_full_price', $total_full_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee); |
| 2176 |
|
| 2177 |
return $res."#usces#".$discount."#usces#".usces_crform( $tax, false, false, 'return', false )."#usces#".$point."#usces#".usces_crform( $total_full_price, false, false, 'return', false ); |
| 2178 |
} |
| 2179 |
?> |
| 2180 |
|