| 1 | package LIMS::Web::Interface; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | our $VERSION = '1.4'; | |||||||||
| 6 | |||||||||||
| 7 | { package lims_interface; | ||||||||||
| 8 | |||||||||||
| 9 | 1 | require LIMS::Base; | |||||||||
| 10 | 1 | ▶ | use CGI qw( :standard :html3 *table *Tr *td *div *p ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | our @ISA = qw( lims ); | |||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||
| 15 | 0 | my $self = shift; | |||||||||
| 16 | 0 | $self->SUPER::DESTROY; | |||||||||
| 17 | } | ||||||||||
| 18 | 0 | ▶ | sub start_cgi { | ||||||||
|
Subroutine
start_cgi: not called CC=2 SCAR=17.9
| |||||||||||
| 19 | 0 | my $self = shift; | |||||||||
| 20 | 0 | ▶ | my $q = new CGI or die "Could not create CGI object"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 0 | $self->{ _cgi } = $q; | |||||||||
| 22 | } | ||||||||||
| 23 | 0 | ▶ | sub get_cgi { | ||||||||
|
Subroutine
get_cgi: not called CC=2 SCAR=17.9
| |||||||||||
| 24 | 0 | my $self = shift; | |||||||||
| 25 | 0 | ▶ | unless (defined $self->{ _cgi }){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | $self->start_cgi; | |||||||||
| 27 | } | ||||||||||
| 28 | 0 | $self->{ _cgi }; | |||||||||
| 29 | } | ||||||||||
| 30 | 0 | ▶ | sub has_cgi { | ||||||||
|
Subroutine
has_cgi: not called CC=2 SCAR=17.9
| |||||||||||
| 31 | 0 | my $self = shift; | |||||||||
| 32 | 0 | ▶ | if (defined $self->{ _cgi }){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | return 1; | |||||||||
| 34 | } else { | ||||||||||
| 35 | 0 | return; | |||||||||
| 36 | } | ||||||||||
| 37 | } | ||||||||||
| 38 | 0 | ▶ | sub page_title { | ||||||||
|
Subroutine
page_title: not called CC=1 SCAR=6.9
| |||||||||||
| 39 | 0 | my $self = shift; | |||||||||
| 40 | 0 | $self->{ _page_title }; | |||||||||
| 41 | } | ||||||||||
| 42 | 0 | ▶ | sub css { | ||||||||
|
Subroutine
css: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | 0 | return; | |||||||||
| 44 | } | ||||||||||
| 45 | 0 | ▶ | sub verbatim { | ||||||||
|
Subroutine
verbatim: not called CC=1 SCAR=6.9
| |||||||||||
| 46 | 0 | return; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | ▶ | sub print_header { | ||||||||
|
Subroutine
print_header: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | 0 | my $self = shift; | |||||||||
| 50 | 0 | $self->print_cgi_header; | |||||||||
| 51 | 0 | $self->print_title; | |||||||||
| 52 | } | ||||||||||
| 53 | 0 | ▶ | sub print_title { | ||||||||
|
Subroutine
print_title: not called CC=2 SCAR=17.9
| |||||||||||
| 54 | 0 | my $self = shift; | |||||||||
| 55 | 0 | ▶ | return if ($self->title_printed); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | my $q = $self->get_cgi; | |||||||||
| 57 | 0 | print $q->h1($self->page_title); | |||||||||
| 58 | 0 | $self->{ _title } = 1; | |||||||||
| 59 | } | ||||||||||
| 60 | 0 | ▶ | sub print_footer { | ||||||||
|
Subroutine
print_footer: not called CC=3 SCAR=24.8
| |||||||||||
| 61 | 0 | my $self = shift; | |||||||||
| 62 | 0 | ▶ | return if ($self->footer_printed); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | ▶ | $self->print_header unless ($self->header_printed); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | print $self->footer; | |||||||||
| 65 | 0 | $self->{ _footer } = 1; | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | ▶ | sub print_cgi_header { | ||||||||
|
Subroutine
print_cgi_header: not called CC=2 SCAR=17.9
| |||||||||||
| 68 | 0 | my $self = shift; | |||||||||
| 69 | 0 | ▶ | return if ($self->header_printed); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | my $q = $self->get_cgi; | |||||||||
| 71 | 0 | my $home_id = $self->home_id; | |||||||||
| 72 | 0 | my $base_url = $self->base_url; | |||||||||
| 73 | 0 | my $css = $self->css; | |||||||||
| 74 | 0 | my $verbatim = $self->verbatim; | |||||||||
| 75 | 0 | my $javascript = $self->javascript; | |||||||||
| 76 | 0 | my $bgcolor = $self->bgcolor; | |||||||||
| 77 | 0 | my $font_color = $self->font_color; | |||||||||
| 78 | |||||||||||
| 79 | 0 | print $q->header( -type => "text/html", -expires => "+30m" ), | |||||||||
| 80 | $q->start_html( -title=>$home_id, | ||||||||||
| 81 | -script=>$javascript, | ||||||||||
| 82 | -style=>{ -verbatim=>$verbatim, | ||||||||||
| 83 | -src=>$css }, | ||||||||||
| 84 | -topmargin=>0, | ||||||||||
| 85 | -leftmargin=>0, | ||||||||||
| 86 | -marginheight=>0, | ||||||||||
| 87 | -marginwidth=>0, | ||||||||||
| 88 | -bgcolor=>$bgcolor, | ||||||||||
| 89 | -text=>$font_color | ||||||||||
| 90 | ); | ||||||||||
| 91 | 0 | $self->{ _cgi_header } = 1; | |||||||||
| 92 | } | ||||||||||
| 93 | # the javascript value can be a hash ref containing one or more urls to javascript files | ||||||||||
| 94 | # of the kind { -language => 'JAVASCRIPT', -src => $url } | ||||||||||
| 95 | # or a HERE string of formatted javascript code to be included in the <HEAD> tag | ||||||||||
| 96 | # either way, this has to be specified in your script, and the default is null | ||||||||||
| 97 | 0 | ▶ | sub javascript { | ||||||||
|
Subroutine
javascript: not called CC=2 SCAR=17.9
| |||||||||||
| 98 | 0 | my $self = shift; | |||||||||
| 99 | @_ ? $self->{ _javascript } = shift | ||||||||||
| 100 | 0 | ▶ | : $self->{ _javascript }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | } | ||||||||||
| 102 | 0 | ▶ | sub right_graphic { | ||||||||
|
Subroutine
right_graphic: not called CC=3 SCAR=24.8
| |||||||||||
| 103 | 0 | my $self = shift; | |||||||||
| 104 | 0 | ▶ | if (@_){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | $self->{ _right_graphic } = shift; | |||||||||
| 106 | } else { | ||||||||||
| 107 | 0 | ▶ | if (defined $self->{ _right_graphic }){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | $self->{ _right_graphic }; | |||||||||
| 109 | } else { | ||||||||||
| 110 | 0 | $self->default_right_graphic; | |||||||||
| 111 | } | ||||||||||
| 112 | } | ||||||||||
| 113 | } | ||||||||||
| 114 | 0 | ▶ | sub breadcrumb_printed { | ||||||||
|
Subroutine
breadcrumb_printed: not called CC=1 SCAR=6.9
| |||||||||||
| 115 | 0 | my $self = shift; | |||||||||
| 116 | 0 | $self->{ _breadcrumb }; | |||||||||
| 117 | } | ||||||||||
| 118 | 0 | ▶ | sub sidebar_printed { | ||||||||
|
Subroutine
sidebar_printed: not called CC=1 SCAR=6.9
| |||||||||||
| 119 | 0 | my $self = shift; | |||||||||
| 120 | 0 | $self->{ _sidebar }; | |||||||||
| 121 | } | ||||||||||
| 122 | 0 | ▶ | sub header_printed { | ||||||||
|
Subroutine
header_printed: not called CC=1 SCAR=6.9
| |||||||||||
| 123 | 0 | my $self = shift; | |||||||||
| 124 | 0 | $self->{ _cgi_header }; | |||||||||
| 125 | } | ||||||||||
| 126 | 0 | ▶ | sub title_printed { | ||||||||
|
Subroutine
title_printed: not called CC=1 SCAR=6.9
| |||||||||||
| 127 | 0 | my $self = shift; | |||||||||
| 128 | 0 | $self->{ _title }; | |||||||||
| 129 | } | ||||||||||
| 130 | 0 | ▶ | sub footer_printed { | ||||||||
|
Subroutine
footer_printed: not called CC=1 SCAR=6.9
| |||||||||||
| 131 | 0 | my $self = shift; | |||||||||
| 132 | 0 | $self->{ _footer }; | |||||||||
| 133 | } | ||||||||||
| 134 | #ÊVery dirty way of moving parameters from one script to the next. | ||||||||||
| 135 | #ÊOught to be a better way to do it. | ||||||||||
| 136 | 0 | ▶ | sub param_forward { | ||||||||
|
Subroutine
param_forward: not called CC=3 SCAR=24.8
| |||||||||||
| 137 | 0 | my $self = shift; | |||||||||
| 138 | 0 | ▶ | return if ($self->forward_done); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 139 | # Get all parameter names | ||||||||||
| 140 | 0 | my $q = $self->get_cgi; | |||||||||
| 141 | 0 | my @aParam_Names = $q->param; | |||||||||
| 142 | 0 | for my $param(@aParam_Names){ | |||||||||
| 143 | 0 | print $q->hidden($param,$q->param($param)); | |||||||||
| 144 | } | ||||||||||
| 145 | 0 | $self->{ _forward } = 1; | |||||||||
| 146 | } | ||||||||||
| 147 | 0 | ▶ | sub min_param_forward { | ||||||||
|
Subroutine
min_param_forward: not called CC=3 SCAR=24.8
| |||||||||||
| 148 | 0 | my $self = shift; | |||||||||
| 149 | 0 | ▶ | return if ($self->forward_done); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 150 | 0 | my $q = $self->get_cgi; | |||||||||
| 151 | 0 | my @aParam = ('user_name','personnel_id','session_id'); | |||||||||
| 152 | 0 | for my $param (@aParam){ | |||||||||
| 153 | 0 | print $q->hidden($param,$q->param($param)); | |||||||||
| 154 | } | ||||||||||
| 155 | 0 | $self->{ _forward } = 1; | |||||||||
| 156 | } | ||||||||||
| 157 | 0 | ▶ | sub forward_done { | ||||||||
|
Subroutine
forward_done: not called CC=1 SCAR=6.9
| |||||||||||
| 158 | 0 | my $self = shift; | |||||||||
| 159 | 0 | $self->{ _forward }; | |||||||||
| 160 | } | ||||||||||
| 161 | 0 | ▶ | sub finish { | ||||||||
|
Subroutine
finish: not called CC=1 SCAR=6.9
| |||||||||||
| 162 | 0 | my $self = shift; | |||||||||
| 163 | 0 | $self->param_forward; | |||||||||
| 164 | 0 | $self->print_footer; | |||||||||
| 165 | } | ||||||||||
| 166 | 0 | ▶ | sub format_url_base_query { | ||||||||
|
Subroutine
format_url_base_query: not called CC=3 SCAR=24.8
| |||||||||||
| 167 | 0 | my $self = shift; | |||||||||
| 168 | 0 | my $q = $self->get_cgi; | |||||||||
| 169 | 0 | ▶ | return if ($q->param('logout')); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | 0 | ▶ | if (my $user_name = $self->db_user_name){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 171 | 0 | my $personnel_id = $self->personnel_id; | |||||||||
| 172 | 0 | my $session_id = $self->session_id; | |||||||||
| 173 | 0 | return "?user_name=$user_name&personnel_id=$personnel_id&session_id=$session_id"; | |||||||||
| 174 | } else { | ||||||||||
| 175 | 0 | return; | |||||||||
| 176 | } | ||||||||||
| 177 | } | ||||||||||
| 178 | 0 | ▶ | sub format_full_url_query { | ||||||||
|
Subroutine
format_full_url_query: not called CC=2 SCAR=17.9
| |||||||||||
| 179 | 0 | my $self = shift; | |||||||||
| 180 | 0 | my $q = $self->get_cgi; | |||||||||
| 181 | 0 | my @aParam_Names = $q->param; | |||||||||
| 182 | 0 | my $query_string = '?'; | |||||||||
| 183 | 0 | for my $param(@aParam_Names){ | |||||||||
| 184 | 0 | $query_string .= "$param=".$q->param($param)."&"; | |||||||||
| 185 | } | ||||||||||
| 186 | 0 | $query_string =~ s/&$//; | |||||||||
| 187 | 0 | return $query_string; | |||||||||
| 188 | } | ||||||||||
| 189 | 0 | ▶ | sub url_add_params { | ||||||||
|
Subroutine
url_add_params: not called CC=2 SCAR=17.9
| |||||||||||
| 190 | 0 | my $self = shift; | |||||||||
| 191 | 0 | my $link = shift; | |||||||||
| 192 | 0 | my $aParams = shift; | |||||||||
| 193 | 0 | my $q = $self->get_cgi; | |||||||||
| 194 | 0 | for my $param (@$aParams){ | |||||||||
| 195 | 0 | $link .= "&$param=".$q->param($param); | |||||||||
| 196 | } | ||||||||||
| 197 | 0 | return $link; | |||||||||
| 198 | } | ||||||||||
| 199 | 0 | ▶ | sub redirect_add_params { | ||||||||
|
Subroutine
redirect_add_params: not called CC=1 SCAR=6.9
| |||||||||||
| 200 | 0 | my $self = shift; | |||||||||
| 201 | 0 | $self->url_add_params($self->format_redirect(shift),shift); # shifting $script, $aParams | |||||||||
| 202 | } | ||||||||||
| 203 | 0 | ▶ | sub format_redirect { | ||||||||
|
Subroutine
format_redirect: not called CC=1 SCAR=6.9
| |||||||||||
| 204 | 0 | my $self = shift; | |||||||||
| 205 | 0 | my $script = shift; | |||||||||
| 206 | 0 | return "http://".$self->base_url."/cgi-bin/$script".$self->format_url_base_query; | |||||||||
| 207 | } | ||||||||||
| 208 | 0 | ▶ | sub format_redirect_full { | ||||||||
|
Subroutine
format_redirect_full: not called CC=1 SCAR=6.9
| |||||||||||
| 209 | 0 | my $self = shift; | |||||||||
| 210 | 0 | my $script = shift; | |||||||||
| 211 | 0 | return "http://".$self->base_url."/cgi-bin/$script".$self->format_full_url_query; | |||||||||
| 212 | } | ||||||||||
| 213 | 0 | ▶ | sub referring_page { | ||||||||
|
Subroutine
referring_page: not called CC=2 SCAR=17.9
| |||||||||||
| 214 | 0 | my $self = shift; | |||||||||
| 215 | @_ ? $self->{ _referring_page } = shift | ||||||||||
| 216 | 0 | ▶ | : $self->{ _referring_page }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 217 | } | ||||||||||
| 218 | 0 | ▶ | sub is_back_sensitive { | ||||||||
|
Subroutine
is_back_sensitive: not called CC=1 SCAR=6.9
| |||||||||||
| 219 | 0 | my $self = shift; | |||||||||
| 220 | 0 | $self->back_sensitive(1); | |||||||||
| 221 | } | ||||||||||
| 222 | 0 | ▶ | sub back_sensitive { | ||||||||
|
Subroutine
back_sensitive: not called CC=2 SCAR=17.9
| |||||||||||
| 223 | 0 | my $self = shift; | |||||||||
| 224 | 0 | my $q = $self->get_cgi; | |||||||||
| 225 | 0 | ▶ | @_ ? $q->param('back_sensitive',1) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 226 | : $q->param('back_sensitive'); | ||||||||||
| 227 | } | ||||||||||
| 228 | 0 | ▶ | sub not_back_sensitive { | ||||||||
|
Subroutine
not_back_sensitive: not called CC=1 SCAR=6.9
| |||||||||||
| 229 | 0 | my $self = shift; | |||||||||
| 230 | 0 | my $q = $self->get_cgi; | |||||||||
| 231 | 0 | $q->delete('back_sensitive'); | |||||||||
| 232 | } | ||||||||||
| 233 | 0 | ▶ | sub print_standard_errors { | ||||||||
|
Subroutine
print_standard_errors: not called CC=5 SCAR=34.0
| |||||||||||
| 234 | 0 | my $self = shift; | |||||||||
| 235 | 0 | ▶ | return unless (my $aErrors = $self->standard_error); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 236 | 0 | ▶ | if ($self->has_cgi){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 237 | 0 | my $q = $self->get_cgi; | |||||||||
| 238 | 0 | ▶ | $self->print_header unless ($self->title_printed); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 239 | 0 | print $q->start_p; | |||||||||
| 240 | 0 | for my $error (@$aErrors){ | |||||||||
| 241 | 0 | print $q->em($error), br; | |||||||||
| 242 | } | ||||||||||
| 243 | 0 | print $q->end_p; | |||||||||
| 244 | } else { | ||||||||||
| 245 | 0 | print $self->get_error_string($aErrors); | |||||||||
| 246 | } | ||||||||||
| 247 | } | ||||||||||
| 248 | 0 | ▶ | sub upload_file { | ||||||||
|
Subroutine
upload_file: not called CC=2 SCAR=14.4
| |||||||||||
| 249 | 1 | ▶ | use CGI::Upload; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 250 | 0 | my $self = shift; | |||||||||
| 251 | 0 | my $var = shift; # the param name | |||||||||
| 252 | 0 | my ($file_name,$filehandle); | |||||||||
| 253 | 0 | my $upload = CGI::Upload->new; | |||||||||
| 254 | 0 | ▶ | if (@_){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 255 | 0 | $file_name = shift; # user defined file name without extension | |||||||||
| 256 | 0 | my $upload_name = $upload->file_name($var); | |||||||||
| 257 | 0 | $upload_name =~ s/.*\./\./; # leave upload file extension | |||||||||
| 258 | 0 | $file_name .= $upload_name; # append upload file extension | |||||||||
| 259 | } else { | ||||||||||
| 260 | 0 | $file_name = $upload->file_name($var); | |||||||||
| 261 | } | ||||||||||
| 262 | 0 | $filehandle = $upload->file_handle($var); | |||||||||
| 263 | 0 | return ($filehandle,$file_name); | |||||||||
| 264 | } | ||||||||||
| 265 | 0 | ▶ | sub bgcolor { | ||||||||
|
Subroutine
bgcolor: not called CC=1 SCAR=6.9
| |||||||||||
| 266 | 0 | '#FFFFFF' | |||||||||
| 267 | } | ||||||||||
| 268 | 0 | ▶ | sub font_color { | ||||||||
|
Subroutine
font_color: not called CC=1 SCAR=6.9
| |||||||||||
| 269 | 0 | '#000000' | |||||||||
| 270 | } | ||||||||||
| 271 | } | ||||||||||
| 272 | |||||||||||
| 273 | 1 | 1; | |||||||||
| 274 | |||||||||||
| 275 | __END__ | ||||||||||