mattpant Posted March 20, 2012 Posted March 20, 2012 Hello, We are trying to develop a new Intranet page for our school using Joomla, we operate a 2 Week timetable and so, what we would like on the HomePage is some kind of coding/script that would display the current date (that's easy enough) but would also display whether we were currently on Week 1 or Week 2 for the timetable. Is anybody able to point me in the right direction of how we get this working? Or does anybody have a code already to do this or similar? I've never done any coding before, so don't really know where to start on this! Many Thanks Matt
howartp Posted April 2, 2012 Posted April 2, 2012 Matt, weeks.php <?php //Usage: //echo getWeekByDate("25/03/08"); // OR //echo getWeekByDate(date("d/m/Y",strtotime("now"))); function getWeekByDate($dateIN) // DD/MM/YY format { $dateIN = invertdate2($dateIN); $dateIN = str_replace("/","-",$dateIN); $dateIN = date("y-m-d",strtotime($dateIN)); $file = "weeks.csv"; $lines = file($file); $size = count($lines); $weekcom = date("Y",strtotime("now")); if (date("N",strtotime($dateIN)) == 1) { $dateIN = date("y-m-d",strtotime($dateIN)); } else { $dateIN = date("y-m-d",strtotime("last monday",strtotime($dateIN))); } $weekcom = date("dmy",strtotime($dateIN)); $wkfound = false; for($i=0;$i<$size;$i++) { list($wkdate,$week) = explode("," , $lines[$i]); $m = substr($wkdate,0,2); $d = substr($wkdate,3,2); $y = substr($wkdate,7,4); $wkdate = $d . "/" . $m . "/" . $y; if (date("dmy",strtotime($wkdate)) == $weekcom) { return $week; $wkfound = true; } } if (!$wkfound) { return "Unknown Week [$dateIN]"; } else { return "Known Week [$dateIN]"; } } //end function getWeekByDate function invertdate2($inDate) { $lenPart1 = strpos($inDate,"/"); $lenPart2 = strpos($inDate,"/",$lenPart1); $stPart3 = $lenPart1+$lenPart2+2; $part1 = substr($inDate,0,$lenPart1); $part2 = substr($inDate,$lenPart1+1,$lenPart2); $part3 = substr($inDate,$stPart3); return $part3 . "/" . $part2 . "/" . $part1; } ?> weeks.csv 05/03/2012,Week A 12/03/2012,Week B 19/03/2012,Week A 26/03/2012,Week B 02/04/2012,Easter Holiday 09/04/2012,Easter Holiday 16/04/2012,Week A 23/04/2012,Week B The above PHP code, together with a 2-column CSV file called "weeks.csv" in the same folder, will do what you want - it's just a case of working out how to display it in Joomla which I can't help with. I do exactly the same as what you're asking, except in Frog - we embed a HTML brick/widget which displays this page hosted on our internal webserver. Peter 3
mattpant Posted April 2, 2012 Author Posted April 2, 2012 Many Thanks Peter for the scripts you use. I will try them out on our setup. Matt
gumbygaz Posted May 17, 2013 Posted May 17, 2013 Cheers! Year old post, but was just what I needed for our Frog page Thanks for sharing
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now