id = $param;
$this->reload();
}
} else {
$this->id = $param[0];
$this->tema = $param[1];
$this->url = $param[2];
$this->autor = $param[3];
$this->comentario = $param[4];
$this->ranking = $param[5];
$this->fecha = $param[6];
$this->texto = '';
}
}
function reload() {
if (is_file($this->infoCSVConst)) {
$record_info = fsearchcsv($this->infoCSVConst, $this->id);
if ($record_info) {
$this->id = $record_info[0];
$this->tema = $record_info[1];
$this->url = $record_info[2];
$this->autor = $record_info[3];
$this->comentario = $record_info[4];
$this->ranking = $record_info[5];
$this->fecha = $record_info[6];
$this->texto = '';
}
}
}
function saveNew() {
return fappendcsv($this->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 = 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 (!$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;
}
function toHTML() {
?>