";} function ep($a){global $ep;if($ep)echo $a."
";} $ok=true; if(isset($_POST["frompwd"]) && htmlspecialchars($_POST["frompwd"]) == "Submit" && strtolower(htmlspecialchars($_POST["pwd"])) != "colin geary") { echo "Password incorrect"; $ok=false; } if (isset($_POST['frompwd']) && htmlspecialchars($_POST["frompwd"]) == "Submit" && strtolower(htmlspecialchars($_POST["pwd"])) == "colin geary")$editit=true; else $editit=false; if (isset($_POST['initialedit']) && htmlspecialchars($_POST["initialedit"]) == "yes") $editit=true; if($editit) { if(isset($_GET['benefice']))$bfname=htmlspecialchars($_GET["benefice"]); else $bfname=htmlspecialchars($_POST["benefice"]);$fname=$bfname.".txt"; if(file_exists("xxvvcew".$fname))unlink("xxvvcew".$fname);else if(isset($_POST['initialedit']) && htmlspecialchars($_POST["initialedit"]) != "yes" && isset($_POST['edit']) && htmlspecialchars($_POST["edit"]) != "check")die("Sorry, you can't edit, someone is currently editing ".$fname); } if($editend) { //This is a check of the existance of a file which should not exist if this was in editing mode. it is a CANCEL editing to release the key for others if(isset($_GET['benefice']))$bfname=htmlspecialchars($_GET["benefice"]); else $bfname=htmlspecialchars($_POST["benefice"]);$fname=$bfname.".txt"; if(!file_exists("xxvvcew".$fname)) { $ss=fopen("xxvvcew".$fname,"w"); fclose($ss); } } if(isset($_GET['benefice']))$bfname=htmlspecialchars($_GET["benefice"]); else $bfname=htmlspecialchars($_POST["benefice"]);$fname=$bfname.".txt"; if($e)echo '72 ok='.$ok.' bfname='.$bfname.' fname='.$fname.'
'; if ($ok) { ?>
' name="benefice"> "; $getdata = $_SERVER['QUERY_STRING']; ep('getdata='.$getdata); $printout=false; $noentry=false; $firsttime=true; $bfname=htmlspecialchars($_GET["benefice"]);$fname=$bfname.".txt"; $ss=fopen($fname,"w") or die("Unable to open file ".$fname); fputs($ss,$getdata); fclose($ss); } if ($_SERVER['REQUEST_METHOD'] === 'POST')if(htmlspecialchars($_POST["frompwd"]) != "Submit" || htmlspecialchars($_POST["initialedit"]) == "yes" ) { //this is from the this program so save it // this is about stopping editing if(isset($_GET['benefice']))$bfname=htmlspecialchars($_GET["benefice"]); else $bfname=htmlspecialchars($_POST["benefice"]);$fname=$bfname.".txt"; if(!file_exists("xxvvcew".$fname)) { $ss=fopen("xxvvcew".$fname,"w"); fclose($ss); } $postdata = file_get_contents("php://input"); $printout=true; $noentry=false; if(isset($_GET['benefice']))$bfname=htmlspecialchars($_GET["benefice"]); else $bfname=htmlspecialchars($_POST["benefice"]);$fname=$bfname.".txt"; $ss=fopen($fname,"r") or die("Unable to open file ".$fname); $qqs=str_replace("\r","",str_replace("\n","",fgets($ss))); fclose($ss); $ss=fopen($fname,"w") or die("Unable to open file ".$fname); fputs($ss,$qqs."\n"); //fputs($ss,$qqs); fputs($ss,$postdata); fclose($ss); } if ($bfname != "") { //we now read the first line in ee('Line 134'); $noentry=false; if(isset($_GET['benefice']))$bfname=htmlspecialchars($_GET["benefice"]); else $bfname=htmlspecialchars($_POST["benefice"]);$fname=$bfname.".txt"; $ss=fopen($fname,"r") or die("Unable to open file ".$fname); $qqs=str_replace("%0A",chr(10),str_replace("%0D",chr(13),str_replace("+"," ",fgets($ss)))); if (!feof($ss))$fm=str_replace("%0A",chr(10),str_replace("%0D",chr(13),str_replace("+"," ",fgets($ss)))); else $fm=""; fclose($ss); } if (isset($_GET["hymnhelp"]) && htmlspecialchars($_GET["hymnhelp"]) != "") $hymnhelp=true; else $hymnhelp=false; if (isset($_GET["edit"]) && htmlspecialchars($_GET["edit"]) != "" || $editit) $printout=false; if (isset($_GET["all"]) && htmlspecialchars($_GET["all"]) == "true") $all=true;else $all=false; if (isset($_GET["autoalloc"]) && htmlspecialchars($_GET["autoalloc"]) == "random") $dorandom=true; else $dorandom=false; if (isset($_GET["autoalloc"]) && htmlspecialchars($_GET["autoalloc"]) == "sequence") $dosequence=true; else $dosequence=false; if (isset($_GET["autoalloc"]) && htmlspecialchars($_GET["autoalloc"]) == "mixed") $domixed=true; else $domixed=false; if (isset($_GET["autoalloc"]) && htmlspecialchars($_GET["autoalloc"]) == "no") $autoalloc=false; else $autoalloc=true; if (isset($_GET["autoalloc"]) && htmlspecialchars($_GET["autoalloc"]) == "no")$autoalloc=false; else $autoalloc=true; if (!$noentry) { $colours=['Xmas'=>'yellow','Epip'=>'white','Palm'=>'red','Ress'=>'yellow','East'=>'white','Prop'=>'green','Lent'=>'purple','Tran'=>'red','Advt'=>'purple','Trin'=>'yellow','PDay'=>'red','Pres'=>'yellow']; $osdates=array(); $hymns=array(); $seq=array(); //seq(10,10) for ($i=1; $i<=10; $i++)for ($j=1; $j<=10; $j++)$seq[$i][$j]=1; function nearlyequal($a, $b) { $_retval=false; if ($a == $b) { $_retval=true; } else { $x=_instrrev($a,"-",0); if ($x > 0)if (substr($a,0,$x-2) == substr($b,0,$x-2))$_retval=true; } return $_retval; } function vvx($a) { return vv($a); } function vv($a) { $stt=""; $lastat=1; $a=str_replace("%0D%0A"," ",$a); $a=str_replace("+"," ",$a); $at=_instr(0,$a,"%",0); while ($at != 0) { $stt.=substr($a,$lastat-1,$at-$lastat); $c1=substr($a,$at,1); $c2=substr($a,($at + 1),1); if ($c1 >= "A")$x1=(ord($c1)-ord("A") + 10); else $x1=ord($c1)-ord("0"); if ($c2 >= "A")$x2=(ord($c2)-ord("A") + 10); else $x2=ord($c2)-ord("0"); $stt.=chr($x1 * 16 + $x2); $lastat=($at + 3); if($lastat<=strlen($a))$at=_instr($lastat,$a,"%",0);else $at=0; } $stt.=substr($a,($lastat - 1)); $_retval=$stt; return $_retval; } function refmx($wwq, $z, $colum) { global $firsttime, $zpcount, $znumber, $autoalloc, $dorandom, $domixed, $zpeople, $zpcount, $used, $usedsofar, $dosequence, $domixed, $seq; $uuu=0; if ($colum > 0 && $firsttime && $zpcount[$wwq][$colum] >= $znumber[$wwq][$colum] && $autoalloc) { $choice=(float)mt_rand(0,99)/100.0; if ($dorandom || ($domixed && $choice < 0.5)) { $doneit=false; while (!$doneit) { $_retval=$zpeople[$wwq][$colum][(int)((float)mt_rand(0,99)/100.0 * $zpcount[$wwq][$colum]) + 1]; $doneit=true; for ($o=1; $o<=$usedsofar; $o++)if ($_retval == $used[$o])$doneit=false; } $used[($usedsofar + 1)]=$_retval; $usedsofar++; } else { if ($dosequence || ($domixed && $choice > 0.5)) { $doneit=false; while (!$doneit) { $_retval=$zpeople[$wwq][$colum][$seq[$wwq][$colum]]; $seq[$wwq][$colum]++; if ($seq[$wwq][$colum] > $zpcount[$wwq][$colum])$seq[$wwq][$colum]=1; $doneit=true; if($domixed)for ($o=1; $o<=$usedsofar; $o++)if ($_retval == $used[$o])$doneit=false; } $used[($usedsofar + 1)]=$_retval; $usedsofar++; } } } else { $_retval=refm($z); } return $_retval; } function rqqqsn($z, $i) { global $qqs; //this gets the ith occurrance of z $b=0; for ($x=1; $x<=$i; $x++) { if ($b == 0 && substr($qqs,0,(strlen($z) + 1)) == $z."=") { $b=1; } else { $b=_instr(($b + 1),$qqs,"&".$z."=",0); if ($b == 0)$x=$i; else $b++; } } if ($b != 0) { $b+=strlen($z) + 1; $a=_instr($b,$qqs,"&",0); if ($a == 0)$a=strlen($qqs) + 1; $_retval=substr($qqs,$b-1,$a-$b); } else { $_retval=""; } return $_retval; } function rqqqs($z) { global $qqs;global $b; if (substr($qqs,0,strlen($z) + 1) == $z."=") { $b=1; } else { $b=_instr($b + 1,$qqs,"&".$z."=",0); if ($b != 0)$b++; } if ($b != 0) { $b+=strlen($z) + 1; $a=_instr($b,$qqs,"&",0); if ($a == 0)$a=(strlen($qqs) + 1); $_retval=substr($qqs,$b-1,$a-$b); } else { $_retval=""; } return $_retval; } function rqqqscn($cnumber, $z) { global $qqs; //cnumber is 1 after the first churchname= 2 after the second etc. it returns true if there is &z= between the two $cn=$cnumber; $at=_instr(1,$qqs,"churchname=",0); $cn--; While($cn>0 && $at>0) { $at=_instr($at+1,$qqs,"churchname=",0); $cn--; } if ($at > 0) { $atend=_instr($at + 1,$qqs,"churchname=",0); if ($atend == 0)$atend=strlen($qqs); $place=_instr($at,$qqs,'&'.$z.'=',0); if ($place < $atend && $place > 0)$_retval=true; else $_retval=false; } else { $_retval=false; } return $_retval; } function refm($z) { global $fm,$firsttime; $b=0; if (substr($fm,0,strlen($z) + 1) == $z.'=')$b=1; else $b=_instr(0,$fm,'&'.$z.'=',0); if ($b != 0) { $b+=strlen($z) + 1; $a=_instr($b,$fm,"&",0); if ($a == 0)$a=strlen($fm) + 1; $_retval=substr($fm,$b,$a-$b-1); } else { $_retval=""; } return $_retval; // } } function refmcb($z) { global $firsttime,$fm,$i; $b=0; if ($firsttime) { $_retval="checked"; } else { if (substr($fm,0,strlen($z) + 1) == $z."=")$b=1;else $b=_instr($b + 1,$fm,"&".$z."=",0); if ($b != 0) { $b+=strlen($z) + 1; $a=_instr($b,$fm,"&",0); if ($a == 0)$a=strlen($fm) + 1; $_retval=substr($fm,$b,$a-$b-1); } else { $_retval=""; } } return $_retval; } function coded($i) { global $sundaydate,$sundaycode; if(gettype($sundaydate[$i])!="object")die("Line 362 i=".$i); $_retval="x".str_replace("/","x",date_format($sundaydate[$i],"d/m/Y")."x".$sundaycode[$i]); return $_retval; } function addaline($d, $ddate, $dname, $dcode, $festr, $servicet,$strq) { global $sundaydate,$sundaycode,$sundayname,$freadings,$j,$servicetype,$strequired; ee('391 Addaline:'.$d.' '.$dname); $di=200; while(_year($sundaydate[$di]) < 2000) $di--; ee('394 Adding a line at '.$di.'
'); for ($dii=$di; $dii>=($d + 1); $dii--) { $sundaydate[($dii + 1)]=$sundaydate[$dii]; if(isset($sundayname[$dii]))$sundayname[($dii + 1)]=$sundayname[$dii];else $sundayname[($dii+1)]=''; if(isset($sundaycode[$dii]))$sundaycode[($dii + 1)]=$sundaycode[$dii];else $sundaycode[($dii+1)]=''; if(isset($freadings[$dii]))$freadings[($dii + 1)]=$freadings[$dii];else $freadings[($dii+1)]=''; if(isset($servicetype[$dii]))$servicetype[($dii+1)]=$servicetype[$dii];else $servicetype[($dii+1)]=''; if(isset($strequired[$dii]))$strequired[($dii+1)]=$strequired[$dii];else $strequired[($dii+1)]=''; } $sundaydate[($d+1)]=$ddate; $sundayname[($d+1)]=$dname; $sundaycode[($d+1)]=$dcode; $freadings[($d+1)]=$festr; $servicetype[($d+1)]=$servicet; $strequired[($d+1)]=$strq; $j++; } $h4o=array(); function buildhymnlist($bb, $weekno) { // bb is the reading and bbcode is the sunday code global $themedone,$oremusentry,$hymnreading,$hymns,$noh,$hymnstr,$called,$nooremus,$h4o,$sundaycode; $regex="/^(\d\s)?([A-Za-z\s]*\s\(?\d+:)\(?(\d+[abc]?((\s\-\s\d+:\d+[abc]?)|(\-\d+[abc]?))?)\)?(,\s\(?((\d+:)?\d+[abc]?\-\d+[abc]?)\)?)*/"; $matches=array(); $nomatches=preg_match_all ($regex, $bb, $matches); $h4o[$weekno].=$matches[1][0].$matches[2][0].preg_replace("/(\d)[abc]/","$1",$matches[3][0])."$"; if($matches[8][0].length>0)$h4o[$weekno].=$matches[1][0].$matches[2][0].preg_replace("/(\d)[abc]/","$1",$matches[8][0])."$"; $bbcode=$sundaycode[$weekno]; $called++; $hr=array(); $nn=array(); $xhlist=""; $xx=explode(" ",$bb); $hr[1]=$bb; $qsofar=1; if (_instr(0,$hr[1],"(",0) > 0) { $xx=explode(":",str_replace("(","",str_replace(")","",$hr[1]))); $v=explode("-",$xx[1]); $qat=1; for ($q=0; $q<=count($v)-1; $q++) { if (_instr(0,$v[$q],", ",0) > 0) { $zz=explode(", ",$v[$q]); $nn[$qat]=$zz[0]; $nn[$qat + 1]=$zz[1]; $qat+=2; } else { $nn[$qat]=$v[$q]; $qat++; } } for ($q=1; $q<=$qat-2; $q++) { for ($q1=($q + 1); $q1<=$qat-1; $q1++) { $hr[$qsofar + 1]=$xx[0].":".$nn[$q]."-".$nn[$q1]; $qsofar++; } } } //********************************************************* //Is this checking the whole reading as well as the bits? //********************************************************* $done=false; for ($q=1; $q<=$qsofar; $q++) { for ($p=1; $p<=$nooremus; $p++) { if (nearlyequal($hr[$q], $hymnreading[$p]) || $bbcode == $hymnreading[$p]) { ep('******** bbcode='.$bbcode.' hr(q)='.$hr[$q].' q='.$q.' p='.$p.' hymnreading(p)='.$hymnreading[$p].' bb=!'.$bb.'
'); $xx=explode('$',$oremusentry[$p]); if ($bbcode == $hymnreading[$p]) { $additem='Theme'; if (!$themedone)$hymnstr=$hymnstr.'$Theme$'.substr($oremusentry[$p],_instr(0,$oremusentry[$p],'$',0),strlen($oremusentry[$p])-(2+_instr(0,$oremusentry[$p],'$',0))); $themedone=true; } else { $u=substr($hr[$q],0,1); $additem=$hymnreading[$p]; $hymnstr=$hymnstr.'$'.$additem.'$'.substr($oremusentry[$p],_instr(0,$oremusentry[$p],'$',0),strlen($oremusentry[$p])-(2+_instr(0,$oremusentry[$p],'$',0))); } for ($g=1; $g<=count($xx)-1; $g++) { if ($hymns[$xx[$g]] == "") { $hymns[$xx[$g]]=$additem; $noh++; } else { if (_instr(0,$hymns[$xx[$g]],$additem,0) == 0)$hymns[$xx[$g]]=$hymns[$xx[$g]].",".$additem; } } $done=true; } } } } function _day($_r){if(gettype($_r)!="object")$_xx=date_create($_r); else $_xx=$_r; return date_format($_xx,"j");} function _dayofyear($_r){if(gettype($_r)!="object")$_xx=date_create($_r); else $_xx=$_r; return date_format($_xx,"z");} function _year($_r){if(gettype($_r)!="object")$_xx=date_create($_r); else $_xx=$_r; return date_format($_xx,"Y");} function _weekday($_r){if(gettype($_r)!="object")$_xx=date_create($_r); else $_xx=$_r; return date_format($_xx,"w");} function _month($_r){if(gettype($_r)!="object")$_xx=date_create($_r); else $_xx=$_r; return date_format($_xx,"n");} function stfdate($_r){if(gettype($_r)!="object")$_xx=date_create($_r); else $_xx=$_r; return date_format($_xx,"Ymd");} function hymnarydate($_r) {if(gettype($_r)!="object")$_xx=date_create($_r); else $_xx=$_r; return date_format($_xx,"n/j/Y");} function _colour($i) { global $colours,$sundaycode,$sundayname; if(isset($sundayname[$i]) && is_numeric(strpos($sundayname[$i],'Lent-'))) { $www='green'; } else { if(isset($sundaycode[$i]) && $sundaycode[$i]!='') { if($sundaycode[$i][0]=='A'||$sundaycode[$i][0]=='B'||$sundaycode[$i][0]=='C')$www=$colours[substr($sundaycode[$i],1,4)]; else $www=$colours[substr($sundaycode[$i],0,4)]; } else { $www='white'; } } return $www; } function _date_add($_a,$_b) { global $e; if($e)echo '534 '.gettype($_a)." ".gettype($_b)."
"; if(gettype($_a)!="object")$_xxa=date_create($_a); else $_xxa= clone $_a; $_xxb=date_interval_create_from_date_string($_b); date_add($_xxa,$_xxb); return $_xxa; } function _date_diff($_a,$_b) { if(gettype($_a)!="object")$_xxa=date_create($_a); else $_xxa=$_a; if(gettype($_b)!="object")$_xxb=date_create($_b); else $_xxb=$_b; return date_diff($_xxa,$_xxb)->format("%R%a"); } function _date_diff_nosn($_a,$_b) { if(gettype($_a)!="object")$_xxa=date_create($_a); else $_xxa=$_a; if(gettype($_b)!="object")$_xxb=date_create($_b); else $_xxb=$_b; return date_diff($_xxa,$_xxb)->format("%a"); } function sundayinmonth($sdate) { if (gettype($sdate)=="object")if(_year($sdate)>2000 && _weekday($sdate) == 0 && !(_day($sdate) == 25 && _month($sdate) == 12))$_retval=(int)((_day($sdate)-1) / 7) + 1; else $_retval=0; return $_retval; } //END IF FUNCTIONS ee("562 End of Functions"); $extraservice=array(); $i=1; $bz=rqqqsn("extra",$i); while($bz!="") { $extraservice[$i]=$bz; if($e)echo '569 '."










