Esempio n. 1
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Session["BlockGuid"] = BlockCache.Guid;

            if (CurrentCheckInState == null)
            {
                LogException(new CheckInStateLost("Lost check-in state on init"));
                NavigateToPreviousPage();
                return;
            }

            var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"];

            if (kioskTypeCookie != null)
            {
                KioskType = KioskTypeCache.Get(kioskTypeCookie.Value.AsInteger());
            }

            if (KioskType == null)
            {
                NavigateToHomePage();
            }

            RockPage.AddScriptLink("~/scripts/jquery.plugin.min.js");
            RockPage.AddScriptLink("~/scripts/jquery.countdown.min.js");
            RockPage.AddScriptLink("~/Scripts/CheckinClient/ZebraPrint.js");

            RegisterScript();
        }
Esempio n. 2
0
        private void UpdateKioskText()
        {
            if (ddlCampus.SelectedValue.IsNotNullOrWhiteSpace())
            {
                var kioskTypeId = ddlCampus.SelectedValue.AsInteger();
                var kioskType   = KioskTypeCache.Get(kioskTypeId);

                lCampusLava.Text = kioskType.Message;
                DateTime?activeAt = null;
                bool     isOpen   = CheckinIsActive(kioskType, out activeAt);

                if (isOpen)
                {
                    btnSelectCampus.Enabled       = true;
                    btnSelectCampus.OnClientClick = "";
                    btnSelectCampus.Text          = "Begin Check-in";
                }
                else if (activeAt.HasValue)
                {
                    btnSelectCampus.Enabled       = false;
                    btnSelectCampus.OnClientClick = "javascript:return false;";
                    lblActiveWhen.Text            = activeAt.Value.AddSeconds(30).ToString("o");
                    RegisterCountdownScript();
                }
                else
                {
                    btnSelectCampus.Enabled       = false;
                    btnSelectCampus.OnClientClick = "javascript:return false;";
                    btnSelectCampus.Text          = "No More Check-ins Today";
                }
            }
        }
        protected void gKioskTypes_RowSelected(object sender, RowEventArgs e)
        {
            var id   = e.RowKeyValue.ToString().AsInteger();
            var item = KioskTypeCache.Get(id);

            KioskTypeCache.ClearForTemplateId(item.CheckinTemplateId ?? 0);
        }
Esempio n. 4
0
        public HttpResponseMessage KioskStatus(int param)
        {
            CheckInState currentCheckInState;
            var          kioskType = KioskTypeCache.Get(param);
            var          Session   = HttpContext.Current.Session;

            if (Session["CheckInState"] != null)
            {
                currentCheckInState = Session["CheckInState"] as CheckInState;
            }
            else
            {
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, new Dictionary <string, bool> {
                    { "active", false }
                }));
            }

            if (kioskType == null ||
                currentCheckInState == null ||
                !kioskType.IsOpen() ||
                currentCheckInState.Kiosk.FilteredGroupTypes(currentCheckInState.ConfiguredGroupTypes).Count == 0 ||
                !currentCheckInState.Kiosk.HasLocations(currentCheckInState.ConfiguredGroupTypes))
            {
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, new Dictionary <string, bool> {
                    { "active", false }
                }));
            }

            return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, new Dictionary <string, bool> {
                { "active", true }
            }));
        }
Esempio n. 5
0
        protected void btnSelectCampus_Click(object sender, EventArgs e)
        {
            var kiosk     = ConfigureKiosk();
            var kioskType = KioskTypeCache.Get(kiosk.KioskTypeId ?? 0);

            PersonService.SaveUserPreference(currentPerson, UserPreferenceKeys.PreferredCampusId, kioskType.CampusId.ToString());

            DateTime?activeAt = null;

            if (CheckinIsActive(kioskType, out activeAt))
            {
                ActivateCheckIn();
            }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            RockPage.AddScriptLink("~/Scripts/CheckinClient/ZebraPrint.js");

            var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"];

            if (kioskTypeCookie != null)
            {
                KioskType = KioskTypeCache.Get(kioskTypeCookie.Value.AsInteger());
            }

            if (KioskType == null)
            {
                NavigateToPreviousPage();
            }
        }
