-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathsave-data.functions.php
More file actions
executable file
·566 lines (496 loc) · 24.3 KB
/
save-data.functions.php
File metadata and controls
executable file
·566 lines (496 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
<?php
/**
* This file used for adding fields to the products category taxonomy page and saving those values correctly :)
*
* @package wp-e-commerce
* @since 3.8
* @todo UI needs a lot of loving - lots of padding issues, if we have these boxes, they should be sortable, closable, hidable, etc.
*/
function wpsc_ajax_set_variation_order(){
global $wpdb;
$sort_order = $_POST['sort_order'];
$parent_id = $_POST['parent_id'];
$result = true;
foreach( $sort_order as $key=>$value ){
if ( empty( $value ) )
continue;
$value = preg_replace( '/[^0-9]/', '', $value );
if( ! wpsc_update_meta( $value, 'sort_order', $key, 'wpsc_variation' ) )
$result = false;
}
}
/**
* WP eCommerce edit and add product category page functions
*
* These are the main WPSC Admin functions
*
* @package wp-e-commerce
* @since 3.7
*/
function wpsc_ajax_set_category_order(){
global $wpdb;
$sort_order = $_POST['sort_order'];
$parent_id = $_POST['parent_id'];
$result = true;
foreach ( $sort_order as $key=>$value ){
if ( empty( $value ) )
continue;
$value = preg_replace( '/[^0-9]/', '', $value );
if ( ! wpsc_update_meta( $value, 'sort_order', $key, 'wpsc_category' ) )
$result = false;
}
}
add_filter( 'manage_edit-wpsc_product_category_columns', 'wpsc_custom_category_columns' );
add_filter( 'manage_wpsc_product_category_custom_column', 'wpsc_custom_category_column_data', 10, 3);
add_action( 'wpsc_product_category_add_form_fields', 'wpsc_admin_category_forms_add' ); // After left-col
add_action( 'wpsc_product_category_edit_form_fields', 'wpsc_admin_category_forms_edit' ); // After left-col
add_action( 'created_wpsc_product_category', 'wpsc_save_category_set', 10 , 2 ); //After created
add_action( 'edited_wpsc_product_category', 'wpsc_save_category_set', 10 , 2 ); //After saved
/**
* wpsc_custom_category_columns
* Adds images column to category column.
* @internal Don't feel handle column is necessary, but you would add it here if you wanted to
* @param (array) columns | Array of columns assigned to this taxonomy
* @return (array) columns | Modified array of columns
*/
function wpsc_custom_category_columns( $columns ) {
// Doing it this funny way to ensure that image stays in far left, even if other items are added via plugin.
unset( $columns["cb"] );
$custom_array = array(
'cb' => '<input type="checkbox" />',
'image' => __( 'Image', 'wpsc' )
);
$columns = array_merge( $custom_array, $columns );
return $columns;
}
/**
* wpsc_custom_category_column_data
* Adds images to the custom category column
* @param (array) column_name | column name
* @return nada
*/
function wpsc_custom_category_column_data( $string, $column_name, $term_id ) {
global $wpdb;
$image = wpsc_get_categorymeta( $term_id, 'image' );
$name = get_term_by( 'id', $term_id, 'wpsc_product_category' );
$name = $name->name;
if ( ! empty( $image ) )
$image = "<img src='" . WPSC_CATEGORY_URL . $image . "' title='" . esc_attr( $name ) . "' alt='" . esc_attr( $name ) . "' width='30' height='30' />";
else
$image = "<img src='" . WPSC_CORE_IMAGES_URL . "/no-image-uploaded.gif' title='" . esc_attr( $name ) . "' alt='" . esc_attr( $name ) . "' width='30' height='30' />";
return $image;
}
/**
* wpsc_admin_get_category_array
* Recursively step through the categories and return it in a clean multi demensional array
* for use in other list functions
* @param int $parent_id
*/
function wpsc_admin_get_category_array( $parent_id = null ){
global $wpdb;
$orderedList = array();
if ( ! isset( $parent_id ) )
$parent_id = 0;
$category_list = get_terms( 'wpsc_product_category', 'hide_empty=0&parent=' . $parent_id );
if ( ! is_array( $category_list ) ) {
return false;
}
foreach ( $category_list as $category ) {
$category_order = wpsc_get_categorymeta( $category->term_id, 'order' );
$category_image = wpsc_get_categorymeta( $category->term_id, 'image' );
if ( ! isset( $category_order ) || $category_order == 0 )
$category_order = ( count( $orderedList ) + 1 );
print "<!-- setting category Order number to " . $category_order . "-->";
$orderedList[$category_order]['id'] = $category->term_id;
$orderedList[$category_order]['name'] = $category->name;
$orderedList[$category_order]['image'] = $category_image;
$orderedList[$category_order]['parent_id'] = $parent_id;
$orderedList[$category_order]['children'] = wpsc_admin_get_category_array( $category->term_id );
}
ksort( $orderedList );
return $orderedList;
}
/**
* wpsc_admin_category_group_list, prints the left hand side of the add categories page
* nothing returned
*/
function wpsc_admin_category_forms_add() {
global $wpdb;
$category_value_count = 0;
$display_type = isset( $category['display_type'] ) ? $category['display_type'] : '';
?>
<h3><?php esc_html_e('Advanced Store Settings', 'wpsc'); ?></h3>
<h4><?php esc_html_e('Presentation Settings', 'wpsc'); ?></h4>
<p class='description'><?php esc_html_e( 'These settings override the general presentation settings found in Settings > Store > Presentation.', 'wpsc' ); ?></p>
<div class="form-field">
<label for='image'><?php esc_html_e( 'Category Image' , 'wpsc' ); ?></label>
<input type='file' name='image' value='' />
</div>
<div class="form-field">
<label for='display_type'><?php esc_html_e( 'Product Display', 'wpsc' ); ?></label>
<select name='display_type'>
<option value='default'<?php checked( $display_type, 'default' ); ?>><?php esc_html_e('Default View', 'wpsc'); ?></option>
<option value='list'<?php disabled( _wpsc_is_display_type_supported( 'list' ), false ); ?><?php checked( $display_type, 'list' ); ?>><?php esc_html_e('List View', 'wpsc'); ?></option>
<option value='grid'<?php disabled( _wpsc_is_display_type_supported( 'grid' ), false ); ?><?php checked( $display_type, 'grid' ); ?>><?php esc_html_e('Grid View', 'wpsc'); ?></option>
</select>
</div>
<?php if ( function_exists( "getimagesize" ) ) : ?>
<div class="form-field">
<?php esc_html_e( 'Thumbnail Size', 'wpsc' ); ?>
<fieldset class="wpsc-width-height-fields">
<legend class="screen-reader-text"><span><?php esc_html_e( 'Thumbnail Size', 'wpsc' ); ?></span></legend>
<label for="image_width"><?php esc_html_e( 'Width', 'wpsc' ); ?></label>
<input name="image_width" type="number" step="1" min="0" id="image_width" value="<?php if ( isset( $category['image_width'] ) ) echo esc_attr( $category['image_width'] ); ?>" class="small-text">
<label for="large_size_h"><?php esc_html_e( 'Height', 'wpsc' ); ?></label>
<input name="image_height" type="number" step="1" min="0" id="image_height" value="<?php if ( isset( $category['image_height'] ) ) echo esc_attr( $category['image_height'] ); ?>" class="small-text">
</fieldset>
</div>
<?php endif;?>
<!-- START OF TARGET MARKET SELECTION -->
<?php
$category_id = '';
if ( isset( $_GET["tag_ID"] ) )
$category_id = $_GET["tag_ID"];
$countrylist = $wpdb->get_results("SELECT id,country,visible FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY country ASC ", ARRAY_A);
$selectedCountries = wpsc_get_meta( $category_id, 'target_market', 'wpsc_category' );
?>
<h4><?php esc_html_e( 'Restrict to Target Markets', 'wpsc' )?></h4>
<div class='form-field'>
<?php if( @extension_loaded( 'suhosin' ) ) : ?>
<em><?php esc_html__( "The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature then disable the suhosin extension, if you can not do this, you will need to contact your hosting provider.", 'wpsc' ); ?></em>
<?php else: ?>
<div class='multiple-select-container'>
<span><?php esc_html_e( 'Select', 'wpsc' ); ?> <a href='' class='wpsc_select_all'><?php esc_html_e( 'All', 'wpsc' ); ?></a> <a href='' class='wpsc_select_none'><?php esc_html_e( 'None', 'wpsc' ); ?></a></span><br />
<div id='resizeable' class='ui-widget-content multiple-select'>
<?php foreach( $countrylist as $country ): ?>
<?php if ( in_array( $country['id'], (array)$selectedCountries ) ): ?>
<input type='checkbox' name='countrylist2[]' id='countrylist2-<?php echo $country['id']; ?>' value='<?php echo $country['id']; ?>' checked='<?php echo $country['visible']; ?>' />
<label for="countrylist2-<?php echo $country['id']; ?>"><?php esc_html_e( $country['country'] ); ?></label><br />
<?php else: ?>
<input type='checkbox' name='countrylist2[]' id='countrylist2-<?php echo $country['id']; ?>' value='<?php echo $country['id']; ?>' />
<label for="countrylist2-<?php echo $country['id']; ?>"><?php esc_html_e( $country['country'] ); ?></label><br />
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
<span class='wpscsmall description'><?php esc_html_e( 'Select the markets you are selling this category to.', 'wpsc' ); ?><span>
<?php endif; ?>
</div>
<!-- Checkout settings -->
<h4><?php esc_html_e( 'Checkout Settings', 'wpsc' ); ?></h4>
<?php
if ( ! isset( $category['term_id'] ) ) $category['term_id'] = '';
$used_additonal_form_set = wpsc_get_categorymeta( $category['term_id'], 'use_additional_form_set' );
?>
<div class='form-field'>
<label for="use_additional_form_set"><?php esc_html_e( 'Category requires additional checkout form fields', 'wpsc' ); ?></label>
<select name='use_additional_form_set'>
<option value=''><?php esc_html_e( 'None', 'wpsc' ); ?></option>
<?php
$checkout_sets = get_option( 'wpsc_checkout_form_sets' );
unset( $checkout_sets[0] );
foreach ( (array)$checkout_sets as $key => $value ) {
$selected_state = "";
if ( $used_additonal_form_set == $key )
$selected_state = "selected='selected'";
?>
<option <?php echo $selected_state; ?> value='<?php echo $key; ?>'><?php echo esc_html( $value ); ?></option>
<?php
}
?>
</select>
</div>
<?php $uses_billing_address = (bool)wpsc_get_categorymeta( $category['term_id'], 'uses_billing_address' ); ?>
<div>
<label><?php esc_html_e( 'Address to calculate shipping with', 'wpsc' ); ?></label>
<label><input type='radio' value='1' name='uses_billing_address' <?php echo ( ( $uses_billing_address == true ) ? "checked='checked'" : "" ); ?> /> <?php esc_html_e( 'Billing Address', 'wpsc' ); ?></label>
<label><input type='radio' value='0' name='uses_billing_address' <?php echo ( ( $uses_billing_address != true ) ? "checked='checked'" : "" ); ?> /> <?php esc_html_e( 'Default Setting', 'wpsc' ); ?></label>
<p class='description'><?php esc_html_e( 'Products in this category will use the address specified to calculate shipping costs.', 'wpsc' ); ?></p>
</div>
<table class="category_forms">
<tr>
</tr>
</table>
<?php
}
/**
* Check whether a display type (such as grid, list) is supported.
*
* @since 3.8.9
* @access private
* @param string $display_type Display type
* @return bool Return true if display type is supported.
*/
function _wpsc_is_display_type_supported( $display_type ) {
$callback = 'product_display_' . $display_type;
return function_exists( $callback );
}
/**
* Renders the additional content for the category edit page
*/
function wpsc_admin_category_forms_edit() {
global $wpdb;
$category_value_count = 0;
$category_name = '';
$category = array();
$category_id = absint( $_REQUEST['tag_ID'] );
$category = get_term( $category_id, 'wpsc_product_category', ARRAY_A );
$category['nice-name'] = wpsc_get_categorymeta( $category['term_id'], 'nice-name' );
$category['description'] = wpsc_get_categorymeta( $category['term_id'], 'description' );
$category['image'] = wpsc_get_categorymeta( $category['term_id'], 'image' );
$category['fee'] = wpsc_get_categorymeta( $category['term_id'], 'fee' );
$category['active'] = wpsc_get_categorymeta( $category['term_id'], 'active' );
$category['order'] = wpsc_get_categorymeta( $category['term_id'], 'order' );
$category['display_type'] = wpsc_get_categorymeta( $category['term_id'], 'display_type' );
$category['image_height'] = wpsc_get_categorymeta( $category['term_id'], 'image_height' );
$category['image_width'] = wpsc_get_categorymeta( $category['term_id'], 'image_width' );
$category['use_additional_form_set'] = wpsc_get_categorymeta( $category['term_id'], 'use_additional_form_set' );
?>
<tr>
<td colspan="2">
<h3><?php esc_html_e( 'Advanced Store Settings', 'wpsc' ); ?></h3>
<h4><?php esc_html_e( 'Shortcodes and Template Tags', 'wpsc' ); ?></h4>
<p class='description'><?php esc_html_e( 'These settings override the general presentation settings found in Settings > Store > Presentation.', 'wpsc' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="display_type"><?php esc_html_e( 'Catalog View', 'wpsc' ); ?></label>
</th>
<td>
<?php
$display_type = isset( $category['display_type'] ) ? $category['display_type'] : '';
?>
<select name='display_type'>
<option value='default'<?php checked( $display_type, 'default' ); ?>><?php esc_html_e( 'Default View', 'wpsc' ); ?></option>
<option value='list'<?php disabled( _wpsc_is_display_type_supported( 'list' ), false ); ?><?php checked( $display_type, 'list' ); ?>><?php esc_html_e( 'List View', 'wpsc' ); ?></option>
<option value='grid' <?php disabled( _wpsc_is_display_type_supported( 'grid' ), false ); ?><?php checked( $display_type, 'grid' ); ?>><?php esc_html_e( 'Grid View', 'wpsc' ); ?></option>
</select><br />
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="image"><?php esc_html_e( 'Category Image', 'wpsc' ); ?></label>
</th>
<td>
<?php
$category_image = wpsc_category_image( $category['term_id'] );
if ( $category_image )
echo '<p><img src=' . esc_url( $category_image ) . ' alt="' . esc_attr( $category['name'] ) . '" title="' . esc_attr( $category['name'] ) . '" class="wpsc_category_image" /></p>';
?>
<input type='file' name='image' value='' /><br />
<label><input type='checkbox' name='deleteimage' class="wpsc_cat_box" value='1' /><?php esc_html_e( 'Delete Image', 'wpsc' ); ?></label><br/>
<span class="description"><?php esc_html_e( 'You can set an image for the category here. If one exists, check the box to delete.', 'wpsc' ); ?></span>
</td>
</tr>
<?php if ( function_exists( 'getimagesize' ) ) : ?>
<tr class="form-field">
<th scope="row" valign="top">
<label for="image"><?php esc_html_e( 'Thumbnail Size', 'wpsc' ); ?></label>
</th>
<td>
<fieldset class="wpsc-width-height-fields">
<legend class="screen-reader-text"><span><?php esc_html_e( 'Thumbnail Size', 'wpsc' ); ?></span></legend>
<label for="image_width"><?php esc_html_e( 'Width', 'wpsc' ); ?></label>
<input name="image_width" type="number" step="1" min="0" id="image_width" value="<?php if ( isset( $category['image_width'] ) ) echo esc_attr( $category['image_width'] ); ?>" class="small-text">
<label for="large_size_h"><?php esc_html_e( 'Height', 'wpsc' ); ?></label>
<input name="image_height" type="number" step="1" min="0" id="image_height" value="<?php if ( isset( $category['image_height'] ) ) echo esc_attr( $category['image_height'] ); ?>" class="small-text">
</fieldset>
</td>
</tr>
<?php endif; // 'getimagesize' condition ?>
<tr>
<td colspan="2"><h4><?php esc_html_e( 'Shortcodes and Template Tags', 'wpsc' ); ?></h4></td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="image"><?php esc_html_e( 'Display Category Shortcode', 'wpsc' ); ?></label>
</th>
<td>
<code>[wpsc_products category_url_name='<?php echo esc_html($category['slug']); ?>']</code><br />
<span class="description"><?php esc_html_e( 'Shortcodes are used to display a particular category or group within any WordPress page or post.', 'wpsc' ); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="image"><?php esc_html_e( 'Display Category Template Tag', 'wpsc' ); ?></label>
</th>
<td>
<code><?php echo wpsc_display_products_page( array( 'category_url_name' => '<?php echo esc_html( $category['slug'] ); ?>' ) ); ?></code><br />
<span class="description"><?php esc_html_e( 'Template tags are used to display a particular category or group within your theme / template.', 'wpsc' ); ?></span>
</td>
</tr>
<!-- START OF TARGET MARKET SELECTION -->
<tr>
<td colspan="2">
<h4><?php esc_html_e( 'Target Market Restrictions', 'wpsc' ); ?></h4>
</td>
</tr>
<?php
$countrylist = $wpdb->get_results( 'SELECT id,country,visible FROM `'.WPSC_TABLE_CURRENCY_LIST.'` ORDER BY country ASC ',ARRAY_A );
$selectedCountries = wpsc_get_meta( $category_id,'target_market','wpsc_category' );
?>
<tr>
<th scope="row" valign="top">
<label for="image"><?php esc_html_e( 'Target Markets', 'wpsc' ); ?></label>
</th>
<td>
<?php if ( wpsc_is_suhosin_enabled() ) : ?>
<em><?php esc_html_e( 'The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature, then disable the suhosin extension. If you can not do this, you will need to contact your hosting provider.','wpsc' ); ?></em>
<?php else : ?>
<span><?php esc_html_e( 'Select', 'wpsc' ); ?>: <a href='' class='wpsc_select_all'><?php esc_html_e( 'All', 'wpsc' ); ?></a> <a href='' class='wpsc_select_none'><?php esc_html_e( 'None', 'wpsc' ); ?></a></span><br />
<div id='resizeable' class='ui-widget-content multiple-select'>
<?php foreach ( $countrylist as $country ) {
if ( in_array( $country['id'], (array)$selectedCountries ) ) {
?>
<input type='checkbox' name='countrylist2[]' id='countrylist2-<?php echo esc_attr( $country['id'] ); ?>' value='<?php echo esc_attr( $country['id'] ); ?>' checked='<?php echo esc_attr( $country['visible'] ); ?>' />
<label for="countrylist2-<?php echo esc_attr( $country['id'] ); ?>"><?php esc_html_e( $country['country'] ); ?></label><br />
<?php
} else {
?>
<input type='checkbox' name='countrylist2[]' id='countrylist2-<?php echo esc_attr( $country['id'] ); ?>' value='<?php echo esc_attr( $country['id'] ); ?>' />
<label for="countrylist2-<?php echo esc_attr( $country['id'] ); ?>"><?php esc_html_e( $country['country'] ); ?></label><br />
<?php
}
} ?>
</div>
<?php endif; ?><br />
<span class="description"><?php esc_html_e( 'Select the markets you are selling this category to.', 'wpsc' ); ?></span>
</td>
</tr>
<!-- Checkout settings -->
<tr>
<td colspan="2">
<h4><?php esc_html_e( 'Checkout Settings', 'wpsc' ); ?></h4>
</td>
</tr>
<?php
if ( !isset( $category['term_id'] ) )
$category['term_id'] = '';
$used_additonal_form_set = wpsc_get_categorymeta( $category['term_id'], 'use_additional_form_set' );
$checkout_sets = get_option( 'wpsc_checkout_form_sets' );
unset($checkout_sets[0]);
$uses_billing_address = (bool)wpsc_get_categorymeta( $category['term_id'], 'uses_billing_address' );
?>
<tr class="form-field">
<th scope="row" valign="top">
<label for="image"><?php esc_html_e( 'Category requires additional checkout form fields', 'wpsc' ); ?></label>
</th>
<td>
<select name='use_additional_form_set'>
<option value=''><?php esc_html_e( 'None', 'wpsc' ); ?></option>
<?php
foreach ( (array) $checkout_sets as $key => $value ) {
$selected_state = '';
if ( $used_additonal_form_set == $key ) {
$selected_state = "selected='selected'";
} ?>
<option <?php echo $selected_state; ?> value='<?php echo esc_attr( $key ); ?>'><?php echo esc_html( $value ); ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label><?php esc_html_e( 'Address to calculate shipping with', 'wpsc' ); ?></label>
</th>
<td>
<label><input type='radio' class='wpsc_cat_box' value='0' name='uses_billing_address' <?php checked( $uses_billing_address, false ); ?> /> <?php esc_html_e( 'Default Setting', 'wpsc' ); ?></label>
<label><input type='radio' class='wpsc_cat_box' value='1' name='uses_billing_address' <?php checked( $uses_billing_address ); ?> /> <?php esc_html_e( 'Billing Address', 'wpsc' ); ?></label>
<p class='description'><?php esc_html_e( 'Products in this category will use the address specified to calculate shipping costs.', 'wpsc' ); ?></p>
</td>
</tr>
<?php
}
/**
* wpsc_save_category_set, Saves the category set data
* @param nothing
* @return nothing
*/
function wpsc_save_category_set( $category_id, $tt_id ) {
global $wpdb;
if ( ! empty( $_POST ) ) {
/* Image Processing Code*/
if ( ! empty( $_FILES['image'] ) && preg_match( "/\.(gif|jp(e)*g|png){1}$/i", $_FILES['image']['name'] ) ) {
if ( function_exists( "getimagesize" ) ) {
if ( isset( $_POST['width'] ) && ( (int) $_POST['width'] > 10 && (int) $_POST['width'] < 512 ) && ( (int)$_POST['height'] > 10 && (int)$_POST['height'] < 512 ) ) {
$width = (int) $_POST['width'];
$height = (int) $_POST['height'];
image_processing( $_FILES['image']['tmp_name'], ( WPSC_CATEGORY_DIR.$_FILES['image']['name'] ), $width, $height, 'image' );
} else {
image_processing( $_FILES['image']['tmp_name'], ( WPSC_CATEGORY_DIR.$_FILES['image']['name'] ), null, null, 'image' );
}
$image = esc_sql( $_FILES['image']['name'] );
} else {
$new_image_path = ( WPSC_CATEGORY_DIR.basename($_FILES['image']['name'] ) );
move_uploaded_file( $_FILES['image']['tmp_name'], $new_image_path );
$stat = stat( dirname( $new_image_path ) );
$perms = $stat['mode'] & 0000666;
@ chmod( $new_image_path, $perms );
$image = esc_sql( $_FILES['image']['name'] );
}
} else {
$image = '';
}
//Good to here
if ( isset( $_POST['tag_ID'] ) ) {
//Editing
$category_id = $_POST['tag_ID'];
$category = get_term_by( 'id', $category_id, 'wpsc_product_category' );
$url_name = $category->slug;
}
if ( isset( $_POST['deleteimage'] ) && $_POST['deleteimage'] == 1 ) {
wpsc_delete_categorymeta( $category_id, 'image' );
} else if ( $image != '' ) {
wpsc_update_categorymeta( $category_id, 'image', $image );
}
if ( ! empty( $_POST['height'] ) && is_numeric( $_POST['height'] ) && ! empty( $_POST['width'] ) && is_numeric( $_POST['width'] ) && $image == null ) {
$imagedata = wpsc_get_categorymeta( $category_id, 'image' );
if ( $imagedata != null ) {
$height = $_POST['height'];
$width = $_POST['width'];
$imagepath = WPSC_CATEGORY_DIR . $imagedata;
$image_output = WPSC_CATEGORY_DIR . $imagedata;
image_processing( $imagepath, $image_output, $width, $height );
}
}
wpsc_update_categorymeta( $category_id, 'fee', '0' );
wpsc_update_categorymeta( $category_id, 'active', '1' );
wpsc_update_categorymeta( $category_id, 'order', '0' );
if ( isset( $_POST['display_type'] ) )
wpsc_update_categorymeta( $category_id, 'display_type', esc_sql( stripslashes( $_POST['display_type'] ) ) );
if ( isset( $_POST['image_height'] ) )
wpsc_update_categorymeta( $category_id, 'image_height', absint( $_POST['image_height'] ) );
if ( isset( $_POST['image_width'] ) )
wpsc_update_categorymeta( $category_id, 'image_width', absint($_POST['image_width'] ) );
if ( ! empty( $_POST['use_additional_form_set'] ) ) {
wpsc_update_categorymeta( $category_id, 'use_additional_form_set', $_POST['use_additional_form_set'] );
//exit('<pre>'.print_r($_POST,1).'</pre>');
} else {
wpsc_delete_categorymeta( $category_id, 'use_additional_form_set' );
}
if ( ! empty( $_POST['uses_billing_address'] ) ) {
wpsc_update_categorymeta( $category_id, 'uses_billing_address', 1 );
$uses_additional_forms = true;
} else {
wpsc_update_categorymeta( $category_id, 'uses_billing_address', 0 );
$uses_additional_forms = false;
}
if ( ! empty( $_POST['countrylist2'] ) && ( $category_id > 0 ) ) {
$AllSelected = false;
$countryList = $wpdb->get_col( "SELECT `id` FROM `" . WPSC_TABLE_CURRENCY_LIST . "`" );
if ( $AllSelected != true ){
$unselectedCountries = array_diff( $countryList, $_POST['countrylist2'] );
//find the countries that are selected
$selectedCountries = array_intersect( $countryList, $_POST['countrylist2'] );
wpsc_update_categorymeta( $category_id, 'target_market', $selectedCountries );
}
} elseif ( ! isset( $_POST['countrylist2'] ) ){
wpsc_update_categorymeta( $category_id, 'target_market', '' );
$AllSelected = true;
}
}
}
?>