Can I direct report output to a PHP variable?

(16 posts) (2 voices)
  1. shem, Member

    Our PHP code uses an Object tag to display report output.

    In addition to that, we want to be able to have the output from the myDBR report assigned to a PHP variable.
    Then I want to use our applications own code to mail it.

    I saw on the forum someone mentioned select 'dbr.mail';
    But I would rather not have a special report for mailing.
    I just want to take an existing myDBR report (which does not involve mailing) and mail it using our PHP code.

    I am guessing that I may have to append to the report url &export=pdf or &export=excel which is fine because I don't have to change the report itself.

  2. myDBR Team, Key Master

    What do you mean by "output from the myDBR report assigned to a PHP variable". What would the variable contain and in what format?

    The easiest way of mailing a myDBR report is to use dbr.mail. You can then attach the report in desired format in the mail.
    --
    myDBR Team

  3. shem, Member

    You asked
    "What do you mean by "output from the myDBR report assigned to a PHP variable". What would the variable contain and in what format?"

    Now that I think about it, I think I need it to be the output that you see when you click on "Export to PDF" (or "Export to Excel").
    I just want to put together my direct URL (with all its protected parameters, etc.) and reference it like I do now in the embeded html object tag in our PHP application, and append to it "&export=pdf", but instead of having the result display inside my webpage, I want the result to be stored in a PHP variable, so I can do with it as I please.

    You also wrote:
    "The easiest way of mailing a myDBR report is to use dbr.mail"
    That is what I am trying to avoid.
    So if I have currently have a report called "Customers" I don't want to have a second almost identical report called "Customers_for_email" just so that I could email it. Furthermore, I don't want to have to pass email parameters to the report when I have them already in my PHP code, and my PHP code can do the emailing.

  4. myDBR Team, Key Master

    You can always create your own code to call myDBR for the PDF version of the report and attach the generated PDF file to your email process.

    If you choose to use myDBR's mailing functionality, you do not need to create a separate 'Customers_for_email' report. Instead, you can add an existing report as an attachment.

    Choose the solution that works best for you.

    --
    myDBR Team

  5. shem, Member

    You wrote:
    "You can always create your own code to call myDBR for the PDF version of the report and attach the generated PDF file to your email process."
    When you say "call myDBR for the PDF version" Do you mean call it to download automatically onto my server?
    Is there a way to do this in PHP/html without it downloading?

    And you write:
    "If you choose to use myDBR's mailing functionality, you do not need to create a separate 'Customers_for_email' report. Instead, you can add an existing report as an attachment."
    I don't exactly understand.
    Can you please give me an example?

    Thanks

  6. myDBR Team, Key Master

    When you say "call myDBR for the PDF version" Do you mean call it to download automatically onto my server?
    Is there a way to do this in PHP/html without it downloading?

    myDBR will produce the PDF file for you. Unfortunatly we do not know how your application works, but in general, you can read the generated file directly into your application.

    I don't exactly understand.
    Can you please give me an example?

    See the dbr.mail.attach command in the documentation.

    --
    myDBR Team

  7. shem, Member

    Still not clear on what you mean.
    It will generate a PDF file that gets automatically downloaded? Or is there a possibility that it generates a file WITHOUT downloading, and where I can store the contents of the file into a PHP variable?
    Currently when I click on export to pdf it does not automatically download but rather displays on the web page. So my question is can that html display code be assigned to a PHP variable instead of displaying on the web page using my object tag?

  8. myDBR Team, Key Master

    In your application, you need to access the myDBR URL, read the output, and handle it with your mailing code. How to do it depends entirely on your application/code.

    Mailing myDBR reports is easy enough with myDBR alone. It has all the necessary capabilities for it. Choose the solution that works best for you.

    --
    myDBR Team

  9. shem, Member

    Please just clarify what you mean by "read the output". Thats what I am asking. How do I read the output?
    Can I do something like
    $php_variable = header('Location: https://server/mydbr/...

  10. myDBR Team, Key Master

    This is more of a generic PHP question than a myDBR question.

    To read a remote resource into a PHP variable, you can use PHP's file_get_contents, cURL, or any other HTTP library (such as Guzzle) that your application may have.

    To access a myDBR report via an HTTP GET request, you need to authenticate. The easiest way is to use HTTP basic access authentication. Refer to the myDBR documentation and the cURL sample code for more information.

    --
    myDBR Team

  11. shem, Member

    Two follow up questions:

    1) If I have SSO for authorization, shouldn't a GET (vi a file_get_contents for example) work without additional authenticating?

    2) I tried the following
    $direct_url starts as the exact value which works on our system when inside an object tag (both with and without SSO)
    Yet it echos nothing to the screen

    $direct_url = $direct_url . "&export=json";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $direct_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, 'test@verifacto.com:test@verifacto.com');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MYDBR-AUTH: 1'));
    $reportContent = curl_exec($ch);
    curl_close($ch);

    echo "The report content is:";
    echo ($reportContent);

  12. myDBR Team, Key Master

    1) If I have SSO for authorization, shouldn't a GET (vi a file_get_contents for example) work without additional authenticating?

    No, your application does not know that the user is logged into myDBR and it does not have the cookie to be passed alongside the call.

    2) I tried the following

    The Basic Access Authentication uses local myDBR authentication. Try with those credentials and check for any errors in your calls to cURL.

    --
    myDBR Team

  13. shem, Member

    I have debugged the problem:
    What I found is that the CURL won't work with a user whose authentication type is Single Sign-On, so I had to create another user with the identical credentials whose authentication type is myDBR user.

    But I am still curious about two things:

    1) you wrote above:
    "myDBR will produce the PDF file for you. ... in general, you can read the generated file directly into your application."
    I understand what you meant by "produce the PDF" - I believe you mean append "&export=pdf" to the end of the URL.
    Then the PDF format of the report output gets displayed on the webpage.
    But what did you mean by the word "file"?
    How is the PDF file generated from within my PHP application?
    Did you mean there is a specific setting to cause an "automatic download" of the file?

    2) How come when I run the Curl command referencing a myDBR URL, it doesn't try to call the "SSO Server URL" which I have defined in the Environment settings?

  14. myDBR Team, Key Master

    1) you wrote above:
    "myDBR will produce the PDF file for you. ... in general, you can read the generated file directly into your application."
    I understand what you meant by "produce the PDF" - I believe you mean append "&export=pdf" to the end of the URL.
    Then the PDF format of the report output gets displayed on the webpage.
    But what did you mean by the word "file"?
    How is the PDF file generated from within my PHP application?
    Did you mean there is a specific setting to cause an "automatic download" of the file?

    When you ask for PDF report from myDBR in the browser, myDBR will send the generated PDF to your browser. Depending on the setting, the browser will either display the PDF in the page or download it as a file. Either way, the same PDF content is sent from myDBR.

    When you read the same PDF report into your own application using cURL, the same conent is read into a PHP variable ($reportContent = curl_exec($ch);. It is up to you to decide what you do with it.

    2) How come when I run the Curl command referencing a myDBR URL, it doesn't try to call the "SSO Server URL" which I have defined in the Environment settings?

    See the answer above.

    --
    myDBR Team

  15. shem, Member

    You write
    "Depending on the setting, the browser will either display the PDF in the page or download it as a file. "
    Where is this setting?

    Also, forgive me but I don't see above that you answered my question of
    How come when I run the Curl command referencing a myDBR URL, it doesn't try to call the "SSO Server URL" which I have defined in the Environment settings?

    Thanks

  16. myDBR Team, Key Master

    You write
    "Depending on the setting, the browser will either display the PDF in the page or download it as a file. "
    Where is this setting?

    See the documentation about content-disposition option in the export options.

    Also, forgive me but I don't see above that you answered my question of
    How come when I run the Curl command referencing a myDBR URL, it doesn't try to call the "SSO Server URL" which I have defined in the Environment settings?

    See the documentation about the Using HTTP basic access authentication.

    The SSO protocol does not know how your application authenticates the user. It can use username/password, two-factor authentication, or something else. Since cURL access is a direct call, there is no UI for the user to perform two-factor authentication or any other actions that might occur at the SSO app's end. Therefore, cURL access does utilize myDBR authentication when the server is using SSO.

    --
    myDBR Team


Reply

You must log in to post.