forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Permissions => Topic started by: vortac on October 03, 2006, 03:56:56 am

Title: Mod: User Categories
Post by: vortac on October 03, 2006, 03:56:56 am
I downloaded Coppermine last week to setup a family and friends photo site (it's getting too big to manage with Dave James' album script).  I was surprised to find that Coppermine does not have support for user owned categories.  I really need this functionality and from searching the forums, it seems like a lot of other users want it too.  So I put together this patch.  It adds the following features:

- A new selection box, "Category owner", is added to the Administrator category page allowing administrators to assign ownership to categories.
- The category page is now accessible to registered users, who are allowed to fully manipulate (move, delete, edit) the categories which they own.
- Support for nesting of categories owned by different users (e.g. "Family" category owned by user "Son", "Family->Dad" category owned by user "Dad", "Family ->Mom" owned by "Mom" etc.)
- Users can create subcategories and albums in their categories.
- xp_publish has been modified to allow users to create albums and upload directly into categories which they own.
- Users can also upload via the web form into albums under their categories.
- All albums within a user's owned categories can be modified by the user, including movement between user owned categories.
- Albums can now be moved to and from the User Gallery.
- This patch should make it easier to add real permissions (unix style, acl, etc) since the diffs highlight many (all?) of the critical points for permissions.

Caveat emptor:
- This is a first cut (aka alpha code).
- Seems to work well for me, but ymmv (translation: the usual disclaimer, I take no responsibility for this patch breaking your site or causing your server to burst into flames).
- If anyone is interested in trying this out, I'd like to hear feedback about bugs/issues/etc.
- If anyone familiar with the Coppermine code could take a look, that would be great.
- I have no idea whatsoever how this will or will not work with bridging.

Bugs/Known issues:
- User category view and movement can be confusing if a user's categories are not positionally contiguous within each hierarchy level.  Solution is probably a constraint enforcing positional grouping of user categories.
- I used a couple of negative constants for convenience in some of the code/queries.  These should probably be replaced with nulls or something.
- There is a query that uses UNION, which is only supported in mysql 4+.
- There are some other queries that would be nicer using UNION, but I generally tried to avoid it since this system seems to support mysql 3.x.
- Categories which a user does not own are displayed in the selects using "optgroups".  Any better ideas for this?  Leaving them out entirely makes the menus confusing in terms of hierarchy.
- A non-admin user can move a category he owns at the root level into another category he owns, however he cannot move it back to the root level, since the root level is owned by Administrator.  Solution is probably to either not allow this, or to keep track of if a user owned category was ever at the root level, and allow users to move such categories back.
- Others I can't recall or don't know about now.

Installation:

Download and unzip the patch into your toplevel cpg directory (e.g. cpg149), and run this command: "patch -p1 < patch-cpg149-usrcat".  No database modifications are required as this patch uses the existing and seemingly unused "owner_id" field in the categories table.  Log on as administrator and add some new categories owned by users.  To get a "My Categories" menu item for users, add the following line to $template_user_admin_menu in your theme:

<td class="admin_menu"><a href="catmgr.php" title="Create, manage, and delete categories">My categories</a></td>

- Eric
Title: Re: Mod: User Categories
Post by: vortac on October 04, 2006, 07:39:14 am
This incremental patch fixes the following bugs/issues in the user categories mod:

- The "EDIT FILES" button next to the albums now works in user categories.
- In some cases the "DELETE", "PROPERTIES", "EDIT FILES" buttons were displayed to Guests (although they did not have permissions if they clicked these options).  This has been fixed.
- Eliminated unnecessary DB queries when Guests load index.php.

Installation:

AFTER having installed the initial user categories patch, download and unzip this patch into your cpg directory.  Then do "patch -p1 < patch-cpg149-usrcat-inc1".
Title: Re: Mod: User Categories
Post by: djpvx on October 05, 2006, 09:25:37 pm
i'm very newbie, but can you tell me, how to patch it?
Title: Re: Mod: User Categories
Post by: vortac on October 06, 2006, 03:20:05 am
Hi there, can you provide more information about your setup?  Do you have shell access to your account (ssh for example), or are you only able to modify files on the server via FTP?  Since you must have read the installation instructions in the previous posts, which cover the case where you have shell access, I'll assume the latter.  I'll also assume your local machine is windows based, which means it does not come with a "patch" utility.

What you probably need to do is first install a windows patch utility, such as http://gnuwin32.sourceforge.net/packages/patch.htm.  Then, download and unzip cpg149.  Next, download and unzip the patches into this cpg149 directory.  In the cpg149 directory, issue the patch commands exactly as stated in the previous posts, and in that order.  Finally, upload the patched cpg149 tree to your server.

Beyond that, you'll need to provide more information.

- Eric

i'm very newbie, but can you tell me, how to patch it?
Title: Re: Mod: User Categories
Post by: djpvx on October 06, 2006, 08:31:58 am
i can access my files via ftp only. :-\
Title: Re: Mod: User Categories
Post by: Little_rU on October 17, 2006, 04:11:36 pm
Hi!

First of all thanks a lot for this great hack, this is what I was looking for a long time.

But I have an installation problem. I've successfully applied both patches and administrator can now assign owner to a category but I don't see how this user (owner) can do something with it (any new menu etc). And when owner tries to open catmgr.php page it says "You don't have permission to access this page."

Where can I find this $template_user_admin_menu where as I understand I have to put a link to this category management page ?
Title: Re: Mod: User Categories
Post by: Bazzah on October 30, 2006, 01:36:11 pm
This mod sounds like exactly what I need, but I can not get it to work either. I too am a bit of a newbie when it comes to php and sql. I have followed your instructions to the letter. I downloaded that patching utility you suggested (Im on a windows machine, and trying to install the mod via ftp) but when running the patch, it comes up with errors each time it attempts to patch.

can't find file to patch at input line 4
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -ru cpg149-ORIG/albmgr.php cpg149/albmgr.php
|--- cpg149-ORIG/albmgr.php     2006-09-26 19:34:27.000000000 -0400
|+++ cpg149/albmgr.php  2006-10-02 14:19:38.000000000 -0400
--------------------------
File to patch:
Title: Re: Mod: User Categories
Post by: Piotras on November 06, 2006, 07:58:43 am
This is what i was looking for.  Worked great thx alot.   :) ;)
Title: Re: Mod: User Categories
Post by: Piotras on November 06, 2006, 09:18:10 am
Found a bug.

After allowing a user to create albums i specific category it adds the album to the user categories not to the specified category.

Title: Re: Mod: User Categories
Post by: codegirl42 on November 11, 2006, 10:49:25 pm
this is EXACTLY what i've been looking for for a long time....but...for some reason....i produce errors when i try to patch

I have shell access....

these are the errors that I get:

Code: [Select]
patching file albmgr.php
Hunk #1 FAILED at 51.
Hunk #2 FAILED at 337.
Hunk #3 FAILED at 360.
3 out of 3 hunks FAILED -- saving rejects to file albmgr.php.rej
patching file catmgr.php
Hunk #1 FAILED at 26.
Hunk #2 FAILED at 51.
Hunk #3 FAILED at 64.
Hunk #4 FAILED at 105.
Hunk #5 FAILED at 209.
Hunk #6 FAILED at 233.
Hunk #7 FAILED at 257.
Hunk #8 FAILED at 306.
Hunk #9 FAILED at 321.
Hunk #10 FAILED at 361.
Hunk #11 FAILED at 400.
Hunk #12 FAILED at 421.
Hunk #13 FAILED at 517.
Hunk #14 FAILED at 532.
Hunk #15 FAILED at 582.
15 out of 15 hunks FAILED -- saving rejects to file catmgr.php.rej
patching file db_input.php
Hunk #1 FAILED at 197.
1 out of 1 hunk FAILED -- saving rejects to file db_input.php.rej
patching file delete.php
Hunk #1 FAILED at 148.
Hunk #2 FAILED at 282.
2 out of 2 hunks FAILED -- saving rejects to file delete.php.rej
patching file include/functions.inc.php
Hunk #1 FAILED at 2995.
1 out of 1 hunk FAILED -- saving rejects to file include/functions.inc.php.rej
patching file index.php
Hunk #1 FAILED at 536.
Hunk #2 FAILED at 547.
Hunk #3 FAILED at 695.
Hunk #4 FAILED at 705.
Hunk #5 FAILED at 862.
5 out of 5 hunks FAILED -- saving rejects to file index.php.rej
patching file lang/english.php
Hunk #1 FAILED at 398.
Hunk #2 FAILED at 565.
Hunk #3 FAILED at 576.
Hunk #4 FAILED at 1378.
Hunk #5 FAILED at 2110.
5 out of 5 hunks FAILED -- saving rejects to file lang/english.php.rej
patching file modifyalb.php
Hunk #1 FAILED at 58.
Hunk #2 FAILED at 131.
Hunk #3 FAILED at 148.
Hunk #4 FAILED at 428.
Hunk #5 FAILED at 448.
Hunk #6 FAILED at 463.
6 out of 6 hunks FAILED -- saving rejects to file modifyalb.php.rej
patching file picmgr.php
Hunk #1 FAILED at 85.
1 out of 1 hunk FAILED -- saving rejects to file picmgr.php.rej
patching file upload.php
Hunk #1 FAILED at 839.
Hunk #2 FAILED at 2209.
2 out of 2 hunks FAILED -- saving rejects to file upload.php.rej
patching file xp_publish.php
Hunk #1 FAILED at 173.
Hunk #2 FAILED at 200.
Hunk #3 FAILED at 236.
Hunk #4 FAILED at 627.
Hunk #5 FAILED at 644.
Hunk #6 FAILED at 673.
Hunk #7 FAILED at 718.
7 out of 7 hunks FAILED -- saving rejects to file xp_publish.php.rej
Title: Re: Mod: User Categories
Post by: codegirl42 on November 11, 2006, 10:50:28 pm
forgot to mention that this is a unix server
Title: Re: Mod: User Categories
Post by: codegirl42 on November 12, 2006, 12:33:06 am
i implemented this manually...but was curious to know if there was a way that users could add sub-categories/albums to ANY ADMIN CREATED CATEGORY except USER albums. This would be great. I have a website in which i create a main category such as "FORD" and I would like users to create sub-categories and albums of their own such as: "2006 FOCUS"....

