public static function draw($only_records = false)
    {
        self::saveExternalZip();
        $history = self::get_history();
        $state = Sns_State::get_status();
        $disabled = $only_records && $state['status'] == Sns_State::STATUS_ACTIVE ? ' disabled="disabled" ' : '';
        if (!$only_records) {
            ?>
            <span class="menu-title">Your Backup History</span>
            <div class="menu-content">
                <div class="external-restore">
                    <input type="text" placeholder="Browse a backup file to restore from." class="form-control external-backup-input">
                    <div id="external-container">
                        <button id="external-browse" type="button" class="btn btn-default sns-action">Browse</button>
                        <button id="external-restore" type="button" class="btn btn-primary sns-action">Restore</button>
                    </div>
                </div>

                <div class="separator"></div>
                <div id="progressbar-restore"><div class="progress-label"></div></div>
<?php 
        }
        ?>
            <div class="records">
                <table class="table">
                    <?php 
        if (empty($history)) {
            echo 'Your history is empty';
        } else {
            ?>
                            <thead>
                                <th class="h-date">Backup date</th>
                                <th>Information</th>
                                <th class="h-actions">Actions</th>
                            </thead>
                            <tbody>
                    <?php 
            foreach ($history as $item) {
                ?>
                             <tr>
                                 <td><?php 
                echo date('M d, Y H:i', strtotime($item->backup_date));
                ?>
</td>
                                 <td>
                                     <?php 
                $info = json_decode($item->info, true);
                echo '<b>options:</b> ' . implode(', ', $info['options']) . '<br/>';
                echo '<b>destinations:</b> local' . (empty($info['destinations']) ? '' : ',') . implode(', ', $info['destinations']) . '<br/>';
                ?>
                                 </td>
                                 <td>
                                     <button type="button" class="btn btn-primary btn-restore sns-action" <?php 
                echo $disabled;
                ?>
 data-backup_id="<?php 
                echo $item->id;
                ?>
">Restore</button>
                                     <a href="<?php 
                echo SNS_BACKUPS_URL . $item->filename . '.zip';
                ?>
"><button type="button" class="btn btn-default btn-download sns-action" <?php 
                echo $disabled;
                ?>
 data-backup_id="<?php 
                echo $item->id;
                ?>
">Download</button></a>
                                     <button type="button" class="btn btn-danger btn-delete sns-action" <?php 
                echo $disabled;
                ?>
 data-backup_id="<?php 
                echo $item->id;
                ?>
"><span class="glyphicon glyphicon-remove"></span></button>
                                 </td>
                             </tr>
                    <?php 
            }
            ?>
                            </tbody>
                    <?php 
        }
        ?>
                </table>
            </div>
            <?php 
        if (!$only_records) {
            ?>
            </div>
        <?php 
        }
    }
function sns_backup_action()
{
    $proc = Sns_State::get_status();
    $scheduleState = Sns_State::get_status(Sns_Backup::BACKUP_MODE_SCHEDULE);
    if ($proc['status'] != Sns_State::STATUS_ACTIVE && empty($scheduleState)) {
        $backup = new Sns_Backup('schedule');
        $data = array('status' => Sns_State::STATUS_ACTIVE);
        Sns_State::update($data);
        try {
            $backup->backup();
        } catch (Exception $e) {
            Sns_Log::log_exception_obj($e);
        }
        $data = array('status' => Sns_State::STATUS_FINISHED);
        Sns_State::update($data);
    }
}
function sns_backup_state_get_status()
{
    $result = new stdClass();
    $result->status = 'OK';
    $data = Sns_State::get_status();
    if ($data['status'] == Sns_State::STATUS_ACTIVE) {
        $temp = (time() - strtotime($data['start_date'])) * 1000 * (SNS_PROCESS_STEP_COUNT / SNS_PROCESS_DURATION);
        $progress = round($temp * (100 / SNS_PROCESS_STEP_COUNT), 1);
        $data['progress'] = $progress >= 99 ? 99 : $progress;
        $data['progress_view'] = $data['progress'] . '%';
    }
    $result->data = $data;
    $result->response_time = time();
    sns_send_response($result);
}