4 // Lucarella, Schein, Arena
\r
6 // Creado: Sebastian Arena
\r
9 require_once 'Item.php';
\r
10 require_once 'file.php';
\r
11 require_once 'file.log.php';
\r
13 class Info extends Item
\r
23 var $autor_apellido;
\r
26 var $infoCSVConst = 'data/infos.csv';
\r
29 id | tema | url | autor | comentario | ranking | fecha
\r
32 function Info($param, $loadFromRecord) {
\r
33 if (!$loadFromRecord) {
\r
39 $this->id = $param[0];
\r
40 $this->tema = $param[1];
\r
41 $this->url = $param[2];
\r
42 $this->autor = $param[3];
\r
43 $this->comentario = $param[4];
\r
44 $this->ranking = $param[5];
\r
45 $this->fecha = $param[6];
\r
52 if (is_file($this->infoCSVConst)) {
\r
53 $record_info = fsearchcsv($this->infoCSVConst, $this->id);
\r
55 $this->id = $record_info[0];
\r
56 $this->tema = $record_info[1];
\r
57 $this->url = $record_info[2];
\r
58 $this->autor = $record_info[3];
\r
59 $this->comentario = $record_info[4];
\r
60 $this->ranking = $record_info[5];
\r
61 $this->fecha = $record_info[6];
\r
67 function saveNew() {
\r
68 return fappendcsv($this->infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));
\r
71 function saveExisting() {
\r
72 if (($f = fopen($this->infoCSVConst, 'r')) == false) return false; // error
\r
77 $d = fgetcsv($f, 4096);
\r
79 if ($d[0] == $this->id)
\r
82 if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error
\r
83 while ($indexSave!=($index-1)) { fgetcsv($f, 4096); $indexSave++; }
\r
84 fputcsv($f, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));
\r
93 function saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario ) {
\r
95 $this->tema = $pTema;
\r
97 $this->autor = $pAutor;
\r
98 $this->comentario = preg_replace('[\n|\r\n]','<br/>',$pComentario);
\r
100 $this->fecha = time();
\r
104 function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {
\r
105 $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario );
\r
107 if (!$this->saveNew()) {
\r
108 $resultado = "<strong>ERROR</strong> al agregar la informacion. Revise que los parametros sean los adecuados";
\r
109 file_log_add($pAutor,$resultado);
\r
111 file_log_add($pAutor,"Se agregó la información");
\r
116 function modificar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {
\r
117 $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario );
\r
119 if (!$this->saveExisting()) {
\r
120 $resultado = "<strong>ERROR</strong> al modificar la informacion. Revise que los parametros sean los adecuados";
\r
121 file_log_add($pAutor,$resultado);
\r
123 file_log_add($pAutor,"Se modificó la información");
\r
128 function toHTML() {
\r
130 <td><img src="<?php echo $this->tema_icono;?>" border="0" alt="icono tema"/></td>
\r
131 <td><img src="<?php echo $this->autor_foto;?>" border="0" alt="icono usuario"/></td>
\r
132 <td><a href="<?php echo $this->url;?>" onclick="location.href='<?php echo $_SERVER['PHP_SELF'] ?>/../info.agregarRanking.php?id=<?php echo $this->id;?>';return false;"><?php echo $this->url;?></a></td>
\r
133 <td><?php echo $this->comentario;?></td>
\r
134 <td><?php echo $this->ranking;?></td>
\r
135 <td><a href="info.listarComentarios.php?id=<?php echo $this->id; ?>">Ver Comentarios</a></td>
\r
140 function incrementarRanking() {
\r
141 //file_log_add($_SESSION['user']->getId(),"Se visitó una informacion (" . $this->url . ")");
\r
142 $this->ranking = $this->ranking + 1;
\r
143 return $this->saveExisting();
\r