⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runreport.php

📁 jsp程序开发系统
💻 PHP
📖 第 1 页 / 共 4 页
字号:

	if ($data2) { // Two-axis processing
		// Draw the heading row (X axis)
		$html .= "<tr><td bgcolor=\"#FFFF99\">&nbsp;</td>\n";
		foreach ($data2 AS $key1 => $var1) {
			$html .= "<td bgcolor=\"#FFFFCC\"><b>$key1</b></td>";
			$cols[$key1] = 1;
		}
		$html .= "</tr>\n";
	
		$rowdata = 0;
		// Now figure out what rows we've got
		foreach ($data2 AS $key1 => $var1) {
			if (is_array($var1)) {
				foreach ($var1 AS $key2 => $var2) {
					$rows[$key2] = 1;
					$rowdata = 1;
				}
			}
		}

		// Now render the table
		if (!$rowdata) { // Another way out, just in case there aren't any tickets matched in any row
			$html = "<font size=\"+1\" $tc><B>$stat[title]</B></font><br />\n<font $dc><b>$stat[description]</b></font><br />\n<br />\n";
			$html .= "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td bgcolor=\"#000000\"><table cellspacing=\"1\" cellpadding=\"3\">";
			$html .= "<td bgcolor=\"#FFFF99\">No tickets found</td></tr></table></td></tr></table>";
			return $html;
		}

		// Generate each row of the table.
		foreach ($rows AS $key1 => $val1) {
			$html .= "<tr>";
			if (!$key1) {
				$key1 = "<I>None Assigned</I>";
			}
			$html .= "<td bgcolor=\"#FFFFCC\" align=\"right\"><B>$key1</B></td>\n";
			foreach ($cols AS $key2 => $val2) {
				if ($data2[$key2][$key1]) {
					$html .= "<td bgcolor=\"#FFFFFF\">" . $data2[$key2][$key1] . "</td>\n";
				} else {
					$html .= "<td bgcolor=\"#FFFFFF\"><font color=\"gray\">0</font></td>\n";
				}
				$colnum++;
			}
			$html .= "</tr>";
		}
		$html .= "</table></td></tr></table>";
	} else {
		// 1-axis processing.
		foreach ($data AS $key => $var) {
			if (!$key) {
				$key = "<I>None Assigned</I>";
			}
			$html .= "<tr><td bgcolor=\"#FFFFCC\"><b>$key</b></td><td bgcolor=\"#FFFFFF\">$var tickets</td></tr>";
		}
		$html .= "</table></td></tr></table>";
	}
	return $html;
}

// ============================================
// Function make_csv
// ============================================
// Generates a CSV file containing the
// number of tickets matched per grouping
// during the reporting run.
// ============================================
// Arguments:
// 		data	First series of data
//		data2	First and second series of data
//		stat	Statistic definition from DB
// ============================================
// Returns:
//		The CSV data.
// ============================================

function make_csv($data = NULL, $data2 = NULL, $stat) {
	if ((!$data) AND (!$data2)) { // If it's an empty data set, return an empty table
		return "No tickets found.";
	}

	if ($data2) {
		$headers = array('"Labels"');
		// Draw the heading row (X axis)
		foreach ($data2 AS $key1 => $var1) {
			$headers[] = "\"$key1\"";
			$cols[$key1] = 1;
		}
		$ret = join(',',$headers) . "\n\n";

		// Now figure out what rows we've got
		foreach ($data2 AS $key1 => $var1) {
			foreach ($var1 AS $key2 => $var2) {
				$rows[$key2] = 1;
			}
		}
	
		// Now produce the records
		foreach ($rows AS $key1 => $val1) {
			$row = array();
			$row[] = "\"$key1\"";
			foreach ($cols AS $key2 => $val2) {
				if ($data2[$key2][$key1]) {
					$row[] = '"' . $data2[$key2][$key1] . '"';
				} else {
					$row[] = '"0"';
				}
				$colnum++;
			}
			$ret .= join(',',$row) . "\n";
		}
	} else {
		$headers = array();
		$row = array();
		foreach ($data AS $key => $var) {
			$headers[] = "\"$key\"";
			$row[] = "\"$var\"";
		}
		$ret .= join(',',$headers);
		$ret .= "\n\n";
		$ret .= join(',',$row);
	}
	return $ret;
}

