function findLinkedEntries($startForm, $targetForm, $startEntry, $gperm_handler, $owner_groups, $mid, $member_handler, $owner) { if (!$mid) { $mid = getFormulizeModId(); } if (!$gperm_handler) { $gperm_handler = xoops_gethandler('groupperm'); } if (!$member_handler) { $member_handler = xoops_gethandler('member'); } // set scope filter -- may need to pass in some exceptions here in the case of viewing entries that are covered by reports? global $xoopsUser; $groups = $xoopsUser ? $xoopsUser->getGroups() : array(0 => XOOPS_GROUP_ANONYMOUS); $owner = $xoopsUser ? $xoopsUser->getVar('uid') : 0; if ($global_scope = $gperm_handler->checkRight("view_globalscope", $targetForm['fid'], $groups, $mid)) { $all_users = ""; $all_groups = ""; } elseif ($group_scope = $gperm_handler->checkRight("view_groupscope", $targetForm['fid'], $groups, $mid)) { $formulize_permHandler = new formulizePermHandler($targetForm['fid']); $all_groups = $formulize_permHandler->getGroupScopeGroupIds($groups); if ($all_groups === false) { $groupsWithAccess = $gperm_handler->getGroupIds("view_form", $targetForm['fid'], $mid); $all_groups = array_intersect($groups, $groupsWithAccess); } $all_users = ""; $uq = makeUidFilter($all_users); } else { $all_users = array(0 => $owner); $all_groups = ""; } global $xoopsDB; //targetForm is a special array containing the keys as specified in the framework, and the target form //keys: fid, keyself, keyother //keyself and other are the ele_id from the form table for the elements that need to be matched. Must get captions and convert to formulize_form format in order to find the matching values // linking based on uid, in the case of one to one forms, assumption is that these forms are both single_entry forms (otherwise linking one_to_one based on uid doesn't make any sense) if ($targetForm['keyself'] == 0) { // get uid of first entry // look for that uid in the target form $data_handler_start = new formulizeDataHandler($startForm); $data_handler_target = new formulizeDataHandler($targetForm['fid']); $metaData = $data_handler_start->getEntryMeta($startEntry); $entry_ids = $data_handler_target->getAllEntriesForUsers($metaData['creation_uid'], $all_users, $all_groups); if (count($entry_ids) > 0) { $entries_to_return = $entry_ids; } else { $entries_to_return = ""; } return $entries_to_return; } elseif ($targetForm['common']) { // support for true shared values added September 4 2006 // return id_reqs from $targetForm['fid'] where the value of the matching element is the same as in the startEntry, startForm $data_handler_start = new formulizeDataHandler($startForm); $data_handler_target = new formulizeDataHandler($targetForm['fid']); $foundValue = $data_handler_start->getElementValueInEntry($startEntry, $targetForm['keyother']); $entry_ids = $data_handler_target->findAllEntriesWithValue($targetForm['keyself'], $foundValue, $all_users, $all_groups); if (count($entry_ids) > 0) { $entries_to_return = $entry_ids; } else { $entries_to_return = ""; } return $entries_to_return; } else { // linking based on a shared value. in the case of one to one forms assumption is that the shared value does not appear more than once in either form's field (otherwise this will be a defacto one to many link) // else we're looking at a classic "shared value" which is really a linked selectbox $element_handler = xoops_getmodulehandler('elements', 'formulize'); $startElement = $element_handler->get($targetForm['keyother']); $startEleValue = $startElement->getVar('ele_value'); // option 2, start form is the linked selectbox if (strstr($startEleValue[2], "#*=:*")) { // so look in the startEntry for the values in its linked field and return them. They will be a comma separated list of entry ids in the target form. $data_handler_start = new formulizeDataHandler($startForm); $foundValue = $data_handler_start->getElementValueInEntry($startEntry, $targetForm['keyother'], $all_users, $all_groups); if ($foundValue) { return explode(",", trim($foundValue, ",")); } else { return false; } } else { // option 3. target form is the linked selectbox // so look for all the entry ids in the target form, where the linked field has the startEntry in it $data_handler_target = new formulizeDataHandler($targetForm['fid']); $entries_to_return = $data_handler_target->findAllEntriesWithValue($targetForm['keyself'], $startEntry, $all_users, $all_groups); if ($entries_to_return !== false) { return $entries_to_return; } else { return false; } } } }