Esempio n. 7
0
        private Kiosk ConfigureKiosk()
        {
            var rockContext = new RockContext();
            var kioskTypeId = ddlCampus.SelectedValue.AsInteger();

            var kioskType = KioskTypeCache.Get(kioskTypeId);

            var kioskName = "Mobile:" + kioskType.Name.RemoveAllNonAlphaNumericCharacters();

            var mobileUserCategory = CategoryCache.Get(org.secc.FamilyCheckin.Utilities.Constants.KIOSK_CATEGORY_MOBILEUSER);

            var kioskService = new KioskService(rockContext);
            var kiosk        = kioskService.Queryable("KioskType")
                               .Where(k => k.Name == kioskName)
                               .FirstOrDefault();

            if (kiosk == null)
            {
                kiosk = new Kiosk
                {
                    Name        = kioskName,
                    CategoryId  = mobileUserCategory.Id,
                    Description = "Automatically created mobile Kiosk"
                };
                kioskService.Add(kiosk);
            }

            kiosk.KioskTypeId = kioskType.Id;
            rockContext.SaveChanges();

            DeviceService deviceService = new DeviceService(rockContext);


            //Load matching device and update or create information
            var device = deviceService.Queryable("Location").Where(d => d.Name == kioskName).FirstOrDefault();

            var dirty = false;

            //create new device to match our kiosk
            if (device == null)
            {
                device = new Device();
                device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id;
                device.Name = kioskName;
                deviceService.Add(device);
                device.PrintFrom       = PrintFrom.Client;
                device.PrintToOverride = PrintTo.Default;
                dirty = true;
            }

            var deviceLocationIds = device.Locations.Select(l => l.Id);
            var ktLocationIds     = kioskType.Locations.Select(l => l.Id);

            var unmatchedDeviceLocations = deviceLocationIds.Except(ktLocationIds).Any();
            var unmatchedKtLocations     = ktLocationIds.Except(deviceLocationIds).Any();

            if (unmatchedDeviceLocations || unmatchedKtLocations)
            {
                LocationService locationService = new LocationService(rockContext);
                device.Locations.Clear();
                foreach (var loc in kioskType.Locations.ToList())
                {
                    var location = locationService.Get(loc.Id);
                    device.Locations.Add(location);
                }
                dirty = true;
            }

            if (this.IsUserAuthorized(Rock.Security.Authorization.ADMINISTRATE))
            {
                device.LoadAttributes();

                if (PageParameter("datetime").IsNotNullOrWhiteSpace())
                {
                    device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime"));
                }
                else
                {
                    device.SetAttributeValue("core_device_DebugDateTime", "");
                }
            }

            if (dirty)
            {
                rockContext.SaveChanges();
                device.SaveAttributeValues(rockContext);
                KioskDevice.Remove(device.Id);
            }

            LocalDeviceConfig.CurrentKioskId       = device.Id;
            LocalDeviceConfig.CurrentGroupTypeIds  = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList();
            LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId;

            CurrentCheckInState = null;
            CurrentWorkflow     = null;

            var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"];

            if (kioskTypeCookie == null)
            {
                kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId");
            }

            kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1);
            kioskTypeCookie.Value   = kiosk.KioskType.Id.ToString();

            this.Page.Response.Cookies.Set(kioskTypeCookie);

            Session["KioskTypeId"] = kioskType.Id;
            SaveState();
            return(kiosk);
        }
