forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 permissions => Topic started by: colapaca on November 11, 2010, 06:30:08 pm

Title: limit one user album by category ?
Post by: colapaca on November 11, 2010, 06:30:08 pm
Hello,

I recently upgrade the CPG gallery from 1.4.18 to 1.5.8 after expecting since a long time the new administrative right possibilities.
I really appreciate now that it's possible for user to add their own gallery in existing category.

I would appreciate to limit one user album by category (I don't talk about limit the number of pictures). I suppose the code should be modified somewhere ?

Perhaps I'm wrong but I didn't find any discussion about this possibility.
Thanks for your listening and your help.
Title: Re: limit one user album by category ?
Post by: Αndré on November 11, 2010, 06:41:48 pm
Shall your users can create just 1 album per public category or in general?
Title: Re: limit one user album by category ?
Post by: colapaca on November 11, 2010, 10:04:18 pm
Yes, just 1 album per public category is my absolute organization priority (I would like to only have category by events and that's why one album by user is enough inside).

For the in general, not really sure about consequences. I didn't really think about it. is it about personal album?
Title: Re: limit one user album by category ?
Post by: Αndré on November 12, 2010, 11:42:47 am
We need to modify some core code and add a check that counts the albums. It was just a question, so I can generate the correct check for you.
Title: Re: limit one user album by category ?
Post by: colapaca on November 12, 2010, 09:51:06 pm
if you could take in count my request, it could be helpful and interesting.
One user album by category is fine.
Title: Re: limit one user album by category ?
Post by: klinkoo on November 14, 2010, 06:48:12 am
I am also interested in this option André! merci!
Title: Re: limit one user album by category ?
Post by: Αndré on November 19, 2010, 02:56:36 pm
Open delete.php, find
Code: [Select]
        if (!empty($get_album_name)) {
            //add the album to database
            $query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos, description, owner) VALUES ('$category', '$get_album_name', 'NO', '{$position}', '', '$user_id')";
            cpg_db_query($query);
   
            //get the aid of added the albums
            $getAid = mysql_insert_id($CONFIG['LINK_ID']);
   
            $dataArray = array(
                'message' => 'true',
                'newAid'  => $getAid,
            );
        } else {
            $dataArray = array(
                'message' => 'false',
                'title'  => $lang_errors['error'],
                'description' => $lang_albmgr_php['alb_need_name']
            );
        }
and replace with
Code: [Select]
        if (!GALLERY_ADMIN_MODE && $category < FIRST_USER_CAT && mysql_result(cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $category AND owner = ".USER_ID), 0) > 0) {
            $dataArray = array(
                'message' => 'false',
                'title'  => $lang_errors['error'],
                'description' => 'Only 1 album per public category'
            );
        } elseif (!empty($get_album_name)) {
            //add the album to database
            $query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos, description, owner) VALUES ('$category', '$get_album_name', 'NO', '{$position}', '', '$user_id')";
            cpg_db_query($query);

            //get the aid of added the albums
            $getAid = mysql_insert_id($CONFIG['LINK_ID']);

            $dataArray = array(
                'message' => 'true',
                'newAid'  => $getAid,
                'album_name' => $get_album_name,
            );
        } else {
            $dataArray = array(
                'message' => 'false',
                'title'  => $lang_errors['error'],
                'description' => $lang_albmgr_php['alb_need_name']
            );
        }
Title: Re: limit one user album by category ?
Post by: colapaca on November 21, 2010, 07:06:25 pm
Dear Andre,

thank you for this useful solution and your so quick reply. It's perfect!


A nice extension to stay in the same spirit, could be to assign automatically the name of the user to the album and grant directly some default permissions decided by the administrator. Should I need to open another post?
Title: Re: limit one user album by category ?
Post by: Αndré on November 21, 2010, 07:18:47 pm
Should I need to open another post?
Yes.
Title: Re: limit one user album by category ?
Post by: colapaca on January 28, 2014, 02:19:08 am
Dear André,

I think my new question concern this modification you made previous for one album creation by category but let me know if you want I open another topic.

When you select the option "create/sort album" under "my profil", you see the full list of albums and it's not usefull to select quickly the category when you have created an album. The result written on the left can only appear after you select one of the album:


You can't see it as well as it's in the option list for example:


Could you please help to have a request code to have the same useful display as the second picture ?

Many thanks.
Title: Re: limit one user album by category ?
Post by: colapaca on January 28, 2014, 02:20:32 am
Dear André,

I think my new question concern this modification you made previous for one album creation by category but let me know if you want I open another topic.

When you select the option "create/sort album" under "my profil", you see the full list of albums and it's not usefull to select quickly the category when you have created an album. The result written on the left can only appear after you select one of the album (alb1):

You can't see it as well as it's in the option list for example (alb2):

Could you please help to have a request code to have the same useful display as the second picture ?

Many thanks.
Title: Re: limit one user album by category ?
Post by: Αndré on January 28, 2014, 10:34:41 am
Please don't mix up the terms "category" and "album". Your screenshot "alb1" shows the album manager, where you need to select a category first. After you selected a category, you'll see the existing albums of that category, which you can move, delete, rename or create a new album.

I currently don't get why you want to adjust the drop-down box according to screenshot "alb2", as you'd select albums, which is not how the album manager is supposed to work. What exactly do you want to accomplish?
Title: Re: limit one user album by category ?
Post by: colapaca on January 28, 2014, 01:56:15 pm
Andre,

you are right I'm confusing both of them in my explaination.

I would really appreciate a to improve the "create/sort album" selection list (under "my profil") who could show directly if an album already exist in public category (and not to have to display the category one by one before the result display on the page)
That 's why I thought it could look like the "modify my albums" list : alb2.png (where the album already appear in the list).

Also to be in coherency with the delete.php you well modified for me long time ago (in order to force users to create only one just 1 album per public category), the *my album* should not appear to not allow them to create an album outside the fixed public category.

Let me know if you know how to modify the script as I would be very happy to improve this "limit one user album by category" case and share it with other interested people.

Title: Re: limit one user album by category ?
Post by: Αndré on January 28, 2014, 02:00:04 pm
Your goal is to have 1 album at maximum per user in each category, right? If so, I suggest to display just the categories where the user doesn't already created an album. If you agree, I'll try to create the mod.
Title: Re: limit one user album by category ?
Post by: colapaca on January 28, 2014, 02:20:03 pm
this is exactly that, as the case "sort album" isn't necessary with this goal.
And in addition, it will avoid the Error message display : "Only 1 album per public category".
Perfect! :)
Title: Re: limit one user album by category ?
Post by: Αndré on January 28, 2014, 02:53:40 pm
Open albmgr.php, find
Code: [Select]
                if ($check_group_rowset) {
                    $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name']);
                }
