#!/usr/bin/perl -w
# -*- perl -*-
use P4CGI ;
use strict ;
#
#################################################################
#  CONFIGURATION INFORMATION 
#  All config info should be in P4CGI.pm
#
#################################################################
#
#  Search changes for pattern
#
#################################################################

my $FSPC = &P4CGI::cgi()->param("FSPC") ;
$FSPC = "//..." unless defined $FSPC ;
$FSPC = &P4CGI::htmlEncode($FSPC) ;

my $LABEL = &P4CGI::cgi()->param("LABEL") ;
$LABEL = &P4CGI::htmlEncode($LABEL) if defined $LABEL ;


my @labels ;
&P4CGI::p4call(\@labels,"labels") ;
map { s/^Label (\S+) .*/$1/ ; } @labels ;
unshift @labels,"" ;
my %labelLabels ;
foreach (@labels) {
    $labelLabels{$_} = $_ ;
}
$labelLabels{""} = " - No label specified - " ;

print
    &P4CGI::start_page("Find files",""),
    "<br>\n",
    &P4CGI::start_framedTable("Find file by name"),
    &P4CGI::start_table(),
    &P4CGI::cgi()->startform("-action","fileSearch.cgi",
			     "-method","GET") ;

print &P4CGI::table_row({-class => "\"Prompt\"",
			 -text => "File spec:" },	
			&P4CGI::cgi()->textfield(-name      => "FSPC",
						 -default   => $FSPC,
						 -override  => 1,
						 -size      => 40,
						 -maxlength => 256,
						 -title     => "File spec in p4 depot notation")) ;

print &P4CGI::table_row({-class => "\"Prompt\"",
			 -text => "Label:" },
			&P4CGI::cgi()->popup_menu(-name => "LABEL",
						  -values => \@labels,
						  -labels => \%labelLabels,
						  -title => "Search only in label")) ;

print &P4CGI::table_row("",
			&P4CGI::cgi()->hidden(-name=>"DP",
					      -value=>&P4CGI::CURR_DEPOT_NO()) . 
			&P4CGI::cgi()->submit(-name  => "0",
					      -value => "GO!",
					      -title => "Go")) ;

print    
    &P4CGI::cgi()->endform(),
    &P4CGI::end_table(),
    &P4CGI::end_framedTable() ;

sub prSelection($$$ )
{
    my $cgitarget  = shift @_ ;
    my $fields     = shift @_ ;
    my $helpTarget = shift @_ ;
    
    print
	&P4CGI::cgi()->startform(-action => $cgitarget,
				 -method => "GET"),
	&P4CGI::table_row({-text => $fields},
			  { -width=>"1",
			    -text => join("\n",
					  (&P4CGI::cgi()->hidden(-name=>"DP",
								 -value=>&P4CGI::CURR_DEPOT_NO()),
					   &P4CGI::cgi()->submit(-name  => "ignore",
								 -value => "GO!"),
					   &P4CGI::cgi()->endform()))
			    },
			  ) ;
} ;

my %dayValues = ( 0 => "Zero days",
		  1 => "One day",
		  2 => "Two days",
		  3 => "Three days",
		  4 => "Four days",
		  5 => "Five days",
		  6 => "Six days") ;

my %hourValues = ( 0 => "Zero hours",
		   1 => "One hour",
		   2 => "Two hours",
		   3 => "Three hours",
		   4 => "Four hours",
		   5 => "Five hours",
		   6 => "Six hours",
		   7 => "Seven hours",
		   8 => "Eight hours",
		   9 => "Nine hours") ;
{
    my $n = 9 ;
    while($n++ < 24) {
	$hourValues{$n} = "$n hours" ;
    }
}

my %weekValues = ( 0 => "Zero weeks",
		   1 => "One week",
		   2 => "Two weeks",
		   3 => "Three weeks",
		   4 => "Four weeks",
		   5 => "Five weeks",
		   6 => "Six weeks",
		   7 => "Seven weeks",
		   8 => "Eight weeks",
		   9 => "Nine weeks") ;
{
    my $n = 9 ;
    while($n++ < 52) {
	$weekValues{$n} = "$n weeks" ;
    }
}


my @dayValues = sort { $a <=> $b } keys %dayValues ;
my @hourValues = sort { $a <=> $b } keys %hourValues ;
my @weekValues = sort { $a <=> $b } keys %weekValues ;

print 
    "<br>" , 
    &P4CGI::start_framedTable("Find recently modified files") , 
    &P4CGI::start_table("") ;

	       
prSelection("filesChangedSince.cgi",
	    join("\n",(&P4CGI::start_table(""),
		       "<tr>",
		       "<td class=\"Prompt\">File spec:</td>",
		       "<td>",
		       &P4CGI::cgi()->textfield(-name      => "FSPC",
						-default   => $FSPC,
						-override  => 1,
						-size      => 50,
						-maxlength => 256),
		       "</td></tr>",
		       "<td class=\"Prompt\">Changed within:</td>",
		       "<td>",
		       &P4CGI::cgi()->popup_menu(-name      => "WEEKS",
						 -default   => 0,
						 -values    => \@weekValues,
						 -labels    => \%weekValues),
		       "&nbsp;",
		       &P4CGI::cgi()->popup_menu(-name      => "DAYS",
						 -default   => 0,
						 -values    => \@dayValues,
						 -labels    => \%dayValues),
		       "&nbsp;and&nbsp;",
		       &P4CGI::cgi()->popup_menu(-name      => "HOURS",
						 -default   => 0,
						 -values    => \@hourValues,
						 -labels    => \%hourValues),
		       "</td></tr>",
		       "</table>")),
	    "searchPatt") ;
		       
print
    &P4CGI::cgi()->endform(),
    &P4CGI::end_table(),
    &P4CGI::end_framedTable() ;


print &P4CGI::end_page() ;

#
# That's all folks
#