| 1 |
# Copyright (C) 2001 Craig Small <csmall@debian.org>
|
| 2 |
# Copyright (C) 2001, 2002, 2003, 2004, 2005 Martin Michlmayr <tbm@cyrius.com>
|
| 3 |
# This file may be distributed under the GPL v2 or higher.
|
| 4 |
|
| 5 |
<?
|
| 6 |
session_start();
|
| 7 |
include("config.inc");
|
| 8 |
include("common.inc");
|
| 9 |
|
| 10 |
function find_user($db, $email) {
|
| 11 |
$sql = "SELECT * FROM applicant WHERE email = '$email'";
|
| 12 |
if (! ($result = pg_exec($db, $sql))) {
|
| 13 |
echo "Problem with query", pg_ErrorMessage($db), "<BR>";
|
| 14 |
return TRUE;
|
| 15 |
}
|
| 16 |
if (pg_NumRows($result) == 0) {
|
| 17 |
return FALSE;
|
| 18 |
}
|
| 19 |
return TRUE;
|
| 20 |
}
|
| 21 |
|
| 22 |
function update_db($db, $sql) {
|
| 23 |
if (! ($result = pg_exec($db, $sql))) {
|
| 24 |
echo "Problem with query", pg_ErrorMessage($db), "<BR>";
|
| 25 |
return -1;
|
| 26 |
}
|
| 27 |
if (($tuples = pg_CmdTuples($result)) != 1) {
|
| 28 |
echo "Only one row should be effected but $tuples rows were<BR>\n";
|
| 29 |
}
|
| 30 |
return $tuples;
|
| 31 |
}
|
| 32 |
function get_text($name, $value)
|
| 33 |
{
|
| 34 |
if ($value == "" ) {
|
| 35 |
$str = " null ";
|
| 36 |
} else {
|
| 37 |
$str = "'" . $value . "'";
|
| 38 |
}
|
| 39 |
return $str;
|
| 40 |
}
|
| 41 |
function get_bool($name, $value)
|
| 42 |
{
|
| 43 |
if ($value == 't')
|
| 44 |
{
|
| 45 |
$str = $name . "= true ";
|
| 46 |
} else if ($value == 'f') {
|
| 47 |
$str = $name . " = false ";
|
| 48 |
} else {
|
| 49 |
$str = $name . " = null ";
|
| 50 |
}
|
| 51 |
return $str;
|
| 52 |
}
|
| 53 |
?>
|
| 54 |
#use wml::nmpage title="Debian New Maintainer - New Applicant"
|
| 55 |
<?
|
| 56 |
if (!session_is_registered("s_username") || !session_is_registered("s_isam")
|
| 57 |
|| !session_is_registered("s_isfd")) {
|
| 58 |
?>
|
| 59 |
<STRONG>
|
| 60 |
You should not be here!</STRONG>
|
| 61 |
<? } else {
|
| 62 |
session_register("s_username");
|
| 63 |
session_register("s_isfd");
|
| 64 |
session_register("s_isdam");
|
| 65 |
?>
|
| 66 |
<?
|
| 67 |
|
| 68 |
if ($_SESSION['s_isfd'] == 't') {
|
| 69 |
if ( ($db = open_db())) {
|
| 70 |
# Check ze values, any bad things we abort
|
| 71 |
$errors = "";
|
| 72 |
$forename = trim(strip_tags(_REQUEST['forename'];
|
| 73 |
$surname = trim(strip_tags(_REQUEST['surname'];
|
| 74 |
$apply_date = trim(strip_tags(_REQUEST['apply_date'];
|
| 75 |
$email = trim(strip_tags(_REQUEST['email'];
|
| 76 |
$manager = trim(strip_tags(_REQUEST['manager'];
|
| 77 |
$manager_date = trim(strip_tags(_REQUEST['manager_date'];
|
| 78 |
if ($forename == "") { $errors .= "<LI>You must have a first name entered.\n"; }
|
| 79 |
if ($surname == "") { $errors .= "<LI>You must have a surname entered.\n"; }
|
| 80 |
if ($apply_date == "") { $errors .= "<LI>You must have a date of application.\n"; }
|
| 81 |
if ($email == "") { $errors .= "<LI>You must have an email address entered.\n"; }
|
| 82 |
if ($manager != "" && $manager_date == "")
|
| 83 |
{ $errors .= "<LI>A manager has been assigned but with no date.\n"; }
|
| 84 |
if ($manager == "" && $manager_date != "")
|
| 85 |
{ $errors .= "<LI>A manager has not been assigned but there is a manager assigned date.\n"; }
|
| 86 |
if (($errors == "") && (find_user($db, $email))) { $errors .= "<LI>The user's email addres already exists in the database.\n"; }
|
| 87 |
# Possibly more checks later
|
| 88 |
if ($errors != "")
|
| 89 |
{
|
| 90 |
echo "<P>There have been some problems with what you entered, please hit ",
|
| 91 |
"the back button and correct the following errors:",
|
| 92 |
"<UL>$errors</UL>\n";
|
| 93 |
} else {
|
| 94 |
echo "<P>Submission has passed sanity checks.<BR>\n";
|
| 95 |
$sql = "INSERT INTO applicant" .
|
| 96 |
"(forename, surname, email, apply_date, manager, manager_date) VALUES (" .
|
| 97 |
"'$forename', '$surname', '$email', '$apply_date' " .
|
| 98 |
", " . get_text("manager", $manager) .
|
| 99 |
", " . get_text("manager_date", $manager_date) . ")";
|
| 100 |
if (($erows = update_db($db, $sql)) > 0)
|
| 101 |
{
|
| 102 |
echo "<P>$erows rows updated in database.<BR>\n";
|
| 103 |
}
|
| 104 |
}
|
| 105 |
} # DB ok
|
| 106 |
} else {
|
| 107 |
?>
|
| 108 |
You shoulnt be here
|
| 109 |
<? } } ?>
|