// don't store blank values for new entries, we don't want to write those (if desubform is used only for blank defaults, then it will always be "new" but we'll keep this as is for now, can't hurt) $formulize_elementData[$elementMetaData[1]][$elementMetaData[2] . $blankSubformCounter . "x" . $blankSubformElementId][$elementMetaData[3]] = $v; if (!isset($formulize_subformBlankCues[$elementMetaData[1]])) { $formulize_subformBlankCues[$elementMetaData[1]] = $elementMetaData[1]; // we will watch for entries being written to this form, and store the resulting entries in global space so we can synch them later } // also...the entry id that the new entries received was stored after writing in this array: // this is the subform id, and the subform placeholder, which must receive the last insert id when it's values are saved //$GLOBALS['formulize_subformCreateEntry'][$element->getVar('id_form')][$desubformEntryIndex] } elseif (substr($k, 0, 6) == "decue_") { // store values according to form, entry and element ID // prep them all for writing $elementMetaData = explode("_", $k); if (isset($_POST["de_" . $elementMetaData[1] . "_" . $elementMetaData[2] . "_" . $elementMetaData[3]])) { $elementObject = $element_handler->get($elementMetaData[3]); $v = prepDataForWrite($elementObject, $_POST["de_" . $elementMetaData[1] . "_" . $elementMetaData[2] . "_" . $elementMetaData[3]], $elementMetaData[2]); $formulize_elementData[$elementMetaData[1]][$elementMetaData[2]][$elementMetaData[3]] = $v; } elseif (is_numeric($elementMetaData[1])) { $formulize_elementData[$elementMetaData[1]][$elementMetaData[2]][$elementMetaData[3]] = "{WRITEASNULL}"; // no value returned for this element that was included (cue was found) so we write it as blank to the db } } elseif (substr($k, 0, 12) == "userprofile_") { $formulize_up[substr($k, 12)] = $v; } } // write all the user profile info if (count($formulize_up) > 0) { $formulize_up['uid'] = $GLOBALS['userprofile_uid']; writeUserProfile($formulize_up, $uid); } // figure out proxy user situation
function loadValue($prevEntry, $element, $ele_value, $owner_groups, $groups, $entry, $profileForm = "") { //global $xoopsUser; //if($xoopsUser->getVar('uid') == 1) { //print_r($prevEntry); //} global $myts; /* * Hack by F�lix <INBOX Solutions> for sedonde * myts == NULL */ if (!$myts) { $myts =& MyTextSanitizer::getInstance(); } /* * Hack by F�lix <INBOX Solutions> for sedonde * myts == NULL */ $type = $element->getVar('ele_type'); // going direct from the DB since if multi-language is active, getVar will translate the caption //$caption = $element->getVar('ele_caption'); $ele_id = $element->getVar('ele_id'); // if we're handling a new profile form, check to see if the user has filled in the form already and use that value if necessary // This logic could be of general use in handling posted requests, except for it's inability to handle 'other' boxes. An update may pay off in terms of speed of reloading the page. $value = ""; if ($profileForm === "new") { $dataFromUser = ""; foreach ($_POST as $k => $v) { if (preg_match('/de_/', $k)) { $n = explode("_", $k); if ($n[3] == $ele_id) { // found the element in $_POST; $dataFromUser = prepDataForWrite($element, $v); break; } } } if ($dataFromUser) { $value = $dataFromUser; } } // no value detected in form submission of this element... if (!$value) { $handle = $element->getVar('ele_handle'); $key = ""; $keysFound = array_keys($prevEntry['handles'], $handle); foreach ($keysFound as $thisKeyFound) { if ("xyz" . $prevEntry['handles'][$thisKeyFound] == "xyz" . $handle) { // do a comparison with a prefixed string to avoid problems comparing numbers to numbers plus text, ie: "1669" and "1669_copy" since the loose typing in PHP will not interpret those as intended $key = $thisKeyFound; break; } } // if the handle was not found in the existing values for this entry, then return the ele_value, unless we're looking at an existing entry, and then we need to clear defaults first // not sure this IF block will ever happen, this could be a holdover from the 2.0 data structure - jwe June 1 2014 if (!is_numeric($key) and $key == "") { if ($entry) { switch ($type) { case "text": $ele_value[2] = ""; break; case "textarea": $ele_value[0] = ""; break; } } return $ele_value; } if ($key !== "") { // grab previously saved value and treat it as the value for this element $value = $prevEntry['values'][$key]; } if (($element->getVar('ele_use_default_when_blank') or $element->getVar('ele_req')) and !$value) { // do not load in saved value over top of ele_value when the saved value is empty/blank // and the element is required, or the element has the use-defaults-when-blank option on return $ele_value; } } /*print_r($ele_value); print "<br>After: "; //debug block */ // based on element type, swap in saved value from DB over top of default value for this element switch ($type) { case "derived": $ele_value[5] = $value; // there is not a number 5 position in ele_value for derived values...we add the value to print in this position so we don't mess up any other information that might need to be carried around break; case "text": $ele_value[2] = $value; $ele_value[2] = eregi_replace("'", "'", $ele_value[2]); break; case "textarea": case "colorpick": $ele_value[0] = $value; break; case "select": case "radio": case "checkbox": // NOTE: unique delimiter used to identify LINKED select boxes, so they can be handled differently. if (is_string($ele_value[2]) and strstr($ele_value[2], "#*=:*")) { // if we've got a linked select box, then do everything differently $ele_value[2] .= "#*=:*" . $value; // append the selected entry ids to the form and handle info in the element definition } else { // put the array into another array (clearing all default values) // then we modify our place holder array and then reassign if ($type != "select") { $temparray = $ele_value; } else { $temparray = $ele_value[2]; } if (is_array($temparray)) { $temparraykeys = array_keys($temparray); } else { $temparraykeys = array(); } if ($temparraykeys[0] === "{FULLNAMES}" or $temparraykeys[0] === "{USERNAMES}") { // ADDED June 18 2005 to handle pulling in usernames for the user's group(s) $ele_value[2]['{SELECTEDNAMES}'] = explode("*=+*:", $value); if (count($ele_value[2]['{SELECTEDNAMES}']) > 1) { array_shift($ele_value[2]['{SELECTEDNAMES}']); } $ele_value[2]['{OWNERGROUPS}'] = $owner_groups; break; } // need to turn the prevEntry got from the DB into something the same as what is in the form specification so defaults show up right // important: this is safe because $value itself is not being sent to the browser! // we're comparing the output of these two lines against what is stored in the form specification, which does not have HTML escaped characters, and has extra slashes. Assumption is that lack of HTML filtering is okay since only admins and trusted users have access to form creation. Not good, but acceptable for now. $value = $myts->undoHtmlSpecialChars($value); if (get_magic_quotes_gpc()) { $value = addslashes($value); } $selvalarray = explode("*=+*:", $value); $numberOfSelectedValues = strstr($value, "*=+*:") ? count($selvalarray) - 1 : 1; // if this is a multiple selection value, then count the array values, minus 1 since there will be one leading separator on the string. Otherwise, it's a single value element so the number of selections is 1. $assignedSelectedValues = array(); foreach ($temparraykeys as $k) { if ((string) $k === (string) $value or trans((string) $k) === (string) $value) { $temparray[$k] = 1; $assignedSelectedValues[$k] = true; } elseif (is_array($selvalarray) and (in_array((string) $k, $selvalarray, TRUE) or in_array(trans((string) $k), $selvalarray, TRUE))) { $temparray[$k] = 1; $assignedSelectedValues[$k] = true; } else { $temparray[$k] = 0; } } if ((!empty($value) or $value === 0 or $value === "0") and count($assignedSelectedValues) < $numberOfSelectedValues) { // if we have not assigned the selected value from the db to one of the options for this element, then lets add it to the array of options, and flag it as out of range. This is to preserve out of range values in the db that are there from earlier times when the options were different, and also to preserve values that were imported without validation on purpose foreach ($selvalarray as $selvalue) { if (!isset($assignedSelectedValues[$selvalue]) and (!empty($selvalue) or $selvalue === 0 or $selvalue === "0")) { $temparray[_formulize_OUTOFRANGE_DATA . $selvalue] = 1; } } } if ($type == "radio" and $entry != "new" and ($value === "" or is_null($value)) and array_search(1, $ele_value)) { // for radio buttons, if we're looking at an entry, and we've got no value to load, but there is a default value for the radio buttons, then use that default value (it's normally impossible to unset the default value of a radio button, so we want to ensure it is used when rendering the element in these conditions) $ele_value = $ele_value; } elseif ($type != "select") { $ele_value = $temparray; } else { $ele_value[2] = $temparray; } } // end of IF we have a linked select box break; case "yn": if ($value == 1) { $ele_value = array("_YES" => 1, "_NO" => 0); } elseif ($value == 2) { $ele_value = array("_YES" => 0, "_NO" => 1); } else { $ele_value = array("_YES" => 0, "_NO" => 0); } break; case "date": $ele_value[0] = $value; break; default: if (file_exists(XOOPS_ROOT_PATH . "/modules/formulize/class/" . $type . "Element.php")) { $customTypeHandler = xoops_getmodulehandler($type . "Element", 'formulize'); return $customTypeHandler->loadValue($value, $ele_value, $element); } } // end switch /*print_r($ele_value); print "<br>"; //debug block */ return $ele_value; }
foreach ($_GET as $k => $v) { if ($k == 'elementId' or $k == 'entryId' or $k == 'fid' or $k == 'frid' or substr($k, 0, 8) == 'onetoone') { // serveral onetoone keys can be passed back too if ($k == 'onetooneentries' or $k == 'onetoonefids') { ${$k} = unserialize($v); } else { ${$k} = $v; } } elseif (substr($k, 0, 3) == 'de_') { $keyParts = explode("_", $k); // ANY KEY PASSED THAT IS THE NAME OF A DE_ ELEMENT IN MARKUP, WILL GET UNPACKED AS A VALUE THAT CAN BE SUBBED IN WHEN DOING LOOKUPS LATER ON. $passedEntryId = $keyParts[2]; $passedElementId = $keyParts[3]; $passedElementObject = $element_handler->get($passedElementId); $handle = $passedElementObject->getVar('ele_handle'); $databaseReadyValue = prepDataForWrite($passedElementObject, $v); $databaseReadyValue = $databaseReadyValue === "{WRITEASNULL}" ? NULL : $databaseReadyValue; if (substr($v, 0, 9) == "newvalue:") { $sendBackValue[$k] = $databaseReadyValue; } $GLOBALS['formulize_asynchronousFormDataInDatabaseReadyFormat'][$passedEntryId][$handle] = $databaseReadyValue; $apiFormatValue = prepvalues($databaseReadyValue, $handle, $passedEntryId); // will be an array if (is_array($apiFormatValue) and count($apiFormatValue) == 1) { $apiFormatValue = $apiFormatValue[0]; // take the single value if there's only one, same as display function does } $GLOBALS['formulize_asynchronousFormDataInAPIFormat'][$passedEntryId][$handle] = $apiFormatValue; } } $elementObject = $element_handler->get($elementId);