| 1 | package CGI::AppBuilder::TaskDisps; | ||
| 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 File::Copy; | ||
| 14 | use File::Basename; | ||
| 15 | use Archive::Tar; | ||
| 16 | use IO::File; | ||
| 17 | use Net::Rexec 'rexec'; | ||
| 18 | |||
| 19 | our $VERSION = 0.12; | ||
| 20 | require Exporter; | ||
| 21 | our @ISA = qw(Exporter CGI::AppBuilder); | ||
| 22 | our @EXPORT = qw(); | ||
| 23 | our @EXPORT_OK = qw(disp_links build_links cc_andwhere | ||
| 24 | disp_client disp_project disp_study disp_job disp_hjob | ||
| 25 | disp_cptable disp_rpts disp_tabs disp_hids disp_archive | ||
| 26 | test_dbl check_droptabs check_chkids disp_htmlrpt | ||
| 27 | ); | ||
| 28 | our %EXPORT_TAGS = ( | ||
| 29 | all => [@EXPORT_OK] | ||
| 30 | ); | ||
| 31 | |||
| 32 | =head1 NAME | ||
| 33 | |||
| 34 | CGI::AppBuilder::TaskDisps - Display tasks | ||
| 35 | |||
| 36 | =head1 SYNOPSIS | ||
| 37 | |||
| 38 | use CGI::AppBuilder::TaskDisps; | ||
| 39 | |||
| 40 | my $sec = CGI::AppBuilder::TaskDisps->new(); | ||
| 41 | my ($sta, $msg) = $sec->exe_sql($ar); | ||
| 42 | |||
| 43 | =head1 DESCRIPTION | ||
| 44 | |||
| 45 | This class provides methods for reading and parsing configuration | ||
| 46 | files. | ||
| 47 | |||
| 48 | =cut | ||
| 49 | |||
| 50 | =head2 new (ifn => 'file.cfg', opt => 'hvS:') | ||
| 51 | |||
| 52 | This is a inherited method from CGI::AppBuilder. See the same method | ||
| 53 | in CGI::AppBuilder for more details. | ||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | sub new { | ||
| 58 | my ($s, %args) = @_; | ||
| 59 | return $s->SUPER::new(%args); | ||
| 60 | } | ||
| 61 | |||
| 62 | =head2 check_chkids($q,$ar) | ||
| 63 | |||
| 64 | Input variables: | ||
| 65 | |||
| 66 | $q - CGI class | ||
| 67 | $ar - array ref containing the following variables: | ||
| 68 | |||
| 69 | Variables used or routines called: | ||
| 70 | |||
| 71 | None | ||
| 72 | |||
| 73 | How to use: | ||
| 74 | |||
| 75 | Return: None | ||
| 76 | |||
| 77 | History: | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | sub check_chkids { | ||
| 82 | my ($s, $q, $ar) = @_; | ||
| 83 | |||
| 84 | my $prg = 'CGI::AppBuilder::TaskDisps->check_chkids'; | ||
| 85 | # 1. get variables | ||
| 86 | my ($sn,$dbl,$dbl_vars, $study_id,$study_name,$tnm,$xnm) = (); | ||
| 87 | $sn = $ar->{sid} if exists $ar->{sid}; | ||
| 88 | $sn = $ar->{target} if exists $ar->{target} && !$sn; | ||
| 89 | $sn = $ar->{sel_sn1} if exists $ar->{sel_sn1} && !$sn; | ||
| 90 | $study_id = $ar->{study_id} if exists $ar->{study_id}; | ||
| 91 | $study_name = $ar->{study_name} if exists $ar->{study_name}; | ||
| 92 | my $id = 'rule_version'; | ||
| 93 | my $r_vsn = (exists $ar->{$id} && $ar->{$id}) ? $ar->{$id} : ''; | ||
| 94 | $id = 'sel_list'; | ||
| 95 | my $r_dmn = (exists $ar->{$id} && $ar->{$id}) ? $ar->{$id} : ''; | ||
| 96 | $id = 'sel_rid'; | ||
| 97 | my $r_rid = (exists $ar->{$id} && $ar->{$id}) ? $ar->{$id} : ''; | ||
| 98 | $id = 'exl_list'; | ||
| 99 | my $r_exl = (exists $ar->{$id} && $ar->{$id}) ? $ar->{$id} : ''; | ||
| 100 | |||
| 101 | # 2. check required elements | ||
| 102 | if (!$sn) { | ||
| 103 | $s->echo_msg("ERR: ($prg) server name is not defined.", 0); return; | ||
| 104 | } | ||
| 105 | if ($study_id != 0 && !$study_id) { | ||
| 106 | $s->echo_msg("ERR: ($prg) study_id is not provided.", 0); return; | ||
| 107 | } | ||
| 108 | |||
| 109 | # 3. build where clause and SQL statements | ||
| 110 | |||
| 111 | my $wh1 = "WHERE upper(rule_status) = 'ACTIVE' "; | ||
| 112 | $wh1 .= ' AND (effective_date is null OR sysdate > effective_date) '; | ||
| 113 | $wh1 .= ' AND (expiration_date is null OR sysdate < expiration_date) '; | ||
| 114 | $wh1 .= $s->cc_andwhere($r_vsn, 'rule_version', 'and'); | ||
| 115 | $wh1 .= $s->cc_andwhere($r_dmn, 'rule_domain', 'and'); | ||
| 116 | $wh1 .= $s->cc_andwhere($r_rid, 'rule_id', 'and'); | ||
| 117 | $wh1 .= $s->cc_andwhere($r_exl, 'rule_domain', 'andnot'); | ||
| 118 | my $s1 = "SELECT rule_uid FROM cc_rules\n $wh1\n"; | ||
| 119 | my $wh2 = " WHERE rule_uid IN ($s1)\n"; | ||
| 120 | $wh2 .= " AND cc_status = 'A' \n"; | ||
| 121 | $wh2 .= " AND (cc_effective_date is null OR sysdate > cc_effective_date)\n"; | ||
| 122 | $wh2 .= " AND (cc_expiration_date is null OR sysdate < cc_expiration_date)\n"; | ||
| 123 | my $s2 = "SELECT chk_id FROM cc_checks\n $wh2\n"; | ||
| 124 | |||
| 125 | my $c1 = "rule_id,rule_domain,rule_version,severity,rule_description"; | ||
| 126 | my $r1 = $s->run_sqlcmd($ar,$c1,'cc_rules', $wh1, 1); | ||
| 127 | my $rec_cnt = $#$r1 + 1; | ||
| 128 | |||
| 129 | my $m = "($r_vsn:$r_dmn:$r_rid:$r_exl)"; | ||
| 130 | if (! $rec_cnt) { | ||
| 131 | $m = "ERR: ($prg) no rule id is found for Study $study_id $m."; | ||
| 132 | $s->echo_msg($m, 0); | ||
| 133 | return; | ||
| 134 | } | ||
| 135 | |||
| 136 | my $c2 = "chk_id"; | ||
| 137 | my $r2 = $s->run_sqlcmd($ar,$c2,'cc_checks',$wh2); | ||
| 138 | my $chk_ids = ''; | ||
| 139 | for my $i (0..$#$r2) { | ||
| 140 | $chk_ids .= ($chk_ids) ? "," : ''; | ||
| 141 | $chk_ids .= $r2->[$i]{chk_id}; | ||
| 142 | } | ||
| 143 | |||
| 144 | $s->echo_msg("SQL: $s1", 3); | ||
| 145 | $s->echo_msg("SQL: $s2", 3); | ||
| 146 | |||
| 147 | # 4. build html | ||
| 148 | my $t = "<table>\n"; | ||
| 149 | $t .= "<caption>Rule List In Study "; | ||
| 150 | $t .= (defined $study_id) ? "$study_id - " : ' - '; | ||
| 151 | $t .= (defined $study_name) ? "$study_name $m" : " $m"; | ||
| 152 | $t .= "</caption>\n"; | ||
| 153 | my $t1 = "<tr>\n"; | ||
| 154 | my $f_tr = "<tr class=%s>\n"; | ||
| 155 | my $c_cnt = 0; | ||
| 156 | for my $k (split /,/,$c1) { | ||
| 157 | ++$c_cnt; | ||
| 158 | $t1 .= " <th>" . ucfirst($k) . "</th>\n"; | ||
| 159 | $f_tr .= " <td>%s</td>\n"; | ||
| 160 | } | ||
| 161 | $t1 .= "</tr>\n"; | ||
| 162 | $f_tr .= "</tr>\n"; | ||
| 163 | $t .= $t1; | ||
| 164 | for my $i (0..$#$r1) { | ||
| 165 | my @rec = (); | ||
| 166 | push @rec, (($i % 2 == 0) ? 'even' : 'odd'); | ||
| 167 | for my $k (split /,/,$c1) { | ||
| 168 | my $v = $r1->[$i]{$k}; | ||
| 169 | push @rec, ($v !~ /^\s*$/) ? $v : ' '; | ||
| 170 | } | ||
| 171 | $t .= sprintf $f_tr, @rec; | ||
| 172 | } | ||
| 173 | $t .= "<tr><td colspan=$c_cnt>"; | ||
| 174 | $t .= "<b>Total $rec_cnt records: </b>$chk_ids</td>\n</tr>\n"; | ||
| 175 | $t .= "</table>\n"; | ||
| 176 | |||
| 177 | # 5. print html | ||
| 178 | |||
| 179 | print $t; | ||
| 180 | return; | ||
| 181 | } | ||
| 182 | |||
| 183 | |||
| 184 | =head2 check_droptabs($q,$ar) | ||
| 185 | |||
| 186 | Input variables: | ||
| 187 | |||
| 188 | $q - CGI class | ||
| 189 | $ar - array ref containing the following variables: | ||
| 190 | |||
| 191 | Variables used or routines called: | ||
| 192 | |||
| 193 | None | ||
| 194 | |||
| 195 | How to use: | ||
| 196 | |||
| 197 | Return: None | ||
| 198 | |||
| 199 | History: | ||
| 200 | |||
| 201 | =cut | ||
| 202 | |||
| 203 | sub check_droptabs { | ||
| 204 | my ($s, $q, $ar) = @_; | ||
| 205 | |||
| 206 | my $prg = 'CGI::AppBuilder::TaskDisps->check_droptabs'; | ||
| 207 | # 1. get variables | ||
| 208 | my ($sn,$dbl,$dbl_vars, $study_id,$study_name,$tnm,$xnm) = (); | ||
| 209 | $sn = $ar->{sid} if exists $ar->{sid}; | ||
| 210 | $sn = $ar->{target} if exists $ar->{target} && !$sn; | ||
| 211 | $sn = $ar->{sel_sn1} if exists $ar->{sel_sn1} && !$sn; | ||
| 212 | $study_id = $ar->{study_id} if exists $ar->{study_id}; | ||
| 213 | $study_name = $ar->{study_name} if exists $ar->{study_name}; | ||
| 214 | my $obj_vars = (exists $ar->{obj_vars}) ? $ar->{obj_vars} : ''; | ||
| 215 | if ($obj_vars) { | ||
| 216 | foreach my $k (split /,/, $obj_vars) { | ||
| 217 | $tnm = uc($ar->{$k}) if exists $ar->{$k} && $ar->{$k}; | ||
| 218 | } | ||
| 219 | } | ||
| 220 | $tnm = '%FINAL' if !$tnm; | ||
| 221 | my $exc_vars = (exists $ar->{exc_vars}) ? $ar->{exc_vars} : ''; | ||
| 222 | if ($exc_vars) { | ||
| 223 | for my $k (split /,/, $exc_vars) { | ||
| 224 | $xnm = uc($ar->{$k}) if !$xnm && exists $ar->{$k}; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | # 2. check required elements | ||
| 229 | if (!$sn) { | ||
| 230 | $s->echo_msg("ERR: server name is not defined.", 0); return; | ||
| 231 | } | ||
| 232 | if ($study_id != 0 && !$study_id) { | ||
| 233 | $s->echo_msg("ERR: study_id is not provided.", 0); return; | ||
| 234 | } | ||
| 235 | |||
| 236 | # 3. get study schema and DBL | ||
| 237 | |||
| 238 | my $whr = "where study_id = $study_id order by study_id"; | ||
| 239 | my $rr = $s->run_sqlcmd($ar,'study_name,stg_schema,stg_dbl','cc_studies', $whr); | ||
| 240 | |||
| 241 | if ($#$rr < 0) { | ||
| 242 | $s->echo_msg("ERR: could not find study_id - $study_id in study table.", 0); | ||
| 243 | return; | ||
| 244 | } | ||
| 245 | $study_name = $rr->[0]{study_name} if !$study_name; | ||
| 246 | my $stg_sch = uc $rr->[0]{stg_schema}; | ||
| 247 | my $stg_dbl = uc $rr->[0]{stg_dbl}; | ||
| 248 | if (!$stg_sch ) { | ||
| 249 | $s->echo_msg("ERR: could not find stg_schema($stg_sch).",0); | ||
| 250 | return; | ||
| 251 | } | ||
| 252 | $s->echo_msg("INFO: STG_SCH=$stg_sch, STG_DBL=$stg_dbl", 3); | ||
| 253 | |||
| 254 | # 4. get all tables from staging schema | ||
| 255 | my $r = {}; # result array ref | ||
| 256 | my ($wh1,$wh2,$r1,$r2) = (); | ||
| 257 | |||
| 258 | # get number of rows for the tables | ||
| 259 | $wh1 = $s->cc_andwhere($stg_sch, 'owner', 'where'); | ||
| 260 | $wh1 .= $s->cc_andwhere($tnm, 'table_name', 'and'); | ||
| 261 | $wh1 .= $s->cc_andwhere($xnm, 'table_name', 'andnot'); | ||
| 262 | $r1 = $s->run_sqlcmd($ar,'table_name,num_rows','all_tables', $wh1); | ||
| 263 | $wh2 = $s->cc_andwhere($stg_sch, 'owner', 'where'); | ||
| 264 | $wh2 .= $s->cc_andwhere('TABLE', 'object_type', 'and'); | ||
| 265 | $wh2 .= $s->cc_andwhere($tnm, 'object_name', 'and'); | ||
| 266 | $wh2 .= $s->cc_andwhere($xnm, 'object_name', 'andnot'); | ||
| 267 | $r2 = $s->run_sqlcmd($ar,'object_name,last_ddl_time','all_objects', $wh2); | ||
| 268 | # $s->echo_msg("WH1=$wh1; WH2=$wh2",0); | ||
| 269 | for my $i (0..$#$r1) { | ||
| 270 | my $k = $r1->[$i]{table_name}; | ||
| 271 | $r->{$k} = {} if !exists $r->{$k}; | ||
| 272 | $r->{$k}{t_rows} = $r1->[$i]{num_rows}; | ||
| 273 | } | ||
| 274 | for my $i (0..$#$r2) { | ||
| 275 | my $k = $r2->[$i]{object_name}; | ||
| 276 | $r->{$k} = {} if !exists $r->{$k}; | ||
| 277 | $r->{$k}{t_time} = $r2->[$i]{last_ddl_time}; | ||
| 278 | } | ||
| 279 | |||
| 280 | # 5. build html | ||
| 281 | my $f_th = " <tr><th>%s\n <th>%s\n <th>%s\n </tr>\n"; | ||
| 282 | my $f_tr = " <tr class=%s><td>%s\n <td>%s\n "; | ||
| 283 | $f_tr .= "<td align=right>%s\n </tr>\n"; | ||
| 284 | my $rec_cnt = 0; | ||
| 285 | my $t = "<font color=red>The following tables will be dropped if you click "; | ||
| 286 | $t .= "the <b>Go</b> button:</font> <br><br>\n"; | ||
| 287 | $t .= "<table>\n"; | ||
| 288 | $t .= "<caption>Tables In Study $study_id - $study_name<br>"; | ||
| 289 | $t .= "($stg_sch;$tnm;$xnm)</caption>\n"; | ||
| 290 | $t .= sprintf $f_th, "Table Name", "DDL Time", "Num of Rows"; | ||
| 291 | my @rec = (); | ||
| 292 | foreach my $k (sort keys %$r) { | ||
| 293 | $rec_cnt += 1; | ||
| 294 | my @rec = (); | ||
| 295 | push @rec, (($rec_cnt % 2 == 0) ? 'even' : 'odd'); | ||
| 296 | push @rec, $k; | ||
| 297 | foreach my $j (split /,/,'t_time,t_rows') { | ||
| 298 | push @rec,((!exists $r->{$k}{$j}) ? '<b>N/A</b>' : | ||
| 299 | (($r->{$k}{$j})?$r->{$k}{$j}:' ')); | ||
| 300 | } | ||
| 301 | $t .= sprintf $f_tr, @rec; | ||
| 302 | } | ||
| 303 | $t .= "</table>\n"; | ||
| 304 | $t .= "<b>Total $rec_cnt records.</b>\n"; | ||
| 305 | |||
| 306 | # 6. print html | ||
| 307 | |||
| 308 | if (! $rec_cnt) { | ||
| 309 | my $m = "ERR: no table is found for Study $study_id ($tnm)."; | ||
| 310 | $s->echo_msg($m, 0); | ||
| 311 | return; | ||
| 312 | } | ||
| 313 | print $t; | ||
| 314 | return; | ||
| 315 | } | ||
| 316 | |||
| 317 | |||
| 318 | =head2 test_dbl($q,$ar) | ||
| 319 | |||
| 320 | Input variables: | ||
| 321 | |||
| 322 | $q - CGI class | ||
| 323 | $ar - array ref containing the following variables: | ||
| 324 | |||
| 325 | Variables used or routines called: | ||
| 326 | |||
| 327 | None | ||
| 328 | |||
| 329 | How to use: | ||
| 330 | |||
| 331 | Return: None | ||
| 332 | |||
| 333 | History: | ||
| 334 | |||
| 335 | =cut | ||
| 336 | |||
| 337 | sub test_dbl { | ||
| 338 | my ($s, $q, $ar) = @_; | ||
| 339 | |||
| 340 | my $prg = 'CGI::AppBuilder::TaskDisps->test_dbl'; | ||
| 341 | # 1. get variables | ||
| 342 | my ($sn,$dbl,$dbl_vars, $study_id,$study_name) = (); | ||
| 343 | $sn = $ar->{sid} if exists $ar->{sid}; | ||
| 344 | $sn = $ar->{target} if exists $ar->{target} && !$sn; | ||
| 345 | $sn = $ar->{sel_sn1} if exists $ar->{sel_sn1} && !$sn; | ||
| 346 | $study_id = $ar->{study_id} if exists $ar->{study_id}; | ||
| 347 | $study_name = $ar->{study_name} if exists $ar->{study_name}; | ||
| 348 | $dbl_vars = $ar->{dbl_vars} if exists $ar->{dbl_vars}; | ||
| 349 | if ($dbl_vars) { | ||
| 350 | foreach my $k (split /,/, $dbl_vars) { | ||
| 351 | $dbl = $ar->{$k} if exists $ar->{$k} && $ar->{$k}; | ||
| 352 | } | ||
| 353 | } | ||
| 354 | $s->echo_msg("INFO: ($prg) DBL: $dbl",3); | ||
| 355 | |||
| 356 | # 2. check required elements | ||
| 357 | if (!$dbl) { | ||
| 358 | $s->echo_msg("ERR: ($prg) no DB Link is specified.", 1); | ||
| 359 | $s->echo_msg("Please select a Source DBL.", 1); | ||
| 360 | return; | ||
| 361 | } | ||
| 362 | my $pid = $ar->{pid}; # project id: ckpt, dba, owb | ||
| 363 | my $url = $ar->{web_url}; # web URL | ||
| 364 | $url .= "?pid=$pid&no_dispform=1&task=run_dropdbl&sel_sn1=$sn"; | ||
| 365 | $url .= "&sel_sn2=$dbl"; | ||
| 366 | |||
| 367 | # 3. get db link | ||
| 368 | my $whr = ""; | ||
| 369 | my $cns = 'sysdate as sys_dtm'; | ||
| 370 | my $rr = $s->run_sqlcmd($ar,$cns,"dual\@$dbl", $whr); | ||
| 371 | my $dbl_flag = 1; | ||
| 372 | |||
| 373 | my $msg = ''; | ||
| 374 | if (! exists $rr->[0]{sys_dtm}) { | ||
| 375 | $msg = "ERR: DBL - $dbl is not valid. "; | ||
| 376 | $dbl_flag = 0; | ||
| 377 | } else { | ||
| 378 | $msg = "INFO: DBL - $dbl is valid and got DTM ($rr->[0]{sys_dtm})"; | ||
| 379 | } | ||
| 380 | $s->echo_msg($msg, 0); | ||
| 381 | |||
| 382 | # 4. get a list of DBL | ||
| 383 | $whr = "where UPPER(db_link) like UPPER('$dbl%')"; | ||
| 384 | $cns = 'owner,db_link,username,host,created'; | ||
| 385 | $rr = $s->run_sqlcmd($ar,$cns,"dba_db_links", $whr); | ||
| 386 | my $cn = [split /,/, $cns]; | ||
| 387 | |||
| 388 | # 5. build html | ||
| 389 | my $f_th = " <th>%s</th>\n"; | ||
| 390 | my $f_td = " <td>%s</td>\n"; | ||
| 391 | my $f_tr = " <tr>\n%s</tr>\n"; | ||
| 392 | my ($t, $t1) = (); | ||
| 393 | my $rec_cnt = 0; | ||
| 394 | $t = "<p><p>\n<table border=1>\n"; | ||
| 395 | $t .= "<caption>Table DB Link Detail for $dbl</caption>\n"; | ||
| 396 | for my $i (0..$#$cn) { | ||
| 397 | $t1 .= sprintf $f_th, ucfirst($cn->[$i]); | ||
| 398 | } | ||
| 399 | $t .= sprintf $f_tr, $t1; | ||
| 400 | $rec_cnt = $#$rr + 1; | ||
| 401 | for my $i (0..$#$rr) { | ||
| 402 | $t1 = ''; | ||
| 403 | for my $j (0..$#$cn) { | ||
| 404 | my $k = $cn->[$j]; | ||
| 405 | $t1 .= sprintf $f_td, $rr->[$i]{$k}; | ||
| 406 | } | ||
| 407 | $t .= sprintf $f_tr, $t1; | ||
| 408 | } | ||
| 409 | $t .= "</table>\n"; | ||
| 410 | $t .= "<b>Total $rec_cnt records.</b>\n"; | ||
| 411 | |||
| 412 | # 6. print html | ||
| 413 | |||
| 414 | if (! $rec_cnt) { | ||
| 415 | my $m = "ERR: no record found for DBL $dbl."; | ||
| 416 | $s->echo_msg($m, 0); | ||
| 417 | return; | ||
| 418 | } else { | ||
| 419 | if (! $dbl_flag) { | ||
| 420 | $msg = "You can remove this invalid DBL by click "; | ||
| 421 | $msg .= "<a href='$url'>Remove $dbl</a>."; | ||
| 422 | $s->echo_msg($msg, 0); | ||
| 423 | } | ||
| 424 | } | ||
| 425 | print $t; | ||
| 426 | return; | ||
| 427 | } | ||
| 428 | |||
| 429 | |||
| 430 | =head2 disp_archive($q,$ar) | ||
| 431 | |||
| 432 | Input variables: | ||
| 433 | |||
| 434 | $q - CGI class | ||
| 435 | $ar - array ref containing the following variables: | ||
| 436 | |||
| 437 | Variables used or routines called: | ||
| 438 | |||
| 439 | None | ||
| 440 | |||
| 441 | How to use: | ||
| 442 | |||
| 443 | Return: None | ||
| 444 | |||
| 445 | =cut | ||
| 446 | |||
| 447 | sub disp_archive { | ||
| 448 | my ($s, $q, $ar) = @_; | ||
| 449 | |||
| 450 | my $prg = "AppBuilder::TaskDisps->disp_archive"; | ||
| 451 | # 1. get variables | ||
| 452 | $s->echo_msg("1. get variables", 2); | ||
| 453 | |||
| 454 | my $pid = (exists $ar->{pid}) ? $ar->{pid} : ''; | ||
| 455 | my $sn = (exists $ar->{sid}) ? $ar->{sid} : ''; | ||
| 456 | $sn = $ar->{target} if exists $ar->{target} && !$sn; | ||
| 457 | $sn = $ar->{sel_sn1} if exists $ar->{sel_sn1} && !$sn; | ||
| 458 | my $ds = (exists $ar->{dir_sep}) ? $ar->{dir_sep} : ''; | ||
| 459 | $ds = ($^O =~ /^MSWin/i) ? '\\' : '/' if ! $ds; | ||
| 460 | my $adr = (exists $ar->{arch_dir}) ? (join $ds, $ar->{arch_dir}, $sn) : ''; | ||
| 461 | my $odr = eval $s->set_param('out_dir', $ar); # output dir | ||
| 462 | my $rdr = (exists $odr->{$sn}{rpt}) ? $odr->{$sn}{rpt} : ''; # rpt dir | ||
| 463 | my $dsp = (exists $odr->{$sn}{dsp}) ? $odr->{$sn}{dsp} : ''; # dsp url | ||
| 464 | $dsp = (exists $ar->{script_url}) ? $ar->{script_url} :'' if !$dsp; | ||
| 465 | $s->echo_msg("WARN: ($prg) DSP URL is not defined.", 1) if ! $dsp; | ||
| 466 | $dsp .= '?' . "pid=$pid&target=$sn&task=disp_file&f="; | ||
| 467 | |||
| 468 | my $css_style = (exists $ar->{css_style}) ? $ar->{css_style} : ''; | ||
| 469 | my $dsp_owb = (exists $ar->{dsp_owb}) ? $ar->{dsp_owb} : ''; | ||
| 470 | my $dsp_dir = (exists $ar->{dsp_dir}) ? $ar->{dsp_dir} : ''; | ||
| 471 | my $rpt_kp = (exists $ar->{rpt_keep}) ? $ar->{rpt_keep} : ''; # seconds | ||
| 472 | |||
| 473 | # my ($jid,$hid) = (); | ||
| 474 | my $study_id = (exists $ar->{study_id}) ? $ar->{study_id} : ''; | ||
| 475 | my $study_name= (exists $ar->{study_name})? $ar->{study_name}: ''; | ||
| 476 | my $job_id = (exists $ar->{job_id}) ? $ar->{job_id} : ''; | ||
| 477 | my $hjob_id = (exists $ar->{hjob_id}) ? $ar->{hjob_id} : ''; | ||
| 478 | |||
| 479 | $s->echo_msg("INFO: ($prg) RDR - $rdr<br>\nDSP - $dsp",3); | ||
| 480 | |||
| 481 | # 2. check required elements | ||
| 482 | $s->echo_msg("2. check required variables", 2); | ||
| 483 | if (! -d $ar->{arch_dir}) { | ||
| 484 | $s->echo_msg("ERR: ($prg) could not find archive dir - $ar->{arch_dir}.", 0); | ||
| 485 | return; | ||
| 486 | } | ||
| 487 | $s->echo_msg("INFO: mkpath - $adr", 2); | ||
| 488 | eval { mkpath($adr) }; | ||
| 489 | $s->echo_msg("ERR: ($prg) couldn't create $adr: $@", 0) if ($@); | ||
| 490 | |||
| 491 | if (! -d $rdr) { | ||
| 492 | $s->echo_msg("ERR: ($prg) could not find rpt dir - $rdr.", 0); return; | ||
| 493 | } | ||
| 494 | |||
| 495 | if (! -f $css_style) { | ||
| 496 | $s->echo_msg("WARN: ($prg) could not find css style file - $css_style.", 1); | ||
| 497 | } | ||
| 498 | |||
| 499 | # 3. get study id | ||
| 500 | $s->echo_msg("3. get study id and name", 2); | ||
| 501 | my $studyid = $s->get_studyid($ar); # study ids | ||
| 502 | my $sd = {}; # study id hash array | ||
| 503 | for my $i (0..$#$studyid) { | ||
| 504 | $sd->{$studyid->[$i][0]} = $studyid->[$i][1]; | ||
| 505 | } | ||
| 506 | $s->echo_msg($sd, 3); | ||
| 507 | |||
| 508 | # 4. get all index files | ||
| 509 | $s->echo_msg("4. get all index files", 2); | ||
| 510 | # my $fname = 'index'; | ||
| 511 | # opendir DD, "$rdr" or die "ERR: could not opendir - $rdr: $!\n"; | ||
| 512 | # my @a = sort grep !/\.bak$/, (grep /$fname/, readdir DD); | ||
| 513 | # closedir DD; | ||
| 514 | $ar->{job_id} = ''; # remove job_id to use study_id to get_htmlrpts | ||
| 515 | my $rr = $s->get_htmlrpts($ar); | ||
| 516 | $ar->{job_id} = $job_id; | ||
| 517 | $s->echo_msg($rr, 3); | ||
| 518 | my @a = (); | ||
| 519 | for my $i (0..$#$rr) { | ||
| 520 | $a[$i] = $rr->[$i]{stat}{fn}; | ||
| 521 | } | ||
| 522 | $s->echo_msg("INFO: Found " . ($#a+1) . " index files", 3); | ||
| 523 | |||
| 524 | # 5. loop through each file | ||
| 525 | $s->echo_msg("5. build index file array", 2); | ||
| 526 | my $r = {}; # result array ref | ||
| 527 | my $rpt_cnt = 0; | ||
| 528 | my @b = (); | ||
| 529 | my ($ctm, $tit,$sub, $sb2) = (); | ||
| 530 | my $dft = "%Y/%m/%d %H:%M:%S"; | ||
| 531 | for my $i (0..$#a) { | ||
| 532 | my ($fn) = ($a[$i] =~ m/(rpt\d+_\d+_\d+_\d+_\w+\.\w+)/); | ||
| 533 | my $f2 = $rr->[$i]{fn2}; # report file name | ||
| 534 | $s->echo_msg("processing $f2 ($fn)...", 3); | ||
| 535 | my ($sid, $jid, $hid, $hms) = ($fn =~ m/rpt(\d+)_(\d+)_(\d+)_(\d+)/); | ||
| 536 | next if ($study_id =~ /^\d+$/) && $study_id != $sid; | ||
| 537 | next if ($job_id =~ /^\d+$/) && $job_id != $jid; | ||
| 538 | next if ($hjob_id =~ /^\d+$/) && $hjob_id != $hid; | ||
| 539 | if (-f $f2) { | ||
| 540 | $rpt_cnt += 1; | ||
| 541 | @b = stat "$f2"; | ||
| 542 | $ctm = strftime $dft, localtime($b[9]); | ||
| 543 | } else { | ||
| 544 | $ctm = ''; | ||
| 545 | $s->echo_msg("WARN: could not find file - $f2.", 2); | ||
| 546 | } | ||
| 547 | $tit = sprintf "S%03dJ%04dH%05d", $sid, $jid, $hid; | ||
| 548 | $sub = sprintf "S%05d${ds}J%05d${ds}H%05d$ds%d", $sid, $jid, $hid, $hms; | ||
| 549 | $sb2 = sprintf "S%05d${ds}J%05d${ds}H%05d$ds%d", $sid, $jid, $hid, $hms; | ||
| 550 | $r->{$sid} = [] if !exists $r->{$sid}; | ||
| 551 | push @{$r->{$sid}}, {dsp=>"$dsp$f2",ctm=>$ctm,fn=>$fn,f2=>$f2,t=>$tit, | ||
| 552 | rdr=>$rdr,adr=>$adr, sub=>$sub, | ||
| 553 | # ffn=>"$rdr/$fn", | ||
| 554 | ffn=>$f2, | ||
| 555 | dsp_owb=>"$dsp_owb$ds$sn$ds$sub", ptm=>$b[9], | ||
| 556 | dsp_dir=>"$dsp_dir$ds$sn$ds$sb2" | ||
| 557 | }; | ||
| 558 | # print "$a[$i] - $sid:$jid:$hid:$hms:$ctm<br>\n"; | ||
| 559 | } | ||
| 560 | $s->echo_msg($r,3); | ||
| 561 | |||
| 562 | # 6. archive the reports | ||
| 563 | $s->echo_msg("6. archive reports", 2); | ||
| 564 | foreach my $k (sort keys %$r) { | ||
| 565 | for my $i (0..$#{$r->{$k}}) { | ||
| 566 | my $p = $r->{$k}[$i]; | ||
| 567 | my $tm1 = $p->{ptm}; | ||
| 568 | my $rd = $p->{rdr}; | ||
| 569 | my $sd = $p->{sub}; | ||
| 570 | my $ffn = $p->{ffn}; # from file name | ||
| 571 | my $fn = $p->{fn}; # just file name | ||
| 572 | my $dr = join $ds, $adr, $sd; # output dir | ||
| 573 | my $ofn = join $ds, $adr, $sd, $fn; # output file name | ||
| 574 | my ($f_n, $f_p, $sfx) = fileparse($ffn,qr{\..*}); | ||
| 575 | if ($^O =~ /^MSWin/i) { | ||
| 576 | $f_p =~ s/\\$//; # remove the ending $ds | ||
| 577 | } else { | ||
| 578 | $f_p =~ s/\/$//; # remove the ending $ds | ||
| 579 | } | ||
| 580 | # 6.1 check if the target file exist and older than current on | ||
| 581 | $s->echo_msg("INFO: 6.1 - check file $ofn...", 3); | ||
| 582 | if (-f $ofn) { | ||
| 583 | my $tm2 = (stat $ofn)[9]; | ||
| 584 | if ($tm2 > $tm1) { | ||
| 585 | $s->echo_msg("INFO: $fn - skipped.", 3); | ||
| 586 | next; | ||
| 587 | } | ||
| 588 | } | ||
| 589 | $s->echo_msg("INFO: $ffn<br>--->: $ofn...",1); | ||
| 590 | # 6.2 make target dir | ||
| 591 | $s->echo_msg("INFO: 6.2 - check dir $dr...", 3); | ||
| 592 | if (!-d $dr) { | ||
| 593 | $s->echo_msg("INFO: mkpath - $dr", 3); | ||
| 594 | eval { mkpath($dr) }; | ||
| 595 | $s->echo_msg("ERR: couldn't create $dr: $@", 0) if ($@); | ||
| 596 | } | ||
| 597 | # 6.3 copy the css style file to the target folder | ||
| 598 | $s->echo_msg("INFO: 6.3 - copy file $css_style to $dr...", 3); | ||
| 599 | copy $css_style, $dr if $css_style; | ||
| 600 | |||
| 601 | # 6.4 open the index file and target file | ||
| 602 | $s->echo_msg("INFO: 6.4 - read from $ffn...", 3); | ||
| 603 | if (! -f $ffn) { | ||
| 604 | $s->echo_msg("WARN: 6.4 - could not find file $ffn.", 3); | ||
| 605 | next; | ||
| 606 | } | ||
| 607 | if (!(open IDX, "<$ffn")) { | ||
| 608 | $s->echo_msg("ERR: could not open file - $ffn: $!",0); | ||
| 609 | next; | ||
| 610 | } | ||
| 611 | $s->echo_msg("INFO: 6.4 - write to $ofn...", 3); | ||
| 612 | if (! (open OFN, ">$ofn")) { | ||
| 613 | $s->echo_msg("ERR: could not write to file - $ofn: $!",0); | ||
| 614 | next; | ||
| 615 | } | ||
| 616 | while (<IDX>) { | ||
| 617 | my $rec = $_; | ||
| 618 | # href="http://ors2di/cgi/dsp.pl?t=vpapp2&f=logs/rpts/rpt92_287_646_115805_10268.htm" | ||
| 619 | # href="http://ors-owbtest2:7777/cgi/cpp2.pl?pid=ckpt&target=vpapp2&task=disp_file&f=\\vpapp2\share\ckpt_vpapp2\rpts\OracleServicesAdmin\2012\01\09\rpt236_812_1728_173640_10007.htm" | ||
| 620 | my ($f0,$f1) = ($rec =~ m/\"(http:.+)(rpt\d+_\d+_\d+_\d+_\w+\.\w+)\"/); | ||
| 621 | if ($f0 && $f1) { | ||
| 622 | my $ifn2 = join $ds, $f_p, $f1; | ||
| 623 | my $ofn2 = join $ds, $adr, $sd, $f1; | ||
| 624 | $rec =~ s/\"(http:.+)\"/\"$f1\"/; | ||
| 625 | $s->echo_msg("INFO: copying $ifn2 to $ofn2",3); | ||
| 626 | # copy($ifn2,$ofn2); | ||
| 627 | if (!(open IFN2, "<$ifn2")) { | ||
| 628 | $s->echo_msg("ERR: (IFN2) could not open - $ifn2: $!",0); | ||
| 629 | next; | ||
| 630 | } | ||
| 631 | if (!(open OFN2, ">$ofn2")) { | ||
| 632 | $s->echo_msg("ERR: (OFN2) could not write to $ofn2: $!",0); | ||
| 633 | close IFN2; | ||
| 634 | next; | ||
| 635 | } | ||
| 636 | while (<IFN2>) { | ||
| 637 | if ($_ =~ m/(href\=\"\/styles\/)/ ) { | ||
| 638 | $_ =~ s/(href\=\"\/styles\/)/href\=\"/; | ||
| 639 | } | ||
| 640 | print OFN2 $_; | ||
| 641 | } | ||
| 642 | close IFN2; | ||
| 643 | close OFN2; | ||
| 644 | } elsif ($rec =~ m/(href\=\"\/styles\/)/ ) { | ||
| 645 | # <link rel="stylesheet" type="text/css" href="/styles/dfcommon.css" /> | ||
| 646 | $rec =~ s/(href\=\"\/styles\/)/href\=\"/; | ||
| 647 | } elsif ($rec =~ m/(href\=\"mailto:)/ ) { | ||
| 648 | # <link rev="made" href="mailto:Hanming.Tu@gmail.com"/> | ||
| 649 | $rec =~ s/(href\=\"mailto):([\w\.\@]+)\"/$1:htu\@octagonresearch.com\"/; | ||
| 650 | } elsif ($rec =~ m/(content\=\"copyright)/ ) { | ||
| 651 | # <meta name="copyright" content="copyright 2010 Hanming Tu" /> | ||
| 652 | $rec =~ s/(content\=\"copyright)\s*(\d+)\s*([\w ]+)\"/$1 $2 Octagon Research Solutions\"/; | ||
| 653 | } | ||
| 654 | print OFN $rec; | ||
| 655 | } | ||
| 656 | close OFN; | ||
| 657 | close IDX; | ||
| 658 | } | ||
| 659 | } | ||
| 660 | |||
| 661 | # 7. tar and compress reports | ||
| 662 | $s->echo_msg("7. tar and gzip reports", 2); | ||
| 663 | my $gzp_prg = ""; | ||
| 664 | $gzp_prg = $ar->{arch_prg} if exists $ar->{arch_prg}; | ||
| 665 | my $ad2 = "$adr/archived"; | ||
| 666 | if (!-d $ad2) { | ||
| 667 | $s->echo_msg("INFO: mkpath - $ad2", 3); | ||
| 668 | eval { mkpath($ad2) }; | ||
| 669 | $s->echo_msg("ERR: ($prg) couldn't create $ad2: $@", 0) if ($@); | ||
| 670 | } | ||
| 671 | my ($css_fn, $path, $sfx) = fileparse($css_style,qr{\..*}); | ||
| 672 | foreach my $k (sort keys %$r) { | ||
| 673 | for my $i (0..$#{$r->{$k}}) { | ||
| 674 | my $p = $r->{$k}[$i]; | ||
| 675 | my $dp = $p->{dsp}; | ||
| 676 | my $rd = $p->{rdr}; | ||
| 677 | my $tm = $p->{ptm}; | ||
| 678 | my $fn = $p->{fn}; | ||
| 679 | my $sd = $p->{sub}; | ||
| 680 | my $elp = time - $tm; | ||
| 681 | my $rt = $fn; $rt =~ s/_index\.htm//; | ||
| 682 | my $sd2 = $sd; $sd2 =~ s/\/\w+$//; | ||
| 683 | my ($tf1,$tf2) = (); | ||
| 684 | if ($^O =~ /^MSWin/i) { | ||
| 685 | $tf1 = join $ds, $ad2, "$rt.tar"; | ||
| 686 | $tf2 = join $ds, $adr, $sd2, "$rt.tar"; | ||
| 687 | if ($gzp_prg && -f $gzp_prg) { | ||
| 688 | # $p->{dsp_tgz} = "$dsp_owb/$sn/$sd2/$rt.tar.gz"; | ||
| 689 | $p->{dsp_tgz} = join $ds, "$dsp$p->{adr}",$p->{sub},"$rt.tar.gz"; | ||
| 690 | $p->{fn_tgz} = "$rt.tar.gz"; | ||
| 691 | } else { | ||
| 692 | # $p->{dsp_tgz} = "$dsp_owb/$sn/$sd2/$rt.tar"; | ||
| 693 | $p->{dsp_tgz} = join $ds, "$dsp$p->{adr}",$p->{sub},"$rt.tar"; | ||
| 694 | $p->{fn_tgz} = "$rt.tar"; | ||
| 695 | } | ||
| 696 | } else { | ||
| 697 | $tf1 = join $ds, $ad2, "$rt.tgz"; | ||
| 698 | $tf2 = join $ds, $adr, $sd2, "$rt.tgz"; | ||
| 699 | # $p->{dsp_tgz} = "$dsp_owb/$sn/$sd2/$rt.tgz"; | ||
| 700 | $p->{dsp_tgz} = join $ds,"$dsp$p->{adr}",$p->{sub},"$rt.tgz"; | ||
| 701 | $p->{fn_tgz} = "$rt.tgz"; | ||
| 702 | } | ||
| 703 | my ($tm1, $tm2) = (0,0); | ||
| 704 | $tm1 = (stat $tf1)[9] if -f $tf1; | ||
| 705 | $tm2 = (stat $tf2)[9] if -f $tf2; | ||
| 706 | if ($tm > $tm1 || $elp >= $rpt_kp) { | ||
| 707 | $s->echo_msg("INFO: reading $rd...", 2); | ||
| 708 | opendir RD, "$rd" || $s->echo_msg("WARN: (RD) could not opendir - $rd: $!", 0); | ||
| 709 | my @a = map {join $ds, $rdr, $_; } sort grep !/\.bak$/, (grep /$rt/, readdir RD); | ||
| 710 | closedir RD; | ||
| 711 | $p->{old_fns} = []; | ||
| 712 | for my $i (0..$#a) { $p->{old_fns}[$i] = $a[$i]; } | ||
| 713 | } | ||
| 714 | # archived the original files | ||
| 715 | if (!-f $tf1 || $tm > $tm1) { | ||
| 716 | unlink $tf1 if -f $tf1; | ||
| 717 | my $fh1; | ||
| 718 | my $tar = Archive::Tar->new(); | ||
| 719 | if ($^O =~ /^MSWin/i) { | ||
| 720 | $fh1 = new IO::File " > $tf1"; | ||
| 721 | } else { | ||
| 722 | $fh1 = new IO::File "| /usr/bin/compress -c > $tf1"; | ||
| 723 | } | ||
| 724 | $tar->setcwd($rd); | ||
| 725 | $tar->add_files(@{$p->{old_fns}}); | ||
| 726 | $tar->write($fh1); | ||
| 727 | $fh1->close ; | ||
| 728 | if ($^O =~ /^MSWin/i && $gzp_prg && -f $gzp_prg) { | ||
| 729 | system($gzp_prg, $tf1) == 0 || | ||
| 730 | $s->echo_msg("ERR: could not run $gzp_prg $tf1",0); | ||
| 731 | } | ||
| 732 | } | ||
| 733 | # archived formated files | ||
| 734 | if (!-f $tf2 || $tm > $tm2) { | ||
| 735 | unlink $tf2 if -f $tf2; | ||
| 736 | my $d2 = join $ds, $adr, $sd; | ||
| 737 | opendir RD, "$d2" || $s->echo_msg("WARN: could not opendir - $d2: $!", 0); | ||
| 738 | my @b = map {join $ds, $d2, $_; } sort grep !/\.bak$/, (grep /$rt/, readdir RD); | ||
| 739 | closedir RD; | ||
| 740 | my $fh2; | ||
| 741 | my $ta2 = Archive::Tar->new(); | ||
| 742 | if ($^O =~ /^MSWin/i) { | ||
| 743 | $fh2 = new IO::File " > $tf2"; | ||
| 744 | } else { | ||
| 745 | $fh2 = new IO::File "| /usr/bin/compress -c > $tf2"; | ||
| 746 | } | ||
| 747 | $ta2->setcwd("$d2"); | ||
| 748 | $ta2->add_files(@b); | ||
| 749 | $ta2->write($fh2); | ||
| 750 | $fh2->close ; | ||
| 751 | if ($^O =~ /^MSWin/i && $gzp_prg && -f $gzp_prg) { | ||
| 752 | system($gzp_prg, $tf2) == 0 || | ||
| 753 | $s->echo_msg("ERR: could not run $gzp_prg $tf2",0); | ||
| 754 | } | ||
| 755 | } | ||
| 756 | if ($elp < $rpt_kp) { | ||
| 757 | $s->echo_msg("INFO: $fn is still young.", 2); | ||
| 758 | next; | ||
| 759 | } else { | ||
| 760 | $s->echo_msg("INFO: deleting $fn...", 2); | ||
| 761 | } | ||
| 762 | # $s->disp_param($p->{old_fns}); | ||
| 763 | for my $i (0..$#{$p->{old_fns}}) { | ||
| 764 | # we could not remove files from Window server right now | ||
| 765 | my $f = $p->{old_fns}[$i]; | ||
| 766 | # print "RM: $f<br>\n"; | ||
| 767 | } | ||
| 768 | } | ||
| 769 | } | ||
| 770 | |||
| 771 | # 8. print the html | ||
| 772 | $s->echo_msg("8. print html", 2); | ||
| 773 | if (! $rpt_cnt) { | ||
| 774 | my $m = "ERR: ($prg) no report from $rdr is found"; | ||
| 775 | $m .= " for Study $study_id" if $study_id || $study_id == 0; | ||
| 776 | $m .= " , Job $job_id" if $job_id || $job_id == 0; | ||
| 777 | $m .= " , HJob $hjob_id" if $hjob_id || $hjob_id == 0; | ||
| 778 | $s->echo_msg($m, 0); | ||
| 779 | # return; | ||
| 780 | } | ||
| 781 | |||
| 782 | my $f_li = " <li><b>%s - %s</b></li>\n"; | ||
| 783 | my $f_la = " <li><a href='%s' target=_new title='%s'>%s</a> (%s)</li>\n"; | ||
| 784 | my $f_l2 = " <li><a href='%s' target=_new title='%s'>%s</a> \[created at %s\] (%s)</li>\n"; | ||
| 785 | my $f_aa = " <a href='%s' target=R title='%s'>%s</a> (%s)\n"; | ||
| 786 | my $f_a2 = "<a href='%s' target=_blank title='%s'>%s</a>"; | ||
| 787 | my $t = "<ul>\n"; | ||
| 788 | foreach my $k (sort keys %$r) { | ||
| 789 | $t .= sprintf $f_li, $k, $sd->{$k}; | ||
| 790 | $t .= " <ul>\n"; | ||
| 791 | for my $i (sort {$r->{$k}[$a]{ctm} cmp $r->{$k}[$b]{ctm} } 0..$#{$r->{$k}}) { | ||
| 792 | my $p = $r->{$k}[$i]; | ||
| 793 | my $tgz = join $ds, $p->{adr}, $p->{sub}, $p->{fn_tgz}; | ||
| 794 | my $s1 = "$p->{fn_tgz} [created at $p->{ctm}]"; | ||
| 795 | my $s2 = join $ds, $p->{dsp_dir}, $p->{fn}; | ||
| 796 | my $t2 = sprintf $f_a2, $s2, $p->{ffn},$s2; | ||
| 797 | # if (exists $p->{old_fns}) { | ||
| 798 | # $t .= sprintf $f_la, $p->{dsp_tgz}, $p->{t}, $s1, $s2; | ||
| 799 | $t .= sprintf $f_l2, $tgz, $p->{t}, $p->{fn_tgz},$p->{ctm}, $t2; | ||
| 800 | # } else { | ||
| 801 | # $t .= " <li> $s1 ($s2)"; | ||
| 802 | # } | ||
| 803 | } | ||
| 804 | $t .= " </ul>\n"; | ||
| 805 | } | ||
| 806 | $t .= "</ul>\n"; | ||
| 807 | print $t; | ||
| 808 | return; | ||
| 809 | } | ||
| 810 | |||
| 811 | |||
| 812 | =head2 disp_hids($q,$ar) | ||
| 813 | |||
| 814 | Input variables: | ||
| 815 | |||
| 816 | $q - CGI class | ||
| 817 | $ar - array ref containing the following variables: | ||
| 818 | |||
| 819 | Variables used or routines called: | ||
| 820 | |||
| 821 | None | ||
| 822 | |||
| 823 | How to use: | ||
| 824 | |||
| 825 | Return: None | ||
| 826 | |||
| 827 | =cut | ||
| 828 | |||
| 829 | sub disp_hids { | ||
| 830 | my ($s, $q, $ar) = @_; | ||
| 831 | |||
| 832 | # 1. get variables | ||
| 833 | my ($pid,$sn,$study_id,$study_name) = (); | ||
| 834 | $pid = $ar->{pid} if exists $ar->{pid}; | ||
| 835 | $sn = $ar->{sid} if exists $ar->{sid}; | ||
| 836 | $sn = $ar->{target} if exists $ar->{target} && !$sn; | ||
| 837 | $sn = $ar->{sel_sn1} if exists $ar->{sel_sn1} && !$sn; | ||
| 838 | $study_id = $ar->{study_id} if exists $ar->{study_id}; | ||
| 839 | $study_name = $ar->{study_name} if exists $ar->{study_name}; | ||
| 840 | |||
| 841 | # 2. check required elements | ||
| 842 | if (!$pid) { | ||
| 843 | $s->echo_msg("ERR: pid is not defined.", 0); return; | ||
| 844 | } | ||
| 845 | if (!$sn) { | ||
| 846 | $s->echo_msg("ERR: server name is not defined.", 0); return; | ||
| 847 | } | ||
| 848 | if ($study_id != 0 && !$study_id) { | ||
| 849 | $s->echo_msg("ERR: study_id is not provided.", 0); return; | ||
| 850 | } | ||
| 851 | |||
| 852 | # 3. get a list of job ids | ||
| 853 | my $jr = $s->get_jobid($ar); | ||
| 854 | my $jids = ""; | ||
| 855 | my $jhr = {}; | ||
| 856 | for my $i (0..$#$jr) { | ||
| 857 | $jids .= ($jids) ? ",$jr->[$i][0]" : $jr->[$i][0]; | ||
| 858 | $jhr->{$jr->[$i][0]} = $jr->[$i][1]; | ||
| 859 | } | ||
| 860 | |||
| 861 | # 4. get a list of hist job ids | ||
| 862 | my $whr = "where job_id in ($jids)"; | ||
| 863 | $whr .= ' order by hjob_id'; | ||
| 864 | my $cns = 'hjob_id,job_id,job_starttime,job_endtime,job_status'; | ||
| 865 | my $rr = $s->run_sqlcmd($ar,$cns,'cc_hist_jobs', $whr); | ||
| 866 | my $hids = ""; | ||
| 867 | for my $i (0..$#$rr) { | ||
| 868 | $hids .= ($hids) ? ",$rr->[$i]{hjob_id}" : $rr->[$i]{hjob_id}; | ||
| 869 | } | ||
| 870 | |||
| 871 | # 5. get finding count | ||
| 872 | $whr = "where hjob_id in ($hids) group by hjob_id"; | ||
| 873 | $cns = "hjob_id,sum(count_invalid) as cnt_inv"; | ||
| 874 | my $r2 = $s->run_sqlcmd($ar,$cns,'cc_results', $whr); | ||
| 875 | my $h2 = {}; | ||
| 876 | for my $i (0..$#$r2) { | ||
| 877 | $h2->{$r2->[$i]{hjob_id}} = $r2->[$i]{cnt_inv}; | ||
| 878 | } | ||
| 879 | |||
| 880 | # 6. build html | ||
| 881 | my $f_th = " <tr><th>%s\n <th>%s\n <th>%s\n"; | ||
| 882 | $f_th .= " <th>%s\n <th>%s\n <th>%s\n </tr>\n"; | ||
| 883 | my $f_tr = " <tr class=%s><td>%s\n <td>%s\n <td align=right>%s\n"; | ||
| 884 | $f_tr .= " <td>%s\n <td>%s\n <td align=right>%s\n </tr>\n"; | ||
| 885 | my $f_aa = " <a href='%s' title='%s' target=R>%s</a>\n"; | ||
| 886 | my $url = $ar->{web_url}; # web URL | ||
| 887 | $url .= "?pid=$pid&no_dispform=1&sel_sn1=$sn"; | ||
| 888 | my $t = "<table>\n"; | ||
| 889 | $t .= "<caption>Hist Job List for Study $study_id"; | ||
| 890 | $t .= " - $study_name" if $study_name; | ||
| 891 | $t .= "</caption>\n"; | ||
| 892 | $t .= sprintf $f_th, "HJob ID", "Job Name", "Start Time", "End Time", | ||
| 893 | "Status", "Finding Count"; | ||
| 894 | my @rec = (); | ||
| 895 | for my $i (0..$#$rr) { | ||
| 896 | @rec = (); | ||
| 897 | push @rec, (($i % 2 == 0) ? 'even' : 'odd'); | ||
| 898 | my $k = $rr->[$i]{hjob_id}; | ||
| 899 | my $v = $jhr->{$rr->[$i]{job_id}}; | ||
| 900 | my $u = "$url&task=sel_stat&sel_sn2=$k"; | ||
| 901 | push @rec, (sprintf $f_aa, $u, "Disp Stat (HJob_ID=$k)",$k); | ||
| 902 | push @rec, "$rr->[$i]{job_id} - $v"; | ||
| 903 | foreach my $j (split /,/,'job_starttime,job_endtime,job_status') { | ||
| 904 | push @rec, ($rr->[$i]{$j}) ? $rr->[$i]{$j} : ' '; | ||
| 905 | } | ||
| 906 | push @rec, $h2->{$k}; | ||
| 907 | $t .= sprintf $f_tr, @rec if $#rec >= 0; | ||
| 908 | } | ||
| 909 | $t .= "</table>\n"; | ||
| 910 | |||
| 911 | # 6. print html | ||
| 912 | |||
| 913 | if ($#$rr < 0) { | ||
| 914 | my $m = "ERR: no table is found for Study $study_id - $study_name."; | ||
| 915 | $s->echo_msg($m, 0); | ||
| 916 | return; | ||
| 917 | } | ||
| 918 | print $t; | ||
| 919 | return; | ||
| 920 | } | ||
| 921 | |||
| 922 | |||
| 923 | =head2 disp_tabs($q,$ar) | ||
| 924 | |||
| 925 | Input variables: | ||
| 926 | |||
| 927 | $q - CGI class | ||
| 928 | $ar - array ref containing the following variables: | ||
| 929 | |||
| 930 | Variables used or routines called: | ||
| 931 | |||
| 932 | None | ||
| 933 | |||
| 934 | How to use: | ||
| 935 | |||
| 936 | Return: None | ||
| 937 | |||
| 938 | History: mm/dd/yyyy (developer) - description | ||
| 939 | |||
| 940 | 03/28/2011 (htu) - added $exc_vars | ||
| 941 | 03/29/2011 (htu) - added $obj_vars | ||
| 942 | |||
| 943 | =cut | ||
| 944 | |||
| 945 | sub disp_tabs { | ||
| 946 | my ($s, $q, $ar) = @_; | ||
| 947 | |||
| 948 | # 1. get variables | ||
| 949 | my $prg = 'disp_tabs'; | ||
| 950 | my ($sn,$odr,$rdr,$dsp,$study_id,$study_name,$tnm,$xnm) = (); | ||
| 951 | $sn = $ar->{sid} if exists $ar->{sid}; | ||
| 952 | $sn = $ar->{target} if exists $ar->{target} && !$sn; | ||
| 953 | $sn = $ar->{sel_sn1} if exists $ar->{sel_sn1} && !$sn; | ||
| 954 | |||
| 955 | $study_id = $ar->{study_id} if exists $ar->{study_id}; | ||
| 956 | $study_name = $ar->{study_name} if exists $ar->{study_name}; | ||
| 957 | my $obj_vars = (exists $ar->{obj_vars}) ? $ar->{obj_vars} : ''; | ||
| 958 | if ($obj_vars) { | ||
| 959 | foreach my $k (split /,/, $obj_vars) { | ||
| 960 | $tnm = uc($ar->{$k}) if exists $ar->{$k} && $ar->{$k}; | ||
| 961 | } | ||
| 962 | } | ||
| 963 | $tnm = '%FINAL' if !$tnm; | ||
| 964 | my $exc_vars = (exists $ar->{exc_vars}) ? $ar->{exc_vars} : ''; | ||
| 965 | if ($exc_vars) { | ||
| 966 | for my $k (split /,/, $exc_vars) { | ||
| 967 | $xnm = uc($ar->{$k}) if !$xnm && exists $ar->{$k}; | ||
| 968 | } | ||
| 969 | } | ||
| 970 | |||
| 971 | $tnm = uc($ar->{src_obj}) if !$tnm && exists $ar->{src_obj}; | ||
| 972 | $tnm = uc($ar->{src_objects}) if !$tnm && exists $ar->{src_objects}; | ||
| 973 | $tnm = uc($ar->{cpt_src_obj}) if !$tnm && exists $ar->{cpt_src_obj}; | ||
| 974 | $tnm = '%FINAL' if !$tnm; | ||
| 975 | $xnm = uc($ar->{exl_objects}) if !$xnm && exists $ar->{exl_objects}; | ||
| 976 | $xnm = uc($ar->{src_excl}) if !$xnm && exists $ar->{src_excl}; | ||
| 977 | $xnm = uc($ar->{cpt_exl_obj}) if !$xnm && exists $ar->{cpt_exl_obj}; | ||
| 978 | $xnm = '' if !$xnm; | ||
| 979 | |||
| 980 | # 2. check required elements | ||
| 981 | if (!$sn) { | ||
| 982 | $s->echo_msg("ERR: server name is not defined.", 0); return; | ||
| 983 | } | ||
| 984 | if ($study_id != 0 && !$study_id) { | ||
| 985 | $s->echo_msg("ERR: study_id is not provided.", 0); return; | ||
| 986 | } | ||
| 987 | |||
| 988 | # 3. get study schema and DBL | ||
| 989 | |||
| 990 | my $whr = "where study_id = $study_id order by study_id"; | ||
| 991 | my $rr = $s->run_sqlcmd($ar,'stg_schema,stg_dbl','cc_studies', $whr); | ||
| 992 | |||
| 993 | if ($#$rr < 0) { | ||
| 994 | $s->echo_msg("ERR: could not find study_id - $study_id in study table.", 0); | ||
| 995 | return; | ||
| 996 | } | ||
| 997 | my $stg_sch = uc $rr->[0]{stg_schema}; | ||
| 998 | my $stg_dbl = uc $rr->[0]{stg_dbl}; | ||
| 999 | if (!$stg_sch && !$stg_dbl) { | ||
| 1000 | $s->echo_msg("ERR: could not find stg_schema($stg_sch) or stg_dbl($stg_dbl).",0); | ||
| 1001 | return; | ||
| 1002 | } | ||
| 1003 | # $s->echo_msg("INFO: STG_SCH=$stg_sch, STG_DBL=$stg_dbl", 3); | ||
| 1004 | |||
| 1005 | # 4. get all tables from staging schema and dbl link | ||
| 1006 | my $r = {}; # result array ref | ||
| 1007 | my ($wh1,$wh2,$r1,$r2) = (); | ||
| 1008 | |||
| 1009 | # get number of rows for the tables | ||
| 1010 | if ($stg_sch) { | ||
| 1011 | $wh1 = $s->cc_andwhere($stg_sch, 'owner', 'where'); | ||
| 1012 | $wh1 .= $s->cc_andwhere($tnm, 'table_name', 'and'); | ||
| 1013 | $wh1 .= $s->cc_andwhere($xnm, 'table_name', 'andnot'); | ||
| 1014 | $r1 = $s->run_sqlcmd($ar,'table_name,num_rows','all_tables', $wh1); | ||
| 1015 | $wh2 = $s->cc_andwhere($stg_sch, 'owner', 'where'); | ||
| 1016 | $wh2 .= $s->cc_andwhere('TABLE', 'object_type', 'and'); | ||
| 1017 | $wh2 .= $s->cc_andwhere($tnm, 'object_name', 'and'); | ||
| 1018 | $wh2 .= $s->cc_andwhere($xnm, 'object_name', 'andnot'); | ||
| 1019 | $r2 = $s->run_sqlcmd($ar,'object_name,last_ddl_time','all_objects', $wh2); | ||
| 1020 | # $s->echo_msg("WH1=$wh1; WH2=$wh2",0); | ||
| 1021 | for my $i (0..$#$r1) { | ||
| 1022 | my $k = $r1->[$i]{table_name}; | ||
| 1023 | $r->{$k} = {} if !exists $r->{$k}; | ||
| 1024 | $r->{$k}{t_rows} = $r1->[$i]{num_rows}; | ||
| 1025 | } | ||
| 1026 | for my $i (0..$#$r2) { | ||
| 1027 | my $k = $r2->[$i]{object_name}; | ||
| 1028 | $r->{$k} = {} if !exists $r->{$k}; | ||
| 1029 | $r->{$k}{t_time} = $r2->[$i]{last_ddl_time}; | ||
| 1030 | } | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | if ($stg_dbl) { | ||
| 1034 | $wh1 = $s->cc_andwhere($tnm, 'table_name', 'where'); | ||
| 1035 | $wh1 .= $s->cc_andwhere($xnm, 'table_name', 'andnot'); | ||
| 1036 | $r1 = $s->run_sqlcmd($ar,'table_name,num_rows',"user_tables\@$stg_dbl", $wh1); | ||
| 1037 | $wh2 = $s->cc_andwhere('TABLE', 'object_type', 'where'); | ||
| 1038 | $wh2 .= $s->cc_andwhere($tnm, 'object_name', 'and'); | ||
| 1039 | $wh2 .= $s->cc_andwhere($xnm, 'object_name', 'andnot'); | ||
| 1040 | $r2 = $s->run_sqlcmd($ar,'object_name,last_ddl_time',"user_objects\@$stg_dbl", $wh2); | ||
| 1041 | for my $i (0..$#$r1) { | ||
| 1042 | my $k = $r1->[$i]{table_name}; | ||
| 1043 | $r->{$k} = {} if !exists $r->{$k}; | ||
| 1044 | $r->{$k}{s_rows} = $r1->[$i]{num_rows}; | ||
| 1045 | } | ||
| 1046 | for my $i (0..$#$r2) { | ||
| 1047 | my $k = $r2->[$i]{object_name}; | ||
| 1048 | $r->{$k} = {} if !exists $r->{$k}; | ||
| 1049 | $r->{$k}{s_time} = $r2->[$i]{last_ddl_time}; | ||
| 1050 | } | ||
| 1051 | } | ||
| 1052 | |||
| 1053 | # 5. build html | ||
| 1054 | my $f_th = " <tr><th>%s\n <th>%s\n <th>%s\n"; | ||
| 1055 | $f_th .= " <th>%s\n <th>%s\n </tr>\n"; | ||
| 1056 | my $f_tr = " <tr class=%s><td>%s\n <td>%s\n <td align=right>%s\n"; | ||
| 1057 | $f_tr .= " <td>%s\n <td align=right>%s\n </tr>\n"; | ||
| 1058 | my $rec_cnt = 0; | ||
| 1059 | my $t = "<table>\n"; | ||
| 1060 | $t .= "<caption>Table comparison Between Source "; | ||
| 1061 | $t .= "and Staging Schemas "; | ||
| 1062 | $t .= "for Study $study_id - $study_name<br>($tnm;$xnm)</caption>\n"; | ||
| 1063 | $t .= " <tr><th><th colspan=2>Source: $stg_dbl\n"; | ||
| 1064 | $t .= " <th colspan=2>Target: $stg_sch</tr>\n"; | ||
| 1065 | $t .= sprintf $f_th, "Table Name", "DDL Time", "Num of Rows", | ||
| 1066 | "DDL Time", "Num of Rows"; | ||
| 1067 | my @rec = (); | ||
| 1068 | foreach my $k (sort keys %$r) { | ||
| 1069 | $rec_cnt += 1; | ||
| 1070 | my @rec = (); | ||
| 1071 | push @rec, (($rec_cnt % 2 == 0) ? 'even' : 'odd'); | ||
| 1072 | push @rec, $k; | ||
| 1073 | foreach my $j (split /,/,'s_time,s_rows,t_time,t_rows') { | ||
| 1074 | push @rec,((!exists $r->{$k}{$j}) ? '<b>N/A</b>' : | ||
| 1075 | (($r->{$k}{$j})?$r->{$k}{$j}:' ')); | ||
| 1076 | } | ||
| 1077 | $t .= sprintf $f_tr, @rec; | ||
| 1078 | } | ||
| 1079 | $t .= "</table>\n"; | ||
| 1080 | $t .= "<b>Total $rec_cnt records.</b>\n"; | ||
| 1081 | |||
| 1082 | # 6. print html | ||
| 1083 | |||
| 1084 | if (! $rec_cnt) { | ||
| 1085 | my $m = "ERR: no table is found for Study $study_id ($tnm)."; | ||
| 1086 | $s->echo_msg($m, 0); | ||
| 1087 | return; | ||
| 1088 | } | ||
| 1089 | print $t; | ||
| 1090 | return; | ||
| 1091 | } | ||
| 1092 | |||
| 1093 | |||
| 1094 | =head2 disp_rpts($q,$ar) | ||
| 1095 | |||
| 1096 | Input variables: | ||
| 1097 | |||
| 1098 | $q - CGI class | ||
| 1099 | $ar - array ref containing the following variables: | ||
| 1100 | |||
| 1101 | Variables used or routines called: | ||
| 1102 | |||
| 1103 | None | ||
| 1104 | |||
| 1105 | How to use: | ||
| 1106 | |||
| 1107 | Return: None | ||
| 1108 | |||
| 1109 | =cut | ||
| 1110 | |||
| 1111 | sub disp_rpts { | ||
| 1112 | my ($s, $q, $ar) = @_; | ||
| 1113 | |||
| 1114 | my $prg = 'AppBuilder::TaskDisps->disp_rpts'; | ||
| 1115 | # 1. get variables | ||
| 1116 | $s->echo_msg(" 1. Get variables...", 2); | ||
| 1117 | my ($sn,$odr,$rdr,$dsp) = (); | ||
| 1118 | my $pid = (exists $ar->{pid}) ? $ar->{pid} : ''; | ||
| 1119 | my $drv = (exists $ar->{drv_map}) ? $ar->{drv_map} : ''; | ||
| 1120 | my $ds = (exists $ar->{dir_sep}) ? $ar->{dir_sep} : ''; | ||
| 1121 | $ds = ($^O =~ /^MSWin/i) ? '\\' : '/' if ! $ds; | ||
| 1122 | |||
| 1123 | $sn = $ar->{sid} if exists $ar->{sid}; | ||
| 1124 | $sn = $ar->{target} if exists $ar->{target} && !$sn; | ||
| 1125 | $sn = $ar->{sel_sn1} if exists $ar->{sel_sn1} && !$sn; | ||
| 1126 | $drv = '\\\\$sn' if ! $drv; | ||
| 1127 | $odr = eval $s->set_param('out_dir', $ar); # output dir | ||
| 1128 | $rdr = $odr->{$sn}{rpt}; # rpt dir | ||
| 1129 | $dsp = (exists $odr->{$sn}{dsp}) ? $odr->{$sn}{dsp} : $ar->{script_url}; # dsp url | ||
| 1130 | $dsp .= '?' . "pid=$pid&target=$sn&task=disp_file"; | ||
| 1131 | $dsp .= '&' . "f="; | ||
| 1132 | my $study_id = (exists $ar->{study_id}) ? $ar->{study_id} : ''; | ||
| 1133 | my $study_name= (exists $ar->{study_name}) ? $ar->{study_name} : ''; | ||
| 1134 | |||
| 1135 | $s->echo_msg("INFO: RDR - $rdr<br>\nDSP - $dsp",3); | ||
| 1136 | |||
| 1137 | # 2. check required elements | ||
| 1138 | $s->echo_msg(" 2. Check required elements...", 2); | ||
| 1139 | if (! -d $rdr) { | ||
| 1140 | $s->echo_msg("ERR: ($prg) could not find rpt dir - $rdr.", 0); return; | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | # 3. get study id | ||
| 1144 | $s->echo_msg(" 3. Get study ID...", 2); | ||
| 1145 | my $studyid = $s->get_studyid($ar); # study ids | ||
| 1146 | my $sd = {}; # study id hash array | ||
| 1147 | for my $i (0..$#$studyid) { | ||
| 1148 | $sd->{$studyid->[$i][0]} = $studyid->[$i][1]; | ||
| 1149 | } | ||
| 1150 | $s->echo_msg($sd, 5); | ||
| 1151 | |||
| 1152 | # 4. get all index files | ||
| 1153 | $s->echo_msg(" 4. Get all index files from $rdr...", 2); | ||
| 1154 | my $fname = 'index'; | ||
| 1155 | |||
| 1156 | # 01/05/2012: let's get the out dir stored in cc_hist_jobs table | ||
| 1157 | my $rr = $s->get_htmlrpts($ar); | ||
| 1158 | |||
| 1159 | # 5. loop through each file | ||
| 1160 | $s->echo_msg(" 5. Loop through each file...", 2); | ||
| 1161 | my $r = {}; # result array ref | ||
| 1162 | for my $i (0..$#$rr) { | ||
| 1163 | my $sid = $rr->[$i]{sid}; | ||
| 1164 | $r->{$sid} = [] if !exists $r->{$sid}; | ||
| 1165 | push @{$r->{$sid}}, $rr->[$i]{stat}; | ||
| 1166 | } | ||
| 1167 | |||
| 1168 | # 6. print the html | ||
| 1169 | $s->echo_msg(" 6. Print HTML doc...", 2); | ||
| 1170 | if (!@$rr) { | ||
| 1171 | $s->echo_msg("ERR: no report is found for study $study_id - $study_name.",0); | ||
| 1172 | return; | ||
| 1173 | } | ||
| 1174 | |||
| 1175 | my $f_li = " <li><b>%s - %s</b></li>\n"; | ||
| 1176 | my $f_la = " <li><a href='%s' target=R title='%s'>%s</a> (%s)</li>\n"; | ||
| 1177 | my $t = "<ul>\n"; | ||
| 1178 | foreach my $k (sort keys %$r) { | ||
| 1179 | $t .= sprintf $f_li, $k, $sd->{$k}; | ||
| 1180 | $t .= " <ul>\n"; | ||
| 1181 | for my $i (sort {$r->{$k}[$a]{ctm} cmp $r->{$k}[$b]{ctm} } 0..$#{$r->{$k}}) { | ||
| 1182 | my $p = $r->{$k}[$i]; | ||
| 1183 | $t .= sprintf $f_la, $p->{dsp}, $p->{fn}, $p->{t}, | ||
| 1184 | "reported at $p->{rtm} and created at $p->{ctm}"; | ||
| 1185 | } | ||
| 1186 | $t .= " </ul>\n"; | ||
| 1187 | } | ||
| 1188 | $t .= "</ul>\n"; | ||
| 1189 | print $t; | ||
| 1190 | return; | ||
| 1191 | } | ||
| 1192 | |||
| 1193 | |||
| 1194 | =head2 disp_client($q,$ar) | ||
| 1195 | |||
| 1196 | Input variables: | ||
| 1197 | |||
| 1198 | $q - CGI class | ||
| 1199 | $ar - array ref containing the following variables: | ||
| 1200 | |||
| 1201 | Variables used or routines called: | ||
| 1202 | |||
| 1203 | None | ||
| 1204 | |||
| 1205 | How to use: | ||
| 1206 | |||
| 1207 | Return: None | ||
| 1208 | |||
| 1209 | =cut | ||
| 1210 | |||
| 1211 | sub disp_client { | ||
| 1212 | my ($s, $q, $ar) = @_; | ||
| 1213 | |||
| 1214 | my $whr = 'ORDER BY client_id'; | ||
| 1215 | my $r = $s->run_sqlcmd($ar, 'client_id,client_name', 'cc_clients', $whr); | ||
| 1216 | print $s->build_links($r, $ar); | ||
| 1217 | return; | ||
| 1218 | } | ||
| 1219 | |||
| 1220 | =head2 disp_project($q,$ar) | ||
| 1221 | |||
| 1222 | Input variables: | ||
| 1223 | |||
| 1224 | $q - CGI class | ||
| 1225 | $ar - array ref containing the following variables: | ||
| 1226 | |||
| 1227 | Variables used or routines called: | ||
| 1228 | |||
| 1229 | None | ||
| 1230 | |||
| 1231 | How to use: | ||
| 1232 | |||
| 1233 | Return: None | ||
| 1234 | |||
| 1235 | =cut | ||
| 1236 | |||
| 1237 | sub disp_project { | ||
| 1238 | my ($s, $q, $ar) = @_; | ||
| 1239 | |||
| 1240 | my $whr = ""; | ||
| 1241 | $whr = "WHERE client_id=$ar->{cln_id} ORDER BY prj_id " | ||
| 1242 | if exists $ar->{cln_id} && ($ar->{cln_id} =~ /^\d+$/); | ||
| 1243 | my $r = $s->run_sqlcmd($ar, 'prj_id,prj_name', 'cc_projects', $whr); | ||
| 1244 | print $s->build_links($r, $ar); | ||
| 1245 | return; | ||
| 1246 | } | ||
| 1247 | |||
| 1248 | =head2 disp_study($q,$ar) | ||
| 1249 | |||
| 1250 | Input variables: | ||
| 1251 | |||
| 1252 | $q - CGI class | ||
| 1253 | $ar - array ref containing the following variables: | ||
| 1254 | |||
| 1255 | Variables used or routines called: | ||
| 1256 | |||
| 1257 | None | ||
| 1258 | |||
| 1259 | How to use: | ||
| 1260 | |||
| 1261 | Return: None | ||
| 1262 | |||
| 1263 | =cut | ||
| 1264 | |||
| 1265 | sub disp_study { | ||
| 1266 | my ($s, $q, $ar) = @_; | ||
| 1267 | |||
| 1268 | my $whr = " WHERE study_status = 1"; | ||
| 1269 | $whr .= " AND prj_id=$ar->{prj_id}" | ||
| 1270 | if exists $ar->{prj_id} && ($ar->{prj_id} =~ /^\d+$/); | ||
| 1271 | $whr .= ' ORDER BY study_id '; | ||
| 1272 | my $r = $s->run_sqlcmd($ar, 'study_id,study_name', 'cc_studies', $whr); | ||
| 1273 | print $s->build_links($r, $ar); | ||
| 1274 | return; | ||
| 1275 | } | ||
| 1276 | |||
| 1277 | =head2 disp_job($q,$ar) | ||
| 1278 | |||
| 1279 | Input variables: | ||
| 1280 | |||
| 1281 | $q - CGI class | ||
| 1282 | $ar - array ref containing the following variables: | ||
| 1283 | |||
| 1284 | Variables used or routines called: | ||
| 1285 | |||
| 1286 | None | ||
| 1287 | |||
| 1288 | How to use: | ||
| 1289 | |||
| 1290 | Return: None | ||
| 1291 | |||
| 1292 | =cut | ||
| 1293 | |||
| 1294 | sub disp_job { | ||
| 1295 | my ($s, $q, $ar) = @_; | ||
| 1296 | |||
| 1297 | my $whr = ""; | ||
| 1298 | $whr = "WHERE study_id=$ar->{study_id}" | ||
| 1299 | if exists $ar->{study_id} && $ar->{study_id} =~ /^\d+$/; | ||
| 1300 | $whr .= " ORDER BY job_id"; | ||
| 1301 | my $r = $s->run_sqlcmd($ar, 'job_id,job_name', 'cc_jobs', $whr); | ||
| 1302 | print $s->build_links($r, $ar); | ||
| 1303 | return; | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | =head2 disp_hjob($q,$ar) | ||
| 1307 | |||
| 1308 | Input variables: | ||
| 1309 | |||
| 1310 | $q - CGI class | ||
| 1311 | $ar - array ref containing the following variables: | ||
| 1312 | |||
| 1313 | Variables used or routines called: | ||
| 1314 | |||
| 1315 | None | ||
| 1316 | |||
| 1317 | How to use: | ||
| 1318 | |||
| 1319 | Return: None | ||
| 1320 | |||
| 1321 | =cut | ||
| 1322 | |||
| 1323 | sub disp_hjob { | ||
| 1324 | my ($s, $q, $ar) = @_; | ||
| 1325 | |||
| 1326 | my $sql = "ALTER session SET nls_date_format='YYYYMMDD.HH24MISS';\n"; | ||
| 1327 | $sql .= "SET linesize 999 serveroutput ON SIZE 1000000 FORMAT WRAPPED;\n"; | ||
| 1328 | $sql .= "SELECT '==,'||hjob_id||','||replace(job_action,',','#') as record "; | ||
| 1329 | $sql .= "FROM cc_hist_jobs "; | ||
| 1330 | if (exists $ar->{job_id} && ($ar->{job_id} =~ /^\d+$/)) { | ||
| 1331 | $sql .= " WHERE job_id = $ar->{job_id} ORDER BY hjob_id; \n"; | ||
| 1332 | } else { | ||
| 1333 | $sql .= ";\n"; | ||
| 1334 | } | ||
| 1335 | my $rst = $s->open_cmd($sql,$ar); | ||
| 1336 | my $vr = ['hjob_id','job_action']; | ||
| 1337 | $ar->{var_arf} = $vr; | ||
| 1338 | my $rr = $s->parse_records($rst, $vr, '==', ','); | ||
| 1339 | |||
| 1340 | for my $i (0..$#$rr) { | ||
| 1341 | $rr->[$i]{job_action} =~ s/\#/,/g; | ||
| 1342 | } | ||
| 1343 | |||
| 1344 | # $s->disp_param($rr); | ||
| 1345 | |||
| 1346 | print $s->build_links($rr, $ar); | ||
| 1347 | return; | ||
| 1348 | } | ||
| 1349 | |||
| 1350 | =head2 disp_htmlrpt($q,$ar) | ||
| 1351 | |||
| 1352 | Input variables: | ||
| 1353 | |||
| 1354 | $q - CGI class | ||
| 1355 | $ar - array ref containing the following variables: | ||
| 1356 | |||
| 1357 | Variables used or routines called: | ||
| 1358 | |||
| 1359 | None | ||
| 1360 | |||
| 1361 | How to use: | ||
| 1362 | |||
| 1363 | Return: None | ||
| 1364 | |||
| 1365 | =cut | ||
| 1366 | |||
| 1367 | sub disp_htmlrpt { | ||
| 1368 | my ($s, $q, $ar) = @_; | ||
| 1369 | |||
| 1370 | my $rr = $s->get_htmlrpts($ar); | ||
| 1371 | my $f_la = " <li><a href=\"%s\" target=\"%s\" title=\"%s\">%s</a> (%s)\n"; | ||
| 1372 | |||
| 1373 | my $t = "<ul>\n"; | ||
| 1374 | for my $i (0..$#$rr) { | ||
| 1375 | my $url = $rr->[$i]{stat}{dsp}; | ||
| 1376 | my $tit = $rr->[$i]{stat}{fn}; | ||
| 1377 | my $sta = $rr->[$i]{job_status}; | ||
| 1378 | my $txt = "Reported at $rr->[$i]{stat}{rtm}; "; | ||
| 1379 | $txt .= "Created at $rr->[$i]{stat}{ctm}"; | ||
| 1380 | $t .= sprintf $f_la, $url, "R", $tit, $sta, $txt; | ||
| 1381 | } | ||
| 1382 | $t .= "</ul>\n"; | ||
| 1383 | print $t; | ||
| 1384 | return; | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | =head2 build_links($q,$pr,$ar) | ||
| 1388 | |||
| 1389 | Input variables: | ||
| 1390 | |||
| 1391 | $pr - array ref containing id and name | ||
| 1392 | $ar - array ref containing the following variables: | ||
| 1393 | |||
| 1394 | Variables used or routines called: | ||
| 1395 | |||
| 1396 | None | ||
| 1397 | |||
| 1398 | How to use: | ||
| 1399 | |||
| 1400 | Return: None | ||
| 1401 | |||
| 1402 | =cut | ||
| 1403 | |||
| 1404 | sub build_links { | ||
| 1405 | my ($s, $pr, $ar) = @_; | ||
| 1406 | |||
| 1407 | my $prg = 'TaskDisp->build_links'; | ||
| 1408 | # 0 - return if $pr is empty | ||
| 1409 | if (!$pr || $#$pr < 0) { | ||
| 1410 | $s->echo_msg("WARN: ($prg) No records.",0); return; | ||
| 1411 | } | ||
| 1412 | |||
| 1413 | # 1. define variables | ||
| 1414 | $s->echo_msg(" 1. Define variables...", 2); | ||
| 1415 | my $pid = (exists $ar->{pid}) ? $ar->{pid} : ''; | ||
| 1416 | my $sid = (exists $ar->{sid}) ? $ar->{sid} : ''; | ||
| 1417 | $sid = $ar->{sel_sn1} if !$sid && exists $ar->{sel_sn1}; | ||
| 1418 | my $tsk = (exists $ar->{task}) ? $ar->{task} : ''; # such as disp_client | ||
| 1419 | my $tgt = (exists $ar->{fr_tgt}) ? $ar->{fr_tgt} : ''; # frame target | ||
| 1420 | $tgt = 'R' if ! $tgt; | ||
| 1421 | |||
| 1422 | my $tk = $tsk; $tk =~ s/(disp_)//; | ||
| 1423 | my $tr = {'client'=>'project','project'=>'study','study'=>'job','job'=>'hjob' }; | ||
| 1424 | my $br = {'client'=>'','project'=>'cln','study'=>'prj','job'=>'study' | ||
| 1425 | ,'hjob'=>'job' }; | ||
| 1426 | my $tg = {'client'=>'D2','project'=>'D3','study'=>'D4','job'=>'R' }; | ||
| 1427 | my $id = {'client'=>'cln_id','project'=>'prj_id','study'=>'study_id' | ||
| 1428 | ,'job'=>'job_id','hjob'=>'hjob_id' }; | ||
| 1429 | my $nm = {'client'=>'cln_name','project'=>'prj_name','study'=>'study_name' | ||
| 1430 | ,'job'=>'job_name','hjob'=>'hjob_name' }; | ||
| 1431 | |||
| 1432 | my $url = $ar->{web_url}; # web URL | ||
| 1433 | $url =~ s/(\?.*)// if $url; # remove parameters | ||
| 1434 | $url .= "?pid=$pid&sel_sn1=$sid"; | ||
| 1435 | $s->echo_msg("INFO: TASK=$tk, URL=$url", 3); | ||
| 1436 | $s->echo_msg($pr,3); | ||
| 1437 | |||
| 1438 | # 2. check required variables | ||
| 1439 | $s->echo_msg(" 2. Check required variables...", 2); | ||
| 1440 | if (!$pid) { | ||
| 1441 | $s->echo_msg("ERR: ($prg) could not find pid.",0); return; | ||
| 1442 | } | ||
| 1443 | if (!$sid) { | ||
| 1444 | $s->echo_msg("ERR: ($prg) could not find sid.",0); return; | ||
| 1445 | } | ||
| 1446 | $s->echo_msg("INFO: PID=$pid, SID=$sid", 3); | ||
| 1447 | |||
| 1448 | # 3. build links | ||
| 1449 | $s->echo_msg(" 3. Build links...", 2); | ||
| 1450 | my $f_aa = " <a href=\"%s\" target=\"%s\" title=\"%s\">%s</a>\n"; | ||
| 1451 | my $f_bb = "<b>%s</b>\n"; | ||
| 1452 | my $f_li = " <li>%s</li>\n"; | ||
| 1453 | |||
| 1454 | my $vr = $ar->{var_arf}; | ||
| 1455 | my $u_lf = "$url&task=disp_usr_task"; | ||
| 1456 | my ($u_rt, $u_ct) = (); | ||
| 1457 | if (exists $tr->{$tk} && $tr->{$tk}) { | ||
| 1458 | $u_rt = "$url&task=disp_$tr->{$tk}"; | ||
| 1459 | $u_ct = "$url&task=disp_new&new_task=add_$tr->{$tk}"; | ||
| 1460 | } | ||
| 1461 | $s->echo_msg("INFO: ULT=$u_lf, UCT=$u_ct, URT=$u_rt", 3); | ||
| 1462 | $s->echo_msg($id, 3); | ||
| 1463 | |||
| 1464 | # my $ids = 'cln_id,prj_id,study_id,job_id,hjob_id'; | ||
| 1465 | my $cnt_ar = {}; | ||
| 1466 | foreach my $kk (keys %$id) { | ||
| 1467 | my $k = $id->{$kk}; | ||
| 1468 | my $n = $nm->{$kk}; | ||
| 1469 | if ($kk eq $tk) { | ||
| 1470 | $s->echo_msg("WARN: skipped ID for $tk.", 3); | ||
| 1471 | next; # so that we do not duplicated the id | ||
| 1472 | } | ||
| 1473 | if (exists $ar->{$k} && $ar->{$k} =~ /^\d+$/) { | ||
| 1474 | $u_lf .= "&$k=$ar->{$k}"; | ||
| 1475 | $u_rt .= "&$k=$ar->{$k}"; | ||
| 1476 | $u_ct .= "&$k=$ar->{$k}"; | ||
| 1477 | } | ||
| 1478 | if (exists $ar->{$n} && $ar->{$n}) { | ||
| 1479 | $u_lf .= "&$n=$ar->{$n}"; | ||
| 1480 | $u_rt .= "&$n=$ar->{$n}"; | ||
| 1481 | $u_ct .= "&$n=$ar->{$n}"; | ||
| 1482 | } | ||
| 1483 | # $cnt_ar->{$n} += 1; | ||
| 1484 | } | ||
| 1485 | $s->echo_msg("WARN: ULT=$u_lf",3); | ||
| 1486 | $s->echo_msg("WARN: UCT=$u_ct",3); | ||
| 1487 | $s->echo_msg("WARN: URT=$u_rt",3); | ||
| 1488 | my $ar_id = {}; | ||
| 1489 | foreach my $k (sort keys %$ar) { next if $k !~ /id$/i; $ar_id->{$k} = $ar->{$k}; } | ||
| 1490 | $s->echo_msg($ar_id, 3); | ||
| 1491 | |||
| 1492 | my $t = "<center>" . (sprintf $f_bb, uc($tk)) . ': '; | ||
| 1493 | # $t = sprintf $f_aa, "$url&task=disp_new&new_task=add_$tk", 'R', "Add $tk", $t; | ||
| 1494 | # $t .= "<ul>\n"; | ||
| 1495 | my $v_id = $vr->[0]; | ||
| 1496 | my $v_nm = $vr->[1]; | ||
| 1497 | $s->echo_msg("INFO: VID=$v_id, VNM=$v_nm",3); | ||
| 1498 | |||
| 1499 | my $k1 = $br->{$tk} . '_id'; | ||
| 1500 | my $n1 = $br->{$tk} . '_name'; | ||
| 1501 | my $kn = (exists $ar->{$n1}) ? "$ar->{$k1} - $ar->{$n1}" : "Add $tk"; | ||
| 1502 | my $u1 = "$url&task=disp_new&new_task=add_$tk"; | ||
| 1503 | $t .= (sprintf $f_aa, $u1 ,"R","Add $tk",$kn) . "</center>"; | ||
| 1504 | $t .= "<br>\n"; | ||
| 1505 | $s->echo_msg("INFO: K1=$k1, N1=$n1, U1=$u1", 3); | ||
| 1506 | |||
| 1507 | for my $i (0..$#$pr) { | ||
| 1508 | next if ref($pr->[$i]) !~ /^HASH/; | ||
| 1509 | my $k = $pr->[$i]{$v_id}; | ||
| 1510 | my $v = $pr->[$i]{$v_nm}; | ||
| 1511 | my $uk = "$id->{$tk}=$k"; | ||
| 1512 | my $un = "$nm->{$tk}=$v"; | ||
| 1513 | my $lf = "$u_lf&$uk&$un"; | ||
| 1514 | my $rt = "$u_rt&$uk&$un"; | ||
| 1515 | my $ct = "$u_ct&$uk&$un"; | ||
| 1516 | my $t1 = "[\n" . sprintf $f_aa, $lf, 'L', "Set", "<"; | ||
| 1517 | if (exists $tr->{$tk}) { | ||
| 1518 | $t1 .= sprintf $f_aa, $ct, 'R', "Add $tr->{$tk} to $tk $k", '+'; | ||
| 1519 | $t1 .= sprintf $f_aa, $rt, $tg->{$tk}, "expand to $tr->{$tk}", ">"; | ||
| 1520 | } else { | ||
| 1521 | # http://ors2di/cgi/jp2.pl?pid=ckpt&no_dispform=1&sel_sn1=vpapp2&sel_sn2=1261&task=sel_stat | ||
| 1522 | my $u = "$url&no_dispform=1&task=sel_stat&sel_sn2=$k"; | ||
| 1523 | $t1 .= sprintf $f_aa, $u, 'R', "Show Stat for HJob - $k", 'S'; | ||
| 1524 | } | ||
| 1525 | $t1 .= "]\n"; | ||
| 1526 | $t1 .= sprintf "%3d - %s<br>\n", $k, $v; | ||
| 1527 | # $t .= sprintf $f_li, $t1; | ||
| 1528 | $t .= $t1; | ||
| 1529 | } | ||
| 1530 | # $t .= "</ul>\n"; | ||
| 1531 | |||
| 1532 | return $t; | ||
| 1533 | |||
| 1534 | } | ||
| 1535 | |||
| 1536 | |||
| 1537 | =head2 disp_links($q,$ar) | ||
| 1538 | |||
| 1539 | Input variables: | ||
| 1540 | |||
| 1541 | $q - CGI class | ||
| 1542 | $ar - array ref containing the following variables: | ||
| 1543 | |||
| 1544 | Variables used or routines called: | ||
| 1545 | |||
| 1546 | None | ||
| 1547 | |||
| 1548 | How to use: | ||
| 1549 | |||
| 1550 | Return: None | ||
| 1551 | |||
| 1552 | =cut | ||
| 1553 | |||
| 1554 | sub disp_links { | ||
| 1555 | my ($s, $q, $ar) = @_; | ||
| 1556 | my $ovs = eval $s->set_param('opf_values', $ar); | ||
| 1557 | my $ols = eval $s->set_param('opf_labels', $ar); | ||
| 1558 | # my $utk = eval $s->set_param('act_user',$ar); | ||
| 1559 | # my $utk = eval $s->set_param('act_admin',$ar); | ||
| 1560 | my $avl = eval $s->set_param('act_values',$ar); | ||
| 1561 | my $alb = eval $s->set_param('act_labels',$ar); | ||
| 1562 | |||
| 1563 | my $f_li = " <li><a href=\"%s\" target=R>%s</a></li>\n"; | ||
| 1564 | my $f_bb = "<b>%s</b>\n"; | ||
| 1565 | |||
| 1566 | # my $pr = $s->def_inputvars($ar); | ||
| 1567 | my $sn = $ar->{sid}; # server id | ||
| 1568 | my $url = $ar->{web_url}; # web URL | ||
| 1569 | $url =~ s/(\?.*)// if $url; # remove parameters | ||
| 1570 | $url .= "?pid=ckpt"; | ||
| 1571 | $url .= "&sel_sn1=$sn" if $sn; | ||
| 1572 | my $f_sid = (exists $ar->{study_id} && $ar->{study_id} =~ /^\d+$/) ? 1 : 0; | ||
| 1573 | my $study_id = ($f_sid) ? $ar->{study_id} : ''; | ||
| 1574 | $url .= "&study_id=$study_id" if $f_sid; | ||
| 1575 | |||
| 1576 | my $t = ""; | ||
| 1577 | for my $i (0..$#$avl) { | ||
| 1578 | my $k = $avl->[$i]; | ||
| 1579 | my $v = $alb->{$k}; | ||
| 1580 | next if $k =~ /^0$/; | ||
| 1581 | if ($k =~ /^\d+/) { | ||
| 1582 | if ($k !~ /^0$/) { | ||
| 1583 | $t .= "</ul>\n"; | ||
| 1584 | $v =~ s/_//g if $v; | ||
| 1585 | $t .= sprintf $f_bb, "$k - $v"; | ||
| 1586 | } | ||
| 1587 | next; | ||
| 1588 | } | ||
| 1589 | $t .= sprintf $f_li, "$url&task=$k&a=help", $v | ||
| 1590 | } | ||
| 1591 | $s->disp_task_form($q,$ar,$t); | ||
| 1592 | |||
| 1593 | return; | ||
| 1594 | |||
| 1595 | } | ||
| 1596 | |||
| 1597 | 1; | ||
| 1598 | |||
| 1599 | =head1 HISTORY | ||
| 1600 | |||
| 1601 | =over 4 | ||
| 1602 | |||
| 1603 | =item * Version 0.10 | ||
| 1604 | |||
| 1605 | This version extracted from jp2.pl on 09/08/2010. | ||
| 1606 | |||
| 1607 | =item * Version 0.20 | ||
| 1608 | |||
| 1609 | 09/08/2010 (htu): | ||
| 1610 | 1. start this PM | ||
| 1611 | 01/05/2012 (htu): added disp_htmlrpt | ||
| 1612 | |||
| 1613 | =cut | ||
| 1614 | |||
| 1615 | =head1 SEE ALSO (some of docs that I check often) | ||
| 1616 | |||
| 1617 | Oracle::Loader, Oracle::Trigger, CGI::AppBuilder, File::Xcopy, | ||
| 1618 | CGI::AppBuilder::Message | ||
| 1619 | |||
| 1620 | =head1 AUTHOR | ||
| 1621 | |||
| 1622 | Copyright (c) 2009 Hanming Tu. All rights reserved. | ||
| 1623 | |||
| 1624 | This package is free software and is provided "as is" without express | ||
| 1625 | or implied warranty. It may be used, redistributed and/or modified | ||
| 1626 | under the terms of the Perl Artistic License (see | ||
| 1627 | http://www.perl.com/perl/misc/Artistic.html) | ||
| 1628 | |||
| 1629 | =cut | ||
| 1630 |