<link rel="stylesheet" type="text/css" href="css/style.css">
<svg id="svg-kalendar" height="230" width="320" style="padding-left:50px;">
<style type="text/css">
<![CDATA[
  text.tk_mesic {stroke: grey; fill: black; text-anchor: middle; font-size: 20px;}
  text.tk_d_label, text.tk_d, text.tk_d_so,text.tk_d_ne, text.tk_d_svatek,text.tk_sipky  {-webkit-user-select: none;-moz-user-select: none; -ms-user-select: none; user-select: none;}
  text.tk_d_label, text.tk_d, text.tk_d_so,text.tk_d_ne, text.tk_d_svatek {text-anchor: end;}
  text.tk_d_label {stroke: none; fill: black;  font-size: 12px;}
  text.tk_d, text.tk_d_so,text.tk_d_ne, text.tk_d_svatek {font-size: 16px;}
  text.tk_d {stroke: none; fill: black;}
  text.tk_d_so {stroke: cornflowerblue; fill: blue;}
  text.tk_d_ne {stroke: tomato; fill: red;  }
  text.tk_d_svatek {stroke: crimson; fill: red; }
  text.tk_sipky {cursor: pointer; font-size: 28px;}
  rect.tk_r { cursor: pointer;stroke:none;fill-opacity:0.4;}
  rect.tk_tr{stroke:blue;fill-opacity:0.4;fill:none;stroke-width: 3;}
  .tk_popis {font-weight: bold;}
  #akce {padding-left:50px;}
]]>
</style>
<text class="tk_d_label" x="30" y="60">Po</text>
<text class="tk_d_label" x="60" y="60">Út</text>
<text class="tk_d_label" x="90" y="60">St</text>
<text class="tk_d_label" x="120" y="60">Čt</text>
<text class="tk_d_label" x="150" y="60">Pá</text>
<text class="tk_d_label" x="180" y="60">So</text>
<text class="tk_d_label" x="210" y="60">Ne</text>
<text class="tk_sipky" x="15" y="30"  onclick="kalendar_minus();">«</text>
<text class="tk_sipky" x="195" y="30" onclick="kalendar_plus();">»</text>
</svg>
<div id="akce"></div>
 
<script>   
var yyyy,mm;
var aAkce = new Array();
var aAkce_OK;
var id_view,o_focus;
var today = new Date();
var url_csv = 'https://chess.vstecb.cz/wp-content/uploads/2021/06/kalendar-1.csv';


mm=today.getMonth()+1;
yyyy=today.getFullYear();
aAkce_OK = 0;

loadCSV();

id_view=0;
o_focus=0;
 
svg=document.getElementById('svg-kalendar'); 
mesic = new Array("Leden", "Únor", "Březen", "Duben", "Květen", "Červen", "Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec");

kalendar();

function akce_view(o,id){
 if(o_focus) o_focus.style.stroke = 'none';
 o.style.stroke = 'black';
 o_focus=o;
 if(id_view!=0){
   o=document.getElementById(id_view);
   if(o) o.style.display='none';  
 }
 o=document.getElementById(id);
 if(o) {
   o.style.display='block';
   id_view=id;
 } 
}

function kalendar_minus(){
   mm=mm-1;
   if(mm==0) {mm=12;yyyy=yyyy-1;}
   kalendar();
}

function kalendar_plus(){
   mm=mm+1;
   if(mm==13) { mm=1;
     yyyy=yyyy+1;
   }
   kalendar();
}

         
function removeAllElement(e)  {
  var i;
  for (i = e.length; i > 0 ; i--) {
    e[i-1].remove();
  } }
         