and replace with
Code: [Select]
                if ($check_group_rowset) {
                    if (mysql_result(cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$subcat['cid']} AND owner = ".USER_ID), 0) == 0) {
                        $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name']);
                    }
                }

Note: I used the code from 2010-11-19 as base. I just noticed that code checks for the overall number of albums. This means, if one user (or you, as admin) already created an album in a category, no other user can create an additional album. I assume this is not how it is supposed to work? If so, I'll update both database queries (i.e. add an additional check for the user ID).


*my album* should not appear to not allow them to create an album outside the fixed public category.
Disable personal gallery in the groups manager.
Title: Re: limit one user album by category ?
Post by: colapaca on January 29, 2014, 01:57:42 pm
you're right, this is not how it is supposed to work.
The logical is well that each user should be able to create one album in the category even if another user already create one in this category. It would be nice if you could update the script as you suggested.

Therefore, don't know if the modification you made in albmgr.php already work like that, but the interest is that the drop-down menu should display all the category where the user didn't already create an album.


Furthermore, "my album*" is not showed anymore (as excepted) after the setup change in the groups manager, thanks!
Title: Re: limit one user album by category ?
Post by: Αndré on January 29, 2014, 02:07:33 pm
I just updated both codes accordingly.
Title: Re: limit one user album by category ?
Post by: colapaca on January 31, 2014, 03:31:28 am
update done, working fine on the principle but just small issue:

