Ignore:
Timestamp:
Dec 5, 2004, 12:47:40 PM (19 years ago)
Author:
plg
Message:
  • search modified : possible to partially fill the date, allwords are separated from more specific search, separation of HTML (in template) and PHP code)
File:
1 edited

Legend:

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

    r630 r634  
    416416        // SQL where clauses are stored in $clauses array during query
    417417        // construction
    418         $clauses = $temp_clauses = array();
    419         if (isset($search['fields']['allwords']))
    420     {
    421           $textfields = array('file', 'name', 'comment', 'keywords', 'author');
    422           foreach ($textfields as $textfield)
     418        $clauses = array();
     419       
     420        $textfields = array('file', 'name', 'comment', 'keywords', 'author');
     421        foreach ($textfields as $textfield)
     422        {
     423          if (isset($search['fields'][$textfield]))
    423424          {
    424425            $local_clauses = array();
    425             foreach ($search['fields']['allwords']['words'] as $word)
     426            foreach ($search['fields'][$textfield]['words'] as $word)
    426427            {
    427428              array_push($local_clauses, $textfield." LIKE '%".$word."%'");
     
    429430            // adds brackets around where clauses
    430431            array_walk($local_clauses,create_function('&$s','$s="(".$s.")";'));
    431             array_push($temp_clauses,
    432                        implode(' '.$search['fields']['allwords']['mode'].' ',
     432            array_push($clauses,
     433                       implode(' '.$search['fields'][$textfield]['mode'].' ',
    433434                               $local_clauses));
    434435          }
    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     }
     436        }
     437
     438        if (isset($search['fields']['allwords']))
     439        {
     440          $fields = array('file', 'name', 'comment', 'keywords');
     441          // in the OR mode, request bust be :
     442          // ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
     443          // OR (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
     444          //
     445          // in the AND mode :
     446          // ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
     447          // AND (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
     448          $word_clauses = array();
     449          foreach ($search['fields']['allwords']['words'] as $word)
     450          {
     451            $field_clauses = array();
     452            foreach ($fields as $field)
     453            {
     454              array_push($field_clauses, $field." LIKE '%".$word."%'");
     455            }
     456            // adds brackets around where clauses
     457            array_push($word_clauses, implode(' OR ', $field_clauses));
     458          }
     459          array_walk($word_clauses, create_function('&$s','$s="(".$s.")";'));
     460          array_push($clauses,
     461                     implode(' '.$search['fields']['allwords']['mode'].' ',
     462                               $word_clauses));
     463        }
    442464
    443465        $datefields = array('date_available', 'date_creation');
     
    447469          if (isset($search['fields'][$key]))
    448470          {
    449             $local_clause = $datefield." ";
    450       if (isset($search['fields'][$key]['mode']))
    451       {
    452         $local_clause .=">";
    453       }
    454       $local_clause .="= '";
    455       $local_clause.= str_replace('.', '-',
     471            $local_clause = $datefield." = '";
     472            $local_clause.= str_replace('.', '-',
    456473                                        $search['fields'][$key]['words'][0]);
    457       $local_clause.= "'";
    458       array_push($clauses, $local_clause);
    459      
    460       if (isset($search['fields'][$key]['mode']))
    461       {
    462         $end_sql_date = str_replace('.', '-',
    463                                         $search['fields'][$key]['mode']);
    464         $local_clause = $datefield." <= '".$end_sql_date."'";
    465         array_push($clauses, $local_clause);
    466       }
    467     }
    468   }
    469        
     474            $local_clause.= "'";
     475            array_push($clauses, $local_clause);
     476          }
     477
     478          foreach (array('after','before') as $suffix)
     479          {
     480            $key = $datefield.'-'.$suffix;
     481            if (isset($search['fields'][$key]))
     482            {
     483              $local_clause = $datefield;
     484              if ($suffix == 'after')
     485              {
     486                $local_clause.= ' >';
     487              }
     488              else
     489              {
     490                $local_clause.= ' <';
     491              }
     492              if (isset($search['fields'][$key]['mode'])
     493                  and $search['fields'][$key]['mode'] == 'inc')
     494              {
     495                $local_clause.= '=';
     496              }
     497              $local_clause.= " '";
     498              $local_clause.= str_replace('.', '-',
     499                                          $search['fields'][$key]['words'][0]);
     500              $local_clause.= "'";
     501              array_push($clauses, $local_clause);
     502            }
     503          }
     504        }
     505
    470506        if (isset($search['fields']['cat']))
    471507        {
     
    509545        // adds brackets around where clauses
    510546        array_walk($clauses, create_function('&$s', '$s = "(".$s.")";'));
    511         $page['where'] = 'WHERE '.implode(' AND ', $clauses);
     547        $page['where'] = 'WHERE '.implode(' '.$search['mode'].' ', $clauses);
    512548        if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden;
    513549
Note: See TracChangeset for help on using the changeset viewer.