Want more features on Pastebin? Sign Up, it's FREE!
Guest

Perl # Symbol Breaks URL

By: a guest on Mar 2nd, 2011  |  syntax: Perl  |  size: 3.56 KB  |  views: 163  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package CGI_mis;
  2. use URI::Escape;
  3.  
  4. # I've only included two functions that I believe are key to the solution:
  5.  
  6. ################################################################################
  7. #
  8. # Name: GetAllParams
  9. #
  10. # Parameters:
  11. #
  12. # [I] $script - Name of script parameters have been passed to.
  13. #
  14. # Returns:
  15. #
  16. # Hash Ref - Containing all the parameters.
  17. #
  18. # Implementation:
  19. #
  20. # Gets all the parameters passed to the script, plus the default parameters
  21. # for this script, provided they have not been overridden.  Parameters with
  22. # multiple values are held in an array reference, as are single valued
  23. # parameters that are known to be able to hold multiple values.
  24. #
  25. # Params are got from CGI query, database defaults then PageConfig defaults
  26. # in that order.
  27. #
  28. ################################################################################
  29. sub GetAllParams
  30. {
  31.     my $script      = shift || basename($0);
  32.  
  33.     my %all_params;
  34.     my @params = $query->param();
  35.     my $p;
  36.  
  37.     my $db_defaults;
  38.  
  39.     foreach $p (@params)
  40.     {
  41.         @{$all_params{$p}} = $query->param($p);
  42.  
  43.         if(scalar(@{$all_params{$p}}) == 1)
  44.         {
  45.             # Make it scalar unless it's meant to be an array
  46.             if((! defined $PageConfig::scripts{$script}->{$p}) ||
  47.                ref($PageConfig::scripts{$script}->{$p}->{'default'}) ne 'ARRAY')
  48.             {
  49.                 $all_params{$p} = ${$all_params{$p}}[0];
  50.             }
  51.         }
  52.     }
  53.  
  54.     # Check any defaults that are not set
  55.  
  56.     # check the DB first
  57.     $db_defaults = PageConfig::GetDBDefaults($script);
  58.     if(defined $db_defaults)
  59.     {
  60.         foreach $p (keys %$db_defaults)
  61.         {
  62.             # Set the db default is it has not already been set
  63.             if(! defined $all_params{$p})
  64.             {
  65.                 $all_params{$p} = $db_defaults->{$p};
  66.             }
  67.         }
  68.     }
  69.  
  70.     # then the 'default' default
  71.     if(defined $PageConfig::scripts{$script})
  72.     {
  73.  
  74.         foreach $p (keys %{$PageConfig::scripts{$script}})
  75.         {
  76.             if(! defined $all_params{$p})
  77.             {
  78.                 $all_params{$p} =
  79.                     $PageConfig::scripts{$script}->{$p}->{'default'};
  80.             }
  81.         }
  82.     }
  83.  
  84.     return \%all_params;
  85. }
  86.  
  87.  
  88. ################################################################################
  89. #
  90. # Name: GetQueryString
  91. #
  92. # Parameters:
  93. #
  94. # $all_params_ref - Hash Ref contining all the params to construct the
  95. #                   query from.
  96. #
  97. # Returns:
  98. #
  99. # A text string of the built up query.
  100. #
  101. # Implementation:
  102. #
  103. # Simple concats the parameters together.
  104. #
  105. ################################################################################
  106. sub GetQueryString
  107. {
  108.     my $all_params_ref = shift || GetAllParams();
  109.  
  110.     my $q_string = "";
  111.  
  112.     foreach my $p (keys %$all_params_ref)
  113.     {
  114.         next if (! defined $all_params_ref->{$p});
  115.  
  116.         if(ref($all_params_ref->{$p}) eq 'ARRAY')
  117.         {
  118.             foreach (@{$all_params_ref->{$p}})
  119.             {
  120.                 $p = uri_escape($p);
  121.                 $q_string .= "$p=".uri_escape($_)."&";
  122.             }
  123.         }
  124.         else
  125.         {
  126.             $q_string .= "$p=".uri_escape($all_params_ref->{$p})."&";
  127.         }
  128.     }
  129.  
  130.     $q_string =~ s/\s/\%20/g if $q_string;
  131.     #$q_string =~ s/#/HASH/g;
  132.  
  133.     return $q_string;
  134. }
  135.  
  136. # end of CGI_mis
  137. #####################################
  138.  
  139.  
  140. # this is the line in the front end page that gets all the parameters from the above script
  141. my $all_params_ref = CGI_mis::GetAllParams($script);
clone this paste RAW Paste Data