<?php

if(!defined('VIRTUALIZOR')){
	die('Hacking Attempt');
}

function getSortHeader($header_name, $sort_column, $sort_column_by, $column ,$size = 90){

	global $globals;
	
	$str = '<div class="d-inline-flex align-items-center" style="width:'.$size.'px;">
		<div class="mr-2">
			<span class="" >'.$header_name.'</span>
		</div>
		<span class="sorter">
			<a class="text-always-white" href="'.$globals['index'].'act=backup_dashboard&sortcolumn='.$column.'&sortby=asc"><i class="fas fa-sort-up"></i></a><br>
			<a class="text-always-white" href="'.$globals['index'].'act=backup_dashboard&sortcolumn='.$column.'&sortby=desc"><i class="fas fa-sort-down"></i></a>
		</span>
	</div>';
	return $str;
}

function get_status_icon($progress){

    $icon = [
        -1 => '<a class="badge badge-danger px-2 py-1 mt-2 mb-2">Failed</a>',
        2 => '<a class="badge badge-settings px-2 py-1 mt-2 mb-2">Running</a>',
        1 => '<a class="badge badge-success px-2 py-1 mt-2 mb-2">Successful</a>',
    ];

    return $icon[$progress];

}

function backup_dashboard_theme(){

    global $theme, $l, $globals, $servers, $error, $done, $backup_stats, $backup_tasks_data, $sort_column, $sort_column_by, $search;

	softheader($l['<title>']);
    
    // Some css tweaks
    echo '
    <style>
        td:not(:has(a)), #table_tasks th, #table_backuply th {
            text-align: left;
        }
    </style>';

    // JS
    echo '
    <script type="text/javascript" charset="utf8" src="'.$theme['url'].'/js2/jquery-simple-tree-table.js"></script>
    <script language="javascript" type="text/javascript"><!-- // --><![CDATA[

        var prog = 0;

        function toggle_option(option){
            if ($("#"+option).is(":hidden")){
                $("#"+option).slideDown("slow");
                $("#"+option+"_toggle_indicator").text(" - ");
            }else{
                $("#"+option).slideUp("slow");
                $("#"+option+"_toggle_indicator").text(" + ");
            }
        }

        function dashboard_donut_chart(data, donut_chart_id){

            var options = {
                series: [data["data"][0], data["data"][1], data["data"][2]],
                chart: {
                    type: "donut",
                    width: 100,
                    height: 100,
                },

                plotOptions: {
                    pie: {
                        donut: {
                            size: "70%", // Adjust the width of the circular bar
                        }
                    }
                },

                legend: {
                    show: false,
                    position: "right",
                },

                dataLabels: {
                    enabled: false,
                },

                labels: [data["label"][0], data["label"][1], data["label"][2]],

                grid:{
                    padding: {
                        top: 0,
                        right: 0,
                        bottom: 0,
                        left: 0
                    },
                },

                colors: ["#6F58FF", "#F76775", "#46C9B8"],

                noData: {
                    text: "ND",
                    style: {
                        color: "#000",
                        fontSize: "6px",
                        fontFamily: undefined
                    }
                },
            };

            var chart = new ApexCharts(document.querySelector(donut_chart_id), options);
            chart.render();

        }

        // Plot the charts
        $(document).ready(function(){

            var server_vps_chart_data = {
                                data : ['.$backup_stats['vps_with_backups'].', '.$backup_stats['vps_without_backups'].', 0],
                                label : ["'.__J('With Backups').'", "'.__J('Without Backups').'", ""]
                            };
            dashboard_donut_chart(server_vps_chart_data, "#server_vps_chart");

            if('.$backup_stats['backups_full'].' == 0 && '.$backup_stats['backups_inc'].' == 0 && '.$backup_stats['backups_legacy'].' == 0){
                $("#backup_chart").html("<div class=\'no_data_circle\'>'.__J('! No Backups Found').'</div>");
            }else{
                var backup_chart_data = {
                                    data : ['.$backup_stats['backups_full'].', '.$backup_stats['backups_inc'].', '.$backup_stats['backups_legacy'].'],
                                    label : ["'.__J('Full Backups').'", "'.__J('Incremental Backups').'", "'.__J('Legacy Backups').'"]
                                };
                dashboard_donut_chart(backup_chart_data, "#backup_chart");
            }

            if('.$backup_stats['success_backup_tasks'].' == 0 && '.$backup_stats['failed_backup_tasks'].' == 0 && '.$backup_stats['backup_running_tasks'].' == 0){
                $("#backup_task_chart").html("<div class=\'no_data_circle\'>'.__J('! No Backup Tasks Found').'</div>");
            }else{
                var backup_task_chart_data = {
                                    data : ['.$backup_stats['success_backup_tasks'].', '.$backup_stats['failed_backup_tasks'].', '.$backup_stats['backup_running_tasks'].'],
                                    label : ["'.__J('Successful Backup Tasks').'", "'.__J('Failed Backup Tasks').'", "'.__J('Running Backup Tasks').'"]
                                };
                dashboard_donut_chart(backup_task_chart_data, "#backup_task_chart");
            }

            if('.$backup_stats['success_restore_tasks'].' == 0 && '.$backup_stats['failed_restore_tasks'].' == 0 && '.$backup_stats['restore_running_tasks'].' == 0){
                $("#restore_task_chart").html("<div class=\'no_data_circle\'>'.__J('! No Restore Tasks Found').'</div>");
            }else{
                var restore_task_chart_data = {
                                    data : ['.$backup_stats['success_restore_tasks'].', '.$backup_stats['failed_restore_tasks'].', '.$backup_stats['restore_running_tasks'].'],
                                    label : ["'.__J('Successful Restore Tasks').'", "'.__J('Failed Restore Tasks').'", "'.__J('Running Restore Tasks').'"]
                                };
                dashboard_donut_chart(restore_task_chart_data, "#restore_task_chart");
            }
        });

        function make_progress(index, progress){
            var steps = 20;
            var start = $("#pbar"+index).text();
            start = (start.slice(0, -1));
            if(isNaN(start)){
                start = 0;
            }
            var step = (progress - start)/steps;
            if(step < 0){ step = 0;}
            var increment = function(){
                var val = $("#pbar"+index).text();
                val = Number(val.slice(0, - 1));
                prog = parseInt(val + Math.round(step));
                if(prog > progress){ prog = progress;}
                if(prog < parseInt("100")){
                    $("#pbar"+index).text(prog + "%");
                    $("#progressbar"+index).width(prog + "%");
                }else{
                    $("#progressbar"+index).width(100 + "%");
                }
                if (prog < progress){setTimeout(increment, 500);}
            };
            increment();
        };

        function get_task_progress(actids){

            var search = $("#task_search").find("input[type=text], select").serialize();

            $.ajax({
                type: "GET",
                url: "'.$globals['index'].'&act=tasks&api=json",
                dataType : "json",
                data : {
                    actid : actids
                },
                success:function(data){
                    var tasks = data.tasks;
                    $.each(tasks, function(index, value){
                        if(tasks[index]["progress"] == 100){
                            $("#status"+index).removeAttr("tooltip");
                            $("#status"+index).unbind();
                            $("#status"+index).text("'.__J('Completed').'");
                            $("#pbar"+index).html("<i style=\"font-size:24px !important;\" class=\"fas fa-2x text-success fa-check-circle\"></i>");
                            $("#progressbar"+index).hide();
                            $("#progressbar"+index).parent().css("border", "0px");
                            $("#progressbar"+index).parent().removeClass("progress");
                        }else if(tasks[index]["status"] == -1){
                            $("#status"+index).html(tasks[index]["status_txt"]);
                            if(!empty(tasks[index]["status_txt"])){
                                $("#status"+index).attr("tooltip",tasks[index]["status_txt"]);
                            }
                            $("#pbar"+index).html("<i style=\"font-size:24px !important;\" class=\"fas text-danger fa-2x fa-times-circle\"></i>");
                            $("#progressbar"+index).hide();
                            $("#progressbar"+index).parent().css("border", "0px");
                            $("#progressbar"+index).parent().removeClass("progress");
                        }else{

                            $("#status"+index).text(tasks[index]["status_txt"]);
                            if(!empty(tasks[index]["status_txt"])){
                                $("#status"+index).attr("tooltip",tasks[index]["status_txt"]);
                            }
                            $("#progressbar"+index).hide();
                            $("#progressbar"+index).parent().css("border", "0px");
                            $("#progressbar"+index).parent().removeClass("progress");

                            if(isNaN(tasks[index]["progress"])){
                                $("#pbar"+index).unbind();
                                $("#pbar"+index).text(tasks[index]["progress"]);
                                $("#progressbar"+index).hide();
                                $(".progress_"+index).hide();
                            }else{
                                $("#progressbar"+index).parent().addClass("progress");
                                make_progress(index, Number(tasks[index]["progress"]));
                                $("#progressbar"+index).show();
                            }
                        }

                        $("#started"+index).html(tasks[index]["started"]);
                        $("#updated"+index).html(tasks[index]["updated"]);
                        $("#ended"+index).html(tasks[index]["ended"]);
                        
                    });

                    show_tooltip();
                }
            });

            setTimeout(function(){get_task_progress(actids);}, 10000);
        };
        
        function retry_task(actid, is_restore){

            let task_name = is_restore ? "'.__J('Restore').'" : "'.__J('Backup').'";

            showalert("Are you sure, you want to retry the "+task_name+" task" ,"3" , function(confirm){
            
                if(confirm == false){
                    return false;
                }
        
                $.ajax({
                    type: "POST",
                    url: "'.$globals['index'].'act=backup_dashboard&api=json&retry="+actid,
                    dataType : "json",
                    success: function(data){

                        if("retry_done" in data){
                            let done_msg = task_name + " process has been started successfully";
                            showalert(done_msg);
                        }
    
                        if("error" in data) {
                            setTimeout(function(){
                                let err = `<ul>${Object.values(data.error).map(e => `<li>${e}</li>`).join("")}</ul>`;
                                showalert(err ,"1");
                                return false;
                            }, 200);
                        }
                    }
                });
            });
        }

        $(document).ready(function(){
            get_task_progress("'.implode(',',array_keys($backup_tasks_data)).'" );
        });

    // ]]></script>';

    echo '
    <div class="card2 p-3 mx-3 mt-3 card_title">
        <div class="row">
            <div class="card2-title col d-flex align-items-center justify-content-center">
                '.__('Backups').' '.(empty($search) ? '<span> | Last 7 Days </span>' : '').'
            </div>
        </div>
    </div>

    <div class="bg">

        <!-- Charts -->
        <div class="row dashboard_row mt-3 mx-auto w-100">
            <!-- Server vps data card start -->
            <div class="col-lg-3 col-sm-6 col-md-6 mb-3 res_card h-50">
                <div class="card3 cluster-card1 res_card h-25">
                    <div class="card_icon_title">
                        <h5 class="text-nowrap m-0 d-flex flex-fill align-items-center justify-content-between mx-1">
                            <div>
                                <img  src="'.$theme['svg'].'vms.svg" title="'.__('RAM').'"/>
                                <a href="'.$globals['ind'].'act=vs&serid='.$globals['server'].'&search=1">
                                    Total '.VM_SHORT.'
                                </a>
                            </div>
                            <span>'.$backup_stats['num_vps'].'</span>
                        </h5>
                    </div>
                    <div class="d-flex justify-content-center mt-1">
                        <div id="server_vps_chart" class="p-0"></div>
                        <div class="w-100 my-auto ml-2">
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                <span class="purple_dot"></span> 
                                <label class="">'.__('With Backups').'</label>
                                </div>
                                <div class="">'.$backup_stats['vps_with_backups'].'</div>
                            </div>
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                <span class="red_dot"></span>
                                <label class="">'.__('Without Backups').'</label>
                                </div>
                                <div class="">'.$backup_stats['vps_without_backups'].'</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Server vps data card end -->

            <!-- Total backup data card start -->
            <div class="col-lg-3 col-sm-6 col-md-6 mb-3 res_card h-50">
                <div class="card3 cluster-card1 res_card h-25">
                    <div class="card_icon_title">
                        <h5 class="text-nowrap m-0 d-flex flex-fill align-items-center justify-content-between mx-1">
                            <div>
                                <img  src="'.$theme['svg'].'vms.svg" title="'.__('RAM').'"/>
                                <a href="'.$globals['ind'].'act=backup_dashboard">
                                    '.__('Backups').'
                                </a>
                            </div>
                            <span>'.$backup_stats['total_backups'].'</span>
                        </h5>
                    </div>
                    <div class="d-flex justify-content-center mt-1">
                        <div id="backup_chart" class="p-0"></div>
                        <div class="w-100 my-auto ml-2">
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="purple_dot"></span> 
                                    <label class="">'.__('Full').'</label>
                                </div>
                                <div class="">'.$backup_stats['backups_full'].'</div>
                            </div>
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="red_dot"></span>
                                    <label class="">'.__('Incremental').'</label>
                                </div>
                                <div class="">'.$backup_stats['backups_inc'].'</div>
                            </div>
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="green_dot"></span>
                                    <label class="">'.__('Legacy').'</label>
                                </div>
                                <div class="">'.$backup_stats['backups_legacy'].'</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Total backup data card end -->

            <!-- Backup tasks count card start -->
            <div class="col-lg-3 col-sm-6 col-md-6 mb-3 res_card h-50">
                <div class="card3 cluster-card1 res_card h-25">
                    <div class="card_icon_title">
                        <h5 class="text-nowrap m-0 d-flex flex-fill align-items-center justify-content-between mx-1">
                            <div>
                                <img src="'.$theme['svg'].'vms.svg" title="'.__('RAM').'"/>
                                <a href="'.$globals['ind'].'act=backup_dashboard&search=1">
                                    '.__('Backup Tasks').'
                                </a>
                            </div>
                            <span>'.$backup_stats['total_backup_tasks'].'</span>
                        </h5>
                    </div>
                    <div class="d-flex justify-content-center mt-1">
                        <div id="backup_task_chart" class="p-0"></div>
                        <div class="w-100 my-auto ml-2">
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="purple_dot"></span>
                                    <a style="color: var(--black);" href="'.$globals['ind'].'act=backup_dashboard&action=backup&status=1&search=1">
                                        <label class="cursor-pointer">'.__('Successful').'</label>
                                    </a>
                                </div>
                                <div class="">'.$backup_stats['success_backup_tasks'].'</div>
                            </div>
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="red_dot"></span>
                                    <a style="color: var(--black);" href="'.$globals['ind'].'act=backup_dashboard&action=backup&status=-1&search=1">
                                        <label class="cursor-pointer">'.__('Failed').'</label>
                                    </a>
                                </div>
                                <div class="">'.$backup_stats['failed_backup_tasks'].'</div>
                            </div>
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="green_dot"></span>
                                    <a style="color: var(--black);" href="'.$globals['ind'].'act=backup_dashboard&action=backup&status=2&search=1">
                                        <label class="cursor-pointer">'.__('Running').'</label>
                                    </a>
                                </div>
                                <div class="">'.$backup_stats['backup_running_tasks'].'</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Backup tasks count card end -->

            <!-- Restore tasks count card start -->
            <div class="col-lg-3 col-sm-6 col-md-6 mb-3 res_card h-50">
                <div class="card3 cluster-card1 res_card h-25">
                    <div class="card_icon_title">
                        <h5 class="text-nowrap m-0 d-flex flex-fill align-items-center justify-content-between mx-1">
                            <div>
                                <img src="'.$theme['svg'].'vms.svg" title="'.__('RAM').'"/>
                                <a href="'.$globals['ind'].'act=backup_dashboard&search=1">
                                    '.__('Restore Tasks').'
                                </a>
                            </div>
                            <span>'.$backup_stats['total_restore_tasks'].'</span>
                        </h5>
                    </div>
                    <div class="d-flex justify-content-center mt-1">
                        <div id="restore_task_chart" class="p-0"></div>
                        <div class="w-100 my-auto ml-2">
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="purple_dot"></span>
                                    <a style="color: var(--black);" href="'.$globals['ind'].'act=backup_dashboard&action=restore&status=1&search=1">
                                        <label class="cursor-pointer">'.__('Successful').'</label>
                                    </a>
                                </div>
                                <div class="">'.$backup_stats['success_restore_tasks'].'</div>
                            </div>
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="red_dot"></span>
                                    <a style="color: var(--black);" href="'.$globals['ind'].'act=backup_dashboard&action=restore&status=-1&search=1">
                                        <label class="cursor-pointer">'.__('Failed').'</label>
                                    </a>
                                </div>
                                <div class="">'.$backup_stats['failed_restore_tasks'].'</div>
                            </div>
                            <div class="d-flex align-items-center justify-content-between card_content">
                                <div class="">
                                    <span class="green_dot"></span>
                                    <a style="color: var(--black);" href="'.$globals['ind'].'act=backup_dashboard&action=restore&status=2&search=1">
                                        <label class="cursor-pointer">'.__('Running').'</label>
                                    </a>
                                </div>
                                <div class="">'.$backup_stats['restore_running_tasks'].'</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Restore tasks count card end -->

        </div>            
    </div>';
        
    error_handle($error);

    if(!empty($done)){
        show_alert(__('The VPS backup was created successfully'));
    }

    $backup_task_name = [
        'backuply_vpsbackups_plan' => ' Backuply Backup',
        'backuply_restorevps_plan' => ' Backuply Restore',
        'vpsbackups_plan' => ' Backup',
        'restorevps_plan' => ' Restore',
    ];

    echo '
    <div class="card p-2 mx-3">

        <div class="row mx-auto w-100 mb-3 justify-content-between">
            <div class="col-sm-4 col-lg-4 col-md-6 text-right d-flex align-items-center p-0">
            </div>
            <div class="col-sm-8 col-lg-8 col-md-6 d-flex align-items-center justify-content-end p-0 mt-2 mt-md-0 mt-lg-0 gap-2">';
                page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
                echo get_num_records($globals['num_res']).'
                <div>
                    <span class="icon-fix d-flex align-items-center justify-content-center" style="float: right !important;">
                        <a href="javascript:showsearch();" class="text-light">
                            <i class="fas fa-search text-black"></i>
                        </a>
                    </span>
                </div>
            </div>
        </div>

        <!-- Search Form -->
        <div id="showsearch" class="mb-3" style="display:'.(optREQ('search') || (!empty($backup_tasks_data) && !empty($globals['showsearch'])) ? "" : "none").';">
            <form accept-charset="'.$globals['charset'].'"  class="form-horizontal" name="backup_dashboard_search" method="GET" action="" id="task_search">
                <input type="hidden" name="act" value="backup_dashboard">
                <div class="form-group_head">
                    <div class="row mx-auto w-100">
                        <div class="col-sm-4">
                            <label>'.__('Actid').'</label>
                            <input type="text" class="form-control" name="actid" id="actid" size="15" value="'.REQval('actid','').'" />
                        </div>
                        <div class="col-sm-4">
                            <label>'.__('VPS ID').'</label>
                            <input type="text" class="form-control" name="vpsid" id="vpsid" size="15" value="'.REQval('vpsid','').'" />
                        </div>
                        <div class="col-sm-4">
                            <label>'.__('User').'</label>
                            <input type="text" class="form-control" name="username" id="username" size="15" value="'.REQval('username','').'" />
                        </div>
                    </div>

                    <div class="row mx-auto w-100">
                        <div class="col-sm-4">
                            <label>'.__('Status').'</label>
                            <select class="custom-select" name="status">
                                <option value="">---</option>
                                <option value="1" '.REQselect('status', 1).'>Success</option>
                                <option value="-1" '.REQselect('status', -1).'>Failed</option>
                                <option value="2" '.REQselect('status', 2).'>Running</option>
                            </select>
                        </div>
                        <div class="col-sm-4">
                            <label>'.__('Action').'</label>
                            <select class="custom-select" name="action">
                                <option value="">---</option>
                                <option value="backuply_vpsbackups_plan" '.REQselect('action', 'backuply_vpsbackups_plan').'>'.$backup_task_name['backuply_vpsbackups_plan'].'</option>
                                <option value="backuply_restorevps_plan" '.REQselect('action', 'backuply_restorevps_plan').'>'.$backup_task_name['backuply_restorevps_plan'].'</option>
                                <option value="vpsbackups_plan" '.REQselect('action', 'vpsbackups_plan').'>'.$backup_task_name['vpsbackups_plan'].'</option>
                                <option value="restorevps_plan" '.REQselect('action', 'restorevps_plan').'>'.$backup_task_name['restorevps_plan'].'</option>
                            </select>
                        </div>
                        <div class="col-sm-4">
                            <label>'.__('Server').'</label>
                            <select class="custom-select" name="server">
                                <option value="-1">---</option>';
                                foreach($servers as $id => $data){
                                    echo '<option value="'.$id.'" '.REQselect('server', $id).'>'.$data['server_name'].'</option>';
                                }
                            echo'
                            </select>
                        </div>
                    </div>

                    <div class="row mx-auto w-100 my-2">
                        <div class="col-sm-12 text-center">
                            <button type="submit" name="search" value="1" class="go_btn mt-2">'.__('Submit').'</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <!-- Search Form End -->';

    // Not found any backup/restore logs
    if(empty($backup_tasks_data)){
        optREQ('vpsid') ? show_alert(__('VPS not found'), "2") : show_alert(__('Tasks not Found'), "2");
        echo '<div class="notice"><b>'.__('Note').' : </b> &nbsp; '.(optREQ('vpsid') ? __('VPS not found') : __('Tasks not Found')).'</div>';
   
    } else {

        echo '
        <!-- Create Backup Logs Table -->
        <div class="panel-content scrollbar-virt">
            <table class="table table-hover tablesorter common-table">
                <thead>
                    <tr class="table_heading">
                        <th class="min_width">'.getSortHeader(__('Actid'), $sort_column, $sort_column_by, 'actid','50').'</td>
                        <th class="min_width">'.getSortHeader(__('VPS ID'), $sort_column, $sort_column_by, 'vpsid','55').'</th>
                        <th style="width: 55px;"><span class="">'.__('User').'</span><br>'.getSortHeader(__('Server').'('.__('ID').')', $sort_column, $sort_column_by, 'server').' </th>
                        <th class="min_width">'.getSortHeader(__('Started'), $sort_column, $sort_column_by, 'started', '70').'</th>
                        <th class="min_width">'.getSortHeader(__('Updated'), $sort_column, $sort_column_by, 'updated', '70').'</th>
                        <th class="min_width">'.getSortHeader(__('Ended'), $sort_column, $sort_column_by, 'ended', '70').'</th>
                        <th class="min_width"><span class="">'.__('Action').'</span></th>
                        <th class="min_width">'.getSortHeader(__('Status'), $sort_column, $sort_column_by, 'status', 70).'</th>
                        <th class="min_width text-center"><span class="">'.__('Progress').'</span></th>
                        <th class="min_width text-center"><span class="">'.__('Logs').'</span></th>
                    </tr>
                </thead>';

                // <td>'.$servers[$tasks_data['serid']]['server_name'].'</td>
                
                foreach($backup_tasks_data as $actid => $tasks_data){
                    echo '<tr>
                        <td>'.$actid.'</td>
                        <td>'.$tasks_data['vpsid'].'</td>
                        <td><span id="email" class="userflare">'.((!empty($tasks_data['uid']) && !empty($tasks_data['email'])) ? $tasks_data['email'] : 'root').'</span><br>'.(!empty($servers[$tasks_data['serid']]['server_name']) ? $servers[$tasks_data['serid']]['server_name'].' ('.$tasks_data['serid'].')' : __('Unslaved Server')).'</td>
                        <td>'.$tasks_data['started'].'</td>
                        <td>'.$tasks_data['updated'].'</td>
                        <td>'.$tasks_data['ended'].'</td>
                        <td>'.$backup_task_name[$tasks_data['action']].'</td>
                        <td align="left">'.get_status_icon($tasks_data['status_icon']).'</td>


                        <td class="d-flex align-items-center justify-content-center">';
                            if($tasks_data['status'] == -1 && empty($tasks_data['data']['retry_done'])){
                                $is_restore_task = in_array($tasks_data['action'], ['backuply_restorevps_plan', 'restorevps_plan']) ? 1 : 0;
                                echo '<div><label class="control-label">
                                        <i style="font-size:24px !important;" class="fas fa-redo text-warning" onclick="return retry_task('.$actid.', '.$is_restore_task.');" tooltip="'.__($is_restore_task ? 'Retry Restore Task' : 'Retry Backup Task').'"></i>
                                </label></div>';
                                
                            } else {
                                echo '
                                <div class="progress-cont" id="progress-cont'.$actid.'">
                                <center><div id="pbar'.$actid.'">'.$tasks_data['progress'].'%</center>
                                <div class="progress progress_'.$actid.'">
                                    <div class="progress-bar bg-primary progress-bar-striped progress-bar-animated" style="width:0px;" id="progressbar'.$actid.'">
                                    </div>
                                </div>';
                            }
                            echo '
                        </td>
                        <td align="center" class="text-center">
                            <a href="javascript:void(0);" onclick="return loadlogs('.$actid.');" class="btn px-2 py-1 mt-2 mb-2">'.__('Show').'</a>
                        </td>
                    </tr>';
                }

                echo '
                </tbody>
            </table>
        </div>

    </div>';

    }

    echo '
    </div>';
    
    softfooter();
}
