PluginProbe
Welcart e-Commerce / 1.4.0
Welcart e-Commerce v1.4.0
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / functions / system_post.php

system_post.php in Welcart e-Commerce 1.4.0, at functions/system_post.php

976 lines 30.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * system_option
4 */
5 function usces_add_system_option( $option_name, $newvalue ){
6 global $usces;
7 $newvalue = $usces->stripslashes_deep_post($newvalue);
8 $option_value = get_option($option_name);
9
10 if( !empty($option_value) ){
11 $option_num = count($option_value);
12 $unique = true;
13 $sortnull = true;
14 foreach( (array)$option_value as $value ){
15 if( $value['name'] == $newvalue['name'] )
16 $unique = false;
17 if( !isset($value['sort']) )
18 $sortnull = false;
19 $sort[] = $value['sort'];
20 }
21 if( !$unique )
22 return -1;
23
24 rsort($sort);
25 $next_number = reset($sort) + 1;
26 $unique_sort = array_unique($sort);
27 if( $option_num !== count($unique_sort) || $option_num !== $next_number || !$sortnull){
28 //To repair the sort data
29 $i = 0;
30 foreach( $option_value as $opkey => $opvalue ){
31 $option_value[$opkey]['sort'] = $i;
32 $i++;
33 }
34 }
35 }
36 $newvalue['sort'] = !empty($option_num) ? $option_num : 0;
37 $option_value[] = $newvalue;
38 update_option($option_name, $option_value);
39 krsort($option_value);
40 $key_arr = each($option_value);
41 $last_index = $key_arr['key'];
42
43 return $last_index;
44 }
45
46 function usces_update_system_option( $option_name, $index, $newvalue ){
47 global $usces;
48 $newvalue = $usces->stripslashes_deep_post($newvalue);
49 $option_value = get_option($option_name);
50
51 if( !empty($option_value) ){
52 $unique = true;
53 foreach( (array)$option_value as $value_id => $value ){
54 if( $value['name'] == $newvalue['name'] && $value_id != $index ){
55 $unique = false;
56 break;
57 }
58 }
59 if( !$unique )
60 return -1;
61
62 $option_value[$index] = $newvalue;
63 update_option($option_name, $option_value);
64 $lid = $index;
65 }else{
66 $lid = -1;
67 }
68
69 return $lid;
70 }
71 function usces_get_system_option( $option_name, $keyflag = 'sort' ) {
72 $sysopts = array();
73 $option_value = get_option($option_name);
74
75 if( !is_array($option_value) ) return $sysopts;
76
77 foreach( $option_value as $id => $value ){
78 $key = isset($value[$keyflag]) ? $value[$keyflag] : $value['sort'];
79 switch( $option_name ){
80 case 'usces_payment_method':
81 $sysopts[$key] = array(
82 'id' => $id,
83 'name' => $value['name'],
84 'explanation' => $value['explanation'],
85 'settlement' => $value['settlement'],
86 'module' => $value['module'],
87 'sort' => $value['sort'],
88 'use' => isset( $value['use'] ) ? $value['use'] : 'activate'
89 );
90 break;
91 }
92 }
93 ksort($sysopts);
94
95 return $sysopts;
96 }
97
98 function usces_sort_system_option( $option_name, $idstr ) {
99 global $usces;
100 $option_value = get_option($option_name);
101
102 if( !empty($option_value) ){
103 $ids = explode(',', $idstr);
104 $c = 0;
105 foreach( (array)$ids as $id ){
106 // usces_log('ids : '.$id.$c, 'acting_transaction.log');
107 $option_value[$id]['sort'] = $c;
108 $c++;
109 // usces_log('options : '.print_r($option_value,true), 'acting_transaction.log');
110 }
111 update_option( $option_name, $option_value );
112 }
113 return;
114 }
115
116 function usces_del_system_option( $option_name, $id ) {
117 global $usces;
118 $option_value = get_option($option_name);
119
120 if( !empty($option_value) && isset($option_value[$id]) && !empty($option_value)){
121 unset($option_value[$id]);
122 $op = array();
123 foreach( (array)$option_value as $opkey => $opvalue ){
124 $op[$opvalue['sort']] = $opkey;
125 }
126
127 ksort($op);
128
129 $c = 0;
130 foreach( $op as $opid ){
131 $option_value[$opid]['sort'] = $c;
132 $c++;
133 }
134 update_option( $option_name, $option_value );
135 }
136 return;
137 }
138
139 /**
140 * payment_list
141 */
142 function payment_list( $option_value ) {
143 // Exit if no meta
144 if ( empty($option_value) ) {
145 ?>
146 <table id="payment-table" class="list" style="display: none;">
147 <thead>
148 <tr>
149 <th class="hanldh"> </th>
150 <th class="left"><?php _e('A payment method name','usces'); ?></th>
151 <th><?php _e('explanation','usces'); ?></th>
152 <th><?php _e('Type of payment','usces'); ?></th>
153 <th><?php _e('Payment module','usces'); ?></th>
154 </tr>
155 </thead>
156 <tbody id="payment-list">
157 <tr><td></td><td></td><td></td></tr>
158 </tbody>
159 </table>
160 <?php
161 }else{
162 ?>
163 <table id="payment-table" class="list">
164 <thead>
165 <tr>
166 <th class="hanldh"> </th>
167 <th class="paymentname"><?php _e('A payment method name','usces') ?></th>
168 <th class="paymentexplanation"><?php _e('explanation','usces') ?></th>
169 <th class="paymentsettlement"><?php _e('Type of payment','usces') ?></th>
170 <th class="paymentmodule"><?php _e('Payment module','usces') ?></th>
171 </tr>
172 </thead>
173 <tbody id="payment-list">
174 <?php
175 foreach ( $option_value as $value )
176 echo _payment_list_row( $value );
177 ?>
178 </tbody>
179 </table>
180 <div id="payment_ajax-response"></div>
181 <?php
182 }
183 }
184
185 /**
186 * payment_list_row
187 */
188 function _payment_list_row( $value ) {
189 global $usces;
190 $r = '';
191 $style = '';
192
193 if ( empty($value) ) return;
194 $id = (int) $value['id'];
195 $name = esc_attr($value['name']);
196 $explanation = esc_attr($value['explanation']);
197 $settlement = $value['settlement'];
198 $module = esc_attr($value['module']);
199 $sort = (int) $value['sort'];
200 $use = ( isset($value['use']) ) ? $value['use'] : 'activate';
201
202 ob_start();
203 ?>
204 <tr class='metastuffrow'>
205 <td colspan='5'>
206 <table id='payment-<?php echo $id; ?>' class='metastufftable'>
207 <tr>
208 <th class='handlb' rowspan='2'> </th>
209 <td class='paymentname'>
210 <div><input name='payment[<?php echo $id; ?>][name]' id='payment[<?php echo $id; ?>][name]' class='metaboxfield' type='text' value='<?php echo $name; ?>' /></div>
211 <div><input name='payment[<?php echo $id; ?>][use]' id='payment[<?php echo $id; ?>][use_activate]' type="radio" value="activate"<?php if($use != 'deactivate') echo ' checked="checked"'; ?> /><label for='payment[<?php echo $id; ?>][use_activate]'><?php _e('Activate','usces'); ?></label> 
212 <input name='payment[<?php echo $id; ?>][use]' id='payment[<?php echo $id; ?>][use_deactivate]' type="radio" value="deactivate"<?php if($use == 'deactivate') echo ' checked="checked"'; ?> /><label for='payment[<?php echo $id; ?>][use_deactivate]'><?php _e('Deactivate','usces'); ?></label></div>
213 </td>
214 <td class='paymentexplanation'><textarea name='payment[<?php echo $id; ?>][explanation]' id='payment[<?php echo $id; ?>][explanation]' class='metaboxfield'><?php echo $explanation; ?></textarea></td>
215 <td class='paymentsettlement'>
216 <select name='payment[<?php echo $id; ?>][settlement]' id='payment[<?php echo $id; ?>][settlement]' class='metaboxfield'>
217 <option value='#NONE#'><?php _e('-- Select --','usces'); ?></option>
218 <?php
219 foreach ($usces->payment_structure as $psk => $psv){
220 $selected = ($psk == $settlement) ? ' selected="selected"' : '';
221 ?>
222 <option value='<?php echo $psk; ?>'<?php echo $selected; ?>><?php echo esc_html($psv); ?></option>
223 <?php
224 }
225 ?>
226 </select>
227 </td>
228 <td class='paymentmodule'><div><input name='payment[<?php echo $id; ?>][module]' id='payment[<?php echo $id; ?>][module]' class='metaboxfield' type='text' value='<?php echo $module; ?>' /></div></td>
229 </tr>
230 <tr>
231 <td colspan='4' class='submittd'>
232 <div id='paymentsubmit-<?php echo $id; ?>' class='submit'>
233 <input name='deletepayment' id='deletepayment[<?php echo $id; ?>]' type='button' value='<?php esc_attr_e(__( 'Delete' )); ?>' onclick="payment.post('del', <?php echo $id; ?>);" />
234 <input name='updatepayment' id='updatepayment[<?php echo $id; ?>]' type='button' value='<?php esc_attr_e(__( 'Update' )); ?>' onclick="payment.post('update', <?php echo $id; ?>);" />
235 <input name='payment[<?php echo $id; ?>][sort]' id='payment[<?php echo $id; ?>][sort]' type='hidden' value='<?php echo $sort; ?>' />
236 </div>
237 <div id='payment_loading-<?php echo $id; ?>' class='meta_submit_loading'></div>
238 </td>
239 </tr>
240 </table>
241 </td>
242 </tr>
243 <?php
244 $r = ob_get_contents();
245 ob_end_clean();
246 return $r;
247 }
248 /**
249 * payment_form
250 */
251 function payment_form() {
252 global $usces;
253 ?>
254 <p><strong><?php _e('Add a new method forpayment ','usces') ?> : </strong></p>
255 <table id="newmeta2">
256 <thead>
257 <tr>
258 <th class="left"><?php _e('A payment method name','usces') ?></th>
259 <th><?php _e('explanation','usces') ?></th>
260 <th><?php _e('Type of payment','usces') ?></th>
261 <th><?php _e('Payment module','usces') ?></th>
262 </tr>
263 </thead>
264 <tbody>
265 <tr>
266 <td class='paymentname'><input type="text" id="newname" name="newname" class="metaboxfield" tabindex="7" value="" /></td>
267 <td class='paymentexplanation'><textarea id="newexplanation" name="newexplanation" class='metaboxfield'></textarea></td>
268 <td class='paymentsettlement'>
269 <select name="newsettlement" id="newsettlement" class='metaboxfield'>
270 <option value='#NONE#'><?php _e('-- Select --','usces'); ?></option>
271 <?php foreach ($usces->payment_structure as $psk => $psv) { ?>
272 <option value="<?php echo esc_attr($psk); ?>"><?php echo esc_html($psv); ?></option>
273 <?php } ?>
274 </select>
275 </td>
276 <td class='paymentmodule'><input type="text" id="newmodule" name="newmodule" class="metaboxfield" tabindex="9" value="" /></td>
277 </tr>
278
279 <tr>
280 <td colspan="4" class="submittd">
281 <div id='newpaymentsubmit' class='submit'><input name="add_payment" type="button" id="add_payment" tabindex="9" value="<?php _e('Add a new method forpayment ','usces') ?>" onclick="payment.post('add', 0);" /></div>
282 <div id="newpayment_loading" class="meta_submit_loading"></div>
283 </td>
284 </tr>
285 </tbody>
286 </table>
287 <?php
288 }
289
290
291 function payment_ajax()
292 {
293 global $usces;
294
295 $id = NULL;
296
297 if( $_POST['action'] != 'payment_ajax' ) die(0);
298
299 if(isset($_POST['update'])){
300 $id = up_payment_method();
301
302 }else if(isset($_POST['delete'])){
303 $id = del_payment_method();
304
305 }else if(isset($_POST['sort'])){
306 $res = sort_payment_method();
307
308 }else{
309 $id = add_payment_method();
310
311 }
312
313 $option_value = usces_get_system_option('usces_payment_method', 'sort');
314 $r = '';
315 foreach ( $option_value as $value )
316 $r .= _payment_list_row( $value );
317
318 $res = $r . '#usces#' . $id;
319
320 die( $res );
321 }
322 /**
323 * add_payment
324 */
325 function add_payment_method() {
326
327 $newvalue['name'] = isset($_POST['newname']) ? trim( $_POST['newname'] ) : '';
328 $newvalue['explanation'] = isset($_POST['newexplanation']) ? trim( $_POST['newexplanation'] ) : '';
329 $newvalue['settlement'] = isset($_POST['newsettlement']) ? $_POST['newsettlement'] : '';
330 $newvalue['module'] = isset($_POST['newmodule']) ? trim( $_POST['newmodule'] ) : '';
331 if( 'acting_paypal_ec' == $newvalue['settlement'] ) {
332 $newvalue['explanation'] .= "
333 <div><a href=\"#\" onclick=\"javascript:window.open('https://www.paypal.com/jp/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside','olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350');\"><img src=\"https://www.paypal.com/ja_JP/JP/i/bnr/horizontal_solution_4_jcb.gif\" border=\"0\" alt=\"ソリューション画像\"></a></div>
334 <div><a href=\"https://www.paypal.com/jp/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside\" target=\"_blank\" >PayPal について</a></div>";
335 }
336 if ( !empty( $newvalue['name'] ) ) {
337 $lid = usces_add_system_option( 'usces_payment_method', $newvalue );
338
339 return $lid;
340 }
341 return false;
342 } // add_meta
343 /**
344 * update_payment
345 */
346
347 function up_payment_method() {
348 global $usces;
349
350 $value = array();
351 //$id = isset($_POST['id']) ? (int)$_POST['id'] : '';
352 $id = $_POST['id'];
353 $value['name'] = isset($_POST['name']) ? trim( $_POST['name'] ) : '';
354 $value['explanation'] = isset($_POST['explanation']) ? trim( $_POST['explanation'] ) : '';
355 $value['settlement'] = isset($_POST['settlement']) ? $_POST['settlement'] : '';
356 $value['module'] = isset($_POST['module']) ? trim( $_POST['module'] ) : '';
357 $value['sort'] = isset($_POST['sort']) ?(int)$_POST['sort'] : 0;
358 $value['use'] = isset($_POST['use']) ? $_POST['use'] : 'activate';
359
360 if ( !empty( $value['name'] ) && !WCUtils::is_blank($id) ) {
361
362 $id = usces_update_system_option( 'usces_payment_method', $id, $value );
363
364 return $id;
365 }
366 return -2;
367 } // add_meta
368
369 /**
370 * delete_payment
371 */
372 function del_payment_method() {
373 global $usces;
374
375 $id = $_POST['id'];
376
377 if ( !WCUtils::is_blank($id) ) {
378
379 usces_del_system_option( 'usces_payment_method', $id );
380
381 return $id;
382 }
383 return false;
384 }
385
386 function sort_payment_method(){
387
388 return usces_sort_system_option( 'usces_payment_method', $_POST['idstr'] );
389 }
390
391 function add_delivery_method() {
392 $options = get_option('usces');
393 $name = trim($_POST['name']);
394 foreach((array)$options['delivery_method'] as $deli){
395 $ids[] = (int)$deli['id'];
396 }
397 if(isset($ids)){
398 rsort($ids);
399 $newid = $ids[0]+1;
400 }else{
401 $newid = 0;
402 }
403 $index = isset($options['delivery_method']) ? count($options['delivery_method']) : 0;
404 $options['delivery_method'][$index]['id'] = $newid;
405 $options['delivery_method'][$index]['name'] = $name;
406 $options['delivery_method'][$index]['time'] = str_replace("\r\n", "\n", $_POST['time']);
407 $options['delivery_method'][$index]['time'] = str_replace("\r", "\n", $options['delivery_method'][$index]['time']);
408 $options['delivery_method'][$index]['charge'] = (int)$_POST['charge'];
409 //20101208ysk start
410 $options['delivery_method'][$index]['days'] = (int)$_POST['days'];
411 //20101208ysk end
412 //20101119ysk start
413 $options['delivery_method'][$index]['nocod'] = $_POST['nocod'];
414 //20101119ysk end
415 //20110317ysk start
416 $options['delivery_method'][$index]['intl'] = $_POST['intl'];
417 //20110317ysk end
418 update_option('usces', $options);
419
420 //20101208ysk start
421 //20101119ysk start
422 //$res = $newid . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'];
423 //$res = $newid . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'] . '#usces#' . $options['delivery_method'][$index]['nocod'];
424 //20101119ysk end
425 //20110317ysk start
426 //$res = $newid . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'] . '#usces#' . $options['delivery_method'][$index]['days'] . '#usces#' . $options['delivery_method'][$index]['nocod'];
427 $res = $newid . '#usces#' . stripslashes($name) . '#usces#' . stripslashes($options['delivery_method'][$index]['time']) . '#usces#' . $options['delivery_method'][$index]['charge'] . '#usces#' . $options['delivery_method'][$index]['days'] . '#usces#' . $options['delivery_method'][$index]['nocod'] . '#usces#' . $options['delivery_method'][$index]['intl'];
428 //20110317ysk end
429 //20101208ysk end
430 return $res;
431 }
432
433 function update_delivery_method() {
434 $options = get_option('usces');
435 $name = trim($_POST['name']);
436 $id = (int)$_POST['id'];
437 $charge = (int)$_POST['charge'];
438 for($i=0; $i<count($options['delivery_method']); $i++){
439 if($options['delivery_method'][$i]['id'] === $id){
440 $index = $i;
441 }
442 }
443 $options['delivery_method'][$index]['name'] = $name;
444 $options['delivery_method'][$index]['charge'] = $charge;
445 $options['delivery_method'][$index]['time'] = str_replace("\r\n", "\n", $_POST['time']);
446 $options['delivery_method'][$index]['time'] = str_replace("\r", "\n", $options['delivery_method'][$index]['time']);
447 //20101208ysk start
448 $options['delivery_method'][$index]['days'] = (int)$_POST['days'];
449 //20101208ysk end
450 //20101119ysk start
451 $options['delivery_method'][$index]['nocod'] = $_POST['nocod'];
452 //20101119ysk end
453 //20110317ysk start
454 $options['delivery_method'][$index]['intl'] = $_POST['intl'];
455 //20110317ysk end
456 update_option('usces', $options);
457
458 //20101208ysk start
459 //20101119ysk start
460 //$res = $id . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'];
461 //$res = $id . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'] . '#usces#' . $options['delivery_method'][$index]['nocod'];
462 //20101119ysk end
463 //20110317ysk start
464 //$res = $id . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'] . '#usces#' . $options['delivery_method'][$index]['days'] . '#usces#' . $options['delivery_method'][$index]['nocod'];
465 $res = $id . '#usces#' . stripslashes($name) . '#usces#' . stripslashes($options['delivery_method'][$index]['time']) . '#usces#' . $options['delivery_method'][$index]['charge'] . '#usces#' . $options['delivery_method'][$index]['days'] . '#usces#' . $options['delivery_method'][$index]['nocod'] . '#usces#' . $options['delivery_method'][$index]['intl'];
466 //20110317ysk end
467 //20101208ysk end
468 return $res;
469 }
470
471 function delete_delivery_method() {
472 $options = get_option('usces');
473 $id = (int)$_POST['id'];
474 for($i=0; $i<count($options['delivery_method']); $i++){
475 if($options['delivery_method'][$i]['id'] === $id){
476 $index = $i;
477 }
478 }
479 array_splice($options['delivery_method'], $index, 1);
480 update_option('usces', $options);
481
482 $res = $id . '#usces#0';
483 return $res;
484 }
485
486 function moveup_delivery_method() {
487 $options = get_option('usces');
488 $selected_id = (int)$_POST['id'];
489 $ct = count($options['delivery_method']);
490 for($i=0; $i<$ct; $i++){
491 if($options['delivery_method'][$i]['id'] === $selected_id){
492 $index = $i;
493 }
494 }
495 if($index !== 0) {
496 $from_index = $index;
497 $to_index = $index - 1;
498 $from_dm = $options['delivery_method'][$from_index];
499 $to_dm = $options['delivery_method'][$to_index];
500 for($i=0; $i<$ct; $i++){
501 if($i === $to_index){
502 $options['delivery_method'][$i] = $from_dm;
503 }else if($i === $from_index){
504 $options['delivery_method'][$i] = $to_dm;
505 }
506 }
507 update_option('usces', $options);
508 }
509
510 $id = '';
511 $name = '';
512 $charge = '';
513 $time = '';
514 //20101208ysk start
515 $days = '';
516 //20101208ysk end
517 //20101119ysk start
518 $nocod = '';
519 //20101119ysk end
520 //20110317ysk start
521 $intl = '';
522 //20110317ysk end
523 for($i=0; $i<$ct; $i++){
524 $id .= $options['delivery_method'][$i]['id'] . ',';
525 $name .= $options['delivery_method'][$i]['name'] . ',';
526 $charge .= $options['delivery_method'][$i]['charge'] . ',';
527 $time .= $options['delivery_method'][$i]['time'] . ',';
528 //20101208ysk start
529 $days .= $options['delivery_method'][$i]['days'] . ',';
530 //20101208ysk end
531 //20101119ysk start
532 $nocod .= $options['delivery_method'][$i]['nocod'] . ',';
533 //20101119ysk end
534 //20110317ysk start
535 $intl .= $options['delivery_method'][$i]['intl'] . ',';
536 //20110317ysk end
537 }
538 $id = rtrim($id,',');
539 $name = rtrim($name,',');
540 $charge = rtrim($charge,',');
541 $time = rtrim($time,',');
542 //20101208ysk start
543 $days = rtrim($days,',');
544 //20101208ysk end
545 //20101119ysk start
546 $nocod = rtrim($nocod,',');
547 //20101119ysk end
548 //20110317ysk start
549 $intl = rtrim($intl,',');
550 //20110317ysk end
551
552 //20101208ysk start
553 //20101119ysk start
554 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $selected_id;
555 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $nocod . '#usces#' . $selected_id;
556 //20101119ysk end
557 //20110317ysk start
558 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $days . '#usces#' . $nocod . '#usces#' . $selected_id;
559 $res = $id . '#usces#' . stripslashes($name) . '#usces#' . stripslashes($time) . '#usces#' . $charge . '#usces#' . $days . '#usces#' . $nocod . '#usces#' . $intl . '#usces#' . $selected_id;
560 //20110317ysk end
561 //20101208ysk end
562 return $res;
563 }
564
565 function movedown_delivery_method() {
566 $options = get_option('usces');
567 $selected_id = (int)$_POST['id'];
568 $ct = count($options['delivery_method']);
569 for($i=0; $i<$ct; $i++){
570 if($options['delivery_method'][$i]['id'] === $selected_id){
571 $index = $i;
572 }
573 }
574 if($index < $ct-1) {
575 $from_index = $index;
576 $to_index = $index + 1;
577 $from_dm = $options['delivery_method'][$from_index];
578 $to_dm = $options['delivery_method'][$to_index];
579 for($i=0; $i<$ct; $i++){
580 if($i === $to_index){
581 $options['delivery_method'][$i] = $from_dm;
582 }else if($i === $from_index){
583 $options['delivery_method'][$i] = $to_dm;
584 }
585 }
586 update_option('usces', $options);
587 }
588
589 $id = '';
590 $name = '';
591 $charge = '';
592 $time = '';
593 //20101208ysk start
594 $days = '';
595 //20101208ysk end
596 //20101119ysk start
597 $nocod = '';
598 //20101119ysk end
599 //20110317ysk start
600 $intl = '';
601 //20110317ysk end
602 for($i=0; $i<$ct; $i++){
603 $id .= $options['delivery_method'][$i]['id'] . ',';
604 $name .= $options['delivery_method'][$i]['name'] . ',';
605 $charge .= $options['delivery_method'][$i]['charge'] . ',';
606 $time .= $options['delivery_method'][$i]['time'] . ',';
607 //20101208ysk start
608 $days .= $options['delivery_method'][$i]['days'] . ',';
609 //20101208ysk end
610 //20101119ysk start
611 $nocod .= $options['delivery_method'][$i]['nocod'] . ',';
612 //20101119ysk end
613 //20110317ysk start
614 $intl .= $options['delivery_method'][$i]['intl'] . ',';
615 //20110317ysk end
616 }
617 $id = rtrim($id,',');
618 $name = rtrim($name,',');
619 $charge = rtrim($charge,',');
620 $time = rtrim($time,',');
621 //20101208ysk start
622 $days = rtrim($days,',');
623 //20101208ysk end
624 //20101119ysk start
625 $nocod = rtrim($nocod,',');
626 //20101119ysk end
627 //20110317ysk start
628 $intl = rtrim($intl,',');
629 //20110317ysk end
630
631 //20101208ysk start
632 //20101119ysk start
633 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $selected_id;
634 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $nocod . '#usces#' . $selected_id;
635 //20101119ysk end
636 //20110317ysk start
637 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $days . '#usces#' . $nocod . '#usces#' . $selected_id;
638 $res = $id . '#usces#' . stripslashes($name) . '#usces#' . stripslashes($time) . '#usces#' . $charge . '#usces#' . $days . '#usces#' . $nocod . '#usces#' . $intl . '#usces#' . $selected_id;
639 //20110317ysk end
640 //20101208ysk end
641 return $res;
642 }
643
644 function add_shipping_charge() {
645 global $usces;
646
647 $options = get_option('usces');
648 $name = trim($_POST['name']);
649 //20110317ysk start
650 //20120710ysk start 0000472
651 //$country = trim($_POST['country']);
652 //20110317ysk end
653 //$value = $_POST['value'];
654 //20120710ysk end
655 foreach((array)$options['shipping_charge'] as $charge){
656 $ids[] = (int)$charge['id'];
657 }
658 if(isset($ids)){
659 rsort($ids);
660 $newid = $ids[0]+1;
661 }else{
662 $newid = 0;
663 }
664 $index = isset($options['shipping_charge']) ? count($options['shipping_charge']) : 0;
665 // $prefs = get_option('usces_pref');
666 //20110317ysk start
667 //$prefs = $usces->options['province'];
668 //20110331ysk start
669 //$prefs = $usces_states[$country];
670 //20120710ysk start 0000472
671 //$prefs = get_usces_states($country);
672 //20110331ysk end
673 //20110317ysk end
674 //array_shift($prefs);
675 $target_market = ( isset($options['system']['target_market']) && !empty($options['system']['target_market']) ) ? $options['system']['target_market'] : usces_get_local_target_market();
676 foreach( (array)$target_market as $tm ) {
677 $prefs = get_usces_states($tm);
678 array_shift($prefs);
679 $value = $_POST['value_'.$tm];
680 //20120710ysk end
681
682 $options['shipping_charge'][$index]['id'] = $newid;
683 $options['shipping_charge'][$index]['name'] = $name;
684 //20110317ysk start
685 //20120710ysk start 0000472
686 //$options['shipping_charge'][$index]['country'] = $country;
687 //20110317ysk end
688 //$options['shipping_charge'][$index]["value"] = array();
689 //for($i=0; $i<count($prefs); $i++){
690 // $pref = $prefs[$i];
691 // $options['shipping_charge'][$index]['value'][$pref] = (int)$value[$i];
692 //}
693 for( $i = 0; $i < count($prefs); $i++ ) {
694 $options['shipping_charge'][$index][$tm][$prefs[$i]] = (float)$value[$i];
695 }
696 }
697 //20120710ysk end
698 update_option('usces', $options);
699
700 //20120710ysk start 0000472
701 //$valuestr = implode(',', $options['shipping_charge'][$index]['value']);
702 //20110317ysk start
703 //$res = $newid . '#usces#' . $name . '#usces#' . $valuestr;
704 //$res = $newid . '#usces#' . $name . '#usces#' . $country . '#usces#' . $valuestr;
705 $res = (string)$newid;
706 //20120710ysk end
707 //20110317ysk end
708 return $res;
709 }
710
711 function update_shipping_charge() {
712 global $usces;
713
714 $options = get_option('usces');
715 $name = trim($_POST['name']);
716 //20110317ysk start
717 //20120710ysk start 0000472
718 //$country = trim($_POST['country']);
719 //20110317ysk end
720 //$value = $_POST['value'];
721 //20120710ysk end
722 $id = (int)$_POST['id'];
723 // $prefs = get_option('usces_pref');
724 //20110317ysk start
725 //$prefs = $usces->options['province'];
726 //20110331ysk start
727 //$prefs = $usces_states[$country];
728 //20120710ysk start 0000472
729 //$prefs = get_usces_states($country);
730 //20110331ysk end
731 //20110317ysk end
732 //array_shift($prefs);
733 //20120710ysk end
734
735 for($i=0; $i<count($options['shipping_charge']); $i++){
736 if($options['shipping_charge'][$i]['id'] === $id){
737 $index = $i;
738 }
739 }
740 $options['shipping_charge'][$index]["name"] = $name;
741 //20110317ysk start
742 //20120710ysk start 0000472
743 //$options['shipping_charge'][$index]['country'] = $country;
744 $target_market = ( isset($options['system']['target_market']) && !empty($options['system']['target_market']) ) ? $options['system']['target_market'] : usces_get_local_target_market();
745 foreach( (array)$target_market as $tm ) {
746 $prefs = get_usces_states($tm);
747 array_shift($prefs);
748 $value = $_POST['value_'.$tm];
749 //20110317ysk end
750 //$options['shipping_charge'][$index]["value"] = array();
751 //for($i=0; $i<count($prefs); $i++){
752 // $pref = $prefs[$i];
753 // $options['shipping_charge'][$index]["value"][$pref] = (int)$value[$i];
754 //}
755 for( $i = 0; $i < count($prefs); $i++ ) {
756 $options['shipping_charge'][$index][$tm][$prefs[$i]] = (float)$value[$i];
757 }
758 //20120710ysk end
759 }
760 update_option('usces', $options);
761
762 //20120710ysk start 0000472
763 //$valuestr = implode(',', $options['shipping_charge'][$index]["value"]);
764 //20110317ysk start
765 //$res = $id . '#usces#' . $name . '#usces#' . $valuestr;
766 //$res = $id . '#usces#' . $name . '#usces#' . $country . '#usces#' . $valuestr;
767 $res = (string)$id;
768 //20120710ysk end
769 //20110317ysk end
770 return $res;
771 }
772
773 function delete_shipping_charge() {
774 $options = get_option('usces');
775 $id = (int)$_POST['id'];
776 for($i=0; $i<count($options['shipping_charge']); $i++){
777 if($options['shipping_charge'][$i]['id'] === $id){
778 $index = $i;
779 }
780 }
781 array_splice($options['shipping_charge'], $index, 1);
782 update_option('usces', $options);
783
784 $res = $id . '#usces#0';
785 return $res;
786 }
787 //20101208ysk start
788 function add_delivery_days() {
789 global $usces;
790
791 $options = get_option('usces');
792 $name = trim($_POST['name']);
793 //20110317ysk start
794 //20120710ysk start 0000472
795 //$country = trim($_POST['country']);
796 //20110317ysk end
797 //$value = $_POST['value'];
798 //20120710ysk end
799 foreach((array)$options['delivery_days'] as $charge){
800 $ids[] = (int)$charge['id'];
801 }
802 if(isset($ids)){
803 rsort($ids);
804 $newid = $ids[0]+1;
805 }else{
806 $newid = 0;
807 }
808 $index = isset($options['delivery_days']) ? count($options['delivery_days']) : 0;
809 //20110317ysk start
810 //$prefs = $usces->options['province'];
811 //20110331ysk start
812 //$prefs = $usces_states[$country];
813 //20120710ysk start 0000472
814 //$prefs = get_usces_states($country);
815 //20110331ysk end
816 //20110317ysk end
817 //array_shift($prefs);
818 $target_market = ( isset($options['system']['target_market']) && !empty($options['system']['target_market']) ) ? $options['system']['target_market'] : usces_get_local_target_market();
819 foreach( (array)$target_market as $tm ) {
820 $prefs = get_usces_states($tm);
821 array_shift($prefs);
822 $value = $_POST['value_'.$tm];
823 //20120710ysk end
824
825 $options['delivery_days'][$index]['id'] = $newid;
826 $options['delivery_days'][$index]['name'] = $name;
827 //20110317ysk start
828 //20120710ysk start 0000472
829 //$options['delivery_days'][$index]['country'] = $country;
830 //20110317ysk end
831 //for($i=0; $i<count($prefs); $i++){
832 // $pref = $prefs[$i];
833 // $options['delivery_days'][$index]['value'][$pref] = (int)$value[$i];
834 //}
835 for( $i = 0; $i < count($prefs); $i++ ) {
836 $options['delivery_days'][$index][$tm][$prefs[$i]] = (int)$value[$i];
837 }
838 }
839 //20120710ysk end
840 update_option('usces', $options);
841
842 //20120710ysk start 0000472
843 //$valuestr = implode(',', $options['delivery_days'][$index]['value']);
844 //20110317ysk start
845 //$res = $newid . '#usces#' . $name . '#usces#' . $valuestr;
846 //$res = $newid . '#usces#' . $name . '#usces#' . $country . '#usces#' . $valuestr;
847 $res = (string)$newid;
848 //20120710ysk end
849 //20110317ysk end
850 return $res;
851 }
852
853 function update_delivery_days() {
854 global $usces;
855
856 $options = get_option('usces');
857 $name = trim($_POST['name']);
858 //20110317ysk start
859 //20120710ysk start 0000472
860 //$country = trim($_POST['country']);
861 //20110317ysk end
862 //$value = $_POST['value'];
863 //20120710ysk end
864 $id = (int)$_POST['id'];
865 //20110317ysk start
866 //$prefs = $usces->options['province'];
867 //20110331ysk start
868 //$prefs = $usces_states[$country];
869 //20120710ysk start 0000472
870 //$prefs = get_usces_states($country);
871 //20110331ysk end
872 //20110317ysk end
873 //array_shift($prefs);
874 //20120710ysk end
875
876 for($i=0; $i<count($options['delivery_days']); $i++){
877 if($options['delivery_days'][$i]['id'] === $id){
878 $index = $i;
879 }
880 }
881 $options['delivery_days'][$index]['name'] = $name;
882 //20110317ysk start
883 //20120710ysk start 0000472
884 //$options['delivery_days'][$index]['country'] = $country;
885 $target_market = ( isset($options['system']['target_market']) && !empty($options['system']['target_market']) ) ? $options['system']['target_market'] : usces_get_local_target_market();
886 foreach( (array)$target_market as $tm ) {
887 $prefs = get_usces_states($tm);
888 array_shift($prefs);
889 $value = $_POST['value_'.$tm];
890 //20110317ysk end
891 //for($i=0; $i<count($prefs); $i++){
892 // $pref = $prefs[$i];
893 // $options['delivery_days'][$index]['value'][$pref] = (int)$value[$i];
894 //}
895 for( $i = 0; $i < count($prefs); $i++ ) {
896 $options['delivery_days'][$index][$tm][$prefs[$i]] = (int)$value[$i];
897 }
898 }
899 //20120710ysk end
900 update_option('usces', $options);
901
902 //20120710ysk start 0000472
903 //$valuestr = implode(',', $options['delivery_days'][$index]['value']);
904 //20110317ysk start
905 //$res = $id . '#usces#' . $name . '#usces#' . $valuestr;
906 //$res = $id . '#usces#' . $name . '#usces#' . $country . '#usces#' . $valuestr;
907 $res = (string)$id;
908 //20120710ysk end
909 //20110317ysk end
910 return $res;
911 }
912
913 function delete_delivery_days() {
914 $options = get_option('usces');
915 $id = (int)$_POST['id'];
916 for($i=0; $i<count($options['delivery_days']); $i++){
917 if($options['delivery_days'][$i]['id'] === $id){
918 $index = $i;
919 }
920 }
921 array_splice($options['delivery_days'], $index, 1);
922 update_option('usces', $options);
923
924 $res = $id . '#usces#0';
925 return $res;
926 }
927
928 /************************************************************************************************/
929 function shop_options_ajax()
930 {
931 global $usces;
932
933 if( $_POST['action'] != 'shop_options_ajax' ) die(0);
934
935 switch ($_POST['mode']) {
936 case 'add_delivery_method':
937 $res = add_delivery_method();
938 break;
939 case 'update_delivery_method':
940 $res = update_delivery_method();
941 break;
942 case 'delete_delivery_method':
943 $res = delete_delivery_method();
944 break;
945 case 'moveup_delivery_method':
946 $res = moveup_delivery_method();
947 break;
948 case 'movedown_delivery_method':
949 $res = movedown_delivery_method();
950 break;
951 case 'add_shipping_charge':
952 $res = add_shipping_charge();
953 break;
954 case 'update_shipping_charge':
955 $res = update_shipping_charge();
956 break;
957 case 'delete_shipping_charge':
958 $res = delete_shipping_charge();
959 break;
960 //20101208ysk start
961 case 'add_delivery_days':
962 $res = add_delivery_days();
963 break;
964 case 'update_delivery_days':
965 $res = update_delivery_days();
966 break;
967 case 'delete_delivery_days':
968 $res = delete_delivery_days();
969 break;
970 //20101208ysk end
971 }
972
973 die( $res );
974 }
975
976 ?>