1

I have custom reporting which has few dropdowns. A report is generated in the form of a table with selected dropdown values.

I have tried adding pager to the table.

When I click on next page, all the form values loose their form state and page is reloaded back and table gets disappeared.

Im using 'drupal_get_form' in pagecallback in the menu items list.

Here is the code to generate report.

/**
 * Method to implement menu for this page
 *
 * @return multitype:multitype:string multitype:string
 */

function dm_reports_menu() {
    return array (
            'dm_reports' => array (
                    'title' => 'Reports',
                    'page callback' => 'drupal_get_form',
                    'page arguments' => array (
                            'dm_reports_form' 
                    ),
                    'access callback' => 'user_access',
                    'access arguments' => array (
                            'administer dm_reports' 
                    ) 
            ) 
    );
}


/**
 * Method to submit the form and generate report
 *
 * @param unknown $form         
 * @param unknown $form_state           
 */
function dm_reports_form_submit($form, &$form_state) {
    $circle_name = $form_state ['values'] ['circle_name'];
    $report_type = $form_state ['values'] ['choose_report'];
    $system_type = $form_state ['values'] ['system_type'];
    $office_name = $form_state ['values'] ['office_name'];
    $migration_type = $form_state ['values'] ['migration_type'];
    $from_date = get_date_SQL ( $form_state ['input'] ['from_date'] );
    $to_date = get_date_SQL ( $form_state ['input'] ['to_date'] );
    $plan_type = $form_state ['values'] ['plan_type'];
    $phase_type = $form_state ['values'] ['phase'];
    $vendor_name=$form_state ['values'] ['vendor_name'];

    if ($form_state ['values'] ['op'] == 'Generate Report') {

        // Report header
        $header = get_header_data ( $report_type, $system_type );
        $rows = array ();
        // Get rows data
        try {

            $rows = get_row_data ( $report_type, $circle_name, $office_name, $system_type, $migration_type, $from_date, $to_date, $plan_type, $form_state,$phase_type,$vendor_name );
        } catch ( Exception $e ) {
            form_set_error ( '', t ( 'Error occurred. Please try again, or report a problem to administrator.'.$e ) );
            watchdog ( 'atm_status', $e->getMessage (), NULL, WATCHDOG_ERROR );
        }
        $report_name = '';
        if (sizeof ( $rows ) > 0) {
            $report_name = $report_type .'_' . date ( 'd_M_Y_H_i_s', time () ) . '.xls';
    //      generate_xls ( $header, $rows, $report_name);
        }
        $form_state ['report_name'] = $report_name;



        // build the results table
        $form_state['results_table'] = array (
                '#title' => $report_type,
                '#theme' => 'table',
                '#header' => $header,
                '#rows' => $rows,
                '#sticky' => TRUE,
                '#empty' => t ( 'NO DATA FOUND.' ) 
        // '#prefix' => '<hr><strong>' . $report_type . '</strong><div style="width: 720px; height: 300px; overflow: auto;">',
        // '#suffix' => '</div>'
        );


        $form_state ['rebuild'] = TRUE;
    }

}

function get_dm_issues_data($circle_name,$office_name)
{
$rows = array ();

    $query = db_select('dm_issues', 'di')
    ->extend('PagerDefault')
    ->limit(3)
    ->fields('di');

    $results = $query->execute();

    foreach ( $results as $node ) {
        $rows [] = array (

                $node->de_date,
                $node->po_name,
                //$node->weg_code,
                $node->kvp_duplicates,
                $node->nsc_duplicates,
                $node->duplicate_int_ent,
                $node->no_int,
                $node->nominee_grt_one,
                $node->account_his_na,
                $node->comments

        );
    }
    return $rows;
}

Any help would ne appreciated.

  • 1
    where is your "dm_reports_form" function ? – shrish May 26 '14 at 5:10
