More work on flags

This commit is contained in:
2026-02-17 14:43:46 -05:00
parent 35173f6faa
commit 63bb7a3445
3 changed files with 54 additions and 77 deletions

View File

@@ -176,10 +176,10 @@ if ($mfadd) {
$newmaintformid=mysqli_insert_id($db); $newmaintformid=mysqli_insert_id($db);
$mfidtoprint=$newmaintformid; $mfidtoprint=$newmaintformid;
// add this maintformid to the appropriate flag_tables // update the flagmap table
foreach ($flags as $flagtblnum) { foreach ($flags as $thisflag) {
$flagtblname="flag_".$flagtblnum; // set flag for this maintenance form
mysqli_query($db,"insert into $flagtblname(target,id) values(\"maintforms\",\"$newmaintformid\")"); mysqli_query($db,"insert into flagmap(flagid,maintformid) values(\"$thisflag\",\"$$newmaintformid\")");
} }
} }
} }
@@ -209,20 +209,12 @@ if ($mfedit) {
if (! $pdatamismatch) { if (! $pdatamismatch) {
mysqli_query($db,"update maintforms set mfdate=\"$mfdate\", mftime=\"$mftime\", mfpart=\"$mfpart\", mfpartloc=\"$mfpartloc\", mysqli_query($db,"update maintforms set mfdate=\"$mfdate\", mftime=\"$mftime\", mfpart=\"$mfpart\", mfpartloc=\"$mfpartloc\",
mfmalfunction=\"$mfmalfunction\", nha=\"$nha\", repord=\"$repord\", lognoteid=\"$lognoteid\", pending=\"$pending\" where maintformid=\"$maintformid\""); mfmalfunction=\"$mfmalfunction\", nha=\"$nha\", repord=\"$repord\", lognoteid=\"$lognoteid\", pending=\"$pending\" where maintformid=\"$maintformid\"");
// update the appropriate flag_tables
$flagids=mysqli_query($db,"select flagid from flags"); // update the flagmap table
while ($thisflagid=mysqli_fetch_row($flagids)) { mysqli_query($db,"delete from flagmap where maintformid=\"$maintformid\"");
$thisflag_tbl="flag_".$thisflagid[0]; foreach ($flags as $thisflag) {
if ($flags[0]=="") $flags=[]; // set flag for this maintenance form
if (in_array($thisflagid[0],$flags)) { mysqli_query($db,"insert into flagmap(flagid,maintformid) values(\"$thisflag\",\"$$maintformid\")");
if(!mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"maintforms\" and id=\"$maintformid\""))) {
mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"maintforms\",\"$maintformid\")");
}
} else {
if(mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"maintforms\" and id=\"$maintformid\""))) {
mysqli_query($db,"delete from $thisflag_tbl where target=\"maintforms\" and id=\"$maintformid\"");
}
}
} }
} }
} }
@@ -233,12 +225,8 @@ if ($mfedit) {
if ($mfdelete && $mfauthorized) { if ($mfdelete && $mfauthorized) {
// delete from maintforms table // delete from maintforms table
mysqli_query($db,"delete from maintforms where maintformid=\"$maintformid\""); mysqli_query($db,"delete from maintforms where maintformid=\"$maintformid\"");
// delete occurances from the flag_ tables // delete occurances from the flagmap table
$flagids=mysqli_query($db,"select flagid from flags"); mysqli_query($db,"delete from flagmap where maintformid=\"$maintformid\"");
while ($thisflagid=mysqli_fetch_row($flagids)) {
$delflag_tbl="flag_".$thisflagid[0];
mysqli_query($db,"delete from $delflag_tbl where target=\"maintforms\" and id=\"$maintformid\"");
}
} }
if ($actionadd) { if ($actionadd) {
@@ -384,22 +372,33 @@ if ($printfmt) {
<b><u>Flags</u></b><br> <b><u>Flags</u></b><br>
<table width=\"100%\" border=\"0\"> <table width=\"100%\" border=\"0\">
"; ";
// get an array of flagids set for this maintformid
$allflags=mysqli_query($db,"select flagid from flags");
unset($theseflags);
while ($thisflag=mysqli_fetch_row($allflags)) {
$thisflagtbl="flag_".$thisflag[0];
if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"maintforms\" and id=\"$maintformid\""))) {
$theseflags[]=$thisflag[0];
}
}
$flagslist=mysqli_query($db,"select * from flags");
while ($flagsymbol=mysqli_fetch_assoc($flagslist)) {
if ($theseflags[0]=="") $theseflags=[]; // // get an array of flagids set for this maintformid
if (in_array($flagsymbol["flagid"],$theseflags)) { // $allflags=mysqli_query($db,"select flagid from flags");
echo $flagsymbol['flagsym']."&nbsp;&nbsp;"; // unset($theseflags);
} // while ($thisflag=mysqli_fetch_row($allflags)) {
} // $thisflagtbl="flag_".$thisflag[0];
// if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"maintforms\" and id=\"$maintformid\""))) {
// $theseflags[]=$thisflag[0];
// }
// }
// $flagslist=mysqli_query($db,"select * from flags");
// while ($flagsymbol=mysqli_fetch_assoc($flagslist)) {
// if ($theseflags[0]=="") $theseflags=[];
// if (in_array($flagsymbol["flagid"],$theseflags)) {
// echo $flagsymbol['flagsym']."&nbsp;&nbsp;";
// }
// }
echo " echo "
</table><hr> </table><hr>
<b><u>Maintenance Actions</u></b><br> <b><u>Maintenance Actions</u></b><br>

View File

@@ -70,18 +70,6 @@ while($mptr<count($master)) {
} }
} }
//$allflagqry=mysqli_query($db,"select flagid from flags");
//while ($allflagids=mysqli_fetch_row($allflagqry)) {
//$flagid=$allflagids[0];
//$flag_tbl="flag_".$flagid;
//if (mysqli_num_rows(mysqli_query($db,"select id from $flag_tbl where target=\"lognotes\" and id=\"$noteid\""))) {
//$flagparam=mysqli_fetch_assoc(mysqli_query($db,"select * from flags where flagid=\"$flagid\""));
//$flagcolor=$flagparam["flagcolor"];
//$flagsym=$flagparam["flagsym"];
//$flagstring=$flagstring."<font color=\"$flagcolor\">$flagsym</font>&nbsp;&nbsp;";
//}
//}
if ($flagstring) $fmtnote=$fmtnote."<br>".$flagstring; if ($flagstring) $fmtnote=$fmtnote."<br>".$flagstring;
printf(" printf("
<tr> <tr>

View File

@@ -54,7 +54,9 @@ if ($print) {
framework("begin","$logname Search","Search",$print); framework("begin","$logname Search","Search",$print);
//var_dump($_REQUEST); // echo "REQUEST variables: <br>";
// var_dump($_REQUEST);
// ******** begin database manipulation ******** // ******** begin database manipulation ********
@@ -199,24 +201,9 @@ if ($search) {
$logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; $logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\"";
} }
// build the clauses and run the query // build the clauses and run the query
echo "logfromtables: ";
foreach ($logfromtables as $lft) {
echo "$lft&nbsp;";
}
echo "<br><br>";
echo "logconstraints: ";
foreach ($logconstraints as $lc) {
echo "$lc&nbsp;";
}
echo "<br><br>";
$logfromclause=implode(",",array_unique($logfromtables)); $logfromclause=implode(",",array_unique($logfromtables));
echo "logfromclause: $logfromclause <br><br>";
$logwhereclause=implode(" and ",$logconstraints); $logwhereclause=implode(" and ",$logconstraints);
echo "logwhereclause: $logwhereclause <br><br>";
$logrowqry=mysqli_query($db,"select lognotes.* from $logfromclause where $logwhereclause order by lognotes.date asc, lognotes.time asc"); $logrowqry=mysqli_query($db,"select lognotes.* from $logfromclause where $logwhereclause order by lognotes.date asc, lognotes.time asc");
echo "select lognotes.* from $logfromclause where $logwhereclause order by lognotes.date asc, lognotes.time asc";
} }
if ($target[0]=="") $target=[]; if ($target[0]=="") $target=[];
if (in_array("maintform",$target)) { if (in_array("maintform",$target)) {
@@ -268,15 +255,15 @@ if ($search) {
$mffromtables[]="maintforms"; $mffromtables[]="maintforms";
$mffromtables[]="flagmap"; $mffromtables[]="flagmap";
$flagconstraints[]="flagmap.maintformid=maintforms.maintformid and flagmap.flagid in ("; $flagconstraints[]="flagmap.maintformid=maintforms.maintformid and flagmap.flagid in (";
foreach ($srchflags as $flagid) { foreach ($srchflags as $thisflagid) {
$flagconstraints[]="\"$flagid\""; $flagconstraints[]="\"$thisflagid\"";
$flagconstraints[]=","; $flagconstraints[]=",";
} }
// remove final comma // remove final comma
array_splice($flagconstraints, -1, 1); array_splice($flagconstraints, -1, 1);
$flagconstraints[]=") group by flagmap.maintformid having count(distinct flagmap.flagid)=$flagcount"; $flagconstraints[]=") group by flagmap.maintformid having count(distinct flagmap.flagid)=$flagcount";
// make flagconstraints a single string so that the final implode doesn't split it // make flagconstraints a single string so that the final implode doesn't split it
$logconstraints[]=join('', $flagconstraints); $mfconstraints[]=join('', $flagconstraints);
} }
// uid // uid
if ($srchuid != "any" && $srchuid != "") { if ($srchuid != "any" && $srchuid != "") {
@@ -687,9 +674,10 @@ if ($search) {
if ($target[0]=="") $target=[]; if ($target[0]=="") $target=[];
if (in_array("log",$target)) { if (in_array("log",$target)) {
// run lognotes query and show results // run lognotes query and show results
if(mysqli_num_rows($logrowqry)) { $log_num_results=mysqli_num_rows($logrowqry);
if($log_num_results) {
echo " echo "
<b>Results from Logbook</b><br><br> <b>Results from Logbook: $log_num_results</b><br><br>
<table border=\"1\" width=\"100%\"> <table border=\"1\" width=\"100%\">
<tr><th>Note ID</th><th>Date/Time</th><th>Shift</th><th>Tech</th><th>Subject</th><th>Note</th><th>References</th></tr> <tr><th>Note ID</th><th>Date/Time</th><th>Shift</th><th>Tech</th><th>Subject</th><th>Note</th><th>References</th></tr>
"; ";
@@ -748,9 +736,10 @@ if ($search) {
if ($target[0]=="") $target=[]; if ($target[0]=="") $target=[];
if (in_array("maintform",$target)) { if (in_array("maintform",$target)) {
// run maintforms query and show results // run maintforms query and show results
if(mysqli_num_rows($mfrowqry)) { $mf_num_results=mysqli_num_rows($mfrowqry);
if($mf_num_results) {
echo " echo "
<b>Results from Maintenance Forms</b><br><br> <b>Results from Maintenance Forms: $mf_num_results</b><br><br>
<br><table border=\"1\" width=\"100%\"> <br><table border=\"1\" width=\"100%\">
<tr> <tr>
<th>ID</th> <th>ID</th>
@@ -811,9 +800,10 @@ if ($search) {
if ($target[0]=="") $target=[]; if ($target[0]=="") $target=[];
if (in_array("part",$target)) { if (in_array("part",$target)) {
// run parts query and show results // run parts query and show results
if(mysqli_num_rows($prowqry)) { $p_num_results=mysqli_num_rows($prowqry);
if($p_num_results) {
echo " echo "
<b>Results from Parts</b><br><br> <b>Results from Parts: $p_num_results</b><br><br>
<table width=\"100%\" border=\"1\" cellpadding=\"5\"> <table width=\"100%\" border=\"1\" cellpadding=\"5\">
<tr> <tr>
<th>Action</th> <th>Action</th>