<!-- COMENÇA LES ACTIVITATS PER AVUI PER ESPAI -->
        
        <table style="display:none;" id="LLISTAT_ORDENAT_ESPAIS" class="DADES">                
                <?php 
if (empty($ACTIVITATS)) {
    echo '<tr><td></td></tr>';
}
$ESPAIS = array();
foreach ($ACTIVITATS as $idH => $A) {
    foreach ($A['ESPAIS'] as $idE => $E) {
        $ESPAIS[$idE][] = $idH;
    }
}
$ANT = "";
//Reordeno espais perquè apareguin com estan ordenats a la intranet.
$ESPAIS_REAL = EspaisPeer::getEspaisSite($IDS);
$ESPAIS_ORDENAT = array();
foreach ($ESPAIS_REAL as $OE) {
    $idE = $OE->getNom();
    if (isset($ESPAIS[$idE])) {
        $ESPAIS_ORDENAT[$idE] = $ESPAIS[$idE];
    }
}
foreach ($ESPAIS_ORDENAT as $idE => $HORA) {
    foreach ($HORA as $idH) {
        $A = $ACTIVITATS[$idH];
        echo '<tr>';
        if (strlen($A['AVIS']) > 2) {
            $AVIS = '<a href="#" class="tt2">' . image_tag('tango/32x32/emblems/emblem-important.png', array('size' => '16x16')) . '<span>' . $A['AVIS'] . '</span></a>';
        } else {
            $AVIS = "";
function formLlistaActivitats($ACTIVITATS, $PAGINA, $IDS)
{
    ?>

     <div class="REQUADRE">
        <div class="TITOL">Llistat d'activitats <span style="color:gray; font-weight:normal; ">(Ordenat per <a id="ORDENA_HORARIS" href="#">horaris</a> / <a id="ORDENA_ESPAIS" href="#">espais</a> )</span></div>
      	<table id="LLISTAT_ORDENAT_HORARIS" class="DADES">
 			<?php 
    if (sizeof($ACTIVITATS) == 0) {
        echo '<TR><TD class="LINIA">No s\'ha trobat cap activitat.</TD></TR>';
    }
    foreach ($ACTIVITATS as $idH => $A) {
        $AVIS = "";
        $ESP = "";
        $MAT = "";
        $PUBLICAT = "";
        if (!empty($A['ESPAIS'])) {
            $ESP = implode("<br />", $A['ESPAIS']);
        }
        if (!empty($A['MATERIAL'])) {
            $MAT = implode("<br />", $A['MATERIAL']);
        }
        if (strlen($A['AVIS']) > 2) {
            $AVIS = '<a href="#" class="tt2">' . image_tag('tango/32x32/emblems/emblem-important.png', array('size' => '16x16')) . '<span>' . $A['AVIS'] . '</span></a>';
        } else {
            $AVIS = "";
        }
        if ($A['PUBLICAT'] == 'OK') {
            $PUBLICAT = image_tag('template/exclamation.png', array('size' => '16x16'));
        } elseif ($A['PUBLICAT'] == 'FALTA_INFO') {
            $PUBLICAT = image_tag('template/stop.png', array('size' => '16x16'));
        }
        $j = 1;
        $PAR = ParImpar($j++);
        $url_act = link_to($A['NOM_ACTIVITAT'], 'gestio/gActivitats?accio=ACTIVITAT&IDA=' . $A['ID'], array('style' => 'font-size:12px'));
        $url_hor = "";
        //link_to('Edita informació pràctica','gestio/gActivitats?accio=HORARI&IDA='.$A['ID'].'&IDH='.$idH,array('style'=>'font-size:10px'));
        $org = empty($A['ORGANITZADOR']) ? "" : "<span style=\"font-size:8px; color:gray; \"> (" . $A['ORGANITZADOR'] . ") </span>";
        echo '	<tr><td style="background-color:#EEEEEE; border:1px solid #EEEEEE; height:15px;" colspan="6"></td></tr>';
        echo '	<tr><td class="LIST2 ' . $PAR . '" colspan="6">' . $url_act . $AVIS . ' ' . $PUBLICAT . $org . ' <div style="float:right">' . $url_hor . '</div></td></tr>';
        echo '	<TR>                      						               							                	
	                  				<TD class="LIST2 ' . $PAR . '"><span style="font-weight:bold; font-size:10px; color:#880000;">' . $A['HORA_PRE'] . '</span></TD>	
				               		<TD class="LIST2 ' . $PAR . '"><span style="font-weight:bold; font-size:12px; color:green;">' . $A['HORA_INICI'] . '</span></TD>
				               		<TD class="LIST2 ' . $PAR . '"><b>' . $A['HORA_FI'] . '</b></TD>';
        echo '	    <TD class="LIST2 ' . $PAR . '"><span style="font-weight:bold; font-size:12px; color:#800000;">' . $ESP . '</span></TD>';
        echo '     	<TD class="LIST2 ' . $PAR . '">' . $MAT . '</TD>
				                	<TD class="LIST2 ' . $PAR . '">' . $A['DIA'] . '</TD>						            
				                </TR>';
    }
    ?>
            	
      	</table>

      	<table id="LLISTAT_ORDENAT_ESPAIS" class="DADES" style="display: none;">
 			<?php 
    if (sizeof($ACTIVITATS) == 0) {
        echo '<TR><TD class="LINIA">No s\'ha trobat cap activitat.</TD></TR>';
    }
    $ESPAIS = array();
    foreach ($ACTIVITATS as $idH => $A) {
        foreach ($A['ESPAIS'] as $idE => $E) {
            $ESPAIS[$idE][] = $idH;
        }
    }
    $ANT = "";
    //Reordeno espais perquè apareguin com estan ordenats a la intranet.
    $ESPAIS_REAL = EspaisPeer::getEspaisSite($IDS);
    $ESPAIS_ORDENAT = array();
    foreach ($ESPAIS_REAL as $OE) {
        $idE = $OE->getNom();
        if (isset($ESPAIS[$idE])) {
            $ESPAIS_ORDENAT[$idE] = $ESPAIS[$idE];
        }
    }
    foreach ($ESPAIS_ORDENAT as $idE => $HORA) {
        foreach ($HORA as $idH) {
            $A = $ACTIVITATS[$idH];
            //Per cada horari, agafem l'espai i fem un vector on guardarem els resultats.'
            $AVIS = "";
            $ESP = "";
            $MAT = "";
            $PUBLICAT = "";
            if (!empty($A['ESPAIS'])) {
                $ESP = $A['ESPAIS'][$idE];
            }
            if (!empty($A['MATERIAL'])) {
                $MAT = implode("<br />", $A['MATERIAL']);
            }
            if (strlen($A['AVIS']) > 2) {
                $AVIS = '<a href="#" class="tt2">' . image_tag('tango/32x32/emblems/emblem-important.png', array('size' => '16x16')) . '<span>' . $A['AVIS'] . '</span></a>';
            } else {
                $AVIS = "";
            }
            if ($A['PUBLICAT'] == 'OK') {
                $PUBLICAT = image_tag('template/exclamation.png', array('size' => '16x16'));
            } elseif ($A['PUBLICAT'] == 'FALTA_INFO') {
                $PUBLICAT = image_tag('template/stop.png', array('size' => '16x16'));
            }
            $j = 1;
            $PAR = ParImpar($j++);
            $url_act = link_to($A['NOM_ACTIVITAT'], 'gestio/gActivitats?accio=ACTIVITAT&IDA=' . $A['ID'], array('style' => 'font-size:12px'));
            $url_hor = $org = empty($A['ORGANITZADOR']) ? "" : "<span style=\"font-size:8px; color:gray; \"> (" . $A['ORGANITZADOR'] . ") </span>";
            if ($ANT != $ESP) {
                echo '	<tr><td style="background-color:#AAAAAA; font-size:14px; color:EEEEEE; font-style:italic; border:1px solid #EEEEEE; height:15px;" colspan="6">' . $ESP . '</td></tr>';
            } else {
                echo '	<tr><td style="background-color:#EEEEEE; border:1px solid #EEEEEE; height:15px;" colspan="6">&nbsp;</td></tr>';
            }
            $ANT = $ESP;
            echo '	<tr><td class="LIST2 ' . $PAR . '" colspan="6">' . $url_act . $AVIS . ' ' . $PUBLICAT . $org . ' <div style="float:right">' . $url_hor . '</div></td></tr>';
            echo '	<TR>                      						               							                	
                      				<TD class="LIST2 ' . $PAR . '"><span style="font-weight:bold; font-size:10px; color:#880000;">' . $A['HORA_PRE'] . '</span></TD>	
    			               		<TD class="LIST2 ' . $PAR . '"><span style="font-weight:bold; font-size:12px; color:green;">' . $A['HORA_INICI'] . '</span></TD>
    			               		<TD class="LIST2 ' . $PAR . '"><b>' . $A['HORA_FI'] . '</b></TD>';
            echo '	    <TD class="LIST2 ' . $PAR . '"><span style="font-weight:bold; font-size:12px; color:#800000;">' . $ESP . '</span></TD>';
            echo '     	<TD class="LIST2 ' . $PAR . '">' . $MAT . '</TD>
    			                	<TD class="LIST2 ' . $PAR . '">' . $A['DIA'] . '</TD>						            
    			                </TR>';
        }
    }
    ?>
            	 				                         	
      	</table>      

                
      </div>

<?php 
}
 public function executeEspais(sfWebRequest $request)
 {
     $this->LoadWEB($request);
     $this->setTemplate('index');
     $this->LLISTAT_ESPAIS = EspaisPeer::getEspaisSite($this->IDS);
     $this->ACCIO = 'espais';
 }