<?php

    global $tpl;
    
    
    $Proces = procesy::getWithDetails( core::$i->id );
    
    if( $Proces )
    {
        
        // Naglowki
        if( $Proces->user ) $query = db::$i->q("SELECT * FROM `alternatywy` WHERE `proces_id`='".( $Proces->id )."'  ORDER BY `id` ASC", true );
        else $query = db::$i->q("SELECT * FROM `alternatywy` WHERE `temat_id`='".( $Proces->temat_id )."' AND `proces_id` IS NULL  ORDER BY `id` ASC", true ); 
        //
        if( db::$i->rows )
        {
            while( $item = db::$i->f( $query ) )
            {
                $AlternatywaIdGroup[] = $item['id'];
                $Headers[$item['id']] = $item['nazwa'];
            }
        }
        
        // Wartosci
        $query = db::$i->q("SELECT w.*,k.nazwa FROM `wartosci` w,`kryteria` k WHERE w.alternatywa_id IN(".join(',',$AlternatywaIdGroup).") AND w.proces_id='{$Proces->id}' AND k.id=w.kryterium_id ORDER BY w.alternatywa_id ASC,w.kryterium_id ASC",true);

        
        if( db::$i->rows )
        {
            
            for( $i = 1 ; $item = db::$i->f( $query ) ; $i++ )
            {
                $Wartosci[$item['nazwa']][] = $item;
            }

        }
        
        

        
        $tpl->assign(array(
            'Headers' => $Headers,
            'Wartosci' => $Wartosci,
            'Proces' => $Proces
        ));
        
        module::$i->on();
    } 
    else 
    {
       core::page404();
    }
    
    
    

?>