PageRenderTime 66ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/3.7.5.1 Beta/wpsc-includes/form-display.functions.php

https://github.com/evadne/wp-e-commerce
PHP | 215 lines | 186 code | 20 blank | 9 comment | 49 complexity | ff9f47ad11e9b5eb9046d7d02bdde244 MD5 | raw file
  1. <?php
  2. function nzshpcrt_country_list($selected_country = null) {
  3. global $wpdb;
  4. $output = "<option value=''></option>";
  5. if($selected_country == null) {
  6. $output = "<option value=''>".TXT_WPSC_PLEASE_SELECT."</option>";
  7. }
  8. $country_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_CURRENCY_LIST."` ORDER BY `country` ASC",ARRAY_A);
  9. foreach ($country_data as $country) {
  10. $selected ='';
  11. if($selected_country == $country['isocode']) {
  12. $selected = "selected='true'";
  13. }
  14. $output .= "<option value='".$country['isocode']."' $selected>".$country['country']."</option>";
  15. }
  16. return $output;
  17. }
  18. function nzshpcrt_region_list($selected_country = null, $selected_region = null) {
  19. global $wpdb;
  20. if($selected_region == null) {
  21. $selected_region = get_option('base_region');
  22. }
  23. $output = "";
  24. $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) ;
  25. if($region_list != null) {
  26. $output .= "<select name='base_region'>\n\r";
  27. $output .= "<option value=''>None</option>";
  28. foreach($region_list as $region) {
  29. if($selected_region == $region['id']) {
  30. $selected = "selected='true'";
  31. } else {
  32. $selected = "";
  33. }
  34. $output .= "<option value='".$region['id']."' $selected>".$region['name']."</option>\n\r";
  35. }
  36. $output .= "</select>\n\r";
  37. } else {
  38. $output .= "<select name='base_region' disabled='true'><option value=''>None</option></select>\n\r";
  39. }
  40. return $output;
  41. }
  42. function nzshpcrt_form_field_list($selected_field = null)
  43. {
  44. global $wpdb;
  45. $output = "";
  46. $output .= "<option value=''>Please choose</option>";
  47. $form_sql = "SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1';";
  48. $form_data = $wpdb->get_results($form_sql,ARRAY_A);
  49. foreach ((array)$form_data as $form) {
  50. $selected ='';
  51. if($selected_field == $form['id']) {
  52. $selected = "selected='true'";
  53. }
  54. $output .= "<option value='".$form['id']."' $selected>".$form['name']."</option>";
  55. }
  56. return $output;
  57. }
  58. function wpsc_parent_category_list($group_id, $category_id, $category_parent_id) {
  59. global $wpdb,$category_data;
  60. $options = "";
  61. $options .= "<option value='0'>".TXT_WPSC_SELECT_PARENT."</option>\r\n";
  62. $options .= wpsc_category_options((int)$group_id, (int)$category_id, null, 0, (int)$category_parent_id);
  63. $concat .= "<select name='category_parent'>".$options."</select>\r\n";
  64. return $concat;
  65. }
  66. function wpsc_category_options($group_id, $this_category = null, $category_id = null, $iteration = 0, $selected_id = null) {
  67. /*
  68. * Displays the category forms for adding and editing products
  69. * Recurses to generate the branched view for subcategories
  70. */
  71. global $wpdb;
  72. $siteurl = get_option('siteurl');
  73. if(is_numeric($category_id)) {
  74. $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);
  75. } else {
  76. $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);
  77. }
  78. foreach((array)$values as $option) {
  79. if($selected_id == $option['id']) {
  80. $selected = "selected='selected'";
  81. }
  82. $output .= "<option $selected value='".$option['id']."'>".str_repeat("-", $iteration).stripslashes($option['name'])."</option>\r\n";
  83. $output .= wpsc_category_options($group_id, $this_category, $option['id'], $iteration+1, $selected_id);
  84. $selected = "";
  85. }
  86. return $output;
  87. }
  88. function wpsc_uploaded_files() {
  89. global $wpdb, $wpsc_uploaded_file_cache;
  90. $dir = @opendir(WPSC_FILE_DIR);
  91. $num = 0;
  92. if(count($wpsc_uploaded_file_cache) > 0) {
  93. $dirlist = $wpsc_uploaded_file_cache;
  94. } else {
  95. while(($file = @readdir($dir)) !== false) {
  96. //filter out the dots, macintosh hidden files and any backup files
  97. if(($file != "..") && ($file != ".") && ($file != "product_files") && ($file != "preview_clips") && !stristr($file, "~") && !( strpos($file, ".") === 0 ) && !strpos($file, ".old")) {
  98. $file_data = $wpdb->get_row("SELECT `id`,`filename` FROM `".WPSC_TABLE_PRODUCT_FILES."` WHERE `idhash` LIKE '".$wpdb->escape($file)."' LIMIT 1",ARRAY_A);
  99. if($file_data != null) {
  100. $dirlist[$num]['display_filename'] = $file_data['filename'];
  101. $dirlist[$num]['file_id'] = $file_data['id'];
  102. } else {
  103. $dirlist[$num]['display_filename'] = $file;
  104. $dirlist[$num]['file_id'] = null;
  105. }
  106. $dirlist[$num]['real_filename'] = $file;
  107. $num++;
  108. }
  109. }
  110. if(count($dirlist) > 0) {
  111. $wpsc_uploaded_file_cache = $dirlist;
  112. }
  113. }
  114. return $dirlist;
  115. }
  116. function wpsc_select_product_file($product_id = null) {
  117. global $wpdb;
  118. //return false;
  119. $file_list = wpsc_uploaded_files();
  120. $file_id = $wpdb->get_var("SELECT `file` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id` = '".$product_id."' LIMIT 1");
  121. $output = "<span class='admin_product_notes select_product_note '>".TXT_WPSC_CHOOSE_DOWNLOADABLE_PRODUCT."</span><br>";
  122. //$output .= "<pre>".print_r($file_list,true)."</pre>";
  123. $output .= "<div class='ui-widget-content multiple-select ".((is_numeric($product_id)) ? "edit_" : "")."select_product_file'>";
  124. //$output .= "<div class='select_product_file'>";
  125. $num = 0;
  126. $output .= "<p ".((($num % 2) > 0) ? '' : "class='alt'")."><input type='radio' name='select_product_file' value='.none.' id='select_product_file_$num' ".((!is_numeric($file_id) || ($file_id < 1)) ? "checked='checked'" : "")." /><label for='select_product_file_$num'>".TXT_WPSC_SHOW_NO_PRODUCT."</label></p>";
  127. foreach((array)$file_list as $file) {
  128. $num++;
  129. $deletion_url = wp_nonce_url("admin.php?wpsc_admin_action=delete_file&amp;file_id=".$file['file_id'], 'delete_file_'.absint($file['file_id']));
  130. $output .= "<p ".((($num % 2) > 0) ? '' : "class='alt'").">\n";
  131. $output .= " <input type='radio' name='select_product_file' value='".$file['real_filename']."' id='select_product_file_$num' ".((is_numeric($file_id) && ($file_id == $file['file_id'])) ? "checked='checked'" : "")." />\n";
  132. $output .= " <label for='select_product_file_$num'>".$file['display_filename']."</label>\n";
  133. $output .= " <a class='file_delete_button' href='{$deletion_url}'>\n";
  134. $output .= " <img src='".WPSC_URL."/images/cross.png' />\n";
  135. $output .= " </a>\n";
  136. $output .= "</p>\n";
  137. }
  138. $output .= "</div>";
  139. $output .= "<div class='".((is_numeric($product_id)) ? "edit_" : "")."select_product_handle'><div></div></div>";
  140. $output .= "<script type='text/javascript'>\n\r";
  141. $output .= "var select_min_height = ".(25*3).";\n\r";
  142. $output .= "var select_max_height = ".(25*($num+1)).";\n\r";
  143. $output .= "</script>";
  144. return $output;
  145. }
  146. function wpsc_select_variation_file($file_id, $variation_ids, $variation_combination_id = null) {
  147. global $wpdb;
  148. //return false;
  149. $file_list = wpsc_uploaded_files();
  150. $unique_id_component = ((int)$variation_combination_id)."_".str_replace(",","_",$variation_ids);
  151. $output = "<div class='variation_settings_contents'>\n\r";
  152. $output .= "<span class='admin_product_notes select_product_note '>".TXT_WPSC_CHOOSE_DOWNLOADABLE_VARIATIONS."</span>\n\r";
  153. $output .= "<div class='select_variation_file'>\n\r";
  154. $num = 0;
  155. $output .= " <p>\n\r";
  156. $output .= " <input type='radio' name='variation_priceandstock[{$variation_ids}][file]' value='0' id='select_variation_file{$unique_id_component}_{$num}' ".((!is_numeric($file_id) || ($file_id < 1)) ? "checked='checked'" : "")." />\n\r";
  157. $output .= " <label for='select_variation_file{$unique_id_component}_{$num}'>".TXT_WPSC_SHOW_NO_PRODUCT."</label>\n\r";
  158. $output .= " </p>\n\r";
  159. foreach((array)$file_list as $file) {
  160. $num++;
  161. $output .= " <p>\n\r";
  162. $output .= " <input type='radio' name='variation_priceandstock[{$variation_ids}][file]' value='".$file['file_id']."' id='select_variation_file{$unique_id_component}_{$num}' ".((is_numeric($file_id) && ($file_id == $file['file_id'])) ? "checked='checked'" : "")." />\n\r";
  163. $output .= " <label for='select_variation_file{$unique_id_component}_{$num}'>".$file['display_filename']."</label>\n\r";
  164. $output .= " </p>\n\r";
  165. }
  166. $output .= "</div>\n\r";
  167. $output .= "</div>\n\r";
  168. return $output;
  169. }
  170. function wpsc_list_product_themes($theme_name = null) {
  171. global $wpdb, $wpsc_theme_path;
  172. $selected_theme = get_option('wpsc_selected_theme');
  173. if($selected_theme == '') {
  174. $selected_theme = 'default';
  175. }
  176. $theme_path = $wpsc_theme_path;
  177. $theme_list = wpsc_list_dir($theme_path);
  178. foreach($theme_list as $theme_file) {
  179. if(is_dir($theme_path.$theme_file) && is_file($theme_path.$theme_file."/".$theme_file.".css")) {
  180. $theme[$theme_file] = get_theme_data($theme_path.$theme_file."/".$theme_file.".css");
  181. }
  182. }
  183. $output .= "<select name='wpsc_options[wpsc_selected_theme]'>\n\r";
  184. foreach((array)$theme as $theme_file=>$theme_data) {
  185. if(stristr($theme_file, $selected_theme)) {
  186. $selected = "selected='selected'";
  187. } else {
  188. $selected = "";
  189. }
  190. $output .= "<option value='$theme_file' $selected>".$theme_data['Name']."</option>\n\r";
  191. }
  192. $output .= "</select>\n\r";
  193. return $output;
  194. }
  195. ?>