// 09/11/2007 Paul. Provide quick access to team management flags. protected void Page_Command(Object sender, CommandEventArgs e) { try { if (e.CommandName == "Teams.Enable") { SqlProcs.spCONFIG_Update("system", "enable_team_management", "true"); Application["CONFIG.enable_team_management"] = true; } else if (e.CommandName == "Teams.Disable") { SqlProcs.spCONFIG_Update("system", "enable_team_management", "false"); Application["CONFIG.enable_team_management"] = false; } else if (e.CommandName == "Teams.Require") { SqlProcs.spCONFIG_Update("system", "require_team_management", "true"); Application["CONFIG.require_team_management"] = true; } else if (e.CommandName == "Teams.Optional") { SqlProcs.spCONFIG_Update("system", "require_team_management", "false"); Application["CONFIG.require_team_management"] = false; } // 01/01/2008 Paul. We need a quick way to require user assignments across the system. else if (e.CommandName == "UserAssignement.Require") { SqlProcs.spCONFIG_Update("system", "require_user_assignment", "true"); Application["CONFIG.require_user_assignment"] = true; } else if (e.CommandName == "UserAssignement.Optional") { SqlProcs.spCONFIG_Update("system", "require_user_assignment", "false"); Application["CONFIG.require_user_assignment"] = false; } else if (e.CommandName == "System.RebuildAudit") { // 12/31/2007 Paul. In case there is a problem, we need a way to rebuild the audit tables and triggers. SqlProcs.spSqlBuildAllAuditTables(); } else if (e.CommandName == "System.RecompileViews") { // 12/31/2007 Paul. Use a special version of spSqlRefreshAllViews that does not timeout. Utils.RefreshAllViews(); } else if (e.CommandName == "System.Reload") { // 01/18/2008 Paul. Speed the reload by doing directly instead of going to SystemCheck page. SplendidInit.InitApp(); SplendidInit.LoadUserPreferences(Security.USER_ID, Sql.ToString(Session["USER_SETTINGS/THEME"]), Sql.ToString(Session["USER_SETTINGS/CULTURE"])); } Response.Redirect("default.aspx"); } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); lblError.Text = ex.Message; } }
protected void Page_Command(Object sender, CommandEventArgs e) { if (e.CommandName == "Login") { if (Page.IsValid) { bool bValidUser = false; try { if (Security.IsWindowsAuthentication()) { SplendidInit.ChangeTheme(lstTHEME.SelectedValue, lstLANGUAGE.SelectedValue); bValidUser = true; } else { bValidUser = SplendidInit.LoginUser(txtUSER_NAME.Text, txtPASSWORD.Text, lstTHEME.SelectedValue, lstLANGUAGE.SelectedValue); } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); trError.Visible = true; lblError.Text = ex.Message; return; } // 09/12/2006 Paul. Move redirect outside try/catch to avoid catching "Thread was being aborted" exception. if (bValidUser) { string sDefaultModule = Sql.ToString(Application["CONFIG.default_module"]); // 10/06/2007 Paul. Prompt the user for the timezone. if (Sql.IsEmptyString(Session["USER_SETTINGS/TIMEZONE/ORIGINAL"])) { Response.Redirect("~/Users/SetTimezone.aspx"); } else if (sDefaultModule.StartsWith("~")) { Response.Redirect(sDefaultModule); } else if (!Sql.IsEmptyString(sDefaultModule)) { Response.Redirect("~/" + sDefaultModule + "/"); } else { Response.Redirect("~/Home/"); } return; } else { trError.Visible = true; lblError.Text = L10n.Term("Users.ERR_INVALID_PASSWORD"); } } } }
protected void ImportFromStream(Stream stm) { // http://msdn.microsoft.com/msdnmag/issues/03/06/ZipCompression/default.aspx // http://community.sharpdevelop.net/forums/738/ShowPost.aspx // The #ZipLib is licensed under a modified GPL. This modification grants you the right to use the compiled .DLL in closed source applications. // Modifcations to the library however fall under the provisions of the GPL. Hashtable hashLanguages = new Hashtable(); using (ZipInputStream stmZip = new ZipInputStream(stm)) { ZipEntry theEntry = null; while ((theEntry = stmZip.GetNextEntry()) != null) { string sFileName = Path.GetFileName(theEntry.Name); if (sFileName != String.Empty) { Response.Write(theEntry.Name + "<br>" + ControlChars.CrLf); if (theEntry.Name.EndsWith(".lang.php")) { string sLang = LanguagePackImport.GetLanguage(theEntry.Name); // 11/13/2006 Paul. SugarCRM still has not fixed their German language pack. Convert ge-GE to de-DE. if (String.Compare(sLang, "ge-GE", true) == 0) { sLang = "de-DE"; } // 08/22/2007 Paul. Only insert the language record once. if (!hashLanguages.ContainsKey(sLang)) { CultureInfo culture = new CultureInfo(sLang); if (culture == null) { throw(new Exception("Unknown language: " + sLang)); } SqlProcs.spLANGUAGES_InsertOnly(sLang, culture.LCID, true, culture.NativeName, culture.DisplayName); if (chkTruncate.Checked) { SqlProcs.spTERMINOLOGY_DeleteAll(sLang); hashLanguages.Add(sLang, String.Empty); } } LanguagePackImport.InsertTerms(theEntry.Name, stmZip, chkForceUTF8.Checked); } } } // 01/12/2006 Paul. Update internal cache. SplendidInit.InitTerminology(); // 01/13/2006 Paul. Clear the language cache. SplendidCache.ClearLanguages(); } }
protected void Page_Command(object sender, CommandEventArgs e) { if (e.CommandName == "Admin.Reload") { if (Security.IS_ADMIN) { SplendidInit.InitApp(); // 11/17/2007 Paul. New function to determine if user is authenticated. if (Security.IsAuthenticated()) { SplendidInit.LoadUserPreferences(Security.USER_ID, Sql.ToString(Session["USER_SETTINGS/THEME"]), Sql.ToString(Session["USER_SETTINGS/CULTURE"])); } // 06/30/2007 Paul. Perform a redirect so that the entire page will reload and rebind. Response.Redirect(Request.RawUrl); } } }
protected void Page_Command(object sender, CommandEventArgs e) { if (e.CommandName == "Save") { try { string sUSER_PREFERENCES = Sql.ToString(Session["USER_PREFERENCES"]); if (Sql.IsEmptyString(sUSER_PREFERENCES)) { sUSER_PREFERENCES = "<xml></xml>"; } XmlDocument xml = SplendidInit.InitUserPreferences(sUSER_PREFERENCES); XmlUtil.SetSingleNode(xml, "timezone", lstTIMEZONE.SelectedValue); Session["USER_SETTINGS/TIMEZONE"] = lstTIMEZONE.SelectedValue; Session["USER_SETTINGS/TIMEZONE/ORIGINAL"] = lstTIMEZONE.SelectedValue; SqlProcs.spUSERS_PreferencesUpdate(Security.USER_ID, xml.OuterXml); Session["USER_PREFERENCES"] = xml.OuterXml; } catch (Exception ex) { lblError.Text = ex.Message; return; } string sDefaultModule = Sql.ToString(Application["CONFIG.default_module"]); if (sDefaultModule.StartsWith("~")) { Response.Redirect(sDefaultModule); } else if (!Sql.IsEmptyString(sDefaultModule)) { Response.Redirect("~/" + sDefaultModule + "/"); } else { Response.Redirect("~/Home/"); } } }
private void Page_Load(object sender, System.EventArgs e) { Session.Clear(); SplendidInit.InitSession(); Response.Redirect("Login.aspx"); }
protected void lstLANGUAGE_Changed(Object sender, EventArgs e) { SplendidInit.ChangeTheme(lstTHEME.SelectedValue, lstLANGUAGE.SelectedValue); Response.Redirect(Request.RawUrl); }
protected void Page_Command(Object sender, CommandEventArgs e) { if (e.CommandName == "Next") { reqFILENAME.Enabled = true; reqFILENAME.Validate(); if (Page.IsValid) { Response.Write("<div id=\"divImportList\">" + ControlChars.CrLf); try { HttpPostedFile pstIMPORT = fileIMPORT.PostedFile; if (pstIMPORT != null) { if (pstIMPORT.FileName.Length > 0) { string sFILENAME = Path.GetFileName(pstIMPORT.FileName); string sFILE_EXT = Path.GetExtension(sFILENAME); string sFILE_MIME_TYPE = pstIMPORT.ContentType; //string sLocalFile = Path.Combine(Path.GetTempPath(), sFILENAME); //pstIMPORT.SaveAs(sLocalFile); //ProcessDirectory(sLocalFile + "\\SugarRus\\manifest.php"); if (sFILE_MIME_TYPE == "application/x-zip-compressed") { // http://msdn.microsoft.com/msdnmag/issues/03/06/ZipCompression/default.aspx // http://community.sharpdevelop.net/forums/738/ShowPost.aspx // The #ZipLib is licensed under a modified GPL. This modification grants you the right to use the compiled .DLL in closed source applications. // Modifcations to the library however fall under the provisions of the GPL. Hashtable hashLanguages = new Hashtable(); using (ZipInputStream stmZip = new ZipInputStream(pstIMPORT.InputStream)) { ZipEntry theEntry = null; while ((theEntry = stmZip.GetNextEntry()) != null) { string sFileName = Path.GetFileName(theEntry.Name); if (sFileName != String.Empty) { Response.Write(theEntry.Name + "<br>" + ControlChars.CrLf); if (theEntry.Name.EndsWith(".lang.php")) { string sLang = LanguagePackImport.GetLanguage(theEntry.Name); CultureInfo culture = new CultureInfo(sLang); if (culture == null) { throw(new Exception("Unknown language: " + sLang)); } SqlProcs.spLANGUAGES_InsertOnly(sLang, culture.LCID, true, culture.NativeName, culture.DisplayName); if (chkTruncate.Checked) { if (!hashLanguages.ContainsKey(sLang)) { SqlProcs.spTERMINOLOGY_DeleteAll(sLang); hashLanguages.Add(sLang, String.Empty); } } LanguagePackImport.InsertTerms(theEntry.Name, stmZip, chkForceUTF8.Checked); } } } // 01/12/2006 Paul. Update internal cache. SplendidInit.InitTerminology(); // 01/13/2006 Paul. Clear the language cache. SplendidCache.ClearLanguages(); } } else { throw(new Exception("ZIP is the only supported format at this time.")); } } } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message); lblError.Text = ex.Message; } finally { Response.Write("</div>" + ControlChars.CrLf); Page.RegisterClientScriptBlock("HideImportList", "<script type=\"text/javascript\">document.getElementById('divImportList').style.display='none';</script>"); } } } else if (e.CommandName == "Back") { } }
private void Page_Load(object sender, System.EventArgs e) { SetPageTitle(L10n.Term(".moduleList." + m_sMODULE)); // 06/04/2006 Paul. Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load. // 07/11/2006 Paul. Users must be able to view and edit their own settings. this.Visible = bMyAccount || SplendidCRM.Security.IS_ADMIN; //(SplendidCRM.Security.GetUserAccess(m_sMODULE, "view") >= 0); if (!this.Visible) { return; } try { gID = Sql.ToGuid(Request["ID"]); if (bMyAccount) { // 11/19/2005 Paul. SugarCRM 3.5.0 allows administrator to duplicate itself. btnDuplicate.Visible = Security.IS_ADMIN; gID = Security.USER_ID; } ctlAccessView.USER_ID = gID; // 12/06/2005 Paul. The password button is only visible if not windows authentication or Admin. // The reason to allow the admin to change a password is so that the admin can prepare to turn off windows authentication. btnChangePassword.Visible = !Security.IsWindowsAuthentication() || Security.IS_ADMIN; btnReset.Visible = Security.IS_ADMIN; if (!Sql.IsEmptyString(txtNEW_PASSWORD.Value)) { bool bValidOldPassword = false; if (!Security.IS_ADMIN) { DbProviderFactory dbf = DbProviderFactories.GetFactory(); using (IDbConnection con = dbf.CreateConnection()) { string sSQL; // 07/17/2006 Paul. The USER_HASH has been removed from the main vwUSERS view to prevent its use in reports. sSQL = "select * " + ControlChars.CrLf + " from vwUSERS_Login " + ControlChars.CrLf + " where ID = @ID " + ControlChars.CrLf + " and USER_HASH = @USER_HASH" + ControlChars.CrLf; using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = sSQL; Sql.AddParameter(cmd, "@ID", gID); Sql.AddParameter(cmd, "@USER_HASH", Security.HashPassword(txtOLD_PASSWORD.Value)); con.Open(); using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if (rdr.Read()) { bValidOldPassword = true; } } } } if (!bValidOldPassword) { lblError.Text = L10n.Term("Users.ERR_PASSWORD_INCORRECT_OLD"); } } if (bValidOldPassword || Security.IS_ADMIN) { if (txtNEW_PASSWORD.Value == txtCONFIRM_PASSWORD.Value) { SqlProcs.spUSERS_PasswordUpdate(gID, Security.HashPassword(txtNEW_PASSWORD.Value)); if (bMyAccount) { Response.Redirect("MyAccount.aspx"); } else { Response.Redirect("view.aspx?ID=" + gID.ToString()); } } else { lblError.Text = L10n.Term("Users.ERR_REENTER_PASSWORDS"); } } } if (!IsPostBack) { // 05/09/2006 Paul. We need to always initialize the separators, just in case the user is new. txtGROUP_SEPARATOR.Text = SplendidDefaults.GroupSeparator(); txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator(); if (!Sql.IsEmptyGuid(gID)) { DbProviderFactory dbf = DbProviderFactories.GetFactory(); using (IDbConnection con = dbf.CreateConnection()) { string sSQL; sSQL = "select * " + ControlChars.CrLf + " from vwUSERS_Edit" + ControlChars.CrLf + " where ID = @ID " + ControlChars.CrLf; using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = sSQL; Sql.AddParameter(cmd, "@ID", gID); con.Open(); if (bDebug) { RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd)); } using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if (rdr.Read()) { ctlModuleHeader.Title = Sql.ToString(rdr["FULL_NAME"]) + " (" + Sql.ToString(rdr["USER_NAME"]) + ")"; SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title); Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title); // main txtNAME.Text = Sql.ToString(rdr["FULL_NAME"]); txtUSER_NAME.Text = Sql.ToString(rdr["USER_NAME"]); txtSTATUS.Text = Sql.ToString(L10n.Term(".user_status_dom.", rdr["STATUS"])); // user_settings chkIS_ADMIN.Checked = Sql.ToBoolean(rdr["IS_ADMIN"]); chkPORTAL_ONLY.Checked = Sql.ToBoolean(rdr["PORTAL_ONLY"]); chkRECEIVE_NOTIFICATIONS.Checked = Sql.ToBoolean(rdr["RECEIVE_NOTIFICATIONS"]); this.AppendDetailViewFields(m_sMODULE + ".DetailView", tblMain, rdr); // 08/05/2006 Paul. MailOptions are populated manually. this.AppendDetailViewFields(m_sMODULE + ".MailOptions", tblMailOptions, null); // 01/20/2008 Paul. The mail options panel is manually populated. new DynamicControl(this, "EMAIL1").Text = Sql.ToString(rdr["EMAIL1"]); new DynamicControl(this, "EMAIL2").Text = Sql.ToString(rdr["EMAIL2"]); string sUSER_PREFERENCES = Sql.ToString(rdr["USER_PREFERENCES"]); if (!Sql.IsEmptyString(sUSER_PREFERENCES)) { XmlDocument xml = SplendidInit.InitUserPreferences(sUSER_PREFERENCES); try { // user_settings txtLANGUAGE.Text = L10N.NormalizeCulture(XmlUtil.SelectSingleNode(xml, "culture")); try { DataView vwLanguages = new DataView(SplendidCache.Languages()); vwLanguages.RowFilter = "NAME = '" + txtLANGUAGE.Text + "'"; if (vwLanguages.Count > 0) { txtLANGUAGE.Text = Sql.ToString(vwLanguages[0]["NATIVE_NAME"]); } } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } txtDATEFORMAT.Text = XmlUtil.SelectSingleNode(xml, "dateformat"); txtTIMEFORMAT.Text = XmlUtil.SelectSingleNode(xml, "timeformat"); // 08/05/2006 Paul. Remove stub of unsupported code. Show Gridline is not supported at this time. //chkGRIDLINE .Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "gridline" )); // mail_options new DynamicControl(this, "MAIL_FROMNAME").Text = XmlUtil.SelectSingleNode(xml, "mail_fromname"); new DynamicControl(this, "MAIL_FROMADDRESS").Text = XmlUtil.SelectSingleNode(xml, "mail_fromaddress"); new DynamicControl(this, "MAIL_SENDTYPE").Text = XmlUtil.SelectSingleNode(xml, "mail_sendtype"); new DynamicControl(this, "MAIL_SMTPSERVER").Text = XmlUtil.SelectSingleNode(xml, "mail_smtpserver"); new DynamicControl(this, "MAIL_SMTPPORT").Text = XmlUtil.SelectSingleNode(xml, "mail_smtpport"); new DynamicControl(this, "MAIL_SMTPAUTH_REQ").Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "mail_smtpauth_req")); new DynamicControl(this, "MAIL_SMTPUSER").Text = XmlUtil.SelectSingleNode(xml, "mail_smtpuser"); // freebusy // 08/05/2006 Paul. Remove stub of unsupported code. Calendar Publish Key is not supported at this time. //txtCALENDAR_PUBLISH_KEY .Text = XmlUtil.SelectSingleNode(xml, "calendar_publish_key" ); //txtCALENDAR_PUBLISH_URL .Text = XmlUtil.SelectSingleNode(xml, "calendar_publish_url" ); //txtCALENDAR_SEARCH_URL .Text = XmlUtil.SelectSingleNode(xml, "calendar_search_url" ); // 05/09/2006 Paul. Initialize the numeric separators. txtGROUP_SEPARATOR.Text = XmlUtil.SelectSingleNode(xml, "num_grp_sep"); txtDECIMAL_SEPARATOR.Text = XmlUtil.SelectSingleNode(xml, "dec_sep"); // 05/09/2006 Paul. Check for empty strings as the user may have legacy data. if (Sql.IsEmptyString(txtGROUP_SEPARATOR.Text)) { txtGROUP_SEPARATOR.Text = SplendidDefaults.GroupSeparator(); } if (Sql.IsEmptyString(txtDECIMAL_SEPARATOR.Text)) { txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator(); } string sTIMEZONE = XmlUtil.SelectSingleNode(xml, "timezone"); DataView vwTimezones = new DataView(SplendidCache.Timezones()); vwTimezones.RowFilter = "ID = '" + sTIMEZONE + "'"; if (vwTimezones.Count > 0) { txtTIMEZONE.Text = Sql.ToString(vwTimezones[0]["NAME"]); } string sCURRENCY = XmlUtil.SelectSingleNode(xml, "currency_id"); DataView vwCurrencies = new DataView(SplendidCache.Currencies()); vwCurrencies.RowFilter = "ID = '" + sCURRENCY + "'"; if (vwCurrencies.Count > 0) { txtCURRENCY.Text = Sql.ToString(vwCurrencies[0]["NAME_SYMBOL"]); } // 08/05/2006 Paul. Remove stub of unsupported code. Reminder is not supported at this time. /* * try * { * int nREMINDER_TIME = Sql.ToInteger(XmlUtil.SelectSingleNode(xml, "reminder_time")); * if ( nREMINDER_TIME > 0 ) * { * txtREMINDER_TIME.Text = L10n.Term(".reminder_time_options." + nREMINDER_TIME.ToString()); * chkREMINDER.Checked = true; * } * } * catch(Exception ex) * { * SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); * } */ } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); } } //txtDESCRIPTION.Text = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String("YToxODp7czo4OiJncmlkbGluZSI7czozOiJvZmYiO3M6ODoibWF4X3RhYnMiO3M6MjoiMTIiO3M6MTI6ImRpc3BsYXlfdGFicyI7YToxNTp7aTowO3M6NDoiSG9tZSI7aToxO3M6NzoiaUZyYW1lcyI7aToyO3M6ODoiQ2FsZW5kYXIiO2k6MztzOjEwOiJBY3Rpdml0aWVzIjtpOjQ7czo4OiJBY2NvdW50cyI7aTo1O3M6NToiTGVhZHMiO2k6NjtzOjEzOiJPcHBvcnR1bml0aWVzIjtpOjc7czo1OiJDYXNlcyI7aTo4O3M6NDoiQnVncyI7aTo5O3M6OToiRG9jdW1lbnRzIjtpOjEwO3M6NjoiRW1haWxzIjtpOjExO3M6OToiQ2FtcGFpZ25zIjtpOjEyO3M6NzoiUHJvamVjdCI7aToxMztzOjU6IkZlZWRzIjtpOjE0O3M6OToiRGFzaGJvYXJkIjt9czoxMzoicmVtaW5kZXJfdGltZSI7czozOiI5MDAiO3M6NToidGltZWYiO3M6MzoiSDppIjtzOjg6ImN1cnJlbmN5IjtzOjM6Ii05OSI7czo1OiJkYXRlZiI7czo1OiJZLW0tZCI7czo1OiJ0aW1leiI7czoxOiIwIjtzOjEzOiJtYWlsX2Zyb21uYW1lIjtzOjQ6IlBhdWwiO3M6MTY6Im1haWxfZnJvbWFkZHJlc3MiO3M6MTM6InBhdWxAcm9ueS5jb20iO3M6MTM6Im1haWxfc2VuZHR5cGUiO3M6NDoiU01UUCI7czoxNToibWFpbF9zbXRwc2VydmVyIjtzOjM6Im5zMSI7czoxMzoibWFpbF9zbXRwcG9ydCI7czoyOiIyMyI7czoxMzoibWFpbF9zbXRwdXNlciI7czo4OiJwYXVscm9ueSI7czoxMzoibWFpbF9zbXRwcGFzcyI7czo3OiJwb2NrZXQxIjtzOjE3OiJtYWlsX3NtdHBhdXRoX3JlcSI7czowOiIiO3M6MTY6Im1haWxfcG9wYXV0aF9yZXEiO3M6MDoiIjtzOjIwOiJjYWxlbmRhcl9wdWJsaXNoX2tleSI7czoxMToicHVibGlzaCBoZXkiO30=")); } } } } } } // 06/09/2006 Paul. Remove data binding in the user controls. Binding is required, but only do so in the ASPX pages. //Page.DataBind(); } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); lblError.Text = ex.Message; } }
protected void Page_Command(Object sender, CommandEventArgs e) { Guid gPARENT_ID = Sql.ToGuid(Request["PARENT_ID"]); string sMODULE = String.Empty; string sPARENT_TYPE = String.Empty; string sPARENT_NAME = String.Empty; try { SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME); } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); // The only possible error is a connection failure, so just ignore all errors. gPARENT_ID = Guid.Empty; } if (e.CommandName == "Save") { // 01/16/2006 Paul. Enable validator before validating page. this.ValidateEditViewFields(m_sMODULE + ".EditView"); this.ValidateEditViewFields(m_sMODULE + ".EditAddress"); if (Page.IsValid) { string sUSER_PREFERENCES = String.Empty; XmlDocument xml = new XmlDocument(); try { try { sUSER_PREFERENCES = Sql.ToString(ViewState["USER_PREFERENCES"]); xml.LoadXml(sUSER_PREFERENCES); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); xml.AppendChild(xml.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"")); xml.AppendChild(xml.CreateElement("USER_PREFERENCE")); } // user_settings XmlUtil.SetSingleNode(xml, "gridline", chkGRIDLINE.Checked ? "true" : "false"); XmlUtil.SetSingleNode(xml, "culture", lstLANGUAGE.SelectedValue); XmlUtil.SetSingleNode(xml, "theme", lstTHEME.SelectedValue); XmlUtil.SetSingleNode(xml, "dateformat", lstDATE_FORMAT.SelectedValue); XmlUtil.SetSingleNode(xml, "timeformat", lstTIME_FORMAT.SelectedValue); XmlUtil.SetSingleNode(xml, "timezone", lstTIMEZONE.SelectedValue); XmlUtil.SetSingleNode(xml, "currency_id", lstCURRENCY.SelectedValue); XmlUtil.SetSingleNode(xml, "num_grp_sep", txtGROUP_SEPARATOR.Text); XmlUtil.SetSingleNode(xml, "dec_sep", txtDECIMAL_SEPARATOR.Text); // 08/05/2006 Paul. Remove stub of unsupported code. Reminder is not supported at this time. //XmlUtil.SetSingleNode(xml, "reminder_time" , chkSHOULD_REMIND.Checked ? lstREMINDER_TIME.SelectedValue : "0" ); // mail_options string sMAIL_SMTPPASS = Sql.ToString(ViewState["mail_smtppass"]); // 08/06/2005 Paul. Password might be our empty value. TextBox txtMAIL_SMTPPASS = FindControl("MAIL_SMTPPASS") as TextBox; if (txtMAIL_SMTPPASS != null) { // 08/05/2006 Paul. Allow the password to be cleared. if (txtMAIL_SMTPPASS.Text != sEMPTY_PASSWORD) { sMAIL_SMTPPASS = txtMAIL_SMTPPASS.Text; } } XmlUtil.SetSingleNode(xml, "mail_fromname", new DynamicControl(this, "MAIL_FROMNAME").Text); XmlUtil.SetSingleNode(xml, "mail_fromaddress", new DynamicControl(this, "MAIL_FROMADDRESS").Text); XmlUtil.SetSingleNode(xml, "mail_smtpserver", new DynamicControl(this, "MAIL_SMTPSERVER").Text); XmlUtil.SetSingleNode(xml, "mail_smtpport", new DynamicControl(this, "MAIL_SMTPPORT").Text); XmlUtil.SetSingleNode(xml, "mail_sendtype", new DynamicControl(this, "MAIL_SENDTYPE").Text); XmlUtil.SetSingleNode(xml, "mail_smtpauth_req", new DynamicControl(this, "MAIL_SMTPAUTH_REQ").Checked ? "true" : "false"); XmlUtil.SetSingleNode(xml, "mail_smtpuser", new DynamicControl(this, "MAIL_SMTPUSER").Text); XmlUtil.SetSingleNode(xml, "mail_smtppass", sMAIL_SMTPPASS); // freebusy // 08/05/2006 Paul. Remove stub of unsupported code. Calendar Publish Key is not supported at this time. //XmlUtil.SetSingleNode(xml, "calendar_publish_key", txtCALENDAR_PUBLISH_KEY .Text ); //XmlUtil.SetSingleNode(xml, "calendar_publish_url", txtCALENDAR_PUBLISH_URL .Text ); //XmlUtil.SetSingleNode(xml, "calendar_search_url" , txtCALENDAR_SEARCH_URL .Text ); } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); } if (Sql.ToBoolean(Application["CONFIG.XML_UserPreferences"])) { sUSER_PREFERENCES = xml.OuterXml; } else { sUSER_PREFERENCES = XmlUtil.ConvertToPHP(xml.DocumentElement); } // 12/06/2005 Paul. Need to prevent duplicate users. string sUSER_NAME = txtUSER_NAME.Text.Trim(); DbProviderFactory dbf = DbProviderFactories.GetFactory(); try { // 11/10/2006 Paul. If the decimal and group separate match, then .NET will not be able to parse decimals. // The exception "Input string was not in a correct format." is thrown. if (txtGROUP_SEPARATOR.Text == txtDECIMAL_SEPARATOR.Text) { throw(new Exception(L10n.Term("Users.LBL_INVALID_DECIMAL"))); } if (!Sql.IsEmptyString(sUSER_NAME)) { using (IDbConnection con = dbf.CreateConnection()) { string sSQL; sSQL = "select USER_NAME " + ControlChars.CrLf + " from vwUSERS " + ControlChars.CrLf + " where USER_NAME = @USER_NAME" + ControlChars.CrLf; using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = sSQL; Sql.AddParameter(cmd, "@USER_NAME", sUSER_NAME); if (!Sql.IsEmptyGuid(gID)) { // 12/06/2005 Paul. Only include the ID if it is not null as we cannot compare NULL to anything. cmd.CommandText += " and ID <> @ID" + ControlChars.CrLf; Sql.AddParameter(cmd, "@ID", gID); } con.Open(); using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if (rdr.Read()) { string sMESSAGE = String.Empty; sMESSAGE = String.Format(L10n.Term("Users.ERR_USER_NAME_EXISTS_1") + "{0}" + L10n.Term("Users.ERR_USER_NAME_EXISTS_2"), sUSER_NAME); throw(new Exception(sMESSAGE)); } } } } } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); ctlEditButtons.ErrorText = ex.Message; return; } string sCUSTOM_MODULE = "USERS"; DataTable dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE); using (IDbConnection con = dbf.CreateConnection()) { con.Open(); // 11/18/2007 Paul. Use the current values for any that are not defined in the edit view. DataRow rowCurrent = null; DataTable dtCurrent = new DataTable(); if (!Sql.IsEmptyGuid(gID)) { string sSQL; sSQL = "select * " + ControlChars.CrLf + " from vwUSERS_Edit" + ControlChars.CrLf; using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = sSQL; Security.Filter(cmd, m_sMODULE, "edit"); Sql.AppendParameter(cmd, gID, "ID", false); using (DbDataAdapter da = dbf.CreateDataAdapter()) { ((IDbDataAdapter)da).SelectCommand = cmd; da.Fill(dtCurrent); if (dtCurrent.Rows.Count > 0) { rowCurrent = dtCurrent.Rows[0]; } else { // 11/19/2007 Paul. If the record is not found, clear the ID so that the record cannot be updated. // It is possible that the record exists, but that ACL rules prevent it from being selected. gID = Guid.Empty; } } } } using (IDbTransaction trn = con.BeginTransaction()) { try { bool bNewUser = Sql.IsEmptyGuid(gID); // 04/24/2006 Paul. Upgrade to SugarCRM 4.2 Schema. // 11/18/2007 Paul. Use the current values for any that are not defined in the edit view. SqlProcs.spUSERS_Update (ref gID , sUSER_NAME , txtFIRST_NAME.Text , txtLAST_NAME.Text , new DynamicControl(this, rowCurrent, "REPORTS_TO_ID").ID , (Security.IS_ADMIN ? chkIS_ADMIN.Checked : Sql.ToBoolean(ViewState["IS_ADMIN"])) , chkRECEIVE_NOTIFICATIONS.Checked , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text , new DynamicControl(this, rowCurrent, "TITLE").Text , new DynamicControl(this, rowCurrent, "DEPARTMENT").Text , new DynamicControl(this, rowCurrent, "PHONE_HOME").Text , new DynamicControl(this, rowCurrent, "PHONE_MOBILE").Text , new DynamicControl(this, rowCurrent, "PHONE_WORK").Text , new DynamicControl(this, rowCurrent, "PHONE_OTHER").Text , new DynamicControl(this, rowCurrent, "PHONE_FAX").Text , new DynamicControl(this, rowCurrent, "EMAIL1").Text , new DynamicControl(this, rowCurrent, "EMAIL2").Text , lstSTATUS.SelectedValue , new DynamicControl(this, rowCurrent, "ADDRESS_STREET").Text , new DynamicControl(this, rowCurrent, "ADDRESS_CITY").Text , new DynamicControl(this, rowCurrent, "ADDRESS_STATE").Text , new DynamicControl(this, rowCurrent, "ADDRESS_POSTALCODE").Text , new DynamicControl(this, rowCurrent, "ADDRESS_COUNTRY").Text , sUSER_PREFERENCES , chkPORTAL_ONLY.Checked , new DynamicControl(this, rowCurrent, "EMPLOYEE_STATUS").SelectedValue , new DynamicControl(this, rowCurrent, "MESSENGER_ID").Text , new DynamicControl(this, rowCurrent, "MESSENGER_TYPE").SelectedValue , sMODULE , gPARENT_ID , new DynamicControl(this, rowCurrent, "IS_GROUP").Checked , trn ); SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields); trn.Commit(); // 09/09/2006 Paul. Refresh cached user information. if (bNewUser) { SplendidCache.ClearUsers(); } // 08/27/2005 Paul. Reload session with user preferences. // 08/30/2005 Paul. Only reload preferences the user is editing his own profile. // We want to allow an administrator to update other user profiles. if (Security.USER_ID == gID) { SplendidInit.LoadUserPreferences(gID, lstTHEME.SelectedValue, lstLANGUAGE.SelectedValue); } } catch (Exception ex) { trn.Rollback(); SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); ctlEditButtons.ErrorText = ex.Message; return; } } } if (!Sql.IsEmptyGuid(gPARENT_ID)) { Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString()); } else if (bMyAccount) { Response.Redirect("MyAccount.aspx"); } else { Response.Redirect("view.aspx?ID=" + gID.ToString()); } } } else if (e.CommandName == "Cancel") { if (!Sql.IsEmptyGuid(gPARENT_ID)) { Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString()); } else if (bMyAccount) { Response.Redirect("MyAccount.aspx"); } else if (Sql.IsEmptyGuid(gID)) { Response.Redirect("default.aspx"); } else { Response.Redirect("view.aspx?ID=" + gID.ToString()); } } }
private void Page_Load(object sender, System.EventArgs e) { SetPageTitle(L10n.Term(".moduleList." + m_sMODULE)); // 06/04/2006 Paul. Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load. // 07/11/2006 Paul. Users must be able to view and edit their own settings. this.Visible = bMyAccount || SplendidCRM.Security.IS_ADMIN; //(SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0); if (!this.Visible) { return; } reqUSER_NAME.DataBind(); reqLAST_NAME.DataBind(); try { // 06/09/2006 Paul. Remove data binding in the user controls. Binding is required, but only do so in the ASPX pages. //Page.DataBind(); gID = Sql.ToGuid(Request["ID"]); if (bMyAccount) { gID = Security.USER_ID; } // 07/12/2006 Paul. Status can only be edited by an administrator. lstSTATUS.Enabled = false; // 12/06/2005 Paul. A user can only edit his own user name if Windows Authentication is off. if (Security.IS_ADMIN) { // 12/06/2005 Paul. An administrator can always edit the user name. This is to allow him to pre-add any NTLM users. txtUSER_NAME.Enabled = true; lstSTATUS.Enabled = true; } else if (gID == Security.USER_ID) { // 12/06/2005 Paul. If editing yourself, then you can only edit if not NTLM. // txtUSER_NAME.Enabled = !Security.IsWindowsAuthentication(); // 11/26/2006 Paul. A user cannot edit their own user name. This is a job for the admin. txtUSER_NAME.Enabled = false; } else { // 12/06/2005 Paul. If not an administrator and not editing yourself, then the name cannot be edited. txtUSER_NAME.Enabled = false; } if (!IsPostBack) { // 'date_formats' => array('Y-m-d'=>'2006-12-23', 'm-d-Y'=>'12-23-2006', 'Y/m/d'=>'2006/12/23', 'm/d/Y'=>'12/23/2006') // 'time_formats' => array('H:i'=>'23:00', 'h:ia'=>'11:00pm', 'h:iA'=>'11:00PM', 'H.i'=>'23.00', 'h.ia'=>'11.00pm', 'h.iA'=>'11.00PM' ) lstSTATUS.DataSource = SplendidCache.List("user_status_dom"); lstSTATUS.DataBind(); // 08/05/2006 Paul. Remove stub of unsupported code. Reminder is not supported at this time. //lstREMINDER_TIME .DataSource = SplendidCache.List("reminder_time_dom"); //lstREMINDER_TIME .DataBind(); lstTIMEZONE.DataSource = SplendidCache.TimezonesListbox(); lstTIMEZONE.DataBind(); lstCURRENCY.DataSource = SplendidCache.Currencies(); lstCURRENCY.DataBind(); // 05/09/2006 Paul. We need to always initialize the separators, just in case the user is new. txtGROUP_SEPARATOR.Text = SplendidDefaults.GroupSeparator(); txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator(); lstLANGUAGE.DataSource = SplendidCache.Languages(); lstLANGUAGE.DataBind(); lstLANGUAGE_Changed(null, null); lstTHEME.DataSource = SplendidCache.Themes(); lstTHEME.DataBind(); Guid gDuplicateID = Sql.ToGuid(Request["DuplicateID"]); if (!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID)) { DbProviderFactory dbf = DbProviderFactories.GetFactory(); using (IDbConnection con = dbf.CreateConnection()) { string sSQL; sSQL = "select * " + ControlChars.CrLf + " from vwUSERS_Edit" + ControlChars.CrLf + " where ID = @ID " + ControlChars.CrLf; using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = sSQL; if (!Sql.IsEmptyGuid(gDuplicateID)) { Sql.AddParameter(cmd, "@ID", gDuplicateID); gID = Guid.Empty; } else { Sql.AddParameter(cmd, "@ID", gID); } con.Open(); if (bDebug) { RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd)); } using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if (rdr.Read()) { ctlModuleHeader.Title = Sql.ToString(rdr["FULL_NAME"]); SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title + " (" + Sql.ToString(rdr["USER_NAME"]) + ")"); Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title); ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title; this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, rdr); this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, rdr); // 08/05/2006 Paul. Use the dynamic grid to create the fields, but populate manually. this.AppendEditViewFields(m_sMODULE + ".EditMailOptions", tblMailOptions, null); // 01/20/2008 Paul. The mail options panel is manually populated. new DynamicControl(this, "EMAIL1").Text = Sql.ToString(rdr["EMAIL1"]); new DynamicControl(this, "EMAIL2").Text = Sql.ToString(rdr["EMAIL2"]); // main txtUSER_NAME.Text = Sql.ToString(rdr["USER_NAME"]); txtFIRST_NAME.Text = Sql.ToString(rdr["FIRST_NAME"]); txtLAST_NAME.Text = Sql.ToString(rdr["LAST_NAME"]); // user_settings chkIS_ADMIN.Checked = Sql.ToBoolean(rdr["IS_ADMIN"]); chkPORTAL_ONLY.Checked = Sql.ToBoolean(rdr["PORTAL_ONLY"]); chkRECEIVE_NOTIFICATIONS.Checked = Sql.ToBoolean(rdr["RECEIVE_NOTIFICATIONS"]); // 12/04/2005 Paul. Only allow the admin flag to be changed if the current user is an admin. chkIS_ADMIN.Enabled = Security.IS_ADMIN; // 12/04/2005 Paul. Save admin flag in ViewState to prevent hacking. ViewState["IS_ADMIN"] = Sql.ToBoolean(rdr["IS_ADMIN"]); try { lstSTATUS.SelectedValue = Sql.ToString(rdr["STATUS"]); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } string sUSER_PREFERENCES = Sql.ToString(rdr["USER_PREFERENCES"]); if (!Sql.IsEmptyString(sUSER_PREFERENCES)) { XmlDocument xml = SplendidInit.InitUserPreferences(sUSER_PREFERENCES); try { ViewState["USER_PREFERENCES"] = xml.OuterXml; // user_settings chkGRIDLINE.Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "gridline")); try { lstLANGUAGE.SelectedValue = L10N.NormalizeCulture(XmlUtil.SelectSingleNode(xml, "culture")); lstLANGUAGE_Changed(null, null); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } try { lstLANGUAGE.SelectedValue = XmlUtil.SelectSingleNode(xml, "theme"); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } try { lstDATE_FORMAT.SelectedValue = XmlUtil.SelectSingleNode(xml, "dateformat"); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } try { lstTIME_FORMAT.SelectedValue = XmlUtil.SelectSingleNode(xml, "timeformat"); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } try { lstTIMEZONE.SelectedValue = XmlUtil.SelectSingleNode(xml, "timezone"); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } try { lstCURRENCY.SelectedValue = XmlUtil.SelectSingleNode(xml, "currency_id"); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } // mail_options new DynamicControl(this, "MAIL_FROMNAME").Text = XmlUtil.SelectSingleNode(xml, "mail_fromname"); new DynamicControl(this, "MAIL_FROMADDRESS").Text = XmlUtil.SelectSingleNode(xml, "mail_fromaddress"); new DynamicControl(this, "MAIL_SENDTYPE").Text = XmlUtil.SelectSingleNode(xml, "mail_sendtype"); new DynamicControl(this, "MAIL_SMTPSERVER").Text = XmlUtil.SelectSingleNode(xml, "mail_smtpserver"); new DynamicControl(this, "MAIL_SMTPPORT").Text = XmlUtil.SelectSingleNode(xml, "mail_smtpport"); new DynamicControl(this, "MAIL_SMTPAUTH_REQ").Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "mail_smtpauth_req")); new DynamicControl(this, "MAIL_SMTPUSER").Text = XmlUtil.SelectSingleNode(xml, "mail_smtpuser"); new DynamicControl(this, "MAIL_SMTPPASS").Text = XmlUtil.SelectSingleNode(xml, "mail_smtppass"); ViewState["mail_smtppass"] = XmlUtil.SelectSingleNode(xml, "mail_smtppass"); // 08/06/2005 Paul. Never return password to user. TextBox txtMAIL_SMTPPASS = FindControl("MAIL_SMTPPASS") as TextBox; if (txtMAIL_SMTPPASS != null) { if (!Sql.IsEmptyString(txtMAIL_SMTPPASS.Text)) { txtMAIL_SMTPPASS.Text = sEMPTY_PASSWORD; } } // 05/09/2006 Paul. Initialize the numeric separators. txtGROUP_SEPARATOR.Text = XmlUtil.SelectSingleNode(xml, "num_grp_sep"); txtDECIMAL_SEPARATOR.Text = XmlUtil.SelectSingleNode(xml, "dec_sep"); // 05/09/2006 Paul. Check for empty strings as the user may have legacy data. if (Sql.IsEmptyString(txtGROUP_SEPARATOR.Text)) { txtGROUP_SEPARATOR.Text = SplendidDefaults.GroupSeparator(); } if (Sql.IsEmptyString(txtDECIMAL_SEPARATOR.Text)) { txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator(); } // freebusy // 08/05/2006 Paul. Remove stub of unsupported code. Calendar Publish Key is not supported at this time. //txtCALENDAR_PUBLISH_KEY .Text = XmlUtil.SelectSingleNode(xml, "calendar_publish_key" ); //txtCALENDAR_PUBLISH_URL .Text = XmlUtil.SelectSingleNode(xml, "calendar_publish_url" ); //txtCALENDAR_SEARCH_URL .Text = XmlUtil.SelectSingleNode(xml, "calendar_search_url" ); // 08/05/2006 Paul. Remove stub of unsupported code. Reminder is not supported at this time. /* * try * { * int nREMINDER_TIME = Sql.ToInteger(XmlUtil.SelectSingleNode(xml, "reminder_time")); * if ( nREMINDER_TIME > 0 ) * { * lstREMINDER_TIME.SelectedValue = nREMINDER_TIME.ToString(); * chkSHOULD_REMIND.Checked = true; * } * } * catch(Exception ex) * { * SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); * } */ } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); } } } } } } } else { this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, null); this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, null); this.AppendEditViewFields(m_sMODULE + ".EditMailOptions", tblMailOptions, null); try { lstTHEME.SelectedValue = SplendidDefaults.Theme(); } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } try { string sDefaultLanguage = Sql.ToString(Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"]); if (Sql.IsEmptyString(sDefaultLanguage)) { sDefaultLanguage = "en-US"; } lstLANGUAGE.SelectedValue = sDefaultLanguage; } catch (Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } lstLANGUAGE_Changed(null, null); } } else { // 12/02/2005 Paul. When validation fails, the header title does not retain its value. Update manually. ctlModuleHeader.Title = Sql.ToString(ViewState["ctlModuleHeader.Title"]); SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title); } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); ctlEditButtons.ErrorText = ex.Message; } }