0
function dm_reports_form($form, &$form_state) {
    $REPORT_TYPE = array (
            ATM_STATUS_SUMMARY_REPORT => ATM_STATUS_SUMMARY_REPORT,
            ATM_STATUS_DETAILED_REPORT => ATM_STATUS_DETAILED_REPORT,
            BRANCH_HARDWARE_SUMMARY_REPORT => BRANCH_HARDWARE_SUMMARY_REPORT,
            BRANCH_HARDWARE_DETAILED_REPORT => BRANCH_HARDWARE_DETAILED_REPORT,
            CPC_STATUS_REPORT => CPC_STATUS_REPORT,
            DATA_CLEANSING_SUMMARY_REPORT => DATA_CLEANSING_SUMMARY_REPORT,
            DATA_CLEANSING_DETAILED_REPORT => DATA_CLEANSING_DETAILED_REPORT,
            DAILY_STATUS_REPORT => DAILY_STATUS_REPORT,
            DATA_CAPTURE_STATUS_SUMMARY_REPORT => DATA_CAPTURE_STATUS_SUMMARY_REPORT,
            DATA_CAPTURE_STATUS_DETAILED_REPORT => DATA_CAPTURE_STATUS_DETAILED_REPORT,
            DATA_CAPTURE_DETAILED_SUMMARY_REPORT => DATA_CAPTURE_DETAILED_SUMMARY_REPORT,
            DATA_CAPTURE_STATUS_FOR_PAYMENT_REPORT => DATA_CAPTURE_STATUS_FOR_PAYMENT_REPORT,
            POVsVendor_STATUS_SUMMARY_REPORT=>POVsVendor_STATUS_SUMMARY_REPORT,
            PRODUCT_WISE_DATA_CAPTURE_DETAILED_REPORT => PRODUCT_WISE_DATA_CAPTURE_DETAILED_REPORT,
            DATA_MIGRATION_SUMMARY_REPORT => DATA_MIGRATION_SUMMARY_REPORT,
            DATA_MIGRATION_DETAILED_REPORT => DATA_MIGRATION_DETAILED_REPORT,
            PROBLEMS_REPORTED => PROBLEMS_REPORTED,
            ROLLOUT_DASHBOARD => ROLLOUT_DASHBOARD,
            ROLLOUT_PLANNING_REPORT => ROLLOUT_PLANNING_REPORT,
            TRAINING_STATUS_REPORT => TRAINING_STATUS_REPORT,
            DM_SUMMARY_REPORT => DM_SUMMARY_REPORT,
            DM_ISSUES_REPORT => DM_ISSUES_REPORT,
            DE_STATUS_DASHBOARD => DE_STATUS_DASHBOARD
              // GoLiveVsPO_NOT_STARTED => GoLiveVsPO_NOT_STARTED,
             // GoLiveVsPO_COMPLETED => GoLiveVsPO_COMPLETED 
    );

$system_types = array (
        CBS => CBS,
        PLI => PLI 
);

$migration_types = array (
        MOCK_MIGRATION => MOCK_MIGRATION,
        FINAL_MIGRATION => FINAL_MIGRATION 
);

$plan_types = array (
        END_USER_TRAINING_PLAN => END_USER_TRAINING_PLAN,
        USER_CHAMP_TRAINING_PLAN => USER_CHAMP_TRAINING_PLAN,
        DATA_CAPTURE_PLAN => DATA_CAPTURE_PLAN,
        MOCK_MIGRATION_PLAN => MOCK_MIGRATION_PLAN 
);

$phase = array (
        ALL=> ALL,
        PHASE_PILOT => PHASE_PILOT,
        "1000 PO" => "1000 PO",
        PHASE_1A => PHASE_1A,
        PHASE_1B => PHASE_1B,
        PHASE_2A => PHASE_2A,
        PHASE_2B => PHASE_2B 
);

$form = array ();
$form ['#attributes'] = array (
        'enctype' => 'multipart/form-data' 
);

$form ['choose_report'] = array (
        '#type' => 'select',
        '#title' => t ( 'Choose Report' ),
        '#options' => $REPORT_TYPE 
);



$form ['phase'] = array (
        '#type' => 'select',
        '#title' => t ( 'Phase' ),
        '#options' => $phase,
        '#states' => array (
                'invisible' => array ( // Making circle name list invisible if report selected is PROBLEMS_REPORTED
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => PROBLEMS_REPORTED 
                                ),
                                //array (
                                //      'value' => DM_SUMMARY_REPORT 
                                //),
                                //array (
                                //      'value' => DM_ISSUES_REPORT 
                                //),
                                array (
                                        'value' => DE_STATUS_DASHBOARD 
                                ),
                            )
                        )
                    )
);  


$circle_names [ALL] = ALL;
$circle_names = array_merge ( $circle_names, getCircleNames () );

$form ['circle_name'] = array (
        '#type' => 'select',
        '#title' => t ( 'Circle Name' ),
        '#options' => $circle_names,
        '#ajax' => array (
                'callback' => 'reports_populateOfficeName',
                'wrapper' => 'textbox-div',
                'method' => 'replace',
                'effect' => 'fade' 
        ),
        '#states' => array (
                'invisible' => array ( // Making circle name list invisible if report selected is PROBLEMS_REPORTED
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => PROBLEMS_REPORTED 
                                ),
                                array (
                                        'value' => ROLLOUT_PLANNING_REPORT 
                                ),
                                array (
                                        'value' => DE_STATUS_DASHBOARD 
                                )                                   
                        ) 
                ) 
        ) 
);

// Populating PO names dynamically
$circle_name = reset ( $circle_names );

if (! empty ( $form_state ['values'] ['circle_name'] )) {
    $circle_name = $form_state ['values'] ['circle_name'];
}

$office_names [ALL] = ALL;

$office_names = array_merge ( $office_names, getPONamesReports ( $circle_name ) );

