";
if ($hastemplates) {
// print the user header
if ($user=="0") {
echo "Global Templates";
} else {
if ($user==$techid) {
echo "My templates";
} else {
echo "Templates for $tblusername";
}
}
// print the table
echo "
";
echo "
Template Name
Shift
Subject
Note
References
";
while ($tablerow = mysqli_fetch_assoc($templatequery)) {
$templateid=$tablerow["templateid"];
$templatename=$tablerow["templatename"];
// convert shift number to name
$shiftname=dblookup($db,"shifts","shiftid","shiftname",$tablerow["shift"]);
// 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="";
$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."$flagsym ";
}
if ($flagstring) {
$fmtnote=$fmtnote." ".$flagstring." ";
} else {
$fmtnote=$fmtnote." ";
}
// 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];
}
// now print the line in the table
if (!$isadmin && $user=="0") {
$nameblock="$templatename";
} else {
$nameblock="$templatename";
}
printf(
"
";
} else if ($operation=="add" || $operation=="edit") {
// Display the input form
if ($loadtemplate) {
// make templateid the selected template
if ($usertemplateid) {
$templateid=$usertemplateid;
} else if ($globaltemplateid) {
$templateid=$globaltemplateid;
} else {
$templateid=NULL;
}
}
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"];
if ($efftechid) {
$filltech=$efftechid;
} else if ($isadmin && $loadeddata["tech"]=="0") {
$filltech="0";
} else {
$filltech=$techid;
}
$fillshift=$loadeddata["shift"];
$fillsubject=$loadeddata["subject"];
$fillnote=$loadeddata["lognote"];
} else {
// use empty values with a defined tech id
$filltemplatename=NULL;
if ($efftechid) {
$filltech=$efftechid;
} else {
$filltech=$techid;
}
$fillshift=$defaultshift;
$fillsubject=NULL;
$fillnote=NULL;
}
if ($operation=="add") $optext="Creating new";
if ($operation=="edit") $optext="Editing";
echo "
$optext template
";
// show the template selection line
templateselect($db,$techid,$operation);
// start template entry section
echo "
";
} else {
echo " Create or copy a template ";
// Show my user template table
templatetable($db,$techid,$techid);
// Show global template table
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]);
}
}
}
banner($print);
pageblock("right","end");
pagetable("end");
framework("end","","",$print);
?>