Author Topic: [MOD] Picture Upload Limit for User  (Read 7868 times)

0 Members and 1 Guest are viewing this topic.

Offline mentrid

  • Pre-Newbie
  • Posts: 4
    • View Profile
[MOD] Picture Upload Limit for User
« on: April 27, 2009, 11:17:31 AM »
I searched the board for this MOD, but all Versions I found where allready outdated and not working,
so I decided to write it myself.

This MOD adds an additional field to the Category forms in the Admin Panel in which you can insert
a number(Integer). This number is the picture upload limit for all users, who try to upload in this category.
The default Limit is 1000 so you don't need to worry about existent categories.

I am using Version 1.7.6 and haven't tested it with other environments.

I don't think that this is the best way to program this feature but it works just fine with me. So
feel free to use or modify it to your needs.

Here we go!


lang/english/main.php

search for:
Code: [Select]
$lang['no_permission'] = "You are not logged in or do not have permissions to enter this site!";
add after:
Code: [Select]
$lang['uploadlimit_exceeded'] ="You can not upload more images!";

member.php

search for:
Code: [Select]
if ($action == "uploadform") {
  if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_permission("auth_upload", $cat_id))) {
    show_error_page($lang['no_permission']);
    exit;
  }

add before:
Code: [Select]
function check_picture_limit($cat_cache, $cat_id, $user_id) {

$uploadlimit=$cat_cache[$cat_id]['auth_uploadlimit'];
echo $uploadlimit;
//Count validated pictures
$sql = "SELECT image_id FROM ".IMAGES_TABLE." WHERE cat_id=".$cat_id." AND user_id=".$user_id."";
$result = mysql_query($sql);
$images_user = mysql_num_rows($result);

//Count not validated pictures
$sql = "SELECT image_id FROM ".IMAGES_TEMP_TABLE." WHERE cat_id=".$cat_id." AND user_id=".$user_id."";
$result = mysql_query($sql);
$images_user_temp = mysql_num_rows($result);

$images_user_total=$images_user+$images_user_temp;
if($images_user_total >= $uploadlimit)
{
return false;
}
else
{
return true;
}
}

add after:
Code: [Select]
  if( $user_info['user_level'] != ADMIN && !check_picture_limit($cat_cache, $cat_id, $user_info['user_id']))
  {
    show_error_page($lang['uploadlimit_exceeded']);
    exit; 
  }


global.php

search for:
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
replace with:
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, auth_uploadlimit

admin/categories.php

search for:
Code: [Select]
show_table_separator($permission_headline, 2);
  foreach ($access_field_array as $key => $val) {
    show_access_select($lang[$key], $key, $val);
  }

add after:
Code: [Select]
echo "<tr class=\"".get_row_bg()."\" valign=\"top\">\n<td><p class=\"rowtitle\">".$lang['auth_uploadlimit']."</p></td>\n";
    echo"<td><input type=\"text\" value=\"\" name=\"auth_uploadlimit\" size=\"30\"/></td>";

search 2x (savecat and updatecat) for :
Code: [Select]
$auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
add after:
Code: [Select]
$auth_uploadlimit = $HTTP_POST_VARS['auth_uploadlimit'];
search for:
Code: [Select]
$sql = "INSERT INTO ".CATEGORIES_TABLE."
            (cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment)
            VALUES
            ('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment)";

replace with:
Code: [Select]
    $sql = "INSERT INTO ".CATEGORIES_TABLE."
            (cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, auth_uploadlimit)
            VALUES
            ('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment, $auth_uploadlimit)";

search for:
Code: [Select]
$sql = "UPDATE ".CATEGORIES_TABLE."
            SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
            WHERE cat_id = $cat_id";

replace with:
Code: [Select]
$sql = "UPDATE ".CATEGORIES_TABLE."
            SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, auth_uploadlimit=$auth_uploadlimit
            WHERE cat_id = $cat_id";

search for:
Code: [Select]
$sql = "SELECT 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
          FROM ".CATEGORIES_TABLE."
          WHERE cat_id = $cat_id";

replace with:
Code: [Select]
$sql = "SELECT 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, auth_uploadlimit
          FROM ".CATEGORIES_TABLE."
          WHERE cat_id = $cat_id";

search for:
Code: [Select]
foreach ($access_field_array as $key => $val) {
    show_access_select($lang[$key], $key, $cat_row[$key]);
  }

add after:
Code: [Select]
echo "<tr class=\"".get_row_bg()."\" valign=\"top\">\n<td><p class=\"rowtitle\">".$lang['auth_uploadlimit']."</p></td>\n";
  echo"<td><input type=\"text\" value=\"".$cat_row['auth_uploadlimit']."\" name=\"auth_uploadlimit\" size=\"30\"/></td>";


lang/englisch/admin.php

search for:
Code: [Select]
$lang['auth_postcomment'] = "Post Comment";
add after:
Code: [Select]
$lang['auth_uploadlimit'] = "Picture uploadlimit for User";

Add Field in the Database:
Code: [Select]
ALTER TABLE `4images_categories` ADD `auth_uploadlimit` INT( 10 ) NOT NULL DEFAULT '1000';or take the Installation script


I hope I didn't miss anything and hope this works for you as well.
« Last Edit: April 29, 2009, 10:15:07 AM by mentrid »

Offline belenix

  • Pre-Newbie
  • Posts: 2
    • View Profile
Re: [MOD] Picture Upload Limit for User
« Reply #1 on: September 02, 2010, 12:48:03 AM »
Hi,

i've tried your script but reason :

-
Executing:

    ALTER TABLE `4images_categories`
    ADD 'auth_uploadlimit' INT(10) NOT NULL DEFAULT '1';


    An unexpected error occured. Please try again later.
    Try again
    Back to the gallery
-
what wrong bout this?

tanks

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Re: [MOD] Picture Upload Limit for User
« Reply #2 on: September 02, 2010, 01:27:05 AM »
Welcome to 4images forum.
It's possible that you ran that script twice, the table is already updated and you are good to go.
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.

Offline belenix

  • Pre-Newbie
  • Posts: 2
    • View Profile
Re: [MOD] Picture Upload Limit for User
« Reply #3 on: September 03, 2010, 01:23:43 AM »
but not working this mod at own gallery, are script running at 4images  1.7.7


thanks before

Rembrandt

  • Guest
Re: [MOD] Picture Upload Limit for User
« Reply #4 on: September 03, 2010, 06:18:54 AM »
Hi!
...
    An unexpected error occured. Please try again later.
    Try again
    Back to the gallery
-
what wrong bout this?

copy the installer in your root and call it to, see attachment.

mfg Andi