diff options
author | Sashi20 | 2024-08-05 11:30:29 +0530 |
---|---|---|
committer | GitHub | 2024-08-05 11:30:29 +0530 |
commit | 8fc5ee962cb8a29f458b354e1ca9676b02ff5fef (patch) | |
tree | ef9b2342a27630cedbded12008cc65fef49d1268 | |
parent | a2dc9e540c3392163862b4fd6e7a120b3d2e54b0 (diff) | |
parent | 3e4125b2568cdc8467e0f949560986ae7e722990 (diff) | |
download | cfd_lab_migration-8fc5ee962cb8a29f458b354e1ca9676b02ff5fef.tar.gz cfd_lab_migration-8fc5ee962cb8a29f458b354e1ca9676b02ff5fef.tar.bz2 cfd_lab_migration-8fc5ee962cb8a29f458b354e1ca9676b02ff5fef.zip |
Display list of experiments from the completed labs page, add field in proposal form for problem statement
-rwxr-xr-x | download.inc | 12 | ||||
-rw-r--r-- | experiments_list.inc | 455 | ||||
-rwxr-xr-x | lab_details.inc | 10 | ||||
-rwxr-xr-x | lab_migration.module | 32 | ||||
-rwxr-xr-x | manage_proposal.inc | 141 | ||||
-rwxr-xr-x | proposal.inc | 82 | ||||
-rwxr-xr-x | run.inc | 172 | ||||
-rwxr-xr-x | settings.inc | 36 | ||||
-rwxr-xr-x | solution_proposal.inc | 8 | ||||
-rwxr-xr-x | upload_code.inc | 49 |
10 files changed, 769 insertions, 228 deletions
diff --git a/download.inc b/download.inc index f16cf0f..821025b 100755 --- a/download.inc +++ b/download.inc @@ -18,6 +18,18 @@ function lab_migration_download_solution_file() header('Content-Length: ' . filesize($root_path . $solution_file_data->directory_name . '/' . $solution_file_data->filepath)); readfile($root_path . $solution_file_data->directory_name . '/' . $solution_file_data->filepath); } + function lab_migration_download_problem_statement() + { + $proposal_id = arg(3); + $root_path = lab_migration_path(); + $proposal_q = db_query("SELECT lmp.* FROM lab_migration_proposal lmp WHERE lmp.id = :proposal_id LIMIT 1", array(':proposal_id' => $proposal_id)); + $proposal_data = $proposal_q->fetchObject(); + header('Content-Type: doc'); + //header('Content-Type: application/octet-stram'); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', ($proposal_data->problem_statement_file)) . '"'); + header('Content-Length: ' . filesize($root_path . $proposal_data->directory_name . '/' . $proposal_data->problem_statement_file)); + readfile($root_path . $proposal_data->directory_name . '/' . $proposal_data->problem_statement_file); + } function lab_migration_download_dependency_file() { $dependency_file_id = arg(3); diff --git a/experiments_list.inc b/experiments_list.inc new file mode 100644 index 0000000..7d63fea --- /dev/null +++ b/experiments_list.inc @@ -0,0 +1,455 @@ +<?php +function lab_migration_experiments_list($form, &$form_state) + { + $options_first = _list_of_labs(); + $options_two = _ajax_get_experiments_list(); + $select_two = isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : key($options_two); + $url_lab_id = (int) arg(2); + if (!$url_lab_id) + { + $selected = isset($form_state['values']['lab']) ? $form_state['values']['lab'] : key($options_first); + } + elseif ($url_lab_id == '') + { + $selected = 0; + } + else + { + $selected = $url_lab_id; + ; + } + $form = array(); + $form['lab'] = array( + '#type' => 'select', + '#title' => t('Title of the lab'), + '#options' => _list_of_labs(), + '#default_value' => $selected, + '#ajax' => array( + 'callback' => 'ajax_experiments_list_callback' + ) + ); + if (!$url_lab_id) + { + $form['selected_lab'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_selected_lab"></div>' + ); + $form['selected_lab_cfd'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_selected_lab_cfd"></div>' + ); + $form['selected_lab_pdf'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_selected_lab_pdf"></div>' + ); + /* $form['lab_details'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_lab_details"></div>' + );*/ + $form['lab_experiment_list'] = array( + '#type' => 'item', + '#title' => t('Title of the experiment'), + '#markup' => _ajax_get_experiments_list($selected), + //'#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '',s + '#prefix' => '<div id="ajax_selected_experiment">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + } + else + { + $lab_default_value = $url_lab_id; + $form['selected_lab'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_selected_lab">' . l('Download Lab Solutions', 'lab-migration/download/lab/' . $lab_default_value) . '</div>' + ); + /* $form['selected_lab_pdf'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_selected_lab_pdf">'. l('Download PDF of Lab Solutions', 'lab-migration/generate-lab/' . $lab_default_value . '/1') .'</div>', + + );*/ + if ($lab_default_value == '2') + { + $form['selected_lab_cfd'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_selected_lab_cfd">' . l('Download Lab Solutions (OpenFOAM Version)', 'lab-migration-uploads/OpenFOAM_Version.zip') . '</div>' + ); + } + /* $form['lab_details'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_lab_details">' . _lab_details($lab_default_value) . '</div>' + );*/ + $form['lab_experiment_list'] = array( + '#type' => 'item', + '#title' => t('Titile of the experiment'), + //'#options' => _ajax_get_experiments_list($selected), + '#markup' => _ajax_get_experiments_list($lab_default_value), + // '#default_value' => isset($form_state['values']['lab_experiment_list']) ? //$form_state['values']['lab_experiment_list'] : '', + '#prefix' => '<div id="ajax_selected_experiment">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + } + /* + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('If Dis-Approved please specify reason for Dis-Approval'), + '#prefix' => '<div id= "message_submit">', + '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0,),),), + + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + '#suffix' => '</div>', + '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0,),),), + + );*/ + return $form; + } +function ajax_experiments_list_callback($form, $form_state) + { + $commands = array(); + $lab_default_value = $form_state['values']['lab']; + if ($lab_default_value != 0) + { + $form['lab_details']['#markup'] = _lab_details($lab_default_value); + $lab_details = _lab_information($lab_default_value); + $user_solution_provider = user_load($lab_details->solution_provider_uid); + //var_dump($lab_details->solution_provider_uid); + if ($lab_details->solution_provider_uid > 0) + { + $commands[] = ajax_command_html('#ajax_selected_lab', l('Download Lab Solutions', 'lab-migration/download/lab/' . $lab_default_value)); + if ($lab_default_value == '2') + { + $commands[] = ajax_command_html('#ajax_selected_lab_cfd', l('Download Lab Solutions (OpenFOAM Version)', 'lab-migration_uploads/OpenFOAM_Version.zip')); + } + /* $commands[] = ajax_command_html('#ajax_selected_lab_pdf', l('Download PDF of Lab Solutions', 'lab-migration/generate-lab/' . $lab_default_value . '/1'));*/ + } + else + { + $commands[] = ajax_command_html('#ajax_selected_lab', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_pdf', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_cfd', ''); + } + $commands[] = ajax_command_html('#ajax_lab_details', _lab_details($lab_default_value)); + $form['lab_experiment_list']['#markup'] = _ajax_get_experiments_list($lab_default_value); + $commands[] = ajax_command_replace('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + } + else + { + $form['lab_experiment_list']['#markup'] = _ajax_get_experiments_list(); + $commands[] = ajax_command_replace('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + $commands[] = ajax_command_html('#ajax_lab_details', ''); + $commands[] = ajax_command_html('#ajax_selected_lab', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_cfd', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_pdf', ''); + $commands[] = ajax_command_data('#ajax_selected_lab', 'form_state_value_select', $form_state['values']['lab']); + $commands[] = ajax_command_html('#ajax_selected_experiment', ''); + $commands[] = ajax_command_html('#ajax_download_experiments', ''); + $commands[] = ajax_command_html('#ajax_selected_solution', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +function ajax_solution_list_callback($form, $form_state) + { + $commands = array(); + $experiment_list_default_value = $form_state['values']['lab_experiment_list']; + //var_dump($lab_default_value); + if ($experiment_list_default_value != 0) + { + $form['lab_solution_list']['#options'] = _ajax_get_solution_list($experiment_list_default_value); + $commands[] = ajax_command_html('#ajax_download_experiments', l('Download Experiment', 'lab-migration/download/experiment/' . $experiment_list_default_value)); + $commands[] = ajax_command_html('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); + // $commands[] = ajax_command_html('#ajax_solution_files', ''); + // $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + // $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + } + else + { + $form['lab_solution_list']['#options'] = _ajax_get_solution_list(); + $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); + $commands[] = ajax_command_html('#ajax_download_experiments', ''); + $commands[] = ajax_command_html('#ajax_selected_solution', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + // $commands[] = ajax_command_replace('#ajax_selected_experiment',drupal_render($form['lab_experiment_list'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +function ajax_solution_files_callback($form, $form_state) + { + $commands = array(); + $solution_list_default_value = $form_state['values']['lab_solution_list']; + //var_dump($lab_default_value); + if ($solution_list_default_value != 0) + { + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', drupal_render($form['lab_experiment_solution_actions'])); + /*************************************************************************************/ + //$solution_list_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $form_state['values']['solution']); + $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_list_default_value); + $solution_list_q = $query->execute(); + if ($solution_list_q) + { + $solution_files_rows = array(); + while ($solution_list_data = $solution_list_q->fetchObject()) + { + $solution_file_type = ''; + switch ($solution_list_data->filetype) + { + case 'S': + $solution_file_type = 'Source or Main file'; + break; + case 'R': + $solution_file_type = 'Result file'; + break; + case 'X': + $solution_file_type = 'xcos file'; + break; + default: + $solution_file_type = 'Unknown'; + break; + } + $solution_files_rows[] = array( + l($solution_list_data->filename, 'lab-migration/download/file/' . $solution_list_data->id), + $solution_file_type + ); + } + /* dependency files */ + //$dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $form_state['values']['solution']); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_list_default_value); + $dependency_q = $query->execute(); + while ($dependency_data = $dependency_q->fetchObject()) + { + //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_data->dependency_id); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $dependency_data->dependency_id); + $dependency_files_q = $query->execute(); + $dependency_files_data = $dependency_files_q->fetchObject(); + $solution_file_type = 'Dependency file'; + $solution_files_rows[] = array( + l($dependency_files_data->filename, 'lab-migration/download/dependency/' . $dependency_files_data->id), + $solution_file_type + ); + } + /* creating list of files table */ + $solution_files_header = array( + 'Filename', + 'Type' + ); + $solution_files = theme('table', array( + 'header' => $solution_files_header, + 'rows' => $solution_files_rows + )); + } + $form['solution_files']['#title'] = 'List of solution files'; + $form['solution_files']['#markup'] = $solution_files; + $commands[] = ajax_command_html('#ajax_download_experiment_solution', l('Download Solution', 'lab-migration/download/solution/' . $solution_list_default_value)); + // $commands[] = ajax_command_html('#ajax_edit_experiment_solution', l('Edit Solution', 'code_approval/editcode/' . $solution_list_default_value)); + // $commands[] = ajax_command_html('#ajax_solution_files', $solution_files); + $commands[] = ajax_command_html('#ajax_solution_files', drupal_render($form['solution_files'])); + } + else + { + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +function bootstrap_table_format($headers, $rows) + { + $thead = ""; + $tbody = ""; + foreach ($headers as $header) + { + $thead .= "<th>{$header}</th>"; + } + foreach ($rows as $row) + { + $tbody .= "<tr>"; + foreach ($row as $data) + { + $tbody .= "<td>{$data}</td>"; + } + $tbody .= "</tr>"; + } + $table = " + <table class='table table-bordered table-hover' style='margin-left:-140px'> + <thead>{$thead}</thead> + <tbody>{$tbody}</tbody> + </table> + "; + return $table; + } +/*****************************************************/ +function _list_of_labs() + { + $lab_titles = array( + '0' => 'Please select...' + ); + //$lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_display = 1 ORDER BY lab_title ASC"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('solution_display', 1); + $query->condition('approval_status', 3); + $query->orderBy('lab_title', 'ASC'); + $lab_titles_q = $query->execute(); + while ($lab_titles_data = $lab_titles_q->fetchObject()) + { + $lab_titles[$lab_titles_data->id] = $lab_titles_data->lab_title . ' (Proposed by ' . $lab_titles_data->name_title .' '.$lab_titles_data->name . ')'; + } + return $lab_titles; + } +function _ajax_get_experiments_list($lab_default_value = '') + { + $experiments = array( + '0' => 'Please select...' + ); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $lab_default_value); + $query->orderBy('lab_title', 'ASC'); + $lab_titles_q = $query->execute(); + $lab_titles_data = $lab_titles_q->fetchObject(); + //$experiments_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number ASC", $proposal_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $lab_default_value); + $query->orderBy('number', 'ASC'); + $experiments_q = $query->execute(); + $solution_provider_user_name = ''; + $user_data = user_load($proposal_data->solution_provider_uid); + if ($user_data) + { + $solution_provider_user_name = $user_data->name; + } + else + { + $solution_provider_user_name = $lab_titles_data->name; + } + while ($experiments_data = $experiments_q->fetchObject()) + { + $pending_solution_rows[] = array( + $lab_titles_data->lab_title, + $experiments_data->title, + l('View Solution', 'lab-migration/lab-migration-run/' . $lab_titles_data->id . '/' . $experiments_data->id) + ); + } + $header = array( + 'Title of the Lab', + 'Experiment', + 'Actions' + ); + //$output = theme_table($header, $pending_solution_rows); + $output = theme('table', array( + 'header' => $header, + 'rows' => $pending_solution_rows + )); + return $output; + } +function _ajax_get_solution_list($lab_experiment_list = '') + { + $solutions = array( + '0' => 'Please select...' + ); + // $solutions_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d ORDER BY + // CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY) ASC, + // CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED) ASC, + // CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED) ASC", $experiment_id); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $lab_experiment_list); + //$query->orderBy("CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY", "ASC"); + // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED", "ASC"); + // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED", "ASC"); + $solutions_q = $query->execute(); + while ($solutions_data = $solutions_q->fetchObject()) + { + $solutions[$solutions_data->id] = $solutions_data->code_number . ' (' . $solutions_data->caption . ')'; + } + return $solutions; + } +function _lab_information($proposal_id) + { + //$lab_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $query->condition('approval_status', 3); + $lab_q = $query->execute(); + $lab_data = $lab_q->fetchObject(); + if($lab_data){ + return $lab_data; + } + else + { + return ; + } + + } +function _lab_details($lab_default_value) + { + //$lab_default_value = $form_state['values']['lab']; + $lab_details = _lab_information($lab_default_value); + if ($lab_default_value != 0) + { + if ($lab_details){ + if ($lab_details->solution_provider_uid > 0) + { + $user_solution_provider = user_load($lab_details->solution_provider_uid); + if ($user_solution_provider) + { + $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Solution Provider Name:</strong> ' . $lab_details->solution_provider_name_title . ' ' . $lab_details->solution_provider_name . '</li>' . '<li><strong>Department:</strong> ' . $lab_details->solution_provider_department . '</li>' . '<li><strong>University:</strong> ' . $lab_details->solution_provider_university . '</li>' . '</ul>'; + } + else + { + $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Solution Provider: </strong> (Open) </li>' . '</ul>'; + } + } + else + { + $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Solution Provider: </strong> (Open) </li>' . '</ul>'; + }} + else{ + drupal_goto('lab-migration/lab-migration-run'); + + } + $form['lab_details']['#markup'] = '<span style="color: rgb(128, 0, 0);"><strong>About the Lab</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Proposer Name:</strong> ' . $lab_details->name_title . ' ' . $lab_details->name . '</li>' . '<li><strong>Title of the Lab:</strong> ' . $lab_details->lab_title . '</li>' . '<li><strong>Department:</strong> ' . $lab_details->department . '</li>' . '<li><strong>University:</strong> ' . $lab_details->university . '</li>' . '<li><strong>Category:</strong> ' . $lab_details->category . '</li>' . '</ul>' . $solution_provider; + $details = $form['lab_details']['#markup']; + return $details; + } + } diff --git a/lab_details.inc b/lab_details.inc index 898b504..bd270f7 100755 --- a/lab_details.inc +++ b/lab_details.inc @@ -20,10 +20,17 @@ function lab_migration_completed_labs_all() while ($row = $result->fetchObject()) { $approval_date = date("Y", $row->approval_date); + if($row->problem_statement_file == ''){ + $problem_statement_file = "NA"; + } + else{ + $problem_statement_file = l('View', 'lab-migration/download/problem-statement/' . $row->id); + } $preference_rows[] = array( $i, $row->university, - l($row->lab_title, "lab-migration/lab-migration-run/" . $row->id), + l($row->lab_title, "lab-migration/experiments-list/" . $row->id), + $problem_statement_file, $approval_date ); $i--; @@ -32,6 +39,7 @@ function lab_migration_completed_labs_all() 'No', 'Institute', 'Lab', + 'Problem Statement', 'Year' ); $output .= theme('table', array( diff --git a/lab_migration.module b/lab_migration.module index fb03977..68d849f 100755 --- a/lab_migration.module +++ b/lab_migration.module @@ -341,14 +341,16 @@ function lab_migration_menu() 'type' => MENU_CALLBACK, 'file' => 'download.inc' ); - /*$items['lab_migration/download/dependency'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'lab_migration_download_dependency_file', - 'access arguments' => array('lab migration download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - );*/ + $items['lab-migration/download/problem-statement'] = array( + 'title' => 'Download Problem Statement', + 'description' => 'Download Problem Statement', + 'page callback' => 'lab_migration_download_problem_statement', + 'access arguments' => array( + 'lab migration download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); $items['lab-migration/download/solution'] = array( 'title' => 'Code Download', 'description' => 'Code Download', @@ -408,6 +410,18 @@ function lab_migration_menu() ), 'file' => 'lab_details.inc' ); + $items['lab-migration/experiments-list'] = array( + 'title' => 'Download Codes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_experiments_list' + ), + 'access arguments' => array( + 'lab migration download code' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'experiments_list.inc' + ); /* LABS IN PROGRESS */ $items['lab-migration/labs-progress'] = array( 'title' => 'Labs in Progress', @@ -715,7 +729,7 @@ function lab_migration_ajax() /*************************** VALIDATION FUNCTIONS *****************************/ function lab_migration_check_valid_filename($file_name) { - if (!preg_match('/^[0-9a-zA-Z\.]+$/', $file_name)) + if (!preg_match('/^[0-9a-zA-Z_\.]+$/', $file_name)) return FALSE; else if (substr_count($file_name, ".") > 1) return FALSE; diff --git a/manage_proposal.inc b/manage_proposal.inc index 6df058c..9769880 100755 --- a/manage_proposal.inc +++ b/manage_proposal.inc @@ -297,6 +297,11 @@ function lab_migration_proposal_approval_form($form, $form_state) '#title' => t('Do you want to provide the solution'), '#markup' => $solution_provider ); + $form['problem_statement_file'] = array( + '#type' => 'item', + '#title' => t('Problem statement file uploaded by the proposer'), + '#markup' => l('View', 'lab-migration/download/problem-statement/' . $proposal_data->id) + ); /* $form['solution_display'] = array( '#type' => 'item', '#title' => t('Do you want to display the solution on the www.dwsim.fossee.in website'), @@ -861,7 +866,7 @@ function lab_migration_proposal_edit_form($form, $form_state) '#type' => 'textfield', '#title' => t('Title of the Lab'), '#size' => 30, - '#maxlength' => 50, + '#maxlength' => 255, '#required' => TRUE, '#default_value' => $proposal_data->lab_title ); @@ -941,6 +946,19 @@ function lab_migration_proposal_edit_form($form, $form_state) ); } } + if(!$proposal_data->problem_statement_file){ + $existing_uploaded_A_file = new stdClass(); + $existing_uploaded_A_file->filename = "No file uploaded"; + } + else{ + $existing_uploaded_A_file->filename = $proposal_data->problem_statement_file; + } + $form['edit_problem_statement'] = array( + '#type' => 'file', + '#title' => t('Edit the Problem statement file'), + //'#required' => TRUE, + '#description' => t('<span style="color:red;">Current File :</span> ' . $existing_uploaded_A_file->filename . '<br />Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions: ') . variable_get('lab_migration_problem_statement_extensions', '') . '</span>', + ); if ($proposal_data->solution_provider_uid == 0) { $solution_provider_user = 'Open'; @@ -1016,12 +1034,34 @@ function lab_migration_proposal_edit_form_validate($form, &$form_state) } } } + if (isset($_FILES['files'])) + { + /* check for valid filename extensions */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + $allowed_extensions_str = variable_get('lab_migration_problem_statement_extensions', ''); + $allowed_extensions = explode(',', $allowed_extensions_str); + $fnames = explode('.', strtolower($_FILES['files']['name'][$file_form_name])); + $temp_extension = end($fnames); + if (!in_array($temp_extension, $allowed_extensions)) + form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.')); + if ($_FILES['files']['size'][$file_form_name] <= 0) + form_set_error($file_form_name, t('File size cannot be zero.')); + /* check if valid file name */ + if (!lab_migration_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.')); + } //$file_name + } //$_FILES['files']['name'] as $file_form_name => $file_name + } return; } function lab_migration_proposal_edit_form_submit($form, &$form_state) { global $user; /* get current proposal */ + $root_path = lab_migration_path(); $proposal_id = (int) arg(3); // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); $query = db_select('lab_migration_proposal'); @@ -1097,17 +1137,6 @@ function lab_migration_proposal_edit_form_submit($form, &$form_state) } /* update proposal */ $v = $form_state['values']; - //$query = "UPDATE {lab_migration_proposal} SET name_title = :name_title, name = :name, contact_ph = :contact_ph, department = :department, university = :unversity, lab_title = :lab_title, solution_display = :solution_display WHERE id = :id"; - // $args= array( - // ":name_title" => $v['name_title'], - // ":name" => $v['name'], - // "contact_ph" => $v['contact_ph'], - // ":department" => $v['department'], - // ":university" => $v['university'], - // ":lab_title" => $v['lab_title'], - // ":solution_display" => $solution_display, - // ":id" => $proposal_id, - // ); $lab_title = $v['lab_title']; $proposar_name = $v['name_title'] . ' ' . $v['name']; $university = $v['university']; @@ -1131,9 +1160,35 @@ function lab_migration_proposal_edit_form_submit($form, &$form_state) 'state' => $v['all_state'], 'lab_title' => $v['lab_title'], 'solution_display' => $solution_display, - 'directory_name' => $directory_name + 'directory_name' => $directory_name, ))->condition('id', $proposal_id); $result1 = $query->execute(); + /*Updating the Problem statement file*/ + if (isset($_FILES['files'])) { + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { + if (file_exists($root_path . $directory_name . '/' . $_FILES['files']['name'][$file_form_name])) { + unlink($root_path . $directory_name . '/' . $_FILES['files']['name'][$file_form_name]); + move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $directory_name . '/' . $_FILES['files']['name'][$file_form_name]); + drupal_set_message(t("File !filename already exists hence overwirtten the exisitng file ", array( + '!filename' => $_FILES['files']['name'][$file_form_name], + )), 'status'); + } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]) + /* uploading file */ + else if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $directory_name . '/' . $_FILES['files']['name'][$file_form_name])) { + /* for uploaded files making an entry in the database */ + unlink($root_path . $directory_name . '/' . $proposal_data->problem_statement_file); + $query = "UPDATE lab_migration_proposal SET problem_statement_file = :filename WHERE id = :proposal_id"; + $args = array( + ":filename" => $_FILES['files']['name'][$file_form_name], + ":proposal_id" => $proposal_id, + ); + db_query($query, $args, array('return' => Database::RETURN_INSERT_ID, + )); + + drupal_set_message($file_name . ' file updated successfully.', 'status'); + } + } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]) + } //$result=db_query($query, $args); /* updating existing experiments */ $query = db_select('lab_migration_experiment'); @@ -1172,28 +1227,6 @@ function lab_migration_proposal_edit_form_submit($form, &$form_state) } } } - /* foreach ($form_state['values']['lab_experiment']['update'] as $update_id => $update_value) { - if (strlen(trim($update_value)) >= 1) { - $description= $form_state['values']['lab_experiment_description']['update']; - $query = "UPDATE {lab_migration_experiment} SET title = :title and description=:description WHERE id = :id"; - $args = array( - ":title"=> trim($update_value), - ":description"=>trim($description), - ":id"=> $update_id, - ); - $result2 = db_query($query, $args); - if (!$result2) - { - drupal_set_message(t('Could not update Title of the Experiment : ') . trim($update_value), 'error'); - } - } else { - $query = "DELETE FROM {lab_migration_experiment} WHERE id = :id LIMIT 1"; - $args = array( - ":id" => $update_id - ); - $result3 = db_query($query, $args); - } - }*/ /* inserting new experiments */ $query = db_select('lab_migration_experiment'); $query->fields('lab_migration_experiment'); @@ -1236,43 +1269,7 @@ function lab_migration_proposal_edit_form_submit($form, &$form_state) } } } - /* $query = db_select('lab_migration_experiment'); - $query->fields('lab_migration_experiment'); - $query->condition('proposal_id', $proposal_id); - $query->orderBy('number', 'DESC'); - $query->range(0, 1); - $number_q = $query->execute(); - if ($number_data = $number_q->fetchObject()) { - $number = (int)$number_data->number; - $number++; - } else { - $number = 1; - } - $insertvalue = array($insert_id => $insert_value); - $lab_experimentinsert = $form_state['values']['lab_experiment']['insert']; - $lab_exp_descriptioninsert=$form_state['values']['lab_experiment_description']['insert']; - if (is_array($lab_experimentinsert) || is_object($lab_experimentinsert)) - { - foreach ($lab_experimentinsert as $insertvalue) { - //foreach ($form_state['values']['lab_experiment']['insert'] as $insert_id => $insert_value) { - if (strlen(trim($insert_value)) >= 1) { - $query = "INSERT INTO {lab_migration_experiment} (proposal_id, number, title, description) VALUES :proposal_id, :number, :title, :description"; - $args = array( - ":proposal_id" => $proposal_id, - ":number" => $number, - ":title" => trim($insert_value), - ":description"=>"" - ); - $result4 = db_query($query, $args); - if (!$result4) - { - drupal_set_message(t('Could not insert Title of the Experiment : ') . trim($insert_value), 'error'); - } else { - $number++; - } - } - } - }*/ + drupal_set_message(t('Proposal Updated'), 'status'); } /******************************************************************************/ diff --git a/proposal.inc b/proposal.inc index 720d1a7..d6d3e8c 100755 --- a/proposal.inc +++ b/proposal.inc @@ -227,17 +227,19 @@ function lab_migration_proposal_form($form, &$form_state) '#type' => 'textfield', '#title' => t('Title of the Lab'), '#size' => 50, + '#maxlength' => 255, '#required' => TRUE ); $first_experiemnt = TRUE; for ($counter = 1; $counter <= 15; $counter++) { - if ($counter <= 5) + if ($counter <= 1) { $form['lab_experiment-' . $counter] = array( '#type' => 'textfield', '#title' => t('Title of the Experiment ') . $counter, '#size' => 50, + '#required' => TRUE ); $namefield = "lab_experiment-" . $counter; $form['lab_experiment_description-' . $counter] = array( @@ -308,6 +310,19 @@ function lab_migration_proposal_form($form, &$form_state) '#description' => 'If yes, solutions will be made available to everyone for downloading.', '#disabled' => FALSE ); + $form['problem_statement'] = array( + '#type' => 'fieldset', + '#title' => t('Problem statement for the proposed lab<span style="color:red">*</span>'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + ); + $form['problem_statement']['ps_file'] = array( + '#type' => 'file', + '#title' => t('<span style="color:red;font-weight:bold">NOTE: </span>Please upload a Problem Statement for each experiment proposed in a document format. To view the template of the document please click <a href="https://cfd.fossee.in/sites/default/files/Problem_Statement_Template.doc" target="_blank">here</a>'), + '#size' => 48, + '#description' => t('Only alphabets and numbers are allowed as a valid filename.') . '<br />' . + t('Allowed file extensions: ') . variable_get('lab_migration_problem_statement_extensions', ''), + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') @@ -387,10 +402,35 @@ function lab_migration_proposal_form_validate($form, &$form_state) form_set_error('older', t('Please provide valid version')); } } + if (isset($_FILES['files'])) + { + /* check if atleast one source or result file is uploaded */ + if (!($_FILES['files']['name']['ps_file'])) + form_set_error('ps_file', t('Please upload file with the problem statement.')); + /* check for valid filename extensions */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + $allowed_extensions_str = variable_get('lab_migration_problem_statement_extensions', ''); + $allowed_extensions = explode(',', $allowed_extensions_str); + $fnames = explode('.', strtolower($_FILES['files']['name'][$file_form_name])); + $temp_extension = end($fnames); + if (!in_array($temp_extension, $allowed_extensions)) + form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.')); + if ($_FILES['files']['size'][$file_form_name] <= 0) + form_set_error($file_form_name, t('File size cannot be zero.')); + /* check if valid file name */ + if (!lab_migration_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.')); + } //$file_name + } //$_FILES['files']['name'] as $file_form_name => $file_name + } return; } function lab_migration_proposal_form_submit($form, &$form_state) { + $root_path = lab_migration_path(); global $user; if (!$user->uid) { @@ -442,11 +482,11 @@ function lab_migration_proposal_form_submit($form, &$form_state) $university = $v['university']; $directory_name = _lm_dir_name($lab_title, $proposar_name, $university); $result = "INSERT INTO {lab_migration_proposal} - (uid, approver_uid, name_title, name, contact_ph, department, university, city, pincode, state, country, version, lab_title, approval_status, solution_status, solution_provider_uid, solution_display, creation_date, approval_date, solution_date, solution_provider_name_title, solution_provider_name, solution_provider_contact_ph, solution_provider_department, solution_provider_university, solution_provider_city, solution_provider_country, solution_provider_state, solution_provider_pincode, directory_name) VALUES + (uid, approver_uid, name_title, name, contact_ph, department, university, city, pincode, state, country, version, lab_title, approval_status, solution_status, solution_provider_uid, solution_display, creation_date, approval_date, solution_date, solution_provider_name_title, solution_provider_name, solution_provider_contact_ph, solution_provider_department, solution_provider_university, solution_provider_city, solution_provider_country, solution_provider_state, solution_provider_pincode, directory_name,problem_statement_file) VALUES (:uid, :approver_uid, :name_title, :name, :contact_ph, :department, :university, :city, :pincode, :state, :country, :version, :lab_title, :approval_status, :solution_status, :solution_provider_uid, :solution_display, :creation_date, :approval_date, :solution_date, :solution_provider_name_title, :solution_provider_name, - :solution_provider_contact_ph, :solution_provider_department, :solution_provider_university, :solution_provider_city, :solution_provider_country, :solution_provider_state, :solution_provider_pincode, :directory_name)"; + :solution_provider_contact_ph, :solution_provider_department, :solution_provider_university, :solution_provider_city, :solution_provider_country, :solution_provider_state, :solution_provider_pincode, :directory_name, :problem_statement_file)"; $args = array( ":uid" => $user->uid, ":approver_uid" => 0, @@ -477,11 +517,45 @@ function lab_migration_proposal_form_submit($form, &$form_state) ":solution_provider_country" => $solution_provider_country, ":solution_provider_state" => $solution_provider_state, ":solution_provider_pincode" => $solution_provider_pincode, - ":directory_name" => $directory_name + ":directory_name" => $directory_name, + ":problem_statement_file" => "" ); $proposal_id = db_query($result, $args, array( 'return' => Database::RETURN_INSERT_ID )); + $dest_path = $directory_name . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + /* uploading files */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + //$file_type = 'S'; + if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error'); + //unlink($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]); + } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]) + /* uploading file */ + if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + $query = "UPDATE lab_migration_proposal SET problem_statement_file = :problem_statement_file WHERE id = :id"; + $args = array( + ":problem_statement_file" => $_FILES['files']['name'][$file_form_name], + ":id" => $proposal_id + ); + + $updateresult = db_query($query, $args); + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]) + else + { + drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error'); + } + } //$file_name + } if (!$proposal_id) { drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error'); @@ -1,10 +1,12 @@ <?php function lab_migration_run_form($form, &$form_state) { - $options_first = _list_of_labs(); + $options_two = _ajax_get_experiment_list(); $select_two = isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : key($options_two); $url_lab_id = (int) arg(2); + $url_experiment_id = (int) arg(3); + $options_first = _list_of_labs($url_lab_id); if (!$url_lab_id) { $selected = isset($form_state['values']['lab']) ? $form_state['values']['lab'] : key($options_first); @@ -16,19 +18,27 @@ function lab_migration_run_form($form, &$form_state) else { $selected = $url_lab_id; - ; + } + if (!$url_experiment_id) + { + $selected_experiment = isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : key($options_two); + } + elseif ($url_experiment_id == '') + { + $selected_experiment = 0; + } + else + { + $selected_experiment = $url_experiment_id; } $form = array(); $form['lab'] = array( '#type' => 'select', '#title' => t('Title of the lab'), - '#options' => _list_of_labs(), + '#options' => _list_of_labs($selected), '#default_value' => $selected, - '#ajax' => array( - 'callback' => 'ajax_experiment_list_callback' - ) ); - if (!$url_lab_id) + /*if (!$url_lab_id) { $form['selected_lab'] = array( '#type' => 'item', @@ -48,21 +58,14 @@ function lab_migration_run_form($form, &$form_state) ); $form['lab_experiment_list'] = array( '#type' => 'select', - '#title' => t('Titile of the experiment'), + '#title' => t('Title of the experiment'), '#options' => _ajax_get_experiment_list($selected), - //'#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '', + '#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '', '#ajax' => array( 'callback' => 'ajax_solution_list_callback' ), '#prefix' => '<div id="ajax_selected_experiment">', '#suffix' => '</div>', - '#states' => array( - 'invisible' => array( - ':input[name="lab"]' => array( - 'value' => 0 - ) - ) - ) ); $form['download_experiment'] = array( '#type' => 'item', @@ -79,13 +82,6 @@ function lab_migration_run_form($form, &$form_state) ), '#prefix' => '<div id="ajax_selected_solution">', '#suffix' => '</div>', - '#states' => array( - 'invisible' => array( - ':input[name="lab"]' => array( - 'value' => 0 - ) - ) - ) ); $form['download_solution'] = array( '#type' => 'item', @@ -109,67 +105,63 @@ function lab_migration_run_form($form, &$form_state) ); } else - { + {*/ $lab_default_value = $url_lab_id; - $form['selected_lab'] = array( + $experiment_default_value = $url_experiment_id; + /*$form['selected_lab'] = array( '#type' => 'item', '#markup' => '<div id="ajax_selected_lab">' . l('Download Lab Solutions', 'lab-migration/download/lab/' . $lab_default_value) . '</div>' ); - /* $form['selected_lab_pdf'] = array( - '#type' => 'item', - '#markup' => '<div id="ajax_selected_lab_pdf">'. l('Download PDF of Lab Solutions', 'lab-migration/generate-lab/' . $lab_default_value . '/1') .'</div>', - - );*/ if ($lab_default_value == '2') { $form['selected_lab_dwsim'] = array( '#type' => 'item', '#markup' => '<div id="ajax_selected_lab_dwsim">' . l('Download Lab Solutions (dwsim Version)', 'lab-migration-uploads/dwsim_Version.zip') . '</div>' ); - } - $form['lab_details'] = array( + }*/ + $form['selected_lab'] = array( '#type' => 'item', - '#markup' => '<div id="ajax_lab_details">' . _lab_details($lab_default_value) . '</div>' + '#markup' => '<div id="ajax_selected_lab">' . l('Download Lab Solutions', 'lab-migration/download/lab/' . $lab_default_value) . '</div>' ); $form['lab_experiment_list'] = array( '#type' => 'select', - '#title' => t('Titile of the experiment'), + '#title' => t('Title of the experiment'), '#options' => _ajax_get_experiment_list($selected), - // '#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '', + '#default_value' => $selected_experiment, '#ajax' => array( 'callback' => 'ajax_solution_list_callback' ), '#prefix' => '<div id="ajax_selected_experiment">', '#suffix' => '</div>', - '#states' => array( + /*'#states' => array( 'invisible' => array( ':input[name="lab"]' => array( 'value' => 0 ) ) - ) + )*/ ); $form['download_experiment'] = array( '#type' => 'item', - '#markup' => '<div id="ajax_download_experiments"></div>' + '#markup' => '<div id="ajax_download_experiments">' . l('Download Experiment', 'lab-migration/download/experiment/' . $selected_experiment) . '</div>' ); $form['lab_solution_list'] = array( '#type' => 'select', '#title' => t('Solution'), - '#options' => _ajax_get_solution_list($select_two), - '#default_value' => isset($form_state['values']['lab_solution_list']) ? $form_state['values']['lab_solution_list'] : '', + '#options' => _ajax_get_solution_list($selected_experiment), + //'#default_value' => isset($form_state['values']['lab_solution_list']) ? $form_state['values']['lab_solution_list'] : '', '#ajax' => array( 'callback' => 'ajax_solution_files_callback' ), '#prefix' => '<div id="ajax_selected_solution">', '#suffix' => '</div>', - '#states' => array( + /*'#states' => array( 'invisible' => array( ':input[name="lab_experiment_list"]' => array( 'value' => 0 ) ) - ) + )*/ ); $form['download_solution'] = array( '#type' => 'item', @@ -191,54 +183,50 @@ function lab_migration_run_form($form, &$form_state) ) ) ); - } - /* - $form['message'] = array( - '#type' => 'textarea', - '#title' => t('If Dis-Approved please specify reason for Dis-Approval'), - '#prefix' => '<div id= "message_submit">', - '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0,),),), - - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - '#suffix' => '</div>', - '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0,),),), - - );*/ + $form['lab_details'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_lab_details">' . _lab_details($lab_default_value) . '</div>' + ); + $form['back_to_completed_labs'] = array( + '#type' => 'item', + '#markup' => l('Back to Completed Labs', 'lab-migration/completed-labs') + ); + //} return $form; } function ajax_experiment_list_callback($form, $form_state) { $commands = array(); $lab_default_value = $form_state['values']['lab']; + //var_dump($lab_default_value);die; if ($lab_default_value != 0) { $form['lab_details']['#markup'] = _lab_details($lab_default_value); $lab_details = _lab_information($lab_default_value); $user_solution_provider = user_load($lab_details->solution_provider_uid); //var_dump($lab_details->solution_provider_uid); - if ($lab_details->solution_provider_uid > 0) + /*if ($lab_details->solution_provider_uid > 0) { $commands[] = ajax_command_html('#ajax_selected_lab', l('Download Lab Solutions', 'lab-migration/download/lab/' . $lab_default_value)); if ($lab_default_value == '2') { $commands[] = ajax_command_html('#ajax_selected_lab_dwsim', l('Download Lab Solutions (dwsim Version)', 'lab-migration_uploads/dwsim_Version.zip')); } - /* $commands[] = ajax_command_html('#ajax_selected_lab_pdf', l('Download PDF of Lab Solutions', 'lab-migration/generate-lab/' . $lab_default_value . '/1'));*/ + } else { $commands[] = ajax_command_html('#ajax_selected_lab', ''); $commands[] = ajax_command_html('#ajax_selected_lab_pdf', ''); $commands[] = ajax_command_html('#ajax_selected_lab_dwsim', ''); - } + }*/ $commands[] = ajax_command_html('#ajax_lab_details', _lab_details($lab_default_value)); $form['lab_experiment_list']['#options'] = _ajax_get_experiment_list($lab_default_value); $commands[] = ajax_command_replace('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); $commands[] = ajax_command_html('#ajax_selected_solution', ''); + /*$form['lab_solution_list']['#options'] = _ajax_get_solution_list(); + $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); + *///$commands[] = ajax_command_replace('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); $commands[] = ajax_command_html('#ajax_solution_files', ''); $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); @@ -248,14 +236,16 @@ function ajax_experiment_list_callback($form, $form_state) { $form['lab_experiment_list']['#options'] = _ajax_get_experiment_list(); $commands[] = ajax_command_replace('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + /*$form['lab_solution_list']['#options'] = _ajax_get_solution_list();*/ $commands[] = ajax_command_html('#ajax_lab_details', ''); $commands[] = ajax_command_html('#ajax_selected_lab', ''); $commands[] = ajax_command_html('#ajax_selected_lab_dwsim', ''); $commands[] = ajax_command_html('#ajax_selected_lab_pdf', ''); - $commands[] = ajax_command_data('#ajax_selected_lab', 'form_state_value_select', $form_state['values']['lab']); - $commands[] = ajax_command_html('#ajax_selected_experiment', ''); + //$commands[] = ajax_command_data('#ajax_selected_lab', 'form_state_value_select', $form_state['values']['lab']); + //$commands[] = ajax_command_html('#ajax_selected_experiment', ''); $commands[] = ajax_command_html('#ajax_download_experiments', ''); $commands[] = ajax_command_html('#ajax_selected_solution', ''); + //$commands[] = ajax_command_replace('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); $commands[] = ajax_command_html('#ajax_solution_files', ''); $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); @@ -268,14 +258,17 @@ function ajax_experiment_list_callback($form, $form_state) function ajax_solution_list_callback($form, $form_state) { $commands = array(); + //$lab_default_value = $form_state['values']['lab']; $experiment_list_default_value = $form_state['values']['lab_experiment_list']; - //var_dump($lab_default_value); + //var_dump($lab_default_value . ' ' . $experiment_list_default_value);die; if ($experiment_list_default_value != 0) { + //var_dump($experiment_list_default_value); $form['lab_solution_list']['#options'] = _ajax_get_solution_list($experiment_list_default_value); + $commands[] = ajax_command_replace('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); $commands[] = ajax_command_html('#ajax_download_experiments', l('Download Experiment', 'lab-migration/download/experiment/' . $experiment_list_default_value)); - $commands[] = ajax_command_html('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); - $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); +/* $commands[] = ajax_command_html('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); +*/ // $commands[] = ajax_command_html('#ajax_solution_files', ''); // $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); // $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); @@ -283,12 +276,12 @@ function ajax_solution_list_callback($form, $form_state) else { $form['lab_solution_list']['#options'] = _ajax_get_solution_list(); - $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); - $commands[] = ajax_command_html('#ajax_download_experiments', ''); - $commands[] = ajax_command_html('#ajax_selected_solution', ''); + $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); + /* $commands[] = ajax_command_html('#ajax_download_experiments', ''); + //$commands[] = ajax_command_html('#ajax_selected_solution', ''); $commands[] = ajax_command_html('#ajax_solution_files', ''); $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); - $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', '');*/ // $commands[] = ajax_command_replace('#ajax_selected_experiment',drupal_render($form['lab_experiment_list'])); } return array( @@ -305,7 +298,6 @@ function ajax_solution_files_callback($form, $form_state) { $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', drupal_render($form['lab_experiment_solution_actions'])); /*************************************************************************************/ - //$solution_list_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $form_state['values']['solution']); $query = db_select('lab_migration_solution_files'); $query->fields('lab_migration_solution_files'); $query->condition('solution_id', $solution_list_default_value); @@ -410,17 +402,13 @@ function bootstrap_table_format($headers, $rows) "; return $table; } -/*****************************************************/ -function _list_of_labs() + function _list_of_labs($selected) { - $lab_titles = array( - '0' => 'Please select...' - ); + $lab_titles = array(); //$lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_display = 1 ORDER BY lab_title ASC"); $query = db_select('lab_migration_proposal'); $query->fields('lab_migration_proposal'); - $query->condition('solution_display', 1); - $query->condition('approval_status', 3); + $query->condition('id',$selected); $query->orderBy('lab_title', 'ASC'); $lab_titles_q = $query->execute(); while ($lab_titles_data = $lab_titles_q->fetchObject()) @@ -429,6 +417,17 @@ function _list_of_labs() } return $lab_titles; } +/*****************************************************/ +function _selected_lab_name($selected) + { + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $selected); + $query->condition('approval_status', 3); + $lab_titles_q = $query->execute(); + $lab_titles_data = $lab_titles_q->fetchObject(); + return $lab_titles_data->lab_title; + } function _ajax_get_experiment_list($lab_default_value = '') { $experiments = array( @@ -451,16 +450,9 @@ function _ajax_get_solution_list($lab_experiment_list = '') $solutions = array( '0' => 'Please select...' ); - // $solutions_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d ORDER BY - // CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY) ASC, - // CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED) ASC, - // CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED) ASC", $experiment_id); $query = db_select('lab_migration_solution'); $query->fields('lab_migration_solution'); $query->condition('experiment_id', $lab_experiment_list); - //$query->orderBy("CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY", "ASC"); - // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED", "ASC"); - // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED", "ASC"); $solutions_q = $query->execute(); while ($solutions_data = $solutions_q->fetchObject()) { @@ -498,22 +490,22 @@ function _lab_details($lab_default_value) $user_solution_provider = user_load($lab_details->solution_provider_uid); if ($user_solution_provider) { - $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Solution Provider Name:</strong> ' . $lab_details->solution_provider_name_title . ' ' . $lab_details->solution_provider_name . '</li>' . '<li><strong>Department:</strong> ' . $lab_details->solution_provider_department . '</li>' . '<li><strong>University:</strong> ' . $lab_details->solution_provider_university . '</li>' . '</ul>'; + $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span>' . '<ul>' . '<li><strong>Solution Provider Name:</strong> ' . $lab_details->solution_provider_name_title . ' ' . $lab_details->solution_provider_name . '</li>' . '<li><strong>Department:</strong> ' . $lab_details->solution_provider_department . '</li>' . '<li><strong>University:</strong> ' . $lab_details->solution_provider_university . '</li>' . '</ul>'; } else { - $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Solution Provider: </strong> (Open) </li>' . '</ul>'; + $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span>' . '<ul>' . '<li><strong>Solution Provider: </strong> (Open) </li>' . '</ul>'; } } else { - $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Solution Provider: </strong> (Open) </li>' . '</ul>'; + $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span>' . '<ul>' . '<li><strong>Solution Provider: </strong> (Open) </li>' . '</ul>'; }} else{ drupal_goto('lab-migration/lab-migration-run'); } - $form['lab_details']['#markup'] = '<span style="color: rgb(128, 0, 0);"><strong>About the Lab</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Proposer Name:</strong> ' . $lab_details->name_title . ' ' . $lab_details->name . '</li>' . '<li><strong>Title of the Lab:</strong> ' . $lab_details->lab_title . '</li>' . '<li><strong>Department:</strong> ' . $lab_details->department . '</li>' . '<li><strong>University:</strong> ' . $lab_details->university . '</li>' . '<li><strong>Category:</strong> ' . $lab_details->category . '</li>' . '</ul>' . $solution_provider; + $form['lab_details']['#markup'] = '<table><tr><td><span style="color: rgb(128, 0, 0);"><strong>About the Lab</strong></span>' . '<ul>' . '<li><strong>Proposer Name:</strong> ' . $lab_details->name_title . ' ' . $lab_details->name . '</li>' . '<li><strong>Title of the Lab:</strong> ' . $lab_details->lab_title . '</li>' . '<li><strong>Department:</strong> ' . $lab_details->department . '</li>' . '<li><strong>University:</strong> ' . $lab_details->university . '</li>' . '<li><strong>Category:</strong> ' . $lab_details->category . '</li>' . '</ul></td><td>' . $solution_provider . '</td></tr></table>'; $details = $form['lab_details']['#markup']; return $details; } diff --git a/settings.inc b/settings.inc index 1856a25..8af9fd3 100755 --- a/settings.inc +++ b/settings.inc @@ -29,6 +29,15 @@ function lab_migration_settings_form($form, $form_state) '#required' => TRUE, '#default_value' => variable_get('lab_migration_from_email', '') ); + $form['extensions']['proposal_problem_statement'] = array( + '#type' => 'textfield', + '#title' => t('Allowed extensions for the problem statement in the Proposal form'), + '#description' => t('A comma separated list WITHOUT SPACE of file extensions for the problem statement that are permitted to be uploaded on the server'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_problem_statement_extensions', '') + ); $form['extensions']['source'] = array( '#type' => 'textfield', '#title' => t('Allowed source file extensions'), @@ -38,33 +47,24 @@ function lab_migration_settings_form($form, $form_state) '#required' => TRUE, '#default_value' => variable_get('lab_migration_source_extensions', '') ); - $form['extensions']['dependency'] = array( + $form['extensions']['code_submission_result_pdf'] = array( '#type' => 'textfield', - '#title' => t('Allowed dependency file extensions'), - '#description' => t('A comma separated list WITHOUT SPACE of dependency file extensions that are permitted to be uploaded on the server'), + '#title' => t('Allowed file extensions for results in the form of PDF'), + '#description' => t('A comma separated list WITHOUT SPACE of report file extensions that are permitted to be uploaded on the server'), '#size' => 50, '#maxlength' => 255, '#required' => TRUE, - '#default_value' => variable_get('lab_migration_dependency_extensions', '') + '#default_value' => variable_get('lab_migration_result_pdf_extensions', '') ); - $form['extensions']['result'] = array( + $form['extensions']['result_zip'] = array( '#type' => 'textfield', - '#title' => t('Allowed result file extensions'), + '#title' => t('Allowed result file extensions in the zip format'), '#description' => t('A comma separated list WITHOUT SPACE of result file extensions that are permitted to be uploaded on the server'), '#size' => 50, '#maxlength' => 255, '#required' => TRUE, '#default_value' => variable_get('lab_migration_result_extensions', '') ); - $form['extensions']['xcos'] = array( - '#type' => 'textfield', - '#title' => t('Allowed xcos file extensions'), - '#description' => t('A comma separated list WITHOUT SPACE of xcos file extensions that are permitted to be uploaded on the server'), - '#size' => 50, - '#maxlength' => 255, - '#required' => TRUE, - '#default_value' => variable_get('lab_migration_xcos_extensions', '') - ); $form['extensions']['pdf'] = array( '#type' => 'textfield', '#title' => t('Allowed pdf file extensions'), @@ -89,10 +89,10 @@ function lab_migration_settings_form_submit($form, &$form_state) variable_set('lab_migration_emails', $form_state['values']['emails']); variable_set('lab_migration_cc_emails', $form_state['values']['cc_emails']); variable_set('lab_migration_from_email', $form_state['values']['from_email']); + variable_set('lab_migration_problem_statement_extensions', $form_state['values']['proposal_problem_statement']); variable_set('lab_migration_source_extensions', $form_state['values']['source']); - variable_set('lab_migration_dependency_extensions', $form_state['values']['dependency']); - variable_set('lab_migration_result_extensions', $form_state['values']['result']); - variable_set('lab_migration_xcos_extensions', $form_state['values']['xcos']); + variable_set('lab_migration_result_pdf_extensions', $form_state['values']['code_submission_result_pdf']); + variable_set('lab_migration_result_extensions', $form_state['values']['result_zip']); variable_set('lab_migration_pdf_extensions', $form_state['values']['pdf']); drupal_set_message(t('Settings updated'), 'status'); } diff --git a/solution_proposal.inc b/solution_proposal.inc index e23f4fa..b06b6f5 100755 --- a/solution_proposal.inc +++ b/solution_proposal.inc @@ -16,13 +16,21 @@ function lab_migration_proposal_open() { while ($proposal_data = $proposal_q->fetchObject()) { + if($proposal_data->problem_statement_file == ''){ + $problem_statement_file = "NA"; + } + else{ + $problem_statement_file = l('View', 'lab-migration/download/problem-statement/' . $proposal_data->id); + } $proposal_rows[] = array( l($proposal_data->lab_title, 'lab-migration/show-proposal/' . $proposal_data->id), + $problem_statement_file, l('Apply', 'lab-migration/show-proposal/' . $proposal_data->id) ); } $proposal_header = array( 'Title of the Lab', + 'Problem Statement', 'Actions' ); $return_html = theme('table', array( diff --git a/upload_code.inc b/upload_code.inc index 7dca349..be59edc 100755 --- a/upload_code.inc +++ b/upload_code.inc @@ -219,7 +219,7 @@ function lab_migration_upload_code_form($form,$form_state) ); $form['code_warning'] = array( '#type' => 'item', - '#title' => t('Upload all the dwsim project files in .zip format'), + '#title' => t('Upload all the OpenFOAM project files in .zip format'), '#prefix' => '<div style="color:red">', '#suffix' => '</div>', ); @@ -234,7 +234,7 @@ function lab_migration_upload_code_form($form,$form_state) '#title' => t('Upload main or source file'), '#size' => 48, '#description' => t('Only alphabets and numbers are allowed as a valid filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_source_extensions', ''), + t('Allowed file extensions: ') . variable_get('lab_migration_source_extensions', ''), ); /* $form['dep_files'] = array( @@ -292,40 +292,18 @@ function lab_migration_upload_code_form($form,$form_state) ); $form['result']['result1'] = array( '#type' => 'file', - '#title' => t('Upload result file'), + '#title' => t('Upload result file. To view the template for result submission please click <a href="https://cfd.fossee.in/sites/default/files/Template_For_Result.doc" target="_blank">here</a>.'), '#size' => 48, '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), + t('Allowed file extensions: ') . variable_get('lab_migration_result_pdf_extensions', ''), ); $form['result']['result2'] = array( '#type' => 'file', '#title' => t('Upload result file'), '#size' => 48, '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), - ); -/* - $form['xcos'] = array( - '#type' => 'fieldset', - '#title' => t('XCOS Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['xcos']['xcos1'] = array( - '#type' => 'file', - '#title' => t('Upload xcos file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), - ); - $form['xcos']['xcos2'] = array( - '#type' => 'file', - '#title' => t('Upload xcos file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), + t('Allowed file extensions: ') . variable_get('lab_migration_result_extensions', ''), ); -*/ $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') @@ -357,7 +335,8 @@ function lab_migration_upload_code_form_validate($form, &$form_state) /* check if atleast one source or result file is uploaded */ if ( ! ($_FILES['files']['name']['sourcefile1'] )) form_set_error('sourcefile1', t('Please upload atleast one main or source file.')); - +if ( ! ($_FILES['files']['name']['result1'] )) + form_set_error('result1', t('Please upload the result file in the form of pdf.')); /* check for valid filename extensions */ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { @@ -366,10 +345,10 @@ function lab_migration_upload_code_form_validate($form, &$form_state) /* checking file type */ if (strstr($file_form_name, 'source')) $file_type = 'S'; - else if (strstr($file_form_name, 'result')) + else if (strstr($file_form_name, 'result1')) + $file_type = 'P'; + else if (strstr($file_form_name, 'result2')) $file_type = 'R'; - else if (strstr($file_form_name, 'xcos')) - $file_type = 'X'; else $file_type = 'U'; @@ -382,8 +361,8 @@ function lab_migration_upload_code_form_validate($form, &$form_state) case 'R': $allowed_extensions_str = variable_get('lab_migration_result_extensions', ''); break; - case 'X': - $allowed_extensions_str = variable_get('lab_migration_xcos_extensions', ''); + case 'P': + $allowed_extensions_str = variable_get('lab_migration_result_pdf_extensions', ''); break; } $allowed_extensions = explode(',' , $allowed_extensions_str); @@ -562,17 +541,19 @@ function lab_migration_upload_code_form_submit($form, &$form_state) { return; } + /* uploading file */ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) { /* for uploaded files making an entry in the database */ + //var_dump($_FILES['files']['type'][$file_form_name]);die; $query = "INSERT INTO {lab_migration_solution_files} (solution_id, filename, filepath, filemime, filesize, filetype, timestamp) VALUES (:solution_id, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)"; $args = array( ":solution_id" => $solution_id, ":filename" => $_FILES['files']['name'][$file_form_name], ":filepath" => $file_path . $_FILES['files']['name'][$file_form_name], - ":filemime" => 'application/zip', + ":filemime" => $_FILES['files']['type'][$file_form_name], ":filesize" => $_FILES['files']['size'][$file_form_name], ":filetype" => $file_type, ":timestamp" => time() |