PluginProbe
Welcart e-Commerce / 1.3.16
Welcart e-Commerce v1.3.16
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.3.16, at functions/system_post.php

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