Esempio n. 8
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var isMobile          = GetAttributeValue(action, "IsMobile").AsBoolean();
            var mobileDidAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_DID_ATTEND).Id;
            var mobileNotAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_NOT_ATTEND).Id;

            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                KioskService kioskService = new KioskService(rockContext);
                var          kioskTypeId  = kioskService.GetByClientName(checkInState.Kiosk.Device.Name).KioskTypeId;
                var          kioskType    = KioskTypeCache.Get(kioskTypeId.Value);
                var          campusId     = kioskType.CampusId;
                if (campusId == null)
                {
                    var compatableKioskType = KioskTypeCache.All().Where(kt => kt.CampusId.HasValue && kt.CheckinTemplateId == kioskType.CheckinTemplateId).FirstOrDefault();
                    if (compatableKioskType != null)
                    {
                        campusId = compatableKioskType.CampusId;
                    }
                    else
                    {
                        campusId = 0;
                    }
                }

                campusId = GetCampusOrFamilyCampusId(campusId, checkInState.CheckIn.CurrentFamily.Group.CampusId);


                AttendanceCode attendanceCode = null;
                DateTime       startDateTime  = Rock.RockDateTime.Now;
                DateTime       today          = startDateTime.Date;
                DateTime       tomorrow       = startDateTime.AddDays(1);

                bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode;
                int  securityCodeLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3;

                var attendanceCodeService = new AttendanceCodeService(rockContext);
                var attendanceService     = new AttendanceService(rockContext);
                var groupMemberService    = new GroupMemberService(rockContext);
                var personAliasService    = new PersonAliasService(rockContext);

                //This list is just for mobile check-in
                List <Attendance> attendances = new List <Attendance>();

                var family = checkInState.CheckIn.CurrentFamily;
                if (family != null)
                {
                    foreach (var person in family.GetPeople(true))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GetGroupTypes(true))
                        {
                            foreach (var group in groupType.GetGroups(true))
                            {
                                if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
                                    groupType.GroupType.DefaultGroupRoleId.HasValue &&
                                    !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any())
                                {
                                    var groupMember = new GroupMember();
                                    groupMember.GroupId     = group.Group.Id;
                                    groupMember.PersonId    = person.Person.Id;
                                    groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
                                    groupMemberService.Add(groupMember);
                                }

                                foreach (var location in group.GetLocations(true))
                                {
                                    foreach (var schedule in location.GetSchedules(true))
                                    {
                                        var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                        if (primaryAlias != null)
                                        {
                                            int groupId = ActualGroupId(group.Group);
                                            // If a like attendance service exists close it before creating another one.
                                            var oldAttendance = attendanceService.Queryable()
                                                                .Where(a =>
                                                                       a.StartDateTime >= today &&
                                                                       a.StartDateTime < tomorrow &&
                                                                       a.Occurrence.LocationId == location.Location.Id &&
                                                                       a.Occurrence.ScheduleId == schedule.Schedule.Id &&
                                                                       a.Occurrence.GroupId == groupId &&
                                                                       a.PersonAlias.PersonId == person.Person.Id)
                                                                .FirstOrDefault();

                                            if (oldAttendance != null)
                                            {
                                                oldAttendance.EndDateTime = Rock.RockDateTime.Now;
                                                oldAttendance.DidAttend   = false;
                                            }
                                            var attendance = attendanceService.AddOrUpdate(primaryAlias.Id, startDateTime.Date, groupId,
                                                                                           location.Location.Id, schedule.Schedule.Id, campusId ?? location.CampusId,
                                                                                           checkInState.Kiosk.Device.Id, checkInState.CheckIn.SearchType.Id,
                                                                                           checkInState.CheckIn.SearchValue, family.Group.Id, attendanceCode.Id);

                                            attendance.DeviceId                 = checkInState.Kiosk.Device.Id;
                                            attendance.SearchTypeValueId        = checkInState.CheckIn.SearchType.Id;
                                            attendance.SearchValue              = checkInState.CheckIn.SearchValue;
                                            attendance.CheckedInByPersonAliasId = checkInState.CheckIn.CheckedInByPersonAliasId;
                                            attendance.SearchResultGroupId      = family.Group.Id;
                                            attendance.AttendanceCodeId         = attendanceCode.Id;
                                            attendance.CreatedDateTime          = startDateTime;
                                            attendance.StartDateTime            = startDateTime;
                                            attendance.EndDateTime              = null;
                                            attendance.Note      = group.Notes;
                                            attendance.DidAttend = isMobile ? false : groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean();
                                            if (isMobile)
                                            {
                                                if (groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean())
                                                {
                                                    attendance.QualifierValueId = mobileDidAttendId;
                                                }
                                                else
                                                {
                                                    attendance.QualifierValueId = mobileNotAttendId;
                                                }
                                            }
                                            ;

                                            attendanceService.Add(attendance);
                                            attendances.Add(attendance);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (isMobile)
                {
                    var alreadyExistingMobileCheckin = MobileCheckinRecordCache.GetActiveByFamilyGroupId(checkInState.CheckIn.CurrentFamily.Group.Id);
                    if (alreadyExistingMobileCheckin != null)
                    {
                        //This should never run, it's just in case. Each family should only have 1 mobile check-in reservation.
                        MobileCheckinRecordCache.CancelReservation(alreadyExistingMobileCheckin, true);
                    }

                    campusId = RollUpToParentCampus(campusId);

                    MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext);
                    var mobileCheckinRecord = new MobileCheckinRecord
                    {
                        AccessKey             = "MCR" + Guid.NewGuid().ToString("N").Substring(0, 12),
                        ReservedUntilDateTime = Rock.RockDateTime.Now.AddMinutes(kioskType.MinutesValid ?? 10),
                        ExpirationDateTime    = Rock.RockDateTime.Now.AddMinutes((kioskType.MinutesValid ?? 10) + (kioskType.GraceMinutes ?? 60)),
                        UserName      = checkInState.CheckIn.SearchValue,
                        FamilyGroupId = checkInState.CheckIn.CurrentFamily.Group.Id,
                        CampusId      = campusId.Value
                    };

                    foreach (var attendance in attendances)
                    {
                        mobileCheckinRecord.Attendances.Add(attendance);
                    }

                    mobileCheckinRecordService.Add(mobileCheckinRecord);
                }

                rockContext.SaveChanges();
                foreach (var attendance in attendances)
                {
                    AttendanceCache.AddOrUpdate(attendance);
                }
                return(true);
            }
            errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null.");
            return(false);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            KioskType kioskType = null;

            var rockContext      = new RockContext();
            var kioskTypeService = new KioskTypeService(rockContext);
            var attributeService = new AttributeService(rockContext);
            var locationService  = new LocationService(rockContext);
            var scheduleService  = new ScheduleService(rockContext);
            var groupTypeService = new GroupTypeService(rockContext);

            int kioskTypeId = int.Parse(hfKioskTypeId.Value);

            if (kioskTypeId != 0)
            {
                kioskType = kioskTypeService.Get(kioskTypeId);
            }

            if (kioskType == null)
            {
                kioskType = new KioskType();
                kioskTypeService.Add(kioskType);
            }

            if (kioskType != null)
            {
                kioskType.Name         = tbName.Text;
                kioskType.Description  = tbDescription.Text;
                kioskType.Message      = tbMessage.Text;
                kioskType.IsMobile     = cbIsMobile.Checked;
                kioskType.MinutesValid = tbMinutesValid.Text.AsIntegerOrNull();
                kioskType.GraceMinutes = tbGraceMinutes.Text.AsIntegerOrNull();


                if (!kioskType.IsValid || !Page.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                // Remove any deleted locations
                foreach (var location in kioskType.Locations
                         .Where(l =>
                                !Locations.Keys.Contains(l.Id))
                         .ToList())
                {
                    kioskType.Locations.Remove(location);
                }

                // Remove any deleted schedules
                foreach (var schedule in kioskType.Schedules
                         .Where(s =>
                                !Schedules.Keys.Contains(s.Id))
                         .ToList())
                {
                    kioskType.Schedules.Remove(schedule);
                }

                // Add any new locations
                var existingLocationIDs = kioskType.Locations.Select(l => l.Id).ToList();
                foreach (var location in locationService.Queryable()
                         .Where(l =>
                                Locations.Keys.Contains(l.Id) &&
                                !existingLocationIDs.Contains(l.Id)))
                {
                    kioskType.Locations.Add(location);
                }

                // Add any new schedules
                var existingScheduleIDs = kioskType.Schedules.Select(s => s.Id).ToList();
                foreach (var schedule in scheduleService.Queryable()
                         .Where(s =>
                                Schedules.Keys.Contains(s.Id) &&
                                !existingScheduleIDs.Contains(s.Id)))
                {
                    kioskType.Schedules.Add(schedule);
                }

                //Save checkin template
                kioskType.CheckinTemplateId = ddlTemplates.SelectedValue.AsInteger();


                var GroupTypes = kioskType.GroupTypes;
                GroupTypes.Clear();

                foreach (ListItem item in cblPrimaryGroupTypes.Items)
                {
                    if (item.Selected)
                    {
                        GroupTypes.Add(groupTypeService.Get(item.Value.AsInteger()));
                    }
                }

                kioskType.CampusId = ddlCampus.SelectedCampusId;

                rockContext.SaveChanges();

                KioskTypeCache.Remove(kioskType.Id);
                KioskTypeCache.Get(kioskType.Id);
                Rock.CheckIn.KioskDevice.Clear();

                NavigateToParentPage();
            }
        }