function _user_table_action in Ubercart 5
Perform a specified action on the uc_file_users table
@return: Specified by op argument
Parameters
$op: The action to perform on uc_file_users table
- allow: insert a new file download for a user
- download: update a row after a download takes places
- remove: remove a file download for specified files, users, keys
$arg1: Specified by op argument
$arg2: Specified by op argument
$arg3: Specified by op argument
4 calls to _user_table_action()
- uc_file_order in uc_file/
uc_file.module - Implementation of hook_order().
- uc_file_user in uc_file/
uc_file.module - Implementation of hook_user().
- _file_download_transfer in uc_file/
uc_file.module - Send the file's binary data to a user via HTTP and update the uc_file_users table.
- _file_table_action in uc_file/
uc_file.module - Perform a specified action on the uc_files table
File
- uc_file/
uc_file.module, line 1519 - Allows products to be associated with downloadable files.
Code
function _user_table_action($op, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL) {
switch ($op) {
case 'allow':
//arg1 = file id, arg2 = user id, $arg3 = pfid
//@return file_user objects inserted into table
if (!is_null($arg1) && !is_null($arg2)) {
$output = array();
$granted = time();
$fids = _get_dir_file_ids($arg1) ? _get_dir_file_ids($arg1) : array(
$arg1,
);
foreach ($fids as $fid) {
$values = array(
$arg1,
$arg2,
$arg3,
'',
$granted,
0,
serialize(array()),
);
$hash = _generate_hash($values);
db_query("INSERT INTO {uc_file_users} (fid, uid, pfid, `file_key`, granted, accessed, addresses) VALUES (%d, %d, %d, '%s', %d, %d, '%s')", $fid, $arg2, $arg3, $hash, $granted, 0, serialize(array()));
$output[] = db_fetch_object(db_query("SELECT * FROM {uc_file_users} WHERE uid = %d AND `file_key` = '%s'", $arg2, $hash));
}
}
return !is_null($output) ? $output : FALSE;
break;
case 'download':
//arg1 = existing file_user object, arg2 = ip download was made from, arg3 not used
if (!is_null($arg1) && !is_null($arg2)) {
$addresses = unserialize($arg1->addresses);
if (!in_array($arg2, $addresses)) {
$addresses[] = $arg2;
}
$accessed = $arg1->accessed + 1;
$values = array(
$arg1->fid,
$arg1->uid,
$arg1->pfid,
$arg1->file_key,
$arg1->granted,
$accessed,
serialize($addresses),
);
$hash = _generate_hash($values);
db_query("UPDATE {uc_file_users} SET accessed = %d, addresses = '%s', `file_key` = '%s' WHERE fid = %d AND uid = %d AND `file_key` = '%s'", $accessed, serialize($addresses), $hash, $arg1->fid, $arg1->uid, $arg1->file_key);
}
break;
case 'remove':
//arg1 = file id, arg2 = user id, $arg3 = key
if (!is_null($arg1) || !is_null($arg2)) {
if (!is_null($arg1) && is_null($arg2) && is_null($arg3)) {
//Remove a file from download
db_query("DELETE FROM {uc_file_users} WHERE fid = %d", $arg1);
}
if (is_null($arg1) && !is_null($arg2) && is_null($arg3)) {
//Remove a user's downloads
db_query("DELETE FROM {uc_file_users} WHERE uid = %d", $arg2);
}
if (!is_null($arg1) && !is_null($arg2) && is_null($arg3)) {
//Remove a certain files from a user
db_query("DELETE FROM {uc_file_users} WHERE fid = %d AND uid = %d", $arg1, $arg2);
}
if (is_null($arg1) && !is_null($arg2) && !is_null($arg3)) {
//Remove a certain file from a user
db_query("DELETE FROM {uc_file_users} WHERE uid = %d AND `file_key` = '%s'", $arg2, $arg3);
}
}
break;
default:
break;
}
}