Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Duplicating a report into the session and opening a report on it without using session.session_folder

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Duplicating a report into the session and opening a report on it without using session.session_folder

    I need to sort reports that display totals, by those totals.

    (Here is an example: visitors visited open space properties in 2013. One of my reports displays the total number of visitors for each open space property. It needs to be sorted by the total number of visitors, so that one can see easily, which properties were visited the most.)

    I have come to the conclusion that this cannot be done, unless I first assemble the data (including the totals), using the crosstab method, in a separate table and then build my report on that table.

    The report also needs to be filtered by a date range that the user can provide. I am attaching a screenshot of the report interface.

    I can't just filter the report by this date range, as I would normally do, since the totals have to be recalculated first.

    Since several users could be running reports for different date ranges, this means, that I need to create a separate temporary table for each user that is running the report.

    My plan was, using a solution described by Steve Workings in a different post, to:

    - create the crosstab for the default date range
    - use the <tbl>.duplicate method to create an empty copy that includes the report in the session folder
    - fill that table with the data for the user entered date range
    - create the report on the table in the session folder and pop it up for the user to see.

    I can do this using session.session_folder, but this has been deprecated and is supposed to be replaced using Session.SaveDataAsFile and Session.FormatFileDataURL.

    I managed to do a lot of what I need to do using these functions by looking at the examples on the wiki, but there are still two pieces of code left that I don't know how to rewrite without using session.session_folder: the part that duplicates the table into the session folder and the string that tells a5w_report_saveAs what report to run.

    Code:
    function serverside_067066f1fb34448babec61699aa7c127 as c (e as p)
    
    'Duplicate the relevant table including its layouts into the session folder:
    dim t1 as p
    t1 = table.open("[PathAlias.ADB_Path]\l_acti_ini.dbf")
    t1.duplicate(session.session_folder + "l_acti_ini.dbf",3)
    t1.close()
    
    
    'Create the report on the duplicated table in the session folder and put it also into the session folder:
    dim filter as c = ""
    dim order as c = ""
    dim filename as c = Request.GetRequestTempFileName() 'the filename that the pdf should be saved to
    
    'dim reportname as c = a5w_report_saveAs("test@[PathAlias.ADB_Path]\l_acti_ini.ddd","pdf",filter,order,filename,global_variables())
    dim reportname as c = a5w_report_saveAs("test@" + session.session_folder + "l_acti_ini.ddd","pdf",filter,order,filename,global_variables()) 'legacy->bad, how do I replace that?
    
    dim returned as c
    if file.exists(reportname)
    	Session.SaveDataAsFile("test.pdf",file.to_blob(reportname))
    	returned = Session.FormatFileDataURL("test.pdf")
    	'Response.Redirect("http://" + request.host + returned) 'This doesn't seem to be working, even though it should
    end if
    
    
    dim js as c = ""
    'js = js + "window.location = 'http://" + request.host + "/A5SessionFile/" + "test.pdf" + "';" 'This code works, but I want to open the report in a modal window.
    
    'Regarding the code below:
    'I created and action with action javascript to open the fixed url "http://localhost/A5SessionFile/test.pdf"
    'I then copied the resulting javascript and adjusted the url to use request.host.
    
    js = <<%jstxt%
    window['{grid.componentName}_O_1A90DA050B0C48BFA989CC73A01677BD'] = function(rowNum,rowId,objEle) {
    
    window['{Grid.ComponentName}_1A90DA050B0C48BFA989CC73A01677BD'] = {grid.object}.createWindow('{grid.componentName}_WINDOW_1A90DA050B0C48BFA989CC73A01677BD','modal-url-resizable',{
    	height: '5in',
    	width: '8in',
    	title: {
    		html: 'Window',
    		location: 'top'
    	},
    	disableMove: false,
    	theme: '{grid.style}',
    	body: {
    		content: {
    			type: 'url',
    			url: '__workingMessage.a5w'
    		}
    	},
    	onHide: function() { $(this.getWindowId('body')).src = '__workingMessage.a5w';}
    }   );
    window['{Grid.ComponentName}_1A90DA050B0C48BFA989CC73A01677BD'].show();
    %jstxt%
    
    
    js = js + "$(window['{Grid.ComponentName}_1A90DA050B0C48BFA989CC73A01677BD'].getWindowId('body')).src = 'http://" + request.host + "/A5SessionFile/test.pdf';"
    
    dim js_tail as c = ""
    js_tail = <<%jstxt%
    }
    
    {grid.componentName}_O_1A90DA050B0C48BFA989CC73A01677BD({grid.rownumber},'{grid.rowId}',this);
    %jstxt%
    
    js = js + js_tail
    
    serverside_067066f1fb34448babec61699aa7c127 = js
    So here is my question: is there a way to do all of this with the new Session.SaveDataAsFile and Session.FormatFileDataURL functions? Also, am I on the right track or is there an alltogether easier way of doing this that I have missed?

    Thanks a lot for any help! I have been banging my head against the wall for quite a while...
    Attached Files

    #2
    Re: Duplicating a report into the session and opening a report on it without using session.session_folder

    Does running "l_acti_ini.ddd" through Session.FormatFileDataURL give you an appropriate URL?


    Code:
    'FormatFileDataURL will give you the full URL to the file. You don't need to add extra.
    returned = Session.FormatFileDataURL("test.pdf")
    js = "window.location = '" + js_escape(returned) + "';"
    Better question. Can you generate your temporary table using Request.GetRequestTempFileName() and work off of that instead of copying it to the user's session folder?

    eg:
    Code:
    t1 = table.open("[PathAlias.ADB_Path]\l_acti_ini.dbf")
    dim temptbl as c = Request.GetRequestTempFileName(".dbf")
    t1.duplicate(temptbl,3)
    You'll have to do extra work to replace the .dbf with .ddd in the filename for your later operation. But I think it becomes "test@" + temptlb in your a5w_report_saveas operation.
    Last edited by TheSmitchell; 02-06-2014, 07:49 PM.
    Alpha Anywhere latest pre-release

    Comment


      #3
      Re: Duplicating a report into the session and opening a report on it without using session.session_folder

      If you need to work with a physical file on disk, such as copying your DBF and then reporting against it, you cannot work with a file in Session storage. You will need to create a temporary file, use it as needed, then move it into Session storage if you need to persist it.

      For creating a temporary file, look at using Request.GetRequestTempFileName(). The Wiki includes an example on the Storing Files in Sessions page under the Legacy Compatibility heading.

      Lenny Forziati
      Vice President, Internet Products and Technical Services
      Alpha Software Corporation

      Comment


        #4
        Re: Duplicating a report into the session and opening a report on it without using session.session_folder

        Thanks to both of you for getting me unstuck!
        Sarah: thanks for coming to my rescue yet again!

        Here is the code that works:

        Code:
        function serverside_067066f1fb34448babec61699aa7c127 as c (e as p)
        
        'Duplicate the relevant table including its layouts into a temporary folder:
        dim t1 as p
        t1 = table.open("[PathAlias.ADB_Path]\l_acti_ini.dbf")
        dim dup_table_full_name as c = Request.GetRequestTempFileName(".dbf") 
        t1.duplicate(dup_table_full_name,3)
        dim report_path as c = substr(dup_table_full_name,1,len(dup_table_full_name) - 3) + "ddd"
        t1.close()
        
        'Create the report on the duplicated table and put it into the session folder:
        dim filter as c = ""
        dim order as c = ""
        dim filename as c = Request.GetRequestTempFileName() 'the filename that the pdf should be saved to
        
        dim reportname as c = a5w_report_saveAs("test@" + report_path,"pdf",filter,order,filename,global_variables()) 
        
        dim returned as c
        if file.exists(reportname)
        	Session.SaveDataAsFile("test.pdf",file.to_blob(reportname))
        	returned = Session.FormatFileDataURL("test.pdf")
        end if
        
        dim js as c = ""
        'js = js + "window.location = 'http://" + request.host + "/A5SessionFile/" + "test.pdf" + "';" 'This code works, but I want to open the report in a modal window.
        
        'Regarding the code below:
        'I created an action with action javascript to open the fixed url "http://localhost/A5SessionFile/test.pdf"
        'I then copied the resulting javascript and adjusted the url to use request.host.
        
        js = <<%jstxt%
        window['{grid.componentName}_O_1A90DA050B0C48BFA989CC73A01677BD'] = function(rowNum,rowId,objEle) {
        
        window['{Grid.ComponentName}_1A90DA050B0C48BFA989CC73A01677BD'] = {grid.object}.createWindow('{grid.componentName}_WINDOW_1A90DA050B0C48BFA989CC73A01677BD','modal-url-resizable',{
        	height: '5in',
        	width: '8in',
        	title: {
        		html: 'Window',
        		location: 'top'
        	},
        	disableMove: false,
        	theme: '{grid.style}',
        	body: {
        		content: {
        			type: 'url',
        			url: '__workingMessage.a5w'
        		}
        	},
        	onHide: function() { $(this.getWindowId('body')).src = '__workingMessage.a5w';}
        }   );
        window['{Grid.ComponentName}_1A90DA050B0C48BFA989CC73A01677BD'].show();
        %jstxt%
        
        
        js = js + "$(window['{Grid.ComponentName}_1A90DA050B0C48BFA989CC73A01677BD'].getWindowId('body')).src = 'http://" + request.host + "/A5SessionFile/test.pdf';"
        
        dim js_tail as c = ""
        js_tail = <<%jstxt%
        }
        
        {grid.componentName}_O_1A90DA050B0C48BFA989CC73A01677BD({grid.rownumber},'{grid.rowId}',this);
        %jstxt%
        
        js = js + js_tail
        
        serverside_067066f1fb34448babec61699aa7c127 = js
        Regarding the url of the report: I think the request.host is necessary.

        When I print the "returned" variable to a debug file, using:

        Code:
        '*********************************
        'DEBUG CODE
        dim debugInfo as p
        debugInfo.returned = returned
        
        dim txt as c
        txt = property_to_string(debugInfo)
        dim fn as c
        fn = "c:\TEMP\Debug\debugInfo_" + time("hms3",now()) + ".txt"
        file.from_string(fn,txt)
        '*********************************
        I get only: returned="/A5SessionFile/test.pdf", which doesn't work.

        I got the request.host trick from this msgboard post:
        http://msgboard.alphasoftware.com/al...=A5SessionFile

        Thanks again. I really appreciate it!

        Comment


          #5
          Re: Duplicating a report into the session and opening a report on it without using session.session_folder

          Originally posted by Simone View Post
          Regarding the url of the report: I think the request.host is necessary.

          When I print the "returned" variable to a debug file, using:

          Code:
          '*********************************
          'DEBUG CODE
          dim debugInfo as p
          debugInfo.returned = returned
          
          dim txt as c
          txt = property_to_string(debugInfo)
          dim fn as c
          fn = "c:\TEMP\Debug\debugInfo_" + time("hms3",now()) + ".txt"
          file.from_string(fn,txt)
          '*********************************
          I get only: returned="/A5SessionFile/test.pdf", which doesn't work.

          I got the request.host trick from this msgboard post:
          http://msgboard.alphasoftware.com/al...=A5SessionFile

          Thanks again. I really appreciate it!
          As far as I know, "/A5SessionFile/test.pdf" should be treated as a relative URL. This is literally the last line in my show report stuff:

          Code:
          	displayPlanPDF = "window.location = '" + js_escape(Session.FormatFileDataURL(filename)) + "';"
          It redirects to "http://www.myhost.com/A5SessionFile/file.pdf" even though Session.FormatFileDataURL(filename) returns "/A5SessionFile/file.pdf". But, if you're experiencing problems, then you probably should pre-pend your host address to the file address.
          Alpha Anywhere latest pre-release

          Comment


            #6
            Re: Duplicating a report into the session and opening a report on it without using session.session_folder

            Thanks, Sarah, I was wondering if it was safe to use /A5SessionFile/ directly. I will see if I can get your code to work...

            Comment


              #7
              Re: Duplicating a report into the session and opening a report on it without using session.session_folder

              Yes, it works! Thank you, Sarah!

              Comment


                #8
                Re: Duplicating a report into the session and opening a report on it without using session.session_folder

                Hello Simone,

                I see from following along on your code that you could not get the window to open up as modal. Did you ever get that fixed and if so could you enlighten how?

                I am trying to open a pdf in a session folder from a xbasic function in a Dialog2. A lot of the answers on the forum have been to use response.redirect(), but have no luck with that displaying at all. Best so far has been this thread, but would love to see it open in a modal window. I am using controls in the Dialog2 to server as filter arguments and have buttons running different reports that are saved as pdf. I would like to open as modal so the user doesn't have to reenter all of the filter criteria each time a report is run.

                Thanks for the help.

                Andy

                Comment


                  #9
                  Re: Duplicating a report into the session and opening a report on it without using session.session_folder

                  I forgot to say the original code is which shows the pdf, but overwrites the tabbed ui window:

                  Report1Print = "window.location = '" + js_escape(Session.FormatFileDataURL("tempreport.pdf")) + "';"

                  I tried with this code, but got the exact same result:

                  dim exper as c = "window.location = '" + js_escape(Session.FormatFileDataURL("tempreport.pdf")) + "'"
                  Report1Print = "window.showModalDialog(" + exper +");"

                  Comment


                    #10
                    Re: Duplicating a report into the session and opening a report on it without using session.session_folder

                    Hi Andy,

                    Yes, my reports open in modal popup windows:

                    report.png

                    It's been a while that I worked on this. I will paste the code from the dialog component shown in the above screenshot. Hopefully, you can figure out from there. If not, just let me know and I will see if I can remember the details...

                    The code for the onDialogInitialize server side event is:
                    (it contains a lot of comments that might help you...)

                    Code:
                    function onDialogInitialize as v (e as p)
                    	
                    	'------------------------------------------------------------------------------------------------------------------
                    	'Some ranger reports need to be sorted by group totals. This means that the data and totals needs to be assembled in 
                    	'a crosstab table, for the date range chosen by the user, before a report is run. The report, which is then built on 
                    	'this crosstab table, can then sort by the totals, since these already exist and are not computed on the fly. 
                    	
                    	'Since different users can run the same report for different date ranges at the same time, the data needs to be put into 
                    	'the temporary folder. (A5 provides functions for saving and accessing temporary stuff to and from a temporary folder, 
                    	'the location of which it determines, but hides from the developer.)
                    	
                    	'In order to run the reports on the data in the temporary folder, we need to put them there. We can only do this by 
                    	'duplicating the underlying tables into that folder, since the reports are contained in the .ddd file of their 
                    	'underlying table. This means we have to create the crosstabs in the main data folder first. Of course, we also need 
                    	'to do this so that we can build the reports. We also need to not forget to publish the underlyingthese tables to the 
                    	'main data folder on the hosting server.
                    		
                    	'------------------------------------------------------------------------------------------------------------------
                    	'We will create a join table and then several crosstab tables. For each of these we define the following 
                    	'session variables. Then, when the user opens one of the above reports, we can use these to 
                    	'determine if the data already exists for the submitted date range or if it needs to be re-calculated.
                    	
                    	'Make sure we start with blank variables:
                    	session.start_date_join = ""
                    	session.end_date_join = ""
                    	session.full_name_join = ""
                    	
                    	session.start_date_ct_reg_viol = ""
                    	session.end_date_ct_reg_viol = ""
                    	session.full_name_ct_reg_viol = ""
                    	
                    	session.start_date_ct_prop_viol = ""
                    	session.end_date_ct_prop_viol = ""
                    	session.full_name_ct_prop_viol = ""
                    	
                    	session.start_date_ct_prop_visits = ""
                    	session.end_date_ct_prop_visits = ""
                    	session.full_name_ct_prop_visits = ""
                    	
                    	session.start_date_ct_prop_activity = ""
                    	session.end_date_ct_prop_activity = ""
                    	session.full_name_ct_prop_activity = ""
                    	
                    	'NOTE: the full_name variables will stay the same for the entire session.
                    	
                    	'We define one more session variable to identify the window we open before the report data is calculated. It can 
                    	'take a while before the calulation is finished. We need to show the window to the user sooner than that so that 
                    	'they know that something is happening. Once we have the data we will open the report in this window, but to do so
                    	'we need to know which window it is.
                    	
                    	session.window_id = "" 
                    	
                    	
                    	'------------------------------------------------------------------------------------------------------------------
                    	'We create the initial join and crosstab tables in the main data folder:
                    	
                    	'(This is commented out because we only need to do this once. We could do this manually, but we'll do it this way 
                    	'to ensure that the tables have correct field names and types. Note: when I create these for the 
                    	'first time I have to add them to the database.)
                    	
                    	'calc_join("[PathAlias.ADB_Path]\\" + "join.dbf")
                    	'calc_crosstab("ct_reg_viol", "[PathAlias.ADB_Path]\\" + "ct_reg_viol.dbf", "[PathAlias.ADB_Path]\\" + "join.dbf")
                    	'calc_crosstab("ct_prop_viol", "[PathAlias.ADB_Path]\\" + "ct_prop_viol.dbf", "[PathAlias.ADB_Path]\\" + "join.dbf")
                    	'calc_crosstab("ct_prop_visits", "[PathAlias.ADB_Path]\\" + "ct_prop_visits.dbf", "[PathAlias.ADB_Path]\\" + "join.dbf")
                    	'calc_crosstab("ct_prop_activity", "[PathAlias.ADB_Path]\\" + "ct_prop_activity.dbf", "[PathAlias.ADB_Path]\\" + "join.dbf")
                    	
                    	'------------------------------------------------------------------------------------------------------------------
                    	'We duplicate the initial join and crosstab tables to the temporary folder and set the "full_name" session variables:
                    	
                    	dim dup_table_full_name as c = ""
                    	dim tbl as p
                    	
                    	'join
                    	tbl = table.open("[PathAlias.ADB_Path]\join.dbf")
                    	dup_table_full_name = Request.GetRequestTempFileName(".dbf") 
                    	tbl.duplicate(dup_table_full_name,3) 'option 3 copies it without records but with layouts
                    	session.full_name_join = dup_table_full_name
                    	tbl.close()
                    	
                    	'ct_reg_viol
                    	tbl = table.open("[PathAlias.ADB_Path]\ct_reg_viol.dbf")
                    	dup_table_full_name = Request.GetRequestTempFileName(".dbf") 
                    	tbl.duplicate(dup_table_full_name,3) 'option 3 copies it without records but with layouts
                    	session.full_name_ct_reg_viol = dup_table_full_name
                    	tbl.close()
                    
                    	'ct_prop_viol
                    	tbl = table.open("[PathAlias.ADB_Path]\ct_prop_viol.dbf")
                    	dup_table_full_name = Request.GetRequestTempFileName(".dbf") 
                    	tbl.duplicate(dup_table_full_name,3) 'option 3 copies it without records but with layouts
                    	session.full_name_ct_prop_viol = dup_table_full_name
                    	tbl.close()
                    
                    	'ct_prop_visits
                    	tbl = table.open("[PathAlias.ADB_Path]\ct_prop_visits.dbf")
                    	dup_table_full_name = Request.GetRequestTempFileName(".dbf") 
                    	tbl.duplicate(dup_table_full_name,3) 'option 3 copies it without records but with layouts
                    	session.full_name_ct_prop_visits = dup_table_full_name
                    	tbl.close()
                    
                    	'ct_prop_activity
                    	tbl = table.open("[PathAlias.ADB_Path]\ct_prop_activity.dbf")
                    	dup_table_full_name = Request.GetRequestTempFileName(".dbf") 
                    	tbl.duplicate(dup_table_full_name,3) 'option 3 copies it without records but with layouts
                    	session.full_name_ct_prop_activity = dup_table_full_name
                    	tbl.close()
                    
                    	'They reports are now in the temporary folder. 
                    	
                    	'Next, I implemented the following:
                    	
                    	'When the user clicks on a button that opens a report, two AJAX callbacks are made:
                    	
                    	'The callback function open_report_window 
                    	'		- opens a window
                    	'		- gives it a unique id 
                    	'		- and puts this id into session.window_id 
                    	'We only need one id since the report window is modal.
                    	
                    	'The callback function get_data_and_show_report 
                    	'		- re-calculates the underlying tables in the temporary folder, if it is necessary
                    	'		- creates the report
                    	'		- and opens it in the already existing window. 
                    	'I think, I can assume that calculating the data and creating the report will never take less 
                    	'long than it takes to open the window. Hence, even though the callbacks are executed asynchronously, 
                    	'we can assume that the window is created before it is used to display the report.
                    	
                    	
                    end function
                    Here are the callback that are defined for each of the report buttons:
                    ReportButtonCallback1.png
                    ReportButtonCallback2.png

                    And here are the Xbasic function definitions:

                    Code:
                    function open_report_window as c(e as p) 'AJAX callback to open initial window
                    	
                    	dim js as c = ""
                    	dim unique_id as c = "report" + time("hms3",now()) 'Only one report can be open at a time, so this should be a unique id for this user's current session
                    	session.window_id = unique_id
                    	
                    	js = <<%jstxt%
                    	window['{grid.componentName}_O_UNIQUE_ID'] = function(rowNum,rowId,objEle) {
                    		if({grid.object}._embeddedMode) {
                    			alert('Opening .a5w pages is not supported when the Component is running on the Desktop.');
                    			return false;
                    		}
                    		
                    	window['{Grid.ComponentName}_UNIQUE_ID'] = {grid.object}.createWindow('{grid.componentName}_WINDOW_UNIQUE_ID','modal-url-resizable',{
                    		height: '5in',
                    		width: '8in',
                    		title: {
                    			html: 'Window',
                    			location: 'top'
                    		},
                    		disableMove: false,
                    		theme: '{grid.style}',
                    		body: {
                    			content: {
                    				type: 'url',
                    				url: '__workingMessage.a5w'
                    			}
                    		},
                    		onHide: function() { $(this.getWindowId('body')).src = '__workingMessage.a5w';}
                    	}   );
                    	window['{Grid.ComponentName}_UNIQUE_ID'].show();
                    	$(window['{Grid.ComponentName}_UNIQUE_ID'].getWindowId('body')).src = '__workingMessage.a5w';
                    	
                    	}
                    	
                    	{grid.componentName}_O_UNIQUE_ID({grid.rownumber},'{grid.rowId}',this);
                    	%jstxt%
                    	
                    	js = strtran(js, "UNIQUE_ID", unique_id)
                    	
                    	open_report_window = js
                    	
                    end function
                    
                    
                    function get_data_and_show_report as c (e as p)  'AJAX callback to re-calculate data, create report, and open it in the already existing window
                    	
                    	dim js as c = ""
                    	
                    	dim submitted_start_date as c = ""
                    	dim submitted_end_date as c = ""
                    	
                    	'Get the full path of the report
                    	dim report_table_location as c = ""
                    	if (e.report == "ct_reg_viol") then
                    		report_table_location = session.full_name_ct_reg_viol
                    	elseif (e.report == "ct_prop_viol") then
                    		report_table_location = session.full_name_ct_prop_viol
                    	elseif (e.report == "ct_prop_visits") then
                    		report_table_location = session.full_name_ct_prop_visits
                    	elseif (e.report == "ct_prop_activity") then
                    		report_table_location = session.full_name_ct_prop_activity
                    	else
                    		js = "alert('Not a valid report.');"
                    	end if
                    
                    	
                    	'Check if the user has provided proper dates:
                    	if (js = "") then 'no problem, yet
                    		
                    		if .NOT. isdate(e.dataSubmitted.start_date) .OR. .NOT. isdate(e.dataSubmitted.start_date) then
                    			js = "alert('Please enter proper dates.');"
                    		else
                    			submitted_start_date = alltrim(e.dataSubmitted.start_date)
                    			submitted_end_date = alltrim(e.dataSubmitted.end_date)
                    		end if
                    		
                    	end if
                    	
                    	'If necessary, re-calculate the join:
                    	if (js = "") then 'no problem, yet
                    		
                    		js = recalc_join(submitted_start_date, submitted_end_date)
                    		
                    	end if	
                    	
                    	'If necessary, re-calculate the crosstab:
                    	if  (js = "") then 'no problem, yet
                    		
                    		js = recalc_crosstab(e.report, submitted_start_date, submitted_end_date)
                    		
                    	end if
                    	
                    	'Open the report:
                    	if  (js = "") then 'no problem, yet
                    		
                    		js = open_report_in_existing_window_js(report_table_location, e.report + "_" + e.sort) ' the last argument produces this: ct_prop_activity_sby_prp
                    	
                    	end if
                    
                    	get_data_and_show_report = js
                    	
                    	
                    end function 
                    
                    
                    function open_report_in_existing_window_js as c(table_full_name as c, report as c)
                    
                    	'Create the report on the underlying table in the temporary folder (it has a different name there) and put it into the session folder:
                    	dim report_path as c = substr(table_full_name,1,len(table_full_name) - 3) + "ddd"
                    	
                    	dim filter as c = ""
                    	dim order as c = ""
                    	dim filename as c = Request.GetRequestTempFileName() 'the filename that the pdf should be saved to
                    	
                    	dim reportname as c = a5w_report_saveAs(report + "@" + report_path,"pdf",filter,order,filename,global_variables()) 
                    	
                    	'Get the url to the report:
                    	dim returned as c = ""
                    	if file.exists(reportname)
                    		Session.SaveDataAsFile(report + ".pdf",file.to_blob(reportname))
                    		returned = Session.FormatFileDataURL(report + ".pdf")
                    	end if
                    	
                    	'Create and emit the javascript that opens it in the existing window:
                    	dim js as c = ""  
                    	
                    	js = js + "$(window['{Grid.ComponentName}_" + session.window_id + "'].getWindowId('body')).src = '" + js_escape(Session.FormatFileDataURL(returned)) + "';"
                    
                    	open_report_in_existing_window_js = js
                    	
                    end function
                    
                    
                    function calc_join as l(full_name_result = "", startdate = "1/1/"+cyear(date()), enddate = "12/31/"+cyear(date()))
                    
                    	'******************************************************************************************
                    	'First, we will create the date filter:
                    	dim filter as c
                    	filter = "between(The_Date, ctod(" + quote(startdate) + "), ctod(" + quote(enddate) + "))"
                    	
                    	'******************************************************************************************
                    	'Next, we join the contacts table (primary table) with the activities table (secondary table).
                    	'We know that every contact links to one and only one activity. So this join will include all contacts.
                    	'However, it misses the activities that have no children.
                    	
                    	'We use the date filter to filter the activities. There is no date at the contacts level, so we can't use it to filter those. 
                    	'This join will produce "orphan" contacts, for which the activity fields are blank because they belong to an activity outside the date range.
                    	'We will have to delete these orphans later.
                    	
                    	'In case the destination table name is stored as a relative file name, or uses an alias 
                    	'in the drive/path specification, use the filename_decode() function to convert the 
                    	'filename to an absolute filename.
                    	
                            '...code that creates teh join on which the reports are built...
                    	
                    	calc_join = .t.
                    	
                    	
                    
                    end function
                    
                    
                    function recalc_join as c(submitted_start_date as c, submitted_end_date as c)
                    	
                    	dim js as c = ""
                    	dim tblname_join as c = session.full_name_join
                    
                    	'If necessary, (re-)calculate the join:
                    	if (session.start_date_join <> submitted_start_date) .OR. (session.end_date_join <> submitted_end_date) then
                    	
                    		if calc_join(tblname_join, submitted_start_date, submitted_end_date) then
                    			session.start_date_join = submitted_start_date
                    			session.end_date_join = submitted_end_date
                    		else
                    			js = "alert('An error occured when calculating the join.');"
                    		end if
                    		
                    	end if
                    	
                    	'We stop if the join is empty:
                    	if table_is_empty(tblname_join) then
                    		js = "alert('There are no records for the date range you provided.');"
                    	end if
                    
                    	recalc_join = js
                    
                    end function
                    
                    
                    function calc_crosstab as l(crosstab_name as c, full_name_result = "", join_full_name = "session")
                    	
                    	dim result as l = .t.
                    	dim tbl as p
                    	
                    	if (join_full_name == "session") then
                    		join_full_name = session.full_name_join
                    	end if	
                    	
                    	'We know that the join has been calculated for the correct date range.
                    	
                    	'*************************************************************************************************************************
                    	if (crosstab_name == "ct_reg_viol") then
                    	
                    	'...code that recalculates the crosstab on which teh report is built...	
                    	
                    	
                    	end if
                    	
                    	
                    	calc_crosstab = .t.
                    	
                    end function
                    
                    
                    function recalc_crosstab as c(crosstab_name as c, submitted_start_date as c, submitted_end_date as c)	
                    
                    	dim js as c = ""
                    	dim tblname as c = ""
                    	
                    	'----------------------------------------------------------------------------------------------------------------------------------------
                    	if (crosstab_name == "ct_reg_viol") then
                    	
                    		tblname = session.full_name_ct_reg_viol
                    	
                    		'If necessary, (re-)calculate the crosstab:
                    		if (session.start_date_ct_reg_viol <> submitted_start_date) .OR. (session.end_date_ct_reg_viol <> submitted_end_date) then
                    			
                    		
                    			if calc_crosstab(crosstab_name, tblname) then
                    				session.start_date_ct_reg_viol = submitted_start_date
                    				session.end_date_ct_reg_viol = submitted_end_date
                    			else
                    				js = "alert('An error occured when calculating the join.');"
                    			end if
                    			
                    		end if
                    		
                    		'We stop if the crosstab is empty:
                    		if table_is_empty(tblname) then
                    			js = "alert('There are no records for the date range you provided.');"
                    		end if
                    	
                    	'----------------------------------------------------------------------------------------------------------------------------------------
                    	'other elseifs .... 
                    
                    	end if
                    
                    	
                    	recalc_crosstab = js
                    	
                    end function

                    Comment


                      #11
                      Re: Duplicating a report into the session and opening a report on it without using session.session_folder

                      Simone,
                      Holy Basset Hounds was that a lot of code. Many kudos to you for the excellent documentation you put in your code which helped my understanding of what was going on by an order of magnitude. I did not need all of the cross tabs, etc. that you had going on but desperately needed the code that got the pdf into the window. Thank you for your generosity in sharing the code.

                      I answered my own post and documented what I did specifically to solve my problem (which was much simpler than yours and only solved with your help) in the following post..
                      http://www.alphasoftware.com/alphafo...517#post687517

                      Thanks again

                      Comment


                        #12
                        Re: Duplicating a report into the session and opening a report on it without using session.session_folder

                        You are most welcome, Andy! I am glad this helped you out.
                        :-)

                        Comment

                        Working...
                        X