Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use lib q{..};
- use RMS;
- use RMS::Db;
- use RMS::Page;
- use CGI qw(:standard);
- use Switch;
- use Data::Dumper;
- use strict;
- #Variable definitions
- my $page = new RMS::Page({-header => {-title => 'RMS Support Site | Fix Reserved status '}});
- my $db = new RMS::Db;
- my $cgi = $page->cgi;
- my $query1 = 'query_1.sql';
- my $query2 = 'query_2.sql';
- my $serial_no;
- my $login_id = $page->session->param("user");
- my $type = $cgi->param("type");
- my $serial_no = $cgi->param("serial_no");
- my $final_query;
- my $database;
- my $sth;
- my $content;
- #Functions definitions
- sub checkUpdateNeeded{
- #args should follow this order: database, serial_no
- my $query = "select nvl(to_char(status_cd), 'null'), equip_status_id from rms.serial_inventory where serial_no = ?";
- my ($subdb, $serial) = @_;
- my ($status_cd, $equip_status_id) = $subdb->selectrow_array($query , undef, $serial);
- if(($status_cd eq "null") && ($equip_status_id eq 14)){
- return 1;
- }elsif(($status_cd ne "null") && ($equip_status_id eq 14)){
- return 2;
- } else{
- return 0;
- }
- }
- sub updateESNDatabase{
- #args should follow this order: database, final_query
- my ($subdb, $query) = @_;
- $content .= "$query";
- #$sth = $subdb->prepare($_);
- #$sth->execute() or die $subdb->errstr;
- #$sth->finish();
- $content = "<h1>Update completed</h1>";
- }
- #it should only enter here when the user confirmed that he wants to proceed with those updates
- if ($final_query) {
- $content = "<h1>primeiro if</h1>";
- #updateESNDatabase($database, $final_query);
- #it only enters here if the user type the ESN
- }elsif ($serial_no) {
- if ("$type" eq "RHS") {
- $database = $db->dbrhsa;
- }elsif ("$type" eq "LFO") {
- $database = $db->lfoarchive;
- }
- switch(checkUpdateNeeded($database, $serial_no)) {
- case 0 {
- $content .= "<br><br><b>There is no need to update the ESN</b>";
- $page->set_content($content);
- $page->process;
- }
- case 1 {
- $final_query = `cat $query1`;
- chop($final_query);
- $final_query =~ s/SERIALNUM/$serial_no/g;
- $final_query =~ s/LOGINID/$login_id/g;
- $content = $cgi->start_form .
- "<center>" .
- "<h3> Please double check the queries below before you update on database </h3>" .
- "</center>" .
- $cgi->submit("Confirm") . $cgi->end_form;
- $content .= $final_query;
- }
- case 2 {
- $final_query = `cat $query2`;
- chop($final_query);
- $final_query =~ s/SERIALNUM/$serial_no/g;
- $final_query =~ s/LOGINID/$login_id/g;
- $content = $cgi->start_form .
- "<center>" .
- "<h3> Please double check the queries below before you update on database </h3>" .
- "</center>" .
- $cgi->submit("Confirm") . $cgi->end_form;
- $content .= $final_query;
- }
- }
- #runs this if the page has just been opened or the user didn't type anything
- } else {
- $content = $cgi->start_form .
- "Serial #: " . $cgi->textfield("serial_no") . "<br>" .
- "<input type=\"radio\" name=\"type\" value=\"RHS\" checked> RHS <input type=\"radio\" name=\"type\" value=\"LFO\"> LFO" . "<br>" .
- $cgi->submit("Fix ESN") . $cgi->end_form;
- }
- $page->set_content($content);
- $page->process;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement