ASNMTAP

 view release on metacpan or  search on metacpan

lib/ASNMTAP/Asnmtap/Applications/CGI.pm  view on Meta::CPAN

<br>
HTML

      $errorUserAccessControl = $logonRequest;
    }
  } elsif( $logonRequest eq "logoff" ) {
    print_header (*STDOUT, $pagedir, $pageset, $htmlTitle, "Logoff", 3600, '', 'F', '', $sessionID);
    $errorUserAccessControl = "Logged off remote user: " .$session->param('givenName'). " " .$session->param('familyName');
    print "<br>\n<h1 align=\"center\">$errorUserAccessControl</h1>\n";
    $session->delete();
    return ("", 0, 0, 0, 0, 1, 1, $errorUserAccessControl, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $subTitle);
  }

  $subTitle = setAccessControlParameters( $level, $pagedir, $pageset, $debug, $cgi, $session, $sessionID, $subTitle, $queryString );
  return ($sessionID, $session->param('iconAdd'), $session->param('iconDelete'), $session->param('iconDetails'), $session->param('iconEdit'), $session->param('iconQuery'), $session->param('iconTable'), $errorUserAccessControl, $session->param('remote...
}

# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

sub do_action_DBI {
  my ($rv, $dbh, $sql, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_;

  my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
  $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;
  my $numberRecordsIntoQuery = ($rv) ? $sth->fetchrow_array() : 0;
  $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;

  return ($rv, $numberRecordsIntoQuery);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub error_trap_DBI {
  my ($HTML, $error_message, $debug, $pagedir, $pageset, $htmlTitle, $subTitle, $refresh, $onload, $sessionID) = @_;

  my $subject = "$htmlTitle / error_trap_DBI: " . get_datetimeSignal();
  my $message = get_datetimeSignal() . "\npagedir   : $pagedir\npageset   : $pageset\nhtml title: $htmlTitle\n\nerror message:\n$error_message\n\n--> ERROR: $DBI::err ($DBI::errstr)\n";
  my $returnCode = sending_mail ( $SERVERLISTSMTP, $SENDEMAILTO, $SENDMAILFROM, $subject, $message, $debug );
  print "Problem sending email to the '$APPLICATION' server administrators\n" unless ( $returnCode );

  if ( $refresh == 0 ) {
    return (0, $error_message, "DBI Error: $DBI::err", "DBI String: $DBI::errstr");
  } elsif ( $refresh == -1 ) {
    print "<H1>DBI Error:</H1>\n", $error_message, "\n<br><br>ERROR: $DBI::err ($DBI::errstr)\n<BR>";
    return 0;
  } else {
    print_header ($HTML, $pagedir, $pageset, $htmlTitle, $subTitle, $refresh, $onload, 'F', '', $sessionID);
    print "<H1>DBI Error:</H1>\n", $error_message, "\n<br><br>ERROR: $DBI::err ($DBI::errstr)\n<BR>";
    return 0;
  }
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub check_record_exist {
  my ($rv, $dbh, $sql, $titleTXT, $keyTXT, $nameTXT, $matchingRecords, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_;

  my ($key, $title);
  my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
  $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;
  $sth->bind_columns( \$key, \$title ) or $rv = error_trap_DBI(*STDOUT, "Cannot sth->bind_columns: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;

  if ( $rv ) {
    if ( $sth->rows ) {
      $matchingRecords .= "<h1>$titleTXT:</h1><table><tr><th>$keyTXT</th><th>$nameTXT</th></tr>";
      while( $sth->fetch() ) { $matchingRecords .= "<tr><td>" .encode_html_entities('K', $key). "</td><td>" .encode_html_entities('T', $title). "</td></tr>"; }
      $matchingRecords .= "</table>\n";
    }

    $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
  }

  return ($rv, $matchingRecords);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub create_sql_query_events_from_range_year_month {
  my ($inputType, $startDate, $endDate, $sqlSelect, $sqlForce, $sqlWhere, $sqlPeriode, $sqlQuery, $sqlGroup, $sqlOrder, $sqlOrderUnion, $sqlUnionKeyword) = @_;

  $sqlUnionKeyword = 'ALL' if ($sqlUnionKeyword ne 'ALL' or $sqlUnionKeyword ne 'DISTINCT');

  my ($yearFrom,  $monthFrom,  $dayFrom) = split (/-/, $startDate);
  my ($yearTo,    $monthTo,    $dayTo)   = split (/-/, $endDate);

  use Date::Calc qw(Add_Delta_Days Delta_Days);
  my $deltaDays = Delta_Days ($yearFrom, $monthFrom, $dayFrom, $yearTo, $monthTo, $dayTo);

  my ($sql, $sqlUnion);

  if ( $deltaDays >=0 ) {
    my $sqlCommon = "$sqlSelect FROM `$SERVERTABLEVENTS` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder";

    if ( $SERVERMYSQLMERGE eq '1' ) {
      if ($inputType eq "year" and $yearFrom = $yearTo) {
        $sqlUnion = "union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". sprintf ("%04d", $yearFrom) ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)";
      } elsif ($inputType eq "quarter" and $monthFrom = $monthTo) {
        $sqlUnion = "union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". sprintf ("%04d", $yearFrom) ."_Q". (int(($monthFrom+2)/3)) ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)";
      }
    }

    unless (defined $sqlUnion) {
      foreach my $year ($yearFrom..$yearTo) {
        my $monthF = ($year == $yearFrom) ? $monthFrom : 1;
        my $monthT = ($year == $yearTo or $yearFrom == $yearTo) ? $monthTo : 12;

        foreach my $month ($monthF..$monthT) {
          my $yearTable  = sprintf ("%04d", $year);
          my $monthTable = sprintf ("%02d", $month);
          $sqlUnion .= " union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". $yearTable ."_". $monthTable ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)";
        }
      }
    }

    if (defined $sqlUnion) {
      $sql = "($sqlCommon) $sqlUnion $sqlOrderUnion";
    } else {
      $sql = $sqlCommon;
    }
  }
 
  return $sql;
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub create_sql_query_from_range_SLA_window {
  my (@days) = @_; # @_ => ($sunday, $monday, $tuesday, $wednesday, $thursday, $friday, $saturday)

  my ($day, $windowSLA) = (0);

  foreach my $periode (@days) {
    $day++;

    if ( defined $periode and $periode and $periode !~ /00:00-24:00/ ) {
      my @range = split (/,/, $periode);
      my $windowToday;

      foreach my $range (@range) {
        my ($from, $to) = split (/-/, $range);

        if ( defined $from and defined $to ) {
          $windowToday .= ' or ' if ( defined $windowToday );
          $windowToday .= "startTime BETWEEN '$from:00' and '$to:00'";
        }
      }

      if ( defined $windowToday ) {
        $windowSLA .= ' or ' if ( defined $windowSLA );
        $windowSLA .= '( DAYOFWEEK(startDate) = '. $day .' and ( '. $windowToday .' ) )'
      }
    }
  }

  return ( defined $windowSLA ? ' and ( '. $windowSLA .' )' : '' );
}

# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

sub get_title {
  my ($dbh, $rv, $catalogID, $uKey, $debug, $refresh, $sessionID) = @_;

  my ($sql, $sth, $errorMessage, $dbiErrorCode, $dbiErrorString, $title, $environment, $trendline, $step, $applicationTitle, $trendValue, $stepValue);
  $sql = "select concat( LTRIM(SUBSTRING_INDEX(title, ']', -1)), ' (', $SERVERTABLENVIRONMENT.label, ')' ), $SERVERTABLPLUGINS.environment, trendline, step from $SERVERTABLPLUGINS, $SERVERTABLENVIRONMENT WHERE catalogID = '$catalogID' and uKey = '$uK...
  $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", $refresh, '', $sessionID);
  $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", $refresh, '', $sessionID) if $rv;
  $sth->bind_columns( \$title, \$environment, \$trendline, \$step ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", $refresh, '', $sessionID) if $rv;

  if ( $rv ) {
    while( $sth->fetch() ) {
      $title =~ s/^[\[[\S+|\s+]*\]\s+]{0,1}([\S+|\s+]*)/$1/g;
      $applicationTitle = $title;
      $trendValue = $trendline;
      $stepValue = $step;
    }

    $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", $refresh, '', $sessionID);
  }

  if ( $refresh == 0 ) {
    return ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $applicationTitle, $trendValue, $stepValue);
  } elsif ( $refresh == -1 ) {
    return ($rv, $applicationTitle);
  } else {
    return ($rv, $applicationTitle, $trendValue);
  }
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub get_sql_crontab_scheduling_report_data {
  my ($dbh, $sql, $rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $sessionID, $hight, $hightMin, $uKeys, $labels, $stepValue, $catalogID, $uKeysSqlWhere, $debug) = @_;

  my ($collectorDaemon, $uKey, $lineNumber, $minute, $hour, $dayOfTheMonth, $monthOfTheYear, $dayOfTheWeek, $noOffline, $applicationTitle, $step);
  my $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID);
  $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
  $sth->bind_columns( \$collectorDaemon, \$uKey, \$lineNumber, \$minute, \$hour, \$dayOfTheMonth, \$monthOfTheYear, \$dayOfTheWeek, \$noOffline ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: ...

  my $numberOfLabels = 0;

  if ( $rv ) {
    if ( $sth->rows ) {
      while( $sth->fetch() ) {
        if (exists $$uKeys{$uKey}) {
          $$uKeys{$uKey}->{collectorDaemon} .= '|' .$collectorDaemon if ($collectorDaemon ne $$uKeys{$uKey}->{collectorDaemon});
          $$uKeys{$uKey}->{noOffline}       .= '|' .$noOffline if ($noOffline ne $$uKeys{$uKey}->{noOffline});
        } else {
          $$uKeys{$uKey}->{collectorDaemon}  = $collectorDaemon;
          $$uKeys{$uKey}->{noOffline}        = $noOffline;
          $$uKeys{$uKey}->{numberOfLabel}    = $numberOfLabels;

          if (defined $$uKeysSqlWhere) { $$uKeysSqlWhere .= (($$uKeysSqlWhere) ? ' OR ' : '') . "$SERVERTABLEVENTS.uKey = '$uKey'"; }

         ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $applicationTitle, undef, $step) = get_title( $dbh, $rv, $catalogID, $uKey, $debug, 0, $sessionID );

          if ($rv) {
            @$labels[$numberOfLabels] = $applicationTitle;
            @$stepValue[$numberOfLabels] = $step;
          }

          $numberOfLabels++;
        }

        $$uKeys{$uKey}->{lineNumbers}->{$lineNumber} = { minute => $minute, hour => $hour, dayOfTheMonth => $dayOfTheMonth, monthOfTheYear => $monthOfTheYear, dayOfTheWeek => $dayOfTheWeek };
      }
    } else {
      $hight = $hightMin; $rv = 0; $errorMessage = "There are no Crontabs available";
    }

    $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", 0, '', $sessionID);
  }

  return ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $hight, $numberOfLabels);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub get_sql_startDate_sqlEndDate_numberOfDays_test {
  my ($strictDate, $firstStartDate, $inputType, $selYear, $selQuarter, $selMonth, $selWeek, $selStartDate, $selEndDate, $currentYear, $currentMonth, $currentDay, $debug) = @_;

  use Date::Calc qw(Add_Delta_Days check_date Days_in_Month Delta_Days Monday_of_Week Week_of_Year);

  my ($startDate, $endDate, $goodDate);

  if ($inputType eq "fromto") {
    if (defined $selEndDate and $selEndDate ne '') {
      $startDate = $selStartDate;
      $endDate   = $selEndDate;
    } else {
      $startDate = $selStartDate;
      $endDate   = $selStartDate;
    }
  } elsif ($inputType eq "year") {
    $startDate = "$selYear-1-1";
    $endDate   = "$selYear-12-31";
  } elsif ($inputType eq "quarter") {
    my $fromQuarterMonth = $QUARTERS{ $selQuarter };

lib/ASNMTAP/Asnmtap/Applications/CGI.pm  view on Meta::CPAN

# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

sub create_combobox_from_keys_and_values_pairs {
  my ($comboboxSelectKeysAndValuesPairs, $sortOn, $sortNumeric, $Ckey, $selectName, $selectValue, $selectLabel, $formDisabled, $onChange, $debug) = @_;

  my %comboSelectKeysAndValuesPairs = map { my ($key, $value) = split (/=>/) } split (/\|/, $comboboxSelectKeysAndValuesPairs);

  my $comboSelect  = "<select name=\"$selectName\" $formDisabled $onChange>\n";

  if ($selectLabel ne '') {
    $comboSelect .= "          <option value=\"$selectValue\"";
    $comboSelect .= " selected" if ($Ckey eq $selectValue);
    $comboSelect .= ">$selectLabel</option>\n";
  }

  if ($sortOn eq 'K') {
    foreach my $key ( sort keys ( %comboSelectKeysAndValuesPairs ) ) {
      my $value = $comboSelectKeysAndValuesPairs{$key};
      $comboSelect .= "          <option value=\"$key\"";
      $comboSelect .= " selected" if ($Ckey eq $key);
      $comboSelect .= ">$value</option>\n";
    }
  } elsif ($sortOn eq 'V') {
    if ($sortNumeric) {
      foreach my $key ( sort { $comboSelectKeysAndValuesPairs{$a} <=> $comboSelectKeysAndValuesPairs{$b}; } keys ( %comboSelectKeysAndValuesPairs ) ) {
        my $value = $comboSelectKeysAndValuesPairs{$key};
        $comboSelect .= "          <option value=\"$key\"";
        $comboSelect .= " selected" if ($Ckey eq $key);
        $comboSelect .= ">$value</option>\n";
      }
    } else {
      foreach my $key ( sort { $comboSelectKeysAndValuesPairs{$a} cmp $comboSelectKeysAndValuesPairs{$b}; } keys ( %comboSelectKeysAndValuesPairs ) ) {
        my $value = $comboSelectKeysAndValuesPairs{$key};
        $comboSelect .= "          <option value=\"$key\"";
        $comboSelect .= " selected" if ($Ckey eq $key);
        $comboSelect .= ">$value</option>\n";
      }
    }
  } else {
    foreach my $key ( keys ( %comboSelectKeysAndValuesPairs ) ) {
      my $value = $comboSelectKeysAndValuesPairs{$key};
      $comboSelect .= "          <option value=\"$key\"";
      $comboSelect .= " selected" if ($Ckey eq $key);
      $comboSelect .= ">$value</option>\n";
    }
  }

  $comboSelect .= "        </select>\n";
  return ($comboSelect);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub create_combobox_from_DBI {
  my ($rv, $dbh, $sql, $firstOption, $nextAction, $Ckey, $selectName, $selectValue, $selectLabel, $formDisabled, $onChange, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_;

  my ($key, $value);

  my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
  $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;
  $sth->bind_columns( \$key, \$value) or $rv = error_trap_DBI(*STDOUT, "Cannot sth->bind_columns: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;

  my $comboSelect  = "<select name=\"$selectName\" $formDisabled $onChange>\n";

  if ($selectLabel ne '') {
    if ($firstOption or (! $firstOption and $Ckey eq $selectValue)) {
      $comboSelect .= "          <option value=\"$selectValue\"";
      $comboSelect .= " selected" if ($Ckey eq $selectValue);
      $comboSelect .= ">$selectLabel</option>\n";
    }
  }

  if ( $rv ) {
    while( $sth->fetch() ) {
      $comboSelect .= "          <option value=\"$key\"";

      if ($Ckey eq $key) {
        $htmlTitle = "$value: $nextAction" if ($nextAction ne '');
        $comboSelect .= " selected";
      }

      $comboSelect .= ">$value</option>\n";
    }

    $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
  }

  $comboSelect .= "        </select>\n";
  return ($rv, $comboSelect, $htmlTitle);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub create_combobox_multiple_from_DBI {
  my ($rv, $dbh, $sql, $action, $Ckey, $selectName, $selectValue, $selectSize, $textareaCols, $formDisabled, $onChange, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_;

  my ($key, $value);
  my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
  $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;
  $sth->bind_columns( \$key, \$value) or $rv = error_trap_DBI(*STDOUT, "Cannot sth->bind_columns: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;

  my $comboboxSelect = '';

  if ($rv) {
    if ( $sth->rows ) {
      my $comboboxSelectSize = 0;

      if ($action eq 'duplicateView' or $action eq 'editView' or $action eq 'insertView') {
        while( $sth->fetch() ) {
          $comboboxSelectSize++;
          $comboboxSelect .= "<option value=\"$key\"";
          $comboboxSelect .= " selected" if ($Ckey =~ /\/$key\//);
          $comboboxSelect .= ">$value</option>";
        }

        $comboboxSelectSize = ($comboboxSelectSize > $selectSize) ? $selectSize : $comboboxSelectSize;
        $comboboxSelect =  "<select name=\"$selectName\" id=\"${selectName}_id\" size=\"$comboboxSelectSize\" multiple $onChange>" .$comboboxSelect. "</select>";
      } else {
        while( $sth->fetch() ) {
          if ($Ckey =~ /\/$key\//) {
            $comboboxSelectSize++;
            $comboboxSelect .= "$value\n" if ($Ckey =~ /\/$key\//);
          }
        }

        $comboboxSelect = "<textarea name=$selectName cols=$textareaCols rows=$comboboxSelectSize $formDisabled>$comboboxSelect</textarea>";
      }
    } else {
      if ($action eq 'duplicateView' or $action eq 'editView' or $action eq 'insertView') {
        $comboboxSelect = "<select name=\"$selectName\" size=\"1\" multiple $onChange></select>";
      } else {
        $comboboxSelect = $selectValue;
      }
    }

    $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
  }

  return ($rv, $comboboxSelect);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub record_navigation_table {
  my ($rv, $dbh, $sql, $label, $keyLabels, $keyNumbers, $ignoreFieldNumbers, $translationFieldsKeysAndValues, $addAccessParameters, $orderBy, $header, $navigationBar, $iconAdd, $iconDelete, $iconDetails, $iconEdit, $nextAction, $pagedir, $pageset, $p...

  my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
  $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;

  my $matchingRecords = '';

  if ( $rv ) {
    my @keyLabels  = split (/\|/, $keyLabels);
	my @keyNumbers = split (/\|/, $keyNumbers);

    my @translationFieldsKeysAndValues = split (/\|\|/, $translationFieldsKeysAndValues);
    my %translationFieldKeyAndValue = ();

    foreach $translationFieldsKeysAndValues (@translationFieldsKeysAndValues) {
      my ($translationField, $translationKeysAndValues) = split (/#/, $translationFieldsKeysAndValues, 2);

lib/ASNMTAP/Asnmtap/Applications/CGI.pm  view on Meta::CPAN

    $currentPageNo = $numberOffPagesMax if ($currentPageNo > $numberOffPagesMax);
    my $wantedRecordFirst = (($currentPageNo - 1)  * $showRecordsOnPage) + 1;
    my $TwantedRecordLast = $wantedRecordFirst + ($showRecordsOnPage - 1);
    my $wantedRecordLast  = ($TwantedRecordLast < $numberRecordsIntoQuery) ? $TwantedRecordLast : $numberRecordsIntoQuery;

    my $numberOffRecords  = (($wantedRecordLast - 1) % $showRecordsOnPage) + 1;

    $navigationBar = "<table border=\"0\" width=\"100%\" bgcolor=\"$COLORSTABLE{ENDBLOCK}\"><tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td align=\"center\" width=\"36\">$currentPageNo/$numberOffPagesMax</td><td align=\"center\">";

    if ($wantedRecordLast > 1) {
      if ($currentPageNo > 1) {
        my $previousPage = $currentPageNo - 1;
        my $previousPageOffset = ($showRecordsOnPage * ($previousPage - 1));
        $navigationBar .= "&nbsp;<a href=\"$urlWithAccessParameters&amp;pageNo=1&amp;pageOffset=0\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{first}\" ALT=\"First\" BORDER=0></a>&nbsp;<a href=\"$urlWithAccessParameters&pageNo=$previousPage&pageOffset=$previ...
      } else {
        $navigationBar .= "&nbsp;1";
      }

      for (my $currentPage = 2; $currentPage < $numberOffPagesMax; $currentPage++) {
        if ( $currentPageNo != $currentPage ) {
          my $offsetOffRecords = ($showRecordsOnPage * ($currentPage - 1));
          $navigationBar .= "&nbsp;<a href=\"$urlWithAccessParameters&amp;pageNo=$currentPage&amp;pageOffset=$offsetOffRecords\">$currentPage</a>";
        } else {
          $navigationBar .= "&nbsp;$currentPage";
        }
      }

      if ($currentPageNo < $numberOffPagesMax) {
        my $nextPage = $currentPageNo + 1;
        my $nextPageOffset = ($showRecordsOnPage * ($nextPage - 1));
        my $lastPageOffset = ($showRecordsOnPage * ($numberOffPagesMax - 1));
        $navigationBar .= "&nbsp;<a href=\"$urlWithAccessParameters&amp;pageNo=$numberOffPagesMax&amp;pageOffset=$lastPageOffset\">$numberOffPagesMax</a>&nbsp;&nbsp;<a href=\"$urlWithAccessParameters&amp;pageNo=$nextPage&amp;pageOffset=$nextPageOffse...
      } else {
        $navigationBar .= "&nbsp;$numberOffPagesMax";
      }
    } else {
      $navigationBar .= "&nbsp;";
    }

    $navigationBar .= "</td></tr></table>\n";
  }

  return ($navigationBar);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub record_navigation_bar_alpha {
  my ($rv, $dbh, $table, $field, $where, $numberRecordsIntoQuery, $showRecordsOnPage, $urlWithAccessParameters, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_;

  my $navigationBarAlpha = '';

  if ( $numberRecordsIntoQuery > $showRecordsOnPage ) {
    $navigationBarAlpha = "<table border=\"0\" width=\"100%\" bgcolor=\"$COLORSTABLE{ENDBLOCK}\"><tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td align=\"center\">";

    my ($rownumber, $label);

    my $sql = "select DISTINCT \@rownum:=\@rownum+1 AS rownumber, LEFT($table.$field, 1) as AtoZ from (select \@rownum:=0) r, `$table` force index ($field) where $where group by AtoZ order by $field asc";
    my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
    $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;
    $sth->bind_columns( \$rownumber, \$label ) or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;

    if ( $rv ) {
      if ( $sth->rows ) {
        while( $sth->fetch() ) {
          my $currentPage = int ( ( $rownumber / $showRecordsOnPage ) - 0.001 );
          my $offsetOffRecords = $currentPage * $showRecordsOnPage;
          $currentPage++;
          $navigationBarAlpha .= "&nbsp;<a href=\"$urlWithAccessParameters&amp;pageNo=$currentPage&amp;pageOffset=$offsetOffRecords&amp;orderBy=$field asc\">$label</a>";
        }
      }
    }

    $navigationBarAlpha .= "</td></tr></table>\n";
  }

  return ($navigationBarAlpha);
}

# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

1;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

__END__

=head1 NAME

ASNMTAP::Asnmtap::Applications::CGI is a Perl module that provides a nice object oriented interface for ASNMTAP CGI Applications

=head1 Description

ASNMTAP::Asnmtap::Applications::CGI Subclass of ASNMTAP::Asnmtap::Applications

=head1 SEE ALSO

ASNMTAP::Asnmtap, ASNMTAP::Asnmtap::Applications

=head1 AUTHOR

Alex Peeters [alex.peeters@citap.be]

=head1 COPYRIGHT NOTICE

(c) Copyright 2000-2007 by Alex Peeters [alex.peeters@citap.be],
                        All Rights Reserved.

ASNMTAP is based on 'Process System daemons v1.60.17-01', Alex Peeters [alex.peeters@citap.be]

 Purpose: CronTab (CT, sysdCT),
          Disk Filesystem monitoring (DF, sysdDF),
          Intrusion Detection for FW-1 (ID, sysdID)
          Process System daemons (PS, sysdPS),
          Reachability of Remote Hosts on a network (RH, sysdRH),
          Rotate Logfiles (system activity files) (RL),
          Remote Socket monitoring (RS, sysdRS),
          System Activity monitoring (SA, sysdSA).

'Process System daemons' is based on 'sysdaemon 1.60' written by Trans-Euro I.T Ltd



( run in 1.595 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )