<?php

error_reporting(0);

$filename = 'c_leitura.php';
session_start();
if (!file_exists($filename)) {
    header("Location: error.php");
    exit;
}
include 'c_leitura.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . "sealed" . DIRECTORY_SEPARATOR . "autoload.php";
include ('db.php');

$versao = $_POST['versao'];
$changelog = $_POST['changelog'];
$NEWLINE_RE = '/(\r\n)|\r|\n/';

$fileAPK = array_map('basename', glob(UPDATE . "*.{apk}", GLOB_BRACE))[0];
if ($fileAPK) {
    $changelog = preg_replace($NEWLINE_RE,',', $changelog);
    $file_data = $fileAPK . ":" . $versao . ":" . date('d-m-Y') . ':' . $changelog;
}
file_put_contents(UPDATE . 'changelog.txt', PHP_EOL . $file_data, FILE_APPEND);

echo json_encode(array('success' => 1, 'msg' => 'Versão APK atualizada com sucesso!'));exit;


