 <?php require("../fpdf/fpdf.php");
       require("../private/connect.inc");
       require("../private/text.inc");
       require ("../private/func-personal.inc");
       $link=Conectar();
       if ($_GET["order"]==1) {
         $result=mysql_query("SELECT * FROM personal ORDER BY area,nom", $link);
       } else {
         $result=mysql_query("SELECT * FROM personal ORDER BY nom", $link);
       }
       $pdf= new FPDF('P', 'mm', 'A4');
       $pdf->Open();
       $pdf->AddPage();
       $pdf->Image('images/logodeim.jpg',60,16,80);
       $pdf->SetFont('Arial', 'B', 16);
       //$pdf->Ln(30);
       if ($_GET["order"]==1) {
         $pdf->MultiCell(0,5,'Llistat del personal ordenat per area', 0, 'C');
         while($row = mysql_fetch_array($result)){
           if ($area !=  $row["area"]) {
             $pdf->Ln(8);
             $area = $row["area"];
             $pdf->SetX(15);
             $pdf->SetFont('Arial', 'B', 12);
             $pdf->Write(60, ' AREA: ' . area($row["area"]));
             $pdf->Ln(10);
             $pdf->SetFont('Arial', 'B', 10);
             $pdf->SetX(15);
             $pdf->Write(60, ' NOM ');
             $pdf->SetX(80);
             $pdf->Write(60, ' TELEFON ');
             $pdf->SetX(115);
             $pdf->Write(60, ' DESPATX ');
             $pdf->SetX(143);
             $pdf->Write(60, ' EMAIL ');
             $pdf->Ln(8);
             $pdf->SetFont('Arial', '', 10);
          }
          $pdf->SetX(15);
          $pdf->Write(60, ' ' . $row["nom"]);
          $pdf->SetX(80);
          if ($row["telf"] != 0) {
            $pdf->Write(60, ' ' . $row["telf"]);
          }
          $pdf->SetX(115);
          $pdf->Write(60, ' ' . $row["despatx"]);
          $pdf->SetX(143);
          $pdf->Write(60, ' ' . $row["email"]);
          $pdf->Ln(5);
        }
       } else {
         $pdf->MultiCell(0,5,'Llistat del personal ordenat per cognoms', 0, 'C');
         $pdf->SetFont('Arial', 'B', 10);
         $pdf->SetX(15);
         $pdf->Write(60, ' NOM ');
         $pdf->SetX(80);
         $pdf->Write(60, ' TELEFON ');
         $pdf->SetX(115);
         $pdf->Write(60, ' DESPATX ');
         $pdf->SetX(143);
         $pdf->Write(60, ' EMAIL ');
         $pdf->Ln(8);
         $pdf->SetFont('Arial', '', 10);
         while($row = mysql_fetch_array($result)){
           $pdf->SetX(15);
           $pdf->Write(60, ' ' . $row["nom"]);
           $pdf->SetX(80);
           if ($row["telf"] != 0) {
             $pdf->Write(60, ' ' . $row["telf"]);
           }
           $pdf->SetX(115);
           $pdf->Write(60, ' ' . $row["despatx"]);
           $pdf->SetX(143);
           $pdf->Write(60, ' ' . $row["email"]);
           $pdf->Ln(5);
         }
       }
       mysql_free_result($result);

       /*$pdf->SetFont('Arial', 'B', 14);
       $pdf->MultiCell(0,5,'' . $row["encarregat"], 0, 'C');
       $pdf->Ln(3);
       $pdf->MultiCell(0,5,'' . $row["institucio"], 0, 'C');
       $pdf->Ln(3);
       $pdf->MultiCell(0,5,'' . $row["departament"], 0, 'C');
       $pdf->Ln(15);
       
       
       $pdf->SetFont('Arial', 'B', 12);
       $pdf->MultiCell(0,5,'Resum:');
       $pdf->SetFont('Times', '', 12);
       // Hem de treure format html i ficar-ho en format normal (espais
       // en blanc i newlines)
       $pdf->MultiCell(0,5,'' . unformat_all($row["resum"]));
       
       

       $pdf->Ln(20);
       $pdf->SetFont('Arial', 'B', 12);
       if (($dd!=31)||($mm!=12)||($yy!=9999)){
         $pdf->MultiCell(0,5,'Dia i hora: ' . $dd . ' ' . $mes . ' ' . $yy . '  ' . $hora .
         ':' . $min . 'H');
       } else {
         $pdf->MultiCell(0,5,'Dia i hora: Sense determinar');
       }
       $pdf->MultiCell(0,5,'Lloc: ' . $row["lloc"]);
       $pdf->MultiCell(0,5,'Obert a: ' . $row["obert_a"]);
       $pdf->MultiCell(0,5,'Idioma: ' . $row["idioma"]);*/
       $pdf->Output();

       mysql_free_result($result);
 ?>

