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

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