Files
OpenLog/distfiles/refchain.php

106 lines
3.7 KiB
PHP

<?php
/*
refchain.php
OpenLog Online Logbook
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("functions.php");
$print = $_REQUEST['print'] ?? "";
$chainnote = $_REQUEST['chainnote'] ?? NULL;
$logname = LOG_NAME;
if ($print) {
$sbcolor = P_SIDEBAR_COLOR;
$mbgcolor = P_MENUBG_COLOR;
} else {
$sbcolor = SIDEBAR_COLOR;
$mbgcolor = MENUBG_COLOR;
}
framework("begin", "$logname", "Reference Chain Display", $print);
// ******** begin database manipulation ********
$master = generate_chain($chainnote);
// ******** end database manipulation ********
pagetable("begin");
if (!$print) {
pageblock("left", "begin");
sidemenu();
pageblock("left", "end");
}
pageblock("right", "begin");
banner($print);
// display the chain
$mptr = 0;
echo "<br><br><table border=\"1\" width=\"100%\">";
echo "<tr><th>Note ID</th><th>Date &#47; Time</th><th>Shift</th><th>Tech</th><th>Subject</th><th>Note</th><th>References</th></tr>";
while ($mptr < count($master)) {
if (mysqli_num_rows(mysqli_query($db, "select * from lognotes where lognoteid=$master[$mptr]"))) {
$tablerow = mysqli_fetch_assoc(mysqli_query($db, "select * from lognotes where lognoteid=$master[$mptr]"));
$noteid = $tablerow["lognoteid"];
$urldatestr = "y=" . date("Y", strtotime($tablerow["date"])) . "&m=" . date("m", strtotime($tablerow["date"])) . "&d=" . date("d", strtotime($tablerow["date"]));
$refs = "&nbsp;&nbsp;<a href=\"logentry.php?add=1&refto=$noteid\"><img src=\"icons/plus.png\" border=\"0\" alt=\"Add referring note\" title=\"Add referring note\"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"lognotes.php?$urldatestr\" title=\"View note in log\"><img src=\"icons/magnifier--arrow.png\"></a>";
// convert the shift number to a name
$shname = dblookup($db, "shifts", "shiftid", "shiftname", $tablerow["shift"]);
// convert tech number to name
$tname = dblookup($db, "techs", "techid", "techname", $tablerow["tech"]);
//convert subject number to name
$subjname = dblookup($db, "subjects", "subjectid", "subjectname", $tablerow["subject"]);
// create links of urls in note
$fmtnote = convertweblinks($tablerow["lognote"]);
// generate the flags string
$flagstring = "";
$flagmapqry = mysqli_query($db, "select flagid from flagmap where lognoteid=$noteid");
if (mysqli_num_rows($flagmapqry)) {
while ($flagids = mysqli_fetch_row($flagmapqry)) {
$flagid = $flagids[0];
$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;
printf(
"
<tr>
<td><a href=\"logentry.php?edit=1&noteid=%s\">%s</a></td>
<td>%s &#47; %s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>",
$tablerow["lognoteid"],
$tablerow["lognoteid"],
$tablerow["date"],
$tablerow["time"],
$shname,
$tname,
$subjname,
$fmtnote,
$refs
);
} else {
printf("<tr><td colspan=\"7\"><font color=\"red\">Note Id <b> %s</b> has been deleted and cannot be displayed.</font></td></tr>\n", $master[$mptr]);
}
$mptr = $mptr + 1;
}
echo "</table><br><br>";
banner($print);
pageblock("right", "end");
pagetable("end");
framework("end", "", "", $print);