<?php setcookie("login", $_COOKIE["login"] , time()+3600, "/", "deim.etse.urv.es", 1 ); ?>
<?php setcookie("sessio", $_COOKIE["sessio"] , time()+3600, "/", "deim.etse.urv.es", 1 ); ?>
<html>
  <head>
    <link rel="stylesheet" href="../estils/hoja.css" type="text/css">
    <title>Cercar personal</title>
  </head>

  <body leftmargin="0" topmargin="0" bgcolor="#8F0000">
    <table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
      <tr>
        <!-- Menú dret -->
        <td align="left" valign="top" width="100" bgcolor="#4F0000">
          <?php include("../menu.inc") ?>
        </td>

        <!-- Capçalera -->
        <td align="left" valign="top" width="100%" class="centered">
        <h2>Departament d'Enginyeria Informàtica i Matemàtiques</h2>
        <img src="images/separador.gif">
        <br><br>
        <div align="left"><blockquote>
        <h2>Administració Personal: Cercar</h2>
        <!-- Començament del cos -->
        <?php
           require("../private/connect.inc");
           require("../private/ident.inc");
           ident();
           autoritzar($_COOKIE["login"], "personal");
        ?>
        <?php 
              include("../private/func-personal.inc");
              $link=Conectar();
              if (!strcmp($_POST["type"], "nom")) {
                $nom=addslashes($_POST["nom"]);
                $result=mysql_query("SELECT id,nom,despatx,area FROM personal WHERE nom LIKE 
                '%$nom%' ORDER BY nom", $link);
              } elseif (!strcmp($_POST["type"], "despatx")) {
                $despatx=addslashes($_POST["despatx"]);
                $result=mysql_query("SELECT id,nom,despatx,area FROM personal WHERE despatx
                LIKE '%$despatx%' ORDER BY nom", $link);
              } elseif (!strcmp($_POST["type"], "telf")) {
                $telf=addslashes($_POST["telf"]);
                $result=mysql_query("SELECT id,nom,despatx,area FROM personal WHERE
                telf=$telf ORDER BY nom", $link);
              } elseif (!strcmp($_POST["type"], "email")) {
                $email=addslashes($_POST["email"]);
                $result=mysql_query("SELECT id,nom,despatx,area FROM personal WHERE email
                LIKE '%$email%' ORDER BY nom", $link);
              } elseif (!strcmp($_POST["type"], "web")) {
                $web=addslashes($_POST["web"]);
                $result=mysql_query("SELECT id,nom,despatx,area FROM personal WHERE web LIKE
                '%$web%' ORDER BY nom", $link);
              } elseif (!strcmp($_POST["type"], "area")) {
                $area=aid(addslashes($_POST["area"]));
                $link=Conectar();
                $result=mysql_query("SELECT id,nom,despatx,area FROM personal WHERE area = $area ORDER BY nom", $link);
              } elseif (!strcmp($_POST["type"], "extra")) {
                // MySQL no soporta consultas anidadas, asi que tenemos que dividirla
                if (!strcmp($_POST["extra"], "Professor Associat")) {
                  $tabla="profes_associats";
                } elseif (!strcmp($_POST["extra"], "Becari")) {
                  $tabla="becaris";
                }
                $result=mysql_query("SELECT * FROM $tabla");
                while($row = mysql_fetch_array($result)){
                  if ($profes == ""){
                    $profes=$row["id"];
                  }else{
                    $profes=$profes . "," . $row["id"];
                  }
                }
                mysql_free_result($result);
                $result=mysql_query("SELECT id,nom,despatx,area FROM personal WHERE
                 id IN ($profes)");
              }
              echo("<table border=\"0\" width=\"90%\" align=\"left\">");
              echo("<tr bgcolor=black><td><b>Nom</b></td><td><b>Despatx</b></td>
              </td><td><b>Area</b></td></tr>");
              while($row = mysql_fetch_array($result)){
                $id = $row["id"];
                echo("<tr><td align=\"left\"> <div align=\"left\">" . $row["nom"] . "</td>" );
                printf("<td>%s</td>", $row["despatx"]);
                printf("<td>%s</td>", area($row["area"]));
                echo("<td><form action=\"modificar-reg.php\" method=\"post\"><input
                      type=\"hidden\" name=\"id\" value=\"$id\">");
                echo("<input type=\"image\" src=\"images/modificar.jpg\" border=\"0\"></form></td>");
                echo("<td><form action=\"esborrar-reg.php\" method=\"post\"><input
                       type=\"hidden\" name=\"id\" value=\"$id\">");
                echo("<input type=\"image\" src=\"images/esborrar.jpg\" border=\"0\"></form></td></tr>");
              }
              mysql_free_result($result);
        ?>
        <td colspan="5"><br><input type="image" onClick="history.go(-1)"
        src="images/tornar.jpg"></td>
        </table>
        </blockquote></div>
        </td>
      </tr>
    </table>
  </body>
</html>

