diff options
-rwxr-xr-x | cfd_case_study.module | 43 | ||||
-rwxr-xr-x | email.inc | 8 | ||||
-rwxr-xr-x | manage_proposal.inc | 180 | ||||
-rwxr-xr-x | proposal.inc | 124 |
4 files changed, 322 insertions, 33 deletions
diff --git a/cfd_case_study.module b/cfd_case_study.module index dde2929..568d673 100755 --- a/cfd_case_study.module +++ b/cfd_case_study.module @@ -76,7 +76,7 @@ function cfd_case_study_menu() 'title' => 'Edit code files', 'description' => 'Edit code files', 'page callback' => 'cfd_case_study_proposal_edit_file_all', - 'access callback' => 'Case Study approve abstract', + 'access callback' => 'user_access', 'access arguments' => array( 'Case Study manage proposal', ), @@ -142,7 +142,7 @@ function cfd_case_study_menu() 'title' => 'Case Study Project Directory edit uploaded files for proposal', 'description' => 'Project Edit Upload', 'page callback' => 'drupal_get_form', - 'access callback' => 'Case Study approve abstract', + 'access callback' => 'user_access', 'page arguments' => array( 'cfd_case_study_edit_upload_abstract_code_form', ), @@ -592,6 +592,45 @@ function _cs_list_of_case_studies() return $existing_case_studies; } +function _cs_list_of_versions(){ + $versions = array(); + $query = db_select('case_study_software_version'); + $query->fields('case_study_software_version'); + $version_list = $query->execute(); + while($version_data = $version_list->fetchObject()){ + $versions[$version_data->id] = $version_data->case_study_version; + } + return $versions; +} + +function _cs_list_of_simulation_types(){ + $simulation_types = array(); + $query = db_select('case_study_simulation_type'); + $query->fields('case_study_simulation_type'); + $simulation_type_list = $query->execute(); + while ($simulation_type_data = $simulation_type_list->fetchObject()) { + $simulation_types[$simulation_type_data->id] = $simulation_type_data->simulation_type; + } + return $simulation_types; +} + +function _cs_list_of_solvers($version_id, $simulation_id){ + $version_id = $version_id; + $simulation_id = $simulation_id; + $solvers = array( + 0 => '-Select-', + ); + $query = db_select('case_study_solvers'); + $query->fields('case_study_solvers'); + $query->condition('version_id',$version_id); + $query->condition('simulation_type_id',$simulation_id); + $solvers_list = $query->execute(); + while($solvers_data = $solvers_list->fetchObject()){ + $solvers[$solvers_data->solver_name] = $solvers_data->solver_name; + } + return $solvers; +} + function _df_dir_name($project, $proposar_name) { $project_title = ucname($project); @@ -282,18 +282,14 @@ FOSSEE,IIT Bombay', array( 'body' => t(' Dear !user_name, -You have updated the following abstract/ project files for case studies: +You have updated the abstract/ project files for the following case study: Project Title: ' . $proposal_data->project_title . ' -Abstract File: ' . $abs_file_name . ' - -Project File: ' . $proj_file_name . ' - Best Wishes, !site_name Team, -FOSSEE,IIT Bombay', array( +FOSSEE, IIT Bombay', array( '!site_name' => variable_get('site_name', ''), '!user_name' => $user->name, ), array( diff --git a/manage_proposal.inc b/manage_proposal.inc index cd4fb87..937b4aa 100755 --- a/manage_proposal.inc +++ b/manage_proposal.inc @@ -58,6 +58,9 @@ function cfd_case_study_proposal_all() case 3: $approval_status = 'Completed'; break; + case 5: + $approval_status = 'On Hold'; + break; default: $approval_status = 'Unknown'; break; @@ -227,6 +230,16 @@ function cfd_case_study_proposal_approval_form($form, &$form_state) } else { $faculty_email = $proposal_data->faculty_email; } + $query = db_select('case_study_software_version'); + $query->fields('case_study_software_version'); + $query->condition('id', $proposal_data->version_id); + $version_data = $query->execute()->fetchObject(); + $version = $version_data->case_study_version; + $query = db_select('case_study_simulation_type'); + $query->fields('case_study_simulation_type'); + $query->condition('id', $proposal_data->simulation_type_id); + $simulation_type_data = $query->execute()->fetchObject(); + $simulation_type = $simulation_type_data->simulation_type; $form['contributor_name'] = array( '#type' => 'item', '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid), @@ -293,11 +306,22 @@ function cfd_case_study_proposal_approval_form($form, &$form_state) '#markup' => $proposal_data->project_title, '#title' => t('Title of the Case Study Project'), ); + $form['version'] = array( + '#type' => 'item', + '#markup' => $version, + '#title' => t('Version used'), + ); + $form['simulation_type'] = array( + '#type' => 'item', + '#markup' => $simulation_type, + '#title' => t('Simulation Type'), + ); $form['solver_used'] = array( '#type' => 'item', '#markup' => $proposal_data->solver_used, '#title' => t('Solver used'), ); + $form['date_of_proposal'] = array( '#type' => 'textfield', '#title' => t('Date of Proposal'), @@ -509,6 +533,26 @@ function cfd_case_study_proposal_status_form($form, &$form_state) } else { $faculty_email = $proposal_data->faculty_email; } + $query = db_select('case_study_software_version'); + $query->fields('case_study_software_version'); + $query->condition('id', $proposal_data->version_id); + $version_data = $query->execute()->fetchObject(); + if(!$version_data){ + $version = 'NA'; + } + else{ + $version = $version_data->case_study_version; + } + $query = db_select('case_study_simulation_type'); + $query->fields('case_study_simulation_type'); + $query->condition('id', $proposal_data->simulation_type_id); + $simulation_type_data = $query->execute()->fetchObject(); + if(!$simulation_type_data){ + $simulation_type = 'NA'; + } + else{ + $simulation_type = $simulation_type_data->simulation_type; + } $form['contributor_name'] = array( '#type' => 'item', '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid), @@ -570,6 +614,16 @@ function cfd_case_study_proposal_status_form($form, &$form_state) '#markup' => $proposal_data->project_title, '#title' => t('Title of the Case Study Project'), ); + $form['version'] = array( + '#type' => 'item', + '#markup' => $version, + '#title' => t('Version used'), + ); + $form['simulation_type'] = array( + '#type' => 'item', + '#markup' => $simulation_type, + '#title' => t('Simulation Type'), + ); $form['solver_used'] = array( '#type' => 'item', '#markup' => $proposal_data->solver_used, @@ -615,6 +669,9 @@ function cfd_case_study_proposal_status_form($form, &$form_state) case 3: $proposal_status = t('Completed'); break; + case 5: + $approval_status = t('On Hold'); + break; default: $proposal_status = t('Unkown'); break; @@ -734,9 +791,10 @@ function cfd_case_study_proposal_edit_form($form, &$form_state) $query->fields('case_study_proposal'); $query->condition('id', $proposal_id); $proposal_q = $query->execute(); - if ($proposal_q) { + $proposal_data = $proposal_q->fetchObject(); + /*if ($proposal_q) { if ($proposal_data = $proposal_q->fetchObject()) { - /* everything ok */ + /* everything ok } //$proposal_data = $proposal_q->fetchObject() else { drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); @@ -748,7 +806,7 @@ function cfd_case_study_proposal_edit_form($form, &$form_state) drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); drupal_goto('case-study-project/manage-proposal'); return; - } + }*/ $user_data = user_load($proposal_data->uid); $form['name_title'] = array( '#type' => 'select', @@ -926,14 +984,68 @@ function cfd_case_study_proposal_edit_form($form, &$form_state) '#required' => true, '#default_value' => $proposal_data->project_title, ); + $version_options = _cs_list_of_versions(); + $form['version'] = array( + '#type' => 'select', + '#title' => t('Version used'), + '#options' => $version_options, + '#default_value' => $proposal_data->version_id + ); + $simulation_type_options = _cs_list_of_simulation_types(); + $form['simulation_type'] = array( + '#type' => 'select', + '#title' => t('Simulation Type used'), + '#options' => $simulation_type_options, + '#default_value' => $proposal_data->simulation_type_id, + '#ajax' => array( + 'callback' => 'ajax_solver_used_callback', + ), + ); + $version_id = isset($form_state['values']['version']) ? $form_state['values']['version'] : $proposal_data->version_id; + $simulation_id = isset($form_state['values']['simulation_type']) ? $form_state['values']['simulation_type'] : $proposal_data->simulation_type_id; + $form['solver_used'] = array( + '#type' => 'select', + '#title' => t('Select the Solver to be used'), + '#options' => _cs_list_of_solvers($version_id, $simulation_id), + '#prefix' => '<div id="ajax-solver-replace">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="simulation_type"]' => array( + 'value' => 13 + ) + ) + ), + //'#required' => TRUE + '#default_value' => $proposal_data->solver_used, + ); + + $form['solver_used_text'] = array( + '#type' => 'textfield', + '#title' => t('Enter the Solver to be used'), + '#size' => 100, + '#description' => t('Maximum character limit is 50'), + //'#required' => TRUE, + '#prefix' => '<div id="ajax-solver-text-replace">', + '#suffix' => '</div>', + '#states' => array( + 'visible' => array( + ':input[name="simulation_type"]' => array( + 'value' => 13 + ) + ) + ), + '#default_value' => $proposal_data->solver_used + ); + /* $form['solver_used'] = array( '#type' => 'textfield', '#title' => t('Solver to be used'), '#size' => 50, '#maxlength' => 50, '#required' => true, '#default_value' => $proposal_data->solver_used, - ); + );*/ $form['date_of_proposal'] = array( '#type' => 'textfield', '#title' => t('Date of Proposal'), @@ -954,6 +1066,52 @@ function cfd_case_study_proposal_edit_form($form, &$form_state) ); return $form; } + +function ajax_solver_used_callback($form, $form_state){ + $version_id = isset($form_state['values']['version']) ? $form_state['values']['version'] : key($version_options); + $simulation_id = isset($form_state['values']['simulation_type']) ? $form_state['values']['simulation_type'] : key($simulation_type_options); + if($simulation_id < 13){ + $form['solver_used']['#options'] = _cs_list_of_solvers($version_id, $simulation_id); + $form['solver_used']['#required'] = TRUE; + $form['solver_used']['#validated'] = TRUE; + $commands[] = ajax_command_replace('#ajax-solver-replace', drupal_render($form['solver_used'])); + $commands[] = ajax_command_html('#ajax-solver-text-replace', ''); + } + else{ + $commands[] = ajax_command_html('#ajax-solver-replace', ''); + $form['solver_used_text']['#required'] = TRUE; + $form['solver_used_text']['#validated'] = TRUE; + $commands[] = ajax_command_replace('#ajax-solver-text-replace', drupal_render($form['solver_used_text'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function cfd_case_study_proposal_edit_form_validate($form, $form_state){ + if ($form_state['values']['simulation_type'] < 13) { + if($form_state['values']['solver_used'] == '0'){ + form_set_error('solver_used', t('Please select an option')); + } + } + else if ($form_state['values']['simulation_type'] == 13) { + if ($form_state['values']['solver_used_text'] != '') + { + if (strlen($form_state['values']['solver_used_text']) > 100) + { + form_set_error('solver_used_text', t('Maximum charater limit is 100 charaters only, please check the length of the solver used')); + } //strlen($form_state['values']['project_title']) > 250 + else if (strlen($form_state['values']['solver_used_text']) < 7) + { + form_set_error('solver_used_text', t('Minimum charater limit is 7 charaters, please check the length of the solver used')); + } //strlen($form_state['values']['project_title']) < 10 + } + else + { + form_set_error('solver_used_text', t('Solver used cannot be empty')); + } + } +} function cfd_case_study_proposal_edit_form_submit($form, &$form_state) { global $user; @@ -1014,7 +1172,6 @@ function cfd_case_study_proposal_edit_form_submit($form, &$form_state) /* update proposal */ $v = $form_state['values']; $project_title = $v['project_title']; - $solver_used = $v['solver_used']; $proposar_name = $v['name_title'] . ' ' . $v['contributor_name']; $university = $v['university']; $directory_names = _df_dir_name($project_title, $proposar_name); @@ -1024,6 +1181,13 @@ function cfd_case_study_proposal_edit_form_submit($form, &$form_state) else { return; } + $simulation_id = $v['simulation_type']; + if($simulation_id < 13){ + $solver = $v['solver_used']; + } + else{ + $solver = $v['solver_used_text']; + } $query = "UPDATE case_study_proposal SET name_title=:name_title, contributor_name=:contributor_name, @@ -1037,6 +1201,8 @@ function cfd_case_study_proposal_edit_form_submit($form, &$form_state) pincode=:pincode, state=:state, project_title=:project_title, + version_id=:version_id, + simulation_type_id=:simulation_type_id, solver_used=:solver_used, directory_name=:directory_name WHERE id=:proposal_id"; @@ -1053,7 +1219,9 @@ function cfd_case_study_proposal_edit_form_submit($form, &$form_state) ':pincode' => $v['pincode'], ':state' => $v['all_state'], ':project_title' => $project_title, - ":solver_used" => $solver_used, + ':version_id' => $v['version'], + ':simulation_type_id' => $simulation_id, + ":solver_used" => $solver, ':directory_name' => $directory_name, ':proposal_id' => $proposal_id, ); diff --git a/proposal.inc b/proposal.inc index 9d9b064..c13100a 100755 --- a/proposal.inc +++ b/proposal.inc @@ -285,20 +285,61 @@ function cfd_case_study_proposal_form($form, &$form_state, $no_js_use = FALSE) ) ), ); - /*$form['project_title'] = array( - '#type' => 'textfield', - '#title' => t('Project Title'), - '#size' => 250, - '#description' => t('Maximum character limit is 250'), + $version_options = _cs_list_of_versions(); + $form['version'] = array( + '#type' => 'select', + '#title' => t('Version used'), + '#options' => $version_options, '#required' => TRUE - );*/ + ); + $simulation_type_options = _cs_list_of_simulation_types(); + $form['simulation_type'] = array( + '#type' => 'select', + '#title' => t('Simulation Type used'), + '#options' => $simulation_type_options, + '#required' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_solver_used_callback', + ), + ); + $version_id = isset($form_state['values']['version']) ? $form_state['values']['version'] : key($version_options); + $simulation_id = isset($form_state['values']['simulation_type']) ? $form_state['values']['simulation_type'] : key($simulation_type_options); + //if($simulation_id < 13){ $form['solver_used'] = array( + '#type' => 'select', + '#title' => t('Select the Solver to be used'), + '#options' => _cs_list_of_solvers($version_id, $simulation_id), + '#prefix' => '<div id="ajax-solver-replace">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="simulation_type"]' => array( + 'value' => 13 + ) + ) + ), + //'#required' => TRUE + + ); + //} + //else if ($simulation_id == 13){ + $form['solver_used_text'] = array( '#type' => 'textfield', - '#title' => t('Solver to be used'), - '#size' => 50, + '#title' => t('Enter the Solver to be used'), + '#size' => 100, '#description' => t('Maximum character limit is 50'), - '#required' => TRUE + //'#required' => TRUE, + '#prefix' => '<div id="ajax-solver-text-replace">', + '#suffix' => '</div>', + '#states' => array( + 'visible' => array( + ':input[name="simulation_type"]' => array( + 'value' => 13 + ) + ) + ), ); + //} $form['abstract_file'] = array( '#type' => 'fieldset', '#title' => t('Submit an Abstract'), @@ -344,8 +385,32 @@ function cfd_case_study_proposal_form($form, &$form_state, $no_js_use = FALSE) ); return $form; } + +function ajax_solver_used_callback($form, $form_state){ + $version_id = isset($form_state['values']['version']) ? $form_state['values']['version'] : key($version_options); + $simulation_id = isset($form_state['values']['simulation_type']) ? $form_state['values']['simulation_type'] : key($simulation_type_options); + if($simulation_id < 13){ + $form['solver_used']['#options'] = _cs_list_of_solvers($version_id, $simulation_id); + $form['solver_used']['#required'] = TRUE; + $form['solver_used']['#validated'] = TRUE; + $commands[] = ajax_command_replace('#ajax-solver-replace', drupal_render($form['solver_used'])); + $commands[] = ajax_command_html('#ajax-solver-text-replace', ''); + } + else{ + $commands[] = ajax_command_html('#ajax-solver-replace', ''); + $form['solver_used_text']['#required'] = TRUE; + $form['solver_used_text']['#validated'] = TRUE; + $commands[] = ajax_command_replace('#ajax-solver-text-replace', drupal_render($form['solver_used_text'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + function cfd_case_study_proposal_form_validate($form, &$form_state) { + //var_dump($form_state['values']['solver_used']);die; if($form_state['values']['cfd_project_title_check'] == 1) { $project_title = $form_state['values']['cfd_case_study_name_dropdown']; @@ -424,20 +489,28 @@ function cfd_case_study_proposal_form_validate($form, &$form_state) { form_set_error('project_title', t('Project title shoud not be empty')); }*/ - if ($form_state['values']['solver_used'] != '') + + if ($form_state['values']['simulation_type'] < 13) { + if($form_state['values']['solver_used'] == '0'){ + form_set_error('solver_used', t('Please select an option')); + } + } + else if ($form_state['values']['simulation_type'] == 13) { + if ($form_state['values']['solver_used_text'] != '') { - if (strlen($form_state['values']['solver_used']) > 50) + if (strlen($form_state['values']['solver_used_text']) > 100) { - form_set_error('solver_used', t('Maximum charater limit is 50 charaters only, please check the length of the solver used')); + form_set_error('solver_used_text', t('Maximum charater limit is 100 charaters only, please check the length of the solver used')); } //strlen($form_state['values']['project_title']) > 250 - else if (strlen($form_state['values']['solver_used']) < 7) + else if (strlen($form_state['values']['solver_used_text']) < 7) { - form_set_error('project_title', t('Minimum charater limit is 7 charaters, please check the length of the solver used')); + form_set_error('solver_used_text', t('Minimum charater limit is 7 charaters, please check the length of the solver used')); } //strlen($form_state['values']['project_title']) < 10 - } //$form_state['values']['project_title'] != '' + } else { - form_set_error('solver_used', t('Solver used cannot be empty')); + form_set_error('solver_used_text', t('Solver used cannot be empty')); + } } if(strtotime(date($form_state['values']['expected_date_of_completion'])) < time()) { @@ -456,7 +529,7 @@ function cfd_case_study_proposal_form_validate($form, &$form_state) $form_state['values']['how_did_you_know_about_project'] = $form_state['values']['others_how_did_you_know_about_project']; } } - if ($form_state['values']['faculty_name'] != '' || $form_state['values']['faculty_name'] != "NULL") { + /*if ($form_state['values']['faculty_name'] != '' || $form_state['values']['faculty_name'] != "NULL") { if($form_state['values']['faculty_email'] == '' || $form_state['values']['faculty_email'] == "NULL") { form_set_error('faculty_email', t('Please enter the email id of your faculty')); @@ -464,7 +537,7 @@ function cfd_case_study_proposal_form_validate($form, &$form_state) if($form_state['values']['faculty_department'] == '' || $form_state['values']['faculty_department'] == 'NULL'){ form_set_error('faculty_department', t('Please enter the Department of your faculty')); } - } + }*/ if (isset($_FILES['files'])) { @@ -523,6 +596,13 @@ function cfd_case_study_proposal_form_submit($form, &$form_state) $proposar_name = $v['name_title'] . ' ' . $v['contributor_name']; $university = $v['university']; $directory_name = _df_dir_name($project_title, $proposar_name); + $simulation_id = $v['simulation_type']; + if($simulation_id < 13){ + $solver = $v['solver_used']; + } + else{ + $solver = $v['solver_used_text']; + } $result = "INSERT INTO {case_study_proposal} ( uid, @@ -541,6 +621,8 @@ function cfd_case_study_proposal_form_submit($form, &$form_state) state, country, project_title, + version_id, + simulation_type_id, solver_used, directory_name, approval_status, @@ -567,6 +649,8 @@ function cfd_case_study_proposal_form_submit($form, &$form_state) :state, :country, :project_title, + :version_id, + :simulation_type_id, :solver_used, :directory_name, :approval_status, @@ -593,7 +677,9 @@ function cfd_case_study_proposal_form_submit($form, &$form_state) ":state" => $v['all_state'], ":country" => $v['country'], ":project_title" => $project_title, - ":solver_used" => $v['solver_used'], + ":version_id" => $v['version'], + ":simulation_type_id" => $simulation_id, + ":solver_used" => $solver, ":directory_name" => $directory_name, ":approval_status" => 0, ":is_completed" => 0, |