but the way this is setup, admin has to give OWNERSHIP in order for the user to create subcategories...I wish there was a way that EVERYONE could own ALL categories.

I hope this makes sense....

Thanks for any help
Title: Re: Mod: User Categories
Post by: MrOrange on November 12, 2006, 12:02:54 pm
I can't figure out that patch thing either on Win XP.

Can someone give a quick run down of how to read the patch file?

I take it this tells us what file to modify, and the the lines to change?

Code: [Select]
diff -ru cpg149-ORIG/catmgr.php cpg149/catmgr.php
--- cpg149-ORIG/catmgr.php 2006-09-26 19:34:27.000000000 -0400
+++ cpg149/catmgr.php 2006-10-02 15:08:15.000000000 -0400
@@ -26,7 +26,7 @@

Any help would be appreciated.
Title: Re: Mod: User Categories
Post by: codegirl42 on November 12, 2006, 06:08:15 pm
I can't figure out that patch thing either on Win XP.

Can someone give a quick run down of how to read the patch file?

I take it this tells us what file to modify, and the the lines to change?

Code: [Select]
diff -ru cpg149-ORIG/catmgr.php cpg149/catmgr.php
--- cpg149-ORIG/catmgr.php 2006-09-26 19:34:27.000000000 -0400
+++ cpg149/catmgr.php 2006-10-02 15:08:15.000000000 -0400
@@ -26,7 +26,7 @@

Any help would be appreciated.

might sound dumb, but i just followed the '+'s and '-'s in patching it manually. if you look at what you posted....the file that it's editing is "catmgr.php" first....so then the line that would be REMOVED would begin with a single '-' and the line that it is replaced with, begins with a single '+'.
Title: Re: Mod: User Categories
Post by: MrOrange on November 13, 2006, 03:24:43 pm
might sound dumb, but i just followed the '+'s and '-'s in patching it manually. if you look at what you posted....the file that it's editing is "catmgr.php" first....so then the line that would be REMOVED would begin with a single '-' and the line that it is replaced with, begins with a single '+'.

ahh awesome! thank you!
Title: Re: Mod: User Categories
Post by: vortac on November 14, 2006, 04:24:53 am
Hi, sorry for the poor response latency, I've actually been using a different photo gallery lately.  I don't know why you are having such problems with patch.  Are you using cpg 1.4.9?  A different version, or a version that has other mods may cause problems.  It's also possible that you're in the wrong directory, which affects which -p option you need to use (-p1, -p2, etc).  But you have the right idea regarding how patch works with "+" and "-", although it is tedious to do by hand.

As for the subcategory part of your post, that should work if you've added:

<td class="admin_menu"><a href="catmgr.php" title="Create, manage, and delete categories">My categories</a></td>

to your "$template_user_admin_menu" in the template, as described in the first post.  To test this immediately, you can just enter "catmgr.php" directly into the url after the "/" and you should see the option for users to create subcategories in categories they own (if memory serves, it's been a couple of months since I've looked at this).

- Eric

i implemented this manually...but was curious to know if there was a way that users could add sub-categories/albums to ANY ADMIN CREATED CATEGORY except USER albums. This would be great. I have a website in which i create a main category such as "FORD" and I would like users to create sub-categories and albums of their own such as: "2006 FOCUS"....

but the way this is setup, admin has to give OWNERSHIP in order for the user to create subcategories...I wish there was a way that EVERYONE could own ALL categories.

I hope this makes sense....

Thanks for any help
Title: Re: Mod: User Categories
Post by: codegirl42 on November 14, 2006, 04:42:20 am
Hi, sorry for the poor response latency, I've actually been using a different photo gallery lately.  I don't know why you are having such problems with patch.  Are you using cpg 1.4.9?  A different version, or a version that has other mods may cause problems.  It's also possible that you're in the wrong directory, which affects which -p option you need to use (-p1, -p2, etc).  But you have the right idea regarding how patch works with "+" and "-", although it is tedious to do by hand.

As for the subcategory part of your post, that should work if you've added:

<td class="admin_menu"><a href="catmgr.php" title="Create, manage, and delete categories">My categories</a></td>

to your "$template_user_admin_menu" in the template, as described in the first post.  To test this immediately, you can just enter "catmgr.php" directly into the url after the "/" and you should see the option for users to create subcategories in categories they own (if memory serves, it's been a couple of months since I've looked at this).

- Eric


thanks for the post Eric!

But what i would like is for them NOT to have to own the category in order to create albums in it...you know what i mean?
Title: Re: Mod: User Categories
Post by: vortac on November 15, 2006, 07:27:55 pm
OK, I know what you mean now.  If you only want this for one or two parent categories, you should be able to easily hack it in the code by hard coding the category id in each conditional that checks the category permission.  Just go through the patch diff and you should see every such point.  A less hacky approach would be to add a database column for each category allowing this, or actually add a table for real permissions.

- Eric

thanks for the post Eric!