When you validate the new album name typed on the boxfield, the name becomes finally "undefined".
Could it take the text typed - and/or - may be a better solution, assign directly the owner user name without having typing something ?

I also noticed 2 strange Menu behaviours :

1) With "create/sort my albums":
After creating an new album, even if you select another menu and came back on the "create/sort my albums" area, you still see the category with the new album jsute created. It's only cleared if you select another category in the drop list. Could it be arrange?

2) Same kind of display in the "main menu":
latence if you select the "Albums" menu directly it show you the same result as when you are arriving in the gallery or if you select "Home" (it shows all the categories). But, if you select "Albums", just after "My Gallery", it's staying blocked on the same "My Gallery" display.

Seems that I clearly abuse with all my review and requests... :)
Sorry for the time and the work I'm asking you to improve the gallery ergonomic experience.
Title: Re: limit one user album by category ?
Post by: Αndré on February 03, 2014, 11:32:53 am
When you validate the new album name typed on the boxfield, the name becomes finally "undefined".
I just updated the above code (for some reason the line "'album_name' => $get_album_name," got lost).


Could it take the text typed - and/or - may be a better solution, assign directly the owner user name without having typing something ?
We have 2 possibilities:
1. Pre-populate the album manager with the user name, so he just need to accept the default value. In this case, the user is able to change the album name.
2. Always force the user name as album name, regardless what the user enters. Keep in mind that it's still possible to change the album name at another form, so if you want to disable that option you need some more modification.

Which option do you prefer?


1) With "create/sort my albums":
After creating an new album, even if you select another menu and came back on the "create/sort my albums" area, you still see the category with the new album jsute created. It's only cleared if you select another category in the drop list. Could it be arrange?
Quick & dirty solution: open js/albmgr.js, find
Code: [Select]
if(data['message'] == 'true'){and below, add
Code: [Select]
window.location.replace('albmgr.php');

2) Same kind of display in the "main menu":
latence if you select the "Albums" menu directly it show you the same result as when you are arriving in the gallery or if you select "Home" (it shows all the categories). But, if you select "Albums", just after "My Gallery", it's staying blocked on the same "My Gallery" display.
That's intended behavior, but could of course be changed if you always want to go to your gallery root when selecting "Album list".
Title: Re: limit one user album by category ?
Post by: colapaca on February 03, 2014, 07:23:00 pm
We have 2 possibilities:
1. Pre-populate the album manager with the user name, so he just need to accept the default value. In this case, the user is able to change the album name.
2. Always force the user name as album name, regardless what the user enters. Keep in mind that it's still possible to change the album name at another form, so if you want to disable that option you need some more modification.
Which option do you prefer?

We could start with case the 2. - Always force the user name and keep the possibility of change later (if username is not user friendly or if they thought to enter first name or last as it's not mandatory). It still could try to hide the album name field by myself but I suppose it will hidde it for all users even admininstor.

Quote
Quick & dirty solution: open js/albmgr.js, find
Code: [Select]
if(data['message'] == 'true'){and below, add
Code: [Select]
window.location.replace('albmgr.php');

yes, it seems a little bit dirty because the created album still appears while the next available category is also listed and at this step this not possible to create a new album properly : error message as if it was second album creation. Going on anohter menu change nothing, the only way to clean it is to select another category available and coming back to the first available category that become then usable.
I would prefer waiting for your better refresh solution (display the next available category without the display of the previous created album below or going to new created album properties directly).


Quote
That's intended behavior, but could of course be changed if you always want to go to your gallery root when selecting "Album list".
yes, I admit I'm not very accustomed with this change of menu behavior (same menu could display 2 different windows depending the main menu previously you used before). Perhaps there is good reason but I admit I didn't think yet.

In fact, I'm also in trouble with the Main menu because I noticed when connected as Administrator, I have well the "upload" menu file but I can't find "create/sort album" because this option (under the "My profil" menu when as users) is not available. The "admin "My profil"" is inserted under the "users" admin menu).

That's why concerning the behaviour menu I also have prefering having the "create/sort album" menu and all other album manipulation menu directly placed under the main "Album" menu (as if it's possible). It then could work as administrator too, and cheery and the cake more clear for user to find where to manage album.

