Various reformats. Changed boolean variables from 1/0 to TRUE/FALSE in multiple files.

This commit is contained in:
2026-02-19 14:08:40 -05:00
parent 9122040863
commit 01fd47814b
22 changed files with 3502 additions and 3150 deletions

View File

@@ -10,72 +10,73 @@
include("functions.php");
if (!$_SESSION['login'] && !$_REQUEST['partview']) {
header ("Location: login.php");
header("Location: login.php");
}
$techid=$_SESSION['login'] ?? NULL;
$isadmin=dblookup($db,"techs","techid","admin",$techid);
$print=$_REQUEST['print'] ?? NULL;
$efftechid=$_REQUEST['efftechid'] ?? NULL;
$shift=$_REQUEST['shift'] ?? NULL;
$subject=$_REQUEST['subject'] ?? NULL;
$note=$_REQUEST['note'] ?? NULL;
$flags=$_POST['flags'] ?? [];
$refstring=$_REQUEST['refstring'] ?? NULL;
$submit=$_REQUEST['submit'] ?? NULL;
$operation=$_REQUEST['operation'] ?? NULL;
$templateid=$_REQUEST['templateid'] ?? NULL;
$templatename=$_REQUEST['templatename'] ?? NULL;
$usertemplateid=$_REQUEST['usertemplateid'] ?? NULL;
$globaltemplateid=$_REQUEST['globaltemplateid'] ?? NULL;
$loadtemplate=$_REQUEST['loadtemplate'] ?? NULL;
$techid = $_SESSION['login'] ?? NULL;
$isadmin = dblookup($db, "techs", "techid", "admin", $techid);
$print = $_REQUEST['print'] ?? NULL;
$efftechid = $_REQUEST['efftechid'] ?? NULL;
$shift = $_REQUEST['shift'] ?? NULL;
$subject = $_REQUEST['subject'] ?? NULL;
$note = $_REQUEST['note'] ?? NULL;
$flags = $_POST['flags'] ?? [];
$refstring = $_REQUEST['refstring'] ?? NULL;
$submit = $_REQUEST['submit'] ?? NULL;
$operation = $_REQUEST['operation'] ?? NULL;
$templateid = $_REQUEST['templateid'] ?? NULL;
$templatename = $_REQUEST['templatename'] ?? NULL;
$usertemplateid = $_REQUEST['usertemplateid'] ?? NULL;
$globaltemplateid = $_REQUEST['globaltemplateid'] ?? NULL;
$loadtemplate = $_REQUEST['loadtemplate'] ?? NULL;
$logname=LOG_NAME;
$techalpha=TECH_ALPHA;
$subjalpha=SUBJ_ALPHA;
$logname = LOG_NAME;
$techalpha = TECH_ALPHA;
$subjalpha = SUBJ_ALPHA;
$defaultshift=dblookup($db,"techs","techid","shift",$techid);
$defaultshift = dblookup($db, "techs", "techid", "shift", $techid);
if ($print=="Printer Friendly") {
$sbcolor=P_SIDEBAR_COLOR;
$mbgcolor=P_MENUBG_COLOR;
if ($print == "Printer Friendly") {
$sbcolor = P_SIDEBAR_COLOR;
$mbgcolor = P_MENUBG_COLOR;
} else {
$sbcolor=SIDEBAR_COLOR;
$mbgcolor=MENUBG_COLOR;
$sbcolor = SIDEBAR_COLOR;
$mbgcolor = MENUBG_COLOR;
}
framework("begin","$logname","Note Templates",$print);
framework("begin", "$logname", "Note Templates", $print);
// make basic determination about authorization
if ($isadmin) {
$authorized=TRUE;
} else if ($efftechid==$techid) {
$authorized=TRUE;
$authorized = TRUE;
} else if ($efftechid == $techid) {
$authorized = TRUE;
} else {
$authorized=FALSE;
$authorized = FALSE;
}
// var_dump($_REQUEST);
function templatetable($db,$techid,$user) {
function templatetable($db, $techid, $user)
{
// Show template table
$isadmin=dblookup($db,"techs","techid","admin",$techid);
$templatequery=mysqli_query($db,"select * from notetemplates where tech=\"$user\" order by templatename asc");
$tblusername=dblookup($db,"techs","techid","techname",$user);
$isadmin = dblookup($db, "techs", "techid", "admin", $techid);
$templatequery = mysqli_query($db, "select * from notetemplates where tech=\"$user\" order by templatename asc");
$tblusername = dblookup($db, "techs", "techid", "techname", $user);
if (mysqli_num_rows($templatequery)) {
$hastemplates=TRUE;
$hastemplates = TRUE;
} else {
$hastemplates=FALSE;
$hastemplates = FALSE;
}
echo "<b><font size=\"+1\">";
if ($hastemplates) {
// print the user header
if ($user=="0") {
if ($user == "0") {
echo "Global Templates</font></b>";
} else {
if ($user==$techid) {
if ($user == $techid) {
echo "My templates</font></b>";
} else {
echo "Templates for $tblusername</font></b>";
@@ -85,62 +86,62 @@ function templatetable($db,$techid,$user) {
echo "<br><table border=\"1\" width=\"100%\">";
echo "<tr><th width=\"70\">Template Name</th><th width=\"100\">Shift</th><th width=\"100\">Subject</th><th>Note</th><th width=\"70\">References</th></tr>";
while ($tablerow = mysqli_fetch_assoc($templatequery)) {
$templateid=$tablerow["templateid"];
$templatename=$tablerow["templatename"];
$templateid = $tablerow["templateid"];
$templatename = $tablerow["templatename"];
// convert shift number to name
$shiftname=dblookup($db,"shifts","shiftid","shiftname",$tablerow["shift"]);
$shiftname = dblookup($db, "shifts", "shiftid", "shiftname", $tablerow["shift"]);
// convert subject number to name
$subjname=dblookup($db,"subjects","subjectid","subjectname",$tablerow["subject"]);
$subjname = dblookup($db, "subjects", "subjectid", "subjectname", $tablerow["subject"]);
// create links of urls in note
$fmtnote=convertweblinks($tablerow["lognote"]);
$fmtnote = convertweblinks($tablerow["lognote"]);
// generate the flags string
$flagstring="";
$flagqry=mysqli_query($db,"select flagid from flagmap where notetemplateid=$templateid");
while ($flagid=mysqli_fetch_row($flagqry)) {
$flagparams=mysqli_fetch_assoc(mysqli_query($db,"select * from flags where flagid=\"$flagid[0]\""));
$flagcolor=$flagparams["flagcolor"];
$flagsym=$flagparams["flagsym"];
$flagname=$flagparams["flagname"];
$flagstring=$flagstring."<font color=\"$flagcolor\" title=\"$flagname\">$flagsym</font>&nbsp;&nbsp;";
$flagstring = "";
$flagqry = mysqli_query($db, "select flagid from flagmap where notetemplateid=$templateid");
while ($flagid = mysqli_fetch_row($flagqry)) {
$flagparams = mysqli_fetch_assoc(mysqli_query($db, "select * from flags where flagid=\"$flagid[0]\""));
$flagcolor = $flagparams["flagcolor"];
$flagsym = $flagparams["flagsym"];
$flagname = $flagparams["flagname"];
$flagstring = $flagstring . "<font color=\"$flagcolor\" title=\"$flagname\">$flagsym</font>&nbsp;&nbsp;";
}
if ($flagstring) {
$fmtnote=$fmtnote."<br>".$flagstring."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
} else {
$fmtnote=$fmtnote."<br>";
$fmtnote = $fmtnote . "<br>" . $flagstring . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
} else {
$fmtnote = $fmtnote . "<br>";
}
// generate a reference string
$refstring=NULL;
$refstringqry=mysqli_query($db,"select target from reflinks where templateid=\"$templateid\"");
while ($tgt=mysqli_fetch_row($refstringqry)) {
$refstring=$refstring." ".$tgt[0];
$refstring = NULL;
$refstringqry = mysqli_query($db, "select target from reflinks where templateid=\"$templateid\"");
while ($tgt = mysqli_fetch_row($refstringqry)) {
$refstring = $refstring . " " . $tgt[0];
}
// now print the line in the table
if (!$isadmin && $user=="0") {
$nameblock="$templatename</a>";
if (!$isadmin && $user == "0") {
$nameblock = "$templatename</a>";
} else {
$nameblock="<a href=\"templates.php?operation=edit&templateid=$templateid\">$templatename</a>";
$nameblock = "<a href=\"templates.php?operation=edit&templateid=$templateid\">$templatename</a>";
}
printf(
"<tr>
"<tr>
<td valign=\"top\">%s</td>
<td valign=\"top\"> %s</td>
<td valign=\"top\">%s</td>
<td valign=\"top\">%s</td>
<td valign=\"top\">%s</td>
</tr>\n",
$nameblock,
$shiftname,
$subjname,
$fmtnote,
$refstring
$nameblock,
$shiftname,
$subjname,
$fmtnote,
$refstring
);
};
echo "</table><br><hr><br>";
} else {
if ($user=="0") {
if ($user == "0") {
echo "There are no global templates</font></b>";
} else {
if ($user==$techid) {
if ($user == $techid) {
echo "You have no templates</font></b>";
} else {
echo "$tblusername has no templates</font></b>";
@@ -154,108 +155,108 @@ function templatetable($db,$techid,$user) {
// ******** begin database manipulation ********
if ($usertemplateid) {
$templateid=$usertemplateid;
$templateid = $usertemplateid;
} else if ($globaltemplateid) {
$templateid=$globaltemplateid;
$templateid = $globaltemplateid;
} else {
$loadtemplate=NULL;
$loadtemplate = NULL;
}
if ($operation=="add") {
if ($submit) {
if ($operation == "add") {
if ($submit) {
if ($note) {
// remove cruft from note text
$note=strip_tags($note,"<a>");
$note=mysqli_real_escape_string($db,$note);
$note = strip_tags($note, "<a>");
$note = mysqli_real_escape_string($db, $note);
if ($authorized) {
// check if name supplied
if ($templatename) {
$namesupplied=TRUE;
$namesupplied = TRUE;
// check if supplied name already exists
if (! mysqli_num_rows(mysqli_query($db,"select templateid from notetemplates where tech=\"$efftechid\" and templatename=\"$templatename\""))) {
if (! mysqli_num_rows(mysqli_query($db, "select templateid from notetemplates where tech=\"$efftechid\" and templatename=\"$templatename\""))) {
// add the record to notetemplates
mysqli_query($db,"insert into notetemplates(templatename,shift,tech,subject,lognote) values (\"$templatename\", \"$shift\",\"$efftechid\",\"$subject\",\"$note\")");
$newtemplateid=mysqli_insert_id($db);
mysqli_query($db, "insert into notetemplates(templatename,shift,tech,subject,lognote) values (\"$templatename\", \"$shift\",\"$efftechid\",\"$subject\",\"$note\")");
$newtemplateid = mysqli_insert_id($db);
// update the flagmap table
foreach ($flags as $thisflag) {
// set flag for this note
mysqli_query($db,"insert into flagmap(flagid,notetemplateid) values(\"$thisflag\",\"$newtemplateid\")");
mysqli_query($db, "insert into flagmap(flagid,notetemplateid) values(\"$thisflag\",\"$newtemplateid\")");
}
// add references to the reflinks table
if (strlen($refstring)) {
$refstring=trim($refstring);
$refarray=explode(" ",$refstring);
$refstring = trim($refstring);
$refarray = explode(" ", $refstring);
foreach ($refarray as $target) {
mysqli_query($db,"insert into reflinks(templateid,target) values($newtemplateid,$target)");
mysqli_query($db, "insert into reflinks(templateid,target) values($newtemplateid,$target)");
}
}
$templateid=$newtemplateid;
$templateid = $newtemplateid;
} else {
$nameexists=TRUE;
$nameexists = TRUE;
}
} else {
$namesupplied=FALSE;
$namesupplied = FALSE;
}
}
}
}
}
if ($operation=="edit" || $operation=="delete") {
if ($operation == "edit" || $operation == "delete") {
// test to see if this templateid is owned by techid to prevent hijacking
$owner=dblookup($db,"notetemplates","templateid","tech",$templateid);
if (!$isadmin && ($owner!=$techid)) $authorized=FALSE;
if ($submit) {
$owner = dblookup($db, "notetemplates", "templateid", "tech", $templateid);
if (!$isadmin && ($owner != $techid)) $authorized = FALSE;
if ($submit) {
if ($note) {
// remove cruft from note text
$note=strip_tags($note,"<a>");
$note=mysqli_real_escape_string($db,$note);
$note = strip_tags($note, "<a>");
$note = mysqli_real_escape_string($db, $note);
if ($templatename) {
$namesupplied=TRUE;
$namesupplied = TRUE;
} else {
$namesupplied=FALSE;
$namesupplied = FALSE;
}
if ($authorized) {
// check if name was supplied
if ($templatename) {
// update notetemplates
mysqli_query($db,"update notetemplates set templatename=\"$templatename\", shift=\"$shift\", tech=\"$efftechid\", subject=\"$subject\", lognote=\"$note\" where templateid=\"$templateid\"");
mysqli_query($db, "update notetemplates set templatename=\"$templatename\", shift=\"$shift\", tech=\"$efftechid\", subject=\"$subject\", lognote=\"$note\" where templateid=\"$templateid\"");
// update the flagmap table
mysqli_query($db,"delete from flagmap where notetemplateid=\"$templateid\"");
mysqli_query($db, "delete from flagmap where notetemplateid=\"$templateid\"");
foreach ($flags as $thisflag) {
// set flag for this note
mysqli_query($db,"insert into flagmap(flagid,notetemplateid) values(\"$thisflag\",\"$templateid\")");
mysqli_query($db, "insert into flagmap(flagid,notetemplateid) values(\"$thisflag\",\"$templateid\")");
}
// update the reflinks table
mysqli_query($db,"delete from reflinks where templateid=\"$templateid\"");
mysqli_query($db, "delete from reflinks where templateid=\"$templateid\"");
if (strlen($refstring)) {
$refstring=trim($refstring);
$refarray=explode(" ",$refstring);
$refstring = trim($refstring);
$refarray = explode(" ", $refstring);
foreach ($refarray as $target) {
mysqli_query($db,"insert into reflinks(templateid,target) values($templateid,$target)");
mysqli_query($db, "insert into reflinks(templateid,target) values($templateid,$target)");
}
}
}
}
}
}
if ($operation=="delete") {
if ($operation == "delete") {
if ($authorized) {
// update notetemplates
mysqli_query($db,"delete from notetemplates where templateid=\"$templateid\"");
mysqli_query($db, "delete from notetemplates where templateid=\"$templateid\"");
// update the flagmap table
mysqli_query($db,"delete from flagmap where notetemplateid=\"$templateid\"");
mysqli_query($db, "delete from flagmap where notetemplateid=\"$templateid\"");
// update the reflinks table
mysqli_query($db,"delete from reflinks where templateid=\"$templateid\"");
$templateid=NULL;
$note=NULL;
mysqli_query($db, "delete from reflinks where templateid=\"$templateid\"");
$templateid = NULL;
$note = NULL;
}
}
}
@@ -264,118 +265,118 @@ if ($operation=="edit" || $operation=="delete") {
pagetable("begin");
if (!$print) {
pageblock("left","begin");
pageblock("left", "begin");
sidemenu();
pageblock("left","end");
pageblock("left", "end");
}
pageblock("right","begin");
pageblock("right", "begin");
banner($print);
if ($submit || $operation=="delete") {
if ($submit || $operation == "delete") {
// show success/failure messages
$nameexists=$nameexists ?? NULL;
$namesupplied=$namesupplied ?? NULL;
if ($operation=="add") {
$addfail=FALSE;
$nameexists = $nameexists ?? NULL;
$namesupplied = $namesupplied ?? NULL;
if ($operation == "add") {
$addfail = FALSE;
if ($nameexists) {
format_message(1,"Template creation failed because the name you supplied already exists. Please try again.");
$addfail=TRUE;
format_message(1, "Template creation failed because the name you supplied already exists. Please try again.");
$addfail = TRUE;
}
if (!$namesupplied) {
format_message(1,"Template creation failed because you didn't supply a name. Please try again.");
$addfail=TRUE;
format_message(1, "Template creation failed because you didn't supply a name. Please try again.");
$addfail = TRUE;
}
if (!$note) {
format_message(1,"Template creation failed because you didn't enter any note text. Please try again.");
$addfail=TRUE;
format_message(1, "Template creation failed because you didn't enter any note text. Please try again.");
$addfail = TRUE;
}
if (!$authorized) {
format_message(1,"Template creation failed because you are not authorized to do so.");
$addfail=TRUE;
format_message(1, "Template creation failed because you are not authorized to do so.");
$addfail = TRUE;
}
if (!$addfail) format_message(0,"<strong>Template created.</strong>");
if (!$addfail) format_message(0, "<strong>Template created.</strong>");
}
if ($operation=="edit") {
$editfail=FALSE;
if ($operation == "edit") {
$editfail = FALSE;
if (!$namesupplied) {
format_message(1,"Template save failed because you didn't supply a name. Please try again.");
$editfail=TRUE;
format_message(1, "Template save failed because you didn't supply a name. Please try again.");
$editfail = TRUE;
}
if (!$note) {
format_message(1,"Template save failed because you didn't enter any note text. Please try again.");
$editfail=TRUE;
format_message(1, "Template save failed because you didn't enter any note text. Please try again.");
$editfail = TRUE;
}
if (!$authorized) {
format_message(1,"Template save failed because you are not authorized to do so.");
$editfail=TRUE;
format_message(1, "Template save failed because you are not authorized to do so.");
$editfail = TRUE;
}
if (!$editfail) format_message(0,"<strong>Template modified.</strong>");
if (!$editfail) format_message(0, "<strong>Template modified.</strong>");
}
if ($operation=="delete") {
$deletefail=FALSE;
if ($operation == "delete") {
$deletefail = FALSE;
if (!$authorized) {
format_message(1,"Template delete failed because you are not authorized to do so.");
$deletefail=TRUE;
format_message(1, "Template delete failed because you are not authorized to do so.");
$deletefail = TRUE;
}
if (!$deletefail) format_message(0,"<strong>Template deleted.</strong>");
if (!$deletefail) format_message(0, "<strong>Template deleted.</strong>");
}
}
if ($operation=="delete") {
if ($operation == "delete") {
// just show the link back to the templates page
echo "
<br><a href=\"templates.php\">Manage templates</a><br><br><br><br>
";
} else if ($operation=="add" || $operation=="edit") {
} else if ($operation == "add" || $operation == "edit") {
// Display the input form
if ($loadtemplate) {
// make templateid the selected template
if ($usertemplateid) {
$templateid=$usertemplateid;
$templateid = $usertemplateid;
} else if ($globaltemplateid) {
$templateid=$globaltemplateid;
$templateid = $globaltemplateid;
} else {
$templateid=NULL;
$templateid = NULL;
}
}
if ($operation=="edit" || $loadtemplate) {
if ($operation == "edit" || $loadtemplate) {
// use values from the templateid supplied with a defined tech id
$loadeddata=mysqli_fetch_assoc(mysqli_query($db,"select * from notetemplates where templateid=\"$templateid\""));
$filltemplatename=$loadeddata["templatename"];
$loadeddata = mysqli_fetch_assoc(mysqli_query($db, "select * from notetemplates where templateid=\"$templateid\""));
$filltemplatename = $loadeddata["templatename"];
if ($efftechid) {
$filltech=$efftechid;
} else if ($isadmin && $loadeddata["tech"]=="0") {
$filltech="0";
$filltech = $efftechid;
} else if ($isadmin && $loadeddata["tech"] == "0") {
$filltech = "0";
} else {
$filltech=$techid;
$filltech = $techid;
}
$fillshift=$loadeddata["shift"];
$fillsubject=$loadeddata["subject"];
$fillnote=$loadeddata["lognote"];
$fillshift = $loadeddata["shift"];
$fillsubject = $loadeddata["subject"];
$fillnote = $loadeddata["lognote"];
} else {
// use empty values with a defined tech id
$filltemplatename=NULL;
$filltemplatename = NULL;
if ($efftechid) {
$filltech=$efftechid;
$filltech = $efftechid;
} else {
$filltech=$techid;
$filltech = $techid;
}
$fillshift=$defaultshift;
$fillsubject=NULL;
$fillnote=NULL;
$fillshift = $defaultshift;
$fillsubject = NULL;
$fillnote = NULL;
}
if ($operation=="add") $optext="Creating new";
if ($operation=="edit") $optext="Editing";
if ($operation == "add") $optext = "Creating new";
if ($operation == "edit") $optext = "Editing";
echo "
<br><b>$optext template</b><br><hr>
";
// show the template selection line
templateselect($techid,$operation);
templateselect($techid, $operation);
// start template entry section
echo "
<form method=\"post\" action=\"templates.php\">
@@ -388,25 +389,26 @@ if ($operation=="delete") {
<tr><td colspan=\"2\"><b>Tech: </b>&nbsp;
<select name=\"efftechid\">
";
if ($filltech=="0") {
if ($filltech == "0") {
echo "<option value=\"0\" selected>--Global Template--</option>";
} else {
echo "<option value=\"0\">--Global Template--</option>";
}
if ($techalpha) $torder="techname"; else $torder="techid";
$techrow=mysqli_query($db,"select * from techs order by $torder asc");
while ($techitem=mysqli_fetch_assoc($techrow)) {
if ($techitem["techid"]==$filltech) {
printf("<option value=\"%s\" selected>%s</option>",$techitem["techid"],$techitem["techname"]);
if ($techalpha) $torder = "techname";
else $torder = "techid";
$techrow = mysqli_query($db, "select * from techs order by $torder asc");
while ($techitem = mysqli_fetch_assoc($techrow)) {
if ($techitem["techid"] == $filltech) {
printf("<option value=\"%s\" selected>%s</option>", $techitem["techid"], $techitem["techname"]);
} else {
printf("<option value=\"%s\">%s</option>",$techitem["techid"],$techitem["techname"]);
printf("<option value=\"%s\">%s</option>", $techitem["techid"], $techitem["techname"]);
}
}
echo "
</select></td></tr>
";
} else {
$authorized=TRUE;
$authorized = TRUE;
echo "
<input type=\"hidden\" name=\"efftechid\" value=\"$techid\">
";
@@ -416,13 +418,13 @@ if ($operation=="delete") {
<td><b>Shift: </b>&nbsp;
<select name=\"shift\">
";
$shiftrow=mysqli_query($db,"select * from shifts");
while ($shiftitem=mysqli_fetch_assoc($shiftrow)) {
$shiftrow = mysqli_query($db, "select * from shifts");
while ($shiftitem = mysqli_fetch_assoc($shiftrow)) {
if ($shiftitem["status"] == 1) {
if ($shiftitem["shiftid"]==$fillshift) {
printf("<option value=\"%s\" selected>%s</option>",$shiftitem["shiftid"],$shiftitem["shiftname"]);
if ($shiftitem["shiftid"] == $fillshift) {
printf("<option value=\"%s\" selected>%s</option>", $shiftitem["shiftid"], $shiftitem["shiftname"]);
} else {
printf("<option value=\"%s\">%s</option>",$shiftitem["shiftid"],$shiftitem["shiftname"]);
printf("<option value=\"%s\">%s</option>", $shiftitem["shiftid"], $shiftitem["shiftname"]);
}
}
}
@@ -431,18 +433,19 @@ if ($operation=="delete") {
<td><b>Subject: </b>&nbsp;
<select name=\"subject\">
";
if ($subjalpha) $sorder="subjectname"; else $sorder="subjectid";
$subjrow=mysqli_query($db,"select * from subjects order by $sorder asc");
while ($subjitem=mysqli_fetch_assoc($subjrow)) {
if ($subjitem["status"]==1) {
if ($subjitem["subjectid"]==$fillsubject) {
printf("<option value=\"%s\" selected>%s</option>",$subjitem["subjectid"],$subjitem["subjectname"]);
if ($subjalpha) $sorder = "subjectname";
else $sorder = "subjectid";
$subjrow = mysqli_query($db, "select * from subjects order by $sorder asc");
while ($subjitem = mysqli_fetch_assoc($subjrow)) {
if ($subjitem["status"] == 1) {
if ($subjitem["subjectid"] == $fillsubject) {
printf("<option value=\"%s\" selected>%s</option>", $subjitem["subjectid"], $subjitem["subjectname"]);
} else {
printf("<option value=\"%s\">%s</option>",$subjitem["subjectid"],$subjitem["subjectname"]);
printf("<option value=\"%s\">%s</option>", $subjitem["subjectid"], $subjitem["subjectname"]);
}
}
}
echo "
</select></td>
</tr></table>
@@ -454,50 +457,60 @@ if ($operation=="delete") {
<input type=\"text\" size=\"23\" id=\"linkurlfield\" placeholder=\"Enter URL here\">&nbsp;
<a href=\"#\" onclick=\"insertUrlAtCaret('notetextarea','linktextfield','linkurlfield');return false;\">Insert Link</a><br>
";
// create an array called theseflags and optionally load it with flagids set for this template
unset($theseflags);
$theseflags=[];
$theseflags = [];
if ($templateid) {
$allflags=mysqli_query($db,"select flagid from flags");
while ($thisflag=mysqli_fetch_row($allflags)) {
if (mysqli_num_rows(mysqli_query($db,"select id from flagmap where flagid=\"$thisflag[0]\" and notetemplateid=\"$templateid\""))) {
$theseflags[]=$thisflag[0];
$allflags = mysqli_query($db, "select flagid from flags");
while ($thisflag = mysqli_fetch_row($allflags)) {
if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and notetemplateid=\"$templateid\""))) {
$theseflags[] = $thisflag[0];
}
}
}
$flagslist=mysqli_query($db,"select * from flags where status=1");
$flagsperline=8;
$flagcount=1;
$flagslist = mysqli_query($db, "select * from flags where status=1");
$flagsperline = 8;
$flagcount = 1;
// display checkboxes for all the flags, selecting the ones that are set for this template
while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) {
if ($operation=="edit" && in_array($flagcheckbox["flagid"],$theseflags)) {
printf("<input type=\"checkbox\" name=\"flags[]\" value=\"%s\" checked><font color=\"%s\" title=\"%s\">%s</font>",
$flagcheckbox["flagid"],$flagcheckbox["flagcolor"],$flagcheckbox["flagname"],$flagcheckbox["flagsym"]);
while ($flagcheckbox = mysqli_fetch_assoc($flagslist)) {
if ($operation == "edit" && in_array($flagcheckbox["flagid"], $theseflags)) {
printf(
"<input type=\"checkbox\" name=\"flags[]\" value=\"%s\" checked><font color=\"%s\" title=\"%s\">%s</font>",
$flagcheckbox["flagid"],
$flagcheckbox["flagcolor"],
$flagcheckbox["flagname"],
$flagcheckbox["flagsym"]
);
} else {
$flagid=$flagcheckbox["flagid"];
if (mysqli_num_rows(mysqli_query($db,"select flagid from flags where flagid=\"$flagid\" and status=1"))) {
printf("<input type=\"checkbox\" name=\"flags[]\" value=\"%s\"><font color=\"%s\" title=\"%s\">%s</font>",
$flagcheckbox["flagid"],$flagcheckbox["flagcolor"],$flagcheckbox["flagname"],$flagcheckbox["flagsym"]);
$flagid = $flagcheckbox["flagid"];
if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagid=\"$flagid\" and status=1"))) {
printf(
"<input type=\"checkbox\" name=\"flags[]\" value=\"%s\"><font color=\"%s\" title=\"%s\">%s</font>",
$flagcheckbox["flagid"],
$flagcheckbox["flagcolor"],
$flagcheckbox["flagname"],
$flagcheckbox["flagsym"]
);
}
}
if ($flagcount<$flagsperline) {
if ($flagcount < $flagsperline) {
echo "&nbsp;&nbsp;&nbsp;";
$flagcount++;
} else {
echo "<br>";
$flagcount=1;
$flagcount = 1;
}
}
if ($operation=="edit" || $loadtemplate) {
if ($operation == "edit" || $loadtemplate) {
// generate a reference string
$refstring=NULL;
$refstringqry=mysqli_query($db,"select target from reflinks where templateid=\"$templateid\"");
while ($tgt=mysqli_fetch_row($refstringqry)) {
$refstring=$refstring." ".$tgt[0];
$refstring = NULL;
$refstringqry = mysqli_query($db, "select target from reflinks where templateid=\"$templateid\"");
while ($tgt = mysqli_fetch_row($refstringqry)) {
$refstring = $refstring . " " . $tgt[0];
}
}
echo "
@@ -505,14 +518,14 @@ if ($operation=="delete") {
<input type=\"text\" name=\"refstring\" size=\"20\" value=\"$refstring\" title=\"One or more Note ID numbers separated by spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
";
if ($operation=="add" && $authorized) {
if ($operation == "add" && $authorized) {
echo "
<input type=\"hidden\" name=\"operation\" value=\"add\">
<input type=\"submit\" name=\"submit\" value=\"Save Template\">
";
}
if ($operation=="edit" && $authorized) {
if ($operation == "edit" && $authorized) {
echo "
<input type=\"hidden\" name=\"operation\" value=\"edit\">
<input type=\"hidden\" name=\"templateid\" value=\"$templateid\">
@@ -521,34 +534,32 @@ if ($operation=="delete") {
<button type=\"submit\" name=\"operation\" value=\"delete\">Delete this template</button><font color=\"#FF0000\"><b>Deleted templates are irretrievable!</b></font>
";
}
echo "
</form>
<br>
";
} else {
echo "<br><font size= \"+1\"><b><a href=\"templates.php?operation=add\">Create or copy a template</a></b></font><br><hr>";
// Show my user template table
templatetable($db,$techid,$techid);
templatetable($db, $techid, $techid);
// Show global template table
templatetable($db,$techid,"0");
templatetable($db, $techid, "0");
if ($isadmin) {
// Show template tables for other users
$techqry=mysqli_query($db,"select techid from techs where techid != $techid and techid != 0");
while ($techtblrow=(mysqli_fetch_row($techqry))) {
templatetable($db,$techid,$techtblrow[0]);
$techqry = mysqli_query($db, "select techid from techs where techid != $techid and techid != 0");
while ($techtblrow = (mysqli_fetch_row($techqry))) {
templatetable($db, $techid, $techtblrow[0]);
}
}
}
banner($print);
pageblock("right","end");
pageblock("right", "end");
pagetable("end");
framework("end","","",$print);
?>
framework("end", "", "", $print);