Hooch Posted September 29, 2011 Share Posted September 29, 2011 (edited) Hi all.I came across a script that is exactly what I need, unfortunately it's mostly JS.I could work things out if it were PHP but I need some help here. Here is the code.. <html> <head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Shift Schedule</title> </head><body background="" bgcolor="#CCCCCC" text="#000000" link="#996600" vlink="#666666" alink="#336600"><script LANGUAGE="JavaScript"><!-- var dayName=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); var monthName=new Array("January","February","March","April","May","June","July","August","September","October","November","December"); var monthDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31); var ondays=new Array("D","D","A","A","B","B","B","C","C","D","D","A","A","A","B","B","C","C","D","D","D","A","A","B","B","C","C","C"); var onnights=new Array("B","B","C","C","D","D","D","A","A","B","B","C","C","C","D","D","A","A","B","B","B","C","C","D","D","A","A","A"); var now=new Date(); var nowd=now.getDate(); var nowm=now.getMonth(); var nowy=now.getYear(); var startdate=new Date("Jan 1 2001 00:00:01"); function showCalendar(day,month,year) { // if this year is divisable by 4 or 100, and is divisible by 400... then change last day of feb to 29. // if ((year%4==0)||(year%100==0)) {monthDays[1]=29;} if (year%400==0) {monthDays[1]=29;} var firstDay=new Date(year,month,1).getDay() var calStr="<br><span id=instruction>Instruction<br></span id=instruction>" calStr+="<div class=headerRow>" calStr+="<span class=headerLeft><InPut type = button value = 'Last Month' onClick='nowm--; if (nowm<0) { nowy--; nowm=11; } showCalendar(nowd,nowm,nowy)'></span>" calStr+="<span class=headerRight><InPut type = button value = 'Next Month'onClick='nowm++; if (nowm>11) { nowy++; nowm=0; } showCalendar(nowd,nowm,nowy)'></span>" calStr+="<span class=headerCenter><font size=2>12 Hour Shift Schedule</font><br>"+monthName[month].toUpperCase()+", "+year+"</span>" calStr+="</div class=headerRow><div class=headerDayRow>" for (var i=0;i<dayName.length;i++) calStr+="<span class=headerDays>"+dayName[i].substring(0,3)+"</span>" var dayCount=1 calStr+="</div class=headerDayRow><div class=dayRow>" for (var i=0;i<firstDay;i++) calStr+="<span class=emptyDaysTop> </span>" for (var i=0;i<monthDays[month];i++) { calStr+="<span class=ACDays><span class=daynumber>"+dayCount++ var fDate = new Date(monthName[month]+" "+dayCount+" "+nowy+" 00:00:01") var diffdate = (fDate - startdate)/86400000 -1 var diffdate = Math.round(diffdate) var remainder=diffdate%28 var days=ondays[remainder] var nights=onnights[remainder] calStr+="</span><br><b>Days= " calStr+=days calStr+="<br>Nights= " calStr+=nights+"</b></span>" if ((i+firstDay+1)%7==0&&(dayCount<monthDays[month]+1)) calStr+="</div><div class=dayRow>" } var totCells=firstDay+monthDays[month] for (var i=0;i<(totCells>28?(totCells>35?42:35):28)-totCells;i++) calStr+="<span class=emptyDaysBottom> </span>" calStr+="</div>" //define what html to put in the span tag // calendar.innerHTML=calStr } //--></SCRIPT><center><SPAN ID=calendar><script> showCalendar(nowd,nowm,nowy)</SCRIPT></SPAN></center></body></html> Basically I need the following line calStr+="<span class=ACDays><span class=daynumber>"+dayCount++ to switch from it to this calStr+="<span class=BDDays><span class=daynumber>"+dayCount++ whenever the variable ondays is either A or C show the switch 1. When variable ondays is either B or D show switch 2. I tried many different ways with my knowledge of PHP but nothing works. Thank you for your time Edited September 29, 2011 by Hooch Link to comment Share on other sites More sharing options...
justsomeguy Posted September 29, 2011 Share Posted September 29, 2011 if (ondays == 'A' || ondays == 'C'){ // option 1}else if (ondays == 'B' || ondays == 'D'){ // option 2} It looks like ondays is an array, so you probably want to test one particular array element instead of the entire variable. Link to comment Share on other sites More sharing options...
Hooch Posted September 29, 2011 Author Share Posted September 29, 2011 Thanks Guy.But this gives me more errors. To show you how I implemented your code look below <script LANGUAGE="JavaScript"><!-- var dayName=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); var monthName=newArray("January","February","March","April","May","June","July","August","September","October","November","December"); var monthDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31); var ondays=newArray("D","D","A","A","B","B","B","C","C","D","D","A","A","A","B","B","C","C","D","D","D","A","A","B","B","C","C","C"); var onnights=newArray("B","B","C","C","D","D","D","A","A","B","B","C","C","C","D","D","A","A","B","B","B","C","C","D","D","A","A","A"); var now=new Date(); var nowd=now.getDate(); var nowm=now.getMonth(); var nowy=now.getYear(); var startdate=new Date("Jan 1 2001 00:00:01"); function showCalendar(day,month,year) { // if this year is divisable by 4 or 100, and is divisible by 400... then change last day of feb to 29. // if ((year%4==0)||(year%100==0)) {monthDays[1]=29;} if (year%400==0) {monthDays[1]=29;} var firstDay=new Date(year,month,1).getDay() var calStr="<br><span id=instruction>Instruction<br></span id=instruction>" calStr+="<div class=headerRow>" calStr+="<span class=headerLeft><InPut type = button value = 'Last Month' onClick='nowm--; if (nowm<0) { nowy--;nowm=11; } showCalendar(nowd,nowm,nowy)'></span>" calStr+="<span class=headerRight><InPut type = button value = 'Next Month'onClick='nowm++; if (nowm>11) { nowy++;nowm=0; } showCalendar(nowd,nowm,nowy)'></span>" calStr+="<span class=headerCenter><font size=2>12 Hour Shift Schedule</font><br>"+monthName[month].toUpperCase()+","+year+"</span>" calStr+="</div class=headerRow><div class=headerDayRow>" for (var i=0;i<dayName.length;i++) calStr+="<span class=headerDays>"+dayName[i].substring(0,3)+"</span>" var dayCount=1 calStr+="</div class=headerDayRow><div class=dayRow>" for (var i=0;i<firstDay;i++) calStr+="<span class=emptyDaysTop> </span>" for (var i=0;i<monthDays[month];i++) {if (ondays == 'A' || ondays == 'C'){ calStr+="<span class=ACDays><span class=daynumber>"+dayCount++} else if (ondays == 'B' || ondays == 'D'){ calStr+="<span class=BDDays><span class=daynumber>"+dayCount++} var fDate = new Date(monthName[month]+" "+dayCount+" "+nowy+" 00:00:01") var diffdate = (fDate - startdate)/86400000 -1 var diffdate = Math.round(diffdate) var remainder=diffdate%28 var days=ondays[remainder] var nights=onnights[remainder] calStr+="</span><br><b>Days= " calStr+=days calStr+="<br>Nights= " calStr+=nights+"</b></span>" if ((i+firstDay+1)%7==0&&(dayCount<monthDays[month]+1)) calStr+="</div><div class=dayRow>" } var totCells=firstDay+monthDays[month] for (var i=0;i<(totCells>28?(totCells>35?42:35):28)-totCells;i++) calStr+="<span class=emptyDaysBottom> </span>" calStr+="</div>" //define what html to put in the span tag // calendar.innerHTML=calStr } //--></SCRIPT></head><body background="" bgcolor="#CCCCCC" text="#000000" link="#996600" vlink="#666666" alink="#336600"><center><SPAN ID=calendar><script> showCalendar(nowd,nowm,nowy)</SCRIPT></SPAN></center></body></html> This my show you what I am trying to do.Just an FYI this code (well the 1st code posted) only works in IE not FF Hooch Link to comment Share on other sites More sharing options...
thescientist Posted September 29, 2011 Share Posted September 29, 2011 well, what are the errors? have you tried figuring out what to do about them? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 29, 2011 Share Posted September 29, 2011 Like I said, you're testing the entire array. The entire array is not going to be equal to a single letter. You probably want to test one particular element in the array, but I don't know which one you want to test. Link to comment Share on other sites More sharing options...
Drycodez Posted September 29, 2011 Share Posted September 29, 2011 (edited) What JSG is saying, is that you should test for one particular Value inside the Array. Ex: If for example, you want to get the first value inside the Array (ondays), then you will do something like this: if(ondays[0]=="A")//if the first value in the Array is: A. Edited September 29, 2011 by O. Samuel Link to comment Share on other sites More sharing options...
Hooch Posted October 2, 2011 Author Share Posted October 2, 2011 Thanks for the info guys.Using javascript is not something I do often so I decided to convert it all to PHP. I appreciate you taking the time to help me. If anyone wants the code I will post it. Oh..if you want to see what I was going for look here...This is a 12hr shift schedule my workplace has. Now we cansee what we are working months/years in advance. Againthank you. Hooch Link to comment Share on other sites More sharing options...
Hooch Posted December 7, 2013 Author Share Posted December 7, 2013 (edited) See below: Edited December 7, 2013 by Hooch Link to comment Share on other sites More sharing options...
Hooch Posted December 7, 2013 Author Share Posted December 7, 2013 (edited) Ooops..I got to this post via my panel and forgot it started in javascript. Sorry for posting this PHP problem here. I removed the above post and added a new one to PHP Edited December 7, 2013 by Hooch Link to comment Share on other sites More sharing options...
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