".$extraservice[$i]."
"; $i++; $bz=rqqqsn("extra",$i); } $noextraservices=$i-1; $nchs=rqqqs("nochurches"); ee('575 nochurches from qqs='.$nchs); if ($nchs != "")$nochurches=intval($nchs); else $nochurches=1; $nchs=rqqqs("nochurches");$churchname=array(); $dochurchweek=array(); $churchbible=array(); $printpartial=0; ee("Line 581"); for ($i=1; $i<=$nochurches; $i++) { $churchname[$i]=rqqqsn("churchname", $i); $churchbible[$i]=rqqqsn("churchbible", $i); if(isset($_GET["edit"]) && is_numeric($_GET["edit"])) if (intval($_GET["edit"]) == $i)$printpartial=$i; for ($j=1; $j<=5; $j++)if (rqqqscn($i,'s'.$j))$dochurchweek[$i][$j]=true; else $dochurchweek[$i][$j]=false; } ee("Line 589"); if ($printpartial > 0)$dsbld="disabled"; else $dsbld=""; $benefice=$bfname; ?>


") if ($qs == "")$datex=clone $now; else $datex=date_create("1-".$qs); //response.write(datex&"
") $lmonth=array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $zzyear=_year($datex); if (_month($datex) > 2) $zzyear++; if ((int)($zzyear / 4) == $zzyear / 4)$lmonth[1]=29; //response.write(lmonth(0)&" "&lmonth(1)&"

