diff --git a/,dockerignore b/,dockerignore deleted file mode 100644 index 2bbc36f8a..000000000 --- a/,dockerignore +++ /dev/null @@ -1,3 +0,0 @@ -.git -includes/settings.php -node_modules diff --git a/.dockerignore b/.dockerignore index 6895048b1..169da602c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,24 +1,19 @@ +.git +.gitignore bump_version.sh docker -docs/event_status.gif -docs/extractfaqs.pl -docs/faqs.html -docs/Makefile -docs/php2html.pl -docs/README -docs/sql2html.pl -docs/WebCalendar-Database.html -docs/WebCalendar-DeveloperGuide.html -docs/WebCalendar-Functions.html -docs/WebCalendar-Styling.html -docs/WebCalendar-UserManual.html -*.git -*.gitignore + +# ignore all docs/ +docs +# except these 2 +!docs/newwin.gif +!docs/WebCalendar-SysAdmin.html + includes/settings.php java Makefile -sqlite-data release-files +sqlite-data tests TODO vendor diff --git a/access.php b/access.php index a892f12f2..193e4e5cf 100644 --- a/access.php +++ b/access.php @@ -35,7 +35,8 @@ $defConfigStr = translate( 'DEFAULT CONFIGURATION' ); $goStr = ' - + '; $saveStr = translate( 'Save' ); $undoStr = translate( 'Undo' ); @@ -262,8 +263,9 @@ - - + + '; $pagetitle = translate( 'Allow Access to Other Users Calendar' ); @@ -415,13 +417,15 @@ echo ' ' - . ( $otheruser != '__default__' && $otheruser != '__public__' ? ' -   ' : '' ) . ' -    - + . ( $otheruser !== '__default__' && $otheruser !== '__public__' ? ' + ' + : '' ) . ' + + @@ -438,8 +442,10 @@ echo ' diff --git a/admin.php b/admin.php index 65d607294..2bdc4050e 100644 --- a/admin.php +++ b/admin.php @@ -110,10 +110,10 @@ function save_pref ( $prefs, $src ) { @session_start(); $_SESSION['webcal_tmp_login'] = 'blahblahblah'; - $editStr = ''; + $editStr = ''; $choices = ['day.php', 'week.php', 'month.php', 'year.php']; $choices_text = [translate ( 'Day' ), translate ( 'Week' ), translate ( 'Month' ), translate ( 'Year' )]; @@ -243,8 +243,8 @@ function save_pref ( $prefs, $src ) { ' . csrf_form_key() . display_admin_link() . ' -

+

' . $tabs . ' @@ -852,7 +852,8 @@ function save_pref ( $prefs, $src ) {
- +
diff --git a/approve_entry.php b/approve_entry.php index edb22bdfc..01063da74 100644 --- a/approve_entry.php +++ b/approve_entry.php @@ -31,10 +31,10 @@ diff --git a/assistant_edit.php b/assistant_edit.php index a1f659aca..cabfd71c3 100644 --- a/assistant_edit.php +++ b/assistant_edit.php @@ -57,14 +57,15 @@ echo "\n"; if ( $GROUPS_ENABLED == 'Y' ) { - echo ''; + echo ''; } echo "\n"; ?>
- +
diff --git a/category.php b/category.php index 342ff99f3..d3afcf4db 100644 --- a/category.php +++ b/category.php @@ -66,7 +66,7 @@
@@ -76,19 +76,19 @@
    - -
' : '') // end test of ENABLE_ICON_UPLOADS - . '
- ' + +
' : '' ) . ' +
+ ' . 'Cancel ' . (!empty($id) ? ' - ' : '') . ' + ' : '' ) . '
'; } else @@ -141,7 +141,8 @@
diff --git a/catsel.php b/catsel.php index 9a2a64eab..64c68c9df 100644 --- a/catsel.php +++ b/catsel.php @@ -59,8 +59,8 @@ } echo ' - + - + . '    +
- - + +
-     - +     +
- +
*' . translate ( 'Global Category' ) - . '     
diff --git a/docadd.php b/docadd.php index 28a2c4d8f..7a2db359c 100644 --- a/docadd.php +++ b/docadd.php @@ -216,7 +216,7 @@ : - + @@ -236,7 +236,7 @@ - + diff --git a/docker/Dockerfile-php8-dev b/docker/Dockerfile-php8-dev index 609197595..207f576cc 100644 --- a/docker/Dockerfile-php8-dev +++ b/docker/Dockerfile-php8-dev @@ -1,6 +1,5 @@ FROM php:8.0-apache -MAINTAINER craigk5n - +LABEL org.opencontainers.image.authors="craig@k5n.us" RUN docker-php-ext-install mysqli #COPY docker/cron-hourly /tmp/cron.hourly @@ -11,4 +10,3 @@ RUN docker-php-ext-install mysqli #TODO: setup cron #RUN chown -R www-data:www-data /var/www - diff --git a/docs/extractfaqs.pl b/docs/extractfaqs.pl index 3e40d7e29..523818948 100755 --- a/docs/extractfaqs.pl +++ b/docs/extractfaqs.pl @@ -15,13 +15,13 @@ # 02-Feb-2005 Craig Knudsen # Updated to group into categories. # -####################################################################### +################################################################################ -my @files = ( ); -my @questions = ( ); my @answers = ( ); -my @file = ( ); my @cat = ( ); +my @file = ( ); +my @files = ( ); +my @questions = ( ); for ( $i = 0; $i < @ARGV; $i++ ) { if ( -f $ARGV[$i] ) { @@ -152,4 +152,3 @@ sub process_file { } } } - diff --git a/docs/php2html.pl b/docs/php2html.pl index 220d79728..d30f1077c 100755 --- a/docs/php2html.pl +++ b/docs/php2html.pl @@ -6,8 +6,7 @@ # # Description: # Create HTML documentation from a PHP include file. -# The PHP file must use a specific syntax for documenting -# functions. +# The PHP file must use a specific syntax for documenting functions. # # History: # 21-Jan-2005 Craig Knudsen @@ -15,17 +14,17 @@ # 30-Nov-2002 Craig Knudsen # Created # -####################################################################### +################################################################################ $TITLE = 'WebCalendar Function Documentation'; sub add_links { my ( $in ) = @_; - $in =~ s/(webcal_[a-z_]+)\s+table/$1<\/tt><\/a> table/g; + $in =~ s/(webcal_[a-z_]+)\s+table/$1<\/span><\/a> table/g; foreach $funcName ( keys ( %funcNames ) ) { - $in =~ s/($funcName)\s+function/$1<\/tt><\/a> function/ig; + $in =~ s/($funcName)\s+function/$1<\/span><\/a> function/ig; } $in =~ s/&/&/g; @@ -39,11 +38,11 @@ sub add_links { sub print_function { my ( $loc ) = @_; $out{$name} = "

$name

\n"; - $out{$name} .= "$name ( " . '$' . join ( ', $', @params ) . - " )

\n"; + $out{$name} .= "$name ( " + . '$' . join ( ', $', @params ) . " )

\n"; if ( defined ( $description ) ) { - $out{$name} .= "Description:" . - "
"; + $out{$name} .= "Description:" + . "
"; $out{$name} .= add_links ( $description ) . "
\n"; } $out{$name} .= "Parameters:
\n
    \n"; @@ -51,16 +50,17 @@ sub print_function { $out{$name} .= "
  • None
  • \n"; } foreach $p ( @params ) { - $out{$name} .= "
  • \$$p"; + $out{$name} .= "
  • \$$p"; $out{$name} .= " - " . add_links ( $paramDescr{$p} ) if ( defined ( $paramDescr{$p} ) ); $out{$name} .= "
  • \n"; } $out{$name} .= "
\n"; - $out{$name} .= "Returns:
" . - ( $returns eq '' ? "Nothing" : add_links ( $returns ) ) . "
\n"; - $out{$name} .= "Location:" . - "
$loc
\n"; + $out{$name} .= "Returns:
" + . ( $returns eq '' ? "Nothing" : add_links ( $returns ) ) + . "
\n"; + $out{$name} .= "Location:" + . "
$loc
\n"; $out{$name} .= "

\n"; } @@ -174,108 +174,90 @@ sub print_function { } close ( F ); -print< - -$TITLE - - - -

$TITLE

-
-$info -
- - - - - -
Home Page:$url
WebCalendar Version:$version ($date)
Last updated:$now
-

List of Functions

