Hi there,
I have a node (page) that contains descriptions of pdfs and download links for each, which are visible to all visitors to our website.
What I want to do is prevent anonymous users from downloading the pdfs without registering first, so when they click on a download link (which is an image) they are redirected to a registration page. For logged-in users, obviously, clicking on a download link should allow them to download without problem.
I have scouted around on this site (and elsewhere) but don't seem to be any nearer a solution. Am I right in thinking I need Javascript to pick up the onclick behaviour? Where would that go - in the template? And do I need php to interrogate the status of the visitor? Bear in mind, I am a complete Drupal-newbie, and would appreciate an easy solution if possible!
Comments
From your description it
From your description it sounds like you have a node with a number of descriptions and hard coded links. Is that correct?
If so, it would be quite straightforward to check if the user is logged in or not and change the link appropriately. I doubt that would really solve your problem though as once someone has the link they could give that to anyone to use, as the document itself isn't likely to be protected.
I'm trying to picture what the user would/should see when they get to your site, so I may have this wrong but...
I'm thinking that you could do this by creating a simple content type that has the description in the body, and add the pdf as an attachment but only give registered users access to download attachments?
Yes - I'm trying to fashion
Yes - I'm trying to fashion something like this...
http://downloads.techrepublic.com.com/download.aspx?docid=346199&promo=1...
The blue button download link won't work for anyone not registered with TechRepublic - they are redirected to a register page.
The solution you propose sounds very likely to work, if I can just get my head around how to set it up! I have a module called node privacy by role installed that will hide a new content type from anonymous users ok,(so I can set up my download link images as this new content type) but I'm stumped as to how to present this on a page which is itself another node!
I very much appreciate your time in answering this...
Oh right, so there is only
Oh right, so there is only one link per node?
no - my page (node) contains
no - my page (node) contains several similar links - picture it as a table of elements, each description paired with a download link, like this...
Description of pdf 1....Download link
Description of pdf 2......Download link
...etc
So I'd need something to ensure that clicking any download link will redirect to the registration page for anonymous users.
Hope this is clear.
Many thanks for your feedback....!
I think this will probably
I think this will probably do all you need:
Make sure you've enabled the PHP filter on the modules page, and set the input type for your node to php. Then use something like the code below:
Logged in users will see the link to the file, anonymous users will see the click to register link.
Right- yes I see how the php
Right- yes I see how the php works....that's great!
However, having thought carefully about how to format the page to the user I came up with this solution, using your if-else logic...
I created a page that is accessed from the menu option "downloads", that contains this code (and nothing else)...
Page downloads-reg contains the pdf descriptions and download links, whereas page downloads-anon contains the descriptions plus download links that point to the login/register. This magically seems to be working.
I have no clue as to whether this is a "good" solution or not, but it is what I had envisaged the user seeing.
Once again, very many thanks for taking the time to help. What seems obvious to those "in the know" can be an impossible problem to the rest of us!
Maybe this will help others, too.
In order to cut out that
In order to cut out that page, you could put that code (or similar) in a block that appears beside your content. That's one less click for your visitors to take.