WC_Compare_Fields_Class

WooCommerce Compare Fields.

Defined (1)

The class is defined in the following location(s).

/admin/classes/class-wc-compare-fields.php  
  1. class WC_Compare_Fields_Class  
  2. public static $default_types = array( 
  3. 'input-text' => array('name' => 'Input Text', 'description' => 'Use when option is single Line of Text'),  
  4. 'text-area' => array('name' => 'Text Area', 'description' => 'When option is Multiple lines of Text'),  
  5. 'checkbox' => array('name' => 'Check Box', 'description' => 'Options in a row allows multiple select'),  
  6. 'radio' => array('name' => 'Radio button', 'description' => 'Like check box but only single select'),  
  7. 'drop-down' => array('name' => 'Drop Down', 'description' => 'Options in dropdown, only select one'),  
  8. 'multi-select' => array('name' => 'Multi Select', 'description' => 'Like Drop Down but mutiple select'),  
  9. 'wp-video' => array('name' => 'Video Player', 'description' => 'Text Field to add Video URL'),  
  10. 'wp-audio' => array('name' => 'Audio Player', 'description' => 'Text Field to add Audio URL'),  
  11. ); 
  12.  
  13. public static function init_features_actions() { 
  14. $result_msg = ''; 
  15.  
  16. if (isset($_REQUEST['bt_save_field'])) { 
  17. $field_name = trim(strip_tags(addslashes($_REQUEST['field_name']))); 
  18. if (isset($_REQUEST['field_id']) && $_REQUEST['field_id'] > 0) { 
  19. $field_id = trim($_REQUEST['field_id']); 
  20. $count_field_name = WC_Compare_Data::get_count("field_name = '".$field_name."' AND id != '".$field_id."'"); 
  21. if ($field_name != '' && $count_field_name == 0) { 
  22. $result = WC_Compare_Data::update_row($_REQUEST); 
  23. if (isset($_REQUEST['field_cats']) && count((array)$_REQUEST['field_cats']) > 0) { 
  24. foreach ($_REQUEST['field_cats'] as $cat_id) { 
  25. $check_existed = WC_Compare_Categories_Fields_Data::get_count("cat_id='".$cat_id."' AND field_id='".$field_id."'"); 
  26. if ($check_existed == 0) { 
  27. WC_Compare_Categories_Fields_Data::insert_row($cat_id, $field_id); 
  28. WC_Compare_Categories_Fields_Data::delete_row("field_id='".$field_id."' AND cat_id NOT IN(".implode(', ', $_REQUEST['field_cats']).")"); 
  29. }else { 
  30. WC_Compare_Categories_Fields_Data::delete_row("field_id='".$field_id."'"); 
  31. $result_msg = '<div class="updated" id="result_msg"><p>'.__('Compare Feature Successfully edited', 'woocommerce-compare-products' ).'.</p></div>'; 
  32. }else { 
  33. $result_msg = '<div class="error" id="result_msg"><p>'.__('Nothing edited! You already have a Compare Feature with that name. Use the Features Search function to find it. Use unique names to edit each Compare Feature.', 'woocommerce-compare-products' ).'</p></div>'; 
  34. }else { 
  35. $count_field_name = WC_Compare_Data::get_count("field_name = '".$field_name."'"); 
  36. if ($field_name != '' && $count_field_name == 0) { 
  37. $field_id = WC_Compare_Data::insert_row($_REQUEST); 
  38. if ($field_id > 0) { 
  39. WC_Compare_Categories_Fields_Data::delete_row("field_id='".$field_id."'"); 
  40. if (isset($_REQUEST['field_cats']) && count((array)$_REQUEST['field_cats']) > 0) { 
  41. foreach ($_REQUEST['field_cats'] as $cat_id) { 
  42. WC_Compare_Categories_Fields_Data::insert_row($cat_id, $field_id); 
  43. $result_msg = '<div class="updated" id="result_msg"><p>'.__('Compare Feature Successfully created', 'woocommerce-compare-products' ).'.</p></div>'; 
  44. }else { 
  45. $result_msg = '<div class="error" id="result_msg"><p>'.__('Compare Feature Error created', 'woocommerce-compare-products' ).'.</p></div>'; 
  46.  
  47. }else { 
  48. $result_msg = '<div class="error" id="result_msg"><p>'.__('Nothing created! You already have a Compare Feature with that name. Use the Features Search function to find it. Use unique names to create each Compare Feature.', 'woocommerce-compare-products' ).'</p></div>'; 
  49. }elseif (isset($_REQUEST['bt_delete'])) { 
  50. $list_fields_delete = $_REQUEST['un_fields']; 
  51. if (is_array($list_fields_delete) && count($list_fields_delete) > 0) { 
  52. foreach ($list_fields_delete as $field_id) { 
  53. WC_Compare_Data::delete_row($field_id); 
  54. WC_Compare_Categories_Fields_Data::delete_row("field_id='".$field_id."'"); 
  55. $result_msg = '<div class="updated" id="result_msg"><p>'.__('Compare Feature successfully deleted', 'woocommerce-compare-products' ).'.</p></div>'; 
  56. }else { 
  57. $result_msg = '<div class="updated" id="result_msg"><p>'.__('Please select item(s) to delete', 'woocommerce-compare-products' ).'.</p></div>'; 
  58.  
  59. if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'field-delete') { 
  60. $field_id = trim($_REQUEST['field_id']); 
  61. if (isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] > 0) { 
  62. WC_Compare_Categories_Fields_Data::delete_row("field_id='".$field_id."' AND cat_id='".$_REQUEST['cat_id']."'"); 
  63. $result_msg = '<div class="updated" id="result_msg"><p>'.__('Compare Feature successfully removed', 'woocommerce-compare-products' ).'.</p></div>'; 
  64. }else { 
  65. WC_Compare_Data::delete_row($field_id); 
  66. WC_Compare_Categories_Fields_Data::delete_row("field_id='".$field_id."'"); 
  67. $result_msg = '<div class="updated" id="result_msg"><p>'.__('Compare Feature successfully deleted', 'woocommerce-compare-products' ).'.</p></div>'; 
  68.  
  69. return $result_msg; 
  70.  
  71. public static function woocp_features_manager() { 
  72. global $wpdb; 
  73. ?> 
  74. <h3 id="add_feature"><?php if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'field-edit') { _e('Edit Compare Product Features', 'woocommerce-compare-products' ); }else { _e('Add Compare Product Features', 'woocommerce-compare-products' ); }?></h3> 
  75. <form action="admin.php?page=woo-compare-features" method="post" name="form_add_compare" id="form_add_compare"> 
  76. <?php 
  77. if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'field-edit') { 
  78. $field_id = $_REQUEST['field_id']; 
  79. $field = WC_Compare_Data::get_row($field_id); 
  80. ?> 
  81. <input type="hidden" value="<?php echo $field_id; ?>" name="field_id" id="field_id" /> 
  82. <?php 
  83. }else { 
  84. $field_id = 0; 
  85. $have_value = false; 
  86. ?> 
  87. <table cellspacing="0" class="widefat post fixed"> 
  88. <thead> 
  89. <tr><th class="manage-column" scope="col"><?php if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'field-edit') { _e('Edit Compare Features', 'woocommerce-compare-products' ); }else { _e('Create New Compare Features', 'woocommerce-compare-products' ); } ?></th></tr> 
  90. </thead> 
  91. <tbody> 
  92. <tr> 
  93. <td> 
  94. <table cellspacing="0" class="form-table"> 
  95. <tr> 
  96. <th><div class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e('This is the Feature Name that users see in the Compare Fly-Out Window, for example- System Height', 'woocommerce-compare-products' ) ?>"></div> <label for="field_name"><?php _e('Feature Name', 'woocommerce-compare-products' ); ?></label></th> 
  97. <td><input type="text" name="field_name" id="field_name" value="<?php if (!empty($field)) echo stripslashes($field->field_name); ?>" style="width:300px" /></td> 
  98. </tr> 
  99. <tr> 
  100. <th><div class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("e.g kgs, mm, lbs, cm, inches - the unit of measurement shows after the Feature name in (brackets). If you leave this blank you will just see the Feature name.", 'woocommerce-compare-products' ) ?>"></div> <label for="field_unit"><?php _e('Feature Unit of Measurement', 'woocommerce-compare-products' ); ?></label></th> 
  101. <td><input type="text" name="field_unit" id="field_unit" value="<?php if (!empty($field)) echo stripslashes($field->field_unit); ?>" style="width:300px" /></td> 
  102. </tr> 
  103. <tr> 
  104. <th><div class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("Users don't see this. Use to set the data input field type that you will use on to enter the Products data for this feature.", 'woocommerce-compare-products' ) ?>"></div> <label for="field_type"><?php _e('Feature Input Type', 'woocommerce-compare-products' ); ?></label></th> 
  105. <td> 
  106. <select style="width:300px;" name="field_type" id="field_type" class="chzn-select"> 
  107. <?php 
  108. foreach (WC_Compare_Fields_Class::$default_types as $type => $type_name) { 
  109. if ( in_array( $type, array( 'wp-video', 'wp-audio' ) ) ) { 
  110. echo '<option value="'.$type.'" >'.$type_name['name'].' - '.$type_name['description'].'</option>'; 
  111. } elseif (!empty($field) && $type == $field->field_type) { 
  112. echo '<option value="'.$type.'" selected="selected">'.$type_name['name'].' - '.$type_name['description'].'</option>'; 
  113. } else { 
  114. echo '<option value="'.$type.'">'.$type_name['name'].' - '.$type_name['description'].'</option>'; 
  115. if (!empty($field) && in_array($field->field_type, array('checkbox' , 'radio', 'drop-down', 'multi-select'))) { 
  116. $have_value = true; 
  117. ?> 
  118. </select> 
  119. </td> 
  120. </tr> 
  121. <tr id="field_value" <?php if (!$have_value) { echo 'style="display:none"';} ?>> 
  122. <th><div class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("You have selected one of the Check Box, Radio Button, Drop Down, Mutli Select Input Types. Type your Options here, one line for each option.", 'woocommerce-compare-products' ) ?>"></div> <label for="default_value"><?php _e('Enter Input Type options', 'woocommerce-compare-products' ); ?></label></th> 
  123. <td><textarea style="width:300px;height:100px;" name="default_value" id="default_value"><?php if (!empty($field)) echo stripslashes($field->default_value); ?></textarea></td> 
  124. </tr> 
  125. <tr> 
  126. <th><div class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("Assign features to one or more Categories. Features such as Colour, Size, Weight can be applicable to many Product categories. Create the Feature once and assign it to one or multiple categories.", 'woocommerce-compare-products' ) ?>"></div> <label for="field_type"><?php _e('Assign Feature to Categories', 'woocommerce-compare-products' ); ?></label></th> 
  127. <td> 
  128. <?php 
  129. $all_cat = WC_Compare_Categories_Data::get_results('', 'category_order ASC'); 
  130. $cat_fields = WC_Compare_Categories_Fields_Data::get_catid_results($field_id); 
  131. if (is_array($all_cat) && count($all_cat) > 0) { 
  132. ?> 
  133. <select multiple="multiple" name="field_cats[]" data-placeholder="<?php _e('Select Compare Categories', 'woocommerce-compare-products' ); ?>" style="width:300px; height:80px;" class="chzn-select"> 
  134. <?php 
  135. foreach ($all_cat as $cat) { 
  136. if (in_array($cat->id, (array)$cat_fields)) { 
  137. ?> 
  138. <option value="<?php echo $cat->id; ?>" selected="selected"><?php echo stripslashes($cat->category_name); ?></option> 
  139. <?php 
  140. } else { 
  141. ?> 
  142. <option value="<?php echo $cat->id; ?>"><?php echo stripslashes($cat->category_name); ?></option> 
  143. <?php  
  144. ?> 
  145. </select> 
  146. <?php  
  147. ?> 
  148. </td> 
  149. </tr> 
  150. </table> 
  151. </td> 
  152. </tr> 
  153. </tbody> 
  154. </table> 
  155. <p class="submit"> 
  156. <input type="submit" name="bt_save_field" id="bt_save_field" class="button button-primary" value="<?php if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'field-edit') { _e('Save', 'woocommerce-compare-products' ); }else { _e('Create', 'woocommerce-compare-products' ); } ?>" />  
  157. <input type="button" class="button" onclick="window.location='admin.php?page=woo-compare-features'" value="<?php _e('Cancel', 'woocommerce-compare-products' ); ?>" /> 
  158. </p> 
  159. </form> 
  160. <script> 
  161. (function($) { 
  162. $(document).ready(function() { 
  163. var old_type_selected = $("select#field_type").val(); 
  164. $("select#field_type").on( 'change', function() { 
  165. var field_type = $(this).val(); 
  166. if ( field_type == 'wp-video' || field_type == 'wp-audio' ) { 
  167. alert('<?php _e( 'This Type just is enabled on PRO version.', 'woocommerce-compare-products' ); ?>'); 
  168. $(this).val( old_type_selected ); 
  169. if(old_type_selected == 'checkbox' || old_type_selected == 'radio' || old_type_selected == 'drop-down' || old_type_selected == 'multi-select') { 
  170. $("#field_value").show(); 
  171. }else{ 
  172. $("#field_value").hide(); 
  173. $("select#field_type").trigger("chosen:updated"); 
  174. }); 
  175. }); 
  176. })(jQuery); 
  177. </script> 
  178. <div style="clear:both"></div> 
  179. <?php 
  180.  
  181. public static function woocp_features_orders() { 
  182. $unavaliable_fields = WC_Compare_Categories_Fields_Data::get_unavaliable_field_results('field_name ASC'); 
  183. if (is_array($unavaliable_fields) && count($unavaliable_fields) > 0) { 
  184. $un_i = 0; 
  185. ?> 
  186.  
  187. <h3 id="#un_assigned"><?php _e('Un-Assigned Features (Assign to a Category to activate)', 'woocommerce-compare-products' ); ?></h3> 
  188. <form action="admin.php?page=woo-compare-features" method="post" name="form_delete_fields" id="form_delete_fields" style="margin-bottom:30px;"> 
  189. <table cellspacing="0" class="widefat post fixed" style="width:535px;"> 
  190. <thead> 
  191. <tr> 
  192. <th width="25" class="manage-column" scope="col" style="white-space: nowrap;"><input id="toggle1" class="toggle" type="checkbox" style="margin:0;" /></th> 
  193. <th width="30" class="manage-column" scope="col" style="white-space: nowrap;"><?php _e('No', 'woocommerce-compare-products' ); ?></th> 
  194. <th class="manage-column" scope="col"><?php _e('Feature Name', 'woocommerce-compare-products' ); ?></th> 
  195. <th width="90" class="manage-column" scope="col" style="text-align:right"><?php _e('Type', 'woocommerce-compare-products' ); ?></th> 
  196. <th width="100" class="manage-column" scope="col" style="text-align:right"></th> 
  197. </tr> 
  198. </thead> 
  199. <tbody> 
  200. <?php 
  201. foreach ($unavaliable_fields as $field_data) { 
  202. $un_i++; 
  203. ?> 
  204. <tr> 
  205. <td><input class="list_fields" type="checkbox" name="un_fields[]" value="<?php echo $field_data->id; ?>" /></td> 
  206. <td><?php echo $un_i; ?></td> 
  207. <td><?php echo stripslashes($field_data->field_name); ?></td> 
  208. <td align="right"><?php echo WC_Compare_Fields_Class::$default_types[$field_data->field_type]['name']; ?></td> 
  209. <td align="right"><a href="admin.php?page=woo-compare-features&act=field-edit&field_id=<?php echo $field_data->id; ?>" class="c_field_edit" title="<?php _e('Edit', 'woocommerce-compare-products' ) ?>" ><?php _e('Edit', 'woocommerce-compare-products' ) ?></a> | <a href="admin.php?page=woo-compare-features&act=field-delete&field_id=<?php echo $field_data->id; ?>" class="c_field_delete" onclick="javascript:return confirmation('<?php _e('Are you sure you want to delete', 'woocommerce-compare-products' ) ; ?> #<?php echo htmlspecialchars($field_data->field_name); ?>');" title="<?php _e('Delete', 'woocommerce-compare-products' ) ?>" ><?php _e('Delete', 'woocommerce-compare-products' ) ?></a></td> 
  210. </tr> 
  211. <?php } ?> 
  212. </tbody> 
  213. </table> 
  214. <div style="margin-top:10px;"><input type="submit" name="bt_delete" id="bt_delete" class="button button-primary" value="<?php _e('Delete', 'woocommerce-compare-products' ) ; ?>" onclick="if (confirm('<?php _e('Are you sure about deleting this?', 'woocommerce-compare-products' ) ; ?>')) return true; else return false" /></div> 
  215. </form> 
  216. <?php 
  217.  
  218. $compare_cats = WC_Compare_Categories_Data::get_results('', 'category_order ASC'); 
  219. if (is_array($compare_cats) && count($compare_cats)>0) { 
  220. ?> 
  221. <h3><?php _e('Manage Compare Categories and Features', 'woocommerce-compare-products' ); ?></h3> 
  222. <p><?php _e('Use drag and drop to change Category order and Feature order within Categories.', 'woocommerce-compare-products' ) ?></p> 
  223. <div class="updated below-h2 update_feature_order_message" style="display:none"><p></p></div> 
  224. <div style="clear:both"></div> 
  225. <ul style="margin:0; padding:0;" class="sorttable"> 
  226. <?php 
  227. foreach ($compare_cats as $cat) { 
  228. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$cat->id."'", 'cf.field_order ASC'); 
  229. ?> 
  230. <li id="recordsArray_<?php echo $cat->id; ?>"> 
  231. <input type="hidden" name="compare_orders_<?php echo $cat->id; ?>" class="compare_category_id" value="<?php echo $cat->id; ?>" /> 
  232. <table cellspacing="0" class="widefat post fixed sorttable" id="compare_orders_<?php echo $cat->id; ?>" style="width:535px; margin-bottom:20px;"> 
  233. <thead> 
  234. <tr> 
  235. <th width="25" style="white-space: nowrap;"><span class="c_field_name"> </span></th> 
  236. <th><strong><?php echo stripslashes($cat->category_name) ;?></strong> :</th> 
  237. <th width="90"></th> 
  238. <th width="100" style="text-align:right; font-size:12px;white-space: nowrap;"><a href="admin.php?page=woo-compare-features&act=cat-edit&category_id=<?php echo $cat->id; ?>" class="c_field_edit" title="<?php _e('Edit', 'woocommerce-compare-products' ) ?>"><?php _e('Edit', 'woocommerce-compare-products' ) ?></a> | <a href="admin.php?page=woo-compare-features&act=cat-delete&category_id=<?php echo $cat->id; ?>" title="<?php _e('Delete', 'woocommerce-compare-products' ) ?>" class="c_field_delete" onclick="javascript:return confirmation('<?php _e('Are you sure you want to delete', 'woocommerce-compare-products' ) ; ?> #<?php echo htmlspecialchars($cat->category_name); ?>');"><?php _e('Delete', 'woocommerce-compare-products' ) ?></a><?php if (is_array($compare_fields) && count($compare_fields)>0) { ?> | <span class="c_openclose_table c_close_table" id="expand_<?php echo $cat->id; ?>"> </span><?php }else {?> | <span class="c_openclose_none"> </span><?php }?></th> 
  239. </tr> 
  240. </thead> 
  241. <tbody class="expand_<?php echo $cat->id; ?>"> 
  242. <?php 
  243. if (is_array($compare_fields) && count($compare_fields)>0) { 
  244. $i= 0; 
  245. foreach ($compare_fields as $field_data) { 
  246. $i++; 
  247. ?> 
  248. <tr id="recordsArray_<?php echo $field_data->id; ?>" style="display:none"> 
  249. <td><span class="compare_sort"><?php echo $i; ?></span>.</td> 
  250. <td><div class="c_field_name"><?php echo stripslashes($field_data->field_name); ?></div></td> 
  251. <td align="right"><?php echo WC_Compare_Fields_Class::$default_types[$field_data->field_type]['name']; ?></td> 
  252. <td align="right"><a href="admin.php?page=woo-compare-features&act=field-edit&field_id=<?php echo $field_data->id; ?>" class="c_field_edit" title="<?php _e('Edit', 'woocommerce-compare-products' ) ?>" ><?php _e('Edit', 'woocommerce-compare-products' ) ?></a> | <a href="admin.php?page=woo-compare-features&act=field-delete&field_id=<?php echo $field_data->id; ?>&cat_id=<?php echo $cat->id; ?>" class="c_field_delete" onclick="javascript:return confirmation('<?php _e('Are you sure you want to remove', 'woocommerce-compare-products' ) ; ?> #<?php echo htmlspecialchars($field_data->field_name); ?> <?php _e('from', 'woocommerce-compare-products' ) ; ?> #<?php echo htmlspecialchars($cat->category_name); ?>');" title="<?php _e('Remove', 'woocommerce-compare-products' ) ?>" ><?php _e('Remove', 'woocommerce-compare-products' ) ?></a></td> 
  253. </tr> 
  254. <?php 
  255. }else { 
  256. echo '<tr><td colspan="4">'.__('You have not assigned any Features to this category yet. No Hurry!', 'woocommerce-compare-products' ).'</td></tr>'; 
  257. ?> 
  258. </tbody> 
  259. </table> 
  260. </li> 
  261. <?php 
  262. ?> 
  263. </ul> 
  264. <?php wp_enqueue_script('jquery-ui-sortable'); ?> 
  265. <?php $woocp_update_order = wp_create_nonce("woocp-update-order"); ?> 
  266. <?php $woocp_update_cat_order = wp_create_nonce("woocp-update-cat-order"); ?> 
  267. <script type="text/javascript"> 
  268. (function($) { 
  269. $(function() { 
  270. $(".c_openclose_table").click( function() { 
  271. if ( $(this).hasClass('c_close_table') ) { 
  272. $(this).removeClass("c_close_table"); 
  273. $(this).addClass("c_open_table"); 
  274. $("tbody."+$(this).attr('id')+" tr").css('display', ''); 
  275. } else { 
  276. $(this).removeClass("c_open_table"); 
  277. $(this).addClass("c_close_table"); 
  278. $("tbody."+$(this).attr('id')+" tr").css('display', 'none'); 
  279. }); 
  280.  
  281. var fixHelper = function(e, ui) { 
  282. ui.children().each(function() { 
  283. $(this).width($(this).width()); 
  284. }); 
  285. return ui; 
  286. }; 
  287.  
  288. $(".sorttable tbody").sortable({ helper: fixHelper, placeholder: "ui-state-highlight", opacity: 0.8, cursor: 'move', update: function() { 
  289. var cat_id = $(this).parent('table').siblings(".compare_category_id").val(); 
  290. var order = $(this).sortable("serialize") + '&action=woocp_update_orders&security=<?php echo $woocp_update_order; ?>&cat_id='+cat_id; 
  291. $.post("<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>", order, function(theResponse) { 
  292. $(".update_feature_order_message p").html(theResponse); 
  293. $(".update_feature_order_message").show(); 
  294. $("#compare_orders_"+cat_id).find(".compare_sort").each(function(index) { 
  295. $(this).html(index+1); 
  296. }); 
  297. }); 
  298. }); 
  299.  
  300. $("ul.sorttable").sortable({ placeholder: "ui-state-highlight", opacity: 0.8, cursor: 'move', update: function() { 
  301. var order = $(this).sortable("serialize") + '&action=woocp_update_cat_orders&security=<?php echo $woocp_update_cat_order; ?>'; 
  302. $.post("<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>", order, function(theResponse) { 
  303. $(".update_feature_order_message p").html(theResponse).show(); 
  304. $(".update_feature_order_message").show(); 
  305. }); 
  306. }); 
  307. }); 
  308. })(jQuery); 
  309. </script> 
  310. <?php 
  311.  
  312. public static function woocp_update_orders() { 
  313. check_ajax_referer( 'woocp-update-order', 'security' ); 
  314. $updateRecordsArray = $_REQUEST['recordsArray']; 
  315. $cat_id = $_REQUEST['cat_id']; 
  316. $listingCounter = 1; 
  317. foreach ($updateRecordsArray as $recordIDValue) { 
  318. WC_Compare_Categories_Fields_Data::update_order($cat_id, $recordIDValue, $listingCounter); 
  319. $listingCounter++; 
  320.  
  321. _e('You just save the order for Compare Features.', 'woocommerce-compare-products' ); 
  322. die(); 
  323.  
  324. public static function features_search_area() { 
  325. global $wpdb; 
  326. ?> 
  327. <div class="icon32 icon32-compare-product" id="icon32-compare-product"><br></div> 
  328. <h1><?php _e('Categories & Features', 'woocommerce-compare-products' ); ?> <a href="admin.php?page=woo-compare-features&act=add-new" class="add-new-h2"><?php _e('Add New', 'woocommerce-compare-products' ); ?></a></h1> 
  329. <div style="clear:both;height:12px"></div> 
  330. <form method="get" action="admin.php?page=woo-compare-features" name="compare_search_features"> 
  331. <input type="hidden" name="page" value="woo-compare-features" /> 
  332. <input type="hidden" name="tab" value="features" /> 
  333. <?php 
  334. $s_feature = ''; 
  335. if (isset($_REQUEST['s_feature']) && trim($_REQUEST['s_feature']) != '') $s_feature = trim(stripslashes($_REQUEST['s_feature']));  
  336. ?> 
  337. <table class="form-table" style="width:535px;"> 
  338. <tbody> 
  339. <tr valign="top"> 
  340. <th class="titledesc" scope="rpw" style="padding-left:0;"><input type="text" name="s_feature" id="s_feature" value="<?php echo $s_feature; ?>" style="min-width:300px" /></th> 
  341. <td class="forminp search_features_td" style="padding-right:0; text-align:right;"><input type="submit" id="search_features" name="" value="<?php _e('Search Features', 'woocommerce-compare-products' ); ?>" class="button"></td> 
  342. </tr> 
  343. </tbody> 
  344. </table> 
  345. <?php 
  346. if (isset($_REQUEST['s_feature'])) { 
  347. $p = 1; 
  348. $rows = 25; 
  349. if (isset($_REQUEST['pp'])) $p = $_REQUEST['pp']; 
  350. if (isset($_REQUEST['rows'])) $rows = $_REQUEST['rows']; 
  351. $start = ($p - 1 ) * $rows; 
  352. $end = $start+$rows; 
  353. $div = 5; 
  354. $keyword = trim(stripslashes($_REQUEST['s_feature'])); 
  355.  
  356. // fixed for 4.1.2 
  357. $link = esc_url( add_query_arg(array('pp' => '', 'rows' => $rows, 's_feature' => $keyword ) ) ); 
  358.  
  359. $character = 'latin1'; 
  360. if ( $wpdb->has_cap( 'collation' ) )  
  361. if( ! empty($wpdb->charset ) ) $character = "$wpdb->charset"; 
  362.  
  363. $where = "LOWER( CONVERT( field_name USING ".$character.") ) LIKE '%".strtolower(trim($_REQUEST['s_feature']))."%'"; 
  364.  
  365. $total = WC_Compare_Data::get_count($where); 
  366. if ($end > $total) $end = $total; 
  367. $items = WC_Compare_Data::get_results($where, 'field_name ASC', $start.', '.$rows); 
  368.  
  369. $innerPage = WC_Compare_Functions::printPage($link, $total, $p, $div, $rows, false); 
  370.  
  371. ?> 
  372. <h3><?php _e('Found', 'woocommerce-compare-products' ); ?> <?php echo $total; ?> <?php _e('feature(s)', 'woocommerce-compare-products' ); ?></h3> 
  373. <?php 
  374. if ($total > 0) { 
  375. ?> 
  376. <table cellspacing="0" class="widefat post fixed" style="width:535px;"> 
  377. <thead> 
  378. <tr> 
  379. <th class="manage-column" scope="col"><?php _e('Feature Name', 'woocommerce-compare-products' ); ?></th> 
  380. <th width="90" class="manage-column" scope="col" style="text-align:right"><?php _e('Type', 'woocommerce-compare-products' ); ?></th> 
  381. <th width="100" class="manage-column" scope="col" style="text-align:right"></th> 
  382. </tr> 
  383. </thead> 
  384. <tbody> 
  385. <?php 
  386. foreach ($items as $field_data) { 
  387. ?> 
  388. <tr> 
  389. <td><?php echo stripslashes($field_data->field_name); ?></td> 
  390. <td align="right"><?php echo WC_Compare_Fields_Class::$default_types[$field_data->field_type]['name']; ?></td> 
  391. <td align="right"><a href="admin.php?page=woo-compare-features&act=field-edit&field_id=<?php echo $field_data->id; ?>" class="c_field_edit" title="<?php _e('Edit', 'woocommerce-compare-products' ) ?>" ><?php _e('Edit', 'woocommerce-compare-products' ) ?></a> | <a href="admin.php?page=woo-compare-features&act=field-delete&field_id=<?php echo $field_data->id; ?>" class="c_field_delete" onclick="javascript:return confirmation('<?php _e('Are you sure you want to delete', 'woocommerce-compare-products' ) ; ?> #<?php echo htmlspecialchars($field_data->field_name); ?>');" title="<?php _e('Delete', 'woocommerce-compare-products' ) ?>" ><?php _e('Delete', 'woocommerce-compare-products' ) ?></a></td> 
  392. </tr> 
  393. <?php } ?> 
  394. </tbody> 
  395. <tfoot> 
  396. <tr> 
  397. <th class="manage-column column-title" colspan="3" style="padding:2px 7px"> 
  398. <div class="tablenav"> 
  399. <span class="search_item_title"><?php _e('Show', 'woocommerce-compare-products' ); ?>:</span> 
  400. <select name="rows" class="number_items"> 
  401. <?php $number_items_array = array('15' => '15', '25' => '25', '50' => '50', '75' => '75', '100' => '100', '200' => '200', '1000000' => 'All');  
  402. foreach($number_items_array as $key => $value) { 
  403. if($key == $rows) 
  404. echo "<option selected='selected' value='$key'>$value</option>"; 
  405. else 
  406. echo "<option value='$key'>$value</option>"; 
  407. ?> 
  408. </select> 
  409. <input type="submit" class="button" value="<?php _e('Go', 'woocommerce-compare-products' ); ?>" name="" id="search_items" /> 
  410. <div class="tablenav-pages"><span class="displaying-num"><?php _e('Displaying', 'woocommerce-compare-products' ) ; ?> <?php echo ($start+1); ?> - <?php echo $end; ?> <?php _e('of', 'woocommerce-compare-products' ) ; ?> <?php echo $total; ?></span><?php echo $innerPage;?></div> 
  411. </div> 
  412. </th> 
  413. </tr> 
  414. </tfoot> 
  415. </table> 
  416. <?php 
  417. ?> 
  418. </form> 
  419. <?php  
  420.