"Fossies" - the Fresh Open Source Software Archive

Member "metadot/metadot/Metadot/SystemApp/AppObjectField.pm" (10 Nov 2005, 4420 Bytes) of package /linux/www/old/Metadot6.4.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AppObjectField.pm" see the Fossies "Dox" file reference documentation.

    1 ###########################################################################
    2 # <LICENSEINFO>
    3 # Copyright (C) Daniel Guermeur - 1999-2001
    4 # Copyright (C) Metadot Corporation - 2001-2005
    5 #
    6 # This file is part of Metadot Portal Server software $Name: Release_6_4_5_4 $
    7 #
    8 # Metadot Portal Server software is free software; you can
    9 # redistribute it and/or modify it under the terms of the GNU General Public
   10 # License as published by the Free Software Foundation; either version 2 of
   11 # the License, or (at your option) any later version.
   12 #
   13 # Metadot Portal Server software is distributed in the hope that it
   14 # will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   15 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
   16 # Public License for more details.
   17 #
   18 # You should have received a copy of the GNU General Public License along with
   19 # Metadot Portal Server; if not, write to the Free Software
   20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21 #
   22 # For more information, please contact info@metadot.com.
   23 #</LICENSEINFO>
   24 ############################################################################
   25 package Metadot::SystemApp::AppObjectField;
   26 use strict;
   27 
   28 use Metadot::SystemApp::Util;
   29 
   30 my $util = Metadot::SystemApp::Util->new();
   31 
   32 ############################################################################
   33 ##  constructor
   34 ############################################################################
   35 sub new {
   36     my $proto = shift;
   37     my $class = ref($proto) || $proto;
   38     my $params = shift;
   39     # if constructor was called with parameter - hash
   40     unless (defined $params && ref $params) {
   41         $params = {};
   42     }
   43 
   44     my $self = $params;
   45 
   46     bless ($self, $class);
   47     return $self;
   48 }
   49 
   50 ############################################################################
   51 #   instance methods
   52 ############################################################################
   53 sub set_value {
   54     my $self = shift;
   55     my $field_name = shift;
   56     my $field_value = shift;
   57 
   58     $self->{$field_name} = $field_value;
   59 }
   60 
   61 sub get_value {
   62     my $self = shift;
   63     my $field_name = shift;
   64     my $field_value = $self->{$field_name};
   65 
   66     return $field_value;
   67 }
   68 
   69 sub key {
   70     my $self = shift;
   71     return $self->get_value('key');
   72 }
   73 
   74 sub type {
   75     my $self = shift;
   76     return $self->get_value('type');
   77 }
   78 
   79 sub get_search_value {
   80     my $self = shift;
   81     my $form = shift;
   82     my $suffix = shift || '';
   83     return '' unless $form;
   84 
   85     return $form->{"search_".$self->key().$suffix};
   86 }
   87 
   88 sub get_search_tag {
   89     my $self = shift;
   90     my $type = $self->get_value('type');
   91     my $parameter = shift;
   92     my $value = undef;
   93     $value = $parameter unless (ref $parameter);
   94     $value ||= $self->get_value('value');
   95     $value ||= $parameter->{"search_".$self->key()} if (ref $parameter);
   96     $value ||= '';
   97 
   98     my $out = "";
   99 
  100     $out = "<INPUT TYPE=text size=7 name=\"search_".$self->key()."\" value=\"".$value."\">";
  101     return $out;
  102 }
  103 
  104 sub get_search_condition {
  105     my $self = shift;
  106     my $form = shift;
  107     my $persistent_fields = shift || {};
  108     my $key = $self->key();
  109     return "1 = 1" unless (defined $persistent_fields->{$key});
  110     my $value = $form->{"search_".$key};
  111     my $type = $self->get_value('type');
  112 
  113     return "1 = 1" unless (defined $value && $value ne '');
  114 
  115     if ($type eq 'number') {
  116         $value =~ s/\D//g;
  117         return "1 = 1" if ("$value" eq "");
  118         return $key." = ".$value;
  119     } elsif ($type eq 'datetime') {
  120         my $from = $form->{"search_".$key};
  121         my $to = $form->{"search_".$key."_to"};
  122         $from = $util->date_to_time($from);
  123         $to   = $util->date_to_time($to);
  124         $to = time() if ($to < $from);
  125         #print STDERR "************************\n$from :: $to\n*************************\n";
  126         return $key." >= ".$from." and ".$key." <= ".$to;
  127     }
  128 
  129     return $key." LIKE '\%".$value."\%'";
  130 }
  131 
  132 sub get_list_tag {
  133     my $self = shift;
  134     my $value = shift || $self->get_value('value');
  135     my $type = $self->get_value('type');
  136 
  137     if ($type eq 'datetime') {
  138         return $util->format_datetime($value, 'M D, Y');
  139     } elsif ($type eq 'number') {
  140         return defined ($value) ? $value : 0;
  141     } elsif ($type eq 'boolean') {
  142         return "$value" eq "1" ? "<font class='yes'>Yes</font>" : "<font class='no'>No</font>";
  143     }
  144 
  145     $value ||= 'N/A';
  146     return $value;
  147 }
  148 
  149 1;