public void Disable(List <int> validUsers) { XDocument xdocResults = GetPeople(); if (xdocResults != null) { AttributeGroup pcoAttrGroup = GetPcoAttributeGroup(_organizationId, _pcoAccount); Arena.Core.Attribute pcoIDAttr = GetPcoAttribute(pcoAttrGroup, "PCO_ID", Enums.DataType.String); Arena.DataLayer.Organization.OrganizationData oData = new DataLayer.Organization.OrganizationData(); foreach (XElement xPerson in xdocResults.Descendants("person")) { try { string pcoID = xPerson.Descendants("id").First().Value; string sql = string.Format("SELECT person_id FROM core_person_attribute WHERE attribute_id = {0} AND int_value = {1}", pcoIDAttr.AttributeId.ToString(), pcoID); System.Data.SqlClient.SqlDataReader rdr = oData.ExecuteReader(sql); if (rdr.Read()) { if (!validUsers.Contains((int)rdr["person_id"])) { Disable(pcoID); } } rdr.Close(); } catch { } } } }
public static Arena.Core.Attribute GetPcoAttribute(AttributeGroup attributeGroup, string attributeName, DataType attributeType) { Arena.Core.Attribute pcoAttribute = attributeGroup.Attributes.FindByName(attributeName); if (pcoAttribute == null || pcoAttribute.AttributeId == -1) { Arena.DataLayer.Organization.OrganizationData oData = new Arena.DataLayer.Organization.OrganizationData(); string sql = string.Format( "SELECT ISNULL(MAX(attribute_order),-1) FROM core_attribute WHERE attribute_group_id = {0}", attributeGroup.AttributeGroupId.ToString()); int groupOrder = (int)oData.ExecuteScalar(sql); Guid attributeGuid = Guid.NewGuid(); sql = string.Format( "insert into core_attribute (guid, attribute_group_id, attribute_name, attribute_type, attribute_order) values ('{0}', {1}, '{2}', '{3}', (({4})+2))", attributeGuid.ToString(), attributeGroup.AttributeGroupId.ToString(), attributeName, Enum.Format(typeof(DataType), attributeType, "D"), groupOrder.ToString()); oData.ExecuteNonQuery(sql); pcoAttribute = new Arena.Core.Attribute(attributeGuid); attributeGroup.Attributes.Add(pcoAttribute); } return(pcoAttribute); }
private void LoadAttributes() { if (!string.IsNullOrEmpty(this.AttributesSetting)) { string[] array = this.AttributesSetting.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string s = array2[i]; int num = -1; if (int.TryParse(s, out num) && num != -1) { Arena.Core.Attribute attribute = new Arena.Core.Attribute(num); PersonAttribute personAttribute = (PersonAttribute)this.person.Attributes.FindByID(attribute.AttributeId); if (personAttribute == null) { personAttribute = new PersonAttribute(this.person.PersonID, num); } this.AddAttributeEdit(attribute, personAttribute, !this.Page.IsPostBack); } } } }
protected IEnumerable <Lookup> GetTopicPreferences() { IEnumerable <int> lookupIDs = null; if (Request.IsAuthenticated) { var attribute = new Arena.Core.Attribute(SystemGuids.WEB_PREFS_NEWS_TOPICS_ATTRIBUTE); var pa = new PersonAttribute(CurrentPerson.PersonID, attribute.AttributeId); if (!string.IsNullOrEmpty(pa.StringValue)) { lookupIDs = pa.StringValue.SplitAndConvertTo <int>(new[] { ',' }, Convert.ToInt32); } } else { var cookie = Request.Cookies["Cccev.Web.Settings"] != null ? Request.Cookies["Cccev.Web.Settings"].Value : Constants.NULL_STRING; var array = Server.UrlDecode(cookie).Split(new[] { "|||" }, StringSplitOptions.None); if (!string.IsNullOrEmpty(array.Last().Trim())) { lookupIDs = array.Last().SplitAndConvertTo <int>(new[] { ',' }, Convert.ToInt32); } } return(lookupIDs != null ? (from s in lookupIDs select new Lookup(s)).ToList() : new List <Lookup>()); }
/// <summary> /// Verifies that a valid Tag and Attribute were selected, then loops through the ProfileMembers of the selected Tag /// and calls the SaveAttributeValue method for each ProfileMember /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnCreate_Click(object sender, EventArgs e) { if (ppTag.ProfileID == -1 || drpAttribute.SelectedValue == "-1") return; Profile p = new Profile(ppTag.ProfileID); Arena.Core.Attribute attr = new Arena.Core.Attribute(int.Parse(drpAttribute.SelectedValue)); if (p.ProfileID == -1 && attr.AttributeId != -1) return; int memberCount = 0; try { foreach (ProfileMember member in p.Members) { PersonAttribute pa = new PersonAttribute(member.PersonID, attr.AttributeId); if (pa.PersonID == -1) pa.PersonID = member.PersonID; if (SaveAttributeValue(pa, member, cbOverwrite.Checked)) memberCount++; } lcResult.Text = string.Format("{0} Member(s) updated", memberCount.ToString()); } catch (Exception ex) { lcMessage.Text = "The following errors have occurred:<br />" + ex.Message; pnlError.Visible = true; lcResult.Text = string.Format("{0} Member(s) updated", memberCount.ToString()); } }
private static void SavePersonAttribute(Person person, string facebookID, int orgID) { var attribute = new Arena.Core.Attribute(SystemGuids.FACEBOOK_USER_ID_ATTRIBUTE); var facebookSetting = new PersonAttribute { PersonID = person.PersonID, AttributeId = attribute.AttributeId, StringValue = facebookID }; facebookSetting.Save(orgID, CREATED_BY); }
protected void SetFromAttributeAndAdd(WebControl control, Arena.Core.Attribute attribute) { Label label = new Label(); label.Text = attribute.AttributeName + " "; control.ID = attribute.AttributeId.ToString(); control.Enabled = (attribute.Readonly == false ? true : false); phAttributes.Controls.Add(label); phAttributes.Controls.Add(control); }
private static PersonAttribute GetPcoPersonAttribute(Lookup pcoAccount, Person person, string attributeName) { AttributeGroup attributeGroup = GetPcoAttributeGroup(person.OrganizationID, pcoAccount); if (attributeGroup != null) { Arena.Core.Attribute pcoAttribute = attributeGroup.Attributes.FindByName(attributeName); if (pcoAttribute != null) { PersonAttribute pa = (PersonAttribute)person.Attributes.FindByID(pcoAttribute.AttributeId); if (pa == null) { pa = new PersonAttribute(person.PersonID, pcoAttribute.AttributeId); } return(pa); } } return(null); }
/// <summary> /// Verifies that a valid Tag and Attribute were selected, then loops through the ProfileMembers of the selected Tag /// and calls the SaveAttributeValue method for each ProfileMember /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnCreate_Click(object sender, EventArgs e) { if (ppTag.ProfileID == -1 || drpAttribute.SelectedValue == "-1") { return; } Profile p = new Profile(ppTag.ProfileID); Arena.Core.Attribute attr = new Arena.Core.Attribute(int.Parse(drpAttribute.SelectedValue)); if (p.ProfileID == -1 && attr.AttributeId != -1) { return; } int memberCount = 0; try { foreach (ProfileMember member in p.Members) { PersonAttribute pa = new PersonAttribute(member.PersonID, attr.AttributeId); if (pa.PersonID == -1) { pa.PersonID = member.PersonID; } if (SaveAttributeValue(pa, member, cbOverwrite.Checked)) { memberCount++; } } lcResult.Text = string.Format("{0} Member(s) updated", memberCount.ToString()); } catch (Exception ex) { lcMessage.Text = "The following errors have occurred:<br />" + ex.Message; pnlError.Visible = true; lcResult.Text = string.Format("{0} Member(s) updated", memberCount.ToString()); } }
private void AddAttributeEdit(Arena.Core.Attribute attribute, PersonAttribute personAttribute, bool setValues) { TableRow tableRow = new TableRow(); tableRow.ID = "trAttribute_" + attribute.AttributeId.ToString(); TableCell tableCell = new TableCell(); tableRow.Cells.Add(tableCell); tableCell.ID = "tcAttribute_" + attribute.AttributeId.ToString(); tableCell.VerticalAlign = VerticalAlign.Middle; tableCell.HorizontalAlign = HorizontalAlign.Right; tableCell.Wrap = false; tableCell.CssClass = "formLabel"; tableCell.Text = attribute.AttributeName; tableCell = new TableCell(); tableCell.CssClass = "formItem"; tableCell.Wrap = false; tableRow.Cells.Add(tableCell); new AttributeHelper { EditItemCssClass = "formItem" }.AddEditControls(tableCell, attribute, personAttribute, setValues); this.tbl.Rows.AddAt(this.tbl.Rows.Count - 2, tableRow); }
private void LoadFbAttributes() { const string OPT_OUT_KEY = "CentralAZ.Web.FacebookAuth.OptOut"; const string CONNECT_KEY = "CentralAZ.Web.FacebookAuth.AccountIsConnected"; //if (Session[OPT_OUT_KEY] != null || Session[CONNECT_KEY] != null) //{ // hasOptedOut = Convert.ToBoolean(Session[OPT_OUT_KEY]); // connectedToFacebook = Convert.ToBoolean(Session[CONNECT_KEY]); // return; //} var optOutAttribute = new Arena.Core.Attribute(SystemGuids.FACEBOOK_OPT_OUT_ATTRIBUTE); var optedOut = new PersonAttribute(CurrentPerson.PersonID, optOutAttribute.AttributeId); hasOptedOut = Convert.ToBoolean(optedOut.IntValue); //Session[OPT_OUT_KEY] = hasOptedOut; var facebookIdAttribute = new Arena.Core.Attribute(SystemGuids.FACEBOOK_USER_ID_ATTRIBUTE); var facebookID = new PersonAttribute(CurrentPerson.PersonID, facebookIdAttribute.AttributeId); connectedToFacebook = !string.IsNullOrEmpty(facebookID.StringValue); //Session[CONNECT_KEY] = connectedToFacebook; }
public override bool PerformAction(DataUpdate dataUpdate) { // Create objects based on setting Arena.Core.Attribute attribute = new Arena.Core.Attribute((Convert.ToInt32(AttributeIdSetting))); // Add primary key to 'Before' dataset so that it can be searched if (dataUpdate.DataBefore != null) { DataColumn[] primaryKey = new DataColumn[2]; primaryKey[0] = dataUpdate.DataBefore.Columns["person_id"]; primaryKey[1] = dataUpdate.DataBefore.Columns["attribute_id"]; dataUpdate.DataBefore.PrimaryKey = primaryKey; } // Loop through each new row if (dataUpdate.DataAfter != null) { foreach (DataRow newRow in dataUpdate.DataAfter.Rows) { // If this update is for the attribute type we care about if (Convert.ToInt32(newRow["attribute_id"].ToString()) == attribute.AttributeId) { // Load New Person Attribute PersonAttribute newPA = new PersonAttribute(attribute.AttributeId); newPA.PersonID = Convert.ToInt32(newRow["person_id"].ToString()); if (newRow["int_value"] != DBNull.Value) { newPA.IntValue = Convert.ToInt32(newRow["int_value"].ToString()); } if (newRow["decimal_value"] != DBNull.Value) { newPA.DecimalValue = Convert.ToDecimal(newRow["decimal_value"].ToString()); } if (newRow["varchar_value"] != DBNull.Value) { newPA.StringValue = newRow["varchar_value"].ToString(); } if (newRow["datetime_value"] != DBNull.Value) { newPA.DateValue = Convert.ToDateTime(newRow["datetime_value"].ToString()); } // If this is a date attribute and the ignore date setting is set, make sure the date setting is not too old if (IgnoreDateDaysSetting == "-1" || newPA.AttributeType != Arena.Enums.DataType.DateTime || newPA.DateValue.AddDays(Convert.ToInt32(IgnoreDateDaysSetting)).CompareTo(DateTime.Today) >= 0) { // If we don't need a specific value or the value is equal to our test value if (SpecificValueSetting == string.Empty || newPA.ToString().Trim().ToLower() == SpecificValueSetting.Trim().ToLower()) { // Look for the previous version of this row DataRow oldRow = null; if (dataUpdate.DataBefore != null) { object[] key = new object[2]; key[0] = newPA.PersonID; key[1] = newPA.AttributeId; oldRow = dataUpdate.DataBefore.Rows.Find(key); } string title = string.Empty; string description = string.Empty; // If a previous version doesn't exist (was an add) if (oldRow == null) { title = attribute.AttributeName + " Value Added"; description = string.Format("{0} was updated to '{1}' on {2} at {3}.", attribute.AttributeName, newPA.ToString(), dataUpdate.UpdateDateTime.ToShortDateString(), dataUpdate.UpdateDateTime.ToShortTimeString()); } else { // Load Old Person Attribute PersonAttribute oldPA = new PersonAttribute(attribute.AttributeId); oldPA.PersonID = Convert.ToInt32(oldRow["person_id"].ToString()); if (oldRow["int_value"] != DBNull.Value) { oldPA.IntValue = Convert.ToInt32(oldRow["int_value"].ToString()); } if (oldRow["decimal_value"] != DBNull.Value) { oldPA.DecimalValue = Convert.ToDecimal(oldRow["decimal_value"].ToString()); } if (oldRow["varchar_value"] != DBNull.Value) { oldPA.StringValue = oldRow["varchar_value"].ToString(); } if (oldRow["datetime_value"] != DBNull.Value) { oldPA.DateValue = Convert.ToDateTime(oldRow["datetime_value"].ToString()); } // Or it was different (was an update) if (newPA.ToString() != oldPA.ToString()) { title = attribute.AttributeName + " Value Updated"; description = string.Format("{0} was updated from '{1}' to '{2}' on {3} at {4}.", attribute.AttributeName, oldPA.ToString(), newPA.ToString(), dataUpdate.UpdateDateTime.ToShortDateString(), dataUpdate.UpdateDateTime.ToShortTimeString()); } } // Create a new assignment if (title != string.Empty) { AssignmentType assignmentType = new AssignmentType((Convert.ToInt32(AssignmentTypeIdSetting))); Assignment assignment = new Assignment(); assignment.AssignmentTypeId = assignmentType.AssignmentTypeId; assignment.Title = title; assignment.Description = description; assignment.RequesterPersonId = Convert.ToInt32(newRow["person_id"].ToString()); assignment.PriorityId = assignmentType.DefaultPriorityId; assignment.SubmitAssignmentEntry(null, "PersonAttributeDataChange"); } } } } } } return(true); }
private string CreateStaffXML() { StringBuilder sbMessages = new StringBuilder(); AttributeGroup StaffDetailsGroup = new AttributeGroup(StaffDetailsAttributeGroupID); Arena.Core.Attribute departmentAttribute = new Arena.Core.Attribute(DepartmentAttributeID); LookupType departments = new LookupType(Convert.ToInt32(departmentAttribute.TypeQualifier)); List <StaffMember> staff = new List <StaffMember>(); PersonCollection people = new PersonCollection(); people.LoadStaffMembers(); foreach (Person person in people) { string title = string.Empty; Lookup department = null; Lookup departmentPosition = null; PersonAttribute pa = (PersonAttribute)person.Attributes.FindByID(PositionAttributeID); if (pa != null) { title = pa.StringValue; } pa = (PersonAttribute)person.Attributes.FindByID(DepartmentAttributeID); if (pa != null && pa.IntValue != -1) { department = new Lookup(pa.IntValue); } pa = (PersonAttribute)person.Attributes.FindByID(DepartmentPositionAttributeID); if (pa != null && pa.IntValue != -1) { departmentPosition = new Lookup(pa.IntValue); } if (department != null && departmentPosition != null) { staff.Add(new StaffMember( person.PersonID, person.PersonGUID, person.NickName, person.LastName, person.Blob != null ? person.Blob.GUID : Guid.Empty, person.Emails.FirstActive, title, department, departmentPosition)); } } staff.Sort(); // Delete any existing department XML files in the staff folder DirectoryInfo staffFolder = new DirectoryInfo(Path.Combine(XMLFolderPath, "Staff")); if (staffFolder.Exists) { foreach (FileInfo fi in staffFolder.GetFiles()) { try { fi.Delete(); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not delete {0} file: {1}\n", fi.FullName, ex.Message); } } } else { staffFolder.Create(); } if (staff.Count > 0) { LookupCollection activeDepartments = new LookupCollection(); Lookup currentDepartment = new Lookup(); XmlDocument xdoc = null; XmlNode departmentNode = null; foreach (StaffMember StaffMember in staff) { if (currentDepartment.LookupID != StaffMember.Department.LookupID) { if (xdoc != null) { string path = Path.Combine(staffFolder.FullName, currentDepartment.Guid.ToString() + ".xml"); try { xdoc.Save(path); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message); } } currentDepartment = StaffMember.Department; activeDepartments.Add(currentDepartment); xdoc = new XmlDocument(); departmentNode = xdoc.CreateNode(XmlNodeType.Element, "department", xdoc.NamespaceURI); XmlAttribute xattr = xdoc.CreateAttribute("", "name", xdoc.NamespaceURI); xattr.Value = currentDepartment.Value; departmentNode.Attributes.Append(xattr); xdoc.AppendChild(departmentNode); } departmentNode.AppendChild(StaffMember.XMLNode(xdoc)); if (StaffMember.DepartmentPosition.Qualifier2 == "1") { XmlDocument xdocStaff = new XmlDocument(); XmlNode xnodeStaff = StaffMember.XMLNode(xdocStaff); xdocStaff.AppendChild(xnodeStaff); if (_assistantTypeID != -1) { RelationshipCollection relationships = new RelationshipCollection(StaffMember.ID); foreach (Relationship relationship in relationships) { if (relationship.RelationshipTypeId == _assistantTypeID) { XmlNode xnodeAssistant = xdocStaff.CreateNode(XmlNodeType.Element, "assistant", xdocStaff.NamespaceURI); XmlAttribute xattr = xdocStaff.CreateAttribute("", "fn", xdocStaff.NamespaceURI); xattr.Value = relationship.RelatedPerson.NickName; xnodeAssistant.Attributes.Append(xattr); xattr = xdocStaff.CreateAttribute("", "ln", xdocStaff.NamespaceURI); xattr.Value = relationship.RelatedPerson.LastName; xnodeAssistant.Attributes.Append(xattr); xattr = xdocStaff.CreateAttribute("", "email", xdocStaff.NamespaceURI); xattr.Value = relationship.RelatedPerson.Emails.FirstActive; xnodeAssistant.Attributes.Append(xattr); xnodeStaff.AppendChild(xnodeAssistant); break; } } } PersonAttributeCollection pAttributes = new PersonAttributeCollection(); pAttributes.LoadByGroup(StaffDetailsGroup, StaffMember.ID); foreach (PersonAttribute pa in pAttributes) { if (pa.AttributeType == Arena.Enums.DataType.Document) { if (BioDocumentTypeID != -1 && pa.TypeQualifier == BioDocumentTypeID.ToString()) { Arena.Utility.ArenaDataBlob bioDoc = new Arena.Utility.ArenaDataBlob(pa.IntValue); if (bioDoc.FileExtension == "txt") { ASCIIEncoding enc = new ASCIIEncoding(); string bio = enc.GetString(bioDoc.ByteArray); if (bio != string.Empty) { XmlNode xnodeBio = xdocStaff.CreateNode(XmlNodeType.Element, "biography", xdocStaff.NamespaceURI); xnodeBio.AppendChild(xdocStaff.CreateCDataSection(bio)); xnodeStaff.AppendChild(xnodeBio); } } } } else { XmlNode xnodeAttribute = xdocStaff.CreateNode(XmlNodeType.Element, "attribute", xdocStaff.NamespaceURI); XmlAttribute xattr = xdocStaff.CreateAttribute("", "name", xdocStaff.NamespaceURI); xattr.Value = pa.AttributeName; xnodeAttribute.Attributes.Append(xattr); xattr = xdocStaff.CreateAttribute("", "value", xdocStaff.NamespaceURI); xattr.Value = pa.ToString(); xnodeAttribute.Attributes.Append(xattr); xnodeStaff.AppendChild(xnodeAttribute); } } string path = Path.Combine(staffFolder.FullName, StaffMember.Guid.ToString() + ".xml"); try { xdocStaff.Save(path); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message); } } } if (xdoc != null) { string path = Path.Combine(staffFolder.FullName, currentDepartment.Guid.ToString() + ".xml"); try { xdoc.Save(path); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message); } } XmlDocument xdocDepartments = new XmlDocument(); XmlNode xnodeDepartments = xdocDepartments.CreateNode(XmlNodeType.Element, "departments", xdocDepartments.NamespaceURI); xdocDepartments.AppendChild(xnodeDepartments); foreach (Lookup activeDepartment in activeDepartments) { XmlNode xnodeDepartment = xdocDepartments.CreateNode(XmlNodeType.Element, "department", xdocDepartments.NamespaceURI); XmlAttribute xattr = xdocDepartments.CreateAttribute("", "guid", xdocDepartments.NamespaceURI); xattr.Value = activeDepartment.Guid.ToString(); xnodeDepartment.Attributes.Append(xattr); xattr = xdocDepartments.CreateAttribute("", "name", xdocDepartments.NamespaceURI); xattr.Value = activeDepartment.Value; xnodeDepartment.Attributes.Append(xattr); XmlNode xnodeDeptDescription = xdocDepartments.CreateNode(XmlNodeType.Element, "description", xdocDepartments.NamespaceURI); xnodeDeptDescription.InnerText = activeDepartment.Qualifier8; xnodeDepartment.AppendChild(xnodeDeptDescription); xnodeDepartments.AppendChild(xnodeDepartment); } try { xdocDepartments.Save(Path.Combine(staffFolder.FullName, "departments.xml")); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not save {0} file: {1}\n", Path.Combine(staffFolder.FullName, "departments.xml"), ex.Message); } } return(sbMessages.ToString()); }