-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.pl
executable file
·163 lines (143 loc) · 5.83 KB
/
search.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/perl -w
use strict;
use lib qw(.);
use PMT;
use XML::RSS;
use PMT::Common;
my $pmt = PMT->new() or die "couldn't make new pmt object";
my $cgi = CGI->new();
eval {
my $username = $cgi->cookie('pmtusername') || "";
my $password = $cgi->cookie('pmtpassword') || "";
my $user = PMT::User->retrieve($username);
$user->check_pass($username,$password);
# the default to "" here so we can do a conditional test below
# to see if any were set or not.
my $pid = $cgi->param('pid') || "";
my $q = $cgi->param('q') || "";
my $type = $cgi->param('type') || "";
my $owner = $cgi->param('owner') || "";
my $assigned_to = $cgi->param('assigned_to') || "";
my @status = $cgi->param('status');
my $tag = $cgi->param('tag') || "";
my @show = $cgi->param('show');
my $number = $cgi->param('number') || "";
my $sortby = $cgi->param('sortby') || "";
my $order = $cgi->param('order') || "";
my $limit = $cgi->param('limit') || 100;
my $offset = $cgi->param('offset') || 0;
my $csv = $cgi->param('csv') || "";
my $rss = $cgi->param('rss') || "";
my $max_date = $cgi->param('max_date') || "";
my $min_date = $cgi->param('min_date') || "";
my $max_mod_date= $cgi->param('max_mod_date') || "";
my $min_mod_date= $cgi->param('min_mod_date') || "";
my $hide_menu = $cgi->param('hide_menu') || "";
my $results_title = $cgi->param('results_title') || "";
my $template;
if($csv eq "") {
$template = get_template("search.tmpl");
$template->param($user->menu());
$template->param(items_mode => 1);
$template->param(wiki_base_url => PMT::Common::get_wiki_url());
} else {
$template = get_template("search_tab.tmpl");
}
my $rows = 0;
my %show;
foreach my $show (@show) {
$show{$show} = 1;
}
if ($pid ne "" || $q ne "" || $type ne "" || $owner ne ""
|| $assigned_to ne "" || $number ne "" || $sortby ne "" || $order ne "")
{
my $current_time = time();
my $r = PMT::Item->search_items(pid => $pid, q => $q, type => $type, owner => $owner,
assigned_to => $assigned_to, status => \@status, tag => $tag,
number => $number, sortby => $sortby, order => $order, limit => $limit,
offset => $offset, max_date => $max_date, min_date => $min_date,
max_mod_date => $max_mod_date, min_mod_date => $min_mod_date,
show => \@show);
$current_time = time();
my @items;
my %shows;
foreach my $show (@show) {
$shows{"show_$show"} = 1;
}
if($rss) {
my $feed = new XML::RSS(version => '1.0');
$feed->channel(
title => "PMT feed",
link => "http://$ENV{'SERVER_NAME'}/",
);
foreach my $i (@$r) {
$feed->add_item(title => $i->{title},
link => "http://$ENV{'SERVER_NAME'}/item/$i->{iid}/",
description => $i->{description});
}
print $cgi->header("text/xml"),$feed->as_string();
} else {
if ((exists $shows{show_tags}) ||
(exists $shows{show_comments}) ||
(exists $shows{show_history}) ||
(exists $shows{show_time_on_task})) {
foreach my $i (@$r) {
my $item = PMT::Item->retrieve($i->{iid});
my $r = $item->full_data();
my %data = %$r;
foreach my $k (keys %shows) {$data{$k} = 1;}
if(exists $shows{show_time_on_task}) {
$data{resolve_times} = $item->resolve_times();
}
push @items, \%data;
}
} else {
foreach my $i (@$r) {
my %data = %$i;
foreach my $k (keys %shows) {$data{$k} = 1;}
push @items, \%data;
}
}
my %PRIORITIES = (4 => 'CRITICAL', 3 => 'HIGH', 2 => 'MEDIUM', 1 => 'LOW',
0 => 'ICING');
@items = map {
$_->{priority_label} = $PRIORITIES{$_->{priority}};
$_->{type_class} = $_->{type};
$_->{type_class} =~ s/\s//g;
$_;} @items;
$template->param(\%shows);
$template->param(results => 1,
page_title => $results_title || 'search results',
results_title => $results_title,
hide_menu => $hide_menu,
found_items => ($#items >= 0),
items => \@items);
if($csv) {
print $cgi->header("application/vnd.ms-excel");
} else {
print $cgi->header();
}
print $template->output();
}
} else {
$template->param(users => [map {$_->data()}
PMT::User->all_active()]);
$template->param(page_title => 'search/filter');
print $cgi->header, $template->output();
}
};
if($@) {
my $E = $@;
if($E->isa('Error::Simple')) {
if ($E->isa('Error::NO_USERNAME') ||
$E->isa('Error::NO_PASSWORD') ||
$E->isa('Error::AUTHENTICATION_FAILURE')) {
print $cgi->redirect('login.pl');
} else {
print $cgi->header(), "<h1>error:</h1><p>$E->{-text}</p>";
}
} else {
print $cgi->header(),
"an unknown error occurred: $E";
}
}