diff options
Diffstat (limited to 'textbook_companion.module')
-rwxr-xr-x | textbook_companion.module | 219 |
1 files changed, 202 insertions, 17 deletions
diff --git a/textbook_companion.module b/textbook_companion.module index fcc12fb..8c4bee4 100755 --- a/textbook_companion.module +++ b/textbook_companion.module @@ -905,6 +905,62 @@ function textbook_companion_permission() ), ); } + +function _tbc_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 _tbc_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 _tbc_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 _tbc_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 textbook_companion_aicte_proposal_all() { global $user; @@ -1129,8 +1185,16 @@ function textbook_companion_proposal_all() } function book_proposal_form($form, &$form_state) { - global $user; - $form = array(); + global $user;$form = array(); + $state = _tbc_list_of_states(); + $selected_state = isset($form_state['values']['all_state'])?$form_state['values']['all_state']:key($state); + $district = _tbc_list_of_district(); + $selected_district = isset($form_state['values']['district'])?$form_state['values']['district']:key($district); + $city = _tbc_list_of_cities(); + $selected_city = isset($form_state['values']['city'])?$form_state['values']['city']:key($city); + $pincode = _tbc_list_of_city_pincode(); + $selected_pincode = isset($form_state['values']['picode'])?$form_state['values']['pincode']:key($pincode); + $form['imp_notice'] = array( '#type' => 'item', '#markup' => '<font color="red"><b>Please fill up this form carefully as the details entered here will be exactly written in the Textbook Companion</b></font>' @@ -1260,6 +1324,12 @@ function book_proposal_form($form, &$form_state) 'India' => 'India', 'Others' => 'Others' ), + //'#default_value' => 'India', + '#prefix' => '<div id="ajax-country-list-replace">', + '#suffix' => '</div>', + // '#ajax' => array( + // 'callback' => 'ajax_get_district_list_callback', + // ), '#required' => TRUE, '#tree' => TRUE, '#validated' => TRUE @@ -1311,11 +1381,17 @@ function book_proposal_form($form, &$form_state) ); $form['all_state'] = array( '#type' => 'select', - '#title' => t('State'), - '#selected' => array( - '' => '-select-' - ), - '#options' => _list_of_states(), + '#title' => t('State/UT'), + '#options' => _tbc_list_of_states(), + //'#empty_value' => '0', + //'#empty_option' => '- Select -', + '#default_value' => '0', + '#prefix' => '<div id="ajax-state-list-replace">', + '#suffix' => '</div>', + '#required' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_get_district_list_callback', + ), '#validated' => TRUE, '#states' => array( 'visible' => array( @@ -1325,26 +1401,64 @@ function book_proposal_form($form, &$form_state) ) ) ); + $form['district'] = array( + '#type' => 'select', + '#title' => t('District/Area'), + '#options' => _tbc_list_of_district($selected_state), + //'#empty_value' => '0', + //'#empty_option' => '- Select -', + '#prefix' => '<div id="ajax-district-list-replace">', + '#suffix' => '</div>', + '#validated' => TRUE, + '#required' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_get_city_list_callback', + ), + '#states' => array( + 'visible' => array( + ':input[name="all_state"]' => array( + 'value' => 'India' + ) + ) + ) + ); $form['city'] = array( '#type' => 'select', - '#title' => t('City'), - '#options' => _list_of_cities(), + '#title' => t('City/Area'), + '#options' => _tbc_list_of_cities($selected_state, $selected_district), + //'#empty_value' => '0', + //'#empty_option' => '- Select -', + '#prefix' => '<div id="ajax-city-list-replace">', + '#suffix' => '</div>', + '#validated' => TRUE, + '#required' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_get_city_pincode_list_callback', + ), '#states' => array( 'visible' => array( - ':input[name="country"]' => array( + ':input[name="district"]' => array( 'value' => 'India' ) ) ) ); $form['pincode'] = array( - '#type' => 'textfield', + '#type' => 'select', '#title' => t('Pincode'), - '#size' => 30, - '#maxlength' => 6, - '#required' => True, - '#attributes' => array( - 'placeholder' => 'Enter pincode....' + '#options' => _tbc_list_of_city_pincode($selected_city, $selected_state, $selected_district), + '#prefix' => '<div id="ajax-pincode-list-replace">', + '#suffix' => '</div>', + //'#empty_value' => '0', + //'#empty_option' => '- Select -', + '#required' => TRUE, + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="city"]' => array( + 'value' => 'India' + ) + ) ) ); /***************************************************************************/ @@ -1717,7 +1831,7 @@ function book_proposal_form_submit($form, &$form_state, $directory_name = NULL) $form_state['values']['reason'] = $my_reason; } //isset($_POST['reason']) $query = "INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, name_title, full_name, mobile, how_project, course, branch, university,city,pincode,state,country, faculty, reviewer,reference, completion_date, creation_date, approval_date, proposal_status, r_version, operating_system, teacher_email,reason,samplefilepath,proposal_type,proposed_completion_date, book_download_link) VALUES (:uid, :approver_uid, :name_title, :full_name, :mobile, :how_project, :course, :branch, :university, :city,:pincode,:state,:country, :faculty, :reviewer,:reference, :completion_date, + (uid, approver_uid, name_title, full_name, mobile, how_project, course, branch, university,city,district,pincode,state,country, faculty, reviewer,reference, completion_date, creation_date, approval_date, proposal_status, r_version, operating_system, teacher_email,reason,samplefilepath,proposal_type,proposed_completion_date, book_download_link) VALUES (:uid, :approver_uid, :name_title, :full_name, :mobile, :how_project, :course, :branch, :university, :city,:district,:pincode,:state,:country, :faculty, :reviewer,:reference, :completion_date, :creation_date, :approval_date, :proposal_status, :r_version, :operating_system, :teacher_email,:reason,:samplefilepath,:proposal_type, :proposed_completion_date, :book_download_link)"; $args = array( @@ -1731,6 +1845,7 @@ function book_proposal_form_submit($form, &$form_state, $directory_name = NULL) ":branch" => trim($form_state['values']['branch']), ":university" => trim($form_state['values']['university']), ":city" => trim($form_state['values']['city']), + ":district" => $form_state['values']['district'], ":pincode" => $form_state['values']['pincode'], ":state" => trim($form_state['values']['all_state']), ":country" => $form_state['values']['country'], @@ -1844,6 +1959,76 @@ function book_proposal_form_submit($form, &$form_state, $directory_name = NULL) drupal_set_message(t('We have received you book proposal. We will get back to you soon.'), 'status'); drupal_goto(''); } + + +function ajax_get_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'] = _tbc_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_district_list_callback($form, $form_state) +{ + $state_default_value = $form_state['values']['all_state']; + if ($state_default_value != '0') + { + $form['district']['#options'] = _tbc_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_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'] = _tbc_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 + ); +} + + + + + + + /** * Implementation of hook_mail(). */ |