function uc_file_feature_form_submit in Ubercart 6.2
Same name and namespace in other branches
- 5 uc_file/uc_file.module \uc_file_feature_form_submit()
- 7.3 uc_file/uc_file.module \uc_file_feature_form_submit()
Submit handler for uc_file_feature_form().
See also
File
- uc_file/
uc_file.module, line 919
Code
function uc_file_feature_form_submit($form, &$form_state) {
global $user;
// Build the file_product object from the form values.
$file = uc_file_get_by_name($form_state['values']['uc_file_filename']);
$file_product = array(
'fid' => $file->fid,
'filename' => $file->filename,
'pfid' => $form_state['values']['pfid'],
'model' => $form_state['values']['uc_file_model'],
'description' => $form_state['values']['uc_file_description'],
'shippable' => $form_state['values']['uc_file_shippable'],
// Local limitations... set them if there's an override.
'download_limit' => $form_state['values']['download_override'] ? $form_state['values']['download_limit_number'] : UC_FILE_LIMIT_SENTINEL,
'address_limit' => $form_state['values']['location_override'] ? $form_state['values']['download_limit_addresses'] : UC_FILE_LIMIT_SENTINEL,
'time_granularity' => $form_state['values']['time_override'] ? $form_state['values']['download_limit_duration_granularity'] : UC_FILE_LIMIT_SENTINEL,
'time_quantity' => $form_state['values']['time_override'] ? $form_state['values']['download_limit_duration_qty'] : UC_FILE_LIMIT_SENTINEL,
);
// Build product feature descriptions.
$description = t('<strong>SKU:</strong> !sku<br />', array(
'!sku' => empty($file_product['model']) ? 'Any' : $file_product['model'],
));
if (is_dir(variable_get('uc_file_base_dir', NULL) . "/" . $file_product['filename'])) {
$description .= t('<strong>Directory:</strong> !dir<br />', array(
'!dir' => $file_product['filename'],
));
}
else {
$description .= t('<strong>File:</strong> !file<br />', array(
'!file' => basename($file_product['filename']),
));
}
$description .= $file_product['shippable'] ? t('<strong>Shippable:</strong> Yes') : t('<strong>Shippable:</strong> No');
$data = array(
'pfid' => $file_product['pfid'],
'nid' => $form_state['values']['nid'],
'fid' => 'file',
'description' => $description,
);
// TODO: Pass $data byref so that we can use drupal_write_record within and automatically return the pfid.
$form_state['redirect'] = uc_product_feature_save($data);
// Insert or update uc_file_product table
if (empty($file_product['pfid'])) {
$file_product['pfid'] = db_last_insert_id('uc_product_features', 'pfid');
}
$key = NULL;
if ($fpid = _uc_file_get_fpid($file_product['pfid'])) {
$key = 'fpid';
$file_product['fpid'] = $fpid;
}
drupal_write_record('uc_file_products', $file_product, $key);
}