Using XMod with Active Forums to select Avatars

By Kirk Dickens, http://www.GymnasticsMedia.com
November 2006

Within our GymnasticsMedia.com portal, we have enabled the users to customize their forum profile by selecting an avatar image from a selection of images stored in the portal files.

We found a solution to this by combining the ActiveForums module with the XMod Module. We created the ability to select an avatar with XMod, and a AJAX call to an aspx page that updated the Active Forums tables.

This tutorial outlines how we combined the two modules to work together.

If you have any questions regarding this, then please ask any questions at this forum post

avatar selection

The XMod Form

Our form has two fields, Name & Avatar. The Name field allows us to sort the avatars in the template list view (green). The Avatar field allows us to upload the avatar file to the directory SystemAvatar, and store the file name in Avatar field (orange). The UserName field is hidden and allows us to store which user added the avatar (red). The last portion of the form emails us when a user submits a new avatar (blue).

<form>
<register tagprefix="abmc" namespace="knowbetter.xmodcontrols" assembly="knowbetter.xmodcontrols" />
<controls>
<input ref="Name">
<label>Name</label>
<validate type="required" errormessage="Name required" />
</input>
<custom tagprefix="abmc" name="FileUpload" ref="Avatar" cssclass="NormalTextBox" cssclasslink="Normal" extensions="jpg,gif" uploaddirectory="SystemAvatar" noneselected="true" uploadsuccessmsg="Avatar Uploaded" required="true">
<label>Avatar</label>
</custom>
<hidden ref="UserName">{XMOD_UserUsername}</hidden>
<email target="gymnasticsmedia@somedomain.com" from="Admin@somedomain.com" subject="New Avatar Uploaded">
<content format="html">
<literal>
New Avatar Uploaded!
</literal>
</content>
</email>
</controls>
</form>

XMod Template

The XMod template is a list view showing all the avatar images available, while allowing the user to highlight, and click to select the avatar to be used in Active Forum.

Highlighting the Image to be Selected

We implement events onMouseOver & onMouseLeave of the table encapsulating the avatar image. This code is highlighted in orange.

Selecting the Avatar

We implement the onClick event of the table encapsulating the avatar image.
This calls the the selectavatar.aspx passing in the variables portal id, user id, and avatar name via XMod constants {XMOD_PortalId}, {XMOD_UserId}, and our XMod form field Avatar. This code is highlighted in green.

<xmod:scriptblock scriptid="AjaxCallback" registeronce="true" blocktype="ClientScript">
<script language="javascript" type="text/javascript">
function showResults(status,statusText,responseText,responseXML){
alert('Avatar Saved!');
}
</script>
</xmod:scriptblock>
<xmod:ajax id="ajax<xmod:recordid/>" action="CallFunction" target="showResults"/>
<table onclick="ajax<xmod:recordid/>.call('/selectavatar.aspx?pid={XMOD_PortalId}&uid={XMOD_UserId}&avatar=<xmod:field name="Avatar"/>')" onMouseOver="javascript:this.bgColor='#fc7d14';" onMouseLeave="javascript:this.bgColor='#FFFFFF';"><tr><td style="height:130" align="center"><img src="/Portals/{XMOD_PortalId}/SystemAvatar/<xmod:field name="Avatar"/>" name="theImage" alt="<xmod:field name="Name"/> photo"/></td></tr>
<tr><td align="center">
<font size="-1"><xmod:field name="Name" /></font>
</td></tr></table>

Selectavatar.aspx

The selectavatar.aspx is stored at the root of the website (not the portal root), simply takes in portalid, userid, avatar url encoded parameters, and save the avatar to Active Forum User Details table.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objConn As New SqlClient.SqlConnection("Server=someserver;Database=somedatabase;uid=someuserid;pwd=somepassword;")
Dim objCommand As New SqlClient.SqlCommand
Dim sql As String
Dim PortalID As String
Dim UserID As String
Dim Avatar As String
Try
PortalID = Request.QueryString("pid")
UserID = Request.QueryString("uid")
Avatar = "/Portals/" & PortalID & "/SystemAvatar/" & Request.QueryString("avatar")
sql = "UPDATE NTForums_UserDetails SET AvatarLink=@Avatar, AvatarFileName='' WHERE PortalID=@PortalID AND UserID=@UserID"
objConn.Open()
objCommand.Connection = objConn
objCommand.CommandText = sql
objCommand.Parameters.Add("@Avatar", Avatar)
objCommand.Parameters.Add("@PortalID", PortalID)
objCommand.Parameters.Add("@UserID", UserID)
objCommand.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
objConn.Close()
objConn.Dispose()
objCommand.Dispose()
End Try
End Sub

Kirk Dickens is the founder of GymnasticsMedia.com

GymnasticsMedia.com has adopted DotNetNuke as its platform for delivering content, while giving users a rich, and comfortable user interface. Our goal is to be the ultimate portal for gymnastics fans.


Other areas of interest:

How to Quickly Edit Module Titles and Text
User Accounts new features in DotNetNuke 4.3+
User Accounts and User Settings
Enforcing Terms and Conditions on User Registration
How to Create a Custom Registration Page Using Manage Profile Properties
DotNetNuke User Profile Features v5.4
Security Roles new features
File Manager
Page Management – New Functions DotNetNuke v4.5+
DotNetNuke Authentication Settings (Configuring the Login Page)
DotNetNuke Ribbon Bar Admin Control Panel


Administrator Tutorials:
DotNetNuke Users & Setting the Registration Options
Working with DotNetNuke Security Roles
Specifying The Required Fields Upon User Registration
User Accounts: Adding, Editing, Viewing, Deleting
How to Assign a Security Role to a User Account
DotNetNuke 5 Page and Module Permissions
Assigning Security Roles to Pages and Modules
The Advanced Page Settings
Managing Pages
How to create Page Templates in DotNetNuke
How to create an RSS feed
How to display RSS feeds
How to set up DotNetNuke to accept subscription payments
How to set up email in DotNetNuke
How to send Newsletters in DotNetNuke
Working with Vendors, Banners and Affiliates
How to limit access to the admin menu
Token Replacement in DotNetNuke
Using Favicons within DotNetNuke
DotNetNuke Recycle Bin
How to Reset Host and Admin Login Details
How to Limit Access to Administrator Modules in DotNetNuke 5
How to Limit Modules Available in the Control Panel (Premium Modules)
How to Configure Which Modules Non-Administrators Can Add to a Page
Taxonomy and Folksonomy in DotNetNuke
You are not logged in.
You must log in to access all 
650+ videos, tutorials, podcasts, and more.
RSS Feeds