/phprptinc/ewrfn5.php
PHP | 5950 lines | 4888 code | 483 blank | 579 comment | 1169 complexity | a3ee7402a967cdb6c8efb8195c9a516b MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
-
- // Functions for PHP Report Maker 5
- // (C) 2007-2011 e.World Technology Limited
-
- if (!function_exists("G")) {
-
- function &G($name) {
- return $GLOBALS[$name];
- }
- }
-
- // Get current page object
- function &CurrentPage() {
- return $GLOBALS["Page"];
- }
-
- // Get current main table object
- function &CurrentTable() {
- return $GLOBALS["Table"];
- }
-
- /**
- * Langauge class for reports
- */
-
- class crLanguage {
- var $LanguageId;
- var $Phrases = NULL;
-
- // Constructor
- function crLanguage() {
- global $gsLanguage;
- $this->LoadFileList(); // Set up file list
- if (@$_GET["language"] <> "") { // Set up language id
- $this->LanguageId = $_GET["language"];
- $_SESSION[EWRPT_SESSION_LANGUAGE_ID] = $this->LanguageId;
- } elseif (@$_SESSION[EWRPT_SESSION_LANGUAGE_ID] <> "") {
- $this->LanguageId = $_SESSION[EWRPT_SESSION_LANGUAGE_ID];
- } else {
- $this->LanguageId = EWRPT_LANGUAGE_DEFAULT_ID;
- }
- $gsLanguage = $this->LanguageId;
- $this->Load($this->LanguageId);
- }
-
- // Load language file list
- function LoadFileList() {
- global $EWRPT_LANGUAGE_FILE;
- if (is_array($EWRPT_LANGUAGE_FILE)) {
- $cnt = count($EWRPT_LANGUAGE_FILE);
- for ($i = 0; $i < $cnt; $i++)
- $EWRPT_LANGUAGE_FILE[$i][1] = $this->LoadFileDesc(EWRPT_LANGUAGE_FOLDER . $EWRPT_LANGUAGE_FILE[$i][2]);
- }
- }
-
- // Load language file description
- function LoadFileDesc($File) {
- if (EWRPT_USE_DOM_XML) {
- $this->Phrases = new crXMLDocument();
- if ($this->Phrases->Load($File))
- return $this->GetNodeAtt($this->Phrases->DocumentElement(), "desc");
- } else {
- $ar = ewrpt_Xml2Array(substr(file_get_contents($File), 0, 512)); // Just read the first part
- return (is_array($ar)) ? @$ar['ew-language']['attr']['desc'] : "";
- }
- }
-
- // Load language file
- function Load($id) {
- $sFileName = $this->GetFileName($id);
- if ($sFileName == "")
- $sFileName = $this->GetFileName(EWRPT_LANGUAGE_DEFAULT_ID);
- if ($sFileName == "")
- return;
- if (EWRPT_USE_DOM_XML) {
- $this->Phrases = new crXMLDocument();
- $this->Phrases->Load($sFileName);
- } else {
- if (is_array(@$_SESSION[EWRPT_PROJECT_VAR . "_" . $sFileName])) {
- $this->Phrases = $_SESSION[EWRPT_PROJECT_VAR . "_" . $sFileName];
- } else {
- $this->Phrases = ewrpt_Xml2Array(file_get_contents($sFileName));
- }
- }
- }
-
- // Get language file name
- function GetFileName($Id) {
- global $EWRPT_LANGUAGE_FILE;
- if (is_array($EWRPT_LANGUAGE_FILE)) {
- $cnt = count($EWRPT_LANGUAGE_FILE);
- for ($i = 0; $i < $cnt; $i++)
- if ($EWRPT_LANGUAGE_FILE[$i][0] == $Id) {
- return EWRPT_LANGUAGE_FOLDER . $EWRPT_LANGUAGE_FILE[$i][2];
- }
- }
- return "";
- }
-
- // Get node attribute
- function GetNodeAtt($Nodes, $Att) {
- $value = ($Nodes) ? $this->Phrases->GetAttribute($Nodes, $Att) : "";
-
- //return ewrpt_ConvertFromUtf8($value);
- return $value;
- }
-
- // Get phrase
- function Phrase($Name) {
- if (is_object($this->Phrases)) {
- return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//global/phrase[@id='" . strtolower($Name) . "']"), "value");
- } elseif (is_array($this->Phrases)) {
- return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['global']['phrase'][strtolower($Name)]['attr']['value']);
- }
- }
-
- // Get project phrase
- function ProjectPhrase($Id) {
- if (is_object($this->Phrases)) {
- return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/phrase[@id='" . strtolower($Id) . "']"), "value");
- } elseif (is_array($this->Phrases)) {
- return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['phrase'][strtolower($Id)]['attr']['value']);
- }
- }
-
- // Set project phrase
- function setProjectPhrase($Id, $Value) {
- if (is_array($this->Phrases)) {
- $this->Phrases['ew-language']['project']['phrase'][strtolower($Id)]['attr']['value'] = $Value;
- }
- }
-
- // Get menu phrase
- function MenuPhrase($MenuId, $Id) {
- if (is_object($this->Phrases)) {
- return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/menu[@id='" . $MenuId . "']/phrase[@id='" . strtolower($Id) . "']"), "value");
- } elseif (is_array($this->Phrases)) {
- return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['menu'][$MenuId]['phrase'][strtolower($Id)]['attr']['value']);
- }
- }
-
- // Set menu phrase
- function setMenuPhrase($MenuId, $Id, $Value) {
- if (is_array($this->Phrases)) {
- $this->Phrases['ew-language']['project']['menu'][$MenuId]['phrase'][strtolower($Id)]['attr']['value'] = $Value;
- }
- }
-
- // Get table phrase
- function TablePhrase($TblVar, $Id) {
- if (is_object($this->Phrases)) {
- return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/table[@id='" . strtolower($TblVar) . "']/phrase[@id='" . strtolower($Id) . "']"), "value");
- } elseif (is_array($this->Phrases)) {
- return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['phrase'][strtolower($Id)]['attr']['value']);
- }
- }
-
- // Set table phrase
- function setTablePhrase($TblVar, $Id, $Value) {
- if (is_array($this->Phrases)) {
- $this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['phrase'][strtolower($Id)]['attr']['value'] = $Value;
- }
- }
-
- // Get chart phrase
- function ChartPhrase($TblVar, $ChtVar, $Id) {
- if (is_object($this->Phrases)) {
- return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/table[@id='" . strtolower($TblVar) . "']/chart[@id='" . strtolower($ChtVar) . "']/phrase[@id='" . strtolower($Id) . "']"), "value");
- } elseif (is_array($this->Phrases)) {
- return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['chart'][strtolower($ChtVar)]['phrase'][strtolower($Id)]['attr']['value']);
- }
- }
-
- // Set chart phrase
- function setChartPhrase($TblVar, $FldVar, $Id, $Value) {
- if (is_array($this->Phrases)) {
- $this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['chart'][strtolower($FldVar)]['phrase'][strtolower($Id)]['attr']['value'] = $Value;
- }
- }
-
- // Get field phrase
- function FieldPhrase($TblVar, $FldVar, $Id) {
- if (is_object($this->Phrases)) {
- return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/table[@id='" . strtolower($TblVar) . "']/field[@id='" . strtolower($FldVar) . "']/phrase[@id='" . strtolower($Id) . "']"), "value");
- } elseif (is_array($this->Phrases)) {
- return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['field'][strtolower($FldVar)]['phrase'][strtolower($Id)]['attr']['value']);
- }
- }
-
- // Set field phrase
- function setFieldPhrase($TblVar, $FldVar, $Id, $Value) {
- if (is_array($this->Phrases)) {
- $this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['field'][strtolower($FldVar)]['phrase'][strtolower($Id)]['attr']['value'] = $Value;
- }
- }
-
- // Output XML as JSON
- function XmlToJSON($XPath) {
- $NodeList = $this->Phrases->SelectNodes($XPath);
- $Str = "{";
- foreach ($NodeList as $Node) {
- $Id = $this->GetNodeAtt($Node, "id");
- $Value = $this->GetNodeAtt($Node, "value");
- $Str .= "\"" . ewrpt_JsEncode2($Id) . "\":\"" . ewrpt_JsEncode2($Value) . "\",";
- }
- if (substr($Str, -1) == ",") $Str = substr($Str, 0, strlen($Str)-1);
- $Str .= "}";
- return $Str;
- }
-
- // Output array as JSON
- function ArrayToJSON($client) {
- $ar = @$this->Phrases['ew-language']['global']['phrase'];
- $Str = "{";
- if (is_array($ar)) {
- foreach ($ar as $id => $node) {
- $is_client = @$node['attr']['client'] == '1';
- $value = ewrpt_ConvertFromUtf8(@$node['attr']['value']);
- if (!$client || ($client && $is_client))
- $Str .= "\"" . ewrpt_JsEncode2($id) . "\":\"" . ewrpt_JsEncode2($value) . "\",";
- }
- }
- if (substr($Str, -1) == ",") $Str = substr($Str, 0, strlen($Str)-1);
- $Str .= "}";
- return $Str;
- }
-
- // Output all phrases as JSON
- function AllToJSON() {
- if (is_object($this->Phrases)) {
- return "var ewLanguage = new ewrpt_Language(" . $this->XmlToJSON("//global/phrase") . ");";
- } elseif (is_array($this->Phrases)) {
- return "var ewLanguage = new ewrpt_Language(" . $this->ArrayToJSON(FALSE) . ");";
- }
- }
-
- // Output client phrases as JSON
- function ToJSON() {
- if (is_object($this->Phrases)) {
- return "var ewLanguage = new ewrpt_Language(" . $this->XmlToJSON("//global/phrase[@client='1']") . ");";
- } elseif (is_array($this->Phrases)) {
- return "var ewLanguage = new ewrpt_Language(" . $this->ArrayToJSON(TRUE) . ");";
- }
- }
- }
-
- // Convert XML to array
- function ewrpt_Xml2Array($contents) {
- if (!$contents) return array();
- if (!function_exists('xml_parser_create')) return FALSE;
- $get_attributes = 1; // Always get attributes. DO NOT CHANGE!
-
- // Get the XML Parser of PHP
- $parser = xml_parser_create();
- xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); // Always return in utf-8
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parse_into_struct($parser, trim($contents), $xml_values);
- xml_parser_free($parser);
- if (!$xml_values) return;
- $xml_array = array();
- $parents = array();
- $opened_tags = array();
- $arr = array();
- $current = &$xml_array;
- $repeated_tag_index = array(); // Multiple tags with same name will be turned into an array
- foreach ($xml_values as $data) {
- unset($attributes, $value); // Remove existing values
-
- // Extract these variables into the foreach scope
- // tag(string), type(string), level(int), attributes(array)
-
- extract($data);
- $result = array();
- if (isset($value))
- $result['value'] = $value; // Put the value in a assoc array
-
- // Set the attributes
- if (isset($attributes) and $get_attributes) {
- foreach ($attributes as $attr => $val)
- $result['attr'][$attr] = $val; // Set all the attributes in a array called 'attr'
- }
-
- // See tag status and do the needed
- if ($type == "open") { // The starting of the tag '<tag>'
- $parent[$level-1] = &$current;
- if (!is_array($current) || !in_array($tag, array_keys($current))) { // Insert New tag
- if ($tag <> 'ew-language' && @$result['attr']['id'] <> '') { //
- $last_item_index = $result['attr']['id'];
- $current[$tag][$last_item_index] = $result;
- $repeated_tag_index[$tag.'_'.$level] = 1;
- $current = &$current[$tag][$last_item_index];
- } else {
- $current[$tag] = $result;
- $repeated_tag_index[$tag.'_'.$level] = 0;
- $current = &$current[$tag];
- }
- } else { // Another element with the same tag name
- if ($repeated_tag_index[$tag.'_'.$level] > 0) { // If there is a 0th element it is already an array
- if (@$result['attr']['id'] <> '') {
- $last_item_index = $result['attr']['id'];
- } else {
- $last_item_index = $repeated_tag_index[$tag.'_'.$level];
- }
- $current[$tag][$last_item_index] = $result;
- $repeated_tag_index[$tag.'_'.$level]++;
- } else { // Make the value an array if multiple tags with the same name appear together
- $temp = $current[$tag];
- $current[$tag] = array();
- if (@$temp['attr']['id'] <> '') {
- $current[$tag][$temp['attr']['id']] = $temp;
- } else {
- $current[$tag][] = $temp;
- }
- if (@$result['attr']['id'] <> '') {
- $last_item_index = $result['attr']['id'];
- } else {
- $last_item_index = 1;
- }
- $current[$tag][$last_item_index] = $result;
- $repeated_tag_index[$tag.'_'.$level] = 2;
- }
- $current = &$current[$tag][$last_item_index];
- }
- } elseif ($type == "complete") { // Tags that ends in one line '<tag>'
- if (!isset($current[$tag])) { // New key
- $current[$tag] = array(); // Always use array for "complete" type
- if (@$result['attr']['id'] <> '') {
- $current[$tag][$result['attr']['id']] = $result;
- } else {
- $current[$tag][] = $result;
- }
- $repeated_tag_index[$tag.'_'.$level] = 1;
- } else { // Existing key
- if (@$result['attr']['id'] <> '') {
- $current[$tag][$result['attr']['id']] = $result;
- } else {
- $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
- }
- $repeated_tag_index[$tag.'_'.$level]++;
- }
- } elseif ($type == 'close') { // End of tag '</tag>'
- $current = &$parent[$level-1];
- }
- }
- return($xml_array);
- }
-
- /**
- * XML document class
- */
-
- class crXMLDocument {
- var $Encoding = "utf-8";
- var $RootTagName;
- var $RowTagName;
- var $XmlDoc = FALSE;
- var $XmlTbl;
- var $XmlRow;
- var $NullValue = 'NULL';
-
- function crXMLDocument($encoding = "") {
- if ($encoding <> "")
- $this->Encoding = $encoding;
- if ($this->Encoding <> "") {
- $this->XmlDoc = new DOMDocument("1.0", strval($this->Encoding));
- } else {
- $this->XmlDoc = new DOMDocument("1.0");
- }
- }
-
- function Load($filename) {
- $filepath = realpath($filename);
- return $this->XmlDoc->load($filepath);
- }
-
- function &DocumentElement() {
- $de = $this->XmlDoc->documentElement;
- return $de;
- }
-
- function GetAttribute($element, $name) {
- return ($element) ? ewrpt_ConvertFromUtf8($element->getAttribute($name)) : "";
- }
-
- function SelectSingleNode($query) {
- $elements = $this->SelectNodes($query);
- return ($elements->length > 0) ? $elements->item(0) : NULL;
- }
-
- function SelectNodes($query) {
- $xpath = new DOMXPath($this->XmlDoc);
- return $xpath->query($query);
- }
-
- function AddRoot($roottagname = 'table') {
- $this->RootTagName = $roottagname;
- $this->XmlTbl = $this->XmlDoc->createElement($this->RootTagName);
- $this->XmlDoc->appendChild($this->XmlTbl);
- }
-
- function AddRow($rowtagname = 'row') {
- $this->RowTagName = $rowtagname;
- $this->XmlRow = $this->XmlDoc->createElement($this->RowTagName);
- if ($this->XmlTbl)
- $this->XmlTbl->appendChild($this->XmlRow);
- }
-
- function AddField($name, $value) {
- if (is_null($value)) $value = $this->NullValue;
- $value = ewrpt_ConvertToUtf8($value); // Convert to UTF-8
- $xmlfld = $this->XmlDoc->createElement($name);
- $this->XmlRow->appendChild($xmlfld);
- $xmlfld->appendChild($this->XmlDoc->createTextNode($value));
- }
-
- function XML() {
- return $this->XmlDoc->saveXML();
- }
- }
-
- // Select nodes from XML document
- function &ewrpt_SelectNodes(&$xmldoc, $query) {
- if ($xmldoc) {
- $xpath = new DOMXPath($xmldoc);
- return $xpath->query($query);
- }
- return NULL;
- }
-
- // Select single node from XML document
- function &ewrpt_SelectSingleNode(&$xmldoc, $query) {
- $elements = ewrpt_SelectNodes($xmldoc, $query);
- return ($elements && $elements->length > 0) ? $elements->item(0) : NULL;
- }
-
- // Debug timer
- class crTimer {
- var $StartTime;
- var $EndTime;
-
- function crTimer($start = TRUE) {
- if ($start)
- $this->Start();
- }
-
- function GetTime() {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
-
- // Get script start time
- function Start() {
- if (EWRPT_DEBUG_ENABLED)
- $this->StartTime = $this->GetTime();
- }
-
- // display elapsed time (in seconds)
- function Stop() {
- if (EWRPT_DEBUG_ENABLED)
- $this->EndTime = $this->GetTime();
- if (isset($this->EndTime) && isset($this->StartTime) &&
- $this->EndTime > $this->StartTime)
- echo '<p>Page processing time: ' . ($this->EndTime - $this->StartTime) . ' seconds</p>';
- }
- }
-
- /**
- * Field class
- */
-
- class crField {
- var $TblName; // Table name
- var $TblVar; // Table variable name
- var $FldName; // Field name
- var $FldVar; // Field variable name
- var $FldExpression; // Field expression (used in SQL)
- var $FldDefaultErrMsg; // Default error message
- var $FldType; // Field type
- var $FldDataType; // PHPMaker Field type
- var $FldDateTimeFormat; // Date time format
- var $Count; // Count
- var $SumValue; // Sum
- var $AvgValue; // Average
- var $MinValue; // Minimum
- var $MaxValue; // MaxValue
- var $SumViewValue; // Sum
- var $AvgViewValue; // Average
- var $MinViewValue; // Minimum
- var $MaxViewValue; // MaxValue
- var $OldValue; // Old Value
- var $CurrentValue; // Current value
- var $ViewValue; // View value
- var $HrefValue; // Href value
- var $FormValue; // Form value
- var $QueryStringValue; // QueryString value
- var $DbValue; // Database value
- var $ImageWidth = 0; // Image width
- var $ImageHeight = 0; // Image height
- var $ImageResize = FALSE; // Image resize
- var $Sortable = TRUE; // Sortable
- var $GroupingFieldId = 0; // Grouping field id
- var $UploadPath = EWRPT_UPLOAD_DEST_PATH; // Upload path
- var $TruncateMemoRemoveHtml = FALSE; // Remove HTML from memo field
- var $CellAttrs = array(); // Cell custom attributes
- var $ViewAttrs = array(); // View custom attributes
- var $LinkAttrs = array(); // Href custom attributes
- var $FldGroupByType; // Group By Type
- var $FldGroupInt; // Group Interval
- var $FldGroupSql; // Group SQL
- var $GroupDbValues; // Group DB Values
- var $GroupViewValue; // Group View Value
- var $GroupSummaryOldValue; // Group Summary Old Value
- var $GroupSummaryValue; // Group Summary Value
- var $GroupSummaryViewValue; // Group Summary View Value
- var $SqlSelect; // Field SELECT
- var $SqlGroupBy; // Field GROUP BY
- var $SqlOrderBy; // Field ORDER BY
- var $ValueList; // Value List
- var $SelectionList; // Selection List
- var $DefaultSelectionList; // Default Selection List
- var $AdvancedFilters; // Advanced Filters
- var $RangeFrom; // Range From
- var $RangeTo; // Range To
- var $DropDownList; // Dropdown List
- var $DropDownValue; // Dropdown Value
- var $DefaultDropDownValue; // Default Dropdown Value
- var $DateFilter; // Date Filter
- var $SearchValue; // Search Value 1
- var $SearchValue2; // Search Value 2
- var $SearchOperator; // Search Operator 1
- var $SearchOperator2; // Search Operator 2
- var $SearchCondition; // Search Condition
- var $DefaultSearchValue; // Default Search Value 1
- var $DefaultSearchValue2; // Default Search Value 2
- var $DefaultSearchOperator; // Default Search Operator 1
- var $DefaultSearchOperator2; // Default Search Operator 2
- var $DefaultSearchCondition; // Default Search Condition
-
- // Constructor
- function crField($tblvar, $tblname, $fldvar, $fldname, $fldexpression, $fldtype, $flddatatype, $flddtfmt) {
- $this->TblVar = $tblvar;
- $this->TblName = $tblname;
- $this->FldVar = $fldvar;
- $this->FldName = $fldname;
- $this->FldExpression = $fldexpression;
- $this->FldType = $fldtype;
- $this->FldDataType = $flddatatype;
- $this->FldDateTimeFormat = $flddtfmt;
- }
-
- // Field caption
- function FldCaption() {
- global $ReportLanguage;
- return $ReportLanguage->FieldPhrase($this->TblVar, substr($this->FldVar, 2), "FldCaption");
- }
-
- // Field title
- function FldTitle() {
- global $ReportLanguage;
- return $ReportLanguage->FieldPhrase($this->TblVar, substr($this->FldVar, 2), "FldTitle");
- }
-
- // Field image alt
- function FldAlt() {
- global $ReportLanguage;
- return $ReportLanguage->FieldPhrase($this->TblVar, substr($this->FldVar, 2), "FldAlt");
- }
-
- // Field error message
- function FldErrMsg() {
- global $ReportLanguage;
- $err = $ReportLanguage->FieldPhrase($this->TblVar, substr($this->FldVar, 2), "FldErrMsg");
- if ($err == "") $err = $this->FldDefaultErrMsg . " - " . $this->FldCaption();
- return $err;
- }
-
- // Reset CSS styles for field object
- function ResetCSS() {
- $this->CellAttrs["style"] = "";
- $this->CellAttrs["class"] = "";
- $this->ViewAttrs["style"] = "";
- $this->ViewAttrs["class"] = "";
- }
-
- // View Attributes
- function ViewAttributes() {
- $sAtt = "";
- if (intval($this->ImageWidth) > 0 && (!$this->ImageResize || ($this->ImageResize && intval($this->ImageHeight) <= 0)))
- $sAtt .= " width=\"" . intval($this->ImageWidth) . "\"";
- if (intval($this->ImageHeight) > 0 && (!$this->ImageResize || ($this->ImageResize && intval($this->ImageWidth) <= 0)))
- $sAtt .= " height=\"" . intval($this->ImageHeight) . "\"";
- foreach ($this->ViewAttrs as $k => $v) {
- if (trim($v) <> "")
- $sAtt .= " " . $k . "=\"" . trim($v) . "\"";
- }
- return $sAtt;
- }
-
- // Link Attributes
- function LinkAttributes() {
- $sAtt = "";
- $sHref = trim($this->HrefValue);
- foreach ($this->LinkAttrs as $k => $v) {
- if (trim($v) <> "") {
- if ($k == "href")
- $sHref .= " " . $v;
- else
- $sAtt .= " " . $k . "=\"" . trim($v) . "\"";
- }
- }
- if ($sHref <> "")
- $sAtt .= " href=\"" . trim($sHref) . "\"";
-
- // if (trim($this->LinkCustomAttributes) <> "")
- // $sAtt .= " " . trim($this->LinkCustomAttributes);
-
- return $sAtt;
- }
-
- // Cell attributes
- function CellAttributes() {
- $sAtt = "";
- foreach ($this->CellAttrs as $k => $v) {
- if (trim($v) <> "")
- $sAtt .= " " . $k . "=\"" . trim($v) . "\"";
- }
- return $sAtt;
- }
-
- // Sort
- function getSort() {
- return @$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TblVar . "_" . EWRPT_TABLE_SORT . "_" . $this->FldVar];
- }
-
- function setSort($v) {
- if (@$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TblVar . "_" . EWRPT_TABLE_SORT . "_" . $this->FldVar] <> $v) {
- $_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TblVar . "_" . EWRPT_TABLE_SORT . "_" . $this->FldVar] = $v;
- }
- }
-
- function ReverseSort() {
- return ($this->getSort() == "ASC") ? "DESC" : "ASC";
- }
-
- // List view value
- function ListViewValue() {
- $value = trim(strval($this->ViewValue));
- if ($value <> "") {
- $value2 = trim(preg_replace('/<[^img][^>]*>/i', '', strval($value)));
- return ($value2 <> "") ? $this->ViewValue : " ";
- } else {
- return " ";
- }
- }
-
- // Form value
- function setFormValue($v) {
- $this->FormValue = ewrpt_StripSlashes($v);
- if (is_array($this->FormValue))
- $this->FormValue = implode(",", $this->FormValue);
- $this->CurrentValue = $this->FormValue;
- }
-
- // QueryString value
- function setQueryStringValue($v) {
- $this->QueryStringValue = ewrpt_StripSlashes($v);
- $this->CurrentValue = $this->QueryStringValue;
- }
-
- // Database value
- function setDbValue($v) {
- $this->OldValue = $this->DbValue;
- if (EWRPT_IS_MSSQL && ($this->FldType == 131 || $this->FldType == 139)) // MS SQL adNumeric/adVarNumeric field
- $this->DbValue = floatval($v);
- else
- $this->DbValue = $v;
- $this->CurrentValue = $this->DbValue;
- }
-
- // Group value
- function GroupValue() {
- return $this->getGroupValue($this->CurrentValue);
- }
-
- // Group old value
- function GroupOldValue() {
- return $this->getGroupValue($this->OldValue);
- }
-
- // Get group value
- function getGroupValue($v) {
- if ($this->GroupingFieldId == 1) {
- return $v;
- } elseif (is_array($this->GroupDbValues)) {
- return @$this->GroupDbValues[$v];
- } elseif ($this->FldGroupByType <> "" && $this->FldGroupByType <> "n") {
- return ewrpt_GroupValue($this, $v);
- } else {
- return $v;
- }
- }
- }
-
- /**
- * Chart class
- */
-
- class crChart {
- var $TblName; // Table name
- var $TblVar; // Table variable name
- var $ChartName; // Chart name
- var $ChartVar; // Chart variable name
- var $ChartXFldName; // Chart X Field name
- var $ChartYFldName; // Chart Y Field name
- var $ChartSFldName; // Chart Series Field name
- var $ChartType; // Chart Type
- var $ChartSummaryType; // Chart Type
- var $ChartWidth; // Chart Width
- var $ChartHeight; // Chart Height
- var $ChartAlign; // Chart Align
- var $SqlSelect;
- var $SqlGroupBy;
- var $SqlOrderBy;
- var $XAxisDateFormat;
- var $NameDateFormat;
- var $SeriesDateType;
- var $SqlSelectSeries;
- var $SqlGroupBySeries;
- var $SqlOrderBySeries;
- var $ID;
- var $Parms = array();
- var $Trends;
- var $Data;
- var $Series;
- var $XmlDoc;
- var $XmlRoot;
-
- // Constructor
- function crChart($tblvar, $tblname, $chartvar, $chartname, $xfld, $yfld, $sfld, $type, $smrytype, $width, $height, $align="") {
- $this->TblVar = $tblvar;
- $this->TblName = $tblname;
- $this->ChartVar = $chartvar;
- $this->ChartName = $chartname;
- $this->ChartXFldName = $xfld;
- $this->ChartYFldName = $yfld;
- $this->ChartSFldName = $sfld;
- $this->ChartType = $type;
- $this->ChartSummaryType = $smrytype;
- $this->ChartWidth = $width;
- $this->ChartHeight = $height;
- $this->ChartAlign = $align;
- $this->ID = NULL;
- $this->Parms = NULL;
- $this->Trends = NULL;
- $this->Data = NULL;
- $this->Series = NULL;
- $this->XmlDoc = new DOMDocument("1.0", "utf-8");
- }
-
- // Chart caption
- function ChartCaption() {
- global $ReportLanguage;
- return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartCaption");
- }
-
- // function xaxisname
- function ChartXAxisName() {
- global $ReportLanguage;
- return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartXAxisName");
- }
-
- // function yaxisname
- function ChartYAxisName() {
- global $ReportLanguage;
- return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartYAxisName");
- }
-
- // function PYAxisName
- function ChartPYAxisName() {
- global $ReportLanguage;
- return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartPYAxisName");
- }
-
- // function SYAxisName
- function ChartSYAxisName() {
- global $ReportLanguage;
- return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartSYAxisName");
- }
-
- // Set chart parameters
- function SetChartParam($Name, $Value, $Output) {
- $this->Parms[$Name] = array($Name, $Value, $Output);
- }
-
- // Set up default chart parm
- function SetupDefaultChartParm($key, $value) {
- if (is_array($this->Parms)) {
- $parm = $this->LoadParm($key);
- if (is_null($parm)) {
- $this->Parms[$key] = array($key, $value, TRUE);
- } elseif ($parm == "") {
- $this->SaveParm($key, $value);
- }
- }
- }
-
- // Load chart parm
- function LoadParm($key) {
- if (is_array($this->Parms) && array_key_exists($key, $this->Parms))
- return $this->Parms[$key][1];
- return NULL;
- }
-
- // Save chart parm
- function SaveParm($key, $value) {
- if (is_array($this->Parms) && array_key_exists($key, $this->Parms))
- $this->Parms[$key][1] = $value;
- }
-
- // Chart Xml
- function ChartXml() {
-
- // Initialize default values
- $this->SetupDefaultChartParm("caption", "Chart");
-
- // Show names/values/hover
- $this->SetupDefaultChartParm("shownames", "1"); // Default show names
- $this->SetupDefaultChartParm("showvalues", "1"); // Default show values
- $this->SetupDefaultChartParm("showhover", "1"); // Default show hover
-
- // Get showvalues/showhovercap
- $cht_showValues = $this->LoadParm("showvalues");
- $cht_showHoverCap = $this->LoadParm("showhovercap");
-
- // Format percent for Pie charts
- $cht_showPercentageValues = $this->LoadParm("showPercentageValues");
- $cht_showPercentageInLabel = $this->LoadParm("showPercentageInLabel");
- $cht_type = $this->LoadParm("type");
- if ($cht_type == 2 || $cht_type == 6 || $cht_type == 8 || $cht_type == 101) {
- if (($cht_showHoverCap == "1" && $cht_showPercentageValues == "1") ||
- ($cht_showValues == "1" && $cht_showPercentageInLabel == "1")) {
- $this->SetupDefaultChartParm("formatNumber", "1");
- $this->SaveParm("formatNumber", "1");
- }
- } elseif ($cht_type == 20) {
- $this->SetupDefaultChartParm("bearBorderColor", "E33C3C");
- $this->SetupDefaultChartParm("bearFillColor", "E33C3C");
- }
-
- // Process chart parms
- $this->ProcessChartParms($cht_type, $this->Parms);
- $chartseries =& $this->Series;
- $chartdata =& $this->Data;
- $cht_series = ((intval($cht_type) >= 9 && intval($cht_type) <= 19) || (intval($cht_type) >= 102 && intval($cht_type) <= 103)) ? 1 : 0; // $cht_series = 1 (Multi series charts)
- $cht_series_type = $this->LoadParm("seriestype");
- $cht_alpha = $this->LoadParm("alpha");
-
- // Hide legend for single series (Bar 3D / Column 2D / Line 2D / Area 2D)
- $scrollchart = (intval($this->LoadParm("numVisiblePlot")) > 0 && ($cht_type == 1 || $cht_type == 4 || $cht_type == 7)) ? 1 : 0;
- $cht_single_series = ($cht_type == 104 || $scrollchart == 1) ? 1 : 0;
- if ($cht_single_series == 1) {
- $this->SetupDefaultChartParm("showLegend", "0");
- $this->SaveParm("showLegend", "0");
- }
- if (is_array($chartdata)) {
- $this->WriteChartHeader(); // Write chart header
-
- // Candlestick
- if ($cht_type == 20) {
-
- // Write candlestick cat
- if (count($chartdata[0]) >= 7) {
- $cats = $this->XmlDoc->createElement('categories');
- $this->XmlRoot->appendChild($cats);
- $cntcat = count($chartdata);
- for ($i = 0; $i < $cntcat; $i++) {
- $xindex = $i+1;
- $name = $chartdata[$i][6];
- if ($name <> "")
- $this->WriteChartCandlestickCatContent($cats, $xindex, $name);
- }
- }
-
- // Write candlestick data
- $data = $this->XmlDoc->createElement('data');
- $this->XmlRoot->appendChild($data);
- $cntdata = count($chartdata);
- for ($i = 0; $i < $cntdata; $i++) {
- $open = is_null($chartdata[$i][2]) ? 0 : (float)$chartdata[$i][2];
- $high = is_null($chartdata[$i][3]) ? 0 : (float)$chartdata[$i][3];
- $low = is_null($chartdata[$i][4]) ? 0 : (float)$chartdata[$i][4];
- $close = is_null($chartdata[$i][5]) ? 0 : (float)$chartdata[$i][5];
- $xindex = $i+1;
- $this->WriteChartCandlestickContent($data, $open, $high, $low, $close, $xindex);
- }
-
- // Multi series
- } else if ($cht_series == 1) {
-
- // Multi-Y values
- if ($cht_series_type == "1") {
-
- // Write cat
- $cats = $this->XmlDoc->createElement('categories');
- $this->XmlRoot->appendChild($cats);
- $cntcat = count($chartdata);
- for ($i = 0; $i < $cntcat; $i++) {
- $name = $this->ChartFormatName($chartdata[$i][0]);
- $this->WriteChartCatContent($cats, $name);
- }
-
- // Write series
- $cntdata = count($chartdata);
- $cntseries = count($chartseries);
- if ($cntseries > count($chartdata[0])-2) $cntseries = count($chartdata[0])-2;
- for ($i = 0; $i < $cntseries; $i++) {
- $color = $this->GetPaletteColor($i);
- $bShowSeries = EWRPT_CHART_SHOW_BLANK_SERIES;
- $dataset = $this->XmlDoc->createElement('dataset');
- $this->WriteChartSeriesHeader($dataset, $chartseries[$i], $color, $cht_alpha);
- $bWriteSeriesHeader = TRUE;
- for ($j = 0; $j < $cntdata; $j++) {
- $val = $chartdata[$j][$i+2];
- $val = (is_null($val)) ? 0 : (float)$val;
- if ($val <> 0) $bShowSeries = TRUE;
- $this->WriteChartSeriesContent($dataset, $val);
- }
- if ($bShowSeries)
- $this->XmlRoot->appendChild($dataset);
- }
-
- // Series field
- } else {
-
- // Get series names
- if (is_array($chartseries)) {
- $nSeries = count($chartseries);
- } else {
- $nSeries = 0;
- }
-
- // Write cat
- $cats = $this->XmlDoc->createElement('categories');
- $this->XmlRoot->appendChild($cats);
- $chartcats = array();
- $cntdata = count($chartdata);
- for ($i = 0; $i < $cntdata; $i++) {
- $name = $chartdata[$i][0];
- if (!in_array($name, $chartcats)) {
- $this->WriteChartCatContent($cats, $name);
- $chartcats[] = $name;
- }
- }
-
- // Write series
- for ($i = 0; $i < $nSeries; $i++) {
- $seriesname = (is_array($chartseries[$i])) ? $chartseries[$i][0] : $chartseries[$i];
- $color = $this->GetPaletteColor($i);
- $bShowSeries = EWRPT_CHART_SHOW_BLANK_SERIES;
- $dataset = $this->XmlDoc->createElement('dataset');
- $this->WriteChartSeriesHeader($dataset, $chartseries[$i], $color, $cht_alpha);
- $cntcats = count($chartcats);
- $cntdata = count($chartdata);
- for ($j = 0; $j < $cntcats; $j++) {
- $val = 0;
- for ($k = 0; $k < $cntdata; $k++) {
- if ($chartdata[$k][0] == $chartcats[$j] && $chartdata[$k][1] == $seriesname) {
- $val = $chartdata[$k][2];
- $val = (is_null($val)) ? 0 : (float)$val;
- if ($val <> 0) $bShowSeries = TRUE;
- break;
- }
- }
- $this->WriteChartSeriesContent($dataset, $val);
- }
- if ($bShowSeries)
- $this->XmlRoot->appendChild($dataset);
- }
- }
-
- // Show single series
- } elseif ($cht_single_series == 1) {
-
- // Write multiple cats
- $cats = $this->XmlDoc->createElement('categories');
- $this->XmlRoot->appendChild($cats);
- $cntcat = count($chartdata);
- for ($i = 0; $i < $cntcat; $i++) {
- $name = $this->ChartFormatName($chartdata[$i][0]);
- if ($chartdata[$i][1] <> "")
- $name .= ", " . $chartdata[$i][1];
- $this->WriteChartCatContent($cats, $name);
- }
-
- // Write series
- $toolTipSep = $this->LoadParm("toolTipSepChar");
- if ($toolTipSep == "") $toolTipSep = ":";
- $cntdata = count($chartdata);
- $dataset = $this->XmlDoc->createElement('dataset');
- $this->WriteChartSeriesHeader($dataset, '', '', $cht_alpha);
- for ($i = 0; $i < $cntdata; $i++) {
- $name = $this->ChartFormatName($chartdata[$i][0]);
- if ($chartdata[$i][1] <> "")
- $name .= ", " . $chartdata[$i][1];
- $val = $chartdata[$i][2];
- $val = (is_null($val)) ? 0 : (float)$val;
- $color = $this->GetPaletteColor($i);
- $toolText = $name . $toolTipSep . $val;
- $this->WriteChartSeriesContent($dataset, $val, $color, $cht_alpha, '', $toolText);
- $this->XmlRoot->appendChild($dataset);
- }
-
- // Single series
- } else {
- $cntdata = count($chartdata);
- for ($i = 0; $i < $cntdata; $i++) {
- $name = $this->ChartFormatName($chartdata[$i][0]);
- $color = $this->GetPaletteColor($i);
- if ($chartdata[$i][1] <> "")
- $name .= ", " . $chartdata[$i][1];
- $val = $chartdata[$i][2];
- $val = (is_null($val)) ? 0 : (float)$val;
- $this->WriteChartContent($this->XmlRoot, $name, $val, $color, $cht_alpha, @$link); // Get chart content
- }
- }
-
- // Get trend lines
- $this->WriteChartTrendLines();
- }
- $wrk = $this->XmlDoc->saveXML();
- return $wrk;
-
- // ewrpt_Trace($wrk);
- }
-
- // Show chart (FusionCharts Free)
- // typ: chart type (1/2/3/4/...)
- // id: chart id
- // parms: "bgcolor=FFFFFF|..."
- // trends: trend lines
- function ShowChartFCF($xml) {
- $typ = $this->ChartType;
- $id = $this->ID;
- $parms = $this->Parms;
- $trends = $this->Trends;
- $data = $this->Data;
- $series = $this->Series;
- $width = $this->ChartWidth;
- $height = $this->ChartHeight;
- $align = $this->ChartAlign;
- if (empty($typ))
- $typ = 1;
-
- // Get chart swf
- switch ($typ) {
-
- // Single Series
- case 1: $chartswf = "FCF_Column2D.swf"; break; // Column 2D
- case 2: $chartswf = "FCF_Pie2D.swf"; break; // Pie 2D
- case 3: $chartswf = "FCF_Bar2D.swf"; break; // Bar 2D
- case 4: $chartswf = "FCF_Line.swf"; break; // Line 2D
- case 5: $chartswf = "FCF_Column3D.swf"; break; // Column 3D
- case 6: $chartswf = "FCF_Pie3D.swf"; break; // Pie 3D
- case 7: $chartswf = "FCF_Area2D.swf"; break; // Area 2D
- case 8: $chartswf = "FCF_Doughnut2D.swf"; break; // Doughnut 2D
-
- // Multi Series
- case 9: $chartswf = "FCF_MSColumn2D.swf"; break; // Multi-series Column 2D
- case 10: $chartswf = "FCF_MSColumn3D.swf"; break; // Multi-series Column 3D
- case 11: $chartswf = "FCF_MSLine.swf"; break; // Multi-series Line 2D
- case 12: $chartswf = "FCF_MSArea2D.swf"; break; // Multi-series Area 2D
- case 13: $chartswf = "FCF_MSBar2D.swf"; break; // Multi-series Bar 2D
-
- // Stacked
- case 14: $chartswf = "FCF_StackedColumn2D.swf"; break; // Stacked Column 2D
- case 15: $chartswf = "FCF_StackedColumn3D.swf"; break; // Stacked Column 3D
- case 16: $chartswf = "FCF_StackedArea2D.swf"; break; // Stacked Area 2D
- case 17: $chartswf = "FCF_StackedBar2D.swf"; break; // Stacked Bar 2D
-
- // Combination
- case 18: $chartswf = "FCF_MSColumn2DLineDY.swf"; break; // Multi-series Column 2D Line Dual Y Chart
- case 19: $chartswf = "FCF_MSColumn3DLineDY.swf"; break; // Multi-series Column 3D Line Dual Y Chart
-
- // Financial
- case 20: $chartswf = "FCF_Candlestick.swf"; break; // Candlestick
-
- // Other
- case 21: $chartswf = "FCF_Gantt.swf"; break; // Gantt
- case 22: $chartswf = "FCF_Funnel.swf"; break; // Funnel
-
- // Additional FusionCharts
- case 101: $chartswf = "FCF_Doughnut2D.swf"; break; // Doughnut 3D, switch back to 2D
- case 102: $chartswf = "FCF_MSBar2D.swf"; break; // Multi-series Bar 3D, switch back to 2D
- case 103: $chartswf = "FCF_StackedBar2D.swf"; break; // Stacked Bar 3D, switch back to 2D
- case 104: $chartswf = "FCF_Bar2D.swf"; break; // Bar 3D, switch back to 2D
-
- // Default
- default: $chartswf = "FCF_Column2D.swf"; // Default = Column 2D
- }
-
- // Set width, height and align
- if (is_numeric($width) && is_numeric($height)) {
- $wrkwidth = $width;
- $wrkheight = $height;
- } else { // default
- $wrkwidth = EWRPT_CHART_WIDTH;
- $wrkheight = EWRPT_CHART_HEIGHT;
- }
- if (strtolower($align) == "left" || strtolower($align) == "right") {
- $wrkalign = strtolower($align);
- } else {
- $wrkalign = EWRPT_CHART_ALIGN; // default
- }
-
- // Output JavaScript for FCF
- $chartxml = $xml;
- $wrk = "<script type=\"text/javascript\">\n";
- $wrk .= "var chartwidth = \"$wrkwidth\";\n";
- $wrk .= "var chartheight = \"$wrkheight\";\n";
-
- //$wrk .= "var chartalign = \"$wrkalign\";\n";
- $wrk .= "var chartxml = \"" . ewrpt_EscapeJs($chartxml) . "\";\n";
- $wrk .= "var chartid = \"div_$id\";\n";
- $wrk .= "var chartswf = \"" . EWRPT_FUSIONCHARTS_FREE_CHART_PATH . $chartswf . "\";\n";
- $wrk .= "var cht_$id = new FusionChartsFree(chartswf, \"chart_$id\", chartwidth, chartheight);\n";
- $wrk .= "cht_$id.addParam(\"wmode\", \"transparent\");\n";
- $wrk .= "cht_$id.setDataXML(chartxml);\n";
- $wrk .= "var f = " . CurrentPage()->PageObjName . ".Chart_Rendering;\n";
- $wrk .= "if (typeof f == \"function\") f(cht_$id, 'chart_$id');\n";
- $wrk .= "cht_$id.render(chartid);\n";
- $wrk .= "f = " . CurrentPage()->PageObjName . ".Chart_Rendered;\n";
- $wrk .= "if (typeof f == \"function\") f(cht_$id, 'chart_$id');\n";
- $wrk .= "</script>\n";
-
- // Add debug xml
- if (EWRPT_DEBUG_ENABLED)
- $wrk .= "<p>(Chart XML): " . ewrpt_HtmlEncode($chartxml) . "</p>";
- return $wrk;
- }
-
- // Show Chart Xml
- function ShowChartXml() {
-
- // Build chart content
- $sChartContent = $this->ChartXml();
- header("Content-Type: text/xml; charset=UTF-8");
-
- // Write utf-8 BOM
- echo "\xEF\xBB\xBF";
-
- // Write utf-8 encoding
- echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
-
- // Write content
- echo $sChartContent;
- }
-
- // Show Chart Text
- function ShowChartText() {
-
- // Build chart content
- $sChartContent = $this->ChartXml();
- header("Content-Type: text/plain; charset=UTF-8");
-
- // Write content
- echo $sChartContent;
- }
-
- // Get color
- function GetPaletteColor($i) {
- $colorpalette = $this->LoadParm("colorpalette");
- $ar_cht_colorpalette = explode("|", $colorpalette);
- if (is_array($ar_cht_colorpalette))
- $cntar = count($ar_cht_colorpalette);
- return $ar_cht_colorpalette[$i % $cntar];
- }
-
- // Convert to HTML color
- function ColorCode($c) {
- if ($c <> "") {
-
- // remove #
- $color = str_replace("#", "", $c);
-
- // fill to 6 digits
- return str_pad($color, 6, "0", STR_PAD_LEFT);
- } else {
- return "";
- }
- }
-
- // Output chart header
- function WriteChartHeader() {
- $cht_parms = $this->Parms;
- $chartElement = ($this->ChartType == 20 || (EWRPT_FUSIONCHARTS_FREE && $this->ChartType <> 21 && $this->ChartType <> 22)) ? 'graph' : 'chart';
- $chart = $this->XmlDoc->createElement($chartElement);
- $this->XmlRoot =& $chart;
- $this->XmlDoc->appendChild($chart);
- if (is_array($cht_parms)) {
- foreach ($cht_parms as $parm) {
- if ($parm[2])
- $this->WriteAtt($chart, $parm[0], $parm[1]);
- }
- }
- }
-
- // Get TrendLine XML
- // <trendlines>
- // <line startvalue='0.8' displayValue='Good' color='FF0000' thickness='1' isTrendZone='0'/>
- // <line startvalue='-0.4' displayValue='Bad' color='009999' thickness='1' isTrendZone='0'/>
- // </trendlines>
- function WriteChartTrendLines() {
- $cht_trends = $this->Trends;
- if (is_array($cht_trends)) {
- foreach ($cht_trends as $trend) {
- $trends = $this->XmlDoc->createElement('trendlines');
- $this->XmlRoot->appendChild($trends);
-
- // Get all trend lines
- $this->WriteChartTrendLine($trends, $trend[0], $trend[1], $trend[2], $trend[3], $trend[4], $trend[5], $trend[6], $trend[7]);
- }
- }
- }
-
- // Output trend line
- function WriteChartTrendLine(&$node, $startval, $endval, $color, $dispval, $thickness, $trendzone, $showontop, $alpha) {
- $line = $this->XmlDoc->createElement('line');
- $this->WriteAtt($line, "startValue", $startval); // Starting y value
- if ($endval <> 0)
- $this->WriteAtt($line, "endValue", $endval); // Ending y value
- $this->WriteAtt($line, "color", $this->CheckColorCode($color)); // Color
- if ($dispval <> "")
- $this->WriteAtt($line, "displayValue", $dispval); // Display value
- if ($thickness > 0)
- $this->WriteAtt($line, "thickness", $thickness); // Thickness
- $this->WriteAtt($line, "isTrendZone", $trendzone); // Display trend as zone or line
- $this->WriteAtt($line, "showOnTop", $showontop); // Show on top
- if ($alpha > 0)
- $this->WriteAtt($line, "alpha", $alpha); // Alpha
- $node->appendChild($line);
- }
-
- // Series header/footer XML (multi series)
- function WriteChartSeriesHeader(&$node, $series, $color, $alpha) {
- global $ReportLanguage;
- $seriesname = is_array($series) ? $series[0] : $series;
- if (is_null($seriesname)) {
- $seriesname = $ReportLanguage->Phrase("NullLabel");
- } elseif ($seriesname == "") {
- $seriesname = $ReportLanguage->Phrase("EmptyLabel");
- }
- $this->WriteAtt($node, "seriesname", $seriesname);
- $this->WriteAtt($node, "color", $this->ColorCode($color));
- $this->WriteAtt($node, "alpha", $alpha);
- if (is_array($series))
- $this->WriteAtt($node, "parentYAxis", $series[1]);
- }
-
- // Series content XML (multi series)
- function WriteChartSeriesContent(&$node, $val, $color = "", $alpha = "", $lnk = "", $toolText = "") {
- $set = $this->XmlDoc->createElement('set');
- $this->WriteAtt($set, "value", $this->ChartFormatNumber($val));
- if ($color <> "")
- $this->WriteAtt($set, "color", $this->ColorCode($color));
- if ($alpha <> "")
- $this->WriteAtt($set, "alpha", $alpha);
- if ($lnk <> "")
- $this->WriteAtt($set, "link", $lnk);
- if ($toolText <> "")
- $this->WriteAtt($set, "toolText", $toolText);
- $node->appendChild($set);
- }
-
- // Category content XML (Candlestick category)
- function WriteChartCandlestickCatContent(&$node, $xindex, $name) {
- $cat = $this->XmlDoc->createElement('category');
- $this->WriteAtt($cat, "name", $name);
- $this->WriteAtt($cat, "xindex", $xindex);
- $this->WriteAtt($cat, "showline", "1");
- $node->appendChild($cat);
- }
-
- // Chart content XML (Candlestick)
- function WriteChartCandlestickContent(&$node, $open, $high, $low, $close, $xindex) {
- $set = $this->XmlDoc->createElement('set');
- $this->WriteAtt($set, "open", $this->ChartFormatNumber($open));
- $this->WriteAtt($set, "high", $this->ChartFormatNumber($high));
- $this->WriteAtt($set, "low", $this->ChartFormatNumber($low));
- $this->WriteAtt($set, "close", $this->ChartFormatNumber($close));
- if ($xindex <> "")
- $this->WriteAtt($set, "xindex", $xindex);
- $node->appendChild($set);
- }
-
- // Format name for chart
- function ChartFormatName($name) {
- global $ReportLanguage;
- if (is_null($name)) {
- return $ReportLanguage->Phrase("NullLabel");
- } elseif ($name == "") {
- return $ReportLanguage->Phrase("EmptyLabel");
- } else {
- return $name;
- }
- }
-
- // Format number for chart
- function ChartFormatNumber($v) {
- $cht_decimalprecision = $this->LoadParm("decimalPrecision");
- if (is_null($cht_decimalprecision)) {
- return $v;
- } else {
- return number_format($v, $cht_decimalprecision, '.', '');
- }
- }
-
- // Write attribute
- function WriteAtt(&$node, $name, $val) {
- $val = $this->CheckColorCode(strval($val));
- $val = $this->ChartEncode($val);
- if ($node->hasAttribute($name)) {
- $node->getAttributeNode($name)->value = ewrpt_XmlEncode(ewrpt_ConvertToUtf8($val));
- } else {
- $att = $this->XmlDoc->createAttribute($name);
- $att->value = ewrpt_XmlEncode(ewrpt_ConvertToUtf8($val));
- $node->appendChild($att);
- }
- }
-
- // Check color code
- function CheckColorCode($val) {
- if (substr($val, 0, 1) == "#" && strlen($val) == 7) {
- return substr($val, 1);
- } else {
- return $val;
- }
- }
-
- // Process chart parms
- function ProcessChartParms(&$ChartType, &$Parms) {
- if ($ChartType == 104) $ChartType = 3; // Bar 3D, Switch back to Bar 2D
-
- // Remove numVisiblePlot (scroll charts)
- if (array_key_exists("numVisiblePlot", $Parms))
- unset($Parms["numVisiblePlot"]);
- }
-
- // Encode special characters for FusionChartsFree
- // + => %2B
- function ChartEncode($val) {
- $v = str_replace("+", "%2B", $val);
- return $v;
- }
-
- // Category content XML (multi series)
- function WriteChartCatContent(&$node, $name) {
- $cat = $this->XmlDoc->createElement('category');
- $this->WriteAtt($cat, "name", $name);
- $node->appendChild($cat);
- }
-
- // Chart content XML
- function WriteChartContent(&$node, $name, $val, $color, $alpha, $lnk) {
- $cht_shownames = $this->LoadParm("shownames");
- $set = $this->XmlDoc->createElement('set');
- $this->WriteAtt($set, "name", $name);
- $this->WriteAtt($set, "value", $this->ChartFormatNumber($val));
- $this->WriteAtt($set, "color", $this->ColorCode($color));
- $this->WriteAtt($set, "alpha", $alpha);
- $this->WriteAtt($set, "link", $lnk);
- if ($cht_shownames == "1")
- $this->WriteAtt($set, "showName", "1");
- $node->appendChild($set);
- }
- }
-
- //
- // Column class
- //
- class crCrosstabColumn {
- var $Caption;
- var $Value;
- var $Visible;
-
- function crCrosstabColumn($value, $caption, $visible = TRUE) {
- $this->Caption = $caption;
- $this->Value = $value;
- $this->Visible = $visible;
- }
- }
-
- //
- // Advanced filter class
- //
- class crAdvancedFilter {
- var $ID;
- var $Name;
- var $FunctionName;
- var $Enabled = TRUE;
-
- function crAdvancedFilter($filterid, $filtername, $filterfunc) {
- $this->ID = $filterid;
- $this->Name = $filtername;
- $this->FunctionName = $filterfunc;
- }
- }
-
- /**
- * List option collection class
- */
-
- class crListOptions {
- var $Items = array();
- var $CustomItem = "";
- var $Tag = "td";
- var $Separator = "";
-
- // Add and return a new option (return-by-reference is for PHP 5 only)
- function &Add($Name) {
- $item = new crListOption($Name, $this->Tag, $this->Separator);
- $item->Parent =& $this;
- $this->Items[$Name] = $item;
- return $item;
- }
-
- // Load default settings
- function LoadDefault() {
- $this->CustomItem = "";
- foreach ($this->Items as $key => $item)
- $this->Items[$key]->Body = "";
- }
-
- // Hide all options
- function HideAllOptions() {
- foreach ($this->Items as $key => $item)
- $this->Items[$key]->Visible = FALSE;
- }
-
- // Show all options
- function ShowAllOptions() {
- foreach ($this->Items as $key => $item)
- $this->Items[$key]->Visible = TRUE;
- }
-
- // Get item by name (return-by-reference is for PHP 5 only)
- // predefined names: view/edit/copy/delete/detail_<DetailTable>/userpermission/checkbox
- function &GetItem($Name) {
- $item = array_key_exists($Name, $this->Items) ? $this->Items[$Name] : NULL;
- return $item;
- }
-
- // Move item to position
- function MoveItem($Name, $Pos) {
- $cnt = count($this->Items);
- if ($Pos < 0 || $Pos >= $cnt)
- return;
- $item = $this->GetItem($Name);
- if ($item) {
- unset($this->Items[$Name]);
- $this->Items = array_merge(array_slice($this->Items, 0, $Pos),
- array($Name => $item), array_slice($this->Items, $Pos));
- }
- }
-
- // Render list options
- function Render($Part, $Pos="") {
- if ($this->CustomItem <> "") {
- $cnt = 0;
- foreach ($this->Items as &$item) {
- if ($item->Visible && $this->ShowPos($item->OnLeft, $Pos))
- $cnt++;
- if ($item->Name == $this->CustomItem)
- $opt = $item;
- }
- if (is_object($opt) && $cnt > 0) {
- if ($this->ShowPos($opt->OnLeft, $Pos)) {
- echo $opt->Render($Part, $cnt);
- } else {
- echo $opt->Render("", $cnt);
- }
- }
- } else {
- foreach ($this->Items as &$item) {
- if ($item->Visible && $this->ShowPos($item->OnLeft, $Pos))
- echo $item->Render($Part);
- }
- }
- }
-
- function ShowPos($OnLeft, $Pos) {
- return ($OnLeft && $Pos == "left") || (!$OnLeft && $Pos == "right") || ($Pos == "");
- }
- }
-
- /**
- * List option class
- */
-
- class crListOption {
- var $Name;
- var $OnLeft;
- var $CssStyle;
- var $Visible = TRUE;
- var $Header;
- var $Body;
- var $Footer;
- var $Tag = "td";
- var $Separator = "";
- var $Parent;
-
- function crListOption($Name, $Tag, $Separator) {
- $this->Name = $Name;
- $this->Tag = $Tag;
- $this->Separator = $Separator;
- }
-
- function MoveTo($Pos) {
- $this->Parent->MoveItem($this->Name, $Pos);
- }
-
- function Render($Part, $ColSpan = 1) {
- if ($Part == "header") {
- $value = $this->Header;
- } elseif ($Part == "body") {
- $value = $this->Body;
- } elseif ($Part == "footer") {
- $value = $this->Footer;
- } else {
- $value = $Part;
- }
- if (strval($value) == "" && strtolower($this->Tag) <> "td")
- return "";
- $res = ($value <> "") ? $value : " ";
- $tage = "</" . $this->Tag . ">";
- $tags = "<" . $this->Tag;
- if ($this->CssStyle <> "")
- $tags .= " style=\"" . $this->CssStyle . "\"";
- if (strtolower($this->Tag) == "td" && $ColSpan > 1)
- $tags .= " colspan=\"" . $ColSpan . "\"";
- $tags .= " class=\"phpmaker\"";
- $tags .= ">";
- $res = $tags . $res . $tage . $this->Separator;
- return $res;
- }
- }
-
- /…
Large files files are truncated, but you can click here to view the full file