0

I have written a custom module which generates a PDF when a Webform is submitted and mails it to the admin. I am using the Print module to generate the PDF. The problem is, it seems to use the user's permissions when generating the PDF, and not the admin's. This is generally ok for authenticated users, but for guests, it just fails completely.

I have enabled "Access the PDF version" and "Access own webform submissions" permissions for all users (anonymous and authenticated), but I guess "own" still checks for a user ID and fails for guests.

The Print module uses this code to get the content of the $node from the URL.

$node = new stdClass();
$node->body = menu_execute_active_handler($path, FALSE);

This is how I am using the Print module to generate the PDF content.

module_load_include('inc', 'print_pdf', 'print_pdf.pages');
$pdf_url = 'node/' . $nid . '/submission/' . $sid;
$file_content = module_invoke('print_pdf', 'generate_path', $pdf_url);

When the logged-in user has the permission, this works fine; it generates and mails the PDF successfully. The content of $node->body is fully populated.

However, when with anonymous users, the content of $node->body is just an integer. Is there any way for me to tell it to bypass the permissions when generating the PDF? Or is there a better, secure way around this?

1 Answer 1

1

Looking at webform_submission_access, prior to getting the PDF url, try:

// Where $sid is the webform submission id
$_SESSION['webform_submission'][$sid] = TRUE;

If that works for the anonymous user, it may grant access to view that submission.

2
  • Thanks, that seems to be working! There are some notices in the Webform module about an $account variable missing, but they are just notices.
    – user11312
    Jul 23, 2013 at 3:44
  • And just a note for anybody else that I still had to have both permissions enabled for anonymous users.
    – user11312
    Jul 23, 2013 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.