function compileElements($fid, $form, $formulize_mgr, $prevEntry, $entry, $go_back, $parentLinks, $owner_groups, $groups, $overrideValue = "", $elements_allowed = "", $profileForm = "", $frid = "", $mid, $sub_entries, $sub_fids, $member_handler, $gperm_handler, $title, $screen = null, $printViewPages = "", $printViewPageTitles = "")
{
    include_once XOOPS_ROOT_PATH . '/modules/formulize/include/elementdisplay.php';
    $entryForDEElements = is_numeric($entry) ? $entry : "new";
    // if there is no entry, ie: a new entry, then $entry is "" so when writing the entry value into decue_ and other elements that go out to the HTML form, we need to use the keyword "new"
    global $xoopsDB, $xoopsUser;
    $elementsAvailableToUser = array();
    // set criteria for matching on display
    // set the basics that everything has to match
    $criteriaBase = new CriteriaCompo();
    $criteriaBase->add(new Criteria('ele_display', 1), 'OR');
    foreach ($groups as $thisgroup) {
        $criteriaBase->add(new Criteria('ele_display', '%,' . $thisgroup . ',%', 'LIKE'), 'OR');
    }
    if (is_array($elements_allowed) and count($elements_allowed) > 0) {
        // if we're limiting the elements, then add a criteria for that (multiple criteria are joined by AND unless you specify OR manually when adding them (as in the base above))
        $criteria = new CriteriaCompo();
        $criteria->add(new Criteria('ele_id', "(" . implode(",", $elements_allowed) . ")", "IN"));
        $criteria->add($criteriaBase);
    } else {
        $criteria = $criteriaBase;
        // otherwise, just use the base
    }
    $criteria->setSort('ele_order');
    $criteria->setOrder('ASC');
    $elements =& $formulize_mgr->getObjects($criteria, $fid, true);
    // true makes the keys of the returned array be the element ids
    $count = 0;
    global $gridCounter;
    $gridCounter = array();
    $inGrid = 0;
    formulize_benchmark("Ready to loop elements.");
    // set the array to be used as the structure of the loop, either the passed in elements in order, or the elements as gathered from the DB
    // ignore passed in element order if there's a screen in effect, since we assume that official element order is authoritative when screens are involved
    // API should still allow arbitrary ordering, so $element_allowed can still be set manually as part of a displayForm call, and the order will be respected then
    if (!is_array($elements_allowed) or $screen) {
        $element_order_array = $elements;
    } else {
        $element_order_array = $elements_allowed;
    }
    // if this is a printview page,
    foreach ($element_order_array as $thisElement) {
        if (is_numeric($thisElement)) {
            // if we're doing the order based on passed in element ids...
            if (isset($elements[$thisElement])) {
                $i = $elements[$thisElement];
                // set the element object for this iteration of the loop
            } else {
                continue;
                // do not try to render elements that don't exist in the form!! (they might have been deleted from a multipage definition, or who knows what)
            }
            $this_ele_id = $thisElement;
            // set the element ID number
        } else {
            // else...we're just looping through the elements directly from the DB
            $i = $thisElement;
            // set the element object
            $this_ele_id = $i->getVar('ele_id');
            // get the element ID number
        }
        // check if we're at the start of a page, when doing a printable view of all pages (only situation when printViewPageTitles and printViewPages will be present), and if we are, then put in a break for the page titles
        if ($printViewPages) {
            if (!$currentPrintViewPage) {
                $currentPrintViewPage = 1;
            }
            while (!in_array($this_ele_id, $printViewPages[$currentPrintViewPage]) and $currentPrintViewPage <= count($printViewPages)) {
                $currentPrintViewPage++;
            }
            if ($this_ele_id == $printViewPages[$currentPrintViewPage][0]) {
                $form->insertBreak("<div id=\"formulize-printpreview-pagetitle\">" . $printViewPageTitles[$currentPrintViewPage] . "</div>", "head");
            }
        }
        // check if this element is included in a grid, and if so, skip it
        // $inGrid will be a number indicating how many times we have to skip things
        if ($inGrid or isset($gridCounter[$this_ele_id])) {
            if (!$inGrid) {
                $inGrid = $gridCounter[$this_ele_id];
            }
            $inGrid--;
            continue;
        }
        $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
        $owner = getEntryOwner($entry, $fid);
        $ele_type = $i->getVar('ele_type');
        $ele_value = $i->getVar('ele_value');
        if ($go_back['form']) {
            // if there's a parent form...
            // check here to see if we need to initialize the value of a linked selectbox when it is the key field for a subform
            // although this is setup as a loop through all found parentLinks, only the last one will be used, since ele_value[2] is overwritten each time.
            // assumption is there will only be one parent link for this form
            for ($z = 0; $z < count($parentLinks['source']); $z++) {
                if ($this_ele_id == $parentLinks['self'][$z]) {
                    // this is the element
                    $ele_value[2] = $go_back['entry'];
                    // 3.0 datastructure...needs to be tested!! -- now updated for 5.0
                }
            }
        } elseif ($overrideValue) {
            // used to force a default setting in a form element, other than the normal default
            if (!is_array($overrideValue)) {
                //convert a string to an array so that strings don't screw up logic below (which is designed for arrays)
                $temp = $overrideValue;
                unset($overrideValue);
                $overrideValue[0] = $temp;
            }
            // currently only operative for select boxes
            switch ($ele_type) {
                case "select":
                    foreach ($overrideValue as $ov) {
                        if (array_key_exists($ov, $ele_value[2])) {
                            $ele_value[2][$ov] = 1;
                        }
                    }
                    break;
                case "date":
                    // debug
                    //var_dump($overrideValue);
                    foreach ($overrideValue as $ov) {
                        //if(ereg ("([0-9]{4})-([0-9]{2})-([0-9]{2})", $ov, $regs)) {
                        if (ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $ov, $regs)) {
                            $ele_value[0] = $ov;
                        }
                    }
                    break;
            }
        }
        if ($ele_type != "subform" and $ele_type != 'grid') {
            // "" is framework, ie: not applicable
            // $i is element object
            // $entry is entry_id
            // false is "nosave" param...only used to force element to not be picked up by readelements.php after saving
            // $screen is the screen object
            // false means don't print it out to screen, return it here
            $GLOBALS['formulize_sub_fids'] = $sub_fids;
            // set here so we can pick it up in the render method of elements, if necessary (only necessary for subforms?);
            $deReturnValue = displayElement("", $i, $entry, false, $screen, $prevEntry, false, $profileForm, $groups);
            if (is_array($deReturnValue)) {
                $form_ele = $deReturnValue[0];
                $isDisabled = $deReturnValue[1];
            } else {
                $form_ele = $deReturnValue;
                $isDisabled = false;
            }
            $elementsAvailableToUser[$this_ele_id] = true;
            if ($form_ele == "not_allowed" or $form_ele == "hidden") {
                if (isset($GLOBALS['formulize_renderedElementHasConditions']["de_" . $fid . "_" . $entryForDEElements . "_" . $this_ele_id])) {
                    // need to add a tr container for elements that are not allowed, since if it was a condition that caused them to not show up, they might appear later on asynchronously, and we'll need the row to attach them to
                    if ($ele_type == "ib" and $form_ele == "not_allowed") {
                        $rowHTML = "<tr style='display: none' id='formulize-de_" . $fid . "_" . $entryForDEElements . "_" . $this_ele_id . "'></tr>";
                    } elseif ($form_ele == "not_allowed") {
                        $rowHTML = "<tr style='display: none' id='formulize-de_" . $fid . "_" . $entryForDEElements . "_" . $this_ele_id . "' valign='top' align='" . _GLOBAL_LEFT . "'></tr>";
                    }
                    // need to also get the validation code for this element, wrap it in a check for the table row being visible, and assign that to the global array that contains all the validation javascript that we need to add to the form
                    // following code follows the pattern set in elementdisplay.php for actually creating rendered element objects
                    if ($ele_type != "ib") {
                        $conditionalValidationRenderer = new formulizeElementRenderer($i);
                        if ($prevEntry or $profileForm === "new") {
                            $data_handler = new formulizeDataHandler($i->getVar('id_form'));
                            $ele_value = loadValue($prevEntry, $i, $ele_value, $data_handler->getEntryOwnerGroups($entry), $groups, $entry, $profileForm);
                            // get the value of this element for this entry as stored in the DB -- and unset any defaults if we are looking at an existing entry
                        }
                        $conditionalElementForValidiationCode = $conditionalValidationRenderer->constructElement("de_" . $fid . "_" . $entryForDEElements . "_" . $this_ele_id, $ele_value, $entry, $isDisabled, $screen);
                        if ($js = $conditionalElementForValidiationCode->renderValidationJS()) {
                            $GLOBALS['formulize_renderedElementsValidationJS'][$GLOBALS['formulize_thisRendering']][$conditionalElementForValidiationCode->getName()] = "if(window.document.getElementById('formulize-" . $conditionalElementForValidiationCode->getName() . "').style.display != 'none') {\n" . $js . "\n}\n";
                        }
                        unset($conditionalElementForValidiationCode);
                        unset($conditionalValidationRenderer);
                    }
                    $form->addElement($rowHTML);
                    // since it was treated as a conditional element, and the user might interact with it, then we don't consider it a not-available-to-user element
                    unset($elementsAvailableToUser[$this_ele_id]);
                }
                continue;
            }
        }
        $req = !$isDisabled ? intval($i->getVar('ele_req')) : 0;
        $GLOBALS['sub_entries'] = $sub_entries;
        if ($ele_type == "subform") {
            $thissfid = $ele_value[0];
            if (!$thissfid) {
                continue;
            }
            // can't display non-specified subforms!
            $deReturnValue = displayElement("", $i, $entry, false, $screen, $prevEntry, false, $profileForm, $groups);
            // do this just to evaluate any conditions...it won't actually render anything, but will return "" for the first key in the array, if the element is allowed
            if (is_array($deReturnValue)) {
                $form_ele = $deReturnValue[0];
                $isDisabled = $deReturnValue[1];
            } else {
                $form_ele = $deReturnValue;
                $isDisabled = false;
            }
            if ($passed = security_check($thissfid) and $form_ele == "") {
                $GLOBALS['sfidsDrawn'][] = $thissfid;
                $customCaption = $i->getVar('ele_caption');
                $customElements = $ele_value[1] ? explode(",", $ele_value[1]) : "";
                if (isset($GLOBALS['formulize_inlineSubformFrid'])) {
                    $newLinkResults = checkForLinks($GLOBALS['formulize_inlineSubformFrid'][0], array($fid), $fid, array($fid => array($entry)), null, $owner_groups, $mid, null, $owner, true);
                    // final true means only include entries from unified display linkages
                    $sub_entries = $newLinkResults['sub_entries'];
                }
                // 2 is the number of default blanks, 3 is whether to show the view button or not, 4 is whether to use captions as headings or not, 5 is override owner of entry, $owner is mainform entry owner, 6 is hide the add button, 7 is the conditions settings for the subform element, 8 is the setting for showing just a row or the full form, 9 is text for the add entries button
                $subUICols = drawSubLinks($thissfid, $sub_entries, $uid, $groups, $frid, $mid, $fid, $entry, $customCaption, $customElements, intval($ele_value[2]), $ele_value[3], $ele_value[4], $ele_value[5], $owner, $ele_value[6], $ele_value[7], $this_ele_id, $ele_value[8], $ele_value[9], $thisElement);
                if (isset($subUICols['single'])) {
                    $form->insertBreak($subUICols['single'], "even");
                } else {
                    $subLinkUI = new XoopsFormLabel($subUICols['c1'], $subUICols['c2']);
                    $form->addElement($subLinkUI);
                }
                unset($subLinkUI);
            }
        } elseif ($ele_type == "grid") {
            // we are going to have to store some kind of flag/counter with the id number of the starting element in the table, and the number of times we need to ignore things
            // we need to then listen for this up above and skip those elements as they come up.  This is why grids must come before their elements in the form definition
            include_once XOOPS_ROOT_PATH . "/modules/formulize/include/griddisplay.php";
            list($grid_title, $grid_row_caps, $grid_col_caps, $grid_background, $grid_start, $grid_count) = compileGrid($ele_value, $title, $i);
            $headingAtSide = ($ele_value[5] and $grid_title) ? true : false;
            // if there is a value for ele_value[5], then the heading should be at the side, otherwise, grid spans form width as it's own chunk of HTML
            $gridCounter[$grid_start] = $grid_count;
            $gridContents = displayGrid($fid, $entry, $grid_row_caps, $grid_col_caps, $grid_title, $grid_background, $grid_start, "", "", true, $screen, $headingAtSide);
            if ($headingAtSide) {
                // grid contents is the two bits for the xoopsformlabel when heading is at side, otherwise, it's just the contents for the break
                $form->addElement(new XoopsFormLabel($gridContents[0], $gridContents[1]));
            } else {
                $form->insertBreak($gridContents, "head");
                // head is the css class of the cell
            }
        } elseif ($ele_type == "ib" or is_array($form_ele)) {
            // if it's a break, handle it differently...$form_ele may be an array if it's a non-interactive element such as a grid
            if (is_object($thisElement)) {
                // final param is used as id name in the table row where this element exists, so we can interact with it for showing and hiding
                $form->insertBreakFormulize("<div class=\"formulize-subform-heading\">" . trans(stripslashes($form_ele[0])) . "</div>", $form_ele[1], 'de_' . $fid . '_' . $entryForDEElements . '_' . $this_ele_id, $thisElement->getVar("ele_handle"));
            }
        } else {
            $form->addElement($form_ele, $req);
        }
        $count++;
        unset($hidden);
        unset($form_ele);
        // apparently necessary for compatibility with PHP 4.4.0 -- suggested by retspoox, sept 25, 2005
    }
    formulize_benchmark("Done looping elements.");
    // find any hidden elements in the form, that aren't available to the user in this rendering of the form...
    unset($criteria);
    $notAllowedCriteria = new CriteriaCompo();
    $notAllowedCriteria->add(new Criteria('ele_forcehidden', 1));
    foreach ($elementsAvailableToUser as $availElementId => $boolean) {
        $notAllowedCriteria->add(new Criteria('ele_id', $availElementId, '!='));
    }
    $notAllowedCriteria->setSort('ele_order');
    $notAllowedCriteria->setOrder('ASC');
    $notAllowedElements =& $formulize_mgr->getObjects($notAllowedCriteria, $fid);
    $hiddenElements = generateHiddenElements($notAllowedElements, $entryForDEElements);
    // in functions.php, keys in returned array will be the element ids
    foreach ($hiddenElements as $element_id => $thisHiddenElement) {
        $form->addElement(new xoopsFormHidden("decue_" . $fid . "_" . $entryForDEElements . "_" . $element_id, 1));
        if (is_array($thisHiddenElement)) {
            // could happen for checkboxes
            foreach ($thisHiddenElement as $thisIndividualHiddenElement) {
                $form->addElement($thisIndividualHiddenElement);
            }
        } else {
            $form->addElement($thisHiddenElement);
        }
        unset($thisHiddenElement);
        // some odd reference thing going on here...$thisHiddenElement is being added by reference or something like that, so that when $thisHiddenElement changes in the next run through, every previous element that was created by adding it is updated to point to the next element.  So if you unset at the end of the loop, it forces each element to be added as you would expect.
    }
    if ($entry and !is_a($form, 'formulize_elementsOnlyForm')) {
        // two hidden fields encode the main entry id, the first difficult-to-use format is a legacy thing
        // the 'lastentry' format is more sensible, but is only available when there was a real entry, not 'new' (also a legacy convention)
        $form->addElement(new XoopsFormHidden('entry' . $fid, $entry));
        if (is_numeric($entry)) {
            $form->addElement(new XoopsFormHidden('lastentry', $entry));
        }
    }
    if ($_POST['parent_form']) {
        // if we just came back from a parent form, then if they click save, we DO NOT want an override condition, even though we are now technically editing an entry that was previously saved when we went to the subform in the first place.  So the override logic looks for this hidden value as an exception.
        $form->addElement(new XoopsFormHidden('back_from_sub', 1));
    }
    // add a hidden element to carry all the validation javascript that might be associated with elements rendered with elementdisplay.php...only relevant for elements rendered inside subforms or grids...the validation code comes straight from the element, doesn't have a check around it for the conditional table row id, like the custom form classes at the top of the file use, since those elements won't render as hidden and show/hide in the same way
    if (isset($GLOBALS['formulize_renderedElementsValidationJS'][$GLOBALS['formulize_thisRendering']])) {
        $formulizeHiddenValidation = new XoopsFormHidden('validation', '');
        foreach ($GLOBALS['formulize_renderedElementsValidationJS'][$GLOBALS['formulize_thisRendering']] as $thisValidation) {
            // grab all the validation code we stored in the elementdisplay.php file and attach it to this element
            foreach (explode("\n", $thisValidation) as $thisValidationLine) {
                $formulizeHiddenValidation->customValidationCode[] = $thisValidationLine;
            }
        }
        $form->addElement($formulizeHiddenValidation, 1);
    }
    if (get_class($form) == "formulize_elementsOnlyForm") {
        // forms of this class are ones that we're rendering just the HTML for the elements, and we need to preserve any validation javascript to stick in the final, parent form when it's finished
        $validationJS = $form->renderValidationJS();
        if (trim($validationJS) != "") {
            $GLOBALS['formulize_elementsOnlyForm_validationCode'][] = $validationJS . "\n\n";
        }
    } elseif (count($GLOBALS['formulize_elementsOnlyForm_validationCode']) > 0) {
        $elementsonlyvalidation = new XoopsFormHidden('elementsonlyforms', '');
        $elementsonlyvalidation->customValidationCode = $GLOBALS['formulize_elementsOnlyForm_validationCode'];
        $form->addElement($elementsonlyvalidation, 1);
    }
    return $form;
}
     $derivedValueFound = true;
     if (!$frid) {
         // if no framework in effect, then update each form's derived values in isolation
         foreach ($entries as $thisEntry) {
             formulize_updateDerivedValues($thisEntry, $allWrittenFid);
         }
     }
 }
 if ($frid and ($mainFormHasDerived or $derivedValueFound)) {
     // if there is a framework in effect, then update derived values across the entire framework...strong assumption would be that when a framework is in effect, all the forms being saved are related...if there are outliers they will not get their derived values updated!  We handle them below.
     foreach ($entries as $thisEntry) {
         if ($allWrittenFid == $fid) {
             $foundEntries['entries'][$fid] = $entries;
         } else {
             // Since this isn't the main form, then we need to check for which mainform entries match to the entries we're updating right now
             $foundEntries = checkForLinks($frid, array($allWrittenFid), $allWrittenFid, array($allWrittenFid => array($thisEntry)), null, null, null, null, null, null);
         }
         foreach ($foundEntries['entries'][$fid] as $mainFormEntry) {
             if (!in_array($mainFormEntry, $mainFormEntriesUpdatedForDerived) and $mainFormEntry) {
                 formulize_updateDerivedValues($mainFormEntry, $fid, $frid);
                 $mainFormEntriesUpdatedForDerived[] = $mainFormEntry;
                 if (!isset($formsUpdatedInFramework[$allWrittenFid])) {
                     // if the form we're on has derived values, then flag it as one of the updated forms
                     $formsUpdatedInFramework[$allWrittenFid] = $allWrittenFid;
                 }
             }
         }
         if ($allWrittenFid == $fid) {
             break;
             // we will now have processed all the $entries, so we can bail on this loop (when we're on the mainform, the $entries will be all the mainform entries, but when it's another form, then the entries might link to who knows what other entries in the main form.)
         }
Beispiel #3
0
function getDefaultCols($fid, $frid = "")
{
    global $xoopsDB, $xoopsUser;
    if ($frid) {
        // expand the headerlist to include the other forms
        $fids[0] = $fid;
        $check_results = checkForLinks($frid, $fids, $fid, "", "", "", "", "", "", "0");
        $fids = $check_results['fids'];
        $sub_fids = $check_results['sub_fids'];
        $gperm_handler =& xoops_gethandler('groupperm');
        $groups = $xoopsUser ? $xoopsUser->getGroups() : array(0 => XOOPS_GROUP_ANONYMOUS);
        $uid = $xoopsUser ? $xoopsUser->getVar('uid') : "0";
        $mid = getFormulizeModId();
        $ele_handles = array();
        $processedFids = array();
        foreach ($fids as $this_fid) {
            if (security_check($this_fid, "", $uid, "", $groups, $mid, $gperm_handler) and !isset($processedFids[$this_fid])) {
                $ele_handles = array_merge($ele_handles, getHeaderList($this_fid, true, true));
                $processedFids[$this_fid] = true;
            }
        }
        foreach ($sub_fids as $this_fid) {
            if (security_check($this_fid, "", $uid, "", $groups, $mid, $gperm_handler) and !isset($processedFids[$this_fid])) {
                $ele_handles = array_merge($ele_handles, getHeaderList($this_fid, true, true));
                $processedFids[$this_fid] = true;
            }
        }
        return $ele_handles;
    } else {
        $ele_handles = getHeaderList($fid, true, true);
        // third param causes element handles to be returned instead of IDs
        return $ele_handles;
    }
}
         // 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);
 $html = "";
 if ($onetoonekey) {
     // the onetoonekey is what changed, not a regular conditional element, so in that case, we need to re-determine the entryId that we should be displaying
     // rebuild entries and fids so it only has the main form entry in it, since we want to get the correct other one-to-one entries back
     $onetooneentries = array($onetoonefid => array($onetooneentries[$onetoonefid][0]));
     $onetoonefids = array($onetoonefid);
     $checkForLinksResults = checkForLinks($onetoonefrid, $onetoonefids, $onetoonefid, $onetooneentries);
     $entryId = $checkForLinksResults['entries'][$elementObject->getVar('id_form')][0];
 }
 if (security_check($fid, $entryId)) {
     // "" is framework, ie: not applicable
     $deReturnValue = displayElement("", $elementObject, $entryId, false, null, null, false);
     // false, null, null, false means it's not a noSave element, no screen, no prevEntry data passed in, and do not render the element on screen
     if (is_array($deReturnValue)) {
         $form_ele = $deReturnValue[0];
         $isDisabled = $deReturnValue[1];
         $label_class = " formulize-label-" . $elementObject->getVar("ele_handle");
         $input_class = " formulize-input-" . $elementObject->getVar("ele_handle");
         // rendered HTML code below is taken from the formulize classes at the top of include/formdisplay.php
         if ($elementObject->getVar('ele_type') == "ib") {
             // if it's a break, handle it differently...
             $class = $form_ele[1] != '' ? " class='" . $form_ele[1] . "'" : '';
function displayFormPages($formframe, $entry = "", $mainform = "", $pages, $conditions = "", $introtext = "", $thankstext = "", $done_dest = "", $button_text = "", $settings = "", $overrideValue = "", $printall = 0, $screen = null, $saveAndContinueButtonText = null)
{
    // nmc 2007.03.24 - added 'printall'
    formulize_benchmark("Start of displayFormPages.");
    // extract the optional page titles from the $pages array for use in the jump to box
    // NOTE: pageTitles array must start with key 1, not 0.  Page 1 is the first page of the form
    $pageTitles = array();
    if (isset($pages['titles'])) {
        $pageTitles = $pages['titles'];
        unset($pages['titles']);
    }
    if (!$saveAndContinueButtonText and isset($_POST['formulize_saveAndContinueButtonText'])) {
        $saveAndContinueButtonText = unserialize($_POST['formulize_saveAndContinueButtonText']);
    }
    if (!$done_dest and $_POST['formulize_doneDest']) {
        $done_dest = $_POST['formulize_doneDest'];
    }
    if (!$button_text and $_POST['formulize_buttonText']) {
        $button_text = $_POST['formulize_buttonText'];
    }
    list($fid, $frid) = getFormFramework($formframe, $mainform);
    $thankstext = $thankstext ? $thankstext : _formulize_DMULTI_THANKS;
    $introtext = $introtext ? $introtext : "";
    global $xoopsUser;
    $mid = getFormulizeModId();
    $groups = $xoopsUser ? $xoopsUser->getGroups() : array(0 => XOOPS_GROUP_ANONYMOUS);
    $uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
    $gperm_handler =& xoops_gethandler('groupperm');
    $member_handler =& xoops_gethandler('member');
    $single_result = getSingle($fid, $uid, $groups, $member_handler, $gperm_handler, $mid);
    // if this function was called without an entry specified, then assume the identity of the entry we're editing (unless this is a new save, in which case no entry has been made yet)
    // no handling of cookies here, so anonymous multi-page surveys will not benefit from that feature
    // this emphasizes how we need to standardize a lot of these interfaces with a real class system
    if (!$entry and $_POST['entry' . $fid]) {
        $entry = $_POST['entry' . $fid];
    } elseif (!$entry) {
        // or check getSingle to see what the real entry is
        $entry = $single_result['flag'] ? $single_result['entry'] : 0;
    }
    // formulize_newEntryIds is set when saving data
    if (!$entry and isset($GLOBALS['formulize_newEntryIds'][$fid])) {
        $entry = $GLOBALS['formulize_newEntryIds'][$fid][0];
    }
    $owner = getEntryOwner($entry, $fid);
    $prevPage = isset($_POST['formulize_prevPage']) ? $_POST['formulize_prevPage'] : 1;
    // last page that the user was on, not necessarily the previous page numerically
    $currentPage = isset($_POST['formulize_currentPage']) ? $_POST['formulize_currentPage'] : 1;
    $thanksPage = count($pages) + 1;
    // debug control:
    $currentPage = (isset($_GET['debugpage']) and is_numeric($_GET['debugpage'])) ? $_GET['debugpage'] : $currentPage;
    $usersCanSave = formulizePermHandler::user_can_edit_entry($fid, $uid, $entry);
    if ($pages[$prevPage][0] !== "HTML" and $pages[$prevPage][0] !== "PHP") {
        // remember prevPage is the last page the user was on, not the previous page numerically
        if (isset($_POST['form_submitted']) and $usersCanSave) {
            include_once XOOPS_ROOT_PATH . "/modules/formulize/include/formread.php";
            include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php";
            include_once XOOPS_ROOT_PATH . "/modules/formulize/class/data.php";
            //$owner_groups =& $member_handler->getGroupsByUser($owner, FALSE);
            $data_handler = new formulizeDataHandler($fid);
            $owner_groups = $data_handler->getEntryOwnerGroups($entry);
            $entries[$fid][0] = $entry;
            if ($frid) {
                $linkResults = checkForLinks($frid, array(0 => $fid), $fid, $entries, $gperm_handler, $owner_groups, $mid, $member_handler, $owner);
                unset($entries);
                $entries = $linkResults['entries'];
            }
            $entries = $GLOBALS['formulize_allWrittenEntryIds'];
            // set in readelements.php
            // if there has been no specific entry specified yet, then assume the identity of the entry that was just saved -- assumption is it will be a new save
            // from this point forward in time, this is the only entry that should be involved, since the 'entry'.$fid condition above will put this value into $entry even if this function was called with a blank entry value
            if (!$entry) {
                $entry = $entries[$fid][0];
            }
            synchSubformBlankDefaults($fid, $entry);
        }
    }
    // there are several points above where $entry is set, and now that we have a final value, store in ventry
    if ($entry > 0) {
        $settings['ventry'] = $entry;
    }
    // check to see if there are conditions on this page, and if so are they met
    // if the conditions are not met, move on to the next page and repeat the condition check
    // conditions only checked once there is an entry!
    $pagesSkipped = false;
    if (is_array($conditions) and $entry) {
        $conditionsMet = false;
        while (!$conditionsMet) {
            if (isset($conditions[$currentPage]) and count($conditions[$currentPage][0]) > 0) {
                // conditions on the current page
                $thesecons = $conditions[$currentPage];
                $elements = $thesecons[0];
                $ops = $thesecons[1];
                $terms = $thesecons[2];
                $types = $thesecons[3];
                // indicates if the term is part of a must or may set, ie: boolean and or or
                $filter = "";
                $oomfilter = "";
                $blankORSearch = "";
                foreach ($elements as $i => $thisElement) {
                    if ($ops[$i] == "NOT") {
                        $ops[$i] = "!=";
                    }
                    if ($terms[$i] == "{BLANK}") {
                        // NOTE...USE OF BLANKS WON'T WORK CLEANLY IN ALL CASES DEPENDING WHAT OTHER TERMS HAVE BEEN SPECIFIED!!
                        if ($ops[$i] == "!=" or $ops[$i] == "NOT LIKE") {
                            if ($types[$i] != "oom") {
                                // add to the main filter, ie: entry id = 1 AND x=5 AND y IS NOT "" AND y IS NOT NULL
                                if (!$filter) {
                                    $filter = $entry . "][" . $elements[$i] . "/**//**/!=][" . $elements[$i] . "/**//**/IS NOT NULL";
                                } else {
                                    $filter .= "][" . $elements[$i] . "/**//**/!=][" . $elements[$i] . "/**//**/IS NOT NULL";
                                }
                            } else {
                                // Add to the OOM filter, ie: entry id = 1 AND (x=5 OR y IS NOT "" OR y IS NOT NULL)
                                if (!$oomfilter) {
                                    $oomfilter = $elements[$i] . "/**//**/=][" . $elements[$i] . "/**//**/IS NULL";
                                } else {
                                    $oomfilter .= "][" . $elements[$i] . "/**//**/=][" . $elements[$i] . "/**//**/IS NULL";
                                }
                            }
                        } else {
                            if ($types[$i] != "oom") {
                                // add to its own OR filter, since we MUST match this condition, but we don't care if it's "" OR NULL
                                // ie: entry id = 1 AND (x=5 OR y=10) AND (z = "" OR z IS NULL)
                                if (!$blankORSearch) {
                                    $blankORSearch = $elements[$i] . "/**//**/=][" . $elements[$i] . "/**//**/IS NULL";
                                } else {
                                    $blankORSearch .= "][" . $elements[$i] . "/**//**/=][" . $elements[$i] . "/**//**/IS NULL";
                                }
                            } else {
                                // it's part of the oom filters anyway, so we put it there, because we don't care if it's null or "" or neither
                                if (!$oomfilter) {
                                    $oomfilter = $elements[$i] . "/**//**/=][" . $elements[$i] . "/**//**/IS NULL";
                                } else {
                                    $oomfilter .= "][" . $elements[$i] . "/**//**/=][" . $elements[$i] . "/**//**/IS NULL";
                                }
                            }
                        }
                    } elseif ($types[$i] == "oom") {
                        if (!$oomfilter) {
                            $oomfilter = $elements[$i] . "/**/" . trans($terms[$i]) . "/**/" . $ops[$i];
                        } else {
                            $oomfilter .= "][" . $elements[$i] . "/**/" . trans($terms[$i]) . "/**/" . $ops[$i];
                        }
                    } else {
                        if (!$filter) {
                            $filter = $entry . "][" . $elements[$i] . "/**/" . trans($terms[$i]) . "/**/" . $ops[$i];
                        } else {
                            $filter .= "][" . $elements[$i] . "/**/" . trans($terms[$i]) . "/**/" . $ops[$i];
                        }
                    }
                }
                if ($oomfilter and $filter) {
                    $finalFilter = array();
                    $finalFilter[0][0] = "AND";
                    $finalFilter[0][1] = $filter;
                    $finalFilter[1][0] = "OR";
                    $finalFilter[1][1] = $oomfilter;
                    if ($blankORSearch) {
                        $finalFilter[2][0] = "OR";
                        $finalFilter[2][1] = $blankORSearch;
                    }
                } elseif ($oomfilter) {
                    // need to add the $entry as a separate filter from the oom, so the entry and oom get an AND in between them
                    $finalFilter = array();
                    $finalFilter[0][0] = "AND";
                    $finalFilter[0][1] = $entry;
                    $finalFilter[1][0] = "OR";
                    $finalFilter[1][1] = $oomfilter;
                    if ($blankORSearch) {
                        $finalFilter[2][0] = "OR";
                        $finalFilter[2][1] = $blankORSearch;
                    }
                } else {
                    if ($blankORSearch) {
                        $finalFilter[0][0] = "AND";
                        $finalFilter[0][1] = $filter ? $filter : $entry;
                        $finalFilter[1][0] = "OR";
                        $finalFilter[1][1] = $blankORSearch;
                    } else {
                        $finalFilter = $filter;
                    }
                }
                $masterBoolean = "AND";
                include_once XOOPS_ROOT_PATH . "/modules/formulize/include/extract.php";
                $data = getData($frid, $fid, $finalFilter, $masterBoolean, "", "", "", "", "", false, 0, false, "", false, true);
                if (!$data) {
                    if ($prevPage <= $currentPage) {
                        $currentPage++;
                    } else {
                        $currentPage--;
                    }
                    $pagesSkipped = true;
                } else {
                    $conditionsMet = true;
                }
            } else {
                // no conditions on the current page
                $conditionsMet = true;
            }
        }
    }
    if ($currentPage > 1) {
        $previousPage = $currentPage - 1;
        // previous page numerically
    } else {
        $previousPage = "none";
    }
    $nextPage = $currentPage + 1;
    $done_dest = $done_dest ? $done_dest : getCurrentURL();
    $done_dest = substr($done_dest, 0, 4) == "http" ? $done_dest : "http://" . $done_dest;
    // Set up the javascript that we need for the form-submit functionality to work
    // note that validateAndSubmit calls the form validation function again, but obviously it will pass if it passed here.  The validation needs to be called prior to setting the pages, or else you can end up on the wrong page after clicking an ADD button in a subform when you've missed a required field.
    // savedPage and savedPrevPage are used to pick up the page and prevpage only when a two step validation, such as checking for uniqueness, returns and calls validateAndSubmit again
    ?>
	
	<script type='text/javascript'>
	var savedPage;
	var savedPrevPage;
	function submitForm(page, prevpage) {
		var validate = xoopsFormValidate_formulize();
		if(validate) {
			savedPage = 0;
			savedPrevPage = 0;
			multipageSetHiddenFields(page, prevpage);
			if (formulizechanged) {
        validateAndSubmit();
      } else {
        jQuery("#formulizeform").animate({opacity:0.4}, 200, "linear");
        jQuery("input[name^='decue_']").remove();
        // 'rewritePage' will trigger the page to change after the locks have been removed
        removeEntryLocks('rewritePage');
      }
    } else {
			savedPage = page;
			savedPrevPage = prevpage;
		}
  }

	function multipageSetHiddenFields(page, prevpage) {
		<?php 
    // neuter the ventry which is the key thing that keeps us on the form page,
    //  if in fact we just came from a list screen of some kind.
    // need to use an unusual selector, because something about selecting by id wasn't working,
    //  apparently may be related to setting actions on forms with certain versions of jQuery?
    print "\r\n\t\t\tif(page == {$thanksPage}) {\r\n\t\t\t\twindow.document.formulize.ventry.value = '';\r\n\t\t\t\tjQuery('form[name=formulize]').attr('action', '{$done_dest}');\r\n      }\r\n";
    ?>
      window.document.formulize.formulize_currentPage.value = page;
      window.document.formulize.formulize_prevPage.value = prevpage;
      window.document.formulize.formulize_doneDest.value = '<?php 
    print $done_dest;
    ?>
';
      window.document.formulize.formulize_buttonText.value = '<?php 
    print $button_text;
    ?>
';
	}

	function pageJump(options, prevpage) {
		for (var i=0; i < options.length; i++) {
			if (options[i].selected) {
				submitForm(options[i].value, prevpage);
				return false;
			}
		}
	}
	
	</script><noscript>
	<h1>You do not have javascript enabled in your web browser.  This form will not work with your web browser.  Please contact the webmaster for assistance.</h1>
	</noscript>
	<?php 
    if ($currentPage == $thanksPage) {
        if ($screen and $screen->getVar('finishisdone')) {
            print "<script type='text/javascript'>location = '{$done_dest}';</script>";
            return;
            // if we've ended up on the thanks page via conditions (last page was not shown) then we should just bail if there is not supposed to be a thanks page
        }
        if (is_array($thankstext)) {
            if ($thankstext[0] === "PHP") {
                eval($thankstext[1]);
            } else {
                print $thankstext[1];
            }
        } else {
            // HTML
            print html_entity_decode($thankstext);
        }
        print "<br><hr><br><div id=\"thankYouNavigation\"><p><center>\n";
        if ($pagesSkipped) {
            print _formulize_DMULTI_SKIP . "</p><p>\n";
        }
        $button_text = $button_text ? $button_text : _formulize_DMULTI_ALLDONE;
        if ($button_text != "{NOBUTTON}") {
            print "<a href='{$done_dest}'";
            if (is_array($settings)) {
                print " onclick=\"javascript:window.document.calreturnform.submit();return false;\"";
            }
            print ">" . $button_text . "</a>\n";
        }
        print "</center></p></div>";
        if (is_array($settings)) {
            print "<form name=calreturnform action=\"{$done_dest}\" method=post>\n";
            writeHiddenSettings($settings);
            print "</form>";
        }
    }
    if ($currentPage == 1 and $pages[1][0] !== "HTML" and $pages[1][0] !== "PHP" and !$_POST['goto_sfid']) {
        // only show intro text on first page if there's actually a form there
        print html_entity_decode(html_entity_decode($introtext));
    }
    unset($_POST['form_submitted']);
    // display an HTML or PHP page if that's what this page is...
    if ($currentPage != $thanksPage and ($pages[$currentPage][0] === "HTML" or $pages[$currentPage][0] === "PHP")) {
        // PHP
        if ($pages[$currentPage][0] === "PHP") {
            eval($pages[$currentPage][1]);
            // HTML
        } else {
            print $pages[$currentPage][1];
        }
        // put in the form that passes the entry, page we're going to and page we were on
        include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php";
        ?>
	
		
		<form name=formulize id=formulize action=<?php 
        print getCurrentURL();
        ?>
 method=post>
		<input type=hidden name=entry<?php 
        print $fid;
        ?>
 id=entry<?php 
        print $fid;
        ?>
 value=<?php 
        print $entry;
        ?>
>
		<input type=hidden name=formulize_currentPage id=formulize_currentPage value="">
		<input type=hidden name=formulize_prevPage id=formulize_prevPage value="">
		writeHiddenSettings($settings);
		</form>
	
		<script type="text/javascript">
			function validateAndSubmit() {
				window.document.formulize.submit();
			}
		</script>
	
		<?php 
    }
    // display a form if that's what this page is...
    if ($currentPage != $thanksPage and $pages[$currentPage][0] !== "HTML" and $pages[$currentPage][0] !== "PHP") {
        $buttonArray = array(0 => "{NOBUTTON}", 1 => "{NOBUTTON}");
        foreach ($pages[$currentPage] as $element) {
            $elements_allowed[] = $element;
        }
        $forminfo['elements'] = $elements_allowed;
        $forminfo['formframe'] = $formframe;
        $titleOverride = isset($pageTitles[$currentPage]) ? trans($pageTitles[$currentPage]) : "all";
        // we can pass in any text value as the titleOverride, and it will have the same effect as "all", but the alternate text will be used as the title for the form
        $GLOBALS['nosubforms'] = true;
        // subforms cannot have a view button on multipage forms, since moving to a sub causes total confusion of which entry and fid you are looking at
        $settings['formulize_currentPage'] = $currentPage;
        $settings['formulize_prevPage'] = $currentPage;
        // now that we're done everything else, we can send the current page as the previous page when initializing the form.  Javascript will set the true value prior to submission.
        formulize_benchmark("Before drawing nav.");
        $previousButtonText = (is_array($saveAndContinueButtonText) and isset($saveAndContinueButtonText['previousButtonText'])) ? $saveAndContinueButtonText['previousButtonText'] : _formulize_DMULTI_PREV;
        if ($usersCanSave and $nextPage == $thanksPage) {
            $nextButtonText = (is_array($saveAndContinueButtonText) and $saveAndContinueButtonText['saveButtonText']) ? $saveAndContinueButtonText['saveButtonText'] : _formulize_DMULTI_SAVE;
        } else {
            $nextButtonText = (is_array($saveAndContinueButtonText) and $saveAndContinueButtonText['nextButtonText']) ? $saveAndContinueButtonText['nextButtonText'] : _formulize_DMULTI_NEXT;
        }
        $previousPageButton = generatePrevNextButtonMarkup("prev", $previousButtonText, $usersCanSave, $nextPage, $previousPage, $thanksPage);
        $nextPageButton = generatePrevNextButtonMarkup("next", $nextButtonText, $usersCanSave, $nextPage, $previousPage, $thanksPage);
        $savePageButton = generatePrevNextButtonMarkup("save", _formulize_SAVE, $usersCanSave, $nextPage, $previousPage, $thanksPage);
        $totalPages = count($pages);
        $skippedPageMessage = $pagesSkipped ? _formulize_DMULTI_SKIP : "";
        $pageSelectionList = pageSelectionList($currentPage, $totalPages, $pageTitles, "above");
        // calling for the 'above' drawPageNav
        // setting up the basic templateVars for all templates
        $templateVariables = array('previousPageButton' => $previousPageButton, 'nextPageButton' => $nextPageButton, 'savePageButton' => $savePageButton, 'totalPages' => $totalPages, 'currentPage' => $currentPage, 'skippedPageMessage' => $skippedPageMessage, 'pageSelectionList' => $pageSelectionList, 'pageTitles' => $pageTitles, 'entry_id' => $entry, 'form_id' => $fid, 'owner' => $owner);
        print "<form name=\"pageNavOptions_above\" id=\"pageNavOptions_above\">\n";
        if ($screen and $toptemplate = $screen->getTemplate('toptemplate')) {
            formulize_renderTemplate('toptemplate', $templateVariables, $screen->getVar('sid'));
        } else {
            drawPageNav($usersCanSave, $currentPage, $totalPages, "above", $nextPageButton, $previousPageButton, $skippedPageMessage, $pageSelectionList);
        }
        print "</form>";
        formulize_benchmark("After drawing nav/before displayForm.");
        // need to check for the existence of an elementtemplate property in the screen, like we did with the top and bottom templates
        // if there's an eleemnt template, then do this loop, otherwise, do the displayForm call like normal
        if ($screen and $elementtemplate = $screen->getTemplate('elementtemplate')) {
            // Code added by Julian 2012-09-04 and Gordon Woodmansey 2012-09-05 to render the elementtemplate
            if (!security_check($fid, $entry)) {
                exit;
            }
            // start the form manually...
            $formObjectForRequiredJS = new formulize_themeForm('form object for required js', 'formulize', getCurrentURL(), "post", true);
            $element_handler = xoops_getmodulehandler('elements', 'formulize');
            print "<div id='formulizeform'><form id='formulize' name='formulize' action='" . getCurrentURL() . "' method='post' onsubmit='return xoopsFormValidate_formulize();' enctype='multipart/form-data'>";
            foreach ($elements_allowed as $thisElement) {
                // entry is a recordid, $thisElement is the element id
                // to get the conditional logic to be captured, we should buffer the drawing of the displayElement, and then output that later, because when displayElement does NOT return an object, then we get conditional logic -- subform rendering does it this way
                unset($form_ele);
                // previously set elements may linger when added to the form object, due to assignment of objects by reference or something odd like that...legacy of old code in the form class I think
                $deReturnValue = displayElement("", $thisElement, $entry, false, $screen, null, false);
                if (is_array($deReturnValue)) {
                    $form_ele = $deReturnValue[0];
                    $isDisabled = $deReturnValue[1];
                    if (isset($deReturnValue[2])) {
                        $hiddenElements = $deReturnValue[2];
                    }
                } else {
                    $form_ele = $deReturnValue;
                    $isDisabled = false;
                }
                if ($form_ele == "not_allowed") {
                    continue;
                } elseif ($form_ele == "hidden") {
                    $cueEntryValue = $entry ? $entry : "new";
                    $cueElement = new xoopsFormHidden("decue_" . $fid . "_" . $cueEntryValue . "_" . $thisElement, 1);
                    print $cueElement->render();
                    if (is_array($hiddenElements)) {
                        foreach ($hiddenElements as $thisHiddenElement) {
                            if ($is_object($thisHiddenElement)) {
                                print $thisHiddenElement->render() . "\n";
                            }
                        }
                    } elseif (is_object($hiddenElements)) {
                        print $hiddenElements->render() . "\n";
                    }
                    continue;
                } else {
                    $thisElementObject = $element_handler->get($thisElement);
                    $req = !$isDisabled ? intval($thisElementObject->getVar('ele_req')) : 0;
                    $formObjectForRequiredJS->addElement($form_ele, $req);
                    $elementMarkup = $form_ele->render();
                    $elementCaption = displayCaption("", $thisElement);
                    $elementDescription = displayDescription("", $thisElement);
                    $templateVariables['elementObjectForRendering'] = $form_ele;
                    $templateVariables['elementCaption'] = $elementCaption;
                    // here we can assume that the $previousPageButton etc has not be changed before rendering
                    $templateVariables['elementMarkup'] = $elementMarkup;
                    $templateVariables['elementDescription'] = $elementDescription;
                    $templateVariables['element_id'] = $thisElement;
                    formulize_renderTemplate('elementtemplate', $templateVariables, $screen->getVar('sid'));
                }
            }
            // now we also need to add in some bits that are necessary for the form submission logic to work...borrowed from parts of formdisplay.php mostly...this should be put together into a more distinct rendering system for forms, so we can call the pieces as needed
            print "<input type=hidden name=formulize_currentPage value='" . $settings['formulize_currentPage'] . "'>";
            print "<input type=hidden name=formulize_prevPage value='" . $settings['formulize_prevPage'] . "'>";
            print "<input type=hidden name=formulize_doneDest value='" . $settings['formulize_doneDest'] . "'>";
            print "<input type=hidden name=formulize_buttonText value='" . $settings['formulize_buttonText'] . "'>";
            print "<input type=hidden name=ventry value='" . $settings['ventry'] . "'>";
            print $GLOBALS['xoopsSecurity']->getTokenHTML();
            if ($entry) {
                print "<input type=hidden name=entry" . $fid . " value=" . intval($entry) . ">";
                // need this to persist the entry that the user is
            }
            print "</form></div>";
            print "<div id=savingmessage style=\"display: none; position: absolute; width: 100%; right: 0px; text-align: center; padding-top: 50px;\">\n";
            if (file_exists(XOOPS_ROOT_PATH . "/modules/formulize/images/saving-" . $xoopsConfig['language'] . ".gif")) {
                print "<img src=\"" . XOOPS_URL . "/modules/formulize/images/saving-" . $xoopsConfig['language'] . ".gif\">\n";
            } else {
                print "<img src=\"" . XOOPS_URL . "/modules/formulize/images/saving-english.gif\">\n";
            }
            print "</div>\n";
            drawJavascript();
            // need to create the form object, and add all the rendered elements to it, and then we'll have working required elements if we render the validation logic for the form
            print $formObjectForRequiredJS->renderValidationJS(true, true);
            // with tags, true, skip the extra js that checks for the formulize theme form divs around the elements so that conditional animation works, true
            // print "<script type=\"text/javascript\">function xoopsFormValidate_formulize(){return true;}</script>"; // shim for the validation javascript that is created by the xoopsThemeForms, and which our saving logic currently references...saving won't work without this...we should actually render the proper validation logic at some point, but not today.
        } else {
            displayForm($forminfo, $entry, $mainform, "", $buttonArray, $settings, $titleOverride, $overrideValue, "", "", 0, 0, $printall, $screen);
            // nmc 2007.03.24 - added empty params & '$printall'
        }
        formulize_benchmark("After displayForm.");
    }
    if ($currentPage != $thanksPage and !$_POST['goto_sfid']) {
        // have to get the new value for $pageSelection list if the user requires it on the users view.
        $pageSelectionList = pageSelectionList($currentPage, $totalPages, $pageTitles, "below");
        print "<form name=\"pageNavOptions_below\" id=\"pageNavOptions_below\">\n";
        if ($screen and $bottomtemplate = $screen->getTemplate('bottomtemplate')) {
            $templateVariables['pageSelectionList'] = $pageSelectionList;
            // assign the new pageSelectionList, since it was redone for the bottom section
            formulize_renderTemplate('bottomtemplate', $templateVariables, $screen->getVar('sid'));
        } else {
            drawPageNav($usersCanSave, $currentPage, $totalPages, "below", $nextPageButton, $previousPageButton, $skippedPageMessage, $pageSelectionList);
        }
        print "</form>";
    }
    formulize_benchmark("End of displayFormPages.");
}