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

965 lines 29.5 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
326 if ( !empty( $newvalue['name'] ) ) {
327 $lid = usces_add_system_option( 'usces_payment_method', $newvalue );
328
329 return $lid;
330 }
331 return false;
332 } // add_meta
333 /**
334 * update_payment
335 */
336
337 function up_payment_method() {
338 global $usces;
339
340 $value = array();
341 //$id = isset($_POST['id']) ? (int)$_POST['id'] : '';
342 $id = $_POST['id'];
343 $value['name'] = isset($_POST['name']) ? trim( $_POST['name'] ) : '';
344 $value['explanation'] = isset($_POST['explanation']) ? trim( $_POST['explanation'] ) : '';
345 $value['settlement'] = isset($_POST['settlement']) ? $_POST['settlement'] : '';
346 $value['module'] = isset($_POST['module']) ? trim( $_POST['module'] ) : '';
347 $value['sort'] = isset($_POST['sort']) ?(int)$_POST['sort'] : 0;
348
349 if ( !empty( $value['name'] ) && !WCUtils::is_blank($id) ) {
350
351 $id = usces_update_system_option( 'usces_payment_method', $id, $value );
352
353 return $id;
354 }
355 return -2;
356 } // add_meta
357
358 /**
359 * delete_payment
360 */
361 function del_payment_method() {
362 global $usces;
363
364 $id = $_POST['id'];
365
366 if ( !WCUtils::is_blank($id) ) {
367
368 usces_del_system_option( 'usces_payment_method', $id );
369
370 return $id;
371 }
372 return false;
373 }
374
375 function sort_payment_method(){
376
377 return usces_sort_system_option( 'usces_payment_method', $_POST['idstr'] );
378 }
379
380 function add_delivery_method() {
381 $options = get_option('usces');
382 $name = trim($_POST['name']);
383 foreach((array)$options['delivery_method'] as $deli){
384 $ids[] = (int)$deli['id'];
385 }
386 if(isset($ids)){
387 rsort($ids);
388 $newid = $ids[0]+1;
389 }else{
390 $newid = 0;
391 }
392 $index = isset($options['delivery_method']) ? count($options['delivery_method']) : 0;
393 $options['delivery_method'][$index]['id'] = $newid;
394 $options['delivery_method'][$index]['name'] = $name;
395 $options['delivery_method'][$index]['time'] = str_replace("\r\n", "\n", $_POST['time']);
396 $options['delivery_method'][$index]['time'] = str_replace("\r", "\n", $options['delivery_method'][$index]['time']);
397 $options['delivery_method'][$index]['charge'] = (int)$_POST['charge'];
398 //20101208ysk start
399 $options['delivery_method'][$index]['days'] = (int)$_POST['days'];
400 //20101208ysk end
401 //20101119ysk start
402 $options['delivery_method'][$index]['nocod'] = $_POST['nocod'];
403 //20101119ysk end
404 //20110317ysk start
405 $options['delivery_method'][$index]['intl'] = $_POST['intl'];
406 //20110317ysk end
407 update_option('usces', $options);
408
409 //20101208ysk start
410 //20101119ysk start
411 //$res = $newid . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'];
412 //$res = $newid . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'] . '#usces#' . $options['delivery_method'][$index]['nocod'];
413 //20101119ysk end
414 //20110317ysk start
415 //$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'];
416 $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'];
417 //20110317ysk end
418 //20101208ysk end
419 return $res;
420 }
421
422 function update_delivery_method() {
423 $options = get_option('usces');
424 $name = trim($_POST['name']);
425 $id = (int)$_POST['id'];
426 $charge = (int)$_POST['charge'];
427 for($i=0; $i<count($options['delivery_method']); $i++){
428 if($options['delivery_method'][$i]['id'] === $id){
429 $index = $i;
430 }
431 }
432 $options['delivery_method'][$index]['name'] = $name;
433 $options['delivery_method'][$index]['charge'] = $charge;
434 $options['delivery_method'][$index]['time'] = str_replace("\r\n", "\n", $_POST['time']);
435 $options['delivery_method'][$index]['time'] = str_replace("\r", "\n", $options['delivery_method'][$index]['time']);
436 //20101208ysk start
437 $options['delivery_method'][$index]['days'] = (int)$_POST['days'];
438 //20101208ysk end
439 //20101119ysk start
440 $options['delivery_method'][$index]['nocod'] = $_POST['nocod'];
441 //20101119ysk end
442 //20110317ysk start
443 $options['delivery_method'][$index]['intl'] = $_POST['intl'];
444 //20110317ysk end
445 update_option('usces', $options);
446
447 //20101208ysk start
448 //20101119ysk start
449 //$res = $id . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'];
450 //$res = $id . '#usces#' . $name . '#usces#' . $options['delivery_method'][$index]['time'] . '#usces#' . $options['delivery_method'][$index]['charge'] . '#usces#' . $options['delivery_method'][$index]['nocod'];
451 //20101119ysk end
452 //20110317ysk start
453 //$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'];
454 $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'];
455 //20110317ysk end
456 //20101208ysk end
457 return $res;
458 }
459
460 function delete_delivery_method() {
461 $options = get_option('usces');
462 $id = (int)$_POST['id'];
463 for($i=0; $i<count($options['delivery_method']); $i++){
464 if($options['delivery_method'][$i]['id'] === $id){
465 $index = $i;
466 }
467 }
468 array_splice($options['delivery_method'], $index, 1);
469 update_option('usces', $options);
470
471 $res = $id . '#usces#0';
472 return $res;
473 }
474
475 function moveup_delivery_method() {
476 $options = get_option('usces');
477 $selected_id = (int)$_POST['id'];
478 $ct = count($options['delivery_method']);
479 for($i=0; $i<$ct; $i++){
480 if($options['delivery_method'][$i]['id'] === $selected_id){
481 $index = $i;
482 }
483 }
484 if($index !== 0) {
485 $from_index = $index;
486 $to_index = $index - 1;
487 $from_dm = $options['delivery_method'][$from_index];
488 $to_dm = $options['delivery_method'][$to_index];
489 for($i=0; $i<$ct; $i++){
490 if($i === $to_index){
491 $options['delivery_method'][$i] = $from_dm;
492 }else if($i === $from_index){
493 $options['delivery_method'][$i] = $to_dm;
494 }
495 }
496 update_option('usces', $options);
497 }
498
499 $id = '';
500 $name = '';
501 $charge = '';
502 $time = '';
503 //20101208ysk start
504 $days = '';
505 //20101208ysk end
506 //20101119ysk start
507 $nocod = '';
508 //20101119ysk end
509 //20110317ysk start
510 $intl = '';
511 //20110317ysk end
512 for($i=0; $i<$ct; $i++){
513 $id .= $options['delivery_method'][$i]['id'] . ',';
514 $name .= $options['delivery_method'][$i]['name'] . ',';
515 $charge .= $options['delivery_method'][$i]['charge'] . ',';
516 $time .= $options['delivery_method'][$i]['time'] . ',';
517 //20101208ysk start
518 $days .= $options['delivery_method'][$i]['days'] . ',';
519 //20101208ysk end
520 //20101119ysk start
521 $nocod .= $options['delivery_method'][$i]['nocod'] . ',';
522 //20101119ysk end
523 //20110317ysk start
524 $intl .= $options['delivery_method'][$i]['intl'] . ',';
525 //20110317ysk end
526 }
527 $id = rtrim($id,',');
528 $name = rtrim($name,',');
529 $charge = rtrim($charge,',');
530 $time = rtrim($time,',');
531 //20101208ysk start
532 $days = rtrim($days,',');
533 //20101208ysk end
534 //20101119ysk start
535 $nocod = rtrim($nocod,',');
536 //20101119ysk end
537 //20110317ysk start
538 $intl = rtrim($intl,',');
539 //20110317ysk end
540
541 //20101208ysk start
542 //20101119ysk start
543 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $selected_id;
544 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $nocod . '#usces#' . $selected_id;
545 //20101119ysk end
546 //20110317ysk start
547 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $days . '#usces#' . $nocod . '#usces#' . $selected_id;
548 $res = $id . '#usces#' . stripslashes($name) . '#usces#' . stripslashes($time) . '#usces#' . $charge . '#usces#' . $days . '#usces#' . $nocod . '#usces#' . $intl . '#usces#' . $selected_id;
549 //20110317ysk end
550 //20101208ysk end
551 return $res;
552 }
553
554 function movedown_delivery_method() {
555 $options = get_option('usces');
556 $selected_id = (int)$_POST['id'];
557 $ct = count($options['delivery_method']);
558 for($i=0; $i<$ct; $i++){
559 if($options['delivery_method'][$i]['id'] === $selected_id){
560 $index = $i;
561 }
562 }
563 if($index < $ct-1) {
564 $from_index = $index;
565 $to_index = $index + 1;
566 $from_dm = $options['delivery_method'][$from_index];
567 $to_dm = $options['delivery_method'][$to_index];
568 for($i=0; $i<$ct; $i++){
569 if($i === $to_index){
570 $options['delivery_method'][$i] = $from_dm;
571 }else if($i === $from_index){
572 $options['delivery_method'][$i] = $to_dm;
573 }
574 }
575 update_option('usces', $options);
576 }
577
578 $id = '';
579 $name = '';
580 $charge = '';
581 $time = '';
582 //20101208ysk start
583 $days = '';
584 //20101208ysk end
585 //20101119ysk start
586 $nocod = '';
587 //20101119ysk end
588 //20110317ysk start
589 $intl = '';
590 //20110317ysk end
591 for($i=0; $i<$ct; $i++){
592 $id .= $options['delivery_method'][$i]['id'] . ',';
593 $name .= $options['delivery_method'][$i]['name'] . ',';
594 $charge .= $options['delivery_method'][$i]['charge'] . ',';
595 $time .= $options['delivery_method'][$i]['time'] . ',';
596 //20101208ysk start
597 $days .= $options['delivery_method'][$i]['days'] . ',';
598 //20101208ysk end
599 //20101119ysk start
600 $nocod .= $options['delivery_method'][$i]['nocod'] . ',';
601 //20101119ysk end
602 //20110317ysk start
603 $intl .= $options['delivery_method'][$i]['intl'] . ',';
604 //20110317ysk end
605 }
606 $id = rtrim($id,',');
607 $name = rtrim($name,',');
608 $charge = rtrim($charge,',');
609 $time = rtrim($time,',');
610 //20101208ysk start
611 $days = rtrim($days,',');
612 //20101208ysk end
613 //20101119ysk start
614 $nocod = rtrim($nocod,',');
615 //20101119ysk end
616 //20110317ysk start
617 $intl = rtrim($intl,',');
618 //20110317ysk end
619
620 //20101208ysk start
621 //20101119ysk start
622 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $selected_id;
623 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $nocod . '#usces#' . $selected_id;
624 //20101119ysk end
625 //20110317ysk start
626 //$res = $id . '#usces#' . $name . '#usces#' . $time . '#usces#' . $charge . '#usces#' . $days . '#usces#' . $nocod . '#usces#' . $selected_id;
627 $res = $id . '#usces#' . stripslashes($name) . '#usces#' . stripslashes($time) . '#usces#' . $charge . '#usces#' . $days . '#usces#' . $nocod . '#usces#' . $intl . '#usces#' . $selected_id;
628 //20110317ysk end
629 //20101208ysk end
630 return $res;
631 }
632
633 function add_shipping_charge() {
634 global $usces;
635
636 $options = get_option('usces');
637 $name = trim($_POST['name']);
638 //20110317ysk start
639 //20120710ysk start 0000472
640 //$country = trim($_POST['country']);
641 //20110317ysk end
642 //$value = $_POST['value'];
643 //20120710ysk end
644 foreach((array)$options['shipping_charge'] as $charge){
645 $ids[] = (int)$charge['id'];
646 }
647 if(isset($ids)){
648 rsort($ids);
649 $newid = $ids[0]+1;
650 }else{
651 $newid = 0;
652 }
653 $index = isset($options['shipping_charge']) ? count($options['shipping_charge']) : 0;
654 // $prefs = get_option('usces_pref');
655 //20110317ysk start
656 //$prefs = $usces->options['province'];
657 //20110331ysk start
658 //$prefs = $usces_states[$country];
659 //20120710ysk start 0000472
660 //$prefs = get_usces_states($country);
661 //20110331ysk end
662 //20110317ysk end
663 //array_shift($prefs);
664 $target_market = ( isset($options['system']['target_market']) && !empty($options['system']['target_market']) ) ? $options['system']['target_market'] : usces_get_local_target_market();
665 foreach( (array)$target_market as $tm ) {
666 $prefs = get_usces_states($tm);
667 array_shift($prefs);
668 $value = $_POST['value_'.$tm];
669 //20120710ysk end
670
671 $options['shipping_charge'][$index]['id'] = $newid;
672 $options['shipping_charge'][$index]['name'] = $name;
673 //20110317ysk start
674 //20120710ysk start 0000472
675 //$options['shipping_charge'][$index]['country'] = $country;
676 //20110317ysk end
677 //$options['shipping_charge'][$index]["value"] = array();
678 //for($i=0; $i<count($prefs); $i++){
679 // $pref = $prefs[$i];
680 // $options['shipping_charge'][$index]['value'][$pref] = (int)$value[$i];
681 //}
682 for( $i = 0; $i < count($prefs); $i++ ) {
683 $options['shipping_charge'][$index][$tm][$prefs[$i]] = (float)$value[$i];
684 }
685 }
686 //20120710ysk end
687 update_option('usces', $options);
688
689 //20120710ysk start 0000472
690 //$valuestr = implode(',', $options['shipping_charge'][$index]['value']);
691 //20110317ysk start
692 //$res = $newid . '#usces#' . $name . '#usces#' . $valuestr;
693 //$res = $newid . '#usces#' . $name . '#usces#' . $country . '#usces#' . $valuestr;
694 $res = (string)$newid;
695 //20120710ysk end
696 //20110317ysk end
697 return $res;
698 }
699
700 function update_shipping_charge() {
701 global $usces;
702
703 $options = get_option('usces');
704 $name = trim($_POST['name']);
705 //20110317ysk start
706 //20120710ysk start 0000472
707 //$country = trim($_POST['country']);
708 //20110317ysk end
709 //$value = $_POST['value'];
710 //20120710ysk end
711 $id = (int)$_POST['id'];
712 // $prefs = get_option('usces_pref');
713 //20110317ysk start
714 //$prefs = $usces->options['province'];
715 //20110331ysk start
716 //$prefs = $usces_states[$country];
717 //20120710ysk start 0000472
718 //$prefs = get_usces_states($country);
719 //20110331ysk end
720 //20110317ysk end
721 //array_shift($prefs);
722 //20120710ysk end
723
724 for($i=0; $i<count($options['shipping_charge']); $i++){
725 if($options['shipping_charge'][$i]['id'] === $id){
726 $index = $i;
727 }
728 }
729 $options['shipping_charge'][$index]["name"] = $name;
730 //20110317ysk start
731 //20120710ysk start 0000472
732 //$options['shipping_charge'][$index]['country'] = $country;
733 $target_market = ( isset($options['system']['target_market']) && !empty($options['system']['target_market']) ) ? $options['system']['target_market'] : usces_get_local_target_market();
734 foreach( (array)$target_market as $tm ) {
735 $prefs = get_usces_states($tm);
736 array_shift($prefs);
737 $value = $_POST['value_'.$tm];
738 //20110317ysk end
739 //$options['shipping_charge'][$index]["value"] = array();
740 //for($i=0; $i<count($prefs); $i++){
741 // $pref = $prefs[$i];
742 // $options['shipping_charge'][$index]["value"][$pref] = (int)$value[$i];
743 //}
744 for( $i = 0; $i < count($prefs); $i++ ) {
745 $options['shipping_charge'][$index][$tm][$prefs[$i]] = (float)$value[$i];
746 }
747 //20120710ysk end
748 }
749 update_option('usces', $options);
750
751 //20120710ysk start 0000472
752 //$valuestr = implode(',', $options['shipping_charge'][$index]["value"]);
753 //20110317ysk start
754 //$res = $id . '#usces#' . $name . '#usces#' . $valuestr;
755 //$res = $id . '#usces#' . $name . '#usces#' . $country . '#usces#' . $valuestr;
756 $res = (string)$id;
757 //20120710ysk end
758 //20110317ysk end
759 return $res;
760 }
761
762 function delete_shipping_charge() {
763 $options = get_option('usces');
764 $id = (int)$_POST['id'];
765 for($i=0; $i<count($options['shipping_charge']); $i++){
766 if($options['shipping_charge'][$i]['id'] === $id){
767 $index = $i;
768 }
769 }
770 array_splice($options['shipping_charge'], $index, 1);
771 update_option('usces', $options);
772
773 $res = $id . '#usces#0';
774 return $res;
775 }
776 //20101208ysk start
777 function add_delivery_days() {
778 global $usces;
779
780 $options = get_option('usces');
781 $name = trim($_POST['name']);
782 //20110317ysk start
783 //20120710ysk start 0000472
784 //$country = trim($_POST['country']);
785 //20110317ysk end
786 //$value = $_POST['value'];
787 //20120710ysk end
788 foreach((array)$options['delivery_days'] as $charge){
789 $ids[] = (int)$charge['id'];
790 }
791 if(isset($ids)){
792 rsort($ids);
793 $newid = $ids[0]+1;
794 }else{
795 $newid = 0;
796 }
797 $index = isset($options['delivery_days']) ? count($options['delivery_days']) : 0;
798 //20110317ysk start
799 //$prefs = $usces->options['province'];
800 //20110331ysk start
801 //$prefs = $usces_states[$country];
802 //20120710ysk start 0000472
803 //$prefs = get_usces_states($country);
804 //20110331ysk end
805 //20110317ysk end
806 //array_shift($prefs);
807 $target_market = ( isset($options['system']['target_market']) && !empty($options['system']['target_market']) ) ? $options['system']['target_market'] : usces_get_local_target_market();
808 foreach( (array)$target_market as $tm ) {
809 $prefs = get_usces_states($tm);
810 array_shift($prefs);
811 $value = $_POST['value_'.$tm];
812 //20120710ysk end
813
814 $options['delivery_days'][$index]['id'] = $newid;
815 $options['delivery_days'][$index]['name'] = $name;
816 //20110317ysk start
817 //20120710ysk start 0000472
818 //$options['delivery_days'][$index]['country'] = $country;
819 //20110317ysk end
820 //for($i=0; $i<count($prefs); $i++){
821 // $pref = $prefs[$i];
822 // $options['delivery_days'][$index]['value'][$pref] = (int)$value[$i];
823 //}
824 for( $i = 0; $i < count($prefs); $i++ ) {
825 $options['delivery_days'][$index][$tm][$prefs[$i]] = (int)$value[$i];
826 }
827 }
828 //20120710ysk end
829 update_option('usces', $options);
830
831 //20120710ysk start 0000472
832 //$valuestr = implode(',', $options['delivery_days'][$index]['value']);
833 //20110317ysk start
834 //$res = $newid . '#usces#' . $name . '#usces#' . $valuestr;
835 //$res = $newid . '#usces#' . $name . '#usces#' . $country . '#usces#' . $valuestr;
836 $res = (string)$newid;
837 //20120710ysk end
838 //20110317ysk end
839 return $res;
840 }
841
842 function update_delivery_days() {
843 global $usces;
844
845 $options = get_option('usces');
846 $name = trim($_POST['name']);
847 //20110317ysk start
848 //20120710ysk start 0000472
849 //$country = trim($_POST['country']);
850 //20110317ysk end
851 //$value = $_POST['value'];
852 //20120710ysk end
853 $id = (int)$_POST['id'];
854 //20110317ysk start
855 //$prefs = $usces->options['province'];
856 //20110331ysk start
857 //$prefs = $usces_states[$country];
858 //20120710ysk start 0000472
859 //$prefs = get_usces_states($country);
860 //20110331ysk end
861 //20110317ysk end
862 //array_shift($prefs);
863 //20120710ysk end
864
865 for($i=0; $i<count($options['delivery_days']); $i++){
866 if($options['delivery_days'][$i]['id'] === $id){
867 $index = $i;
868 }
869 }
870 $options['delivery_days'][$index]['name'] = $name;
871 //20110317ysk start
872 //20120710ysk start 0000472
873 //$options['delivery_days'][$index]['country'] = $country;
874 $target_market = ( isset($options['system']['target_market']) && !empty($options['system']['target_market']) ) ? $options['system']['target_market'] : usces_get_local_target_market();
875 foreach( (array)$target_market as $tm ) {
876 $prefs = get_usces_states($tm);
877 array_shift($prefs);
878 $value = $_POST['value_'.$tm];
879 //20110317ysk end
880 //for($i=0; $i<count($prefs); $i++){
881 // $pref = $prefs[$i];
882 // $options['delivery_days'][$index]['value'][$pref] = (int)$value[$i];
883 //}
884 for( $i = 0; $i < count($prefs); $i++ ) {
885 $options['delivery_days'][$index][$tm][$prefs[$i]] = (int)$value[$i];
886 }
887 }
888 //20120710ysk end
889 update_option('usces', $options);
890
891 //20120710ysk start 0000472
892 //$valuestr = implode(',', $options['delivery_days'][$index]['value']);
893 //20110317ysk start
894 //$res = $id . '#usces#' . $name . '#usces#' . $valuestr;
895 //$res = $id . '#usces#' . $name . '#usces#' . $country . '#usces#' . $valuestr;
896 $res = (string)$id;
897 //20120710ysk end
898 //20110317ysk end
899 return $res;
900 }
901
902 function delete_delivery_days() {
903 $options = get_option('usces');
904 $id = (int)$_POST['id'];
905 for($i=0; $i<count($options['delivery_days']); $i++){
906 if($options['delivery_days'][$i]['id'] === $id){
907 $index = $i;
908 }
909 }
910 array_splice($options['delivery_days'], $index, 1);
911 update_option('usces', $options);
912
913 $res = $id . '#usces#0';
914 return $res;
915 }
916
917 /************************************************************************************************/
918 function shop_options_ajax()
919 {
920 global $usces;
921
922 if( $_POST['action'] != 'shop_options_ajax' ) die(0);
923
924 switch ($_POST['mode']) {
925 case 'add_delivery_method':
926 $res = add_delivery_method();
927 break;
928 case 'update_delivery_method':
929 $res = update_delivery_method();
930 break;
931 case 'delete_delivery_method':
932 $res = delete_delivery_method();
933 break;
934 case 'moveup_delivery_method':
935 $res = moveup_delivery_method();
936 break;
937 case 'movedown_delivery_method':
938 $res = movedown_delivery_method();
939 break;
940 case 'add_shipping_charge':
941 $res = add_shipping_charge();
942 break;
943 case 'update_shipping_charge':
944 $res = update_shipping_charge();
945 break;
946 case 'delete_shipping_charge':
947 $res = delete_shipping_charge();
948 break;
949 //20101208ysk start
950 case 'add_delivery_days':
951 $res = add_delivery_days();
952 break;
953 case 'update_delivery_days':
954 $res = update_delivery_days();
955 break;
956 case 'delete_delivery_days':
957 $res = delete_delivery_days();
958 break;
959 //20101208ysk end
960 }
961
962 die( $res );
963 }
964
965 ?>