Saturday, October 1, 2005

Getting inside the code of the automated signature generator

PROGRAMMING POWER

By Mick Moignard

This is the third part in our "Building an automated signature generator application" series. If you haven't read Part I, all about the user experience, or Part II, all about creating templates, you'll find a link to both at the end of this article. In this week's installment, we'll learn how the application actually works.

And how does it work?

I'm not going to show you exactly how all of it works. I'm assuming that you've downloaded the thing, and if you haven't, go ahead and do it (the link's at the end of this article), then explore it. But I will call out a few features that help it on its way.

First of all, the intention is that the end-users are Readers in the ACL. This basically means that they can't update anything in it, but in fact that's not true; their signature data is stored as public documents, and the end-users can read and write public documents via the -Default- entry in the ACL.

You'll see a $PublicAccess field in the signature data documents. End-users are not able to see the Admin view of all users data, because that area of the Left Page page is hidden from anyone with Reader or below access level. It's not secure, but then it's not intended to be. It just keeps other people's signature data away from most prying eyes. They can only interact with their own.

The administrator, who is anyone with access greater than Reader, can see all the data. This is useful for helping people who are having trouble.

When any user, regular end-user or Administrator, clicks on "My Signature", an agent called (MYSIG) is run. This locates a document in the (USERS) view, keyed on the end-user's abbreviated name. If there is one present, it is displayed in edit mode. If not, one is created, and opened in edit. This means that there will be one and only one document for each user, by abbreviated Notes name.

The signature templates are just Notes documents. The only clever bit is the placeholder piece. As you've seen in the example above, placeholders are added into the text bounded by the characters #%..%#. Inserting a placeholder is done with the following formula code -- of which the meat is the five @commands at the end.

promptlist:= "HTTP Link 1":"Logo Image 1":"Logo Alt 1":"HTTP Link 2":"Logo Image 2":
"Logo Alt 2":"User Name":"Email":"Job Title":"Phone":"Fax":"Site Address":"Map Street":
"Map Country":"Map City":"Map PostCode":"Department":"Room":"Company":"Cell Phone":
"MAP URL":"Strapline";
fieldlist:= "http":"http_image":"http_image_alt":"http_1":"http_image_1":
"http_image_alt_1":"username":"email":"title":"Phone":"fax":"Address":"Street":
"country":"city":"zip":"dept":"room":"company":"cellPhone":"MapURL":"strapline";
fieldname := @Prompt([OkCancelList]; "Select Field"; "Select the fieldname to insert as a placeholder"; "";promptlist);
@Command([TextSetFontColor];[Red]);
@Command([TextBold]);
@Command([EditInsertText];"#%"+\@ReplaceSubstring(fieldname;promptlist;fieldlist)+"%#");
@Command([TextSetFontColor];[Black]);
@Command([TextBold])