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);

And here is how I am using the Print module to generate the PDF contents

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 it's a user with permission (authenticated), this works fine, it generates and mails the PDF successfully. The contents of $node->body are fully populated.

However, when it's a guest, the contents 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?

0

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.

  • 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 '13 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 '13 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy