Welcome Guest, Not a member yet? Register   Sign In
Loading View with Posting Data
#4

(02-25-2016, 12:22 PM)RobertSF Wrote: Yes, I'm not really picturing it. If you load a view and pass it an array ($data), and that view itself loads a view, you don't need to pass the array to that second view. Like Wouter60 suggest, post some code, and make sure to put it in a PHP code block.

National method in controller
PHP Code:
       public function national(){
 
               $this->head->add('js'GLOBAL_LIB '/chartjs/ChartNew.js');
 
               log_message("debug""At start of National Report");
 
               $this->load->helper("form");
 
               if$this->input->post() ):
 
                       log_message("debug""data Product ID is: " $data['product_id']);
 
                       if($data['product_id'] == NULL) {
 
                               $data['product_id'] = $this->input->post('product_id');
 
                       }
 
                       $data['start_date'] = $this->input->post('start_date');
 
                       $data['end_date'] = $this->input->post('end_date');
 
                       $this->load->model('campaigns_model');
 
                       $this->campaigns_model->product_id $data['product_id'];
 
                       $campaigns $this->campaigns_model->load(false,false,true);

 
                       if( empty( $campaigns ) ):
 
                               $data['report_description'] = 'Select your program to display the overview of national statistics for the selected program.';
 
                               $this->session->set_userdata(array('status_message' => 'No campaigns selected.''status_type' => 'bad'));
 
                               //$this->load->private_view('reports/select_product');
 
                               redirect('private/reports/national'); 
 
                       else:

 
                               $this->load->model('reports_model');
 
                               $report_data $this->reports_model->get_campaign_report($campaigns$data['start_date'], $data['end_date']);           

                                list
