function uc_file_user_form_submit in Ubercart 6.2
Same name and namespace in other branches
- 7.3 uc_file/uc_file.module \uc_file_user_form_submit()
Submit handler for per-user file download administration.
File
- uc_file/
uc_file.module, line 317
Code
function uc_file_user_form_submit($form, &$form_state) {
$account = $form['#parameters'][2];
$edit = $form_state['values'];
// Check out if any downloads were modified.
if (isset($edit['file_download'])) {
foreach ((array) $edit['file_download'] as $fid => $download_modification) {
// Remove this user download?
if ($download_modification['remove']) {
uc_file_remove_user_file_by_id($account, $fid);
}
else {
// Calculate the new expiration.
$download_modification['expiration'] = _uc_file_expiration_date($download_modification, $download_modification['expiration']);
// Don't touch anything if everything's the same.
if ($download_modification['download_limit'] == $download_modification['download_limit_old'] && $download_modification['address_limit'] == $download_modification['address_limit_old'] && $download_modification['expiration'] == $download_modification['expiration_old']) {
continue;
}
// Renew. (Explicit overwrite)
uc_file_user_renew($fid, $account, NULL, $download_modification, TRUE);
}
}
}
// Check out if any downloads were added. We pass NULL to file_user_renew,
// because this shouldn't be associated with a random product.
if (isset($edit['file_add'])) {
foreach ((array) $edit['file_add'] as $fid => $data) {
$download_modification['download_limit'] = variable_get('uc_file_download_limit_number', NULL);
$download_modification['address_limit'] = variable_get('uc_file_download_limit_addresses', NULL);
$download_modification['expiration'] = _uc_file_expiration_date(array(
'time_polarity' => '+',
'time_quantity' => variable_get('uc_file_download_limit_duration_qty', NULL),
'time_granularity' => variable_get('uc_file_download_limit_duration_granularity', 'never'),
), time());
// Renew. (Explicit overwrite)
uc_file_user_renew($fid, $account, NULL, $download_modification, TRUE);
}
}
}