Пример #1
0
function printResults($masterResults, $blankSettings, $groupingSettings, $groupingValues, $masterResultsRaw, $filename = "", $title = "")
{
    $output = "";
    foreach ($masterResults as $elementId => $calcs) {
        $output .= "<tr><td class=head colspan=2>\n";
        $output .= printSmart(trans(getCalcHandleText($elementId)), 100);
        $output .= "\n</td></tr>\n";
        foreach ($calcs as $calc => $groups) {
            $countGroups = count($groups);
            $rowspan = ($countGroups > 1 and $calc != "count" and $calc != "sum") ? $countGroups : 1;
            $output .= "<tr><td class=even rowspan={$rowspan}>\n";
            // start of row with calculation results (possibly first row among many)
            switch ($calc) {
                case "sum":
                    $calc_name = _formulize_DE_CALC_SUM;
                    break;
                case "avg":
                    $calc_name = _formulize_DE_CALC_AVG;
                    break;
                case "min":
                    $calc_name = _formulize_DE_CALC_MIN;
                    break;
                case "max":
                    $calc_name = _formulize_DE_CALC_MAX;
                    break;
                case "count":
                    $calc_name = _formulize_DE_CALC_COUNT;
                    break;
                case "per":
                    $calc_name = _formulize_DE_CALC_PER;
                    break;
            }
            $output .= "<p><b>{$calc_name}</b></p>\n";
            switch ($blankSettings[$elementId][$calc]) {
                case "all":
                    $bsetting = _formulize_DE_INCLBLANKS;
                    break;
                case "noblanks":
                    $bsetting = _formulize_DE_EXCLBLANKS;
                    break;
                case "onlyblanks":
                    $bsetting = _formulize_DE_INCLONLYBLANKS;
                    break;
                case "justnoblanks":
                    $bsetting = _formulize_DE_EXCLONLYBLANKS;
                    break;
                case "justnozeros":
                    $bsetting = _formulize_DE_EXCLONLYZEROS;
                    break;
                default:
                    // must be custom
                    $bsetting = _formulize_DE_EXCLCUSTOM;
                    $setting = explode(",", substr(str_replace("!@^%*", ",", $blankSettings[$elementId][$calc]), 6));
                    // replace back the commas and remove the word custom from the front, and explode it into an array
                    $start = 1;
                    foreach ($setting as $thissetting) {
                        if (!$start) {
                            $bsetting .= ", ";
                        }
                        $start = 0;
                        if (substr($thissetting, 0, 1) == "!") {
                            $notText = strtolower(_formulize_NOT) . " ";
                            $thissetting = substr($thissetting, 1);
                        } else {
                            $notText = "";
                        }
                        $bsetting .= $notText . $thissetting;
                    }
                    break;
            }
            $output .= "<p class='formulize_blank_setting'>{$bsetting}</p>\n</td>\n";
            // start of right hand column for calculation results
            if ($calc == "count") {
                $output .= "<td class=odd>\n";
                // start of cell with calculations results
                if ($countGroups > 1) {
                    $theseGroupSettings = explode("!@^%*", $groupingSettings[$elementId][$calc]);
                    $firstGroupSettingText = printSmart(trans(getCalcHandleText($theseGroupSettings[0], true)));
                    $output .= "<table style='width: auto;'><tr><th>{$firstGroupSettingText}</th><td class='count-total' style='padding-left: 2em;'><center><b>" . _formulize_DE_CALC_NUMENTRIES . "</b><center></td><td class='count-unique' style='padding-left: 2em;'><center><b>" . _formulize_DE_CALC_NUMUNIQUE . "</b><center></td></tr>\n";
                    $totalCount = 0;
                    $totalUnique = 0;
                    foreach ($masterResultsRaw[$elementId][$calc] as $group => $rawResult) {
                        foreach ($theseGroupSettings as $id => $thisGroupSetting) {
                            if ($thisGroupSetting === "none") {
                                continue;
                            }
                            $elementMetaData = formulize_getElementMetaData($thisGroupSetting, false);
                            $groupText = formulize_swapUIText($groupingValues[$elementId][$calc][$group][$id], unserialize($elementMetaData['ele_uitext']));
                            $output .= "<tr><td>" . printSmart(trans($groupText)) . "</td><td class='count-total' style='text-align: right;'>" . $rawResult['count'] . "</td><td class='count-unique' style='text-align: right;'>" . $rawResult['countunique'] . "</td></tr>";
                            $totalCount += $rawResult['count'];
                            $totalUnique += $rawResult['countunique'];
                        }
                    }
                    $output .= "<tr><td style='border-top: 1px solid black;'><b>" . _formulize_DE_CALC_GRANDTOTAL . "</b></td><td style='border-top: 1px solid black; text-align: right;' class='count-total'><b>{$totalCount}</b></td><td style='border-top: 1px solid black; text-align: right;' class='count-unique'><b>{$totalUnique}</b></td></tr>\n";
                    $output .= "</table>";
                } else {
                    $rawResult = $masterResultsRaw[$elementId][$calc][0];
                    $output .= "<div class='count-total'><p><b>" . _formulize_DE_CALC_NUMENTRIES . " . . . " . $rawResult['count'] . "</b></p></div><div class='count-unique'><p><b>" . _formulize_DE_CALC_NUMUNIQUE . " . . . " . $rawResult['countunique'] . "</b></p></div>\n";
                }
                $output .= "</td></tr>";
                // end of the main row, and the specific cell with the calculations results
            } elseif ($calc == "sum") {
                $output .= "<td class=odd>\n";
                // start of cell with calculations results
                $handle = convertElementIdsToElementHandles($elementId);
                // returns an array, since it might be passed multiple values
                $handle = $handle[0];
                if ($countGroups > 1) {
                    $theseGroupSettings = explode("!@^%*", $groupingSettings[$elementId][$calc]);
                    $firstGroupSettingText = printSmart(trans(getCalcHandleText($theseGroupSettings[0], true)));
                    $output .= "<table style='width: auto;'><tr><th>{$firstGroupSettingText}</th><td class='sum-total' style='padding-left: 2em;'><center><b>" . _formulize_DE_CALC_SUM . "</b><center></td></tr>\n";
                    $totalSum = 0;
                    foreach ($masterResultsRaw[$elementId][$calc] as $group => $rawResult) {
                        foreach ($theseGroupSettings as $id => $thisGroupSetting) {
                            if ($thisGroupSetting === "none") {
                                continue;
                            }
                            $elementMetaData = formulize_getElementMetaData($thisGroupSetting, false);
                            $groupText = formulize_swapUIText($groupingValues[$elementId][$calc][$group][$id], unserialize($elementMetaData['ele_uitext']));
                            $output .= "<tr><td>" . printSmart(trans($groupText)) . "</td><td class='sum-total' style='text-align: right;'>" . formulize_numberFormat($rawResult['sum'], $handle) . "</td></tr>";
                            $totalSum += $rawResult['sum'];
                        }
                    }
                    $output .= "<tr><td style='border-top: 1px solid black;'><b>" . _formulize_DE_CALC_GRANDTOTAL . "</b></td><td style='border-top: 1px solid black; text-align: right;' class='sum-total'><b>" . formulize_numberFormat($totalSum, $handle) . "</b></td></tr>\n";
                    $output .= "</table>";
                } else {
                    $rawResult = $masterResultsRaw[$elementId][$calc][0];
                    $output .= "<div class='sum-total'><p><b>" . _formulize_DE_CALC_SUM . " . . . " . formulize_numberFormat($rawResult['sum'], $handle) . "</b></p></div>\n";
                }
                $output .= "</td></tr>";
                // end of the main row, and the specific cell with the calculations results
            } else {
                $start = 1;
                foreach ($groups as $group => $result) {
                    //foreach($result as $resultID=>$thisResult) {
                    if (!$start) {
                        $output .= "<tr>\n";
                    }
                    $start = 0;
                    $output .= "<td class=odd>\n";
                    //if(count($groups)>1) { // OR count($groups)>1) { // output the heading section for this group of results
                    $output .= "<p><b>";
                    $start2 = true;
                    foreach (explode("!@^%*", $groupingSettings[$elementId][$calc]) as $id => $thisGroupSetting) {
                        if ($thisGroupSetting === "none") {
                            continue;
                        }
                        if (!$start2) {
                            $output .= "<br>\n";
                        }
                        $start2 = false;
                        $elementMetaData = formulize_getElementMetaData($thisGroupSetting, false);
                        $groupText = formulize_swapUIText($groupingValues[$elementId][$calc][$group][$id], unserialize($elementMetaData['ele_uitext']));
                        $output .= printSmart(trans(getCalcHandleText($thisGroupSetting, true))) . ": " . printSmart(trans($groupText)) . "\n";
                    }
                    $output .= "</b></p>\n";
                    //}
                    $output .= "<p>{$result}</p>\n";
                    $output .= "</td></tr>\n";
                    //}
                }
            }
        }
    }
    print $output;
    // addition of calculation download, August 22 2006
    if ($filename) {
        // get the current CSS values for head, even and odd
        global $xoopsConfig;
        $head = "";
        $odd = "";
        $even = "";
        formulize_benchmark("before reading stylesheet");
        if (file_exists(XOOPS_ROOT_PATH . "/themes/" . $xoopsConfig['theme_set'] . "/style.css")) {
            if (!class_exists('csstidy')) {
                // use supplied csstidy in parent if one exists...
                if (file_exists(XOOPS_ROOT_PATH . "/plugins/csstidy/class.csstidy.php")) {
                    include_once XOOPS_ROOT_PATH . "/plugins/csstidy/class.csstidy.php";
                } else {
                    include_once XOOPS_ROOT_PATH . "/modules/formulize/class/class.csstidy.php";
                }
            }
            $css = new csstidy();
            $css->set_cfg('merge_selectors', 0);
            $css->parse_from_url(XOOPS_ROOT_PATH . "/themes/" . $xoopsConfig['theme_set'] . "/style.css");
            $parsed_css = $css->css;
            // parsed_css seems to have only one key when looking at the default template...key is the number of styles?
            foreach ($parsed_css as $thiscss) {
                $head = isset($thiscss['.head']['background-color']) ? $thiscss['.head']['background-color'] : isset($thiscss['.head']['background']) ? $thiscss['.head']['background'] : "";
                $even = isset($thiscss['.even']['background-color']) ? $thiscss['.even']['background-color'] : isset($thiscss['.even']['background']) ? $thiscss['.even']['background'] : "";
                $odd = isset($thiscss['.odd']['background-color']) ? $thiscss['.odd']['background-color'] : isset($thiscss['.odd']['background']) ? $thiscss['.odd']['background'] : "";
            }
        }
        formulize_benchmark("after reading stylesheet");
        unset($css);
        // if we couldn't find any values, use these:
        $head = $head ? $head : "#c2cdd6";
        $even = $even ? $even : "#dee3e7";
        $odd = $odd ? $odd : "#E9E9E9";
        // create the file
        formulize_benchmark("before creating file");
        $outputfile = "<HTML>\n<head>\n<meta name=\"generator\" content=\"Formulize -- form creation and data management for XOOPS\" />\n<title>" . _formulize_DE_EXPORTCALC_TITLE . " '{$title}'</title>\n<style type=\"text/css\">\n.outer {border: 1px solid silver;}\n.head { background-color: {$head}; padding: 5px; font-weight: bold; }\n.even { background-color: {$even}; padding: 5px; }\t\t\n.odd { background-color: {$odd}; padding: 5px; }\nbody {color: black; background: white; margin-top: 30px; margin-bottom: 30px; margin-left: 30px; margin-right: 30px; padding: 0; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt;}\ntd { vertical-align: top; }\n</style>\n</head>\n<body>\n<h1>" . _formulize_DE_EXPORTCALC_TITLE . " '{$title}'</h1>\n<table class=outer>\n{$output}\n</table>\n</body>\n</html>";
        // output the file
        $exfilename = strrchr($filename, "/");
        $wpath = XOOPS_ROOT_PATH . SPREADSHEET_EXPORT_FOLDER . "{$exfilename}";
        $exportfile = fopen($wpath, "w");
        fwrite($exportfile, $outputfile);
        fclose($exportfile);
    }
    formulize_benchmark("after creating file");
}
Пример #2
0
function writableQuery($items, $mod = "")
{
    for ($i = 0; $i < count($items); $i++) {
        unset($temp_text);
        if (substr($items['as_' . $i], 0, 7) == "[field]" and substr($items['as_' . $i], -8) == "[/field]") {
            // a field has been found
            $fieldLen = strlen($items['as_' . $i]);
            $items['as_' . $i] = substr($items['as_' . $i], 7, $fieldLen - 15);
            // 15 is the length of [field][/field]
            $temp_text = getCalcHandleText($items['as_' . $i], true);
            // last param forces colhead
            if (strlen($temp_text) > 20) {
                $items['as_' . $i] = "<a href=\"\" alt=\"" . trans($temp_text) . "\" title=\"" . trans($temp_text) . "\" onclick=\"javascript:return false;\">" . printSmart(trans($temp_text), "20") . "</a>";
            } else {
                $items['as_' . $i] = trans($temp_text);
            }
        } elseif ($items['as_' . $i] == "==") {
            $items['as_' . $i] = "=";
        } elseif ($items['as_' . $i] == "!=") {
            $items['as_' . $i] = " NOT ";
        } elseif ($items['as_' . $i] == "NOT") {
            $items['as_' . $i] = " NOT ";
        } elseif ($items['as_' . $i] == "AND") {
            $items['as_' . $i] = " AND ";
        } elseif ($items['as_' . $i] == "OR") {
            $items['as_' . $i] = " OR ";
        } elseif ($items['as_' . $i] == "LIKE") {
            $items['as_' . $i] = " LIKE ";
        } elseif ($items['as_' . $i] == "NOT LIKE") {
            $items['as_' . $i] = " NOT LIKE ";
        } elseif ($items['as_' . $i] == "{USER}" and $mod != 1) {
            global $xoopsUser;
            $term = $xoopsUser->getVar('name');
            if (!$term) {
                $term = $xoopsUser->getVar('uname');
            }
            $items['as_' . $i] = $term;
        } elseif ($items['as_' . $i] == "{BLANK}" and $mod != 1) {
            $items['as_' . $i] = "\" \"";
        } elseif (ereg_replace("[^A-Z{}]", "", $items['as_' . $i]) == "{TODAY}" and $mod != 1) {
            $number = ereg_replace("[^0-9+-]", "", $items['as_' . $i]);
            $items['as_' . $i] = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + $number, date("Y")));
        }
        $item_to_write = stripslashes($items['as_' . $i]);
        if (strlen($item_to_write) > 20 and !$temp_text) {
            $item_to_write = "<a href=\"\" alt=\"" . $items['as_' . $i] . "\" title=\"" . $items['as_' . $i] . "\" onclick=\"javascript:return false;\">" . printSmart($item_to_write, "20") . "</a>";
        }
        $qstring .= $item_to_write;
    }
    return $qstring;
}