<?php

    global $tpl;

    if( core::$i->id )
    {
        if( user::$i->mode == 'therapist' )
        {
                    db::$i->del('kryteria',core::$i->id,'id');
                    
                    if( $KryteriumData )
                    {
                        db::$i->q("DELETE FROM `wagi` WHERE `proces_id`='".( $KryteriumData['proces_id'] )."' AND `kryterium_id`='".( core::$i->id )."'");
                    }
        } 
        else 
        {
            switch( core::$i->method )
            {
                
                case 'confirm':
                
                    $KryteriumData = db::$i->byid( 'kryteria' , core::$i->id );
                
                    if( db::$i->row("SELECT 1 FROM `user` WHERE `pass`='".( esc( user::pass_encoder( $_REQUEST['password'] ) ) )."' AND `mode`='therapist'") )
                    {
                        db::$i->del('kryteria',core::$i->id,'id');
                        
                        if( $KryteriumData )
                        {
                            db::$i->q("DELETE FROM `wagi` WHERE `proces_id`='".( $KryteriumData['proces_id'] )."' AND `kryterium_id`='".( core::$i->id )."'");
                        }
                        
                        js::$i->setJSON(array(
                            'status' => true,
                            'html' => "<script>CloseUsableWindow();$('.AlternativeQuestion".( core::$i->id )."').remove();</script>"
                        ));
                    } 
                    else 
                    {
                        js::$i->setJSON(array(
                            'status' => false,
                            'error' => 'Błędne hasło'
                        ));
                    }
                
                    
                break;
    
                default:
                
                    $tpl->assign(array(
                        'id' => core::$i->id
                    ));
                
                    js::$i->setJSON(array(   
                        'status' => true,
                        'html' => $tpl->fetch('ajax/' . core::$i->mode . '/' . core::$i->function . '.tpl' )
                    ));
                break;
                
            }
        }

        
    } 
    else 
    {
        js::$i->setJSON(array(
            'status' => false,
            'error' => 'Kryterium o takim identyfikatorze nie istnieje'
        ));
    }

?>