PageRenderTime 23ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/wpsc-includes/form-display.functions.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 229 lines | 199 code | 22 blank | 8 comment | 51 complexity | fc5cb33acf08f22a0204f18f96f6fb5f 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=''>".__('Please select', 'wpsc')."</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'>".__('Select Parent', 'wpsc')."</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. $product_id = absint($product_id);
  120. $file_list = wpsc_uploaded_files();
  121. $file_id = $wpdb->get_var("SELECT `file` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id` = '".$product_id."' LIMIT 1");
  122. //$product_files = $wpdb->get_row("SELECT `meta_value` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `product_id` = '".$product_id."' AND `meta_key` = 'product_files'", ARRAY_A);
  123. $product_files = get_product_meta($product_id, 'product_files');
  124. $output = "<span class='admin_product_notes select_product_note '>".__('Choose a downloadable file for this product:', 'wpsc')."</span><br>";
  125. $output .= "<div class='ui-widget-content multiple-select ".((is_numeric($product_id)) ? "edit_" : "")."select_product_file'>";
  126. $num = 0;
  127. foreach((array)$file_list as $file) {
  128. $num++;
  129. if(is_array($product_files)){
  130. if (in_array($file['file_id'], $product_files)){
  131. $checked_curr_file="checked='checked'";
  132. }
  133. else{$checked_curr_file="";}
  134. }
  135. else{
  136. if(is_numeric($file_id) && ($file_id == $file['file_id'])){
  137. $checked_curr_file="checked='checked'";
  138. }
  139. else{$checked_curr_file="";}
  140. }
  141. $deletion_url = wp_nonce_url("admin.php?wpsc_admin_action=delete_file&amp;file_id=".$file['file_id'], 'delete_file_'.absint($file['file_id']));
  142. $output .= "<p ".((($num % 2) > 0) ? '' : "class='alt'").">\n";
  143. $output .= " <input type='checkbox' name='select_product_file[]' value='".$file['real_filename']."' id='select_product_file_$num' ".$checked_curr_file." />\n";
  144. $output .= " <label for='select_product_file_$num'>".$file['display_filename']."</label>\n";
  145. $output .= " <a class='file_delete_button' href='{$deletion_url}'>\n";
  146. $output .= " <img src='".WPSC_URL."/images/cross.png' />\n";
  147. $output .= " </a>\n";
  148. $output .= "</p>\n";
  149. }
  150. $output .= "</div>";
  151. $output .= "<div class='".((is_numeric($product_id)) ? "edit_" : "")."select_product_handle'><div></div></div>";
  152. $output .= "<script type='text/javascript'>\n\r";
  153. $output .= "var select_min_height = ".(25*3).";\n\r";
  154. $output .= "var select_max_height = ".(25*($num+1)).";\n\r";
  155. $output .= "</script>";
  156. return $output;
  157. }
  158. function wpsc_select_variation_file($file_id, $variation_ids, $variation_combination_id = null) {
  159. global $wpdb;
  160. //return false;
  161. $file_list = wpsc_uploaded_files();
  162. $unique_id_component = ((int)$variation_combination_id)."_".str_replace(",","_",$variation_ids);
  163. $output = "<div class='variation_settings_contents'>\n\r";
  164. $output .= "<span class='admin_product_notes select_product_note '>".__('Choose a downloadable file for this variation', 'wpsc')."</span>\n\r";
  165. $output .= "<div class='select_variation_file'>\n\r";
  166. $num = 0;
  167. $output .= " <p>\n\r";
  168. $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";
  169. $output .= " <label for='select_variation_file{$unique_id_component}_{$num}'>".__('No Product', 'wpsc')."</label>\n\r";
  170. $output .= " </p>\n\r";
  171. foreach((array)$file_list as $file) {
  172. $num++;
  173. $output .= " <p>\n\r";
  174. $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";
  175. $output .= " <label for='select_variation_file{$unique_id_component}_{$num}'>".$file['display_filename']."</label>\n\r";
  176. $output .= " </p>\n\r";
  177. }
  178. $output .= "</div>\n\r";
  179. $output .= "</div>\n\r";
  180. return $output;
  181. }
  182. function wpsc_list_product_themes($theme_name = null) {
  183. global $wpdb, $wpsc_theme_path;
  184. $selected_theme = get_option('wpsc_selected_theme');
  185. if($selected_theme == '') {
  186. $selected_theme = 'default';
  187. }
  188. $theme_path = $wpsc_theme_path;
  189. $theme_list = wpsc_list_dir($theme_path);
  190. foreach($theme_list as $theme_file) {
  191. if(is_dir($theme_path.$theme_file) && is_file($theme_path.$theme_file."/".$theme_file.".css")) {
  192. $theme[$theme_file] = get_theme_data($theme_path.$theme_file."/".$theme_file.".css");
  193. }
  194. }
  195. $output .= "<select name='wpsc_options[wpsc_selected_theme]'>\n\r";
  196. foreach((array)$theme as $theme_file=>$theme_data) {
  197. if(stristr($theme_file, $selected_theme)) {
  198. $selected = "selected='selected'";
  199. } else {
  200. $selected = "";
  201. }
  202. $output .= "<option value='$theme_file' $selected>".$theme_data['Name']."</option>\n\r";
  203. }
  204. $output .= "</select>\n\r";
  205. return $output;
  206. }
  207. ?>