Thanks for hearing patiently all my suggestions as usual.
Title: Re: limit one user album by category ?
Post by: colapaca on February 03, 2014, 10:29:14 pm
yes, it seems a little bit dirty because the created album still appears while the next available category is also listed and at this step this not possible to create a new album properly : error message as if it was second album creation. Going on another menu change nothing, the only way to clean it is to select another category available and coming back to the first available category that become then usable.

edit 1 : those symptoms appear on "registred" profile but it works fine under "admin" profile!

Quote

In fact, I'm also in trouble with the Main menu because I noticed when connected as Administrator, I have well the "upload" menu file but I can't find "create/sort album" because this option (under the "My profil" menu when as users) is not available. The "admin "My profil"" is inserted under the "users" admin menu).

edit 2 : I finally found the "create/sort album" submenu but under "Files" Menu on admin profile.

Quote
That's why concerning the behaviour menu I also have prefering having the "create/sort album" menu and all other album manipulation menu directly placed under the main "Album" menu (as if it's possible). It then could work as administrator too, and cheery and the cake more clear for user to find where to manage album.
edit 3: still would prefer this Menu possibility for "registered" users but I suppose it should be under another discussion...

edit 4 : Under admin profil, even if I create an album, nothing appears under the "Album" main Menu. Not sure if it's a normal behaviour because result is nothing.

8 years after my first coppermine try, almost really near to put this type of gallery configuration in production with your assistance !!
Title: Re: limit one user album by category ?
Post by: Αndré on February 04, 2014, 10:44:04 am
Always force the user name

Open delete.php, find
Code: [Select]
$get_album_name = trim($superCage->get->getEscaped('name'));and replace with
Code: [Select]
$get_album_name = GALLERY_ADMIN_MODE ? trim($superCage->get->getEscaped('name')) : $USER_DATA['user_name'];

those symptoms appear on "registred" profile but it works fine under "admin" profile!

This also works for non-admins in my gallery.


Regarding your theme question, please start a new thread.
Title: Re: Re: limit one user album by category ?
Post by: colapaca on February 04, 2014, 01:07:52 pm
Open delete.php, find
Code: [Select]
$get_album_name = trim($superCage->get->getEscaped('name'));and replace with
Code: [Select]
$get_album_name = GALLERY_ADMIN_MODE ? trim($superCage->get->getEscaped('name')) : $USER_DATA['user_name'];

it works but the "regardless what the user enters" is confusing for users, could it be avoid with a direct validation on "OK" or "New album" button (with removing the entry field).

Quote
This also works for non-admins in my gallery.

Tried again the quick & dirty solution (js/albmgr.js) but unfortunately it's still not well working for me under "registred",

see pict: 2.jpg (as "registered" user the album staies on the screen),
see pict: 3.jpg (as "admin": there is well the reset of the screen and the dropdown list)

