示例#1
0
 /**
  * Functon: xml2query
  *
  * Analyses XML report definition and builds Reportico report instance from it
  * 
  */
 function xml2query()
 {
     if (array_key_exists("CogModule", $this->data)) {
         $q =& $this->data["CogModule"];
     } else {
         $q =& $this->data["Report"];
     }
     $criteria_links = array();
     // Generate Output Information...
     $ds = false;
     if (!$q) {
         return;
     }
     foreach ($q as $cogquery) {
         // Set Query Attributes
         foreach ($cogquery["Format"] as $att => $val) {
             $this->query->set_attribute($att, $val);
         }
         // Set DataSource
         if (isset($cogquery["Datasource"])) {
             foreach ($cogquery["Datasource"] as $att => $val) {
                 //if ( $att == "SourceType" )
                 //$this->query->source_type = $val;
                 if ($att == "SourceConnection") {
                     // No longer relevant - connections are not supplied in xml files
                 }
             }
         }
         // Set Query Columns
         if (!($ef =& $this->get_array_element($cogquery, "EntryForm"))) {
             $this->ErrorMsg = "No EntryForm tag within Format";
             return false;
         }
         if (!($qu =& $this->get_array_element($ef, "Query"))) {
             $this->ErrorMsg = "No Query tag within EntryForm";
             return false;
         }
         $this->query->table_text = $this->get_array_element($qu, "TableSql");
         $this->query->where_text = $this->get_array_element($qu, "WhereSql");
         $this->query->group_text = $this->get_array_element($qu, "GroupSql");
         $this->query->rowselection = $this->get_array_element($qu, "RowSelection");
         $has_cols = true;
         if ($qc =& $this->get_array_element($qu, "SQL")) {
             $this->query->sql_raw = $this->get_array_element($qc, "SQLRaw");
         }
         if (!($qc =& $this->get_array_element($qu, "QueryColumns"))) {
             $this->ErrorMsg = "No QueryColumns tag within Query";
             $has_cols = false;
         }
         // Generate reportico_query_column for each column found
         if ($has_cols) {
             foreach ($qc as $col) {
                 $in_query = true;
                 if (!$col["ColumnName"]) {
                     $in_query = false;
                 }
                 $this->query->create_criteria_column($col["Name"], $col["TableName"], $col["ColumnName"], $col["ColumnType"], $col["ColumnLength"], "###.##", $in_query);
                 // Set any Attributes
                 if ($fm =& $this->get_array_element($col, "Format")) {
                     foreach ($fm as $att => $val) {
                         $this->query->set_column_attribute($col["Name"], $att, $val);
                     }
                 }
             }
             // Generate Order By List
             if ($oc =& $this->get_array_element($qu, "OrderColumns")) {
                 // Generate reportico_query_column for each column found
                 foreach ($oc as $col) {
                     if (!$col["Name"]) {
                         return;
                     }
                     $this->query->create_order_column($col["Name"], $col["OrderType"]);
                 }
             }
             // Generate Query Assignments
             if ($as =& $this->get_array_element($ef, "Assignments")) {
                 foreach ($as as $col) {
                     if (array_key_exists("AssignName", $col)) {
                         $this->query->add_assignment($col["AssignName"], $col["Expression"], $col["Condition"]);
                     } else {
                         $this->query->add_assignment($col["Name"], $col["Expression"], $col["Condition"]);
                     }
                 }
             }
         }
         // Generate Query Assignments
         if ($pq =& $this->get_array_element($qu, "PreSQLS")) {
             foreach ($pq as $col) {
                 $this->query->add_pre_sql($col["SQLText"]);
             }
         }
         // Generate Output Information...
         if ($op =& $this->get_array_element($ef, "Output")) {
             // Generate Page Headers
             if ($ph = $this->get_array_element($op, "PageHeaders")) {
                 foreach ($ph as $k => $phi) {
                     $this->query->create_page_header($k, $phi["LineNumber"], $phi["HeaderText"]);
                     if ($fm =& $this->get_array_element($phi, "Format")) {
                         foreach ($fm as $att => $val) {
                             $this->query->set_page_header_attribute($k, $att, $val);
                         }
                     }
                 }
             }
             // Generate Page Footers
             if ($ph = $this->get_array_element($op, "PageFooters")) {
                 foreach ($ph as $k => $phi) {
                     $this->query->create_page_footer($k, $phi["LineNumber"], $phi["FooterText"]);
                     if ($fm =& $this->get_array_element($phi, "Format")) {
                         foreach ($fm as $att => $val) {
                             $this->query->set_page_footer_attribute($k, $att, $val);
                         }
                     }
                 }
             }
             // Generate Display Orders
             if ($has_cols && ($ph = $this->get_array_element($op, "DisplayOrders"))) {
                 foreach ($ph as $k => $phi) {
                     $this->query->set_column_order($phi["ColumnName"], $phi["OrderNumber"]);
                 }
             }
             if ($has_cols && ($ph = $this->get_array_element($op, "Groups"))) {
                 foreach ($ph as $k => $phi) {
                     if (array_key_exists("GroupName", $phi)) {
                         $gpname = $phi["GroupName"];
                     } else {
                         $gpname = $phi["Name"];
                     }
                     $grn = $this->query->create_group($gpname);
                     if (array_key_exists("BeforeGroupHeader", $phi)) {
                         $grn->set_attribute("before_header", $phi["BeforeGroupHeader"]);
                         $grn->set_attribute("after_header", $phi["AfterGroupHeader"]);
                         $grn->set_attribute("before_trailer", $phi["BeforeGroupTrailer"]);
                         $grn->set_attribute("after_trailer", $phi["AfterGroupTrailer"]);
                         $grn->set_format("before_header", $phi["BeforeGroupHeader"]);
                         $grn->set_format("after_header", $phi["AfterGroupHeader"]);
                         $grn->set_format("before_trailer", $phi["BeforeGroupTrailer"]);
                         $grn->set_format("after_trailer", $phi["AfterGroupTrailer"]);
                     }
                     if ($gp =& $this->get_array_element($phi, "GroupHeaders")) {
                         foreach ($gp as $att => $val) {
                             if (!isset($val["GroupHeaderCustom"])) {
                                 $val["GroupHeaderCustom"] = false;
                             }
                             $this->query->create_group_header($gpname, $val["GroupHeaderColumn"], $val["GroupHeaderCustom"]);
                         }
                     }
                     if ($gp =& $this->get_array_element($phi, "GroupTrailers")) {
                         foreach ($gp as $att => $val) {
                             if (!isset($val["GroupTrailerCustom"])) {
                                 $val["GroupTrailerCustom"] = false;
                             }
                             $this->query->create_group_trailer($gpname, $val["GroupTrailerDisplayColumn"], $val["GroupTrailerValueColumn"], $val["GroupTrailerCustom"]);
                         }
                     }
                 }
             }
             // Generate Graphs
             if ($has_cols && ($gph = $this->get_array_element($op, "Graphs"))) {
                 foreach ($gph as $k => $gphi) {
                     $ka = array_keys($gphi);
                     $gph =& $this->query->create_graph();
                     $gph->set_graph_column($gphi["GraphColumn"]);
                     $gph->set_title($gphi["Title"]);
                     $gph->set_xtitle($gphi["XTitle"]);
                     $gph->set_xlabel_column($gphi["XLabelColumn"]);
                     $gph->set_ytitle($gphi["YTitle"]);
                     //$gph->set_ylabel_column($gphi["YLabelColumn"]);
                     //////HERE!!!
                     if (array_key_exists("GraphWidth", $gphi)) {
                         $gph->set_width($gphi["GraphWidth"]);
                         $gph->set_height($gphi["GraphHeight"]);
                         $gph->set_width_pdf($gphi["GraphWidthPDF"]);
                         $gph->set_height_pdf($gphi["GraphHeightPDF"]);
                     } else {
                         $gph->set_width($gphi["Width"]);
                         $gph->set_height($gphi["Height"]);
                     }
                     if (array_key_exists("GraphColor", $gphi)) {
                         $gph->set_graph_color($gphi["GraphColor"]);
                         $gph->set_grid($gphi["GridPosition"], $gphi["XGridDisplay"], $gphi["XGridColor"], $gphi["YGridDisplay"], $gphi["YGridColor"]);
                         $gph->set_title_font($gphi["TitleFont"], $gphi["TitleFontStyle"], $gphi["TitleFontSize"], $gphi["TitleColor"]);
                         $gph->set_xtitle_font($gphi["XTitleFont"], $gphi["XTitleFontStyle"], $gphi["XTitleFontSize"], $gphi["XTitleColor"]);
                         $gph->set_ytitle_font($gphi["YTitleFont"], $gphi["YTitleFontStyle"], $gphi["YTitleFontSize"], $gphi["YTitleColor"]);
                         $gph->set_xaxis($gphi["XTickInterval"], $gphi["XTickLabelInterval"], $gphi["XAxisColor"]);
                         $gph->set_yaxis($gphi["YTickInterval"], $gphi["YTickLabelInterval"], $gphi["YAxisColor"]);
                         $gph->set_xaxis_font($gphi["XAxisFont"], $gphi["XAxisFontStyle"], $gphi["XAxisFontSize"], $gphi["XAxisFontColor"]);
                         $gph->set_yaxis_font($gphi["YAxisFont"], $gphi["YAxisFontStyle"], $gphi["YAxisFontSize"], $gphi["YAxisFontColor"]);
                         $gph->set_margin_color($gphi["MarginColor"]);
                         $gph->set_margins($gphi["MarginLeft"], $gphi["MarginRight"], $gphi["MarginTop"], $gphi["MarginBottom"]);
                     }
                     foreach ($gphi["Plots"] as $pltk => $pltv) {
                         $pl =& $gph->create_plot($pltv["PlotColumn"]);
                         $pl["type"] = $pltv["PlotType"];
                         $pl["fillcolor"] = $pltv["FillColor"];
                         $pl["linecolor"] = $pltv["LineColor"];
                         $pl["legend"] = $pltv["Legend"];
                     }
                 }
             }
         }
         // Output
         // Check for Criteria Items ...
         if ($crt =& $this->get_array_element($ef, "Criteria")) {
             foreach ($crt as $ci) {
                 $critnm = $this->get_array_element($ci, "Name");
                 $crittb = $this->get_array_element($ci, "QueryTableName");
                 $critcl = $this->get_array_element($ci, "QueryColumnName");
                 $linked_report = $this->get_array_element($ci, "LinkToReport");
                 $linked_report_item = $this->get_array_element($ci, "LinkToReportItem");
                 // If we are not designing a report then
                 // replace a linked criteria with the criteria
                 // item it links to from another report
                 if ($linked_report && $this->query->execute_mode != "MAINTAIN") {
                     $q = new reportico();
                     global $g_project;
                     $q->reports_path = $q->projects_folder . "/" . $g_project;
                     $reader = new reportico_xml_reader($q, $linked_report, false);
                     $reader->xml2query();
                     foreach ($q->lookup_queries as $k => $v) {
                         $found = false;
                         foreach ($this->query->columns as $querycol) {
                             if ($querycol->query_name == $v->query_name) {
                                 $found = true;
                             }
                         }
                         $qu = new reportico();
                         if ($linked_report_item == $v->query_name) {
                             $this->query->lookup_queries[$v->query_name] = $v;
                         }
                     }
                     continue;
                 }
                 if ($crittb) {
                     $critcl = $crittb . "." . $critcl;
                     $crittb = "";
                 }
                 $crittp = $this->get_array_element($ci, "CriteriaType");
                 $critlt = $this->get_array_element($ci, "CriteriaList");
                 $crituse = $this->get_array_element($ci, "Use");
                 //$crithelp = $this->get_array_element($ci, "CriteriaHelp") ;
                 $critds = $this->get_array_element($ci, "CriteriaDisplay");
                 $critexp = $this->get_array_element($ci, "ExpandDisplay");
                 $critmatch = $this->get_array_element($ci, "MatchColumn");
                 $critdefault = $this->get_array_element($ci, "CriteriaDefaults");
                 $crittitle = $this->get_array_element($ci, "Title");
                 $crit_lookup_return = $this->get_array_element($ci, "ReturnColumn");
                 $crit_lookup_display = $this->get_array_element($ci, "DisplayColumn");
                 $crit_criteria_display = $this->get_array_element($ci, "OverviewColumn");
                 if ($crittp == "ANYCHAR") {
                     $crittp = "TEXTFIELD";
                 }
                 if ($critds == "ANYCHAR") {
                     $critds = "TEXTFIELD";
                 }
                 if ($critexp == "ANYCHAR") {
                     $critexp = "TEXTFIELD";
                 }
                 // Generate criteria lookup info unless its a link to a criteria in a nother report
                 if (!$linked_report && !($ciq =& $this->get_array_element($ci, "Query"))) {
                     continue;
                 }
                 $critquery = new reportico();
                 // Generate Criteria Query Columns
                 if (!$linked_report && ($ciqc =& $this->get_array_element($ciq, "QueryColumns"))) {
                     foreach ($ciqc as $ccol) {
                         $in_query = true;
                         if (!$ccol["ColumnName"]) {
                             $in_query = false;
                         }
                         $critquery->create_criteria_column($ccol["Name"], $ccol["TableName"], $ccol["ColumnName"], $ccol["ColumnType"], $ccol["ColumnLength"], "###.##", $in_query);
                     }
                 }
                 // Generate Order By List
                 if (!$linked_report && ($coc =& $this->get_array_element($ciq, "OrderColumns"))) {
                     // Generate reportico_query_column for each column found
                     foreach ($coc as $col) {
                         $critquery->create_order_column($col["Name"], $col["OrderType"]);
                     }
                 }
                 if (!$linked_report && ($as =& $this->get_array_element($ciq, "Assignments"))) {
                     foreach ($as as $ast) {
                         if (array_key_exists("AssignName", $ast)) {
                             $critquery->add_assignment($ast["AssignName"], $ast["Expression"], $ast["Condition"]);
                         } else {
                             $critquery->add_assignment($ast["Name"], $ast["Expression"], $ast["Condition"]);
                         }
                     }
                 }
                 // Generate Criteria Links  In Array for later use
                 if (!$linked_report && ($cl =& $this->get_array_element($ci, "CriteriaLinks"))) {
                     foreach ($cl as $clitem) {
                         $criteria_links[] = array("LinkFrom" => $clitem["LinkFrom"], "LinkTo" => $clitem["LinkTo"], "LinkClause" => $clitem["LinkClause"]);
                     }
                 }
                 // Set Query SQL Text
                 if (!$linked_report) {
                     $critquery->table_text = $this->get_array_element($ciq, "TableSql");
                     $critquery->where_text = $this->get_array_element($ciq, "WhereSql");
                     $critquery->group_text = $this->get_array_element($ciq, "GroupSql");
                     $critquery->sql_raw = $this->get_array_element($ciq, "SQLRaw");
                     $critquery->rowselection = $this->get_array_element($ciq, "RowSelection");
                 }
                 $critquery->set_lookup_return($crit_lookup_return);
                 $critquery->set_lookup_display($crit_lookup_display, $crit_criteria_display);
                 $critquery->set_lookup_expand_match($critmatch);
                 $this->query->set_criteria_lookup($critnm, $critquery, $crittb, $critcl);
                 $this->query->set_criteria_input($critnm, $crittp, $critds, $critexp, $crituse);
                 $this->query->set_criteria_link_report($critnm, $linked_report, $linked_report_item);
                 $this->query->set_criteria_list($critnm, $critlt);
                 //$this->query->set_criteria_help($critnm, $crithelp);
                 $this->query->set_criteria_attribute($critnm, "column_title", $crittitle);
                 $this->query->set_criteria_defaults($critnm, $critdefault);
             }
             // End Criteria Item
             // Set up any Criteria Links
             foreach ($criteria_links as $cl) {
                 $this->query->set_criteria_link($cl["LinkFrom"], $cl["LinkTo"], $cl["LinkClause"]);
             }
         }
     }
 }