]> git.llucax.com Git - z.facultad/75.43/tp1.git/commitdiff
(no commit message)
authorSebastian Arena <seba.arena@gmail.com>
Sun, 8 May 2005 13:30:29 +0000 (13:30 +0000)
committerSebastian Arena <seba.arena@gmail.com>
Sun, 8 May 2005 13:30:29 +0000 (13:30 +0000)
src/lib/Info.php [new file with mode: 0644]
src/lib/Link.php [deleted file]
src/lib/Tema.php [new file with mode: 0644]
src/lib/info.forms.php [new file with mode: 0644]
src/lib/info.functions.php [new file with mode: 0644]
src/lib/pagina.php

diff --git a/src/lib/Info.php b/src/lib/Info.php
new file mode 100644 (file)
index 0000000..4579ed5
--- /dev/null
@@ -0,0 +1,120 @@
+<?php\r
+// vim: set binary noeol et sw=4 sts=4 :\r
+// Grupo 10\r
+//\r
+// Lucarella, Schein, Arena\r
+//\r
+// Creado: Leandro Lucarella (sáb abr 30 20:21:30 ART 2005)\r
+//\r
+// $Id: Link.php 9 2005-04-30 23:51:21Z llucare $\r
+\r
+require_once 'Item.php';\r
+require_once 'file.php';\r
+\r
+class Info extends Item\r
+{\r
+       var $id;\r
+    var $url;\r
+       var $tema;\r
+       var $comentario;\r
+    var $ranking;\r
+\r
+       /*Extra Data*/\r
+       var $autor_foto;\r
+       var $autor_apellido;\r
+       var $tema_icono;\r
+\r
+       var $infoCSVConst = 'data/infos.csv';\r
+    /* \r
+               Formato en Disco:\r
+                       id | tema | url | autor | comentario | ranking | fecha\r
+       */\r
+\r
+       function Info($param, $loadFromRecord) {\r
+               if (!$loadFromRecord) {\r
+            if ($param) {\r
+                               $this->id = $param;\r
+                               $this->reload();\r
+                       }\r
+               } else {\r
+                       $this->id                       = $param[0];\r
+                       $this->tema                     = $param[1];\r
+                       $this->url                      = $param[2];\r
+            $this->autor               = $param[3];\r
+                       $this->comentario       = $param[4];\r
+            $this->ranking     = $param[5];\r
+                       $this->fecha            = $param[6];\r
+                       $this->texto            = '';\r
+                       \r
+               }\r
+    }\r
+\r
+       function reload() {\r
+               if (is_file($this->infoCSVConst)) {\r
+                       $record_info = fsearchcsv($this->infoCSVConst, $this->id);\r
+            if ($record_info) {\r
+                               $this->id                       = $record_info[0];\r
+                               $this->tema                     = $record_info[1];\r
+                               $this->url                      = $record_info[2];\r
+                               $this->autor            = $record_info[3];\r
+                               $this->comentario       = $record_info[4];\r
+                               $this->ranking          = $record_info[5];\r
+                               $this->fecha            = $record_info[6];\r
+                               $this->texto            = '';\r
+                       }\r
+               }\r
+       }\r
+\r
+    function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
+               $this->id                       = $pId;\r
+               $this->tema                     = $pTema;\r
+               $this->url                      = $pURL;\r
+               $this->autor            = $pAutor;\r
+               $this->comentario       = $pComentario;\r
+               $this->ranking          = 0;\r
+               $this->fecha            = time();\r
+               $this->texto            = '';\r
+\r
+               $resultado = "";\r
+        if (!fappendcsv($this->infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha))) {\r
+                       $resultado = "<strong>ERROR</strong> al agregar la informacion. Revise que los parametros sean los adecuados";\r
+        }\r
+               return $resultado;\r
+       }\r
+\r
+       function toHTML() {\r
+        ?><tr>\r
+                       <td><img src="<?php echo $this->tema_icono;?>" border="0" alt="icono tema"/></td>\r
+                       <td><img src="<?php echo $this->autor_foto;?>" border="0" alt="icono usuario"/></td>\r
+            <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
+                       <td><?php echo $this->comentario;?></td>\r
+                       <td><?php echo $this->ranking;?></td>\r
+                 </tr>\r
+               <?php\r
+       }\r
+\r
+       function incrementarRanking() {\r
+               $this->ranking = $this->ranking + 1;\r
+               if (($f = fopen($this->infoCSVConst, 'r')) == false) return false; // error\r
+               $index = 0;\r
+               $indexSave = 0;\r
+        while (!feof($f))\r
+               {\r
+                       $d = fgetcsv($f, 4096);\r
+                       $index++;\r
+                       if ($d[0] == $this->id)\r
+                       {\r
+                               $d[5] = $this->ranking;\r
+                               fclose($f);\r
+                               if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error\r
+                               while ($indexSave!=($index-1)) { fgetcsv($f, 4096); $indexSave++; }\r
+                fputcsv($f, $d);\r
+                               fclose($f);\r
+                               return true;\r
+                       }\r
+               }\r
+               fclose($f);\r
+               return false;\r
+       }\r
+}\r
+?>\r
diff --git a/src/lib/Link.php b/src/lib/Link.php
deleted file mode 100644 (file)
index 5abef6c..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-// vim: set binary noeol et sw=4 sts=4 :
-// Grupo 10
-//
-// Lucarella, Schein, Arena
-//
-// Creado: Leandro Lucarella (sáb abr 30 20:21:30 ART 2005)
-//
-// $Id$
-
-require_once 'Item.php';
-
-/**
- * XXX detailed description
- *
- * @author    XXX
- * @copyright XXX
- */
-class Link extends Item
-{
-    // Attributes
-   /**
-    *    XXX
-    *    @access public
-    */
-    var $url;
-
-   /**
-    *    XXX
-    *    @access public
-    */
-    var $accesos;
-
-   /**
-    *    XXX
-    *    @access public
-    */
-    var $comentarios;
-
-    // Operations
-}
-
-?>
\ No newline at end of file
diff --git a/src/lib/Tema.php b/src/lib/Tema.php
new file mode 100644 (file)
index 0000000..0129489
--- /dev/null
@@ -0,0 +1,88 @@
+<?php\r
+// Grupo 10\r
+//\r
+// Lucarella, Schein, Arena\r
+//\r
+// Creado: Sebastian Arena\r
+//\r
+\r
+require_once 'Item.php';\r
+require_once 'lib/file.php';\r
+require_once 'Usuario.php';\r
+\r
+class Tema extends Item\r
+{\r
+       var $id;\r
+       var $icono;\r
+       var $nombre;\r
+\r
+       var $temasCSVConst = 'data/temas.csv';\r
+    /* \r
+               Formato en Disco:\r
+                       id | autor | nombre | icono | descripcion | fecha\r
+       */\r
+\r
+       function Tema($param, $loadFromRecord) {\r
+               if (!$loadFromRecord) {\r
+                       if ($param) {\r
+                               $this->id = $param;\r
+                               $this->reload();\r
+                       }\r
+               } else {\r
+                       $this->id               = $param[0];\r
+                       $this->autor    = $param[1];\r
+                       $this->nombre   = $param[2];\r
+                       $this->icono    = $param[3];\r
+                       $this->texto    = $param[4];\r
+                       $this->fecha    = $param[5];\r
+               }\r
+    }\r
+\r
+       function reload() {\r
+               if (is_file($this->temasCSVConst)) {\r
+                       $record_tema = fsearchcsv($this->temasCSVConst, $this->id);\r
+                       if ($record_tema) {\r
+                               $this->id               = $record_tema[0];\r
+                               $this->autor    = $record_tema[1];\r
+                               $this->nombre   = $record_tema[2];\r
+                               $this->icono    = $record_tema[3];\r
+                               $this->texto    = $record_tema[4];\r
+                               $this->fecha    = $record_tema[5];\r
+                       }\r
+               }\r
+       }\r
+\r
+    function ingresar( $pId, $pNombre, $pAutor, $pDescripcion, $pIcono ) {\r
+               $this->id               = $pId;\r
+               $this->autor    = $pAutor;\r
+               $this->nombre   = $pNombre;\r
+               $this->icono    = 'temas/' . $pId;\r
+               $this->texto    = $pDescripcion;\r
+               $this->fecha    = time();\r
+\r
+               $resultado = "";\r
+        //Se obtiene el ID mas alto actual\r
+               if (!fappendcsv($this->temasCSVConst, array($this->id, $this->autor, $this->nombre, $this->icono, $this->texto, $this->fecha))) {\r
+                       $resultado = "<strong>ERROR</strong> al agregar el Tema '" . $pNombre . "'. Revise que los parametros sean los adecuados";\r
+               } else {\r
+            if (!copy($pIcono, "temas/" . $pId)) {\r
+                               $resultado = "No se pudo copiar la foto.";\r
+                       }\r
+               }\r
+               return $resultado;\r
+       }\r
+\r
+       function toHTML() {\r
+               $objUser = new Usuario($this->autor);\r
+               ?><tr>\r
+            <td><?php echo $this->id;?></td>\r
+                       <td><img src="<?php echo $this->icono;?>" border="0" alt="icono tema <?php echo $this->id;?>"/></td>\r
+                       <td><?php echo $this->nombre;?></td>\r
+            <td><?php echo $this->texto;?></td>\r
+                       <td><img src="<?php echo $objUser->getFotoFilename();?>" border="0" alt="icono usuario <?php echo $objUser->getId();?>"/></td>\r
+                       <td><?php echo $objUser->getApellido() . ", " . $objUser->getNombre() . " (". $objUser->getId() . ")";?></td>\r
+                 </tr>\r
+               <?php\r
+       }\r
+}\r
+?>\r
diff --git a/src/lib/info.forms.php b/src/lib/info.forms.php
new file mode 100644 (file)
index 0000000..8af0c93
--- /dev/null
@@ -0,0 +1,92 @@
+<?php\r
+// Grupo 10\r
+//\r
+// Lucarella, Schein, Arena\r
+//\r
+// Creado: Sebastian Arena 01/05/2005\r
+//\r
+require_once 'lib/info.functions.php';\r
+require_once 'Tema.php';\r
+\r
+function info_form_ingresar_tema( $nombre, $icono, $descripcion ) {\r
+?>\r
+       <form name="info_ingresar_tema" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" onSubmit="return info_validar_ingresar_tema(this);" enctype="multipart/form-data">\r
+            <script type="text/javascript" language="JavaScript">\r
+                <!--\r
+                function info_validar_ingresar_tema(f)\r
+                {\r
+                    if (!check_vacio(f.txtNombre, 'Nombre')) return false;\r
+                                       if (!check_vacio(f.txtIcono, 'Icono')) return false;\r
+                                       if (!check_vacio(f.txtDescripcion, 'Descripcion')) return false;\r
+                    return true;\r
+                }\r
+                -->\r
+            </script>\r
+                       <table>\r
+                               <tr>\r
+                                       <td>Tema:</td>\r
+                                       <td><input type="text" name="txtNombre" value="<?php echo $nombre ?>"/></td>\r
+                               </tr>\r
+                               <tr>\r
+                                       <td>Icono:</td>\r
+                                       <td><input type="file" name="txtIcono" value="<?php echo $icono ?>" accept="image/png;image/jpeg;image/gif"/></td>\r
+                               </tr>\r
+                               <tr>\r
+                                       <td>Descripción:</td>\r
+                                       <td><textarea name="txtDescripcion" rows="3" cols="50"><?php echo $descripcion ?></textarea></td>\r
+                               </tr>\r
+                               <tr>\r
+                    <td colspan="2"><input type="submit" name="btnSubmit" value="Guardar"/></td>\r
+                               </tr>\r
+                       </table>\r
+       </form>\r
+<?php\r
+}\r
+\r
+\r
+\r
+function info_form_ingresar_info( $tema, $url, $comentario ) {\r
+?>\r
+       <form name="info_ingresar_info" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" onSubmit="return info_validar_ingresar_info(this);">\r
+            <script type="text/javascript" language="JavaScript">\r
+                <!--\r
+                function info_validar_ingresar_info(f)\r
+                {\r
+                                       if (!check_vacio(f.txtTema, 'Tema')) return false;\r
+                    if (!check_vacio(f.txtURL, 'URL')) return false;\r
+                    if (!check_vacio(f.txtComentario, 'Comentario')) return false;\r
+                    return true;\r
+                }\r
+                -->\r
+            </script>\r
+                       <table>\r
+                               <tr>\r
+                                       <td>Tema:</td>\r
+                                       <td>\r
+                                               <select name="txtTema">\r
+                                                       <option value="">Seleccione un Tema...</option>\r
+                                               <?php\r
+                                                       $arrTemas = info_obtener_temas();\r
+                                                       foreach( $arrTemas as $objTema ) {\r
+                                                       ?><option value="<?php echo $objTema->id; ?>"<?php if ($tema == $objTema->id) { echo " selected"; } ?>><? echo $objTema->nombre; ?></option><?php\r
+                                                       }\r
+                                               ?>\r
+                                               </select>\r
+                                       </td>\r
+                               </tr>\r
+                               <tr>\r
+                                       <td>URL:</td>\r
+                                       <td><input type="text" name="txtURL" value="<?php echo $url ?>"/></td>\r
+                               </tr>\r
+                               <tr>\r
+                                       <td>Comentario:</td>\r
+                                       <td><textarea name="txtComentario" rows="3" cols="50"><?php echo $comentario ?></textarea></td>\r
+                               </tr>\r
+                               <tr>\r
+                    <td colspan="2"><input type="submit" name="btnSubmit" value="Guardar"/></td>\r
+                               </tr>\r
+                       </table>\r
+       </form>\r
+<?php\r
+}\r
+?>\r
diff --git a/src/lib/info.functions.php b/src/lib/info.functions.php
new file mode 100644 (file)
index 0000000..fa9aaba
--- /dev/null
@@ -0,0 +1,156 @@
+<?php\r
+require_once 'pagina.php';\r
+require_once 'file.php';\r
+require_once 'Tema.php';\r
+require_once 'Info.php';\r
+require_once 'Usuario.php';\r
+\r
+/************** Funciones para Temas ***************/\r
+function info_obtener_temas() {\r
+    $arr = array();\r
+       $temasCSVConst = 'data/temas.csv';\r
+\r
+       if (is_file($temasCSVConst)) {\r
+               $arrFile = fgetallcsv($temasCSVConst);\r
+        if ($arrFile) {\r
+            foreach ( $arrFile as $record_tema) {\r
+                               $objTema = new Tema($record_tema,1);\r
+                               $arr[] = $objTema;\r
+                       }\r
+               }\r
+       }\r
+       return $arr;\r
+}\r
+\r
+function info_obtener_mayor_id() {\r
+       $arrTemas = info_obtener_temas();\r
+       $cantidad_temas = count($arrTemas);\r
+\r
+       $maxId = 0;\r
+       if ($cantidad_temas != 0) {\r
+               $objTema        = $arrTemas[$cantidad_temas - 1];\r
+               $maxId          = $objTema->id;\r
+       }\r
+       return $maxId;\r
+}\r
+\r
+function info_ingresar_tema( $pNombre, $pAutor, $pDescripcion, $pIcono ) {\r
+       $objTema = new Tema(0,0);\r
+       $pId = info_obtener_mayor_id() + 1;\r
+\r
+    $resultado = $objTema->ingresar( $pId, $pNombre, $pAutor, $pDescripcion, $pIcono );\r
+    if ( $resultado == "" ) {\r
+               echo ok("Se agregó el Tema '" . $pNombre . "'");\r
+               return true;\r
+       } else {\r
+               echo warn($resultado);\r
+               return false;\r
+       }\r
+}\r
+\r
+function info_listar_temas () {\r
+       $arrTemas = info_obtener_temas();\r
+       foreach ( $arrTemas as $objTema) {\r
+               $objTema->toHTML();\r
+       }\r
+}\r
+/************** Fin Funciones para Temas ***************/\r
+\r
+\r
+\r
+\r
+/************** Funciones para Infos ***************/\r
+function info_obtener_infos($loadPrintData,$simpleSort) {\r
+    $arr = array();\r
+       $infosCSVConst = 'data/infos.csv';\r
+\r
+       if (is_file($infosCSVConst)) {\r
+               $arrFile = fgetallcsv($infosCSVConst);\r
+        if ($arrFile) {\r
+            foreach ( $arrFile as $record_info) {\r
+                               $objInfo = new Info($record_info,1);\r
+                               if ($loadPrintData) {\r
+                                       $objUsuario = new Usuario($objInfo->autor);\r
+                                       $objTema = new Tema($objInfo->tema,0);\r
+                                       /* Cargo la foto del usuario */\r
+                                       $objInfo->autor_foto = $objUsuario->getFotoFilename();\r
+                                       $objInfo->autor_apellido = $objUsuario->getApellido();\r
+                                       /* Cargo el icono del Tema */\r
+                                       $objInfo->tema_icono = $objTema->icono;\r
+                               }\r
+                               if ($simpleSort == -1 ) {\r
+                                       $arr[] = $objInfo;\r
+                               } else {\r
+                                       if ($simpleSort == 1) {\r
+                                               $arr[] = array($objInfo->ranking,$objInfo);\r
+                                       } else {\r
+                                               $arr[] = array($objInfo->tema * 1, $objInfo->ranking * -1,$objInfo);\r
+                                       }\r
+                               }\r
+                               \r
+                       }\r
+               }\r
+       }\r
+       if ($simpleSort != -1) {\r
+        rsort($arr);\r
+       }\r
+       return $arr;\r
+}\r
+\r
+function info_obtener_mayor_id_info() {\r
+       $arrInfos = info_obtener_infos(false, -1);\r
+       $cantidad_infos = count($arrInfos);\r
+\r
+       $maxId = 0;\r
+       if ($cantidad_infos != 0) {\r
+               $objInfo        = $arrInfos[$cantidad_infos - 1];\r
+               $maxId          = $objInfo->id;\r
+       }\r
+       return $maxId;\r
+}\r
+\r
+function info_ingresar_info( $pTema, $pURL, $pAutor, $pComentario ) {\r
+       $objInfo = new Info(0,0);\r
+    $pId = info_obtener_mayor_id_info() + 1;\r
+\r
+       $resultado = $objInfo->ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario );\r
+    if ( $resultado == "" ) {\r
+               echo ok("Se agregó la informacion.");\r
+               return true;\r
+       } else {\r
+               echo warn($resultado);\r
+               return false;\r
+       }\r
+}\r
+\r
+function info_listar_infos ($simpleSort = 1) {\r
+       if ($simpleSort) {\r
+               $arrInfos = info_obtener_infos(true,$simpleSort);\r
+               echo '<tr><td>Tema</td><td>Autor</td><td>URL</td><td>Descripcion</td><td>Ranking</td></tr>';\r
+               foreach ( $arrInfos as $objInfo ) {\r
+                       $objInfo[1]->toHTML();\r
+               }\r
+       } else {\r
+        $mtxInfos = info_obtener_infos(true,$simpleSort);\r
+               $oldTema = 0;\r
+               $newTema = 0;\r
+               $max = count($mtxInfos);\r
+               $index = $max - 1;\r
+        while ($index >= 0) {\r
+                       $arrInfos = $mtxInfos[$index];\r
+            $objTema = new Tema($arrInfos[0],0);\r
+                       $newTema = $objTema->id;\r
+                       if ($oldTema != $newTema ) {\r
+                               if ($oldTema) {\r
+                                       echo '<tr><td colspan="5">&nbsp;</td></tr>';\r
+                               }\r
+                               $oldTema = $newTema;\r
+                               echo '<tr><td colspan="5">"' . $objTema->nombre . '"</td></tr>';\r
+                               echo '<tr><td>Tema</td><td>Autor</td><td>URL</td><td>Descripcion</td><td>Ranking</td></tr>';\r
+                       }\r
+            $arrInfos[2]->toHTML();\r
+                       $index--;\r
+               }\r
+       }\r
+}\r
+?>\r
index 883aa6380bf681469887add06de43a6529749679..f96ce078c056c4cffc3f96033f51d9d45e691a62 100644 (file)
@@ -40,7 +40,7 @@ function pagina_cabecera($titulo = '')
         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
     </head>
     <body>
