Plugin Directory

Changeset 3312748


Ignore:
Timestamp:
06/16/2025 08:25:54 PM (10 months ago)
Author:
wibergsweb
Message:

Focus on attributes for grouping totals and bugfix while using headerrow_exists is set to no.

Location:
csv-to-html
Files:
891 added
2 edited

Legend:

Unmodified
Added
Removed
  • csv-to-html/trunk/csvtohtml.php

    r3308108 r3312748  
    44Plugin URI: http://www.wibergsweb.se/plugins/csvtohtml
    55Description:Display/edit/synchronize csv-file(s) dynamically into a html-table
    6 Version: 3.57
     6Version: 3.63
    77Author: Wibergs Web
    88Author URI: http://www.wibergsweb.se/
     
    31633163            'htmltags_autoconvert_imagealt' => '',              //Set alt text based on a specific columns value (Or same text for all images if you just set some text here instead of a number)
    31643164            'htmltags_autoconvert_imagewidth' => null,          //Width of converted images, can be set in px (default), %, vw, em, rem etc
    3165             'totals_cols_bottom_countlines' => 'no',            //Total number of lines
    3166             'totals_cols_bottom' => null,                       //Add totals with given columns at bottom of table (example 1,2,4 or 1-2,4)
    3167             'totals_cols_bottom_empty' => '',                   //What string/character (maybe a zero?) to show when there's no calculation
    31683165            'totals_cols_prefix' => '',                         //Add prefix to the total column(s) (e.g. $10)
    31693166            'totals_cols_suffix' => '',                         //Add suffix to the total column(s) (e.g. 10$)
     3167            'totals_forgrouping' => 'no',                       //When totals_forgrouping is set to yes, totals are shown for each grouping (instead of whole table)
     3168            'totals_cols_bottom_countlines' => 'no',            //Total number of lines
     3169            'totals_cols_bottom' => null,                       //Add totals with given columns at bottom of table (or grouping) (example 1,2,4 or 1-2,4)
     3170            'totals_cols_bottom_empty' => '',                   //What string/character (maybe a zero?) to show when there's no calculation
    31703171            'totals_cols_bottom_title' => null,                 //Set a specific string when added totals (overrides totals_cols_bottom_empty)
    3171             'totals_cols_bottom_title_col' => null,             //Which column to set this specific string           
     3172            'totals_cols_bottom_title_col' => null,             //Which column to set this specific string                                               
     3173            'totals_cols_top_countlines' => 'no',               //Total number of lines
     3174            'totals_cols_top' => null,                          //Add totals with given columns at top of table (or grouping)           
     3175            'totals_cols_top_empty' => '',                      //What string/character (maybe a zero?) to show when there's no calculation           
     3176            'totals_cols_top_title' => null,                    //Set a specific string when added totals (overrides totals_cols_top_empty)
     3177            'totals_cols_top_title_col' => null,                //Which column to set this specific string                       
    31723178            'total_percentage_above_table' => 'yes',            //Show total percentage of a specific value above table
    31733179            'total_percentage_below_table' => 'no',             //Show total percentage of a specific value below table
     
    42124218        if ( $groupby_col !== null )
    42134219        {
    4214             $groups_arr = [];       
     4220            $groups_arr = [];     
     4221
     4222            if ($totals_forgrouping === 'yes')
     4223            {
     4224                if ( $totals_cols_top !== null )
     4225                {
     4226                    $use_cols = $this->adjust_columns( $totals_cols_top );
     4227                }
     4228
     4229                $groups_arr_totals = [];   
     4230            }
     4231
    42154232            $groupby_column = $groupby_col-1; //Index-based 0
    42164233
     
    42254242                }
    42264243
    4227                 $groups_arr[$groupedby_value][] = array_slice($row,0);
    4228             }
    4229    
     4244                $groups_arr[$groupedby_value][] = array_slice($row,0);               
     4245               
     4246                //Set totals for all columns for this group
     4247                if ($totals_forgrouping === 'yes')
     4248                {
     4249                    if (!isset($groups_arr_totals[$groupedby_value]))
     4250                    {
     4251                        $groups_arr_totals[$groupedby_value] = array_fill(0,count($row_values),0);
     4252                    }
     4253
     4254                    //Count totals for columns
     4255                    foreach($use_cols as $key=>$column)
     4256                    {
     4257                        if ( $totals_cols_top_countlines === "yes" )
     4258                        {
     4259                            $add_value = 1; //Count lines instead of values
     4260                        }
     4261                        else
     4262                        {
     4263                            $add_value = (int)($row[$column][1]); //Actual value in column to add
     4264                        }
     4265                        $groups_arr_totals[$groupedby_value][$column] += $add_value;
     4266                    }
     4267                }
     4268            }
     4269
     4270           
    42304271            //...then simply create new array based on temporary array
    42314272            //(so things will get in correct order)
     
    42374278                    $row_groupedby_header = [];
    42384279                    $first_col = true;
    4239                     foreach( $inner_arr[0] as $kv=>$value ) //$inner_arr is basically the first item, so we know number of cols
     4280                    foreach( $inner_arr[0] as $kv=>$value ) //$inner_arr is basically the first item, so we know number of cols. $kv is the index of column
    42404281                    {
    42414282                        if ( $first_col === true )
     
    42464287                        else
    42474288                        {
    4248                             $row_groupedby_header[] = ['', ''];
    4249                         }                       
     4289                            if ($totals_forgrouping === 'yes')
     4290                            {
     4291                                if ( in_array($kv, $use_cols) !== false)
     4292                                {
     4293                                    $row_groupedby_header[] = ['', '<span class="subtotal">' . $totals_cols_prefix . $groups_arr_totals[$key][$kv] . $totals_cols_suffix  . '</span>'];                           
     4294                                }
     4295                                else
     4296                                {
     4297                                    //If title is set somewhere for totals, override totals_col_top_empty setting
     4298                                    //($kv is index of column, so $kv=0 is column1, $kv=1 is column2 etc)
     4299                                    if ( mb_strlen( $totals_cols_top_title ) >0 && (int)$totals_cols_top_title_col == $kv+1 )
     4300                                    {
     4301                                        $row_groupedby_header[] = ['', '<span class="subtotal-title">' . $totals_cols_top_title . '</span>'];   
     4302                                    }
     4303                                    else
     4304                                    {
     4305                                        $row_groupedby_header[] = ['', '<span class="subtotal-novalue">' . $totals_cols_top_empty . '</span>'];                   
     4306                                    }         
     4307                                }
     4308                            }
     4309                            else
     4310                            {
     4311                                $row_groupedby_header[] = ['', ''];                           
     4312                            }
     4313                        }                                                   
    42504314                    }
    42514315                    $row_values[] = array_slice($row_groupedby_header,0);
     
    48554919        //If skip header is set to yes, header will not be included in html
    48564920        $hide_row_class = '';
     4921        $nr_col = 1;
    48574922        if ( $skip_headerrow === "no" )
    48584923        {
     
    48664931
    48674932            //Take for granted HTML5 is used. Then this below is ok
    4868             $nr_col = 1;
     4933           
    48694934            $html .= '<style>';
    48704935            if ( $header_type === "sticky" )
     
    50005065        {
    50015066            $use_cols = $this->adjust_columns( $totals_cols_bottom );
    5002 
     5067           
    50035068            $row_sum = [];
    50045069            $cnt_rowvalues = count ( $row_values );
    5005                        
     5070                 
    50065071            //If totals_cols_bottom_countlines is defined and set to yes,
    50075072            //then count lines else don't
     
    50155080            }
    50165081
    5017             for( $i=0;$i<$nr_col-1;$i++ )
     5082            $nr_col = count($row_values[0]);           
     5083
     5084            for( $i=0;$i<$nr_col;$i++ )
    50185085            {
    50195086                if ( in_array( $i, $use_cols) !== false )
     
    50375104                            $row_sum[$i][] = $numberonly_str;
    50385105                        }
    5039                     }               
     5106                    }
     5107
     5108                    $subtract_fromtotal = 0;
     5109
     5110                    //If using totals for grouping, these subtotals should not
     5111                    //be included in total sum, therefore tell how much to subtract in total below
     5112                    if ($totals_forgrouping === 'yes')
     5113                    {
     5114                        foreach($groups_arr_totals as $gat)
     5115                        {               
     5116                            $subtract_fromtotal += $gat[$i];           
     5117                        }                       
     5118                    }
    50405119                   
    50415120                    //Add row with totals to the bottom of table
    5042                     //If suffix or prefix (or both) is given then print out those as well
     5121                    //If suffix or prefix (or both) is given then print out those as well                   
    50435122                    if ( !empty( $row_sum[$i] ))
    50445123                    {     
    5045                         $row_values[$cnt_rowvalues][$i] = array( '',  $totals_cols_prefix . array_sum($row_sum[$i]) . $totals_cols_suffix );
     5124                        //subtract_fromtotal is used when using subtotals in this column
     5125                        $row_values[$cnt_rowvalues][$i] = array( '',  '<span class="total">' . $totals_cols_prefix . array_sum($row_sum[$i]) - $subtract_fromtotal . $totals_cols_suffix . '</span>');
    50465126                    }
    50475127                }
     
    50495129                {
    50505130                    //Show empty totals (not even zeros)
    5051                     $row_values[$cnt_rowvalues][$i] = array('',   $totals_cols_bottom_empty );
     5131                    $row_values[$cnt_rowvalues][$i] = array('',   '<span class="empty-novalue">' . $totals_cols_bottom_empty . '</span>' );
    50525132                }
    50535133               
     
    50665146                    if ( $title_col === $i )
    50675147                    {
    5068                         $row_values[$cnt_rowvalues][$i] = array( '',  $totals_cols_bottom_title );
     5148                        $row_values[$cnt_rowvalues][$i] = array( '',  '<span class="total-title">' . $totals_cols_bottom_title . '</span>' );
    50695149                    }
    50705150                }
     
    53255405                else
    53265406                {         
     5407                    if ( empty( $tablecell_hidecolumn_class[$m_colkey] ) ) {$tablecell_hidecolumn_class[$m_colkey] = '';}
     5408                   
    53275409                    if ( !isset( $inner_value[1] ) )
    53285410                    {
     
    53335415                        if ( $nr_col == 1 )
    53345416                        {
    5335                             if ( empty( $tablecell_hidecolumn_class[$m_colkey] ) ) {$tablecell_hidecolumn_class[$m_colkey] = '';}
    53365417                            $html .= '<'. $tdh . ' data-editable="' . $editable . '" class="' . $tablecell_hidecolumn_class[$m_colkey] . 'td colset colset-' . $nr_col . '">';
    53375418                        }
  • csv-to-html/trunk/readme.txt

    r3308108 r3312748  
    55Requires PHP: 8.0
    66Requires at least: 3.0.1
    7 Tested up to: 6.8.1
    8 Stable Tag: 3.57
     7Tested up to: 6.8
     8Stable Tag: 3.63
    99License: GPLv2
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    141141* CSV to HTML addon
    142142
     143= 3.63 = (2025-06-16)
     144Bugfix: When using headerrow_exists="no" totals were not shown. They are now.
     145Totals now available for each grouping (at top at each grouping) when using group by column.
     146Suffixes, prefixes also avaialable in grouping totals (same attributes as before)
     147Count lines instead of sum in grouping totals, total_cols_top_empty in grouping,
     148New attributes (only applicable for grouping totals): totals_forgrouping, totals_cols_top_empty, totals_cols_top_title, totals_cols_top_title_col
     149Classes added for totals and subtotals for easier applicance of css.
     150
    143151= 3.57 = (2025-06-08)
    144152Internally now using the class as singleton (good for using this plugin from other plugins etc)
Note: See TracChangeset for help on using the changeset viewer.