But what i would like is for them NOT to have to own the category in order to create albums in it...you know what i mean?
Title: Re: Mod: User Categories
Post by: JCphotog on November 17, 2006, 01:16:46 am
This looks great.  It's all a bit beyond me.  But sort of like codegirl42 I'd love the opportunity to allow my users the ability to move their albums or create their albums in categories other than the user gallery cat.  Great work. 
Title: Re: Mod: User Categories
Post by: webberz on November 20, 2006, 01:00:53 pm
This is exactly what I am looking for! I wish I can get it installed.  I can't locate version 1.4.9 only the lastest coppermine 1.4.10 and this gives errors.  I expect because the files being updated have been changed in 1.4.10.  I would use 1.4.9 instead if I can get it, even though it may have security problems.  Or can you provide a updated patch for 1.4.10.  thanks
Title: Re: Mod: User Categories
Post by: vortac on November 20, 2006, 11:58:15 pm
What are the errors you are getting?  I doubt there are enormous changes between .9 and .10, especially if it's strictly a security update, but I don't really know (I'm not using coppermine these days).  Patch has the ability to figure out how to patch some types of changes, and others will result in rejected hunks.  If you get a ton of rejected hunks, it may mean you are not in the correct directory, which sounds like the problems others have had.  Make sure you unzip the patch file into the directory that contains the coppermine php files (files like catmgr.php, install.php, etc), and then execute the patch command within that same directory.

- Eric

This is exactly what I am looking for! I wish I can get it installed.  I can't locate version 1.4.9 only the lastest coppermine 1.4.10 and this gives errors.  I expect because the files being updated have been changed in 1.4.10.  I would use 1.4.9 instead if I can get it, even though it may have security problems.  Or can you provide a updated patch for 1.4.10.  thanks
Title: Re: Mod: User Categories
Post by: webberz on November 22, 2006, 08:12:34 pm
all files had missing hunks.  I was in the correct directory.  Anyways, I found a copy of 1.4.9 and applied against that and it worked.  thanks.  Is it a small change to allow group access to categories. ie. a user can create albums within a category, can this be done for groups?

Problem. I have a group of friends and we all take pictures.  I have top categories like Parties, Birthdays, Weddings, etc.  Then I must create sub-categories for each user under each top category.  I would like to give my freinds group access to the Parties top category so anyone within that group can create sub-categories or albums under Parties ???
Title: Re: Mod: User Categories
Post by: rongallon on December 03, 2006, 04:39:09 am
How can  I use this patch if I don't have access to my webserver via ssh.  I just have ftp access.  Is there a way to patch my files.
Title: Re: Mod: User Categories
Post by: Joachim Müller on December 03, 2006, 12:06:50 pm
It's not an actual patch, but a mod - it just uses the Lunix-command "patch". Although we appreciate all contributions, the thread starter has posted his hack in a format that we don't recommend, basically because it is not newbie-proof and can't be used by everyone.
However, it should be pretty easy to come up with this hack using a plain text editor - just take a look at the file provided inside the zip file. It is written in plain text.
A "minus" in front of a line means "remove this line", a "plus" in front of it means "add this line instead".

We'd like to see this mod "translated" to the regular way we usually see mods, using the syntax
Quote
edit foobar.php

find
Code: [Select]
somecodeand replace with
Code: [Select]
someothercode
Title: Re: Mod: User Categories
Post by: vortac on December 05, 2006, 10:44:44 pm
I didn't realize that posting the mod as a patch would be so problematic.  Since the patch file is about 750 lines and touches about 10 files, it seems like it might be impractical to post it in the format you are suggesting.  If I have some free time and there is sufficient interest maybe I'll forward port the changes into .10 and then upload the entire modified source tree for people to download.  Does this sound reasonable?

rongallon: there are some instructions covering your situation earlier in the thread.  Since my time is quite limited right now, this is probably your best bet.

- Eric

It's not an actual patch, but a mod - it just uses the Lunix-command "patch". Although we appreciate all contributions, the thread starter has posted his hack in a format that we don't recommend, basically because it is not newbie-proof and can't be used by everyone.
However, it should be pretty easy to come up with this hack using a plain text editor - just take a look at the file provided inside the zip file. It is written in plain text.
A "minus" in front of a line means "remove this line", a "plus" in front of it means "add this line instead".

We'd like to see this mod "translated" to the regular way we usually see mods, using the syntax
Title: Re: Mod: User Categories
Post by: bennettsweb on January 03, 2007, 07:50:19 am
--Interest--

I tried to patch with the windows prog, but got errors.  I will probably get around to doing it manually if someone doesn't modify the source files first.

Thanks for the mod though!
Title: Re: Mod: User Categories
Post by: colin911 on January 26, 2007, 09:10:53 pm
I'm super interested in this.  I just created a coppermine site tht needs this functionality to work correctly under the structure I have in mind.  But I don;t have Shell access, only FTP. 

any chances of getting this to work without shell access?

Title: Re: Mod: User Categories
Post by: Nibbler on January 27, 2007, 02:54:17 pm
Edit file albmgr.php

Find:

Code: [Select]
{
     global $CONFIG, $CAT_LIST;
 
     $result = cpg_db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
     if (mysql_num_rows($result) > 0) {
         $rowset = cpg_db_fetch_rowset($result);
         foreach ($rowset as $subcat) {
             $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name']);
             alb_get_subcat_data($subcat['cid'], $ident . '&nbsp;&nbsp;&nbsp;');
         }
     }

Change to:

Code: [Select]
{
     global $CONFIG, $CAT_LIST;
 
     $result = cpg_db_query("SELECT cid, name, description, owner_id FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
     if (mysql_num_rows($result) > 0) {
         $rowset = cpg_db_fetch_rowset($result);
         foreach ($rowset as $subcat) {
             $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name'], $subcat['owner_id']);
             alb_get_subcat_data($subcat['cid'], $ident . '&nbsp;&nbsp;&nbsp;');
         }
     }


Find:

Code: [Select]
?>
 <tr>
 <?php
 $cat 
= isset($_GET['cat']) ? ($_GET['cat']) : 0;
 if (
$cat == 1$cat 0;
 
 if (
GALLERY_ADMIN_MODE) {
     
$result cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $cat ORDER BY pos ASC");
 } elseif (
USER_ADMIN_MODE) {
     
$result cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . (USER_ID FIRST_USER_CAT) . " ORDER BY pos ASC");
 } else 
cpg_die(ERROR$lang_errors['perm_denied'], __FILE____LINE__);
 
$rowset cpg_db_fetch_rowset($result);
 
$i 100;

Change to:

Code: [Select]
?>
 <tr>
 <?php
 $cat 
= isset($_GET['cat']) ? ($_GET['cat']) : (USER_ID FIRST_USER_CAT);
 if (
$cat == 1$cat 0;
 
 if (
GALLERY_ADMIN_MODE) {
     
$result cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $cat ORDER BY pos ASC");
 } elseif (
USER_ADMIN_MODE) {
     
$result cpg_db_query("SELECT DISTINCT t1.aid, t1.title FROM {$CONFIG['TABLE_ALBUMS']} t1, {$CONFIG['TABLE_CATEGORIES']} t2 WHERE ($cat> " FIRST_USER_CAT " AND t1.category = " . (USER_ID FIRST_USER_CAT) . ") OR (t1.category=$cat AND t1.category=t2.cid AND t2.owner_id=" USER_ID ") ORDER BY t1.pos ASC");
 } else 
cpg_die(ERROR$lang_errors['perm_denied'], __FILE____LINE__);
 
$rowset cpg_db_fetch_rowset($result);
 
$i 100;


Find:

Code: [Select]
                 <br />
                 <table width="300" border="0" cellspacing="0" cellpadding="0">
 <?php
 
if (GALLERY_ADMIN_MODE) {
     
$CAT_LIST = array();
     
$CAT_LIST[] = array(FIRST_USER_CAT USER_ID$lang_albmgr_php['my_gallery']);
     
$CAT_LIST[] = array(0$lang_albmgr_php['no_category']);
     
alb_get_subcat_data(0'');
 
     echo <<<EOT
                 <tr>
                         <td>
                                 <b>
{$lang_albmgr_php['select_category']}</b>
                                 <select onChange="if(this.options[this.selectedIndex].value) window.location.href='
{$_SERVER['PHP_SELF']}?cat='+this.options[this.selectedIndex].value;"  name="cat" class="listbox">
 EOT;
     foreach(
$CAT_LIST as $category) {
         echo '                                <option value="' . 
$category[0] . '"' . ($cat == $category[0] ? ' selected': '') . ">" . $category[1] . "</option>\n";
     }
     echo <<<EOT
                                 </select>
                                 <br /><br />
                         </td>
                 </tr>
 
 EOT;
 }
 
 ?>

                 <tr>

Change to:

Code: [Select]
                 <br />
                 <table width="300" border="0" cellspacing="0" cellpadding="0">
 <?php
 
 $CAT_LIST 
= array();
 
$CAT_LIST[] = array(FIRST_USER_CAT USER_ID$lang_albmgr_php['my_gallery']);
 if (
GALLERY_ADMIN_MODE) {
     
$CAT_LIST[] = array(0$lang_albmgr_php['no_category']);
 }
 
alb_get_subcat_data(0'');
 
 echo <<<EOT
                 <tr>
                         <td>
                                 <b>
{$lang_albmgr_php['select_category']}</b>
                                 <select onChange="if(this.options[this.selectedIndex].value) window.location.href='
{$_SERVER['PHP_SELF']}?cat='+this.options[this.selectedIndex].value;"  name="cat" class="listbox">
 EOT;
 foreach(
$CAT_LIST as $category) {
     if (GALLERY_ADMIN_MODE || 
$category[2] == USER_ID || $category[0] == FIRST_USER_CAT + USER_ID) {
         echo '                                <option value="' . 
$category[0] . '"' . ($cat == $category[0] ? ' selected': '') . ">" . $category[1] . "</option>\n";
     } else {
         echo '                                <optgroup label="' . 
$category[1] . '"></optgroup>\n"';
     }
 }
 echo <<<EOT
                                 </select>
                                 <br /><br />
                         </td>
                 </tr>
 
 EOT;
 
 ?>

                 <tr>


Edit file catmgr.php

Find:

Code: [Select]

 //ob_end_flush(); //commented out, as it doesn't seem to do anything particularly helpful
 
 if (!GALLERY_ADMIN_MODE) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
 // Fix categories that have an invalid parent
 function fix_cat_table()
 {

Change to:

Code: [Select]

 //ob_end_flush(); //commented out, as it doesn't seem to do anything particularly helpful
 
 if (!(GALLERY_ADMIN_MODE || USER_ADMIN_MODE)) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
 // Fix categories that have an invalid parent
 function fix_cat_table()
 {


Find:

Code: [Select]
     $sort_query = 'pos';
     }
 
     $sql = "SELECT cid, name, description " . "FROM {$CONFIG['TABLE_CATEGORIES']} " . "WHERE parent = '$parent' " . "ORDER BY $sort_query";
     $result = cpg_db_query($sql);
 
     if (($cat_count = mysql_num_rows($result)) > 0) {

Change to:

Code: [Select]
     $sort_query = 'pos';
     }
 
     $sql = "SELECT cid, name, description, owner_id " . "FROM {$CONFIG['TABLE_CATEGORIES']} " . "WHERE parent = '$parent' " . "ORDER BY $sort_query";
     $result = cpg_db_query($sql);
 
     if (($cat_count = mysql_num_rows($result)) > 0) {


Find:

Code: [Select]
                     'pos' => $pos++,
                     'prev' => $prev_cid,
                     'cat_count' => $cat_count,
                     'name' => $ident . $subcat['name']);
                 $CAT_LIST[$last_index]['next'] = $subcat['cid'];
             } else {
                 $CAT_LIST[] = array('cid' => $subcat['cid'],
                     'parent' => $parent,
                     'pos' => $pos++,
                     'cat_count' => $cat_count,
                     'name' => $ident . $subcat['name']);
             }
             $prev_cid = $subcat['cid'];

Change to:

Code: [Select]
                     'pos' => $pos++,
                     'prev' => $prev_cid,
                     'cat_count' => $cat_count,
                     'name' => $ident . $subcat['name'],
                     'owner_id' => $subcat['owner_id']);
                 $CAT_LIST[$last_index]['next'] = $subcat['cid'];
             } else {
                 $CAT_LIST[] = array('cid' => $subcat['cid'],
                     'parent' => $parent,
                     'pos' => $pos++,
                     'cat_count' => $cat_count,
                     'name' => $ident . $subcat['name'],
                     'owner_id' => $subcat['owner_id']);
             }
             $prev_cid = $subcat['cid'];


Find:

Code: [Select]

 EOT;
     }
     $lb .= '                        <option value="0"' . ($highlight == 0 ? ' selected': '') . '>' . $lang_albmgr_php['no_category'] . "</option>\n";
     foreach($CAT_LIST as $category) if ($category['cid'] != 1 && $category['cid'] != $curr_cat) {
         $lb .= '                        <option value="' . $category['cid'] . '"' . ($highlight == $category['cid'] ? ' selected': '') . ">" . $category['name'] . "</option>\n";
     } elseif ($category['cid'] != 1 && $category['cid'] == $curr_cat) {
         $lb .= '                        <option value="' . $category['parent'] . '"' . ($highlight == $category['cid'] ? ' selected': '') . ">" . $category['name'] . "</option>\n";
     }
 
     $lb .= <<<EOT

Change to:

Code: [Select]

 EOT;
     }
     
     if (GALLERY_ADMIN_MODE) {
         $lb .= '                        <option value="0"' . ($highlight == 0 ? ' selected': '') . '>' . $lang_albmgr_php['no_category'] . "</option>\n";
     } else {
         $lb .= '                        <option value="0"' . ($highlight == 0 ? ' selected': '') . '>' . $lang_albmgr_php['no_user_category'] . "</option>\n";
     }
 
     foreach($CAT_LIST as $category) {
         if (!(GALLERY_ADMIN_MODE || $category['owner_id'] == USER_ID)) {
             $lb .= '                        <optgroup label="' . $category['name'] .'"></optgroup>\n"';
         } elseif ($category['cid'] != 1 && $category['cid'] != $curr_cat) {
             $lb .= '                        <option value="' . $category['cid'] . '"' . ($highlight == $category['cid'] ? ' selected': '') . ">" . $category['name'] . "</option>\n";
         } elseif ($category['cid'] != 1 && $category['cid'] == $curr_cat) {
             $lb .= '                        <option value="' . $category['parent'] . '"' . ($highlight == $category['cid'] ? ' selected': '') . ">" . $category['name'] . "</option>\n";
         }
     }
 
     $lb .= <<<EOT


Find:

Code: [Select]
     $CAT_LIST3 = $CAT_LIST;
 
     foreach ($CAT_LIST3 as $key => $category) {
         echo "        <tr>\n";
         echo '                <td class="tableb" width="80%"><b>' . $category['name'] . '</b></td>' . "\n";
 

Change to:

Code: [Select]
     $CAT_LIST3 = $CAT_LIST;
 
     foreach ($CAT_LIST3 as $key => $category) {
         if (!(GALLERY_ADMIN_MODE || $category['owner_id'] == USER_ID))
             continue;
 
         echo "        <tr>\n";
         echo '                <td class="tableb" width="80%"><b>' . $category['name'] . '</b></td>' . "\n";
 


Find:

Code: [Select]
             echo '                <td class="tableb" width="4%">' . '&nbsp;' . '</td>' . "\n";
         }
 
         echo '                <td class="tableb" width="4%">' . '<a href="' . $_SERVER['PHP_SELF'] . '?op=editcat&amp;cid=' . $category['cid'] . '">' . '<img src="images/edit.gif" border="0" alt="" />' . '</a></td>' . "\n";
         echo '                <td class="tableb" width="4%">' . "\n" . cat_list_box($category['parent'], $category['cid']) . "\n" . '</td>' . "\n";
         echo "        </tr>\n";
     }

Change to:

Code: [Select]
             echo '                <td class="tableb" width="4%">' . '&nbsp;' . '</td>' . "\n";
         }
 
         echo '                <td class="tableb" width="4%">' . '<a href="' . $_SERVER['PHP_SELF'] . '?op=editcat&amp;cid=' . $category['cid'] . '&amp;owner_id=' . $category['owner_id'] . '">' . '<img src="images/edit.gif" border="0" alt="" />' . '</a></td>' . "\n";
         echo '                <td class="tableb" width="4%">' . "\n" . cat_list_box($category['parent'], $category['cid']) . "\n" . '</td>' . "\n";
         echo "        </tr>\n";
     }


