Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.20 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use lib q{..};
  3. use RMS;
  4. use RMS::Db;
  5. use RMS::Page;
  6. use CGI qw(:standard);
  7. use Switch;
  8. use Data::Dumper;
  9. use strict;
  10.  
  11. #Variable definitions
  12. my $page = new RMS::Page({-header => {-title => 'RMS Support Site | Fix Reserved status '}});
  13. my $db = new RMS::Db;
  14. my $cgi = $page->cgi;
  15. my $query1 = 'query_1.sql';
  16. my $query2 = 'query_2.sql';
  17. my $serial_no;
  18. my $login_id = $page->session->param("user");
  19. my $type = $cgi->param("type");
  20. my $serial_no = $cgi->param("serial_no");
  21. my $final_query;
  22. my $database;
  23. my $sth;
  24. my $content;
  25.  
  26. #Functions definitions
  27. sub checkUpdateNeeded{
  28. #args should follow this order: database, serial_no
  29.  
  30.     my $query  = "select nvl(to_char(status_cd), 'null'), equip_status_id from rms.serial_inventory where serial_no = ?";
  31.    
  32.     my ($subdb, $serial) = @_;
  33.    
  34.     my ($status_cd, $equip_status_id) = $subdb->selectrow_array($query , undef, $serial);
  35.    
  36.     if(($status_cd eq "null") && ($equip_status_id eq 14)){
  37.         return 1;
  38.     }elsif(($status_cd ne "null") && ($equip_status_id eq 14)){
  39.         return 2;
  40.     } else{
  41.         return 0;
  42.     }
  43. }
  44.  
  45. sub updateESNDatabase{
  46. #args should follow this order: database, final_query
  47.    
  48.     my ($subdb, $query) = @_;
  49.  
  50.     $content .= "$query";
  51.         #$sth = $subdb->prepare($_);
  52.         #$sth->execute() or die $subdb->errstr;
  53.         #$sth->finish();
  54.     $content = "<h1>Update completed</h1>";
  55. }
  56.  
  57. #it should only enter here when the user confirmed that he wants to proceed with those updates
  58. if ($final_query) {
  59.  
  60.         $content = "<h1>primeiro if</h1>";
  61. #updateESNDatabase($database, $final_query);
  62.  
  63. #it only enters here if the user type the ESN
  64. }elsif ($serial_no) {
  65.         if ("$type" eq "RHS") {
  66.             $database = $db->dbrhsa;
  67.         }elsif ("$type" eq "LFO") {
  68.             $database = $db->lfoarchive;
  69.         }
  70.             switch(checkUpdateNeeded($database, $serial_no)) {
  71.                 case 0 {
  72.                         $content .= "<br><br><b>There is no need to update the ESN</b>";
  73.                         $page->set_content($content);
  74.                         $page->process;
  75.                 }
  76.                 case 1 {
  77.                     $final_query = `cat $query1`;
  78.                     chop($final_query);
  79.                     $final_query =~ s/SERIALNUM/$serial_no/g;
  80.                     $final_query =~ s/LOGINID/$login_id/g;
  81.                     $content = $cgi->start_form .
  82.                     "<center>" .
  83.                         "<h3> Please double check the queries below before you update on database </h3>" .
  84.                     "</center>" .
  85.                     $cgi->submit("Confirm") . $cgi->end_form;
  86.                    
  87.                     $content .= $final_query;
  88.                    
  89.                 }
  90.                 case 2 {
  91.                     $final_query = `cat $query2`;
  92.                     chop($final_query);
  93.                     $final_query =~ s/SERIALNUM/$serial_no/g;
  94.                     $final_query =~ s/LOGINID/$login_id/g;
  95.                
  96.                     $content = $cgi->start_form .
  97.                     "<center>" .
  98.                         "<h3> Please double check the queries below before you update on database </h3>" .
  99.                     "</center>" .
  100.                     $cgi->submit("Confirm") . $cgi->end_form;
  101.                    
  102.                     $content .= $final_query;
  103.  
  104.                 }
  105.             }
  106. #runs this if the page has just been opened or the user didn't type anything
  107. } else {
  108.     $content = $cgi->start_form .
  109.         "Serial #:&nbsp;" . $cgi->textfield("serial_no") . "<br>" .
  110.         "<input type=\"radio\" name=\"type\" value=\"RHS\" checked> RHS <input type=\"radio\" name=\"type\" value=\"LFO\"> LFO" . "<br>" .
  111.         $cgi->submit("Fix ESN") . $cgi->end_form;
  112.  
  113. }
  114. $page->set_content($content);
  115. $page->process;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement