fork download
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use CGI qw(:standard);
  5.  
  6. # HTML Template
  7. my $html_template = <<'HTML';
  8. <!DOCTYPE html>
  9. <html lang="en">
  10. <head>
  11.   <meta charset="UTF-8">
  12.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  13.   <title>Table and Pie Chart with Tabs</title>
  14.   <link rel="stylesheet" href="https://c...content-available-to-author-only...e.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
  15.   <!-- Removed Chart.js, added Google Charts -->
  16.   <script type="text/javascript" src="https://w...content-available-to-author-only...c.com/charts/loader.js"></script>
  17.   <style>
  18.   /* Default Light Mode */
  19.   body {
  20.   font-family: Arial, sans-serif;
  21.   margin: 0;
  22.   padding: 0;
  23.   background-color: #f4f4f4;
  24.   color: #333;
  25.   transition: all 0.3s ease;
  26.   }
  27.  
  28.   header {
  29.   width: 100%;
  30.   text-align: center;
  31.   padding: 20px 0;
  32.   font-size: 24px;
  33.   font-weight: bold;
  34.   background-color: #fff;
  35.   color: #333;
  36.   }
  37.  
  38.   .container {
  39.   display: flex;
  40.   justify-content: space-between;
  41.   padding: 20px;
  42.   }
  43.  
  44.   .table-container {
  45.   flex: 1;
  46.   margin-right: 20px;
  47.   }
  48.  
  49.   .chart-container {
  50.   width: 100%;
  51.   height: 400px; /* Updated height to make chart more flexible */
  52.   }
  53.  
  54.   table {
  55.   width: 100%;
  56.   border-collapse: collapse;
  57.   margin-bottom: 20px;
  58.   }
  59.  
  60.   table, th, td {
  61.   border: 1px solid #ddd;
  62.   }
  63.  
  64.   th, td {
  65.   padding: 8px 12px;
  66.   text-align: left;
  67.   }
  68.  
  69.   th {
  70.   background-color: #f4f4f4;
  71.   }
  72.  
  73.   canvas {
  74.   width: 200px;
  75.   height: 200px;
  76.   }
  77.  
  78.   .tabs {
  79.   display: flex;
  80.   margin-top: 20px;
  81.   justify-content: center;
  82.   }
  83.  
  84.   .tab {
  85.   padding: 10px 20px;
  86.   margin: 0 5px;
  87.   cursor: pointer;
  88.   border: 1px solid #ddd;
  89.   border-radius: 5px;
  90.   background-color: #f4f4f4;
  91.   text-align: center;
  92.   }
  93.  
  94.   .tab:hover {
  95.   background-color: #ddd;
  96.   }
  97.  
  98.   .tab-content {
  99.   display: none;
  100.   margin-top: 20px;
  101.   padding: 20px;
  102.   border: 1px solid #ddd;
  103.   border-top: none;
  104.   }
  105.  
  106.   .active-tab {
  107.   background-color: #ccc;
  108.   }
  109.  
  110.   .active-content {
  111.   display: block;
  112.   }
  113.  
  114.   .active-row {
  115.   background-color: #e0f7fa;
  116.   }
  117.  
  118.   /* Dark Mode Styles */
  119.   .dark-mode {
  120.   background-color: #333;
  121.   color: #fff;
  122.   }
  123.  
  124.   .dark-mode header {
  125.   background-color: #444;
  126.   color: #fff;
  127.   }
  128.  
  129.   .dark-mode .tab {
  130.   background-color: #444;
  131.   color: #fff;
  132.   border: 1px solid #555;
  133.   }
  134.  
  135.   .dark-mode .tab:hover {
  136.   background-color: #555;
  137.   }
  138.  
  139.   .dark-mode table, .dark-mode th, .dark-mode td {
  140.   border: 1px solid #555;
  141.   }
  142.  
  143.   .dark-mode th {
  144.   background-color: #666;
  145.   }
  146.  
  147.   .dark-mode .tab-content {
  148.   background-color: #444;
  149.   color: #fff;
  150.   }
  151.  
  152.   .dark-mode .active-row {
  153.   background-color: #555;
  154.   }
  155.  
  156.   /* Dark Mode Button (Icon version) */
  157.   .dark-mode-toggle {
  158.   position: absolute;
  159.   top: 20px;
  160.   right: 20px;
  161.   background-color: transparent;
  162.   border: none;
  163.   cursor: pointer;
  164.   font-size: 24px;
  165.   color: #fff;
  166.   transition: background-color 0.3s ease, color 0.3s ease;
  167.   display: flex;
  168.   justify-content: center;
  169.   align-items: center;
  170.   width: 40px;
  171.   height: 40px;
  172.   border-radius: 50%;
  173.   padding: 5px;
  174.   }
  175.  
  176.   /* Light Mode Icon */
  177.   .dark-mode-toggle.light-mode i {
  178.   color: #ffeb3b; /* Yellow sun icon for light mode */
  179.   }
  180.  
  181.   /* Hover Effect for Light Mode (Sun) */
  182.   .dark-mode-toggle.light-mode:hover {
  183.   background-color: #fff;
  184.   }
  185.  
  186.   /* Dark Mode Icon (Moon) */
  187.   .dark-mode-toggle.dark-mode i {
  188.   color: #fff; /* White crescent icon in dark mode */
  189.   }
  190.  
  191.   /* Hover Effect for Dark Mode (Moon) */
  192.   .dark-mode-toggle.dark-mode:hover {
  193.   background-color: #444; /* Blends with the dark background */
  194.   }
  195.  
  196.   /* "Back to Top" Button */
  197.   .back-to-top {
  198.   position: fixed;
  199.   bottom: 20px;
  200.   right: 20px;
  201.   background-color: transparent;
  202.   border: none;
  203.   cursor: pointer;
  204.   font-size: 24px;
  205.   color: #fff;
  206.   transition: background-color 0.3s ease, color 0.3s ease;
  207.   display: flex;
  208.   justify-content: center;
  209.   align-items: center;
  210.   width: 40px;
  211.   height: 40px;
  212.   border-radius: 50%;
  213.   padding: 5px;
  214.   opacity: 0; /* Initially hidden */
  215.   visibility: hidden; /* Initially hidden */
  216.   transition: opacity 0.3s ease, visibility 0.3s ease;
  217.   }
  218.  
  219.   .back-to-top.show {
  220.   opacity: 1;
  221.   visibility: visible;
  222.   }
  223.  
  224.   .back-to-top i {
  225.   color: #00bcd4; /* Light cyan color for the arrow */
  226.   }
  227.  
  228.   /* Hover Effect for "Back to Top" Button */
  229.   .back-to-top:hover {
  230.   background-color: #00bcd4;
  231.   color: #fff;
  232.   }
  233.  
  234.   .back-to-top:hover i {
  235.   transform: scale(1.1);
  236.   }
  237.   </style>
  238. </head>
  239. <body>
  240.  
  241.   <header>Table and Pie Chart with Tab</header>
  242.   <div class="container">
  243.   <!-- Table Section -->
  244.   <div class="table-container">
  245.   <table>
  246.   <thead>
  247.   <tr>
  248.   <th>ID</th>
  249.   <th>Name</th>
  250.   <th>Age</th>
  251.   <th>City</th>
  252.   </tr>
  253.   </thead>
  254.   <tbody>
  255.   %TABLE_ROWS%
  256.   </tbody>
  257.   </table>
  258.   </div>
  259.  
  260.   <!-- Pie Chart Section -->
  261.   <div class="chart-container">
  262.   <!-- This is where the Google Pie Chart will be rendered -->
  263.   <div id="pieChart"></div>
  264.   </div>
  265.   </div>
  266.  
  267.   <!-- Tabs Section -->
  268.   <div class="tabs">
  269.   %TABS%
  270.   </div>
  271.  
  272.   <!-- Tab Content -->
  273.   %TAB_CONTENTS%
  274.  
  275.   <!-- Dark Mode Toggle Button -->
  276.   <button id="darkModeToggle" class="dark-mode-toggle light-mode">
  277.   <i class="fas fa-sun"></i>
  278.   </button>
  279.  
  280.   <!-- Back to Top Button -->
  281.   <button class="back-to-top" id="backToTopBtn">
  282.   <i class="fas fa-arrow-up"></i>
  283.   </button>
  284.  
  285.   <script type="text/javascript">
  286.   // Load Google Charts library
  287.   google.charts.load('current', {
  288.   packages: ['corechart', 'piechart']
  289.   });
  290.  
  291.   google.charts.setOnLoadCallback(drawChart);
  292.  
  293.   // Pie Chart Data and Options
  294.   function drawChart() {
  295.   var data = google.visualization.arrayToDataTable([
  296.   ['Category', 'Value'],
  297.   ['Red', 300],
  298.   ['Blue', 50],
  299.   ['Yellow', 100],
  300.   ['Green', 40],
  301.   ['Purple', 120]
  302.   ]);
  303.  
  304.   var options = {
  305.   title: 'Pie Chart Example',
  306.   is3D: false,
  307.   slices: {
  308.   0: {offset: 0.1},
  309.   1: {offset: 0.1},
  310.   2: {offset: 0.1},
  311.   3: {offset: 0.1},
  312.   4: {offset: 0.1}
  313.   },
  314.   legend: { position: 'top' }
  315.   };
  316.  
  317.   var chart = new google.visualization.PieChart(document.getElementById('pieChart'));
  318.   chart.draw(data, options);
  319.   }
  320.  
  321.   // Dark Mode Toggle Functionality (Same as before)
  322.   const toggleButton = document.getElementById('darkModeToggle');
  323.   toggleButton.addEventListener('click', () => {
  324.   document.body.classList.toggle('dark-mode');
  325.   const icon = document.querySelector('.dark-mode-toggle i');
  326.   if (document.body.classList.contains('dark-mode')) {
  327.   icon.classList.remove('fa-sun');
  328.   icon.classList.add('fa-moon');
  329.   toggleButton.classList.remove('light-mode');
  330.   toggleButton.classList.add('dark-mode');
  331.   } else {
  332.   icon.classList.remove('fa-moon');
  333.   icon.classList.add('fa-sun');
  334.   toggleButton.classList.remove('dark-mode');
  335.   toggleButton.classList.add('light-mode');
  336.   }
  337.   });
  338.   </script>
  339. </body>
  340. </html>
  341. HTML
  342.  
  343. # Sample data for the table (can be dynamic)
  344. my @table_data = (
  345. { id => 1, name => "John Doe", age => 28, city => "New York" },
  346. { id => 2, name => "Jane Smith", age => 34, city => "Los Angeles" },
  347. { id => 3, name => "Sam Johnson", age => 25, city => "Chicago" },
  348. );
  349.  
  350. # Generate table rows
  351. my $table_rows = '';
  352. foreach my $row (@table_data) {
  353. $table_rows .= "<tr data-tab=\"tab$row->{id}\">\n";
  354. $table_rows .= "<td class=\"tab-id\">$row->{id}</td>\n";
  355. $table_rows .= "<td>$row->{name}</td>\n";
  356. $table_rows .= "<td>$row->{age}</td>\n";
  357. $table_rows .= "<td>$row->{city}</td>\n";
  358. $table_rows .= "</tr>\n";
  359. }
  360.  
  361. # Generate tabs
  362. my $tabs = '';
  363. for (my $i = 1; $i <= 7; $i++) {
  364. $tabs .= "<div class=\"tab\" data-tab=\"tab$i\">Tab $i</div>\n";
  365. }
  366.  
  367. # Generate tab contents
  368. my $tab_contents = '';
  369. for (my $i = 1; $i <= 7; $i++) {
  370. $tab_contents .= "<div class=\"tab-content\" id=\"tab$i\">\n";
  371. $tab_contents .= "<p>This is content for Tab $i.</p>\n";
  372. $tab_contents .= "</div>\n";
  373. }
  374.  
  375. # Replace placeholders in the template
  376. $html_template =~ s/%TABLE_ROWS%/$table_rows/g;
  377. $html_template =~ s/%TABS%/$tabs/g;
  378. $html_template =~ s/%TAB_CONTENTS%/$tab_contents/g;
  379.  
  380. # Output the final HTML
  381. print header(-type => 'text/html', -charset => 'UTF-8');
  382. print $html_template;
  383.  