$form ['office_name'] = array (
        '#type' => 'select',
        '#title' => t ( 'Office Name' ),
        '#options' => $office_names,
        '#prefix' => '<div id="textbox-div">',
        '#suffix' => '</div>',
        '#states' => array (
                'invisible' => array ( // Making circle name list invisible if report selected is PROBLEMS_REPORTED
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => PROBLEMS_REPORTED 
                                ),
                                array (
                                        'value' => ROLLOUT_PLANNING_REPORT 
                                ),
                                array (
                                        'value' => DE_STATUS_DASHBOARD 
                                ) 
                        ) 
                ) 
        ) 
);

$form ['system_type'] = array (
        '#type' => 'select',
        '#title' => t ( 'System Type' ),
        '#options' => $system_types,
        '#states' => array (
                'visible' => array ( // Making circle name list visible if report selected is TRAINING_STATUS_REPORT
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => TRAINING_STATUS_REPORT 
                                ),
                        /*      array (
                                        'value' => CPC_STATUS_REPORT 
                                ),
                                array (
                                        'value' => BRANCH_HARDWARE_DETAILED_REPORT 
                                ),
                                array (
                                        'value' => BRANCH_HARDWARE_SUMMARY_REPORT 
                                ) 
                        */
                        ) 
                ) 
        ) 
);



$form ['migration_type'] = array (
        '#type' => 'select',
        '#title' => t ( 'Migration Type' ),
        '#options' => $migration_types,
        '#states' => array (
                'visible' => array ( // Making circle name list invisible if report selected is PROBLEMS_REPORTED
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => DATA_MIGRATION_SUMMARY_REPORT 
                                ),
                                array (
                                        'value' => DATA_MIGRATION_DETAILED_REPORT 
                                ) 
                        ) 
                ) 
        ) 
);

$form ['plan_type'] = array (
        '#type' => 'select',
        '#title' => t ( 'Plan Type' ),
        '#options' => $plan_types,
        '#states' => array (
                'visible' => array ( // Making circle name list invisible if report selected is PROBLEMS_REPORTED
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => ROLLOUT_PLANNING_REPORT 
                                ) 
                        ) 
                ) 
        ) 
);

$stored_date = get_stored_date_value ( $form_state, 'from_date' );

$form ['from_date'] = array (
        '#type' => 'date',
        '#title' => t ( 'From Date' ),
        '#value' => $stored_date,
        '#process' => array (
                'form_process_date',
                'fix_year_range_current' 
        ),
        '#states' => array (
                'visible' => array (
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => ROLLOUT_PLANNING_REPORT 
                                ) ,
                                array (
                                        'value' => DE_STATUS_DASHBOARD 
                                ) 
                        ) 
                ) 
        ) 
);

$stored_date = get_stored_date_value ( $form_state, 'to_date' );

$form ['to_date'] = array (
        '#type' => 'date',
        '#title' => t ( 'To Date' ),
        '#value' => $stored_date,
        '#process' => array (
                'form_process_date',
                'fix_year_range_current' 
        ),
        '#states' => array (
                'visible' => array (
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => ROLLOUT_PLANNING_REPORT 
                                ) ,
                                array (
                                        'value' => DE_STATUS_DASHBOARD 
                                ) 
                        ) 
                ) 
        ) 
);


$Vendor_Name [ALL] = ALL;
$Vendor_Name = array_merge ( $Vendor_Name, getVendorNames_O());

$form ['Vendor_Name'] = array (
        '#type' => 'select',
        '#title' => t ( 'Vendor Name' ),
        '#options' => $Vendor_Name,
        '#prefix' => '<div id="textbox-div">',
        '#suffix' => '</div>',
        '#states' => array (
                'visible' => array ( // Making circle name list visible if report selected is POVsVendor_STATUS_SUMMARY_REPORT
                        ':input[name=choose_report]' => array (
                                array (
                                        'value' => POVsVendor_STATUS_SUMMARY_REPORT 
                                )
                        ) 
                ) 
        ) 
);



$form ['submit'] = array (
        '#type' => 'submit',
        '#value' => t ( 'Generate Report' ),
        '#suffix' => '&emsp;&emsp;&emsp;' 
);

if (! empty ( $form_state ['results_table'] )) {
    if (! empty ( $form_state ['report_name'] )) {
        // code to generate link for downloading report
        $base_url = $GLOBALS ['base_url'];
        //$currentDate = date ( 'd-M-Y', time () );
        $currentDate = date ( "d-M-Y H:i:s");
        $form ['download'] = array (
                '#markup' => '<strong><a href="' . $base_url . REPORTS_URL . $form_state ['report_name'] . '">Download Report</a></strong> : As on '.$currentDate 
        );
    }

//   Code to display report in table format
$form ['table'] = $form_state ['results_table'];
}



return $form;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.