Page 1 of 2

[SOLVED] View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 3:15 pm
by jtcreate
I'm running the latest version of CMSMS... fully up-to-date Red Hat and MySQL. All is running perfectly.

Here's what I'd like to do:
1) Public user visits a page on the site. Sees list of files in a table format:  Product Number, Product Name, PDF Download 1, PDF Download 2
2) User can see that there are downloadable files, but can't download them.

Then...
1) User gets username and password logs in to the page.
2) Once logged in, the registered user can see the same list, but now CAN download the PDFs.

Is this possible within the current structure? Or by using any of the modules? Any direction is highly appreciated. Let me know if you need further clarification. Thanks!

Jeff T.

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 3:54 pm
by Nullig
Yes, with the Frontend Users/Custom Content modules you could have:

{if $ccuser->loggedin()} 

table with download links

{else}

table without download links

{/if}

Nullig

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 7:01 pm
by jtcreate
Good idea. Thanks.

I would, however, have to have two full tables, correct? No way to have one set of data and just {else} {/if} the links?

I appreciate your help.

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 7:11 pm
by Nullig
You could have your table and put the links within {if} ...  {else} ...  {/if}, but, with a large table, you'd have a lot of them like:


{if $ccuser->loggedin()}
linked text
{else}
unlinked text
{/if}


Where are you pulling the table data from? or are you just hard coding it?

Nullig

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 7:16 pm
by jtcreate
That's the trick... I need to have it so my customer can edit/add as needed through the WYSIWYG interface (ideally).

Jeff T.

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 7:19 pm
by Nullig
Why not have them upload to a specific directory, then pull the info automatically using a UDT?

Nullig

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 7:31 pm
by jtcreate
That sounds great. Can you elaborate on the specifics? I'm assuming we'd need some PHP that examines the directory, pulls the filename, adds the else/ifs and then it gets 'printed' to the page.

This is a smidge beyond my PHP skills...

Thanks,
Jeff T.

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 7:54 pm
by Nullig
Something like this (untested)...

Assuming files names like ###-Product name.pdf in the directory /uploads/products/ - adjust according to your needs.

Create a UDT called "productfiles" (without the quotes) and use this code:

Code: Select all

global $gCms;

echo "<table>";
echo "<tr>";
echo "<th>Product Number</th>";
echo "<th>Product Name</th>";
echo "<th>Document</th>";
echo "</tr>";

$dir = "uploads/products/";
if (is_dir($dir)) {

   if ($dh = opendir($dir)) {

      if ($handle = opendir($dir)) {

         while (false !== ($file = readdir($handle))) {

            if ($file != "." && $file != "..") {

               $products = explode("-", $file);
               $products2 = explode(".", $products[1]);

               echo "<tr>";
               echo "<td>$products[0]</td>";
               echo "<td>$products2[0]</td>";

                  if ($params['linked']=='true') {

                     echo "<td><a href='$dir$file' target='_blank'>$file</a></td>";

                  } else {

                     echo "<td>$file</td>";

                  }

               echo "</tr>";

            }

         }

        closedir($handle);

      }

   }
	
}

echo "</table>";
Then use the tag like this:

Code: Select all

{if $ccuser->loggedin()}  

{productfiles linked='true'}

{else}

{productfiles linked='false'}

{/if}
Nullig

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 8:02 pm
by jtcreate
Nice. I'll be working on this later today and tomorrow and will report back as to how it went. Thank you very much.

Jeff T.

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 8:13 pm
by Nullig
Tested it myself and made a couple of changes. Recopy the code from the previous post. It will work better.

Nullig

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 8:18 pm
by jtcreate
Thanks again...

Jeff T.

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 8:22 pm
by Nullig
You could also add:

Code: Select all

if ($params['linked']=='false') {
   echo "<p>You must be logged in to download these documents.</p>";
}
to the end of the UDT.

Nullig

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 9:26 pm
by jtcreate
Nullig,

This works absolutely great! I can't thank you enough.

One final question... I wasn't clear on how to properly name the second PDF that would end up in the same line. When I add multiple files to the uploads/products folder, they show up on separate lines (which is good, if they're different products).

Thanks again. You've really saved the day.

Jeff T.

Re: View Page, No Download | View Page, Download

Posted: Wed Jul 09, 2008 11:20 pm
by Nullig
How do you name the files now?

In order to parse the filename to extract the info you want to add to the table, you need to have the product number, product name and an id or number to differentiate the two documents.

If you used a naming convention like ###-Product Name-#.pdf, the script could be easily modified to strip out the info and post it properly.

Nullig

Re: View Page, No Download | View Page, Download

Posted: Thu Jul 10, 2008 12:29 am
by jtcreate
The files will be adjusted to fit our naming scheme. So, ###-Product Name-A.pdf for one and ###-Product Name-B.pdf for the other would work great.

So, in the end the table would look like this:

Prod Number  |  Prod Name  |  Doc 1(A)  |  Doc 2(B)

Some may only have one or the other, but all will most likely have both. Would you be up for one last tweak to the script? I think we'd be all set after this. Again, thank you.

Jeff T.