Success #stdin #stdout 0.04s 9232KB
stdin
Standard input is empty
stdout
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Table and Pie Chart with Tabs</title>
    <link rel="stylesheet" href="https://c...content-available-to-author-only...e.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <!-- Removed Chart.js, added Google Charts -->
    <script type="text/javascript" src="https://w...content-available-to-author-only...c.com/charts/loader.js"></script>
    <style>
        /* Default Light Mode */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
            color: #333;
            transition: all 0.3s ease;
        }

        header {
            width: 100%;
            text-align: center;
            padding: 20px 0;
            font-size: 24px;
            font-weight: bold;
            background-color: #fff;
            color: #333;
        }

        .container {
            display: flex;
            justify-content: space-between;
            padding: 20px;
        }

        .table-container {
            flex: 1;
            margin-right: 20px;
        }

        .chart-container {
            width: 100%;
            height: 400px;  /* Updated height to make chart more flexible */
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }

        table, th, td {
            border: 1px solid #ddd;
        }

        th, td {
            padding: 8px 12px;
            text-align: left;
        }

        th {
            background-color: #f4f4f4;
        }

        canvas {
            width: 200px;
            height: 200px;
        }

        .tabs {
            display: flex;
            margin-top: 20px;
            justify-content: center;
        }

        .tab {
            padding: 10px 20px;
            margin: 0 5px;
            cursor: pointer;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f4f4f4;
            text-align: center;
        }

        .tab:hover {
            background-color: #ddd;
        }

        .tab-content {
            display: none;
            margin-top: 20px;
            padding: 20px;
            border: 1px solid #ddd;
            border-top: none;
        }

        .active-tab {
            background-color: #ccc;
        }

        .active-content {
            display: block;
        }

        .active-row {
            background-color: #e0f7fa;
        }

        /* Dark Mode Styles */
        .dark-mode {
            background-color: #333;
            color: #fff;
        }

        .dark-mode header {
            background-color: #444;
            color: #fff;
        }

        .dark-mode .tab {
            background-color: #444;
            color: #fff;
            border: 1px solid #555;
        }

        .dark-mode .tab:hover {
            background-color: #555;
        }

        .dark-mode table, .dark-mode th, .dark-mode td {
            border: 1px solid #555;
        }

        .dark-mode th {
            background-color: #666;
        }

        .dark-mode .tab-content {
            background-color: #444;
            color: #fff;
        }

        .dark-mode .active-row {
            background-color: #555;
        }

        /* Dark Mode Button (Icon version) */
        .dark-mode-toggle {
            position: absolute;
            top: 20px;
            right: 20px;
            background-color: transparent;
            border: none;
            cursor: pointer;
            font-size: 24px;
            color: #fff;
            transition: background-color 0.3s ease, color 0.3s ease;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            padding: 5px;
        }

        /* Light Mode Icon */
        .dark-mode-toggle.light-mode i {
            color: #ffeb3b;  /* Yellow sun icon for light mode */
        }

        /* Hover Effect for Light Mode (Sun) */
        .dark-mode-toggle.light-mode:hover {
            background-color: #fff;
        }

        /* Dark Mode Icon (Moon) */
        .dark-mode-toggle.dark-mode i {
            color: #fff;  /* White crescent icon in dark mode */
        }

        /* Hover Effect for Dark Mode (Moon) */
        .dark-mode-toggle.dark-mode:hover {
            background-color: #444; /* Blends with the dark background */
        }

        /* "Back to Top" Button */
        .back-to-top {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: transparent;
            border: none;
            cursor: pointer;
            font-size: 24px;
            color: #fff;
            transition: background-color 0.3s ease, color 0.3s ease;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            padding: 5px;
            opacity: 0; /* Initially hidden */
            visibility: hidden; /* Initially hidden */
            transition: opacity 0.3s ease, visibility 0.3s ease;
        }

        .back-to-top.show {
            opacity: 1;
            visibility: visible;
        }

        .back-to-top i {
            color: #00bcd4; /* Light cyan color for the arrow */
        }

        /* Hover Effect for "Back to Top" Button */
        .back-to-top:hover {
            background-color: #00bcd4;
            color: #fff;
        }

        .back-to-top:hover i {
            transform: scale(1.1);
        }
    </style>
