<?php
ob_start();
// session_start();
 require_once("Sigma.php");
// require_once("dispatcher.php");
// mb_http_output('UTF-8');
$tpl =& new HTML_Template_Sigma('.','./template/cache');

//redireccionamientos.
$tpl->loadTemplateFile('nba.html');

$colores = "";
//$res = LoadConfiguration();

if(IfSportExists($res,'NHL') || IfSportExists($res,'AFL'))
{

if (file_exists('nhl.xml') && !file_exists('bal.xml') && file_exists('afl.xml'))
{
   //$tpl->setVariable('link', 'mlb.php');
   //60;

  $afl = 1;
  $nhl = 1;
  if(is_readable('afl.xml'))
  {
    $reloj = GetTimeRemaining($res,'AFL');
   if (!$myxml=simplexml_load_file('afl.xml'))
        echo 'Error al Cargar Archivo NFL.XML';
       else
       {

        foreach($myxml as $node)
        {
              if ($colores == "#99FFFF")
                {
                  $tpl->setVariable('colores', 'bgcolor=""');
                  $colores = "";
                }
              else
                {
                  $tpl->setVariable('colores', 'bgcolor="#99FFFF"');
                  $colores = "#99FFFF";
                }
               $tpl->setVariable('dep2',   'AFL');
                          $tpl->setVariable('JC-RL2',   'JC-RL');
                          $tpl->setVariable('JC-ML2',   'JC-ML');
                          $tpl->setVariable('H1-ML2',   'H1-ML');
                          $tpl->setVariable('H1-RL2',   'H1-RL');
                          $tpl->setVariable('Q1-ML2',   'Q1-ML');
                          $tpl->setVariable('Q1-RL2',   'Q1-RL');
               $timegame = explode(":", $node->TimeGame);
               $hora = $timegame[0].':'.$timegame[1];
               $meridian = $timegame[2];

                  $tpl->setVariable('hora2',$hora);
                  $tpl->setVariable('espa2',$meridian);
                  $tpl->setVariable('vId2',$node->VisTeam);

                  $tpl->setVariable('eq_visitante2',   $node->EquipoVisitante);
                  $tpl->setVariable('lId2', $node->LocTeam);

                  $tpl->setVariable('eq_local2',   ($node->EquipoLocal));
                  $tpl->setVariable('jc_mlv2',     ($node->PriceMLJCVis));

                  $tpl->setVariable('jc_mll2',     ($node->PriceMLJCLoc));
                  $tpl->setVariable('jc_rlv2',     ($node->RLJCVis));

                  $tpl->setVariable('jc_rll2',     ($node->RLJCLoc));
                  #$tpl->setVariable('srl_vjc',    utf8_decode($node->SRLJCVis));

                 # $tpl->setVariable('srl_ljc',    utf8_decode($node->SRLJCLoc));
                  $tpl->setVariable('h1_mlv2',     ($node->PriceMLPMVis));

                  $tpl->setVariable('h1_mll2',     ($node->PriceMLPMLoc));
                 // $tpl->setVariable('ml_lpm',     utf8_decode($node->PriceMLPMVis));

                  $tpl->setVariable('h1_rlv2',     ($node->RLPMVis));
                  $tpl->setVariable('h1_rll2',     ($node->RLPMLoc));

                  $tpl->setVariable('q1_mlv2',     ($node->PriceMLPPVis));
                  $tpl->setVariable('q1_mll2',     ($node->PriceMLPPLoc));

                  $tpl->setVariable('q1_rlv2',     ($node->RLPPVis));
                  $tpl->setVariable('q1_rll2',     ($node->RLPPLoc));
                  $registro++;

               $tpl->parse('bloque2');

        }//for.
       }//else
   }//is readable.
      if($registro < 15)
           {
                $total = (15 - $registro);
                for($i = 0; $i < $total; $i++)
                         {
                                  $tpl->setVariable('hora2','&nbsp;');
                  $tpl->setVariable('espa2','&nbsp;');
                  $tpl->setVariable('vId2','&nbsp;');

                  $tpl->setVariable('eq_visitante2',   '&nbsp;');
                  $tpl->setVariable('lId2', '&nbsp;');

                  $tpl->setVariable('eq_local2',   '&nbsp;');
                  $tpl->setVariable('jc_mlv2',     '&nbsp;');

                  $tpl->setVariable('jc_mll2',     '&nbsp;');
                  $tpl->setVariable('jc_rlv2',     '&nbsp;');

                  $tpl->setVariable('jc_rll2',     '&nbsp;');
                  #$tpl->setVariable('srl_vjc',    utf8_decode($node->SRLJCVis));

                 # $tpl->setVariable('srl_ljc',    utf8_decode($node->SRLJCLoc));
                  $tpl->setVariable('h1_mlv2',     '&nbsp;');

                  $tpl->setVariable('h1_mll2',    '&nbsp;');
                 // $tpl->setVariable('ml_lpm',     utf8_decode($node->PriceMLPMVis));

                  $tpl->setVariable('h1_rlv2',     '&nbsp;');
                  $tpl->setVariable('h1_rll2',     '&nbsp;');

                  $tpl->setVariable('q1_mlv2',     '&nbsp;');
                  $tpl->setVariable('q1_mll2',     '&nbsp;');

                  $tpl->setVariable('q1_rlv2',   '&nbsp;');
                  $tpl->setVariable('q1_rll2',   '&nbsp;');
                  $tpl->parse('bloque2');

                                }
                        $registro = 0;
           }

           //NHL .....
   if(is_readable('nhl.xml'))
   {
     $reloj = GetTimeRemaining($res,'NHL');
       if (!$myxml=simplexml_load_file('nhl.xml'))
        echo 'Error al Cargar Archivo NHL.XML';
       else
       {

        foreach($myxml as $node)
        {
              if ($colores == "#99FFFF")
                {
                  $tpl->setVariable('colores', 'bgcolor=""');
                  $colores = "";
                }
              else
                {
                  $tpl->setVariable('colores', 'bgcolor="#99FFFF"');
                  $colores = "#99FFFF";
                }
               $tpl->setVariable('dep1',   'NHL');
                          $tpl->setVariable('JC-RL',   'JC-RL');
                          $tpl->setVariable('JC-ML',   'JC-ML');
                          $tpl->setVariable('H1-ML',   'H1-ML');
                          $tpl->setVariable('H1-RL',   'H1-RL');
                          $tpl->setVariable('Q1-ML',   'Q1-ML');
                          $tpl->setVariable('Q1-RL',   'Q1-RL');
               $timegame = explode(":", $node->TimeGame);
               $hora = $timegame[0].':'.$timegame[1];
               $meridian = $timegame[2];

                  $tpl->setVariable('hora1',$hora);
                  $tpl->setVariable('espa1',$meridian);
                  $tpl->setVariable('vId1',$node->VisTeam);

                  $tpl->setVariable('eq_visitante1',   $node->EquipoVisitante);
                  $tpl->setVariable('lId1', $node->LocTeam);

                  $tpl->setVariable('eq_local1',   ($node->EquipoLocal));
                  $tpl->setVariable('jc_mlv1',     ($node->PriceMLJCVis));

                  $tpl->setVariable('jc_mll1',     ($node->PriceMLJCLoc));
                  $tpl->setVariable('jc_rlv1',     ($node->RLJCVis));

                  $tpl->setVariable('jc_rll1',     ($node->RLJCLoc));
                  #$tpl->setVariable('srl_vjc',    utf8_decode($node->SRLJCVis));

                 # $tpl->setVariable('srl_ljc',    utf8_decode($node->SRLJCLoc));
                  $tpl->setVariable('h1_mlv1',     ($node->PriceMLPMVis));

                  $tpl->setVariable('h1_mll1',     ($node->PriceMLPMLoc));
                 // $tpl->setVariable('ml_lpm',     utf8_decode($node->PriceMLPMVis));

                  $tpl->setVariable('h1_rlv1',     ($node->RLPMVis));
                  $tpl->setVariable('h1_rll1',     ($node->RLPMLoc));

                  $tpl->setVariable('q1_mlv1',     ($node->PriceMLPPVis));
                  $tpl->setVariable('q1_mll1',     ($node->PriceMLPPLoc));

                  $tpl->setVariable('q1_rlv1',     ($node->RLPPVis));
                  $tpl->setVariable('q1_rll1',     ($node->RLPPLoc));
                  $registro++;

               $tpl->parse('bloque1');

        }//for.
       }//else
   }//is readable.
      if($registro < 15)
           {
                $total = (15 - $registro);
                for($i = 0; $i < $total; $i++)
                         {
                                  $tpl->setVariable('hora1','&nbsp;');
                  $tpl->setVariable('espa1','&nbsp;');
                  $tpl->setVariable('vId1','&nbsp;');

                  $tpl->setVariable('eq_visitante1',   '&nbsp;');
                  $tpl->setVariable('lId1', '&nbsp;');

                  $tpl->setVariable('eq_local1',   '&nbsp;');
                  $tpl->setVariable('jc_mlv1',     '&nbsp;');

                  $tpl->setVariable('jc_mll1',     '&nbsp;');
                  $tpl->setVariable('jc_rlv1',     '&nbsp;');

                  $tpl->setVariable('jc_rll1',     '&nbsp;');
                  #$tpl->setVariable('srl_vjc',    utf8_decode($node->SRLJCVis));

                 # $tpl->setVariable('srl_ljc',    utf8_decode($node->SRLJCLoc));
                  $tpl->setVariable('h1_mlv1',     '&nbsp;');

                  $tpl->setVariable('h1_mll1',    '&nbsp;');
                 // $tpl->setVariable('ml_lpm',     utf8_decode($node->PriceMLPMVis));

                  $tpl->setVariable('h1_rlv1',     '&nbsp;');
                  $tpl->setVariable('h1_rll1',     '&nbsp;');

                  $tpl->setVariable('q1_mlv1',     '&nbsp;');
                  $tpl->setVariable('q1_mll1',     '&nbsp;');

                  $tpl->setVariable('q1_rlv1',   '&nbsp;');
                  $tpl->setVariable('q1_rll1',   '&nbsp;');
                  $tpl->parse('bloque1');

                                }
                        $registro = 0;
           }
}
elseif (file_exists('nhl.xml') && file_exists('bal.xml') && file_exists('afl.xml'))
{
   //$tpl->setVariable('link', 'mlb.php');
  $afl = 1;
  $nhl = 1;
  $bal = 1;
  if(is_readable('afl.xml'))
  {
    $reloj = GetTimeRemaining($res,'AFL');
    if (!$myxml=simplexml_load_file('afl.xml'))
        echo 'Error al Cargar Archivo AFL.XML';
       else
       {

        foreach($myxml as $node)
        {
              if ($colores == "#99FFFF")
                {
                  $tpl->setVariable('colores', 'bgcolor=""');
                  $colores = "";
                }
              else
                {
                  $tpl->setVariable('colores', 'bgcolor="#99FFFF"');
                  $colores = "#99FFFF";
                }
               $tpl->setVariable('dep2',   'AFL');
                          $tpl->setVariable('JC-RL2',   'JC-RL');
                          $tpl->setVariable('JC-ML2',   'JC-ML');
                          $tpl->setVariable('H1-ML2',   'H1-ML');
                          $tpl->setVariable('H1-RL2',   'H1-RL');
                          $tpl->setVariable('Q1-ML2',   'Q1-ML');
                          $tpl->setVariable('Q1-RL2',   'Q1-RL');
               $timegame = explode(":", $node->TimeGame);
               $hora = $timegame[0].':'.$timegame[1];
               $meridian = $timegame[2];

                  $tpl->setVariable('hora2',$hora);
                  $tpl->setVariable('espa2',$meridian);
                  $tpl->setVariable('vId2',$node->VisTeam);

                  $tpl->setVariable('eq_visitante2',   $node->EquipoVisitante);
                  $tpl->setVariable('lId2', $node->LocTeam);

                  $tpl->setVariable('eq_local2',   ($node->EquipoLocal));
                  $tpl->setVariable('jc_mlv2',     ($node->PriceMLJCVis));

                  $tpl->setVariable('jc_mll2',     ($node->PriceMLJCLoc));
                  $tpl->setVariable('jc_rlv2',     ($node->RLJCVis));

                  $tpl->setVariable('jc_rll2',     ($node->RLJCLoc));
                  #$tpl->setVariable('srl_vjc',    utf8_decode($node->SRLJCVis));

                 # $tpl->setVariable('srl_ljc',    utf8_decode($node->SRLJCLoc));
                  $tpl->setVariable('h1_mlv2',     ($node->PriceMLPMVis));

                  $tpl->setVariable('h1_mll2',     ($node->PriceMLPMLoc));
                 // $tpl->setVariable('ml_lpm',     utf8_decode($node->PriceMLPMVis));

                  $tpl->setVariable('h1_rlv2',     ($node->RLPMVis));
                  $tpl->setVariable('h1_rll2',     ($node->RLPMLoc));

                  $tpl->setVariable('q1_mlv2',     ($node->PriceMLPPVis));
                  $tpl->setVariable('q1_mll2',     ($node->PriceMLPPLoc));

                  $tpl->setVariable('q1_rlv2',     ($node->RLPPVis));
                  $tpl->setVariable('q1_rll2',     ($node->RLPPLoc));
                  $registro++;

               $tpl->parse('bloque2');

        }//for.
       }//else
  }//is readable.
      if($registro < 15)
           {
                $total = (15 - $registro);
                for($i = 0; $i < $total; $i++)
                         {
                                  $tpl->setVariable('hora2','&nbsp;');
                  $tpl->setVariable('espa2','&nbsp;');
                  $tpl->setVariable('vId2','&nbsp;');

                  $tpl->setVariable('eq_visitante2',   '&nbsp;');
                  $tpl->setVariable('lId2', '&nbsp;');

                  $tpl->setVariable('eq_local2',   '&nbsp;');
                  $tpl->setVariable('jc_mlv2',     '&nbsp;');

                  $tpl->setVariable('jc_mll2',     '&nbsp;');
                  $tpl->setVariable('jc_rlv2',     '&nbsp;');

                  $tpl->setVariable('jc_rll2',     '&nbsp;');
                  #$tpl->setVariable('srl_vjc',    utf8_decode($node->SRLJCVis));

                 # $tpl->setVariable('srl_ljc',    utf8_decode($node->SRLJCLoc));
                  $tpl->setVariable('h1_mlv2',     '&nbsp;');

                  $tpl->setVariable('h1_mll2',    '&nbsp;');
                 // $tpl->setVariable('ml_lpm',     utf8_decode($node->PriceMLPMVis));

                  $tpl->setVariable('h1_rlv2',     '&nbsp;');
                  $tpl->setVariable('h1_rll2',     '&nbsp;');

                  $tpl->setVariable('q1_mlv2',     '&nbsp;');
                  $tpl->setVariable('q1_mll2',     '&nbsp;');

                  $tpl->setVariable('q1_rlv2',   '&nbsp;');
                  $tpl->setVariable('q1_rll2',   '&nbsp;');
                  $tpl->parse('bloque2');

                                }
                        $registro = 0;
           }

           //NHL .....
   if(is_readable('mhl.xml'))
   {
     $reloj = GetTimeRemaining($res,'NHL');
      if (!$myxml=simplexml_load_file('nhl.xml'))
        echo 'Error al Cargar Archivo NHL.XML';
       else
       {

        foreach($myxml as $node)
        {
              if ($colores == "#99FFFF")
                {
                  $tpl->setVariable('colores', 'bgcolor=""');
                  $colores = "";
                }
              else
                {
                  $tpl->setVariable('colores', 'bgcolor="#99FFFF"');
                  $colores = "#99FFFF";
                }
               $tpl->setVariable('dep1',   'NHL');
                          $tpl->setVariable('JC-RL',   'JC-RL');
                          $tpl->setVariable('JC-ML',   'JC-ML');
                          $tpl->setVariable('H1-ML',   'H1-ML');
                          $tpl->setVariable('H1-RL',   'H1-RL');
                          $tpl->setVariable('Q1-ML',   'Q1-ML');
                          $tpl->setVariable('Q1-RL',   'Q1-RL');
               $timegame = explode(":", $node->TimeGame);
               $hora = $timegame[0].':'.$timegame[1];
               $meridian = $timegame[2];

                  $tpl->setVariable('hora1',$hora);
                  $tpl->setVariable('espa1',$meridian);
                  $tpl->setVariable('vId1',$node->VisTeam);

                  $tpl->setVariable('eq_visitante1',   $node->EquipoVisitante);
                  $tpl->setVariable('lId1', $node->LocTeam);

                  $tpl->setVariable('eq_local1',   ($node->EquipoLocal));
                  $tpl->setVariable('jc_mlv1',     ($node->PriceMLJCVis));

                  $tpl->setVariable('jc_mll1',     ($node->PriceMLJCLoc));
                  $tpl->setVariable('jc_rlv1',     ($node->RLJCVis));

                  $tpl->setVariable('jc_rll1',     ($node->RLJCLoc));
                  #$tpl->setVariable('srl_vjc',    utf8_decode($node->SRLJCVis));

                 # $tpl->setVariable('srl_ljc',    utf8_decode($node->SRLJCLoc));
                  $tpl->setVariable('h1_mlv1',     ($node->PriceMLPMVis));

                  $tpl->setVariable('h1_mll1',     ($node->PriceMLPMLoc));
                 // $tpl->setVariable('ml_lpm',     utf8_decode($node->PriceMLPMVis));

                  $tpl->setVariable('h1_rlv1',     ($node->RLPMVis));
                  $tpl->setVariable('h1_rll1',     ($node->RLPMLoc));

                  $tpl->setVariable('q1_mlv1',     ($node->PriceMLPPVis));
                  $tpl->setVariable('q1_mll1',     ($node->PriceMLPPLoc));

                  $tpl->setVariable('q1_rlv1',     ($node->RLPPVis));
                  $tpl->setVariable('q1_rll1',     ($node->RLPPLoc));
                  $registro++;

               $tpl->parse('bloque1');

        }//for.
       }//else
   }//is readable
      if($registro < 15)
           {
                $total = (15 - $registro);
                for($i = 0; $i < $total; $i++)
                         {
                                  $tpl->setVariable('hora1','&nbsp;');
                  $tpl->setVariable('espa1','&nbsp;');
                  $tpl->setVariable('vId1','&nbsp;');

                  $tpl->setVariable('eq_visitante1',   '&nbsp;');
                  $tpl->setVariable('lId1', '&nbsp;');

                  $tpl->setVariable('eq_local1',   '&nbsp;');
                  $tpl->setVariable('jc_mlv1',     '&nbsp;');

                  $tpl->setVariable('jc_mll1',     '&nbsp;');
                  $tpl->setVariable('jc_rlv1',     '&nbsp;');

                  $tpl->setVariable('jc_rll1',     '&nbsp;');
                  #$tpl->setVariable('srl_vjc',    utf8_decode($node->SRLJCVis));

                 # $tpl->setVariable('srl_ljc',    utf8_decode($node->SRLJCLoc));
                  $tpl->setVariable('h1_mlv1',     '&nbsp;');

                  $tpl->setVariable('h1_mll1',    '&nbsp;');
                 // $tpl->setVariable('ml_lpm',     utf8_decode($node->PriceMLPMVis));

                  $tpl->setVariable('h1_rlv1',     '&nbsp;');
                  $tpl->setVariable('h1_rll1',     '&nbsp;');

                  $tpl->setVariable('q1_mlv1',     '&nbsp;');
                  $tpl->setVariable('q1_mll1',     '&nbsp;');

                  $tpl->setVariable('q1_rlv1',   '&nbsp;');
                  $tpl->setVariable('q1_rll1',   '&nbsp;');
                  $tpl->parse('bloque1');

                                }
                        $registro = 0;
           }
}
}
else
   header('location:caf.php');


//  if ($bal == 1)
   $tpl->setVariable('link', 'caf.php');
 // else
//   $tpl->setVariable('link', 'mlb.php');
// $tpl->setVariable('meta','<meta http-equiv="refresh" content="'.$reloj.';url=bal.php">');
$tpl->setVariable('tiempo', $reloj);
$tpl->show();
?>