/*======================================================================
The get_db_complnk_rec function retrieves a single competitor link
from the database. This is a method of the competitor object. Once
the competitor object has been created and an initial value for
competitorid placed in it, this method is called to complete the
population of the objects attribute values.
=======================================================================
*/
function get_db_complnk_rec()
{ complnk_info = database.cursor('SELECT competitorid, competitorname, url, competitor.interestgroupid, interestgroup.interestgroup, competitor.description, 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 competitor, interestgroup WHERE competitor.interestgroupid = interestgroup.interestgroupid and competitorid = '+this.competitorid);
if(complnk_info.next())
{this.competitorid = complnk_info.competitorid;
this.competitorname = ""+complnk_info.competitorname+"";
this.url = ""+complnk_info.url+"";
this.interestgroupid = complnk_info.interestgroupid;
this.interestgroup = ""+complnk_info.interestgroup+"";
this.description = ""+complnk_info.description+"";
this.ownerid = ""+complnk_info.ownerid+"";
this.expirationdate = complnk_info.ex_mon + "/" + complnk_info.ex_day + "/" + complnk_info.ex_year;
this.activationdate = complnk_info.ac_mon + "/" + complnk_info.ac_day + "/" + complnk_info.ac_year;
this.modifieddate = complnk_info.modifieddate;
complnk_info.close();
result = true;
}
else
{write('Record Not Found!
Another administrator has deleted this record!');
result = false;
}
return result;
}
/*======================================================================
The get_db_complnk_rec2 function retrieves a single competitor link
from the database. This is a method of the competitor object. If a new
competitor record is created by the user, the application has no way
of getting the competitor id generated by the database. This method
attempts to retrieve the record, (including the competitor id) from
the database by matching other criteria that it has about the record.
======================================================================
*/
function get_db_complnk_rec2()
{ complnk_info = database.cursor('SELECT competitorid, competitorname, url, competitor.interestgroupid, interestgroup.interestgroup, competitor.description, 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 competitor, interestgroup '+
'WHERE competitor.interestgroupid = interestgroup.interestgroupid and competitorname = "'+
this.competitorname+'" and url = "'+this.url+'" and ownerid = "'+this.ownerid+'" and competitor.description = "'+
this.description+'" and competitor.interestgroupid = '+this.interestgroupid+' and expirationdate = DATE("'+
this.expirationdate+'") and activationdate = DATE("'+this.activationdate+'")');
if(complnk_info.next())
{this.competitorid = complnk_info.competitorid;
this.competitorname = ""+complnk_info.competitorname+"";
this.url = ""+complnk_info.url+"";
this.interestgroupid = complnk_info.interestgroupid;
this.interestgroup = ""+complnk_info.interestgroup+"";
this.description = ""+complnk_info.description+"";
this.ownerid = ""+complnk_info.ownerid+"";
this.expirationdate = complnk_info.ex_mon + "/" + complnk_info.ex_day + "/" + complnk_info.ex_year;
this.activationdate = complnk_info.ac_mon + "/" + complnk_info.ac_day + "/" + complnk_info.ac_year;
this.modifieddate = complnk_info.modifieddate;
complnk_info.close();
result = true;
}
else
{write('Record Not Found!
Another administrator has deleted this record!');
result = false;
}
return result;
}
/*======================================================================
The ins_db_complnk_rec function inserts a single competitor link
into the database. This is a method of the competitor object.
======================================================================
*/
function ins_db_complnk_rec()
{ this.description = check_size(this.description, 255);
this.competitorname = check_text_entry(this.competitorname);
this.url = check_text_entry(this.url);
this.description = check_text_entry(this.description);
result = database.execute('INSERT INTO competitor (competitorid, competitorname, url, interestgroupid, description, ownerid, expirationdate, activationdate, modifieddate ) VALUES ('+this.competitorid+',"'
+ this.competitorname
+'","'+this.url
+'",' +this.interestgroupid
+',"' +this.description
+'","'+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 External Link has been added.
');}
}
/*======================================================================
The del_db_complnk_rec function deletes a single competitor link
from the database. This is a method of the competitor object.
======================================================================
*/
function del_db_complnk_rec()
{
result = database.execute('DELETE FROM competitor WHERE competitorid='+this.competitorid);
if (result != 0)
{write('
A Database error has occurred ' + result + '');
write('
' + database.majorErrorCode() + '');
write('
' + database.majorErrorMessage() + '');
request.mode="D"};
else
{write('External Link: '+this.competitorname+' deleted.');
}
}
/*======================================================================
The upd_db_complnk_rec function updates a single competitor link
in the database. This is a method of the competitor object.
======================================================================
*/
function upd_db_complnk_rec()
{ this.description = check_size(this.description, 255);
this.competitorname = check_text_entry(this.competitorname);
this.url = check_text_entry(this.url);
this.description = check_text_entry(this.description);
result = database.execute('UPDATE competitor SET competitorname="'+ this.competitorname
+'", description="'+ this.description
+'", url="'+this.url
+'", interestgroupid='+this.interestgroupid
+' , ownerid="'+this.ownerid
+'" , expirationdate= (DATE("'+this.expirationdate
+'")), activationdate= (DATE("'+this.activationdate
+'")), modifieddate = CURRENT WHERE competitorid='+this.competitorid);
if (result != 0)
{write('
A Database error has occurred ' + result + '');
write('
' + database.majorErrorCode() + '');
write('
' + database.majorErrorMessage() + '');
request.mode="M"};
else
{write('The following External Link has been updated.
');}
}
//Competitor Link Object
function complnk_rec(competitorid, competitorname, url, interestgroupid, interestgroup, description, ownerid, expirationdate, activationdate, modifieddate)
{ this.competitorid = competitorid;
this.competitorname = competitorname;
this.url = url;
this.interestgroupid = interestgroupid;
this.interestgroup = interestgroup;
this.description = description;
this.ownerid = ownerid;
this.expirationdate = expirationdate;
this.activationdate = activationdate;
this.modifieddate = modifieddate;
this.ins_db_complnk_rec = ins_db_complnk_rec;
this.upd_db_complnk_rec = upd_db_complnk_rec;
this.get_db_complnk_rec = get_db_complnk_rec;
this.get_db_complnk_rec2 = get_db_complnk_rec2;
this.del_db_complnk_rec = del_db_complnk_rec;
}
/*======================================================================
The load_Comp_Lnk_Tbl function creates the competitor 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_Comp_Lnk_Tbl()
{ if (request.mode == "insert")
{ temp_complnk = new complnk_rec(request.competitorid, request.competitorname, request.url, request.interestgroupid, "", request.description, request.ownerid, request.expirationdate, request.activationdate, request.modifieddate);
temp_complnk.ins_db_complnk_rec();
result = temp_complnk.get_db_complnk_rec2();
}
if (request.mode == "add")
{ todays_date = makeToday();
expir_date = todayPlus(1, "M");
temp_complnk = new complnk_rec(0,"","",1,"","",client.userid,expir_date,todays_date,"");
result = true;
}
if (request.mode == "dump")
{ temp_complnk = new complnk_rec(request.competitorid, request.competitorname, request.url, request.interestgroupid, "",request.description, request.ownerid, request.expirationdate, request.activationdate, request.modifieddate);
temp_complnk.del_db_complnk_rec();
}
if ((request.mode == "M") || (request.mode == "D"))
{ temp_complnk = new complnk_rec(request.competitorid,"","",1,"","",client.userid,"mm/dd/yyyy","mm/dd/yyyy","");
result = temp_complnk.get_db_complnk_rec();
}
if (request.mode == "update")
{ temp_complnk = new complnk_rec(request.competitorid, request.competitorname, request.url, request.interestgroupid, "",request.description, request.ownerid, request.expirationdate, request.activationdate, request.modifieddate);
temp_complnk.upd_db_complnk_rec();
result = temp_complnk.get_db_complnk_rec();
}
if ((request.mode != "dump") && (result))
{
write('');
write('');
displayRow("Company Name","RIGHT","TEXT","competitorname",temp_complnk.competitorname, client.accesslevel, 60, 50,"A");
displayRow("URL","RIGHT","TEXT","url",temp_complnk.url, client.accesslevel, 80, 50 ,"A");
if ((request.mode == "add") || (request.mode == "M"))
{get_int_grp(temp_complnk.interestgroupid, "A");}
else
{write('Interest Group | ');
write(''+temp_complnk.interestgroup+' |
\n');
write('');
}
write('');
write('Description | ');
write('');
if ((request.mode == "add") || (request.mode == "M"))
{
write('');
}
else
{write('');
write(temp_complnk.description);
}
write(' | ');
write('
\n');
write('');
write('Owner ID | ');
write('');
write('');
write(temp_complnk.ownerid);
write(' | ');
write('
\n');
displayRow("Activation Date","RIGHT","TEXT","activationdate",temp_complnk.activationdate, client.accesslevel, 10, 12,"A");
displayRow("Expiration Date","RIGHT","TEXT","expirationdate",temp_complnk.expirationdate, client.accesslevel, 10, 12,"A");
write('
\n');
write('');
result = true;
}
else
{ result = false;
}
return result;
}
write('');
result = load_Comp_Lnk_Tbl();
if (result)
{
write('');
if (request.mode == "add")
{