</head>
<body>

    <header>Table and Pie Chart with Tab</header>
    <div class="container">
        <!-- Table Section -->
        <div class="table-container">
            <table>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Age</th>
                        <th>City</th>
                    </tr>
                </thead>
                <tbody>
                    <tr data-tab="tab1">
<td class="tab-id">1</td>
<td>John Doe</td>
<td>28</td>
<td>New York</td>
</tr>
<tr data-tab="tab2">
<td class="tab-id">2</td>
<td>Jane Smith</td>
<td>34</td>
<td>Los Angeles</td>
</tr>
<tr data-tab="tab3">
<td class="tab-id">3</td>
<td>Sam Johnson</td>
<td>25</td>
<td>Chicago</td>
</tr>

                </tbody>
            </table>
        </div>

        <!-- Pie Chart Section -->
        <div class="chart-container">
            <!-- This is where the Google Pie Chart will be rendered -->
            <div id="pieChart"></div>
        </div>
    </div>

    <!-- Tabs Section -->
    <div class="tabs">
        <div class="tab" data-tab="tab1">Tab 1</div>
<div class="tab" data-tab="tab2">Tab 2</div>
<div class="tab" data-tab="tab3">Tab 3</div>
<div class="tab" data-tab="tab4">Tab 4</div>
<div class="tab" data-tab="tab5">Tab 5</div>
<div class="tab" data-tab="tab6">Tab 6</div>
<div class="tab" data-tab="tab7">Tab 7</div>

    </div>

    <!-- Tab Content -->
    <div class="tab-content" id="tab1">
