diff options
author | Sashi20 | 2021-09-08 17:24:57 +0530 |
---|---|---|
committer | GitHub | 2021-09-08 17:24:57 +0530 |
commit | 3cc55a7692074b8b091b7476573476860e65f4fe (patch) | |
tree | 8e1b08e7d025cc02e5f2d480203be9383d1fbc18 | |
parent | 400c7d35e7fe3a819a005b651f371902895f2e56 (diff) | |
parent | 5d34b8eda7e2766baacc654eb1e10f439cb69112 (diff) | |
download | r_lab_migration-3cc55a7692074b8b091b7476573476860e65f4fe.tar.gz r_lab_migration-3cc55a7692074b8b091b7476573476860e65f4fe.tar.bz2 r_lab_migration-3cc55a7692074b8b091b7476573476860e65f4fe.zip |
Merge pull request #9 from Saketh1499/development
Updating country fields in proposal form
-rwxr-xr-x | download.inc | 22 | ||||
-rwxr-xr-x | lab_migration.module | 67 | ||||
-rwxr-xr-x | manage_proposal.inc | 28 | ||||
-rwxr-xr-x | proposal.inc | 170 | ||||
-rwxr-xr-x | settings.inc | 10 |
5 files changed, 291 insertions, 6 deletions
diff --git a/download.inc b/download.inc index d95c5a2..04fd147 100755 --- a/download.inc +++ b/download.inc @@ -281,3 +281,25 @@ function lab_migration_download_lab() drupal_goto('lab-migration/lab-migration-run'); } } +function lab_migration_download_syllabus_copy() +{ + $proposal_id = (int)arg(3); + $root_path = lab_migration_path(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $query->range(0, 1); + $result = $query->execute(); + $syllabus_copy_file_data = $result->fetchObject(); + $syllabus_copy_file_name = substr($syllabus_copy_file_data->syllabus_copy_file_path, strrpos($syllabus_copy_file_data->syllabus_copy_file_path, '/') + 1); + error_reporting(0); //Errors may corrupt download + ob_start(); //Insert this + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-disposition: attachment; filename="' . $syllabus_copy_file_name . '"'); + header('Content-Length: ' . filesize($root_path . $syllabus_copy_file_data->syllabus_copy_file_path)); + ob_clean(); + ob_end_flush(); + readfile($root_path . $syllabus_copy_file_data->syllabus_copy_file_path); + exit; +}
\ No newline at end of file diff --git a/lab_migration.module b/lab_migration.module index cf40af6..b919211 100755 --- a/lab_migration.module +++ b/lab_migration.module @@ -569,6 +569,16 @@ function lab_migration_menu() ), 'file' => 'pdf/verify_lab_migration_certificates.inc' ); + $items['lab-migration/download/syllabus-copy-file'] = array( + 'title' => 'Syllabus Copy Download', + 'description' => 'Syllabus Copy Download', + 'page callback' => 'lab_migration_download_syllabus_copy', + 'access arguments' => array( + 'lab migration bulk manage code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); return $items; } /** @@ -836,7 +846,59 @@ function lm_ucname($string) } return $string; } - + + function _lab_migration_list_of_city_pincode($city=Null, $state=NULL, $district=NULL) +{ + $pincode = array(); + if($city){ + $pincode_list = db_query("SELECT pincode FROM all_india_pincode WHERE city = :city AND state = :state AND district = :district", array(':city' => $city,':state'=> $state, ':district' => $district)); + while ($pincode_list_data = $pincode_list->fetchObject()) + { + $pincode[$pincode_list_data->pincode] = $pincode_list_data->pincode; + } + } + else{ + $pincode[000000] = '000000'; + } + return $pincode; +} + +function _lab_migration_list_of_cities($state=Null, $district=NULL) +{ + $city = array(''=> '- Select -'); + if($state){ + $city_list = db_query("SELECT city FROM all_india_pincode WHERE state = :state AND district = :district ORDER BY city ASC", array(':state'=> $state, ':district' =>$district)); + while ($city_list_data = $city_list->fetchObject()) + { + $city[$city_list_data->city] = $city_list_data->city; + } + } + return $city; +} + +function _lab_migration_list_of_district($state=Null) +{ + $district = array(''=> '- Select -'); + if($state){ + $district_list = db_query("SELECT district FROM all_india_pincode WHERE state = :state ORDER BY district ASC", array(':state'=> $state)); + while ($district_list_data = $district_list->fetchObject()) + { + $district[$district_list_data->district] = $district_list_data->district; + } + } + return $district; +} + +function _lab_migration_list_of_states() +{ + $states = array(''=> '- Select -'); + $states_list = db_query("SELECT state FROM all_india_pincode WHERE country = 'India' ORDER BY state ASC"); + while ($states_list_data = $states_list->fetchObject()) + { + $states[$states_list_data->state] = $states_list_data->state; + } + return $states; +} function _lm_list_of_states() { $states = array(0 => '-Select-'); @@ -930,7 +992,8 @@ function _list_all_lm_certificates() 'Institute name', 'Name', 'Type', - 'Download Certificates' + 'Download Certificates', + 'Edit Certificates' ); $output .= theme('table', array( 'header' => $search_header, diff --git a/manage_proposal.inc b/manage_proposal.inc index 1a140d0..6e037ae 100755 --- a/manage_proposal.inc +++ b/manage_proposal.inc @@ -276,6 +276,13 @@ function lab_migration_proposal_approval_form($form, $form_state) '#markup' => $experiment_list, '#title' => t('Experiments') ); + if ($proposal_data->syllabus_copy_file_path != "None") + { + $form['syllabus_copy_file_path'] = array( + '#type' => 'markup', + '#markup' => l('Click here to download uploaded syllabus copy', 'lab-migration/download/syllabus-copy-file/' . $proposal_id) . "<br><br>" + ); + } //$row->samplefilepath != "None" if ($proposal_data->solution_provider_uid == 0) { $solution_provider = "User will not provide solution, we will have to provide solution"; @@ -499,6 +506,26 @@ function lab_migration_proposal_status_form($form, $form_state) '#markup' => $proposal_data->university, '#title' => t('University/Institute') ); + $form['country'] = array( + '#type' => 'item', + '#markup' => $proposal_data->country, + '#title' => t('Country') + ); + $form['all_state'] = array( + '#type' => 'item', + '#markup' => $proposal_data->state, + '#title' => t('State') + ); + $form['city'] = array( + '#type' => 'item', + '#markup' => $proposal_data->city, + '#title' => t('City') + ); + $form['pincode'] = array( + '#type' => 'item', + '#markup' => $proposal_data->pincode, + '#title' => t('Pincode/Postal code') + ); $form['lab_title'] = array( '#type' => 'item', '#markup' => $proposal_data->lab_title, @@ -857,6 +884,7 @@ function lab_migration_proposal_edit_form($form, $form_state) 'placeholder' => 'Insert pincode of your city/ village....' ) ); + $form['lab_title'] = array( '#type' => 'textfield', '#title' => t('Title of the Lab'), diff --git a/proposal.inc b/proposal.inc index bc75e4c..932e598 100755 --- a/proposal.inc +++ b/proposal.inc @@ -23,6 +23,15 @@ lab_migration_solution : approval_status function lab_migration_proposal_form($form, &$form_state) { global $user; + $form = array(); + $state = _lab_migration_list_of_states(); + $selected_state = isset($form_state['values']['all_state'])?$form_state['values']['all_state']:key($state); + $district = _lab_migration_list_of_district(); + $selected_district = isset($form_state['values']['district'])?$form_state['values']['district']:key($district); + $city = _lab_migration_list_of_cities(); + $selected_city = isset($form_state['values']['city'])?$form_state['values']['city']:key($city); + $pincode = _lab_migration_list_of_city_pincode(); + $selected_pincode = isset($form_state['values']['picode'])?$form_state['values']['pincode']:key($pincode); /************************ start approve book details ************************/ 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'); @@ -101,7 +110,7 @@ function lab_migration_proposal_form($form, &$form_state) 'placeholder' => 'Insert full name of your institute/ university.... ' ) ); - $form['country'] = array( + $form['country'] = array( '#type' => 'select', '#title' => t('Country'), '#options' => array( @@ -217,6 +226,22 @@ function lab_migration_proposal_form($form, &$form_state) ) ) ); + + $form['syllabus_copy'] = array( + '#type' => 'fieldset', + '#title' => t('<span class="form-required form-item" title="This field is required.">Syllabus copy (PDF) Files *</span>'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + $form['syllabus_copy']['syllabus_copy_file'] = array( + '#type' => 'file', + '#title' => t('Upload pdf file'), + '#size' => 48, + '#description' => t('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_syllabus_file_extensions', '') . '</span>' + ); + $form['lab_title'] = array( '#type' => 'textfield', '#title' => t('Title of the Lab'), @@ -383,6 +408,44 @@ 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']['syllabus_copy_file'])) + form_set_error('syllabus_copy_file', t('Please upload pdf 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, 'syllabus')) + $file_type = 'S'; + else + $file_type = 'U'; + $allowed_extensions_str = ''; + switch ($file_type) + { + case 'S': + $allowed_extensions_str = variable_get('lab_migration_syllabus_file_extensions', ''); + break; + } //$file_type + $allowed_extensions = explode(',', $allowed_extensions_str); + $allowd_file = strtolower($_FILES['files']['name'][$file_form_name]); + $allowd_files = explode('.', $allowd_file); + $temp_extension = end($allowd_files); + 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 + } //isset($_FILES['files']) + return; } function lab_migration_proposal_form_submit($form, &$form_state) @@ -400,6 +463,7 @@ function lab_migration_proposal_form_submit($form, &$form_state) $solution_provider_contact_ph = ''; $solution_provider_department = ''; $solution_provider_university = ''; + $syllabus_copy_file_path = ''; if ($form_state['values']['solution_provider_uid'] == "1") { $solution_provider_uid = $user->uid; @@ -430,11 +494,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, r_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, directory_name) VALUES + (uid, approver_uid, name_title, name, contact_ph, department, university, city, pincode, state, country, r_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, directory_name,syllabus_copy_file_path) VALUES (:uid, :approver_uid, :name_title, :name, :contact_ph, :department, :university, :city, :pincode, :state, :country, :r_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, :directory_name)"; + :solution_provider_contact_ph, :solution_provider_department, :solution_provider_university, :directory_name,:syllabus_copy_file_path)"; $args = array( ":uid" => $user->uid, ":approver_uid" => 0, @@ -461,11 +525,47 @@ function lab_migration_proposal_form_submit($form, &$form_state) ":solution_provider_contact_ph" => $solution_provider_contact_ph, ":solution_provider_department" => $solution_provider_department, ":solution_provider_university" => $solution_provider_university, - ":directory_name" => $directory_name + ":directory_name" => $directory_name, + ":syllabus_copy_file_path" => "", ); $proposal_id = db_query($result, $args, array( 'return' => Database::RETURN_INSERT_ID )); + $root_path = lab_migration_path(); + $dest_path = $proposal_id . '/'; + 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'); + return; + } //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 syllabus_copy_file_path = :syllabus_copy_file_path WHERE id = :id"; + $args = array( + ":syllabus_copy_file_path" => $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 : ' . $dest_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'); @@ -532,3 +632,65 @@ function _lm_dir_name($lab, $name, $university) $directory_name = str_replace("__", "_", str_replace(" ", "_", $dir_name)); return $directory_name; } + +function ajax_get_lm_city_list_callback($form, $form_state) +{ + $state_default_value = $form_state['values']['all_state']; + $district_default_value = $form_state['values']['district']; + if ($district_default_value != '0') + { + $form['city']['#options'] = _lab_migration_list_of_cities($state_default_value, $district_default_value); + $commands[] = ajax_command_replace("#ajax-city-list-replace", drupal_render($form['city'])); + $form['pincode']['#options'] = array('0' => '- Select -'); + $commands[] = ajax_command_replace("#ajax-pincode-list-replace", drupal_render($form['pincode'])); + }else{ + $form['city']['#options'] = array('0' => '- Select -'); + $commands[] = ajax_command_replace("#ajax-city-list-replace", drupal_render($form['city'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function ajax_get_lm_district_list_callback($form, $form_state) +{ + $state_default_value = $form_state['values']['all_state']; + if ($state_default_value != '0') + { + $form['district']['#options'] = _lab_migration_list_of_district($state_default_value); + $commands[] = ajax_command_replace("#ajax-district-list-replace", drupal_render($form['district'])); + $form['pincode']['#options'] = array('0' =>'- Select -'); + $commands[] = ajax_command_replace("#ajax-pincode-list-replace", drupal_render($form['pincode'])); + $form['city']['#options'] = array('0' => '- Select -'); + $commands[] = ajax_command_replace("#ajax-city-list-replace", drupal_render($form['city'])); + }else{ + $form['district']['#options'] = array('0' => '- Select -'); + $commands[] = ajax_command_replace("#ajax-district-list-replace", drupal_render($form['district'])); + $form['pincode']['#options'] = array('0' =>'- Select -'); + $commands[] = ajax_command_replace("#ajax-pincode-list-replace", drupal_render($form['pincode'])); + $form['city']['#options'] = array('0' => '- Select -'); + $commands[] = ajax_command_replace("#ajax-city-list-replace", drupal_render($form['city'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function ajax_get_lm_city_pincode_list_callback($form, $form_state) +{ + $city_default_value = $form_state['values']['city']; + $state_default_value = $form_state['values']['all_state']; + $district_default_value = $form_state['values']['district']; + if ($city_default_value != '0') + { + $form['pincode']['#options'] = _lab_migration_list_of_city_pincode($city_default_value,$state_default_value,$district_default_value); + $commands[] = ajax_command_replace("#ajax-pincode-list-replace", drupal_render($form['pincode'])); + }else{ + $form['pincode']['#options'] = array('0' => '- Select -'); + $commands[] = ajax_command_replace("#ajax-pincode-list-replace", drupal_render($form['pincode'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +}
\ No newline at end of file diff --git a/settings.inc b/settings.inc index 1856a25..aa7945c 100755 --- a/settings.inc +++ b/settings.inc @@ -74,6 +74,15 @@ function lab_migration_settings_form($form, $form_state) '#required' => TRUE, '#default_value' => variable_get('lab_migration_pdf_extensions', '') ); + $form['extensions']['syllabus'] = array( + '#type' => 'textfield', + '#title' => t('Allowed syllabus 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_syllabus_file_extensions', '') + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') @@ -94,5 +103,6 @@ function lab_migration_settings_form_submit($form, &$form_state) variable_set('lab_migration_result_extensions', $form_state['values']['result']); variable_set('lab_migration_xcos_extensions', $form_state['values']['xcos']); variable_set('lab_migration_pdf_extensions', $form_state['values']['pdf']); + variable_set('lab_migration_syllabus_file_extensions', $form_state['values']['syllabus']); drupal_set_message(t('Settings updated'), 'status'); } |