PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-shopping-cart/form_display_functions.php

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