Continued work on templates.php
This commit is contained in:
42
README.md
42
README.md
@@ -1,19 +1,26 @@
|
||||
# OpenLog #
|
||||
|
||||
OpenLog is an online logbook application. It allows anyone with a web browser to read, enter, and search for notes on any subject. The available shifts, employees, and subjects are easily configured. Notes can be referred to other notes and the entire chain of referenced notes can be displayed in a single page. This makes it convenient to track ongoing projects or actions on a particular piece of equipment over a long period of time. Version 5.0 adds parts tracking functionality. Notes can have parts change information associated with them and maintenance/repair forms can be generated for parts. Parts related functions can be disabled to reduce clutter if they are not needed. Version 5.1 adds scheduled maintenance functionality, which can also be disabled if not needed. Notes, parts, and maintenance forms can be searched for based on a number of criteria. The look and feel of the OpenLog pages are easily changed. Settings that affect all users can be changed in the Administration menu. Each user can personalize his or her own settings in the My Profile menu. No browser specific HTML is used in OpenLog, so it should be useable in any browser, and it has been tested using Google Chrome, Mozilla Firefox and Microsoft Internet Explorer.
|
||||
OpenLog is an online logbook application. It allows anyone with a web browser to read, enter, and search for notes on any subject.
|
||||
|
||||
The available shifts, employees, and subjects are easily configured. Notes can be referred to other notes and the entire chain of referenced notes can be displayed in a single page. This makes it convenient to track ongoing projects or actions on a particular piece of equipment over a long period of time.
|
||||
|
||||
Version 5.0 adds parts tracking functionality. Notes can have parts change information associated with them and maintenance/repair forms can be generated for parts. Parts related functions can be disabled to reduce clutter if they are not needed.
|
||||
|
||||
Version 5.1 adds scheduled maintenance functionality, which can also be disabled if not needed. Notes, parts, and maintenance forms can be searched for based on a number of criteria.
|
||||
|
||||
The look and feel of the OpenLog pages are easily changed. Settings that affect all users can be changed in the Administration menu. Each user can personalize his or her own settings in the My Profile menu.
|
||||
|
||||
No browser specific HTML is used in OpenLog, so it should be useable in any browser, and it has been tested using Google Chrome, Mozilla Firefox, Microsoft Internet Explorer, and Edge.
|
||||
|
||||
## Prerequisites ##
|
||||
|
||||
Linux - The installer is written to automate installation on Debian based Linux servers, but OpenLog itself should run on any current Linux distribution, albeit installation will need to be accomplished manually.
|
||||
Apache2 - Current development is using version 2.4.65
|
||||
MySQL or MariaDB - Current development is using MariaDB version 11.8.3
|
||||
php - Current development is using version 8.4.11
|
||||
|
||||
- Linux - The installer is written to automate installation on Debian based Linux servers, but OpenLog itself should run on any current Linux distribution, albeit installation will need to be accomplished manually.
|
||||
- Apache2 - Current development is using version 2.4.65
|
||||
- MySQL or MariaDB - Current development is using MariaDB version 11.8.3
|
||||
- php - Current development is using version 8.4.11
|
||||
|
||||
## Installation ##
|
||||
|
||||
### Linux Instructions ###
|
||||
|
||||
> [!NOTE]
|
||||
> These instructions are used to either install a new instance of OpenLog or upgrade an existing one.
|
||||
|
||||
@@ -21,15 +28,16 @@ php - Current development is using version 8.4.11
|
||||
2. `cd OpenLog-x.x.x`
|
||||
3. `sudo ./install.sh`
|
||||
|
||||
The installer will check for installation of the required packages and prompt for their installation if not found.
|
||||
You'll then be prompted for the webserver's install location. The default should work for standard installations.
|
||||
You'll then be prompted for the installation location of this instance of OpenLog. You should come up with a unique name.
|
||||
If this directory already exists and contains an instance of OpenLog, you will be prompted to cancel the process or upgrade this instance. If you choose to upgrade, your OpenLog instance will be upgraded and you're done.
|
||||
If this directory does not exist, it will be created and a new instance will be installed. You can have multiple instances of OpenLog running under different names in different directories. For example, if you wanted to create an Operations Log, you could enter `opslog`.
|
||||
If installing a new instance, for example, the Operations Log referred to above, you could enter `OpsLog` or `Operations Log`.
|
||||
For a new instance, you'll br prompted for the name of the database to be created. You should choose something appropriate, like `opslog` for the example given.
|
||||
Next, you'll be prompted to enable the apache2 configuration for this instance.
|
||||
The new instance will now be installed and accessible. You will be given some important information.
|
||||
* The installer will check for installation of the required packages and prompt for their installation if not found.
|
||||
* You'll then be prompted for the webserver's install location. The default should work for standard installations.
|
||||
* You'll then be prompted for the installation location of this instance of OpenLog. You should come up with a unique name.
|
||||
* If this directory already exists and contains an instance of OpenLog, you will be prompted to cancel the process or upgrade this instance.
|
||||
* If you choose to upgrade, your OpenLog instance will be upgraded and you're done.
|
||||
* If this directory does not exist, it will be created and a new instance will be installed. You can have multiple instances of OpenLog running under different names in different directories. For example, if you wanted to create an Operations Log, you could enter `opslog`.
|
||||
* In the Operations Log example referred to above, you could enter `OpsLog` or `Operations Log`.
|
||||
* You'll br prompted for the name of the database to be created. You should choose something appropriate, like `opslog` for the example given.
|
||||
* Next, you'll be prompted to enable the apache2 configuration for this instance.
|
||||
*The new instance will now be installed and accessible. You will be given some important information.
|
||||
> [!IMPORTANT]
|
||||
> The default login credentials for the initial admin user are:
|
||||
> login: `OpenLogAdmin`
|
||||
|
||||
@@ -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) {
|
||||
// check if name was supplied
|
||||
if ($templatename) {
|
||||
$namesupplied=TRUE;
|
||||
} else {
|
||||
$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\"");
|
||||
|
||||
@@ -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,31 +322,33 @@ 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.");
|
||||
format_message(1,"Template creation 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.");
|
||||
format_message(1,"Template creation 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.");
|
||||
format_message(1,"Template creation failed because you didn't enter any note text. Please try again.");
|
||||
$addfail=TRUE;
|
||||
}
|
||||
if (!$addfail) format_message(0,"<strong>Template added.</strong>");
|
||||
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;
|
||||
@@ -365,17 +357,28 @@ if ($submit || $delete) {
|
||||
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) {
|
||||
if ($operation=="add") $optext="Creating new";
|
||||
if ($operation=="edit") $optext="Editing";
|
||||
echo "
|
||||
<br><b>$optext global template</b><br><hr>
|
||||
<br><b>$optext template</b><br><hr>
|
||||
";
|
||||
} else {
|
||||
echo "
|
||||
<br><b>$optext user template</b><br><hr>
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
// show the template selection line
|
||||
templateselect($db,$techid);
|
||||
templateselect($db,$techid,$operation);
|
||||
|
||||
// start template entry section
|
||||
echo "
|
||||
@@ -439,12 +435,15 @@ 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 ($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)) {
|
||||
@@ -458,14 +457,7 @@ if ($delete) {
|
||||
</select></td></tr>
|
||||
";
|
||||
} else {
|
||||
// don't show tech line, just force value to 0
|
||||
echo "
|
||||
<input type=\"hidden\" name=\"efftechid\" value=\"0\">
|
||||
";
|
||||
}
|
||||
} 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,32 +557,29 @@ 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\">
|
||||
";
|
||||
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>
|
||||
<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>";
|
||||
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