Hi!
At first i have to say, that i cant guarantee, that this mod will work for everybody.
The Reason: I started PHP "coding" three days ago and my whole experience on this comes from 4images installing and modifying...
I dont know if it is coded correctly so the real coders may laugh at me but it works for me and that is all i wanted
Make BACKUP of all files !
The Mod:
It counts your user´s comments, posts in forum (optional), uploaded images and the image quality (from votes).
For comments users get 5 points, for posts 5 points for uploaded images 5 pts and for and the average image quality multiplyed with 25 = points for quality.
For 50points they get an extra upload.
For example: Standard 20 uploads
Points = 264
Extra Uploads: 5
Global uploads: 25
If users want more uploads, they must be active in your galery...
Mods needed:
User Upload Limits
http://www.4homepages.de/forum/index.php?topic=3607.msg14765#msg14765Dreamboard 2.1 (optional)
http://www.4homepages.de/forum/index.php?topic=9598.msg45950#msg459501. Step:go to myphpadmin and make the following entry in 4images_users:
field: user_global_limit
type: smallint(3)
Null: No
Standard: 20 //here you can change the standard "global uploads"
(radio button click on): --- (dont know how it is called
)
2. Step:Make file:
credits.php in your 4images folder and insert (make changes where i commented out):
<?php
/**************************************************************************
* *
* 4images - A Web Based Image Gallery Management System *
* ---------------------------------------------------------------- *
* *
* File: credits.php *
* Copyright: (C) 2002 Jan Sorgalla *
* Email: jan@4homepages.de *
* Web: http://www.4homepages.de *
* Scriptversion: 1.7.1 *
* *
* Never released without support from: Nicky (http://www.nicky.net) *
* *
**************************************************************************
* *
* Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz- *
* bedingungen (Lizenz.txt) für weitere Informationen. *
* --------------------------------------------------------------- *
* This script is NOT freeware! Please read the Copyright Notice *
* (Licence.txt) for further information. *
* *
*************************************************************************/
$main_template = "credits";
define('GET_CACHES', 1);
define('ROOT_PATH', './');
include(ROOT_PATH.'global.php');
require(ROOT_PATH.'includes/sessions.php');
$user_access = get_permission();
include(ROOT_PATH.'includes/page_header.php');
$user_id = $user_info['user_id'];
$user_name = $user_info['user_name'];
if ($user_info['user_level'] >= USER) {
$sql = "SELECT user_comments AS comments
FROM ".USERS_TABLE."
WHERE ".get_user_table_field("", "user_id")." = $user_id";
$row = $site_db->query_firstrow($sql);
$comments = (isset($row['comments'])) ? $row['comments'] : 0;
$user_pscomments = "<B> ".$row['comments']."</B>\n";
$site_template->register_vars("user_pscomments", $user_pscomments);
$sql2 = "SELECT COUNT(image_id) AS totimg
FROM ".IMAGES_TABLE."
WHERE ".get_user_table_field("", "user_id")." = $user_id";
$row2 = $site_db->query_firstrow($sql2);
$totimg = (isset($row2['totimg'])) ? $row2['totimg'] : 0;
$user_psimages = "<B> ".$row2['totimg']."</B>\n";
$site_template->register_vars("user_psimages", $user_psimages);
$sql3 = "SELECT user_posts AS posts
FROM ".USERS_TABLE."
WHERE ".get_user_table_field("", "user_id")." = $user_id";
$row3 = $site_db->query_firstrow($sql3);
$posts = (isset($row3['posts'])) ? $row3['posts'] : 0;
$user_posts = "<B> ".$row3['posts']."</B>\n";
$site_template->register_vars("user_posts", $user_posts);
$sql4 = "SELECT round(avg(image_rating),2) AS rating
FROM " .IMAGES_TABLE."
WHERE ".get_user_table_field("", "user_id")." = $user_id AND image_rating > 0";
$row4 = $site_db->query_firstrow($sql4);
$rating = (isset($row4['rating'])) ? $row4['rating'] : 0;
if($row2['totimg'] <> 0) {
$psrating = $row4['rating'];}
else {
$psrating="0";
}
$site_template->register_vars("psrating", $psrating);
$sql5 = "SELECT user_global_limit AS globallimit
FROM ".USERS_TABLE."
WHERE ".get_user_table_field("", "user_id")." = $user_id";
$row5 = $site_db->query_firstrow($sql5);
$limit = (isset($row5['globallimit'])) ? $row5['globallimit'] : 0;
$user_global_limitges = $row5['globallimit'] ;
$site_template->register_vars("user_global_limitges", $user_global_limitges);
$sql6 = "SELECT COUNT(image_rating) AS votedimages
FROM ".IMAGES_TABLE."
WHERE ".get_user_table_field("", "user_id")." = $user_id AND image_rating > 0";
$row6 = $site_db->query_firstrow($sql6);
$votedimages = (isset($row6['votedimages'])) ? $row6['votedimages'] : 0;
$user_votedimages = $row6['votedimages'];
$site_template->register_vars("user_votedimages", $user_votedimages);
if ($row6['votedimages'] <> 0){
$ratingpoints= round($row4['rating'] *25/$row6['votedimages'],0);
}else{
$ratingpoints= 0;
}
$postpoints= $row3['posts'] * 5; //Change points for posts here
$imagepoints= $row2['totimg'] * 5; //Change points for images here
$commentpoints= $row['comments'] * 5; //Change points for comments here
$totalpoints= $commentpoints + $imagepoints + $postpoints + $ratingpoints;
$zusatzuploads= round($totalpoints/50,0);
$uploadsges= $zusatzuploads + 20; //Change default global limit here
$restuploads=$uploadsges - $row2['totimg'];
$sql = "
UPDATE ".USERS_TABLE."
SET user_global_limit = 20 + '$zusatzuploads'
WHERE ".get_user_table_field("", "user_id")." = $user_id";
$site_db->query($sql);
}
$site_template->register_vars(array(
"user_psname" => $user_name,
"commentpoints" => $commentpoints,
"totalpoints" => $totalpoints,
"imagepoints" => $imagepoints,
"postpoints" => $postpoints,
"ratingpoints" => $ratingpoints,
"zusatzuploads" => $zusatzuploads,
"uploadsges" => $uploadsges,
"restuploads" => $restuploads
));
$site_template->print_template($site_template->parse_template($main_template));
include(ROOT_PATH.'includes/page_footer.php');
?>
3. Step:create new file called credits.html (in template folder) from your template and insert this table:
<table class="head1" width="600" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="367">Credits from {user_psname} </td>
<td width="133"> </td>
</tr>
<tr>
<td height="36">You have written {user_pscomments} comments and get: </td>
<td><div align="center">{commentpoints} Points</div></td>
</tr>
<tr>
<td height="24" colspan="2"><hr size="1"></td>
</tr>
<tr>
<td height="23">You have uploaded {user_psimages} Images and get for that:</td>
<td><div align="center">{imagepoints} Points</div></td>
</tr>
<tr>
<td height="24" colspan="2"><hr size="1"></td>
</tr>
<tr>
<td height="20">You have posted {user_posts} Posts in the Forum and get: </td>
<td><div align="center">{postpoints} Points</div></td>
</tr>
<tr>
<td height="20" colspan="2"><div align="center">
<hr size="1">
</div></td>
</tr>
<tr>
<td>Your images are rated with an average of {psrating}, and for this you get:</td>
<td><div align="center">{ratingpoints} Points </div></td>
</tr>
<tr>
<td height="20" colspan="2"><div align="center">
<hr size="1">
<hr size="1">
</div></td>
</tr>
<tr>
<td>Your Points:</td>
<td><div align="center">{totalpoints} </div></td>
</tr>
<tr>
<td>Additional Uploads for your points: </td>
<td><div align="center">{zusatzuploads}</div></td>
</tr>
<tr>
<td>Your global upload Limit (images) </td>
<td><div align="center">{uploadsges}</div></td>
</tr>
<tr>
<td>Your allready uploaded images: </td>
<td><div align="center">{user_psimages}</div></td>
</tr>
<tr>
<td> </td>
<td><div align="center"></div></td>
</tr>
<tr>
<td colspan="2"><div align="right">You can upload: {restuploads} images.</div></td>
</tr>
</table>
4. Step:in member.php find: ( attention: only availlable if MOD user upload limits is installed!!!)
function check_picture_limit($user_id) {
global $site_db, $site_template;
$sql = "SELECT user_limit FROM ".USERS_TABLE." WHERE user_id = $user_id";
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
$upload_limit = ($row['user_limit']);
$site_template->register_vars("upload_limit", $upload_limit);
$sql = "SELECT image_id FROM ".IMAGES_TABLE." WHERE user_id=$user_id";
$result = $site_db->query($sql);
$images_per_user = $site_db->get_numrows($result);
// $sql = "SELECT image_id FROM ".IMAGES_TEMP_TABLE." WHERE user_id=$user_id";
// $result = $site_db->query($sql);
// $tmp_images_per_user = $site_db->get_numrows($result);
// $images_per_user = $tmp_images_per_user + $images_per_user;
// Uncomment above four lines if you also want to check uploaded but not yet validated images against the user limit
$site_template->register_vars("images_per_user", $images_per_user);
if($images_per_user >= $upload_limit) {
return false;
} else {
return true;
}
}
and replace with:
function check_picture_limit($user_id) {
global $site_db, $site_template;
$sql = "SELECT user_global_limit FROM ".USERS_TABLE." WHERE user_id = $user_id";
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
$global_upload_limit = ($row['user_global_limit']);
$site_template->register_vars("global_upload_limit", $global_upload_limit);
$sql = "SELECT image_id FROM ".IMAGES_TABLE." WHERE user_id=$user_id";
$result = $site_db->query($sql);
$globalimages_per_user = $site_db->get_numrows($result);
$sql = "SELECT image_id FROM ".IMAGES_TEMP_TABLE." WHERE user_id=$user_id";
$result = $site_db->query($sql);
$tmp_images_per_user = $site_db->get_numrows($result);
$globalimages_per_user = $tmp_images_per_user + $globalimages_per_user;
// Uncomment above four lines if you also want to check uploaded but not yet validated images against the user limit
$site_template->register_vars("globalimages_per_user", $globalimages_per_user);
if($globalimages_per_user >= $global_upload_limit) {
return false;
} else {
return true;
}
}
find:
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_picture_limit($user_id))) {
// if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_daily_picture_limit($user_id))) {
//
// Depending on your requirements, you can either check against global or daily limit. For global check leave it as it is now.
// For daily limit comment first line and uncomment second one.
//
$site_template->print_template($site_template->parse_template("over_limit"));
include(ROOT_PATH.'includes/page_footer.php');
exit;
}
and replace with:
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_picture_limit($user_id))) {
$site_template->print_template($site_template->parse_template("over_limit2"));
include(ROOT_PATH.'includes/page_footer.php');
exit;
}
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_daily_picture_limit($user_id))) {
$site_template->print_template($site_template->parse_template("over_limit"));
include(ROOT_PATH.'includes/page_footer.php');
exit;
}
5. Step:open from template folder: over_limit.html
delete:
{lang_no_limits}
{lang_no_limits_text}
{lang_show_my_images}
and insert any message you want (if users are on their global limt) and save it as
over_limit2.html6. Step:open in your template folder user_logininfo.html and find:
<a href="{url_lightbox}">{lang_lightbox}</a><br>
after that add:
<a href="/credits.php">My Points</a><br />
Save and upload all files. It should work
---------------------------------------------------------------------------
If you dont have installed Dreamboard do as follows:
Delete from credits.php:
$sql3 = "SELECT user_posts AS posts
FROM ".USERS_TABLE."
WHERE ".get_user_table_field("", "user_id")." = $user_id";
$row3 = $site_db->query_firstrow($sql3);
$posts = (isset($row3['posts'])) ? $row3['posts'] : 0;
$user_posts = "<B> ".$row3['posts']."</B>\n";
$site_template->register_vars("user_posts", $user_posts);
$postpoints= $row3['posts'] * 5; //Punkte für Posts hier eintragen
+ $postpoints
In credits.html delete from the table code:
<tr>
<td height="20">You have posted {user_posts} Posts in the Forum and get: </td>
<td><div align="center">{postpoints} Points</div></td>
</tr>
<tr>
<td height="20" colspan="2"><div align="center">
<hr size="1">
</div></td>
</tr>
<tr>
Done.
------------------------------------------------------
Question so someone who is really able to code php:
My problem with this is, that the database entry only gets updated, if credits.php will be opened.
How can i fix this?
Maybe i could add to index.php:
include(ROOT_PATH.'credits.php');
and:
$sql = "
UPDATE ".USERS_TABLE."
SET user_global_limit = 20 + '$zusatzuploads'
WHERE ".get_user_table_field("", "user_id")." = $user_id";
$site_db->query($sql);
}
Will that work?
Greez Egly