-
    + + $TITLE + + + + +

    $TITLE

    +
    + $info +
    + + + + + + + + + + + + + +
    Home Page:$url
    WebCalendar Version:$version ($date)
    Last updated:$now
    +

    List of Functions

    +
      EOF foreach $name ( sort keys ( %out ) ) { - print "
    • $name
    • \n"; + print "\n
    • $name
    • "; } -print "
    \n
    \n"; +print "\n
\n
"; foreach $name ( sort keys ( %out ) ) { - print "

\n" . $out{$name}; + print "\n

\n " . $out{$name}; } -print< -

- Valid XHTML 1.0! -

- +print < +

Validate>

+ EOF diff --git a/edit_entry.php b/edit_entry.php index da9bac12d..bd27440f3 100644 --- a/edit_entry.php +++ b/edit_entry.php @@ -1016,7 +1016,8 @@ function time_selection($prefix, $time = '', $trigger = false) - + @@ -1026,7 +1027,8 @@ function time_selection($prefix, $time = '', $trigger = false) - + @@ -1037,7 +1039,8 @@ function time_selection($prefix, $time = '', $trigger = false) - + @@ -1052,8 +1055,10 @@ function time_selection($prefix, $time = '', $trigger = false) - - + + @@ -1067,9 +1072,7 @@ function time_selection($prefix, $time = '', $trigger = false) - - - @@ -1237,9 +1240,9 @@ function time_selection($prefix, $time = '', $trigger = false) . translate($byday_names[$rpt_byday_mod]) : ' ')); echo ' - '; + "; } echo ' '; @@ -1311,9 +1314,9 @@ function time_selection($prefix, $time = '', $trigger = false) ' : '') . ($loop_ctr == 31 ? ' ' : '') . ' - ' + " . ($loop_ctr % 10 == 0 ? ' ' : ''); @@ -1357,9 +1360,10 @@ function time_selection($prefix, $time = '', $trigger = false) . '' : '') . ($loop_ctr == 31 ? ' ' : '') . ' - ' + " . ($loop_ctr % 10 == 0 ? ' ' : ''); @@ -1420,12 +1424,15 @@ function time_selection($prefix, $time = '', $trigger = false) -
-
- +
+
+ @@ -1592,7 +1599,8 @@ function time_selection($prefix, $time = '', $trigger = false) ?>
- + 0 && ($login == $create_by || $single_user == 'Y' || $is_admin)) { ?>
diff --git a/edit_entry_handler.php b/edit_entry_handler.php index c2123fe1c..d0eae6339 100644 --- a/edit_entry_handler.php +++ b/edit_entry_handler.php @@ -1290,10 +1290,10 @@ function sort_byday( $a, $b ) { echo // Allow them to override a conflict if server settings allow it. ( ! empty( $ALLOW_CONFLICT_OVERRIDE ) && $ALLOW_CONFLICT_OVERRIDE == 'Y' ? ' - ' : '' ) . ' - + ' : '' ) . ' + '; } else diff --git a/edit_report.php b/edit_report.php index bf3ac87c6..c01e91d79 100644 --- a/edit_report.php +++ b/edit_report.php @@ -325,13 +325,15 @@ function print_options ( $textarea, $option ) { //} echo '
- ' - . ( $adding_report ? '' : ' - ' . translate('Cancel') . ' - ' ); + ' + . ( $adding_report ? '' : ' + ' + . translate ( 'Cancel' ) . ' + ' ); ?>
diff --git a/edit_template.php b/edit_template.php index b542642ec..eef7631ab 100644 --- a/edit_template.php +++ b/edit_template.php @@ -131,14 +131,13 @@ ' : '' ) . '
- - ' + + ' . ( ! empty ( $user ) ? ' - ' - : '' ) . ' + ' : '' ) . ' ' ) . "\n" . print_trailer ( false, true, true ); ?> diff --git a/export.php b/export.php index c4748f620..8d50698d2 100644 --- a/export.php +++ b/export.php @@ -106,8 +106,8 @@ - + '; diff --git a/groups.php b/groups.php index e7a96da86..a480fabfd 100644 --- a/groups.php +++ b/groups.php @@ -41,7 +41,8 @@ @@ -61,7 +62,9 @@
- +
@@ -111,8 +114,13 @@
@@ -142,8 +150,13 @@
diff --git a/help_bug.php b/help_bug.php index 65c45e9e5..79383c12d 100644 --- a/help_bug.php +++ b/help_bug.php @@ -18,7 +18,7 @@ . str_replace ('XXX', translate ( get_browser_language ( true ) ), translate ( 'Also, please use English rather than XXX.' ) ) : '' ) . '

- +

' . translate ( 'System Settings' ) . '