Find:

Code: [Select]
         return false;
 }
 
 
 if (isset($_POST['update_config'])) {
     $value = $_POST['categories_alpha_sort'];

Change to:

Code: [Select]
         return false;
 }
 
 function cat_owner_box($curr_owner)
 {
     global $CONFIG;
 
     $result = cpg_db_query("SELECT user_name, user_id FROM {$CONFIG['TABLE_USERS']} ORDER BY user_name");
     $rowset = cpg_db_fetch_rowset($result);
     $html = '    <select name="owner_id" class="listbox">' . "\n";
     $html .= '                    <option value="0">Administrator</option>' . "\n";
 
     foreach ($rowset as $user) {
         $html .= '                    <option value="' . $user['user_id'] . '"';
         if ($user['user_id']==$curr_owner)
             $html .= ' selected';
 
         $html .= '>' . $user['user_name'] . "</option>\n";
     }
 
     $html .= "                    </select>";
     return $html;
 }
 
 if (isset($_POST['update_config'])) {
     $value = $_POST['categories_alpha_sort'];


Find:

Code: [Select]
         $pos1 = (int)$_GET['pos1'];
         $pos2 = (int)$_GET['pos2'];
 
         cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos='$pos1' WHERE cid = '$cid1' LIMIT 1");
         cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos='$pos2' WHERE cid = '$cid2' LIMIT 1");
         break;

Change to:

Code: [Select]
         $pos1 = (int)$_GET['pos1'];
         $pos2 = (int)$_GET['pos2'];
 
 
         if (!(GALLERY_ADMIN_MODE || verify_cat_owner($cid1, $cid2))) {
             cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
             break;
         }
 
         cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos='$pos1' WHERE cid = '$cid1' LIMIT 1");
         cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos='$pos2' WHERE cid = '$cid2' LIMIT 1");
         break;


Find:

Code: [Select]

         $cid = (int)$_GET['cid'];
         $parent = (int)$_GET['parent'];
                 $children=array();
                 verify_children($cid, $cid);
                 if (!in_array($parent, $children)){
                 cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', pos='-1' WHERE cid = '$cid' LIMIT 1");
                 }else{
                         cpg_die(ERROR, "You cannot move a category into its own child", __FILE__, __LINE__);
                 }
                 break;
 
     case 'editcat':
         if (!isset($_GET['cid'])) cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'editcat'), __FILE__, __LINE__);
 
         $cid = (int)$_GET['cid'];
         $result = cpg_db_query("SELECT cid, name, parent, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");
 
         if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__);

Change to:

Code: [Select]

         $cid = (int)$_GET['cid'];
         $parent = (int)$_GET['parent'];
         
         if (!(GALLERY_ADMIN_MODE || verify_cat_owner($cid, $parent))) {
             cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
             break;
         }
 
         $children=array();
         verify_children($cid, $cid);
         if (!in_array($parent, $children)){
             cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', pos='-1' WHERE cid = '$cid' LIMIT 1");
         }else{
             cpg_die(ERROR, "You cannot move a category into its own child", __FILE__, __LINE__);
         }
         break;
 
     case 'editcat':
         if (!isset($_GET['cid'])) cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'editcat'), __FILE__, __LINE__);
 
         $cid = (int)$_GET['cid'];
 
         if (!(GALLERY_ADMIN_MODE || verify_cat_owner($cid))) {
             cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
             break;
         }
         $result = cpg_db_query("SELECT cid, name, parent, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");
 
         if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__);


Find:

Code: [Select]

 
         $cid = (int)$_POST['cid'];
         $parent = (int)$_POST['parent'];
         $thumb = (int)$_POST['thumb'];
         $name = trim($_POST['name']) ? addslashes($_POST['name']) : '&lt;???&gt;';
         $description = addslashes($_POST['description']);
                 $children=array();
                 verify_children($cid, $cid);
                 if (!in_array($parent, $children)){
                 cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
                 }else{
                         cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
                 }
         break;
 
     case 'createcat':

Change to:

Code: [Select]

 
         $cid = (int)$_POST['cid'];
         
         if (!(GALLERY_ADMIN_MODE || verify_cat_owner($cid))) {
             cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
             break;
         }
 
         $parent = (int)$_POST['parent'];
         $thumb = (int)$_POST['thumb'];
         $name = trim($_POST['name']) ? addslashes($_POST['name']) : '&lt;???&gt;';
         $description = addslashes($_POST['description']);
         $children=array();
         verify_children($cid, $cid);
         if (GALLERY_ADMIN_MODE && isset($_POST['owner_id'])){
             $owner_id=$_POST['owner_id'];
             if (!in_array($parent, $children)){
                 cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', name='$name', description='$description', thumb='$thumb', owner_id='$owner_id' WHERE cid = '$cid' LIMIT 1");
             }else{
                 cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name='$name', description='$description', thumb='$thumb', owner_id='$owner_id' WHERE cid = '$cid' LIMIT 1");
             }
         } else {
             if (!in_array($parent, $children)){
                 cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
             }else{
                 cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
             }
         }
         break;
 
     case 'createcat':
Title: Re: Mod: User Categories
Post by: Nibbler on January 27, 2007, 02:54:36 pm
Find:

Code: [Select]

 
                 $parent = (int)$_POST['parent'];
         $name = trim($_POST['name']) ? addslashes($_POST['name']) : '&lt;???&gt;';
         $description = addslashes($_POST['description']);
 
         cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description) VALUES ('10000', '$parent', '$name', '$description')");
         break;
 
     case 'deletecat':

Change to:

Code: [Select]

 
                 $parent = (int)$_POST['parent'];
         
         if (!(GALLERY_ADMIN_MODE || verify_cat_owner($parent))) {
             cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
             break;
         }
 
         $name = trim($_POST['name']) ? addslashes($_POST['name']) : '&lt;???&gt;';
         $description = addslashes($_POST['description']);
 
         $query = "INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description, owner_id) VALUES ('10000', '$parent', '$name', '$description', ";
         if (GALLERY_ADMIN_MODE && isset($_POST['owner_id']))
             cpg_db_query($query . "{$_POST['owner_id']})");
         else
             cpg_db_query($query . USER_ID . ")");
         break;
 
     case 'deletecat':


Find:

Code: [Select]

         $cid = (int)$_GET['cid'];
 
         $result = cpg_db_query("SELECT parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");
         if ($cid == 1) cpg_die(ERROR, $lang_catmgr_php['usergal_cat_ro'], __FILE__, __LINE__);
         if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__);

Change to:

Code: [Select]

         $cid = (int)$_GET['cid'];
 
         if (!(GALLERY_ADMIN_MODE || verify_cat_owner($cid))) {
             cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
             break;
         }
 
         $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category='$cid'");
         if (mysql_num_rows($result)) {
             cpg_die(ERROR, $lang_catmgr_php['cat_not_empty'], __FILE__, __LINE__);
             break;
         }
 
         $result = cpg_db_query("SELECT parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");
         if ($cid == 1) cpg_die(ERROR, $lang_catmgr_php['usergal_cat_ro'], __FILE__, __LINE__);
         if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__);


Find:

Code: [Select]

 starttable('100%', $lang_catmgr_php['update_create'], 2);
 $lb = cat_list_box($current_category['parent'], $current_category['cid'], false);
 $op = $current_category['cid'] ? 'updatecat' : 'createcat';
 if ($CONFIG['show_bbcode_help']) {$description_help .= '&nbsp;'. cpg_display_help('f=index.html&amp;base=64&amp;h='.urlencode(base64_encode(serialize($lang_bbcode_help_title))).'&amp;t='.urlencode(base64_encode(serialize($lang_bbcode_help))),470,245);}
 echo <<<EOT

Change to:

Code: [Select]

 starttable('100%', $lang_catmgr_php['update_create'], 2);
 $lb = cat_list_box($current_category['parent'], $current_category['cid'], false);
 $owner_box=cat_owner_box($owner_id);
 $op = $current_category['cid'] ? 'updatecat' : 'createcat';
 if ($CONFIG['show_bbcode_help']) {$description_help .= '&nbsp;'. cpg_display_help('f=index.html&amp;base=64&amp;h='.urlencode(base64_encode(serialize($lang_bbcode_help_title))).'&amp;t='.urlencode(base64_encode(serialize($lang_bbcode_help))),470,245);}
 echo <<<EOT


Find:

Code: [Select]
                 $lb
                 </td>
         </tr>
         <tr>
             <td width="40%" class="tableb">
                         {$lang_catmgr_php['cat_title']}

