Jump to content

checkbox filter not working


erinod

Recommended Posts

Hi all. I have three scripts interacting with one another to create a checkbox that when selected will filter out any products from the table that are custom products (any products with product_type = 3 in the sql database). Right now the page reloads when the checkbox is clicked to the correct url, but the table hasn't actually has custom products filtered out. I'm very new to programming and made these code changes by copying and modifying another checkbox for our website that already worked. Please take a look and let me know if you see where I might be going wrong. I have tried to include all relevant parts of the scripts:

 

// index.php
if (isset( $_GET['exclude_custom'] )) {
    if($_GET['exclude_custom']  == "noexclude"){
       $exclude_custom = '';
       $exclude = "noexclude";
       $AppUI->setState( 'QuoteIdxCond', 'noexclude');
    }
    else{
       $exclude_custom = "exclude";
       $exclude = "exclude";
       $AppUI->setState( 'QuoteIdxCond', 'exclude');
    }
}
$exclude = $AppUI->getState( 'QuoteIdxCond' ) ? $AppUI->getState( 'QuoteIdxCond' ) : '';
if($exclude == "exclude")
  $exclude_custom = "exclude";
else
  $exclude_custom = '';

 

// vw_idx_products.php
global $sort_state, $products_view_mode, $exclude_custom;

include_once("{$dPconfig['root_dir']}/modules/quotes/utility.php");

load_all_products();

<script LANGUAGE="JavaScript">
function excludeCustom() {

     f = document.productQuotes.exclude_custom.checked;
    if(f == true)
       window.location =('./index.php?m=quotes&exclude_custom=exclude');
    else
      // window.location =('./index.php?m=quotes&exclude_custom=noexclude');
      window.location =('./index.php?m=quotes&exclude_custom=noexclude');
}
</script>

<FORM ACTION="?m=quotes" METHOD="post" NAME="productQuotes" ID="productQuotes">
<B> Stock Products & Services Only: </B><input type="checkbox" onclick="excludeCustom()" NAME="exclude_custom" id="exclude_custom" <?php echo ($exclude_custom ? 'checked="checked"' : '');?> />
    <THEAD>
    

 

// utility. php
global $item_list, $drawn_array, $item_list_parents, $sort_state, $AppUI, $exclude_custom;

function load_all_products()
{
    global $AppUI;
    global $sorted_item_list;
    global $additional_pfilter;
    load_type_list();
    $orderby = 'product_id';
    $search_map = array($orderby, 'product_number','product_name');
    $where = $AppUI->getState( 'QuoteIdxWhere' ) ? $AppUI->getState( 'QuoteIdxWhere' ) : '*';
    $not =" ";
    $op =  " OR";
    $check = substr(trim($where),0,4);
    if(stristr($check,"NOT")){
        $op ="AND";
        $not = " NOT ";
        $where = substr(trim($where),4);
        $where = trim($where);
    }

    // assemble the sql statement
    $q = new DBQuery;
    $q->addTable('products');
    $q->addJoin('companies', 'com', 'products.product_company_id = com.company_id');
    $q->addJoin('users', 'u', 'products.product_owner = u.user_id');
    $q->addQuery('products.*, com.company_name, u.user_username');
    $where_filter = " ";
    foreach($search_map as $search_name)
        $where_filter .=" $op $search_name $not REGEXP '$where'";
    $where_filter = substr($where_filter, 5);

//   echo $where_filter;
    if($where != "*")
       $q->addWhere("($where_filter)");
    $q->addOrder('product_id');

      if (isset( $_POST['exclude_custom'] )) {
    $where_filter .= "AND PRODUCT_TYPE != '3'";
     }

    $sql = $q->prepare();
    $q->clear();
    $sql_list = db_exec( $sql );
    if ($sql_list)
  $rn = db_num_rows( $sql_list );
    else {
   echo db_error();
   $rn = 0;
    }

 

Thanks!

Link to comment
Share on other sites

update: i got the filter to work by changing utility.php to be:

    $where_filter = " ";
    foreach($search_map as $search_name)
        $where_filter .=" $op $search_name $not REGEXP '$where'";

    $where_filter = substr($where_filter, 5);

    if($where != "*"){
        $where_filter .= "and product_type!='3'";
        $q->addWhere("($where_filter)");
    }
    else{
        $q->addWhere(" product_type!='3'");
    }

//   echo $where_filter;
    if ($where != "*")
       $q->addWhere("($where_filter)");
    $q->addOrder('product_id');

 

But now when I uncheck the box, this filter is staying on.. hmmm

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.