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");
}
 function formulize_disableElement($element, $type, $ele_desc)
 {
     if ($type == "text" or $type == "textarea" or $type == "date" or $type == "colorpick") {
         $newElement = new xoopsFormElementTray($element->getCaption(), "\n");
         $newElement->setName($element->getName());
         switch ($type) {
             case 'date':
                 if ($timeval = $element->getValue()) {
                     if (is_string($timeval)) {
                         $timeval = strtotime($timeval);
                     }
                     $hiddenValue = date(_SHORTDATESTRING, $timeval);
                 } else {
                     $hiddenValue = "";
                 }
                 break;
             default:
                 // should work for all elements, since non-textbox type elements where the value would not be passed straight back, are handled differently at the time they are constructed
                 $hiddenValue = formulize_numberFormat($element->getValue(), $this->_ele->getVar('ele_handle'));
         }
         if (is_array($hiddenValue)) {
             // not sure when/if this would ever happen
             foreach ($hiddenValue as $value) {
                 $newElement->addElement(new xoopsFormHidden($element->getName() . "[]", $value));
                 unset($value);
             }
             $newElement->addElement(new xoopsFormLabel('', implode(", ", $hiddenValue)));
         } else {
             $newElement->addElement(new xoopsFormHidden($element->getName(), $hiddenValue));
             $newElement->addElement(new xoopsFormLabel('', $hiddenValue));
         }
         if (substr($element->getName(), 0, 9) != "desubform") {
             // we should consider not having a cue at all for any disabled elements, but we're not going to pull it out just yet...more investigation of this is necessary
             $newElement->addElement(new xoopsFormHidden("decue_" . trim($element->getName(), "de_"), 1));
         }
         $newElement->setDescription(html_entity_decode($ele_desc, ENT_QUOTES));
         return $newElement;
     } else {
         return $element;
     }
 }
Example #3
0
function getHTMLForList($value, $handle, $entryId, $deDisplay = 0, $textWidth = 200, $localIds = array(), $fid, $row, $column)
{
    $output = "";
    if (!is_array($value)) {
        $value = array($value);
    }
    if (!is_array($localIds)) {
        $localIds = array($localIds);
    }
    $countOfValue = count($value);
    $counter = 1;
    static $cachedFormIds = array();
    static $cachedElementIds = array();
    static $cached_object_type = array();
    if (!isset($cachedFormIds[$handle])) {
        if ($handle == "mod_datetime" or $handle == "creation_datetime" or $handle == "creator_email") {
            $cachedFormIds[$handle] = $fid;
            $cachedElementIds[$handle] = $handle;
            $cached_object_type[$handle] = "email";
            if ($handle == "mod_datetime" or $handle == "creation_datetime") {
                $cached_object_type[$handle] = "date";
            }
        } else {
            $element_handler = xoops_getmodulehandler('elements', 'formulize');
            $elementObject = $element_handler->get($handle);
            $cachedFormIds[$handle] = $elementObject->getVar('id_form');
            $cachedElementIds[$handle] = $elementObject->getVar('ele_id');
            $cached_object_type[$handle] = $elementObject->getVar('ele_type');
        }
    }
    $fid = $cachedFormIds[$handle];
    $element_type = $cached_object_type[$handle];
    foreach ($value as $valueId => $v) {
        if (is_numeric($v)) {
            $elstyle = 'style="text-align: right;"';
        }
        $thisEntryId = isset($localIds[$valueId]) ? $localIds[$valueId] : $entryId;
        if ($counter == 1 and $deDisplay) {
            $output .= '<div style="float: left; margin-right: 5px; margin-bottom: 5px;"><a href="" onclick="javascript:renderElement(\'' . $handle . '\', ' . $cachedElementIds[$handle] . ', ' . $thisEntryId . ', ' . $fid . ');return false;"><img src="' . XOOPS_URL . '/modules/formulize/images/kedit.gif" /></a></div>';
        }
        if ("date" == $element_type) {
            $time_value = strtotime($v);
            $v = false === $time_value ? "" : date(_SHORTDATESTRING, $time_value);
        }
        $output .= '<div class=\'main-cell-div\' id=\'cellcontents_' . $row . '_' . $column . '\'><span ' . $elstyle . '>' . formulize_numberFormat(str_replace("\n", "<br>", formatLinks($v, $handle, $textWidth, $thisEntryId)), $handle) . '</span>';
        if ($counter < $countOfValue) {
            $output .= "<br>";
        }
        $counter++;
    }
    if ($output) {
        $output .= "</div>";
    }
    return $output;
}