Exemplo n.º 1
0
                    writeOtherValues($writtenEntryId, $elementFid, $subformBlankCounter);
                    // write the other values for this entry
                    if ($creation_user == 0) {
                        // handle cookies for anonymous users
                        setcookie('entryid_' . $elementFid, $writtenEntryId, time() + 60 * 60 * 24 * 7, '/');
                        // the slash indicates the cookie is available anywhere in the domain (not just the current folder)
                        $_COOKIE['entryid_' . $elementFid] = $writtenEntryId;
                    }
                    afterSavingLogic($values, $writtenEntryId);
                }
            }
        } else {
            // save changes to existing elements
            // TODO: should this use $uid or a proxy user setting?
            if (formulizePermHandler::user_can_edit_entry($elementFid, $uid, $currentEntry)) {
                $writtenEntryId = formulize_writeEntry($values, $currentEntry);
                $formulize_allWrittenEntryIds[$elementFid][] = $writtenEntryId;
                // log the written id
                if (!isset($formulize_allWrittenFids[$elementFid])) {
                    $formulize_allWrittenFids[$elementFid] = $elementFid;
                }
                $notEntriesList['update_entry'][$elementFid][] = $writtenEntryId;
                // log the notification info
                writeOtherValues($writtenEntryId, $elementFid);
                // write the other values for this entry
                afterSavingLogic($values, $writtenEntryId);
            }
        }
    }
}
unset($GLOBALS['formulize_afterSavingLogicRequired']);
Exemplo n.º 2
0
function drawSubLinks($subform_id, $sub_entries, $uid, $groups, $frid, $mid, $fid, $entry, $customCaption = "", $customElements = "", $defaultblanks = 0, $showViewButtons = 1, $captionsForHeadings = 0, $overrideOwnerOfNewEntries = "", $mainFormOwner = 0, $hideaddentries = "", $subformConditions = null, $subformElementId = 0, $rowsOrForms = 'row', $addEntriesText = _formulize_ADD_ENTRIES, $subform_element_object = null)
{
    $nestedSubform = false;
    if (isset($GLOBALS['formulize_inlineSubformFrid'])) {
        $frid = $GLOBALS['formulize_inlineSubformFrid'];
        $nestedSubform = true;
    }
    $member_handler = xoops_gethandler('member');
    $gperm_handler = xoops_gethandler('groupperm');
    $addEntriesText = $addEntriesText ? $addEntriesText : _formulize_ADD_ENTRIES;
    global $xoopsDB, $nosubforms;
    $GLOBALS['framework'] = $frid;
    $form_handler = xoops_getmodulehandler('forms', 'formulize');
    // limit the sub_entries array to just the entries that match the conditions, if any
    if (is_array($subformConditions) and is_array($sub_entries[$subform_id])) {
        list($conditionsFilter, $conditionsFilterOOM, $curlyBracketFormFrom) = buildConditionsFilterSQL($subformConditions, $subform_id, $entry, $mainFormOwner, $fid);
        // pass in mainFormOwner as the comparison ID for evaluating {USER} so that the included entries are consistent when an admin looks at a set of entries made by someone else.
        $subformObject = $form_handler->get($subform_id);
        $sql = "SELECT entry_id FROM " . $xoopsDB->prefix("formulize_" . $subformObject->getVar('form_handle')) . "{$curlyBracketFormFrom} WHERE entry_id IN (" . implode(", ", $sub_entries[$subform_id]) . ") {$conditionsFilter} {$conditionsFilterOOM}";
        $sub_entries[$subform_id] = array();
        if ($res = $xoopsDB->query($sql)) {
            while ($array = $xoopsDB->fetchArray($res)) {
                $sub_entries[$subform_id][] = $array['entry_id'];
            }
        }
    }
    include_once XOOPS_ROOT_PATH . "/modules/formulize/include/extract.php";
    $target_sub_to_use = (isset($_POST['target_sub']) and $_POST['target_sub'] != 0) ? $_POST['target_sub'] : $subform_id;
    $elementq = q("SELECT fl_key1, fl_key2, fl_common_value, fl_form2_id FROM " . $xoopsDB->prefix("formulize_framework_links") . " WHERE fl_frame_id=" . intval($frid) . " AND fl_form2_id=" . intval($fid) . " AND fl_form1_id=" . intval($target_sub_to_use));
    // element_to_write is used below in writing results of "add x entries" clicks, plus it is used for defaultblanks on first drawing blank entries, so we need to get this outside of the saving routine
    if (count($elementq) > 0) {
        $element_to_write = $elementq[0]['fl_key1'];
        $value_source = $elementq[0]['fl_key2'];
        $value_source_form = $elementq[0]['fl_form2_id'];
    } else {
        $elementq = q("SELECT fl_key2, fl_key1, fl_common_value, fl_form1_id FROM " . $xoopsDB->prefix("formulize_framework_links") . " WHERE fl_frame_id=" . intval($frid) . " AND fl_form1_id=" . intval($fid) . " AND fl_form2_id=" . intval($target_sub_to_use));
        $element_to_write = $elementq[0]['fl_key2'];
        $value_source = $elementq[0]['fl_key1'];
        $value_source_form = $elementq[0]['fl_form1_id'];
    }
    if (0 == strlen($element_to_write)) {
        error_log("Relationship {$frid} for subform {$subform_id} on form {$fid} is invalid.");
        $to_return = array("c1" => "", "c2" => "", "sigle" => "");
        global $xoopsUser;
        if (is_object($xoopsUser) and in_array(XOOPS_GROUP_ADMIN, $xoopsUser->getGroups())) {
            if (0 == $frid) {
                $to_return['single'] = "This subform cannot be shown because no relationship is active.";
            } else {
                $to_return['single'] = "This subform cannot be shown because relationship {$frid} for subform " . "{$subform_id} on form {$fid} is invalid.";
            }
        }
        return $to_return;
    }
    // check for adding of a sub entry, and handle accordingly -- added September 4 2006
    static $subformInstance;
    $subformInstance = !isset($subformInstance) ? 100 : $subformInstance;
    $subformInstance++;
    if ($_POST['target_sub'] and $_POST['target_sub'] == $subform_id and $_POST['target_sub_instance'] == $subformElementId . $subformInstance) {
        // important we only do this on the run through for that particular sub form (hence target_sub == sfid), and also only for the specific instance of this subform on the page too, since not all entries may apply to all subform instances any longer with conditions in effect now
        // need to handle things differently depending on whether it's a common value or a linked selectbox type of link
        // uid links need to result in a "new" value in the displayElement boxes -- odd things will happen if people start adding linked values to entries that aren't theirs!
        if ($element_to_write != 0) {
            if ($elementq[0]['fl_common_value']) {
                // grab the value from the parent element -- assume that it is a textbox of some kind!
                if (isset($_POST['de_' . $value_source_form . '_' . $entry . '_' . $value_source])) {
                    $value_to_write = $_POST['de_' . $value_source_form . '_' . $entry . '_' . $value_source];
                } else {
                    // get this entry and see what the source value is
                    $data_handler = new formulizeDataHandler($value_source_form);
                    $value_to_write = $data_handler->getElementValueInEntry($entry, $value_source);
                }
            } else {
                $value_to_write = $entry;
            }
            $sub_entry_new = "";
            for ($i = 0; $i < $_POST['numsubents']; $i++) {
                // actually goahead and create the requested number of new sub entries...start with the key field, and then do all textboxes with defaults too...
                //$subEntWritten = writeElementValue($_POST['target_sub'], $element_to_write, "new", $value_to_write, "", "", true); // Last param is override that allows direct writing to linked selectboxes if we have prepped the value first!
                if ($overrideOwnerOfNewEntries) {
                    $creation_user_touse = $mainFormOwner;
                } else {
                    $creation_user_touse = "";
                }
                $subEntWritten = writeElementValue($_POST['target_sub'], $element_to_write, "new", $value_to_write, $creation_user_touse, "", true);
                // Last param is override that allows direct writing to linked selectboxes if we have prepped the value first!
                $element_handler = xoops_getmodulehandler('elements', 'formulize');
                if (!isset($elementsForDefaults)) {
                    $criteria = new CriteriaCompo();
                    $criteria->add(new Criteria('ele_type', 'text'), 'OR');
                    $criteria->add(new Criteria('ele_type', 'textarea'), 'OR');
                    $criteria->add(new Criteria('ele_type', 'date'), 'OR');
                    $criteria->add(new Criteria('ele_type', 'radio'), 'OR');
                    $elementsForDefaults = $element_handler->getObjects($criteria, $_POST['target_sub']);
                    // get all the text or textarea elements in the form
                }
                foreach ($elementsForDefaults as $thisDefaultEle) {
                    // need to write in any default values for any text boxes or text areas that are in the subform.  Perhaps other elements could be included too, but that would take too much work right now. (March 9 2009)
                    $defaultTextToWrite = "";
                    $ele_value_for_default = $thisDefaultEle->getVar('ele_value');
                    switch ($thisDefaultEle->getVar('ele_type')) {
                        case "text":
                            $defaultTextToWrite = getTextboxDefault($ele_value_for_default[2], $_POST['target_sub'], $subEntWritten);
                            // position 2 is default value for text boxes
                            break;
                        case "textarea":
                            $defaultTextToWrite = getTextboxDefault($ele_value_for_default[0], $_POST['target_sub'], $subEntWritten);
                            // position 0 is default value for text boxes
                            break;
                        case "date":
                            $defaultTextToWrite = getDateElementDefault($ele_value_for_default[0]);
                            if (false === $defaultTextToWrite) {
                                $defaultTextToWrite = "";
                            } else {
                                $defaultTextToWrite = date("c", $defaultTextToWrite);
                            }
                            break;
                        case "radio":
                            $thisDefaultEleValue = $thisDefaultEle->getVar('ele_value');
                            $defaultTextToWrite = array_search(1, $thisDefaultEleValue);
                    }
                    if ($defaultTextToWrite) {
                        writeElementValue($_POST['target_sub'], $thisDefaultEle->getVar('ele_id'), $subEntWritten, $defaultTextToWrite);
                    }
                }
                $sub_entry_written[] = $subEntWritten;
            }
        } else {
            $sub_entry_new = "new";
            // this happens in uid-link situations?
            $sub_entry_written = "";
        }
        // need to also enforce any equals conditions that are on the subform element, if any, and assign those values to the entries that were just added
        if (is_array($subformConditions)) {
            $filterValues = array();
            foreach ($subformConditions[1] as $i => $thisOp) {
                if ($thisOp == "=" and $subformConditions[3][$i] != "oom" and $subformConditions[2][$i] != "{BLANK}") {
                    $conditionElementObject = $element_handler->get($subformConditions[0][$i]);
                    $filterValues[$subformConditions[0][$i]] = prepareLiteralTextForDB($conditionElementObject, $subformConditions[2][$i]);
                }
            }
            if (count($filterValues) > 0) {
                foreach ($sub_entry_written as $thisSubEntry) {
                    formulize_writeEntry($filterValues, $thisSubEntry);
                }
            }
        }
    }
    // need to do a number of checks here, including looking for single status on subform, and not drawing in add another if there is an entry for a single
    $sub_single_result = getSingle($subform_id, $uid, $groups, $member_handler, $gperm_handler, $mid);
    $sub_single = $sub_single_result['flag'];
    if ($sub_single) {
        unset($sub_entries);
        $sub_entries[$subform_id][0] = $sub_single_result['entry'];
    }
    if (!is_array($sub_entries[$subform_id])) {
        $sub_entries[$subform_id] = array();
    }
    if ($sub_entry_new and !$sub_single and $_POST['target_sub'] == $subform_id) {
        for ($i = 0; $i < $_POST['numsubents']; $i++) {
            array_unshift($sub_entries[$subform_id], $sub_entry_new);
        }
    }
    if (is_array($sub_entry_written) and !$sub_single and $_POST['target_sub'] == $subform_id) {
        foreach ($sub_entry_written as $sew) {
            array_unshift($sub_entries[$subform_id], $sew);
        }
    }
    if (!$customCaption) {
        // get the title of this subform
        // help text removed for F4.0 RC2, this is an experiment
        $subtitle = q("SELECT desc_form FROM " . $xoopsDB->prefix("formulize_id") . " WHERE id_form = {$subform_id}");
        $col_one = "<p id=\"subform-caption-f{$fid}-sf{$subform_id}\" class=\"subform-caption\"><b>" . trans($subtitle[0]['desc_form']) . "</b></p>";
        // <p style=\"font-weight: normal;\">" . _formulize_ADD_HELP;
    } else {
        $col_one = "<p id=\"subform-caption-f{$fid}-sf{$subform_id}\" class=\"subform-caption\"><b>" . trans($customCaption) . "</b></p>";
        // <p style=\"font-weight: normal;\">" . _formulize_ADD_HELP;
    }
    /*if(intval($sub_entries[$subform_id][0]) != 0 OR $sub_entry_new OR is_array($sub_entry_written)) {
    		if(!$nosubforms) { $col_one .= "<br>" . _formulize_ADD_HELP2; }
    		$col_one .= "<br>" . _formulize_ADD_HELP3;
    	} */
    // list the entries, including links to them and delete checkboxes
    // get the headerlist for the subform and convert it into handles
    // note big assumption/restriction that we are only using the first header found (ie: only specify one header for a sub form!)
    // setup the array of elements to draw
    if (is_array($customElements)) {
        $headingDescriptions = array();
        $headerq = q("SELECT ele_caption, ele_colhead, ele_desc, ele_id FROM " . $xoopsDB->prefix("formulize") . " WHERE ele_id IN (" . implode(", ", $customElements) . ") ORDER BY ele_order");
        foreach ($headerq as $thisHeaderResult) {
            $elementsToDraw[] = $thisHeaderResult['ele_id'];
            $headingDescriptions[] = $thisHeaderResult['ele_desc'] ? $thisHeaderResult['ele_desc'] : "";
            if ($captionsForHeadings) {
                $headersToDraw[] = $thisHeaderResult['ele_caption'];
            } else {
                $headersToDraw[] = $thisHeaderResult['ele_colhead'] ? $thisHeaderResult['ele_colhead'] : $thisHeaderResult['ele_caption'];
            }
        }
    } else {
        $subHeaderList = getHeaderList($subform_id);
        $subHeaderList1 = getHeaderList($subform_id, true);
        if (isset($subHeaderList[0])) {
            $headersToDraw[] = trans($subHeaderList[0]);
        }
        if (isset($subHeaderList[1])) {
            $headersToDraw[] = trans($subHeaderList[1]);
        }
        if (isset($subHeaderList[2])) {
            $headersToDraw[] = trans($subHeaderList[2]);
        }
        $elementsToDraw = array_slice($subHeaderList1, 0, 3);
    }
    $need_delete = 0;
    $drawnHeadersOnce = false;
    if ($rowsOrForms == "row" or $rowsOrForms == '') {
        $col_two = "<table id=\"formulize-subform-table-{$subform_id}\" class=\"formulize-subform-table\">";
    } else {
        $col_two = "";
        if (!strstr($_SERVER['PHP_SELF'], "formulize/printview.php")) {
            $col_two .= "<div id=\"subform-{$subformElementId}\" class=\"subform-accordion-container\" subelementid=\"{$subformElementId}\" style=\"display: none;\">";
        }
        $col_two .= "<input type='hidden' name='subform_entry_" . $subformElementId . "_active' id='subform_entry_" . $subformElementId . "_active' value='' />";
        include_once XOOPS_ROOT_PATH . "/modules/formulize/class/data.php";
        $data_handler = new formulizeDataHandler($subform_id);
    }
    $deFrid = $frid ? $frid : "";
    // need to set this up so we can pass it as part of the displayElement function, necessary to establish the framework in case this is a framework and no subform element is being used, just the default draw-in-the-one-to-many behaviour
    // if there's been no form submission, and there's no sub_entries, and there are default blanks to show, then do everything differently -- sept 8 2007
    if (!$_POST['form_submitted'] and count($sub_entries[$subform_id]) == 0 and $defaultblanks > 0 and ($rowsOrForms == "row" or $rowsOrForms == '')) {
        for ($i = 0; $i < $defaultblanks; $i++) {
            // nearly same header drawing code as in the 'else' for drawing regular entries
            if (!$drawnHeadersOnce) {
                $col_two .= "<tr><td>\n";
                $col_two .= "<input type=\"hidden\" name=\"formulize_subformValueSource_{$subform_id}\" value=\"{$value_source}\">\n";
                $col_two .= "<input type=\"hidden\" name=\"formulize_subformValueSourceForm_{$subform_id}\" value=\"{$value_source_form}\">\n";
                $col_two .= "<input type=\"hidden\" name=\"formulize_subformValueSourceEntry_{$subform_id}\" value=\"{$entry}\">\n";
                $col_two .= "<input type=\"hidden\" name=\"formulize_subformElementToWrite_{$subform_id}\" value=\"{$element_to_write}\">\n";
                $col_two .= "<input type=\"hidden\" name=\"formulize_subformSourceType_{$subform_id}\" value=\"" . $elementq[0]['fl_common_value'] . "\">\n";
                $col_two .= "<input type=\"hidden\" name=\"formulize_subformId_{$subform_id}\" value=\"{$subform_id}\">\n";
                // this is probably redundant now that we're tracking sfid in the names of the other elements
                $col_two .= "</td>\n";
                foreach ($headersToDraw as $x => $thishead) {
                    if ($thishead) {
                        $headerHelpLinkPart1 = $headingDescriptions[$i] ? "<a href=\"#\" onclick=\"return false;\" alt=\"" . $headingDescriptions[$x] . "\" title=\"" . $headingDescriptions[$x] . "\">" : "";
                        $headerHelpLinkPart2 = $headerHelpLinkPart1 ? "</a>" : "";
                        $col_two .= "<th><p>{$headerHelpLinkPart1}<b>{$thishead}</b>{$headerHelpLinkPart2}</p></th>\n";
                    }
                }
                $col_two .= "</tr>\n";
                $drawnHeadersOnce = true;
            }
            $col_two .= "<tr>\n<td>";
            $col_two .= "</td>\n";
            include_once XOOPS_ROOT_PATH . "/modules/formulize/include/elementdisplay.php";
            foreach ($elementsToDraw as $thisele) {
                if ($thisele) {
                    ob_start();
                    // critical that we *don't* ask for displayElement to return the element object, since this way the validation logic is passed back through the global space also (ugh).  Otherwise, no validation logic possible for subforms.
                    $renderResult = displayElement($deFrid, $thisele, "subformCreateEntry_" . $i . "_" . $subformElementId);
                    $col_two_temp = ob_get_contents();
                    ob_end_clean();
                    if ($col_two_temp or $renderResult == "rendered") {
                        // only draw in a cell if there actually is an element rendered (some elements might be rendered as nothing (such as derived values)
                        $col_two .= "<td>{$col_two_temp}</td>\n";
                    } else {
                        $col_two .= "<td>******</td>";
                    }
                }
            }
            $col_two .= "</tr>\n";
        }
    } elseif (count($sub_entries[$subform_id]) > 0) {
        // need to figure out the proper order for the sub entries based on the properties set for this form
        // for now, hard code to the word number field to suit the map site only
        // if it's the word subform, then sort the entries differently
        /*if($subform_id == 281) {
        			$sortClause = " fas_281, block_281, word_number ";
        		} 
        		elseif ($subform_id == 283) {
        			$sortClause = " fas_283 ";
        		}
        		else {*/
        $sortClause = " entry_id ";
        //}
        $sformObject = $form_handler->get($subform_id);
        $subEntriesOrderSQL = "SELECT entry_id FROM " . $xoopsDB->prefix("formulize_" . $sformObject->getVar('form_handle')) . " WHERE entry_id IN (" . implode(",", $sub_entries[$subform_id]) . ") ORDER BY {$sortClause}";
        if ($subEntriesOrderRes = $xoopsDB->query($subEntriesOrderSQL)) {
            $sub_entries[$subform_id] = array();
            while ($subEntriesOrderArray = $xoopsDB->fetchArray($subEntriesOrderRes)) {
                $sub_entries[$subform_id][] = $subEntriesOrderArray['entry_id'];
            }
        }
        $currentSubformInstance = $subformInstance;
        foreach ($sub_entries[$subform_id] as $sub_ent) {
            if ($sub_ent != "") {
                if ($rowsOrForms == 'row' or $rowsOrForms == '') {
                    if (!$drawnHeadersOnce) {
                        $col_two .= "<tr><th></th>\n";
                        foreach ($headersToDraw as $i => $thishead) {
                            if ($thishead) {
                                $headerHelpLinkPart1 = $headingDescriptions[$i] ? "<a href=\"#\" onclick=\"return false;\" alt=\"" . $headingDescriptions[$i] . "\" title=\"" . $headingDescriptions[$i] . "\">" : "";
                                $headerHelpLinkPart2 = $headerHelpLinkPart1 ? "</a>" : "";
                                $col_two .= "<th><p>{$headerHelpLinkPart1}<b>{$thishead}</b>{$headerHelpLinkPart2}</p></th>\n";
                            }
                        }
                        $col_two .= "</tr>\n";
                        $drawnHeadersOnce = true;
                    }
                    $col_two .= "<tr>\n<td>";
                    // check to see if we draw a delete box or not
                    if ($sub_ent !== "new" and "hideaddentries" != $hideaddentries and formulizePermHandler::user_can_delete_entry($subform_id, $uid, $sub_ent) and !strstr($_SERVER['PHP_SELF'], "formulize/printview.php")) {
                        // note: if the add/delete entry buttons are hidden, then these delete checkboxes are hidden as well
                        $need_delete = 1;
                        $col_two .= "<input type=checkbox name=delbox{$sub_ent} value={$sub_ent}></input>";
                    }
                    $col_two .= "</td>\n";
                    include_once XOOPS_ROOT_PATH . "/modules/formulize/include/elementdisplay.php";
                    foreach ($elementsToDraw as $thisele) {
                        if ($thisele) {
                            ob_start();
                            // critical that we *don't* ask for displayElement to return the element object, since this way the validation logic is passed back through the global space also (ugh).  Otherwise, no validation logic possible for subforms.
                            $renderResult = displayElement($deFrid, $thisele, $sub_ent);
                            $col_two_temp = ob_get_contents();
                            ob_end_clean();
                            if ($col_two_temp or $renderResult == "rendered") {
                                // only draw in a cell if there actually is an element rendered (some elements might be rendered as nothing (such as derived values)
                                $col_two .= "<td>{$col_two_temp}</td>\n";
                            } else {
                                $col_two .= "<td>******</td>";
                            }
                        }
                    }
                    if (!$nosubforms and $showViewButtons and !strstr($_SERVER['PHP_SELF'], "formulize/printview.php")) {
                        $col_two .= "<td><input type=button name=view" . $sub_ent . " value='" . _formulize_SUBFORM_VIEW . "' onclick=\"javascript:goSub('{$sub_ent}', '{$subform_id}');return false;\"></input></td>\n";
                    }
                    $col_two .= "</tr>\n";
                } else {
                    // display the full form
                    $headerValues = array();
                    foreach ($elementsToDraw as $thisele) {
                        $value = $data_handler->getElementValueInEntry($sub_ent, $thisele);
                        $element_object = _getElementObject($thisele);
                        $value = prepvalues($value, $element_object->getVar("ele_handle"), $sub_ent);
                        if (is_array($value)) {
                            $value = implode(" - ", $value);
                        }
                        // may be an array if the element allows multiple selections (checkboxes, multiselect list boxes, etc)
                        $headerValues[] = $value;
                    }
                    $headerToWrite = implode(" &mdash; ", $headerValues);
                    if (str_replace(" &mdash; ", "", $headerToWrite) == "") {
                        $headerToWrite = _AM_ELE_SUBFORM_NEWENTRY_LABEL;
                    }
                    // check to see if we draw a delete box or not
                    $deleteBox = "";
                    if ($sub_ent !== "new" and formulizePermHandler::user_can_delete_entry($subform_id, $uid, $sub_ent) and !strstr($_SERVER['PHP_SELF'], "formulize/printview.php")) {
                        $need_delete = 1;
                        $deleteBox = "<input type=checkbox name=delbox{$sub_ent} value={$sub_ent}></input>&nbsp;&nbsp;";
                    }
                    if (!strstr($_SERVER['PHP_SELF'], "formulize/printview.php")) {
                        $col_two .= "<div class=\"subform-deletebox\">{$deleteBox}</div><div class=\"subform-entry-container\" id=\"subform-" . $subform_id . "-" . "{$sub_ent}\">\r\n\t<p class=\"subform-header\"><a href=\"#\"><span class=\"accordion-name\">" . $headerToWrite . "</span></a></p>\r\n\t<div class=\"accordion-content content\">";
                    }
                    ob_start();
                    $GLOBALS['formulize_inlineSubformFrid'] = $frid;
                    if ($display_screen = get_display_screen_for_subform($subform_element_object)) {
                        $subScreen_handler = xoops_getmodulehandler('formScreen', 'formulize');
                        $subScreenObject = $subScreen_handler->get($display_screen);
                        $subScreen_handler->render($subScreenObject, $sub_ent, null, true);
                    } else {
                        // SHOULD CHANGE THIS TO USE THE DEFAULT SCREEN FOR THE FORM!!!!!!????
                        $renderResult = displayForm($subform_id, $sub_ent, "", "", "", "", "formElementsOnly");
                    }
                    if (!$nestedSubform) {
                        unset($GLOBALS['formulize_inlineSubformFrid']);
                    }
                    $col_two_temp = ob_get_contents();
                    ob_end_clean();
                    $col_two .= $col_two_temp;
                    if (!strstr($_SERVER['PHP_SELF'], "formulize/printview.php")) {
                        $col_two .= "</div>\n</div>\n";
                    }
                }
            }
        }
        $subformInstance = $currentSubformInstance;
        // instance counter might have changed because the form could include other subforms
    }
    if ($rowsOrForms == 'row' or $rowsOrForms == '') {
        // complete the table if we're drawing rows
        $col_two .= "</table>";
    } else {
        if (!strstr($_SERVER['PHP_SELF'], "formulize/printview.php")) {
            $col_two .= "</div>";
            // close of the subform-accordion-container
        }
        static $jqueryUILoaded = false;
        if (!$jqueryUILoaded) {
            $col_two .= "<script type=\"text/javascript\" src=\"" . XOOPS_URL . "/modules/formulize/libraries/jquery/jquery-ui-1.8.2.custom.min.js\"></script>\n";
            $col_two .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . XOOPS_URL . "/modules/formulize/libraries/jquery/css/start/jquery-ui-1.8.2.custom.css\">\n";
            $jqueryUILoaded = true;
        }
        $col_two .= "\n\r\n<script type=\"text/javascript\">\r\n\tjQuery(document).ready(function() {\r\n\t\tjQuery(\"#subform-{$subformElementId}\").accordion({\r\n\t\t\tautoHeight: false, // no fixed height for sections\r\n\t\t\tcollapsible: true, // sections can be collapsed\r\n\t\t\tactive: ";
        if ($_POST['target_sub_instance'] == $subformElementId . $subformInstance and $_POST['target_sub'] == $subform_id) {
            $col_two .= count($sub_entries[$subform_id]) - $_POST['numsubents'];
        } elseif (is_numeric($_POST['subform_entry_' . $subformElementId . '_active'])) {
            $col_two .= $_POST['subform_entry_' . $subformElementId . '_active'];
        } else {
            $col_two .= 'false';
        }
        $col_two .= ",\r\n\t\t\theader: \"> div > p.subform-header\"\r\n\t\t});\r\n\t\tjQuery(\"#subform-{$subformElementId}\").fadeIn();\r\n\t});\r\n</script>";
    }
    // end of if we're closing the subform inferface where entries are supposed to be collapsable forms
    $deleteButton = "";
    if ((count($sub_entries[$subform_id]) > 0 and $sub_entries[$subform_id][0] != "" or $sub_entry_new or is_array($sub_entry_written)) and $need_delete) {
        $deleteButton = "&nbsp;&nbsp;&nbsp;<input type=button name=deletesubs value='" . _formulize_DELETE_CHECKED . "' onclick=\"javascript:sub_del('{$subform_id}');\">";
        static $deletesubsflagIncluded = false;
        if (!$deletesubsflagIncluded) {
            $col_one .= "\n<input type=hidden name=deletesubsflag value=''>\n";
            $deletesubsflagIncluded = true;
        }
    }
    // if the 'add x entries button' should be hidden or visible
    if ("hideaddentries" != $hideaddentries) {
        $allowed_to_add_entries = false;
        if ("subform" == $hideaddentries or 1 == $hideaddentries) {
            // for compatability, accept '1' which is the old value which corresponds to the new use-subform-permissions (saved as "subform")
            // user can add entries if they have permission on the sub form
            $allowed_to_add_entries = $gperm_handler->checkRight("add_own_entry", $subform_id, $groups, $mid);
        } else {
            // user can add entries if they have permission on the main form
            // the user should only be able to add subform entries if they can *edit* the main form entry, since adding a subform entry
            //  is like editing the main form entry. otherwise they could add subform entries on main form entries owned by other users
            $allowed_to_add_entries = formulizePermHandler::user_can_edit_entry($fid, $uid, $entry);
        }
        if ($allowed_to_add_entries and !strstr($_SERVER['PHP_SELF'], "formulize/printview.php")) {
            if (count($sub_entries[$subform_id]) == 1 and $sub_entries[$subform_id][0] === "" and $sub_single) {
                $col_two .= "<p><input type=button name=addsub value='" . _formulize_ADD_ONE . "' onclick=\"javascript:add_sub('{$subform_id}', 1, " . $subformElementId . $subformInstance . ");\"></p>";
            } elseif (!$sub_single) {
                $use_simple_add_one_button = isset($subform_element_object->ele_value["simple_add_one_button"]) ? 1 == $subform_element_object->ele_value["simple_add_one_button"] : false;
                $col_two .= "<p><input type=button name=addsub value='" . ($use_simple_add_one_button ? trans($subform_element_object->ele_value['simple_add_one_button_text']) : _formulize_ADD) . "' onclick=\"javascript:add_sub('{$subform_id}', window.document.formulize.addsubentries{$subform_id}{$subformElementId}{$subformInstance}.value, " . $subformElementId . $subformInstance . ");\">";
                if ($use_simple_add_one_button) {
                    $col_two .= "<input type=\"hidden\" name=addsubentries{$subform_id}{$subformElementId}{$subformInstance} id=addsubentries{$subform_id}{$subformElementId}{$subformInstance} value=\"1\">";
                } else {
                    $col_two .= "<input type=text name=addsubentries{$subform_id}{$subformElementId}{$subformInstance} id=addsubentries{$subform_id}{$subformElementId}{$subformInstance} value=1 size=2 maxlength=2>";
                    $col_two .= $addEntriesText;
                }
                $col_two .= $deleteButton . "</p>";
            }
        }
    }
    $to_return['c1'] = $col_one;
    $to_return['c2'] = $col_two;
    $to_return['single'] = $col_one . $col_two;
    if (is_object($subform_element_object)) {
        global $xoopsUser;
        $show_element_edit_link = (is_object($xoopsUser) and in_array(XOOPS_GROUP_ADMIN, $xoopsUser->getGroups()));
        $edit_link = "";
        if ($show_element_edit_link) {
            $edit_link = "<a class=\"formulize-element-edit-link\" tabindex=\"-1\" href=\"" . XOOPS_URL . "/modules/formulize/admin/ui.php?page=element&aid=0&ele_id=" . $subform_element_object->getVar("ele_id") . "\" target=\"_blank\">edit element</a>";
        }
        $to_return['single'] = "<div class=\"formulize-subform-" . $subform_element_object->getVar("ele_handle") . "\">{$edit_link} {$col_one} {$col_two}</div>";
    }
    return $to_return;
}
Exemplo n.º 3
0
function formulize_makeOneToOneLinks($frid, $fid)
{
    static $oneToOneLinksMade = array();
    $form1EntryIds = array();
    $form2EntryIds = array();
    $form1s = array();
    $form2s = array();
    if (!isset($oneToOneLinksMade[$frid]) and isset($GLOBALS['formulize_newEntryIds'][$fid])) {
        $frameworkHandler = xoops_getmodulehandler('frameworks', 'formulize');
        $frameworkObject = $frameworkHandler->get($frid);
        foreach ($frameworkObject->getVar('links') as $thisLink) {
            if ($thisLink->getVar('relationship') == 1) {
                // 1 signifies one to one relationships
                $form1 = $thisLink->getVar('form1');
                $form2 = $thisLink->getVar('form2');
                $key1 = $thisLink->getVar('key1');
                $key2 = $thisLink->getVar('key2');
                $form1EntryId = "";
                $form2EntryId = "";
                $entryToWriteToForm1 = $GLOBALS['formulize_newEntryIds'][$form1][0] ? $GLOBALS['formulize_newEntryIds'][$form1][0] : $GLOBALS['formulize_allWrittenEntryIds'][$form1][0];
                if (!$entryToWriteToForm1) {
                    exit("Error: we could not determine which entry in form {$form1} we should use for writing the key value for the relationship.");
                }
                $entryToWriteToForm2 = $GLOBALS['formulize_newEntryIds'][$form2][0] ? $GLOBALS['formulize_newEntryIds'][$form2][0] : $GLOBALS['formulize_allWrittenEntryIds'][$form2][0];
                if (!$entryToWriteToForm2) {
                    exit("Error: we could not determine which entry in form {$form2} we should use for writing the key value for the relationship.");
                }
                if ($thisLink->getVar('common')) {
                    if ((!isset($_POST["de_" . $form1 . "_new_" . $key1]) or $_POST["de_" . $form1 . "_new_" . $key1] === "") and (!isset($_POST["de_" . $form1 . "_" . $GLOBALS['formulize_allWrittenEntryIds'][$form1][0] . "_" . $key1]) or $_POST["de_" . $form1 . "_" . $GLOBALS['formulize_allWrittenEntryIds'][$form1][0] . "_" . $key1] === "")) {
                        // if we don't have a value for this element, then populate it with the value from the other element
                        if ($commonValueToWrite = formulize_findCommonValue($form1, $form2, $key1, $key2)) {
                            $form1EntryId = formulize_writeEntry(array($key1 => $commonValueToWrite), $entryToWriteToForm1);
                        }
                    }
                    if ((!isset($_POST["de_" . $form2 . "_new_" . $key2]) or $_POST["de_" . $form2 . "_new_" . $key2] === "") and (!isset($_POST["de_" . $form2 . "_" . $GLOBALS['formulize_allWrittenEntryIds'][$form2][0] . "_" . $key2]) or $_POST["de_" . $form2 . "_" . $GLOBALS['formulize_allWrittenEntryIds'][$form2][0] . "_" . $key2] === "")) {
                        // if we don't have a value for this element, then populate it with the value from the other element
                        if ($commonValueToWrite = formulize_findCommonValue($form2, $form1, $key2, $key1)) {
                            // since we're looking for the other form, swap the order of param inputs
                            $form2EntryId = formulize_writeEntry(array($key2 => $commonValueToWrite), $entryToWriteToForm2);
                        }
                    }
                } elseif ($thisLink->getVar('unifiedDisplay')) {
                    // figure out which one is on which side of the linked selectbox
                    $element_handler = xoops_getmodulehandler('elements', 'formulize');
                    $linkedElement1 = $element_handler->get($key1);
                    $linkedElement1EleValue = $linkedElement1->getVar('ele_value');
                    if (strstr($linkedElement1EleValue[2], "#*=:*")) {
                        // element 1 is the linked selectbox, so get the value of entry id for what we just created in form 2, and put it in element 1
                        $linkedValueToWrite = isset($GLOBALS['formulize_newEntryIds'][$form2][0]) ? $GLOBALS['formulize_newEntryIds'][$form2][0] : "";
                        $linkedValueToWrite = (!$linkedValueToWrite and isset($GLOBALS['formulize_allWrittenEntryIds'][$form2][0])) ? $GLOBALS['formulize_allWrittenEntryIds'][$form2][0] : $linkedValueToWrite;
                        // or get the first entry ID that we wrote to the form, if no new entries were written to the form
                        $form1EntryId = formulize_writeEntry(array($key1 => $linkedValueToWrite), $entryToWriteToForm1);
                    } else {
                        // element 2 is the linked selectbox, so get the value of entry id for what we just created in form 1 and put it in element 2
                        $linkedValueToWrite = isset($GLOBALS['formulize_newEntryIds'][$form1][0]) ? $GLOBALS['formulize_newEntryIds'][$form1][0] : "";
                        $linkedValueToWrite = (!$linkedValueToWrite and isset($GLOBALS['formulize_allWrittenEntryIds'][$form1][0])) ? $GLOBALS['formulize_allWrittenEntryIds'][$form1][0] : $linkedValueToWrite;
                        // or get the first entry ID that we wrote to the form, if no new entries were written to the form
                        $form2EntryId = formulize_writeEntry(array($key2 => $linkedValueToWrite), $entryToWriteToForm2);
                    }
                }
                $form1EntryIds[] = $form1EntryId;
                $form2EntryIds[] = $form2EntryId;
                $form1s[] = $form1;
                $form2s[] = $form2;
            }
        }
        $oneToOneLinksMade[$frid] = true;
    }
    return array($form1s, $form2s, $form1EntryIds, $form2EntryIds);
}