") $howmanymonths=intval(rqqqs("howmanymonths")); if (rqqqs("gospelatend") == "yes")$gospelatend=true; if (rqqqs("psalms") == "yes")$psalms=true; $qs=rqqqs("readings"); $continuous=true; $related=true; ee("Line 609"); if ($qs == "related") { $continuous=false; } else { if ($qs == "continuous")$related=false; } ?>

Two month listExtended listHelp with hymnsRemove Hymn HelpEdit (password required)
"; if ($qs != "") { $zh=explode(chr(13).chr(10),$qs); $nocols[$q]=count($zh); ee('646 q='.$q.' nocols[q]='.$nocols[$q]); for ($cccol=0; $cccol<=$nocols[$q]-1; $cccol++) { $zheadings[$q][$cccol]=$zh[$cccol]; if($e)echo '650 '.$zheadings[$q][$cccol]."--"; } if($e)echo '652
'; } else { $nocols[$q]=0; } } ee("Line 659"); $znumber=array(); $zpcount=array(); $zpeople=array(); //in each of these the first index is the church, second is the heading, third is the person for ($q=1; $q<=$nochurches; $q++) { for ($cccol=1; $cccol<=$nocols[$q]; $cccol++) { $zheadings[$q][$cccol-1]=trim($zheadings[$q][$cccol-1]); if (is_numeric(substr($zheadings[$q][$cccol-1],0,1))) { $znumber[$q][$cccol-1]=intval(substr($zheadings[$q][$cccol-1],0,1)); //echo "662. ".$cccol.'('.$znumber[$q][$cccol-1].')
'; $zheadings[$q][$cccol-1]=trim(substr($zheadings[$q][$cccol-1],1)); } else { $znumber[$q][$cccol-1]=1; } $zp=explode(" ",$zheadings[$q][$cccol-1]); for ($o=1; $o<=count($zp)-1; $o++)$zpeople[$q][$cccol-1][$o]=$zp[$o]; $zpcount[$q][$cccol-1]=count($zp)-1; $zheadings[$q][$cccol-1]=$zp[0]; } } echo "