Change to:

Code: [Select]
                 $lb
                 </td>
         </tr>
 EOT;
 if (GALLERY_ADMIN_MODE) {
     echo <<<EOT
         <input type="hidden" name="owner_id" />
         <tr>
             <td width="40%" class="tableb">
                         {$lang_catmgr_php['cat_owner']}
         </td>
         <td width="60%" class="tableb" valign="top">
                 $owner_box
                 </td>
         </tr>
 EOT;
 }
       
 echo <<<EOT
         <tr>
             <td width="40%" class="tableb">
                         {$lang_catmgr_php['cat_title']}


Edit file db_input.php

Find:

Code: [Select]

         if (GALLERY_ADMIN_MODE) {
             $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title='$title', description='$description', category='$category', thumb='$thumb', uploads='$uploads', comments='$comments', votes='$votes', visibility='$visibility', alb_password='$password', alb_password_hint='$password_hint', keyword='$keyword' WHERE aid='$aid' LIMIT 1";
         } else {
             $category = FIRST_USER_CAT + USER_ID;
             $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title='$title', description='$description', thumb='$thumb',  comments='$comments', votes='$votes', visibility='$visibility', alb_password='$password', alb_password_hint='$password_hint',keyword='$keyword' WHERE aid='$aid' AND category='$category' LIMIT 1";
         }
 
         $update = cpg_db_query($query);

Change to:

Code: [Select]

         if (GALLERY_ADMIN_MODE) {
             $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title='$title', description='$description', category='$category', thumb='$thumb', uploads='$uploads', comments='$comments', votes='$votes', visibility='$visibility', alb_password='$password', alb_password_hint='$password_hint', keyword='$keyword' WHERE aid='$aid' LIMIT 1";
         } else if (verify_cat_owner($category) || $category == FIRST_USER_CAT + USER_ID) {
             $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title='$title', description='$description', category='$category', thumb='$thumb',  comments='$comments', votes='$votes', visibility='$visibility', alb_password='$password', alb_password_hint='$password_hint',keyword='$keyword' WHERE aid='$aid' LIMIT 1";
         } else {
             cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
         }
 
         $update = cpg_db_query($query);


Edit file delete.php

Find:

Code: [Select]
     $album_data = mysql_fetch_array($result);
 
     if (!GALLERY_ADMIN_MODE) {
         if ($album_data['category'] != FIRST_USER_CAT + USER_ID) cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
     }
 
     $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='$aid'";

Change to:

Code: [Select]
     $album_data = mysql_fetch_array($result);
 
     if (!GALLERY_ADMIN_MODE) {
         $category=$album_data['category'];
         if (!(verify_cat_owner($category) || $category == FIRST_USER_CAT + USER_ID)) cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
     }
 
     $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='$aid'";


Find:

Code: [Select]
                 case '0':
                     break;
                 case '1':
                     if (GALLERY_ADMIN_MODE) {
                         $category = (int)$_POST['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']}')";
                     cpg_db_query($query);
                     break;
                 case '2':
                     echo "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf($lang_delete_php['update_alb'], $op['album_no'], $op['album_nm'], $op['album_sort']) . "</td></tr>\n";
                     $query = "UPDATE $CONFIG[TABLE_ALBUMS] SET title='" . addslashes($op['album_nm']) . "', pos='{$op['album_sort']}' WHERE aid='{$op['album_no']}' $restrict LIMIT 1";
                     cpg_db_query($query);
                     break;
                 default:

Change to:

Code: [Select]
                 case '0':
                     break;
                 case '1':
                     $category = (int)$_POST['cat'];
                     if (!(GALLERY_ADMIN_MODE
                           || verify_cat_owner($category)
                           || ($category == FIRST_USER_CAT + USER_ID))) {
                         cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
                         break;
                     }
                     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']}')";
                     cpg_db_query($query);
                     break;
                 case '2':
                     $category = (int)$_POST['cat'];
                     if (!(GALLERY_ADMIN_MODE
                           || verify_cat_owner($category)
                           || ($category == FIRST_USER_CAT + USER_ID))) {
                         cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
                         break;
                     }
                     echo "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf($lang_delete_php['update_alb'], $op['album_no'], $op['album_nm'], $op['album_sort']) . "</td></tr>\n";
                     $query = "UPDATE $CONFIG[TABLE_ALBUMS] SET title='" . addslashes($op['album_nm']) . "', pos='{$op['album_sort']}' WHERE aid='{$op['album_no']}' LIMIT 1";
                     cpg_db_query($query);
                     break;
                 default:


Edit file include/functions.inc.php

Find:

Code: [Select]
   $query = "DELETE FROM {$CONFIG['TABLE_VOTE_STATS']} WHERE $clause";
   cpg_db_query($query);
 }
 ?>

Change to:

Code: [Select]
   $query = "DELETE FROM {$CONFIG['TABLE_VOTE_STATS']} WHERE $clause";
   cpg_db_query($query);
 }
 
 function verify_cat_owner($cid1, $cid2=-99)
 {
     global $CONFIG;
 
     $result = cpg_db_query("SELECT owner_id FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid1' || cid = '$cid2'");
     $count=mysql_num_rows($result);
     
     if(!$count) {
         return false;
     } else if (($cid2 >= 0) && ($count != 2)) {
         return false;
     }
     
     while($row=cpg_db_fetch_row($result)) {
         if ($row["owner_id"]!=USER_ID) {
             return false;
         }
     }
 
     return true;
 }
 
 ?>


Edit file index.php

Find:

Code: [Select]
             $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
             $alb_list[$alb_idx]['link_pic_count'] = $link_pic_count;
             $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
             $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : ' ';
         } elseif ($CONFIG['show_private']) { // uncomment this else block to show private album description
             $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
             $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;

Change to:

Code: [Select]
             $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
             $alb_list[$alb_idx]['link_pic_count'] = $link_pic_count;
             $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
             $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT) || verify_cat_owner($cat)) ? html_albummenu($alb_thumb['aid']) : ' ';
         } elseif ($CONFIG['show_private']) { // uncomment this else block to show private album description
             $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
             $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;


Find:

Code: [Select]
             $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
             $alb_list[$alb_idx]['link_pic_count'] = $link_pic_count;
             $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},   {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
             $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : ' ';
         }
     }
 

Change to:

Code: [Select]
             $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
             $alb_list[$alb_idx]['link_pic_count'] = $link_pic_count;
             $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},   {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
             $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT) || verify_cat_owner($cat)) ? html_albummenu($alb_thumb['aid']) : ' ';
         }
     }
 


Find:

Code: [Select]
             $alb_list[$alb_idx]['pic_count'] = $count;
             $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
             $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0)  ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
             $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : '';
         } elseif ($CONFIG['show_private']) { // uncomment this else block to show private album description
             $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
             $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;

Change to:

Code: [Select]
             $alb_list[$alb_idx]['pic_count'] = $count;
             $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
             $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0)  ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
             $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT) || verify_cat_owner($cat)) ? html_albummenu($alb_thumb['aid']) : '';
         } elseif ($CONFIG['show_private']) { // uncomment this else block to show private album description
             $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
             $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;


Find:

Code: [Select]
             $alb_list[$alb_idx]['pic_count'] = $count;
             $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
             $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 )? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
             $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : '';
         }
     }
     ob_start();

Change to:

Code: [Select]
             $alb_list[$alb_idx]['pic_count'] = $count;
             $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
             $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 )? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
             $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT) || verify_cat_owner($cat)) ? html_albummenu($alb_thumb['aid']) : '';
         }
     }
     ob_start();
Title: Re: Mod: User Categories
Post by: Nibbler on January 27, 2007, 02:55:01 pm
Edit file lang/english.php


Find:

Code: [Select]
   'alb_mrg' => 'Album Manager',
   'my_gallery' => '* My gallery *',
   'no_category' => '* No category *',
   'delete' => 'Delete',
   'new' => 'New',
   'apply_modifs' => 'Apply modifications',

Change to:

Code: [Select]
   'alb_mrg' => 'Album Manager',
   'my_gallery' => '* My gallery *',
   'no_category' => '* No category *',
   'no_user_category' => '* Click to Choose *',
   'delete' => 'Delete',
   'new' => 'New',
   'apply_modifs' => 'Apply modifications',


Find:

Code: [Select]
   'miss_param' => 'Parameters required for \'%s\'operation not supplied !',
   'unknown_cat' => 'Selected category does not exist in database',
   'usergal_cat_ro' => 'User galleries category can\'t be deleted !',
   'manage_cat' => 'Manage categories',
   'confirm_delete' => 'Are you sure you want to DELETE this category', //js-alert
   'category' => 'Category',

Change to:

Code: [Select]
   'miss_param' => 'Parameters required for \'%s\'operation not supplied !',
   'unknown_cat' => 'Selected category does not exist in database',
   'usergal_cat_ro' => 'User galleries category can\'t be deleted !',
   'cat_not_empty' => 'Category not empty (still contains albums)',
   'manage_cat' => 'Manage categories',
   'confirm_delete' => 'Are you sure you want to DELETE this category', //js-alert
   'category' => 'Category',


Find:

Code: [Select]
   'cat_title' => 'Category title',
   'cat_thumb' => 'Category thumbnail',
   'cat_desc' => 'Category description',
   'categories_alpha_sort' => 'Sort categories alphabetically (instead of custom sort order)', //cpg1.4
   'save_cfg' => 'Save configuration', //cpg1.4
 );

Change to:

Code: [Select]
   'cat_title' => 'Category title',
   'cat_thumb' => 'Category thumbnail',
   'cat_desc' => 'Category description',
   'cat_owner' => 'Category owner',
   'categories_alpha_sort' => 'Sort categories alphabetically (instead of custom sort order)', //cpg1.4
   'save_cfg' => 'Save configuration', //cpg1.4
 );


Find:

Code: [Select]
   'can_post_comments' => 'Visitors can post comments',
   'can_rate' => 'Visitors can rate files',
   'user_gal' => 'User Gallery',
   'no_cat' => '* No category *',
   'alb_empty' => 'Album is empty',
   'last_uploaded' => 'Last uploaded',