function kalendar() {
  var x,y,e;
  var i,j,s,x;
  var t,dt_od, dt_do;
  var aDny, dOd, dDo;
  var iAkce;
  var h;
  var dd;
  var aColor = ["blue", "deeppink", "green", "red", "black"];
  var iColor;

  aDny = new Array(31);
  for(i=0;i<=31;i++) aDny[i]='';
  lmm=mm-1;

  e = document.getElementsByClassName("tk_d");  removeAllElement(e);
  e = document.getElementsByClassName("tk_d_so");  removeAllElement(e);
  e = document.getElementsByClassName("tk_d_ne");  removeAllElement(e);
  e = document.getElementsByClassName("tk_d_svatek");  removeAllElement(e);
  e = document.getElementsByClassName("tk_mesic");  removeAllElement(e);
  e = document.getElementsByClassName("tk_r");  removeAllElement(e);
  e = document.getElementsByClassName("tk_tr");  removeAllElement(e);

  createText(113,30,mesic[lmm]+' '+yyyy,'tk_mesic', svg);

  iColor=0;
  t='';
  for(iAkce=0;iAkce<aAkce.length;iAkce++){
     dt_od=aAkce[iAkce][1].split(".");
     s=aAkce[iAkce][2];
     if(s=='') s=aAkce[iAkce][1];
     dt_do=s.split(".");
     if(parseInt(dt_do[1])!=mm)  dt_do[0]=31;
   
     if((parseInt(dt_od[1])==mm && parseInt(dt_od[2])==yyyy) || (parseInt(dt_do[1])==mm && parseInt(dt_do[2])==yyyy)){
       dOd=parseInt(dt_od[0]);
       dDo=parseInt(dt_do[0]);
       if(dDo=='') dDo=dOd;
       for(i=dOd;i<=dDo;i++){
          if(aDny[i]!='') aDny[i]=aDny[i]+';';
          aDny[i]=aDny[i]+iAkce.toString(); 
       }
       
       aAkce[iAkce][0]=aColor[iColor];
       if(iColor==aColor.length)iColor=0; else iColor=iColor+1;
 
       t=t+'<fieldset id="'+iAkce+'" style="display:none; width:320px;">';
       t=t+'<legend>'+aAkce[iAkce][3]+'</legend>';
       t=t+'<table style="width:320px;">';
       t=t+'<tr><td><span class="tk_popis">Název:</span></td><td>'+aAkce[iAkce][3]+'</td></tr>';
       t=t+'<tr><td><span class="tk_popis">Místo:</span></td><td>'+aAkce[iAkce][4]+'</td></tr>';
       t=t+'<tr><td><span class="tk_popis">Datum:</span></td><td>'+aAkce[iAkce][1];
       if(aAkce[iAkce][2]!='') t=t+' - '+aAkce[iAkce][2];    
       t=t+"</td></tr>";
       
       t=t+'<tr><td><span class="tk_popis">Druh:</span></td><td>'+aAkce[iAkce][5]+'</td></tr>';
       t=t+'<tr><td colspan="2">'+aAkce[iAkce][6]+'</td></tr>';
       t=t+'</table>';
       t=t+'</fieldset>';
     }     
  }
  
  document.getElementById("akce").innerHTML=t;
  x=30; 
  y=84;
  
  var d = new Date(yyyy, lmm, 1);
  s='';
  while(d.getMonth()==lmm) {
    i=d.getDay();
    i=i-1;
    if(i==-1) i=6;
    s='tk_d';
    if(i==5) s='tk_d_so';
    if(i==6) s='tk_d_ne';
    if(is_svatek(d)==true) s='tk_d_svatek';
    
    createText(x+i*30,y,d.getDate(),s, svg);
    
    dd=d.getDate();
    if(aDny[(dd)]!='') {
      a=aDny[(dd)].split(";");
      h=Math.floor(22/a.length);
      for(j=0;j<a.length;j++) {
         //alert(a[j]);
         iAkce=parseInt(a[j]);
         createRect((x+(i*30))-30/2-7,y-13-3+(j*h),(30-3),(h-1),'class=tk_r onclick=akce_view(this,'+iAkce+'); style=fill:'+aAkce[iAkce][0]+'; rx=3 ry=3',aAkce[iAkce][3],svg);       
      }

    }
    if(d.getFullYear()==today.getFullYear() && d.getMonth()== today.getMonth() && d.getDate()==today.getDate()) createRect((x+(i*30))-30/2-6,y-13-2,25,19,'class=tk_tr rx=3 ry=3','',svg);       
    if(i==6) y=y+26;
    d.setDate(d.getDate() + 1);
  }
}                  

function createText(x,y,text,cls,svg) {
  var e = document.createElementNS('http://www.w3.org/2000/svg',"text");
  e.setAttributeNS(null,"x",x);      
  e.setAttributeNS(null,"y",y);
  e.setAttributeNS(null,"class",cls);
  var textNode = document.createTextNode(text);
  e.appendChild(textNode);
  svg.appendChild(e);
  return e;
}

function createRect(x,y,w,h,attr,text,svg) {
  var a,aa,i;
  var e = document.createElementNS('http://www.w3.org/2000/svg',"rect");
  e.setAttributeNS(null,"x",x);      
  e.setAttributeNS(null,"y",y);
  e.setAttributeNS(null,"width",w);      
  e.setAttributeNS(null,"height",h);
  if(attr!=''){
    a=attr.split(' ');
    for(i=0;i<a.length;i++){
      aa=a[i].split("=");
      e.setAttributeNS(null,aa[0],aa[1]);
    }
  }
  var ee = document.createElementNS('http://www.w3.org/2000/svg',"title");
  ee.textContent = text;
  e.appendChild(ee);
  svg.appendChild(e);
  return e;
}


