<%@ Language=VBScript %> <% Dim Kidid,Schedule,ScheduleType,schDay,Fromtime,ToTime,tempFrom1,tempTo1,time1,time2 Dim found Dim str,str1,str2,str3 Dim temp,temp1 Dim retArray1 Dim PrivateArray Dim TimeCheck Dim strTimeCheck Kidid = request.Form("cmbChild") Kidid = session("id")&"_"&Kidid schDay = left(request.Form("cmbDay"),3) FromTime = request.Form("cmbFromHour") &":"& request.Form("cmbFromMinute") ToTime = request.Form("cmbToHour") &":"& request.Form("cmbToMinute") TimeCheck = Split(FromTime,":") strTimeCheck = TimeCheck(0)&":" 'response.write FromTime&"#"&ToTime 'response.end if(StrComp(FromTime, ToTime)=0)then Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Schedule Time Interval is Same") end if str ="" recAffected = 0 Dim ScheduleArray,ScheduleArray2,ScheduleArray3(7),ScheduleArray5 Function CreateSortedDataForWeek(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 For i=0 to (UBound(schArray)-1) step 2 temp = schArray(i) temp1 = schArray(i+1) str1 = str1 & int(temp/60) & ":" & temp Mod 60 &"-"& int(temp1/60) & ":" & temp1 Mod 60 &"," Next 'for each cat in scharray ' dd = dd &"#"& cat ' next 'response.write str1 'response.end Do While Right(str1,1) = "," str1 = Left(str1,Len(str1)-1) loop CreateSortedDataForWeek = str1 End Function Function CreateSortedData(SchArray()) str1 = "" temp = "" temp1 = "" Dim retArray() Dim temp,temp1 ReDim retArray(((UBound(SchArray)+1)/2)-1,1) ulimit = (UBound(SchArray)+1)/2 ulimit = CInt(ulimit) j=0 k=1 For i = 0 to ulimit -1 retArray(i,0) = SchArray(j) retArray(i,1) = SchArray(k) j=j+2 k=k+2 Next For i = 0 to UBound(retArray) For j = i+1 to UBound(retarray) if retArray(i,0) > retArray(j,0) then temp = retArray(i,0) temp1 = retArray(i,1) retArray(i,0) = retArray(j,0) retArray(i,1) = retArray(j,1) retArray(j,0) = temp retArray(j,1) = temp1 End if Next Next j=0 for i=0 to UBound(retArray) SchArray(j) = retArray(i,0) j=j+1 schArray(j) = retArray(i,1) j=j+1 Next For i=0 to (UBound(schArray)-1) step 2 temp = schArray(i) temp1 = schArray(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 'for each cat in scharray ' dd = dd &"#"& cat ' next 'response.write str1 'response.end Do While Right(str1,1) = "," str1 = Left(str1,Len(str1)-1) loop CreateSortedData = str1 End Function Function ConvertScheduleToMinute(SchArray()) For i=0 to (UBound(SchArray)) 'tempArray = Split(SchArray(i),":") 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 CanAddSchedule(schType,schfrom,schto,SchArray) TotalScheduleTime = 0 str2 = "" If UCase(schType) = "D" then for i=0 to UBound(ScheduleArray) - 1 step 2 TotalScheduleTime = TotalScheduleTime + (ScheduleArray(i+1)-ScheduleArray(i)) Next TotalScheduleTime = TotalScheduleTime + (schto - schfrom) if TotalScheduleTime <= (Schedule * 60) then CanAddSchedule = true else anAddSchedule = false End if elseif UCase(schType) = "W" then 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.cursorlocation=3 rs2.cursortype=3 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 then str2 = str2 + ScheduleArray3(0) End if if StrComp(ScheduleArray3(1),"Always") <> 0 And StrComp(ScheduleArray3(1),"Never")<> 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 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 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 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(5),"Never")<> 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(6),"Never")<> 0 then if StrComp(Right(str2,1),",") <> 0 then str2 = str2 + "," + ScheduleArray3(6) else str2 = str2 + Schedulearray3(6) End if 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) for i=0 to UBound(ScheduleArray4) step 2 TotalScheduleTime = TotalScheduleTime + (ScheduleArray4(i+1) - Schedulearray4(i)) Next TotalScheduleTime = TotalScheduleTime + (tempTo1 - tempFrom1) if TotalScheduleTime <= (Schedule * 60) then CanAddSchedule = true else CanAddSchedule = false End if End if End Function 'STARTING POINT OF THIS MODULE set cn = Server.CreateObject("ADODB.Connection") cn.Open "DSN=Kidsnet_Parent;uid=sa;PWD=sgmkj;APP=ASP Script;DATABASE=Kidsnet" Set rs = Server.CreateObject("ADODB.Recordset") rs.cursorlocation=3 rs.cursortype=3 rs.Open "SELECT kidid,schedule,"& schDay &" ScheduleDay From Kidonlinetime where Kidid ='"& kidid &"'",cn if(rs.recordcount = 0)then 'redirect to error page with proper error strErr = "Schedule Type and Total Hours Not Specified for "& right(kidid,len(kidid)-(instr(1,kidid,"_",1)) ) Response.Redirect("ScheduleError.asp?Error=" &strErr ) end if 'If StrComp(FromTime,"always:",VBTextCompare) = 0 or StrComp(FromTime,"always:00",VBTextCompare) = 0 then If StrComp(strTimeCheck,"always:",VBTextCompare) = 0 then str1 = "UPDATE Kidonlinetime SET "&schDay&"='Always'Where kidid = '" &kidid&"'" cn.Execute str1 cn.close() Response.Redirect "ScheduleKid.asp?KidID=" &kidid 'Confirm and on confirm replace schedule in database with Always for that day 'Redirect to schedule page ElseIf StrComp(strTimeCheck,"never:",VBTextCompare) = 0 then str1 = "UPDATE Kidonlinetime SET "&schDay&"='Never'Where kidid = '" &kidid&"'" cn.Execute str1 cn.close() Response.Redirect "ScheduleKid.asp?KidID=" &kidid 'Confirm and on confirm replace schedule in database with Never for that day 'Redirect to schedule page End if if rs.recordcount <> -1 then Schedule = "" ScheduleType = "" ScheduleArray2=0 Schedule = left(rs("schedule"),len(rs("schedule"))-1) ScheduleType = right(rs("schedule"),1) ScheduleArray = Split(rs("ScheduleDay"),",") 'scheduleday is alias for "day" used in select Query ScheduleArray2 = Split(FromTime,":") tempFrom1 = ScheduleArray2(0) * 60 + ScheduleArray2(1) ScheduleArray2 = Split(ToTime,":") tempTo1 = ScheduleArray2(0) * 60 + ScheduleArray2(1) if StrComp(ScheduleArray(0),"Always",VBTextCompare) = 0 then 'check for time span against scheduled hours 'if not more than schedule hours update database If UCase(scheduleType) = "D" then ScheduleArray2 =0 if (Schedule * 60) >= (tempTo1 -tempFrom1) then str2 = "" str2 = FromTime & "-" & ToTime str = "UPDATE Kidonlinetime SET "& schDay &" = '"& str2 &"' Where kidid = '" & kidid & "' " cn.Execute str Response.Redirect "ScheduleKid.asp?KidID=" &kidid Else 'redirect to error page with proper error Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Schedule Time Interval is More Than Allowed Hours") End if Elseif UCase(ScheduleType) = "W" then If true = CanaddSchedule("W",tempFrom1,tempTo1,ScheduleArray5) then str2 = FromTime &"-"& ToTime str = "UPDATE Kidonlinetime SET "&schDay&"= '"& str2 &"' Where kidid = '" &kidid&"'" cn.Execute str Response.Redirect "ScheduleKid.asp?KidID=" &kidid Else 'redirect to error page with proper error Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Exceeding Allowed Hours") End if End if Elseif StrComp(ScheduleArray(0),"Never",VBTextCompare) = 0 then 'check for time span against scheduled hours 'if not more than schedule hours then 'confirm that parent wants to remove restriction 'on confirm update database str3 ="" str ="" If UCase(ScheduleType) = "D" then ScheduleArray2 = Split(FromTime,":") tempFrom1 = ScheduleArray2(0) * 60 + ScheduleArray2(1) ScheduleArray2 = Split(ToTime,":") tempTo1 = ScheduleArray2(0) * 60 + ScheduleArray2(1) ScheduleArray2 =0 if (Schedule * 60) >= (tempTo1 -tempFrom1) then str3 = FromTime &"-"& ToTime str = "UPDATE Kidonlinetime SET "&schDay&"= '"& str3 &"' Where kidid = '" &kidid&"'" cn.Execute str Response.Redirect "ScheduleKid.asp?KidID=" &kidid Else 'redirect to error page with proper error Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Exceeding Allowed Hours") End if Elseif UCase(ScheduleType) = "W" then If true = CanaddSchedule("W",tempFrom1,tempTo1,ScheduleArray5) then str3 = FromTime &"-"& ToTime str = "UPDATE Kidonlinetime SET "&schDay&"= '"& str3 &"' Where kidid = '" &kidid&"'" cn.Execute str Response.Redirect "ScheduleKid.asp?KidID=" &kidid Else 'redirect to error page with proper error Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Exceeding Allowed Hours") End if End if Else str = rs("ScheduleDay") Do While Right(str,1) = "," str = Left(str,Len(str)-1) loop Do While Left(str,1) = "," str = Right(str,Len(str)-1) loop ScheduleArray = Split(Join(split(str,","),"-"),"-") ScheduleArray = ConvertScheduleToMinute(ScheduleArray) ' For each cc in ScheduleArray ' st = st&" "&cc ' Next ' Response.write st ' Response.end ScheduleArray2 = Split(FromTime,":") tempFrom1 = ScheduleArray2(0) * 60 + ScheduleArray2(1) ScheduleArray2 = Split(ToTime,":") tempTo1 = ScheduleArray2(0) * 60 + ScheduleArray2(1) ' for each cat in ScheduleArray ' ss = ss & cat ' next found =1 for i = 0 to UBound(ScheduleArray) step 2 time1 = ScheduleArray(i) time2 = ScheduleArray(i+1) if time1 > tempFrom1 And time1 >= tempTo1 And time2 > tempFrom1 And time2 > tempTo1 then found = 0 Elseif time1 < tempFrom1 And time1 < tempTo1 And time2 <= tempFrom1 And time2 < tempTo1 then found = 0 Else Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Because of Overlapping of Schedules ") found = 1 End if Next if found = 0 And StrComp("D",ScheduleType,VBTextCompare) = 0 then str1="" if True = CanAddSchedule("D",tempFrom1,tempTo1,ScheduleArray) then 'sort data 'update database with from and to time with sorted data str = str & "," & FromTime & "-" & ToTime ScheduleArray = Split(Join(split(str,","),"-"),"-") ScheduleArray = ConvertScheduleToMinute(ScheduleArray) 'for each cat in ScheduleArray ' dd= dd & cat 'next 'dd = CreateSortedData(ScheduleArray) 'response.write dd 'response.end str1 = "UPDATE Kidonlinetime SET "&schDay&"='" & CreateSortedData(ScheduleArray)& "' Where kidid = '" &kidid&"'" cn.Execute str1 Response.Redirect "ScheduleKid.asp?KidID=" &kidid else 'error exceeding schedule time Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Exceeding Allowed Hours") End if Elseif found = 0 And StrComp("W",ScheduleType,VBTextCompare) = 0 then str1 ="" str2 ="" If true = CanAddSchedule("W",tempFrom1,tempTo1,ScheduleArray5) then 'sort data 'update database with from and to time with sorted data if right(str,1) = "," then str = str & FromTime &"-"& ToTime else str = str & "," & FromTime &"-"& ToTime end if Do While Right(str,1) = "," str = Left(str,Len(str)-1) loop ScheduleArray = Split(Join(split(str,","),"-"),"-") ScheduleArray = ConvertScheduleToMinute(ScheduleArray) str2 = CreateSortedDataForWeek(ScheduleArray) str1 = "UPDATE Kidonlinetime SET "&schDay&"='" & str2 & "' Where kidid = '" &kidid&"'" cn.Execute str1 cn.close() Response.Redirect "ScheduleKid.asp?KidID=" &kidid else 'error exceeding schedule time Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Exceeding Allowed Hours") End if Elseif found = 1 then 'error schedule already exists Response.Redirect("ScheduleError.asp?Error=" & "Can Not Add Schedule,Because of Overlapping of Schedules ") End if End if else response.write "First Create the Schedule for Kid :" & kidid &"" response.end end if rs.Close() cn.Close() %>