TimeOut();
// Do some error checking.
if ( request.hiddenLong.length > 155 )
{
ShowError("The long description has exceeded the limit of 155 characters.")
}
if ( request.shortDescription.length > 50 )
{
ShowError("The short description has exceeded the limit of 50 characters.")
}
// Connect to Db, if we are not connected
if ( !ConnectToDatabase() )
{
ShowError("Could not connect to database");
}
else
{
var eventStartDate = "'" + request.startMonth + "/" + request.startDay + "/" + request.startYear + "'";
var eventStopDate = "'" + request.endMonth + "/" + request.endDay + "/" + request.endYear + "'";
// If the action is 'Add', then insert the record
if ( request.actionType == 'Add' || request.actionType == 'Add Task' )
{
// Prepare query
var dbQuery = "INSERT INTO Events ";
dbQuery += "(eventId, loginName, eventStartDate, eventStopDate, eventGMTTime, shortDescription, longDescription) ";
dbQuery += "VALUES ( 0 , '" + request.modifyList + "', ";
dbQuery += eventStartDate + ", " + eventStopDate + ", ";
dbQuery += "'" + request.timeString + "', ";
dbQuery += "'" + request.shortDescription + "', ";
dbQuery += "'" + request.hiddenLong + "')";
}
// Else the action is 'Modify', then update the record
else
{
//Prepare query
var dbQuery = "UPDATE Events SET ";
dbQuery += "loginName = '" + request.modifyList + "',";
dbQuery += "eventStartDate = " + eventStartDate + ",";
dbQuery += "eventStopDate = " + eventStopDate + ",";
dbQuery += "eventGMTTime = '" + request.timeString + "',";
dbQuery += "shortDescription = '" + request.shortDescription + "',";
dbQuery += "longDescription = '" + request.hiddenLong + "' ";
dbQuery += "WHERE eventId = " + request.eventId;
}
// Execute the query
dbStatus = database.execute(dbQuery);
// Check status of the query.
if ( dbStatus )
{
if ( request.actionType == 'Modify' )
ShowError("Could not update record.");
else
ShowError("Could not insert record.");
}
// Redirect to previous page
if (request.hitMe == "back")
{
redirect(client.prevPage);
}
}