From 9bccc8588fc194613e210267fda153631228a621 Mon Sep 17 00:00:00 2001 From: MatthieuLP Date: Mon, 9 Jan 2023 14:49:07 +0100 Subject: [PATCH] related to #1704 Better 'visible' attribute implementation in API * fixed SQL error * Use correct function to save 'visible' attribute * Underlined the 'Unlock it' button on the orange alert --- admin/themes/default/js/cat_modify.js | 1 - admin/themes/default/theme.css | 1 + include/ws_functions/pwg.categories.php | 26 +++++++++++++++++++------ ws.php | 4 ++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/admin/themes/default/js/cat_modify.js b/admin/themes/default/js/cat_modify.js index 23959dc36..d104f776e 100644 --- a/admin/themes/default/js/cat_modify.js +++ b/admin/themes/default/js/cat_modify.js @@ -73,7 +73,6 @@ jQuery(document).ready(function() { comment: $("#cat-comment").val(), visible: $("#cat-locked").is(":checked") ? 'false' : 'true', commentable: $("#cat-commentable").is(":checked") ? "true":"false", - apply_commentable_to_subalbums: $("#cat-apply-commentable-on-sub").is(":checked")? "true":"false", }, success:function(data) { if (data.stat == "ok") { diff --git a/admin/themes/default/theme.css b/admin/themes/default/theme.css index d079b661a..aa84e478b 100644 --- a/admin/themes/default/theme.css +++ b/admin/themes/default/theme.css @@ -406,6 +406,7 @@ LI.menuLi { /* Cat Modify */ .unlock-album { cursor: pointer; + text-decoration: underline; } .cat-modify { diff --git a/include/ws_functions/pwg.categories.php b/include/ws_functions/pwg.categories.php index abbcba43f..1c048c62e 100644 --- a/include/ws_functions/pwg.categories.php +++ b/include/ws_functions/pwg.categories.php @@ -792,7 +792,21 @@ SELECT * 'id' => $params['category_id'], ); - $info_columns = array('name', 'comment','commentable', 'visible'); + foreach (array('visible', 'commentable') as $param_name) + { + if (isset($params[$param_name]) and !preg_match('/^(true|false)$/i', $params[$param_name])) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid param '.$param_name.' : '.$params[$param_name]); + } + } + + if (!empty($params['visible']) and ($params['visible'] != $category['visible'])) + { + include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); + set_cat_visible(array($params['category_id']), $params['visible']); + } + + $info_columns = array('name', 'comment','commentable'); $perform_update = false; foreach ($info_columns as $key) @@ -807,15 +821,15 @@ SELECT * if (isset($params['commentable']) && isset($params['apply_commentable_to_subalbums']) && $params['apply_commentable_to_subalbums']) { - $subcats = get_subcat_ids(array('id' => $params['category_id'])); + $subcats = get_subcat_ids(array($params['category_id'])); if (count($subcats) > 0) { - $query = ' + $query = ' UPDATE '.CATEGORIES_TABLE.' -SET commentable = \''.$params['commentable'].'\' -WHERE id IN ('.implode(',', $subcats).') + SET commentable = \''.$params['commentable'].'\' + WHERE id IN ('.implode(',', $subcats).') ;'; - pwg_query($query); + pwg_query($query); } } diff --git a/ws.php b/ws.php index 2d5ccd99e..ae127cbf1 100644 --- a/ws.php +++ b/ws.php @@ -856,10 +856,10 @@ function ws_addDefaultMethods( $arr ) 'info'=>'public, private'), 'visible' => array('default'=>null, 'flags'=>WS_PARAM_OPTIONAL), - 'commentable' => array('default'=>true, + 'commentable' => array('default'=>null, 'flags'=>WS_PARAM_OPTIONAL, 'info'=>'Boolean, effective if configuration variable activate_comments is set to true'), - 'apply_commentable_to_subalbums' => array('default'=>false, + 'apply_commentable_to_subalbums' => array('default'=>null, 'flags'=>WS_PARAM_OPTIONAL, 'info'=>'If true, set commentable to all sub album'), ),