Skip to content

Commit

Permalink
Merge pull request #32 from UofS-Pulse-Binfo/Issue-#31---Page-redirec…
Browse files Browse the repository at this point in the history
…t,-Non-MS-Excel-spreadsheet-and-Stage-2-and-3-errors

Issue #31 - Bug fixes
  • Loading branch information
laceysanderson authored Apr 6, 2018
2 parents d6805cf + 8e540ea commit bb30062
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
15 changes: 10 additions & 5 deletions include/rawpheno.admin.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ function rawpheno_admin_all_projects_submit($form, &$form_state) {


// Redirect user to project asset management page.
$path = url('../../admin/tripal/extension/rawphenotypes/all_projects/' . $project_id . '/project/manage');
$path = url($GLOBALS['base_url'] . '/admin/tripal/extension/rawphenotypes/all_projects/' . $project_id . '/project/manage');
drupal_goto($path);
}

Expand Down Expand Up @@ -1369,7 +1369,7 @@ function rawpheno_admin_project_headers($form, $form_state, $header_asset, $acti
}
}
elseif ($action == 'delete') {
$path = url('../../admin/tripal/extension/rawphenotypes/all_projects/' . $header_asset['in_project_id'] . '/project/manage');
$path = url($GLOBALS['base_url'] . '/admin/tripal/extension/rawphenotypes/all_projects/' . $header_asset['in_project_id'] . '/project/manage');

// Admin wants to delete/remove the trait from the project.
db_delete('pheno_project_cvterm')
Expand Down Expand Up @@ -1630,7 +1630,7 @@ function rawpheno_admin_project_management_submit($form, &$form_state) {
*/
function rawpheno_admin_project_users($form, $form_state, $user_project_asset, $action) {
if ($action == 'delete') {
$path = url('../../admin/tripal/extension/rawphenotypes/all_projects/' . $user_project_asset['project_id'] . '/project/manage');
$path = url($GLOBALS['base_url'] . '/admin/tripal/extension/rawphenotypes/all_projects/' . $user_project_asset['project_id'] . '/project/manage');

db_delete('pheno_project_user')
->condition('project_user_id', $user_project_asset['project_user_id'])
Expand Down Expand Up @@ -1681,7 +1681,7 @@ function rawpheno_admin_project_envdata($form, $form_state, $envdata_project_ass
}

// Redirect user.
$path = url('../../admin/tripal/extension/rawphenotypes/all_projects/' . $envdata_project_asset['project_id'] . '/project/manage');
$path = url($GLOBALS['base_url'] . '/admin/tripal/extension/rawphenotypes/all_projects/' . $envdata_project_asset['project_id'] . '/project/manage');
drupal_goto($path);
}
}
Expand Down Expand Up @@ -1774,11 +1774,16 @@ function rawpheno_admin_render_form_trait($form, &$form_state, $default) {
$unit = chado_query($sql)
->fetchAllKeyed();

// Default to text unit.
$unit_keys = array_keys($unit);
$textunit = array_search('text', $unit_keys);
$textunit_id = $unit_keys[$textunit];

$form['fieldset_trait']['sel_trait_unit'] = array(
'#type' => 'select',
'#title' => t('Unit:'),
'#options' => $unit,
'#default_value' => isset($default['sel_trait_unit']) ? $default['sel_trait_unit'] : reset($unit),
'#default_value' => isset($default['sel_trait_unit']) ? $default['sel_trait_unit'] : $textunit_id,
'#disabled' => $disabled,
);

Expand Down
6 changes: 5 additions & 1 deletion include/rawpheno.upload.excel.inc
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ function rawpheno_indicate_new_headers($file, $project_id) {
// Determine if column header exists in the expected column headers.
if (!in_array($temp_value, $expected_headers) && !empty($value)) {
// Not in expected column headers, save it as new header.
$value = preg_replace('/\s+/', ' ', $value);
$new_headers[] = $value;
}
}
Expand Down Expand Up @@ -969,7 +970,10 @@ function rawpheno_count_rows($xls_obj) {
* The cvterm_id for the trait.
*/
function rawpheno_get_trait_id($header) {
$header = str_replace(array("\n", "\r", " "), ' ', $header);
// New lines.
$header = str_replace(array("\n", "\r"), ' ', $header);
// Extra spaces.
$header = preg_replace('!\s+!', ' ', $header);

// Query trait. Module stores unit in lowercase but user can use any case
// in the spreadsheet. eg Planting Date (date) and Planting Date (Date).
Expand Down
6 changes: 4 additions & 2 deletions include/rawpheno.upload.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ function rawpheno_upload_form_stage_review(&$form, &$form_state) {
);

// Clean up the current header.
$name = rawpheno_function_delformat($k);
$name = trim(strtolower(preg_replace('!\s+!', ' ', $k)));
$arr_checked_header[] = $name;

// Test if the header has a unit component and set the variable accordingly.
Expand Down Expand Up @@ -454,7 +454,7 @@ function rawpheno_upload_form_stage_review(&$form, &$form_state) {
'#description' => t('A human-readable text definition'),
);

if (isset($cvterm_info)) {
if (isset($cvterm_info) && isset($cvterm_info->definition)) {
$form['xls_review_fldset']['fldset_' . $i]['txt_def_' . $i]['#value'] = $cvterm_info->definition;
$form['xls_review_fldset']['fldset_' . $i]['txt_def_' . $i]['#disabled'] = TRUE;
}
Expand Down Expand Up @@ -1028,6 +1028,8 @@ function rawpheno_submit_review($form, &$form_state) {
// For each new header store information provided in the interface.
// Indicates if user has check this header for saving.
$header = trim(str_replace(array("\n", "\r", " "), ' ', $header));
$header = preg_replace('/\s+/', ' ', $header);

$arr_newheaders[$header]['flag'] = ($form_state['values']['chk_' . $i] == 1) ? 1 : 0;

// Determine if the form in review traits has been filled out and checkbox
Expand Down
6 changes: 5 additions & 1 deletion include/rawpheno.validation.inc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ function validator_is_excel_validate_file($file) {

// First test extension.
$xls_extension = pathinfo($file->filename, PATHINFO_EXTENSION);
if ($xls_extension == 'xlsx' OR $xls_extension == 'xls') {
$xls_mime = $file->filemime;

if (($xls_extension == 'xlsx' OR $xls_extension == 'xls') &&
($xls_mime == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
OR $xls_mime == 'application/vnd.ms-excel')) {

// Then test that the file can be opened.
// This checks against PDFs masquerading as XLS ;-).
Expand Down

0 comments on commit bb30062

Please sign in to comment.