How do I hide only a download link CCK Field of an article for Anonymous users - Am I overkilling?
My challenge:
Someone want to just have small db page imported into a super graphics designed site by means of an iframe.
My job is to do the DB page of this list of descriptions of a lectures/speaches and after such a viewer made a ( money /time or other commitment), can have access to the download link. (manual switching by using Drupal's -Visitors can create accounts but administrator approval is required. functions at user registration) Admin login for uploaders over the web so I though Drupal can do the job easily
My first attempt was to
use the user registration switch for the Anonymous/authenticated. (manual switching by using Drupals -Visitors can create accounts but administrator approval is required. functions at user registration)
All went well with the views having a few CCk fields and one of them was the download link.
The first view for Anonymous users was link-less and do not have that download field in it . The a second view do have it in for Authenticated users . I try to use the panel module to auto detect the logged in/out to display the right view. However to my surprise I found that panels 6.2x. dev do not have a permission for anonymous users as a role (compared to the other roles), so I could not switch between them (Even if views have that distinction)
My second attempt was to use the CCK field Privacy mod. However the closest manual switch was to have a buddy (yes /no) switch enabled to display the link on that download link field. I install friendlist, buddy ipa etc etc, and after all this realise there is not a manual way of switching between buddy yes no without sending reciprocal emails etc.. so this is not practical.
My third option after scratching my head was to go back to the first solution but now to use the frontpage module to determine which panel page is going to be displayed for anonymous/authenticated user
This to me seems that I am busy with over-killing.
I someone do not have an easier solution I will try it but is there some wisdom and experience that someone can share to make this simpler?
(I am not a php fundi and stay out of code, sorry)

Take this as one newb trying
Take this as one newb trying to help another. This may work it may not. I would use the Views Custom Field module to insert a php field into the view. The following code should do what you want and allow you to display the same view for authenticated and anonymous users. The only difference will be the display of the link for authenticated users only.
<?php
if ($user->uid > 0) {
$link = field_file_load($data->node_data_field_name_field_name_fid);
print $link['Array_Item'];
}
?>
For the code above to work correctly you must have your URL field included in the view. To prevent it from displaying simply hide it in the view settings for that field. The code above will handle the display of the field.
In the code above you will need to replace node_data_field_name_field_name_fid with the appropriate entry for your field. To find this, put the line below in the php custom field. When you click update it should show you some information where the field appears in the view. Note the one that ends with _fid and copy it into the code above.
<?php print_r($data) ?>You will also need to replace Array_Item with the item that contains your link. To find this, put the line below into the field. Be sure to replace node_data_field_name_field_name_fid with the value you found above. Note which item contains your link and copy it into the code at the top.
<?php
$link = field_file_load($data->node_data_field_name_field_name_fid);
print_r($link) ?>
I hope this was clear enough. I'm just trying to give back and help out with something I have learned.
tms8707056 firstly thanks
tms8707056 firstly thanks for your time and help.
Having a closer look at what you suggesting convinced me that it can work.
However my PHP learning curve are VERY steep at the moment and I need a bit of grace to move more slowly.
From your first code sniped I am not so sure if the fid should be a number or a fieldname- description. My interpretation is that it should be a fieldname description., and to get it was easy per your instructions.
<?php
if ($user->uid > 0) {
$link = field_file_load($data->node_data_field_camp_field_audio_file_url);
print $link['Array_Item'];
}
?>
However the Array_Item (in Red) got me.
If I put your code in the value of the download field (your code instead of http://www.. . .. ) then it do not want to take it. even if I use it on another field it does not print something.
If I put your code in the custom field then I got an error like : An error occurred at /admin/build/views/ajax/preview/Lectures.
If I use the first value both places (node_data_field_camp_field_audio_file_url ) then nothing is displayed, so somehow I am doing something stupid because my knowledge of PHP is more than dangerous.
below the printed values in the field and below that the query form the views.
Values in custom field
stdClass Object ( [nid] => 1 [node_title] => Hoor God se stem [node_data_field_camp_field_camp_value] => Mannekamp [node_data_field_camp_nid] => 1 [node_type] => lecture [node_data_field_camp_field_speaker_value] => Nev Nuwe test Spreker [node_data_field_camp_field_date_value] => Des 2009 [node_revisions_teaser] => Soek die Here se hartklop met 'n Nou verbintenis met Hom [node_revisions_format] => 1 [node_data_field_camp_field_audio_file_url] => http://www..... [node_data_field_camp_field_audio_file_title] => Hoor God se stem [node_data_field_camp_field_audio_file_attributes] => N; )
and then the query values s displayed ion the views module
SELECT node.nid AS nid,
node.title AS node_title,
node_data_field_camp.field_camp_value AS node_data_field_camp_field_camp_value,
node_data_field_camp.nid AS node_data_field_camp_nid,
node.type AS node_type,
node_data_field_camp.field_speaker_value AS node_data_field_camp_field_speaker_value,
node_data_field_camp.field_date_value AS node_data_field_camp_field_date_value,
node_revisions.teaser AS node_revisions_teaser,
node_revisions.format AS node_revisions_format,
node_data_field_camp.field_audio_file_url AS node_data_field_camp_field_audio_file_url,
node_data_field_camp.field_audio_file_title AS node_data_field_camp_field_audio_file_title,
node_data_field_camp.field_audio_file_attributes AS node_data_field_camp_field_audio_file_attributes
FROM DP6_node node
LEFT JOIN DP6_content_type_lecture node_data_field_camp ON node.vid = node_data_field_camp.vid
LEFT JOIN DP6_node_revisions node_revisions ON node.vid = node_revisions.vid
WHERE (node.type in ('lecture')) AND (node.status <> 0)
ORDER BY node_data_field_camp_field_speaker_value ASC
out of the above codes, hopefully someone can help me to determine the value of ['Array_Item']; which is my problem it seems to me at the moment.
Thanks again to tms8707056 for trying to help me out! (Must say if this is the level of newbie's then I am a green-be)
Looking back at what you are
Looking back at what you are trying to do, I made it more difficult than it should be. According to the data that is displaying in your custom field, it looks like you have the URL field added to the view. You should simply set that field to be hidden and insert the code below into the custom PHP field.
<?php
if ($user->uid > 0) {
print $data->node_data_field_camp_field_audio_file_url;
}
?>
Sorry to make it more difficult than it should have been. I was giving more instructions than were necessary. let me know if that works.
tms8707056 thanks for this
tms8707056 thanks for this input above:
Just some feedback to you and something that can be usefull for other users:
At the end I used your suggestions of the custom field but in my research I find that there is a much simpler method.
The CCK module in DP6 comes standard with the Content Permissions module that can be activated. Well this gave one the option to display your custom CCK fields to certain roles or not, which was what I was looking for in the beginning but were not too familiar with DP6 yet.
I have used the this easy method but also after much research into the custom field module which gave me the further option to not just display (or not) a custom CCK field but further but then to display different instruction mesges to the different role added to the custom fields etc.
So I decided to use both methods and include the code below to be of use to someone else.. Enjoy the code and all the hard work and tips of this wonderful community:
The final code that I used at the end :replace [ with < for original coode- used to display all here
<?phpglobal $user;
if ($user->uid): {
?>
[a href="http://www.example. . . ..net/node/4"> Click here for more info on further downloading [/a>
<?php}
else: {
?>
[a href="http://www.example. . . ..net/node/5"> Click here for more info on downloading [/a>
<?php
}
endif;
?>