function execute($mode = false, $draw = true)
 {
     global $g_system_errors;
     global $g_system_debug;
     global $g_code_area;
     global $g_code_source;
     global $g_debug_mode;
     global $g_language;
     global $g_project;
     global $g_session_namespace;
     global $g_session_namespace_key;
     if ($this->session_namespace) {
         $g_session_namespace = $this->session_namespace;
     }
     if ($g_session_namespace) {
         $g_session_namespace_key = "reportico_" . $g_session_namespace;
     }
     // If a session namespace doesnt exist create one
     if (!isset($_SESSION[$g_session_namespace_key]) || isset($_REQUEST['clear_session']) || $this->clear_reportico_session) {
         initialize_reportico_namespace($g_session_namespace_key);
     }
     // Work out the mode (ADMIN, PREPARE, MENU, EXECUTE, MAINTAIN based on all parameters )
     if (!$mode) {
         $mode = $this->get_execute_mode();
     }
     $old_error_handler = set_error_handler("ErrorHandler");
     set_exception_handler("ExceptionHandler");
     // If new session, we need to use initial project, report etc, otherwise ignore them
     $this->handle_initial_settings();
     // Fetch project config
     set_project_environment($this->initial_project);
     register_session_param("external_user", $this->external_user);
     register_session_param("external_param1", $this->external_param1);
     register_session_param("external_param2", $this->external_param2);
     register_session_param("external_param3", $this->external_param3);
     $this->user_parameters = register_session_param("user_parameters", $this->user_parameters);
     $this->dropdown_menu = register_session_param("dropdown_menu", $this->dropdown_menu);
     $this->static_menu = register_session_param("static_menu", $this->static_menu);
     $this->charting_engine = register_session_param("charting_engine", $this->charting_engine);
     $this->charting_engine_html = register_session_param("charting_engine_html", $this->charting_engine_html);
     $this->output_template_parameters = register_session_param("output_template_parameters", $this->output_template_parameters);
     $this->dynamic_grids = register_session_param("dynamic_grids", $this->dynamic_grids);
     $this->dynamic_grids_sortable = register_session_param("dynamic_grids_sortable", $this->dynamic_grids_sortable);
     $this->dynamic_grids_searchable = register_session_param("dynamic_grids_searchable", $this->dynamic_grids_searchable);
     $this->dynamic_grids_paging = register_session_param("dynamic_grids_paging", $this->dynamic_grids_paging);
     $this->dynamic_grids_page_size = register_session_param("dynamic_grids_page_size", $this->dynamic_grids_page_size);
     // We are in AJAX mode if it is passed throuh
     if (isset($_REQUEST["reportico_ajax_called"])) {
         $this->reportico_ajax_called = $_REQUEST["reportico_ajax_called"];
     }
     //set_reportico_session_param("reportico_ajax_called", $_REQUEST["reportico_ajax_called"] );
     // Store whether in framework
     set_reportico_session_param("framework_parent", $this->framework_parent);
     // Set access mode to decide whether to allow user to access Design Mode, Menus, Criteria or just run a single report
     $this->access_mode = session_item("access_mode", $this->access_mode);
     if ($this->access_mode == "DEMO") {
         $this->allow_maintain = "DEMO";
     }
     $this->reports_path = "projects/" . $g_project;
     // Convert input and out charsets into their PHP versions
     // for later iconv use
     $this->db_charset = db_charset_to_php_charset('UTF-8');
     $this->output_charset = output_charset_to_php_charset('UTF-8');
     // Ensure Smarty Template folder exists and is writeable
     $include_template_dir = "templates_c";
     if (!is_dir("templates_c")) {
         find_file_to_include("templates_c", $include_template_dir, $include_template_dir);
     }
     if (!is_dir($include_template_dir)) {
         echo "Unable to generate output. The <b>{$include_template_dir}</b> folder does not exist within the main reportico area. Please create this folder and ensure it has read, write and execute permissions and then retry.";
         die;
     }
     if (!sw_path_executable($include_template_dir)) {
         echo "Unable to generate output. The <b>{$include_template_dir}</b> folder does not have read, write and execute permissions. Please correct and retry.";
         die;
     }
     $g_debug_mode = get_request_item("debug_mode", "0", $this->first_criteria_selection);
     if (!$mode) {
         $mode = $this->get_execute_mode();
     }
     // If the project is the ADMIN project then the MAin Menu will be the Admin Page
     if ($g_project == "admin" && $mode == "MENU") {
         $mode = "ADMIN";
     }
     // If this is PREPARE mode then we want to identify whether user has entered prepare
     // screen for first time so we know whether to set defaults or not
     switch ($mode) {
         case "PREPARE":
             $this->report_progress("Ready", "READY");
             $this->first_criteria_selection = true;
             // Must find ALternative to THIs for first time in testing!!!
             if (array_key_exists("target_format", $_REQUEST)) {
                 $this->first_criteria_selection = false;
                 set_reportico_session_param("firstTimeIn", false);
             }
             if (!isset_reportico_session_param("firstTimeIn")) {
                 set_reportico_session_param("firstTimeIn", true);
             }
             // Default output to HTML in PREPARE mode first time in
             if (get_reportico_session_param("firstTimeIn") && !isset($_REQUEST["target_format"])) {
                 $this->target_format = "HTML";
                 set_reportico_session_param("target_format", "HTML");
             }
             // Default style to TABLE in PREPARE mode first time in
             //if ( get_reportico_session_param("firstTimeIn") && !isset($_REQUEST["target_style"]))
             //{
             //$this->target_format = "TABLE";
             //set_reportico_session_param("target_style","TABLE");
             //echo "set table ";
             //}
             break;
         case "EXECUTE":
             // If external page has supplied an initial output format then use it
             if ($this->initial_output_format) {
                 $_REQUEST["target_format"] = $this->initial_output_format;
             }
             // If printable HTML requested force output type to HTML
             if (get_request_item("printable_html")) {
                 $_REQUEST["target_format"] = "HTML";
             }
             // Prompt user for report destination if target not already set - default to HTML if not set
             if (!array_key_exists("target_format", $_REQUEST) && $mode == "EXECUTE") {
                 $_REQUEST["target_format"] = "HTML";
             }
             $this->target_format = strtoupper($_REQUEST["target_format"]);
             if (array_key_exists("submit", $_REQUEST)) {
                 $this->first_criteria_selection = false;
             } else {
                 $this->first_criteria_selection = true;
             }
             if (get_reportico_session_param("awaiting_initial_defaults")) {
                 set_reportico_session_param("firstTimeIn", true);
             } else {
                 if (get_reportico_session_param("firstTimeIn") && get_request_item("refreshReport", false)) {
                     set_reportico_session_param("firstTimeIn", true);
                 } else {
                     set_reportico_session_param("firstTimeIn", false);
                 }
             }
             break;
         case "MAINTAIN":
             $this->report_progress("Ready", "READY");
             $this->first_criteria_selection = true;
             set_reportico_session_param("firstTimeIn", true);
             break;
         default:
             //$this->report_progress("Ready", "READY" );
             $this->first_criteria_selection = true;
             set_reportico_session_param("firstTimeIn", true);
             break;
     }
     // If xml file is used to genearate the reportico_query, either by the xmlin session variable
     // or the xmlin request variable then process this before executing
     if ($mode == "EXECUTE") {
         $_REQUEST['execute_mode'] = "{$mode}";
         // If executing report then stored the REQUEST parameters unless this
         // is a refresh of the report in which case we want to keep the ones already there
         $runfromcriteriascreen = get_request_item("user_criteria_entered", false);
         $refreshmode = get_request_item("refreshReport", false);
         if (!get_request_item("printable_html") && ($runfromcriteriascreen || (!isset_reportico_session_param('latestRequest') || !get_reportico_session_param('latestRequest')))) {
             set_reportico_session_param('latestRequest', $_REQUEST);
         } else {
             if (!$runfromcriteriascreen && $refreshmode) {
                 $_REQUEST = get_reportico_session_param('latestRequest');
             }
         }
     } else {
         if ($mode != "MODIFY" && array_key_exists('latestRequest', $_SESSION[reportico_namespace()])) {
             if (get_reportico_session_param('latestRequest')) {
                 $OLD_REQUEST = $_REQUEST;
                 // If a new report is being run dont bother trying to restore previous
                 // run crtieria
                 if (!get_request_item("xmlin")) {
                     $_REQUEST = get_reportico_session_param('latestRequest');
                 }
                 foreach ($OLD_REQUEST as $k => $v) {
                     if ($k == 'partial_template') {
                         $_REQUEST[$k] = $v;
                     }
                     if (preg_match("/^EXPAND_/", $k)) {
                         $_REQUEST[$k] = $v;
                     }
                 }
                 $_REQUEST['execute_mode'] = "{$mode}";
             }
         }
         set_reportico_session_param('latestRequest', "");
     }
     // Derive URL call of the calling script so it can be recalled in form actions when not running in AJAX mode
     if (!$this->url_path_to_calling_script) {
         $this->url_path_to_calling_script = $_SERVER["SCRIPT_NAME"];
     }
     // Work out we are in AJAX mode
     $this->derive_ajax_operation();
     switch ($mode) {
         case "MODIFY":
             require_once "swmodify.php";
             $this->initialize_panels($mode);
             $engine = new reportico_db_engine($this->datasource->ado_connection->_connectionID);
             $status = $engine->perform_project_modifications($g_project);
             if ($status["errstat"] != 0) {
                 header("HTTP/1.0 404 Not Found", true);
             }
             echo json_encode($status);
             die;
         case "ADMIN":
             $txt = "";
             $this->handle_xml_query_input($mode);
             $this->build_admin_screen();
             $text = $this->panels["BODY"]->draw_smarty();
             $this->panels["MAIN"]->smarty->debugging = false;
             $this->panels["MAIN"]->smarty->assign('LANGUAGES', available_languages());
             $this->panels["MAIN"]->smarty->assign('CONTENT', $txt);
             restore_error_handler();
             if ($this->user_template) {
                 $this->panels["MAIN"]->smarty->display($this->user_template . '_admin.tpl');
             } else {
                 $this->panels["MAIN"]->smarty->display('admin.tpl');
             }
             $old_error_handler = set_error_handler("ErrorHandler");
             break;
         case "MENU":
             $this->handle_xml_query_input($mode);
             $this->build_menu();
             load_mode_language_pack("languages", $this->output_charset);
             load_mode_language_pack("menu", $this->output_charset);
             localise_template_strings($this->panels["MAIN"]->smarty);
             $text = $this->panels["BODY"]->draw_smarty();
             $this->panels["MAIN"]->smarty->debugging = false;
             $this->panels["MAIN"]->smarty->assign('CONTENT', $text);
             $this->panels["MAIN"]->smarty->assign('LANGUAGES', available_languages());
             restore_error_handler();
             if ($this->user_template) {
                 $this->panels["MAIN"]->smarty->display($this->user_template . '_menu.tpl');
             } else {
                 $this->panels["MAIN"]->smarty->display('menu.tpl');
             }
             $old_error_handler = set_error_handler("ErrorHandler");
             break;
         case "PREPARE":
             load_mode_language_pack("languages", $this->output_charset);
             $this->initialize_panels($mode);
             $this->handle_xml_query_input($mode);
             $this->set_request_columns();
             global $g_translations;
             global $g_report_desc;
             if ($this->xmlinput == "deleteproject.xml" || $this->xmlinput == "configureproject.xml" || $this->xmlinput == "createtutorials.xml" || $this->xmlinput == "createproject.xml") {
                 // If configuring project then use project language strings from admin project
                 // found in projects/admin/lang.php
                 load_project_language_pack("admin", $this->output_charset);
             }
             load_mode_language_pack("prepare", $this->output_charset);
             localise_template_strings($this->panels["MAIN"]->smarty);
             $text = $this->panels["BODY"]->draw_smarty();
             $this->panels["MAIN"]->smarty->debugging = false;
             $this->panels["MAIN"]->smarty->assign('CONTENT', $text);
             $reportname = preg_replace("/.xml/", "", $this->xmloutfile . '_prepare.tpl');
             restore_error_handler();
             if (preg_match("/{$reportname}/", find_best_location_in_include_path("templates/" . $reportname))) {
                 $this->panels["MAIN"]->smarty->display($reportname);
             } else {
                 if ($this->user_template) {
                     $this->panels["MAIN"]->smarty->display($this->user_template . '_prepare.tpl');
                 } else {
                     $this->panels["MAIN"]->smarty->display('prepare.tpl');
                 }
             }
             $old_error_handler = set_error_handler("ErrorHandler");
             break;
         case "EXECUTE":
             load_mode_language_pack("languages", $this->output_charset);
             $this->initialize_panels($mode);
             $this->handle_xml_query_input($mode);
             // Set Grid display options based on report and session defaults
             if ($this->attributes["gridDisplay"] != ".DEFAULT") {
                 $this->dynamic_grids = $this->attributes["gridDisplay"] == "show";
             }
             if ($this->attributes["gridSortable"] != ".DEFAULT") {
                 $this->dynamic_grids_sortable = $this->attributes["gridSortable"] == "yes";
             }
             if ($this->attributes["gridSearchable"] != ".DEFAULT") {
                 $this->dynamic_grids_searchable = $this->attributes["gridSearchable"] == "yes";
             }
             if ($this->attributes["gridPageable"] != ".DEFAULT") {
                 $this->dynamic_grids_paging = $this->attributes["gridPageable"] == "yes";
             }
             if ($this->attributes["gridPageSize"] != ".DEFAULT" && $this->attributes["gridPageSize"]) {
                 $this->dynamic_grids_page_size = $this->attributes["gridPageSize"];
             }
             $this->panels["MAIN"]->smarty->assign('REPORTICO_DYNAMIC_GRIDS', $this->dynamic_grids);
             $this->panels["MAIN"]->smarty->assign('REPORTICO_DYNAMIC_GRIDS_SORTABLE', $this->dynamic_grids_sortable);
             $this->panels["MAIN"]->smarty->assign('REPORTICO_DYNAMIC_GRIDS_SEARCHABLE', $this->dynamic_grids_searchable);
             $this->panels["MAIN"]->smarty->assign('REPORTICO_DYNAMIC_GRIDS_PAGING', $this->dynamic_grids_paging);
             $this->panels["MAIN"]->smarty->assign('REPORTICO_DYNAMIC_GRIDS_PAGE_SIZE', $this->dynamic_grids_page_size);
             $g_code_area = "Main Query";
             $this->build_query(false, "");
             $g_code_area = false;
             load_mode_language_pack("execute", $this->output_charset);
             localise_template_strings($this->panels["MAIN"]->smarty);
             if ($this->xmlinput == "deleteproject.xml" || $this->xmlinput == "configureproject.xml" || $this->xmlinput == "createtutorials.xml" || $this->xmlinput == "createproject.xml") {
                 // If configuring project then use project language strings from admin project
                 // found in projects/admin/lang.php
                 load_project_language_pack("admin", $this->output_charset);
             }
             if (!get_reportico_session_param("loggedin", false)) {
                 $text = "you are not logged in ";
             } else {
                 $text = $this->execute_query(false);
             }
             if ($this->target_format == "SOAP") {
                 close_reportico_session();
                 return;
             }
             // Situtations where we dont want to swithc results page - no data found, debug mode, not logged in
             if (count($g_system_errors) > 0 || $g_debug_mode || count($g_system_debug) > 0 || !get_reportico_session_param("loggedin")) {
                 // If errors and this is an ajax request return json ajax response for first message
                 $runfromcriteriascreen = get_request_item("user_criteria_entered", false);
                 global $g_no_data;
                 if ($g_no_data && get_request_item("new_reportico_window", false) && !$g_debug_mode && $this->target_format == "HTML" && $runfromcriteriascreen && $this->reportico_ajax_mode && count($g_system_errors) == 1) {
                     header("HTTP/1.0 404 Not Found", true);
                     $response_array = array();
                     $response_array["errno"] = $g_system_errors[0]["errno"];
                     $response_array["errmsg"] = $g_system_errors[0]["errstr"];
                     echo json_encode($response_array);
                     die;
                 }
                 $this->initialize_panels("PREPARE");
                 $this->set_request_columns();
                 $text = $this->panels["BODY"]->draw_smarty();
                 $this->panels["MAIN"]->smarty->debugging = false;
                 $title = sw_translate($this->derive_attribute("ReportTitle", "Unknown"));
                 $this->panels["MAIN"]->smarty->assign('TITLE', $title);
                 $this->panels["MAIN"]->smarty->assign('CONTENT', $text);
                 load_mode_language_pack("languages", $this->output_charset, true);
                 load_mode_language_pack("prepare", $this->output_charset);
                 localise_template_strings($this->panels["MAIN"]->smarty);
                 $reportname = preg_replace("/.xml/", "", $this->xmloutfile . '_prepare.tpl');
                 restore_error_handler();
                 if (preg_match("/{$reportname}/", find_best_location_in_include_path("templates/" . $reportname))) {
                     $this->panels["MAIN"]->smarty->display($reportname);
                 } else {
                     if ($this->user_template) {
                         $this->panels["MAIN"]->smarty->display($this->user_template . '_prepare.tpl');
                     } else {
                         $this->panels["MAIN"]->smarty->display('prepare.tpl');
                     }
                 }
                 $old_error_handler = set_error_handler("ErrorHandler");
             } else {
                 if ($this->target_format != "HTML") {
                     if ($draw) {
                         echo $text;
                     }
                 } else {
                     $title = sw_translate($this->derive_attribute("ReportTitle", "Unknown"));
                     $pagestyle = $this->targets[0]->get_style_tags($this->output_reportbody_styles);
                     $this->panels["MAIN"]->smarty->assign('REPORT_PAGE_STYLE', $pagestyle);
                     $this->panels["MAIN"]->smarty->assign('TITLE', $title);
                     $this->panels["MAIN"]->smarty->assign('CONTENT', $text);
                     $this->panels["MAIN"]->smarty->assign('EMBEDDED_REPORT', $this->embedded_report);
                     // When printing in separate html window make sure we dont treat report as embedded
                     if (get_request_item("new_reportico_window", false)) {
                         $this->panels["MAIN"]->smarty->assign('EMBEDDED_REPORT', false);
                     }
                     if ($this->email_recipients) {
                         $recipients = explode(',', $this->email_recipients);
                         foreach ($recipients as $rec) {
                             load_mode_language_pack("languages", $this->output_charset, true);
                             load_mode_language_pack("execute", $this->output_charset);
                             localise_template_strings($this->panels["MAIN"]->smarty);
                             $mailtext = $this->panels["MAIN"]->smarty->fetch('execute.tpl', NULL, NULL, false);
                             //$boundary = '-----=' . md5( uniqid ( rand() ) );
                             //$message = "Content-Type: text/html; name=\"my attachment\"\n";
                             //$message .= "Content-Transfer-Encoding: base64\n";
                             //$message .= "Content-Transfer-Encoding: quoted-printable\n";
                             //$message .= "Content-Disposition: attachment; filename=\"report.html\"\n\n";
                             $content_encode = chunk_split(base64_encode($mailtext));
                             $message = $mailtext . "\n";
                             //$message .= $boundary . "\n";
                             $headers = "From: \"Report Admin\"<*****@*****.**>\n";
                             $headers .= "MIME-Version: 1.0\n";
                             $headers .= "Content-Transfer-Encoding: base64\n";
                             //$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
                             $headers = "Content-Type: text/html\n";
                             mail($rec, "{$title}", $message, $headers);
                         }
                     } else {
                         load_mode_language_pack("languages", $this->output_charset, true);
                         load_mode_language_pack("execute", $this->output_charset);
                         localise_template_strings($this->panels["MAIN"]->smarty);
                         $reportname = preg_replace("/.xml/", "", $this->xmloutfile . '_execute.tpl');
                         restore_error_handler();
                         if (preg_match("/{$reportname}/", find_best_location_in_include_path("templates/" . $reportname))) {
                             $this->panels["MAIN"]->smarty->display($reportname);
                         } else {
                             if ($this->user_template) {
                                 $this->panels["MAIN"]->smarty->display($this->user_template . '_execute.tpl');
                             } else {
                                 $this->panels["MAIN"]->smarty->display('execute.tpl');
                             }
                         }
                         $old_error_handler = set_error_handler("ErrorHandler");
                     }
                 }
             }
             break;
         case "MAINTAIN":
             $this->handle_xml_query_input($mode);
             if ($this->top_level_query) {
                 $this->initialize_panels($mode);
                 load_mode_language_pack("maintain", $this->output_charset);
                 localise_template_strings($this->panels["MAIN"]->smarty);
                 $this->xmlin->handle_user_entry();
                 set_reportico_session_param("xmlintext", $this->xmlintext);
                 $text = $this->panels["BODY"]->draw_smarty();
                 $this->panels["MAIN"]->smarty->assign('CONTENT', $text);
                 $this->panels["MAIN"]->smarty->display('maintain.tpl');
             } else {
                 $this->premaintain_query();
             }
             break;
         case "XMLOUT":
             $this->handle_xml_query_input($mode);
             $this->xmlout = new reportico_xml_writer($this);
             $this->xmlout->prepare_xml_data();
             if (array_key_exists("xmlout", $_REQUEST)) {
                 $this->xmlout->write_file($_REQUEST["xmlout"]);
             } else {
                 $this->xmlout->write();
             }
             break;
         case "XMLSHOW":
             $this->handle_xml_query_input($mode);
             $this->xmlout = new reportico_xml_writer($this);
             $this->xmlout->prepare_xml_data();
             $this->xmlout->write();
             break;
         case "WSDLSHOW":
             $this->handle_xml_query_input($mode);
             $this->xmlout = new reportico_xml_writer($this);
             $this->xmlout->prepare_wsdl_data();
             break;
         case "SOAPSAVE":
             $this->handle_xml_query_input($mode);
             $this->xmlout = new reportico_xml_writer($this);
             $this->xmlout->generate_web_service($this->xmloutfile);
             break;
     }
     $this->handled_initial_settings();
     close_reportico_session();
 }
Example #2
0
            find_file_to_include("config.php", $configfile);
            if ($configfile) {
                include_once $configfile;
            }
            $g_project = false;
            $g_menu = false;
            $g_menu_title = "";
            $old_error_handler = set_error_handler("\\Reportico\\Reportico\\ErrorHandler");
            handle_error("Configuration Definition file config.php not found in project {$project}", E_USER_ERROR);
        }
        $g_project = $project;
        $g_menu = $menu;
        $g_menu_title = $menu_title;
        return $project;
    }
}
set_project_environment();
$datasource = new reportico_datasource(\DB::connection()->getPdo(), \Config::get("database.connections"));
$datasource->connect();
$imagesql = $_REQUEST["imagesql"];
if (!preg_match("/^select/i", $imagesql)) {
    return false;
}
$rs = $datasource->ado_connection->Execute($imagesql) or die("Query failed : " . $ado_connection->ErrorMsg());
$line = $rs->FetchRow();
//header('Content-Type: image/gif');
foreach ($line as $col) {
    $data = $col;
    break;
}
echo $data;