// ============================================
// Function make_pdf_table
// ============================================
// Generates a PDF table showing the
// number of tickets matched per grouping
// during the reporting run.
// ============================================
// Arguments:
// 		data	First series of data
//		data2	First and second series of data
//		stat	Statistic definition from DB
// ============================================
// Returns:
//		Nothing; directly adds to the PDF
//		object.
// ============================================

function make_pdf_table($data = NULL, $data2 = NULL, $stat) {
	global $pdf;
	$pdf->SetFont('Times', 'B', 20);
	$pdf->Write(8, trim($stat['title'])."\n");
	$pdf->SetFontSize(12);
	$pdf->Write(6, trim($stat['description'])."\n");

	if ((!$data) AND (!$data2)) { // If it's an empty data set, return an empty table
		$pdf->SetFont('Arial', 'B', 10);
		$width = $pdf->GetStringWidth('No tickets found');
		$pdf->SetFillColor(255, 255, 200);
		$pdf->Cell($width+2, 5, 'No tickets found', 1, 1, 'C', 1);
		return;
	}

	if ($data2) { // 2-axis processing.
		$table = array();
		// Load the heading row (X axis) array
		$pdf->SetFont('Arial', 'B', 10);
		$col[] = '';
		$widths[] = $pdf->GetStringWidth('');
		foreach ($data2 AS $key1 => $var1) {
			$col[] = $key1;
			$widths[] = $pdf->GetStringWidth($key1);
			$table[0] = $col;
		}

		// Load the heading column (Y axis) helper array
		foreach ($data2 AS $key1 => $var1) {
			if (is_array($var1)) {
				foreach ($var1 AS $key2 => $var2) {
					$rows[$key2] = 1;
				}
			}
		}

		if (!is_array($rows)) { // Another way out, just in case there aren't any tickets matched in any row
			$pdf->SetFont('Arial', 'B', 10);
			$width = $pdf->GetStringWidth('No tickets found');
			$pdf->SetFillColor(255, 255, 200);
			$pdf->Cell($width+2, 5, 'No tickets found', 1, 1, 'C', 1);
			return $html;
		}
	
		// Load the table array
		foreach ($rows AS $key1 => $val1) {
			$colnum = 0;
			unset($row);
			$width = $pdf->GetStringWidth($key1);
			if ($width > $widths[0]) {
				$widths[0] = $width;
			}
			$row[] = $key1;
			array_shift($col);
			foreach ($col AS $key2 => $val2) {
				if ($data2[$val2][$key1]) {
					$val = $data2[$val2][$key1];
				} else {
					$val = 'None';
				}
				if ($colnum) { // regular cell
					$pdf->SetFont('Arial', '', 10);
				} else { // heading column
					$pdf->SetFont('Arial', 'B', 10);
				}
				$width = $pdf->GetStringWidth($val);
				if ($width > $widths[$colnum]) {
					$widths[$colnum] = $width;
				}
				$row[] = $val;
			}
			array_unshift($col, '');
			$table[] = $row;
		}

		// Render the table
		
		$maxwidth = 195;
		if (array_sum($widths) > $maxwidth) { 
			
			// If the total width of all columns is greater than the page's
			// width, we have to truncate.

			$maxcol = 0;
			$totwid = 0;
			foreach ($widths AS $key => $val) {
				$totwid = $totwid + $val;
				if ($totwid <= $maxwidth) {
					$maxcol++;
				} else {
					$maxwidth = 0;
				}
			}
		}

		// Render the heading row
		$headings = array_shift($table);
		$pdf->SetFont('Arial', 'B', 10);
		$pdf->SetFillColor(255,255,200);
		$colnum = 0;
		foreach ($headings as $key => $val) {
			if ((($colnum+1) < $maxcol) OR (!$maxcol)) {
				$pdf->Cell($widths[$colnum]+2, 4.5, $val, 1, 0, 'C', 1);
				$colnum++;
			}
		}
		$pdf->Ln();

		// Render the remaining rows
		$pdf->SetFillColor(220,220,220);
		$fill = 0;
		foreach ($table as $key => $val) {
			$cell = array_shift($val);
			$pdf->SetFont('Arial', 'B', 10);
			$pdf->Cell($widths[0]+2, 4.5, $cell, 1, 0, 'R', $fill);
			$pdf->SetFont('Arial', '', 10);
			$colnum = 1;
			foreach ($val as $key => $val2) {
				if ((($colnum+1) < $maxcol) OR (!$maxcol)) {
					if ($val2) {
						$pdf->Cell($widths[$colnum]+2, 4.5, $val2, 1, 0, 'C', $fill);
					} else {
						$pdf->SetFont('Arial', 'I', 10);
						$pdf->Cell($widths[$colnum]+2, 4.5, 'None', 1, 0, 'C', $fill);
						$pdf->SetFont('Arial', '', 10);
					}
					$colnum++;
				}
			}
			$pdf->Ln();
			$fill=!$fill;
		}
	} else { // 1-axis processing.
		// Calculate widths
		$widths = array();
		foreach ($data AS $key => $val) {
			if (!$key) {
				$key = "None";
			}

			$pdf->SetFont('Arial', 'B', 10);
			$width = $pdf->GetStringWidth($key);
			if ($width > $widths[0]) {
				$widths[0] = $width;
			}

			$pdf->SetFont('Arial', '', 10);
			$width = $pdf->GetStringWidth($val);
			if ($width > $widths[1]) {
				$widths[1] = $width;
			}
		}
		
		// Render table
		$pdf->SetFillColor(255,255,200);
		foreach ($data AS $key => $val) {
			$pdf->Cell($widths[0]+2, 4.5, $key, 1, 0, 'R', 1);
			$pdf->Cell($widths[1]+2, 4.5, $val, 1, 1, 'L', 1);
		}
	}
	$pdf->Ln();
	return;
}

