| 1 | package CGI::AppBuilder::MapTasks; | ||
| 2 | |||
| 3 | # Perl standard modules | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use Getopt::Std; | ||
| 7 | use POSIX qw(strftime); | ||
| 8 | use Carp; | ||
| 9 | use CGI; | ||
| 10 | use CGI::AppBuilder; | ||
| 11 | use CGI::AppBuilder::Message qw(:echo_msg); | ||
| 12 | use File::Path; | ||
| 13 | use Net::Rexec 'rexec'; | ||
| 14 | |||
| 15 | our $VERSION = 0.12; | ||
| 16 | require Exporter; | ||
| 17 | our @ISA = qw(Exporter CGI::AppBuilder); | ||
| 18 | our @EXPORT = qw(); | ||
| 19 | our @EXPORT_OK = qw(disp_task_form task_url task_usr_input | ||
| 20 | ); | ||
| 21 | our %EXPORT_TAGS = ( | ||
| 22 | tasks => [qw(task_url task_usr_input)], | ||
| 23 | all => [@EXPORT_OK] | ||
| 24 | ); | ||
| 25 | |||
| 26 | =head1 NAME | ||
| 27 | |||
| 28 | CGI::AppBuilder::PLSQL - Oracle PL/SQL Procedures | ||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | use CGI::AppBuilder::MapTasks; | ||
| 33 | |||
| 34 | my $sec = CGI::AppBuilder::PLSQL->new(); | ||
| 35 | my ($sta, $msg) = $sec->exe_sql($ar); | ||
| 36 | |||
| 37 | =head1 DESCRIPTION | ||
| 38 | |||
| 39 | This class provides methods for reading and parsing configuration | ||
| 40 | files. | ||
| 41 | |||
| 42 | =cut | ||
| 43 | |||
| 44 | =head2 new (ifn => 'file.cfg', opt => 'hvS:') | ||
| 45 | |||
| 46 | This is a inherited method from CGI::AppBuilder. See the same method | ||
| 47 | in CGI::AppBuilder for more details. | ||
| 48 | |||
| 49 | =cut | ||
| 50 | |||
| 51 | sub new { | ||
| 52 | my ($s, %args) = @_; | ||
| 53 | return $s->SUPER::new(%args); | ||
| 54 | } | ||
| 55 | |||
| 56 | sub task_url { | ||
| 57 | my ($s, $ar, $pr, $typ) = @_; | ||
| 58 | |||
| 59 | $typ = $ar->{id_type} if !$typ && exists $ar->{id_type} && $ar->{id_type}; | ||
| 60 | $typ = 'studyid' if !$typ; | ||
| 61 | my ($study_id,$study_name,$job_id,$job_name,$hjob_id,$list_id,$spec_id) = (); | ||
| 62 | $study_id = $ar->{study_id} if exists $ar->{study_id} && $ar->{study_id}; | ||
| 63 | $study_id = $ar->{sel_sn2} if !$study_id | ||
| 64 | && exists $ar->{sel_sn2} && $ar->{sel_sn2} && $typ =~ /^studyid/; | ||
| 65 | $job_id = $ar->{job_id} if exists $ar->{job_id} && $ar->{job_id}; | ||
| 66 | $hjob_id = $ar->{hjob_id} if exists $ar->{hjob_id} && $ar->{hjob_id}; | ||
| 67 | $list_id = $ar->{list_id} if exists $ar->{list_id} && $ar->{list_id}; | ||
| 68 | $spec_id = $ar->{spec_id} if exists $ar->{spec_id} && $ar->{spec_id}; | ||
| 69 | my $pid = $pr->{pid}; # project id | ||
| 70 | my $sn = $pr->{sid}; # server id | ||
| 71 | my $url = $pr->{web_url}; # web URL | ||
| 72 | $url =~ s/(\?.*)//; # remove parameters | ||
| 73 | my $u1 = "pid=$pid&no_dispform=1"; | ||
| 74 | $u1 .= "&sel_sn1=$pr->{sid}" if exists $pr->{sid} && $pr->{sid}; | ||
| 75 | $u1 .= "&study_id=$study_id" if $study_id; | ||
| 76 | $u1 .= "&job_id=$job_id" if $job_id; | ||
| 77 | $u1 .= "&hjob_id=$hjob_id" if $hjob_id; | ||
| 78 | $u1 .= "&list_id=$list_id" if $list_id; | ||
| 79 | $u1 .= "&spec_id=$spec_id" if $spec_id; | ||
| 80 | $u1 .= "&study_name=$ar->{study_name}" | ||
| 81 | if exists $ar->{study_name} && $ar->{study_name}; | ||
| 82 | $u1 .= "&job_name=$ar->{job_name}" | ||
| 83 | if exists $ar->{job_name} && $ar->{job_name}; | ||
| 84 | if ($typ && $typ =~ /(cptable|cfgstudy|recfgsch|cfgschema|studyid)/) { | ||
| 85 | $u1 .= "&sel_sn2=$study_id" if $study_id; | ||
| 86 | } elsif ($typ && $typ =~ /(schjob|jobid)/i) { | ||
| 87 | $u1 .= "&sel_sn2=$job_id" if $job_id; | ||
| 88 | } elsif ($typ && $typ =~ /(htmlrpt|xmlrpt|hjobid)/i) { | ||
| 89 | $u1 .= "&sel_sn2=$hjob_id" if $hjob_id; | ||
| 90 | } | ||
| 91 | return "$url?$u1"; | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | sub task_usr_input { | ||
| 96 | my ($s, $ar, $pr, $typ) = @_; | ||
| 97 | |||
| 98 | $typ = $ar->{id_type} if !$typ && exists $ar->{id_type} && $ar->{id_type}; | ||
| 99 | $typ = 'studyid' if !$typ; | ||
| 100 | my ($pid,$study_id,$study_name,$job_id,$job_name,$hjob_id) = (); | ||
| 101 | my ($cln_id, $cln_nm, $prj_id, $prj_nm) = (); | ||
| 102 | $pid = $ar->{pid} if exists $ar->{pid} && $ar->{pid}; | ||
| 103 | $cln_id = $ar->{cln_id} if exists $ar->{cln_id} && $ar->{cln_id}; | ||
| 104 | $prj_id = $ar->{prj_id} if exists $ar->{prj_id} && $ar->{prj_id}; | ||
| 105 | $study_id = $ar->{study_id} if exists $ar->{study_id} && $ar->{study_id}; | ||
| 106 | $job_id = $ar->{job_id} if exists $ar->{job_id} && $ar->{job_id}; | ||
| 107 | $hjob_id = $ar->{hjob_id} if exists $ar->{hjob_id} && $ar->{hjob_id}; | ||
| 108 | if (!$pid) { | ||
| 109 | $s->echo_msg("ERR: pid is not defined.", 0); return; | ||
| 110 | } | ||
| 111 | |||
| 112 | my $fmt = "<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n"; | ||
| 113 | my $t = sprintf $fmt, "pid", $pid; | ||
| 114 | $t .= sprintf $fmt, "sel_sn1", $pr->{sid} if exists $pr->{sid}; | ||
| 115 | $t .= sprintf $fmt, "task", "disp_usr_task"; | ||
| 116 | $t .= sprintf $fmt, "id_type", $typ if $typ; | ||
| 117 | $t .= sprintf $fmt, "cln_id", $cln_id if $cln_id; | ||
| 118 | $t .= sprintf $fmt, "prj_id", $prj_id if $prj_id; | ||
| 119 | $t .= sprintf $fmt, "study_id", $study_id if $study_id; | ||
| 120 | $t .= sprintf $fmt, "job_id", $job_id if $job_id; | ||
| 121 | $t .= sprintf $fmt, "hjob_id", $hjob_id if $hjob_id; | ||
| 122 | $t .= sprintf $fmt, "study_name", $ar->{study_name} | ||
| 123 | if exists $ar->{study_name} && $ar->{study_name}; | ||
| 124 | $t .= sprintf $fmt, "job_name", $ar->{job_name} | ||
| 125 | if exists $ar->{job_name} && $ar->{job_name}; | ||
| 126 | $t .= uc($typ) . ": <input name=\"sel_sn2\" value=\"\" size=5 />\n" ; | ||
| 127 | $t .= "<input name=\"a\" value=\"Set\" type=\"submit\" />"; | ||
| 128 | return $t; | ||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | =head2 disp_task_form($q,$ar,$txt) | ||
| 133 | |||
| 134 | Input variables: | ||
| 135 | |||
| 136 | $q - CGI class | ||
| 137 | $ar - array ref containing the following variables: | ||
| 138 | pid : project id such as ckpt, owb, dba, etc. | ||
| 139 | task : task name required such as task1,task2,etc. | ||
| 140 | target(sel_sn1) : select one (DB/server name) defining sid | ||
| 141 | args(sel_sn2) : select two (Arguments) | ||
| 142 | task_fn : task file name containing all the tasks defined | ||
| 143 | svr_conn : host/server connection info | ||
| 144 | db_conn : db connection info for each target/server | ||
| 145 | task_conn : special connection for tasks. | ||
| 146 | It overwrites db_conn for the task | ||
| 147 | |||
| 148 | Variables used or routines called: | ||
| 149 | |||
| 150 | None | ||
| 151 | |||
| 152 | How to use: | ||
| 153 | |||
| 154 | |||
| 155 | Return: $pr will contain the parameters adn output from running the PL/SQL. | ||
| 156 | |||
| 157 | |||
| 158 | =cut | ||
| 159 | |||
| 160 | sub disp_task_form { | ||
| 161 | my ($s, $q, $ar, $txt, $ret) = @_; | ||
| 162 | |||
| 163 | my $fmn = 'fm1'; | ||
| 164 | $fmn = $ar->{form_name} | ||
| 165 | if exists $ar->{form_name} && $ar->{form_name}; | ||
| 166 | my %fr = (-name => $fmn, -method=>uc $ar->{method}, | ||
| 167 | -action=>"$ar->{action}?", -enctype=>$ar->{encoding} ); | ||
| 168 | if (exists $ar->{hr_form} && $ar->{hr_form}) { | ||
| 169 | my $fr_hr = (ref($ar->{hr_form}) =~ /^HASH/) ? | ||
| 170 | $ar->{hr_form} : eval $ar->{hr_form}; | ||
| 171 | foreach my $k (keys %{$fr_hr}) { $fr{$k} = $fr_hr->{$k}; } | ||
| 172 | } | ||
| 173 | my $t = ""; | ||
| 174 | $t .= $q->start_form(%fr); | ||
| 175 | my $hvs = $s->set_param('vars_keep', $ar); | ||
| 176 | if ($hvs) { | ||
| 177 | foreach my $k (split /,/, $hvs) { | ||
| 178 | my $v = $s->set_param($k, $ar); | ||
| 179 | next if $v =~ /^\s*$/; | ||
| 180 | $t .= $q->hidden($k,$v); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | $t .= "$txt\n"; | ||
| 184 | $t .= $q->end_form . "\n"; | ||
| 185 | print $t if !$ret; | ||
| 186 | return $t if ($ret); | ||
| 187 | } | ||
| 188 | |||
| 189 | 1; | ||
| 190 | |||
| 191 | =head1 HISTORY | ||
| 192 | |||
| 193 | =over 4 | ||
| 194 | |||
| 195 | =item * Version 0.10 | ||
| 196 | |||
| 197 | This version extracted from jp2.pl on 09/08/2010. | ||
| 198 | |||
| 199 | =item * Version 0.20 | ||
| 200 | |||
| 201 | 09/08/2010 (htu): | ||
| 202 | 1. start this PM | ||
| 203 | |||
| 204 | =cut | ||
| 205 | |||
| 206 | =head1 SEE ALSO (some of docs that I check often) | ||
| 207 | |||
| 208 | Oracle::Loader, Oracle::Trigger, CGI::AppBuilder, File::Xcopy, | ||
| 209 | CGI::AppBuilder::Message | ||
| 210 | |||
| 211 | =head1 AUTHOR | ||
| 212 | |||
| 213 | Copyright (c) 2009 Hanming Tu. All rights reserved. | ||
| 214 | |||
| 215 | This package is free software and is provided "as is" without express | ||
| 216 | or implied warranty. It may be used, redistributed and/or modified | ||
| 217 | under the terms of the Perl Artistic License (see | ||
| 218 | http://www.perl.com/perl/misc/Artistic.html) | ||
| 219 | |||
| 220 | =cut | ||
| 221 |