PageRenderTime 69ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/phprptinc/ewrfn5.php

https://bitbucket.org/joemarmatulac/ebutton
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

  1. <?php
  2. // Functions for PHP Report Maker 5
  3. // (C) 2007-2011 e.World Technology Limited
  4. if (!function_exists("G")) {
  5. function &G($name) {
  6. return $GLOBALS[$name];
  7. }
  8. }
  9. // Get current page object
  10. function &CurrentPage() {
  11. return $GLOBALS["Page"];
  12. }
  13. // Get current main table object
  14. function &CurrentTable() {
  15. return $GLOBALS["Table"];
  16. }
  17. /**
  18. * Langauge class for reports
  19. */
  20. class crLanguage {
  21. var $LanguageId;
  22. var $Phrases = NULL;
  23. // Constructor
  24. function crLanguage() {
  25. global $gsLanguage;
  26. $this->LoadFileList(); // Set up file list
  27. if (@$_GET["language"] <> "") { // Set up language id
  28. $this->LanguageId = $_GET["language"];
  29. $_SESSION[EWRPT_SESSION_LANGUAGE_ID] = $this->LanguageId;
  30. } elseif (@$_SESSION[EWRPT_SESSION_LANGUAGE_ID] <> "") {
  31. $this->LanguageId = $_SESSION[EWRPT_SESSION_LANGUAGE_ID];
  32. } else {
  33. $this->LanguageId = EWRPT_LANGUAGE_DEFAULT_ID;
  34. }
  35. $gsLanguage = $this->LanguageId;
  36. $this->Load($this->LanguageId);
  37. }
  38. // Load language file list
  39. function LoadFileList() {
  40. global $EWRPT_LANGUAGE_FILE;
  41. if (is_array($EWRPT_LANGUAGE_FILE)) {
  42. $cnt = count($EWRPT_LANGUAGE_FILE);
  43. for ($i = 0; $i < $cnt; $i++)
  44. $EWRPT_LANGUAGE_FILE[$i][1] = $this->LoadFileDesc(EWRPT_LANGUAGE_FOLDER . $EWRPT_LANGUAGE_FILE[$i][2]);
  45. }
  46. }
  47. // Load language file description
  48. function LoadFileDesc($File) {
  49. if (EWRPT_USE_DOM_XML) {
  50. $this->Phrases = new crXMLDocument();
  51. if ($this->Phrases->Load($File))
  52. return $this->GetNodeAtt($this->Phrases->DocumentElement(), "desc");
  53. } else {
  54. $ar = ewrpt_Xml2Array(substr(file_get_contents($File), 0, 512)); // Just read the first part
  55. return (is_array($ar)) ? @$ar['ew-language']['attr']['desc'] : "";
  56. }
  57. }
  58. // Load language file
  59. function Load($id) {
  60. $sFileName = $this->GetFileName($id);
  61. if ($sFileName == "")
  62. $sFileName = $this->GetFileName(EWRPT_LANGUAGE_DEFAULT_ID);
  63. if ($sFileName == "")
  64. return;
  65. if (EWRPT_USE_DOM_XML) {
  66. $this->Phrases = new crXMLDocument();
  67. $this->Phrases->Load($sFileName);
  68. } else {
  69. if (is_array(@$_SESSION[EWRPT_PROJECT_VAR . "_" . $sFileName])) {
  70. $this->Phrases = $_SESSION[EWRPT_PROJECT_VAR . "_" . $sFileName];
  71. } else {
  72. $this->Phrases = ewrpt_Xml2Array(file_get_contents($sFileName));
  73. }
  74. }
  75. }
  76. // Get language file name
  77. function GetFileName($Id) {
  78. global $EWRPT_LANGUAGE_FILE;
  79. if (is_array($EWRPT_LANGUAGE_FILE)) {
  80. $cnt = count($EWRPT_LANGUAGE_FILE);
  81. for ($i = 0; $i < $cnt; $i++)
  82. if ($EWRPT_LANGUAGE_FILE[$i][0] == $Id) {
  83. return EWRPT_LANGUAGE_FOLDER . $EWRPT_LANGUAGE_FILE[$i][2];
  84. }
  85. }
  86. return "";
  87. }
  88. // Get node attribute
  89. function GetNodeAtt($Nodes, $Att) {
  90. $value = ($Nodes) ? $this->Phrases->GetAttribute($Nodes, $Att) : "";
  91. //return ewrpt_ConvertFromUtf8($value);
  92. return $value;
  93. }
  94. // Get phrase
  95. function Phrase($Name) {
  96. if (is_object($this->Phrases)) {
  97. return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//global/phrase[@id='" . strtolower($Name) . "']"), "value");
  98. } elseif (is_array($this->Phrases)) {
  99. return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['global']['phrase'][strtolower($Name)]['attr']['value']);
  100. }
  101. }
  102. // Get project phrase
  103. function ProjectPhrase($Id) {
  104. if (is_object($this->Phrases)) {
  105. return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/phrase[@id='" . strtolower($Id) . "']"), "value");
  106. } elseif (is_array($this->Phrases)) {
  107. return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['phrase'][strtolower($Id)]['attr']['value']);
  108. }
  109. }
  110. // Set project phrase
  111. function setProjectPhrase($Id, $Value) {
  112. if (is_array($this->Phrases)) {
  113. $this->Phrases['ew-language']['project']['phrase'][strtolower($Id)]['attr']['value'] = $Value;
  114. }
  115. }
  116. // Get menu phrase
  117. function MenuPhrase($MenuId, $Id) {
  118. if (is_object($this->Phrases)) {
  119. return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/menu[@id='" . $MenuId . "']/phrase[@id='" . strtolower($Id) . "']"), "value");
  120. } elseif (is_array($this->Phrases)) {
  121. return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['menu'][$MenuId]['phrase'][strtolower($Id)]['attr']['value']);
  122. }
  123. }
  124. // Set menu phrase
  125. function setMenuPhrase($MenuId, $Id, $Value) {
  126. if (is_array($this->Phrases)) {
  127. $this->Phrases['ew-language']['project']['menu'][$MenuId]['phrase'][strtolower($Id)]['attr']['value'] = $Value;
  128. }
  129. }
  130. // Get table phrase
  131. function TablePhrase($TblVar, $Id) {
  132. if (is_object($this->Phrases)) {
  133. return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/table[@id='" . strtolower($TblVar) . "']/phrase[@id='" . strtolower($Id) . "']"), "value");
  134. } elseif (is_array($this->Phrases)) {
  135. return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['phrase'][strtolower($Id)]['attr']['value']);
  136. }
  137. }
  138. // Set table phrase
  139. function setTablePhrase($TblVar, $Id, $Value) {
  140. if (is_array($this->Phrases)) {
  141. $this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['phrase'][strtolower($Id)]['attr']['value'] = $Value;
  142. }
  143. }
  144. // Get chart phrase
  145. function ChartPhrase($TblVar, $ChtVar, $Id) {
  146. if (is_object($this->Phrases)) {
  147. return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/table[@id='" . strtolower($TblVar) . "']/chart[@id='" . strtolower($ChtVar) . "']/phrase[@id='" . strtolower($Id) . "']"), "value");
  148. } elseif (is_array($this->Phrases)) {
  149. return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['chart'][strtolower($ChtVar)]['phrase'][strtolower($Id)]['attr']['value']);
  150. }
  151. }
  152. // Set chart phrase
  153. function setChartPhrase($TblVar, $FldVar, $Id, $Value) {
  154. if (is_array($this->Phrases)) {
  155. $this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['chart'][strtolower($FldVar)]['phrase'][strtolower($Id)]['attr']['value'] = $Value;
  156. }
  157. }
  158. // Get field phrase
  159. function FieldPhrase($TblVar, $FldVar, $Id) {
  160. if (is_object($this->Phrases)) {
  161. return $this->GetNodeAtt($this->Phrases->SelectSingleNode("//project/table[@id='" . strtolower($TblVar) . "']/field[@id='" . strtolower($FldVar) . "']/phrase[@id='" . strtolower($Id) . "']"), "value");
  162. } elseif (is_array($this->Phrases)) {
  163. return ewrpt_ConvertFromUtf8(@$this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['field'][strtolower($FldVar)]['phrase'][strtolower($Id)]['attr']['value']);
  164. }
  165. }
  166. // Set field phrase
  167. function setFieldPhrase($TblVar, $FldVar, $Id, $Value) {
  168. if (is_array($this->Phrases)) {
  169. $this->Phrases['ew-language']['project']['table'][strtolower($TblVar)]['field'][strtolower($FldVar)]['phrase'][strtolower($Id)]['attr']['value'] = $Value;
  170. }
  171. }
  172. // Output XML as JSON
  173. function XmlToJSON($XPath) {
  174. $NodeList = $this->Phrases->SelectNodes($XPath);
  175. $Str = "{";
  176. foreach ($NodeList as $Node) {
  177. $Id = $this->GetNodeAtt($Node, "id");
  178. $Value = $this->GetNodeAtt($Node, "value");
  179. $Str .= "\"" . ewrpt_JsEncode2($Id) . "\":\"" . ewrpt_JsEncode2($Value) . "\",";
  180. }
  181. if (substr($Str, -1) == ",") $Str = substr($Str, 0, strlen($Str)-1);
  182. $Str .= "}";
  183. return $Str;
  184. }
  185. // Output array as JSON
  186. function ArrayToJSON($client) {
  187. $ar = @$this->Phrases['ew-language']['global']['phrase'];
  188. $Str = "{";
  189. if (is_array($ar)) {
  190. foreach ($ar as $id => $node) {
  191. $is_client = @$node['attr']['client'] == '1';
  192. $value = ewrpt_ConvertFromUtf8(@$node['attr']['value']);
  193. if (!$client || ($client && $is_client))
  194. $Str .= "\"" . ewrpt_JsEncode2($id) . "\":\"" . ewrpt_JsEncode2($value) . "\",";
  195. }
  196. }
  197. if (substr($Str, -1) == ",") $Str = substr($Str, 0, strlen($Str)-1);
  198. $Str .= "}";
  199. return $Str;
  200. }
  201. // Output all phrases as JSON
  202. function AllToJSON() {
  203. if (is_object($this->Phrases)) {
  204. return "var ewLanguage = new ewrpt_Language(" . $this->XmlToJSON("//global/phrase") . ");";
  205. } elseif (is_array($this->Phrases)) {
  206. return "var ewLanguage = new ewrpt_Language(" . $this->ArrayToJSON(FALSE) . ");";
  207. }
  208. }
  209. // Output client phrases as JSON
  210. function ToJSON() {
  211. if (is_object($this->Phrases)) {
  212. return "var ewLanguage = new ewrpt_Language(" . $this->XmlToJSON("//global/phrase[@client='1']") . ");";
  213. } elseif (is_array($this->Phrases)) {
  214. return "var ewLanguage = new ewrpt_Language(" . $this->ArrayToJSON(TRUE) . ");";
  215. }
  216. }
  217. }
  218. // Convert XML to array
  219. function ewrpt_Xml2Array($contents) {
  220. if (!$contents) return array();
  221. if (!function_exists('xml_parser_create')) return FALSE;
  222. $get_attributes = 1; // Always get attributes. DO NOT CHANGE!
  223. // Get the XML Parser of PHP
  224. $parser = xml_parser_create();
  225. xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); // Always return in utf-8
  226. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  227. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  228. xml_parse_into_struct($parser, trim($contents), $xml_values);
  229. xml_parser_free($parser);
  230. if (!$xml_values) return;
  231. $xml_array = array();
  232. $parents = array();
  233. $opened_tags = array();
  234. $arr = array();
  235. $current = &$xml_array;
  236. $repeated_tag_index = array(); // Multiple tags with same name will be turned into an array
  237. foreach ($xml_values as $data) {
  238. unset($attributes, $value); // Remove existing values
  239. // Extract these variables into the foreach scope
  240. // tag(string), type(string), level(int), attributes(array)
  241. extract($data);
  242. $result = array();
  243. if (isset($value))
  244. $result['value'] = $value; // Put the value in a assoc array
  245. // Set the attributes
  246. if (isset($attributes) and $get_attributes) {
  247. foreach ($attributes as $attr => $val)
  248. $result['attr'][$attr] = $val; // Set all the attributes in a array called 'attr'
  249. }
  250. // See tag status and do the needed
  251. if ($type == "open") { // The starting of the tag '<tag>'
  252. $parent[$level-1] = &$current;
  253. if (!is_array($current) || !in_array($tag, array_keys($current))) { // Insert New tag
  254. if ($tag <> 'ew-language' && @$result['attr']['id'] <> '') { //
  255. $last_item_index = $result['attr']['id'];
  256. $current[$tag][$last_item_index] = $result;
  257. $repeated_tag_index[$tag.'_'.$level] = 1;
  258. $current = &$current[$tag][$last_item_index];
  259. } else {
  260. $current[$tag] = $result;
  261. $repeated_tag_index[$tag.'_'.$level] = 0;
  262. $current = &$current[$tag];
  263. }
  264. } else { // Another element with the same tag name
  265. if ($repeated_tag_index[$tag.'_'.$level] > 0) { // If there is a 0th element it is already an array
  266. if (@$result['attr']['id'] <> '') {
  267. $last_item_index = $result['attr']['id'];
  268. } else {
  269. $last_item_index = $repeated_tag_index[$tag.'_'.$level];
  270. }
  271. $current[$tag][$last_item_index] = $result;
  272. $repeated_tag_index[$tag.'_'.$level]++;
  273. } else { // Make the value an array if multiple tags with the same name appear together
  274. $temp = $current[$tag];
  275. $current[$tag] = array();
  276. if (@$temp['attr']['id'] <> '') {
  277. $current[$tag][$temp['attr']['id']] = $temp;
  278. } else {
  279. $current[$tag][] = $temp;
  280. }
  281. if (@$result['attr']['id'] <> '') {
  282. $last_item_index = $result['attr']['id'];
  283. } else {
  284. $last_item_index = 1;
  285. }
  286. $current[$tag][$last_item_index] = $result;
  287. $repeated_tag_index[$tag.'_'.$level] = 2;
  288. }
  289. $current = &$current[$tag][$last_item_index];
  290. }
  291. } elseif ($type == "complete") { // Tags that ends in one line '<tag>'
  292. if (!isset($current[$tag])) { // New key
  293. $current[$tag] = array(); // Always use array for "complete" type
  294. if (@$result['attr']['id'] <> '') {
  295. $current[$tag][$result['attr']['id']] = $result;
  296. } else {
  297. $current[$tag][] = $result;
  298. }
  299. $repeated_tag_index[$tag.'_'.$level] = 1;
  300. } else { // Existing key
  301. if (@$result['attr']['id'] <> '') {
  302. $current[$tag][$result['attr']['id']] = $result;
  303. } else {
  304. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
  305. }
  306. $repeated_tag_index[$tag.'_'.$level]++;
  307. }
  308. } elseif ($type == 'close') { // End of tag '</tag>'
  309. $current = &$parent[$level-1];
  310. }
  311. }
  312. return($xml_array);
  313. }
  314. /**
  315. * XML document class
  316. */
  317. class crXMLDocument {
  318. var $Encoding = "utf-8";
  319. var $RootTagName;
  320. var $RowTagName;
  321. var $XmlDoc = FALSE;
  322. var $XmlTbl;
  323. var $XmlRow;
  324. var $NullValue = 'NULL';
  325. function crXMLDocument($encoding = "") {
  326. if ($encoding <> "")
  327. $this->Encoding = $encoding;
  328. if ($this->Encoding <> "") {
  329. $this->XmlDoc = new DOMDocument("1.0", strval($this->Encoding));
  330. } else {
  331. $this->XmlDoc = new DOMDocument("1.0");
  332. }
  333. }
  334. function Load($filename) {
  335. $filepath = realpath($filename);
  336. return $this->XmlDoc->load($filepath);
  337. }
  338. function &DocumentElement() {
  339. $de = $this->XmlDoc->documentElement;
  340. return $de;
  341. }
  342. function GetAttribute($element, $name) {
  343. return ($element) ? ewrpt_ConvertFromUtf8($element->getAttribute($name)) : "";
  344. }
  345. function SelectSingleNode($query) {
  346. $elements = $this->SelectNodes($query);
  347. return ($elements->length > 0) ? $elements->item(0) : NULL;
  348. }
  349. function SelectNodes($query) {
  350. $xpath = new DOMXPath($this->XmlDoc);
  351. return $xpath->query($query);
  352. }
  353. function AddRoot($roottagname = 'table') {
  354. $this->RootTagName = $roottagname;
  355. $this->XmlTbl = $this->XmlDoc->createElement($this->RootTagName);
  356. $this->XmlDoc->appendChild($this->XmlTbl);
  357. }
  358. function AddRow($rowtagname = 'row') {
  359. $this->RowTagName = $rowtagname;
  360. $this->XmlRow = $this->XmlDoc->createElement($this->RowTagName);
  361. if ($this->XmlTbl)
  362. $this->XmlTbl->appendChild($this->XmlRow);
  363. }
  364. function AddField($name, $value) {
  365. if (is_null($value)) $value = $this->NullValue;
  366. $value = ewrpt_ConvertToUtf8($value); // Convert to UTF-8
  367. $xmlfld = $this->XmlDoc->createElement($name);
  368. $this->XmlRow->appendChild($xmlfld);
  369. $xmlfld->appendChild($this->XmlDoc->createTextNode($value));
  370. }
  371. function XML() {
  372. return $this->XmlDoc->saveXML();
  373. }
  374. }
  375. // Select nodes from XML document
  376. function &ewrpt_SelectNodes(&$xmldoc, $query) {
  377. if ($xmldoc) {
  378. $xpath = new DOMXPath($xmldoc);
  379. return $xpath->query($query);
  380. }
  381. return NULL;
  382. }
  383. // Select single node from XML document
  384. function &ewrpt_SelectSingleNode(&$xmldoc, $query) {
  385. $elements = ewrpt_SelectNodes($xmldoc, $query);
  386. return ($elements && $elements->length > 0) ? $elements->item(0) : NULL;
  387. }
  388. // Debug timer
  389. class crTimer {
  390. var $StartTime;
  391. var $EndTime;
  392. function crTimer($start = TRUE) {
  393. if ($start)
  394. $this->Start();
  395. }
  396. function GetTime() {
  397. list($usec, $sec) = explode(" ", microtime());
  398. return ((float)$usec + (float)$sec);
  399. }
  400. // Get script start time
  401. function Start() {
  402. if (EWRPT_DEBUG_ENABLED)
  403. $this->StartTime = $this->GetTime();
  404. }
  405. // display elapsed time (in seconds)
  406. function Stop() {
  407. if (EWRPT_DEBUG_ENABLED)
  408. $this->EndTime = $this->GetTime();
  409. if (isset($this->EndTime) && isset($this->StartTime) &&
  410. $this->EndTime > $this->StartTime)
  411. echo '<p>Page processing time: ' . ($this->EndTime - $this->StartTime) . ' seconds</p>';
  412. }
  413. }
  414. /**
  415. * Field class
  416. */
  417. class crField {
  418. var $TblName; // Table name
  419. var $TblVar; // Table variable name
  420. var $FldName; // Field name
  421. var $FldVar; // Field variable name
  422. var $FldExpression; // Field expression (used in SQL)
  423. var $FldDefaultErrMsg; // Default error message
  424. var $FldType; // Field type
  425. var $FldDataType; // PHPMaker Field type
  426. var $FldDateTimeFormat; // Date time format
  427. var $Count; // Count
  428. var $SumValue; // Sum
  429. var $AvgValue; // Average
  430. var $MinValue; // Minimum
  431. var $MaxValue; // MaxValue
  432. var $SumViewValue; // Sum
  433. var $AvgViewValue; // Average
  434. var $MinViewValue; // Minimum
  435. var $MaxViewValue; // MaxValue
  436. var $OldValue; // Old Value
  437. var $CurrentValue; // Current value
  438. var $ViewValue; // View value
  439. var $HrefValue; // Href value
  440. var $FormValue; // Form value
  441. var $QueryStringValue; // QueryString value
  442. var $DbValue; // Database value
  443. var $ImageWidth = 0; // Image width
  444. var $ImageHeight = 0; // Image height
  445. var $ImageResize = FALSE; // Image resize
  446. var $Sortable = TRUE; // Sortable
  447. var $GroupingFieldId = 0; // Grouping field id
  448. var $UploadPath = EWRPT_UPLOAD_DEST_PATH; // Upload path
  449. var $TruncateMemoRemoveHtml = FALSE; // Remove HTML from memo field
  450. var $CellAttrs = array(); // Cell custom attributes
  451. var $ViewAttrs = array(); // View custom attributes
  452. var $LinkAttrs = array(); // Href custom attributes
  453. var $FldGroupByType; // Group By Type
  454. var $FldGroupInt; // Group Interval
  455. var $FldGroupSql; // Group SQL
  456. var $GroupDbValues; // Group DB Values
  457. var $GroupViewValue; // Group View Value
  458. var $GroupSummaryOldValue; // Group Summary Old Value
  459. var $GroupSummaryValue; // Group Summary Value
  460. var $GroupSummaryViewValue; // Group Summary View Value
  461. var $SqlSelect; // Field SELECT
  462. var $SqlGroupBy; // Field GROUP BY
  463. var $SqlOrderBy; // Field ORDER BY
  464. var $ValueList; // Value List
  465. var $SelectionList; // Selection List
  466. var $DefaultSelectionList; // Default Selection List
  467. var $AdvancedFilters; // Advanced Filters
  468. var $RangeFrom; // Range From
  469. var $RangeTo; // Range To
  470. var $DropDownList; // Dropdown List
  471. var $DropDownValue; // Dropdown Value
  472. var $DefaultDropDownValue; // Default Dropdown Value
  473. var $DateFilter; // Date Filter
  474. var $SearchValue; // Search Value 1
  475. var $SearchValue2; // Search Value 2
  476. var $SearchOperator; // Search Operator 1
  477. var $SearchOperator2; // Search Operator 2
  478. var $SearchCondition; // Search Condition
  479. var $DefaultSearchValue; // Default Search Value 1
  480. var $DefaultSearchValue2; // Default Search Value 2
  481. var $DefaultSearchOperator; // Default Search Operator 1
  482. var $DefaultSearchOperator2; // Default Search Operator 2
  483. var $DefaultSearchCondition; // Default Search Condition
  484. // Constructor
  485. function crField($tblvar, $tblname, $fldvar, $fldname, $fldexpression, $fldtype, $flddatatype, $flddtfmt) {
  486. $this->TblVar = $tblvar;
  487. $this->TblName = $tblname;
  488. $this->FldVar = $fldvar;
  489. $this->FldName = $fldname;
  490. $this->FldExpression = $fldexpression;
  491. $this->FldType = $fldtype;
  492. $this->FldDataType = $flddatatype;
  493. $this->FldDateTimeFormat = $flddtfmt;
  494. }
  495. // Field caption
  496. function FldCaption() {
  497. global $ReportLanguage;
  498. return $ReportLanguage->FieldPhrase($this->TblVar, substr($this->FldVar, 2), "FldCaption");
  499. }
  500. // Field title
  501. function FldTitle() {
  502. global $ReportLanguage;
  503. return $ReportLanguage->FieldPhrase($this->TblVar, substr($this->FldVar, 2), "FldTitle");
  504. }
  505. // Field image alt
  506. function FldAlt() {
  507. global $ReportLanguage;
  508. return $ReportLanguage->FieldPhrase($this->TblVar, substr($this->FldVar, 2), "FldAlt");
  509. }
  510. // Field error message
  511. function FldErrMsg() {
  512. global $ReportLanguage;
  513. $err = $ReportLanguage->FieldPhrase($this->TblVar, substr($this->FldVar, 2), "FldErrMsg");
  514. if ($err == "") $err = $this->FldDefaultErrMsg . " - " . $this->FldCaption();
  515. return $err;
  516. }
  517. // Reset CSS styles for field object
  518. function ResetCSS() {
  519. $this->CellAttrs["style"] = "";
  520. $this->CellAttrs["class"] = "";
  521. $this->ViewAttrs["style"] = "";
  522. $this->ViewAttrs["class"] = "";
  523. }
  524. // View Attributes
  525. function ViewAttributes() {
  526. $sAtt = "";
  527. if (intval($this->ImageWidth) > 0 && (!$this->ImageResize || ($this->ImageResize && intval($this->ImageHeight) <= 0)))
  528. $sAtt .= " width=\"" . intval($this->ImageWidth) . "\"";
  529. if (intval($this->ImageHeight) > 0 && (!$this->ImageResize || ($this->ImageResize && intval($this->ImageWidth) <= 0)))
  530. $sAtt .= " height=\"" . intval($this->ImageHeight) . "\"";
  531. foreach ($this->ViewAttrs as $k => $v) {
  532. if (trim($v) <> "")
  533. $sAtt .= " " . $k . "=\"" . trim($v) . "\"";
  534. }
  535. return $sAtt;
  536. }
  537. // Link Attributes
  538. function LinkAttributes() {
  539. $sAtt = "";
  540. $sHref = trim($this->HrefValue);
  541. foreach ($this->LinkAttrs as $k => $v) {
  542. if (trim($v) <> "") {
  543. if ($k == "href")
  544. $sHref .= " " . $v;
  545. else
  546. $sAtt .= " " . $k . "=\"" . trim($v) . "\"";
  547. }
  548. }
  549. if ($sHref <> "")
  550. $sAtt .= " href=\"" . trim($sHref) . "\"";
  551. // if (trim($this->LinkCustomAttributes) <> "")
  552. // $sAtt .= " " . trim($this->LinkCustomAttributes);
  553. return $sAtt;
  554. }
  555. // Cell attributes
  556. function CellAttributes() {
  557. $sAtt = "";
  558. foreach ($this->CellAttrs as $k => $v) {
  559. if (trim($v) <> "")
  560. $sAtt .= " " . $k . "=\"" . trim($v) . "\"";
  561. }
  562. return $sAtt;
  563. }
  564. // Sort
  565. function getSort() {
  566. return @$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TblVar . "_" . EWRPT_TABLE_SORT . "_" . $this->FldVar];
  567. }
  568. function setSort($v) {
  569. if (@$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TblVar . "_" . EWRPT_TABLE_SORT . "_" . $this->FldVar] <> $v) {
  570. $_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TblVar . "_" . EWRPT_TABLE_SORT . "_" . $this->FldVar] = $v;
  571. }
  572. }
  573. function ReverseSort() {
  574. return ($this->getSort() == "ASC") ? "DESC" : "ASC";
  575. }
  576. // List view value
  577. function ListViewValue() {
  578. $value = trim(strval($this->ViewValue));
  579. if ($value <> "") {
  580. $value2 = trim(preg_replace('/<[^img][^>]*>/i', '', strval($value)));
  581. return ($value2 <> "") ? $this->ViewValue : "&nbsp;";
  582. } else {
  583. return "&nbsp;";
  584. }
  585. }
  586. // Form value
  587. function setFormValue($v) {
  588. $this->FormValue = ewrpt_StripSlashes($v);
  589. if (is_array($this->FormValue))
  590. $this->FormValue = implode(",", $this->FormValue);
  591. $this->CurrentValue = $this->FormValue;
  592. }
  593. // QueryString value
  594. function setQueryStringValue($v) {
  595. $this->QueryStringValue = ewrpt_StripSlashes($v);
  596. $this->CurrentValue = $this->QueryStringValue;
  597. }
  598. // Database value
  599. function setDbValue($v) {
  600. $this->OldValue = $this->DbValue;
  601. if (EWRPT_IS_MSSQL && ($this->FldType == 131 || $this->FldType == 139)) // MS SQL adNumeric/adVarNumeric field
  602. $this->DbValue = floatval($v);
  603. else
  604. $this->DbValue = $v;
  605. $this->CurrentValue = $this->DbValue;
  606. }
  607. // Group value
  608. function GroupValue() {
  609. return $this->getGroupValue($this->CurrentValue);
  610. }
  611. // Group old value
  612. function GroupOldValue() {
  613. return $this->getGroupValue($this->OldValue);
  614. }
  615. // Get group value
  616. function getGroupValue($v) {
  617. if ($this->GroupingFieldId == 1) {
  618. return $v;
  619. } elseif (is_array($this->GroupDbValues)) {
  620. return @$this->GroupDbValues[$v];
  621. } elseif ($this->FldGroupByType <> "" && $this->FldGroupByType <> "n") {
  622. return ewrpt_GroupValue($this, $v);
  623. } else {
  624. return $v;
  625. }
  626. }
  627. }
  628. /**
  629. * Chart class
  630. */
  631. class crChart {
  632. var $TblName; // Table name
  633. var $TblVar; // Table variable name
  634. var $ChartName; // Chart name
  635. var $ChartVar; // Chart variable name
  636. var $ChartXFldName; // Chart X Field name
  637. var $ChartYFldName; // Chart Y Field name
  638. var $ChartSFldName; // Chart Series Field name
  639. var $ChartType; // Chart Type
  640. var $ChartSummaryType; // Chart Type
  641. var $ChartWidth; // Chart Width
  642. var $ChartHeight; // Chart Height
  643. var $ChartAlign; // Chart Align
  644. var $SqlSelect;
  645. var $SqlGroupBy;
  646. var $SqlOrderBy;
  647. var $XAxisDateFormat;
  648. var $NameDateFormat;
  649. var $SeriesDateType;
  650. var $SqlSelectSeries;
  651. var $SqlGroupBySeries;
  652. var $SqlOrderBySeries;
  653. var $ID;
  654. var $Parms = array();
  655. var $Trends;
  656. var $Data;
  657. var $Series;
  658. var $XmlDoc;
  659. var $XmlRoot;
  660. // Constructor
  661. function crChart($tblvar, $tblname, $chartvar, $chartname, $xfld, $yfld, $sfld, $type, $smrytype, $width, $height, $align="") {
  662. $this->TblVar = $tblvar;
  663. $this->TblName = $tblname;
  664. $this->ChartVar = $chartvar;
  665. $this->ChartName = $chartname;
  666. $this->ChartXFldName = $xfld;
  667. $this->ChartYFldName = $yfld;
  668. $this->ChartSFldName = $sfld;
  669. $this->ChartType = $type;
  670. $this->ChartSummaryType = $smrytype;
  671. $this->ChartWidth = $width;
  672. $this->ChartHeight = $height;
  673. $this->ChartAlign = $align;
  674. $this->ID = NULL;
  675. $this->Parms = NULL;
  676. $this->Trends = NULL;
  677. $this->Data = NULL;
  678. $this->Series = NULL;
  679. $this->XmlDoc = new DOMDocument("1.0", "utf-8");
  680. }
  681. // Chart caption
  682. function ChartCaption() {
  683. global $ReportLanguage;
  684. return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartCaption");
  685. }
  686. // function xaxisname
  687. function ChartXAxisName() {
  688. global $ReportLanguage;
  689. return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartXAxisName");
  690. }
  691. // function yaxisname
  692. function ChartYAxisName() {
  693. global $ReportLanguage;
  694. return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartYAxisName");
  695. }
  696. // function PYAxisName
  697. function ChartPYAxisName() {
  698. global $ReportLanguage;
  699. return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartPYAxisName");
  700. }
  701. // function SYAxisName
  702. function ChartSYAxisName() {
  703. global $ReportLanguage;
  704. return $ReportLanguage->ChartPhrase($this->TblVar, $this->ChartVar, "ChartSYAxisName");
  705. }
  706. // Set chart parameters
  707. function SetChartParam($Name, $Value, $Output) {
  708. $this->Parms[$Name] = array($Name, $Value, $Output);
  709. }
  710. // Set up default chart parm
  711. function SetupDefaultChartParm($key, $value) {
  712. if (is_array($this->Parms)) {
  713. $parm = $this->LoadParm($key);
  714. if (is_null($parm)) {
  715. $this->Parms[$key] = array($key, $value, TRUE);
  716. } elseif ($parm == "") {
  717. $this->SaveParm($key, $value);
  718. }
  719. }
  720. }
  721. // Load chart parm
  722. function LoadParm($key) {
  723. if (is_array($this->Parms) && array_key_exists($key, $this->Parms))
  724. return $this->Parms[$key][1];
  725. return NULL;
  726. }
  727. // Save chart parm
  728. function SaveParm($key, $value) {
  729. if (is_array($this->Parms) && array_key_exists($key, $this->Parms))
  730. $this->Parms[$key][1] = $value;
  731. }
  732. // Chart Xml
  733. function ChartXml() {
  734. // Initialize default values
  735. $this->SetupDefaultChartParm("caption", "Chart");
  736. // Show names/values/hover
  737. $this->SetupDefaultChartParm("shownames", "1"); // Default show names
  738. $this->SetupDefaultChartParm("showvalues", "1"); // Default show values
  739. $this->SetupDefaultChartParm("showhover", "1"); // Default show hover
  740. // Get showvalues/showhovercap
  741. $cht_showValues = $this->LoadParm("showvalues");
  742. $cht_showHoverCap = $this->LoadParm("showhovercap");
  743. // Format percent for Pie charts
  744. $cht_showPercentageValues = $this->LoadParm("showPercentageValues");
  745. $cht_showPercentageInLabel = $this->LoadParm("showPercentageInLabel");
  746. $cht_type = $this->LoadParm("type");
  747. if ($cht_type == 2 || $cht_type == 6 || $cht_type == 8 || $cht_type == 101) {
  748. if (($cht_showHoverCap == "1" && $cht_showPercentageValues == "1") ||
  749. ($cht_showValues == "1" && $cht_showPercentageInLabel == "1")) {
  750. $this->SetupDefaultChartParm("formatNumber", "1");
  751. $this->SaveParm("formatNumber", "1");
  752. }
  753. } elseif ($cht_type == 20) {
  754. $this->SetupDefaultChartParm("bearBorderColor", "E33C3C");
  755. $this->SetupDefaultChartParm("bearFillColor", "E33C3C");
  756. }
  757. // Process chart parms
  758. $this->ProcessChartParms($cht_type, $this->Parms);
  759. $chartseries =& $this->Series;
  760. $chartdata =& $this->Data;
  761. $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)
  762. $cht_series_type = $this->LoadParm("seriestype");
  763. $cht_alpha = $this->LoadParm("alpha");
  764. // Hide legend for single series (Bar 3D / Column 2D / Line 2D / Area 2D)
  765. $scrollchart = (intval($this->LoadParm("numVisiblePlot")) > 0 && ($cht_type == 1 || $cht_type == 4 || $cht_type == 7)) ? 1 : 0;
  766. $cht_single_series = ($cht_type == 104 || $scrollchart == 1) ? 1 : 0;
  767. if ($cht_single_series == 1) {
  768. $this->SetupDefaultChartParm("showLegend", "0");
  769. $this->SaveParm("showLegend", "0");
  770. }
  771. if (is_array($chartdata)) {
  772. $this->WriteChartHeader(); // Write chart header
  773. // Candlestick
  774. if ($cht_type == 20) {
  775. // Write candlestick cat
  776. if (count($chartdata[0]) >= 7) {
  777. $cats = $this->XmlDoc->createElement('categories');
  778. $this->XmlRoot->appendChild($cats);
  779. $cntcat = count($chartdata);
  780. for ($i = 0; $i < $cntcat; $i++) {
  781. $xindex = $i+1;
  782. $name = $chartdata[$i][6];
  783. if ($name <> "")
  784. $this->WriteChartCandlestickCatContent($cats, $xindex, $name);
  785. }
  786. }
  787. // Write candlestick data
  788. $data = $this->XmlDoc->createElement('data');
  789. $this->XmlRoot->appendChild($data);
  790. $cntdata = count($chartdata);
  791. for ($i = 0; $i < $cntdata; $i++) {
  792. $open = is_null($chartdata[$i][2]) ? 0 : (float)$chartdata[$i][2];
  793. $high = is_null($chartdata[$i][3]) ? 0 : (float)$chartdata[$i][3];
  794. $low = is_null($chartdata[$i][4]) ? 0 : (float)$chartdata[$i][4];
  795. $close = is_null($chartdata[$i][5]) ? 0 : (float)$chartdata[$i][5];
  796. $xindex = $i+1;
  797. $this->WriteChartCandlestickContent($data, $open, $high, $low, $close, $xindex);
  798. }
  799. // Multi series
  800. } else if ($cht_series == 1) {
  801. // Multi-Y values
  802. if ($cht_series_type == "1") {
  803. // Write cat
  804. $cats = $this->XmlDoc->createElement('categories');
  805. $this->XmlRoot->appendChild($cats);
  806. $cntcat = count($chartdata);
  807. for ($i = 0; $i < $cntcat; $i++) {
  808. $name = $this->ChartFormatName($chartdata[$i][0]);
  809. $this->WriteChartCatContent($cats, $name);
  810. }
  811. // Write series
  812. $cntdata = count($chartdata);
  813. $cntseries = count($chartseries);
  814. if ($cntseries > count($chartdata[0])-2) $cntseries = count($chartdata[0])-2;
  815. for ($i = 0; $i < $cntseries; $i++) {
  816. $color = $this->GetPaletteColor($i);
  817. $bShowSeries = EWRPT_CHART_SHOW_BLANK_SERIES;
  818. $dataset = $this->XmlDoc->createElement('dataset');
  819. $this->WriteChartSeriesHeader($dataset, $chartseries[$i], $color, $cht_alpha);
  820. $bWriteSeriesHeader = TRUE;
  821. for ($j = 0; $j < $cntdata; $j++) {
  822. $val = $chartdata[$j][$i+2];
  823. $val = (is_null($val)) ? 0 : (float)$val;
  824. if ($val <> 0) $bShowSeries = TRUE;
  825. $this->WriteChartSeriesContent($dataset, $val);
  826. }
  827. if ($bShowSeries)
  828. $this->XmlRoot->appendChild($dataset);
  829. }
  830. // Series field
  831. } else {
  832. // Get series names
  833. if (is_array($chartseries)) {
  834. $nSeries = count($chartseries);
  835. } else {
  836. $nSeries = 0;
  837. }
  838. // Write cat
  839. $cats = $this->XmlDoc->createElement('categories');
  840. $this->XmlRoot->appendChild($cats);
  841. $chartcats = array();
  842. $cntdata = count($chartdata);
  843. for ($i = 0; $i < $cntdata; $i++) {
  844. $name = $chartdata[$i][0];
  845. if (!in_array($name, $chartcats)) {
  846. $this->WriteChartCatContent($cats, $name);
  847. $chartcats[] = $name;
  848. }
  849. }
  850. // Write series
  851. for ($i = 0; $i < $nSeries; $i++) {
  852. $seriesname = (is_array($chartseries[$i])) ? $chartseries[$i][0] : $chartseries[$i];
  853. $color = $this->GetPaletteColor($i);
  854. $bShowSeries = EWRPT_CHART_SHOW_BLANK_SERIES;
  855. $dataset = $this->XmlDoc->createElement('dataset');
  856. $this->WriteChartSeriesHeader($dataset, $chartseries[$i], $color, $cht_alpha);
  857. $cntcats = count($chartcats);
  858. $cntdata = count($chartdata);
  859. for ($j = 0; $j < $cntcats; $j++) {
  860. $val = 0;
  861. for ($k = 0; $k < $cntdata; $k++) {
  862. if ($chartdata[$k][0] == $chartcats[$j] && $chartdata[$k][1] == $seriesname) {
  863. $val = $chartdata[$k][2];
  864. $val = (is_null($val)) ? 0 : (float)$val;
  865. if ($val <> 0) $bShowSeries = TRUE;
  866. break;
  867. }
  868. }
  869. $this->WriteChartSeriesContent($dataset, $val);
  870. }
  871. if ($bShowSeries)
  872. $this->XmlRoot->appendChild($dataset);
  873. }
  874. }
  875. // Show single series
  876. } elseif ($cht_single_series == 1) {
  877. // Write multiple cats
  878. $cats = $this->XmlDoc->createElement('categories');
  879. $this->XmlRoot->appendChild($cats);
  880. $cntcat = count($chartdata);
  881. for ($i = 0; $i < $cntcat; $i++) {
  882. $name = $this->ChartFormatName($chartdata[$i][0]);
  883. if ($chartdata[$i][1] <> "")
  884. $name .= ", " . $chartdata[$i][1];
  885. $this->WriteChartCatContent($cats, $name);
  886. }
  887. // Write series
  888. $toolTipSep = $this->LoadParm("toolTipSepChar");
  889. if ($toolTipSep == "") $toolTipSep = ":";
  890. $cntdata = count($chartdata);
  891. $dataset = $this->XmlDoc->createElement('dataset');
  892. $this->WriteChartSeriesHeader($dataset, '', '', $cht_alpha);
  893. for ($i = 0; $i < $cntdata; $i++) {
  894. $name = $this->ChartFormatName($chartdata[$i][0]);
  895. if ($chartdata[$i][1] <> "")
  896. $name .= ", " . $chartdata[$i][1];
  897. $val = $chartdata[$i][2];
  898. $val = (is_null($val)) ? 0 : (float)$val;
  899. $color = $this->GetPaletteColor($i);
  900. $toolText = $name . $toolTipSep . $val;
  901. $this->WriteChartSeriesContent($dataset, $val, $color, $cht_alpha, '', $toolText);
  902. $this->XmlRoot->appendChild($dataset);
  903. }
  904. // Single series
  905. } else {
  906. $cntdata = count($chartdata);
  907. for ($i = 0; $i < $cntdata; $i++) {
  908. $name = $this->ChartFormatName($chartdata[$i][0]);
  909. $color = $this->GetPaletteColor($i);
  910. if ($chartdata[$i][1] <> "")
  911. $name .= ", " . $chartdata[$i][1];
  912. $val = $chartdata[$i][2];
  913. $val = (is_null($val)) ? 0 : (float)$val;
  914. $this->WriteChartContent($this->XmlRoot, $name, $val, $color, $cht_alpha, @$link); // Get chart content
  915. }
  916. }
  917. // Get trend lines
  918. $this->WriteChartTrendLines();
  919. }
  920. $wrk = $this->XmlDoc->saveXML();
  921. return $wrk;
  922. // ewrpt_Trace($wrk);
  923. }
  924. // Show chart (FusionCharts Free)
  925. // typ: chart type (1/2/3/4/...)
  926. // id: chart id
  927. // parms: "bgcolor=FFFFFF|..."
  928. // trends: trend lines
  929. function ShowChartFCF($xml) {
  930. $typ = $this->ChartType;
  931. $id = $this->ID;
  932. $parms = $this->Parms;
  933. $trends = $this->Trends;
  934. $data = $this->Data;
  935. $series = $this->Series;
  936. $width = $this->ChartWidth;
  937. $height = $this->ChartHeight;
  938. $align = $this->ChartAlign;
  939. if (empty($typ))
  940. $typ = 1;
  941. // Get chart swf
  942. switch ($typ) {
  943. // Single Series
  944. case 1: $chartswf = "FCF_Column2D.swf"; break; // Column 2D
  945. case 2: $chartswf = "FCF_Pie2D.swf"; break; // Pie 2D
  946. case 3: $chartswf = "FCF_Bar2D.swf"; break; // Bar 2D
  947. case 4: $chartswf = "FCF_Line.swf"; break; // Line 2D
  948. case 5: $chartswf = "FCF_Column3D.swf"; break; // Column 3D
  949. case 6: $chartswf = "FCF_Pie3D.swf"; break; // Pie 3D
  950. case 7: $chartswf = "FCF_Area2D.swf"; break; // Area 2D
  951. case 8: $chartswf = "FCF_Doughnut2D.swf"; break; // Doughnut 2D
  952. // Multi Series
  953. case 9: $chartswf = "FCF_MSColumn2D.swf"; break; // Multi-series Column 2D
  954. case 10: $chartswf = "FCF_MSColumn3D.swf"; break; // Multi-series Column 3D
  955. case 11: $chartswf = "FCF_MSLine.swf"; break; // Multi-series Line 2D
  956. case 12: $chartswf = "FCF_MSArea2D.swf"; break; // Multi-series Area 2D
  957. case 13: $chartswf = "FCF_MSBar2D.swf"; break; // Multi-series Bar 2D
  958. // Stacked
  959. case 14: $chartswf = "FCF_StackedColumn2D.swf"; break; // Stacked Column 2D
  960. case 15: $chartswf = "FCF_StackedColumn3D.swf"; break; // Stacked Column 3D
  961. case 16: $chartswf = "FCF_StackedArea2D.swf"; break; // Stacked Area 2D
  962. case 17: $chartswf = "FCF_StackedBar2D.swf"; break; // Stacked Bar 2D
  963. // Combination
  964. case 18: $chartswf = "FCF_MSColumn2DLineDY.swf"; break; // Multi-series Column 2D Line Dual Y Chart
  965. case 19: $chartswf = "FCF_MSColumn3DLineDY.swf"; break; // Multi-series Column 3D Line Dual Y Chart
  966. // Financial
  967. case 20: $chartswf = "FCF_Candlestick.swf"; break; // Candlestick
  968. // Other
  969. case 21: $chartswf = "FCF_Gantt.swf"; break; // Gantt
  970. case 22: $chartswf = "FCF_Funnel.swf"; break; // Funnel
  971. // Additional FusionCharts
  972. case 101: $chartswf = "FCF_Doughnut2D.swf"; break; // Doughnut 3D, switch back to 2D
  973. case 102: $chartswf = "FCF_MSBar2D.swf"; break; // Multi-series Bar 3D, switch back to 2D
  974. case 103: $chartswf = "FCF_StackedBar2D.swf"; break; // Stacked Bar 3D, switch back to 2D
  975. case 104: $chartswf = "FCF_Bar2D.swf"; break; // Bar 3D, switch back to 2D
  976. // Default
  977. default: $chartswf = "FCF_Column2D.swf"; // Default = Column 2D
  978. }
  979. // Set width, height and align
  980. if (is_numeric($width) && is_numeric($height)) {
  981. $wrkwidth = $width;
  982. $wrkheight = $height;
  983. } else { // default
  984. $wrkwidth = EWRPT_CHART_WIDTH;
  985. $wrkheight = EWRPT_CHART_HEIGHT;
  986. }
  987. if (strtolower($align) == "left" || strtolower($align) == "right") {
  988. $wrkalign = strtolower($align);
  989. } else {
  990. $wrkalign = EWRPT_CHART_ALIGN; // default
  991. }
  992. // Output JavaScript for FCF
  993. $chartxml = $xml;
  994. $wrk = "<script type=\"text/javascript\">\n";
  995. $wrk .= "var chartwidth = \"$wrkwidth\";\n";
  996. $wrk .= "var chartheight = \"$wrkheight\";\n";
  997. //$wrk .= "var chartalign = \"$wrkalign\";\n";
  998. $wrk .= "var chartxml = \"" . ewrpt_EscapeJs($chartxml) . "\";\n";
  999. $wrk .= "var chartid = \"div_$id\";\n";
  1000. $wrk .= "var chartswf = \"" . EWRPT_FUSIONCHARTS_FREE_CHART_PATH . $chartswf . "\";\n";
  1001. $wrk .= "var cht_$id = new FusionChartsFree(chartswf, \"chart_$id\", chartwidth, chartheight);\n";
  1002. $wrk .= "cht_$id.addParam(\"wmode\", \"transparent\");\n";
  1003. $wrk .= "cht_$id.setDataXML(chartxml);\n";
  1004. $wrk .= "var f = " . CurrentPage()->PageObjName . ".Chart_Rendering;\n";
  1005. $wrk .= "if (typeof f == \"function\") f(cht_$id, 'chart_$id');\n";
  1006. $wrk .= "cht_$id.render(chartid);\n";
  1007. $wrk .= "f = " . CurrentPage()->PageObjName . ".Chart_Rendered;\n";
  1008. $wrk .= "if (typeof f == \"function\") f(cht_$id, 'chart_$id');\n";
  1009. $wrk .= "</script>\n";
  1010. // Add debug xml
  1011. if (EWRPT_DEBUG_ENABLED)
  1012. $wrk .= "<p>(Chart XML): " . ewrpt_HtmlEncode($chartxml) . "</p>";
  1013. return $wrk;
  1014. }
  1015. // Show Chart Xml
  1016. function ShowChartXml() {
  1017. // Build chart content
  1018. $sChartContent = $this->ChartXml();
  1019. header("Content-Type: text/xml; charset=UTF-8");
  1020. // Write utf-8 BOM
  1021. echo "\xEF\xBB\xBF";
  1022. // Write utf-8 encoding
  1023. echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
  1024. // Write content
  1025. echo $sChartContent;
  1026. }
  1027. // Show Chart Text
  1028. function ShowChartText() {
  1029. // Build chart content
  1030. $sChartContent = $this->ChartXml();
  1031. header("Content-Type: text/plain; charset=UTF-8");
  1032. // Write content
  1033. echo $sChartContent;
  1034. }
  1035. // Get color
  1036. function GetPaletteColor($i) {
  1037. $colorpalette = $this->LoadParm("colorpalette");
  1038. $ar_cht_colorpalette = explode("|", $colorpalette);
  1039. if (is_array($ar_cht_colorpalette))
  1040. $cntar = count($ar_cht_colorpalette);
  1041. return $ar_cht_colorpalette[$i % $cntar];
  1042. }
  1043. // Convert to HTML color
  1044. function ColorCode($c) {
  1045. if ($c <> "") {
  1046. // remove #
  1047. $color = str_replace("#", "", $c);
  1048. // fill to 6 digits
  1049. return str_pad($color, 6, "0", STR_PAD_LEFT);
  1050. } else {
  1051. return "";
  1052. }
  1053. }
  1054. // Output chart header
  1055. function WriteChartHeader() {
  1056. $cht_parms = $this->Parms;
  1057. $chartElement = ($this->ChartType == 20 || (EWRPT_FUSIONCHARTS_FREE && $this->ChartType <> 21 && $this->ChartType <> 22)) ? 'graph' : 'chart';
  1058. $chart = $this->XmlDoc->createElement($chartElement);
  1059. $this->XmlRoot =& $chart;
  1060. $this->XmlDoc->appendChild($chart);
  1061. if (is_array($cht_parms)) {
  1062. foreach ($cht_parms as $parm) {
  1063. if ($parm[2])
  1064. $this->WriteAtt($chart, $parm[0], $parm[1]);
  1065. }
  1066. }
  1067. }
  1068. // Get TrendLine XML
  1069. // <trendlines>
  1070. // <line startvalue='0.8' displayValue='Good' color='FF0000' thickness='1' isTrendZone='0'/>
  1071. // <line startvalue='-0.4' displayValue='Bad' color='009999' thickness='1' isTrendZone='0'/>
  1072. // </trendlines>
  1073. function WriteChartTrendLines() {
  1074. $cht_trends = $this->Trends;
  1075. if (is_array($cht_trends)) {
  1076. foreach ($cht_trends as $trend) {
  1077. $trends = $this->XmlDoc->createElement('trendlines');
  1078. $this->XmlRoot->appendChild($trends);
  1079. // Get all trend lines
  1080. $this->WriteChartTrendLine($trends, $trend[0], $trend[1], $trend[2], $trend[3], $trend[4], $trend[5], $trend[6], $trend[7]);
  1081. }
  1082. }
  1083. }
  1084. // Output trend line
  1085. function WriteChartTrendLine(&$node, $startval, $endval, $color, $dispval, $thickness, $trendzone, $showontop, $alpha) {
  1086. $line = $this->XmlDoc->createElement('line');
  1087. $this->WriteAtt($line, "startValue", $startval); // Starting y value
  1088. if ($endval <> 0)
  1089. $this->WriteAtt($line, "endValue", $endval); // Ending y value
  1090. $this->WriteAtt($line, "color", $this->CheckColorCode($color)); // Color
  1091. if ($dispval <> "")
  1092. $this->WriteAtt($line, "displayValue", $dispval); // Display value
  1093. if ($thickness > 0)
  1094. $this->WriteAtt($line, "thickness", $thickness); // Thickness
  1095. $this->WriteAtt($line, "isTrendZone", $trendzone); // Display trend as zone or line
  1096. $this->WriteAtt($line, "showOnTop", $showontop); // Show on top
  1097. if ($alpha > 0)
  1098. $this->WriteAtt($line, "alpha", $alpha); // Alpha
  1099. $node->appendChild($line);
  1100. }
  1101. // Series header/footer XML (multi series)
  1102. function WriteChartSeriesHeader(&$node, $series, $color, $alpha) {
  1103. global $ReportLanguage;
  1104. $seriesname = is_array($series) ? $series[0] : $series;
  1105. if (is_null($seriesname)) {
  1106. $seriesname = $ReportLanguage->Phrase("NullLabel");
  1107. } elseif ($seriesname == "") {
  1108. $seriesname = $ReportLanguage->Phrase("EmptyLabel");
  1109. }
  1110. $this->WriteAtt($node, "seriesname", $seriesname);
  1111. $this->WriteAtt($node, "color", $this->ColorCode($color));
  1112. $this->WriteAtt($node, "alpha", $alpha);
  1113. if (is_array($series))
  1114. $this->WriteAtt($node, "parentYAxis", $series[1]);
  1115. }
  1116. // Series content XML (multi series)
  1117. function WriteChartSeriesContent(&$node, $val, $color = "", $alpha = "", $lnk = "", $toolText = "") {
  1118. $set = $this->XmlDoc->createElement('set');
  1119. $this->WriteAtt($set, "value", $this->ChartFormatNumber($val));
  1120. if ($color <> "")
  1121. $this->WriteAtt($set, "color", $this->ColorCode($color));
  1122. if ($alpha <> "")
  1123. $this->WriteAtt($set, "alpha", $alpha);
  1124. if ($lnk <> "")
  1125. $this->WriteAtt($set, "link", $lnk);
  1126. if ($toolText <> "")
  1127. $this->WriteAtt($set, "toolText", $toolText);
  1128. $node->appendChild($set);
  1129. }
  1130. // Category content XML (Candlestick category)
  1131. function WriteChartCandlestickCatContent(&$node, $xindex, $name) {
  1132. $cat = $this->XmlDoc->createElement('category');
  1133. $this->WriteAtt($cat, "name", $name);
  1134. $this->WriteAtt($cat, "xindex", $xindex);
  1135. $this->WriteAtt($cat, "showline", "1");
  1136. $node->appendChild($cat);
  1137. }
  1138. // Chart content XML (Candlestick)
  1139. function WriteChartCandlestickContent(&$node, $open, $high, $low, $close, $xindex) {
  1140. $set = $this->XmlDoc->createElement('set');
  1141. $this->WriteAtt($set, "open", $this->ChartFormatNumber($open));
  1142. $this->WriteAtt($set, "high", $this->ChartFormatNumber($high));
  1143. $this->WriteAtt($set, "low", $this->ChartFormatNumber($low));
  1144. $this->WriteAtt($set, "close", $this->ChartFormatNumber($close));
  1145. if ($xindex <> "")
  1146. $this->WriteAtt($set, "xindex", $xindex);
  1147. $node->appendChild($set);
  1148. }
  1149. // Format name for chart
  1150. function ChartFormatName($name) {
  1151. global $ReportLanguage;
  1152. if (is_null($name)) {
  1153. return $ReportLanguage->Phrase("NullLabel");
  1154. } elseif ($name == "") {
  1155. return $ReportLanguage->Phrase("EmptyLabel");
  1156. } else {
  1157. return $name;
  1158. }
  1159. }
  1160. // Format number for chart
  1161. function ChartFormatNumber($v) {
  1162. $cht_decimalprecision = $this->LoadParm("decimalPrecision");
  1163. if (is_null($cht_decimalprecision)) {
  1164. return $v;
  1165. } else {
  1166. return number_format($v, $cht_decimalprecision, '.', '');
  1167. }
  1168. }
  1169. // Write attribute
  1170. function WriteAtt(&$node, $name, $val) {
  1171. $val = $this->CheckColorCode(strval($val));
  1172. $val = $this->ChartEncode($val);
  1173. if ($node->hasAttribute($name)) {
  1174. $node->getAttributeNode($name)->value = ewrpt_XmlEncode(ewrpt_ConvertToUtf8($val));
  1175. } else {
  1176. $att = $this->XmlDoc->createAttribute($name);
  1177. $att->value = ewrpt_XmlEncode(ewrpt_ConvertToUtf8($val));
  1178. $node->appendChild($att);
  1179. }
  1180. }
  1181. // Check color code
  1182. function CheckColorCode($val) {
  1183. if (substr($val, 0, 1) == "#" && strlen($val) == 7) {
  1184. return substr($val, 1);
  1185. } else {
  1186. return $val;
  1187. }
  1188. }
  1189. // Process chart parms
  1190. function ProcessChartParms(&$ChartType, &$Parms) {
  1191. if ($ChartType == 104) $ChartType = 3; // Bar 3D, Switch back to Bar 2D
  1192. // Remove numVisiblePlot (scroll charts)
  1193. if (array_key_exists("numVisiblePlot", $Parms))
  1194. unset($Parms["numVisiblePlot"]);
  1195. }
  1196. // Encode special characters for FusionChartsFree
  1197. // + => %2B
  1198. function ChartEncode($val) {
  1199. $v = str_replace("+", "%2B", $val);
  1200. return $v;
  1201. }
  1202. // Category content XML (multi series)
  1203. function WriteChartCatContent(&$node, $name) {
  1204. $cat = $this->XmlDoc->createElement('category');
  1205. $this->WriteAtt($cat, "name", $name);
  1206. $node->appendChild($cat);
  1207. }
  1208. // Chart content XML
  1209. function WriteChartContent(&$node, $name, $val, $color, $alpha, $lnk) {
  1210. $cht_shownames = $this->LoadParm("shownames");
  1211. $set = $this->XmlDoc->createElement('set');
  1212. $this->WriteAtt($set, "name", $name);
  1213. $this->WriteAtt($set, "value", $this->ChartFormatNumber($val));
  1214. $this->WriteAtt($set, "color", $this->ColorCode($color));
  1215. $this->WriteAtt($set, "alpha", $alpha);
  1216. $this->WriteAtt($set, "link", $lnk);
  1217. if ($cht_shownames == "1")
  1218. $this->WriteAtt($set, "showName", "1");
  1219. $node->appendChild($set);
  1220. }
  1221. }
  1222. //
  1223. // Column class
  1224. //
  1225. class crCrosstabColumn {
  1226. var $Caption;
  1227. var $Value;
  1228. var $Visible;
  1229. function crCrosstabColumn($value, $caption, $visible = TRUE) {
  1230. $this->Caption = $caption;
  1231. $this->Value = $value;
  1232. $this->Visible = $visible;
  1233. }
  1234. }
  1235. //
  1236. // Advanced filter class
  1237. //
  1238. class crAdvancedFilter {
  1239. var $ID;
  1240. var $Name;
  1241. var $FunctionName;
  1242. var $Enabled = TRUE;
  1243. function crAdvancedFilter($filterid, $filtername, $filterfunc) {
  1244. $this->ID = $filterid;
  1245. $this->Name = $filtername;
  1246. $this->FunctionName = $filterfunc;
  1247. }
  1248. }
  1249. /**
  1250. * List option collection class
  1251. */
  1252. class crListOptions {
  1253. var $Items = array();
  1254. var $CustomItem = "";
  1255. var $Tag = "td";
  1256. var $Separator = "";
  1257. // Add and return a new option (return-by-reference is for PHP 5 only)
  1258. function &Add($Name) {
  1259. $item = new crListOption($Name, $this->Tag, $this->Separator);
  1260. $item->Parent =& $this;
  1261. $this->Items[$Name] = $item;
  1262. return $item;
  1263. }
  1264. // Load default settings
  1265. function LoadDefault() {
  1266. $this->CustomItem = "";
  1267. foreach ($this->Items as $key => $item)
  1268. $this->Items[$key]->Body = "";
  1269. }
  1270. // Hide all options
  1271. function HideAllOptions() {
  1272. foreach ($this->Items as $key => $item)
  1273. $this->Items[$key]->Visible = FALSE;
  1274. }
  1275. // Show all options
  1276. function ShowAllOptions() {
  1277. foreach ($this->Items as $key => $item)
  1278. $this->Items[$key]->Visible = TRUE;
  1279. }
  1280. // Get item by name (return-by-reference is for PHP 5 only)
  1281. // predefined names: view/edit/copy/delete/detail_<DetailTable>/userpermission/checkbox
  1282. function &GetItem($Name) {
  1283. $item = array_key_exists($Name, $this->Items) ? $this->Items[$Name] : NULL;
  1284. return $item;
  1285. }
  1286. // Move item to position
  1287. function MoveItem($Name, $Pos) {
  1288. $cnt = count($this->Items);
  1289. if ($Pos < 0 || $Pos >= $cnt)
  1290. return;
  1291. $item = $this->GetItem($Name);
  1292. if ($item) {
  1293. unset($this->Items[$Name]);
  1294. $this->Items = array_merge(array_slice($this->Items, 0, $Pos),
  1295. array($Name => $item), array_slice($this->Items, $Pos));
  1296. }
  1297. }
  1298. // Render list options
  1299. function Render($Part, $Pos="") {
  1300. if ($this->CustomItem <> "") {
  1301. $cnt = 0;
  1302. foreach ($this->Items as &$item) {
  1303. if ($item->Visible && $this->ShowPos($item->OnLeft, $Pos))
  1304. $cnt++;
  1305. if ($item->Name == $this->CustomItem)
  1306. $opt = $item;
  1307. }
  1308. if (is_object($opt) && $cnt > 0) {
  1309. if ($this->ShowPos($opt->OnLeft, $Pos)) {
  1310. echo $opt->Render($Part, $cnt);
  1311. } else {
  1312. echo $opt->Render("", $cnt);
  1313. }
  1314. }
  1315. } else {
  1316. foreach ($this->Items as &$item) {
  1317. if ($item->Visible && $this->ShowPos($item->OnLeft, $Pos))
  1318. echo $item->Render($Part);
  1319. }
  1320. }
  1321. }
  1322. function ShowPos($OnLeft, $Pos) {
  1323. return ($OnLeft && $Pos == "left") || (!$OnLeft && $Pos == "right") || ($Pos == "");
  1324. }
  1325. }
  1326. /**
  1327. * List option class
  1328. */
  1329. class crListOption {
  1330. var $Name;
  1331. var $OnLeft;
  1332. var $CssStyle;
  1333. var $Visible = TRUE;
  1334. var $Header;
  1335. var $Body;
  1336. var $Footer;
  1337. var $Tag = "td";
  1338. var $Separator = "";
  1339. var $Parent;
  1340. function crListOption($Name, $Tag, $Separator) {
  1341. $this->Name = $Name;
  1342. $this->Tag = $Tag;
  1343. $this->Separator = $Separator;
  1344. }
  1345. function MoveTo($Pos) {
  1346. $this->Parent->MoveItem($this->Name, $Pos);
  1347. }
  1348. function Render($Part, $ColSpan = 1) {
  1349. if ($Part == "header") {
  1350. $value = $this->Header;
  1351. } elseif ($Part == "body") {
  1352. $value = $this->Body;
  1353. } elseif ($Part == "footer") {
  1354. $value = $this->Footer;
  1355. } else {
  1356. $value = $Part;
  1357. }
  1358. if (strval($value) == "" && strtolower($this->Tag) <> "td")
  1359. return "";
  1360. $res = ($value <> "") ? $value : "&nbsp;";
  1361. $tage = "</" . $this->Tag . ">";
  1362. $tags = "<" . $this->Tag;
  1363. if ($this->CssStyle <> "")
  1364. $tags .= " style=\"" . $this->CssStyle . "\"";
  1365. if (strtolower($this->Tag) == "td" && $ColSpan > 1)
  1366. $tags .= " colspan=\"" . $ColSpan . "\"";
  1367. $tags .= " class=\"phpmaker\"";
  1368. $tags .= ">";
  1369. $res = $tags . $res . $tage . $this->Separator;
  1370. return $res;
  1371. }
  1372. }
  1373. /

Large files files are truncated, but you can click here to view the full file