PageRenderTime 43ms CodeModel.GetById 31ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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