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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post 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.
Last edited by jtcreate on Fri Jul 11, 2008 11:12 am, edited 1 time in total.
Mmmmm... Tasty.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

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

Post 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
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post 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.
Mmmmm... Tasty.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

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

Post 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
Last edited by Nullig on Wed Jul 09, 2008 7:14 pm, edited 1 time in total.
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post 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.
Mmmmm... Tasty.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

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

Post by Nullig »

Why not have them upload to a specific directory, then pull the info automatically using a UDT?

Nullig
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post 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.
Mmmmm... Tasty.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

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

Post 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
Last edited by Nullig on Wed Jul 09, 2008 8:12 pm, edited 1 time in total.
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post 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.
Mmmmm... Tasty.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

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

Post by Nullig »

Tested it myself and made a couple of changes. Recopy the code from the previous post. It will work better.

Nullig
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post by jtcreate »

Thanks again...

Jeff T.
Mmmmm... Tasty.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

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

Post 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
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post 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.
Mmmmm... Tasty.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

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

Post 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
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post 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.
Mmmmm... Tasty.
Post Reply

Return to “CMSMS Core”