X-Git-Url: https://git.llucax.com/z.facultad/75.43/tp1.git/blobdiff_plain/748dad7dcb2fea29ca8b4b021f93fe0f9373e793..7c33ae00002edd46b787d6b44de3a787b4c92f6b:/src/lib/file.creditos.php diff --git a/src/lib/file.creditos.php b/src/lib/file.creditos.php index 3b4db65..a178911 100644 --- a/src/lib/file.creditos.php +++ b/src/lib/file.creditos.php @@ -66,10 +66,12 @@ function file_creditos_evaluar($user, $es_bonus = false, $bonus_cant = 5) */ function file_creditos_get($user) { - if (($f = fopen("data/$user.creditos.csv", 'r')) === false) return false; + if (($f = fopen("data/creditos.$user.csv", 'r')) === false) return false; $seek = intval(trim(fgets($f, 11))); fseek($f, $seek); - return fgetcsv($f, 4096); + $row = fgetcsv($f, 4096); + fclose($f); + return $row; } /** @@ -77,12 +79,25 @@ function file_creditos_get($user) */ function file_creditos_write($user, $creditos, $bonus, $dias) { - if (($f = fopen("data/$user.creditos.csv", 'a+')) === false) return false; + if (($f = fopen("data/creditos.$user.csv", 'a+')) === false) return false; $seek = ftell($f); $fecha = time(); fputcsv($f, array($fecha, $creditos, $bonus, $dias)); fseek($f, 0); fwrite($f, sprintf("%010d\n", $seek), 11); + fclose($f); + return true; +} + +/** + * Crea el archivo de créditos para el usuario. + */ +function file_creditos_crear($user) +{ + if (($f = fopen("data/creditos.$user.csv", 'w')) === false) return false; + fwrite($f, sprintf("%010d\n", 11), 11); + fputcsv($f, array(time(), 1, 0, 0)); + fclose($f); return true; }