$data['campaign'], $data['product'], $data['questions'], $data['screenings'], $data['risk_levels'], $data['screening_days'], $data['no_misuse'], $data['in_recovery']$

 
                               $data['report_description'] = 'Below is the overview of national statistics for the selected program.';
 
                               $data['report_type'] = 'national';
 
                               $data['report_title'] = $data['product']->title;
 
                               $data['item_type'] = strtolower(str_replace(' ','_',$data['product']->title));
 
                               $data['item_id'] = strtolower(str_replace(' ','_',$data['product']->title));

 
                               // dyanmic js for charts
 
                               $data['js'] = $this->load->view('private/reports/edit.js.php'$datatrue);

 
                               $report_csv_data $this->reports_model->get_campaign_csv$data['screenings'], $data['product']->product_id ); $csv_path REPORT_FILE_PATH '/national_' $data['item_type' '/' $data['item_type' '_' $data['item_id' '.csv';
 
                               $this->load->library('csv_library');
 
                               $this->csv_library->create_csv($csv_path$report_csv_data$data['product']->product_id);
 
                               $this->load->private_view('reports/edit'$data);
 
                               log_message("debug","At end of National");
 
                       endif;
 
               else:
 
                       $data['products'][1] = 'ScreenU Alcohol Campaigns';
 
                       $data['products'][2] = 'ScreenU Rx Campaigns';
 
                       
                        $this
->load->private_view('reports/select_product'$data);
 
               endif;
 
       
edit.php in controller
PHP Code:
public function edit($campaign_id '') {
 
               $this->head->add('css',GLOBAL_LIB '/hopscotch/hopscotch.min.css');
 
               $this->head->add('js',GLOBAL_LIB '/hopscotch/hopscotch.min.js');

 
               $this->head->add('js'GLOBAL_LIB '/chartjs/ChartNew.js');
 
       
                log_message
("debug""In Edit");
 
               $this->load->helper('form');
 
               if ($this->input->post()) {
 
                       log_message("debug""In Edit");
 
                       $data['start_date'] = $this->input->post('start_date');
 
                       $data['end_date'] = $this->input->post('end_date');
 
                       $data['product_id'] = "2"
 
               }

 
               $data['reports_edit_first_visit'] = ( $this->user_model->get_user_meta($this->auth_lib->user_id(),'reports_edit_first_visit') == '' true false );
 
               // its our first time here!
 
               if$data['reports_edit_first_visit'] ){
 
                       $this->user_model->update_user_meta($this->auth_lib->user_id(),'reports_edit_first_visit',date('Y-m-d H:i:s'));
 
               }
 
               
                $this
->load->model('reports_model');
 
               
                if 
($data['campaigns'] == NULL) {
 
                       $data['report_title'] = $data['campaign']->title;
 
                       $report_data $this->reports_model->get_campaign_report($campaign_id$data['start_date'], $data['end_date']);         
                
}else {
 
                       $data['report_title'] = $data['product']->title;
 
                       $report_data $this->reports_model->get_campaign_report($data['campaigns'], $data['start_date'], $data['end_date']);
 
               }
 
               list$data['campaign'], $data['product'], $data['questions'], $data['screenings'], $data['risk_levels'], $data['screening_days'], $data['no_misuse'], $data['in_recovery'] ) = $report_dat$

 
               $data['report_description'] = 'The following is an overview of all the responses for a specific campaign.';
 
               $data['report_type'] = 'campaign';
 
               $data['item_type'] = 'campaign';
 
               $data['item_id'] = $data['campaign']->campaign_id// dyanmic js for charts
 
               $data['js'] = $this->load->view('private/reports/edit.js.php'$datatrue);
 
               
/*
                // generate pdf
                $this->load->library('tcpdf_library');
                $html_content = $this->load->private_pdf_view('reports/campaign_pdf', $data);

                $this->tcpdf_library->create_pdf(REPORT_FILE_PATH . '/campaign_' . $data['campaign']->campaign_id .'/campaign_' . $data['campaign']->campaign_id .'.pdf', $html_content, 'ScreenU Campaign $
*/
 
               
                
// generate csv
 
               $report_csv_data $this->reports_model->get_campaign_csv($data['screenings'], $data['product']->product_id );
 
               $this->load->library('csv_library');
 
               $this->csv_library->create_csv(REPORT_FILE_PATH '/campaign_' $campaign_id '/campaign_' $campaign_id '.csv'$report_csv_data$data['product']->product_id );
 
               
                $this
->load->private_view('reports/edit'$data);
 
       
Select_Product.php (uses National method)
PHP Code:
<script type="text/javascript">
<?
php echo $js?>
</script>
<div class="content-header">
        <h1>Reporting</h1>
</div>  
<div class="content">
        <input type="hidden" name="reports_campus_first_visit" id="reports_campus_first_visit" value="<?php echo ( $reports_campus_first_visit '1' '0' ); ?>" />    
        <p>The following Campus Report is an overview of all the responses for a specific campaign.</p>

        <hr />

        <div id="welcome" class="hopscotch-item">
                <h3>Select a Program and a Date Range</h3>

                <div class="box">
                        <div class="wrapper">
                                <form action="" method="post" id="product_form">
                                        <div class="row">
                                                <div class="col span_4">
                                                        <select name="product_id">
                                                                <option value="">- Select a Program -</option>
                                                                <?php foreach( $products as $kproduct => $product ): ?>
                                                                <option value="<?php echo $kproduct?>"><?php echo $product?></option>
                                                                <?php endforeach; ?>
                                                        </select>
                                                </div>
                                                <div class="col span_3">
                                                        <input type="text" class="datepicker" name="start_date" placeholder="Start Date" />
                                                </div>
                                                <div class="col span_1">&nbsp;</div>
                                                <div class="col span_3">
                                                        <input type="text" class="datepicker" name="end_date" placeholder="End Date" />
                                                </div>
                                        </div>
                                        <div class="row">
                                                <div class="col span_12">
                                                        <input type="submit" class="outline-button" value="See Report" />
                                                </div>
                                        </div>
                                </form>
                        </div>
                </div>
        </div>
</div> 
Edit.php View
PHP Code:
<script type="text/javascript">
<?
php echo $js?>
</script>
<div class="content-header">
        <h1>Reporting</h1>
</div>  
<div class="content">
        <input type="hidden" name="reports_edit_first_visit" id="reports_edit_first_visit" value="<?php echo ( $reports_edit_first_visit '1' '0' ); ?>" />  
        <p class="no-print"><?php echo $report_description?></p>

        <div class="box">
        <div class="wrapper">
        <form action="" method="post" id="date_picker_form">
                <div class="row">
                        <h5>To view a report for a specific date range, please enter the dates below. To see the report without date parameters, please press “see report.”</h5>
                </div>
                </br>
                <div class="row">
                         <div class="col span_3">
                                <input type="text" value="<?php echo set_value('start_date'); ?>" class="datepicker" name="start_date" placeholder="Start Date" />
                        </div>
                        <div class="col span_1">&nbsp;</div>
                        <div class="col span_3">
                                <input type="text" value="<?php echo set_value('end_date'); ?>" class="datepicker" name="end_date" placeholder="End Date" />
                        </div>
                </div>
                <div class="row">
                        <div class="col span_12">
                                 <input type="submit" class="outline-button" value="See Report" />
                        </div>
                </div>
        </form>
        </div>
        </div>


        <?php
        
/* DEBUG
        echo 'report type: ' . $report_type . '<br />';
        echo 'item type: ' . $item_type . '<br />';
        echo 'item id: ' . $item_id . '<br />'; 
         */
 
       ?>
        
        <hr />

        <h3>Data for <?php echo $report_title?> <span><?php echo count($screenings); ?> Responses</span></h3>
        <?php if( isset( $date_range ) ): ?>
        <p><?php echo $date_range?></p>
        <?php endif; ?>

        <div id="welcome" class="hopscotch-item">
                <div class="box plain">
                        <div class="head">
                                <h3><a href="#" class="expandable" rel="in_recovery">Data For Those In Recovery</a></h3>
                        </div>
                        <div class="expandable" id="in_recovery">
                                <div class="row">
                       <div class="expandable" id="in_recovery">
                                <div class="row">
                                        <div class="col span_12">
                                                <div class="minidonuts">
                                                        <div class="minidonut_wrapper">
                                                                <canvas id="in_recovery_chart" class="horiz_chart" height="150" width="150"></canvas>
                                                                
                                                                <span class="download_image" rel="in_recovery_chart" title="Download this graphic"><i class="fa fa-download"></i></span>
                                                        </div>
                                                </div>
                                        </div>
                                </div>
                                <br class="clear" />
                                <div class="question_details">
                                        <div class="head">
                                                <h4><a href="#" class="expandable" rel="in_recovery_gender_details">Gender</a></h4>
                                        </div>
                                        <div class="expandable" id="in_recovery_gender_details">
                                                <canvas id="in_recovery_genders_chart" class="horiz_chart" height="150" width="150"></canvas>
                                                <div style="display: none;"><canvas id="in_recovery_genders_chart_data_only" class="horiz_chart" height="150" width="150"></canvas></div>
                                                <span class="download_image" rel="in_recovery_genders_chart" title="Download this graphic"><i class="fa fa-download"></i></span>
                                        </div>
                                </div>
                                <div class="question_details">
                                        <div class="head">
                                                <h4><a href="#" class="expandable" rel="in_recovery_class_rank_details">Class Rank</a></h4>
                                        </div>
                                        <div class="expandable" id="in_recovery_class_rank_details">
                                                <canvas id="in_recovery_class_ranks_chart" class="horiz_chart" height="100" width="100"></canvas>
                                                <div style="display: none;"><canvas id="in_recovery_class_ranks_chart_data_only" class="horiz_chart" height="150" width="150"></canvas></div>
                                                <span class="download_image" rel="in_recovery_class_ranks_chart" title="Download this graphic"><i class="fa fa-download"></i></span>
                                        </div>
                                </div>
                                <div class="question_details">
                                        <div class="head">
                                                <h4><a href="#" class="expandable" rel="in_recovery_age_details">Age</a></h4>
                                        </div>
                                        <div class="expandable" id="in_recovery_age_details">
                                                <div style="display: none;"><canvas id="in_recovery_ages_chart" class="horiz_chart" height="100" width="100"></canvas></div>
                                                <canvas id="in_recovery_ages_chart_data_only" class="horiz_chart" height="100" width="100"></canvas>
                                                <span class="download_image" rel="in_recovery_ages_chart_data_only" title="Download this graphic"><i class="fa fa-download"></i></span>
                                        </div>
                                </div>
                        </div>
                </div>
                <div class="box plain">
                        <div class="head">
                                <h3><a href="#" class="expandable" rel="no_misuse">Data for those reporting no <?php
if ($product->product_id == '1') {
 
   echo "";
} elseif (
$product->product_id == '2') {
 
   echo "mis";
} else {
 
   echo "";
}
?>use in past 12 months</a></h3>
                        </div>
                        <div class="expandable" id="no_misuse">
... so on so forth 
Reply


Messages In This Thread
Loading View with Posting Data - by acheng16 - 02-24-2016, 03:52 PM
RE: Loading View with Posting Data - by Wouter60 - 02-25-2016, 12:13 PM
RE: Loading View with Posting Data - by RobertSF - 02-25-2016, 12:22 PM
RE: Loading View with Posting Data - by acheng16 - 03-02-2016, 08:46 PM
RE: Loading View with Posting Data - by Wouter60 - 03-03-2016, 08:39 AM
RE: Loading View with Posting Data - by acheng16 - 03-03-2016, 01:56 PM
RE: Loading View with Posting Data - by RobertSF - 03-03-2016, 06:59 PM
RE: Loading View with Posting Data - by acheng16 - 03-05-2016, 08:21 AM
RE: Loading View with Posting Data - by Wouter60 - 03-05-2016, 09:04 AM
RE: Loading View with Posting Data - by acheng16 - 03-05-2016, 01:32 PM
RE: Loading View with Posting Data - by Wouter60 - 03-06-2016, 04:49 AM
RE: Loading View with Posting Data - by acheng16 - 03-06-2016, 02:05 PM
RE: Loading View with Posting Data - by Wouter60 - 03-07-2016, 08:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB