<?php session_start();?>
<?php include('php_gene1.php'); ?>
<?php include('../_cfg/config.php');?>
<?php include('php_session.php');?>

<?php

$cong_sql='select * from cong0 where cong_codigo="'.$_SESSION['cong_codigo'].'"';
$cong_res=msql_query($cong_sql,$link_vcrx);
$salas = msql_result($cong_res,0,'cong_sala');
$grupos = msql_result($cong_res,0,'cong_grupo');

$sql_docu='select * from docu0 where docu_tabla="jwib"';
$xfecha1='2016-10-03';

if($cong_codigo!='')
{  
// for ($fec=-2; $fec<=1; $fec++)
for ($fec=0; $fec<=16; $fec++)
{
    $fecha=strtotime ('last Monday +'.($fec*7).' days');
    $fecha=date('Y-m-d',$fecha);
//     $fecha=date('2017-04-01');

          $panio=substr($fecha,0,4);	
					$pmes=substr($fecha,5,2);	
					$pdia=substr($fecha,8,2);	
  
  
					$jworg='http://wol.jw.org';
					$jworg1=$jworg.'/es/wol/dt/r4/lp-s/'.$panio.'/'.$pmes.'/'.$pdia;

					$page = file_get_contents($jworg1);
					$sec0 = strpos($page,'<h2 id="p2"');
					$sec1 = strpos($page,'id="section1"');
					$sec2 = strpos($page,'id="section2"');
					$sec3 = strpos($page,'id="section3"');
					$sec4 = strpos($page,'id="section4"');
					$sec5 = strpos($page,'<strong>Estudio bíblico de la congregación');
					$sec6 = strpos($page,'SEMANA DEL');

					$sec0 = substr($page,$sec0,$sec1-$sec0); 
					$stdb = substr($page,$sec2,$sec3-$sec2); 
					$ssmm = substr($page,$sec3,$sec4-$sec3); 
					$snvc = substr($page,$sec4,$sec5-$sec4); 
					$slib = substr($page,$sec5,$sec6-$sec5); 
					$sata = substr($page,$sec6,9999999); 
	

					$tdb1 = substr($stdb,strpos($stdb,'<a href='),strpos($stdb,'</a')-strpos($stdb,'<a href=')); 
					$tdb1 = str_replace('href="','target="_blank" tabindex="-1" href="'.$jworg,$tdb1);
					$tdb1 = str_replace('strong','div',$tdb1);
					$tdb1 = str_replace('<div','<div tabindex="-1" ',$tdb1);

					$tdb2 = substr($sec0,strpos($sec0,'<a href='),strpos($sec0,'</a')-strpos($sec0,'<a href=')); 
					$tdb2 = str_replace('href="','target="_blank" tabindex="-1" href="'.$jworg,$tdb2);
					$tdb2 = str_replace('strong','div',$tdb2);
					$tdb2 = str_replace('>','> ',$tdb2);
					$tdb2 = str_replace('<div','<div tabindex="-1" ',$tdb2);
					$tdb2 = ucwords(strtolower($tdb2));


					$smm0 = substr($stdb,strpos($stdb,'ideas de la lectura'),999999999); 
					if($fecha>="2017-04-01")
					{$smm0 = substr($stdb,strpos($stdb,'otras perlas espirituales ha encontrado'),999999999);}
					if($fecha>="2021-01-01")
					{$smm0 = substr($stdb,strpos($stdb,'perlas espirituales ha encontrado'),999999999);}
// 					$smm0 = substr($stdb,strpos($stdb,'<strong>Lectura de la Biblia </strong>'),999999999); 
	

					$smm0 = substr($smm0,strpos($smm0,'<li>'),strpos($smm0,'</li>')-strpos($smm0,'<li>')); 
					$smm0 = str_replace('href="','target="_blank" tabindex="-1" href="'.$jworg,$smm0);
 					$smm0 = str_replace('):','):<br>',$smm0);
 					$smm0 = str_replace('<p','<div',$smm0);
 					$smm0 = str_replace('</p','</div',$smm0);
					$smm0 = str_replace('<div','<div tabindex="-1" ',$smm0);
					$smm0 = str_replace('<li','<span',$smm0);
					$smm0 = str_replace('</li','</span',$smm0);

					$smm00=$ssmm;
					$smm1 = substr($smm00,strpos($smm00,'<li>'),strpos($smm00,'</li>')-strpos($smm00,'<li>')); 
					$smm1 = str_replace('href="','target="_blank" tabindex="-1" href="'.$jworg,$smm1);
 					$smm1 = str_replace('):','):<br>',$smm1);
 					$smm1 = str_replace('</a>','</a><br>',$smm1);
 					$smm1 = str_replace(',</a><br>',',</a>',$smm1);
          $smm1 = str_replace('<p','<div',$smm1);
          $smm1 = str_replace('</p','</div',$smm1);
					$smm1 = str_replace('<div','<div tabindex="-1" ',$smm1);

					$smm1 = str_replace('<li','<span',$smm1);
					$smm1 = str_replace('</li','</span',$smm1);

					$smm00=substr($smm00,strpos($smm00,'</li>')+5,$sec4-strpos($smm00,'</li>'));
					$smm2 = substr($smm00,strpos($smm00,'<li>'),strpos($smm00,'</li>')-strpos($smm00,'<li>')); 
					$smm2 = str_replace('href="','target="_blank" tabindex="-1" href="'.$jworg,$smm2);
 					$smm2 = str_replace('):','):<br>',$smm2);
 					$smm2 = str_replace('</a>','</a><br>',$smm2);
 					$smm2 = str_replace(',</a><br>',',</a>',$smm2);
          $smm2 = str_replace('<p','<div',$smm2);
          $smm2 = str_replace('</p','</div',$smm2);
					$smm2 = str_replace('<div','<div tabindex="-1" ',$smm2);

					$smm2 = str_replace('<li','<span',$smm2);
					$smm2 = str_replace('</li','</span',$smm2);

					$smm00=substr($smm00,strpos($smm00,'</li>')+5,$sec4-strpos($smm00,'</li>'));
					$smm3 = substr($smm00,strpos($smm00,'<li>'),strpos($smm00,'</li>')-strpos($smm00,'<li>')); 
					$smm3 = str_replace('href="','target="_blank" tabindex="-1" href="'.$jworg,$smm3);
 					$smm3 = str_replace('):','):<br>',$smm3);
 					$smm3 = str_replace('</a>','</a><br>',$smm3);
          $smm3 = str_replace('<p','<div',$smm3);
          $smm3 = str_replace('</p','</div',$smm3);
					$smm3 = str_replace('<div','<div tabindex="-1" ',$smm3);

					$smm3 = str_replace('<li','<span',$smm3);
					$smm3 = str_replace('</li','</span',$smm3);
	
					$nvc0=$snvc;
					$nvc0 = substr($nvc0,strpos($nvc0,'</li>')+5,999999); 
					$nvct = substr($nvc0,strpos($nvc0,'<strong>'),strpos($nvc0,'</strong>')-strpos($nvc0,'<strong>')+9); 
					$nvc1 = substr($nvc0,strpos($nvc0,'<a href='),strpos($nvc0,'</a')-strpos($nvc0,'<a href=')); 
					$nvc1 = str_replace('href="','target="_blank" tabindex="-1" href="'.$jworg,$nvc1);
					$nvc1 = str_replace('strong','div',$nvc1);
					$nvc1 = str_replace('<div','<div tabindex="-1" ',$nvc1);
					if(strlen($nvct)>20 and !mb_stristr($nvc1,'href=')){$nvc1 = '';}
					if(strlen($nvct)>20){$nvc1 = $nvct.'<br>'.$nvc1;}

					$nvc0 = substr($nvc0,strpos($nvc0,'</li>')+5,999999); 
					$nvct = substr($nvc0,strpos($nvc0,'<strong>'),strpos($nvc0,'</strong>')-strpos($nvc0,'<strong>')+9); 
					$nvc2 = substr($nvc0,strpos($nvc0,'<a href='),strpos($nvc0,'</a')-strpos($nvc0,'<a href=')); 
					if($nvc2=="")
					{$nvc2 = substr($nvc0,strpos($nvc0,'<p '),strpos($nvc0,'</p')-strpos($nvc0,'<p ')+3);}
					$nvc2 = str_replace('href="','target="_blank" tabindex="-1" href="'.$jworg,$nvc2);
					$nvc2 = str_replace('strong','div',$nvc2);
					$nvc2 = str_replace('<div','<div tabindex="-1" ',$nvc2);
					if(strlen($nvct)>20 and !mb_stristr($nvc2,'href=')){$nvc2 = '';}
					if(strlen($nvct)>20){$nvc2 = $nvct.'<br>'.$nvc2;}
	
					$ata0 = $sata;
					$ata1 = substr($ata0,strpos($ata0,'<a'),strpos($ata0,'</a')-strpos($ata0,'<a')); 
					$ata1 = str_replace('href="','target="_blank" href="'.$jworg,$ata1);
					$ata1 = str_replace('strong','div',$ata1);
					$ata1 = str_replace('<div','<div tabindex="-1" ',$ata1);

					$lib0 = $slib;
					$lib1 = substr($lib0,strpos($lib0,'<a'),strpos($lib0,'</a')-strpos($lib0,'<a')); 
					$lib1 = str_replace('href="','target="_blank" href="'.$jworg,$lib1);
					$lib1 = str_replace('strong','div',$lib1);
					$lib1 = str_replace('<div','<div tabindex="-1" ',$lib1);

      $jwib_sql='select * from jwol0 where jwol_fecha="'.$fecha.'"';

//   echo $jwib_sql;
  
  $jwib_res=msql_query($jwib_sql,$link_vcrx);
      if(msql_num_rows($jwib_res)==0)
      {
        $jwib_sql='insert into jwol0(jwol_codigo,jwol_fecha)value("'.$fecha.'","'.$fecha.'")';
        $jwib_res=msql_query($jwib_sql,$link_vcrx);
      }
        $jwib_sql="update jwol0 set ";
        $jwib_sql.="jwol_tdb1='".$tdb1."',";
        $jwib_sql.="jwol_tdb2='".$tdb2."',";
        $jwib_sql.="jwol_nvc1='".$nvc1."',";
        $jwib_sql.="jwol_nvc2='".$nvc2."',";
        $jwib_sql.="jwol_smm0='".$smm0."',";
        $jwib_sql.="jwol_smm1='".$smm1."',";
        $jwib_sql.="jwol_smm2='".$smm2."',";
        $jwib_sql.="jwol_smm3='".$smm3."',";
        $jwib_sql.="jwol_lib1='".$lib1."',";
        $jwib_sql.="jwol_ata1='".$ata1."',";
        $jwib_sql.="jwol_status='-'";
        $jwib_sql.="where jwol_fecha='".$fecha."'";
        $jwib_res=msql_query($jwib_sql,$link_vcrx);

	echo '<br>'.$fecha;
	echo '<br>'.$tdb1;
	echo '<br>'.$tdb2;
	echo '<br>'.$smm0;
	echo '<br>'.$smm1;
	echo '<br>'.$smm2;
	echo '<br>'.$smm3;
	echo '<br>'.$nvc1;
	echo '<br>'.$nvc2;
	echo '<br>'.$lib1;
	echo '<br>'.$ata1;
  
}
}


?>