function is_svatek(datum) {
  var s,d,f;
  var vn, vpo, vpa;
  s='0'+(datum.getMonth()+1);
  d=s.substr(-2,2);
  s='0'+datum.getDate();
  d=d+s.substr(-2,2);

  f = false;
  if(d == "0101") f = true;
  if(d == "0501") f = true;
  if(d == "0508") f = true;
  if(d == "0705") f = true;
  if(d == "0706") f = true;
  if(d == "0928") f = true;
  if(d == "1028") f = true;
  if(d == "1117") f = true;
  if(d == "1224") f = true;
  if(d == "1225") f = true;
  if(d == "1226") f = true;
  if((!f) && (d.substr(0,2)=='03' ||  d.substr(0,2)=='04')) {
    vn=velikonoce_nedele(datum.getFullYear());
    vn.setDate(vn.getDate()-2);
    if(datum.getTime()==vn.getTime()) f=true;
    vn.setDate(vn.getDate()+3);
    if(datum.getTime()==vn.getTime()) f=true;
  }
  return f;
}  

function velikonoce_nedele(rok)  {
  var a, bc,k,p,q,m,N,d;
  var vn;
  
  a = rok % 19;
  bc = (rok + Math.floor(rok / 4 )) % 7;
  k =  Math.floor(rok / 100);
  p = Math.floor((13 + 8 * k) / 25);
  q = Math.floor(k / 4);
  m = 15 - p + k - q;
  n = 4 + k - q;
  d = (19 * a + m) % 30;
  if(d==28 && a>10) d = d - 1;
  if(d==29) d = d - 1;
  e = (35 + n - bc - d) % 7
  if((d + e + 22) < 32) vn = new Date(rok, 2 , (d + e + 22)); else vn=new Date(rok, 3,  (d + e - 9));
  
  return vn;
}

function loadCSV() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      loadCSV_OK(this);
    }
  };
//  xhttp.open("GET", "kalendar.csv", false);
  xhttp.open("GET", url_csv, false); 
//  xhttp.open("GET", "http://2020-n10-17/intranet/kalendar.csv", false);
                                                                
  xhttp.send();
}

function loadCSV_OK(xhttp) {
  var csv = xhttp.responseText;
  var aRadky;
  var i,a;
  var msg; 
 
 msg='';
  aRadky=csv.split(String.fromCharCode(13)+String.fromCharCode(10));
  for(i=0;i<aRadky.length;i++){
     a=aRadky[i].split(';');
     msg=msg+'i='+i+String.fromCharCode(10);
     aAkce.push(a);
  }  
  aAkce_OK=1;
}


</script>
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/themes/sachy/functions.php:257) in <b>/var/www/html/wp-includes/rest-api/class-wp-rest-server.php</b> on line <b>1648</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/themes/sachy/functions.php:257) in <b>/var/www/html/wp-includes/rest-api/class-wp-rest-server.php</b> on line <b>1648</b><br />
{"id":283,"date":"2015-11-11T12:31:35","date_gmt":"2015-11-11T11:31:35","guid":{"rendered":"http:\/\/chess.vstecb.cz\/?page_id=283"},"modified":"2016-08-17T09:01:36","modified_gmt":"2016-08-17T08:01:36","slug":"kalendar-akci","status":"publish","type":"page","link":"https:\/\/chess.vstecb.cz\/index.php\/kalendar-akci\/","title":{"rendered":"Kalend\u00e1\u0159"},"content":{"rendered":"\n<p><!-- \/* 15pJQhrPh3XJCUOiaQCa62html *\/ --><!-- 5kAUy7LUT6 --><!-- \/* 1uqjsQSyWVhmOHAEVa1i62html *\/ --><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/chess.vstecb.cz\/index.php\/wp-json\/wp\/v2\/pages\/283"}],"collection":[{"href":"https:\/\/chess.vstecb.cz\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/chess.vstecb.cz\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/chess.vstecb.cz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chess.vstecb.cz\/index.php\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":404,"href":"https:\/\/chess.vstecb.cz\/index.php\/wp-json\/wp\/v2\/pages\/283\/revisions"}],"predecessor-version":[{"id":3611,"href":"https:\/\/chess.vstecb.cz\/index.php\/wp-json\/wp\/v2\/pages\/283\/revisions\/3611"}],"wp:attachment":[{"href":"https:\/\/chess.vstecb.cz\/index.php\/wp-json\/wp\/v2\/media?parent=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}