| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | function wpsc_ajax_sales_quarterly() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 	$lastdate = sanitize_text_field( $_POST['add_start'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	$date = preg_split( '/-/', $lastdate ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	if ( !isset( $date[0] ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		$date[0] = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	if ( !isset( $date[1] ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 		$date[1] = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	if ( !isset( $date[2] ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 		$date[2] = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	$lastquart = mktime( 0, 0, 0, $date[1], $date[2], $date[0] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	if ( $lastquart != get_option( 'wpsc_last_quarter' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		update_option( 'wpsc_last_date', $lastdate ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		update_option( 'wpsc_fourth_quart', $lastquart ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		$thirdquart = mktime( 0, 0, 0, $date[1] - 3, $date[2], $date[0] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		update_option( 'wpsc_third_quart', $thirdquart ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		$secondquart = mktime( 0, 0, 0, $date[1] - 6, $date[2], $date[0] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		update_option( 'wpsc_second_quart', $secondquart ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$firstquart = mktime( 0, 0, 0, $date[1] - 9, $date[2], $date[0] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		update_option( 'wpsc_first_quart', $firstquart ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		$finalquart = mktime( 0, 0, 0, $date[1], $date[2], $date[0] - 1 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		update_option( 'wpsc_final_quart', $finalquart ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'wpsc_quarterly') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	add_action( 'admin_init', 'wpsc_ajax_sales_quarterly' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | function wpsc_delete_file() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	$product_id = absint( $_REQUEST['product_id'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	$file_name  = basename( $_REQUEST['file_name'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	check_admin_referer( 'delete_file_' . $file_name ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	_wpsc_delete_file( $product_id, $file_name ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	wp_redirect( $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	exit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'delete_file') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	add_action( 'admin_init', 'wpsc_delete_file' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  *  Function and action for publishing or unpublishing single products | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | function wpsc_ajax_toggle_published() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	$product_id = absint( $_GET['product'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	check_admin_referer( 'toggle_publish_' . $product_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	$status = (wpsc_toggle_publish_status( $product_id )) ? ('true') : ('false'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	$sendback = add_query_arg( 'flipped', "1", wp_get_referer() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	wp_redirect( esc_url_raw( $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'toggle_publish') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	add_action( 'admin_init', 'wpsc_ajax_toggle_published' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  * Function and action for duplicating products, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  * Refactored for 3.8 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  * Purposely not duplicating stick post status (logically, products are most often duplicated because they share many attributes, where products are generally 'featured' uniquely.) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | function wpsc_duplicate_product() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	// Get the original post | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	$id = absint( $_GET['product'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	$post = get_post( $id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	// Copy the post and insert it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	if ( isset( $post ) && $post != null ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		$duplicate = new WPSC_Duplicate_Product( $post->ID ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		$new_id = $duplicate->duplicate_product_process(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		$duplicated = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		$sendback = add_query_arg( 'duplicated', (int) $duplicated, $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		wp_redirect( esc_url_raw( $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		wp_die( __( 'Sorry, for some reason, we couldn\'t duplicate this product because it could not be found in the database, check there for this ID: ', 'wp-e-commerce' ) . $id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | if ( isset( $_GET['wpsc_admin_action'] ) && ( $_GET['wpsc_admin_action'] == 'duplicate_product' ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     add_action( 'admin_init', 'wpsc_duplicate_product' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | function wpsc_purchase_log_csv() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	if ( 'key' == $_REQUEST['rss_key'] && wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		_wpsc_download_purchase_log_csv( $_REQUEST ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | function _wpsc_download_purchase_log_csv( $args = array() ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  | 	global $wpdb, $wpsc_gateways; | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 	get_currentuserinfo(); | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  | 	$count = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  | 	if ( isset( $args['start_timestamp'] ) && isset( $args['end_timestamp'] ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  | 		$start_timestamp = $args['start_timestamp']; | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  | 		$end_timestamp   = $args['end_timestamp']; | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  | 		$start_end_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '%d' AND '%d' ORDER BY `date` DESC"; | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  | 		$start_end_sql = apply_filters( 'wpsc_purchase_log_start_end_csv', $start_end_sql ); | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  | 		$data = $wpdb->get_results( $wpdb->prepare( $start_end_sql, $start_timestamp, $end_timestamp ), ARRAY_A ); | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  | 		/* translators: %1$s is "start" date, %2$s is "to" date */ | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  | 		$csv_name = _x( 'Purchase Log %1$s to %2$s.csv', 'exported purchase log csv file name', 'wp-e-commerce' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  | 		$csv_name = sprintf( $csv_name, date( "M-d-Y", $start_timestamp ), date( "M-d-Y", $end_timestamp ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  | 	} elseif ( isset( $args['m'] ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  | 		$year = (int) substr( $args['m'], 0, 4); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  | 		$month = (int) substr( $args['m'], -2 ); | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  | 		$month_year_sql = " | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  | 			SELECT * | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  | 			FROM " . WPSC_TABLE_PURCHASE_LOGS . " | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  | 			WHERE YEAR(FROM_UNIXTIME(date)) = %d AND MONTH(FROM_UNIXTIME(date)) = %d | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  | 			ORDER BY `id` DESC | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  | 		"; | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  | 		$month_year_sql = apply_filters( 'wpsc_purchase_log_month_year_csv', $month_year_sql ); | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  | 		$data = $wpdb->get_results( $wpdb->prepare( $month_year_sql, $year, $month ), ARRAY_A ); | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  | 		/* translators: %1$s is month, %2$s is year */ | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 		$csv_name = _x( 'Purchase Log %1$s/%2$s.csv', 'exported purchase log csv file name', 'wp-e-commerce' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 		$csv_name = sprintf( $csv_name, $month, $year ); | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  | 	} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  | 		$sql = apply_filters( 'wpsc_purchase_log_month_year_csv', "SELECT * FROM " . WPSC_TABLE_PURCHASE_LOGS . " ORDER BY `id` DESC" ); | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  | 		$data = $wpdb->get_results( $sql, ARRAY_A ); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  | 		$csv_name = _x( "All Purchase Logs.csv", 'exported purchase log csv file name', 'wp-e-commerce' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  | 	$form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' AND `type` != 'heading' ORDER BY `checkout_order` DESC;"; | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  | 	$form_data = $wpdb->get_results( $form_sql, ARRAY_A ); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  | 	$headers_array = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  | 		_x( 'Purchase ID'   , 'purchase log csv headers', 'wp-e-commerce' ), | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  | 		_x( 'Purchase Total', 'purchase log csv headers', 'wp-e-commerce' ), | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  | 	); | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  | 	$headers2_array = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  | 		_x( 'Payment Gateway', 'purchase log csv headers', 'wp-e-commerce' ), | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  | 		_x( 'Payment Status' , 'purchase log csv headers', 'wp-e-commerce' ), | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  | 		_x( 'Purchase Date'  , 'purchase log csv headers', 'wp-e-commerce' ), | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  | 	); | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  | 	$form_headers_array = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  | 	$output = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  | 	foreach ( (array) $form_data as $form_field ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  | 		if ( empty ( $form_field['unique_name'] ) ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  | 			$form_headers_array[] = $form_field['name']; | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  | 		} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  | 			$prefix = false === strstr( $form_field['unique_name'], 'billing' ) ? _x( 'Shipping ', 'purchase log csv header field prefix', 'wp-e-commerce' ) : _x( 'Billing ', 'purchase log csv header field prefix', 'wp-e-commerce' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  | 			$form_headers_array[] = $prefix . $form_field['name']; | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  | 	foreach ( (array) $data as $purchase ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  | 		$form_headers = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  | 		$output .= "\"" . $purchase['id'] . "\","; //Purchase ID | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  | 		$output .= "\"" . $purchase['totalprice'] . "\","; //Purchase Total | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  | 		foreach ( (array) $form_data as $form_field ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  | 			$collected_data_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = '" . $purchase['id'] . "' AND `form_id` = '" . $form_field['id'] . "' LIMIT 1"; | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  | 			$collected_data = $wpdb->get_results( $collected_data_sql, ARRAY_A ); | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  | 			$collected_data = $collected_data[0]; | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  | 			if (  ( 'billingstate' == $form_field['unique_name'] || 'shippingstate' == $form_field['unique_name'] ) && is_numeric( $collected_data['value'] ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  | 				$output .= "\"" . wpsc_get_state_by_id( $collected_data['value'], 'code' ) . "\","; // get form fields | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  | 			else | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  | 				$output .= "\"" . str_replace( array( "\r", "\r\n", "\n" ), ' ', $collected_data['value'] ) . "\","; // get form fields | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 181 |  |  | 		if ( isset( $wpsc_gateways[$purchase['gateway']] ) && isset( $wpsc_gateways[$purchase['gateway']]['display_name'] ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 182 |  |  | 			$output .= "\"" . $wpsc_gateways[$purchase['gateway']]['display_name'] . "\","; //get gateway name | 
            
                                                                        
                            
            
                                    
            
            
                | 183 |  |  | 		else | 
            
                                                                        
                            
            
                                    
            
            
                | 184 |  |  | 			$output .= "\"\","; | 
            
                                                                        
                            
            
                                    
            
            
                | 185 |  |  |  | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 187 |  |  | 		$status_name = wpsc_find_purchlog_status_name( $purchase['processed'] ); | 
            
                                                                        
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 189 |  |  | 		$output .= "\"" . $status_name . "\","; //get purchase status | 
            
                                                                        
                            
            
                                    
            
            
                | 190 |  |  | 		$output .= "\"" . date( apply_filters( 'wpsc_purchase_log_csv_date_format', 'jS M Y' ), $purchase['date'] ) . "\","; //date | 
            
                                                                        
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 192 |  |  | 		$cartsql = "SELECT `prodid`, `quantity`, `name` FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase['id'] . ""; | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  | 		$cart = $wpdb->get_results( $cartsql, ARRAY_A ); | 
            
                                                                        
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 195 |  |  | 		if ( $count < count( $cart ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  | 		    $count = count( $cart ); | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  | 		$items = count( $cart ); | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  | 		$i     = 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 201 |  |  | 		// Go through all products in cart and display quantity and sku | 
            
                                                                        
                            
            
                                    
            
            
                | 202 |  |  | 		foreach ( (array) $cart as $item ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 203 |  |  | 			$skuvalue = get_product_meta( $item['prodid'], 'sku', true ); | 
            
                                                                        
                            
            
                                    
            
            
                | 204 |  |  | 			if( empty( $skuvalue ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 205 |  |  | 			    $skuvalue = __( 'N/A', 'wp-e-commerce' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  | 			$output .= "\"" . $item['quantity'] . "\","; | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  | 			$output .= "\"" . str_replace( '"', '\"', $item['name'] ) . "\","; | 
            
                                                                        
                            
            
                                    
            
            
                | 208 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  | 			if ( $items <= 1 ) | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  | 				$output .= "\"" . $skuvalue . "\"" ; | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  | 			elseif ( $items > 1 && $i != $items  ) | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  | 				$output .= "\"" . $skuvalue . "\"," ; | 
            
                                                                        
                            
            
                                    
            
            
                | 213 |  |  | 			else | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  | 				$output .= "\"" . $skuvalue . "\"" ; | 
            
                                                                        
                            
            
                                    
            
            
                | 215 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 216 |  |  | 			$i++; | 
            
                                                                        
                            
            
                                    
            
            
                | 217 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 218 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 219 |  |  | 		$output .= "\n"; // terminates the row/line in the CSV file | 
            
                                                                        
                            
            
                                    
            
            
                | 220 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 221 |  |  | 	// Get the most number of products and create a header for them | 
            
                                                                        
                            
            
                                    
            
            
                | 222 |  |  | 	$headers3 = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 223 |  |  | 	for( $i = 0; $i < $count; $i++ ){ | 
            
                                                                        
                            
            
                                    
            
            
                | 224 |  |  | 		$headers3[] = _x( 'Quantity', 'purchase log csv headers', 'wp-e-commerce' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 225 |  |  | 		$headers3[] = _x( 'Product Name', 'purchase log csv headers', 'wp-e-commerce' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 226 |  |  | 		$headers3[] = _x( 'SKU', 'purchase log csv headers', 'wp-e-commerce' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 227 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 229 |  |  | 	$headers      = '"' . implode( '","', $headers_array ) . '",'; | 
            
                                                                        
                            
            
                                    
            
            
                | 230 |  |  | 	$form_headers = '"' . implode( '","', $form_headers_array ) . '",'; | 
            
                                                                        
                            
            
                                    
            
            
                | 231 |  |  | 	$headers2     = '"' . implode( '","', $headers2_array ) . '",'; | 
            
                                                                        
                            
            
                                    
            
            
                | 232 |  |  | 	$headers3     = '"' . implode( '","', $headers3 ) . '"'; | 
            
                                                                        
                            
            
                                    
            
            
                | 233 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 234 |  |  | 	$headers      = apply_filters( 'wpsc_purchase_log_csv_headers', $headers . $form_headers . $headers2 . $headers3, $data, $form_data ); | 
            
                                                                        
                            
            
                                    
            
            
                | 235 |  |  | 	$output       = apply_filters( 'wpsc_purchase_log_csv_output' , $output, $data, $form_data ); | 
            
                                                                        
                            
            
                                    
            
            
                | 236 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 237 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 238 |  |  | 	 * Fires when the WPSC purchase log is exported as a CSV | 
            
                                                                        
                            
            
                                    
            
            
                | 239 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 240 |  |  | 	do_action( 'wpsc_purchase_log_csv' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 241 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 242 |  |  | 	header( 'Content-Type: text/csv' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 243 |  |  | 	header( 'Content-Disposition: inline; filename="' . $csv_name . '"' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 244 |  |  | 	echo $headers . "\n". $output; | 
            
                                                                        
                            
            
                                    
            
            
                | 245 |  |  | 	exit; | 
            
                                                                        
                            
            
                                    
            
            
                | 246 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'wpsc_downloadcsv') ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 	add_action( 'admin_init', 'wpsc_purchase_log_csv' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | if ( isset( $_GET['purchase_log_csv'] ) && ( 'true' == $_GET['purchase_log_csv'] ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 	add_action( 'admin_init', 'wpsc_purchase_log_csv' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | function wpsc_admin_sale_rss() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 	global $wpdb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 	if ( ($_GET['rss'] == "true") && ($_GET['rss_key'] == 'key') && ($_GET['action'] == "purchase_log") ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | 		$sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date`!='' ORDER BY `date` DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 		$purchase_log = $wpdb->get_results( $sql, ARRAY_A ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 		header( "Content-Type: application/xml; charset=UTF-8" ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 		header( 'Content-Disposition: inline; filename="WP_E-Commerce_Purchase_Log.rss"' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 		$output = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 		$output .= "<?xml version='1.0'?>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 		$output .= "<rss version='2.0'>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  | 		$output .= "  <channel>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | 		$output .= "    <title>" . _x( 'WP eCommerce Product Log', 'admin rss product feed', 'wp-e-commerce' ) . "</title>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 		$output .= "    <link>" . admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "</link>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | 		$output .= "    <description>" . _x( 'This is the WP eCommerce Product Log RSS feed', 'admin rss product feed', 'wp-e-commerce' ) . "</description>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | 		$output .= "    <generator>" . _x( 'WP eCommerce Plugin', 'admin rss product feed', 'wp-e-commerce' ) . "</generator>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | 		foreach ( (array)$purchase_log as $purchase ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | 			$purchase_link = admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "&purchaseid=" . $purchase['id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | 			$purchase_title = _x( 'Purchase # %d', 'admin rss product feed', 'wp-e-commerce' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  | 			$purchase_title = sprintf( $purchase_title, $purchase['id'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 			$output .= "    <item>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | 			$output .= "      <title>{$purchase_title}</title>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | 			$output .= "      <link>$purchase_link</link>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | 			$output .= "      <description>" . _x( 'This is an entry in the purchase log', 'admin rss product feed', 'wp-e-commerce' ) . ".</description>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | 			$output .= "      <pubDate>" . date( "r", $purchase['date'] ) . "</pubDate>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  | 			$output .= "      <guid>$purchase_link</guid>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | 			$output .= "    </item>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | 		$output .= "  </channel>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | 		$output .= "</rss>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  | 		echo $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | 		exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  | if ( isset( $_GET['action'] ) && ( 'purchase_log' == $_GET['action'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  | 	add_action( 'admin_init', 'wpsc_admin_sale_rss' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |  * Do Purchase Log Actions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |  * All purchase log actions are capability and nonce checked before calling | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |  * the relevent 'wpsc_purchase_log_action-{wpsc_purchase_log_action}' hook. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |  * @since  3.9.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  | function wpsc_do_purchase_log_actions() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  | 	if ( isset( $_GET['wpsc_purchase_log_action'] ) && isset( $_GET['id'] ) && isset( $_GET['_wpnonce'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  | 		$wpsc_purchase_log_action = sanitize_key( $_GET['wpsc_purchase_log_action'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  | 		if ( wp_verify_nonce( $_GET['_wpnonce'], 'wpsc_purchase_log_action_' . $wpsc_purchase_log_action ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  | 			do_action( 'wpsc_purchase_log_action-' . $wpsc_purchase_log_action, absint( $_GET['id'] ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  | add_action( 'admin_init', 'wpsc_do_purchase_log_actions' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |  * Handle clear downloads lock purchase log action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  * The 'wpsc_purchase_log_action-downloads_lock' action hook which calls this function is nonce and capability checked | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |  * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-downloads_lock' ). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |  * @since  3.9.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |  * @param  int  $log_id  Purchase log ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | function wpsc_purchase_log_action_downloads_lock( $log_id ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  | 	wpsc_purchlog_clear_download_items( $log_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  | 	// Redirect back to purchase logs list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  | 	$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  | 	$sendback = esc_url_raw( add_query_arg( 'cleared', 1, $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  | 	wp_redirect( $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  | 	exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  | add_action( 'wpsc_purchase_log_action-downloads_lock', 'wpsc_purchase_log_action_downloads_lock' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |  * Handle delete purchase log action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |  * The 'wpsc_purchase_log_action-delete' action hook which calls this function is nonce and capability checked | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |  * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-delete' ). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |  * @since  3.9.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |  * @param  int  $log_id  Purchase log ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  | function wpsc_purchase_log_action_delete( $log_id ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  | 	$log = new WPSC_Purchase_Log( $log_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  | 	$deleted = $log->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  | 	// Redirect back to purchase logs list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  | 	$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  | 	$sendback = remove_query_arg( array( 'c', 'id' ), $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  | 	$sendback = esc_url_raw( add_query_arg( 'deleted', absint( $deleted ), $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  | 	wp_redirect( $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  | 	exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  | add_action( 'wpsc_purchase_log_action-delete', 'wpsc_purchase_log_action_delete' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |  * Handle email receipt purchase log action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |  * The 'wpsc_purchase_log_action-email_receipt' action hook which calls this function is nonce and capability checked | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |  * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-email_receipt' ). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |  * @since  3.9.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |  * @param  int  $log_id  Purchase log ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  | function wpsc_purchase_log_action_email_receipt( $log_id ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  | 	$sent = wpsc_purchlog_resend_email( $log_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  | 	// Redirect back to purchase logs list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  | 	$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  | 	$sendback = esc_url_raw( add_query_arg( 'sent', absint( $sent ), $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  | 	wp_redirect( $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  | 	exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  | add_action( 'wpsc_purchase_log_action-email_receipt', 'wpsc_purchase_log_action_email_receipt' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |  * Resend Purchase Log Email | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |  * @param   int|string  $log_id  Required. Purchase log ID (empty string is deprecated). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |  * @return  boolean              Sent successfully. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  | function wpsc_purchlog_resend_email( $log_id = '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  | 	global $wpdb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  | 	// Deprecate empty purchase log ID parameter. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  | 	if ( $log_id == '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  | 		_wpsc_doing_it_wrong( 'wpsc_purchlog_resend_email', __( '$log_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  | 		// Support redirect for legacy purposes for the moment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  | 		$sendback = esc_url_raw( add_query_arg( 'sent', 0, wp_get_referer() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  | 		wp_redirect( $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  | 		exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  | 	$log_id = absint( $log_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  | 	if ( $log_id > 0 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  | 		$wpec_taxes_controller = new wpec_taxes_controller(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  | 		if ( is_numeric( $log_id ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  | 			$purchase_log = new WPSC_Purchase_Log( $log_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  | 			return wpsc_send_customer_email( $purchase_log ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  | 	return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  | // Deprecate resending purchase log email receipt via URL query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  | if ( isset( $_REQUEST['email_buyer_id'] ) && is_numeric( $_REQUEST['email_buyer_id'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  | 	_wpsc_doing_it_wrong( 'wpsc_purchlog_resend_email', __( 'Do not trigger resend purchase log email action via email_buyer_id URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |  * Clear Purchase Log Download Locks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |  * @param   string   $log_id  Required. Purchase log ID (empty string is deprecated). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |  * @return  boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  | function wpsc_purchlog_clear_download_items( $log_id = '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  | 	global $wpdb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  | 	// Deprecate empty purchase log ID parameter. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  | 	if ( $log_id == '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  | 		_wpsc_doing_it_wrong( 'wpsc_purchlog_clear_download_items', __( '$log_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  | 		return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  | 	$log_id = absint( $log_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  | 	if ( $log_id > 0 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  | 		$downloadable_items = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `purchid` = %d", $log_id ), ARRAY_A ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  | 		$wpdb->update( WPSC_TABLE_DOWNLOAD_STATUS, array( 'ip_number' => '' ), array( 'purchid' => $log_id ), '%s', '%d' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  | 		$email_form_field = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `checkout_order` ASC LIMIT 1" ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  | 		$email_address = $wpdb->get_var( $wpdb->prepare( "SELECT `value` FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = '{$email_form_field}' LIMIT 1", $log_id ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  | 		foreach ( $downloadable_items as $downloadable_item ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  | 			$download_links .= add_query_arg( 'downloadid', $downloadable_item['uniqueid'], home_url() )  . "\n"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  | 		wp_mail( $email_address, __( 'The administrator has unlocked your file', 'wp-e-commerce' ), str_replace( "[download_links]", $download_links, __( 'Dear Customer, We are pleased to advise you that your order has been updated and your downloads are now active. Please download your purchase using the links provided below. [download_links] Thank you for your order.', 'wp-e-commerce' ) ), "From: " . get_option( 'return_email' )  ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  | 		return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  | 	return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  | // Deprecate clearing purchase log download locks via URL query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'clear_locks') ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  | 	_wpsc_doing_it_wrong( 'wpsc_purchlog_clear_download_items', __( 'Do not trigger clear purchase log download locks action via wpsc_admin_action = clear_locks URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  | //bulk actions for purchase log | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  | function wpsc_purchlog_bulk_modify() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  | 	if ( $_POST['purchlog_multiple_status_change'] != -1 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  | 		if ( is_numeric( $_POST['purchlog_multiple_status_change'] ) && $_POST['purchlog_multiple_status_change'] != 'delete' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  | 			foreach ( (array)$_POST['purchlogids'] as $purchlogid ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  | 				wpsc_purchlog_edit_status( $purchlogid, $_POST['purchlog_multiple_status_change'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  | 				$updated++; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  | 		} elseif ( $_POST['purchlog_multiple_status_change'] == 'delete' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  | 			foreach ( (array)$_POST['purchlogids'] as $purchlogid ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  | 				$log = new WPSC_Purchase_Log( $purchlogid ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  | 				$deleted_log = $log->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  | 				if ( $deleted_log ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  | 					$deleted++; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  | 	$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  | 	if ( isset( $updated ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  | 		$sendback = add_query_arg( 'updated', $updated, $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  | 	if ( isset( $deleted ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  | 		$sendback = add_query_arg( 'deleted', $deleted, $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  | 	if ( isset( $_POST['view_purchlogs_by'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  | 		$sendback = add_query_arg( 'view_purchlogs_by', $_POST['view_purchlogs_by'], $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  | 	if ( isset( $_POST['view_purchlogs_by_status'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  | 		$sendback = add_query_arg( 'view_purchlogs_by_status', $_POST['view_purchlogs_by_status'], $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  | 	wp_redirect( esc_url_raw( $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  | 	exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  | if ( isset( $_REQUEST['wpsc_admin_action2'] ) && ($_REQUEST['wpsc_admin_action2'] == 'purchlog_bulk_modify') ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  | 	add_action( 'admin_init', 'wpsc_purchlog_bulk_modify' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |  * Update Purchase Log Notes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |  * @param  int     $purchlog_id     Purchase log ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |  * @param  string  $purchlog_notes  Notes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  | function wpsc_purchlogs_update_notes( $purchlog_id = 0, $purchlog_notes = '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  | 	if ( isset( $_POST['wpsc_purchlogs_update_notes_nonce'] ) && wp_verify_nonce( $_POST['wpsc_purchlogs_update_notes_nonce'], 'wpsc_purchlogs_update_notes' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  | 		if ( 0 == $purchlog_id && isset( $_POST['purchlog_id'] ) && '' == $purchlog_notes ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  | 			$purchlog_id = absint( $_POST['purchlog_id'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  | 			$purchlog_notes = stripslashes( $_POST['purchlog_notes'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  | 		if ( $purchlog_id > 0 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  | 			$purchase_log = new WPSC_Purchase_Log( $purchlog_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  | 			$purchase_log->set( 'notes', $purchlog_notes ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  | 			$purchase_log->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && $_REQUEST['wpsc_admin_action'] == 'purchlogs_update_notes' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  | 	add_action( 'admin_init', 'wpsc_purchlogs_update_notes' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |  * Delete a purchase log | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |  * @deprecated  Use WPSC_Purchase_Log->delete() instead. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |  * @param   int|string  $purchlog_id  Required. Purchase log ID (empty string is deprecated). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |  * @return  boolean                   Deleted successfully. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  | function wpsc_delete_purchlog( $purchlog_id = '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  | 	global $wpdb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 573 |  |  | 	// Deprecate empty purchase log ID parameter. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 574 |  |  | 	if ( $purchlog_id == '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 575 |  |  | 		_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( '$purchlog_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 576 |  |  | 		return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 577 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 578 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 579 |  |  | 	$log = new WPSC_Purchase_Log( $purchlog_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 580 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 581 |  |  | 	return $log->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 582 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 583 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 584 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 585 |  |  | // Deprecate deleting purchase log via URL query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 586 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'delete_purchlog' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 587 |  |  | 	_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( 'Do not trigger delete purchase log action via wpsc_admin_action = delete_purchlog URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 588 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 589 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 590 |  |  | function _wpsc_action_flush_rewrite_rules() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 591 |  |  | 	flush_rewrite_rules( false ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 592 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 593 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 594 |  |  | function wpsc_update_option_product_category_hierarchical_url() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 595 |  |  | 	_wpsc_action_flush_rewrite_rules(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 596 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 |  |  | add_action( 'update_option_product_category_hierarchical_url', 'wpsc_update_option_product_category_hierarchical_url' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 |  |  | function _wpsc_action_sanitize_option_grid_number_per_row( $value, $option ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 |  |  | 	$value = (int) $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  | 	if ( $value === 0 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  | 		add_settings_error( $option, 'invalid_grid_number_per_row', __( 'You just set the number of item per row for the grid view to 0. This means the column width will fall back to using whatever CSS you have for it. This could break your theme layout, so please make sure you have adjusted your theme\'s CSS accordingly.', 'wp-e-commerce' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 606 |  |  | 	return $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 607 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 608 |  |  | add_filter( 'sanitize_option_grid_number_per_row', '_wpsc_action_sanitize_option_grid_number_per_row', 10, 2 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 609 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 610 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 611 |  |  |  * Automatically enable "Anyone can register" if registration before checkout is required. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 612 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 613 |  |  |  * @since  3.8.9 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 614 |  |  |  * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 615 |  |  |  * @param  mixed $old_value Old value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 616 |  |  |  * @param  mixed $new_value New value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 617 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 618 |  |  | function _wpsc_action_update_option_require_register( $old_value, $new_value ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 619 |  |  | 	if ( $new_value == 1 && ! get_option( 'users_can_register' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 620 |  |  | 		update_option( 'users_can_register', 1 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 621 |  |  | 		$message = __( 'You wanted to require your customers to log in before checking out. However, the WordPress setting <a href="%s">"Anyone can register"</a> was disabled. WP eCommerce has enabled that setting for you automatically.', 'wp-e-commerce' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 622 |  |  | 		$message = sprintf( $message, admin_url( 'options-general.php' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 623 |  |  | 		add_settings_error( 'require_register', 'users_can_register_turned_on', $message, 'updated' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 624 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 625 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 626 |  |  | add_action( 'update_option_require_register', '_wpsc_action_update_option_require_register', 10, 2 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 627 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 628 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 629 |  |  |  * Automatically turn off "require registration before checkout" if "Anyone can register" is disabled. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 630 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 631 |  |  |  * @since  3.8.9 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 632 |  |  |  * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 633 |  |  |  * @param  mixed $old_value Old value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 634 |  |  |  * @param  mixed $new_value New value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 635 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 636 |  |  | function _wpsc_action_update_option_users_can_register( $old_value, $new_value ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 637 |  |  | 	if ( ! $new_value && get_option( 'require_register' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 638 |  |  | 		update_option( 'require_register', 0 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 639 |  |  | 		$message = __( 'You just disabled the "Anyone can register" setting. As a result, the <a href="%s">"Require registration before checking out"</a> setting has been disabled.', 'wp-e-commerce' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 640 |  |  | 		$message = sprintf( $message, admin_url( 'options-general.php?page=wpsc-settings&tab=checkout' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 641 |  |  | 		add_settings_error( 'users_can_register', 'require_register_turned_off', $message, 'updated' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 642 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 643 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 644 |  |  | add_action( 'update_option_users_can_register', '_wpsc_action_update_option_users_can_register', 10, 2 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 645 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 646 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 647 |  |  |  * wpsc_update_page_urls gets the permalinks for products pages and stores them in the options for quick reference | 
            
                                                                                                            
                            
            
                                    
            
            
                | 648 |  |  |  * @public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 649 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 650 |  |  |  * @since 3.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 651 |  |  |  * @param $auto (Boolean) true if coming from WordPress Permalink Page, false otherwise | 
            
                                                                                                            
                            
            
                                    
            
            
                | 652 |  |  |  * @return nothing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 653 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 654 |  |  | function wpsc_update_page_urls( $auto = false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 655 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 656 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 657 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 658 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 659 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 660 |  |  | 	wpsc_update_permalink_slugs(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 661 |  |  | 	wpsc_core_load_page_titles(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 662 |  |  | 	wpsc_register_post_types(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 663 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 664 |  |  | 	if ( ! $auto ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 665 |  |  | 		$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 666 |  |  | 		if ( isset( $updated ) ) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 667 |  |  | 			$sendback = add_query_arg( 'updated', $updated, $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 668 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 669 |  |  | 		if ( isset( $_SESSION['wpsc_settings_curr_page'] ) ) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 670 |  |  | 			$sendback = add_query_arg( 'tab', $_SESSION['wpsc_settings_curr_page'], $sendback ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 671 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 672 |  |  | 		wp_redirect( esc_url_raw( $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 673 |  |  | 		exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 674 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 675 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 676 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'update_page_urls') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 677 |  |  | 	add_action( 'admin_init', 'wpsc_update_page_urls' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 678 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 679 |  |  | //change the regions tax settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 680 |  |  | function wpsc_change_region_tax() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 681 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 682 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 683 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 684 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 685 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 686 |  |  | 	global $wpdb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 687 |  |  | 	if ( is_array( $_POST['region_tax'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 688 |  |  | 		foreach ( $_POST['region_tax'] as $region_id => $tax ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 689 |  |  | 			if ( is_numeric( $region_id ) && is_numeric( $tax ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 690 |  |  | 				$previous_tax = $wpdb->get_var( $wpdb->prepare( "SELECT `tax` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id` = %d LIMIT 1", $region_id ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 691 |  |  | 				if ( $tax != $previous_tax ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 692 |  |  | 					$wpdb->update( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 693 |  |  | 						WPSC_TABLE_REGION_TAX, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 694 |  |  | 						array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 695 |  |  | 						    'tax' => $tax | 
            
                                                                                                            
                            
            
                                    
            
            
                | 696 |  |  | 						), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 697 |  |  | 						array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 698 |  |  | 						    'id' => $region_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 699 |  |  | 						), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 700 |  |  | 						'%s', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 701 |  |  | 						'%d' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 702 |  |  | 					    ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 703 |  |  | 					$changes_made = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 704 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 705 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 706 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 707 |  |  | 		$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 708 |  |  | 		wp_redirect( $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 709 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 710 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 711 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'change_region_tax') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 712 |  |  | 	add_action( 'admin_init', 'wpsc_change_region_tax' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 713 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 714 |  |  | function wpsc_product_files_existing() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 715 |  |  | 	//List all product_files, with checkboxes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 716 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 717 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 718 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 719 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 720 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 721 |  |  | 	$product_id = absint( $_GET["product_id"] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 722 |  |  | 	$file_list = wpsc_uploaded_files(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 723 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 724 |  |  | 	$args = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 725 |  |  | 		'post_type' => 'wpsc-product-file', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 726 |  |  | 		'post_parent' => $product_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 727 |  |  | 		'numberposts' => -1, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 728 |  |  | 		'post_status' => 'all' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 729 |  |  | 	); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 730 |  |  | 	$attached_files = (array)get_posts( $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 731 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 732 |  |  | 	$attached_files_by_file = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 733 |  |  | 	foreach ( $attached_files as $key => $attached_file ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 734 |  |  | 		$attached_files_by_file[$attached_file->post_title] = & $attached_files[$key]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 735 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 736 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 737 |  |  | 	$output = "<span class='admin_product_notes select_product_note '>" . esc_html__( 'Choose a downloadable file for this product:', 'wp-e-commerce' ) . "</span><br>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 738 |  |  | 	$output .= "<form method='post' class='product_upload'>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 739 |  |  | 	$output .= '<div class="ui-widget-content multiple-select select_product_file" style="width:100%">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 740 |  |  | 	$num = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 741 |  |  | 	foreach ( (array)$file_list as $file ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 742 |  |  | 		$num++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 743 |  |  | 		$checked_curr_file = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 744 |  |  | 		if ( isset( $attached_files_by_file[$file['display_filename']] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 745 |  |  | 			$checked_curr_file = "checked='checked'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 746 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 747 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 748 |  |  | 		$output .= "<p " . ((($num % 2) > 0) ? '' : "class='alt'") . " id='select_product_file_row_$num'>\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 749 |  |  | 		$output .= "  <input type='checkbox' name='select_product_file[]' value='" . $file['real_filename'] . "' id='select_product_file_$num' " . $checked_curr_file . " />\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 750 |  |  | 		$output .= "  <label for='select_product_file_$num'>" . $file['display_filename'] . "</label>\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 751 |  |  | 		$output .= "</p>\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 752 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 753 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 754 |  |  | 	$output .= "</div>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 755 |  |  | 	$output .= "<input type='hidden' id='hidden_id' value='$product_id' />"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 756 |  |  | 	$output .= "<input data-nonce='" . _wpsc_create_ajax_nonce( 'upload_product_file' ) . "' type='submit' name='save' name='product_files_submit' class='button-primary prdfil' value='" . esc_html__( 'Save Product Files', 'wp-e-commerce' ) . "' />"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 757 |  |  | 	$output .= "</form>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 758 |  |  | 	$output .= "<div class='" . ((is_numeric( $product_id )) ? "edit_" : "") . "select_product_handle'><div></div></div>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 759 |  |  | 	$output .= "<script type='text/javascript'>\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 760 |  |  | 	$output .= "var select_min_height = " . (25 * 3) . ";\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 761 |  |  | 	$output .= "var select_max_height = " . (25 * ($num + 1)) . ";\n\r"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 762 |  |  | 	$output .= "</script>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 763 |  |  | 	echo $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 764 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 765 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'product_files_existing') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 766 |  |  | 	add_action( 'admin_init', 'wpsc_product_files_existing' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 767 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 768 |  |  | function wpsc_update_variations() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 769 |  |  | 	$product_id = absint( $_POST["product_id"] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 770 |  |  | 	$product_type_object = get_post_type_object('wpsc-product'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 771 |  |  | 	if (!current_user_can($product_type_object->cap->edit_post, $product_id)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 772 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 773 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 774 |  |  | 	//Setup postdata | 
            
                                                                                                            
                            
            
                                    
            
            
                | 775 |  |  | 	$post_data = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 776 |  |  | 	$post_data['edit_var_val'] = isset( $_POST['edit_var_val'] ) ? $_POST["edit_var_val"] : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 777 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 778 |  |  | 	//Add or delete variations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 779 |  |  | 	wpsc_edit_product_variations( $product_id, $post_data ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 780 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 781 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 782 |  |  | if ( isset($_POST["edit_var_val"]) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 783 |  |  | 	add_action( 'admin_init', 'wpsc_update_variations', 50 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 784 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 785 |  |  | function wpsc_delete_variation_set() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 786 |  |  | 	check_admin_referer( 'delete-variation' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 787 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 788 |  |  | 	if ( is_numeric( $_GET['deleteid'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 789 |  |  | 		$variation_id = absint( $_GET['deleteid'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 790 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 791 |  |  | 		$variation_set = get_term( $variation_id, 'wpsc-variation', ARRAY_A ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 792 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 793 |  |  | 		$variations = get_terms( 'wpsc-variation', array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 794 |  |  | 					'hide_empty' => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 795 |  |  | 					'parent' => $variation_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 796 |  |  | 				) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 797 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 798 |  |  | 		foreach ( (array) $variations as $variation ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 799 |  |  | 			$return_value = wp_delete_term( $variation->term_id, 'wpsc-variation' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 800 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 801 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 802 |  |  | 		if ( !empty( $variation_set ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 803 |  |  | 			$return_value = wp_delete_term( $variation_set['term_id'], 'wpsc-variation' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 804 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 805 |  |  | 		$deleted = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 806 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 807 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 808 |  |  | 	$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 809 |  |  | 	if ( isset( $deleted ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 810 |  |  | 		$sendback = add_query_arg( 'deleted', $deleted, $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 811 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 812 |  |  | 	$sendback = remove_query_arg( array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 813 |  |  | 				'deleteid', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 814 |  |  | 				'variation_id' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 815 |  |  | 					), $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 816 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 817 |  |  | 	wp_redirect( esc_url_raw( $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 818 |  |  | 	exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 819 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 820 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 821 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-variation-set' == $_REQUEST['wpsc_admin_action'] ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 822 |  |  | 	add_action( 'admin_init', 'wpsc_delete_variation_set' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 823 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 824 |  |  | function wpsc_backup_theme() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 825 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 826 |  |  | 	if ( ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 827 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 828 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 829 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 830 |  |  | 	$wp_theme_path = get_stylesheet_directory(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 831 |  |  | 	wpsc_recursive_copy( $wp_theme_path, WPSC_THEME_BACKUP_DIR ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 832 |  |  | 	$_SESSION['wpsc_themes_backup'] = true; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 833 |  |  | 	$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 834 |  |  | 	wp_redirect( $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 835 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 836 |  |  | 	exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 837 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 838 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'backup_themes' ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 839 |  |  | 	add_action( 'admin_init', 'wpsc_backup_theme' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 840 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 841 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 842 |  |  |  * Delete a coupon | 
            
                                                                                                            
                            
            
                                    
            
            
                | 843 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 844 |  |  |  * @since 3.8 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 845 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 846 |  |  | function wpsc_delete_coupon(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 847 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 848 |  |  | 	global $wpdb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 849 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 850 |  |  | 	check_admin_referer( 'delete-coupon' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 851 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 852 |  |  | 	if ( ! function_exists( 'wpsc_is_store_admin' ) || ! wpsc_is_store_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 853 |  |  | 		return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 854 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 855 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 856 |  |  | 	$deleted = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 857 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 858 |  |  | 	if ( isset( $_GET['delete_id'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 859 |  |  | 		$coupon = new WPSC_Coupon( $_GET['delete_id'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 860 |  |  | 		$coupon->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 861 |  |  | 		$deleted = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 862 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 863 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 864 |  |  | 	$sendback = wp_get_referer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 865 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 866 |  |  | 	if ( $deleted ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 867 |  |  | 		$sendback = add_query_arg( 'deleted', $deleted, $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 868 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 869 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 870 |  |  | 	$sendback = remove_query_arg( array( 'deleteid', 'wpsc_admin_action' ), $sendback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 871 |  |  | 	wp_redirect( esc_url_raw( $sendback ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 872 |  |  | 	exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 873 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 874 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 875 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 876 |  |  | // Delete Coupon | 
            
                                                                                                            
                            
            
                                    
            
            
                | 877 |  |  | if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-coupon' == $_REQUEST['wpsc_admin_action'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 878 |  |  | 	add_action( 'admin_init', 'wpsc_delete_coupon' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 879 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 880 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 881 |  |  | function _wpsc_action_update_option_base_country( $old_value, $new_value ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 882 |  |  | 	global $wpdb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 883 |  |  | 	$region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')",  $new_value ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 884 |  |  | 	if ( ! $region_count ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 885 |  |  | 		update_option( 'base_region', '' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 886 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 887 |  |  | add_action( 'update_option_base_country', '_wpsc_action_update_option_base_country', 10, 2 ); | 
            
                                                        
            
                                    
            
            
                | 888 |  |  |  |