LogCambios.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * Objeto para escribir los cambios
  4. */
  5. class LogCambios {
  6. //put your code here
  7. private $file, $month, $year;
  8. private $dir;
  9. function __construct($ruta = "/log/"){
  10. $this->month = date("m");
  11. $this->year = date("Y");
  12. //$this->dir = $_SERVER['DOCUMENT_ROOT'].$ruta;
  13. $this->dir = $ruta;
  14. $this->updateFilename();
  15. }
  16. function setMes($mes){
  17. $this->month = $mes;
  18. $this->updateFilename();
  19. }
  20. function setAno($ano){
  21. $this->year = $ano;
  22. $this->updateFilename();
  23. }
  24. private function updateFilename(){
  25. $this->file = "cambios_".$this->year."_".$this->month.".log";
  26. }
  27. private function cleanLog($text){//remueve || de los textos para no afectar estructura
  28. return trim(str_ireplace( "||" , "" , $text));
  29. }
  30. function appendLog($desc){
  31. $filename = $this->dir.$this->file;
  32. /*
  33. if (file_exists($this->dir)){
  34. $data = date('Y-m-d H:i:s')."||".$this->cleanLog($desc)."\n";
  35. //echo $filename;
  36. $res = file_put_contents($filename, $data, FILE_APPEND);
  37. //echo " result: $res<br>";
  38. }*/
  39. }
  40. /*
  41. function getLog($mes ="", $ano = ""){
  42. if($mes != "") $this->setMes($mes);
  43. if($ano != "") $this->setAno($ano);
  44. $filename = $this->dir.$this->file;
  45. if (file_exists($filename)){
  46. return file ($filename , FILE_SKIP_EMPTY_LINES);
  47. }else{
  48. return array();
  49. }
  50. }*/
  51. }