/** * Automated report setup. Establishes all hardcoded * defaults, all overrides from YAML file, captions, column * sizes, page orientation, and so forth and so on. * * @param string $yamlP2 The processed page definition * @since 12/16/07 */ function mainSetup($yamlP2) { // Default UOM is points, so these are 1/2 inch margins $this->margin_left = 36; $this->margin_top = 36; $this->SetMargins($this->margin_left, $this->margin_top); // Set defaults. As of 1/20/08 they are all hardcoded, but // the idea is to let them be set in the YAML file. $this->fontname = 'Arial'; $this->fontsize = 12; $this->linespacing = 1; $this->cpi = 120 / $this->fontsize; $this->lineheight = $this->fontsize * $this->linespacing; // Pull options from Yamlp2 $this->title1 = $yamlP2['options']['title']; // Determine if there are filters to list: $uifilters = ArraySafe($yamlP2, 'uifilter', array()); $atitle2 = array(); foreach ($uifilters as $name => $info) { $atitle2[] = $info['description'] . ':' . trim(gp('ap_' . $name)); } $this->title2 = count($atitle2) == 0 ? '' : implode(", ", $atitle2); // Tell the fpdf parent class about our setting choices $this->SetTextColor(0, 0, 0); $this->SetFont($this->fontname); $this->SetFontSize($this->fontsize); // Set up titles and columns by looping through and figuring // out justification and size $setupArr = array(); $width = 0; foreach ($yamlP2['table'] as $table => $columns) { $dd = dd_tableRef($table); foreach ($columns['column'] as $colname => $colinfo) { if (ArraySafe($colinfo, 'uino', 'N') == 'Y') { continue; } // Use type to figure out if right or left $type_id = $dd['flat'][$colname]['type_id']; $suffix = ''; if (in_array(trim($type_id), array('money', 'numb', 'int'))) { $suffix .= ':R'; $suffix .= ':' . trim($dd['flat'][$colname]['colscale']); } if (trim($type_id) == 'money') { $suffix .= ':M'; } if (ArraySafe($colinfo, 'dispsize', '') != '') { $suffix .= ':C' . $colinfo['dispsize']; } // Work out size using cpi setting $dispsize = ArraySafe($colinfo, 'dispsize', ''); $dispsize = $dispsize != '' ? $dispsize : $dd['flat'][$colname]['dispsize']; $setupArr[] = round($dispsize / $this->cpi, 1) . $suffix; $width += $dispsize * $this->cpi + 0.1; // Save the captions for displaying in header $caption = ArraySafe($colinfo, 'description', ''); $caption = $caption != '' ? $caption : $dd['flat'][$colname]['description']; $this->captions[] = $caption; } } $this->setupColumns(0.1, implode(',', $setupArr)); // Finally, establish orientation by looking at size of report if ($width / 72 < 7.5) { $this->orientation = 'P'; } else { $this->orientation = 'L'; } }
/** */ function hSelectFiltered($table_id, $columns, $name = '', $selected = '', $extra = '', $failsafe = array()) { // Make an empty select to return on failure // Get the correct table_id $table_id_resolved = DDTable_IDResolve($table_id); // Send this if we fail; $failed = count($failsafe) > 0 ? hSelectFromAA($failsafe, $name, $selected, $extra) : hSelect($name, $selected, '', $extra); // Quit on obvious problem if (count($columns) == 0 || !$table_id) { return $failed; } // Find out what column we are missing // And generate the where clause for the upcoming select $dd_ref = dd_tableRef($table_id); $pkeys = explode(',', $dd_ref['pks']); $missing = array(); $where = array(); foreach ($pkeys as $index => $pkey) { if (isset($columns[$pkey])) { $where[] = $pkey . " = '" . $columns[$pkey] . "'"; } else { $missing[] = $pkey; } } $where = implode(' AND ', $where); // Quit if we are not missing exactly 1 column if (count($missing) != 1) { return $failed; } $missing = implode($missing, ','); // Find the possible values of the missing key $possible_sq = "SELECT distinct {$missing}\n FROM {$table_id_resolved}\n WHERE {$where}"; $possibles = SQL_AllRows($possible_sq, $missing); $retval = $failsafe; // Let's rearrange the array to hand it to hSelectFromAA foreach ($possibles as $val => $aMissing) { $retval[$val] = $val; } return hSelectFromAA($retval, $name, $selected, $extra); exit; }