Subversion Repositories DevTools

Rev

Rev 1295 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
###############################################################################
2
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
3
# sits@users.sourceforge.net
4
#
5
# This program is free software; you can redistribute it and modify it under
6
# the terms of the GPL.
7
 
8
# Action object for displaying the topic search page.
9
 
10
package Codestriker::Action::Search;
11
 
12
use strict;
13
use Codestriker::Model::Project;
14
use Codestriker::DB::Database;
15
 
16
# Create an appropriate form for topic searching.
17
sub process($$$) {
18
    my ($type, $http_input, $http_response) = @_;
19
 
20
    my $query = $http_response->get_query();
21
 
22
    # Check if this action is allowed.
23
    if ($Codestriker::allow_searchlist == 0) {
24
	$http_response->error("This function has been disabled");
25
    }
26
 
27
    $http_response->generate_header(topic_title=>"Search",
28
				    reload=>0, cache=>1);
29
 
30
    # Obtain a URL builder object.
31
    my $url_builder = Codestriker::Http::UrlBuilder->new($query);
32
 
33
    # Create the hash for the template variables.
34
    my $vars = {};
35
 
36
    # Create the list of valid states that can be searched over.
37
    my @states = ("Any");
38
    push @states, @Codestriker::topic_states;
39
    $vars->{'states'} = \@states;
40
 
41
    # Get the list of valid topics in the system that can be searched over.
42
    my @projects_db = Codestriker::Model::Project->list();
43
    my @projects = ();
44
    my $any_project = {};
45
    $any_project->{id} = -1;
46
    $any_project->{name} = "Any";
47
    push @projects, $any_project;
48
 
49
    foreach my $project (@projects_db) {
50
	push @projects, $project;
51
    }
52
    $vars->{'projects'} = \@projects;
53
 
54
    # Check if the database supports the like operator over text fields.
55
    my $database = Codestriker::DB::Database->get_database();
56
 
57
    if ($database->has_like_operator_for_text_field()) {
58
	# Can use LIKE over text fields, everything is searchable.
59
	$vars->{'enable_title'} = 1;
60
	$vars->{'enable_description'} = 1;
61
	$vars->{'enable_comment'} = 1;
62
	$vars->{'enable_body'} = 1;
63
	$vars->{'enable_filename'} = 1;
64
    }
65
    else {
66
	# Only varchar fields can be searched over, limit the search
67
	# capability.
68
	$vars->{'enable_title'} = 1;
69
	$vars->{'enable_description'} = 0;
70
	$vars->{'enable_comment'} = 0;
71
	$vars->{'enable_body'} = 0;
72
	$vars->{'enable_filename'} = 1;
73
    }
74
 
75
    my $template = Codestriker::Http::Template->new("search");
76
    $template->process($vars);
77
 
78
    $http_response->generate_footer();
79
}
80
 
81
1;