CGI-AppBuilder-Define

 view release on metacpan or  search on metacpan

Define.pm  view on Meta::CPAN

  my ($s, %args) = @_;
  return $s->SUPER::new(%args);
}

=head2 def_inputvars($ar)

Input variables:

  $ar	- array ref containing the following variables:
  	pid		: project id such as ckpt, owb, dba, etc.
  	task		: task name required such as task1,task2,etc.
  	target(sel_sn1)	: select one (DB/server name) defining sid
  	args(sel_sn2)	: select two (Arguments)
  	task_fn		: task file name containing all the tasks defined
  	svr_conn	: host/server connection info
  	db_conn		: db connection info for each target/server
  	task_conn	: special connection for tasks. 
  	                  It overwrites db_conn for the task
  	HA_*		: hash array

  
Variables used or routines called:

  None

=cut  

sub def_inputvars {
    my ($s, $ar) = @_;
    
    my $r = {};
    my $prg = 'AppBuilder::Define->def_inputvars'; 
    # set pre-defined variables
    my ($pid,$sn,$s2,$ds,$tsk) = ();
    $pid = $ar->{pid}		if exists $ar->{pid};
    $sn  = $ar->{target}  	if exists $ar->{target};
    $sn  = $ar->{sel_sn1} 	if exists $ar->{sel_sn1} && !$sn;
    $tsk = $s->set_param('task', $ar);
    if (!$pid) {
        print header("text/html");
        print start_html(%{$ar->{html_header}});
        $s->echo_msg("ERR: ($prg) project id has not been defined.",0);
        $s->disp_param($ar);
        return;
    }    
    if (!$sn) {
      my $msg = "ERR: ($prg) target/server/database has not been selected.";
      $s->echo_msg($msg,0)  if $tsk !~ /^(login)/;
      return;
    }    
    $s2 = $s->set_param('args', $ar) 	if exists $ar->{args}; 
    $s2 = $s->set_param('sel_sn2', $ar) if exists $ar->{sel_sn2} && !$s2; 
    if ($s2) { 
        my @b = split /:/, $s2;
        for my $i (0..$#b) { $r->{"a$i"} = $b[$i]; }
    }
    $ds = $ar->{dir_sep} 			if exists $ar->{dir_sep}; 
    $ds = ($^O =~ /^MSWin/i) ? '\\' : '/' 	if ! $ds; 
    $ar->{ds} = $ds				if ! exists $ar->{ds}; 

    my $usr_gid = (exists $ar->{guid} && $ar->{guid}) ? $ar->{guid} : ""; 
    my ($usr_sid,$usr_uid,$usr_tmo) = split /:/, $usr_gid; 
    $r->{guid}  = $usr_gid 	if $usr_gid; 
    $r->{pid}	= $pid;	$ar->{pid} = $pid;     
    $r->{sid}   = $sn;	$ar->{sid} = $sn; 
    $r->{dtm}	= strftime "%Y%m%d_%H%M%S", localtime; 
    $r->{dt} 	= substr $r->{dtm}, 0, 8;
    $r->{tm} 	= substr $r->{dtm}, 9, 6;
    $r->{y4} 	= substr $r->{dtm}, 0, 4;
    $r->{mm} 	= substr $r->{dtm}, 4, 2;
    $r->{dd} 	= substr $r->{dtm}, 6, 2;
    $r->{hh} 	= substr $r->{dtm}, 9, 2;
    $r->{mi} 	= substr $r->{dtm},11, 2;
    $r->{ss} 	= substr $r->{dtm},13, 2;
    $r->{vbs}   = $ar->{Verbose} if exists $ar->{Verbose}; 
    $r->{ds}    = $ds;     			# directory separator
    $r->{web_url} = "http://$ENV{HTTP_HOST}$ENV{REQUEST_URI}"; 
    $r->{web_url} =~ s/(\?.*)//; 			# remove parameters
    $r->{cgi_url}  = $ar->{script_url}	if exists $ar->{script_url}; 
    $ar->{ymd} = join $ds, $r->{y4}, $r->{mm}, $r->{dd}; 
    $ar->{hms} = "$r->{hh}$r->{mi}$r->{ss}"; 
    $ar->{web_url} = $r->{web_url}; 
    my ($usr_app,$usr_u2) = $s->get_params('app_user,user_uid',$ar);
    my $uuu = ($usr_uid) ? $usr_uid : $usr_u2; 
       $uuu = $usr_app		if !$uuu && $usr_app;
    if (!$uuu) {
        print header("text/html");
        print start_html(%{$ar->{html_header}});
        $s->echo_msg("ERR: ($prg) user id has not been defined.",0);
        $s->disp_param($ar);
        return;
    }        
    $r->{app_user}  = $uuu; 
    $ar->{app_user} = $uuu;
    
    # my $tsk	= lc $ar->{task};			# task name
    my $odr = {}; 				 	# Out dir
       $odr = eval $s->set_param('out_dir', $ar)
              if exists $ar->{out_dir} && $ar->{out_dir};
    # set outdir 
    my $ldir = ''; 
    if (exists $odr->{$sn}) {
      $r->{db_outdir}  = (exists $odr->{$sn}{db})  ? $odr->{$sn}{db}  : ''; 
      $r->{web_outdir} = (exists $odr->{$sn}{web}) ? $odr->{$sn}{web} : ''; 
      $r->{rpt_outdir} = (exists $odr->{$sn}{rpt}) ? $odr->{$sn}{rpt} : ''; 
      $r->{dsp_url}    = (exists $odr->{$sn}{dsp}) ? $odr->{$sn}{dsp} : '';
      $ldir            = (exists $odr->{$sn}{log}) ? $odr->{$sn}{log} : ''; 
      $r->{drv_map}    = (exists $odr->{$sn}{drv}) ? $odr->{$sn}{drv} : '';
    } else {
      $r->{db_outdir}  = $ar->{outdir} if exists $ar->{outdir}; 
      $r->{web_outdir} = $ar->{outdir} if exists $ar->{outdir}; 
      $r->{rpt_outdir} = $ar->{outdir} if exists $ar->{outdir};
      $r->{drv_map}    = '\\\\$sn';
      # $r->{dsp_url}    = $ar->{outdir} if exists $ar->{outdir}; 
      $ldir            = $ar->{outdir} if exists $ar->{outdir}; 
    }
    $r->{dsp_url} = $r->{web_url} if ! $r->{dsp_url}; 
    $r->{tgt_dir} = join $ds, $r->{web_outdir}, $sn, $tsk;
    $r->{log_dir} = join $ds, $r->{tgt_dir}, $r->{y4}, $r->{mm};
    $r->{sql_fn}  = join $ds, $r->{log_dir}, "s$r->{dtm}.sql"; 
    $ar->{drv_map} = $r->{drv_map}; 

    # set db connection



( run in 2.248 seconds using v1.01-cache-2.11-cpan-5735350b133 )