OK I was given this script by a co-worker some time ago and we have kept adding to it and now we need so help with a few minor issues.
We are using this line to check the data entered into text field 'code1' against values in another table. It displays the error just fine but we have 4 code boxes in total to check, we need to display 'error code X invalid' for each but when we add this for the other boxes, using ELSE IF they work for errors but not SUCCESS! message. (Suspect a { or } somewhere is the issue just can't find which one)
We are writing the information into a CSV file as well (I know, not the best practise but we have a KEA! script that processes this into TELNET commands) we find that if multiple people post at same time, sometimes the data isn't written into the csv, I recently changed to using FLOCK but wonder if there is a better way to 'lock' access to file until a command is done.
==========================================================
if(!mysql_num_rows(mysql_query("SELECT code FROM sc_codes WHERE code = '$c1'"))){
if(isset($_REQUEST['submit'])) {
$system = $_REQUEST['SYSTEM'];
$from = $_REQUEST['EMAIL'];
$tech = $_REQUEST['TECH'];
$sc = $_REQUEST['CALLNUMBER'];
$c1 = $_REQUEST['CODE1'];
if(empty($tech) || empty($sc) || empty($c1) || strlen($sc) !=8 || !is_numeric($sc) || !is_numeric($c1) || strlen($c1) !=3) {
$message = "<font color=\"red\">CALL POST: FAILED! // INVALID POST! CHECK VALUES.</font><br>";
} else {
$c2 = $_REQUEST['CODE2'];
$c3 = $_REQUEST['CODE3'];
$c4 = $_REQUEST['CODE4'];
$t1 = $_REQUEST['TIME1'];
$t2 = $_REQUEST['TIME2'];
$ta = $s2 . $t2;
$f7 = $_REQUEST['ACCOUNT'];
$f8 = implode("-", (array)$NOTE);
$f9 = $_REQUEST['DISPATCH'];
$s1 = ' // ';
$s2 = ' - ';
$spins = $f7 . $s1 . $t1 . $ta . $f8 . $f9;
$nd = $_REQUEST['DROP'];
$ns = $_REQUEST['CBS'];
require_once 'login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to server: " . mysql_error());
mysql_select_db($db_database, $db_server)
or die("Unable to select database: " .mysql_error());
if(!mysql_num_rows(mysql_query("SELECT code FROM sc_codes WHERE code = '$c1'"))){
$message = "<font color=\"red\">CALL POST: FAILED! // INVALID CODE[1]</font><br>";
} else {
$query = "INSERT INTO post VALUES" .
"(NOW(), '$tech', '$sc', '$c1', '$c2', '$c3', '$c4', '$spins', '$nd', '$ns', '$system')";
if (!mysql_query($query, $db_server))
$message = "<font color=\"red\">CALL POST: FAILED! // ALREADY PREVIOUSLY POSTED.</font><br>";
$post = "\"$tech\",\"$sc\",\"\",\"$c1\",\"$c2\",\"$c3\",\"$c4\",\"$f9\",\"$nd\",\"$ns\"\r\n";
if(!file_exists("/home/systm/public_html/sjrb/posting/_store/101.csv")) {
//if file doesn't exist, create it and add headers.
$fp = fopen("/home/systm/public_html/sjrb/posting/_store/101.csv","a");
$headers = "\"TECH_NUMBER\",\"SERVICE_CALL_NUMBER\",\"ACCOUNT_NUMBER\",\"CODE_1\",\"CODE_2\",\"CODE_3\",\"CODE_4\",\"SPECIAL_INSTRUCTIONS\",\"DROP_NOTES\",\"CBS_NOTES\"\r\n";
fwrite($fp,$headers);
fwrite($fp,$post);
fclose($fp);
chmod("/home/systm/public_html/sjrb/posting/_store/101.csv", 0777);
} else {
$fp = fopen("/home/systm/public_html/sjrb/posting/_store/101.csv","a");
fwrite($fp,$post);
fclose($fp);
}
$message = "<font color=\"red\">CALL POST: SUCCESSFUL!</font><br>";
//send email
if(!empty($_REQUEST['ACCOUNT'])) {
$to = 'xxxxxx@xxxxxxx.com'.',xxxxxx@xxxxxxx.com';
//$to = 'ross.neufeld@sjrb.ca';
$subject = "$tech has submitted TSD Notes for Service Call: $sc";
$body = "";
$spins = preg_replace("/\s+/", " ", $spins);
$aspins = str_split($spins, 745);
$body .= sprintf("ACCOUNT: %-45s\r\n", $aspins[0]);
array_shift($aspins);
foreach($aspins as $a) {
$body .= sprintf(" %-45s\r\n", $a);
}
// To send HTML mail
<xxxxxx@xxxxx.com>\r\n";
$headers = 'From: '.$from."\r\n".
$headers = "MIME-Version: 1.0 \r\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$headers .= "X-Priority: 1 (Higuest) \r\n";
$headers .= "X-MSMail-Priority: High \r\n";
$headers .= "Importance: High \r\n";
mail($to,$subject, $body, $headers);
$message = "<font color=\"red\">CALL POST: SUCCESSFUL! // TSD NOTES SUBMITTED.</font><br>";
}
if(isset($_REQUEST['COACHING'])) {
header("Location: http://xxxxxxxx/coaching/index.php?tech=" . $_REQUEST['TECH'] . "&sc=" . $_REQUEST['CALLNUMBER'] . "&message=Service Call : Posted!");
}
}
}
}