"; $easterletter=array(); $easterdate=array(); $easterinstream=fopen("easter.txt","r") or die("Unable to open file easter.txt"); $i=1; while (! feof($easterinstream)) { $x=fgets($easterinstream); $xx=explode("$",$x); $easterletter[(int)trim($xx[0])-2000]=trim($xx[1]); $easterdate[(int)trim($xx[0])-2000]=trim($xx[2]); $i++; } fclose($easterinstream); $noeasters=$i-1; $hymnname=array(); $hymnnameetc=array(); $hymnmap=array(); $htname=array(); $hymnnamestpd=array(); $htcount[1]=0; $htcount[2]=0; $htcount[3]=0; $ht[1]="*"; $ht[2]="#"; $ht[3]="&"; $htname[1]="New"; $htname[2]="Popular A-L"; $htname[3]="Popular M-Z"; $htname[4]="Starter"; $htname[5]="Carols"; $htname[6]="Easter"; $htname[7]="Advent"; $htname[8]="Harvest"; $hymninstream=fopen("metahymntitlesandmatrixandpref.txt","r") or die("Unable to open file easter.txt"); $i=1; $hx=fgets($hymninstream); //header $hymnbook=explode("$",$hx); $hymnnameetc[0]='';// added while (!feof($hymninstream)) { $hx=fgets($hymninstream); $hymnnameetc[$i]=$hx; $vxv=explode("$",$hx); $hymnname[$i]=$vxv[0]; $hymnnamestpd[$i]=trim(str_replace("'","",str_replace('"','',$vxv[0]))); //added this above, not got it right but tried! for($j=1;$j<=count($vxv)-1;$j++)$hymnmap[$i][$j]=$vxv[$j]; $i++; } $nohymnbooks=count($vxv)-1-1; fclose($hymninstream); $nohymns=$i-1; $australia=array(); $auscode=array(); $ausinstream=fopen("australia.txt","r") or die("Unable to open file australia.txt"); $i=1; while (!feof($ausinstream)) { $x=fgets($ausinstream); $xx=explode("$",$x); $australia[$i]=trim($xx[0]); $auscode[$i]=trim($xx[1]); $i++; } fclose($ausinstream); $noaus=$i-1; $hymnreading=array(); $oremusentry=array(); $oremusinstream=fopen("oresmusmetahymn.txt","r") or die("Unable to open file oremusmetahymn.txt"); $i=1; while (!feof($oremusinstream)) { $x=fgets($oremusinstream); $oremusentry[$i]=$x; $xx=explode("$",$x); $hymnreading[$i]=trim($xx[0]); $i++; } fclose($oremusinstream); $nooremus=$i-1; $festname=array(); $festdate=array(); $festreadings=array(); $festinstream=fopen("festivals.txt","r") or die("Unable to open file festivals.txt"); $i=1; while (!feof($festinstream)) { $x=fgets($festinstream); $xx=explode("$",$x); $festname[$i]=trim($xx[0]); $festdate[$i]=date_create(trim($xx[1])." 2000"); $z=trim($xx[2]); $zz=explode("%",$z); $festreadings[$i]=""; for ($q=0; $q<=count($zz)-1; $q++)$festreadings[$i]=$festreadings[$i].$zz[$q]."
"; $i++; } fclose($festinstream); $nofests=$i-1; $RCLreading=array(); $RCLdate=array(); $alternative=array(); $newtestament=array(); $rclinstream=fopen("rcl.txt","r") or die("Unable to open file RCL.txt"); $nt=false; $i=1; while (!feof($rclinstream)) { $x=fgets($rclinstream); $xx=explode("$",$x); if (strlen($xx[0]) == 0) { $RCLreading[$i]=$RCLreading[$i-1]; $newtestament[$i]=$nt; } else { $RCLreading[$i]=trim($xx[0]); if (substr($xx[0],0,7) == "Matthew") $nt=true; //If we have hit Matthew the rest are nt=true $newtestament[$i]=$nt; } $RCLdate[$i]=trim($xx[1]); if (count($xx)-1 > 1)$alternative[$i]=true; else $alternative[$i]=false; $i++; } fclose($rclinstream); $noRCLs=$i-1; $themeref=array(); $theme=array(); $thinstream=fopen("themes.txt","r") or die("Unable to open file themes.txt"); $i=1; while (!feof($thinstream)) { $x=fgets($thinstream); if (substr($x,0,12) != "Mark chapter" && substr($x,0,12) != "Luke chapter" && substr($x,0,12) != "John chapter" && substr($x,0,15) != "Matthew chapter") { $xx=explode(".",$x); $themeref[$i]=trim($xx[0]); $theme[$i]=trim($xx[1]); } $i++; } fclose($thinstream); $noths=$i-1; //Set up array //Get one year of sundays dates $sundaydate=array(); for($i=0;$i<=300;$i++)$sundaydate[$i]=date_create('1-1-1999'); $sundayname=array(); $sundaycode=array(); $freadings=array(); $servicetype=array(); $strequired=array(); for($i=0;$i<=300;$i++){$servicetype[$i]='';$strequired[$i]="";} //firstsunday is the sunday in the first week of december before the current date //easter(0) is the date of easter for the liturgical year including the current date, unless the current date is after it, in which case it is the easter date the forthcoming easter //The list starts at advent year 0 and goes to the end of ordinary year 2, the selection is then made from that $datex->modify("-1 years"); ee("Line 852"); //setup the sundaydate array outside main loop so that there are no gaps $advent4=_date_add("24-dec-"._year($datex),(-_weekday("24-dec-"._year($datex))).' days') ; $firstsunday=_date_add($advent4,"-28 days"); //first sunday of advent $id=clone $firstsunday; for($i=0;$i<105;$i++) { $sundaydate[$i]=clone $id; $servicetype[$i]="normal"; $id->modify('+7 days'); } for ($mainyear=0; $mainyear<=1; $mainyear++) { //Two years always calculated so that the in-year dates are accurate $datex->modify($mainyear." years"); $yearcode=chr(ord("A") + _year($datex) % 3); if ($yearcode == "@") $yearcode="C"; if ($yearcode == "A") $lastyearcode="C"; if ($yearcode == "B") $lastyearcode="A"; if ($yearcode == "C") $lastyearcode="B"; $advent4=_date_add("24-dec-"._year($datex),(-_weekday("24-dec-"._year($datex))).' days') ; ee('876 Advent 4 is'. date_format($advent4,"d-m-Y")); //echo date_format($advent4,"d/m/Y")." advent4
"; $firstsunday=_date_add($advent4,"-28 days"); if($e)echo '879 '.date_format($firstsunday,"d-m-Y")." First Sunday
"; $easter=date_create($easterdate[(_year($datex)-2000 + 1)]."-".(_year($datex) + 1)); ee("Line 881 Easter= and ".$easterdate[(_year($datex)-2000 + 1)]."-".(_year($datex) + 1)); // $id= clone $firstsunday; if ($mainyear == 0) { $jw=52; $a=0; } else { $a=51; $jw=105; } for ($i=$a; $i<=$jw; $i++) { if ($sundaydate[$i] == $advent4) { $adventsunday=$i; $sundayname[$i]="Advent4"; $sundaycode[$i]=$yearcode."Advt04"; for ($k=1; $k<=3; $k++) { //needs sorting if ($sundaydate[$i-$k] instanceof DateTime) { $sundayname[$i-$k]="Advent".(4-$k); $sundaycode[$i-$k]=$yearcode."Advt0".(4-$k); } } $sundayname[$i-4]="Christ the King"; $sundaycode[$i-4]=$lastyearcode."Regn"; //NEW if (_day($sundaydate[$i + 1]) == 25) { $christmas2=$sundaydate[$i + 3];//changed from 2 to 3 - 5/12/2019 $sundayname[$i + 1]="Christmas Day"; $sundaycode[$i + 1]=$yearcode."Natv"; } else { $christmas2=$sundaydate[$i + 2]; $sundayname[$i+1]="Christmas1"; $sundaycode[$i+1]=$yearcode."Xmas01"; addaline($i, date_create("25-dec-"._year($sundaydate[$i])), "Christmas Day", $yearcode."Natv", "","festival",""); } $i=$jw; } } //Need to deal with Prop3 (18-24Feb incl Epip07 Proper3) Prop2 (11-17, Epip06) and Prop1(4-10Feb) all if earlier than Lent-2 which has priority //Lent-2 trumps all Epips //Note Lent-2 is not in the RCL, but I have put it there and Lent-1 is in the RCL as Trans, not sure we need Epip08 and 09 ee("Line 933"); for ($i=$a; $i<=$j; $i++) { if ($sundaydate[$i+1] == $christmas2) { //$christmas2=$i + 1; $doaddaline=0; if($sundaydate[$i+1]0)addaline($doaddaline, $sundaydate[$doaddaline], "ALTERNATIVE - Epiphany", $yearcode."EpDy", "","normal",""); //Deal with Candlemass for ($i=$a; $i<=$jw; $i++) { $yyyy=_year($sundaydate[$i]); if ($sundaydate[$i] <= date_create("3-Feb-".$yyyy) && $sundaydate[$i] >= date_create("28-Jan-".$yyyy)) { if ($sundaydate[$i] == date_create("2-Feb-".$yyyy)) { $sundayname[$i]="Presentation"; $sundaycode[$i]=$yearcode."Pres"; } else { $sundayname[$i]=$sundayname[$i]." or Presentation"; addaline($i, $sundaydate[$i], "ALTERNATIVE - Presentation", $yearcode."Pres", "","normal",""); } $i=$jw; } } for ($i=$a; $i<=$jw; $i++) { if ($sundaydate[$i] == $easter) { $sundayname[$i]="Easter"; $sundaycode[$i]=$yearcode."Ress"; for ($k=0; $k<=5; $k++) { $sundayname[$i + 1 + $k]="Easter plus ".($k + 1); $sundaycode[$i + 1 + $k]=$yearcode."East0".($k + 2); } $sundayname[$i + 7]="Pentecost"; $sundaycode[$i + 7]=$yearcode."PDay"; $sundayname[$i + 8]="Trinity"; $sundaycode[$i + 8]=$yearcode."Trin"; $trinitydate=clone $sundaydate[$i+8]; $sundayname[$i-1]="Palm"; $sundaycode[$i-1]=$yearcode."Palm"; for ($k=2; $k<=6; $k++) { $x="Lent".(7-$k); $sundayname[$i-$k]=$x; $sundaycode[$i-$k]=$yearcode."Lent0".(7-$k); } $mothering=$i-3; $sundayname[$i-7]="Lent-1 (also Transfiguration)"; $sundaycode[$i-7]=$yearcode."Tran"; //if (substr($sundayname[$i-8],0,4) != "Epip") //{ $sundayname[$i-8]="Lent-2"; $sundaycode[$i-8]=$yearcode."Lent-2"; $presentation=date_create('2-2-'._year($sundaydate[$i])); if($sundaydate[$i-9]>$presentation)$sundayname[$i-9].=' Lent-3'; if($sundaydate[$i-10]>$presentation)$sundayname[$i-10].=' Lent-4'; if($sundaydate[$i-11]>$presentation)$sundayname[$i-11].=' Lent-5'; //} $lent2=$i-8; $i=$jw; } } $ninethordinary=date_create("29-may-".(_year($datex) + 1)); ee("Line 1049"); for ($i=$a; $i<=$jw; $i++) { ee('datedif at 1052:'._date_diff($sundaydate[$i], $ninethordinary).' and '.date_format($sundaydate[$i],'d-m-Y').' and nineth='.date_format($ninethordinary,'d-m-Y')); if (_date_diff($sundaydate[$i], $ninethordinary) <= 0 && _date_diff($sundaydate[$i], $ninethordinary) > -7) { ee('1055 Here vvvvv'); $ord=9; while (isset($sundayname[$i]) && $sundayname[$i] != "") { $i++; $ord++; ee('1061 HERE --- vvvv'); } while ((!isset($sundayname[$i]) || $sundayname[$i] == "") && $ord <= 34) { ee('1065 HERE ---- ttttt'); if(isset($sundaydate[$i]))$sundayname[$i]=($ord)." Ordinary time, Proper ".($ord-5).', '.(date_diff($sundaydate[$i],$trinitydate)->format("%a")/7)." after Trinity, "; if ($ord > 14)$sundaycode[$i]=$yearcode."Prop".($ord-5); else $sundaycode[$i]=$yearcode."Prop0".($ord-5); $ord++; $i++; } $i=$jw; } if (_month($sundaydate[$i]) == 5 && _day($sundaydate[$i]) >= 24 && _day($sundaydate[$i]) <= 28 && $sundayname[$i] == "") { $sundayname[$i]="8 Ordinary time, Proper 3"; $sundaycode[$i]=$yearcode."Prop03"; } } ee("Line 1081"); //Deal with Advent - x if ($adventsunday-5 > 0)if (!isset($sundayname[$adventsunday-5]) || $sundayname[$adventsunday-5] == "" || is_numeric(substr($sundayname[$adventsunday-5],0,1)))$sundayname[$adventsunday-5]="Advent-2"; if ($adventsunday-6 > 0)if (!isset($sundayname[$adventsunday-6]) || $sundayname[$adventsunday-6] == "" || is_numeric(substr($sundayname[$adventsunday-6],0,1)))$sundayname[$adventsunday-6]="Advent-3"; if ($adventsunday-7 > 0)if (!isset($sundayname[$adventsunday-7]) || $sundayname[$adventsunday-7] == "" || is_numeric(substr($sundayname[$adventsunday-7],0,1)))$sundayname[$adventsunday-7]="Advent-4"; //Deal with Remembrance for ($i=$a; $i<=$jw; $i++) { $yyyy=_year($sundaydate[$i]); if (_month($sundaydate[$i]) == 11 && _day($sundaydate[$i]) >= 8 && _day($sundaydate[$i]) <= 14) { if(isset($sundayname[$i]))$sundayname[$i]=$sundayname[$i]." AND Remembrance";else $sundayname[$i]="Remembrance"; $i=$jw; } } //Deal with All Saints for ($i=$a+5; $i<=$jw; $i++) //the +5 is a random addition to stop it doing it for the previous year { $yyyy=_year($sundaydate[$i]); if ($sundaydate[$i] <= date_create("5-Nov-".$yyyy) && $sundaydate[$i] >= date_create("30-Oct-".$yyyy)) { //Amend previous Sunday to last after Trinity if(isset($sundayname[$i-1]))$sundayname[$i-1]=preg_replace("/[0-9][0-9] after Trinity/","Last after Trinity",$sundayname[$i-1]); if ($sundaydate[$i] == date_create("1-Nov-".$yyyy)) { $sundayname[$i]="All Saints"; $sundaycode[$i]=$yearcode."AllS"; } else { if(isset($sundayname[$i])) { $sundayname[$i]=$sundayname[$i]." or All Saints"; addaline($i, $sundaydate[$i], "ALTERNATIVE - All Saints", $yearcode."AllS", "","normal",""); }else $sundayname[$i]='All Saints'; } $i=$jw; } } ee("Line 1121"); //Deal with other festivals for ($f=1; $f<=$nofests; $f++) { ee("1125 Fest = ".$f.' = '.$festname[$f].' '.date_format($festdate[$f],'d-m-Y')); for ($i=$a; $i<=$jw; $i++) { if (_month($festdate[$f]) == _month($sundaydate[$i]) && _day($festdate[$f]) == _day($sundaydate[$i])) { if(_colour($i)=='green' ) { $sundayname[$i]=$sundayname[$i]." or ".$festname[$f]; addaline($i, $sundaydate[$i], "ALTERNATIVE - ".$festname[$f], "", $festreadings[$f],"festival",""); $i=$jw; } } } } ee("Line 1140"); addaline($mothering, $sundaydate[$mothering], "ALTERNATIVE - Mothering Sunday", $yearcode."Moth", "","normal",""); } //Deal with other monthly services ee("Line 1145"); $qsos=rqqqs("otherservices"); if ($qsos == "yes") { $qs=rqqqs("startmonth"); //is date right? if($qs=="")$datex=date_create('1-'._month($now).'-'._year($now)); else $datex=date_create('1-'.$qs);// 'reset datex $datex->modify('-1 years'); $oscount=1; $osc=1; for($mainyear=0;$mainyear<=1;$mainyear++) { $datex->modify('+'.$mainyear.' year'); $osnamez=rqqqs("otherservicename"); $osweek=rqqqs("whichweek"); $osday=intval(rqqqs("whichday")); $firstofmonth=_date_add($datex,"1 year"); while ($oscount <= 12) { if ($osweek == "last") { $osdate=($osday-_weekday($firstofmonth)-1 + 1 + 4 * 7); if ($osdate > $lmonth[_month($firstofmonth)-1])$osdate-=7; } else { $osdate=($osday-_weekday($firstofmonth)-1 + 1); if ($osdate <= 0)$osdate+=7; $osdate+=(intval($osweek)-1) * 7; } if ($osdate <= $lmonth[(_month($firstofmonth)-1)]) { $osdates[$osc]=date_create($osdate."-"._month($firstofmonth)."-"._year($firstofmonth)); $osc++; } $oscount++; $firstofmonth->modify('+1 month'); } } $noosc=$osc-1; $osc=1; ee("Line 1188"); for ($i=0; $i<=$jw; $i++) { if ($osc <= $noosc) { ep('Other service for Sanyres '.date_format($sundaydate[$i],'d-m-Y')." ".date_format($osdates[$osc],'d-m-Y')."
"); if ($sundaydate[$i] < $osdates[$osc] && $sundaydate[$i + 1] > $osdates[$osc]) { addaline($i, $osdates[$osc], date_format($osdates[$osc],'l')." ".$osnamez, "", "","other",""); // WARNING: assuming weekdayname is an external array $osc++; } } } } //-------------------------------------------------------------- //deal with extra one-off services for($es=1;$es<=$noextraservices;$es++) { $esxx=explode("$",$extraservice[$es]); $esdate=date_create(str_replace('/','-',$esxx[0])); $eswhere=$esxx[1]; $eswhat=$esxx[2]; $esrequired=trim($esxx[3]); for($i=0;$i<=$jw;$i++) { if($sundaydate[$i]<=$esdate && $sundaydate[$i+1]>$esdate) { addaline($i,$esdate,date_format($esdate,'l')." ".$eswhere." ".$eswhat,str_replace(" ","",$eswhere.$eswhat),"","extra",$esrequired); $i=$i+1; } } } ee("Line 1222"); if($ep) { for($tt=0;$tt<200;$tt++) { if($sundaydate[$tt] instanceof DateTime && isset($sundayname[$tt])) { echo '1229 '.date_format($sundaydate[$tt],'d-m-Y').' '.$sundayname[$tt].' '.$sundaycode[$tt].' '.$servicetype[$tt].' '.$strequired[$tt].'
'; }else echo '1231 no sundayname for tt='.$tt.'
'; } } //------------------------------------------------------------------------- //create old hymns array $churchhymn=array(); $churchname77=array();$candate77=array();$h77=array();$newarr77=array();$hno77=array();$hymns77=array(); $dir77="."; // open pointer to directory and read list of files $dd77 = @dir($dir77) or die("getFileList: Failed opening directory $dir for reading"); while(false !== ($entry77 = $dd77->read())) { if(is_file($entry77) and ($entry77!=".") and ($entry77!="..") and preg_match("/\.txt$/i", $entry77)) { $fname77=$entry77; $ss77=fopen($fname77,"r") or die("Unable to open file ".$fname); $qqs77=str_replace("\r","",str_replace("\n","",fgets($ss77))); $howmany77=preg_match_all("/churchname=([^&]+)/",$qqs77,$details77); for($i=0;$i<$howmany77;$i++) { parse_str("x77=".$details77[1][$i],$presult); $churchname77[$i]=$presult['x77']; } if(false!==($qqs77=fgets($ss77)))if(substr($qqs77,0,9)=="benefice=") { //echo ''.$fname.'
'; $howmany77=preg_match_all("/&x([0-9][0-9])x([0-9][0-9])x(20[0-9][0-9])x[^x]*x[0-9]*x([0-9])xHymns=([0-9]*)\+?([^&]+)/",$qqs77,$makeit77).'
'; if($howmany77>0) { for($i=0;$i<$howmany77;$i++) { parse_str("hymn=".$makeit77[6][$i],$presult); $hymn=$presult['hymn']; //echo $makeit77[6][$i].'
'; $datetry77=$makeit77[1][$i].$makeit77[2][$i].$makeit77[3][$i].$makeit77[4][$i]; //$churchtry77=;//$churchname77[$makeit77[4][$i]-1]; $hymntry77=strtolower($hymn); $hymnno77=$makeit77[5][$i]; $found=false; $hplace77=-1; if(strlen($hymnno77)>0)//this is church hymn number, not global, so it is assuming they are from the same book - probably unwise { for($j=0;$jclose(); //for($j=0;$j'; for($j=0;$j"; $k=$nohymns; } } if($hn77!=-1) { array_push($churchhymn,array()); array_push($churchhymn[sizeof($churchhymn)-1],$hn77); for($i=0;$iMAIN PARAMETERS
'; //echo 'nohymnssofar='.$nohymnssofar.' churchhymn[1]='.$churchhymn[1].'
'; echo 'nohymns='.$nohymns.' hymnname[3]='.$hymnname[3].'
'; echo 'nochurches='.$nochurches.' churchname[1]='.$churchname[1].'
'; //echo 'noextraservices='.$noextraservices.' extraservice[1]='.$extraservice[1].'
'; echo 'printout='.$printout.' sundaydate[1]='.date_format($sundaydate[1],'d-m-Y').'
'; //echo 'noosc='.$noosc.' osnamez='.$osnamez.'
'; //echo 'qsos='.$qsos.' osweek='.$osweek.' osday='.$osday.'
'; echo 'printpartial='.$printpartial.' benefice='.$benefice.'
'; echo 'noths='.$noths.' theme[2]='.$theme[2].'
'; echo 'norcls='.$noRCLs.' RCLreading[2]='.$RCLreading[2].'
'; echo 'nooremus='.$nooremus.' oresmusentry[1]='.$oremusentry[1].'
'; echo 'noeasters='.$noeasters.' easter[16]='.$easterdate[16].'
'; echo 'nofests='.$nofests.' festname[3]='.$festname[3].' festreadings[3]='.$festreadings[3].'
'; //echo '[church][column-1] zheading[2][0]='.$zheadings[2][0].' znumber[1][0]='.$znumber[1][0].' nocols[1]='.$nocols[1].'
'; echo 'nohymnbooks='.$nohymnbooks.' now='.date_format($now,'d-m-Y').'
'; echo '_day='._day($now).' _weekday='._weekday($now).' _dayofyear='._dayofyear($now).' _year='._year($now).' _month='._month($now).' stfdate='.stfdate($now).' hymnarydate='.hymnarydate($now).'
'; $testdate=date_create('15-1-2017'); echo 'sundayinmonth(15th Jan)='.sundayinmonth($testdate).'
'; echo 'year weekday and day of 15th Jan and check the date='._year($testdate).', '._weekday($testdate).', '._day($testdate).', '.date_format($testdate,'d-m-Y').', '.date_format($testdate,'l').'
'; echo '_instr delivers 1-len not 0-len-1 and fail is 0
'; echo 'all='.$all.'
';if($all)echo 'true';else echo'false'; echo'
'; echo 'fm substring='.substr($fm,0,200).'
'; echo '-------------------------------------------------------------
'; echo 'count of lines out is jw='.$jw.'
'; echo '-------------------------------------------------------------'; } //'******************************************************* //Main loop for calculating content of boxes and doing outputs //******************************************************** ?>  = $sundaydate[$i]) { ee('1383 First selection done'); //datex and howmanymonths set the range of dates we are calculating so it selects now //echo 'printout='.$printout.' all='.$all.' ref='.refmcb(coded($i)."xXX"); if (!$printout || (refmcb(coded($i)."xXX") == "checked" && $printout && ($all || (_date_add($now,"-7 days") <= $sundaydate[$i] && _date_add($now,"2 months") >= $sundaydate[$i])))) { if (refmcb(coded($i)."xXX") == "checked")$dlt=""; else $dlt="x"; for ($q=1; $q<=$nochurches; $q++) { $mainrlist[$q]=""; $goslist[$q]=""; } $hlist=""; $themelist=""; if($printout) { if($e)echo'1398 ====================================================================='; ?>