Is it may be a chmod problem ? (my web hosting doesn't accept 777)

Title: Re: Re: limit one user album by category ?
Post by: Αndré on February 04, 2014, 01:19:55 pm
could it be avoid with a direct validation on "OK" or "New album" button (with removing the entry field).

Open albmgr.php, find
Code: [Select]
    echo <<< EOT
                        <button type="button" id="delete_album" name="delete_album" class="button" value="{$lang_albmgr_php['delete_album']}" disabled="disabled" title="{$lang_albmgr_php['delete_album']}">{$icon_array['delete']}</button>
                        &nbsp;&nbsp;&nbsp;
                        <button type="button" id="modify_album" name="modify_album" class="button" value="{$lang_common['album_properties']}" disabled="disabled">{$icon_array['modifyalb']}{$lang_common['album_properties']}</button>
                        <button type="button" id="editfiles_album" name="editfiles_album" class="button" value="{$lang_common['edit_files']}" disabled="disabled">{$icon_array['edit_files']}{$lang_common['edit_files']}</button>
                        <button type="button" id="thumbnail_album" name="thumbnail_album" class="button" value="{$lang_common['thumbnail_view']}" disabled="disabled">{$icon_array['thumbnail']}{$lang_common['thumbnail_view']}</button>
                        &nbsp;&nbsp;&nbsp;
                        <button type="button" id="add_new_album" name="add_new_album" class="button" value="{$lang_albmgr_php['new_album']}">{$icon_array['new']}{$lang_albmgr_php['new_album']}</button>
                        <img id="loading" class="icon" src="{$prefix}images/loader.gif" style="margin-left: 10px; display: none;" alt="" />
                        <input type="text" id="add-name" name="add-name" size="27" maxlength="255" class="textinput" value="" onkeypress="return Sort.disableEnterKey(event)" style="display: none;" />
and replace with
Code: [Select]
    if (GALLERY_ADMIN_MODE) {
        $add_name = '<input type="text" id="add-name" name="add-name" size="27" maxlength="255" class="textinput" value="" onkeypress="return Sort.disableEnterKey(event)" style="display: none;" />';
    } else {
        $add_name = '<input type="hidden" id="add-name" name="add-name" value="user name"/>';
    }
    echo <<< EOT
                        <button type="button" id="delete_album" name="delete_album" class="button" value="{$lang_albmgr_php['delete_album']}" disabled="disabled" title="{$lang_albmgr_php['delete_album']}">{$icon_array['delete']}</button>
                        &nbsp;&nbsp;&nbsp;
                        <button type="button" id="modify_album" name="modify_album" class="button" value="{$lang_common['album_properties']}" disabled="disabled">{$icon_array['modifyalb']}{$lang_common['album_properties']}</button>
                        <button type="button" id="editfiles_album" name="editfiles_album" class="button" value="{$lang_common['edit_files']}" disabled="disabled">{$icon_array['edit_files']}{$lang_common['edit_files']}</button>
                        <button type="button" id="thumbnail_album" name="thumbnail_album" class="button" value="{$lang_common['thumbnail_view']}" disabled="disabled">{$icon_array['thumbnail']}{$lang_common['thumbnail_view']}</button>
                        &nbsp;&nbsp;&nbsp;
                        <button type="button" id="add_new_album" name="add_new_album" class="button" value="{$lang_albmgr_php['new_album']}">{$icon_array['new']}{$lang_albmgr_php['new_album']}</button>
                        <img id="loading" class="icon" src="{$prefix}images/loader.gif" style="margin-left: 10px; display: none;" alt="" />
                        $add_name


Is it may be a chmod problem ?
No.
Title: Re: limit one user album by category ?
Post by: colapaca on February 04, 2014, 01:50:21 pm
modification done: "Ok" & "Cancel" well appeared after clicking on "New album" but nothing happen at all on "OK" confirmation.

Could I cry help and request more investigation on my Gallery for the dropdown list refresh not working "Registred" and this direct validation ? (both are important for the "limit one user album by category" request).

thanks
Title: Re: limit one user album by category ?
Post by: Αndré on February 04, 2014, 01:59:31 pm
nothing happen at all on "OK" confirmation
Above code updated.


Could I cry help and request more investigation on my Gallery for the dropdown list refresh not working "Registred" and this direct validation ?
One thing at a time, please.
Title: Re: Re: limit one user album by category ?
Post by: colapaca on February 04, 2014, 02:47:05 pm
Above code updated.
works very well now, thanks.

Quote
One thing at a time, please.
ok, I'm waiting your suggestion... (just see below detailed symptoms for a better understanding)

1a.jpg : when connected as "registred", we arrive by default, with dropdown list already on the first available category where seems remain a user album (but not existing for real).
2a.jpg : when connected as "admin", by default you have the category dropdown list well waiting on *No category* and without the phantom "user" album.
Title: Re: Re: limit one user album by category ?
Post by: Αndré on February 04, 2014, 03:49:22 pm
1a.jpg : when connected as "registred", we arrive by default, with dropdown list already on the first available category where seems remain a user album (but not existing for real).

This is different from what I understood earlier today/yesterday. I thought the current issue is, that the page isn't refreshing after creating a new album, to update the available category list. Now you just told me something totally different. Does the first issue exist at all? Is it somehow related?
Title: Re: limit one user album by category ?
Post by: colapaca on February 04, 2014, 04:33:57 pm
Previously I tried to described what's happening when you are creating a album. But as you told me it was working on your side I tried to give description of it. In the last remark, I just added something I noticed today and who could help the resolution. But it concerns the same problem and there is no change about the issue: reset dropdown ( and then consequently album creation) works well under admin but not very well under registered user.
Let me know If more details are needed.
Title: Re: limit one user album by category ?
Post by: Αndré on February 04, 2014, 04:40:40 pm
Please post a link to your gallery and a test user account (no admin account!) which can create albums in public categories, to exclude client side issues. I just applied all changes of this thread to an unmodified gallery and it still works for me for non-admin users.
Title: Re: Re: limit one user album by category ?
Post by: colapaca on February 04, 2014, 05:09:15 pm
Please post a link to your gallery and a test user account (no admin account!) which can create albums in public categories, to exclude client side issues. I just applied all changes of this thread to an unmodified gallery and it still works for me for non-admin users.
http://lesgolden.free.fr/gallery
user : test333
pwd : test333
Title: Re: limit one user album by category ?
Post by: Αndré on February 04, 2014, 05:12:49 pm
The redirect works as expected, solely the category "1er étoile de la Paix (Juin 1983)" isn't hidden for some reason. I'll have a look at it tomorrow.
Title: Re: limit one user album by category ?
Post by: colapaca on February 04, 2014, 05:23:39 pm
ok, thanks
Title: Re: limit one user album by category ?
Post by: Αndré on February 05, 2014, 05:01:15 pm
Today I got what happens (I think you already tried to explain that ;)). The category "1er étoile de la Paix (Juin 1983)" (which was the topmost category when I tested yesterday) actually had no album, but Coppermine displayed that it had one. After switching to another category and back, it was empty, as expected.

