function prepareDataForDataset($value, $handle, $entry_id)
 {
     $elementArray = formulize_getElementMetaData($handle, true);
     $ele_value = unserialize($elementArray['ele_value']);
     $listtype = key($ele_value[2]);
     if ($listtype === "{USERNAMES}" or $listtype === "{FULLNAMES}") {
         $uids = explode("*=+*:", $value);
         if (count($uids) > 0) {
             if (count($uids) > 1) {
                 array_shift($uids);
             }
             $uidFilter = extract_makeUidFilter($uids);
             $listtype = $listtype == "{USERNAMES}" ? 'uname' : 'name';
             $names = go("SELECT uname, name FROM " . DBPRE . "users WHERE {$uidFilter} ORDER BY {$listtype}");
             $value = "";
             foreach ($names as $thisname) {
                 if ($thisname[$listtype]) {
                     $value .= "*=+*:" . $thisname[$listtype];
                 } else {
                     $value .= "*=+*:" . $thisname['uname'];
                 }
             }
         } else {
             $value = "";
         }
     }
     return $value;
     // we're not making any modifications for this element type
 }
Beispiel #2
0
function prepvalues($value, $field, $entry_id)
{
    global $xoopsDB;
    // return metadata values without putting them in an array
    if (isMetaDataField($field)) {
        return $value;
    }
    $elementArray = formulize_getElementMetaData($field, true);
    $type = $elementArray['ele_type'];
    // handle yes/no cases
    if ($type == "yn") {
        // if we've found one
        if ($value == "1") {
            $value = _formulize_TEMP_QYES;
        } elseif ($value == "2") {
            $value = _formulize_TEMP_QNO;
        } else {
            $value = "";
        }
    }
    // decrypt encrypted values...pretty inefficient to do this here, one query in the DB per value to decrypt them....but we'd need proper select statements with field names specified in them, instead of *, in order to be able to swap in the AES DECRYPT at the time the data is retrieved in the master query
    if ($elementArray['ele_encrypt']) {
        $decryptSQL = "SELECT AES_DECRYPT('" . formulize_db_escape($value) . "', '" . getAESPassword() . "')";
        if ($decryptResult = $xoopsDB->query($decryptSQL)) {
            $decryptRow = $xoopsDB->fetchRow($decryptResult);
            return $decryptRow[0];
        } else {
            return "";
        }
    }
    // handle cases where the value is linked to another form
    if ($source_ele_value = formulize_isLinkedSelectBox($field, true)) {
        // value is an entry id in another form
        // need to get the form id by checking the ele_value[2] property of the element definition, to get the form id from the first part of that
        $sourceMeta = explode("#*=:*", $source_ele_value[2]);
        // [0] will be the fid of the form we're after, [1] is the handle of that element
        if ($value and $sourceMeta[1]) {
            // need to check if an alternative value field has been defined, or if we're in an export and an alterative field for exports has been defined
            // save the value before convertElementIdsToElementHandles()
            $before_conversion = $sourceMeta[1];
            $altFieldSource = "";
            if ($GLOBALS['formulize_doingExport'] and isset($source_ele_value[11]) and $source_ele_value[11] != "none") {
                $altFieldSource = $source_ele_value[11];
            } elseif (isset($source_ele_value[EV_MULTIPLE_LIST_COLUMNS]) and $source_ele_value[EV_MULTIPLE_LIST_COLUMNS] != "none") {
                $altFieldSource = $source_ele_value[EV_MULTIPLE_LIST_COLUMNS];
            }
            if ($altFieldSource) {
                $altFieldSource = is_array($altFieldSource) ? $altFieldSource : array($altFieldSource);
                $sourceMeta[1] = convertElementIdsToElementHandles($altFieldSource, $sourceMeta[0]);
                // remove empty entries, which can happen if the "use the linked field selected above" option is selected
                $sourceMeta[1] = array_filter($sourceMeta[1]);
                // unfortunately, sometimes sourceMeta[1] seems to be saved as element handles rather than element IDs, and in that case,
                // convertElementIdsToElementHandles() returns array(0 => 'none') which causes an error in the query below.
                // check for that case here and revert back to the value of sourceMeta[1] before convertElementIdsToElementHandles()
                if (1 == count($sourceMeta[1]) and isset($sourceMeta[1][0]) and "none" == $sourceMeta[1][0] or $sourceMeta[1] == "none") {
                    $sourceMeta[1] = $before_conversion;
                }
            }
            $form_handler = xoops_getmodulehandler('forms', 'formulize');
            $sourceFormObject = $form_handler->get($sourceMeta[0]);
            $sourceMeta[1] = is_array($sourceMeta[1]) ? $sourceMeta[1] : array($sourceMeta[1]);
            $query_columns = array();
            foreach ($sourceMeta[1] as $key => $handle) {
                // check if this is a link to a link
                if ($second_source_ele_value = formulize_isLinkedSelectBox($handle, true)) {
                    $secondSourceMeta = explode("#*=:*", $second_source_ele_value[2]);
                    $secondFormObject = $form_handler->get($secondSourceMeta[0]);
                    $sql = "SELECT t1.`" . $secondSourceMeta[1] . "` FROM " . DBPRE . "formulize_" . $secondFormObject->getVar('form_handle') . " as t1, " . DBPRE . "formulize_" . $sourceFormObject->getVar('form_handle') . " as t2 WHERE t2.`entry_id` IN (" . trim($value, ",") . ") AND t1.`entry_id` IN (TRIM(',' FROM t2.`" . $handle . "`)) ORDER BY t2.`entry_id`";
                    if (!($res = $xoopsDB->query($sql))) {
                        print "Error: could not retrieve the source values for a linked linked selectbox ({$field}) during data extraction for entry number {$entry_id}.  SQL:<br>{$sql}<br>";
                    } else {
                        $row = $xoopsDB->fetchRow($res);
                        $linkedvalue = prepvalues($row[0], $handle, $entry_id);
                        $query_columns[] = "'" . formulize_db_escape($linkedvalue[0]) . "'";
                    }
                } else {
                    $query_columns[] = "`{$handle}`";
                }
            }
            $sql = "SELECT " . implode(", ", $query_columns) . " FROM " . DBPRE . "formulize_" . $sourceFormObject->getVar('form_handle') . " WHERE entry_id IN (" . trim($value, ",") . ") ORDER BY entry_id";
            if (!($res = $xoopsDB->query($sql))) {
                print "Error: could not retrieve the source values for a linked selectbox during data extraction for entry number {$entry_id}.  SQL:<br>{$sql}<br>";
            } else {
                $value = "";
                while ($row = $xoopsDB->fetchRow($res)) {
                    $value .= "*=+*:" . implode(" - ", $row);
                }
            }
        } elseif ($value) {
            $value = "";
            // if there was no sourceMeta[1], which is the handle for the field in the source form, then the value should be empty, ie: we cannot make a link...this probably only happens in cases where there's a really old element that had its caption changed, and that happened before Formulize automatically updated all the linked selectboxes that rely on that element's caption, back when captions mattered in the pre F3 days
        }
    }
    // check if this is fullnames/usernames box
    // wickedly inefficient to go to DB for each value!!  This loop executes once per datapoint in the result set!!
    if ($type == "select") {
        $ele_value = unserialize($elementArray['ele_value']);
        if (is_array($ele_value[2])) {
            $listtype = key($ele_value[2]);
            if ($listtype === "{USERNAMES}" or $listtype === "{FULLNAMES}") {
                $uids = explode("*=+*:", $value);
                if (count($uids) > 0) {
                    if (count($uids) > 1) {
                        array_shift($uids);
                    }
                    $uidFilter = extract_makeUidFilter($uids);
                    $listtype = $listtype == "{USERNAMES}" ? 'uname' : 'name';
                    $value = "";
                    if (strlen($uidFilter) > 4) {
                        // skip this when $uidFilter = "uid=" becaues the query will fail
                        $names = go("SELECT uname, name FROM " . DBPRE . "users WHERE {$uidFilter} ORDER BY {$listtype}");
                        foreach ($names as $thisname) {
                            if ($thisname[$listtype]) {
                                $value .= "*=+*:" . $thisname[$listtype];
                            } else {
                                $value .= "*=+*:" . $thisname['uname'];
                            }
                        }
                    }
                } else {
                    $value = "";
                }
            }
        }
    }
    //and remove any leading *=+*: while we're at it...
    if (substr($value, 0, 5) == "*=+*:") {
        $value = substr_replace($value, "", 0, 5);
    }
    // Convert 'Other' options into the actual text the user typed
    if (($type == "radio" or $type == "checkbox") and preg_match('/\\{OTHER\\|+[0-9]+\\}/', $value)) {
        // convert ffcaption to regular and then query for id
        $realcap = str_replace("`", "'", $ffcaption);
        $newValueq = go("SELECT other_text FROM " . DBPRE . "formulize_other, " . DBPRE . "formulize WHERE " . DBPRE . "formulize_other.ele_id=" . DBPRE . "formulize.ele_id AND " . DBPRE . "formulize.ele_handle=\"" . formulize_db_escape($field) . "\" AND " . DBPRE . "formulize_other.id_req='" . intval($entry_id) . "' LIMIT 0,1");
        //$value_other = _formulize_OPT_OTHER . $newValueq[0]['other_text'];
        // removing the "Other: " part...we just want to show what people actually typed...doesn't have to be flagged specifically as an "other" value
        $value_other = $newValueq[0]['other_text'];
        $value = preg_replace('/\\{OTHER\\|+[0-9]+\\}/', $value_other, $value);
    } else {
        $value = formulize_swapUIText($value, unserialize($elementArray['ele_uitext']));
    }
    if (file_exists(XOOPS_ROOT_PATH . "/modules/formulize/class/" . $type . "Element.php")) {
        $elementTypeHandler = xoops_getmodulehandler($type . "Element", "formulize");
        $preppedValue = $elementTypeHandler->prepareDataForDataset($value, $field, $entry_id);
        if (!is_array($preppedValue)) {
            return array($preppedValue);
        } else {
            return $preppedValue;
        }
    }
    return explode("*=+*:", $value);
}