'; diff --git a/import.php b/import.php index 7e8703342..f05ad035e 100644 --- a/import.php +++ b/import.php @@ -173,7 +173,8 @@ function print_categories() { print_categories(); echo '
- + '; } echo print_trailer(); diff --git a/includes/dbi4php.php b/includes/dbi4php.php index 034fc1252..7e4412115 100644 --- a/includes/dbi4php.php +++ b/includes/dbi4php.php @@ -8,8 +8,6 @@ * should be defined somewhere to one of the following: * - ibase (Interbase) * - ibm_db2 - * - mssql - * - mysql * - mysqli * - odbc * - oracle (This uses the Oracle8 OCI API, so Oracle 8 libs are required) @@ -26,8 +24,8 @@ * normal arrays are used with xxx_fetch_row(). (Some db APIs don't support * xxx_fetch_array().) * - * @author Craig Knudsen - * @copyright Craig Knudsen, , http://k5n.us/webcalendar + * @author Craig Knudsen + * @copyright Craig Knudsen, , http://k5n.us/webcalendar * @license https://gnu.org/licenses/old-licenses/gpl-2.0.html GNU LGPL * @package WebCalendar * @@ -35,7 +33,7 @@ * See ChangeLog * * License: - * Copyright (C) 2006 Craig Knudsen + * Copyright (C) 2006-2023 Craig Knudsen * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, @@ -117,40 +115,6 @@ function dbi_connect( $host, $login, $password, $database, $lazy = true ) { $db_connection_info['connection'] = $GLOBALS['ibm_db2_connection'] = $c; return $c; - } elseif( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 ) { - static $old_textlimit, $old_textsize; - - $old_textlimit = ini_get( 'mssql.textlimit' ); - $old_textsize = ini_get( 'mssql.textsize' ); - ini_set( 'mssql.textlimit', '2147483647' ); - ini_set( 'mssql.textsize', '2147483647' ); - $c = ( $GLOBALS['db_persistent'] - ? mssql_pconnect( $host, $login, $password ) - : mssql_connect( $host, $login, $password ) ); - - if( $c ) { - if( ! mssql_select_db( $database ) ) - return false; - - $db_connection_info['connected'] = true; - $db_connection_info['connection'] = $c; - return $c; - } else - return false; - } elseif( strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 ) { - $c = ( $GLOBALS['db_persistent'] - ? mysql_pconnect( $host, $login, $password ) - : mysql_connect( $host, $login, $password ) ); - - if( $c ) { - if( ! mysql_select_db( $database ) ) - return false; - - $db_connection_info['connected'] = true; - $db_connection_info['connection'] = $c; - return $c; - } else - return false; } elseif (strcmp($GLOBALS['db_type'], 'mysqli') == 0) { // mysqli_report(MYSQLI_REPORT_ALL); $c = null; @@ -274,14 +238,6 @@ function dbi_close( $conn ) { return ibase_close( $conn ); elseif( strcmp( $GLOBALS['db_type'], 'ibm_db2' ) == 0 ) return db2_close( $GLOBALS['ibm_db2_connection'] ); - elseif( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 ) { - if( ! empty( $old_textlimit ) ) { - ini_set( 'mssql.textlimit', $old_textlimit ); - ini_set( 'mssql.textsize', $old_textsize ); - } - return mssql_close( $conn ); - } elseif( strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 ) - return mysql_close( $conn ); elseif( strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) return $conn->close(); elseif( strcmp( $GLOBALS['db_type'], 'odbc' ) == 0 ) @@ -378,12 +334,6 @@ function dbi_query( $sql, $fatalOnError = true, $showError = true ) { } elseif( strcmp( $GLOBALS['db_type'], 'ibm_db2' ) == 0 ) { $found_db_type = true; $res = db2_exec( $GLOBALS['ibm_db2_connection'], $sql ); - } elseif( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 ) { - $found_db_type = true; - $res = mssql_query( $sql ); - } elseif( strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 ) { - $found_db_type = true; - $res = mysql_query( $sql, $db_connection_info['connection'] ); } elseif( strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) { $found_db_type = true; try { @@ -446,10 +396,6 @@ function dbi_fetch_row( $res ) { return ibase_fetch_row( $res ); elseif( strcmp( $GLOBALS['db_type'], 'ibm_db2' ) == 0 ) return db2_fetch_array( $res ); - elseif( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 ) - return mssql_fetch_array( $res ); - elseif( strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 ) - return mysql_fetch_array( $res, MYSQL_NUM ); elseif( strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) return $res->fetch_array( MYSQLI_NUM ); elseif( strcmp( $GLOBALS['db_type'], 'odbc' ) == 0 ) @@ -487,10 +433,6 @@ function dbi_affected_rows( $conn, $res ) { return ibase_affected_rows( $conn ); elseif( strcmp( $GLOBALS['db_type'], 'ibm_db2' ) == 0 ) return db2_num_rows( $res ); - elseif( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 ) - return mssql_rows_affected ( $conn ); - elseif( strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 ) - return mysql_affected_rows( $conn ); elseif( strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) return $conn->affected_rows; elseif( strcmp( $GLOBALS['db_type'], 'odbc' ) == 0 ) @@ -523,9 +465,9 @@ function dbi_affected_rows( $conn, $res ) { * @return bool True on success */ function dbi_update_blob( $table, $column, $key, $data ) { - global $unavail_DBI_Update_blob, $db_connection_info; + global $db_connection_info; - $unavail_DBI_Update_blob = str_replace ( ['XXX', 'YYY'], + $notAvailable = str_replace ( ['XXX', 'YYY'], ['dbi_update_blob', $GLOBALS['db_type']], translate( 'Unfortunately, XXX is not implemented for YYY' ) ); @@ -536,19 +478,24 @@ function dbi_update_blob( $table, $column, $key, $data ) { $sql = 'UPDATE ' . $table . ' SET ' . $column; - if( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 ) - return dbi_execute( $sql . ' = 0x' . bin2hex( $data ) . ' WHERE ' . $key ); - elseif ( strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) { - return dbi_execute( $sql . ' = \'' - . ( function_exists( 'mysqli_real_escape_string' ) - ? $db_connection_info['connection']->real_escape_string( $data ) : addslashes( $data ) ) - . '\' WHERE ' . $key ); - } elseif ( strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 ) { - return dbi_execute( $sql . ' = \'' - . ( function_exists( 'mysql_real_escape_string' ) - ? mysql_real_escape_string( $data ) : addslashes( $data ) ) - . '\' WHERE ' . $key ); - } elseif( strcmp( $GLOBALS['db_type'], 'postgresql' ) == 0 ) + if (strcmp($GLOBALS['db_type'], 'mysqli') == 0) { + // Prepare the SQL statement + $stmt = $GLOBALS['db_connection']->prepare($sql . " = ? WHERE " . $key); + if ($stmt === false) { + dbi_fatal_error("Prepare failed: " . $GLOBALS['db_connection']->error); + } + // Bind the BLOB data parameter + $null = NULL; // This is required for binding BLOB data + $stmt->bind_param('b', $null); + $stmt->send_long_data(0, $data); + // Execute the statement + if (!$stmt->execute()) { + dbi_fatal_error("Execute failed: " . $stmt->error); + } + $stmt->close(); + return true; +} +elseif( strcmp( $GLOBALS['db_type'], 'postgresql' ) == 0 ) return dbi_execute( $sql . ' = \'' . pg_escape_bytea( $data ) . '\' WHERE ' . $key ); elseif( strcmp( $GLOBALS['db_type'], 'sqlite' ) == 0 ) @@ -566,7 +513,7 @@ function dbi_update_blob( $table, $column, $key, $data ) { return ( $ret == FALSE ? FALSE : TRUE ); } else // TODO! - die_miserable_death( $unavail_DBI_Update_blob ); + die_miserable_death( $notAvailable ); } /** @@ -579,7 +526,11 @@ function dbi_update_blob( $table, $column, $key, $data ) { * @return bool True on success */ function dbi_get_blob( $table, $column, $key ) { - global $unavail_DBI_Update_blob, $db_connection_info; + global $db_connection_info; + + $notAvailable = str_replace ( ['XXX', 'YYY'], + ['dbi_get_blob', $GLOBALS['db_type']], + translate( 'Unfortunately, XXX is not implemented for YYY' ) ); assert( ! empty( $table ) ); assert( ! empty( $column ) ); @@ -595,19 +546,18 @@ function dbi_get_blob( $table, $column, $key ) { $ret = ''; if( $row = dbi_fetch_row( $res ) ) { - if( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 - || strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 || - strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) { + if (strcmp( $GLOBALS['db_type'], 'mysqli')==0) $ret = $row[0]; - } elseif( strcmp( $GLOBALS['db_type'], 'postgresql' ) == 0 ) + elseif ( strcmp( $GLOBALS['db_type'], 'postgresql' ) == 0 ) $ret = pg_unescape_bytea ( $row[0] ); elseif( strcmp( $GLOBALS['db_type'], 'sqlite' ) == 0 ) $ret = sqlite_udf_decode_binary( $row[0] ); elseif( strcmp( $GLOBALS['db_type'], 'sqlite3' ) == 0 ) { $ret = $row[0]; - } else + } else { // TODO! - die_miserable_death( $unavail_DBI_Update_blob ); + die_miserable_death( $notAvailable ); + } } dbi_free_result( $res ); return $ret; @@ -629,10 +579,6 @@ function dbi_free_result( $res ) { return ibase_free_result( $res ); elseif( strcmp( $GLOBALS['db_type'], 'ibm_db2' ) == 0 ) return db2_free_result( $res ); - elseif( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 ) - return mssql_free_result( $res ); - elseif( strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 ) - return mysql_free_result( $res ); elseif( strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) return mysqli_free_result( $res ); elseif( strcmp( $GLOBALS['db_type'], 'odbc' ) == 0 ) @@ -669,12 +615,7 @@ function dbi_error() { if( $ret == '' ) $ret = db2_stmt_errormsg(); - } elseif( strcmp( $GLOBALS['db_type'], 'mssql' ) == 0 ) - // No real mssql_error function. This is as good as it gets. - $ret = mssql_get_last_message(); - elseif( strcmp( $GLOBALS['db_type'], 'mysql' ) == 0 ) - $ret = mysql_error(); - elseif (strcmp($GLOBALS['db_type'], 'mysqli') == 0) { + } elseif (strcmp($GLOBALS['db_type'], 'mysqli') == 0) { if (!empty($GLOBALS['db_connection_info']['last_error'])) { $ret = $GLOBALS['db_connection_info']['last_error']; } else { @@ -745,16 +686,8 @@ function dbi_escape_string( $string ) { $string = stripslashes( $string ); switch( $GLOBALS['db_type'] ) { case 'ibase': - case 'mssql': case 'oracle': return str_replace( "'", "''", $string ); - case 'mysql': - // MySQL requires an active connection. - return ( empty( $db_connection_info['connected'] ) - ? addslashes( $string ) - : ( version_compare( phpversion(), '4.3.0' ) >= 0 - ? mysql_real_escape_string( $string, $db_connection_info['connection'] ) - : mysql_escape_string( $string ) ) ); case 'mysqli': return ( empty( $db_connection_info['connected'] ) ? addslashes( $string ) diff --git a/includes/dbtable.php b/includes/dbtable.php index d81809fea..989ac510d 100644 --- a/includes/dbtable.php +++ b/includes/dbtable.php @@ -132,8 +132,8 @@ function dbtable_to_html ( $tablear, $valuesar, $action = '', $formname = '', return $ret . ( empty ( $actionlabel ) ? '' : ' - + ' ) . ' diff --git a/includes/js/dblclick_add.js b/includes/js/dblclick_add.js index 7c925ebfa..49af84807 100644 --- a/includes/js/dblclick_add.js +++ b/includes/js/dblclick_add.js @@ -1,8 +1,14 @@ - -// Function that will send user to the add event page. -// This is typically invoked as the ondblclick event handler. -function dblclick_add( date, name, hour, minute ) { +/** + * @description Send user to the add event page. Typically invoked as the ondblclick event handler. + * @author Craig Knudsen + * @date 2023-10-05 + * @param {int} date + * @param {string} name + * @param {int} hour + * @param {int} minute + */ +function dblclick_add ( date, name, hour, minute ) { window.location.href = 'edit_entry.php?date=' + date + '&defusers=' + name + ( hour ? '&hour=' + hour + '&minute=' - + ( typeof( minute ) != 'undefined' ? minute : 0 ) : '' ); + + ( typeof ( minute ) !== 'undefined' ? minute : 0 ) : '' ); } diff --git a/install/headless.php b/install/headless.php index cdcab219e..e5a848b59 100644 --- a/install/headless.php +++ b/install/headless.php @@ -7,19 +7,19 @@ * your settings; and requires settings.php to be present and complete. */ -if (php_sapi_name() !== 'cli'){ +if (php_sapi_name() !== 'cli') { echo 'This is a CLI script and should not be invoked via the web server'; exit; } -include_once __DIR__.'/../includes/translate.php'; -include_once __DIR__.'/../includes/dbi4php.php'; -include_once __DIR__.'/../includes/config.php'; -include_once __DIR__.'/default_config.php'; -include_once __DIR__.'/install_functions.php'; -include_once __DIR__.'/sql/upgrade_matrix.php'; +include_once __DIR__ . '/../includes/translate.php'; +include_once __DIR__ . '/../includes/dbi4php.php'; +include_once __DIR__ . '/../includes/config.php'; +include_once __DIR__ . '/default_config.php'; +include_once __DIR__ . '/install_functions.php'; +include_once __DIR__ . '/sql/upgrade_matrix.php'; -define( '__WC_BASEDIR', __DIR__.'/../' ); +define('__WC_BASEDIR', __DIR__ . '/../'); $fileDir = __WC_BASEDIR . 'includes'; $file = $fileDir . '/settings.php'; chdir(__WC_BASEDIR); @@ -29,98 +29,150 @@ // session functions *do* work. session_start(); - -// Load the settings.php file -$fd = @fopen( $file, 'rb', false ); -if( ! empty( $fd ) ) { - while( ! feof( $fd ) ) { - $buffer = trim( fgets( $fd, 4096 ) ); - - if( preg_match( '/^#|\/\*/', $buffer ) // comments - || preg_match( '/^<\?/', $buffer ) // start php code - || preg_match( '/^\?>/', $buffer ) // end php code - ) { - continue; - } - if( preg_match( '/(\S+):\s*(.*)/', $buffer, $matches ) ) - $settings[$matches[1]] = $matches[2]; - } - fclose( $fd ); -} +// Load the settings.php file or get settings from env vars. +do_config(true); // We'll grab database settings from settings.php. $db_database = $settings['db_database']; $db_host = $settings['db_host']; $db_login = $settings['db_login']; -$db_password = ( empty( $settings['db_password'] ) - ? '' : $settings['db_password'] ); +$db_password = (empty($settings['db_password']) + ? '' : $settings['db_password']); $db_persistent = false; $db_type = $settings['db_type']; -$real_db = ( $db_type== 'sqlite' || $db_type == 'sqlite3' - ? get_full_include_path( $db_database ) : $db_database ); +$real_db = ($db_type == 'sqlite' || $db_type == 'sqlite3' + ? get_full_include_path($db_database) : $db_database); + +// Can we connect? +$c = null; +$dbVersion = null; +$detectedDbVersion = 'Unknown'; +try { + $c = dbi_connect($db_host, $db_login, $db_password, $real_db, false); + $dbVersion = $detectedDbVersion = getDatabaseVersionFromSchema(); + $canConnectDb = true; +} catch (Exception $e) { + // Could not connect +} +$connectError = ''; +$canConnectDb = false; +if (!$canConnectDb) + $connectError = dbi_error(); +$emptyDatabase = $canConnectDb ? isEmptyDatabase() : true; +$reportedDbVersion = 'Unknown'; +$adminUserCount = 0; +$databaseExists = false; +$databaseCurrent = false; -$c = dbi_connect( $db_host, $db_login, $db_password, $real_db, false ); -// It's possible that the tables were created manually -// and we just want to do the database population routines. - get_installed_version(); -if( $c && ! empty( $_SESSION['install_file'] ) ) { - $sess_install = $_SESSION['install_file']; - $install_filename = ( $sess_install == 'tables' ? 'tables-' : 'upgrade-' ); - switch( $db_type ) { - case 'ibase': - case 'mssql': - case 'oracle': - $install_filename .= $db_type . '.sql'; - break; - case 'ibm_db2': - $install_filename .= 'db2.sql'; - break; - case 'odbc': - $install_filename .= $_SESSION['odbc_db'] . '.sql'; - break; - case 'postgresql': - $install_filename .= 'postgres.sql'; - break; - case 'sqlite': - include_once 'sql/tables-sqlite.php'; - populate_sqlite_db( $real_db, $c ); - $install_filename = ''; - break; - case 'sqlite3': - include_once 'sql/tables-sqlite3.php'; - populate_sqlite_db( $real_db, $c ); - $install_filename = ''; - break; - default: - $install_filename .= 'mysql.sql'; +if ($c && !empty($_SESSION['install_file'])) { + $install_filename = (str_starts_with($dbVersion, "v")) ? "upgrade-" : "tables-"; + switch ($db_type) { + case 'ibase': + case 'mssql': + case 'oracle': + $install_filename .= $db_type . '.sql'; + break; + case 'ibm_db2': + $install_filename .= 'db2.sql'; + break; + case 'odbc': + $install_filename .= $_SESSION['odbc_db'] . '.sql'; + break; + case 'postgresql': + $install_filename .= 'postgres.sql'; + break; + case 'sqlite3': + include_once 'sql/tables-sqlite3.php'; + populate_sqlite_db($real_db, $c); + $install_filename = ''; + break; + default: + $install_filename .= 'mysql.sql'; } executeSqlFromFile($install_filename); } // Convert passwords to secure hashes if needed. -$res = dbi_execute( 'SELECT cal_login, cal_passwd FROM webcal_user', -[], false, $show_all_errors ); -if( $res ) { -while( $row = dbi_fetch_row( $res ) ) { - if( strlen( $row[1] ) < 30 ) - dbi_execute( 'UPDATE webcal_user SET cal_passwd = ? - WHERE cal_login = ?', [password_hash ( $row[1], PASSWORD_DEFAULT ), $row[0]] ); -} -dbi_free_result( $res ); +// TODO: Move this into a function we specify in upgrade-sql.php. +echo "Checking passwords...\n"; +$res = dbi_execute( + 'SELECT cal_login, cal_passwd FROM webcal_user', + [], + false, + $show_all_errors +); +if ($res) { + while ($row = dbi_fetch_row($res)) { + if (strlen($row[1]) < 30) + dbi_execute('UPDATE webcal_user SET cal_passwd = ? + WHERE cal_login = ?', [password_hash($row[1], PASSWORD_DEFAULT), $row[0]]); + } + dbi_free_result($res); } // If new install, run 0 GMT offset // just to set webcal_config.WEBCAL_TZ_CONVERSION. -if( $_SESSION['old_program_version'] == 'new_install' ) -convert_server_to_GMT(); +// Commenting out since this was 15+ years ago +// convert_server_to_GMT(); -// For upgrade to v1.1b -// we need to convert existing categories and repeating events. -do_v11b_updates(); +require_once "sql/upgrade-sql.php"; -// v1.1e requires converting webcal_site_extras to webcal_reminders. -do_v11e_updates(); +$error = ''; -// Update the version info. -get_installed_version( true ); +//$detectedDbVersion = 'v1.9.0'; +//echo "Install file: " . $install_filename . "
"; +echo "Detected database schema version: $detectedDbVersion\n"; +try { + $success = true; + if (empty($error)) { + if ($emptyDb) { + echo "Empty database -> creating all tables\n"; + executeSqlFromFile($install_filename); + } else { + if (empty($detectedDbVersion) || $detectedDbVersion == 'Unknown') { + $error = translate('Unable to determine current database version.'); + } else { + // Get a list of SQL commands and possibly PHP function names. + // For any specific version, the function name should appear in this list after + // the SQL commands allowing the upgrade function to use any new db changes. + $sqlLines = getSqlUpdates($detectedDbVersion, $_SETTINGS['db_type'], true); + //print_r($sqlLines); exit; + foreach ($sqlLines as $sql) { + if (str_starts_with($sql, "function:")) { + // Need to run a PHP function + list(, $functionName) = explode(':', $sql); + if (function_exists($functionName)) { + echo "Executing function \"$functionName\"\n"; + $functionName(); + } else { + // Handle the error if function does not exist + $error = "Function $functionName does not exist."; + } + } else { + echo "Executing SQL: $sql \n"; + $ret = dbi_execute($sql, [], false, true); + if (!$ret) { + $success = false; + $error = dbi_error(); + } + } + } + } + } + } +} catch (Exception $e) { + $error = $e->getMessage(); +} +if (empty($error)) { + updateVersionInDatabase(); + $msg = translate('Database successfully migrated from XXX to YYY'); + $msg = str_replace('XXX', $detectedDbVersion, $msg); + $msg = str_replace('YYY', $PROGRAM_VERSION, $msg); + echo $msg . "\n"; +} +if (empty($error)) { + echo "Success.\n"; +} else { + echo "Error: " . $error . "\n"; +} diff --git a/install/index.php b/install/index.php index 569ea71b2..b9edf2584 100644 --- a/install/index.php +++ b/install/index.php @@ -68,45 +68,6 @@ function tryDbConnect() return !empty($c); } -function isEmptyDatabase() -{ - global $debugInstaller; - try { - // If we have 1 or more users in webcal_user, the db is not empty - $res = dbi_execute('SELECT COUNT(*) FROM webcal_config', [], false, false); - if ($res) { - $row = dbi_fetch_row($res); - dbi_free_result($res); - return $row[0] == 0; - } - } catch (Exception $e) { - if ($debugInstaller) { - echo "Error: " . $e->getMessage() . "
"; - } - // Error connecting to db - } - return true; -} - -function getDbVersion() -{ - $dbVersion = 'Unknown'; - $sql = 'SELECT cal_value FROM webcal_config WHERE cal_setting = ?'; - $res = dbi_execute( - $sql, - ['WEBCAL_PROGRAM_VERSION'], - false, - false - ); - if ($res) { - $row = dbi_fetch_row($res); - if ($row) { - $dbVersion = $row[0]; - } - } - return $dbVersion; -} - function getAdminUserCount() { $count = 0; diff --git a/install/install_dbtables_handler.php b/install/install_dbtables_handler.php index d440b676e..03d5d767e 100644 --- a/install/install_dbtables_handler.php +++ b/install/install_dbtables_handler.php @@ -79,6 +79,7 @@ $error = $e->getMessage(); } if (empty($error)) { + updateVersionInDatabase (); $msg = translate('Database successfully migrated from XXX to YYY'); $msg = str_replace('XXX', $detectedDbVersion, $msg); $msg = str_replace('YYY', $PROGRAM_VERSION, $msg); diff --git a/install/install_functions.php b/install/install_functions.php index 1366fedfb..04334c20b 100644 --- a/install/install_functions.php +++ b/install/install_functions.php @@ -1,213 +1,277 @@ $msg\n", // 3, "d:\php\logs\debug.txt" ); } + +function isEmptyDatabase() +{ + global $debugInstaller; + try { + // If we have 1 or more users in webcal_user, the db is not empty + $res = dbi_execute('SELECT COUNT(*) FROM webcal_config', [], false, false); + if ($res) { + $row = dbi_fetch_row($res); + dbi_free_result($res); + return $row[0] == 0; + } + } catch (Exception $e) { + if ($debugInstaller) { + echo "Error: " . $e->getMessage() . "
"; + } + // Error connecting to db + } + return true; +} + +function getDbVersion() +{ + $dbVersion = 'Unknown'; + $sql = 'SELECT cal_value FROM webcal_config WHERE cal_setting = ?'; + $res = dbi_execute( + $sql, + ['WEBCAL_PROGRAM_VERSION'], + false, + false + ); + if ($res) { + $row = dbi_fetch_row($res); + if ($row) { + $dbVersion = $row[0]; + } + } + return $dbVersion; +} + /** * Change string to uppercase */ -function make_uppercase() { - // Make sure all cal_settings are UPPERCASE. - if ( ! dbi_execute ( 'UPDATE webcal_config - SET cal_setting = UPPER( cal_setting )' ) ) - echo str_replace ( ['XXX', 'YYY'], +function make_uppercase() +{ + // Make sure all cal_setting are UPPERCASE. + if (!dbi_execute('UPDATE webcal_config + SET cal_setting = UPPER( cal_setting )')) + echo str_replace( + ['XXX', 'YYY'], ['webcal_config', dbi_error()], - translate ( 'Error updating table XXX' ) ); + translate('Error updating table XXX') + ); - if ( ! dbi_execute ( 'UPDATE webcal_user_pref - SET cal_setting = UPPER( cal_setting )' ) ) - echo str_replace ( ['XXX', 'YYY'], + if (!dbi_execute('UPDATE webcal_user_pref + SET cal_setting = UPPER( cal_setting )')) + echo str_replace( + ['XXX', 'YYY'], ['webcal_user_pref', dbi_error()], - translate ( 'Error updating table XXX' ) ); + translate('Error updating table XXX') + ); } /** * db_load_admin (needs description) */ -function db_load_admin() { - $res = dbi_execute ( 'SELECT cal_login FROM webcal_user - WHERE cal_login = "admin"', [], false, false ); +function db_load_admin() +{ + $res = dbi_execute('SELECT cal_login FROM webcal_user + WHERE cal_login = "admin"', [], false, false); $sql = 'INSERT INTO webcal_user ( cal_login, cal_passwd, cal_lastname, cal_firstname, cal_is_admin ) VALUES ( \'admin\', \'21232f297a57a5a743894a0e4a801fc3\', \'ADMINISTRATOR\', \'DEFAULT\', \'Y\' )'; // Preload access_function premissions. $sql2 = 'INSERT INTO webcal_access_function ( cal_login, cal_permissions ) VALUES ( \'admin\', \'YYYYYYYYYYYYYYYYYYYYYYYYYYY\' )'; - if ( ! $res ) { - dbi_execute ( $sql ); - dbi_execute ( $sql2 ); + if (!$res) { + dbi_execute($sql); + dbi_execute($sql2); } else { // Sqlite returns $res always. - $row = dbi_fetch_row ( $res ); - if ( ! isset ( $row[0] ) ) { - dbi_execute ( $sql ); - dbi_execute ( $sql2 ); + $row = dbi_fetch_row($res); + if (!isset($row[0])) { + dbi_execute($sql); + dbi_execute($sql2); } - dbi_free_result ( $res ); + dbi_free_result($res); } } + /** - * db_check_admin (needs description) + * Update the version of WebCalendar in the database, which is stored in the + * webcal_config table. */ -function db_check_admin() { - $res = dbi_execute ( 'SELECT COUNT( cal_login ) FROM webcal_user - WHERE cal_is_admin = "Y"', [], false, false ); - if ( $res ) { - $row = dbi_fetch_row ( $res ); - dbi_free_result ( $res ); - return ( $row[0] > 0 ); - } - return false; +function updateVersionInDatabase() +{ + global $PROGRAM_VERSION; + dbi_execute( + 'UPDATE webcal_config SET cal_value = ? WHERE cal_setting = ?', + ['WEBCAL_PROGRAM_VERSION', $PROGRAM_VERSION] + ); } + /** * do_v11b_updates (needs description) */ -function do_v11b_updates() { - $res = dbi_execute ( 'SELECT weu.cal_id, cal_category, cat_owner +function do_v11b_updates() +{ + $res = dbi_execute('SELECT weu.cal_id, cal_category, cat_owner FROM webcal_entry_user weu, webcal_categories wc - WHERE weu.cal_category = wc.cat_id' ); - if ( $res ) { - while ( $row = dbi_fetch_row ( $res ) ) { - dbi_execute ( 'INSERT INTO webcal_entry_categories ( cal_id, cat_id,' - . ( empty ( $row[2] ) ? 'cat_order' : 'cat_owner' ) - . ' ) VALUES ( ?, ?, ? )', [$row[0], $row[1], - ( empty ( $row[2] ) ? 99 : $row[2] )] ); + WHERE weu.cal_category = wc.cat_id'); + if ($res) { + while ($row = dbi_fetch_row($res)) { + dbi_execute('INSERT INTO webcal_entry_categories ( cal_id, cat_id,' + . (empty($row[2]) ? 'cat_order' : 'cat_owner') + . ' ) VALUES ( ?, ?, ? )', [ + $row[0], $row[1], + (empty($row[2]) ? 99 : $row[2]) + ]); } - dbi_free_result ( $res ); + dbi_free_result($res); } // Update LANGUAGE settings from Browser-Defined to none. - dbi_execute ( 'UPDATE webcal_config SET cal_value = \'none\' - WHERE cal_setting = \'LANGUAGE\' AND cal_value = \'Browser-defined\'' ); + dbi_execute('UPDATE webcal_config SET cal_value = \'none\' + WHERE cal_setting = \'LANGUAGE\' AND cal_value = \'Browser-defined\''); - dbi_execute ( 'UPDATE webcal_user_pref SET cal_value = \'none\' - WHERE cal_setting = \'LANGUAGE\' AND cal_value = \'Browser-defined\'' ); + dbi_execute('UPDATE webcal_user_pref SET cal_value = \'none\' + WHERE cal_setting = \'LANGUAGE\' AND cal_value = \'Browser-defined\''); // Clear old category values. - dbi_execute ( 'UPDATE webcal_entry_user SET cal_category = NULL' ); + dbi_execute('UPDATE webcal_entry_user SET cal_category = NULL'); // Mark existing exclusions as new exclusion type. - dbi_execute ( 'UPDATE webcal_entry_repeats_not SET cal_exdate = 1' ); + dbi_execute('UPDATE webcal_entry_repeats_not SET cal_exdate = 1'); // Change cal_days format to cal_cal_byday format. // Deprecate monthlyByDayR to simply monthlyByDay. - dbi_execute ( 'UPDATE webcal_entry_repeats SET cal_type = \'monthlyByDay\' - WHERE cal_type = \'monthlyByDayR\'' ); - $res = dbi_execute ( 'SELECT cal_id, cal_days FROM webcal_entry_repeats ' ); - if ( $res ) { - while ( $row = dbi_fetch_row ( $res ) ) { - if ( ! empty ( $row[1] ) && $row[1] != 'yyyyyyy' && $row[1] != 'nnnnnnn' ) { + dbi_execute('UPDATE webcal_entry_repeats SET cal_type = \'monthlyByDay\' + WHERE cal_type = \'monthlyByDayR\''); + $res = dbi_execute('SELECT cal_id, cal_days FROM webcal_entry_repeats '); + if ($res) { + while ($row = dbi_fetch_row($res)) { + if (!empty($row[1]) && $row[1] != 'yyyyyyy' && $row[1] != 'nnnnnnn') { $byday = []; - if ( substr ( $row[1], 0, 1 ) == 'y' ) + if (substr($row[1], 0, 1) == 'y') $byday[] = 'SU'; - if ( substr ( $row[1], 1, 1 ) == 'y' ) + if (substr($row[1], 1, 1) == 'y') $byday[] = 'MO'; - if ( substr ( $row[1], 2, 1 ) == 'y' ) + if (substr($row[1], 2, 1) == 'y') $byday[] = 'TU'; - if ( substr ( $row[1], 3, 1 ) == 'y' ) + if (substr($row[1], 3, 1) == 'y') $byday[] = 'WE'; - if ( substr ( $row[1], 4, 1 ) == 'y' ) + if (substr($row[1], 4, 1) == 'y') $byday[] = 'TH'; - if ( substr ( $row[1], 5, 1 ) == 'y' ) + if (substr($row[1], 5, 1) == 'y') $byday[] = 'FR'; - if ( substr ( $row[1], 6, 1 ) == 'y' ) + if (substr($row[1], 6, 1) == 'y') $byday[] = 'SA'; - $bydays = implode ( ',', $byday ); - dbi_execute ( 'UPDATE webcal_entry_repeats SET cal_byday = ? - WHERE cal_id = ?', [$bydays, $row[0]] ); + $bydays = implode(',', $byday); + dbi_execute('UPDATE webcal_entry_repeats SET cal_byday = ? + WHERE cal_id = ?', [$bydays, $row[0]]); } } - dbi_free_result ( $res ); + dbi_free_result($res); } // Repeat end dates are now exclusive so we need to add 1 day to each. - $res = dbi_execute ( 'SELECT cal_end, cal_id FROM webcal_entry_repeats' ); - if ( $res ) { - while ( $row = dbi_fetch_row ( $res ) ) { - if ( ! empty ( $row[0] ) ) { - $dY = substr ( $row[0], 0, 4 ); - $dm = substr ( $row[0], 4, 2 ); - $dd = substr ( $row[0], 6, 2 ); - $new_date = date ( 'Ymd', gmmktime ( 0, 0, 0, $dm, $dd, $dY ) + 86400 ); - dbi_execute ( 'UPDATE webcal_entry_repeats SET cal_end = ? - WHERE cal_id = ?', [$new_date, $row[1]] ); + $res = dbi_execute('SELECT cal_end, cal_id FROM webcal_entry_repeats'); + if ($res) { + while ($row = dbi_fetch_row($res)) { + if (!empty($row[0])) { + $dY = substr($row[0], 0, 4); + $dm = substr($row[0], 4, 2); + $dd = substr($row[0], 6, 2); + $new_date = date('Ymd', gmmktime(0, 0, 0, $dm, $dd, $dY) + 86400); + dbi_execute('UPDATE webcal_entry_repeats SET cal_end = ? + WHERE cal_id = ?', [$new_date, $row[1]]); } } - dbi_free_result ( $res ); + dbi_free_result($res); } - // Update Priority to new values - //Old High=3, Low = 1....New Highest =1 Lowest =9 - //We will leave 3 alone and change 1,2 to 7,5 - dbi_execute ( 'UPDATE webcal_entry SET cal_priority = 7 - WHERE cal_priority = 1' ); - dbi_execute ( 'UPDATE webcal_entry SET cal_priority = 5 - WHERE cal_priority = 2' ); + // Update Priority to new values + //Old High=3, Low = 1....New Highest =1 Lowest =9 + //We will leave 3 alone and change 1,2 to 7,5 + dbi_execute('UPDATE webcal_entry SET cal_priority = 7 + WHERE cal_priority = 1'); + dbi_execute('UPDATE webcal_entry SET cal_priority = 5 + WHERE cal_priority = 2'); } /** * Convert site_extra reminders to webcal_reminders. */ -function do_v11e_updates() { +function do_v11e_updates() +{ $reminder_log_exists = false; - $res = dbi_execute ( 'SELECT cal_id, cal_data - FROM webcal_site_extras WHERE cal_type = \'7\'' ); + $res = dbi_execute('SELECT cal_id, cal_data + FROM webcal_site_extras WHERE cal_type = \'7\''); $done = []; - if ( $res ) { - while ( $row = dbi_fetch_row ( $res ) ) { - if ( ! empty ( $done[$row[0]] ) ) + if ($res) { + while ($row = dbi_fetch_row($res)) { + if (!empty($done[$row[0]])) // Already did this one; // must have had two site extras for reminder ignore the 2nd one. continue; $date = $last_sent = $offset = $times_sent = 0; - if ( strlen ( $row[1] ) == 8 ) // cal_data is probably a date. - $date = mktime ( 0, 0, 0, substr ( $row[1], 4, 2 ), - substr ( $row[1], 6, 2 ), substr ( $row[1], 0, 4 ) ); + if (strlen($row[1]) == 8) // cal_data is probably a date. + $date = mktime( + 0, + 0, + 0, + substr($row[1], 4, 2), + substr($row[1], 6, 2), + substr($row[1], 0, 4) + ); else $offset = $row[1]; - $res2 = dbi_execute ( 'SELECT cal_last_sent + $res2 = dbi_execute( + 'SELECT cal_last_sent FROM webcal_reminder_log WHERE cal_id = ? AND cal_last_sent > 0', - [$row[0]] ); - if ( $res2 ) { + [$row[0]] + ); + if ($res2) { $reminder_log_exists = true; - $row2 = dbi_fetch_row ( $res2 ); + $row2 = dbi_fetch_row($res2); $times_sent = 1; - $last_sent = ( ! empty ( $row2[0] ) ? $row2[0] : 0 ); - dbi_free_result ( $res2 ); + $last_sent = (!empty($row2[0]) ? $row2[0] : 0); + dbi_free_result($res2); } - dbi_execute ( 'INSERT INTO webcal_reminders ( cal_id, cal_date, + dbi_execute( + 'INSERT INTO webcal_reminders ( cal_id, cal_date, cal_offset, cal_last_sent, cal_times_sent ) VALUES ( ?, ?, ?, ?, ? )', - [$row[0], $date, $offset, $last_sent, $times_sent] ); + [$row[0], $date, $offset, $last_sent, $times_sent] + ); $done[$row[0]] = true; } - dbi_free_result ( $res ); + dbi_free_result($res); // Remove reminders from site_extras. - dbi_execute ( 'DELETE FROM webcal_site_extras - WHERE webcal_site_extras.cal_type = \'7\'' ); + dbi_execute('DELETE FROM webcal_site_extras + WHERE webcal_site_extras.cal_type = \'7\''); // Remove entries from webcal_reminder_log. - if ( $reminder_log_exists == true ) { - dbi_execute ( 'DELETE FROM webcal_reminder_log', [], false, false ); - dbi_execute ( 'DROP TABLE webcal_reminder_log', [], false, false ); + if ($reminder_log_exists == true) { + dbi_execute('DELETE FROM webcal_reminder_log', [], false, false); + dbi_execute('DROP TABLE webcal_reminder_log', [], false, false); } } } /** - * Migrate category icons from the file system into the webcal_categories table as - * part of the updates for v1.9.11. Storing everything in the database will eventually - * allow multiple instances of WebCalendar to run against the same database and make - * database backups a complete site backup. - */ -function do_v1_9_11_updates() { + * Migrate category icons from the file system into the webcal_categories table as + * part of the updates for v1.9.11. Storing everything in the database will eventually + * allow multiple instances of WebCalendar to run against the same database and make + * database backups a complete site backup. + */ +function do_v1_9_11_updates() +{ $icon_path = __DIR__ . "/../wc-icons/"; // Get all icon files from the wc-icons directory $iconFiles = glob($icon_path . 'cat-*.gif'); @@ -275,7 +339,8 @@ function do_v1_9_11_updates() { * @return string|bool Returns 'ON' or 'OFF' for boolean settings. If $string is specified, it returns the string * if found within the directive's value, otherwise false. */ -function get_php_setting($val, $string = false) { +function get_php_setting($val, $string = false) +{ $setting = ini_get($val); return ($string == false ? ($setting == '1' || $setting == 'ON' ? 'ON' : 'OFF') @@ -285,22 +350,24 @@ function get_php_setting($val, $string = false) { /** * get_php_modules (needs description) */ -function get_php_modules ( $val ) { - return ( function_exists ( $val ) ? 'ON' : 'OFF' ); +function get_php_modules($val) +{ + return (function_exists($val) ? 'ON' : 'OFF'); } /** * We will generate many errors while trying to test database. * Disable them temporarily as needed. */ -function show_errors ( $error_val = 0 ) { +function show_errors($error_val = 0) +{ global $show_all_errors; - if ( empty ( $_SESSION['error_reporting'] ) ) - $_SESSION['error_reporting'] = get_php_setting ( 'error_reporting' ); + if (empty($_SESSION['error_reporting'])) + $_SESSION['error_reporting'] = get_php_setting('error_reporting'); - ini_set ( 'error_reporting', ( $show_all_errors == true - ? 64 : ( $error_val ? $_SESSION['error_reporting'] : 64 ) ) ); + ini_set('error_reporting', ($show_all_errors == true + ? 64 : ($error_val ? $_SESSION['error_reporting'] : 64))); } /** @@ -309,89 +376,104 @@ function show_errors ( $error_val = 0 ) { * adjust all existing events by that amount. If cutoffdate is supplied, * only dates prior to that date are affected. */ -function convert_server_to_GMT ( $offset = 0, $cutoffdate = '' ) { +function convert_server_to_GMT($offset = 0, $cutoffdate = '') +{ // Default value. - $error = translate ( 'Conversion Successful' ); + $error = translate('Conversion Successful'); // Don't allow $offsets over 24. - if ( abs ( $offset ) > 24 ) + if (abs($offset) > 24) $offset = 0; // Do webcal_entry update. - $res = dbi_execute ( 'SELECT cal_date, cal_time, cal_id, cal_duration - FROM webcal_entry' ); - if ( $res ) { - while ( $row = dbi_fetch_row ( $res ) ) { + $res = dbi_execute('SELECT cal_date, cal_time, cal_id, cal_duration + FROM webcal_entry'); + if ($res) { + while ($row = dbi_fetch_row($res)) { $cal_date = $row[0]; - $cal_time = sprintf ( "%06d", $row[1] ); + $cal_time = sprintf("%06d", $row[1]); $cal_id = $row[2]; $cal_duration = $row[3]; // Skip Untimed or All Day events. - if ( ( $cal_time == -1 ) || ( $cal_time == 0 && $cal_duration == 1440 ) ) + if (($cal_time == -1) || ($cal_time == 0 && $cal_duration == 1440)) continue; else { - $sy = substr ( $cal_date, 0, 4 ); - $sm = substr ( $cal_date, 4, 2 ); - $sd = substr ( $cal_date, 6, 2 ); - $sh = substr ( $cal_time, 0, 2 ); - $si = substr ( $cal_time, 2, 2 ); - $ss = substr ( $cal_time, 4, 2 ); - - $new_datetime = ( empty ( $offset ) - ? mktime ( $sh, $si, $ss, $sm, $sd, $sy ) - : gmmktime ( $sh + $offset, $si, $ss, $sm, $sd, $sy ) ); - - $new_cal_date = gmdate ( 'Ymd', $new_datetime ); - $new_cal_time = gmdate ( 'His', $new_datetime ); - $cutoff = ( ! empty ( $cutoffdate ) ? ' AND cal_date <= ?' : '' ); + $sy = substr($cal_date, 0, 4); + $sm = substr($cal_date, 4, 2); + $sd = substr($cal_date, 6, 2); + $sh = substr($cal_time, 0, 2); + $si = substr($cal_time, 2, 2); + $ss = substr($cal_time, 4, 2); + + $new_datetime = (empty($offset) + ? mktime($sh, $si, $ss, $sm, $sd, $sy) + : gmmktime($sh + $offset, $si, $ss, $sm, $sd, $sy)); + + $new_cal_date = gmdate('Ymd', $new_datetime); + $new_cal_time = gmdate('His', $new_datetime); + $cutoff = (!empty($cutoffdate) ? ' AND cal_date <= ?' : ''); // Now update row with new data. - if ( ! dbi_execute ( 'UPDATE webcal_entry SET cal_date = ?, cal_time = ? + if (!dbi_execute( + 'UPDATE webcal_entry SET cal_date = ?, cal_time = ? WHERE cal_id = ?' . $cutoff, - [$new_cal_date, $new_cal_time, $cal_id, $cutoffdate] ) ) - return str_replace ( ['XXX', 'YYY'], + [$new_cal_date, $new_cal_time, $cal_id, $cutoffdate] + )) + return str_replace( + ['XXX', 'YYY'], ['webcal_entry', dbi_error()], - translate ( 'Error updating table XXX' ) ); + translate('Error updating table XXX') + ); } } - dbi_free_result ( $res ); + dbi_free_result($res); } // Do webcal_entry_logs update. - $res = dbi_execute ( 'SELECT cal_date, cal_time, cal_log_id - FROM webcal_entry_log' ); - if ( $res ) { - while ( $row = dbi_fetch_row ( $res ) ) { + $res = dbi_execute('SELECT cal_date, cal_time, cal_log_id + FROM webcal_entry_log'); + if ($res) { + while ($row = dbi_fetch_row($res)) { $cal_date = $row[0]; - $cal_time = sprintf ( "%06d", $row[1] ); + $cal_time = sprintf("%06d", $row[1]); $cal_log_id = $row[2]; - $sy = substr ( $cal_date, 0, 4 ); - $sm = substr ( $cal_date, 4, 2 ); - $sd = substr ( $cal_date, 6, 2 ); - $sh = substr ( $cal_time, 0, 2 ); - $si = substr ( $cal_time, 2, 2 ); - $ss = substr ( $cal_time, 4, 2 ); - $new_datetime = mktime ( $sh, $si, $ss, $sm, $sd, $sy ); - $new_cal_date = gmdate ( 'Ymd', $new_datetime ); - $new_cal_time = gmdate ( 'His', $new_datetime ); + $sy = substr($cal_date, 0, 4); + $sm = substr($cal_date, 4, 2); + $sd = substr($cal_date, 6, 2); + $sh = substr($cal_time, 0, 2); + $si = substr($cal_time, 2, 2); + $ss = substr($cal_time, 4, 2); + $new_datetime = mktime($sh, $si, $ss, $sm, $sd, $sy); + $new_cal_date = gmdate('Ymd', $new_datetime); + $new_cal_time = gmdate('His', $new_datetime); // Now update row with new data - if ( ! dbi_execute ( 'UPDATE webcal_entry_log + if (!dbi_execute( + 'UPDATE webcal_entry_log SET cal_date = ?, cal_time = ? WHERE cal_log_id = ?', - [$new_cal_date, $new_cal_time, $cal_log_id] ) ) - return str_replace ( ['XXX', 'YYY'], + [$new_cal_date, $new_cal_time, $cal_log_id] + )) + return str_replace( + ['XXX', 'YYY'], ['webcal_entry_log', dbi_error()], - translate ( 'Error updating table XXX' ) ); + translate('Error updating table XXX') + ); } - dbi_free_result ( $res ); + dbi_free_result($res); } // Update Conversion Flag in webcal_config. // Delete any existing entry. - if ( ! dbi_execute ( 'DELETE FROM webcal_config - WHERE cal_setting = \'WEBCAL_TZ_CONVERSION\'' ) ) - return str_replace( 'XXX', dbi_error(), - translate ( 'Database error XXX.' ) ); + if (!dbi_execute('DELETE FROM webcal_config + WHERE cal_setting = \'WEBCAL_TZ_CONVERSION\'')) + return str_replace( + 'XXX', + dbi_error(), + translate('Database error XXX.') + ); - if ( ! dbi_execute ( 'INSERT INTO webcal_config ( cal_setting, cal_value ) - VALUES ( \'WEBCAL_TZ_CONVERSION\', \'Y\' )' ) ) - return str_replace( 'XXX', dbi_error(), - translate ( 'Database error XXX.' ) ); + if (!dbi_execute('INSERT INTO webcal_config ( cal_setting, cal_value ) + VALUES ( \'WEBCAL_TZ_CONVERSION\', \'Y\' )')) + return str_replace( + 'XXX', + dbi_error(), + translate('Database error XXX.') + ); return $error; } @@ -496,24 +578,6 @@ function getDatabaseVersionFromSchema($silent = true) return $dbVersion; } -/** - * parse_sql (needs description) - */ -function parse_sql ( $sql ) { - $sql = trim ( $sql ); - $sql = trim ( $sql, "\r\n " ); - $ret = []; - - $buffer_str = ''; - for( $i = 0; $i < strlen ( $sql ); $i++ ) { - $buffer_str .= substr ( $sql, $i, 1 ); - if ( substr ( $sql, $i, 1 ) == ';' ) { - $ret[] = $buffer_str; - $buffer_str = ''; - } - } - return ( $ret ); -} /** * Extracts SQL statements from a specified file. * @@ -527,10 +591,11 @@ function parse_sql ( $sql ) { * * @return array An array of SQL statements. */ -function extractSqlCommandsFromFile($filename) { +function extractSqlCommandsFromFile($filename) +{ // Check if file exists if (!file_exists($filename)) { - throw new Exception("File not found: $filename"); + throw new Exception("File not found: $filename"); } // Read the file contents @@ -544,29 +609,31 @@ function extractSqlCommandsFromFile($filename) { } /** -* Executes SQL statements from a specified file. -* -* This function reads the content of the provided SQL file using -* extractSqlCommandsFromFile() and then executes each SQL statement. -* -* @param string $filename The path to the SQL file. -* -* @throws Exception If there are issues executing the SQL or if the file is not found. -* -* @return void -*/ -function executeSqlFromFile($filename) { + * Executes SQL statements from a specified file. + * + * This function reads the content of the provided SQL file using + * extractSqlCommandsFromFile() and then executes each SQL statement. + * + * @param string $filename The path to the SQL file. + * + * @throws Exception If there are issues executing the SQL or if the file is not found. + * + * @return void + */ +function executeSqlFromFile($filename) +{ $sqlStatements = extractSqlCommandsFromFile($filename); foreach ($sqlStatements as $statement) { - if (!empty($statement)) { - // Assuming dbi_execute() is a function that takes a SQL statement and executes it - dbi_execute($statement); - } + if (!empty($statement)) { + // Assuming dbi_execute() is a function that takes a SQL statement and executes it + dbi_execute($statement); + } } } -function getSqlFile($dbType, $isUpgrade=false) { +function getSqlFile($dbType, $isUpgrade = false) +{ $file_base = __DIR__ . '/sql/' . ($isUpgrade ? 'upgrade' : 'tables'); $install_filename = $file_base . '-'; switch ($dbType) { @@ -597,60 +664,16 @@ function getSqlFile($dbType, $isUpgrade=false) { return $install_filename; } -/** - * Extracts SQL commands for upgrading from the specified version to the latest version. - * - * @param string $filename The path to the SQL file containing upgrade commands. - * @param string $version The starting version for the upgrade. - * - * @throws Exception If the specified file is not found. - * - * @return array An array of SQL statements for the upgrade. - */ -function extractUpgradeSqlCommands($filename, $version) { - if (!file_exists($filename)) { - throw new Exception("File not found: $filename"); - } - $content = file_get_contents($filename); - // Split content into chunks based on the upgrade version comments - //preg_match_all('/\/\*upgrade_(v[\d\.]+)\*\/(.*?)(?=\/\*upgrade_|$)/sm', $content, $matches, PREG_SET_ORDER); - preg_match_all('/\/\*upgrade_(v[\d\.]+)\*\/(.*?)(?=\/\*upgrade_|$)/sm', $content, $matches, PREG_SET_ORDER); - - - $commands = []; - $record = false; - echo "
"; print_r($matches); echo "
"; - foreach ($matches as $match) { - echo "match: \"$match[1]\"
"; - if ($match[1] === $version) { - $record = true; // Start recording commands from the provided version - } - if ($record) { - echo "MATCH: " . $match[2] . "
"; - echo "NEXT: " . $match[3] . "
"; - $sqls = array_map('trim', explode(';', $match[2])); - foreach ($sqls as $sql) { - if (!empty($sql)) { - $commands[] = $sql; - } - } - } - } - - return $commands; -} - -function removeWhitespaceOnlyLines($inputStr) { +function removeWhitespaceOnlyLines($inputStr) +{ // Split the string by newlines $lines = explode("\n", $inputStr); - + // Filter out lines that only contain whitespace - $filteredLines = array_filter($lines, function($line) { - return trim($line) !== ''; + $filteredLines = array_filter($lines, function ($line) { + return trim($line) !== ''; }); - + // Join the lines back together return implode("\n", $filteredLines); } - -?> diff --git a/layers.php b/layers.php index 38104c469..b6baaa6ec 100644 --- a/layers.php +++ b/layers.php @@ -38,7 +38,6 @@ $duplicatesStr = translate('Duplicates'); $editLayerStr = translate('Edit layer'); $editStr = translate('Edit'); -$enableLayersStr = translate('Enable layers'); $layerStr = translate('Layer'); $LAYERS_DISABLED = translate('Layers are currently disabled.'); $LAYERS_ENABLED = translate('Layers are currently enabled.'); @@ -87,8 +86,14 @@       - " id="enablebutton" > - " id="disablebutton"> + +


@@ -98,7 +103,8 @@
- +

@@ -179,13 +185,16 @@ diff --git a/login-app.php b/login-app.php index 029c14e34..31bdfd07b 100644 --- a/login-app.php +++ b/login-app.php @@ -117,8 +117,8 @@ function myOnLoad() { } echo ' - + diff --git a/login.php b/login.php index 0b4181b14..1c7dba516 100644 --- a/login.php +++ b/login.php @@ -223,7 +223,8 @@
- +
diff --git a/pref.php b/pref.php index 38bf23878..0f349f1bb 100644 --- a/pref.php +++ b/pref.php @@ -209,7 +209,8 @@ function save_pref( $prefs, $src) { $resetConfirm = str_replace("XXX", $user, $resetConfirm); ?>
- + @@ -840,24 +841,27 @@ function save_pref( $prefs, $src) { "> - name=""> + "> - name=""> + "> - name=""> + @@ -894,7 +898,8 @@ function save_pref( $prefs, $src) {

- +

diff --git a/purge.php b/purge.php index 316733999..c22dbb990 100644 --- a/purge.php +++ b/purge.php @@ -109,9 +109,8 @@ } echo '

...' . translate ( 'Finished' ) . ".

\n"; ?> -
' . "$sqlLog
\n"; @@ -160,10 +159,10 @@ - + diff --git a/register.php b/register.php index db90fd485..db83d9056 100644 --- a/register.php +++ b/register.php @@ -371,7 +371,7 @@ function generate_password() function valid_form() { validform = true; - $(':input[type="submit"]').prop('disabled', false); + document.querySelector(':button[type="submit"]').prop('disabled', false); if ($('#upassword1').length && $('#upassword1').val().length == 0) { $('#infoMessage').html(xlate['inputPassword']); $('#main-dialog-alert').show(); @@ -404,7 +404,7 @@ function valid_form() { checkers('uemail', 'email'); } - $(':input[type="submit"]').prop('disabled', !validform); + document.querySelector(':button[type="submit"]').prop('disabled', !validform); return validform; } @@ -430,14 +430,14 @@ function(data, status) { $('#main-dialog-alert').show(); validform = false; if(!validform) { - $(':input[type="submit"]').prop('disabled', true); + document.querySelector(':button[type="submit"]').prop('disabled', true); } return; } if(!validform) { - $(':input[type="submit"]').prop('disabled', true); + document.querySelector(':button[type="submit"]').prop('disabled', true); } else { - $('#main-dialog-alert').hide(); + document.querySelector('#main-dialog-alert').hide(); } }); } diff --git a/reject_entry.php b/reject_entry.php index 48e69f58e..1a6968783 100644 --- a/reject_entry.php +++ b/reject_entry.php @@ -28,8 +28,8 @@ . ' - + ' diff --git a/remotecal_mgmt.php b/remotecal_mgmt.php index 648fcf849..74f23a4fc 100644 --- a/remotecal_mgmt.php +++ b/remotecal_mgmt.php @@ -96,7 +96,8 @@
- +
@@ -147,8 +148,11 @@
@@ -178,8 +182,12 @@
@@ -211,8 +219,12 @@ diff --git a/resourcecal_mgmt.php b/resourcecal_mgmt.php index efa6d3e32..542b971f3 100644 --- a/resourcecal_mgmt.php +++ b/resourcecal_mgmt.php @@ -72,7 +72,8 @@
- +
@@ -129,8 +130,11 @@ @@ -159,8 +163,11 @@
diff --git a/search.php b/search.php index 5ae1986a7..89cc5076a 100644 --- a/search.php +++ b/search.php @@ -160,13 +160,14 @@ } echo '' - . ( $GROUPS_ENABLED == 'Y' - ? '' : '' ) . ' + . ( $GROUPS_ENABLED === 'Y' + ? '' : '' ) . ' '; } -echo ''; +echo ''; ?>