Continued work on templates.php
This commit is contained in:
@@ -16,7 +16,6 @@ if (!$_SESSION['login'] && !$_REQUEST['partview']) {
|
||||
$techid=$_SESSION['login'] ?? NULL;
|
||||
$isadmin=dblookup($db,"techs","techid","admin",$techid);
|
||||
$print=$_REQUEST['print'] ?? NULL;
|
||||
$tech=$_REQUEST['tech'] ?? NULL;
|
||||
$efftechid=$_REQUEST['efftechid'] ?? NULL;
|
||||
$shift=$_REQUEST['shift'] ?? NULL;
|
||||
$subject=$_REQUEST['subject'] ?? NULL;
|
||||
@@ -24,9 +23,10 @@ $note=$_REQUEST['note'] ?? NULL;
|
||||
$flags=$_POST['flags'] ?? [];
|
||||
$refstring=$_REQUEST['refstring'] ?? NULL;
|
||||
$submit=$_REQUEST['submit'] ?? NULL;
|
||||
$add=$_REQUEST['add'] ?? NULL;
|
||||
$edit=$_REQUEST['edit'] ?? NULL;
|
||||
$delete=$_REQUEST['delete'] ?? NULL;
|
||||
$operation=$_REQUEST['operation'] ?? NULL;
|
||||
//$add=$_REQUEST['add'] ?? NULL;
|
||||
//$edit=$_REQUEST['edit'] ?? NULL;
|
||||
//$delete=$_REQUEST['delete'] ?? NULL;
|
||||
$templateid=$_REQUEST['templateid'] ?? NULL;
|
||||
$templatename=$_REQUEST['templatename'] ?? NULL;
|
||||
$usertemplateid=$_REQUEST['usertemplateid'] ?? NULL;
|
||||
@@ -49,22 +49,14 @@ if ($print=="Printer Friendly") {
|
||||
}
|
||||
|
||||
framework("begin","$logname","Note Templates",$print);
|
||||
|
||||
// make basic determination about authorization
|
||||
if ($isadmin) {
|
||||
$add_auth=TRUE;
|
||||
$edit_auth=TRUE;
|
||||
$del_auth=TRUE;
|
||||
$authorized=TRUE;
|
||||
} else if ($efftechid==$techid) {
|
||||
$add_auth=TRUE;
|
||||
$edit_auth=TRUE;
|
||||
$del_auth=TRUE;
|
||||
} else if ($tech==$techid) {
|
||||
$add_auth=TRUE;
|
||||
$edit_auth=TRUE;
|
||||
$del_auth=TRUE;
|
||||
$authorized=TRUE;
|
||||
} else {
|
||||
$add_auth=FALSE;
|
||||
$edit_auth=FALSE;
|
||||
$del_auth=FALSE;
|
||||
$authorized=FALSE;
|
||||
}
|
||||
|
||||
var_dump($_REQUEST);
|
||||
@@ -85,13 +77,9 @@ function templatetable($db,$techid,$user) {
|
||||
// print the user header
|
||||
if ($user=="0") {
|
||||
echo "Global Templates</font></b>";
|
||||
if ($isadmin) {
|
||||
echo " <a href=\"templates.php?add=1\">Create or copy a global template</a><br>";
|
||||
}
|
||||
} else {
|
||||
if ($user==$techid) {
|
||||
echo "My templates</font></b>";
|
||||
echo " <a href=\"templates.php?add=1\">Create or copy a template</a><br>";
|
||||
} else {
|
||||
echo "Templates for $tblusername</font></b>";
|
||||
}
|
||||
@@ -133,7 +121,7 @@ function templatetable($db,$techid,$user) {
|
||||
if (!$isadmin && $user=="0") {
|
||||
$nameblock="$templatename</a>";
|
||||
} else {
|
||||
$nameblock="<a href=\"templates.php?edit=1&templateid=$templateid\">$templatename</a>";
|
||||
$nameblock="<a href=\"templates.php?operation=edit&templateid=$templateid\">$templatename</a>";
|
||||
}
|
||||
printf(
|
||||
"<tr>
|
||||
@@ -154,25 +142,19 @@ function templatetable($db,$techid,$user) {
|
||||
} else {
|
||||
if ($user=="0") {
|
||||
echo "There are no global templates</font></b>";
|
||||
if ($isadmin) {
|
||||
echo " <a href=\"templates.php?add=1&tech=$user\">Add a new global template</a>";
|
||||
}
|
||||
} else {
|
||||
if ($user==$techid) {
|
||||
echo "You have no templates</font></b>";
|
||||
} else {
|
||||
echo "$tblusername has no templates</font></b>";
|
||||
}
|
||||
if (($user==$techid) || $isadmin) {
|
||||
echo " <a href=\"templates.php?add=1&tech=$user\">Add a new template</a><br>";
|
||||
}
|
||||
}
|
||||
echo "<br><hr>";
|
||||
}
|
||||
echo "<br>";
|
||||
}
|
||||
|
||||
function templateselect($db,$techid) {
|
||||
function templateselect($db,$techid,$operation) {
|
||||
echo "
|
||||
<form method=\"post\" action=\"templates.php\">
|
||||
";
|
||||
@@ -207,6 +189,7 @@ function templateselect($db,$techid) {
|
||||
";
|
||||
// show load button
|
||||
echo "
|
||||
<input type=\"hidden\" name=\"operation\" value=\"$operation\">
|
||||
<input type=\"submit\" name=\"loadtemplate\" value=\"Load Template\">
|
||||
</td>
|
||||
<td>
|
||||
@@ -228,14 +211,14 @@ if ($usertemplateid) {
|
||||
$loadtemplate=NULL;
|
||||
}
|
||||
|
||||
if ($add) {
|
||||
if ($operation=="add") {
|
||||
if ($submit) {
|
||||
if ($note) {
|
||||
// remove cruft from note text
|
||||
$note=strip_tags($note,"<a>");
|
||||
$note=mysqli_real_escape_string($db,$note);
|
||||
|
||||
if ($add_auth) {
|
||||
if ($authorized) {
|
||||
// check if name supplied
|
||||
if ($templatename) {
|
||||
$namesupplied=TRUE;
|
||||
@@ -270,17 +253,26 @@ if ($add) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($edit) {
|
||||
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) {
|
||||
if ($note) {
|
||||
// remove cruft from note text
|
||||
$note=strip_tags($note,"<a>");
|
||||
$note=mysqli_real_escape_string($db,$note);
|
||||
|
||||
if ($edit_auth) {
|
||||
if ($templatename) {
|
||||
$namesupplied=TRUE;
|
||||
} else {
|
||||
$namesupplied=FALSE;
|
||||
}
|
||||
|
||||
if ($authorized) {
|
||||
// check if name was supplied
|
||||
if ($templatename) {
|
||||
$namesupplied=TRUE;
|
||||
// update notetemplates
|
||||
mysqli_query($db,"update notetemplates set templatename=\"$templatename\", shift=\"$shift\", tech=\"$efftechid\", subject=\"$subject\", lognote=\"$note\" where templateid=\"$templateid\"");
|
||||
|
||||
@@ -300,14 +292,12 @@ if ($edit) {
|
||||
mysqli_query($db,"insert into reflinks(templateid,target) values($templateid,$target)");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$namesupplied=FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($delete) {
|
||||
if ($del_auth) {
|
||||
if ($operation=="delete") {
|
||||
if ($authorized) {
|
||||
// update notetemplates
|
||||
mysqli_query($db,"delete from notetemplates where templateid=\"$templateid\"");
|
||||
// update the flagmap table
|
||||
@@ -332,50 +322,63 @@ pageblock("right","begin");
|
||||
banner($print);
|
||||
|
||||
|
||||
if ($submit || $delete) {
|
||||
if ($submit || $operation=="delete") {
|
||||
// show success/failure messages
|
||||
$nameexists=$nameexists ?? NULL;
|
||||
$namesupplied=$namesupplied ?? NULL;
|
||||
if ($delete) {
|
||||
format_message(0,"<strong>Template deleted.</strong>");
|
||||
} else {
|
||||
|
||||
if ($operation=="add") {
|
||||
$addfail=FALSE;
|
||||
if ($add) {
|
||||
if ($nameexists) {
|
||||
format_message(1,"Template save failed because the name you supplied already exists. Please try again.");
|
||||
$addfail=TRUE;
|
||||
}
|
||||
if (!$namesupplied) {
|
||||
format_message(1,"Template save failed because you didn't supply a name. Please try again.");
|
||||
$addfail=TRUE;
|
||||
}
|
||||
if (!$note) {
|
||||
format_message(1,"Template save failed because you didn't enter any note text. Please try again.");
|
||||
$addfail=TRUE;
|
||||
}
|
||||
if (!$addfail) format_message(0,"<strong>Template added.</strong>");
|
||||
if ($nameexists) {
|
||||
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;
|
||||
}
|
||||
if (!$note) {
|
||||
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;
|
||||
}
|
||||
if (!$addfail) format_message(0,"<strong>Template created.</strong>");
|
||||
}
|
||||
if ($operation=="edit") {
|
||||
$editfail=FALSE;
|
||||
if ($edit) {
|
||||
if (!$namesupplied) {
|
||||
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;
|
||||
}
|
||||
if (!$editfail) format_message(0,"<strong>Template modified.</strong>");
|
||||
if (!$namesupplied) {
|
||||
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;
|
||||
}
|
||||
if (!$authorized) {
|
||||
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 ($operation=="delete") {
|
||||
$deletefail=FALSE;
|
||||
if (!$authorized) {
|
||||
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 ($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 ($add || $edit) {
|
||||
} else if ($operation=="add" || $operation=="edit") {
|
||||
// Display the input form
|
||||
if ($loadtemplate) {
|
||||
// make templateid the selected template
|
||||
@@ -387,14 +390,14 @@ if ($delete) {
|
||||
$templateid=NULL;
|
||||
}
|
||||
}
|
||||
if ($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"];
|
||||
if ($tech) {
|
||||
$filltech=$tech;
|
||||
} else if ($efftechid) {
|
||||
if ($efftechid) {
|
||||
$filltech=$efftechid;
|
||||
} else if ($isadmin && $loadeddata["tech"]=="0") {
|
||||
$filltech="0";
|
||||
} else {
|
||||
$filltech=$techid;
|
||||
}
|
||||
@@ -404,9 +407,7 @@ if ($delete) {
|
||||
} else {
|
||||
// use empty values with a defined tech id
|
||||
$filltemplatename=NULL;
|
||||
if ($tech) {
|
||||
$filltech=$tech;
|
||||
} else if ($efftechid) {
|
||||
if ($efftechid) {
|
||||
$filltech=$efftechid;
|
||||
} else {
|
||||
$filltech=$techid;
|
||||
@@ -416,20 +417,15 @@ if ($delete) {
|
||||
$fillnote=NULL;
|
||||
}
|
||||
|
||||
if ($add) $optext="Adding new";
|
||||
if ($edit) $optext="Editing";
|
||||
if ($isadmin && $filltech==0) {
|
||||
echo "
|
||||
<br><b>$optext global template</b><br><hr>
|
||||
";
|
||||
} else {
|
||||
echo "
|
||||
<br><b>$optext user template</b><br><hr>
|
||||
";
|
||||
}
|
||||
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($db,$techid);
|
||||
templateselect($db,$techid,$operation);
|
||||
|
||||
// start template entry section
|
||||
echo "
|
||||
@@ -439,33 +435,29 @@ if ($delete) {
|
||||
<input type=\"text\" name=\"templatename\" size=\"30\" value=\"$filltemplatename\" title=\"What you'd like to name the template.\"></td></tr>
|
||||
";
|
||||
if ($isadmin) {
|
||||
if ($filltech!="0") {
|
||||
// allow tech selection
|
||||
echo "
|
||||
<tr><td colspan=\"2\"><b>Tech: </b>
|
||||
<select name=\"efftechid\">
|
||||
";
|
||||
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"]);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
</select></td></tr>
|
||||
";
|
||||
echo "
|
||||
<tr><td colspan=\"2\"><b>Tech: </b>
|
||||
<select name=\"efftechid\">
|
||||
";
|
||||
if ($filltech=="0") {
|
||||
echo "<option value=\"0\" selected>--Global Template--</option>";
|
||||
} else {
|
||||
// don't show tech line, just force value to 0
|
||||
echo "
|
||||
<input type=\"hidden\" name=\"efftechid\" value=\"0\">
|
||||
";
|
||||
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"]);
|
||||
} else {
|
||||
printf("<option value=\"%s\">%s</option>",$techitem["techid"],$techitem["techname"]);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
</select></td></tr>
|
||||
";
|
||||
} else {
|
||||
$add_auth=TRUE;
|
||||
$edit_auth=TRUE;
|
||||
$authorized=TRUE;
|
||||
echo "
|
||||
<input type=\"hidden\" name=\"efftechid\" value=\"$techid\">
|
||||
";
|
||||
@@ -532,7 +524,7 @@ if ($delete) {
|
||||
|
||||
// display checkboxes for all the flags, selecting the ones that are set for this template
|
||||
while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) {
|
||||
if ($edit && in_array($flagcheckbox["flagid"],$theseflags)) {
|
||||
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 {
|
||||
@@ -551,7 +543,7 @@ if ($delete) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($edit || $loadtemplate) {
|
||||
if ($operation=="edit" || $loadtemplate) {
|
||||
// generate a reference string
|
||||
$refstring=NULL;
|
||||
$refstringqry=mysqli_query($db,"select target from reflinks where templateid=\"$templateid\"");
|
||||
@@ -565,24 +557,20 @@ if ($delete) {
|
||||
|
||||
";
|
||||
|
||||
if ($add && $add_auth) {
|
||||
if ($operation=="add" && $authorized) {
|
||||
echo "
|
||||
<input type=\"hidden\" name=\"add\" value=\"1\">
|
||||
<input type=\"hidden\" name=\"operation\" value=\"add\">
|
||||
<input type=\"submit\" name=\"submit\" value=\"Save Template\">
|
||||
";
|
||||
}
|
||||
if ($edit && $edit_auth) {
|
||||
if ($operation=="edit" && $authorized) {
|
||||
echo "
|
||||
<input type=\"hidden\" name=\"edit\" value=\"1\">
|
||||
<input type=\"hidden\" name=\"operation\" value=\"edit\">
|
||||
<input type=\"hidden\" name=\"templateid\" value=\"$templateid\">
|
||||
<input type=\"submit\" name=\"submit\" value=\"Save Template\">
|
||||
<br><br>
|
||||
<button type=\"submit\" name=\"operation\" value=\"delete\">Delete this template</button><font color=\"#FF0000\"><b>Deleted templates are irretrievable!</b></font>
|
||||
";
|
||||
if ($del_auth) {
|
||||
echo"
|
||||
<br><br>
|
||||
<input type=\"submit\" name=\"delete\" value=\"Delete this template\"><font color=\"#FF0000\"><b>Deleted templates are irretrievable!</b></font>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
echo "
|
||||
@@ -590,7 +578,8 @@ if ($delete) {
|
||||
<br>
|
||||
";
|
||||
} else {
|
||||
echo "<br>";
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user