include "../admin/connect.phtml";
if (!$sid) {
$errors = "Sorry - required parameters not passed.";
}
else {
$sql = "select * from Sid where sid='$sid'";
$result = mysql($database, $sql);
$num = mysql_numrows($result);
if ($num == 0) {
$errors = "Sorry - invalid sid.";
}
else {
$companyID = mysql_result($result,0,"companyID");
$sql = "select * from Company where companyID=$companyID";
$result = mysql($database, $sql);
$num = mysql_numrows($result);
if ($num == 0) {
$errors = "Sorry - invalid companyID ($companyID).";
}
elseif (!$submit) {
$cityID = mysql_result($result,0,"cityID");
if ($cityID) {
$csql = "select * from City where cityID=$cityID";
$cresult = mysql($database, $csql);
$cnum = mysql_numrows($cresult);
$otherCity = mysql_result($cresult,0,"city");
$otherStateID = mysql_result($cresult,0,"stateID");
}
else {
$otherCity = mysql_result($result,0,"otherCity");
$otherStateID = mysql_result($result,0,"otherStateID");
}
$company = mysql_result($result,0,"company");
$address = mysql_result($result,0,"address");
$zip = mysql_result($result,0,"zip");
$phone = mysql_result($result,0,"phone");
$fax = mysql_result($result,0,"fax");
$email = mysql_result($result,0,"email");
$url = mysql_result($result,0,"url");
$login_password = mysql_result($result,0,"password");
$contactFirstName = mysql_result($result,0,"contactFirstName");
$contactLastName = mysql_result($result,0,"contactLastName");
$contactTitle = mysql_result($result,0,"contactTitle");
}
}
}
if ($submit) {
$tok = strtok ($required, ",");
while ($tok) {
if (!$$tok) {
$req[] = $tok;
$missing = 1;
}
$tok = strtok (",");
}
if ((!$otherStateID && !$otherCountryID) || ($otherStateID && $otherCountryID)) {
$req[] = "state OR country";
$missing = 1;
}
if ($missing) {
$errors = "The following fields are mandatory:\n \n
\n
\n";
$i=0;
while ($req[$i]) {
$errors = $errors + "
$req[$i]\n";
$i++;
}
$errors = $errors + "
\n
\n";
}
if ($email) {
$testemail = exec("../cgi-local/validateemail.cgi '$email'");
if (!$testemail) {
$errors = $errors + "Invalid email address format.\n";
}
}
if (!$errors) {
$now = Date("Y-m-d h:m:s");
/* if country code chosen, we know it's not USA or Canada, otherwise they would've chosen a state/province-country. */
/* so, we'll need to create a State record with a blank description and this country code (unless it already exists) */
if ($otherCountryID) {
$sql = "select stateID from State where state='' and countryID=$otherCountryID";
$result = mysql($database, $sql);
$num = mysql_numrows($result);
if ($num) {
$otherStateID = mysql_result($result,$i,"stateID");
}
else {
$sql = "insert into State values ('', '', '', $otherCountryID, '$now', '')";
$result = mysql($database, $sql);
$otherStateID = mysql_insert_id();
}
}
$sql = "update Company set company='$company', address='$address', cityID=0, otherCity='$otherCity', zip='$zip', otherStateID=$otherStateID, phone='$phone', fax='$fax', email='$email', url='$url', password='$login_password', contactFirstName='$contactFirstName', contactLastName='$contactLastName', contactTitle='$contactTitle', processed=0 where companyID=$companyID";
$result = mysql($database, $sql);
$seminarID = mysql_insert_id();
Header("Location: ./index.phtml?sid=$sid");
exit;
}
} # if ($submit)
$sql = "select stateID, state, country, State.countryID from State, Country where (State.countryID = Country.countryID) order by state, country";
$result = mysql($database, $sql);
$num = mysql_numrows($result);
$i=0;
while ($i<$num) {
if ($otherStateID == mysql_result($result,$i,"stateID")) {
if (mysql_result($result,$i,"state")) {
$states = "