protected void btnRequest_Click(object senderObject, EventArgs e)
    {
        RaiseOnCheckPermissions(PERMISSION_MANAGE, this);

        string message = string.Empty;

        // Requested user id not set explicitly
        if (RequestedUserID == 0)
        {
            RequestedUserID = ValidationHelper.GetInteger(selectUser.Value, 0);
        }

        // Both users have to be specified
        if ((RequestedUserID == 0) || (UserID == 0))
        {
            message = GetString("friends.friendrequired");
        }
        else
        {
            UserInfo requestedUser = UserInfoProvider.GetUserInfo(RequestedUserID);
            message = requestedUser == null?GetString("user.error_doesnoteexist") : VerifyRequestedUser(requestedUser);

            if (String.IsNullOrEmpty(message))
            {
                if (!FriendInfoProvider.FriendshipExists(UserID, RequestedUserID))
                {
                    // Set up control
                    Comment         = txtComment.Text;
                    SendMail        = chkSendEmail.Checked;
                    SendMessage     = chkSendMessage.Checked;
                    SelectedFriends = new ArrayList();
                    SelectedFriends.Add(RequestedUserID);
                    AutomaticApprovment = chkAutomaticApprove.Checked;

                    message = PerformAction(FriendsActionEnum.Request);
                }
                else
                {
                    message = GetString("friends.friendshipexists");
                }
            }
        }

        if (!String.IsNullOrEmpty(message))
        {
            ShowError(message);
        }
        else
        {
            // Register wopener script
            ScriptHelper.RegisterWOpenerScript(Page);

            btnRequest.Enabled          = false;
            selectUser.Enabled          = false;
            txtComment.Enabled          = false;
            chkAutomaticApprove.Enabled = false;
            chkSendEmail.Enabled        = false;
            chkSendMessage.Enabled      = false;
            ShowConfirmation(GetString("friends.friendshiprequested"));

            const string refreshScript = "if (window.top && window.top.refreshFriendsList) { window.top.refreshFriendsList(); } else if (window.opener && window.opener.refreshFriendsList) { window.opener.refreshFriendsList(); }";
            ScriptHelper.RegisterStartupScript(Page, typeof(string), "closeFriendsDialogFriendsList", refreshScript, true);

            ScriptHelper.RegisterStartupScript(Page, typeof(string), "closeFriendsDialog", "CloseDialog(true);", true);
        }
    }
Ejemplo n.º 2
0
    protected void btnRequest_Click(object senderObject, EventArgs e)
    {
        RaiseOnCheckPermissions(PERMISSION_MANAGE, this);

        string message = string.Empty;

        // Requested user id not set explicitly
        if (RequestedUserID == 0)
        {
            RequestedUserID = ValidationHelper.GetInteger(selectUser.Value, 0);
        }

        // Both users have to be specified
        if ((RequestedUserID == 0) || (UserID == 0))
        {
            message = GetString("friends.friendrequired");
        }
        else
        {
            bool friendshipExists = FriendInfoProvider.FriendshipExists(UserID, RequestedUserID);

            if (!friendshipExists)
            {
                // Set up control
                Comment         = txtComment.Text;
                SendMail        = chkSendEmail.Checked;
                SendMessage     = chkSendMessage.Checked;
                SelectedFriends = new ArrayList();
                SelectedFriends.Add(RequestedUserID);
                AutomaticApprovment = chkAutomaticApprove.Checked;

                message = PerformAction(FriendsActionEnum.Request);
            }
            else
            {
                message = GetString("friends.friendshipexists");
            }
        }

        bool error = (message != string.Empty);

        lblError.Visible = error;
        lblInfo.Visible  = !error;

        if (error)
        {
            lblError.Text = message;
        }
        else
        {
            // Register wopener script
            ScriptHelper.RegisterWOpenerScript(Page);

            btnRequest.Enabled          = false;
            selectUser.Enabled          = false;
            txtComment.Enabled          = false;
            chkAutomaticApprove.Enabled = false;
            chkSendEmail.Enabled        = false;
            chkSendMessage.Enabled      = false;
            btnCancel.ResourceString    = "general.close";
            lblInfo.ResourceString      = "friends.friendshiprequested";
            btnCancel.OnClientClick     = "if((wopener != null) && (wopener.refreshList != null)){wopener.refreshList();}window.close();return false;";
        }
    }