« blib/lib/ASNMTAP/Asnmtap/Plugins/WebTransact.pm
↑ Summary
blib/lib/ASNMTAP/Asnmtap/Plugins/IO.pm »
| 1 | # ---------------------------------------------------------------------------------------------------------- | ||
| 2 | # © Copyright 2000-2011 by Alex Peeters [alex.peeters@citap.be] | ||
| 3 | # ---------------------------------------------------------------------------------------------------------- | ||
| 4 | # 2011/mm/dd, v3.002.003, package ASNMTAP::Asnmtap::Applications::CGI | ||
| 5 | # ---------------------------------------------------------------------------------------------------------- | ||
| 6 | |||
| 7 | package ASNMTAP::Asnmtap::Applications::CGI; | ||
| 8 | |||
| 9 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 10 | |||
| 11 | use strict; | ||
| 12 | use warnings; # Must be used in test mode only. This reduces a little process speed | ||
| 13 | #use diagnostics; # Must be used in test mode only. This reduces a lot of process speed | ||
| 14 | |||
| 15 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 16 | |||
| 17 | use Carp qw(cluck); | ||
| 18 | use Time::Local; | ||
| 19 | |||
| 20 | # include the class files - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 21 | |||
| 22 | use ASNMTAP::Time qw(&get_datetimeSignal); | ||
| 23 | |||
| 24 | use ASNMTAP::Asnmtap::Applications qw(:APPLICATIONS :COMMANDS :_HIDDEN :CGI); | ||
| 25 | |||
| 26 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 27 | |||
| 28 | BEGIN { | ||
| 29 | use Exporter (); | ||
| 30 | |||
| 31 | @ASNMTAP::Asnmtap::Applications::CGI::ISA = qw(Exporter ASNMTAP::Asnmtap::Applications); | ||
| 32 | |||
| 33 | %ASNMTAP::Asnmtap::Applications::CGI::EXPORT_TAGS = (ALL => [ qw($APPLICATION $BUSINESS $DEPARTMENT $COPYRIGHT $SENDEMAILTO $TYPEMONITORING $RUNCMDONDEMAND | ||
| 34 | $CAPTUREOUTPUT | ||
| 35 | $PREFIXPATH $LOGPATH $PIDPATH $PERL5LIB $MANPATH $LD_LIBRARY_PATH | ||
| 36 | %ERRORS %STATE %TYPE | ||
| 37 | |||
| 38 | &call_system &sending_mail | ||
| 39 | |||
| 40 | $CHATCOMMAND $DIFFCOMMAND $KILLALLCOMMAND $PERLCOMMAND $PPPDCOMMAND $ROUTECOMMAND $RSYNCCOMMAND $SCPCOMMAND $SSHCOMMAND | ||
| 41 | |||
| 42 | &_checkAccObjRef | ||
| 43 | &_checkSubArgs0 &_checkSubArgs1 &_checkSubArgs2 | ||
| 44 | &_checkReadOnly0 &_checkReadOnly1 &_checkReadOnly2 | ||
| 45 | &_dumpValue | ||
| 46 | |||
| 47 | $APPLICATIONPATH $PLUGINPATH | ||
| 48 | |||
| 49 | $ASNMTAPMANUAL | ||
| 50 | $DATABASE $CATALOGID | ||
| 51 | $AWSTATSENABLED | ||
| 52 | $CONFIGDIR $CGISESSDIR $DEBUGDIR $REPORTDIR $RESULTSDIR | ||
| 53 | $CGISESSPATH $HTTPSPATH $IMAGESPATH $PDPHELPPATH $RESULTSPATH $SSHKEYPATH $WWWKEYPATH | ||
| 54 | $HTTPSSERVER $REMOTE_HOST $REMOTE_ADDR $HTTPSURL $IMAGESURL $PDPHELPURL $RESULTSURL | ||
| 55 | $SERVERSMTP $SMTPUNIXSYSTEM $SERVERLISTSMTP $SENDMAILFROM | ||
| 56 | $SSHLOGONNAME $RSYNCIDENTITY $SSHIDENTITY $WWWIDENTITY | ||
| 57 | $RMVERSION $RMDEFAULTUSER | ||
| 58 | $CHARTDIRECTORLIB | ||
| 59 | $HTMLTOPDFPRG $HTMLTOPDFHOW $HTMLTOPDFOPTNS | ||
| 60 | $PERFPARSEBIN $PERFPARSEETC $PERFPARSELIB $PERFPARSESHARE $PERFPARSECGI $PERFPARSEENABLED | ||
| 61 | $PERFPARSEVERSION $PERFPARSECONFIG $PERFPARSEDATABASE $PERFPARSEHOST $PERFPARSEPORT $PERFPARSEUSERNAME $PERFPARSEPASSWORD | ||
| 62 | $RECORDSONPAGE $NUMBEROFFTESTS $VERIFYNUMBEROK $VERIFYMINUTEOK $FIRSTSTARTDATE $STRICTDATE | ||
| 63 | %COLORS %COLORSPIE %COLORSRRD %COLORSTABLE %ICONS %ICONSACK %ICONSUNSTABLE %ICONSRECORD %ICONSSYSTEM %ENVIRONMENT %SOUND %QUARTERS | ||
| 64 | &get_session_param | ||
| 65 | &set_doIt_and_doOffline | ||
| 66 | &encode_html_entities &print_header &print_legend | ||
| 67 | |||
| 68 | $SERVERNAMEREADWRITE $SERVERPORTREADWRITE $SERVERUSERREADWRITE $SERVERPASSREADWRITE | ||
| 69 | $SERVERNAMEREADONLY $SERVERPORTREADONLY $SERVERUSERREADONLY $SERVERPASSREADONLY | ||
| 70 | $SERVERTABLCATALOG $SERVERTABLCLLCTRDMNS $SERVERTABLCOMMENTS $SERVERTABLCOUNTRIES $SERVERTABLCRONTABS $SERVERTABLDISPLAYDMNS $SERVERTABLDISPLAYGRPS $SERVERTABLENVIRONMENT $SERVERTABLEVENTS $SERVERTABLEVENTSCHNGSLGDT $SERVERTABLEVENTSDISPLAYDT $SERVERTABLHOLIDYS $SERVERTABLHOLIDYSBNDL $SERVERTABLLANGUAGE $SERVERTABLPAGEDIRS $SERVERTABLPLUGINS $SERVERTABLREPORTS $SERVERTABLREPORTSPRFDT $SERVERTABLRESULTSDIR $SERVERTABLSERVERS $SERVERTABLTIMEPERIODS $SERVERTABLUSERS $SERVERTABLVIEWS | ||
| 71 | |||
| 72 | &user_session_and_access_control | ||
| 73 | &do_action_DBI &error_trap_DBI &check_record_exist &create_sql_query_events_from_range_year_month &create_sql_query_from_range_SLA_window | ||
| 74 | &get_title &get_sql_startDate_sqlEndDate_numberOfDays_test &get_sql_crontab_scheduling_report_data | ||
| 75 | &create_combobox_from_keys_and_values_pairs &create_combobox_from_DBI &create_combobox_multiple_from_DBI | ||
| 76 | &record_navigation_table &record_navigation_bar &record_navigation_bar_alpha ) ], | ||
| 77 | |||
| 78 | APPLICATIONS => [ qw($APPLICATION $BUSINESS $DEPARTMENT $COPYRIGHT $SENDEMAILTO $TYPEMONITORING $RUNCMDONDEMAND | ||
| 79 | $CAPTUREOUTPUT | ||
| 80 | $PREFIXPATH $PLUGINPATH $LOGPATH $PIDPATH $PERL5LIB $MANPATH $LD_LIBRARY_PATH | ||
| 81 | %ERRORS %STATE %TYPE | ||
| 82 | |||
| 83 | &sending_mail) ], | ||
| 84 | |||
| 85 | COMMANDS => [ qw($CHATCOMMAND $DIFFCOMMAND $KILLALLCOMMAND $PERLCOMMAND $PPPDCOMMAND $ROUTECOMMAND $RSYNCCOMMAND $SCPCOMMAND $SSHCOMMAND) ], | ||
| 86 | |||
| 87 | _HIDDEN => [ qw(&_checkAccObjRef | ||
| 88 | &_checkSubArgs0 &_checkSubArgs1 &_checkSubArgs2 | ||
| 89 | &_checkReadOnly0 &_checkReadOnly1 &_checkReadOnly2 | ||
| 90 | &_dumpValue) ], | ||
| 91 | |||
| 92 | CGI => [ qw($APPLICATIONPATH | ||
| 93 | |||
| 94 | $DATABASE $CATALOGID | ||
| 95 | $AWSTATSENABLED | ||
| 96 | $CONFIGDIR $CGISESSDIR $DEBUGDIR $REPORTDIR $RESULTSDIR | ||
| 97 | $CGISESSPATH $HTTPSPATH $IMAGESPATH $PDPHELPPATH $RESULTSPATH $LOGPATH $PIDPATH $PERL5LIB $MANPATH $LD_LIBRARY_PATH $SSHKEYPATH $WWWKEYPATH | ||
| 98 | $HTTPSSERVER $REMOTE_HOST $REMOTE_ADDR $HTTPSURL $IMAGESURL $PDPHELPURL $RESULTSURL | ||
| 99 | $SERVERSMTP $SMTPUNIXSYSTEM $SERVERLISTSMTP $SENDMAILFROM | ||
| 100 | $CHARTDIRECTORLIB | ||
| 101 | $HTMLTOPDFPRG $HTMLTOPDFHOW $HTMLTOPDFOPTNS | ||
| 102 | $PERFPARSEBIN $PERFPARSEETC $PERFPARSELIB $PERFPARSESHARE $PERFPARSECGI $PERFPARSEENABLED | ||
| 103 | $RECORDSONPAGE $NUMBEROFFTESTS $VERIFYNUMBEROK $VERIFYMINUTEOK $FIRSTSTARTDATE $STRICTDATE | ||
| 104 | %ENVIRONMENT | ||
| 105 | &encode_html_entities &print_header &print_legend | ||
| 106 | |||
| 107 | &user_session_and_access_control | ||
| 108 | &do_action_DBI &error_trap_DBI &check_record_exist | ||
| 109 | &get_title | ||
| 110 | &create_combobox_from_keys_and_values_pairs &create_combobox_from_DBI &create_combobox_multiple_from_DBI | ||
| 111 | &record_navigation_table &record_navigation_bar &record_navigation_bar_alpha ) ], | ||
| 112 | |||
| 113 | |||
| 114 | MEMBER => [ qw(%COLORS %COLORSTABLE %ICONS %ICONSRECORD ) ], | ||
| 115 | |||
| 116 | MODERATOR => [ qw(%COLORS %COLORSTABLE %ICONS %ICONSRECORD %ICONSSYSTEM | ||
| 117 | $SSHLOGONNAME | ||
| 118 | &get_session_param | ||
| 119 | &set_doIt_and_doOffline | ||
| 120 | |||
| 121 | &get_sql_crontab_scheduling_report_data ) ], | ||
| 122 | |||
| 123 | ADMIN => [ qw(%COLORSTABLE %ICONSRECORD ) ], | ||
| 124 | |||
| 125 | SADMIN => [ qw(%COLORSTABLE %ICONSRECORD | ||
| 126 | $SSHLOGONNAME $RSYNCIDENTITY $SSHIDENTITY $WWWIDENTITY | ||
| 127 | $RMVERSION $RMDEFAULTUSER ) ], | ||
| 128 | |||
| 129 | DBPERFPARSE => [ qw($PERFPARSEVERSION $PERFPARSECONFIG $PERFPARSEDATABASE $PERFPARSEHOST $PERFPARSEPORT $PERFPARSEUSERNAME $PERFPARSEPASSWORD ) ], | ||
| 130 | DBREADONLY => [ qw($SERVERNAMEREADONLY $SERVERPORTREADONLY $SERVERUSERREADONLY $SERVERPASSREADONLY ) ], | ||
| 131 | DBREADWRITE => [ qw($SERVERNAMEREADWRITE $SERVERPORTREADWRITE $SERVERUSERREADWRITE $SERVERPASSREADWRITE ) ], | ||
| 132 | DBTABLES => [ qw($SERVERTABLCATALOG $SERVERTABLCLLCTRDMNS $SERVERTABLCOMMENTS $SERVERTABLCOUNTRIES $SERVERTABLCRONTABS $SERVERTABLDISPLAYDMNS $SERVERTABLDISPLAYGRPS $SERVERTABLENVIRONMENT $SERVERTABLEVENTS $SERVERTABLEVENTSCHNGSLGDT $SERVERTABLEVENTSDISPLAYDT $SERVERTABLHOLIDYS $SERVERTABLHOLIDYSBNDL $SERVERTABLLANGUAGE $SERVERTABLPAGEDIRS $SERVERTABLPLUGINS $SERVERTABLREPORTS $SERVERTABLREPORTSPRFDT $SERVERTABLRESULTSDIR $SERVERTABLSERVERS $SERVERTABLTIMEPERIODS $SERVERTABLUSERS $SERVERTABLVIEWS ) ], | ||
| 133 | |||
| 134 | REPORTS => [ qw(%COLORS %COLORSPIE %COLORSRRD %COLORSTABLE %ICONS %QUARTERS | ||
| 135 | |||
| 136 | &create_sql_query_events_from_range_year_month | ||
| 137 | &create_sql_query_from_range_SLA_window | ||
| 138 | &get_sql_startDate_sqlEndDate_numberOfDays_test) ] ); | ||
| 139 | |||
| 140 | @ASNMTAP::Asnmtap::Applications::CGI::EXPORT_OK = ( @{ $ASNMTAP::Asnmtap::Applications::CGI::EXPORT_TAGS{ALL} } ); | ||
| 141 | |||
| 142 | $ASNMTAP::Asnmtap::Applications::CGI::VERSION = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; | ||
| 143 | } | ||
| 144 | |||
| 145 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 146 | # Public subs = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 147 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 148 | |||
| 149 | sub user_session_and_access_control; | ||
| 150 | |||
| 151 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 152 | |||
| 153 | sub do_action_DBI; | ||
| 154 | sub error_trap_DBI; | ||
| 155 | sub check_record_exist; | ||
| 156 | sub create_sql_query_events_from_range_year_month; | ||
| 157 | sub create_sql_query_from_range_SLA_window; | ||
| 158 | |||
| 159 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 160 | |||
| 161 | sub get_title; | ||
| 162 | sub get_sql_crontab_scheduling_report_data; | ||
| 163 | sub get_sql_startDate_sqlEndDate_numberOfDays_test; | ||
| 164 | |||
| 165 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 166 | |||
| 167 | sub create_combobox_from_keys_and_values_pairs; | ||
| 168 | sub create_combobox_from_DBI; | ||
| 169 | sub create_combobox_multiple_from_DBI; | ||
| 170 | |||
| 171 | sub record_navigation_table; | ||
| 172 | sub record_navigation_bar; | ||
| 173 | sub record_navigation_bar_alpha; | ||
| 174 | |||
| 175 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 176 | # Public subs without TAGS = = = = = = = = = = = = = = = = = = = = = = = | ||
| 177 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 178 | |||
| 179 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 180 | # Common variables = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 181 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 182 | |||
| 183 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 184 | |||
| 185 | sub user_session_and_access_control { | ||
| 186 | my ($sessionControl, $level, $cgi, $pagedir, $pageset, $debug, $htmlTitle, $subTitle, $queryString) = @_; | ||
| 187 | |||
| 188 | my ($errorUserAccessControl, $sessionID, $userType, $cfhOld, $cfhNew, $password); | ||
| 189 | $sessionID = ''; | ||
| 190 | |||
| 191 | if (! $sessionControl or ( $ENV{REMOTE_ADDR} eq $REMOTE_ADDR and $ENV{HTTP_HOST} =~ /^${REMOTE_HOST}(:\d+)?/ )) { | ||
| 192 | ($cfhOld) = $|; $cfhNew = select (STDOUT); $| = 1; | ||
| 193 | print $cgi->header; | ||
| 194 | $| = $cfhOld; select ($cfhNew); | ||
| 195 | return ("", 0, 0, 0, 0, 1, 1, $errorUserAccessControl, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $subTitle); | ||
| 196 | # --> ($sessionID, $iconAdd, $iconDelete, $iconDetails, $iconEdit, $iconQuery, $iconTable, | ||
| 197 | # $errorUserAccessControl, $CremoteUser, $CremoteAddr, $CremoteNetmask, $CgivenName, $CfamilyName, | ||
| 198 | # $Cemail, $Cpassword, $CuserType, $Cpagedir, $Cactivated, $CkeyLanguage, $subTitle) | ||
| 199 | } | ||
| 200 | |||
| 201 | sub setAccessControlParameters { | ||
| 202 | my ($level, $pagedir, $pageset, $debug, $cgi, $session, $sessionID, $subTitle, $queryString) = @_; | ||
| 203 | |||
| 204 | my $logonRequestLogoff = ($cgi->param('logonRequest') or "logon"); | ||
| 205 | |||
| 206 | if ( $logonRequestLogoff ne 'logoff' ) { | ||
| 207 | if ( $session->param('~logged-in') ) { | ||
| 208 | $subTitle .= " <a href=\"" .$ENV{SCRIPT_NAME}. "?pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&logonRequest=logoff\"><IMG SRC=\"$IMAGESURL/logoff.jpg\" title=\"Logoff " .$session->param('remoteUser'). "\" alt=\"Logoff " .$session->param('remoteUser'). "\" BORDER=0></a>"; | ||
| 209 | } else { | ||
| 210 | $session->param('remoteUser', $ENV{REMOTE_USER}) if ($ENV{REMOTE_USER}); | ||
| 211 | } | ||
| 212 | } else { | ||
| 213 | if ( $debug eq 'T' and defined $queryString ) { | ||
| 214 | # standard code to parse HTTP query parameters | ||
| 215 | my %query = map { my($k, $v) = split(/=/) } split(/&/, $queryString); | ||
| 216 | while (my ($key, $value) = each(%query)) { print "$key=$value<br>\n"; } | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | return ($subTitle); | ||
| 221 | } | ||
| 222 | |||
| 223 | if ( $level eq 'guest' or $level eq 'member' ) { | ||
| 224 | $sessionID = $cgi->cookie('asnmtap-root-cgisess') || $cgi->param("CGISESSID") || undef; | ||
| 225 | } else { | ||
| 226 | $sessionID = $cgi->param("CGISESSID") || undef; | ||
| 227 | } | ||
| 228 | |||
| 229 | use CGI::Session; | ||
| 230 | my $session = CGI::Session->new ('driver:File;serializer:Default;id:MD5', $sessionID, {Directory=>"$CGISESSPATH"}); | ||
| 231 | $sessionID = $session->id(); | ||
| 232 | |||
| 233 | if ( $level eq 'guest' or $level eq 'member' ) { | ||
| 234 | my $cookieID = ( defined $sessionID ) ? $sessionID : '1'; | ||
| 235 | my $domain = ( ( $ENV{REMOTE_ADDR} eq $REMOTE_ADDR and $ENV{HTTP_HOST} =~ /^${REMOTE_HOST}(:\d+)?/ ) ? $REMOTE_HOST : $HTTPSSERVER ); | ||
| 236 | my $cgiCookieOutRootCgisess = $cgi->cookie(-name=>'asnmtap-root-cgisess', -value=>"$cookieID", -expires=>'+10h', -path=>"$HTTPSURL/cgi-bin", -domain=>"$domain", -secure=>'0'); | ||
| 237 | ($cfhOld) = $|; $cfhNew = select (STDOUT); $| = 1; | ||
| 238 | print $cgi->header(-cookie=>$cgiCookieOutRootCgisess); | ||
| 239 | $| = $cfhOld; select ($cfhNew); | ||
| 240 | } else { | ||
| 241 | ($cfhOld) = $|; $cfhNew = select (STDOUT); $| = 1; | ||
| 242 | print $cgi->header; | ||
| 243 | $| = $cfhOld; select ($cfhNew); | ||
| 244 | } | ||
| 245 | |||
| 246 | my $logonRequestLogoff = ($cgi->param('logonRequest') or "logon"); | ||
| 247 | |||
| 248 | if ( $session->param('~logged-in') and $logonRequestLogoff ne 'logoff' ) { | ||
| 249 | my $TuserType = (defined $session->param('userType')) ? $session->param('userType') : 0; | ||
| 250 | my $Tpagedir = (defined $session->param('pagedir')) ? $session->param('pagedir') : '<NIHIL>'; | ||
| 251 | my $accessGranted = 0; | ||
| 252 | |||
| 253 | my ($Rpagedir, undef) = split (/\//, $pagedir, 2); | ||
| 254 | |||
| 255 | if ($level eq 'sadmin') { # Server Administrator | ||
| 256 | $accessGranted = 1 if ($TuserType == 8); | ||
| 257 | } elsif ($level eq 'admin') { # Administrator | ||
| 258 | $accessGranted = 1 if ($TuserType >= 4); | ||
| 259 | } elsif ($level eq 'moderator') { # Moderator | ||
| 260 | $accessGranted = 1 if ($TuserType >= 2); | ||
| 261 | } elsif ($level eq 'member') { # Member | ||
| 262 | $accessGranted = 1 if ($TuserType >= 1 and $pagedir ne '<NIHIL>' and ($Tpagedir =~ /\/$Rpagedir\//)); | ||
| 263 | } else { # Guest | ||
| 264 | $accessGranted = 1 if ($pagedir ne '<NIHIL>' and ($Tpagedir =~ /\/$Rpagedir\//)); | ||
| 265 | } | ||
| 266 | |||
| 267 | $subTitle = setAccessControlParameters( $level, $pagedir, $pageset, $debug, $cgi, $session, $sessionID, $subTitle, $queryString ); | ||
| 268 | return ($sessionID, $session->param('iconAdd'), $session->param('iconDelete'), $session->param('iconDetails'), $session->param('iconEdit'), $session->param('iconQuery'), $session->param('iconTable'), $errorUserAccessControl, $session->param('remoteUser'), $session->param('remoteAddr'), $session->param('remoteNetmask'), $session->param('givenName'), $session->param('familyName'), $session->param('email'), $session->param('password'), $session->param('userType'), $session->param('pagedir'), $session->param('activated'), $session->param('keyLanguage'), $subTitle) if ($accessGranted); | ||
| 269 | |||
| 270 | print_header (*STDOUT, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', 'F', '', $sessionID); | ||
| 271 | $errorUserAccessControl = "You don\'t have enough permissions!"; | ||
| 272 | print "<br>\n<table WIDTH=\"100%\" border=0><tr><td class=\"HelpPluginFilename\">\n<font size=\"+1\">$errorUserAccessControl</font>\n</td></tr></table>\n<br>\n"; | ||
| 273 | return ("", 0, 0, 0, 0, 1, 1, $errorUserAccessControl, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $subTitle); | ||
| 274 | } | ||
| 275 | |||
| 276 | $session->param('~logged-in', 0); | ||
| 277 | $session->param('ASNMTAP', 'LEXY'); | ||
| 278 | $session->param('iconAdd', 0); | ||
| 279 | $session->param('iconDelete', 0); | ||
| 280 | $session->param('iconDetails', 0); | ||
| 281 | $session->param('iconEdit', 0); | ||
| 282 | $session->param('iconQuery', 1); | ||
| 283 | $session->param('iconTable', 1); | ||
| 284 | |||
| 285 | if ($level eq 'sadmin') { # Server Administrator | ||
| 286 | $session->expire('+15m'); # expire after 15 minutes | ||
| 287 | $userType = 8; | ||
| 288 | } elsif ($level eq 'admin') { # Administrator | ||
| 289 | $session->expire('+30m'); # expire after 30 minutes | ||
| 290 | $userType = 4; | ||
| 291 | } elsif ($level eq 'moderator') { # Moderator | ||
| 292 | $session->expire('+1h'); # expire after 1 hour | ||
| 293 | $userType = 2; | ||
| 294 | } elsif ($level eq 'member') { # Member | ||
| 295 | $session->expire('+10h'); # expire after 10 hours | ||
| 296 | $userType = 1; | ||
| 297 | } else { # Guest | ||
| 298 | $session->expire('+10h'); # expire after 10 hours | ||
| 299 | $userType = 0; | ||
| 300 | } | ||
| 301 | |||
| 302 | my $logonRequest = ($cgi->param('logonRequest') or "logonView"); | ||
| 303 | |||
| 304 | if( $logonRequest eq "logonView" or $logonRequest eq "logonCheck" ) { | ||
| 305 | my $logonPassword = ($cgi->param('logonPassword') or undef); | ||
| 306 | my $logonTimestamp = ($cgi->param('logonTimestamp') or undef); | ||
| 307 | my $loginTrials = ($session->param('~login-trials') or 0); | ||
| 308 | |||
| 309 | if ( $loginTrials >= 3 ) { | ||
| 310 | $errorUserAccessControl = "You failed 3 times in a row.<br>Your session is blocked.<br>Please contact us with the details of your action"; | ||
| 311 | } elsif( $logonRequest eq "logonCheck" ) { | ||
| 312 | my ($CremoteUser, $CremoteAddr, $CremoteNetmask, $CgivenName, $CfamilyName, $Cemail, $Cpassword, $CuserType, $Cpagedir, $Cactivated, $CkeyLanguage); | ||
| 313 | $CremoteUser = ($cgi->param('remoteUser') or undef); | ||
| 314 | $session->param('remoteUser', $CremoteUser) if (defined $CremoteUser); | ||
| 315 | $CuserType = 0; | ||
| 316 | |||
| 317 | if (defined $CremoteUser and defined $logonPassword and defined $logonTimestamp) { | ||
| 318 | my $rv = 1; | ||
| 319 | |||
| 320 | if (defined $CremoteUser) { | ||
| 321 | my ($dbh, $sth, $sql); | ||
| 322 | $dbh = DBI->connect("dbi:mysql:$DATABASE:$SERVERNAMEREADWRITE:$SERVERPORTREADWRITE", "$SERVERUSERREADWRITE", "$SERVERPASSREADWRITE" ) or $rv = error_trap_DBI(*STDOUT, "Cannot connect to the database", $debug, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', $sessionID); | ||
| 323 | |||
| 324 | if ($dbh and $rv) { | ||
| 325 | $sql = "select remoteAddr, remoteNetmask, givenName, familyName, email, password, userType, pagedir, activated, keyLanguage from $SERVERTABLUSERS where catalogID = '$CATALOGID' and remoteUser = '$CremoteUser'"; | ||
| 326 | $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', $sessionID); | ||
| 327 | $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', $sessionID) if $rv; | ||
| 328 | |||
| 329 | if ( $rv ) { | ||
| 330 | if ($sth->rows) { | ||
| 331 | ($CremoteAddr, $CremoteNetmask, $CgivenName, $CfamilyName, $Cemail, $Cpassword, $CuserType, $Cpagedir, $Cactivated, $CkeyLanguage) = $sth->fetchrow_array() or $rv = error_trap_DBI(*STDOUT, "Cannot $sth->fetchrow_array: $sql", $debug, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', $sessionID); | ||
| 332 | |||
| 333 | if ( $rv ) { | ||
| 334 | $errorUserAccessControl = "Remote User '$CremoteUser' not yet activated." if ($Cactivated != 1); | ||
| 335 | } else { | ||
| 336 | $errorUserAccessControl = "Problems with retreiving data from the MySQL database."; | ||
| 337 | } | ||
| 338 | } else { | ||
| 339 | $errorUserAccessControl = "Remote User '$CremoteUser' invalid."; | ||
| 340 | } | ||
| 341 | |||
| 342 | $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', $sessionID) if $rv; | ||
| 343 | } else { | ||
| 344 | $errorUserAccessControl = "Problems with a MySQL database statement."; | ||
| 345 | } | ||
| 346 | } else { | ||
| 347 | $errorUserAccessControl = "Problems with the MySQL database."; | ||
| 348 | } | ||
| 349 | } else { | ||
| 350 | $errorUserAccessControl = "Remote User missing."; | ||
| 351 | } | ||
| 352 | |||
| 353 | my $currentTime = time(); | ||
| 354 | |||
| 355 | if (defined $errorUserAccessControl) { | ||
| 356 | $errorUserAccessControl .= "<br>Please contact us with the details of your action."; | ||
| 357 | |||
| 358 | unless ( $rv ) { | ||
| 359 | print "<br>\n<table WIDTH=\"100%\" border=0><tr><td class=\"HelpPluginFilename\">\n<font size=\"+1\">$errorUserAccessControl</font>\n</td></tr></table>\n<br>\n"; | ||
| 360 | return ("", 0, 0, 0, 0, 1, 1, $errorUserAccessControl, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $subTitle); | ||
| 361 | } | ||
| 362 | } elsif ( $Cpassword ne $logonPassword ) { | ||
| 363 | $errorUserAccessControl = "Bad password"; | ||
| 364 | } elsif( $logonTimestamp > $currentTime or $logonTimestamp < ($currentTime - 300) ) { | ||
| 365 | $errorUserAccessControl = "Time stamp invalid"; | ||
| 366 | } else { | ||
| 367 | if ( $ENV{REMOTE_ADDR} ) { | ||
| 368 | if ( $CremoteAddr ne '' ) { | ||
| 369 | use NetAddr::IP; | ||
| 370 | my $netmask = (int($CremoteNetmask) or 32); | ||
| 371 | my $ipAddr = NetAddr::IP->new($ENV{REMOTE_ADDR}); | ||
| 372 | my $ipRange = NetAddr::IP->new("$CremoteAddr/$netmask"); | ||
| 373 | $errorUserAccessControl = "IP Address Forbidden." unless ( $ipRange->contains ( $ipAddr ) ); | ||
| 374 | } | ||
| 375 | } | ||
| 376 | |||
| 377 | $errorUserAccessControl = "You don't have enough permissions!" if ( $userType > int($CuserType) ); | ||
| 378 | |||
| 379 | unless ( defined $errorUserAccessControl ) { | ||
| 380 | my $accessGranted = 0; | ||
| 381 | |||
| 382 | my ($Rpagedir, undef) = split (/\//, $pagedir, 2); | ||
| 383 | |||
| 384 | if ($level eq 'sadmin') { # Server Administrator | ||
| 385 | $accessGranted = 1 if ($CuserType == 8); | ||
| 386 | } elsif ($level eq 'admin') { # Administrator | ||
| 387 | $accessGranted = 1 if ($CuserType >= 4); | ||
| 388 | } elsif ($level eq 'moderator') { # Moderator | ||
| 389 | $accessGranted = 1 if ($CuserType >= 2); | ||
| 390 | } elsif ($level eq 'member') { # Member | ||
| 391 | $accessGranted = 1 if ($CuserType >= 1 and $pagedir ne '<NIHIL>' and ($Cpagedir =~ /\/$Rpagedir\//)); | ||
| 392 | } else { # Guest | ||
| 393 | $accessGranted = 1 if ($pagedir ne '<NIHIL>' and ($Cpagedir =~ /\/$Rpagedir\//)); | ||
| 394 | } | ||
| 395 | |||
| 396 | $errorUserAccessControl = "You are onto the wrong place to be!" unless ( $accessGranted ); | ||
| 397 | |||
| 398 | unless ( defined $errorUserAccessControl ) { | ||
| 399 | $session->param('~logged-in', 1); | ||
| 400 | $session->clear(['~login-trials']); | ||
| 401 | |||
| 402 | if ( $CuserType eq "8" ) { # Server Administrator | ||
| 403 | $session->param('iconAdd', 1); | ||
| 404 | $session->param('iconDelete', 1); | ||
| 405 | $session->param('iconEdit', 1); | ||
| 406 | $session->param('iconDetails', 1); | ||
| 407 | } elsif ( $CuserType eq "4" ) { # Administrator | ||
| 408 | $session->param('iconAdd', 1); | ||
| 409 | $session->param('iconEdit', 1); | ||
| 410 | $session->param('iconDetails', 1); | ||
| 411 | } elsif ( $CuserType eq "2" ) { # Moderator | ||
| 412 | $session->param('iconEdit', 1); | ||
| 413 | $session->param('iconDetails', 1); | ||
| 414 | } elsif ( $CuserType eq "1" ) { # Member | ||
| 415 | $session->param('iconDetails', 1); | ||
| 416 | } elsif ( $CuserType ne "0" ) { # Guest | ||
| 417 | $errorUserAccessControl = "You are onto the wrong place to be!"; | ||
| 418 | } | ||
| 419 | |||
| 420 | $session->param('iconQuery', 1); | ||
| 421 | $session->param('iconTable', 1); | ||
| 422 | |||
| 423 | $session->param('remoteUser', $CremoteUser); | ||
| 424 | $session->param('remoteAddr', $CremoteAddr); | ||
| 425 | $session->param('remoteNetmask', $CremoteNetmask); | ||
| 426 | $session->param('givenName', $CgivenName); | ||
| 427 | $session->param('familyName', $CfamilyName); | ||
| 428 | $session->param('email', $Cemail); | ||
| 429 | $session->param('keyLanguage', $CkeyLanguage); | ||
| 430 | $session->param('password', $Cpassword); | ||
| 431 | $session->param('userType', $CuserType); | ||
| 432 | $session->param('pagedir', $Cpagedir); | ||
| 433 | $session->param('activated', $Cactivated); | ||
| 434 | } | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | $password = $Cpassword; | ||
| 439 | } else { | ||
| 440 | $errorUserAccessControl = "Remote User, Password and/or Time stamp are missing"; | ||
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | if (defined $errorUserAccessControl) { | ||
| 445 | $logonRequest = "logonView"; | ||
| 446 | my $trials = $session->param('~login-trials') || 0; | ||
| 447 | $session->param('~login-trials', ++$trials); | ||
| 448 | |||
| 449 | if ( $debug eq 'T' and defined $queryString ) { | ||
| 450 | my %query = map { my($k, $v) = split(/=/) } split(/&/, $queryString); | ||
| 451 | while (my ($key, $value) = each(%query)) { print "$key=$value<br>\n"; } | ||
| 452 | print "<$password> " if (defined $password); | ||
| 453 | print "<$logonPassword><br>\n"; | ||
| 454 | } | ||
| 455 | } | ||
| 456 | |||
| 457 | if( $logonRequest eq "logonView" ) { | ||
| 458 | $logonTimestamp = time(); | ||
| 459 | print_header (*STDOUT, $pagedir, $pageset, $htmlTitle, 'Logon', 3600, '', 'F', "<script language=\"JavaScript1.2\" type=\"text/javascript\" src=\"$HTTPSURL/md5.js\"></script>", $sessionID); | ||
| 460 | print "<br>\n<table WIDTH=\"100%\" border=0><tr><td class=\"HelpPluginFilename\">\n<font size=\"+1\">$errorUserAccessControl</font>\n</td></tr></table>\n<br>\n" if ( defined $errorUserAccessControl ); | ||
| 461 | |||
| 462 | print <<HTML; | ||
| 463 | <script language="JavaScript1.2" type="text/javascript"> | ||
| 464 | function validateForm() { | ||
| 465 | // The password must contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter. | ||
| 466 | var objectRegularExpressionPasswordFormat = /\^[\\w|\\W]*(?=[\\w|\\W]*\\d)(?=[\\w|\\W]*[a-z])(?=[\\w|\\W]\*[A-Z])[\\w|\\W]*\$/; | ||
| 467 | |||
| 468 | if ( document.usac.remoteUser.value == null || document.usac.remoteUser.value == '' ) { | ||
| 469 | document.usac.remoteUser.focus(); | ||
| 470 | alert('Please enter a remote user!'); | ||
| 471 | return false; | ||
| 472 | } | ||
| 473 | |||
| 474 | if ( document.usac.logonPassword.value == null || document.usac.logonPassword.value == '' ) { | ||
| 475 | document.usac.logonPassword.focus(); | ||
| 476 | alert('Please enter a password!'); | ||
| 477 | return false; | ||
| 478 | } else { | ||
| 479 | if ( ! objectRegularExpressionPasswordFormat.test(document.usac.logonPassword.value) ) { | ||
| 480 | document.usac.logonPassword.focus(); | ||
| 481 | alert('Please re-enter password: Bad password format!'); | ||
| 482 | return false; | ||
| 483 | } | ||
| 484 | |||
| 485 | document.usac.logonPassword.value = hex_md5(document.usac.logonPassword.value); | ||
| 486 | } | ||
| 487 | |||
| 488 | return true; | ||
| 489 | } | ||
| 490 | </script> | ||
| 491 | <br> | ||
| 492 | <form action="$ENV{SCRIPT_NAME}" method="post" name="usac" onSubmit="return validateForm();"> | ||
| 493 | <input type="hidden" name="pagedir" value="$pagedir"> | ||
| 494 | <input type="hidden" name="pageset" value="$pageset"> | ||
| 495 | <input type="hidden" name="debug" value="$debug"> | ||
| 496 | <input type="hidden" name="CGISESSID" value="$sessionID"> | ||
| 497 | <input type="hidden" name="logonRequest" value="logonCheck"> | ||
| 498 | <input type="hidden" name="logonTimestamp" value="$logonTimestamp"> | ||
| 499 | HTML | ||
| 500 | |||
| 501 | if ( defined $queryString ) { | ||
| 502 | my %query = map { my($k, $v) = split(/=/) } split(/&/, $queryString); | ||
| 503 | while (my ($key, $value) = each(%query)) { print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n"; } | ||
| 504 | } | ||
| 505 | |||
| 506 | print <<HTML; | ||
| 507 | <table border="0" cellspacing="0" cellpadding="0"> | ||
| 508 | <tr><td><b>Remote User: </b></td><td> | ||
| 509 | <input type="text" name="remoteUser" value="" size="15" maxlength="15"> | ||
| 510 | </td></tr><tr><td><b>Password: </b></td><td> | ||
| 511 | <input type="password" name="logonPassword" value="" size="15" maxlength="32"> The password must contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter. | ||
| 512 | </td></tr><tr align="left"><td align="right"><br><input type="submit" value="Logon"></td><td><br><input type="reset" value="Reset"></td></tr> | ||
| 513 | </table> | ||
| 514 | </form> | ||
| 515 | <br> | ||
| 516 | HTML | ||
| 517 | |||
| 518 | $errorUserAccessControl = $logonRequest; | ||
| 519 | } | ||
| 520 | } elsif( $logonRequest eq "logoff" ) { | ||
| 521 | print_header (*STDOUT, $pagedir, $pageset, $htmlTitle, "Logoff", 3600, '', 'F', '', $sessionID); | ||
| 522 | $errorUserAccessControl = "Logged off remote user: " .$session->param('givenName'). " " .$session->param('familyName'); | ||
| 523 | print "<br>\n<h1 align=\"center\">$errorUserAccessControl</h1>\n"; | ||
| 524 | $session->delete(); | ||
| 525 | return ("", 0, 0, 0, 0, 1, 1, $errorUserAccessControl, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $subTitle); | ||
| 526 | } | ||
| 527 | |||
| 528 | $subTitle = setAccessControlParameters( $level, $pagedir, $pageset, $debug, $cgi, $session, $sessionID, $subTitle, $queryString ); | ||
| 529 | return ($sessionID, $session->param('iconAdd'), $session->param('iconDelete'), $session->param('iconDetails'), $session->param('iconEdit'), $session->param('iconQuery'), $session->param('iconTable'), $errorUserAccessControl, $session->param('remoteUser'), $session->param('remoteAddr'), $session->param('remoteNetmask'), $session->param('givenName'), $session->param('familyName'), $session->param('email'), $session->param('password'), $session->param('userType'), $session->param('pagedir'), $session->param('activated'), $session->param('keyLanguage'), $subTitle); | ||
| 530 | } | ||
| 531 | |||
| 532 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 533 | |||
| 534 | sub do_action_DBI { | ||
| 535 | my ($rv, $dbh, $sql, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_; | ||
| 536 | |||
| 537 | my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 538 | $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv; | ||
| 539 | my $numberRecordsIntoQuery = ($rv) ? $sth->fetchrow_array() : 0; | ||
| 540 | $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv; | ||
| 541 | |||
| 542 | return ($rv, $numberRecordsIntoQuery); | ||
| 543 | } | ||
| 544 | |||
| 545 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 546 | |||
| 547 | sub error_trap_DBI { | ||
| 548 | my ($HTML, $error_message, $debug, $pagedir, $pageset, $htmlTitle, $subTitle, $refresh, $onload, $sessionID) = @_; | ||
| 549 | |||
| 550 | my $subject = "$htmlTitle / error_trap_DBI: " . get_datetimeSignal(); | ||
| 551 | 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"; | ||
| 552 | my $returnCode = sending_mail ( $SERVERLISTSMTP, $SENDEMAILTO, $SENDMAILFROM, $subject, $message, $debug ); | ||
| 553 | print "Problem sending email to the '$APPLICATION' server administrators\n" unless ( $returnCode ); | ||
| 554 | |||
| 555 | if ( $refresh == 0 ) { | ||
| 556 | return (0, $error_message, "DBI Error: $DBI::err", "DBI String: $DBI::errstr"); | ||
| 557 | } elsif ( $refresh == -1 ) { | ||
| 558 | print "<H1>DBI Error:</H1>\n", $error_message, "\n<br><br>ERROR: $DBI::err ($DBI::errstr)\n<BR>"; | ||
| 559 | return 0; | ||
| 560 | } else { | ||
| 561 | print_header ($HTML, $pagedir, $pageset, $htmlTitle, $subTitle, $refresh, $onload, 'F', '', $sessionID); | ||
| 562 | print "<H1>DBI Error:</H1>\n", $error_message, "\n<br><br>ERROR: $DBI::err ($DBI::errstr)\n<BR>"; | ||
| 563 | return 0; | ||
| 564 | } | ||
| 565 | } | ||
| 566 | |||
| 567 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 568 | |||
| 569 | sub check_record_exist { | ||
| 570 | my ($rv, $dbh, $sql, $titleTXT, $keyTXT, $nameTXT, $matchingRecords, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_; | ||
| 571 | |||
| 572 | my ($key, $title); | ||
| 573 | my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 574 | $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv; | ||
| 575 | $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; | ||
| 576 | |||
| 577 | if ( $rv ) { | ||
| 578 | if ( $sth->rows ) { | ||
| 579 | $matchingRecords .= "<h1>$titleTXT:</h1><table><tr><th>$keyTXT</th><th>$nameTXT</th></tr>"; | ||
| 580 | while( $sth->fetch() ) { $matchingRecords .= "<tr><td>" .encode_html_entities('K', $key). "</td><td>" .encode_html_entities('T', $title). "</td></tr>"; } | ||
| 581 | $matchingRecords .= "</table>\n"; | ||
| 582 | } | ||
| 583 | |||
| 584 | $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 585 | } | ||
| 586 | |||
| 587 | return ($rv, $matchingRecords); | ||
| 588 | } | ||
| 589 | |||
| 590 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 591 | |||
| 592 | sub create_sql_query_events_from_range_year_month { | ||
| 593 | my ($inputType, $startDate, $endDate, $sqlSelect, $sqlForce, $sqlWhere, $sqlPeriode, $sqlQuery, $sqlGroup, $sqlOrder, $sqlOrderUnion, $sqlUnionKeyword) = @_; | ||
| 594 | |||
| 595 | $sqlUnionKeyword = 'ALL' if ($sqlUnionKeyword ne 'ALL' or $sqlUnionKeyword ne 'DISTINCT'); | ||
| 596 | |||
| 597 | my ($yearFrom, $monthFrom, $dayFrom) = split (/-/, $startDate); | ||
| 598 | my ($yearTo, $monthTo, $dayTo) = split (/-/, $endDate); | ||
| 599 | |||
| 600 | use Date::Calc qw(Add_Delta_Days Delta_Days); | ||
| 601 | my $deltaDays = Delta_Days ($yearFrom, $monthFrom, $dayFrom, $yearTo, $monthTo, $dayTo); | ||
| 602 | |||
| 603 | my ($sql, $sqlUnion); | ||
| 604 | |||
| 605 | if ( $deltaDays >=0 ) { | ||
| 606 | my $sqlCommon = "$sqlSelect FROM `$SERVERTABLEVENTS` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder"; | ||
| 607 | |||
| 608 | if ( $SERVERMYSQLMERGE eq '1' ) { | ||
| 609 | if ($inputType eq "year" and $yearFrom = $yearTo) { | ||
| 610 | $sqlUnion = "union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". sprintf ("%04d", $yearFrom) ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)"; | ||
| 611 | } elsif ($inputType eq "quarter" and $monthFrom = $monthTo) { | ||
| 612 | $sqlUnion = "union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". sprintf ("%04d", $yearFrom) ."_Q". (int(($monthFrom+2)/3)) ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)"; | ||
| 613 | } | ||
| 614 | } | ||
| 615 | |||
| 616 | unless (defined $sqlUnion) { | ||
| 617 | foreach my $year ($yearFrom..$yearTo) { | ||
| 618 | my $monthF = ($year == $yearFrom) ? $monthFrom : 1; | ||
| 619 | my $monthT = ($year == $yearTo or $yearFrom == $yearTo) ? $monthTo : 12; | ||
| 620 | |||
| 621 | foreach my $month ($monthF..$monthT) { | ||
| 622 | my $yearTable = sprintf ("%04d", $year); | ||
| 623 | my $monthTable = sprintf ("%02d", $month); | ||
| 624 | $sqlUnion .= " union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". $yearTable ."_". $monthTable ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)"; | ||
| 625 | } | ||
| 626 | } | ||
| 627 | } | ||
| 628 | |||
| 629 | if (defined $sqlUnion) { | ||
| 630 | $sql = "($sqlCommon) $sqlUnion $sqlOrderUnion"; | ||
| 631 | } else { | ||
| 632 | $sql = $sqlCommon; | ||
| 633 | } | ||
| 634 | } | ||
| 635 | |||
| 636 | return $sql; | ||
| 637 | } | ||
| 638 | |||
| 639 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 640 | |||
| 641 | sub create_sql_query_from_range_SLA_window { | ||
| 642 | my (@days) = @_; # @_ => ($sunday, $monday, $tuesday, $wednesday, $thursday, $friday, $saturday) | ||
| 643 | |||
| 644 | my ($day, $windowSLA) = (0); | ||
| 645 | |||
| 646 | foreach my $periode (@days) { | ||
| 647 | $day++; | ||
| 648 | |||
| 649 | if ( defined $periode and $periode and $periode !~ /00:00-24:00/ ) { | ||
| 650 | my @range = split (/,/, $periode); | ||
| 651 | my $windowToday; | ||
| 652 | |||
| 653 | foreach my $range (@range) { | ||
| 654 | my ($from, $to) = split (/-/, $range); | ||
| 655 | |||
| 656 | if ( defined $from and defined $to ) { | ||
| 657 | $windowToday .= ' or ' if ( defined $windowToday ); | ||
| 658 | $windowToday .= "startTime BETWEEN '$from:00' and '$to:00'"; | ||
| 659 | } | ||
| 660 | } | ||
| 661 | |||
| 662 | if ( defined $windowToday ) { | ||
| 663 | $windowSLA .= ' or ' if ( defined $windowSLA ); | ||
| 664 | $windowSLA .= '( DAYOFWEEK(startDate) = '. $day .' and ( '. $windowToday .' ) )' | ||
| 665 | } | ||
| 666 | } | ||
| 667 | } | ||
| 668 | |||
| 669 | return ( defined $windowSLA ? ' and ( '. $windowSLA .' )' : '' ); | ||
| 670 | } | ||
| 671 | |||
| 672 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 673 | |||
| 674 | sub get_title { | ||
| 675 | my ($dbh, $rv, $catalogID, $uKey, $debug, $refresh, $sessionID) = @_; | ||
| 676 | |||
| 677 | my ($sql, $sth, $errorMessage, $dbiErrorCode, $dbiErrorString, $title, $environment, $trendline, $step, $applicationTitle, $trendValue, $stepValue); | ||
| 678 | $sql = "select concat( LTRIM(SUBSTRING_INDEX(title, ']', -1)), ' (', $SERVERTABLENVIRONMENT.label, ')' ), $SERVERTABLPLUGINS.environment, trendline, step from $SERVERTABLPLUGINS, $SERVERTABLENVIRONMENT WHERE catalogID = '$catalogID' and uKey = '$uKey' and $SERVERTABLPLUGINS.environment = $SERVERTABLENVIRONMENT.environment"; | ||
| 679 | $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", $refresh, '', $sessionID); | ||
| 680 | $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", $refresh, '', $sessionID) if $rv; | ||
| 681 | $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; | ||
| 682 | |||
| 683 | if ( $rv ) { | ||
| 684 | while( $sth->fetch() ) { | ||
| 685 | $title =~ s/^[\[[\S+|\s+]*\]\s+]{0,1}([\S+|\s+]*)/$1/g; | ||
| 686 | $applicationTitle = $title; | ||
| 687 | $trendValue = $trendline; | ||
| 688 | $stepValue = $step; | ||
| 689 | } | ||
| 690 | |||
| 691 | $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", $refresh, '', $sessionID); | ||
| 692 | } | ||
| 693 | |||
| 694 | if ( $refresh == 0 ) { | ||
| 695 | return ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $applicationTitle, $trendValue, $stepValue); | ||
| 696 | } elsif ( $refresh == -1 ) { | ||
| 697 | return ($rv, $applicationTitle); | ||
| 698 | } else { | ||
| 699 | return ($rv, $applicationTitle, $trendValue); | ||
| 700 | } | ||
| 701 | } | ||
| 702 | |||
| 703 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 704 | |||
| 705 | sub get_sql_crontab_scheduling_report_data { | ||
| 706 | my ($dbh, $sql, $rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $sessionID, $hight, $hightMin, $uKeys, $labels, $stepValue, $catalogID, $uKeysSqlWhere, $debug) = @_; | ||
| 707 | |||
| 708 | my ($collectorDaemon, $uKey, $lineNumber, $minute, $hour, $dayOfTheMonth, $monthOfTheYear, $dayOfTheWeek, $noOffline, $applicationTitle, $step); | ||
| 709 | my $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID); | ||
| 710 | $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv; | ||
| 711 | $sth->bind_columns( \$collectorDaemon, \$uKey, \$lineNumber, \$minute, \$hour, \$dayOfTheMonth, \$monthOfTheYear, \$dayOfTheWeek, \$noOffline ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv; | ||
| 712 | |||
| 713 | my $numberOfLabels = 0; | ||
| 714 | |||
| 715 | if ( $rv ) { | ||
| 716 | if ( $sth->rows ) { | ||
| 717 | while( $sth->fetch() ) { | ||
| 718 | if (exists $$uKeys{$uKey}) { | ||
| 719 | $$uKeys{$uKey}->{collectorDaemon} .= '|' .$collectorDaemon if ($collectorDaemon ne $$uKeys{$uKey}->{collectorDaemon}); | ||
| 720 | $$uKeys{$uKey}->{noOffline} .= '|' .$noOffline if ($noOffline ne $$uKeys{$uKey}->{noOffline}); | ||
| 721 | } else { | ||
| 722 | $$uKeys{$uKey}->{collectorDaemon} = $collectorDaemon; | ||
| 723 | $$uKeys{$uKey}->{noOffline} = $noOffline; | ||
| 724 | $$uKeys{$uKey}->{numberOfLabel} = $numberOfLabels; | ||
| 725 | |||
| 726 | if (defined $$uKeysSqlWhere) { $$uKeysSqlWhere .= (($$uKeysSqlWhere) ? ' OR ' : '') . "$SERVERTABLEVENTS.uKey = '$uKey'"; } | ||
| 727 | |||
| 728 | ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $applicationTitle, undef, $step) = get_title( $dbh, $rv, $catalogID, $uKey, $debug, 0, $sessionID ); | ||
| 729 | |||
| 730 | if ($rv) { | ||
| 731 | @$labels[$numberOfLabels] = $applicationTitle; | ||
| 732 | @$stepValue[$numberOfLabels] = $step; | ||
| 733 | } | ||
| 734 | |||
| 735 | $numberOfLabels++; | ||
| 736 | } | ||
| 737 | |||
| 738 | $$uKeys{$uKey}->{lineNumbers}->{$lineNumber} = { minute => $minute, hour => $hour, dayOfTheMonth => $dayOfTheMonth, monthOfTheYear => $monthOfTheYear, dayOfTheWeek => $dayOfTheWeek }; | ||
| 739 | } | ||
| 740 | } else { | ||
| 741 | $hight = $hightMin; $rv = 0; $errorMessage = "There are no Crontabs available"; | ||
| 742 | } | ||
| 743 | |||
| 744 | $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", 0, '', $sessionID); | ||
| 745 | } | ||
| 746 | |||
| 747 | return ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $hight, $numberOfLabels); | ||
| 748 | } | ||
| 749 | |||
| 750 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 751 | |||
| 752 | sub get_sql_startDate_sqlEndDate_numberOfDays_test { | ||
| 753 | my ($strictDate, $firstStartDate, $inputType, $selYear, $selQuarter, $selMonth, $selWeek, $selStartDate, $selEndDate, $currentYear, $currentMonth, $currentDay, $debug) = @_; | ||
| 754 | |||
| 755 | use Date::Calc qw(Add_Delta_Days check_date Days_in_Month Delta_Days Monday_of_Week Week_of_Year); | ||
| 756 | |||
| 757 | my ($startDate, $endDate, $goodDate); | ||
| 758 | |||
| 759 | if ($inputType eq "fromto") { | ||
| 760 | if (defined $selEndDate and $selEndDate ne '') { | ||
| 761 | $startDate = $selStartDate; | ||
| 762 | $endDate = $selEndDate; | ||
| 763 | } else { | ||
| 764 | $startDate = $selStartDate; | ||
| 765 | $endDate = $selStartDate; | ||
| 766 | } | ||
| 767 | } elsif ($inputType eq "year") { | ||
| 768 | $startDate = "$selYear-1-1"; | ||
| 769 | $endDate = "$selYear-12-31"; | ||
| 770 | } elsif ($inputType eq "quarter") { | ||
| 771 | my $fromQuarterMonth = $QUARTERS{ $selQuarter }; | ||
| 772 | my $toQuarterMonth = $fromQuarterMonth + 2; | ||
| 773 | my $toQuarterNumberOfDays = Days_in_Month($selYear, $toQuarterMonth); | ||
| 774 | $startDate = "$selYear-$fromQuarterMonth-1"; | ||
| 775 | $endDate = "$selYear-$toQuarterMonth-$toQuarterNumberOfDays"; | ||
| 776 | } elsif ($inputType eq "month") { | ||
| 777 | my $daysInMonth = Days_in_Month($selYear, $selMonth); | ||
| 778 | $startDate = "$selYear-$selMonth-1"; | ||
| 779 | $endDate = "$selYear-$selMonth-$daysInMonth"; | ||
| 780 | } elsif ($inputType eq "week") { | ||
| 781 | my ($yearFrom, $monthFrom, $dayFrom) = Monday_of_Week( $selWeek, $selYear ); | ||
| 782 | my ($yearTo, $monthTo, $dayTo) = Add_Delta_Days ( $yearFrom, $monthFrom, $dayFrom, 6 ); | ||
| 783 | $startDate = "$yearFrom-$monthFrom-$dayFrom"; | ||
| 784 | $endDate = "$yearTo-$monthTo-$dayTo"; | ||
| 785 | } else { | ||
| 786 | return (0, undef, undef, undef); | ||
| 787 | } | ||
| 788 | |||
| 789 | my ($fromYear, $fromMonth, $fromDay) = split (/-/, $startDate); | ||
| 790 | $fromYear = 0 if (! defined $fromYear or $fromYear !~ /^[0-9]+$/); | ||
| 791 | $fromMonth = 0 if (! defined $fromMonth or $fromMonth !~ /^[0-9]+$/); | ||
| 792 | $fromDay = 0 if (! defined $fromDay or $fromDay !~ /^[0-9]+$/); | ||
| 793 | |||
| 794 | my ($toYear, $toMonth, $toDay) = split (/-/, $endDate); | ||
| 795 | $toYear = 0 if (! defined $toYear or $toYear !~ /^[0-9]+$/); | ||
| 796 | $toMonth = 0 if (! defined $toMonth or $toMonth !~ /^[0-9]+$/); | ||
| 797 | $toDay = 0 if (! defined $toDay or $toDay !~ /^[0-9]+$/); | ||
| 798 | |||
| 799 | return (0, undef, undef, undef) unless ( check_date ( $fromYear, $fromMonth, $fromDay) and check_date($toYear, $toMonth, $toDay ) ); | ||
| 800 | |||
| 801 | my $switchDate = Delta_Days($fromYear, $fromMonth, $fromDay, $toYear, $toMonth, $toDay); | ||
| 802 | |||
| 803 | if ($switchDate < 0) { | ||
| 804 | ($startDate, $endDate) = ($endDate, $startDate) ; | ||
| 805 | ($fromYear, $fromMonth, $fromDay) = split (/-/, $startDate); | ||
| 806 | ($toYear, $toMonth, $toDay) = split (/-/, $endDate); | ||
| 807 | } | ||
| 808 | |||
| 809 | my ($firstYear, $firstMonth, $firstDay) = split (/-/, $firstStartDate); | ||
| 810 | $switchDate = Delta_Days($firstYear, $firstMonth, $firstDay, $fromYear, $fromMonth, $fromDay); | ||
| 811 | |||
| 812 | if ($switchDate < 0) { | ||
| 813 | $startDate = $firstStartDate; | ||
| 814 | ($fromYear, $fromMonth, $fromDay) = split (/-/, $firstStartDate); | ||
| 815 | } | ||
| 816 | |||
| 817 | my $firstDeltaDays = Delta_Days($fromYear, $fromMonth, $fromDay, $toYear, $toMonth, $toDay); | ||
| 818 | |||
| 819 | if ($firstDeltaDays < 0) { | ||
| 820 | $goodDate = 0; | ||
| 821 | print "-) $inputType, $selYear, $selQuarter, $selMonth, $selWeek, $selStartDate, $selEndDate, $startDate, $endDate, <- $firstStartDate, $goodDate\n" if ( $debug eq 'T' ); | ||
| 822 | return (0, $firstStartDate, $firstStartDate, 0); | ||
| 823 | } | ||
| 824 | |||
| 825 | my $fromDeltaDays = Delta_Days($fromYear, $fromMonth, $fromDay, $currentYear, $currentMonth, $currentDay); | ||
| 826 | my $sqlStartDate = ($fromDeltaDays >= 0) ? $startDate : "$currentYear-$currentMonth-$currentDay"; | ||
| 827 | my ($yearFrom, $monthFrom, $dayFrom) = split(/-/, $sqlStartDate); | ||
| 828 | |||
| 829 | my $toDeltaDays = Delta_Days($toYear, $toMonth, $toDay, $currentYear, $currentMonth, $currentDay); | ||
| 830 | my $sqlEndDate = ($toDeltaDays >= 0) ? $endDate : "$currentYear-$currentMonth-$currentDay"; | ||
| 831 | my ($yearTo, $monthTo, $dayTo) = split(/-/, $sqlEndDate); | ||
| 832 | |||
| 833 | my $numberOfDays = Delta_Days($yearFrom, $monthFrom, $dayFrom, $yearTo, $monthTo, $dayTo) + 1; | ||
| 834 | my $sqlDeltaDays = Delta_Days($toYear, $toMonth, $toDay, $yearTo, $monthTo, $dayTo); | ||
| 835 | |||
| 836 | if ($sqlDeltaDays == 0) { | ||
| 837 | print "A) " if ( $debug eq 'T' ); | ||
| 838 | $goodDate = 1; | ||
| 839 | } elsif ($strictDate) { | ||
| 840 | print "B) " if ( $debug eq 'T' ); | ||
| 841 | $goodDate = 0; | ||
| 842 | } elsif ($inputType eq "fromto") { | ||
| 843 | print "C) " if ( $debug eq 'T' ); | ||
| 844 | $goodDate = ($sqlStartDate eq $sqlEndDate and $endDate ne $sqlEndDate ) ? 0 : 1; | ||
| 845 | } elsif ($inputType eq "year" and $toYear == $yearTo) { | ||
| 846 | print "D) " if ( $debug eq 'T' ); | ||
| 847 | $goodDate = 1; | ||
| 848 | } elsif ($fromYear > $yearTo) { # or $toYear > $yearTo | ||
| 849 | print "E) " if ( $debug eq 'T' ); | ||
| 850 | $goodDate = 0; | ||
| 851 | } elsif ($inputType eq "quarter") { | ||
| 852 | print "F) " if ( $debug eq 'T' ); | ||
| 853 | my $fromDays = Days_in_Month($fromYear, $fromMonth); | ||
| 854 | my $daysFrom = Days_in_Month($yearFrom, $monthFrom); | ||
| 855 | $goodDate = ($fromMonth != $monthFrom) ? 0 : 1; | ||
| 856 | } elsif ($inputType eq "month") { | ||
| 857 | print "G) " if ( $debug eq 'T' ); | ||
| 858 | $goodDate = ($toMonth > $monthTo) ? 0 : 1; | ||
| 859 | } elsif ($inputType eq "week") { | ||
| 860 | print "H) " if ( $debug eq 'T' ); | ||
| 861 | my ($toWeek, $toYear) = Week_of_Year( $toYear, $toMonth, $toDay ); | ||
| 862 | my ($weekTo, $yearTo) = Week_of_Year( $yearTo, $monthTo, $dayTo ); | ||
| 863 | $goodDate = ($toYear != $yearTo or $toWeek > $weekTo) ? 0 : 1; | ||
| 864 | } else { | ||
| 865 | print "I) " if ( $debug eq 'T' ); | ||
| 866 | $goodDate = 0; | ||
| 867 | } | ||
| 868 | |||
| 869 | print "$inputType, $selYear, $selQuarter, $selMonth, $selWeek, $selStartDate, $selEndDate, $startDate, $endDate, $sqlStartDate, $sqlEndDate, $fromDeltaDays, $toDeltaDays, $numberOfDays, $sqlDeltaDays, $goodDate\n" if ( $debug eq 'T' ); | ||
| 870 | return ($goodDate, $sqlStartDate, $sqlEndDate, $numberOfDays); | ||
| 871 | } | ||
| 872 | |||
| 873 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 874 | |||
| 875 | sub create_combobox_from_keys_and_values_pairs { | ||
| 876 | my ($comboboxSelectKeysAndValuesPairs, $sortOn, $sortNumeric, $Ckey, $selectName, $selectValue, $selectLabel, $formDisabled, $onChange, $debug) = @_; | ||
| 877 | |||
| 878 | my %comboSelectKeysAndValuesPairs = map { my ($key, $value) = split (/=>/) } split (/\|/, $comboboxSelectKeysAndValuesPairs); | ||
| 879 | |||
| 880 | my $comboSelect = "<select name=\"$selectName\" $formDisabled $onChange>\n"; | ||
| 881 | |||
| 882 | if ($selectLabel ne '') { | ||
| 883 | $comboSelect .= " <option value=\"$selectValue\""; | ||
| 884 | $comboSelect .= " selected" if ($Ckey eq $selectValue); | ||
| 885 | $comboSelect .= ">$selectLabel</option>\n"; | ||
| 886 | } | ||
| 887 | |||
| 888 | if ($sortOn eq 'K') { | ||
| 889 | foreach my $key ( sort keys ( %comboSelectKeysAndValuesPairs ) ) { | ||
| 890 | my $value = $comboSelectKeysAndValuesPairs{$key}; | ||
| 891 | $comboSelect .= " <option value=\"$key\""; | ||
| 892 | $comboSelect .= " selected" if ($Ckey eq $key); | ||
| 893 | $comboSelect .= ">$value</option>\n"; | ||
| 894 | } | ||
| 895 | } elsif ($sortOn eq 'V') { | ||
| 896 | if ($sortNumeric) { | ||
| 897 | foreach my $key ( sort { $comboSelectKeysAndValuesPairs{$a} <=> $comboSelectKeysAndValuesPairs{$b}; } keys ( %comboSelectKeysAndValuesPairs ) ) { | ||
| 898 | my $value = $comboSelectKeysAndValuesPairs{$key}; | ||
| 899 | $comboSelect .= " <option value=\"$key\""; | ||
| 900 | $comboSelect .= " selected" if ($Ckey eq $key); | ||
| 901 | $comboSelect .= ">$value</option>\n"; | ||
| 902 | } | ||
| 903 | } else { | ||
| 904 | foreach my $key ( sort { $comboSelectKeysAndValuesPairs{$a} cmp $comboSelectKeysAndValuesPairs{$b}; } keys ( %comboSelectKeysAndValuesPairs ) ) { | ||
| 905 | my $value = $comboSelectKeysAndValuesPairs{$key}; | ||
| 906 | $comboSelect .= " <option value=\"$key\""; | ||
| 907 | $comboSelect .= " selected" if ($Ckey eq $key); | ||
| 908 | $comboSelect .= ">$value</option>\n"; | ||
| 909 | } | ||
| 910 | } | ||
| 911 | } else { | ||
| 912 | foreach my $key ( keys ( %comboSelectKeysAndValuesPairs ) ) { | ||
| 913 | my $value = $comboSelectKeysAndValuesPairs{$key}; | ||
| 914 | $comboSelect .= " <option value=\"$key\""; | ||
| 915 | $comboSelect .= " selected" if ($Ckey eq $key); | ||
| 916 | $comboSelect .= ">$value</option>\n"; | ||
| 917 | } | ||
| 918 | } | ||
| 919 | |||
| 920 | $comboSelect .= " </select>\n"; | ||
| 921 | return ($comboSelect); | ||
| 922 | } | ||
| 923 | |||
| 924 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 925 | |||
| 926 | sub create_combobox_from_DBI { | ||
| 927 | my ($rv, $dbh, $sql, $firstOption, $nextAction, $Ckey, $selectName, $selectValue, $selectLabel, $formDisabled, $onChange, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_; | ||
| 928 | |||
| 929 | my ($key, $value); | ||
| 930 | |||
| 931 | my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 932 | $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv; | ||
| 933 | $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; | ||
| 934 | |||
| 935 | my $comboSelect = "<select name=\"$selectName\" $formDisabled $onChange>\n"; | ||
| 936 | |||
| 937 | if ($selectLabel ne '') { | ||
| 938 | if ($firstOption or (! $firstOption and $Ckey eq $selectValue)) { | ||
| 939 | $comboSelect .= " <option value=\"$selectValue\""; | ||
| 940 | $comboSelect .= " selected" if ($Ckey eq $selectValue); | ||
| 941 | $comboSelect .= ">$selectLabel</option>\n"; | ||
| 942 | } | ||
| 943 | } | ||
| 944 | |||
| 945 | if ( $rv ) { | ||
| 946 | while( $sth->fetch() ) { | ||
| 947 | $comboSelect .= " <option value=\"$key\""; | ||
| 948 | |||
| 949 | if ($Ckey eq $key) { | ||
| 950 | $htmlTitle = "$value: $nextAction" if ($nextAction ne ''); | ||
| 951 | $comboSelect .= " selected"; | ||
| 952 | } | ||
| 953 | |||
| 954 | $comboSelect .= ">$value</option>\n"; | ||
| 955 | } | ||
| 956 | |||
| 957 | $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 958 | } | ||
| 959 | |||
| 960 | $comboSelect .= " </select>\n"; | ||
| 961 | return ($rv, $comboSelect, $htmlTitle); | ||
| 962 | } | ||
| 963 | |||
| 964 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 965 | |||
| 966 | sub create_combobox_multiple_from_DBI { | ||
| 967 | my ($rv, $dbh, $sql, $action, $Ckey, $selectName, $selectValue, $selectSize, $textareaCols, $formDisabled, $onChange, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_; | ||
| 968 | |||
| 969 | my ($key, $value); | ||
| 970 | my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 971 | $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv; | ||
| 972 | $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; | ||
| 973 | |||
| 974 | my $comboboxSelect = ''; | ||
| 975 | |||
| 976 | if ($rv) { | ||
| 977 | if ( $sth->rows ) { | ||
| 978 | my $comboboxSelectSize = 0; | ||
| 979 | |||
| 980 | if ($action eq 'duplicateView' or $action eq 'editView' or $action eq 'insertView') { | ||
| 981 | while( $sth->fetch() ) { | ||
| 982 | $comboboxSelectSize++; | ||
| 983 | $comboboxSelect .= "<option value=\"$key\""; | ||
| 984 | $comboboxSelect .= " selected" if ($Ckey =~ /\/$key\//); | ||
| 985 | $comboboxSelect .= ">$value</option>"; | ||
| 986 | } | ||
| 987 | |||
| 988 | $comboboxSelectSize = ($comboboxSelectSize > $selectSize) ? $selectSize : $comboboxSelectSize; | ||
| 989 | $comboboxSelect = "<select name=\"$selectName\" id=\"${selectName}_id\" size=\"$comboboxSelectSize\" multiple $onChange>" .$comboboxSelect. "</select>"; | ||
| 990 | } else { | ||
| 991 | while( $sth->fetch() ) { | ||
| 992 | if ($Ckey =~ /\/$key\//) { | ||
| 993 | $comboboxSelectSize++; | ||
| 994 | $comboboxSelect .= "$value\n" if ($Ckey =~ /\/$key\//); | ||
| 995 | } | ||
| 996 | } | ||
| 997 | |||
| 998 | $comboboxSelect = "<textarea name=$selectName cols=$textareaCols rows=$comboboxSelectSize $formDisabled>$comboboxSelect</textarea>"; | ||
| 999 | } | ||
| 1000 | } else { | ||
| 1001 | if ($action eq 'duplicateView' or $action eq 'editView' or $action eq 'insertView') { | ||
| 1002 | $comboboxSelect = "<select name=\"$selectName\" size=\"1\" multiple $onChange></select>"; | ||
| 1003 | } else { | ||
| 1004 | $comboboxSelect = $selectValue; | ||
| 1005 | } | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | return ($rv, $comboboxSelect); | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 1015 | |||
| 1016 | sub record_navigation_table { | ||
| 1017 | my ($rv, $dbh, $sql, $label, $keyLabels, $keyNumbers, $ignoreFieldNumbers, $translationFieldsKeysAndValues, $addAccessParameters, $orderBy, $header, $navigationBar, $iconAdd, $iconDelete, $iconDetails, $iconEdit, $nextAction, $pagedir, $pageset, $pageNo, $pageOffset, $htmlTitle, $subTitle, $sessionID, $debug) = @_; | ||
| 1018 | |||
| 1019 | my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 1020 | $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv; | ||
| 1021 | |||
| 1022 | my $matchingRecords = ''; | ||
| 1023 | |||
| 1024 | if ( $rv ) { | ||
| 1025 | my @keyLabels = split (/\|/, $keyLabels); | ||
| 1026 | my @keyNumbers = split (/\|/, $keyNumbers); | ||
| 1027 | |||
| 1028 | my @translationFieldsKeysAndValues = split (/\|\|/, $translationFieldsKeysAndValues); | ||
| 1029 | my %translationFieldKeyAndValue = (); | ||
| 1030 | |||
| 1031 | foreach $translationFieldsKeysAndValues (@translationFieldsKeysAndValues) { | ||
| 1032 | my ($translationField, $translationKeysAndValues) = split (/#/, $translationFieldsKeysAndValues, 2); | ||
| 1033 | |||
| 1034 | if (defined $translationField) { | ||
| 1035 | my @translationKeyValuePairs = split (/\|/, $translationKeysAndValues); | ||
| 1036 | |||
| 1037 | foreach my $translationKeyValuePairs (@translationKeyValuePairs) { | ||
| 1038 | my ($key, $value) = split (/=>/, $translationKeyValuePairs); | ||
| 1039 | $translationFieldKeyAndValue{$translationField}{$key} = $value; | ||
| 1040 | } | ||
| 1041 | } | ||
| 1042 | } | ||
| 1043 | |||
| 1044 | my $actionPressend = ($iconAdd or $iconDelete or $iconDetails or $iconEdit) ? 1 : 0; | ||
| 1045 | my $actionHeader = ($actionPressend) ? "<th>Action</th>" : ''; | ||
| 1046 | my $urlWithAccessParameters = $ENV{SCRIPT_NAME} . "?pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&pageNo=$pageNo&pageOffset=$pageOffset$addAccessParameters"; | ||
| 1047 | |||
| 1048 | $matchingRecords = "\n <table align=\"center\" border=0 cellpadding=1 cellspacing=1 bgcolor='$COLORSTABLE{TABLE}'>\n <tr>$header$actionHeader</tr>\n"; | ||
| 1049 | my $numFields = $sth->{NUM_OF_FIELDS}; my $colspan = $numFields + 1; | ||
| 1050 | |||
| 1051 | if ( $sth->rows ) { | ||
| 1052 | while ( my $ref = $sth->fetchrow_arrayref ) { | ||
| 1053 | my $actionItem = ($actionPressend) ? "<td align=\"left\"> " : ''; | ||
| 1054 | my $actionKeys = ''; | ||
| 1055 | my $actionSkip = 0; | ||
| 1056 | my $item = 0; | ||
| 1057 | |||
| 1058 | foreach my $keyLabels (@keyLabels) { | ||
| 1059 | $actionKeys .= "&$keyLabels=$$ref[$keyNumbers[$item]]"; | ||
| 1060 | $actionSkip = 1 if ( $label ne 'Catalog' and $keyLabels eq 'catalogID' and $$ref[$keyNumbers[$item]] ne $CATALOGID ); | ||
| 1061 | $item++; | ||
| 1062 | } | ||
| 1063 | |||
| 1064 | my $urlWithAccessParametersAction = "$urlWithAccessParameters$actionKeys&orderBy=$orderBy&action"; | ||
| 1065 | $actionItem .= "<a href=\"$urlWithAccessParametersAction=displayView\"><img src=\"$IMAGESURL/$ICONSRECORD{details}\" title=\"Display $label\" alt=\"Display $label\" border=\"0\"></a> " if ($iconDetails); | ||
| 1066 | $actionItem .= "<a href=\"$urlWithAccessParametersAction=duplicateView\"><img src=\"$IMAGESURL/$ICONSRECORD{duplicate}\" title=\"Duplicate $label\" alt=\"Duplicate $label\" border=\"0\"></a> " if ($iconAdd); | ||
| 1067 | |||
| 1068 | unless ( $actionSkip ) { | ||
| 1069 | $actionItem .= "<a href=\"$urlWithAccessParametersAction=editView\"><img src=\"$IMAGESURL/$ICONSRECORD{edit}\" title=\"Edit $label\" alt=\"Edit $label\" border=\"0\"></a> " if ($iconEdit); | ||
| 1070 | $actionItem .= "<a href=\"$urlWithAccessParametersAction=deleteView\"><img src=\"$IMAGESURL/$ICONSRECORD{delete}\" title=\"Delete $label\" alt=\"Delete $label\" border=\"0\"></a> " if ($iconDelete); | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | $actionItem .= "</td>" if ($actionPressend); | ||
| 1074 | |||
| 1075 | $matchingRecords .= " <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\">"; | ||
| 1076 | |||
| 1077 | for (my $i = 0; $i < $numFields; $i++) { | ||
| 1078 | my $value; | ||
| 1079 | |||
| 1080 | if ($ignoreFieldNumbers eq '') { | ||
| 1081 | $value = $$ref[$i]; | ||
| 1082 | } else { | ||
| 1083 | $value = $$ref[$i] if ("|$ignoreFieldNumbers|" !~ /\|$i\|/); | ||
| 1084 | } | ||
| 1085 | |||
| 1086 | if (defined $value) { | ||
| 1087 | $value = $translationFieldKeyAndValue{$i}{$$ref[$i]} if (defined $translationFieldKeyAndValue{$i}{$$ref[$i]}); | ||
| 1088 | $matchingRecords .= "<td>" .encode_html_entities('T', $value). "</td>"; | ||
| 1089 | } | ||
| 1090 | } | ||
| 1091 | |||
| 1092 | $matchingRecords .= "$actionItem</tr>\n"; | ||
| 1093 | } | ||
| 1094 | } else { | ||
| 1095 | $matchingRecords .= " <tr><td colspan=\"$colspan\">No records found.</td></tr>\n"; | ||
| 1096 | } | ||
| 1097 | |||
| 1098 | $matchingRecords .= " <tr><td colspan=\"$colspan\">$navigationBar</td></tr>\n" if ($navigationBar); | ||
| 1099 | $matchingRecords .= " </table>\n"; | ||
| 1100 | $sth->finish() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->finish: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 1101 | $nextAction = "listView"; | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | return ($rv, $matchingRecords, $nextAction); | ||
| 1105 | } | ||
| 1106 | |||
| 1107 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 1108 | |||
| 1109 | sub record_navigation_bar { | ||
| 1110 | my ($currentPageNo, $numberRecordsIntoQuery, $showRecordsOnPage, $urlWithAccessParameters) = @_; | ||
| 1111 | |||
| 1112 | my $navigationBar; | ||
| 1113 | |||
| 1114 | if ( $numberRecordsIntoQuery > $showRecordsOnPage ) { | ||
| 1115 | my $numberOffPagesMax = int((($numberRecordsIntoQuery - 1) / $showRecordsOnPage) + 1); | ||
| 1116 | $currentPageNo = $numberOffPagesMax if ($currentPageNo > $numberOffPagesMax); | ||
| 1117 | my $wantedRecordFirst = (($currentPageNo - 1) * $showRecordsOnPage) + 1; | ||
| 1118 | my $TwantedRecordLast = $wantedRecordFirst + ($showRecordsOnPage - 1); | ||
| 1119 | my $wantedRecordLast = ($TwantedRecordLast < $numberRecordsIntoQuery) ? $TwantedRecordLast : $numberRecordsIntoQuery; | ||
| 1120 | |||
| 1121 | my $numberOffRecords = (($wantedRecordLast - 1) % $showRecordsOnPage) + 1; | ||
| 1122 | |||
| 1123 | $navigationBar = "<table border=\"0\" width=\"100%\" bgcolor=\"$COLORSTABLE{ENDBLOCK}\"><tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td align=\"center\" width=\"36\">$currentPageNo/$numberOffPagesMax</td><td align=\"center\">"; | ||
| 1124 | |||
| 1125 | if ($wantedRecordLast > 1) { | ||
| 1126 | if ($currentPageNo > 1) { | ||
| 1127 | my $previousPage = $currentPageNo - 1; | ||
| 1128 | my $previousPageOffset = ($showRecordsOnPage * ($previousPage - 1)); | ||
| 1129 | $navigationBar .= " <a href=\"$urlWithAccessParameters&pageNo=1&pageOffset=0\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{first}\" ALT=\"First\" BORDER=0></a> <a href=\"$urlWithAccessParameters&pageNo=$previousPage&pageOffset=$previousPageOffset\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{left}\" ALT=\"Left\" BORDER=0></a> <a href=\"$urlWithAccessParameters&pageNo=1&pageOffset=0\">1</a>"; | ||
| 1130 | } else { | ||
| 1131 | $navigationBar .= " 1"; | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | for (my $currentPage = 2; $currentPage < $numberOffPagesMax; $currentPage++) { | ||
| 1135 | if ( $currentPageNo != $currentPage ) { | ||
| 1136 | my $offsetOffRecords = ($showRecordsOnPage * ($currentPage - 1)); | ||
| 1137 | $navigationBar .= " <a href=\"$urlWithAccessParameters&pageNo=$currentPage&pageOffset=$offsetOffRecords\">$currentPage</a>"; | ||
| 1138 | } else { | ||
| 1139 | $navigationBar .= " $currentPage"; | ||
| 1140 | } | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | if ($currentPageNo < $numberOffPagesMax) { | ||
| 1144 | my $nextPage = $currentPageNo + 1; | ||
| 1145 | my $nextPageOffset = ($showRecordsOnPage * ($nextPage - 1)); | ||
| 1146 | my $lastPageOffset = ($showRecordsOnPage * ($numberOffPagesMax - 1)); | ||
| 1147 | $navigationBar .= " <a href=\"$urlWithAccessParameters&pageNo=$numberOffPagesMax&pageOffset=$lastPageOffset\">$numberOffPagesMax</a> <a href=\"$urlWithAccessParameters&pageNo=$nextPage&pageOffset=$nextPageOffset\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{right}\" ALT=\"Right\" BORDER=0></a> <a href=\"$urlWithAccessParameters&pageNo=$numberOffPagesMax&pageOffset=$lastPageOffset\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{last}\" ALT=\"Last\" BORDER=0></a>"; | ||
| 1148 | } else { | ||
| 1149 | $navigationBar .= " $numberOffPagesMax"; | ||
| 1150 | } | ||
| 1151 | } else { | ||
| 1152 | $navigationBar .= " "; | ||
| 1153 | } | ||
| 1154 | |||
| 1155 | $navigationBar .= "</td></tr></table>\n"; | ||
| 1156 | } | ||
| 1157 | |||
| 1158 | return ($navigationBar); | ||
| 1159 | } | ||
| 1160 | |||
| 1161 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 1162 | |||
| 1163 | sub record_navigation_bar_alpha { | ||
| 1164 | my ($rv, $dbh, $table, $field, $where, $numberRecordsIntoQuery, $showRecordsOnPage, $urlWithAccessParameters, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug) = @_; | ||
| 1165 | |||
| 1166 | my $navigationBarAlpha = ''; | ||
| 1167 | |||
| 1168 | if ( $numberRecordsIntoQuery > $showRecordsOnPage ) { | ||
| 1169 | $navigationBarAlpha = "<table border=\"0\" width=\"100%\" bgcolor=\"$COLORSTABLE{ENDBLOCK}\"><tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td align=\"center\">"; | ||
| 1170 | |||
| 1171 | my ($rownumber, $label); | ||
| 1172 | |||
| 1173 | 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"; | ||
| 1174 | my $sth = $dbh->prepare( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->prepare: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID); | ||
| 1175 | $sth->execute() or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv; | ||
| 1176 | $sth->bind_columns( \$rownumber, \$label ) or $rv = error_trap_DBI(*STDOUT, "Cannot sth->execute: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID) if $rv; | ||
| 1177 | |||
| 1178 | if ( $rv ) { | ||
| 1179 | if ( $sth->rows ) { | ||
| 1180 | while( $sth->fetch() ) { | ||
| 1181 | my $currentPage = int ( ( $rownumber / $showRecordsOnPage ) - 0.001 ); | ||
| 1182 | my $offsetOffRecords = $currentPage * $showRecordsOnPage; | ||
| 1183 | $currentPage++; | ||
| 1184 | $navigationBarAlpha .= " <a href=\"$urlWithAccessParameters&pageNo=$currentPage&pageOffset=$offsetOffRecords&orderBy=$field asc\">$label</a>"; | ||
| 1185 | } | ||
| 1186 | } | ||
| 1187 | } | ||
| 1188 | |||
| 1189 | $navigationBarAlpha .= "</td></tr></table>\n"; | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | return ($navigationBarAlpha); | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||
| 1196 | |||
| 1197 | 1; | ||
| 1198 | |||
| 1199 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 1200 | |||
| 1201 | __END__ |