Wednesday, 24 November 2010

Blackbaud Netcommunity store / shop

I know that some people have the Blackbaud Netcommunity e-store / shop module installed that Blackbaud created themselves. We asked about this a while ago, and were told it's soon going to be a free part of Netcommunity and no longer charged for.

That was nearly a year ago, with no shop in sight as yet.

My next tutorial, hopefully in the next few weeks, will go through how to create your own online shop by using the Netcommunity API.

I've created a shop module of my own that allows you to list items, take payment, and manage stock levels. It also sends all the details through to Raiser's Edge to be processed in the Netcommunity plugin.

Making your own shop can be as complicated as you want it to be - for the purposes of the tutorial I will focus on creating a simple online shopping basket, with a checkout that takes payment and sends the transaction through to RE. The best thing is, the Netcommunity API does all the tricky bits for you in terms of card processing and transaction processing - the rest of the shop's functionality is entirely up to you to create using ASP.NET.

Blackbaud Labs
has an example of how to create a custom donation form that can easily be adapted to function as a checkout for a shop. If you take a look at that example it should give you plenty of ideas - it is in VB, however.

Thursday, 18 November 2010

Most wanted custom parts

If you could create a custom part that could do anything, what would it be? What is your most wanted feature that BBNC doesn't have?

Tuesday, 16 November 2010

Blackbaud Netcommunity says no to IE9

Irritatingly, the Netcommunity built-in text editor doesn't appear to get on with Internet Explorer 9.

More specifically, every single time you click on anything within the text editor box it throws a Javascript error. Disabling Javascript is no good, as everything is so AJAX-ified it won't even let you save changes without JS.

This appears to be an issue with the text editor (Tiny MCE) rather than Netcommunity itself, but as a customer, that's irrelevant.

Please fix this Blackbaud. IE9 will be out of Beta before you know it.

Update

The only reason I'm commenting on this is because installing the IE9 beta automatically removes all previous version of Internet Explorer - therefore it's the only IE I have.

Blackbaud's CTO Shaun Sullivan commented on Twitter that he will look into it - thanks very much.

Thursday, 4 November 2010

Tutorial: Role Redirect

This will be a long post. By the end of it you should be able to create a custom part that allows you to redirect members of certain Netcommunity roles automatically when they land on a certain page. Important: remove asterisks before copy & pasting code.

Create a skeleton custom part

Go back to earlier posts if you're not familiar with how to set up a bare-bones custom part - you'll need an Editor web user control and a Display web user control, along with references to BBNCExtensions in the appropriate places.

Add a new code file

Right-click on the project name and add a new C# code file. In this new file, create a new class:

public class rr_data {
public int pid;
public string roles;
}


This class will be saved in the Netcommunity data store, and will hold the page that you want to redirect users to, and the roles that the redirect applies to. A string is not the best format to hold the roles in, but I don't think the Netcommunity API will allow you to save more complex data types.

Design the Editor part

Open up the design part of the Editor control. Add this below the first ASP.NET statement at the top:

<*%@ Register TagPrefix="bbnc" Namespace="BBNCExtensions.ServerControls" Assembly="BBNCExtensions" %>

This allows you to use some of the Netcommunity server controls that are built-in to the API - in this case, we are going to use the PageLink control to hook into the link selecting functionality in BBNC.

Somewhere on the page, add this in:

<*bbnc:pagelink id="_pid" runat="server"> <*/bbnc:pagelink>

This will create a PageLink server control that allows the user to link to a BBNC page, document etc. Very useful. You might get 'unknown' errors but ignore them - this should work on the server.

Next, drag a CheckBoxList from the toolbox onto the page. Give it an ID of 'role_list'. This element will eventually be populated with all the roles that exist in the BBNC database, so the user can tick which ones they want the redirect to apply to.

Editor code

Now it's time for the Editor code-behind. Add a using statement at the top to System.Data.SqlClient.

In the OnLoadContent() method, add the following - you should be able to copy & paste it in:

// Fetch the data (if any):
rr_data get_data = base.Content.GetContent(typeof(rr_data)) as rr_data;
string[] _roles = null;

if (get_data!=null)
// Get the page ID from the BBNC data store
// and use it to pre-select the page in the PageLink control
_pid.PageID = get_data.pid;

// The roles are stored as a string, seperated
// by the ^ character - split up the string.
_roles = get_data.roles.Split('^');

