Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: editPics.php - adding another "ALL" button - Paypal hack add-on  (Read 8085 times)

0 Members and 1 Guest are viewing this topic.

wprowe

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • Music, Travel, Outdoor, Nature and Wildlife Photography
editPics.php - adding another "ALL" button - Paypal hack add-on
« on: January 31, 2006, 03:52:07 pm »

In editPics.php, there are some "ALL" buttons at the top of the page that let you reset ALL counters, delete ALL pictures, etc. I have a new column I have added to my pictures table called "forsale", and some code I added that will or will not display a paypal shopping cart based on the value of this field. I did the appropriate changes in editOnePic.php and editPics.php to support turning this field on or off in the pictures table. In editPics.php in the line under the description for each picture where you can check the delete box, I added another checkbox called "forsale" that I use to toggle this field in the picture table, and I added the appropriate code in the form processing function to read this field's value from the form and set the database field appropriately. All of this works perfectly.

What I would like to add is another "ALL" button that lets me turn this checkbox on or off for the entire page of pictures similar to turning on or off the reset all counters checkbox. It would appear to be a simple thing to add another button at the top of the page by copying the code for "deleteAll", and changing the names appropriately for my field name "forsale", and adding another line to the language file(s) that provide the text for the button. So I gave it a try.

Here is the code for the deleteAll button as it comes with CPG. As you can see, it depends on a javascript function selectAll().

Code: [Select]
<td width="20%" align="center">
  <span class="admin_menu">
    <input type="checkbox" name="deleteAll" onclick="selectAll(this,'delete');" class="checkbox" id="deleteAll" />
    <label for="deleteAll" class="clickable_option">{$lang_editpics_php['del_all']}</label>
  </span>
</td>

Here is function selectAll() that also comes with CPG:

Code: [Select]
function selectAll(d,box) {
  var f = document.editForm;
  for (i = 0; i < f.length; i  ) {
    if (f[i].type == "checkbox" && f[i].name.indexOf(box) >= 0) {
      if (d.checked) {
        f[i].checked = true;
      } else {
        f[i].checked = false;
      }
    }
  }
}

So I copied/pasted the deleteAll HTML and made appropriate changes to implement similar functionality for my forsale field. Here is what I did:

Code: [Select]
<td width="20%" align="center">
  <span class="admin_menu">
    <input type="checkbox" name="forsaleAll" onclick="selectAll(this,'forsale');" class="checkbox" id="forsaleAll" />
    <label for="forsaleAll" class="clickable_option">{$lang_editpics_php['forsale_all']}</label>
  </span>
</td>

I put this onto my site and ran it. On screen, it appeared to correctly check and uncheck all my forsale checkboxes for each image on the page. However, when I submitted the form, it somehow performed the delete function instead.

Did I make a typo that I can't see? Did I make a wrong assumption about how easy this should be? Do I need to make updates elsewhere that I missed? This seems like an easy enough thing to do. If I check / uncheck my individual "forsale" checkboxes, they work perfectly when the form is submitted. When I click my "forsaleAll" checkbox, all of the forsale checkboxes on the screen change as I would expect. However, when the form is submitted, they somehow perform the delete function instead.

I have attached my complete editPics.php file so folks can see my complete mods if they need to. I would appreciate any help you can provide.

Thanks!
« Last Edit: February 01, 2006, 07:15:53 am by GauGau »
Logged
Walter Rowe
Music, Travel, Outdoor, Nature and Wildlife Photography

Blueiris

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Female
  • Posts: 170
  • Horse poor!
    • Saddlebred World Gallery
Re: editPics.php - adding another "ALL" button
« Reply #1 on: January 31, 2006, 06:58:37 pm »

Unfortunately I don't have enough time right now to go into your problem further. Hopefully by the time I get back to this someone else will have given you more in-depth help.

However, I think you are standing one step too high on the staircase! Your problem isn't with selectAll() - that's working as it's supposed to. In one sense, you have successfully added another "ALL" button that selects all of the "forsale" checkboxes. But the individual "forsale" checkboxes do nothing at this point.

