function importSQL($sql)
 {
     set_project_environment($this->initial_project);
     $p = new reportico_sql_parser($sql);
     if ($p->parse(false)) {
         $p->import_into_query($this);
     }
     //$this->sqlinput = $sql;
     //if ( !get_reportico_session_param("sqlin") )
     //set_reportico_session_param("sqlin",$this->initial_sql);
 }
Example #2
0
	function importSQL($sql)
	{
		$this->set_project_environment($this->initial_project, $this->projects_folder, $this->admin_projects_folder);
        $p = new reportico_sql_parser($sql);
        if ( $p->parse(false) )
        {
                $p->import_into_query($this);
        }
    }
Example #3
0
 function handle_user_entry()
 {
     // First look for a parameter beginning "submit_". This will identify
     // What the user wanted to do.
     $hide_area = false;
     $show_area = false;
     $maintain_sql = false;
     $xmlsavefile = false;
     $xmldeletefile = false;
     if ($k = $this->get_matching_post_item("/^submit_/")) {
         // Strip off "_submit"
         preg_match("/^submit_(.*)/", $k, $match);
         // Now we should be left with a field element and an action
         // Lets strip the two
         $match1 = preg_split('/_/', $match[0]);
         $fld = $match1[1];
         $action = $match1[2];
         switch ($action) {
             case "ADD":
                 // We have chosen to set a block of data so pass through Request set and see which
                 // fields belong to this set and take appropriate action
                 $this->add_maintain_fields($fld);
                 $show_area = $fld;
                 break;
             case "DELETE":
                 // We have chosen to set a block of data so pass through Request set and see which
                 // fields belong to this set and take appropriate action
                 $this->delete_maintain_fields($fld);
                 $show_area = $fld;
                 break;
             case "MOVEUP":
                 // We have chosen to set a block of data so pass through Request set and see which
                 // fields belong to this set and take appropriate action
                 $this->moveup_maintain_fields($fld);
                 $show_area = $fld;
                 break;
             case "MOVEDOWN":
                 // We have chosen to set a block of data so pass through Request set and see which
                 // fields belong to this set and take appropriate action
                 $this->movedown_maintain_fields($fld);
                 $show_area = $fld;
                 break;
             case "SET":
                 // We have chosen to set a block of data so pass through Request set and see which
                 // fields belong to this set and take appropriate action
                 $this->update_maintain_fields($fld);
                 $show_area = $fld;
                 break;
             case "REPORTLINK":
             case "REPORTLINKITEM":
                 // Link in an item from another report
                 $this->link_in_report_fields("link", $fld, $action);
                 $show_area = $fld;
                 break;
             case "REPORTIMPORT":
             case "REPORTIMPORTITEM":
                 // Link in an item from another report
                 $this->link_in_report_fields("import", $fld, $action);
                 $show_area = $fld;
                 break;
             case "SAVE":
                 $xmlsavefile = $this->query->xmloutfile;
                 if (!$xmlsavefile) {
                     trigger_error(template_xlate("UNABLE_TO_SAVE") . template_xlate("SPECIFYXML"), E_USER_ERROR);
                 }
                 break;
             case "DELETEREPORT":
                 $xmldeletefile = $this->query->xmloutfile;
                 break;
             case "HIDE":
                 $hide_area = $fld;
                 break;
             case "SHOW":
                 $show_area = $fld;
                 break;
             case "SQL":
                 $show_area = $fld;
                 if ($fld == "mainquerqury") {
                     // Main Query SQL Generation.
                     $sql = stripslashes($_REQUEST["mainquerqury_SQL"]);
                     $maintain_sql = $sql;
                     if ($this->query->login_check()) {
                         $p = new reportico_sql_parser($sql);
                         if ($p->parse()) {
                             $p->import_into_query($qr);
                             if ($this->query->datasource->connect()) {
                                 $p->test_query($this->query, $sql);
                             }
                         }
                     }
                 } else {
                     // It's a lookup
                     if (preg_match("/mainquercrit(.*)qury/", $fld, $match1)) {
                         $lookup = (int) $match1[1];
                         $lookup_char = $match1[1];
                         // Access the relevant crtieria item ..
                         $qc = false;
                         $ak = array_keys($this->query->lookup_queries);
                         if (array_key_exists($lookup, $ak)) {
                             $q = $this->query->lookup_queries[$ak[$lookup]]->lookup_query;
                         } else {
                             $q = new reportico();
                         }
                         // Parse the entered SQL
                         $sqlparm = $fld . "_SQL";
                         $sql = $_REQUEST[$sqlparm];
                         $q->maintain_sql = $sql;
                         $q = new reportico();
                         $p = new reportico_sql_parser($sql);
                         if ($p->parse()) {
                             if ($p->test_query($this->query, $sql)) {
                                 $p->import_into_query($q);
                                 $this->query->set_criteria_lookup($ak[$lookup], $q, "WHAT", "NOW");
                             }
                         }
                     }
                 }
                 break;
         }
     }
     // Now work out what the maintainance screen should be showing by analysing
     // whether user pressed a SHOW button a HIDE button or keeps a maintenance item
     // show by presence of a shown value
     if (!$show_area) {
         // User has not pressed SHOW_ button - this would have been picked up in previous submit
         // So look for longest shown item - this will allow us to draw the maintenace screen with
         // the correct item maximised
         foreach ($_REQUEST as $k => $req) {
             if (preg_match("/^shown_(.*)/", $k, $match)) {
                 $containee = "/^" . $hide_area . "/";
                 $container = $match[1];
                 if (!preg_match($containee, $container)) {
                     if (strlen($match[1]) > strlen($show_area)) {
                         $show_area = $match[1];
                     }
                 }
             }
         }
     }
     if (!$show_area) {
         $show_area = "mainquer";
     }
     $xmlout = new reportico_xml_writer($this->query);
     $xmlout->prepare_xml_data();
     // If Save option has been used then write data to the named file and
     // use this file as the defalt input for future queries
     if ($xmlsavefile) {
         if ($this->query->allow_maintain != "SAFE" && $this->query->allow_maintain != "DEMO" && SW_ALLOW_MAINTAIN) {
             $xmlout->write_file($xmlsavefile);
             set_reportico_session_param("xmlin", $xmlsavefile);
             unset_reportico_session_param("xmlintext");
         } else {
             trigger_error(template_xlate("SAFENOSAVE"), E_USER_ERROR);
         }
     }
     // If Delete Report option has been used then remove the file
     // use this file as the defalt input for future queries
     if ($xmldeletefile) {
         if ($this->query->allow_maintain != "SAFE" && $this->query->allow_maintain != "DEMO" && SW_ALLOW_MAINTAIN) {
             $xmlout->remove_file($xmldeletefile);
             set_reportico_session_param("xmlin", false);
             unset_reportico_session_param("xmlintext");
         } else {
             trigger_error(template_xlate("SAFENODEL"), E_USER_ERROR);
         }
     }
     $xml = $xmlout->get_xmldata();
     if ($this->query->top_level_query) {
         $this->query->xmlintext = $xml;
     }
     $this->query->xmlin = new reportico_xml_reader($this->query, false, $xml);
     $this->query->xmlin->show_area = $show_area;
     $this->query->maintain_sql = false;
 }