Skip to content

Commit ef04261

Browse files
committed
Better answer message on setting saving.
1 parent 66916b1 commit ef04261

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

‎inc/ajax.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,14 @@ function set_annotation($post_req)
392392
*/
393393
function save_setting($post_req)
394394
{
395-
chdir('..');
396-
397-
saveSetting($post_req['k'], $post_req['v']);
395+
$status = saveSetting($post_req['k'], $post_req['v']);
396+
$raw_answer = array();
397+
if (str_starts_with($status, "OK: ")) {
398+
$raw_answer["save_setting"] = substr($status, 4);
399+
} else {
400+
$raw_answer["error"] = $status;
401+
}
402+
return json_encode($raw_answer);
398403
}
399404

400405
/**

‎inc/database_connect.php‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,21 +433,23 @@ function getSettingWithDefault($key)
433433
*
434434
* @global string $tbpref Table name prefix
435435
*
436-
* @return string Error or success message
436+
* @return string Success message (starts by "OK: "), or error message
437+
*
438+
* @since 2.9.0 Success message starts by "OK: "
437439
*/
438440
function saveSetting($k, $v)
439441
{
440442
global $tbpref;
441443
$dft = get_setting_data();
442444
if (!isset($v)) {
443-
return '';
445+
return 'Value is not set!';
444446
}
445447
if ($v === '') {
446-
return '';
448+
return 'Value is an empty string!';
447449
}
448450
runsql(
449-
'DELETE FROM ' . $tbpref . 'settings
450-
WHERE StKey = ' . convert_string_to_sqlsyntax($k),
451+
"DELETE FROM {$tbpref}settings
452+
WHERE StKey = " . convert_string_to_sqlsyntax($k),
451453
''
452454
);
453455
if (isset($dft[$k]) && $dft[$k]['num']) {
@@ -460,11 +462,14 @@ function saveSetting($k, $v)
460462
}
461463
}
462464
$dum = runsql(
463-
'INSERT INTO ' . $tbpref . 'settings (StKey, StValue) values(' .
465+
"INSERT INTO {$tbpref}settings (StKey, StValue) VALUES(" .
464466
convert_string_to_sqlsyntax($k) . ', ' .
465467
convert_string_to_sqlsyntax($v) . ')',
466468
''
467469
);
470+
if (is_numeric($dum)) {
471+
return "OK: $dum rows changed";
472+
}
468473
return $dum;
469474
}
470475

‎src/js/jq_pgm.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,12 @@ function keydown_event_do_text_text (e) {
12031203
function do_ajax_save_setting (k, v) {
12041204
$.post(
12051205
'inc/ajax.php',
1206-
{ action: '', action_type: 'save_setting', k: k, v: v }
1206+
{
1207+
action: '',
1208+
action_type: 'save_setting',
1209+
k: k,
1210+
v: v
1211+
}
12071212
);
12081213
}
12091214

0 commit comments

Comments
 (0)