";
  if($selected_country == null) {
    $output = "";
	}
  $country_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_CURRENCY_LIST."` ORDER BY `country` ASC",ARRAY_A);
  foreach ($country_data as $country) {
    $selected ='';
    if($selected_country == $country['isocode']) {
      $selected = "selected='true'";
		}
    $output .= "";
	}
  return $output;
}
function nzshpcrt_region_list($selected_country = null, $selected_region = null) {
  global $wpdb;
  if($selected_region == null) {
    $selected_region = get_option('base_region');
	}
  $output = "";
  $region_list = $wpdb->get_results("SELECT `".WPSC_TABLE_REGION_TAX."`.* FROM `".WPSC_TABLE_REGION_TAX."`, `".WPSC_TABLE_CURRENCY_LIST."`  WHERE `".WPSC_TABLE_CURRENCY_LIST."`.`isocode` IN('".$selected_country."') AND `".WPSC_TABLE_CURRENCY_LIST."`.`id` = `".WPSC_TABLE_REGION_TAX."`.`country_id`",ARRAY_A) ;
  if($region_list != null) {
    $output .= "\n\r";    
	} else {
		$output .= "\n\r";
	}
  return $output;
}
  
function nzshpcrt_form_field_list($selected_field = null)
  {
  global $wpdb;
  $output = "";
  $output .= "";
  $form_sql = "SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1';";
  $form_data = $wpdb->get_results($form_sql,ARRAY_A);
  foreach ((array)$form_data as $form) {
    $selected ='';
    if($selected_field == $form['id']) {
      $selected = "selected='true'";
		}
    $output .= "";
	}
  return $output;
}
  
  
function wpsc_parent_category_list($group_id, $category_id, $category_parent_id) {
  global $wpdb,$category_data;
  $options = "";
  $options .= "\r\n";
  $options .= wpsc_category_options((int)$group_id, (int)$category_id, null, 0, (int)$category_parent_id);   
  $concat .= "\r\n";    
  return $concat;
}
function wpsc_category_options($group_id, $this_category = null, $category_id = null, $iteration = 0, $selected_id = null) {
  /*
   * Displays the category forms for adding and editing products
   * Recurses to generate the branched view for subcategories
   */
  global $wpdb;
  $siteurl = get_option('siteurl');
  if(is_numeric($category_id)) {
    $values = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `group_id` = '$group_id' AND `active`='1' AND `id` != '$this_category' AND `category_parent` = '$category_id'  ORDER BY `id` ASC",ARRAY_A);
	} else {
    $values = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `group_id` = '$group_id' AND `active`='1' AND `id` != '$this_category' AND `category_parent` = '0'  ORDER BY `id` ASC",ARRAY_A);
	}
  foreach((array)$values as $option) {
    if($selected_id == $option['id']) {
      $selected = "selected='selected'";
		}
    
    $output .= "\r\n";
    $output .= wpsc_category_options($group_id, $this_category, $option['id'], $iteration+1, $selected_id);
    $selected = "";
	}
  return $output;
}
  
function wpsc_uploaded_files() {
  global $wpdb, $wpsc_uploaded_file_cache;
  
  $dir = @opendir(WPSC_FILE_DIR);
  $num = 0;
  if(count($wpsc_uploaded_file_cache) > 0) {
    $dirlist = $wpsc_uploaded_file_cache;
  } else {
		while(($file = @readdir($dir)) !== false) {
			//filter out the dots, macintosh hidden files and any backup files
			if(($file != "..") && ($file != ".") && ($file != "product_files")  && ($file != "preview_clips") && !stristr($file, "~") && !( strpos($file, ".") === 0 ) && !strpos($file, ".old")) {
				$file_data = $wpdb->get_row("SELECT `id`,`filename` FROM `".WPSC_TABLE_PRODUCT_FILES."` WHERE `idhash` LIKE '".$wpdb->escape($file)."' LIMIT 1",ARRAY_A);
				if($file_data != null) {
					$dirlist[$num]['display_filename'] = $file_data['filename'];
					$dirlist[$num]['file_id'] = $file_data['id'];
				} else {
					$dirlist[$num]['display_filename'] = $file;
					$dirlist[$num]['file_id'] = null;
				}        
				$dirlist[$num]['real_filename'] = $file;
				$num++;
			}
		}
		if(count($dirlist) > 0) {
			$wpsc_uploaded_file_cache = $dirlist;
		}
	}
  return $dirlist;
  }
  
  
function wpsc_select_product_file($product_id = null) {
  global $wpdb;
  //return false;
  $product_id = absint($product_id);
  $file_list = wpsc_uploaded_files();
  $file_id = $wpdb->get_var("SELECT `file` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id` = '".$product_id."' LIMIT 1");
  
	//$product_files = $wpdb->get_row("SELECT `meta_value` FROM  `".WPSC_TABLE_PRODUCTMETA."` WHERE `product_id` = '".$product_id."' AND `meta_key` = 'product_files'", ARRAY_A);
	
	$product_files = get_product_meta($product_id, 'product_files');
  $output = "".__('Choose a downloadable file for this product:', 'wpsc')."
";
  $output .= "
\n\r"; $output .= " \n\r"; $output .= " \n\r"; $output .= "
\n\r"; foreach((array)$file_list as $file) { $num++; $output .= "\n\r"; $output .= " \n\r"; $output .= " \n\r"; $output .= "
\n\r"; } $output .= "