Skip to content

Commit

Permalink
Bug fix #510: Could not create global categories
Browse files Browse the repository at this point in the history
  • Loading branch information
craigk5n committed Sep 3, 2024
1 parent 2d5c0d2 commit 441128a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions category_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function updateIconBlob($catId, $iconData, $iconMimeType) {
if (!dbi_execute(
'DELETE FROM webcal_categories
WHERE cat_id = ? AND ( cat_owner = ?'
. ($is_admin ? ' OR cat_owner IS NULL )' : ' )'),
. ($is_admin ? ' OR cat_owner = \'\' )' : ' )'),
[$id, $login]
)) {
$error = db_error();
Expand Down Expand Up @@ -95,16 +95,18 @@ function updateIconBlob($catId, $iconData, $iconMimeType) {
$row = dbi_fetch_row($res);
$id = $row[0] + 1;
dbi_free_result($res);
// Set catowner to NULL for global category
$catowner = ($is_admin ? ($isglobal == 'Y' ? null : $login) : $login);
// Set catowner to empty string for global category
$catowner = ($is_admin ? ($isglobal == 'Y' ? '' : $login) : $login);
if (!dbi_execute(
'INSERT INTO webcal_categories ( cat_id, cat_owner,
cat_name, cat_color ) VALUES ( ?, ?, ?, ? )',
[$id, $catowner, $catname, $catcolor]
))
)) {
$error = db_error();
} else
}
} else {
$error = db_error();
}
}
if (empty($delIcon) && (!empty($ENABLE_ICON_UPLOADS) && $ENABLE_ICON_UPLOADS == 'Y' || $is_admin)) {
// Save icon if uploaded.
Expand Down
2 changes: 1 addition & 1 deletion edit_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function time_selection($prefix, $time = '', $trigger = false)
if (!empty($cat_id)) {
$res = dbi_execute(
'SELECT cat_name FROM webcal_categories ' .
'WHERE cat_id = ? AND ( cat_owner = ? OR cat_owner IS NULL )',
'WHERE cat_id = ? AND ( cat_owner = ? OR cat_owner = \'\' )',
[$cat_id, $real_user]
);
if ($res) {
Expand Down
4 changes: 2 additions & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,7 @@ function get_categories_by_id ( $id, $user, $asterisk = false ) {

$res = dbi_execute ( 'SELECT wc.cat_name, wc.cat_id, wec.cat_owner
FROM webcal_categories wc, webcal_entry_categories wec WHERE wec.cal_id = ?
AND wec.cat_id = wc.cat_id AND ( wc.cat_owner = ? OR wc.cat_owner IS NULL )
AND wec.cat_id = wc.cat_id AND ( wc.cat_owner = ? OR wc.cat_owner = \'\' )
ORDER BY wec.cat_order', [$id, ( empty ( $user ) ? $login : $user )] );
while ( $row = dbi_fetch_row ( $res ) ) {
$categories[ ( empty ( $row[2] ) ? - $row[1] : $row[1] ) ] = $row[0]
Expand Down Expand Up @@ -4209,7 +4209,7 @@ function load_user_categories ( $ex_global = '' ) {
( $is_assistant || $is_admin ) ? $user : $login );
$rows = dbi_get_cached_rows ( 'SELECT cat_id, cat_name, cat_owner, cat_color, cat_icon_mime
FROM webcal_categories WHERE ( cat_owner = ? ) ' . ( $ex_global == ''
? 'OR ( cat_owner IS NULL ) ORDER BY cat_owner,' : 'ORDER BY' )
? 'OR ( cat_owner = \'\' ) ORDER BY cat_owner,' : 'ORDER BY' )
. ' cat_name', $query_params );
if ( $rows ) {
for ( $i = 0, $cnt = count ( $rows ); $i < $cnt; $i++ ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/xcal.php
Original file line number Diff line number Diff line change
Expand Up @@ -3121,7 +3121,7 @@ function get_categories_id_byname ( $cat_names ) {
$categories = explode ( ',', $cat_names );
foreach ( $categories as $cat_name ) {
$res = dbi_execute ( 'SELECT cat_id FROM webcal_categories
WHERE cat_name = ? AND ( cat_owner = ? OR cat_owner IS NULL )',
WHERE cat_name = ? AND ( cat_owner = ? OR cat_owner = \'\' )',
[$cat_name, $login] );
if ( $res ) {
if ( $row = dbi_fetch_row ( $res ) ) {
Expand Down
2 changes: 1 addition & 1 deletion install/sql/tables-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ CREATE TABLE webcal_entry_log (

/**
* Defines user categories. Categories can be specific to a user or global.
* When a category is global, the cat_owner field will be NULL.
* When a category is global, the cat_owner field will be an empty string.
* (Only an admin user can create a global category.)
*/
CREATE TABLE webcal_categories (
Expand Down

0 comments on commit 441128a

Please sign in to comment.