diff options
Diffstat (limited to 'proposal.inc')
-rwxr-xr-x | proposal.inc | 170 |
1 files changed, 166 insertions, 4 deletions
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 |