Code that makes me smile – more sql, disctinct/paging

Another part of the ever-ongoing project is to find a way to add a CMS function to the timetables.

Now we really should (and almost certainly will in the future) simply API data from our bookings and reservations system onto our site, so this solution is more of a stop-gap, but it does give me an excuse to fiddle with code, and anyone writing an excuse to help me refine it!

So, in essence we break down the list of flights/sailings into categories, for the ship it’s a little different hence; general, special, tidal and gig weekend sailings. So a database with a category field was created, my plan was (rightly or wrongly) to page through the recordset as many times as there were categories, the reason? So I can display them in sections on the page.

The CMS page is more or less the same as you see on the site http://www.islesofscilly-travel.co.uk/timetable_sc3.asp the main difference being that each row is a form, and each field is editable and has an update and delete button.

I’ve also added some (hopefully) intelligence in the page(s) that records will not display past their advertised date (much like the offers page) which keeps the whole thing nice and clean, and hopefully will mean that we can update as we go.

In order to get this happening I envisaged two aspects; 1) cycling through the recordset more than once 2) splitting the page down by category

To start me off I wanted a list of categories, this can be done by getting a “disctinct” set of data from a recordset

Select Distinct categoryname
From tablename

This yields a short list of distinct categories,next thing was to loop through them, but I also wanted to put a drop-down list on each row (in case we decided to change a category) so I added the list to an array, but in trying to cover off all of my bases I wanted the array to be dynamic;

So, I created a variable to count the number of records and used the following code;

number_of_records = 0
DO WHILE NOT recordset.EOF
number_of_records = number_of_records + 1
recordset.MoveNext
Loop

That gave me the magic number, then we reset the recordset and populated the array. The script moves to the first record, creates an array based on the number of records we’d previously counted (I had to use ReDim here, not 100% sure why!) then loop through the recordset adding the categories into the array.

Recordset.MoveFirst
ReDim list_of_categories(number_of_records)
Dim array_id
Do While Not Recordset.EOF
array_id = array_id + 1
list_of_categories(array_id)  = Recordset.Fields.Item(“categoryname”).Value
Recordset.MoveNext
Loop

Ok, so that’s populated our array. Next job is to cycle through the full recordset (remember the first recordset was only a DISTINCT list of categories) and acutally display the details per category. For this I had to use a second version of the recordset.

Recordset.MoveFirst
Do While Not Recordset.EOF
Which_Category = (Recordset.Fields.Item(“categoryname”).Value
<in here we have some html, table headings>
Do While Not Recordset2.EOF
If (Recordset2.Fields.Item(“categoryname”).Value) = Which_Category then
<display the data – as it matches the current category we are looking for>
Else
<do nothing>
End If
Recordset2.MoveNext
Loop

So, this moves through each category type (Recordset) and cycles through the whole, non-DISCTINCT, recordset to display all records in a given category, before moving on to the next. Once complete we have a list by category of all records.

Now, the clever bit (at least for me anyway!) is that I added in a form to each row, and, using Dreamweavers built-in application objects, added an update record script. At the end of each row there is the previously mentioned drop-down list that allows you to change the designation of each record if required. And by using the code that checks if a record is part of the category I also set the selected option correctly.

This gives us inline editing, bundled with my multi-purpose delete record script and we have a powerful CMS page that will deliver the required content.

Reading it back now I barely understand how it works! But that it does is enough!

Adventures in Sharepoint – email setup

Ok, cheeky post but too much wordage for twitter – just a quick post to say that I have configured incoming/outgoing email on my SP application, and normally I’d reproduce the whole lot here but today I’ll just provide you the two excellent links that helped 100%.

http://sharepointgeorge.com/2010/configuring-incoming-email-sharepoint-2010/

And

http://sharepointgeorge.com/2010/configuring-outgoing-email-sharepoint-2010/

Many thanks must go to Sharepoint George for those!

Code that makes me smile – sql comparisons

Ok, just a brief one, but important, for me, nonetheless!

I have a page on our site that displays various special offers – the CMS part is coded so that each offer is an entry in the a database, the form contains two date variables, offer start and offer end dates. The idea being that you can input a special offer record in advance, it will appear on the day the offer starts and disappear the day following the offer ending, as the advert says…We do a similar thing on our vacancies page, the only difference being that some offers do not have end dates.

Why have this?  Isn’t it just overcomplicating? Sure, you could just enter a date far into the future, but that adds to the guesswork, so the section was designed to allow a NULL date entry on the end date field which would allow the record to stay on the site indefinitely, the problem?  Constructing the SQL statement to let that happen….well it may be simple to some, but here’s my solution!

SELECT *
FROM specialofferstable
WHERE offerenddate >= date() or offerenddate is null
ORDER BY offerstartdate ASC

The problem was having the SQL select records that were in date OR nulls, of course I was trying =null and variations thereof, until I found a simple tutorial on SQL statements that showed the way.  Hyper advanced SQL it may not be, but Dreamweaver says it’s advanced and I’m happy to have figured it out!!

http://www.firstsql.com/tutor2.htm

Adventures with Sharepoint – Document Library Setup/Permissions

Keeping things nice and simple, just the one document library but since we have several departments who will manage their documents directly it seemed the most sensible way was to add sub folders and assign permissions to each one for editors.  Rather than extend the collaboration to everyone we are keeping the majority of the users on simple read permissions.

First off set the Document Library Permissions

  • From your sites homepage click Site Actions, Site Settings
  • Under the Site Administration heading click Site Libraries & Lists
  • From the Site Libraries & Lists page click Customize “Shared Documents” (or whatever you want to call it)
  • Under Permissions and Management heading click “Permissions for this document library”
  • If “This library inherits permissions from its parent. (home site)”, disable this by clicking Stop Inheriting Permissions and then Ok
  • You should now see that”This library has unique permissions” and you can modify the permissions as you require without inherited permissions confusing things!

We have stuck with a single limited access group which permits all domain users to read the site without having to log in see; http://www.rikzblog.co.uk/?p=257 and each section administrator is added on an ad hoc basis, there’s so few and they’ll change very infrequently it was easier than using groups – for now

Once that has been completed you can now create sub folders if you choose to

  • Click Shared Documents
  • Under Library Tools, click Documents, and then New Folder.
  • Give the New Folder a name and click Save.
  • Select the folder (click the check box next to the icon) and click Document Permissions on the ribbon
  • Switch off Inheriting Permissions
  • Make permission changes as required

You can now delegate management per folder and start uploading documents!  Just be sure to remember to Publish documents otherwise you’ll be like me, spending 20 mins trying to work out what was wrong with permissions, when in actual fact the documents I’d uploaded were still drafts.

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.