summaryrefslogtreecommitdiff
path: root/proposal.inc
diff options
context:
space:
mode:
Diffstat (limited to 'proposal.inc')
-rwxr-xr-xproposal.inc342
1 files changed, 284 insertions, 58 deletions
diff --git a/proposal.inc b/proposal.inc
index 77a884f..952b61d 100755
--- a/proposal.inc
+++ b/proposal.inc
@@ -20,11 +20,12 @@ dwsim_flowsheet_solution : approval_status
1 - Approved
2 - Disapproved (delete it)
*/
-function dwsim_flowsheet_proposal_form($form, &$form_state)
+function dwsim_flowsheet_proposal_form($form, &$form_state, $no_js_use = FALSE)
{
global $user;
/************************ start approve book details ************************/
- if ($user->uid == 0) {
+ if ($user->uid == 0)
+ {
$msg = drupal_set_message(t('It is mandatory to ' . l('login', 'user') . ' on this website to access the lab proposal form. If you are new user please create a new account first.'), 'error');
//drupal_goto('dwsim-flowsheet-project');
drupal_goto('user');
@@ -37,8 +38,10 @@ function dwsim_flowsheet_proposal_form($form, &$form_state)
$query->range(0, 1);
$proposal_q = $query->execute();
$proposal_data = $proposal_q->fetchObject();
- if ($proposal_data) {
- if ($proposal_data->approval_status == 0 || $proposal_data->approval_status == 1) {
+ if ($proposal_data)
+ {
+ if ($proposal_data->approval_status == 0 || $proposal_data->approval_status == 1)
+ {
drupal_set_message(t('We have already received your proposal.'), 'status');
drupal_goto('');
return;
@@ -59,9 +62,9 @@ function dwsim_flowsheet_proposal_form($form, &$form_state)
),
'#required' => TRUE
);
- $form['student_name'] = array(
+ $form['contributor_name'] = array(
'#type' => 'textfield',
- '#title' => t('Name of the student'),
+ '#title' => t('Name of the contributor'),
'#size' => 250,
'#attributes' => array(
'placeholder' => t('Enter your full name.....')
@@ -69,6 +72,25 @@ function dwsim_flowsheet_proposal_form($form, &$form_state)
'#maxlength' => 250,
'#required' => TRUE
);
+ $form['contributor_contact_no'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Contact No.'),
+ '#size' => 10,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your contact number')
+ ),
+ '#maxlength' => 250
+ );
+ $form['gender'] = array(
+ '#type' => 'select',
+ '#title' => t('Gender'),
+ '#options' => array(
+ 'Male' => 'Male',
+ 'Female' => 'Female',
+ 'Other' => 'Other'
+ ),
+ '#required' => TRUE
+ );
$form['month_year_of_degree'] = array(
'#type' => 'date_popup',
'#title' => t('Month and year of award of degree'),
@@ -83,7 +105,7 @@ function dwsim_flowsheet_proposal_form($form, &$form_state)
),
'#required' => TRUE
);
- $form['student_email_id'] = array(
+ $form['contributor_email_id'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#size' => 30,
@@ -243,8 +265,16 @@ function dwsim_flowsheet_proposal_form($form, &$form_state)
'#type' => 'textfield',
'#title' => t('Name of compound for which process development is carried out'),
'#size' => 50,
- '#description' => t('Mention the compound name with CAS No as shown below:
-Ex: Ethanol (64-17-5)'),
+ '#description' => t('Mention the compound name as shown below:
+Ex: Ethanol'),
+ '#required' => TRUE
+ );
+ $form['process_development_compound_cas_no'] = array(
+ '#type' => 'textfield',
+ '#title' => t('CAS number for compound which process development is carried out'),
+ '#size' => 50,
+ '#description' => t('Mention the compound CAS No as shown below:
+Ex: 64-17-5'),
'#required' => TRUE
);
$form['dwsim_database_compound_name'] = array(
@@ -260,9 +290,22 @@ Ex: Ethanol (64-17-5)'),
'#type' => 'checkbox',
'#title' => t('Upload user defind compound')
);
- $form['user_defined_compounds_used_in_process_flowsheetcompound_name'] = array(
- '#type' => 'textarea',
- '#title' => t('List of user defined compounds used in process flowsheet'),
+ /*$form['user_defined_compounds_used_in_process_flowsheetcompound_name'] = array(
+ '#type' => 'textarea',
+ '#title' => t('List of user defined compounds used in process flowsheet'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="ucompound"]' => array(
+ 'checked' => True
+ )
+ )
+ )
+ );*/
+ $form['upload_u_compound'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Upload user defind compound'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
'#states' => array(
'visible' => array(
':input[name="ucompound"]' => array(
@@ -271,11 +314,11 @@ Ex: Ethanol (64-17-5)'),
)
)
);
- $form['upload_u_compound'] = array(
+ $form['upload_u_compound']['udc_field1_fieldset'] = array(
'#type' => 'fieldset',
- '#title' => t('Upload user defind compound'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
+ '#tree' => TRUE,
+ '#prefix' => '<div id="udc-field1-fieldset-wrapper">',
+ '#suffix' => '</div>',
'#states' => array(
'visible' => array(
':input[name="ucompound"]' => array(
@@ -284,6 +327,68 @@ Ex: Ethanol (64-17-5)'),
)
)
);
+ if (empty($form_state['user_defined_compound_num']))
+ {
+ $form_state['user_defined_compound_num'] = 1;
+ } //empty($form_state['user_defined_compound_num'])
+ $udc_temp1 = 0;
+ for ($udc_i = 0; $udc_i < $form_state['user_defined_compound_num']; $udc_i++)
+ {
+ $udc_temp1 = $udc_i;
+ $form['upload_u_compound']['udc_field1_fieldset'][$udc_i]["compound"] = array(
+ "#type" => "textfield",
+ "#title" => "Name of Product Compound " . ($udc_temp1 + 1),
+ "#default_value" => ""
+ );
+ $form['upload_u_compound']['udc_field1_fieldset'][$udc_i]["cas_no"] = array(
+ "#type" => "textfield",
+ "#title" => "CAS Number " . ($udc_temp1 + 1),
+ "#default_value" => ""
+ );
+ } //$i = 0; $i < $form_state['step1_num_compound']; $i++
+ $form['upload_u_compound']['udc_field1_fieldset']["udc_compound_count"] = array(
+ "#type" => "hidden",
+ "#value" => $udc_temp1
+ );
+ $form['upload_u_compound']['udc_field1_fieldset']['add_compound'] = array(
+ '#type' => 'submit',
+ '#value' => t('Add more compound'),
+ '#limit_validation_errors' => array(),
+ '#submit' => array(
+ 'udc_compound_add_more_add_one'
+ ),
+ '#ajax' => array(
+ 'callback' => 'udc_compound_add_more_callback',
+ 'wrapper' => array(
+ 'udc-field1-fieldset-wrapper'
+ )
+ )
+ );
+ if ($form_state['user_defined_compound_num'] > 1)
+ {
+ $form['upload_u_compound']['udc_field1_fieldset']['remove_compound'] = array(
+ '#type' => 'submit',
+ '#value' => t('Remove compound'),
+ '#limit_validation_errors' => array(),
+ '#submit' => array(
+ 'udc_compound_add_more_remove_one'
+ ),
+ '#ajax' => array(
+ 'callback' => 'udc_compound_add_more_callback',
+ 'wrapper' => array(
+ 'udc-field1-fieldset-wrapper'
+ )
+ )
+ );
+ } //$form_state['step1_num_compound'] > 1
+ if ($no_js_use)
+ {
+ if (!empty($form['upload_u_compound']['udc_field1_fieldset']['remove_compound']['#ajax']))
+ {
+ unset($form['upload_u_compound']['udc_field1_fieldset']['remove_compound']['#ajax']);
+ } //!empty($form['udc_field1_fieldset']['remove_compound']['#ajax'])
+ unset($form['upload_u_compound']['udc_field1_fieldset']['add_compound']['#ajax']);
+ } //$no_js_use
$form['upload_u_compound']['upload_user_compound'] = array(
'#type' => 'file',
'#title' => t('Upload user defined compound'),
@@ -310,99 +415,173 @@ Ex: Ethanol (64-17-5)'),
);
return $form;
}
+/***************************************/
+function udc_compound_add_more_add_one($form, &$form_state)
+{
+ $form_state['user_defined_compound_num']++;
+ $form_state['rebuild'] = TRUE;
+ //$form_state['no_redirect'] = TRUE;
+}
+function udc_compound_add_more_remove_one($form, &$form_state)
+{
+ if ($form_state['user_defined_compound_num'] > 1)
+ {
+ $form_state['user_defined_compound_num']--;
+ } //$form_state['user_defined_compound_num'] > 1
+ $form_state['rebuild'] = TRUE;
+}
+function udc_compound_add_more_callback($form, &$form_state)
+{
+ return $form['upload_u_compound']['udc_field1_fieldset'];
+}
+/***************************************/
function dwsim_flowsheet_proposal_form_validate($form, &$form_state)
{
- if ($form_state['values']['term_condition'] == '1') {
+ if ($form_state['values']['term_condition'] == '1')
+ {
form_set_error('term_condition', t('Please check the terms and conditions'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
} //$form_state['values']['term_condition'] == '1'
- if ($form_state['values']['country'] == 'Others') {
- if ($form_state['values']['other_country'] == '') {
+ if ($form_state['values']['country'] == 'Others')
+ {
+ if ($form_state['values']['other_country'] == '')
+ {
form_set_error('other_country', t('Enter country name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
} //$form_state['values']['other_country'] == ''
- else {
+ else
+ {
$form_state['values']['country'] = $form_state['values']['other_country'];
}
- if ($form_state['values']['other_state'] == '') {
+ if ($form_state['values']['other_state'] == '')
+ {
form_set_error('other_state', t('Enter state name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
} //$form_state['values']['other_state'] == ''
- else {
+ else
+ {
$form_state['values']['all_state'] = $form_state['values']['other_state'];
}
- if ($form_state['values']['other_city'] == '') {
+ if ($form_state['values']['other_city'] == '')
+ {
form_set_error('other_city', t('Enter city name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
} //$form_state['values']['other_city'] == ''
- else {
+ else
+ {
$form_state['values']['city'] = $form_state['values']['other_city'];
}
} //$form_state['values']['country'] == 'Others'
- else {
- if ($form_state['values']['country'] == '') {
+ else
+ {
+ if ($form_state['values']['country'] == '')
+ {
form_set_error('country', t('Select country name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
} //$form_state['values']['country'] == ''
- if ($form_state['values']['all_state'] == '') {
+ if ($form_state['values']['all_state'] == '')
+ {
form_set_error('all_state', t('Select state name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
} //$form_state['values']['all_state'] == ''
- if ($form_state['values']['city'] == '') {
+ if ($form_state['values']['city'] == '')
+ {
form_set_error('city', t('Select city name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
} //$form_state['values']['city'] == ''
}
//Validation for project title
$form_state['values']['project_title'] = trim($form_state['values']['project_title']);
- if ($form_state['values']['project_title'] != '') {
- if (strlen($form_state['values']['project_title']) > 250) {
+ if ($form_state['values']['project_title'] != '')
+ {
+ if (strlen($form_state['values']['project_title']) > 250)
+ {
form_set_error('project_title', t('Maximum charater limit is 250 charaters only, please check the length of the project title'));
} //strlen($form_state['values']['project_title']) > 250
- else if (strlen($form_state['values']['project_title']) < 10) {
+ else if (strlen($form_state['values']['project_title']) < 10)
+ {
form_set_error('project_title', t('Minimum charater limit is 10 charaters, please check the length of the project title'));
} //strlen($form_state['values']['project_title']) < 10
} //$form_state['values']['project_title'] != ''
- else {
+ else
+ {
form_set_error('project_title', t('Project title shoud not be empty'));
}
// validation for Name of compound for which process development is carried out
$form_state['values']['process_development_compound_name'] = trim($form_state['values']['process_development_compound_name']);
- if ($form_state['values']['process_development_compound_name'] != '') {
- if (strlen($form_state['values']['process_development_compound_name']) >= 50) {
+ if ($form_state['values']['process_development_compound_name'] != '')
+ {
+ if (strlen($form_state['values']['process_development_compound_name']) >= 50)
+ {
form_set_error('process_development_compound_name', t('Maximum charater limit is 50 charaters only, please check the length'));
} //strlen($form_state['values']['process_development_compound_name']) >= 50
- else if (strlen($form_state['values']['process_development_compound_name']) < 1) {
+ else if (strlen($form_state['values']['process_development_compound_name']) < 1)
+ {
form_set_error('process_development_compound_name', t('Minimum charater limit is 1 charaters, please check the length'));
} //strlen($form_state['values']['process_development_compound_name']) < 1
} //$form_state['values']['process_development_compound_name'] != ''
- else {
+ else
+ {
form_set_error('process_development_compound_name', t('Field should not be empty'));
}
- if ($form_state['values']['version'] == 'Old version') {
- if ($form_state['values']['older'] == '') {
+ $form_state['values']['process_development_compound_cas_no'] = trim($form_state['values']['process_development_compound_cas_no']);
+ if ($form_state['values']['process_development_compound_cas_no'] != '')
+ {
+ if (strlen($form_state['values']['process_development_compound_cas_no']) < 1)
+ {
+ form_set_error('process_development_compound_cas_no', t('Minimum charater limit is 1 charaters, please check the length'));
+ } //strlen($form_state['values']['process_development_compound_cas_no']) < 1
+ } //$form_state['values']['process_development_compound_cas_no'] != ''
+ else
+ {
+ form_set_error('process_development_compound_cas_no', t('CAS number field should not be empty'));
+ }
+ if ($form_state['values']['version'] == 'Old version')
+ {
+ if ($form_state['values']['older'] == '')
+ {
form_set_error('older', t('Please provide valid version'));
} //$form_state['values']['older'] == ''
} //$form_state['values']['version'] == 'Old version'
- if ($form_state['values']['dwsim_database_compound_name']) {
+ if ($form_state['values']['dwsim_database_compound_name'])
+ {
$dwsim_database_compound_name = implode(", ", $_POST['dwsim_database_compound_name']);
$form_state['values']['dwsim_database_compound_name'] = trim($dwsim_database_compound_name);
} //$form_state['values']['dwsim_database_compound_name']
- if ($form_state['values']['ucompound'] == 1) {
- if (isset($_FILES['files'])) {
+ if ($form_state['values']['ucompound'] == 1)
+ {
+ /* For compounds */
+ /*
+ for ($i = 0; $i <= $v['udc_field1_fieldset']["udc_compound_count"]; $i++)
+ {
+ if ($v['udc_field1_fieldset'][$i]["compound"] == "")
+ {
+ form_set_error('compound', t('Field should not be empty'));
+ }
+ if ($v['udc_field1_fieldset'][$i]["cas_no"] == "")
+ {
+ form_set_error('cas_no', t('Field should not be empty'));
+ }
+ }
+ */
+ if (isset($_FILES['files']))
+ {
/* check if atleast one source or result file is uploaded */
if (!($_FILES['files']['name']['upload_user_compound']))
form_set_error('upload_user_compound', t('Please upload a file.'));
/* check for valid filename extensions */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
- if ($file_name) {
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
/* checking file type */
if (strstr($file_form_name, 'user_compound'))
$file_type = 'S';
else
$file_type = 'U';
$allowed_extensions_str = '';
- switch ($file_type) {
+ switch ($file_type)
+ {
case 'S':
$allowed_extensions_str = variable_get('dwsim_flowsheet_user_defind_compound_source_extensions', '');
break;
@@ -426,17 +605,19 @@ function dwsim_flowsheet_proposal_form_validate($form, &$form_state)
function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
{
global $user;
- if (!$user->uid) {
+ if (!$user->uid)
+ {
drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
return;
} //!$user->uid
- if ($form_state['values']['version'] == 'Old version') {
+ if ($form_state['values']['version'] == 'Old version')
+ {
$form_state['values']['version'] = trim($form_state['values']['older']);
} //$form_state['values']['version'] == 'Old version'
/* inserting the user proposal */
$v = $form_state["values"];
$project_title = trim($v['project_title']);
- $proposar_name = $v['name_title'] . ' ' . $v['student_name'];
+ $proposar_name = $v['name_title'] . ' ' . $v['contributor_name'];
$university = $v['university'];
$month_year_of_degree = $v['month_year_of_degree'];
$directory_name = _df_dir_name($project_title, $proposar_name);
@@ -445,7 +626,9 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
uid,
approver_uid,
name_title,
- student_name,
+ contributor_name,
+ contact_no,
+ gender,
month_year_of_degree,
university,
city,
@@ -457,6 +640,7 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
project_guide_email_id,
project_title,
process_development_compound_name,
+ process_development_compound_cas_number,
dwsim_database_compound_name,
user_defined_compounds_used_in_process,
approval_status,
@@ -470,7 +654,9 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
:uid,
:approver_uid,
:name_title,
- :student_name,
+ :contributor_name,
+ :contact_no,
+ :gender,
:month_year_of_degree,
:university,
:city,
@@ -482,6 +668,7 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
:project_guide_email_id,
:project_title,
:process_development_compound_name,
+ :process_development_compound_cas_number,
:dwsim_database_compound_name,
:user_defined_compounds_used_in_process,
:approval_status,
@@ -495,7 +682,9 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
":uid" => $user->uid,
":approver_uid" => 0,
":name_title" => $v['name_title'],
- ":student_name" => _df_sentence_case(trim($v['student_name'])),
+ ":contributor_name" => _df_sentence_case(trim($v['contributor_name'])),
+ ":contact_no" => $v['contributor_contact_no'],
+ ":gender" => $v['gender'],
":month_year_of_degree" => $month_year_of_degree,
":university" => _df_sentence_case($v['university']),
":city" => $v['city'],
@@ -507,6 +696,7 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
":project_guide_email_id" => trim($v['project_guide_email_id']),
":project_title" => _df_sentence_case($v['project_title']),
":process_development_compound_name" => _df_sentence_case($v['process_development_compound_name']),
+ ":process_development_compound_cas_number" => $v['process_development_compound_cas_no'],
":dwsim_database_compound_name" => trim($v['dwsim_database_compound_name']),
":user_defined_compounds_used_in_process" => _df_sentence_case(trim($v['user_defined_compounds_used_in_process_flowsheetcompound_name'])),
":approval_status" => 0,
@@ -520,7 +710,36 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
$proposal_id = db_query($result, $args, array(
'return' => Database::RETURN_INSERT_ID
));
- if ($form_state['values']['ucompound'] == 1) {
+ if ($form_state['values']['ucompound'] == 1)
+ {
+ /* For adding compounds */
+ $compounds = 0;
+ for ($i = 0; $i <= $v['udc_field1_fieldset']["udc_compound_count"]; $i++)
+ {
+ if ($v['udc_field1_fieldset'][$i]["compound"] != "" && $v['udc_field1_fieldset'][$i]["cas_no"] != "")
+ {
+ $compoundquery = "
+ INSERT INTO dwsim_flowsheet_user_defined_compound
+ (proposal_id, user_defined_compound, cas_no, compound_type)
+ VALUES
+ (:proposal_id, :user_defined_compound, :cas_no, :compound_type)
+ ";
+ $compoundargs = array(
+ ":proposal_id" => $proposal_id,
+ ":user_defined_compound" => $v['udc_field1_fieldset'][$i]["compound"],
+ ":cas_no" => $v['udc_field1_fieldset'][$i]["cas_no"],
+ ":compound_type" => 'U'
+ );
+ /* storing the row id in $result */
+ $compoundresult = db_query($compoundquery, $compoundargs, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ if ($compoundresult != 0)
+ {
+ $compounds++;
+ } //$compoundresult != 0
+ } //$v['udc_field1_fieldset'][$i]["compound"] != ""
+ } //$i = 0; $i <= $v['udc_field1_fieldset']["udc_compound_count"]; $i++
$root_path = dwsim_flowsheet_document_path();
$dest_path1 = $directory_name . '/';
$dest_path2 = 'user_defined_compound/';
@@ -531,16 +750,20 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
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) {
+ 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])) {
+ 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])) {
+ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
$query = "UPDATE {dwsim_flowsheet_proposal} SET user_defined_compound_filepath = :user_defined_compound_filepath WHERE id = :id";
$args = array(
":user_defined_compound_filepath" => $dest_path2 . $_FILES['files']['name'][$file_form_name],
@@ -549,16 +772,19 @@ function dwsim_flowsheet_proposal_form_submit($form, &$form_state)
$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 {
+ else
+ {
drupal_set_message('Error uploading file : ' . $db_path . '/' . $file_name, 'error');
}
} //$file_name
} //$_FILES['files']['name'] as $file_form_name => $file_name
} //$form_state['values']['ucompound'] == 1
- else {
+ else
+ {
$file_name = "Not Uploaded";
}
- if (!$proposal_id) {
+ if (!$proposal_id)
+ {
drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
return;
} //!$proposal_id