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'); return $msg; } //$user->uid == 0 $query = db_select('dwsim_flowsheet_proposal'); $query->fields('dwsim_flowsheet_proposal'); $query->condition('uid', $user->uid); $query->orderBy('id', 'DESC'); $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) { drupal_set_message(t('We have already received your proposal.'), 'status'); drupal_goto(''); return; } //$proposal_data->approval_status == 0 || $proposal_data->approval_status == 1 } //$proposal_data $form['#attributes'] = array( 'enctype' => "multipart/form-data" ); $form['name_title'] = array( '#type' => 'select', '#title' => t('Title'), '#options' => array( 'Dr' => 'Dr', 'Prof' => 'Prof', 'Mr' => 'Mr', 'Mrs' => 'Mrs', 'Ms' => 'Ms' ), '#required' => TRUE ); $form['student_name'] = array( '#type' => 'textfield', '#title' => t('Name of the student'), '#size' => 250, '#attributes' => array( 'placeholder' => t('Enter your full name.....') ), '#maxlength' => 250, '#required' => TRUE ); $form['month_year_of_degree'] = array( '#type' => 'date_popup', '#title' => t('Month and year of award of degree'), '#date_label_position' => '', '#description' => '', '#default_value' => '', '#date_format' => 'M-Y', '#date_increment' => 0, '#date_year_range' => '1960:+0', '#datepicker_options' => array( 'maxDate' => 0 ), '#required' => TRUE ); $form['student_email_id'] = array( '#type' => 'textfield', '#title' => t('Email'), '#size' => 30, '#value' => $user->mail, '#disabled' => TRUE ); $form['project_guide_name'] = array( '#type' => 'textfield', '#title' => t('Project guide'), '#size' => 250, '#attributes' => array( 'placeholder' => t('Enter full name of project guide') ), '#maxlength' => 250 ); $form['project_guide_email_id'] = array( '#type' => 'textfield', '#title' => t('Project guide email'), '#size' => 30 ); $form['university'] = array( '#type' => 'textfield', '#title' => t('University/ Institute'), '#size' => 80, '#maxlength' => 200, '#required' => TRUE, '#attributes' => array( 'placeholder' => 'Insert full name of your institute/ university.... ' ) ); $form['country'] = array( '#type' => 'select', '#title' => t('Country'), '#options' => array( 'India' => 'India', 'Others' => 'Others' ), '#required' => TRUE, '#tree' => TRUE, '#validated' => TRUE ); $form['other_country'] = array( '#type' => 'textfield', '#title' => t('Other than India'), '#size' => 100, '#attributes' => array( 'placeholder' => t('Enter your country name') ), '#states' => array( 'visible' => array( ':input[name="country"]' => array( 'value' => 'Others' ) ) ) ); $form['other_state'] = array( '#type' => 'textfield', '#title' => t('State other than India'), '#size' => 100, '#attributes' => array( 'placeholder' => t('Enter your state/region name') ), '#states' => array( 'visible' => array( ':input[name="country"]' => array( 'value' => 'Others' ) ) ) ); $form['other_city'] = array( '#type' => 'textfield', '#title' => t('City other than India'), '#size' => 100, '#attributes' => array( 'placeholder' => t('Enter your city name') ), '#states' => array( 'visible' => array( ':input[name="country"]' => array( 'value' => 'Others' ) ) ) ); $form['all_state'] = array( '#type' => 'select', '#title' => t('State'), '#options' => _df_list_of_states(), '#validated' => TRUE, '#states' => array( 'visible' => array( ':input[name="country"]' => array( 'value' => 'India' ) ) ) ); $form['city'] = array( '#type' => 'select', '#title' => t('City'), '#options' => _df_list_of_cities(), '#states' => array( 'visible' => array( ':input[name="country"]' => array( 'value' => 'India' ) ) ) ); $form['pincode'] = array( '#type' => 'textfield', '#title' => t('Pincode'), '#size' => 30, '#maxlength' => 6, '#required' => False, '#attributes' => array( 'placeholder' => 'Enter pincode....' ) ); /***************************************************************************/ $form['hr'] = array( '#type' => 'item', '#markup' => '
' ); $form['project_title'] = array( '#type' => 'textarea', '#title' => t('Project Title'), '#size' => 250, '#description' => t('Maximum character limit is 250'), '#required' => TRUE ); $form['version'] = array( '#type' => 'select', '#title' => t('Version'), '#options' => _df_list_of_software_version(), '#required' => TRUE ); $form['older'] = array( '#type' => 'textfield', '#title' => t('Other Version'), '#size' => 30, '#maxlength' => 50, //'#required' => TRUE, '#description' => t('Specify the Older version used as format "DWSIM v2.0"'), '#states' => array( 'visible' => array( ':input[name="version"]' => array( 'value' => 'Old version' ) ) ) ); $form['process_development_compound_name'] = array( '#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)'), '#required' => TRUE ); $form['dwsim_database_compound_name'] = array( '#type' => 'select', '#title' => t('List of compounds from DWSIM Database used in process flowsheet'), '#multiple' => TRUE, '#description' => t('List the compound name from DWSIM database as shown below: Ex: Ethylene (74-85-1)[You can select multiple options by holding ctrl + left key of mouse]'), '#options' => _df_list_of_dwsim_compound(), '#required' => TRUE ); $form['ucompound'] = array( '#type' => 'checkbox', '#title' => t('Upload user defind compound'), '#options' => array( "1" => "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'), '#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( 'checked' => True ) ) ) ); $form['upload_u_compound']['upload_user_compound'] = array( '#type' => 'file', '#title' => t('Upload user defined compound'), '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '
' . t('Allowed file extensions : ') . variable_get('dwsim_flowsheet_user_defind_compound_source_extensions', '') . '', '#states' => array( 'visible' => array( ':input[name="ucompound"]' => array( 'checked' => True ) ) ) ); $form['termconditions'] = array( '#type' => 'checkboxes', '#title' => t('Terms And Conditions'), '#options' => array( 'status' => t('I agree to the Terms and Conditions') ), '#required' => TRUE ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') ); return $form; } function dwsim_flowsheet_proposal_form_validate($form, &$form_state) { if ($form_state['values']['term_condition'] == '1') { form_set_error('other_state', t('Enter state name')); // $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'] == '') { form_set_error('other_country', t('Enter country name')); // $form_state['values']['country'] = $form_state['values']['other_country']; } //$form_state['values']['other_country'] == '' else { $form_state['values']['country'] = $form_state['values']['other_country']; } 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 { $form_state['values']['all_state'] = $form_state['values']['other_state']; } 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 { $form_state['values']['city'] = $form_state['values']['other_city']; } } //$form_state['values']['country'] == 'Others' 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'] == '') { 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'] == '') { form_set_error('city', t('Select city name')); // $form_state['values']['country'] = $form_state['values']['other_country']; } //$form_state['values']['city'] == '' } 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']) { $dwsim_database_compound_name = implode(", ", $_POST['dwsim_database_compound_name']); $form_state['values']['dwsim_database_compound_name'] = $dwsim_database_compound_name; } //$form_state['values']['dwsim_database_compound_name'] 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 sample code main or source file.')); /* check for valid filename extensions */ 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) { case 'S': $allowed_extensions_str = variable_get('dwsim_flowsheet_user_defind_compound_source_extensions', ''); break; } //$file_type $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 (!textbook_companion_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 } //isset($_FILES['files']) return; } function dwsim_flowsheet_proposal_form_submit($form, &$form_state) { global $user; 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') { $form_state['values']['version'] = $form_state['values']['older']; } //$form_state['values']['version'] == 'Old version' /* inserting the user proposal */ $v = $form_state["values"]; $project_title = $v['project_title']; $proposar_name = $v['name_title'] . ' ' . $v['student_name']; $university = $v['university']; $month_year_of_degree = $v['month_year_of_degree']; $directory_name = _df_dir_name($project_title); $result = "INSERT INTO {dwsim_flowsheet_proposal} ( uid, approver_uid, name_title, student_name, month_year_of_degree, university, city, pincode, state, country, version, project_guide_name, project_guide_email_id, project_title, process_development_compound_name, dwsim_database_compound_name, user_defined_compounds_used_in_process, approval_status, dissapproval_reason, creation_date, approval_date, directory_name, user_defined_compound_filepath ) VALUES ( :uid, :approver_uid, :name_title, :student_name, :month_year_of_degree, :university, :city, :pincode, :state, :country, :version, :project_guide_name, :project_guide_email_id, :project_title, :process_development_compound_name, :dwsim_database_compound_name, :user_defined_compounds_used_in_process, :approval_status, :dissapproval_reason, :creation_date, :approval_date, :directory_name, :user_defined_compound_filepath )"; $args = array( ":uid" => $user->uid, ":approver_uid" => 0, ":name_title" => $v['name_title'], ":student_name" => _df_sentence_case($v['student_name']), ":month_year_of_degree" => $month_year_of_degree, ":university" => _df_sentence_case($v['university']), ":city" => $v['city'], ":pincode" => $v['pincode'], ":state" => $v['all_state'], ":country" => $v['country'], ":version" => $v['version'], ":project_guide_name" => _df_sentence_case($v['project_guide_name']), ":project_guide_email_id" => $v['project_guide_email_id'], ":project_title" => _df_dir_name($v['project_title']), ":process_development_compound_name" => _df_sentence_case($v['process_development_compound_name']), ":dwsim_database_compound_name" => $v['dwsim_database_compound_name'], ":user_defined_compounds_used_in_process" => _df_sentence_case($v['user_defined_compounds_used_in_process_flowsheetcompound_name']), ":approval_status" => 0, ":dissapproval_reason" => "NULL", ":creation_date" => time(), ":approval_date" => 0, ":directory_name" => $directory_name, ":user_defined_compound_filepath" => "NULL" ); //var_dump($args);die; $proposal_id = db_query($result, $args, array( 'return' => Database::RETURN_INSERT_ID )); $root_path = dwsim_flowsheet_document_path(); $dest_path1 = $directory_name . '/'; $dest_path = $dest_path1 . 'user_defined_compound/'; $db_path = 'user_defined_compound/'; if (!is_dir($root_path . $dest_path1)) mkdir($root_path . $dest_path1); 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 {dwsim_flowsheet_proposal} SET user_defined_compound_filepath = :user_defined_compound_filepath WHERE id = :id"; $args = array( ":user_defined_compound_filepath" => $dest_path . $_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 : ' . $db_path . '/' . $file_name, 'error'); } } //$file_name } //$_FILES['files']['name'] as $file_form_name => $file_name if (!$proposal_id) { drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error'); return; } //!$proposal_id /* sending email */ $email_to = $user->mail; $from = variable_get('dwsim_flowsheet_from_email', ''); $bcc = variable_get('dwsim_flowsheet_emails', ''); $cc = variable_get('dwsim_flowsheet_cc_emails', ''); $params['dwsim_flowsheet_proposal_received']['proposal_id'] = $proposal_id; $params['dwsim_flowsheet_proposal_received']['user_id'] = $user->uid; $params['dwsim_flowsheet_proposal_received']['headers'] = array( 'From' => $from, 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', 'Content-Transfer-Encoding' => '8Bit', 'X-Mailer' => 'Drupal', 'Cc' => $cc, 'Bcc' => $bcc ); if (!drupal_mail('dwsim_flowsheet', 'dwsim_flowsheet_proposal_received', $email_to, user_preferred_language($user), $params, $from, TRUE)) drupal_set_message('Error sending email message.', 'error'); drupal_set_message(t('We have received you DWSIM Chemical Process Flowsheeting proposal. We will get back to you soon.'), 'status'); drupal_goto(''); }