Change to:

Code: [Select]
   'can_post_comments' => 'Visitors can post comments',
   'can_rate' => 'Visitors can rate files',
   'user_gal' => 'User Gallery',
   'my_gallery' => '* My gallery *',
   'no_cat' => '* No category *',
   'alb_empty' => 'Album is empty',
   'last_uploaded' => 'Last uploaded',


Edit file modifyalb.php

Find:

Code: [Select]
{
     global $CONFIG, $CAT_LIST;
 
     $result = cpg_db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
     if (mysql_num_rows($result) > 0) {
         $rowset = cpg_db_fetch_rowset($result);
         foreach ($rowset as $subcat) {
             $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name']);
             get_subcat_data($subcat['cid'], $ident . '&nbsp;&nbsp;&nbsp;');
         }
     }

Change to:

Code: [Select]
{
     global $CONFIG, $CAT_LIST;
 
     $result = cpg_db_query("SELECT cid, name, description, owner_id FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
     if (mysql_num_rows($result) > 0) {
         $rowset = cpg_db_fetch_rowset($result);
         foreach ($rowset as $subcat) {
             $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name'], $subcat['owner_id']);
             get_subcat_data($subcat['cid'], $ident . '&nbsp;&nbsp;&nbsp;');
         }
     }


Find:

Code: [Select]
{
     global $ALBUM_DATA, $CAT_LIST, $USER_DATA, $lang_modifyalb_php;
 
     if (!GALLERY_ADMIN_MODE || $ALBUM_DATA['category'] > FIRST_USER_CAT) {
         echo <<<EOT
         <tr>
             <td class="tableb">
                         $text
         </td>
         <td class="tableb" valign="top">
                         <i>{$lang_modifyalb_php['user_gal']}</i>
                         <input type="hidden" name="$name" value="{$ALBUM_DATA['category']}" />
                 </td>
 
 EOT;
         return;
     }
 
     $CAT_LIST = array();
     $CAT_LIST[] = array(0, $lang_modifyalb_php['no_cat']);
     get_subcat_data(0, '');
 
     echo <<<EOT

Change to:

Code: [Select]
{
     global $ALBUM_DATA, $CAT_LIST, $USER_DATA, $lang_modifyalb_php;
 
     $CAT_LIST = array();
     if (GALLERY_ADMIN_MODE)
         $CAT_LIST[] = array(0, $lang_modifyalb_php['no_cat']);
     
     $CAT_LIST[] = array(FIRST_USER_CAT + USER_ID, $lang_modifyalb_php['my_gallery']);
     
     get_subcat_data(0, '');
 
     echo <<<EOT


Find:

Code: [Select]
                         <select name="$name" class="listbox">
 EOT;
     foreach($CAT_LIST as $category) {
         echo '                                <option value="' . $category[0] . '"' . ($ALBUM_DATA['category'] == $category[0] ? ' selected': '') . ">" . $category[1] . "</option>\n";
     }
     echo <<<EOT
                         </select>

Change to:

Code: [Select]
                         <select name="$name" class="listbox">
 EOT;
     foreach($CAT_LIST as $category) {
         if (GALLERY_ADMIN_MODE || $category[2] == USER_ID || $category[0] == FIRST_USER_CAT + USER_ID) {
             echo '                                <option value="' . $category[0] . '"' . ($ALBUM_DATA['category'] == $category[0] ? ' selected': '') . ">" . $category[1] . "</option>\n";
         } else {
             echo '                                <optgroup label="' . $category[1] . '"></optgroup>\n"';
         }
     }
     echo <<<EOT
                         </select>


Find:

Code: [Select]
         while ($row = mysql_fetch_array($result)) $rowset[] = $row;
         mysql_free_result($result);
     } else {
         $result = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = '" . (FIRST_USER_CAT + USER_ID) . "' ORDER BY title");
         $rowset = cpg_db_fetch_rowset($result);
         mysql_free_result($result);
     }

Change to:

Code: [Select]
         while ($row = mysql_fetch_array($result)) $rowset[] = $row;
         mysql_free_result($result);
     } else {
         $result = cpg_db_query("SELECT DISTINCT t1.aid, t1.title FROM {$CONFIG['TABLE_ALBUMS']} t1, {$CONFIG['TABLE_CATEGORIES']} t2 WHERE t1.category = " . (USER_ID + FIRST_USER_CAT) . " OR (t1.category=t2.cid AND t2.owner_id=" . USER_ID . ") ORDER BY t1.title ASC");
         $rowset = cpg_db_fetch_rowset($result);
         mysql_free_result($result);
     }


Find:

Code: [Select]
     if (GALLERY_ADMIN_MODE) {
         $results = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE 1 LIMIT 1");
     } else {
         $results = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . (FIRST_USER_CAT + USER_ID) . " LIMIT 1");
     }
     if (mysql_num_rows($results) == 0) cpg_die(ERROR, $lang_modifyalb_php['err_no_alb_to_modify'], __FILE__, __LINE__);
     $ALBUM_DATA = mysql_fetch_array($results);

Change to:

Code: [Select]
     if (GALLERY_ADMIN_MODE) {
         $results = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE 1 LIMIT 1");
     } else {
         $results = cpg_db_query("SELECT DISTINCT t1.* FROM {$CONFIG['TABLE_ALBUMS']} t1, {$CONFIG['TABLE_CATEGORIES']} t2 WHERE t1.category = " . (USER_ID + FIRST_USER_CAT) . " OR (t1.category=t2.cid AND t2.owner_id=" . USER_ID . ") ORDER BY t1.title ASC");
     }
     if (mysql_num_rows($results) == 0) cpg_die(ERROR, $lang_modifyalb_php['err_no_alb_to_modify'], __FILE__, __LINE__);
     $ALBUM_DATA = mysql_fetch_array($results);


Find:

Code: [Select]
$cat = $ALBUM_DATA['category'];
 $actual_cat = $cat;
 
 if (!GALLERY_ADMIN_MODE && $ALBUM_DATA['category'] != FIRST_USER_CAT + USER_ID) {
     cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
 }
 

Change to:

Code: [Select]
$cat = $ALBUM_DATA['category'];
 $actual_cat = $cat;
 
 if (!(GALLERY_ADMIN_MODE || $ALBUM_DATA['category'] == FIRST_USER_CAT + USER_ID || verify_cat_owner($ALBUM_DATA['category']))) {
     cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
 }
 


Edit file picmgr.php

Find:

Code: [Select]
//                $sql = "SELECT aid, CONCAT('(', user_name, ') ', title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (" . FIRST_USER_CAT . " + user_id)";
                 $sql = $cpg_udb->get_admin_album_list();  //it's always bridged so we no longer need to check.
             } else {
                 $sql = "SELECT aid, title AS title FROM {$CONFIG['TABLE_ALBUMS']}  WHERE category = " . (FIRST_USER_CAT + USER_ID);
             }
 //       }
         $result = cpg_db_query($sql);

Change to:

Code: [Select]
//                $sql = "SELECT aid, CONCAT('(', user_name, ') ', title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (" . FIRST_USER_CAT . " + user_id)";
                 $sql = $cpg_udb->get_admin_album_list();  //it's always bridged so we no longer need to check.
             } else {
                 $sql = "SELECT DISTINCT t1.aid, t1.title FROM {$CONFIG['TABLE_ALBUMS']} t1, {$CONFIG['TABLE_CATEGORIES']} t2 WHERE t1.category = " . (USER_ID + FIRST_USER_CAT) . " OR (t1.category=t2.cid AND t2.owner_id=" . USER_ID . ")";
             }
 //       }
         $result = cpg_db_query($sql);


Edit file upload.php

Find:

Code: [Select]
// Get public and private albums, and set maximum individual file size.
 
 if (GALLERY_ADMIN_MODE) {
     $public_albums = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 } else {
  $public_albums = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " AND uploads='YES' AND (visibility = '0' OR visibility IN ".USER_GROUP_SET.") ORDER BY title");
 }
 if (mysql_num_rows($public_albums)) {
     $public_albums_list = cpg_db_fetch_rowset($public_albums);
 } else {
     $public_albums_list = array();
 }
 
 if (USER_ID) {
     $user_albums = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category='" . (FIRST_USER_CAT + USER_ID) . "' ORDER BY title");
     if (mysql_num_rows($user_albums)) {
         $user_albums_list = cpg_db_fetch_rowset($user_albums);
     } else {
         $user_albums_list = array();
     }
 } else {
     $user_albums_list = array();
 }
 
 if (!count($public_albums_list) && !count($user_albums_list)) {
     cpg_die (ERROR, $lang_upload_php['err_no_alb_uploadables'], __FILE__, __LINE__);
 }

Change to:

Code: [Select]
// Get public and private albums, and set maximum individual file size.
 
 if (GALLERY_ADMIN_MODE) {
     $public_albums_q1 = "SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT;
 } else {
     $public_albums_q1 = "SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " AND uploads='YES' AND (visibility = '0' OR visibility IN ".USER_GROUP_SET.") ";
 }
 
 if (USER_ID) {
     $user_albums = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category='" . (FIRST_USER_CAT + USER_ID) . "' ORDER BY title");
     $public_albums = cpg_db_query($public_albums_q1 . " UNION SELECT t1.aid, t1.title FROM {$CONFIG['TABLE_ALBUMS']} t1, {$CONFIG['TABLE_CATEGORIES']} t2 WHERE (t1.category=t2.cid AND t2.owner_id=" . USER_ID . ") ORDER BY title");
     if (mysql_num_rows($user_albums)) {
         $user_albums_list = cpg_db_fetch_rowset($user_albums);
     } else {
         $user_albums_list = array();
     }
 } else {
     $public_albums = cpg_db_query($public_albums_q1 . " ORDER BY title");
     $user_albums_list = array();
 }
 
 if (mysql_num_rows($public_albums)) {
     $public_albums_list = cpg_db_fetch_rowset($public_albums);
 } else {
     $public_albums_list = array();
 }
 
 if (!count($public_albums_list) && !count($user_albums_list)) {
     cpg_die (ERROR, $lang_upload_php['err_no_alb_uploadables'], __FILE__, __LINE__);
 }


