[SOLVED] Selective default album view, based on Group [SOLVED] Selective default album view, based on Group
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

[SOLVED] Selective default album view, based on Group

Started by shaddy, August 13, 2004, 06:22:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

shaddy

I received help making the default view for making new albums Me Only
http://forum.coppermine-gallery.net/index.php?topic=8525.0
and I took away their option to change who the album can be viewed by.

I'd like to be a bit more selective now.  I want it to stay the same for the default Registered User, but I now have a group designated as "Friends".  I'd like their default album to be "Members of the 'Friends' Group".  If there's too much to it, I can, as admin, go in and do it manually ('cause that's kinda what I get for asking to have control over what group gets to see what), but I thought it would be nice to have it done automatically.  

I'm trying to maintain controll over what the groups get to see, and not allow them to overlap.  But made it difficult on myself in the process.  This would simplify things, and allow other friends to immediately see it, instead of waiting for me to change it.  Plus it would still keep them from setting it to "Everyone can see", and having embarrasing alcohol related pics shown to the world.

Thanks
Shaddy

shaddy

It seems like this might be the place to do it, but I don't know PHP so well.
in delete.php, I have

$query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos, visibility) VALUES ('$category', '" . addslashes($op['album_nm']) . "', 'NO',  '{$op['album_sort']}', '" . (FIRST_USER_CAT + USER_ID) . "')";

Would I be able to have something like

If user.group = Friend then
    $query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos, visibility) VALUES ('$category', '" . addslashes($op['album_nm']) . "', 'NO',  '{$op['album_sort']}', '" . (Something here Designating Friend Album) . "')";
    else
       $query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos, visibility) VALUES ('$category', '" . addslashes($op['album_nm']) . "', 'NO',  '{$op['album_sort']}', '" . (FIRST_USER_CAT + USER_ID) . "')";


I've been trying to puzzle it out, but to no avail.  Am I even in te right area?  I obviously don't know the right commands or variables to use, but i didn't want to spend more time piecing things together looking through the other files if I'm not even in the right place, and have it not do what I want anyway.  Any hints would be appreciated.  
Thanks.

shaddy

OK, I'm a tad closer, but it's still not working right...
I used PHPMyAdmin and figured out that my "Friends" group number is 5.  But I can't seem to find the variable where the group number is placed.  USER_GROUP always returns 0, so I think that's not the right thing to use (although it seems like it should be), I just don't know where to look to find the right one.


   if (USER_GROUP == 5) {
                   echo "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf($lang_delete_php['create_alb'], $op['album_nm']) . "</td></tr>\n";
                   $query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos, visibility) VALUES ('$category', '" . addslashes($op['album_nm']) . "', 'NO',  '{$op['album_sort']}', '" . (USER_GROUP) . "')";
                   db_query($query);
   break;
   } else {
                   echo "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf($lang_delete_php['create_alb'], $op['album_nm']) . "</td></tr>\n";
                   $query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos, visibility) VALUES ('$category', '" . addslashes($op['album_nm']) . "', 'NO',  '{$op['album_sort']}', '" . (FIRST_USER_CAT + USER_ID) . "')";
                   db_query($query);
   break;
   }


Any ideas on how I can get the users Group number?
Thanks

shaddy

I believe I did it.  

Kinda cool having a whole thread to myself.

Being a total newbie to PHP, my hack will be ugly.  I'd love to hear alternatives, or beautifications...

synopsis:
I wanted the default album view to be Owner Only for all groups except "Friends", for them, I want the default view to be Viewed By Friends Group Only...

Basically, in delete.php I changed from:
               case '1':
                   if (GALLERY_ADMIN_MODE) {
                       $category = (int)$HTTP_POST_VARS['cat'];
                   } else {
                       $category = FIRST_USER_CAT + USER_ID;
                   }
                   echo "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf($lang_delete_php['create_alb'], $op['album_nm']) . "</td></tr>\n";
                   $query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos) VALUES ('$category', '" . addslashes($op['album_nm']) . "', 'NO',  '{$op['album_sort']}')";
                   db_query($query);
                   break;


to be:
               case '1':
                   if (GALLERY_ADMIN_MODE) {
                       $category = (int)$HTTP_POST_VARS['cat'];
                   } else {
                       $category = FIRST_USER_CAT + USER_ID;
                   }
                   if (USER_GROUP == "Friends") {
                   $groupvariable = 5;
                   } else {
                   $groupvariable = FIRST_USER_CAT + USER_ID;
                   }
                   echo "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf($lang_delete_php['create_alb'], $op['album_nm']) . "</td></tr>\n";
                   $query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos, visibility) VALUES ('$category', '" . addslashes($op['album_nm']) . "', 'NO',  '{$op['album_sort']}', $groupvariable)";
                   db_query($query);
   break;


I hard-coded in Friends group '5' because that's the only group I'm conscerned with right now, all other groups are to be Album Viewed by Owner Only.  If you wanted all groups to post only to their respective groups by default, you could use some SQL to get their number...

$groupnametext = (USER_GROUP);
$query = "SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_name='$groupnametext'";
$result = db_query($query);
$grouparray = mysql_fetch_array($result);
$groupnameinteger = $grouparray['group_id'];


Running that code got me the group number (5 for my group Friends, 2 for Registered...).  substituting '$groupvariable' above with '$groupnameinteger', after running this section would get you the default view to be the corresponding groups.  Seems like an easy way to run a few seperate gallerys in one instance of coppermine , but you'd have to change it somwhere to have crossovers.

Sorry for taking up your space with all my Q's and replies, but I'm so new I just didn't have a clue where to start.

Newbie Side Note:
if you want to play around, make a test.php and in it put
<?php

define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');

echo 
"this will be displayd on screen"
?>



alter the echo line and put in whatever you want to test.  I copy-n-pasted from other php files looking for what code would work.  I had a helluva time figuring out how to see what was in a variable, so I used the echo statment a lot.  

Thanks for readin'
Shaddy

PS  make sure you select the entire text box and COPY when posting a message before hitting Preview or Post, if it took you a while to type, you may have timed out and you'll lose everything, and you'll have to start over. >:(

Joachim Müller

Glad you were able to solve this on your own.
Quotemake sure you select the entire text box and COPY when posting a message before hitting Preview or Post, if it took you a while to type, you may have timed out and you'll lose everything, and you'll have to start over
I'm sorry for this odd behaviour, it is caused by our webhost sourceforge using various servers, while the phpsession is from one server. If the server the session was created on is busy, authentification fails. SMF have promised to fix this issue with the next release. Sorry again.

GauGau

P.S. Now you're not the sole "owner" of the thread anymore  ;)

mayona

is the groupvariable the same as the group ID?

if (USER_GROUP == "Friends") {
                   $groupvariable = 5;

mayona

Alrighty, I think it's the same...