We are using paFileDB (this is a file download system, were you can place files in categories and have everything list as a downloadable file within it's appropriate category) with PHP Nuke and have successfully integrated them to limit the general downloading of files by a user's permissions. I am now trying to limit the actual number of files download based on the user's permissions, but the code I have added to download.php is not working. I have been able to pinpoint the area in the script that is causing me issues and it is as below:
if (($id != '97') || ($id != '98') || ($id != '99')) {
//Pull user id from cookie
$xnum = $HTTP_COOKIE_VARS['bbuserid'];
//Connect to database server
$dbcnx = @mysql_connect($db[host], $db[user], $db[pass]);
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
}
//Select the database
if (! @mysql_select_db($db[name]) ) {
die( '<p>Unable to locate the nuke ' .
'database at this time.</p>' );
}
//Get number of downloads for current member
$query = "SELECT usergroupid, filedownloads FROM user WHERE user.userid = $xnum;";
$result = mysql_query($query);
$total_downloads = mysql_fetch_array($result);
//If the user has a Monthly Membership
if ($total_downloads['$usergroupid'] == 10) {
if ($total_downloads == 5) { //if downloads are 5
//Deny user download and redirect to upgrade page
} else { //if downloads are less than 5
//Allow user to download file
//Increment file counter by 1
$total_downloads++;
//Update file counter field in database
$query = "UPDATE user SET filedownloads = $total_downloads WHERE user.userid = $xnum;";
$result = mysql_query($query);
$file = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_files WHERE file_id = '$id'", 1);
$time = time();
$update = $pafiledb_sql->query($db, "UPDATE $db[prefix]_files SET file_dls=file_dls+1, file_last=$time WHERE file_id = '$id'", 0);
header("Location: $file[file_dlurl]");
}
}
} else {
$file = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_files WHERE file_id = '$id'", 1);
$time = time();
$update = $pafiledb_sql->query($db, "UPDATE $db[prefix]_files SET file_dls=file_dls+1, file_last=$time WHERE file_id = '$id'", 0);
header("Location: $file[file_dlurl]");
}
The 97, 98, and 99 are the actual id numbers for files that should not count to the total download limit. I want to be able to update a counter in another database to control the downloads per user.
Right now... it SEEMS that the script is not connecting to the non-paFileDB database to update the counter field. Although, I happen to know that the script has successfully connected to the database because I have been able to test the following code and it does its job successfully within the same file:
if ($config[15] != date(M)) {
//Update month in database
$config[15] = date(M);
$pafiledb_sql->query($db, "UPDATE $db[prefix]_settings SET settings_month = '$config[15]' WHERE settings_id = '1'", 0);
//Reset file downloads for all Monthly Members
$query = "UPDATE user SET filedownloads = 0 WHERE usergroupid = 10;";
$result = mysql_query($query);
}
'm just frustrated because there doesn't seem to be a way to check the contents of my variables. Each time I try to print out to the page, I get a blank page with HEAD and BODY tags. (After looking at this more last night, I believe this has something to do with the header() function, which I'm reading up on since I have never really used it myself...)
I could use any help our insight that anyone can give. If I have not explained my problem clearly enough, please let me know and I will attempt to elaborate.
Thanks!