Changeset 621 for trunk/include


Ignore:
Timestamp:
Nov 25, 2004, 3:12:33 PM (20 years ago)
Author:
gweltas
Message:

New ergonomic form for search queries.

Location:
trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/category_default.inc.php

    r606 r621  
    4747  LIMIT '.$page['start'].','.$page['nb_image_page'].'
    4848;';
    49 // echo '<pre>'.$query.'</pre>';
     49//echo '<pre>'.$query.'</pre>';
    5050$result = pwg_query($query);
    5151
  • trunk/include/functions_category.inc.php

    r617 r621  
    166166  $query.= ';';
    167167 
    168 //   $query = '
    169 // SELECT COUNT(DISTINCT(image_id)) as total
    170 //   FROM '.PREFIX_TABLE.'image_category';
    171 //   if (count($user['restrictions']) > 0)
    172 //   {
    173 //     $query.= '
    174 //   WHERE category_id NOT IN ('.$user['forbidden_categories'].')';
    175 //   }
    176 //   $query = '
    177 // ;';
    178  
    179168  $row = mysql_fetch_array( pwg_query( $query ) );
    180169
    181170  if ( !isset( $row['total'] ) ) $row['total'] = 0;
    182 
    183171  return $row['total'];
    184172}
     
    345333    $page['nb_image_page'] = $user['nb_image_page'];
    346334    // $url is used to create the navigation bar
    347     $url = './category.php?cat='.$page['cat'];
     335    $url = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'];
    348336    if ( isset($page['expand']) ) $url.= '&amp;expand='.$page['expand'];
    349337    // simple category
     
    428416        // SQL where clauses are stored in $clauses array during query
    429417        // construction
    430         $clauses = array();
    431        
    432         $textfields = array('file', 'name', 'comment', 'keywords', 'author');
    433         foreach ($textfields as $textfield)
    434         {
    435           if (isset($search['fields'][$textfield]))
     418        $clauses = $temp_clauses = array();
     419        if (isset($search['fields']['keywords']))
     420                {
     421          $textfields = array('file', 'name', 'comment', 'keywords', 'author');
     422          foreach ($textfields as $textfield)
    436423          {
    437424            $local_clauses = array();
    438             foreach ($search['fields'][$textfield]['words'] as $word)
     425            foreach ($search['fields']['keywords']['words'] as $word)
    439426            {
    440427              array_push($local_clauses, $textfield." LIKE '%".$word."%'");
     
    442429            // adds brackets around where clauses
    443430            array_walk($local_clauses,create_function('&$s','$s="(".$s.")";'));
    444             array_push($clauses,
    445                        implode(' '.$search['fields'][$textfield]['mode'].' ',
     431            array_push($temp_clauses,
     432                       implode(' '.$search['fields']['keywords']['mode'].' ',
    446433                               $local_clauses));
    447434          }
    448         }
     435                  array_push($clauses, implode(' OR ', $temp_clauses));
     436        }
     437               
     438                if (isset($search['fields']['author']))
     439                {
     440           array_push($clauses, "author LIKE '%".$search['fields']['author']['words'][0]."%'");
     441                }
    449442
    450443        $datefields = array('date_available', 'date_creation');
     
    454447          if (isset($search['fields'][$key]))
    455448          {
    456             $local_clause = $datefield." = '";
     449            $local_clause = $datefield." ";
     450                        if (isset($search['fields'][$key]['mode']))
     451                        {
     452                          $local_clause .=">";
     453                        }
     454                        $local_clause .="= '";
    457455            $local_clause.= str_replace('.', '-',
    458456                                        $search['fields'][$key]['words'][0]);
    459457            $local_clause.= "'";
    460458            array_push($clauses, $local_clause);
    461           }
    462 
    463           foreach (array('after','before') as $suffix)
    464           {
    465             $key = $datefield.'-'.$suffix;
    466             if (isset($search['fields'][$key]))
    467             {
    468               $local_clause = $datefield;
    469               if ($suffix == 'after')
    470               {
    471                 $local_clause.= ' >';
    472               }
    473               else
    474               {
    475                 $local_clause.= ' <';
    476               }
    477               if (isset($search['fields'][$key]['mode'])
    478                   and $search['fields'][$key]['mode'] == 'inc')
    479               {
    480                 $local_clause.= '=';
    481               }
    482               $local_clause.= " '";
    483               $local_clause.= str_replace('.', '-',
    484                                           $search['fields'][$key]['words'][0]);
    485               $local_clause.= "'";
    486               array_push($clauses, $local_clause);
    487             }
    488           }
    489         }
    490 
     459                       
     460                        if (isset($search['fields'][$key]['mode']))
     461          {
     462                    $search_tokens = explode('.', $search['fields'][$key]['words'][0]);
     463                    $start_time = mktime(0, 0, 0, $search_tokens[1], $search_tokens[2],$search_tokens[0]);
     464                        $search_duration = intval($search['fields'][$key]['mode']) * 86400;
     465                        $end_time = $start_time + $search_duration;
     466                        $end_sql_date = date('Y-m-d',$end_time);
     467                    $local_clause = $datefield." <= '".$end_sql_date."'";
     468            array_push($clauses, $local_clause);
     469          }
     470                  }
     471        }
     472       
    491473        if (isset($search['fields']['cat']))
    492474        {
     
    530512        // adds brackets around where clauses
    531513        array_walk($clauses, create_function('&$s', '$s = "(".$s.")";'));
    532         $page['where'] = 'WHERE '.implode(' '.$search['mode'].' ', $clauses);
     514        $page['where'] = 'WHERE '.implode(' AND ', $clauses);
    533515        if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden;
    534516
Note: See TracChangeset for help on using the changeset viewer.