/*======================================================================
The star_password function receives user password and modifies it to
be displayed as a string of "*". This protects the password from
being seen by passers-by. This function is used when re-displaying
the form following a database action. (i.e. not enterable,
confirmation form).
=======================================================================
*/
function star_password(password) //Generates a string of "*" based on the value passed
{ var result = "";
password = "" + password; // convert str to a string if not already
var len = password.length;
var pos = 0;
while( pos < len )
{
result = result + "*";
pos = pos + 1
}
return result;
}
/*======================================================================
The get_db_user_rec function retrieves a single user's account
information from the database. This is a method of the user object.
Once the user object has been created and an initial value for
userid place in it, this method is called to complete the
population of the objects attribute values.
=======================================================================
*/
function get_db_user_rec()
{ user_info = database.cursor('SELECT user.password, user.lastname, user.firstname, user.interestgroupid, interestgroup.interestgroup, user.email, user.phone, user.fax, user.accesslevel FROM user, interestgroup WHERE user.interestgroupid = interestgroup.interestgroupid and user.userid = "'+this.userid+'"');
if(user_info.next())
{this.password = ""+user_info.password+"";
this.lastname = ""+user_info.lastname+"";
this.firstname = ""+user_info.firstname+"";
this.interestgroupid = user_info.interestgroupid;
this.interestgroup = ""+user_info.interestgroup+"";
this.email = ""+user_info.email+"";
this.phone = ""+user_info.phone+"";
this.fax = ""+user_info.fax+"";
this.accesslevel = user_info.accesslevel;
user_info.close();
result = true;
}
else
{write('Record Not Found!
Another administrator has deleted this record!');
result = false;
}
return result;
}
/*======================================================================
The ins_db_user_rec function inserts a single user's account
information into the database. This is a method of the user object.
======================================================================
*/
function ins_db_user_rec()
{ this.userid = check_text_entry(this.userid);
this.lastname = check_text_entry(this.lastname);
this.firstname = check_text_entry(this.firstname);
this.email = check_text_entry(this.email);
this.phone = check_text_entry(this.phone);
this.fax = check_text_entry(this.fax);
result = database.execute('INSERT INTO user (userid, password,lastname,firstname,interestgroupid,accesslevel,email,phone,fax) VALUES("'
+ this.userid
+'","'+this.password
+'","'+this.lastname
+'","'+this.firstname
+'",'+ this.interestgroupid
+',"'+ this.accesslevel
+'","'+this.email
+'","'+this.phone
+'","'+this.fax
+'")' );
if (result != 0)
{write('
A Database error has occurred ' + result + '');
write('
' + database.majorErrorCode() + '');
write('
' + database.majorErrorMessage() + '');
request.mode="add"};
else
{write('The following User information has been added.
');}
}
/*======================================================================
The del_db_user_rec function deletes a single user's account
information from the database. This is a method of the user object.
======================================================================
*/
function del_db_user_rec()
{ result = database.execute('DELETE FROM user WHERE userid="'+this.userid+'"');
if (result != 0)
{write('
A Database error has occurred ' + result + '');
write('
' + database.majorErrorCode() + '');
write('
' + database.majorErrorMessage() + '');
request.mode="D"};
else
{write('User: '+this.userid+' Deleted.');}
}
/*======================================================================
The upd_db_user_rec function updates a single user's account
information in the database. This is a method of the user object.
======================================================================
*/
function upd_db_user_rec() //Updates a user's information in the database
{ this.userid = check_text_entry(this.userid);
this.lastname = check_text_entry(this.lastname);
this.firstname = check_text_entry(this.firstname);
this.email = check_text_entry(this.email);
this.phone = check_text_entry(this.phone);
this.fax = check_text_entry(this.fax);
result = database.execute('UPDATE user SET password="'+ this.password
+'", lastname="'+this.lastname
+'", firstname="'+this.firstname
+'", interestgroupid='+this.interestgroupid
+', email="'+this.email
+'", phone="'+this.phone
+'", fax="'+this.fax
+'", accesslevel="'+this.accesslevel
+'" WHERE userid="'+this.userid+'"');
if (result != 0)
{write('
A Database error has occurred ' + result + '');
write('
' + database.majorErrorCode() + '');
write('
' + database.majorErrorMessage() + '');
request.mode="add"};
else
{write('The following User information has been updated.
');}
}
//User Object
function user_rec(userid, password, lastname, firstname, interestgroupid, interestgroup,
email, phone, fax, accesslevel)
{ this.userid = userid;
this.password = password;
this.lastname = lastname;
this.firstname = firstname;
this.interestgroupid = interestgroupid;
this.interestgroup = interestgroup;
this.email = email;
this.phone = phone;
this.fax = fax;
this.accesslevel = accesslevel;
this.ins_db_user_rec = ins_db_user_rec;
this.upd_db_user_rec = upd_db_user_rec;
this.get_db_user_rec = get_db_user_rec;
this.del_db_user_rec = del_db_user_rec;
}
/*======================================================================
The loadTable function creates the user 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 loadTable()
{ if ((request.mode == "insert"))
{ temp_user = new user_rec(request.userid, request.password, request.lastname,
request.firstname, request.interestgroupid, request.interestgroup, request.email,
request.phone, request.fax, request.accesslevel);
temp_user.ins_db_user_rec();
result = temp_user.get_db_user_rec();
}
if (request.mode == "add")
{ temp_user = new user_rec("","","","",1,"","","","","");
result=true;
}
if (request.mode == "dump")
{ temp_user = new user_rec(request.userid,"","","",1,"","","","","");
temp_user.del_db_user_rec();
}
if ((request.mode == "M") || (request.mode == "D"))
{ temp_user = new user_rec(request.userid,"","","",1,"","","","","");
result = temp_user.get_db_user_rec();
}
if (request.mode == "update")
{ temp_user = new user_rec(request.userid, request.password, request.lastname,
request.firstname, request.interestgroupid, request.interestgroup, request.email,
request.phone, request.fax, request.accesslevel);
temp_user.upd_db_user_rec();
result = temp_user.get_db_user_rec();
}
if ((request.mode != "dump") && (result))
{
write('');
displayRow("User ID","RIGHT","TEXT","userid",temp_user.userid, client.accesslevel,8, 10,"V");
displayRow("First Name","RIGHT","TEXT","firstname",temp_user.firstname, client.accesslevel,20, 22, "A");
displayRow("Last Name","RIGHT","TEXT","lastname",temp_user.lastname, client.accesslevel,20, 22,"A");
displayRow("Password","RIGHT","PASSWORD","password",temp_user.password, client.accesslevel,8, 10, "A");
if (((request.mode == "add") || (request.mode == "M")) && ((temp_user.userid != "Admin") && (client.accesslevel != "U")))
{get_int_grp(temp_user.interestgroupid, "N");}
else
{write('Interest Group | ');
write(''+temp_user.interestgroup+' |
');
write('');
}
displayRow("E-mail Address","RIGHT","TEXT","email",temp_user.email, client.accesslevel,60, 35,"A");
displayRow("Phone Number","RIGHT","TEXT","phone",temp_user.phone, client.accesslevel,25,22, "A");
displayRow("Fax Number","RIGHT","TEXT","fax",temp_user.fax, client.accesslevel,25,22, "A");
write('');
write('Access Level | ');
if ((request.mode == "add") || ((request.mode == "M") && (client.accesslevel == "A") && (temp_user.userid != "Admin")))
{ write(' | ');}
else
{write('
');
write('
');
result = true;
}
else
{ result = false;
}
return result;
}
write('');
result = loadTable();
if (result)
{
write('');
if (request.mode == "add")
{