Find:

Code: [Select]

         // Check if the album id provided is valid
         if (!GALLERY_ADMIN_MODE) {
             $result = cpg_db_query("SELECT category FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='$album' and (uploads = 'YES' OR category = '" . (USER_ID + FIRST_USER_CAT) . "')");
             if (mysql_num_rows($result) == 0)cpg_die(ERROR, $lang_db_input_php['unknown_album'], __FILE__, __LINE__);
             $row = mysql_fetch_array($result);
             mysql_free_result($result);

Change to:

Code: [Select]

         // Check if the album id provided is valid
         if (!GALLERY_ADMIN_MODE) {
             $result = cpg_db_query("SELECT DISTINCT t1.category FROM {$CONFIG['TABLE_ALBUMS']} t1, {$CONFIG['TABLE_CATEGORIES']} t2 WHERE t1.aid='$album' AND (t1.uploads = 'YES' OR t1.category = " . (USER_ID + FIRST_USER_CAT) . " OR (t1.category=t2.cid AND t2.owner_id=" . USER_ID . "))");
             if (mysql_num_rows($result) == 0)cpg_die(ERROR, $lang_db_input_php['unknown_album'], __FILE__, __LINE__);
             $row = mysql_fetch_array($result);
             mysql_free_result($result);


Edit file xp_publish.php

Find:

Code: [Select]
{
     global $CONFIG, $CAT_LIST;
 
     $result = cpg_db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
     if (mysql_num_rows($result) > 0) {
         $rowset = cpg_db_fetch_rowset($result);
         foreach ($rowset as $subcat) {
             $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name']);
             get_subcat_data($subcat['cid'], $ident . '&nbsp;&nbsp;&nbsp;');
         }
     }

Change to:

Code: [Select]
{
     global $CONFIG, $CAT_LIST;
 
     $result = cpg_db_query("SELECT cid, name, description, owner_id FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
     if (mysql_num_rows($result) > 0) {
         $rowset = cpg_db_fetch_rowset($result);
         foreach ($rowset as $subcat) {
             $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name'], $subcat['owner_id']);
             get_subcat_data($subcat['cid'], $ident . '&nbsp;&nbsp;&nbsp;');
         }
     }


Find:

Code: [Select]
     }
 
     if (USER_ID) {
         $user_albums = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category='" . (FIRST_USER_CAT + USER_ID) . "' ORDER BY title");
         if (mysql_num_rows($user_albums)) {
             $user_albums_list = cpg_db_fetch_rowset($user_albums);
         } else {

Change to:

Code: [Select]
     }
 
     if (USER_ID) {
         $user_albums = cpg_db_query("SELECT DISTINCT t1.aid, t1.title FROM {$CONFIG['TABLE_ALBUMS']} t1, {$CONFIG['TABLE_CATEGORIES']} t2 WHERE t1.category = " . (USER_ID + FIRST_USER_CAT) . " OR (t1.category=t2.cid AND t2.owner_id=" . USER_ID . ") ORDER BY t1.pos ASC");
         if (mysql_num_rows($user_albums)) {
             $user_albums_list = cpg_db_fetch_rowset($user_albums);
         } else {


Find:

Code: [Select]

     $html = "\n";
     foreach($CAT_LIST as $category) {
         $html .= '                        <option value="' . $category[0] . '">' . $category[1] . "</option>\n";
     }
 
     return $html;

Change to:

Code: [Select]

     $html = "\n";
     foreach($CAT_LIST as $category) {
         if (GALLERY_ADMIN_MODE || $category[2] == USER_ID || $category[0] == FIRST_USER_CAT + USER_ID) {
             $html .= '                        <option value="' . $category[0] . '">' . $category[1] . "</option>\n";
         } else {
             $html .= '                        <optgroup label="' . $category[1] . '"></optgroup>\n"';
         }
     }
 
     return $html;


Find:

Code: [Select]
         template_extract_block($template_select_album, 'no_album');
         template_extract_block($template_select_album, 'existing_albums');
 
         if (!USER_IS_ADMIN) template_extract_block($template_select_album, 'select_category');
 
         $params = array('{WELCOME}' => sprintf($lang_xp_publish_php['welcome'], USER_NAME),
             '{CREATE_NEW}' => $lang_xp_publish_php['create_new'],

Change to:

Code: [Select]
         template_extract_block($template_select_album, 'no_album');
         template_extract_block($template_select_album, 'existing_albums');
 
 
         $params = array('{WELCOME}' => sprintf($lang_xp_publish_php['welcome'], USER_NAME),
             '{CREATE_NEW}' => $lang_xp_publish_php['create_new'],


Find:

Code: [Select]
     } else {
         template_extract_block($template_select_album, 'no_album');
 
         if (!USER_IS_ADMIN) template_extract_block($template_select_album, 'select_category');
 
         $params = array('{WELCOME}' => sprintf($lang_xp_publish_php['welcome'], USER_NAME),
             '{UPLOAD}' => $lang_xp_publish_php['upload'],

Change to:

Code: [Select]
     } else {
         template_extract_block($template_select_album, 'no_album');
 
 
         $params = array('{WELCOME}' => sprintf($lang_xp_publish_php['welcome'], USER_NAME),
             '{UPLOAD}' => $lang_xp_publish_php['upload'],


Find:

Code: [Select]

     if (!(USER_CAN_CREATE_ALBUMS || USER_IS_ADMIN)) simple_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
 
     if (USER_IS_ADMIN) {
         $category = (int)$_POST['cat'];
     } else {
         $category = FIRST_USER_CAT + USER_ID;
     }

Change to:

Code: [Select]

     if (!(USER_CAN_CREATE_ALBUMS || USER_IS_ADMIN)) simple_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
 
     $cat = (int)$_POST['cat'];
     if (USER_IS_ADMIN) {
         $category = $cat;
     } else if (verify_cat_owner($cat)) {
         $category = $cat;
     } else {
         $category = FIRST_USER_CAT + USER_ID;
     }
Title: Re: Mod: User Categories
Post by: Nibbler on January 27, 2007, 02:55:09 pm
Find:

Code: [Select]
     $position = 0;
     // Check if the album id provided is valid
     if (!USER_IS_ADMIN) {
         $result = cpg_db_query("SELECT category FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='$album' and category = '" . (USER_ID + FIRST_USER_CAT) . "'");
         if (mysql_num_rows($result) == 0) simple_die(ERROR, $lang_db_input_php['unknown_album'], __FILE__, __LINE__);
         $row = mysql_fetch_array($result);
         mysql_free_result($result);

Change to:

Code: [Select]
     $position = 0;
     // Check if the album id provided is valid
     if (!USER_IS_ADMIN) {
         $result = cpg_db_query("SELECT DISTINCT t1.category FROM {$CONFIG['TABLE_ALBUMS']} t1, {$CONFIG['TABLE_CATEGORIES']} t2 WHERE t1.category = " . (USER_ID + FIRST_USER_CAT) . " OR (t1.category=t2.cid AND t2.owner_id=" . USER_ID . ") ORDER BY t1.pos ASC");
         if (mysql_num_rows($result) == 0) simple_die(ERROR, $lang_db_input_php['unknown_album'], __FILE__, __LINE__);
         $row = mysql_fetch_array($result);
         mysql_free_result($result);
Title: Re: Mod: User Categories
Post by: Nibbler on January 27, 2007, 02:55:31 pm
Good luck with that  ;)
Title: Re: Mod: User Categories
Post by: colin911 on January 29, 2007, 07:41:47 pm
WOW!  Coool.  NIbbler.  Before I do all this I want to confirm that doing this should be what i need to do to modify the existing PHP files to have this work without shell access?

Or did you answer another post?

If the former is correct, I can work on base php files for version 1.4.10 and if it works I can post the changed files for others to donwload.

FYI:I'm not a coder, by any means, but I can find and replace!
Title: Re: Mod: User Categories
Post by: Nibbler on January 29, 2007, 08:20:44 pm
Yeah, I just converted the instructions from a patch file to manual instructions. You don't need shell access.
Title: Re: Mod: User Categories
Post by: colin911 on January 29, 2007, 08:40:08 pm
Thanks.  I'll post my results.
Title: Re: Mod: User Categories
Post by: Little_rU on January 30, 2007, 08:35:03 am
Here (http://rapidshare.com/files/14052043/cpg1410_usrcat.zip.html) is my patched version 1.4.10.
Title: Re: Mod: User Categories
Post by: colin911 on January 30, 2007, 02:27:36 pm
Is it a clean CPG? Or did you already have some plugins or mods or something in there>
Title: Re: Mod: User Categories
Post by: Little_rU on January 30, 2007, 04:32:58 pm
Is it a clean CPG

Yes, just downloaded 1.4.10 and applied the patches.
Title: Re: Mod: User Categories
Post by: colin911 on January 30, 2007, 09:00:29 pm
OK, I tired it on the following system:  V1.4.10, with Stramm mod pack, full size photo access control, Jupload v2 and, top level users v1.0.

Get the following error when acessing albums in admin mode:
Quote
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/b/v/i/bviguides/html/Domains/Surfpic/gallery/albmgr.php on line 741

and get same error when acessing Create / order my albums in non admin but logged in as a user:
Quote
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/b/v/i/bviguides/html/Domains/Surfpic/gallery/albmgr.php on line 741

and get similar error when acessing "modify my albums":
Quote
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/b/v/i/bviguides/html/Domains/Surfpic/gallery/modifyalb.php on line 151

I'm going to triple check my copy and paste for those 2 php files but i'm quite sure I did it correctly.

Since I;m not a coder and can only follow directions, any ideas on what this error means?

Title: Re: Mod: User Categories
Post by: Nibbler on January 30, 2007, 10:29:58 pm
It means there is an error in the syntax. Normally this is caused by a typo, missing bracket etc.
Title: Re: Mod: User Categories
Post by: colin911 on January 30, 2007, 11:18:35 pm
I tried copying the changes to the files again as per nibbler's long instructions (thanks again by the way).

Unfortunately i kept geting the same errors so there must be a mistake in the "replace" part for albmgr.php, catmgr.php and modifyalb.php.

Unfortunately i'm not knowledgeable enough to figure out the problem.

But I did get it to work by using the above mentioned files from Littele_rU's patched files and it seems to be working ok.  the only thing is that Stramm's modpack had modified modifyalb.php so I;m guessing I will eventually encounter an error there.  Don't knwo what he modified in his file from the original.

Anyway, one last question:  Is there any hope that furture parts to this code may enable multiple users to be assigned to the same exact category (instead of using the nested option described in the first post of this thread)?
Title: Re: Mod: User Categories
Post by: colin911 on January 30, 2007, 11:20:30 pm
To use the correct terms to the last question above:  Can more thna one user "own" a category?
Title: Re: Mod: User Categories
Post by: colin911 on January 31, 2007, 12:15:45 am
OK, now I'm sure you're tired of me.

Is there a way that this could work with JUpload?

I've attached the php file.  I'm imagining that it just needs a little extra code to allow for the selection of Categories but don;t know how difficult this would be.

Anyway, nothing critical, but just thought I would ask.  thanks for all the help so far.
Title: Re: Mod: User Categories
Post by: tutone on February 09, 2007, 05:31:24 pm
Nibbler,

I realize that this isn't your mod... but I ask hoping that you can help.... my coppermine is bridged with mambo... when i go into categories and then "category owner".. i am only able to see the user accounts that were set up in coppermine prior to the bridge. Any idea on how i can see the usernames of the bridged mambo accounts?  Thanks in advance.
Title: Re: Mod: User Categories
Post by: kroni on February 12, 2007, 11:29:21 pm
OK, now I'm sure you're tired of me.

Is there a way that this could work with JUpload?

I've attached the php file.  I'm imagining that it just needs a little extra code to allow for the selection of Categories but don;t know how difficult this would be.

Anyway, nothing critical, but just thought I would ask.  thanks for all the help so far.
yes, it would be great if someone could combine these 2 mods!
i'd like to use it this way: give users or groups the ownership of categories. the owners can create/delete/.. albums in the category AND only the owner will be able to use/see the JUpload link in the  {SUB_MENU} (not {SYS_MENU} !) and do the uploads in the allowed categories/albums

anyone who can do this? :)   would be great!
Title: Re: Mod: User Categories
Post by: Gamorreaner on February 27, 2007, 11:33:33 am
Hello.

I tried the Mod allready on my Apache and it works really great. But i have the same problem as tutone while using it on my website with a bridge.
I use Woltlab Burningboard 2.3.6 (WBB) and i have no idea how i could change the path from the cpg users to the Wbb users without an error  :'(. I tried to change this Code
Code: [Select]
$result = cpg_db_query("SELECT user_name, user_id FROM {$CONFIG['TABLE_USERS']} ORDER BY user_name");
    $rowset = cpg_db_fetch_rowset($result);

many many... times but it allways shows me error while finding the path. Can someone say me what i have to change if my users are on my MySQL in bb1_users and not in cpg1410_users?
If you need more information say it please.

Thanks vortac for the Mod and thanks Little_rU for the patched cpg!
Title: Re: Mod: User Categories
Post by: SoudageAuto on March 29, 2007, 11:02:26 am
Hi All,

I just install the patched cpg version over the standard one.
In admin mode, I can add owner to categories, but after that. I don't see any change on the user side.
I reset the theme in order to use the standard one, but no change.

Two remarks regarding this mod.
   - We could add a group instead of an user as Owner  (in a professionnal use, more than one people should be able to do the same task)
   - A config panel to mass-modify existing categories (We have more than 130 categories)

Many thanks for this mod!

Title: Re: Mod: User Categories
Post by: vortac on April 04, 2007, 07:49:33 pm
IIRC, to get the user side menu you need to set $template_user_admin_menu in your theme to:

<td class="admin_menu"><a href="catmgr.php" title="Create, manage, and delete categories">My categories</a></td>

see the end of the first post in the thread.

- Yes, groups would be nice but I think it looked like that might require significant additional effort.
- Mass modification interface would be nice too.

This thing basically started as a solution to a problem I had, so I didn't really do it to solve any additional problems.  This is why there is no bridging support, group perms, etc.  My understanding is that coppermine NG will have a full permissions system.  It seems like there are a lot of people who want various aspects of a full permissions system now though, so maybe I could be convinced to do it on some sort of consulting basis.  PM if you're interested, otherwise it may be a while, as my schedule is currently pretty packed with other volunteer work.

- Eric

PS Nibbler, thanks for translating the patch file into the thread, that looked like a herculean effort.

Hi All,

I just install the patched cpg version over the standard one.
In admin mode, I can add owner to categories, but after that. I don't see any change on the user side.
I reset the theme in order to use the standard one, but no change.

Two remarks regarding this mod.
   - We could add a group instead of an user as Owner  (in a professionnal use, more than one people should be able to do the same task)
   - A config panel to mass-modify existing categories (We have more than 130 categories)

Many thanks for this mod!


Title: Re: Mod: User Categories
Post by: ch0de on October 15, 2007, 12:26:19 am
Ok. So let me get this straight. This Mod will allow me to set permission on categories...  so i can block Anonyms users from viewing my Family Albums.. and still give them access to the public albums..

I know i can set user access on each albums. But I would rather Set it at the top level categories..

Now.. I am running .10  and all hunks failed.. have there been any updates to allow this to work in .10? or   is there another way to set user access on categories without having to manually change 100's of albums to keep eyes of my family photos but still let them see my public ones.
Title: Re: Mod: User Categories
Post by: Joachim Müller on November 18, 2007, 07:54:45 pm
Ok. So let me get this straight. This Mod will allow me to set permission on categories
Nope, that's wrong. This mod deals with the user gallery, which is a special category. This mod does not deal with setting permissions on any category.

I know i can set user access on each albums. But I would rather Set it at the top level categories..
Which is impossible.

Now.. I am running .10  and all hunks failed.. have there been any updates to allow this to work in .10?
This mod should work with all coppermine versions of the cpg1.4.x series. However, as you have the wrong impression what this mod actually does, it appears as if it isn't working at all.

It's not a bright idea to run cpg1.4.10 - always use the most recent stable release - currently cpg1.4.14. Upgrading is mandatory no matter what.
Title: Re: Mod: User Categories
Post by: Yadutaf on February 03, 2008, 07:11:38 am
Merci ! Je vais essayer de regarder ça.
[edit by François Keller]this post should be an answer to a previous post from Yadutaf in the french board...[/edit]
Title: Re: Mod: User Categories
Post by: kota069 on February 24, 2008, 04:36:57 am
Installation:

Download and unzip the patch into your toplevel cpg directory (e.g. cpg149), and run this command: "patch -p1 < patch-cpg149-usrcat".  No database modifications are required as this patch uses the existing and seemingly unused "owner_id" field in the categories table.  Log on as administrator and add some new categories owned by users.  To get a "My Categories" menu item for users, add the following line to $template_user_admin_menu in your theme:
...

I hate to seem ignorant here - though I guess I am in this case - but...
WHERE/HOW do I "Run this command"?

I'm using cpg1.4.16 (I'm assuming the patch will work with this?)
I'm on the server with cPanel - I swear I don't know how to "Run the command" (and it's gastly long to modify manually)

Could somebody school me here?
Title: Re: Mod: User Categories
Post by: kota069 on March 01, 2008, 02:49:17 am
... guess nobody ever reads this forum any more.
Title: Re: Mod: User Categories
Post by: Nibbler on March 01, 2008, 02:55:48 am
Plenty of people do, it's just that explaining how to use 'patch' to someone who knows only cPanel is not an easy task.

Best idea I think is to look for a windows equivalent to patch, download Coppermine from your site and apply the patch on your PC, then upload your patched version.

What you probably need to do is first install a windows patch utility, such as http://gnuwin32.sourceforge.net/packages/patch.htm.  Then, download and unzip cpg149.  Next, download and unzip the patches into this cpg149 directory.  In the cpg149 directory, issue the patch commands exactly as stated in the previous posts, and in that order.  Finally, upload the patched cpg149 tree to your server.

I once wrote a script to convert a diff to 'find x change to y' format but I don't know where it is unfortunately.
Title: Re: Mod: User Categories
Post by: kota069 on March 01, 2008, 04:16:20 am
Plenty of people do, it's just that explaining how to use 'patch' to someone who knows only cPanel is not an easy task.

Best idea I think is to look for a windows equivalent to patch, download Coppermine from your site and apply the patch on your PC, then upload your patched version.

I once wrote a script to convert a diff to 'find x change to y' format but I don't know where it is unfortunately.
I appreciate you eventual response.....
but how difficult can it be?
cPanel is the most commonly used server interface......
Is there a command line somewhere that I don't know about?

I mean....
If you can spell it out for me in a paragraph or so - then try me - I'm not totally illiterate.

But if it REALLY is that complex I guess I'll accept that and say 'thank you' anyway.
Title: Re: Mod: User Categories
Post by: Nibbler on March 01, 2008, 05:06:02 am
Easier to just do it myself. See attached zip file.

Created by downloading Coppermine 1.4.9, applying the first patch then the second patch and merging with 1.4.16.
Title: Re: Mod: User Categories
Post by: kota069 on March 01, 2008, 05:31:53 am
Easier to just do it myself. See attached zip file.

Created by downloading Coppermine 1.4.9, applying the first patch then the second patch and merging with 1.4.16.
Well............

Thank you.
Title: Re: Mod: User Categories
Post by: potayo on May 09, 2008, 11:34:25 am
Great mod 1.4.16 and with the probe goes well but I like that instead of letting a user to upload photos to the categories outside a group of users who need to make changes to make the menu of categories rather than users groups would be easier
Title: Re: Mod: User Categories
Post by: potayo on May 09, 2008, 11:40:55 am
Easier to just do it myself. See attached zip file.

Created by downloading Coppermine 1.4.9, applying the first patch then the second patch and merging with 1.4.16.

thanks but could do so let me put a group of users rather than one as owner