-        <h1><img src="img/logo.png" alt="Logo" /></h1>
+        <h1>Grupos</h1>
         <?php if ($titulo) echo "<h2>$titulo</h2>\n" ?>
 <?php
 }
@@ -85,11 +85,17 @@ function menu_cabecera($titulo = '')
                         <li><a href="faq.ingresarPregunta.php">Ingresar Pregunta</a></li>
                     </ul>
                 </li>
-                <li>
-                    <h3>Sitios</h3>
+                               <li>
+                    <h3>Info</h3>
                     <ul>
-                        <li><a href="">Algo</a></li>
-                        <li><a href="">Otro</a></li>
+                                               <?php if ($_SESSION['user']->esAdmin()) { ?>
+                                                       <li><a href="info.ingresarTemas.php">Ingresar Tema</a></li>     
+                                               <?php } ?>
+                                               <?php if (!($_SESSION['user']->esAdmin())) { ?>
+                        <li><a href="info.ingresarInfo.php">Ingresar Info</a></li>
+                                               <?php } ?>
+                                               <li><a href="info.listarTemas.php">Listar Temas</a></li>
+                                               <li><a href="info.listarInfo.php">Listar Informacion</a></li>
                     </ul>
                 </li>
                 <?php if ($_SESSION['user']->esAdmin()) { ?>