// ============================================
// Function make_pdf_appendix
// ============================================
// Generates a PDF table containing a list of
// all tickets matched during the reporting run
// ============================================
// Arguments:
// 		appendix	List of ticket numbers in
//					the appendix
//		appendix_fields
//					List of fields to show in
//					the appendix
//		change		Column or row name mappings
//					to use.
// ============================================
// Returns:
//		Nothing; adds to the PDF object
// ============================================

function make_pdf_appendix($appendix, $appendix_fields = NULL, $change = array()) {
	global $db, $pdf, $tfields, $tfields_names;
	$pdf->SetFont('Arial', 'B', 10);
	$fields = explode(',', $appendix_fields);
	$total = count($fields);
	if ($appendix_fields AND count($appendix)) {
		$appendix = array2sql($appendix);

		foreach ($fields as $key => $var) {
			if ($var == 'user') {
				$fields[$key] = 'userid';
			}
		}

		$appendix_fields = join(',', $fields);

		$db->query(
			"SELECT id, $appendix_fields
			FROM ticket
			WHERE id IN $appendix
			");
	
		// Run through the result set.

		if ($db->num_rows()) {
			$colnum = 0;
			$total++;
			$tickets = $db->num_rows();
			$row = array();
			foreach($fields as $key => $val) {
				switch ($val) {
					case 'subject': $label = 'Subject'; break;
					case 'priority' : $label = 'Priority'; break;
					case 'tech' : $label = 'Technician'; break;
					case 'is_open' : $label = 'Open/Closed'; break;
					case 'awaiting_tech' : $label = 'Awaiting...'; break;
					case 'userid' : $label = 'User'; break;
					case 'category' : $label = 'Category'; break;
					case 'id' : next; break;
					default: $label = $val;
				}
				if (stristr($val, 'custom')) {
					$label = $tfields_names[$val];
				}
				$row[] = $label;
				$widths[$colnum] = $pdf->GetStringWidth($label);
				$colnum++;
			}
			$table[] = $row;
			$row = array();

			$pdf->SetFont('Arial', '', 10);
			while ($result = $db->row_array()) {
				$row = array();
				$colnum = 0;
				foreach($fields as $key => $val) {
					switch ($val) {
						case 'id':
							next;
							break;
						case 'subject':
							if ($result[$val]) {
								$result[$val] = $result[$val];
							} else {
								$result[$val] = "None";
							}
							break;
						case 'category': $result[$val] = $change['category'][$result[$val]]; break;
						case 'priority': $result[$val] = $change['priority'][$result[$val]]; break;
						case 'tech': 
							if ($result[$val]) {
								$result[$val] = $change['tech'][$result[$val]];
							} else {
								$result[$val] = "None";
							}
							break;
						case 'userid': 
							if ($result[$val]) {
								$result[$val] = $change['userid'][$result[$val]];
							} else {
								$result[$val] = "<I>None</I>";
							}
							break;
						case 'is_open': $result[$val] = $change['is_open'][$result[$val]]; break;
						case 'awaiting_tech': $result[$val] = $change['awaiting_tech'][$result[$val]]; break;
					}
					if (stristr($val, 'custom')) {
						$items = explode('|||', $result[$val]);
						$tmptitle = array();
						foreach ($items AS $ikey => $ival) {
							if (is_array($tfields[$val])) {
								foreach ($tfields[$val] AS $tkey => $tval) {
									if ($tval[0] == $ival) {
										$tmptitle[] = $tval[2];
									}
								}
							}
						}
						$result[$val] = join(', ', $tmptitle);
					}
					$row[] = $result[$val];
					$width = $pdf->GetStringWidth($result[$val]);
					if ($width > $widths[$colnum]) {
						$widths[$colnum] = $width;
					}
					$colnum++;
				}
				$table[] = $row;
			}

			// "Letter" size paper is 215.9 mm wide, defaults to 10mm margins.
			$maxwidth = 195;
			if (array_sum($widths) > $maxwidth) { 
				
				// If the total width of all columns is greater than the page's
				// width, we have to truncate.

				$maxcol = 0;
				$totwid = 0;
				foreach ($widths AS $key => $val) {
					$totwid = $totwid + $val;
					if ($totwid <= $maxwidth) {
						$maxcol++;
					} else {
						$maxwidth = 0;
					}
				}
			}
			$pdf->SetFont('Arial', 'B', 10);
			$colnum = 0;
			$row = array_shift($table);
			foreach ($row as $key => $val) {
				if ((($colnum+1) < $maxcol) OR (!$maxcol)) {
					$pdf->Cell($widths[$colnum]+2, 4.5, $val, 1, 0, 'C', 1);
				}
				$colnum++;
			}
			$pdf->Ln();

			$pdf->SetFillColor(220,220,220);
			$fill = 0; 
			$pdf->SetFont('Arial', '', 10);

			foreach ($table as $key => $val) {
				$colnum = 0;
				foreach ($val as $key2 => $val2) {
					if ((($colnum+1) < $maxcol) OR (!$maxcol)) {
						if ($val2) {
							$pdf->Cell($widths[$colnum]+2, 4.5, $val2, 1, 0, 'C', $fill);
						} else {
							$pdf->SetFont('Arial', 'I', 10);
							$pdf->Cell($widths[$colnum]+2, 4.5, 'None', 1, 0, 'C', $fill);
							$pdf->SetFont('Arial', '', 10);
						}
					}
					$colnum++;
				}
				$pdf->Ln();
				$fill=!$fill;
			}
			$pdf->SetFont('Arial', 'I', 10);
			$width = $pdf->GetStringWidth("$tickets tickets found");
			$pdf->Cell($width, 5, "$tickets tickets found", 0, 1, 'L');
			$pdf->Ln();
			$pdf->Ln();
		} else {
			$pdf->SetFont('Arial', 'B', 10);
			$width = $pdf->GetStringWidth('No tickets found');
			$pdf->SetFillColor(255, 255, 200);
			$pdf->Cell($width+2, 5, 'No tickets found', 1, 1, 'C', 1);
		}
	}
	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -