• [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien 4 0 5 1
Currently:  

Author Topic: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien  (Read 230230 times)

0 Members and 1 Guest are viewing this topic.

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #135 on: October 01, 2008, 11:44:01 AM »
YES WE DID IT!    :lol:

Ok with many thanks to V@no, :thumbup: I have managed to alter the code enough to just allow members who have created a new category to write to it, but not allow any other members. I did this by altering the code for the upload button, and by adding a field to the *_categories table in the database.

First of all get in the database and add a new field to the categories table called "cat_author"
The reason for this is because when a new category is made, we are going to add the name of the member who created it.
For those categories where you want anyone to be able to write to, just put 1. If there is already many categories on your site, you'll have to make the new field with a default value of 1, otherwise nobody will be able to write to them again once the code is in. (you have been warned)

After your time in the databse, now lets alter the code to add the members name who created the category.

Find this entry in addcat.php (you can see where I have entered the new entries.   

$sql = "INSERT INTO (name)_categories   (whatever your table is called)
   (
          cat_id,
          cat_name,
          cat_description,
          cat_parent_id,
          cat_author ,         
          cat_hits,
          cat_order,
          auth_viewcat,
          auth_viewimage,
          auth_download,
          auth_upload,
          auth_directupload,
          auth_vote,
          auth_sendpostcard,
          auth_readcomment,
          auth_postcomment
         )
    VALUES
         (
          '$new_cat_id',
          '$new_cat_name',
          '$new_cat_description',
          '$cat_parent_id',
           '$user_name',         
          '$cat_hits',
          '$new_cat_order',
          '$auth_viewcat',
          '$auth_viewimage',
          '$auth_download',
          '$auth_upload',
          '$auth_directupload',
          '$auth_vote',
          '$auth_sendpostcard',
          '$auth_readcomment',
          '$auth_postcomment'
          )";

Use $username as this is what name you are using when you are logged into the gallery.

Next you will need to add "cat_author" to your global.php in your gallery root directory.

Change this line in global.php   (Its line 462 in my script)

Code: [Select]
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
to
Code: [Select]
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_author, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment

Notice the new entry for cat_author?

In catergories.php you need to overwrite and enter some extra code for the new upload button.

Select:
Code: [Select]
//-----------------------------------------------------
//--- Show Categories ---------------------------------
//-----------------------------------------------------
if (!check_permission("auth_upload", $cat_id)) {
  $upload_url = "";
  $upload_button = "<img src=\"".get_gallery_image("upload_off.gif")."\" border=\"0\" alt=\"\" />";
}
else {
  $upload_url = $site_sess->url(ROOT_PATH."member.php?action=uploadform&amp;".URL_CAT_ID."=".$cat_id);
  $upload_button = "<a href=\"".$upload_url."\"><img src=\"".get_gallery_image("upload.gif")."\" border=\"0\" alt=\"\" /></a>";
}

and change to:

Code: [Select]
//-----------------------------------------------------
//--- Show Categories ---------------------------------
//-----------------------------------------------------
$online_member ="$user_info[user_name]";
$cat_creator = $cat_cache[$cat_id]['cat_author'];

if($online_member == $cat_creator || $cat_creator ==1)
{
$upload_allowed = "1";
}
else
{
$upload_allowed = "0";
}

if ($upload_allowed != "1") {
  $upload_url = "";
  $upload_button = "<div align=\"center\"><img src=\"".get_gallery_image("upload_off.gif")."\" border=\"0\" alt=\"\" /> <br />private category</div>";
}
else if (!check_permission("auth_upload", $cat_id)) {
  $upload_url = "";
  $upload_button = "<img src=\"".get_gallery_image("upload_off.gif")."\" border=\"0\" alt=\"\" />";
}
else {
  $upload_url = $site_sess->url(ROOT_PATH."member.php?action=uploadform&amp;".URL_CAT_ID."=".$cat_id);
  $upload_button = "<a href=\"".$upload_url."\"><img src=\"".get_gallery_image("upload.gif")."\" border=\"0\" alt=\"\" /></a>";
}

And thats it.  Now you can write to any category except those that are created by members (after this code is added).

Hope it works for you  :mrgreen:
Gary

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #136 on: October 01, 2008, 03:11:08 PM »
Hmmm
are you sure?
I think there are more to it then just showing the upload button ;)
you also need change member.php.

P.S.

using username to identify the owner is a bad idea, username can be changed, however user_id can not. Use this instead:
$sql "INSERT INTO " CATEGORIES_TABLE "
   (
          cat_id,
          cat_name,
          cat_description,
          cat_parent_id,
          cat_hits,
          cat_order,
          auth_viewcat,
          auth_viewimage,
          auth_download,
          auth_upload,
          auth_directupload,
          auth_vote,
          auth_sendpostcard,
          auth_readcomment,
          auth_postcomment,
          cat_author ,         
         )
    VALUES
         (
          '
$new_cat_id',
          '
$new_cat_name',
          '
$new_cat_description',
          '
$cat_parent_id',
          '
$cat_hits',
          '
$new_cat_order',
          '
$auth_viewcat',
          '
$auth_viewimage',
          '
$auth_download',
          '
$auth_upload',
          '
$auth_directupload',
          '
$auth_vote',
          '
$auth_sendpostcard',
          '
$auth_readcomment',
          '
$auth_postcomment',
          
$user_info['user_id'],
          )"
;



in categories.php
this should be better:
//-----------------------------------------------------
//--- Show Categories ---------------------------------
//-----------------------------------------------------
if (check_permission("auth_upload"$cat_id)
    || (
$user_info['user_level'] > GUEST && $cat_cache[$cat_id]['cat_author'] == $user_info['user_id'])) {
  
$upload_url $site_sess->url(ROOT_PATH."member.php?action=uploadform&amp;".URL_CAT_ID."=".$cat_id);
  
$upload_button "<a href=\"".$upload_url."\"><img src=\"".get_gallery_image("upload.gif")."\" border=\"0\" alt=\"\" /></a>";
}
else {
  
$upload_url "";
  
$upload_button "<img src=\"".get_gallery_image("upload_off.gif")."\" border=\"0\" alt=\"\" />";
}


P.P.S.
I just looked closer at this mod and see that it has no protection of any sorts. Guests can create categories by pressing a link - this means your gallery can get thousands of new categories per minute, which eventually will bring down the site.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #137 on: October 01, 2008, 04:15:56 PM »
Ah, Just goes to show how much of a newbie I really am!

Thanks for the changes, I'll update the pages immediately. Hmmm, for protection could make it so that the upload page and the create category page don't load if your not signed in? I'll have a look at that.

Gazza

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #138 on: October 01, 2008, 05:56:02 PM »
Hello again

I just checked out the site again and my code at the moment seems fine. There is still a prpoblem that members can still add photos to other members categoriesd by altering the code in the address bar, I'll have a look at that.

However, people that are not logged into the site cannot upload any pics. People that are not logged into the site cannot make any categories either. Don't know if this is what you mean

Better get to work now

Gazza

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #139 on: October 02, 2008, 02:00:14 AM »
However, people that are not logged into the site cannot upload any pics. People that are not logged into the site cannot make any categories either. Don't know if this is what you mean
That controls by $auth_... variables, and that is not what I was talking about.
I was talking about creating the categories. All a visitor needs to do is click "New category" link and it's done, no questions asked, no restrictions on who can and cannot create new categories, nada.
With this in place it would take to a lamer 2 minutes and no more then 5 lines of PHP code to create a script that would loop indefinately "clicking" that link. After 10 minutes of such "clicking" your 4images will be virtually inaccessible because it will be so slow with thousands of empty categories (current 4images version is not optimized for lots of categories).
What I'm saying is guests should not be allowed create categories or do any kind of changes to the gallery.


P.S.
Since the author hasn't been here for 2 month, I'll attach optimized addcat.php script with flood protection.

[EDIT]
attached to the original post.
« Last Edit: October 02, 2008, 06:59:57 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #140 on: October 04, 2008, 01:59:39 PM »
hello

However, people that are not logged into the site cannot upload any pics. People that are not logged into the site cannot make any categories either. Don't know if this is what you mean
That controls by $auth_... variables, and that is not what I was talking about.
I was talking about creating the categories. All a visitor needs to do is click "New category" link and it's done, no questions asked, no restrictions on who can and cannot create new categories, nada.
With this in place it would take to a lamer 2 minutes and no more then 5 lines of PHP code to create a script that would loop indefinately "clicking" that link. After 10 minutes of such "clicking" your 4images will be virtually inaccessible because it will be so slow with thousands of empty categories (current 4images version is not optimized for lots of categories).
What I'm saying is guests should not be allowed create categories or do any kind of changes to the gallery.


P.S.
Since the author hasn't been here for 2 month, I'll attach optimized addcat.php script with flood protection.

[EDIT]
attached to the original post.

Thank you for the new script, its in and running.

I have looked at what you said above, and I would like to insure you that a visitor cannot create a new category, or add images or do anything without signing in first. Only the admin can create new members. I even tried this going stright to the add cat page as a visitor and all you get is the error page. I just can't see anyway at all that a visitor can do anything to the site without getting into the code? (I'm very new to this so I don't really know anything yet :) )

http://gallery.lovemansfield.co.uk/addcat.php

I have figured out how to stop members from adding to other members categories by changing the cat_id number. I have added the code to next reply.

Many thanks
Gazza


Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #141 on: October 04, 2008, 02:03:41 PM »
To alter the member.php so that other members cannot just change the cat_id number and add picture to your category, insert the following code.

This code must go over the line below which is line 720 in my code.
if ($action == "uploadform") {

When you are finished you will have two lines of code begiining this way!

Code: [Select]
//----only authorise members can upload to category where author = their own username
//or author = 1 -------------

$online_member ="$user_info[user_name]";
$cat_creator = $cat_cache[$cat_id]['cat_author'];

if($online_member == $cat_creator || $cat_creator ==1)
{
$upload_allowed = "1";
}
else
{
$upload_allowed = "0";
}

if ($action == "uploadform")
{
  if ($upload_allowed != "1") {
    show_error_page($lang['no_permission']);
    exit;
}}

Then the next line of code withh be the orignal
if ($action == "uploadform") {

This will show an error screen if another member tried to upload images to your category.

All the best
Gazza

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #142 on: October 04, 2008, 02:06:24 PM »
Now I am going to attemp to allow members to edit and delete their own categories if they wish :)

Offline KillerCookie

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #143 on: October 11, 2008, 03:07:57 PM »
Now I am going to attemp to allow members to edit and delete their own categories if they wish :)

Hello and sorry for not answering all the questions.

This is a part of Addcat V2 - which is actually tested on my private website. I did it nearly the same way as you, but with some more options, security and a pretty little admin interface (which is currently under development). But i´m just not satisfied about the new version. :(  Some features i wanted don´t work properly and some... call it "design limitations" also occured. Because of the long developement time it is sometimes hard to continue the coding after a break of 1 or 2 weeks.

But i still try to make a perfectly working version with some nice features - but the release is still "when it´s done". :roll:

Quote from: V@no
P.P.S.
I just looked closer at this mod and see that it has no protection of any sorts. Guests can create categories by pressing a link - this means your gallery can get thousands of new categories per minute, which eventually will bring down the site.

You mean the whole mod or just the custom parts postet at these last pages?


Yours sincerely

Maik




Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #144 on: October 11, 2008, 04:54:46 PM »
Hi Killer

Can't wait for the new version to come :)

In the meantime my next task will be to allow members to edit their categories, example "change name of the category" and allow to alter who can see the category example "all, members or private". Private will mean that people have to type in a password to view the category page and see the photos in there. I may also alter the code so that pics don't show up to visitors on the front screen if they are member or private.

I am in the middle of editing a dance show ATM so have no time. Got another large dance show to film and edit at the end of the month too, so don't know when I'll get into the code again (which is very difficult when your used to the simple php, not this {bracketed} stuff.

BTW I have created some code to be able to delete your own categories. It works well deleting all the photos in the category, the database  and the actual folder too, except I haven't found out how to redirect to a page afterwards yet! Tell me if you want to see the code I used.

All the best
Gazza

Offline KillerCookie

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #145 on: October 12, 2008, 09:08:29 PM »
Hi Killer

Can't wait for the new version to come :)

In the meantime my next task will be to allow members to edit their categories, example "change name of the category" and allow to alter who can see the category example "all, members or private". Private will mean that people have to type in a password to view the category page and see the photos in there. I may also alter the code so that pics don't show up to visitors on the front screen if they are member or private.

I am in the middle of editing a dance show ATM so have no time. Got another large dance show to film and edit at the end of the month too, so don't know when I'll get into the code again (which is very difficult when your used to the simple php, not this {bracketed} stuff.

BTW I have created some code to be able to delete your own categories. It works well deleting all the photos in the category, the database  and the actual folder too, except I haven't found out how to redirect to a page afterwards yet! Tell me if you want to see the code I used.

All the best
Gazza

Compress the file(s) to an archive of your choice, upload it to any one click hosting service ( http://www.rapidshare.com ) and send me the link via PN. I´ll try my best to get the new version out as soon as possible and thanks for your help.

Maik

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #146 on: October 19, 2008, 04:20:43 PM »
Hi Killercookie and viewers

Just to let you know that i have succeeded in getting the latest mod done, now people on my site can create there own categories (thanks to killercookies original mod), they can delete the category and all files associated with it (pictures,comments, folders) and now they can modify their categories too. Just the creator of the category can make changes or delete!

By modifying categories I mean they can reedit the name of the category, edit the description and change whom can view the category. Example of this, All visitors can view the picture in the category, Just members can see the photos or they can make them private so that just the author can see the photos.

The next task will be to allow the author to assign a password to private categories so they can allow just visitors with the correct password to view the category.  may need some advise on this one, but I'm going to give it a try first.
« Last Edit: October 19, 2008, 08:36:44 PM by Gazzagreen »

Offline herb

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #147 on: December 04, 2008, 11:38:00 AM »
Hallo KillerCookie,

wenn ich alles richtig verstanden habe, wird es irgendwann (hoffentlich bald) eine überarbeitete Version von dem MOD geben.
Da warte ich drauf, denn es wäre für mich eine richtige Hilfe, wenn die User Kategorien selbst erstellen könnten.

Wir sind eine Senioren-Community, und haben in unserer Bildergalerie http://www.seniorentreff.de/galerie/ schon mehr als 6.000 Bilder.

Für Deine Entwicklungsarbeit vieln Dank.

Es grüßt ein Senior

Offline Elefant

  • Pre-Newbie
  • Posts: 1
    • View Profile
Re: [MOD] V1.3 Let users add (sub-)categories / User erstellen (Sub-)Kategorien
« Reply #148 on: February 15, 2009, 09:40:37 AM »
who post working MOD for add categories? Its very important MOD.
I read 148 post and cant find working version.

Offline lceman

  • Pre-Newbie
  • Posts: 5
    • View Profile
hallo,


Kann mir mal jemand erklären wie das mit dem Mod funktioniert :?:


Bin jetzt alle Seiten durchgegangen, habe aber nirgends eine Datei zum runterladen gefunden...

Der Mod wäre extrem hilfreich  :D


Liebe grüße, Stefan