<%@ Language=VBScript %> <% Dim Kidid,Schedule,ScheduleType,schDay,temp,temp1,temp2,temp3,temp4 Dim found Dim str,errorstr Dim recAffected Dim retArray1() Kidid = request("kidName") Schedule = request("hourallowed") ScheduleType = request("ScheduleType") schDay = request("whichday") str = request("Arrscheduletime") 'response.write Kidid&"#"&Schedule&"#"&ScheduleType&"#"&schDay&"#"&str 'response.end Dim ScheduleArray1,ScheduleArray3(7),ScheduleArray4 Function ConvertScheduleToMinute(SchArray()) For i=0 to (UBound(SchArray)) StartHour = 0 StartMin = 0 pos = InStr(1, SchArray(i), ":", VBTextCompare) if pos <> 0 then StartHour = Left(SchArray(i),pos-1) StartMin = Right(SchArray(i),Len(SchArray(i)) - pos) SchArray(i) = StartHour * 60 + StartMin 'tempArray(0) * 60 + tempArray(1) End if Next ConvertScheduleToMinute = SchArray End Function Function CreateSortedData(SchArray()) str1 = "" temp = "" temp1 = "" Dim temp,temp1 ReDim retArray9(((UBound(SchArray)+1)/2)-1,1) ulimit = (UBound(SchArray)+1)/2 -1 ulimit = CInt(ulimit) j=0 k=1 For i = 0 to ulimit count = count + 1 retArray9(i,0) = SchArray(j) retArray9(i,1) = SchArray(k) j=j+2 k=k+2 Next For i = 0 to UBound(retArray9)-1 For j = i to UBound(retArray9) if retArray9(i,0) > retArray9(j,0) then temp = retArray9(i,0) temp1 = retArray9(i,1) retArray9(i,0) = retArray9(j,0) retArray9(i,1) = retArray9(j,1) retArray9(j,0) = temp retArray9(j,1) = temp1 End if Next Next j=0 for i=0 to UBound(retArray9) SchArray(j) = retArray9(i,0) j=j+1 schArray(j) = retArray9(i,1) j=j+1 Next CreateSortedData = schArray End Function ScheduleArray = Split(Join(Split(str,","),"-"),"-") ScheduleArray1 = ConvertScheduleToMinute(ScheduleArray) ScheduleArray1 = CreateSortedData(ScheduleArray1) found = 1 if UBound(ScheduleArray1) = 1 then ' only one Schedule no need to check for existing schedule found = 0 Else For i = 0 to UBound(ScheduleArray1)-2 Step 2 time1 = ScheduleArray1(i) time2 = ScheduleArray1(i+1) time3 = ScheduleArray1(i+2) time4 = ScheduleArray1(i+3) 'Response.write "1, " & time1 &",2 "& time2 &",3 "& time3 &",4 "& time4 &"# " if time1 > time3 And time1 >= time4 And time2 > time3 And time2 > time4 then 'Not overlapping with existing schedule found = 0 ' Exit For Elseif time1 < time3 And time1 < time4 And time2 <= time3 And time2 < time4 then 'Not overlapping with existing schedule found = 0 ' Exit For Else 'overlapping with existing schedule errorstr = "Can Not Modify Schedule,Because of Overlapping of Schedules " Response.Redirect("ScheduleError.asp?Error=" & errorstr &"&username=" & kidid & "&whichday=" & schDay & "&hoursallowed=" & schedule&ScheduleType & "&scheduleTime=" & str & "&CheckForDelete=1") found = 1 End if Next 'Response.end end if 'Find total scheduled time for selected day 'Create string to update schedule of selected day 'This code be same for both Weekly,Daily schedule 'If schedule type is Weekly then we also have to find total 'Scheduled time of other days (excluding selected day as we 'calculating it here) TotalScheduleTime = 0 for i=0 to UBound(ScheduleArray1) - 1 step 2 TotalScheduleTime = TotalScheduleTime + ( ScheduleArray1(i+1) - ScheduleArray1(i) ) temp = ScheduleArray1(i) temp1 = ScheduleArray1(i+1) nVal = temp Mod 60 nVal2 = temp1 Mod 60 if(nVal < 10) then nVal = "0"&nVal end if if(nVal2 < 10) then nVal2 = "0"&nVal2 end if 'commented for modidication by manish 'str1 = str1 & int(temp/60) & ":" & temp Mod 60 &"-"& int(temp1/60) & ":" & temp1 Mod 60 &"," str1 = str1 & int(temp/60) & ":" & nVal &"-"& int(temp1/60) & ":" & nVal2 &"," Next ' Trim all "," from left and right Do While Right(str1,1) = "," str1 = Left(str1,Len(str1)-1) loop Do While Left(str1,1) = "," str1 = Right(str1,Len(str1)-1) loop if found = 0 And UCase(ScheduleType) = "D" then if TotalScheduleTime <= (Schedule * 60) then 'Update Schedule for that day and kid set cn = Server.CreateObject("ADODB.Connection") cn.Open "DSN=Kidsnet_Parent;uid=sa;PWD=sgmkj;APP=ASP Script;DATABASE=Kidsnet" str = "UPDATE KidOnlineTime SET "&schDay&"='" & str1 &"' Where kidid = '" &kidid&"'" cn.Execute str Response.Redirect "ScheduleKid.asp?KidID=" &kidid cn.Close() else 'Show error errorstr = "Can Not Modify Schedule,Schedule Exceeding Allowed Hours" Response.Redirect("ScheduleError.asp?Error=" &errorstr&"&username="&kidid&"&whichday="&schDay&"&hoursallowed="&schedule&ScheduleType&"&scheduleTime="&str& "&CheckForDelete=1") End if Elseif found = 0 and UCase(ScheduleType) = "W" then ' TotalScheduleTime = 0 ' for i=0 to UBound(retArray) - 1 ' TotalScheduleTime = TotalScheduleTime + (retArray(i,1) - retArray(i,0)) ' temp = retArray(i,0) ' temp1 = retArray(i,1) ' str = str & temp/60 & ":" & temp Mod 60 &"-"& temp1/60 & ":" & temp1 Mod 60 &"," ' Next set cn2 = Server.CreateObject("ADODB.Connection") cn2.Open "DSN=Kidsnet_Parent;uid=sa;PWD=sgmkj;APP=ASP Script;DATABASE=Kidsnet" Set rs2 = Server.CreateObject("ADODB.Recordset") rs2.Open "SELECT kidid,schedule,Mon,Tue,Wed,Thu,Fri,Sat,Sun From Kidonlinetime where Kidid ='"& kidid &"'",cn2 ScheduleArray3(0) = rs2("Mon") ScheduleArray3(1) = rs2("Tue") ScheduleArray3(2) = rs2("Wed") ScheduleArray3(3) = rs2("Thu") ScheduleArray3(4) = rs2("Fri") ScheduleArray3(5) = rs2("Sat") ScheduleArray3(6) = rs2("Sun") rs2.Close() cn2.Close() if (StrComp(ScheduleArray3(0),"Always") <> 0 and StrComp(ScheduleArray3(0),"Never")<> 0 ) And StrComp(schDay,"Mon",VBTextCompare) <> 0 then str2 = str2 + ScheduleArray3(0) End if if (StrComp(ScheduleArray3(1),"Always") <> 0 and StrComp(ScheduleArray3(1),"Never")<> 0 ) And StrComp(schDay,"Tue",VBTextCompare) <> 0 then if StrComp(Right(str2,1),",") <> 0 then str2 = str2 + "," + ScheduleArray3(1) else str2 = str2 + Schedulearray3(1) End if End if if (StrComp(ScheduleArray3(2),"Always") <> 0 and StrComp(ScheduleArray3(2),"Never")<> 0) And StrComp(schDay,"Wed",VBTextCompare) <> 0 then if StrComp(Right(str2,1),",") <> 0 then str2 = str2 + "," + ScheduleArray3(2) else str2 = str2 + Schedulearray3(2) End if End if if (StrComp(ScheduleArray3(3),"Always") <> 0 and StrComp(ScheduleArray3(3),"Never")<> 0) And StrComp(schDay,"Thu",VBTextCompare) <> 0 then if StrComp(Right(str2,1),",") <> 0 then str2 = str2 + "," + ScheduleArray3(3) else str2 = str2 + Schedulearray3(3) End if End if if (StrComp(ScheduleArray3(4),"Always") <> 0 and StrComp(ScheduleArray3(4),"Never")<> 0) And StrComp(schDay,"Fri",VBTextCompare) <> 0 then if StrComp(Right(str2,1),",") <> 0 then str2 = str2 + "," + ScheduleArray3(4) else str2 = str2 + Schedulearray3(4) End if End if if (StrComp(ScheduleArray3(5),"Always") <> 0 and StrComp(ScheduleArray3(0),"Never")<> 0) And StrComp(schDay,"Sat",VBTextCompare) <> 0 then if StrComp(Right(str2,1),",") <> 0 then str2 = str2 + "," + ScheduleArray3(5) else str2 = str2 + Schedulearray3(5) End if End if if (StrComp(ScheduleArray3(6),"Always") <> 0 and StrComp(ScheduleArray3(0),"Never")<> 0) And StrComp(schDay,"Sun",VBTextCompare) <> 0 then if StrComp(Right(str2,1),",") <> 0 then str2 = str2 + "," + ScheduleArray3(6) else str2 = str2 + Schedulearray3(6) End if End if ' Trim all "," from left and right Do While Right(str2,1) = "," str2 = Left(str2,Len(str2)-1) loop Do While Left(str2,1) = "," str2 = Right(str2,Len(str2)-1) loop ' if StrComp(Left(str,1),",") = 0 then ' str = Right(str,Len(str)-1) ' Endif if right(str2,1) = "," then str2 = str2 & str1 else str2 = str2 &","& str1 End if Do While Right(str2,1) = "," str2 = Left(str2,Len(str2)-1) loop Do While Left(str2,1) = "," str2 = Right(str2,Len(str2)-1) loop ScheduleArray4 = Split(Join(Split(str2,","),"-"),"-") ScheduleArray4 = ConvertScheduleToMinute(ScheduleArray4) TotalScheduleTime = 0 for i=0 to UBound(ScheduleArray4) step 2 TotalScheduleTime = TotalScheduleTime + (ScheduleArray4(i+1) - Schedulearray4(i)) Next if TotalScheduleTime <= (Schedule * 60) then 'Update schedule for that day for that kid set cn = Server.CreateObject("ADODB.Connection") cn.Open "DSN=Kidsnet_Parent;uid=sa;PWD=sgmkj;APP=ASP Script;DATABASE=Kidsnet" 'response.write str1 'response.end str = "UPDATE KidOnlineTime SET "&schDay&"='" & str1 &"' Where kidid = '" &kidid&"'" cn.Execute str cn.Close() Response.Redirect "ScheduleKid.asp?KidID=" &kidid else 'show error errorstr = "Can Not Modify Schedule,Schedule Exceeding Allowed Hours" Response.Redirect("ScheduleError.asp?Error=" &errorstr&"&username="&kidid&"&whichday="&schDay&"&hoursallowed="&schedule&"&scheduleTime="&str& "&CheckForDelete=1" ) End if End if %>