X-Git-Url: https://git.llucax.com/z.facultad/75.43/tp1.git/blobdiff_plain/748dad7dcb2fea29ca8b4b021f93fe0f9373e793..acccc4f0814d1d5eb98c2fb184b97ffc6664421f:/src/lib/file.creditos.php?ds=inline diff --git a/src/lib/file.creditos.php b/src/lib/file.creditos.php index 3b4db65..9101eab 100644 --- a/src/lib/file.creditos.php +++ b/src/lib/file.creditos.php @@ -69,7 +69,9 @@ function file_creditos_get($user) if (($f = fopen("data/$user.creditos.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; } /** @@ -83,6 +85,19 @@ function file_creditos_write($user, $creditos, $bonus, $dias) 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/$user.creditos.csv", 'w')) === false) return false; + fwrite($f, sprintf("%010d\n", 11), 11); + fputcsv($f, array(time(), 1, 0, 0)); + fclose($f); return true; }