<p>This is content for Tab 1.</p>
</div>
<div class="tab-content" id="tab2">
<p>This is content for Tab 2.</p>
</div>
<div class="tab-content" id="tab3">
<p>This is content for Tab 3.</p>
</div>
<div class="tab-content" id="tab4">
<p>This is content for Tab 4.</p>
</div>
<div class="tab-content" id="tab5">
<p>This is content for Tab 5.</p>
</div>
<div class="tab-content" id="tab6">
<p>This is content for Tab 6.</p>
</div>
<div class="tab-content" id="tab7">
<p>This is content for Tab 7.</p>
</div>


    <!-- Dark Mode Toggle Button -->
    <button id="darkModeToggle" class="dark-mode-toggle light-mode">
        <i class="fas fa-sun"></i>
    </button>

    <!-- Back to Top Button -->
    <button class="back-to-top" id="backToTopBtn">
        <i class="fas fa-arrow-up"></i>
    </button>

    <script type="text/javascript">
        // Load Google Charts library
        google.charts.load('current', {
            packages: ['corechart', 'piechart']
        });

        google.charts.setOnLoadCallback(drawChart);

        // Pie Chart Data and Options
        function drawChart() {
            var data = google.visualization.arrayToDataTable([
                ['Category', 'Value'],
                ['Red', 300],
                ['Blue', 50],
                ['Yellow', 100],
                ['Green', 40],
                ['Purple', 120]
            ]);

            var options = {
                title: 'Pie Chart Example',
                is3D: false,
                slices: {
                    0: {offset: 0.1},
                    1: {offset: 0.1},
                    2: {offset: 0.1},
                    3: {offset: 0.1},
                    4: {offset: 0.1}
                },
                legend: { position: 'top' }
            };

            var chart = new google.visualization.PieChart(document.getElementById('pieChart'));
            chart.draw(data, options);
        }

        // Dark Mode Toggle Functionality (Same as before)
        const toggleButton = document.getElementById('darkModeToggle');
        toggleButton.addEventListener('click', () => {
            document.body.classList.toggle('dark-mode');
            const icon = document.querySelector('.dark-mode-toggle i');
            if (document.body.classList.contains('dark-mode')) {
                icon.classList.remove('fa-sun');
                icon.classList.add('fa-moon');
                toggleButton.classList.remove('light-mode');
                toggleButton.classList.add('dark-mode');
            } else {
                icon.classList.remove('fa-moon');
                icon.classList.add('fa-sun');
                toggleButton.classList.remove('dark-mode');
                toggleButton.classList.add('light-mode');
            }
        });
    </script>
</body>
</html>