The "good" news, this now also happens in my testbed. The bad news, I haven't found out yet why. I already tried to add some random parameter, as I thought it's some weird caching issue, but this didn't help. I'll perform some other tests as soon as possible.
Title: Re: limit one user album by category ?
Post by: colapaca on February 11, 2014, 02:06:52 pm
ok :) it's clear for everybody now ;)

hope that would be possible to fix this issue in user mode.
Title: Re: limit one user album by category ?
Post by: Αndré on February 11, 2014, 04:05:11 pm
This should fix the issue.

Open albmgr.php, find
Code: [Select]
            $result = cpg_db_query("SELECT cm.cid FROM {$CONFIG['TABLE_CATMAP']} AS cm INNER JOIN {$CONFIG['TABLE_CATEGORIES']} AS c ON cm.cid = c.cid WHERE cm.group_id in (" .  implode(",", $USER_DATA['groups']). ") ORDER BY pos LIMIT 1");
            $cat = mysql_result($result, 0);
            mysql_free_result($result);
and replace with
Code: [Select]
            $result = cpg_db_query("SELECT cm.cid FROM {$CONFIG['TABLE_CATMAP']} AS cm INNER JOIN {$CONFIG['TABLE_CATEGORIES']} AS c ON cm.cid = c.cid WHERE cm.group_id in (" .  implode(",", $USER_DATA['groups']). ") AND c.cid NOT IN (SELECT category FROM {$CONFIG['TABLE_ALBUMS']} WHERE owner = ".USER_ID.") ORDER BY pos LIMIT 1");
            $cat = mysql_result($result, 0);
            mysql_free_result($result);
            if (!$cat) {
                cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
            }
Title: Re: limit one user album by category ?
Post by: colapaca on February 14, 2014, 02:07:02 pm
so easy for you.... works fine. thanks !!!

with all the modification we made, is it still possible to allow the "Allow unlogged users (guest or anonymous) access"   Yes: thumbnail only.  I can only see category title visible but nothing inside.
Title: Re: limit one user album by category ?
Post by: Αndré on February 14, 2014, 03:16:34 pm
I don't see a reason why that shouldn't work. It also works in my test gallery where I've still applied the modifications. It seems that you've currently set your gallery to disable guest access completely.
Title: Re: limit one user album by category ?
Post by: colapaca on February 14, 2014, 04:31:31 pm
you're right!!! I forget to set up album permission correctly :)