/*======================================================================
The get_db_mime_rec function retrieves a single MIME type
from the database. This is a method of the MIME type object. Once
the MIME type object has been created and an initial value for
format placed in it, this method is called to complete the
population of the objects attribute values.
=======================================================================
*/
function get_db_mime_rec()
{ mime_info = database.cursor('SELECT format, type, extension FROM mimetypes WHERE format = "'+this.format+'"');
if(mime_info.next())
{this.format = ""+mime_info.format+"";
this.type = ""+mime_info.type+"";
this.extension = ""+mime_info.extension+"";
mime_info.close();
result = true;
}
else
{write('Record Not Found!
Another administrator has deleted this record!');
result = false;
}
return result;
}
/*======================================================================
The ins_db_mime_rec function inserts a single MIME type
into the database. This is a method of the MIME type object.
======================================================================
*/
function ins_db_mime_rec()
{ this.format = check_text_entry(this.format);
this.extension = check_text_entry(this.extension);
this.type = check_text_entry(this.type);
result = database.execute('INSERT INTO mimetypes (format, type, extension ) VALUES ("'+this.format+'","'
+ this.type
+'","'+this.extension
+'")' );
if (result != 0)
{write('
A Database error has occurred ' + result + '');
write('
' + database.majorErrorCode() + '');
write('
' + database.majorErrorMessage() + '');
request.mode="add"};
else
{write('The following MIME Type has been added.
');}
}
/*======================================================================
The del_db_mime_rec function deletes a single MIME type
from the database. This is a method of the MIME type object.
======================================================================
*/
function del_db_mime_rec()
{ get_count = database.cursor('SELECT * FROM file WHERE format="'+this.format+'"');
if (!get_count.next())
{
get_count.close();
result = database.execute('DELETE FROM mimetypes WHERE format="'+this.format+'"');
if (result != 0)
{write('
A Database error has occurred ' + result + '');
write('
' + database.majorErrorCode() + '');
write('
' + database.majorErrorMessage() + '');
request.mode="D"};
else
{write('MIME Type: '+this.type+' deleted.');
}
}
else
{get_count.close();
write('Unable to delete MIME Type: '+this.type+'
');
write('There are files still linked to this MIME Type!');
}
}
/*======================================================================
The upd_db_mime_rec function updates a single MIME type
in the database. This is a method of the MIME type object.
======================================================================
*/
function upd_db_mime_rec()
{ this.format = check_text_entry(this.format);
this.extension = check_text_entry(this.extension);
this.type = check_text_entry(this.type);
result = database.execute('UPDATE mimetypes SET type="'+ this.type
+'", extension="'+ this.extension
+'" WHERE format="'+this.format+'"');
if (result != 0)
{write('
A Database error has occurred ' + result + '');
write('
' + database.majorErrorCode() + '');
write('
' + database.majorErrorMessage() + '');
request.mode="add"};
else
{write('The following MIME Type has been updated.
');}
}
//MIME Type Object
function mime_rec(format, type, extension)
{ this.format = format;
this.type = type;
this.extension = extension;
this.ins_db_mime_rec = ins_db_mime_rec;
this.upd_db_mime_rec = upd_db_mime_rec;
this.get_db_mime_rec = get_db_mime_rec;
this.del_db_mime_rec = del_db_mime_rec;
}
/*======================================================================
The load_MIME_Tbl function creates the MIME type 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_MIME_Tbl()
{ if (request.mode == "insert")
{ temp_mime = new mime_rec(request.format, request.type, request.extension);
temp_mime.ins_db_mime_rec();
result = temp_mime.get_db_mime_rec();
}
if (request.mode == "add")
{ temp_mime = new mime_rec("","","");
result = true;
}
if (request.mode == "dump")
{ temp_mime = new mime_rec(request.format, request.type, request.extenstion);
temp_mime.del_db_mime_rec();
}
if ((request.mode == "M") || (request.mode == "D"))
{ temp_mime = new mime_rec(request.format,"","");
result = temp_mime.get_db_mime_rec();
}
if (request.mode == "update")
{ temp_mime = new mime_rec(request.format, request.type, request.extension);
temp_mime.upd_db_mime_rec();
result = temp_mime.get_db_mime_rec();
}
if ((request.mode != "dump") && (result))
{
write('');
displayRow("Format","RIGHT","TEXT","format",temp_mime.format, client.accesslevel, 30, 25, "V");
displayRow("Type","RIGHT","TEXT","type",temp_mime.type, client.accesslevel, 40, 30, "A");
displayRow("Extension","RIGHT","TEXT","extension",temp_mime.extension, client.accesslevel, 15, 7, "A");
write('
');
result = true;
}
else
{ result = false;
}
return result;
}
write('');
result = load_MIME_Tbl();
if (result)
{
write('');
if (request.mode == "add")
{