{= # # # email_report_setup.cfv # # # Invoked from client to send email via email_report() # Email address validation is not required, all addresses have been validated on the client side. # include "templates.util.base_util"; include "templates.statistics.util.update_report_job"; include "templates.statistics.build_report_elements"; include "templates.statistics.static_reports.assemble_static_report"; include "templates.statistics.email.email_report_setup_util"; include "templates.statistics.email.email_report"; debug_message("\n\n\n#### email_report_setup START \n"); debug_message("\n" . node_as_string("v.fp") . "\n\n"); string profile_name = internal.profile_name; string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); bool is_email_report_permission = is_root_admin or get_report_feature_permission(session_id, profile_name, "send_report_by_email"); string page_token = v.fp.page_token; if (is_email_report_permission and get_is_valid_page_token(session_id, "statistics", page_token)) then ( string user_node_name = node_name(volatile.authenticated_user_node_path); string report_name = v.fp.report_name; # # # # Create email_info node for email_report() # # # delete_node("volatile.email_info"); volatile.email_info = ""; node email_info = "volatile.email_info"; # # # # # Handle SMTP server # # # # bool is_smtp_server_edit = v.fp.is_smtp_server_edit; node pref_email = "preferences.email"; string smtp_server; string smtp_username; string smtp_password; if (!is_smtp_server_edit) then ( # Get default values from preferences smtp_server = @pref_email{"smtp_server"}; smtp_username = @pref_email{"smtp_username"}; smtp_password = @pref_email{"smtp_password"}; ) else ( # Save new smtp server values smtp_server = v.fp.smtp_server; smtp_username = v.fp.smtp_username; smtp_password = v.fp.smtp_password; # Encrypt password if (smtp_password ne "") then ( smtp_password = format(smtp_password, "!encrypt"); ); set_subnode_value(pref_email, "smtp_server", smtp_server); set_subnode_value(pref_email, "smtp_username", smtp_username); set_subnode_value(pref_email, "smtp_password", smtp_password); save_node("preferences"); ); set_subnode_value(email_info, "smtp_server", smtp_server); set_subnode_value(email_info, "smtp_username", smtp_username); set_subnode_value(email_info, "smtp_password", smtp_password); # # # # # Handle email paramters # # # # handle_email_parameters(session_id, user_node_name, profile_name, "v.fp", email_info); # # # # # Handle the report # # # # string session_profile_path = "sessions_cache." . session_id . ".profiles." . profile_name; string current_report_job_id = v.fp.report_job_id; string report_job_id = update_report_job(session_id, profile_name, report_name, current_report_job_id, "static_email"); node report_job = session_profile_path . ".report_jobs." . report_job_id; bool is_ready_report = @report_job{"is_ready_report"}; if (!is_ready_report) then ( # Create the report elements build_report_elements(session_id, profile_name, report_job); ); # Note, volatile.mime_images_buffer is populated within assemble_static_report(), # so it should be available as global variable when we send the email in email_report() string report_content = assemble_static_report(session_id, is_root_admin, profile_name, report_name, report_job_id, "", false, ""); email_report(email_info, report_content); # # # Send response # # #* string dat = "{"; dat .= add_json("subject", report_label, "string"); dat .= add_json("saveRecipientAddressesAsDefault", save_recipient_addresses_as_default, "bool"); dat .= add_json("returnAddress", default_return_address, "string"); dat .= add_json("defaultAddresses", default_addresses_dat, "obj"); dat = close_json(dat); debug_message("#### dat:\n" . dat . "\n"); *# "emailReport.sendResponse()\n"; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}