/* In order to abstract a CLIENT side JavaScript function we embedded it into a bunch of write statements using SERVER side JavaScript. This allowed us to use the same Client side function in many pages, while keeping the function in only one place (sam.js). */ makeClientScriptDateFunction(); Add/Modify Bulletins

System Administration

Add/Modify Bulletins

/*====================================================================== The get_db_bulltn_rec function retrieves a single bulletin from the database. This is a method of the bulletin object. Once the bulletin object has been created and an initial value for bulletinid placed in it, this method is called to complete the population of the objects attribute values. ======================================================================= */ function get_db_bulltn_rec() { bulltn_info = database.cursor('SELECT bulletinid, title, content, bulletin.interestgroupid, interestgroup.interestgroup, ownerid,'+ ' MONTH(expirationdate) AS ex_mon, DAY(expirationdate) AS ex_day, YEAR(expirationdate) AS ex_year, MONTH(activationdate) AS ac_mon, DAY(activationdate) AS ac_day, YEAR(activationdate) AS ac_year,'+ ' modifieddate FROM bulletin, interestgroup WHERE bulletin.interestgroupid = interestgroup.interestgroupid and bulletinid = '+this.bulletinid); if(bulltn_info.next()) {this.bulletinid = bulltn_info.bulletinid; this.title = ""+bulltn_info.title+""; this.interestgroupid = bulltn_info.interestgroupid; this.interestgroup = ""+bulltn_info.interestgroup+""; this.content = ""+bulltn_info.content+""; this.ownerid = ""+bulltn_info.ownerid+""; this.expirationdate = bulltn_info.ex_mon + "/" + bulltn_info.ex_day + "/" + bulltn_info.ex_year; this.activationdate = bulltn_info.ac_mon + "/" + bulltn_info.ac_day + "/" + bulltn_info.ac_year; this.modifieddate = bulltn_info.modifieddate; bulltn_info.close(); result = true; } else {write('

Record Not Found!

Another administrator has deleted this record!'); result = false; } return result; } /*====================================================================== The get_db_bulltn_rec2 function retrieves a single bulletin from the database. This is a method of the bulletin object. If a new bulletin record is created by the user, the application has no way of getting the bulletin id generated by the database. This method attempts to retrieve the record, (including the bulletin id) from the database by matching other criteria that it has about the record. ====================================================================== */ function get_db_bulltn_rec2() { bulltn_info = database.cursor('SELECT bulletinid, title, bulletin.interestgroupid, interestgroup.interestgroup, content, ownerid, MONTH(expirationdate) AS ex_mon, DAY(expirationdate) AS ex_day, YEAR(expirationdate) AS ex_year, MONTH(activationdate) AS ac_mon, DAY(activationdate) AS ac_day, YEAR(activationdate) AS ac_year, modifieddate FROM bulletin, interestgroup '+ 'WHERE bulletin.interestgroupid = interestgroup.interestgroupid and title = "'+ this.title+'" and ownerid = "'+this.ownerid+'" and content = "'+ this.content+'" and bulletin.interestgroupid = '+this.interestgroupid+' and expirationdate = DATE("'+ this.expirationdate+'") and activationdate = DATE("'+this.activationdate+'")'); if(bulltn_info.next()) {this.bulletinid = bulltn_info.bulletinid; this.title = ""+bulltn_info.title+""; this.interestgroupid = bulltn_info.interestgroupid; this.interestgroup = ""+bulltn_info.interestgroup+""; this.content = ""+bulltn_info.content+""; this.ownerid = ""+bulltn_info.ownerid+""; this.expirationdate = bulltn_info.ex_mon + "/" + bulltn_info.ex_day + "/" + bulltn_info.ex_year; this.activationdate = bulltn_info.ac_mon + "/" + bulltn_info.ac_day + "/" + bulltn_info.ac_year; this.modifieddate = bulltn_info.modifieddate; bulltn_info.close(); result = true; } else {write('

Record Not Found!

Another administrator has deleted this record!'); result = false; } return result; } /*====================================================================== The ins_db_bulltn_rec function inserts a single bulletin into the database. This is a method of the bulletin object. ====================================================================== */ function ins_db_bulltn_rec() { this.content = check_size(this.content, 255); this.content = check_text_entry(this.content); this.title = check_text_entry(this.title); result = database.execute('INSERT INTO bulletin (bulletinid, title, interestgroupid, content, ownerid, expirationdate, activationdate, modifieddate ) VALUES ('+this.bulletinid+',"' + this.title +'",' +this.interestgroupid +',"' +this.content +'","'+this.ownerid +'", "'+this.expirationdate +'", "'+this.activationdate +'", CURRENT)' ); if (result != 0) {write('
A Database error has occurred ' + result + '
'); write('
' + database.majorErrorCode() + '
'); write('
' + database.majorErrorMessage() + '
'); request.mode="add"}; else {write('

The following Bulletin has been added.

');} } /*====================================================================== The del_db_bulltn_rec function deletes a single bulletin from the database. This is a method of the bulletin object. ====================================================================== */ function del_db_bulltn_rec() { result = database.execute('DELETE FROM bulletin WHERE bulletinid='+this.bulletinid); if (result != 0) {write('
A Database error has occurred ' + result + '
'); write('
' + database.majorErrorCode() + '
'); write('
' + database.majorErrorMessage() + '
'); request.mode="D"}; else {write('Bulletin: '+this.title+' deleted.'); } } /*====================================================================== The upd_db_bulltn_rec function updates a single bulletin in the database. This is a method of the bulletin object. ====================================================================== */ function upd_db_bulltn_rec() { this.content = check_size(this.content, 255); this.content = check_text_entry(this.content); this.title = check_text_entry(this.title); result = database.execute('UPDATE bulletin SET title="'+ this.title +'", content="'+ this.content +'", interestgroupid='+this.interestgroupid +' , ownerid="'+this.ownerid +'" , expirationdate= (DATE("'+this.expirationdate +'")), activationdate= (DATE("'+this.activationdate +'")), modifieddate = CURRENT WHERE bulletinid='+this.bulletinid); if (result != 0) {write('
A Database error has occurred ' + result + '
'); write('
' + database.majorErrorCode() + '
'); write('
' + database.majorErrorMessage() + '
'); request.mode="M"}; else {write('

The following Bulletin has been updated.

');} } //Bulletin Object function bulltn_rec(bulletinid, title, interestgroupid, interestgroup, content, ownerid, expirationdate, activationdate, modifieddate) { this.bulletinid = bulletinid; this.title = title; this.interestgroupid = interestgroupid; this.interestgroup = interestgroup; this.content = content; this.ownerid = ownerid; this.expirationdate = expirationdate; this.activationdate = activationdate; this.modifieddate = modifieddate; this.ins_db_bulltn_rec = ins_db_bulltn_rec; this.upd_db_bulltn_rec = upd_db_bulltn_rec; this.get_db_bulltn_rec = get_db_bulltn_rec; this.get_db_bulltn_rec2 = get_db_bulltn_rec2; this.del_db_bulltn_rec = del_db_bulltn_rec; } /*====================================================================== The load_Bulletin_Tbl function creates the bulletin object and loads it with initial values. The appropriate method is then executed against the current object based on the mode the form is in. The form basically has two main categories of modes: user and database. User modes are add, D (delete), M (modify). Database modes are insert, dump, and update. Once the initial method has been called on the object, the specifics of the page formatting are determined based on field, user access, and mode. ====================================================================== */ function load_Bulletin_Tbl() { if (request.mode == "insert") { temp_bulltn = new bulltn_rec(request.bulletinid, request.title, request.interestgroupid, "", request.content, request.ownerid, request.expirationdate, request.activationdate, request.modifieddate); temp_bulltn.ins_db_bulltn_rec(); result = temp_bulltn.get_db_bulltn_rec2(); } if (request.mode == "add") { todays_date = makeToday(); expir_date = todayPlus(7, "D"); temp_bulltn = new bulltn_rec(0,"",1,"","",client.userid,expir_date,todays_date,""); result = true; } if (request.mode == "dump") { temp_bulltn = new bulltn_rec(request.bulletinid, request.title, request.interestgroupid, "",request.content, request.ownerid, request.expirationdate, request.activationdate, request.modifieddate); temp_bulltn.del_db_bulltn_rec(); } if ((request.mode == "M") || (request.mode == "D")) { temp_bulltn = new bulltn_rec(request.bulletinid,"",1,"","",client.userid,"mm/dd/yyyy","mm/dd/yyyy",""); result = temp_bulltn.get_db_bulltn_rec(); } if (request.mode == "update") { temp_bulltn = new bulltn_rec(request.bulletinid, request.title, request.interestgroupid, "",request.content, request.ownerid, request.expirationdate, request.activationdate, request.modifieddate); temp_bulltn.upd_db_bulltn_rec(); result = temp_bulltn.get_db_bulltn_rec(); } if ((request.mode != "dump") && (result)) { write(''); write(''); displayRow("Title","RIGHT","TEXT","title",temp_bulltn.title, client.accesslevel, 60, 50,"A"); if ((request.mode == "add") || (request.mode == "M")) {get_int_grp(temp_bulltn.interestgroupid, "A");} else {write(''); write(''); write(''); } write(''); write(''); write(''); write(''); write(''); write(''); write(''); write(''); displayRow("Activation Date","RIGHT","TEXT","activationdate",temp_bulltn.activationdate, client.accesslevel, 10, 12,"A"); displayRow("Expiration Date","RIGHT","TEXT","expirationdate",temp_bulltn.expirationdate, client.accesslevel, 10, 12,"A"); write('
Interest Group'+temp_bulltn.interestgroup+'
Content'); if ((request.mode == "add") || (request.mode == "M")) { write(''); } else {write(''); write(temp_bulltn.content); } write('
Owner ID'); write(''); write(temp_bulltn.ownerid); write('
'); write(''); result = true; } else { result = false; } return result; } write('
'); write(''); result = load_Bulletin_Tbl(); if (result) { write('

'); if (request.mode == "add") { } if (request.mode == "M") { } if (request.mode == "D") { write(''); } if ((request.mode == "dump") || (request.mode == "insert") || (request.mode == "update")) { write(''); } write('

'); write('
'); } else {write('');}