try {

// Create a new SQL connection to the BBNC database
// You will need your own connection string -
// look in the web.config file in the Netcommunity folder
// on your web server for clues
SqlConnection sql = new SqlConnection("CONNECTION STRING HERE");

// Open the connection
sql.Open();

// Select the names of roles from the database
SqlCommand cmd = new SqlCommand("SELECT Name FROM dbo.ClientRoles", sql);

// Read the data in
SqlDataReader data = cmd.ExecuteReader();

// Create a new list item collection for the roles
ListItemCollection item_list = new ListItemCollection();

// Add each role to the collection
while (data.Read()) {
item_list.Add(data.GetValue(0).ToString());
}

// Close the connections
data.Close();
sql.Close();

// Add the roles to the CheckBoxList
for (int i = 0; i <* item_list.Count; i++) {
role_list.Items.Add(item_list[i]);
}


// If there are pre-selected roles in the data store
if (get_data.roles.Length > 1)
{

// Loop through each role and check for matches against
// the loaded data

for (int j = 0; j <* role_list.Items.Count; j++) {
for (int k = 0; k <* _roles.Length; k++ ) {
if (role_list.Items[j].Text == _roles[k])
{

role_list.Items[j].Selected = true;
}
}
}

}

} catch {

// Error checking etc goes here

}

In the OnSaveContent() method, add the following:

// Create new data object for the part
rr_data save_data = new rr_data();

// Save selected page from PageLink control to object
save_data.pid = _pid.PageID

// Loop through the list of available roles
// Stitch selected roles together with the ^ character
string selected_roles = "";

for (int i = 0; i <* role_list.Items.Count; i++)

{
if (role_list.Items[i].Selected)
{

selected_roles += (role_list.Items[i].Text)+"^";
}
}
// Save ^ seperated string to object
save_data.roles = selected_roles;


// Save the object to the data store
base.Content.SaveContent(save_data);
return true;

In the Page_Load() method of the Display part code-behind, add the following:

// Load data from the store
rr_data get_data = base.Content.GetContent(typeof(rr_data)) as rr_data;

if (get_data!=null)
{
// Split roles
string[] _roles = get_data.roles.Split('^');
int pid = get_data.pid;

bool _roles_match = false;

// Check for any role match
for (int i = 0; i <* _roles.Length; i++)
{
if (API.Users.CurrentUser.IsInRole(_roles[i]))
{
_roles_match = true;
}

}

// If match found
if (_roles_match)
{

// Redirect to specified page
string link = API.Navigation.GetPageURL(pid, 0);
Response.Redirect(link);
}

get_data = null;

That's it. Bit of a long post - even if the part is useless to you, hopefully there will be some stuff in there that will be useful to you.

Bear in mind that this is just an example - you should go through it yourself and ensure that all errors are being captured and dealt with properly, especially if you are hooking into the main BBNC database via SQL. It may be worth creating a new SQL user that only has access to the Roles table, for extra security.

If anyone tries any of the above then please post a comment!

Wednesday, 3 November 2010

Role Redirect

Recently I needed to redirect all users with certain roles as soon as they landed on a specific page - in other words, if a user in X role landed on this page, they would be redirected immedately; everyone else (from all other roles) would see the page normally.

The targeted content part built-in to Netcommunity allows you to target roles specifically with different content, but it doesn't allow you to perform redirects. So I built a custom part to do the job instead. In this post I'll explain what it does - in the next post, I will upload the code so you can see it all.

Role Redirect

The first problem was that Netcommunity doesn't appear to expose the list of roles via the API. It allows you to check whether a user is in a particular role (API.Users.CurrentUser.IsInRole), but that's only useful if you already know the name of the role.

To get around this, my custom part hooks straight into the BBNC database - the Roles table is very simple. When you edit the part, it fetches the list of Roles from the database - you can then select one (or more ) roles that you want to redirect when they land on a page with the part on it.

You then choose the page you want to redirect them to by using the PageLink server control - I don't think I've posted about server controls before, so I'll explain it in more detail in the next post. They are built-in bits of functionality that Blackbaud kindly provide as part of the API - there's more information on them here. They allow you to use some of the built-in Netcommunity parts, like the query picker, HTML editor, link picker, and more.

Once you've picked your page and picked the roles you want to redirect - that's it. You save, and put the part on a page.

The next post will be quite long as this is a more complicated custom part than I've posted before - it'll be up this week.