INAN Documentation - Polls

[ Home | INAN | Glial | Downloads | Documentation | FAQ | Features | Join ]

SourceForge
Project Page
Powered by
SourceForge Logo

Overview

Polls are one of the objects provided by the INAN system. At the moment, the polls are very simple but several improvements are planned. Users should note that no mechanism is provided to prevent ballot box stuffing. I have designed a system based on username and IP logging, but it has not yet been coded. Functions are detailed below. Optional arguments are indicated with italics.

There are four files in the sinaps/polls subdirectory that implement the polling system. addpoll.inc implements the form used to create a poll and insert it into the database. editpoll.inc implements the form used for editing a poll and saving those changes to the database. polls.inc is a library of functions used by the other poll scripts. search.inc implements a very simple search engine for the polls database.

The polls are stored in two parts in the database. The pollinfo table contains the poll ID number, the poll title, the status of the poll (open or closed) and a datestamp calculated when the poll was created. The pollpieces table contains the poll ID number, the poll items, and the number of votes cast for each item. I realize that this is not a normalized database, and I am planning to rewrite the poll system later to clean it up.

Polls API

int gCreatePollBar( int width ) :

Creates a JPEG bar that is width+1 pixels wide and 10 pixels high. The bar is saved in the sinaps/images directory and is used to display poll results - one percentage point equals one pixel of width. If no width is passed to the function, a value of FALSE is returned.

int gDeletePoll( int id ) :

Deletes the poll with ID number id from the tables in the polls database. If no poll ID is passed to the function, a value of FALSE is returned.

int gDisplayAllPolls( int count ) :

Displays all of the current polls in the database in nicely- formatted boxes, with 10 polls per page. If no count is passed to the function, count defaults to 0.

int gDisplayCurrentPoll( int id ) :

Displays the current poll in a nicely-formatted box. If no poll ID is passed to the function, a value of FALSE is returned.

void gFillCurrentPollBox() :

Fills in the "Current Poll" box on INAN pages with the title of the poll most recently added to the database. The title is a hyperlink that displays the current full poll when followed. If no poll is found in the database, a value of FALSE is returned.

int gGetCurrentOpenPollID( int id ) :

Returns the poll ID number of the poll most recently added to the polls database that has a status of "1", which means that the poll is open for voting. When no parameter is passed in, the current poll ID is used. The function recurses down through the polls database until either an open poll is found or the first poll in the database is reached. If no open poll is found in the database, a value of FALSE is returned.

int gGetCurrentPollID() :

Returns the poll ID number of the poll most recently added to the polls database. If no poll is found in the database, a value of FALSE is returned.

int gGetFirstPollID() :

Returns the poll ID number of first poll added to the polls database. If no poll is found in the database, a value of FALSE is returned.

int gGetLongPollArray( int id ) :

Returns all of the columns from the pollinfo and pollpieces tables as single array. If no poll ID is passed to the function, a value of FALSE is returned.

int gGetNewPollID() :

Fetches the ID number from the most recent poll in the database and increments it by one. The incremented number is returned for use as the ID number for the next new poll. If no poll is found in the database, a value of "1" is returned.

int gGetNextPollID( int id ) :

Returns the poll ID number of the poll succeeding poll id in the database. If no poll is found in the database, a value of FALSE is returned.

int gGetPollArray( int id ) :

Returns selected columns from the pollinfo and pollpieces tables as single array. The array contents are as follows: [poll ID, poll title, voting status, datestamp, number of poll items, item 1...item n, count 1...count n]. If no poll ID is passed to the function, a value of FALSE is returned.

int gGetPollTitle( int id ) :

Returns the title of the poll with ID number id in the database. If no poll is found in the database, a value of FALSE is returned.

int gGetPrevPollID( int id ) :

Returns the poll ID number of the poll preceding poll id in the database. If no poll is found in the database, a value of FALSE is returned.

int gVoteInCurrentPoll( int id ) :

Implements the voting booth for poll id. When a vote is cast, this function updates the appropriate counter in the poll database and displays the updated poll. If no poll ID is passed to the function, a value of FALSE is returned.

Top

This page last updated Monday, 20 November 2000.