ppeasy/public/inserttrf.php

135 lines
5.1 KiB
PHP

<?php
include('include/headscript.php'); ?>
<?php
// pickup the get variable
if (isset($_GET["idcertificate"])) {
$certtype=$_GET["idcertificate"];
$idcertificate=$certtype;
}
if (isset($_GET["tempcode"])) {
$tempcode=$_GET["tempcode"]; }
if (isset($_GET["previousrepnumber"])) {
$previousrepnumber=$_GET["previousrepnumber"]; }
else {
$previousrepnumber=""; }
if (isset($_GET["idtrf"])) {
$idtrf=$_GET["idtrf"]; }
if (isset($_GET["issuebycimac"])) {
$issuebycimac=$_GET["issuebycimac"]; }
else {
$issuebycimac=""; }
if (isset($_GET["samplestore"])) {
$samplestore=$_GET["samplestore"]; }
else {
$samplestore=""; }
if (isset($_GET["notificatedorganismname"])) {
$notificatedorganismname=$_GET["notificatedorganismname"]; }
else {
$notificatedorganismname=""; }
if ($certtype==7) {
$certtype=1;
$idcertificate=1;
}
?>
<?php
//calculate next trf number available
$lasttrfnumber = new WA_MySQLi_RS("lasttrfnumber",$cmctrfdb,1);
$lasttrfnumber->setQuery("SELECT * FROM `trf-details` ORDER BY `trf-details`.trfnumber DESC LIMIT 1");
$lasttrfnumber->execute();?>
<?php
$lastnumber=$lasttrfnumber->getColumnVal("trfnumber");
$nextnumber=$lastnumber+1;
?>
<?php
if (!isset($_GET["idtrf"])) {
//check if the tempcode already exist
$tempcodesearch = new WA_MySQLi_RS("tempcodesearch",$cmctrfdb,1);
$tempcodesearch->setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.tempcode='$tempcode'");
$tempcodesearch->execute();
}
?>
<?php
// insert the new TRF into the table
if (!isset($_GET["idtrf"])) {
if (empty($tempcodesearch->getColumnVal("idtrfdetails"))) {
$dateintrf=date('Y-m-d');
$cother=$_SESSION["certotherclientsession"];
$InsertQuery = new WA_MySQLi_Query($cmctrfdb);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`trf-details`";
$InsertQuery->bindColumn("trfnumber", "i", "$nextnumber", "WA_DEFAULT");
$InsertQuery->bindColumn("idcompany", "i", "$idcompany", "WA_DEFAULT");
$InsertQuery->bindColumn("iduser", "i", "$iduserlogin", "WA_DEFAULT");
$InsertQuery->bindColumn("idcertification", "i", "$certtype", "WA_DEFAULT");
$InsertQuery->bindColumn("previousreportnumber", "s", "$previousrepnumber", "WA_DEFAULT");
$InsertQuery->bindColumn("tempcode", "s", "$tempcode", "WA_DEFAULT");
$InsertQuery->bindColumn("notificatedorganismname", "s", "$notificatedorganismname", "WA_DEFAULT");
$InsertQuery->bindColumn("dateintrf", "s", "$dateintrf", "WA_DEFAULT");
$InsertQuery->bindColumn("otherclient", "s", "$cother", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
$InsertQuery->redirect($InsertGoTo);
$tempcodesearch2 = new WA_MySQLi_RS("tempcodesearch",$cmctrfdb,1);
$tempcodesearch2->setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.tempcode='$tempcode'");
$tempcodesearch2->execute();
$idtrf=$tempcodesearch2->getColumnVal("idtrfdetails");
$code="1";
$InsertQuery = new WA_MySQLi_Query($cmctrfdb);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "wheretrfstep";
$InsertQuery->bindColumn("idtrf", "i", "$idtrf", "WA_DEFAULT");
$InsertQuery->bindColumn("code", "i", "$code", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
$InsertQuery->redirect($InsertGoTo);
$code="2";
$InsertQuery = new WA_MySQLi_Query($cmctrfdb);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "wheretrfstep";
$InsertQuery->bindColumn("idtrf", "i", "$idtrf", "WA_DEFAULT");
$InsertQuery->bindColumn("code", "i", "$code", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
$InsertQuery->redirect($InsertGoTo);
}}
?>
<?php
if (!isset($_GET["idtrf"])) {
$trfnumberfinal = new WA_MySQLi_RS("trfnumberfinal",$cmctrfdb,1);
$trfnumberfinal->setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.tempcode='$tempcode'");
$trfnumberfinal->execute();
$idtrf=$trfnumberfinal->getColumnVal("idtrfdetails");
$idcertn=$trfnumberfinal->getColumnVal("idcertification");
} else {
$trfnumberfinal = new WA_MySQLi_RS("trfnumberfinal",$cmctrfdb,1);
$trfnumberfinal->setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.idtrfdetails='$idtrf'");
$trfnumberfinal->execute();
$idcertn=$trfnumberfinal->getColumnVal("idcertification");
}
?>
<?php //redirect based on certificate
if ($idcertificate==1) { header("location: trfdetails.php?idcertificate=$idcertificate&idtrf=$idtrf"); }
if ($idcertificate==2) { header("location: typeofcertificate2.php?certtype=$idcertificate&idtrf=$idtrf"); }
if ($idcertificate==3 || $idcertificate==8) { header("location: typeofcertificate3.php?idcertificate=$idcertificate&idtrf=$idtrf"); }
if ($idcertificate==4) { header("location: typeofcertificate4.php?idcertificate=$idcertificate&idtrf=$idtrf"); }
if ($idcertificate==5) { header("location: typeofcertificate5.php?idcertificate=$idcertificate&idtrf=$idtrf"); }
if ($idcertificate==6) { header("location: typeofcertificate6.php?idcertificate=$idcertificate&idtrf=$idtrf"); }
if ($idcertificate==7) { header("location: typeofcertificate7.php?idcertificate=$idcertificate&idtrf=$idtrf"); }
?>