function addOwnershipList($form, $groups, $member_handler, $gperm_handler, $fid, $mid, $entry_id = "") { global $xoopsDB; $add_groups = $gperm_handler->getGroupIds("add_own_entry", $fid, $mid); // May 5, 2006 -- limit to the user's own groups unless the user has global scope if (!($globalscope = $gperm_handler->checkRight("view_globalscope", $fid, $groups, $mid))) { $add_groups = array_intersect($add_groups, $groups); } $all_add_users = array(); foreach ($add_groups as $grp) { $add_users = $member_handler->getUsersByGroup($grp); $all_add_users = array_merge((array) $add_users, $all_add_users); unset($add_users); } $unique_users = array_unique($all_add_users); $punames = array(); foreach ($unique_users as $uid) { $uqueryforrealnames = "SELECT name, uname FROM " . $xoopsDB->prefix("users") . " WHERE uid={$uid}"; $uresqforrealnames = $xoopsDB->query($uqueryforrealnames); $urowqforrealnames = $xoopsDB->fetchRow($uresqforrealnames); $punames[] = $urowqforrealnames[0] ? $urowqforrealnames[0] : $urowqforrealnames[1]; // use the uname if there is no full name } // alphabetize the proxy list added 11/2/04 array_multisort($punames, $unique_users); if ($entry_id) { include_once XOOPS_ROOT_PATH . "/modules/formulize/class/data.php"; $data_handler = new formulizeDataHandler($fid); $entryMeta = $data_handler->getEntryMeta($entry_id); $entryOwner = $entryMeta[2]; $entryOwnerName = $punames[array_search($entryOwner, $unique_users)]; // need to look in one array to find the key to lookup in the other array...a legacy from when corresponding arrays were a common data structure in Formulize...multidimensional arrays were not well understood in the beginning $proxylist = new XoopsFormSelect(_AM_SELECT_UPDATE_OWNER, 'updateowner_' . $fid . '_' . $entry_id, 0, 1); $proxylist->addOption('nochange', _AM_SELECT_UPDATE_NOCHANGE . $entryOwnerName); } else { $proxylist = new XoopsFormSelect(_AM_SELECT_PROXY, 'proxyuser', 0, 5, TRUE); // made multi May 3 05 $proxylist->addOption('noproxy', _formulize_PICKAPROXY); } for ($i = 0; $i < count($unique_users); $i++) { if ($unique_users[$i]) { $proxylist->addOption($unique_users[$i], $punames[$i]); } } if (!$entry_id) { $proxylist->setValue('noproxy'); } else { $proxylist->setValue('nochange'); } $proxylist->setClass("no-print"); $form->addElement($proxylist); return $form; }
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; } } } }