Plugin Directory

Changeset 1644004


Ignore:
Timestamp:
04/24/2017 02:26:10 PM (9 years ago)
Author:
nexuslink
Message:

Update Code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cf7records/trunk/save-contact-details.php

    r1643961 r1644004  
    2626
    2727    function savedata_px_register_admin_menu() {
    28         add_menu_page('Contact Messages',
    29             'CF7 Records',
    30             'manage_options',
    31             basename(__FILE__), array($this,
    32             'px_options_page'));
     28        add_menu_page( 'Submitted Forms', 'Contact Messages', 'manage_options', basename(__FILE__), array($this, 'px_options_page'));
    3329    }
    3430
     
    112108        <div class="wrap">
    113109
    114             <h1>CF7 Records</h1>
     110            <h1>Save & Export</h1>
    115111            <h3>Select contact form</h3>
    116112
     
    147143                        <!--<button type="submit" class="button button-default button-large export_to_csv" style="float: right;margin-bottom: 10px;">Export to CSV</button>-->
    148144                    </form>
     145
     146                    <?php
     147                    if (isset($_GET['export_csv'])) {
     148                        // Set header row values
     149                        $csv_fields=array();
     150                        $csv_fields[] = 'Field Name 1';
     151                        $csv_fields[] = 'Field Name 2';
     152                        $output_filename = 'MyReport_Contact_Messages.csv';
     153                        $output_handle = @fopen( 'php://output', 'w' );
     154
     155                        header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
     156                        header( 'Content-Description: File Transfer' );
     157                        header( 'Content-type: text/csv' );
     158                        header( 'Content-Disposition: attachment; filename=' . $output_filename );
     159                        header( 'Expires: 0' );
     160                        header( 'Pragma: public' );
     161
     162                        // Insert header row
     163                        fputcsv( $output_handle, $csv_fields );
     164                        foreach ($result as $one_result) {
     165                            $query = 'SELECT `key`, value FROM ' . $wpdb->prefix . 'savedata WHERE form_submit_id="' . $one_result->form_submit_id . '"';
     166                            $data = $wpdb->get_results($query);
     167                            foreach ($data as $item) {
     168                                $leadArray = (array)$item;
     169                                fputcsv($output_handle, $leadArray);
     170                            }
     171                        }
     172                        fclose( $output_handle );
     173                        die();
     174
     175                        // Close output file stream
     176                    }
     177                    ?>
     178
    149179                    <table id="grid-basic" class="table table-hover table-striped">
     180                        <thead>
     181                        <tr>
     182                            <th>Date</th>
    150183
    151184                            <?php
    152185                            $counter=0;
    153186                            foreach ($result as $key => $value):
    154                             $counter++;
    155                             if($counter==1){
    156                             ?>
    157                                 <thead>
    158 
    159                                 <tr>
    160                                     <th>Date</th>
    161                                     <?php $query = 'SELECT `key`, value, id FROM ' . $wpdb->prefix . 'savedata WHERE form_submit_id="' . $value->form_submit_id . '" ORDER BY date DESC'; ?>
    162                                     <?php
     187                                $counter++;
     188                                if($counter==1) {
     189                                    $query = 'SELECT `key`, value, id FROM ' . $wpdb->prefix . 'savedata WHERE form_submit_id="' . $value->form_submit_id . '"';
    163190                                    $data = $wpdb->get_results($query);
    164191                                    $cntH=0;
    165192                                    foreach ($data as $item):
    166                                         echo '<th>'.str_replace("-"," ",ucfirst($item->key)).'</th>';
     193                                        $queryD = 'SELECT value FROM ' . $wpdb->prefix . 'savedata WHERE id="' . $item->id . '"';
     194                                        $dataD = $wpdb->get_results($queryD);
     195                                        echo '<th>' . str_replace("-"," ",ucfirst($item->key)) . '</th>';
    167196                                        $cntH++;
    168                                         if($cntH>3){
     197                                        if($cntH>2){
    169198                                            break;
    170199                                        }
    171                                     endforeach; ?>
    172 
    173 
    174                                     <th>View Details</th>
    175                                 </tr>
    176                                 </thead>
    177                                 <?php } ?>
    178                                 <tbody>
    179                                 <tr>
    180                                     <td><?php echo $value->date ?></td>
    181 
    182                                         <?php $query = 'SELECT `key`, value, id FROM ' . $wpdb->prefix . 'savedata WHERE form_submit_id="' . $value->form_submit_id . '" ORDER BY date DESC'; ?>
    183                                         <?php
    184                                         $data = $wpdb->get_results($query);
    185                                         $cntD=0;
    186                                         foreach ($data as $item):
    187                                             echo '<td>'.$item->value.'</td>';
    188                                             $cntD++;
    189                                             if($cntD>3){
    190                                                 break;
    191                                             }
    192                                         endforeach; ?>
    193                                     </td>
    194                                     <td>
    195                                         <form method="get" action="">
    196                                             <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>">
    197 
    198                                             <input type="hidden" name="sv_data" value="<?php echo $form_id ?>">
    199                                             <input type="hidden" name="form_submit_id" value="<?php echo $value->form_submit_id ?>">
    200                                             <button type="submit" class="button button-primary">View</button>
    201                                         </form>
    202 
    203                                     </td>
    204                                 </tr>
    205                             <?php endforeach; ?>
     200                                    endforeach;
     201                                }
     202                            endforeach;
     203                            ?>
     204                            <th>View Details</th>
     205                        </tr>
     206                        </thead>
     207                        <tbody>
     208                        <?php foreach ($result as $key => $value): ?>
     209                            <tr>
     210                                <td><?php echo $value->date ?></td>
     211
     212                                <?php $query = 'SELECT `key`, value, id FROM ' . $wpdb->prefix . 'savedata WHERE form_submit_id="' . $value->form_submit_id . '"'; ?>
     213                                <?php
     214                                $data = $wpdb->get_results($query);
     215                                $cntH=0;
     216                                foreach ($data as $item):
     217                                    $queryD = 'SELECT value FROM ' . $wpdb->prefix . 'savedata WHERE id="' . $item->id . '"';
     218                                    $dataD = $wpdb->get_results($queryD);
     219                                    echo '<td>'.$item->value.'</td>';
     220                                    $cntH++;
     221                                    if($cntH>2){
     222                                        break;
     223                                    }
     224
     225                                endforeach; ?>
     226                                </td>
     227                                <td>
     228                                    <form method="get" action="">
     229                                        <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>">
     230
     231                                        <input type="hidden" name="sv_data" value="<?php echo $form_id ?>">
     232                                        <input type="hidden" name="form_submit_id" value="<?php echo $value->form_submit_id ?>">
     233                                        <button type="submit" class="button button-primary">View</button>
     234                                    </form>
     235
     236                                </td>
     237                            </tr>
     238                        <?php endforeach; ?>
    206239                        </tbody>
    207240                    </table>
     
    220253                <br>
    221254                <div class="cf7_item_wrapper">
    222                     <h2>User Inputs</h2>
     255                    <h2>User Details</h2>
    223256                    <?php
    224257                    foreach ($result as $item) {
    225258                        ?>
    226259                        <div class="row">
    227                             <label><?php echo str_replace("-"," ",ucfirst($item->key)) ?></label>
     260                            <label><?php echo str_replace("-"," ",ucfirst($item->key)); ?></label>
    228261                            <label style="width: 75%; float: right"><?php echo $item->value ?></label>
    229262                            <div style="clear: both"></div>
     
    258291                    endforeach;
    259292                    ?>
    260                     </div>
    261                     <?php
    262             }
     293                </div>
     294
     295            <?php }
    263296            ?>
    264297            <!--     close div wrap-->
Note: See TracChangeset for help on using the changeset viewer.