summaryrefslogtreecommitdiff
path: root/fml/lib/FML/CGI/ThreadTrack.pm
blob: 479acbe40791434ca490d8556a2480ef5bdf0e6b (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#-*- perl -*-
#
#  Copyright (C) 2001,2002,2003 Ken'ichi Fukamachi
#   All rights reserved. This program is free software; you can
#   redistribute it and/or modify it under the same terms as Perl itself.
#
# $FML: ThreadTrack.pm,v 1.24 2003/02/16 08:33:08 fukachan Exp $
#

package FML::CGI::ThreadTrack;
use strict;
use Carp;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use CGI qw/:standard/; # load standard CGI routines

use FML::Process::CGI;
@ISA = qw(FML::Process::CGI);


=head1 NAME

FML::CGI::ThreadTrack - CGI details to control thread system

=head1 SYNOPSIS

    $obj = new FML::CGI::ThreadTrack;
    $obj->prepare();
    $obj->verify_request();
    $obj->run();
    $obj->finish();

run() executes html_start(), run_cgi() and html_end() described below.

See L<FML::Process::Flow> for flow details.

=head1 DESCRIPTION

=head2 CLASS HIERARCHY

C<FML::CGI::ThreadTrack> is a subclass of C<FML::Process::CGI>.

=head1 METHODS

Almost methods common for CGI or HTML are forwarded to
C<FML::Process::CGI> base class.

=cut


# Descriptions: print out HTML header + body former part
#    Arguments: OBJ($curproc) HASH_REF($args)
# Side Effects: none
# Return Value: none
sub html_start
{
    my ($curproc, $args) = @_;
    my $config  = $curproc->{ config };
    my $title   = $config->{ thread_cgi_title }   || 'thread system interface';
    my $color   = $config->{ thread_cgi_bgcolor } || '#E6E6FA';
    my $myname  = $curproc->myname();
    my $charset = $curproc->language_of_cgi_message();

    # o.k start html
    print start_html(-title   => $title,
		     -lang    => $charset,
		     -BGCOLOR => $color);
    print "\n";
}


# Descriptions: print out body latter part
#    Arguments: OBJ($curproc) HASH_REF($args)
# Side Effects: none
# Return Value: none
sub html_end
{
    my ($curproc, $args) = @_;

    # o.k. end of html
    print end_html;
    print "\n";
}


# Descriptions: main routine for thread control.
#               run_cgi() can process request: list, show, change_status
#    Arguments: OBJ($curproc) HASH_REF($args)
# Side Effects: none
# Return Value: none
sub run_cgi_main
{
    my ($curproc, $args) = @_;
    my $config = $curproc->{ config };
    my $myname = $config->{ program_name }; # XXX-TODO: valid ?
    my $ttargs = $curproc->_build_threadtrack_param($args);
    my $action = $curproc->safe_param_action() || '';

    use Mail::ThreadTrack;
    my $thread = new Mail::ThreadTrack $ttargs;

    if (defined $thread) {
	$thread->set_mode('html');

	if ($action eq 'list') {
	    $thread->summary();
	}
	elsif ($action eq 'show') {
	    my $id  = $curproc->safe_param_article_id();
	    # XXX-TODO: do not call _XXX() internal method from outside.
	    my $tid = $thread->_create_thread_id_strings($id);
	    $thread->show($tid);
	}
	elsif ($action eq 'change_status') {
	    # fmlthread.cgi is for administorator, so you can change status.
	    if ($myname eq 'fmlthread.cgi') {
		my $list = $curproc->safe_paramlist2_threadcgi_change_status();
		for my $param (@$list) {
		    my ($ml, $id, $value) = @$param;
		    if ($value eq 'closed') {
			my $tid = $thread->_create_thread_id_strings($id);
			print "closed $tid", br, "\n";
			$thread->close($tid);
		    }
		}
	    }
	    # XXX-TODO: ? clarify this message more.
	    else {
		print "Warning: only administrator change status\n";
	    }

	    $thread->summary();
	}
	else {
	    $thread->summary();
	}
    }
    else {
	croak("fail to create thread object");
    }
}


# Descriptions: prepare basic parameters for Mail::ThreadTrack module
#    Arguments: OBJ($curproc) HASH_REF($args)
# Side Effects: none
# Return Value: HASH_REF
sub _build_threadtrack_param
{
    my ($curproc, $args) = @_;
    my $config = $curproc->{ config };
    my $myname = $config->{ program_name };
    my $option = $curproc->command_line_options();

    # prepare arguments for thread track module
    # XXX-TODO: hmm, we should provide $curproc->util->article_max_id() ?
    my $ml_name       = $curproc->safe_param_ml_name();
    my $thread_db_dir = $config->{ thread_db_dir };
    my $spool_dir     = $config->{ spool_dir };
    my $max_id        = $curproc->article_max_id();
    my $ttargs        = {
	myname        => $myname,
	logfp         => \&Log,
	fd            => \*STDOUT,
	db_base_dir   => $thread_db_dir,
	ml_name       => $ml_name,
	spool_dir     => $spool_dir,
	reverse_order => 0,
    };

    # import some variables
    for my $varname (qw(base_url msg_base_url)) {
	if (defined $option->{ $varname }) {
	    $ttargs->{ $varname } = $option->{ $varname };
	}
	elsif (defined $config->{ $varname }) {
	    $ttargs->{ $varname } = $config->{ $varname };
	}
    }

    return $ttargs;
}


# Descriptions: print navigation bar
#    Arguments: OBJ($curproc) HASH_REF($args)
# Side Effects: none
# Return Value: none
sub run_cgi_navigator
{
    my ($curproc, $args) = @_;
    my $config  = $curproc->{ config };
    my $action  = $curproc->safe_cgi_action_name();
    my $target  = $config->{ thread_cgi_target_window } || '_top';
    # XXX-TODO: we should provide $curproc->util->get_ml_list() method ?
    my $ml_list = $curproc->get_ml_list($args);
    my $ml_name = $config->{  ml_name };

    print start_form(-action=>$action, -target=>$target);

    print "ML: ";
    print popup_menu(-name   => 'ml_name', -values => $ml_list);
    print "<BR>\n";

    print "orderd by: ";
    my $order = [ 'cost', 'date', 'reverse date' ];
    print popup_menu(-name   => 'order', -values => $order );
    print "<BR>\n";

    print submit(-name => 'change target');
    print reset(-name => 'reset');

    print end_form;
    print "<HR>\n";
}


=head1 SEE ALSO

L<CGI>,
L<FML::Process::CGI>
and
L<FML::Process::Flow>

=head1 CODING STYLE

See C<http://www.fml.org/software/FNF/> on fml coding style guide.

=head1 AUTHOR

Ken'ichi Fukamachi

=head1 COPYRIGHT

Copyright (C) 2001,2002,2003 Ken'ichi Fukamachi

All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

=head1 HISTORY

FML::CGI::ThreadTrack first appeared in fml8 mailing list driver package.
See C<http://www.fml.org/> for more details.

=cut


1;