/* ------- Open the dented database ------- */
$conn = mysql_connect ("localhost","apache","ansh");
if (!$conn) {
print "An error occurred in connection to sql server";
exit;
}
$conn = mysql_select_db("dented");
if (!$conn) {
print "An error occurred connecting to the dented database.\n";
exit;
}
/* ------------- Constants ---------------- */
$white = "#FFFFFF";
$yellow = "#FFFFCC";
$green = "#99FF99";
// $blue = "#000080";
$blue = "#0000a0";
$black = "#000000";
$red = "#800000";
$option["1"] = "Basic";
$option["2"] = "Visit";
$option["3"] = "Working group";
$option["4"] = "Global conference";
$option["5"] = "Other";
/* ----------- Functions ------------------ */
function errormsg($message) {
print $message;
mail("an@dental.tcd.ie","Dented Error: $message","");
return;
}
function html_start($title,$logo) {
global $white, $blue;
$fp = fopen("/www/dented/header1.html", "r");
$tmp = fread( $fp, 10000);
$tmp .= "$title
";
return $tmp;
}
function dread($table,$field,$where) {
// print $where;
$result = mysql_query("select $field from $table where $where");
// print "select $field from $table where $where";
if (mysql_num_rows($result) == 0) {
// print "Ikke fundet";
return NULL;
} else {
// print mysql_num_rows($result);
$data = mysql_fetch_array($result);
$felt = $data["$field"];
// print "Fundet $felt";
}
// print $felt;
return $felt;
}
function dwrite($table,$field,$data,$where) {
$result = mysql_query("update $table set $field=\"$data\" where $where");
if (!$result) {
errormsg("Error updating last login");
}
return;
}
function back($page) {
return "
";
}
/* ---------------------------------------- */
/* End of functions */
/* ---------------------------------------- */
if (!$function) {
$function = "list";
}
if ($cookie_id) {
$result = mysql_query("select * from visitors where visitor_id = \"$cookie_id\"");
if (mysql_num_rows($result)) {
$visitor = mysql_fetch_array($result);
if ($visitor["responsibility"] = "administrator") {
$may_edit = "Y";
} else {
$may_edit = "N";
}
} else {
// errormsg("Error in cookie information - visitor-id".$cookie_id);
exit;
}
} else {
$may_edit = "N";
}
//-----------Liste over dokumenter -------------
if ($function == "list") {
print html_start("List of resources (newest comes first)","yes");
// print "
$may_edit";
if ($may_edit == "Y") {
print "";
}
$i = 0;
$color = $yellow;
$result = mysql_query("select * from resources order by date desc");
if (!$result) {
print "Error extracting information about resources";
exit;
}
if (mysql_num_rows($result) > 0) {
// der er rækker
$heading = "Y";
while ($resources = mysql_fetch_array($result)) {
if ($i == 0) {
print "
| Area |
Heading |
Description |
Date |
| ";
if ($may_edit == "Y") {
print " | ";
}
print "
";
}
// mangler indsættelse af overskrifter
if ($heading == "Y") {
// tjek på type for skift af overskrift
} else {
// evt : print "|
// xxxxx-type---- |
";
}
$i = $i + 1;
if ($color == $yellow) {
$color = $white;
} else {
$color = $yellow;
}
print "";
print "| ".$resources["subject"]." | ";
print "".$resources["heading"]." | ";
print "".$resources["description"]." | ";
print "".$resources["date"]." | ";
if ($may_edit == "Y") {
print "Edit";
print " Remove | ";
}
print "
";
}
} else {
print "There are no resources in the database at this time";
}
print "
";
}
if ($function == "new") {
// tilføj ny record find den igen og sæt log_id og kald til edit
// oprette ny record og sætte visit_id til denne
$result = mysql_query("insert into resources (heading) values (\"New\")");
if (!$result) {
errormsg("Error creating new resource");
}
$result = mysql_query("select * from resources where heading = \"New\"");
if ($resources = mysql_fetch_array($result)) {
$id = $resources["id"];
$result = mysql_query("update resources set heading = \"\" where id = \"$id\"");
} else {
print "
Error removing new label from new resource
";
}
$function = "edit";
}
if ($function == "remove") {
$result = mysql_query("delete from resources where id = \"$id\"");
if (!$result) {
errormsg("Error removing resource from database");
}
print html_start("Resource database : List","logo");
print "Removing resource, please wait....
";
print back("./resources.php3?may_edit=Y");
}
if ($function == "edit") {
// opbyg formular og kald function=save med id
print html_start("Resources : Edit information","logo");
$result = mysql_query("select * from resources where id = \"$id\"");
$resources = mysql_fetch_array($result);
print "";
}
if ($function == "save") {
$date_s = date("Y-m-d");
print html_start("Resource database: Save information","logo");
$result = mysql_query("update resources set
heading = \"$heading\",
subject = \"$subject\",
url = \"$url\",
description = \"$description\",
important = \"$important\",
date = \"$date_s\"
where id=\"$id\"");
print "Saving information, please wait...
";
if ($may_edit) {
print back("./resources.php3?may_edit=Y");
} else {
print back("./resources.php3");
}
}
?>