Skip to content

Commit

Permalink
Bug fix for resynch of changed checkbox options (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
jegelstaff authored Jun 26, 2024
1 parent a700037 commit 1adf74b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 6 additions & 4 deletions modules/formulize/admin/save/element_options_save.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,20 @@ function formulize_extractUIText($values) {
if(isset($_POST['changeuservalues']) AND $_POST['changeuservalues']==1) {
include_once XOOPS_ROOT_PATH . "/modules/formulize/class/data.php";
$data_handler = new formulizeDataHandler($fid);
$newValues = array();
switch($ele_type) {
case "radio":
case "check":
$newValues = $processedValues['elements']['ele_value'];
break;
case "select":
$newValues = $processedValues['elements']['ele_value'][2];
break;
}
if(!$changeResult = $data_handler->changeUserSubmittedValues($ele_id, $newValues)) {
print "Error updating user submitted values for the options in element $ele_id";
}
if(!empty($newValues)) {
if(!$changeResult = $data_handler->changeUserSubmittedValues($ele_id, $newValues)) {
print "Error updating user submitted values for the options in element $ele_id";
}
}
}


Expand Down
7 changes: 7 additions & 0 deletions modules/formulize/class/checkboxElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ function adminSave($element, $ele_value) {
$filter_key = 'formlinkfilter';
list($ele_value[5], $changed) = parseSubmittedConditions($filter_key, 'optionsconditionsdelete');

if(isset($_POST['changeuservalues']) AND $_POST['changeuservalues']==1) {
$data_handler = new formulizeDataHandler($element->getVar('id_form'));
if(!$changeResult = $data_handler->changeUserSubmittedValues($element, $ele_value[2])) {
print "Error updating user submitted values for the options in element ".$element->getVar('ele_id');
}
}

$element->setVar('ele_value', $ele_value);
$element->setVar('ele_uitext', $ele_uitext);
}
Expand Down
7 changes: 3 additions & 4 deletions modules/formulize/class/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ function toggleEncryption($elementHandle, $currentEncryptionStatus) {
// element_id_or_handle is the element we're working with, cannot pass in object!
// this function must be called prior to the new values actually being inserted to the element in the DB, since this function retrieves the current options for the element from the db in order to make a comparison
function changeUserSubmittedValues($element_id_or_handle, $newValues) {
if(!$element = _getElementObject($element_id_or_handle)) {
if(!$element = _getElementObject($element_id_or_handle) AND (!is_array($newValues) OR empty($newValues))) {
return false;
}

Expand All @@ -1281,10 +1281,10 @@ function changeUserSubmittedValues($element_id_or_handle, $newValues) {
$ele_type = $element->getVar('ele_type');
$ele_value = $element->getVar('ele_value');
switch($ele_type) {
case "check":
case "radio":
$oldValues = array_keys($ele_value);
break;
case "checkbox":
case "select":
$oldValues = array_keys($ele_value[2]);
// special check...if this is a linked selectbox or a fullnames/usernames selectbox, then fail
Expand All @@ -1293,7 +1293,7 @@ function changeUserSubmittedValues($element_id_or_handle, $newValues) {
}
break;
}
$prefix = ($ele_type == "check" OR ($ele_type == "select" AND $ele_value[1])) ? "#*=:*" : ""; // multiple selection possible? if so, setup prefix
$prefix = ($ele_type == "checkbox" OR ($ele_type == "select" AND $ele_value[1])) ? "*=+*:" : ""; // multiple selection possible? if so, setup prefix
$newValues = array_keys($newValues);
global $xoopsDB;
$form_handler = xoops_getmodulehandler('forms', 'formulize');
Expand Down Expand Up @@ -1336,7 +1336,6 @@ function changeUserSubmittedValues($element_id_or_handle, $newValues) {
}
if(count((array) $updateSql) > 0) { // if we have some SQL generated, then run it.
foreach($updateSql as $thisSql) {
//print $thisSql."<br>";
if(!$res = $xoopsDB->query($thisSql)) {
return false;
}
Expand Down

0 comments on commit 1adf74b

Please sign in to comment.