X-Git-Url: https://git.llucax.com/z.facultad/75.43/tp1.git/blobdiff_plain/6554fc774c6458cfb1fa451b260047dbcd7ec282..cca05437f65a5e90c1822e0ed3a2439e3c0d98c8:/src/lib/Info.php?ds=inline
diff --git a/src/lib/Info.php b/src/lib/Info.php
index 4579ed5..d2bbbaa 100644
--- a/src/lib/Info.php
+++ b/src/lib/Info.php
@@ -1,15 +1,14 @@
infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));
+ }
+
+ function saveExisting() {
+ if (($f = fopen($this->infoCSVConst, 'r')) == false) return false; // error
+ $index = 0;
+ $indexSave = 0;
+ while (!feof($f))
+ {
+ $d = fgetcsv($f, 4096);
+ $index++;
+ if ($d[0] == $this->id)
+ {
+ fclose($f);
+ if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error
+ while ($indexSave!=($index-1)) { fgetcsv($f, 4096); $indexSave++; }
+ fputcsv($f, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));
+ fclose($f);
+ return true;
+ }
+ }
+ fclose($f);
+ return false;
+ }
+
+ function saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario ) {
$this->id = $pId;
$this->tema = $pTema;
$this->url = $pURL;
$this->autor = $pAutor;
- $this->comentario = $pComentario;
+ $this->comentario = preg_replace('[\n|\r\n]','
',$pComentario);
$this->ranking = 0;
$this->fecha = time();
$this->texto = '';
+ }
+ function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {
+ $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario );
$resultado = "";
- if (!fappendcsv($this->infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha))) {
+ if (!$this->saveNew()) {
$resultado = "ERROR al agregar la informacion. Revise que los parametros sean los adecuados";
- }
+ file_log_add($pAutor,$resultado);
+ } else {
+ file_log_add($pAutor,"Se agregó la información");
+ }
+ return $resultado;
+ }
+
+ function modificar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {
+ $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario );
+ $resultado = "";
+ if (!$this->saveExisting()) {
+ $resultado = "ERROR al modificar la informacion. Revise que los parametros sean los adecuados";
+ file_log_add($pAutor,$resultado);
+ } else {
+ file_log_add($pAutor,"Se modificó la información");
+ }
return $resultado;
}
@@ -89,32 +132,15 @@ class Info extends Item