session_start();
include("config.inc");
include("common.inc");
function email_manager($db, $login, $forename, $surname, $aemail) {
$sql = "SELECT * FROM manager WHERE login = '$login'";
if (! ($result = pg_exec($db, $sql))) {
echo "Problem with query: ", pg_ErrorMessage($db), "
";
echo "SQL was: $sql
\n";
return FALSE;
}
if (pg_NumRows($result) == 0) {
echo "Cannot find mananger in database.
\n";
echo "SQL was: $sql
\n";
return FALSE;
}
$row = pg_Fetch_Array($result, 0);
$body = "Hello " . $row["name"] . ",\n";
$body .= "This is an automatic message from the New Maintainer website found at\n";
$body .= "http://nm.debian.org/ The Front Desk has assigned a new applicant to you:\n";
$body .= "$forename $surname <" . $aemail . ">. Please remember to visit the\n";
$body .= "website to inform the front desk wether or not you accept this applicant.\n\n";
$body .= " - New Maintainer Website.\n";
$headers = "From: new-maintainer@debian.org\nReply-To: $forename $surname <" . $aemail . ">\nX-Mailer: PHP/" . phpversion();
mail($row["email"], "New Debian Maintainer: $aemail", $body, $headers);
return TRUE;
}
function check_manager($db, $manager, $aemail)
{
$sql = "SELECT * FROM applicant WHERE email ='$aemail'";
if (! ($result = pg_exec($db, $sql))) {
echo "Problem with query: ", pg_ErrorMessage($db), "
";
echo "SQL was: $sql
\n";
return FALSE;
}
if (pg_NumRows($result) == 0) {
echo "Could not find applicant $aemail in the database.
\n";
echo "SQL was: $sql
\n";
return FALSE;
}
$row = pg_Fetch_Array($result, 0);
if (trim($row["manager"]) != $manager) {
if ($manager != "") {
echo "
Old manager was '", $row["manager"], "' new one is '$manager'. Emailling new manager.\n"; return (email_manager($db, $manager, $row['forename'], $row['surname'],$aemail)); } else { echo "
Old manager was '", $row["manager"], "' new one is blank.\n";
return TRUE;
}
}
return TRUE;
} #check manager
function find_manager($db, $login) {
$sql = "SELECT * FROM manager WHERE login = '$login'";
if (! ($result = pg_exec($db, $sql))) {
echo "Problem with query", pg_ErrorMessage($db), "
";
return TRUE;
}
if (pg_NumRows($result) == 0) {
return FALSE;
}
return TRUE;
}
function update_db($db, $sql) {
if (! ($result = pg_exec($db, $sql))) {
echo "Problem with query", pg_ErrorMessage($db), "
";
return -1;
}
if (($tuples = pg_CmdTuples($result)) != 1) {
echo "Only one row should be effected but $tuple rows were
\n";
}
return $tuples;
}
function get_text($name, $value)
{
if ($value == "" ) {
$str = $name . "= null";
} else {
$str = $name . "='" . trim(strip_tags($value)) . "'";
}
return $str;
}
function get_bool($name, $value)
{
if ($value == 't')
{
$str = $name . "= true ";
} else if ($value == 'f') {
$str = $name . " = false ";
} else {
$str = $name . " = null ";
}
return $str;
}
function get_textarea($name, $value)
{
if ($value == "" ) {
$str = $name . "= null";
} else {
$str = $name . "='" . trim(strip_tags($value)) . "'";
}
return $str;
}
?>
#use wml::nmpage title="Debian New Maintainer - Applicant Status Update"
if (!session_is_registered("s_username") || !session_is_registered("s_isam")) {
?>
You should not be here!!
} else {
session_register("s_username");
session_register("s_isfd");
session_register("s_isdam");
?>
There have been some problems with what you entered, please hit ", "the back button and correct the following errors:", "
Submission has passed sanity checks.
\n";
$sql = "UPDATE applicant SET ";
if ($s_isdam == 't' || $s_isfd == 't') {
$sql .= get_text("surname", $surname) .
", " . get_text("email", $email) .
", " . get_text("forename", $forename) .
", " . get_text("apply_date", $apply_date) .
", " . get_text("manager", $manager) .
", " . get_text("manager_date", $manager_date) . ", ";
}
$sql .= get_bool("am_confirm", $am_confirm) .
", " . get_text("am_confirm_date", $am_confirm_date) .
", " . get_text("am_contact", $am_contact) .
", " . get_bool("id_ok", $id_ok) .
", " . get_text("id_checked", $id_checked) .
", " . get_bool("pnp_ok", $pnp_ok) .
", " . get_text("pnp_checked", $pnp_checked) .
", " . get_bool("tns_ok", $tns_ok) .
", " . get_text("tns_checked", $tns_checked) .
", " . get_bool("approved", $approved) .
", " . get_text("decision", $decision) .
", " . get_textarea("man_comment", $man_comment) ;
if ($s_isdam == 't') {
$sql .= ", " . get_bool("application_ok", $application_ok) .
", " . get_bool("da_phone_required", $da_phone_required) .
", " . get_text("da_phone", $da_phone) .
", " . get_bool("da_approved", $da_approved) .
", " . get_text("newmaint", $newmaint) .
", " . get_textarea("da_comment", $da_comment) ;
}
$sql .= " WHERE email = '$emailkey'";
if ($s_isfd == 't') {
if (!(check_manager($db, trim($manager), $email))) {
echo "
Problem emailling manager.\n"; } } if (($erows = update_db($db, $sql)) > 0) { echo "
$erows rows updated in database.
\n";
}
}
?>
} #open database ?>
} #session management ?>