ASNMTAP

 view release on metacpan or  search on metacpan

applications/htmlroot/cgi-bin/comments.pl  view on Meta::CPAN

        if ($dbh and $rv) {
          if ($action eq 'insert' or $action eq 'create') {
            if ($CactivationDate eq '' or $CactivationTime eq '') {
              $CactivationDate     = $CentryDate;
              $CactivationTime     = $CentryTime;
              $CactivationTimeslot = $CentryTimeslot;
            }

            if ($CsuspentionDate eq '' or $CsuspentionTime eq '') {
              $CsuspentionDate     = "0000-00-00";
              $CsuspentionTime     = "00:00:00";
              $CsuspentionTimeslot = "9999999999";
            }

            if ($action eq 'create') {
              require "$APPLICATIONPATH/custom/supportRequest.pm";
              my ($description, $outageStartDate, $outageStartTime) = ('Description: Support Ticket ...');
              my ($succeeded, $alert, $error) = insertSupportRequest ($CcatalogID, $CuKey, $title, $CremoteUser, $outageStartDate, $outageStartTime, $description, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID, $debug);

              if (defined $outageStartDate and defined $outageStartTime) {
                $CactivationDate = $outageStartDate;
                $CactivationTime = $outageStartTime;
                ($tyear, $tmonth, $tday) = split(/\-/, $CactivationDate);
                $tyear -= 1900; $tmonth--;
                ($thour, $tmin, $tsec) = split(/:/, $CactivationTime);
                $CactivationTimeslot = timelocal($tsec, $tmin, $thour, $tday, $tmonth, $tyear);
              }

              unless ($succeeded) {
                $action = $nextAction = 'createError';
                $htmlTitle = "$Ctitle: id $Cid create error";
                $matchingComments = "<tr><td><H1>Error:</H1>\n'$error'<BR></td></tr>";
              }

              $CcommentData = 'Support Request: '. (($succeeded) ? "SR $succeeded" : "ERROR '$error'");
              $CcommentData .= ", $CactivationDate $CactivationTime";
            }

            my $dummyInstability = ($Cinstability eq 'on') ? 1 : 0;
            my $dummyPersistent  = ($Cpersistent  eq 'on') ? 1 : 0;
            my $dummyDowntime    = ($Cdowntime    eq 'on') ? 1 : 0;
            $sql = 'INSERT INTO ' .$SERVERTABLCOMMENTS. ' SET catalogID="' .$CcatalogID. '", uKey="' .$CuKey. '", replicationStatus="I", title="' .$Ctitle. '", entryDate="' .$CentryDate. '", entryTime="' .$CentryTime.'", entryTimeslot="' .$CentryTime...
            $dbh->do ( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->do: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);

            if ( $dummyDowntime ) {
              my $tDebug = ($debug eq 'T') ? 2 : 0;

              my ($Tpagedirs, $Temail, $Tpagedir, $sendEmailTo);
              $sql = "select pagedir from $SERVERTABLPLUGINS where catalogID = '$CcatalogID' and uKey = '$CuKey' order by uKey";
              $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;

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

              $sql = "select email, pagedir from $SERVERTABLUSERS where catalogID = '$CcatalogID' and activated = 1 and downtimeScheduling = 1 and userType > 0";
              $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;
              $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;
              $sth->bind_columns( \$Temail, \$Tpagedir ) or $rv = error_trap_DBI(*STDOUT, "Cannot sth->bind_columns: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv;

              if ( $rv ) {
                while( $sth->fetch() ) { 
                  chop $Tpagedir;
                  my (undef, @pagedirs) = split (/\//, $Tpagedir);

                  foreach my $pagedirs (@pagedirs) {
                    if ($Tpagedirs =~ /\/$pagedirs\//) {
                      $sendEmailTo .= "$Temail,";
                      last;
                    }
                  }
                }

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

              my $header = "Downtime scheduling for $Ctitle from $CactivationDate $CactivationTime until ";
              $header .= ($CsuspentionDate eq '0000-00-00') ? '????-??-?? ??:??:??' : "$CsuspentionDate $CsuspentionTime.";
              my $subject = "$BUSINESS / $DEPARTMENT / $APPLICATION / $header";
              my $message = "Geachte, Cher,\n\n$header\n\n$CcommentData\n\n-- $givenNameLoggedOn $familyNameLoggedOn\n\n$APPLICATION\n$DEPARTMENT\n$BUSINESS\n";

              if (defined $sendEmailTo) {
                my $returnCode = sending_mail ( $SERVERLISTSMTP, $sendEmailTo, $SENDMAILFROM, $subject, $message, $tDebug );
                print "Problem sending email to the '$APPLICATION' members\n" unless ( $returnCode );
              }
            }
          } elsif ($action eq 'delete') {
            $sql = 'SELECT commentData from ' .$SERVERTABLCOMMENTS. ' where catalogID="' .$CcatalogID. '" and id="' .$Cid. '"';
            $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;
            ($commentData) = $sth->fetchrow_array() or $rv = error_trap_DBI(*STDOUT, "Cannot $sth->fetchrow_array: $sql", $debug, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', $sessionID) if ( $rv and $sth->rows);
 			      $commentData = "$commentData\n<hr>$CcommentData\n\nClosed by: $givenNameLoggedOn, $familyNameLoggedOn ($remoteUserLoggedOn) on $CsolvedDate $CsolvedTime";

            $sql = 'UPDATE ' .$SERVERTABLCOMMENTS. ' SET replicationStatus="U", problemSolved="' .$CproblemSolved. '", solvedDate="' .$CsolvedDate. '", solvedTime="' .$CsolvedTime. '", solvedTimeslot="' .$CsolvedTimeslot. '", commentData="' .$comment...
            $dbh->do ( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->do: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
          } elsif ($action eq 'editView') {
            $sql = 'SELECT commentData from ' .$SERVERTABLCOMMENTS. ' where catalogID="' .$CcatalogID. '" and id="' .$Cid. '"';
            $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;
            ($commentData) = $sth->fetchrow_array() or $rv = error_trap_DBI(*STDOUT, "Cannot $sth->fetchrow_array: $sql", $debug, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', $sessionID) if ( $rv and $sth->rows);
          } elsif ($action eq 'edit') {
 			      my $commentData = "$CcommentData\n\nEdited by: $givenNameLoggedOn, $familyNameLoggedOn ($remoteUserLoggedOn) on $CentryDate $CentryTime";
            $sql = 'UPDATE ' .$SERVERTABLCOMMENTS. ' SET replicationStatus="U", commentData="' .$commentData. '" where catalogID="' .$CcatalogID. '" and id="' .$Cid. '"';
            $dbh->do ( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->do: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
          } elsif ($action eq 'update') {
            $sql = 'SELECT commentData from ' .$SERVERTABLCOMMENTS. ' where catalogID="' .$CcatalogID. '" and id="' .$Cid. '"';
            $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;
            ($commentData) = $sth->fetchrow_array() or $rv = error_trap_DBI(*STDOUT, "Cannot $sth->fetchrow_array: $sql", $debug, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', $sessionID) if ( $rv and $sth->rows);
 			      $commentData = "$commentData\n<hr>$CcommentData\n\nUpdated by: $givenNameLoggedOn, $familyNameLoggedOn ($remoteUserLoggedOn) on $CentryDate $CentryTime";

            $sql = 'UPDATE ' .$SERVERTABLCOMMENTS. ' SET replicationStatus="U", commentData="' .$commentData. '" where catalogID="' .$CcatalogID. '" and id="' .$Cid. '"';
            $dbh->do ( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->do: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
          }

          if ($action eq 'deleteView' or $action eq 'editView' or $action eq 'updateView') {
            my ($id, $uKey, $title, $givenName, $familyName, $instability, $persistent, $downtime, $entryDate, $entryTime, $activationDate, $activationTime, $suspentionDate, $suspentionTime, $commentData);
            $sql = "select id, uKey, title, $SERVERTABLUSERS.givenName, $SERVERTABLUSERS.familyName, instability, persistent, downtime, entryDate, entryTime, activationDate, activationTime, suspentionDate, suspentionTime, commentData from $SERVERTABL...
            $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( \$id, \$uKey, \$title, \$givenName, \$familyName, \$instability, \$persistent, \$downtime, \$entryDate, \$entryTime, \$activationDate, \$activationTime, \$suspentionDate, \$suspentionTime, \$commentData ) or $rv = erro...

            if ( $rv ) {
              $matchingComments = "\n      <table align=\"center\" border=0 cellpadding=1 cellspacing=1 bgcolor='$COLORSTABLE{TABLE}'>\n        <tr><th colspan=\"9\">Catalog ID: $CcatalogID</th><th></th></tr>\n        <tr><th>Id</th><th>Title</th><th...

              if ( $sth->rows ) {
                while( $sth->fetch() ) {
                  $commentData = encode_html_entities('C', $commentData);
                  $commentData =~ s/\n/<br>/g;
                  $matchingComments .= "        <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td rowspan=\"2\" valign=\"top\">$id</td><td>$title</td><td>$givenName, $familyName</td><td>$entryDate \@ $entryTime</td><td>$activationDate \@ $activationTime</...
                }
              } else {
                $matchingComments .= "        <tr><td colspan=9>No records found for catalog ID: $CcatalogID & id: $Cid</td></tr>\n";
              }

              $matchingComments .= "      </table>";
              $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
            }
  	      } elsif ( $action ne 'createError' ) {
            my ($sqlUKey, $sqlUKeyRows, $sqlWhere, $actionColspan, $actionHeader, $ActionItem, $navigationBarSqlWhere);
			
            if ($action eq 'solvedView' or $action eq 'historyView' or $action eq 'history') {
              $actionColspan = 1;
              $actionHeader  = "<th>Solved Date/Time</th>";
              $sqlUKey       = "$SERVERTABLCOMMENTS.catalogID = '$CcatalogID' and uKey = '$CuKey' and";
              $sqlUKeyRows   = "catalog ID: $CcatalogID & uKey: $CuKey";
              $sqlWhere      = '';

              if ($action eq 'history') {
                $sqlWhere .= "and $SERVERTABLCOMMENTS.remoteUser = '$CremoteUser' " if ($CremoteUser ne 'none');
                $sqlWhere .= "and entryTimeslot >= $CentryTimeslot " if ($CentryTimeslot ne '');
                $sqlWhere .= "and solvedTimeslot <= $CsolvedTimeslot " if ($CsolvedTimeslot ne '');
              }

              $navigationBarSqlWhere = "$sqlWhere and problemSolved = '1'";
              $sqlWhere .= "and problemSolved = '1' order by solvedTimeslot desc limit $pageOffset, $RECORDSONPAGE";
            } else {
              if ($action eq 'listAllView') {
                $actionHeader = '';
                $sqlUKey      = "$SERVERTABLCOMMENTS.catalogID = '$CcatalogID' and";
                $sqlUKeyRows  = "all plugins from catalog ID: $CcatalogID";
              } else {
                $actionHeader = "<th>Action</th>" if ( $userType != 0 );
                $sqlUKey      = "$SERVERTABLCOMMENTS.catalogID = '$CcatalogID' and uKey = '$CuKey' and";
                $sqlUKeyRows  = "catalog ID: $CcatalogID & uKey: $CuKey";
              }

              $actionColspan = 0;
              $navigationBarSqlWhere = "and problemSolved = '0'";
              $sqlWhere = "and problemSolved = '0' order by entryTimeslot limit $pageOffset, $RECORDSONPAGE";
	  	      }

            $sql = "select SQL_NO_CACHE count(id) from $SERVERTABLCOMMENTS, $SERVERTABLUSERS where $sqlUKey $SERVERTABLCOMMENTS.catalogID = $SERVERTABLUSERS.catalogID and $SERVERTABLCOMMENTS.remoteUser = $SERVERTABLUSERS.remoteUser $navigationBarSqlW...

            ($rv, $numberRecordsIntoQuery) = do_action_DBI ($rv, $dbh, $sql, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug);
            $navigationBar = record_navigation_bar ($pageNo, $numberRecordsIntoQuery, $RECORDSONPAGE, "$urlWithAccessParameters&amp;catalogID=$CcatalogID&amp;uKey=$CuKey&amp;action=$nextAction");

    		    my ($id, $uKey, $title, $givenName, $familyName, $instability, $persistent, $downtime, $entryDate, $entryTime, $activationDate, $activationTime, $suspentionDate, $suspentionTime, $solvedDate, $solvedTime, $commentData);
            $sql = "select id, uKey, title, $SERVERTABLUSERS.givenName, $SERVERTABLUSERS.familyName, instability, persistent, downtime, entryDate, entryTime, activationDate, activationTime, suspentionDate, suspentionTime, solvedDate, solvedTime, comm...

            $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( \$id, \$uKey, \$title, \$givenName, \$familyName, \$instability, \$persistent, \$downtime, \$entryDate, \$entryTime, \$activationDate, \$activationTime, \$suspentionDate, \$suspentionTime, \$solvedDate, \$solvedTime, \...

            if ( $rv ) {
              $matchingComments = "\n      <table align=\"center\" border=0 cellpadding=1 cellspacing=1 bgcolor='$COLORSTABLE{TABLE}'>\n        <tr><th colspan=\"". (10 + $actionColspan) ."\">Catalog ID: $CcatalogID</th></tr>\n        <tr><th>Id</th>...

              if ( $sth->rows ) {
                while( $sth->fetch() ) {
                  $commentData = encode_html_entities('C', $commentData);
                  $commentData =~ s/\n/<br>/g;

                  if ($action eq 'solvedView' or $action eq 'historyView' or $action eq 'history') {
		  	            $ActionItem = "<td>$solvedDate \@ $solvedTime</td>";
                  } elsif ($action eq 'listAllView') {
	  		            $ActionItem = '';
                  } else {
                    my $urlWithAccessParametersAction = "$urlWithAccessParameters&amp;id=$id&amp;catalogID=$CcatalogID&amp;uKey=$uKey";

                    if ( $userType != 0 ) {
  	  		            $ActionItem  = "<td align=\"center\" rowspan=\"2\" valign=\"middle\">";
	  		              $ActionItem .= "<a href=\"$urlWithAccessParametersAction&amp;action=editView&amp;problemSolved=0\"><img src=\"$IMAGESURL/$ICONSRECORD{edit}\" title=\"Edit Problem\" alt=\"Edit Problem\" border=\"0\"></a>" if ( $userType >= 4 );
    	  		          $ActionItem .= "<a href=\"$urlWithAccessParametersAction&amp;action=updateView&amp;problemSolved=0\"><img src=\"$IMAGESURL/$ICONSRECORD{duplicate}\" title=\"Update Problem\" alt=\"Update Problem\" border=\"0\"></a>" if ( $userType ...
	  		              $ActionItem .= "<a href=\"$urlWithAccessParametersAction&amp;action=deleteView&amp;problemSolved=1\"><img src=\"$IMAGESURL/$ICONSRECORD{delete}\" title=\"Problem Solved\" alt=\"Problem Solved\" border=\"0\"></a>";
	  		              $ActionItem .= "</td>";
                    }
                  }

                  $matchingComments .= "        <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td rowspan=\"2\" valign=\"top\">$id</td><td>$title</td><td>$givenName, $familyName</td><td>$entryDate \@ $entryTime</td><td>$activationDate \@ $activationTime</...
                }
              } else {
                $matchingComments .= "        <tr><td colspan=\"". (10 + $actionColspan) ."\">No records found for $sqlUKeyRows</td></tr>\n";
              }

              $matchingComments .= "        <tr><td colspan=\"". (10 + $actionColspan) ."\">$navigationBar</td></tr>\n" if ($navigationBar);
              $matchingComments .= "      </table>\n";
              $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
            }
          }
        }

        $dbh->disconnect or $rv = error_trap_DBI(*STDOUT, "Sorry, the database was unable to add your entry.", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
      }

      if ( $rv ) {
        # HTML  - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        if ($action eq 'insertView' or $action eq 'createView' or $action eq 'deleteView' or $action eq 'editView' or $action eq 'historyView' or $action eq 'updateView' ) {
          print_header (*STDOUT, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', 'F', "<script type=\"text/javascript\" language=\"JavaScript\" src=\"$HTTPSURL/TimeParserValidator.js\"></script>\n  <script type=\"text/javascript\" language=\"Jav...

          if ($action eq 'insertView' or $action eq 'createView' or $action eq 'historyView') {
            if ($action eq 'insertView' or $action eq 'createView') {
              my ($firstYear, $firstMonth, $firstDay) = Add_Delta_Days ($currentYear, $currentMonth, $currentDay, -1);

              print <<HTML;
<script language="JavaScript" type="text/javascript" id="jsCal1Calendar">
  var cal1Calendar = new CalendarPopup("CalendarDIV");
  cal1Calendar.offsetX = 1;
  cal1Calendar.showNavigationDropdowns();
  cal1Calendar.addDisabledDates(null, "$firstYear-$firstMonth-$firstDay");
</script>
HTML
            } else {
              my ($firstYear, $firstMonth, $firstDay) = Add_Delta_Days ($currentYear, $currentMonth, $currentDay, +1);



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