I suggest you go back a few steps and work with just changing one image. Rather than using your new "ALL" button, use the checkbox for a single image, and analyze why that checkbox isn't working. Once you get it working for one, it will work for all when you use your new button.
Logged
You can lead a horse to water, but you can't make him drink - he's got to discover that it's wet for himself.

wprowe

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • Music, Travel, Outdoor, Nature and Wildlife Photography
Re: editPics.php - adding another "ALL" button
« Reply #2 on: January 31, 2006, 07:45:35 pm »

Blueiris,

Thanks for taking a look.

The logic for implementing the individual "forsale" checkboxes in editPics.php is already there and works perfectly. I have had that working since 1.4.2 was released. All I am trying to do now is add the "forsaleAll" button to make it faster for me to toggle this checkbox for a whole page of pictures at once.

My mods for the individual "forsale" checkboxes are in the form_options() and the process_post_data() functions. If I check or uncheck the individual "forsale" checkboxes via editPics, they work perfectly. What doesn't work is my "forsaleALL" button. For some reason, it checks and unchecks the individual boxes on the screen, but when I submit the form it does a delete instead of setting the forsale column in my pictures table. Its like something isn't being processed right in process_post_data() - or it isn't getting there correctly.

I'm sure I have missed something significant but small, I just can't seem to find it. I thought it should follow simply and straight forward from the deleteAll and resetAll button code since both of those utilize the same javascript function selectAll() to toggle their checkboxes.

If I sound defensive, I don't mean to. I appreciate your time and assistance very much. My PayPal mods are available for free on my web site should anyone care to see them or use them. All I am trying to do now is add the "forsaleAll" button at the top of the page. Like I said, the individual forsale checkboxes already work.
Logged
Walter Rowe
Music, Travel, Outdoor, Nature and Wildlife Photography

Blueiris

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Female
  • Posts: 170
  • Horse poor!
    • Saddlebred World Gallery
Re: editPics.php - adding another "ALL" button
« Reply #3 on: January 31, 2006, 11:46:56 pm »

Ah! OK, now I have a better understanding, and a better idea of what to look at. Caught this post just as I got back, went to your site to get the mod so I could work on this in my test install. Then had to tear myself away from the site or I'd have been browsing the gallery for hours . . . . Nice photos, nice job.

I'm sure I have missed something significant but small, I just can't seem to find it. I thought it should follow simply and straight forward from the deleteAll and resetAll button code since both of those utilize the same javascript function selectAll() to toggle their checkboxes.

If I sound defensive, I don't mean to.

Defensive, no, frustrated, yes! Those darn small but significant things that seem to hide from your eye can cause a boatload of frustration. Been there, done that, got the bruises and the dents in the monitor case to prove it.

Free now for the evening, so let me see if another pair of eyes can help spot this.
Logged
You can lead a horse to water, but you can't make him drink - he's got to discover that it's wet for himself.

wprowe

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • Music, Travel, Outdoor, Nature and Wildlife Photography
Re: editPics.php - adding another "ALL" button
« Reply #4 on: February 01, 2006, 01:21:18 am »

Thanks much. I look forward to hearing back when you've had a chance to look at it some more.
Logged
Walter Rowe
Music, Travel, Outdoor, Nature and Wildlife Photography

Blueiris

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Female
  • Posts: 170
  • Horse poor!
    • Saddlebred World Gallery
Re: editPics.php - adding another "ALL" button
« Reply #5 on: February 01, 2006, 06:43:24 am »

Well, this is a strange one! I can't duplicate what you described. In fact, in my test install, it's working just as it should. Nothing is being deleted, the change is properly made in the database for all the files in the album being edited, and the shopping cart appears or doesn't appear on all the files in the album.  I've tried everything I can think of to make it break, and it stands up.

My test install is a vanilla cpg142, with no other mods. I simply downloaded Coppermine_PayPal_Files_142.zip from your site and installed it and verified that it was working correctly, then I switched to the file you attached to your first post.

The only quirk I see, and it is one that is to be expected, is that if all or some of the "Show shopping cart" checkboxes are checked in an album, you have to first check, and then uncheck the new "ALL" button in order for the individual checkboxes on each file to be unchecked.

