Invalid argument supplied for foreach()

Posts: 18
Joined: 02/29/2008
Bug Finder

I have Ubercart RC2 installed, and just made a purchase for a download, using a coupon (and the 0 checkout module). Everything went fine until I tried to download the product. When I download the product, it shows up in my file downloads area, but has 2 error messages above it:

warning: Invalid argument supplied for foreach() in /home2/username/public_html/mysite/includes/common.inc on line 744.
warning: strtr() [function.strtr]: The second argument is not an array. in /home2/username/public_html/mysite/includes/common.inc on line 759.

In addition to that, when I click to download the file, I get this message:

Access denied
You are not authorized to access this page.

Any ideas what's going wrong?

Thanks,
Jacob

Posts: 1314
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Not sure about the first issue yet, I haven't noticed anything on my end.

Regarding the authorization, make sure you do have Permissions enabled to download files in your admin/user/access settings.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 18
Joined: 02/29/2008
Bug Finder

That fixed half of it! But I still got the error message. Any other ideas?

Thanks,
Jacob

Posts: 1314
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

The two bits of code the error mentions are part of the function t().

I think the only thing required for t() is the $string being translated. Is that not the case? The other place I see t() being used is for the header 'File downloads' as well as the breadcrumb

I'd like to see a screenshot of your File Downloads area..

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

This is puzzling... there are several places in the module where t() strings need to be cleaned up, but I can't find an illegitimate one for this screen. The closest I could come was changing a t('') to just be '' on line 826. See if that affects anything... Puzzled

Posts: 18
Joined: 02/29/2008
Bug Finder

I've posted a screenshot here:
http://accelerhosting.com/images/error.jpg

Ryan, which file should I make that change in? I would assume not in the common.inc file, but it some part of the ubercart module?

Thank you guys for helping! Smiling

-Jacob

Posts: 18
Joined: 02/29/2008
Bug Finder

I think I found where you were talking about in the uc_file.module, and made the change. It didn't have any effect on the error message though. I refreshed that page and the error msg is still there.

Posts: 1314
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Yeah and the weird thing is that I don't get this error on our live installation. What version of PHP are you running? Not that I think that'd even make a difference...

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

This line is kind of... gross. I'm going to break it up into separate if statements, but in the meantime change line 880 that starts with the $file_link to the one below:

<?php
    $file_link
= (!$expiration) ? l(basename($file->filename), 'download/'. $file->fid .'/'. $file->key, $onclick) : ((time() > $expiration) ? basename($file->filename) : l(basename($file->filename), 'download/'. $file->fid .'/'. $file->key, $onclick) .' ('. t('expires on @date', array('@date' => format_date($expiration, 'custom', 'm/d/Y'))) .')');
?>

There was apparently a misplaced parenthesis on the end there.

I believe this will solve it.

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

N/M - try replacing the entire line with the following to make sure it works:

<?php
   
if (!$expiration) {
     
$file_link = l(basename($file->filename), 'download/'. $file->fid .'/'. $file->key, $onclick);
    }
    else {
      if (
time() > $expiration) {
       
$file_link = basename($file->filename);
      }
      else {
       
$file_link = l(basename($file->filename), 'download/'. $file->fid .'/'. $file->key, $onclick) .' ('. t('expires on @date', array('@date' => format_date($expiration, 'custom', 'm/d/Y'))) .')';
      }
    }
?>

Posts: 18
Joined: 02/29/2008
Bug Finder

Sweet!! That worked. You guys rock!

It was actually line 879 for me though.

Thanks very much!!! Smiling

-Jacob

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Excellent. Well, I've committed this and some other string fixes to the core. It'll be solved as of revision 1027 and the RC3 onward. Smiling

... and you earned your badge. Eye-wink

Posts: 10
Joined: 03/12/2008

Hey ryan...whch file should i make those changes to?

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

uc_file.module