<?php
class securitygdFilter
{

    public function execute( $block )
    {
        $this->app = SF_APP;
        $this->block = $block;
        $this->action = ParameterWR::getInstance()->getActions();
        $this->module = ParameterWR::getInstance()->getModule();
        
        if( $block )
        {
            //$this->securityTaskGD = "mnu." . $this->app . $this->block . "." . $this->module . "." . $this->action;
            //$IdSubSistema = "smnu.".$this->app;
        }
        else
        {
            
        }

        $this->securityTaskGD = "mnu." . $this->app . "." . $this->module . "." . $this->action;
        $IdSubSistema = "smnu.".$this->app;

        //pr( $this->securityTaskGD );

        $a_Data = explode( ".", $this->securityTaskGD );

        $s_ScriptId = $a_Data[2]."/".$a_Data[3];
        $TareaDescripcion = strtoupper( $a_Data[2]." ".$a_Data[3] );
        //$IdSubSistema = "s".$a_Data[0].".".$a_Data[1];

        $s_Sql = "
REPLACE INTO SEG_Tarea
( IdTarea, TareaDescripcion, BotonTexto, TareaTipo, ScriptId, DeshabilitadoFlg, IdPatron, IdSubSistema,  FechaCreacion, UsuarioCreacion )
VALUES
( '".$this->securityTaskGD."', '$TareaDescripcion', '$TareaDescripcion', 'proc', '$s_ScriptId', 'N', 'list001', '$IdSubSistema', '".date( 'Y-m-d H:i:s' )."', 'wtaype' );
                ";
        Conexion::getConexion()->createStatement()->executeQuery( $s_Sql );

        $this->o_sfUser = myUser::getUser();
        
        $this->preExecuteGD();
    }

    function preExecuteGD()
    {
		//Codigo para no pedir autenticacion a pro/PrintPDFToken
		if ($this->module === 'pro' && $this->action === 'printPDFToken') {
			// aquí no validamos sesión ni permisos
			return;
		}
		///
        $b_Access = false;
        if( $this->o_sfUser->hasTask( $this->securityTaskGD ) )
        {
            $b_Access = true;
        }
        
        if( $b_Access )
        {
            $b_Perm = true;
            if( !$this->o_sfUser->getPerm( $this->securityTaskGD ) )
            {
                $b_Perm = false;
                pr( "No tiene Permiso." );
                exit;
                ParameterWR::getInstance()->actions = 'perms';
            }

            if( $this->o_sfUser->mnuTask['TaskType'] != 'proc' )
            {
                //aqui es por que no esta registrado en //SEG_TareaRol
                pr( "No tiene Permiso, no se encontro asignacion a la tarea." );
                exit;
                ParameterWR::getInstance()->actions = 'perms';
            }
        }
        else
        {
            pr( "Por favor registrar la Tarea : ".$this->securityTaskGD );
            exit;
            ParameterWR::getInstance()->actions = 'perms';
        }
    }
}