Soooo, it does work. The trick will be to figure out why it isn't working on your install. Do you have other mods that might be conflicting with this one? Any changes to any of the other files? I confess I'm at a loss to understand why it's deleting the files on your install.



 
Logged
You can lead a horse to water, but you can't make him drink - he's got to discover that it's wet for himself.

wprowe

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • Music, Travel, Outdoor, Nature and Wildlife Photography
Re: editPics.php - adding another "ALL" button - Paypal hack add-on
« Reply #6 on: February 01, 2006, 11:43:44 am »

Thanks Blueiris. I will have to test it again.
« Last Edit: February 01, 2006, 07:52:38 pm by wprowe »
Logged
Walter Rowe
Music, Travel, Outdoor, Nature and Wildlife Photography

wprowe

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • Music, Travel, Outdoor, Nature and Wildlife Photography
Re: editPics.php - adding another "ALL" button - Paypal hack add-on
« Reply #7 on: February 01, 2006, 07:53:13 pm »

Aha! Got it narrowed down now. I think I was trying to do something that wasn't anticipated by Coppermine. Here are my test cases and results.

1) Works: admin logs in, admin creates an album, admin adds pictures, admin uses any of the ALL buttons.
2) Works: user logs in, user creates an album, user adds pictures, user uses any of the ALL buttons.
3) Works: user logs in, user creates an album, user adds pictures, admin uses any of the ALL buttons.
4) Works: user logs in, user creates an album, admin adds pictures, user uses any of the ALL buttons.

5) Breaks: user logs in, user creates an album, admin adds pictures, admin uses any of the ALL buttons.

Admin adding AND changing the pictures to someone else's album seems to be the key here.

After clicking submit, the pages returns with "No images to display".

OHH!!! I just noticed what is happening!!!

In the scenario where it breaks, when you first enter the "Edit Files" screen, the album associated with the pictures doesn't show the correct album. So when you click submit, they get moved to a different album. Why does it do that? Does Coppermine restrict pictures to albums that the user owns? Including admin?

After this happens, there is no way to put the pictures back into the album that admin had initially added them to - even as admin.

Hmm. Interesting.
Logged
Walter Rowe
Music, Travel, Outdoor, Nature and Wildlife Photography

Blueiris

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Female
  • Posts: 170
  • Horse poor!
    • Saddlebred World Gallery
Re: editPics.php - adding another "ALL" button - Paypal hack add-on
« Reply #8 on: February 02, 2006, 05:14:00 am »

In the scenario where it breaks, when you first enter the "Edit Files" screen, the album associated with the pictures doesn't show the correct album. So when you click submit, they get moved to a different album. Why does it do that? Does Coppermine restrict pictures to albums that the user owns? Including admin?

After this happens, there is no way to put the pictures back into the album that admin had initially added them to - even as admin.

OK, NOW I understand! This isn't limited to just your mod, and you might have uncovered a small bug here. In both cpg142 and cpg143, when the admin batch adds files, the user albums appear in the drop down menu and admin can batch add files to those user albums. (If admin uses "file upload," the files uploaded cannot be added to user albums.)

In both versions, if admin goes to "Edit Files" on a user album after batch adding files to that album, only the albums that admin created appear in the individual album menus on each file. At that point, anything you do as admin will re-assign all of the images in that album. If you so much as check "Reset view counter" on one file, all are gone and reassigned as soon as you hit the Apply modifications button.

The only answer for you at this point is probably to avoid using batch add to upload files to user albums.

I'll bring this up on the cpg143 bug forum.



Logged
You can lead a horse to water, but you can't make him drink - he's got to discover that it's wet for himself.

Blueiris

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Female
  • Posts: 170
  • Horse poor!
    • Saddlebred World Gallery
Re: editPics.php - adding another "ALL" button - Paypal hack add-on
« Reply #9 on: February 02, 2006, 06:30:19 pm »

Brought this up on the bug board, and one of the dev team promptly provided the fix. See http://forum.coppermine-gallery.net/index.php?topic=27325.0 for the code changes needed.

I've tested the changes in cpg143 and in cpg142 with your mod installed, and now it works perfectly.
Logged
You can lead a horse to water, but you can't make him drink - he's got to discover that it's wet for himself.
Pages: [1]   Go Up
 

Page created in 0.024 seconds with 20 queries.