9 Commits

30 changed files with 1394 additions and 593 deletions

View File

@@ -1,6 +1,6 @@
CHANGELOG
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
@@ -193,10 +193,50 @@
fixed. Made the corrections to the edit code as well as the
new entry.
- In logentry.php, the default times for notes entered using dates
other than today's date contained a trailing coln that mysql
other than today's date contained a trailing colon that mysql
didn't like. Removed trailing colons.
- Cleaned up the REQUEST importation in multiple files to default to
NULL values for parameters not supplied to prevent warning
messages in the logs.
- In the install.sh script, removed the prompts for optional package
installation. Code is still there, just turned off by default.
5.2.4.1 - 2025-12-10
- Fixed bug in search.php where "Print search results" link on the
search results page resulted in the printable page not showing
any results. This was due to a php fatal error caused by passing
a non-array as the second argument of the php in_array()
function.
5.2.4.2 - 2025-12-11
- Fixed other bugs caused by passing a non-array as the second
argument of the php in_array() function in various files.
5.2.4.3 - 2025-12-16
- Various problems were noted resulting from php's use of UTC as the
default timezone. Now, on installation or upgrade, the installer
gets the correct timezone from the system and sets it as a php
option in a .htaccess file in the install location. This solves
multiple problems and allows today's date and the current time
to be determined from the php date() function as part of the
settings.php once per page load instead of having to query the
database multiple times per page load. Also added the option to
allow apache to read the .htaccess file to the <Directory>
section of the application's conf file in
/etc/apache2/conf-available
- Renamed the installer's db.php_update.sh script to files-update.sh
to reflect that it now can do more than just modify the db.php
file. For this version, it's used to modify the apache conf file
mentioned earlier.
- Completely removed the optional package prompting/installation
code from install.sh. This is best done using separate
installers.
5.2.4.4 - 2025-12-19
-Fixed bugs that caused crashes on the Scheduled Maintenance page
that were caused by more strict behavior of php regarding mysql
queries.
- Fixed bug where some functions defined in functions.php were not
treating the $today variable as global.
- In install.php, if a previous installation was found, make upgrade
the default choice.

View File

@@ -1,6 +1,6 @@
INSTALL
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0

52
README.md Normal file
View File

@@ -0,0 +1,52 @@
# 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, 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
## Installation ##
> [!NOTE]
> These instructions are used to either install a new instance of OpenLog or upgrade an existing one.
1. Unzip the OpenLog-x.x.x.tar.gz file you've downloaded into a convenient place.
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`.
* 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`
> password: `OpenLog-1`
> Make note of these credentials, otherwise you will not be able to login and configure your new installation.
>
> It is highly recommended that you change the OpenLogAdmin user password and/or create your own admin user (with a secure password) and disable this default account after logging in for the first time.
## History ##
OpenLog was written to replace a creaky old inefficient error prone Access database which had in turn replaced stacks of paper logbooks. Now, with some improvements and over 15 years and 44000 notes later in a production environment, it's still going strong.

1
VERSION.txt Normal file
View File

@@ -0,0 +1 @@
5.3.0

View File

@@ -232,6 +232,32 @@ LOCK TABLES `flags` WRITE;
/*!40000 ALTER TABLE `flags` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `flagmap`
--
DROP TABLE IF EXISTS `flagmap`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `flagmap` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`flagid` int(11) NOT NULL,
`lognoteid` int(11) DEFAULT NULL,
`maintformid` int(11) DEFAULT NULL,
`notetemplateid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `flagmap`
--
LOCK TABLES `flagmap` WRITE;
/*!40000 ALTER TABLE `flagmap` DISABLE KEYS */;
/*!40000 ALTER TABLE `flagmap` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `links`
--
@@ -273,7 +299,6 @@ CREATE TABLE `lognotes` (
`tech` int(11) NOT NULL,
`subject` int(11) NOT NULL,
`lognote` text DEFAULT NULL,
`refs` tinytext DEFAULT NULL,
PRIMARY KEY (`lognoteid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -287,6 +312,31 @@ LOCK TABLES `lognotes` WRITE;
/*!40000 ALTER TABLE `lognotes` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `reflinks`
--
DROP TABLE IF EXISTS `reflinks`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `reflinks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`noteid` int(11) DEFAULT NULL,
`templateid` int(11) DEFAULT NULL,
`target` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `reflinks`
--
LOCK TABLES `reflinks` WRITE;
/*!40000 ALTER TABLE `reflinks` DISABLE KEYS */;
/*!40000 ALTER TABLE `reflinks` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `logpartactions`
--

43
database-update.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
# database-update.sh
# OpenLog Online Logbook
# Copyright (C) 2025 Rod Wright
# SPDX-License-Identifier: GPL-2.0
if [[ $1 == "" ]]
then
echo "This script requires a mysql options file, but none was specified. Aborting."
exit 1
fi
mysql_opt_file=$1
if [[ ! -f $mysql_opt_file ]]
then
echo "The mysql options file specified does not exist. Aborting."
exit 1
fi
margs="--defaults-extra-file=$mysql_opt_file"
# ---------- version x.x.x ----------
# Nothing to be done for versions prior to 5.2.4.3
# -----------------------------------
# ---------- version 5.2.4.3 ----------
# Nothing to do
# -------------------------------------
# ---------- version 5.2.4.4 ----------
# Nothing to do
# -------------------------------------
# ---------- version 5.2.5 ------------
# Nothing to do
# -------------------------------------
# ---------- version 5.3.0 ------------
# Nothing to do
# -------------------------------------

View File

@@ -30,3 +30,33 @@ UPDATE configs SET confvalue="5.2.3" WHERE confname="ol_version";
-- Update version number
UPDATE configs SET confvalue="5.2.4" WHERE confname="ol_version";
-- --------------------------------------
-- ---------- version 5.2.4.1 -----------
-- Update version number
UPDATE configs SET confvalue="5.2.4.1" WHERE confname="ol_version";
-- --------------------------------------
-- ---------- version 5.2.4.2 -----------
-- Update version number
UPDATE configs SET confvalue="5.2.4.2" WHERE confname="ol_version";
-- --------------------------------------
-- ---------- version 5.2.4.3 -----------
-- Update version number
UPDATE configs SET confvalue="5.2.4.3" WHERE confname="ol_version";
-- --------------------------------------
-- ---------- version 5.2.4.4 -----------
-- Update version number
UPDATE configs SET confvalue="5.2.4.4" WHERE confname="ol_version";
-- --------------------------------------
-- ---------- version 5.2.5 -------------
-- Update version number
UPDATE configs SET confvalue="5.2.5" WHERE confname="ol_version";
-- --------------------------------------
-- ---------- version 5.3.0 -------------
-- Update version number
UPDATE configs SET confvalue="5.3.0" WHERE confname="ol_version";
-- --------------------------------------

View File

@@ -3,7 +3,7 @@
/*
db.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -1,19 +0,0 @@
# opendrs-update.sh
install_path=$1
# ---------- version 5.2.1 -------------
# No changes to the db.php file
# ---------------------------------------
# ---------- version 5.2.2 -------------
# No changes to the db.php file
# ---------------------------------------
# ---------- version 5.2.3 -------------
# No changes to the db.php file
# ---------------------------------------
# ---------- version 5.2.4 -------------
# No changes to the db.php file
# ---------------------------------------

View File

@@ -1,6 +1,6 @@
CHANGELOG
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
@@ -201,3 +201,42 @@
- In the install.sh script, removed the prompts for optional package
installation. Code is still there, just turned off by default.
5.2.4.1 - 2025-12-10
- Fixed bug in search.php where "Print search results" link on the
search results page resulted in the printable page not showing
any results. This was due to a php fatal error caused by passing
a non-array as the second argument of the php in_array()
function.
5.2.4.2 - 2025-12-11
- Fixed other bugs caused by passing a non-array as the second
argument of the php in_array() function in various files.
5.2.4.3 - 2025-12-16
- Various problems were noted resulting from php's use of UTC as the
default timezone. Now, on installation or upgrade, the installer
gets the correct timezone from the system and sets it as a php
option in a .htaccess file in the install location. This solves
multiple problems and allows today's date and the current time
to be determined from the php date() function as part of the
settings.php once per page load instead of having to query the
database multiple times per page load. Also added the option to
allow apache to read the .htaccess file to the <Directory>
section of the application's conf file in
/etc/apache2/conf-available
- Renamed the installer's db.php_update.sh script to files-update.sh
to reflect that it now can do more than just modify the db.php
file. For this version, it's used to modify the apache conf file
mentioned earlier.
- Completely removed the optional package prompting/installation
code from install.sh. This is best done using separate
installers.
5.2.4.4 - 2025-12-19
-Fixed bugs that caused crashes on the Scheduled Maintenance page
that were caused by more strict behavior of php regarding mysql
queries.
- Fixed bug where some functions defined in functions.php were not
treating the $today variable as global.
- In install.php, if a previous installation was found, make upgrade
the default choice.

View File

@@ -1,6 +1,6 @@
INSTALL
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0

View File

@@ -2,7 +2,7 @@
/*
about.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -2,7 +2,7 @@
/*
admin.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -2,7 +2,7 @@
/*
functions.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
@@ -181,17 +181,28 @@ function framework($option,$htmltitle,$pagetitle,$print) {
}
}).datepicker(\"setDate\", defdate);
function insertUrlAtCaret(outputAreaId, inputAreaId) {
var rawlinktext=document.getElementById(inputAreaId).value;
var url='<a href=\"' + rawlinktext.replace(/ /g,'\%20') + '\">' + rawlinktext + '</a>';
function insertUrlAtCaret(outputAreaId, inputTextAreaId, inputUrlAreaId) {
var linktext=document.getElementById(inputTextAreaId).value;
var rawurltext=document.getElementById(inputUrlAreaId).value;
if (rawurltext=='') return;
var lastslashindex=rawurltext.lastIndexOf('/');
if (lastslashindex==rawurltext.length-1) {
rawurltext=rawurltext.slice(0, -1);
}
if (linktext=='' && rawurltext!= '') {
lastslashindex=rawurltext.lastIndexOf('/');
var lastpartofurl=rawurltext.substring(lastslashindex+1);
linktext=lastpartofurl;
}
var link='<a href=\"' + rawurltext.replace(/ /g,'\%20') + '\" target=\"_blank\">' + linktext + '</a>';
var txtarea = document.getElementById(outputAreaId);
var scrollPos = txtarea.scrollTop;
var caretPos = txtarea.selectionStart;
var front = (txtarea.value).substring(0, caretPos);
var back = (txtarea.value).substring(txtarea.selectionEnd, txtarea.value.length);
txtarea.value = front + url + back;
caretPos = caretPos + url.length;
txtarea.value = front + link + back;
caretPos = caretPos + link.length;
txtarea.selectionStart = caretPos;
txtarea.selectionEnd = caretPos;
txtarea.focus();
@@ -311,6 +322,7 @@ function sidemenu($noprint=false) {
<table bgcolor=\"$mbgcolor\" border=\"1\" width=\"100%\">
<tr><td align=\"center\"><a href=\"admin.php\" title=\"Control global settings. Must be an administrator.\"><b>Administration</b></a></td></tr>
<tr><td align=\"center\"><a href=\"profile.php\">My Profile</a></td></tr>
<tr><td align=\"center\"><a href=\"templates.php\">Manage Templates</a></td></tr>
</table>
";
if (!isset($_SESSION['login'])) {
@@ -375,8 +387,13 @@ function banner($print) {
function dblookup($dbhandle,$table,$in_field,$out_field,$in_data) {
// look up a single field in a database given a value for a single field
$out_data=mysqli_fetch_row(mysqli_query($dbhandle,"select $out_field from $table where $in_field=\"$in_data\""));
return($out_data[0]);
$dbqry=mysqli_query($dbhandle,"select $out_field from $table where $in_field=\"$in_data\"");
if (mysqli_num_rows($dbqry)) {
$out_data=mysqli_fetch_row($dbqry)[0];
} else {
$out_data=NULL;
}
return($out_data);
}
function calendar($year,$month,$day,$link_url) {
@@ -625,63 +642,53 @@ function islink($il_note) {
// determines if the argument is a link in a reference chain
// returns 1 if note is a link, 0 if not
global $db;
$il_pq=mysqli_fetch_row(mysqli_query($db,"select refs from lognotes where lognoteid=\"$il_note\""));
if ($il_pq[0]=="") {
$il_hasprev=0;
} else {
$il_hasprev=1;
}
$il_sq=mysqli_num_rows(mysqli_query($db,"select lognoteid from lognotes where refs like \"%$il_note%\""));
if ($il_sq) {
$il_hassubs=1;
} else {
$il_hassubs=0;
}
if($il_hassubs || $il_hasprev) {
$refqry=mysqli_query($db,"select id from reflinks where noteid is not null and (noteid='$il_note' or target='$il_note')");
if (mysqli_num_rows($refqry)) {
return 1;
} else {
return 0;
}
}
function generate_chain($chainlink) {
// generate a reference chain
// takes a single parameter, a noteid
// finds all notes that are members of a chain containing the supplied noteid
// returns a sorted array of all notes in chain
// returns a sorted array (chainarray) of all notes in chain
global $db;
$refsqry=mysqli_query($db,"select lognoteid,refs from lognotes where refs!=\"\"");
$nanote=array();
$narefs=array();
while ($allrefs=mysqli_fetch_row($refsqry)) {
$spltrefs=explode(",",$allrefs[1]);
$iptr=0;
while ($iptr<count($spltrefs)) {
array_push($nanote,$allrefs[0]);
array_push($narefs,$spltrefs[$iptr]);
$iptr=$iptr+1;
// create notes and refs arrays from the reflinks table
$notes=[];
$targets=[];
$linkqry=mysqli_query($db,"select noteid,target from reflinks where noteid is not null");
while ($link=mysqli_fetch_assoc($linkqry)) {
$notes[]=$link['noteid'];
$targets[]=$link['target'];
}
}
$chainarray=array($chainlink);
$results=array();
$mptr=0;
while($mptr<count($chainarray)) {
$nptr=0;
while($nptr<count($nanote)) {
if(($nanote[$nptr]==$chainarray[$mptr]) && ( ! in_array($narefs[$nptr],$chainarray))) {
array_push($chainarray,$narefs[$nptr]);
$chainarray=array(); // create the chainarray
$chainarray[]=$chainlink; // add the incoming noteid for which the chain should be generated
$captr=0; // chainarray pointer
while($captr<count($chainarray)) { // as long as the chainarray is growing
$nptr=0; // note pointer
// run through the notes array, adding all targets for this note to the chainarray
while($nptr<count($notes)) {
if(($notes[$nptr]==$chainarray[$captr]) && ( ! in_array($targets[$nptr],$chainarray))) {
$chainarray[]=$targets[$nptr];
}
$nptr=$nptr+1;
}
$rptr=0;
while($rptr<count($narefs)) {
if(($narefs[$rptr]==$chainarray[$mptr]) && ( ! in_array($nanote[$rptr],$chainarray))) {
array_push($chainarray,$nanote[$rptr]);
// run through the targets array, adding all notes for this target to the chainarray
$tptr=0; //target pointer
while($tptr<count($targets)) {
if(($targets[$tptr]==$chainarray[$captr]) && ( ! in_array($notes[$tptr],$chainarray))) {
$chainarray[]=$notes[$tptr];
}
$rptr=$rptr+1;
$tptr=$tptr+1;
}
$mptr=$mptr+1;
$captr=$captr+1;
}
// sort and return the output array
sort($chainarray);
return($chainarray);
}
@@ -721,8 +728,7 @@ function showlinklist($print) {
function nag($tech_id) {
// nags the user if something is pending
global $db;
$today=mysqli_fetch_row(mysqli_query($db,"select current_date"))[0];
global $db, $today;
// maintenance forms
$mfpending=mysqli_num_rows(mysqli_query($db,"select maintformid from maintforms where mftech=\"$tech_id\" and pending=1"));
if ($mfpending) {
@@ -820,8 +826,7 @@ function get_upcoming_events() {
// build array of upcoming events
// takes no arguments
// returns an array containing arrays of upcoming event data
global $db;
$today=mysqli_fetch_row(mysqli_query($db,"select current_date"))[0];
global $db, $today;
$uceventsqry=mysqli_query($db,"select * from events where active_flag=\"1\" and (deferred_flag=\"0\" or (deferred_flag=\"1\" and deferred_date <= \"$today\"))");
$ucevents=array();
while ($uceventrow=mysqli_fetch_assoc($uceventsqry)) {

View File

@@ -2,7 +2,7 @@
/*
gpl.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -2,7 +2,7 @@
/*
logentry.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
@@ -18,22 +18,20 @@ $isadmin=dblookup($db,"techs","techid","admin",$techid);
$efftechid=$_REQUEST['efftechid'] ?? NULL;
$noteid=$_REQUEST['noteid'] ?? NULL;
$print=$_REQUEST['print'] ?? NULL;
$refto=$_REQUEST['refto'] ?? NULL;
$date=$_REQUEST['date'] ?? NULL;
$time=$_REQUEST['time'] ?? NULL;
$note=$_REQUEST['note'] ?? NULL;
$shift=$_REQUEST['shift'] ?? NULL;
$subject=$_REQUEST['subject'] ?? NULL;
$refs=$_REQUEST['refs'] ?? NULL;
$refstring=$_REQUEST['refstring'] ?? NULL;
$refto=$_REQUEST['refto'] ?? NULL;
$submit=$_REQUEST['submit'] ?? NULL;
$add=$_REQUEST['add'] ?? NULL;
$edit=$_REQUEST['edit'] ?? NULL;
$delete=$_REQUEST['delete'] ?? NULL;
$templateid=$_REQUEST['templateid'] ?? NULL;
$usertemplateid=$_REQUEST['usertemplateid'] ?? NULL;
$globaltemplateid=$_REQUEST['globaltemplateid'] ?? NULL;
$loadtemplate=$_REQUEST['loadtemplate'] ?? NULL;
$savetemplate=$_REQUEST['savetemplate'] ?? NULL;
$copytemplate=$_REQUEST['copytemplate'] ?? NULL;
$deltemplate=$_REQUEST['deltemplate'] ?? NULL;
$templatename=$_REQUEST['templatename'] ?? NULL;
$removepart=$_REQUEST['removepart'] ?? NULL;
$syncflags=$_REQUEST['syncflags'] ?? NULL;
@@ -63,23 +61,36 @@ if ($print=="Printer Friendly") {
}
if ($partview) $edit=1;
if (!$add && !$edit && !$delete && !$submit) $add=1;
if ($isadmin) {
$authorized=TRUE;
} else {
$authorized=FALSE;
}
if ($add) {
framework("begin","$logname","Note Entry",$print);
$authorized=1;
$authorized=TRUE;
}
if ($edit || $delete) {
framework("begin","$logname","Note Edit",$print);
$owner=dblookup($db,"lognotes","lognoteid","tech",$noteid);
if (($techid==$owner) || $isadmin) $authorized=1;
if ($techid==$owner) $authorized=TRUE;
}
// var_dump($_REQUEST);
// ******** begin database manipulation ********
// determine today's date and make it the default
$today=mysqli_fetch_row(mysqli_query($db,"select current_date"))[0];
$now=mysqli_fetch_row(mysqli_query($db,"select current_time"))[0];
if ($usertemplateid) {
$templateid=$usertemplateid;
} else if ($globaltemplateid) {
$templateid=$globaltemplateid;
} else {
$templateid=NULL;
$loadtemplate=NULL;
}
if ($add) {
if ($submit) {
// add the entry if submit is pressed
@@ -103,9 +114,12 @@ if ($add) {
$note=strip_tags($note,"<a>");
$note=mysqli_real_escape_string($db,$note);
// remove cruft from references and sanitize
$refs=preg_replace("#[a-zA-Z]{1,}#","",$refs);
$refs=mysqli_real_escape_string($db,$refs);
if (strlen($refstring)) {
// remove everything except numbers and spaces from references and sanitize
$refstring=preg_replace("#[^\d ]{1,}#"," ",$refstring);
$refstring=mysqli_real_escape_string($db,$refstring);
$refstring=trim($refstring);
}
if ($doparts==1) {
// inspect part data
@@ -140,19 +154,29 @@ if ($add) {
}
if ($authorized) {
// add the record to lognotes
mysqli_query($db,"insert into lognotes(date,time,shift,tech,subject,lognote,refs) values (\"$date\", \"$time\", \"$shift\",\"$efftechid\",\"$subject\",\"$note\",\"$refs\")");
mysqli_query($db,"insert into lognotes(date,time,shift,tech,subject,lognote) values (\"$date\", \"$time\", \"$shift\",\"$efftechid\",\"$subject\",\"$note\")");
$newnoteid=mysqli_insert_id($db);
// add this noteid to the appropriate flag_tables
// add references to the reflinks table
if (strlen($refstring)) {
$refstring=trim($refstring);
$refarray=explode(" ",$refstring);
foreach ($refarray as $target) {
mysqli_query($db,"insert into reflinks(noteid,target) values($newnoteid,$target)");
}
}
$chainmembers=generate_chain($newnoteid);
foreach ($flags as $flagtblnum) {
$flagtblname="flag_".$flagtblnum;
// update the flagmap table
foreach ($flags as $thisflag) {
// set flag for this note
mysqli_query($db,"insert into $flagtblname(target,id) values(\"lognotes\",\"$newnoteid\")");
mysqli_query($db,"insert into flagmap(flagid,lognoteid) values(\"$thisflag\",\"$newnoteid\")");
if ($syncflags) {
//set flag for reference chain notes
foreach ($chainmembers as $refdnote) {
mysqli_query($db,"insert into $flagtblname(target,id) values(\"lognotes\",\"$refdnote\")");
if ($refdnote != $newnoteid) {
mysqli_query($db,"insert into flagmap(flagid,lognoteid) values(\"$thisflag\",\"$refdnote\")");
}
}
}
}
@@ -223,98 +247,18 @@ if ($add) {
}
}
}
} elseif ($loadtemplate) {
if ($templateid) {
} else {
if ($loadtemplate) {
$templatevalues=mysqli_fetch_assoc(mysqli_query($db,"select * from notetemplates where templateid=\"$templateid\""));
$defaultshift=$templatevalues["shift"];
$defaultsubject=$templatevalues["subject"];
$note=$templatevalues["lognote"];
$refto=$templatevalues["refs"];
$techid=$templatevalues["tech"];
}
} elseif ($savetemplate) {
if ($note) {
// remove cruft from note text
$note=strip_tags($note,"<a>");
$note=mysqli_real_escape_string($db,$note);
// remove cruft from references
$refs=preg_replace("#[a-zA-Z]{1,}#","",$refs);
if ($authorized) {
if ($templateid) {
// update the existing template
mysqli_query($db,"update notetemplates set templatename=\"$templatename\", shift=\"$shift\", subject=\"$subject\", lognote=\"$note\", refs=\"$refs\" where templateid=\"$templateid\"");
// update the flag_ tables
$flagids=mysqli_query($db,"select flagid from flags");
while ($thisflagid=mysqli_fetch_row($flagids)) {
$thisflag_tbl="flag_".$thisflagid[0];
if (in_array($thisflagid[0],$flags)) {
if(!mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"notetemplates\" and id=\"$templateid\""))) {
mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"notetemplates\",\"$templateid\")");
}
} else {
if(mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"notetemplates\" and id=\"$templateid\""))) {
mysqli_query($db,"delete from $thisflag_tbl where target=\"notetemplates\" and id=\"$templateid\"");
$refstringqry=mysqli_query($db,"select target from reflinks where templateid=\"$templateid\"");
while ($thistgt=mysqli_fetch_row($refstringqry)) {
$refstring=$refstring." ".$thistgt[0];
}
}
}
} else {
// check if supplied name already exists
if (! mysqli_num_rows(mysqli_query($db,"select templateid from notetemplates where templatename=\"$templatename\""))) {
// add the record to notetemplates
mysqli_query($db,"insert into notetemplates(templatename,shift,tech,subject,lognote,refs) values (\"$templatename\", \"$shift\",\"$techid\",\"$subject\",\"$note\",\"$refs\")");
$newtemplateid=mysqli_insert_id($db);
// add this templateid to the appropriate flag_tables
foreach ($flags as $flagtblnum) {
$flagtblname="flag_".$flagtblnum;
mysqli_query($db,"insert into $flagtblname(target,id) values(\"notetemplates\",\"$newtemplateid\")");
}
$templateid=$newtemplateid;
} else {
$save_nameexists=TRUE;
}
}
}
}
} elseif ($copytemplate) {
if ($note) {
// remove cruft from note text
$note=strip_tags($note,"<a>");
$note=mysqli_real_escape_string($db,$note);
// remove cruft from references
$refs=preg_replace("#[a-zA-Z]{1,}#","",$refs);
if ($authorized) {
// check if supplied name already exists
if (! mysqli_num_rows(mysqli_query($db,"select templateid from notetemplates where templatename=\"$templatename\""))) {
// add the record to notetemplates
mysqli_query($db,"insert into notetemplates(templatename,shift,tech,subject,lognote,refs) values (\"$templatename\", \"$shift\",\"$techid\",\"$subject\",\"$note\",\"$refs\")");
$newtemplateid=mysqli_insert_id($db);
// add this templateid to the appropriate flag_tables
foreach ($flags as $flagtblnum) {
$flagtblname="flag_".$flagtblnum;
mysqli_query($db,"insert into $flagtblname(target,id) values(\"notetemplates\",\"$newtemplateid\")");
}
$templateid=$newtemplateid;
} else {
$copy_nameexists=TRUE;
}
}
}
} elseif ($deltemplate) {
// delete from notetemplates table
mysqli_query($db,"delete from notetemplates where templateid=\"$templateid\"");
// delete occurances from the flag_ tables
$flagids=mysqli_query($db,"select flagid from flags");
while ($thisflagid=mysqli_fetch_row($flagids)) {
$delflag_tbl="flag_".$thisflagid[0];
mysqli_query($db,"delete from $delflag_tbl where target=\"notetemplates\" and id=\"$templateid\"");
}
unset($templateid);
}
}
if ($edit) {
if ($removepart && $authorized) mysqli_query($db,"delete from logparts where lognoteid=\"$noteid\" and logpartid=\"$removepart\"");
@@ -325,7 +269,10 @@ if ($edit) {
$note=mysqli_real_escape_string($db,$note);
// remove cruft from references
$refs=preg_replace("#[a-zA-Z]{1,}#","",$refs);
if (strlen($refstring)) {
$refstring=trim($refstring);
$refstring=preg_replace("#[a-zA-Z]{1,}#","",$refstring);
}
if ($doparts==1) {
// inspect part data
@@ -361,30 +308,37 @@ if ($edit) {
if ($authorized) {
// update lognotes table
mysqli_query($db,"update lognotes set date=\"$date\", time=\"$time\", shift=\"$shift\", tech=\"$efftechid\", subject=\"$subject\", lognote=\"$note\", refs=\"$refs\" where lognoteid=\"$noteid\"");
mysqli_query($db,"update lognotes set date=\"$date\", time=\"$time\", shift=\"$shift\", tech=\"$efftechid\", subject=\"$subject\", lognote=\"$note\" where lognoteid=\"$noteid\"");
// update the flag_tables
$flagids=mysqli_query($db,"select flagid from flags");
// update the reflinks table
mysqli_query($db,"delete from reflinks where noteid=\"$noteid\"");
if (strlen($refstring)) {
$refstring=trim($refstring);
$refarray=explode(" ",$refstring);
foreach($refarray as $thisref) {
mysqli_query($db,"insert into reflinks(noteid,target) values(\"$noteid\",\"$thisref\")");
}
}
$chainmembers=generate_chain($noteid);
while ($thisflagid=mysqli_fetch_row($flagids)) {
$thisflag_tbl="flag_".$thisflagid[0];
if (in_array($thisflagid[0],$flags)) {
if(!mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"lognotes\" and id=\"$noteid\""))) {
// set flag for this noteid
mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"lognotes\",\"$noteid\")");
// set flag for reference chain notes
// update the flagmap table
mysqli_query($db,"delete from flagmap where lognoteid=\"$noteid\"");
if ($syncflags) {
foreach ($chainmembers as $refdnote) {
if(!mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"lognotes\" and id=\"$refdnote\""))) {
mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"lognotes\",\"$refdnote\")");
if ($refdnote != $noteid) {
mysqli_query($db,"delete from flagmap where lognoteid=\"$refdnote\"");
}
}
}
foreach ($flags as $thisflag) {
// set flag for this note
mysqli_query($db,"insert into flagmap(flagid,lognoteid) values(\"$thisflag\",\"$noteid\")");
if ($syncflags) {
//set flag for reference chain notes
foreach ($chainmembers as $refdnote) {
if ($refdnote != $noteid) {
mysqli_query($db,"insert into flagmap(flagid,lognoteid) values(\"$thisflag\",\"$refdnote\")");
}
} else {
if(mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"lognotes\" and id=\"$noteid\""))) {
// clear flag for this note
mysqli_query($db,"delete from $thisflag_tbl where target=\"lognotes\" and id=\"$noteid\"");
}
}
}
@@ -450,25 +404,48 @@ if ($edit) {
} else {
// no part info was entered
;
}
}
}
}
}
}
if ($loadtemplate) {
// get the note in question from the selected template
$getnote=mysqli_query($db,"select * from notetemplates where templateid=\"$templateid\"");
} else {
// refresh the note in question from the database
$getnote=mysqli_query($db,"select * from lognotes where lognoteid=\"$noteid\"");
}
$notetoedit=mysqli_fetch_assoc($getnote);
}
if ($delete) {
// find notes having this note as a target
$drefnoteqry=mysqli_query($db,"select noteid from reflinks where target=\"$noteid\"");
while ($drefnoterow=mysqli_fetch_assoc($drefnoteqry)) {
$drefnotes[]=$drefnoterow["noteid"];
}
// find targets for this note
$dreftgtqry=mysqli_query($db,"select target from reflinks where noteid=\"$noteid\"");
while ($dreftgtrow=mysqli_fetch_assoc($dreftgtqry)) {
$dreftgts[]=$dreftgtrow["target"];
}
// for every note having this one as a target, add this note's targets
foreach ($drefnotes as $drefnote) {
foreach ($dreftgts as $dreftgt) {
mysqli_query($db,"insert into reflinks(noteid,target) values(\"$drefnote\",\"$dreftgt\")");
}
}
// delete this note from reflinks
mysqli_query($db,"delete from reflinks where noteid is not null and (noteid=\"$noteid\" or target=\"$noteid\")");
// delete from lognotes table
mysqli_query($db,"delete from lognotes where lognoteid=\"$noteid\"");
// delete occurances from the flag_ tables
$flagids=mysqli_query($db,"select flagid from flags");
while ($thisflagid=mysqli_fetch_row($flagids)) {
$delflag_tbl="flag_".$thisflagid[0];
mysqli_query($db,"delete from $delflag_tbl where target=\"lognotes\" and id=\"$noteid\"");
}
// delete occurances from the flagmap table
mysqli_query($db,"delete from flagmap where lognoteid=\"$noteid\"");
// delete occurances from the logparts table
mysqli_query($db,"delete from logparts where lognoteid=\"$noteid\"");
}
@@ -489,17 +466,23 @@ if ($add) {
$notetime=$now;
}
if ($edit || $delete) {
$notedate=$notetoedit["date"];
$notetime=$notetoedit["time"];
$notedate=$notetoedit["date"] ?? $today;
$notetime=$notetoedit["time"] ?? $now;
$defaultshift=$notetoedit["shift"];
$defaultsubject=$notetoedit["subject"];
$note=$notetoedit["lognote"];
$refto=$notetoedit["refs"];
// generate reference string for this note
if ($submit) {
$refstring=NULL;
}
$refstringqry=mysqli_query($db,"select target from reflinks where noteid=\"$noteid\"");
while ($thistgt=mysqli_fetch_row($refstringqry)) {
$refstring=$refstring." ".$thistgt[0];
}
$techid=$notetoedit["tech"];
}
$techname=dblookup($db,"techs","techid","techname",$techid);
$copy_nameexists=$copy_nameexists ?? NULL;
$save_nameexists=$save_nameexists ?? NULL;
if ($submit) {
if ($note) {
if ($add) {
@@ -515,54 +498,64 @@ if ($submit) {
if ($delete) {
format_message(0,"<strong>Note deleted.</strong> <a href=\"lognotes.php\">Return to main page.</a>");
}
if ($copy_nameexists) {
format_message(1,"Template copy failed because the name you supplied already exists.");
}
if ($save_nameexists) {
format_message(1,"Template save failed because the name you supplied already exists.");
}
echo "
<form method=\"post\" action=\"logentry.php\">
";
if ($_SESSION['login']) {
// generate template line
echo "
<table border=\"0\" cellpadding=\"10\"><tr><td>
<select name=\"templateid\" title=\"Select the template you'd like to load and click the Load Template button.\">
<table border=\"0\" cellpadding=\"10\"><tr>
";
if ($loadtemplate) $templatename=dblookup($db,"notetemplates","templateid","templatename",$templateid);
// list user templates
echo "
<td>
<select name=\"usertemplateid\" title=\"Select the user template you'd like to load and click the Load Template button. User template selection takes precedence.\">
";
if ($loadtemplate) $templatename=dblookup($db,"notetemplates","templateid","templatename",$usertemplateid);
$templaterow=mysqli_query($db,"select * from notetemplates where tech=\"$techid\" order by templatename asc");
if ($loadtemplate) {
printf("<option value=\"%s\">%s</option>","0","Select template");
printf("<option value=\"%s\">%s</option>","0","Select user template");
} else {
printf("<option value=\"%s\" selected>%s</option>","0","Select template");
printf("<option value=\"%s\" selected>%s</option>","0","Select user template");
}
while ($templateitem=mysqli_fetch_assoc($templaterow)) {
if ($loadtemplate && ($templateitem["templateid"] == $templateid)) {
if ($loadtemplate && ($templateitem["templateid"] == $usertemplateid)) {
printf("<option value=\"%s\" selected>%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
} else {
printf("<option value=\"%s\">%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
}
}
echo "
</select>&nbsp;&nbsp;<input type=\"submit\" name=\"loadtemplate\" value=\"Load Template\">
</td><td>
<input type=\"submit\" name=\"savetemplate\" value=\"Save As:\" title=\"Enter the name you'd like to use in the field to the right.\">&nbsp;
<input type=\"text\" size=\"25\" name=\"templatename\" value=\"$templatename\" title=\"Name of the template you'd like to save or modify\">
</td>
</select>&nbsp;or&nbsp;
";
// list global templates
echo "
<select name=\"globaltemplateid\" title=\"Select the global template you'd like to load and click the Load Template button. User template selection takes precedence.\">
";
if ($loadtemplate) $templatename=dblookup($db,"notetemplates","templateid","templatename",$globaltemplateid);
$templaterow=mysqli_query($db,"select * from notetemplates where tech=\"0\" order by templatename asc");
if ($loadtemplate) {
echo "
<!-- <input type=\"hidden\" name=\"templateid\" value=\"$templateid\"> -->
<td>
<input type=\"submit\" name=\"deltemplate\" value=\"Delete\" title=\"Delete the template whose name is shown in the field to the left.\">
<input type=\"submit\" name=\"copytemplate\" value=\"Copy\" title=\"Copy the template whose data is shown below to the new name in the field to the left.\">
</td>
";
printf("<option value=\"%s\">%s</option>","0","Select global template");
} else {
printf("<option value=\"%s\" selected>%s</option>","0","Select global template");
}
while ($templateitem=mysqli_fetch_assoc($templaterow)) {
if ($loadtemplate && ($templateitem["templateid"] == $globaltemplateid)) {
printf("<option value=\"%s\" selected>%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
} else {
printf("<option value=\"%s\">%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
}
}
echo "
</select>&nbsp;&nbsp;
";
// show load button
echo "
<input type=\"submit\" name=\"loadtemplate\" value=\"Load Template\">
</td>
<td>
<a href=\"templates.php\">Manage templates</a>
</td>
</tr></table>
<hr>
";
@@ -642,28 +635,32 @@ echo "
</select></td>
</tr></table>
<b>Note:</b>&nbsp;<img src=\"icons/question.png\" title=\"Enter note text below. To insert a link to a web page, enter it in the link field below the Note box and click Insert Link. \"><br>
<b>Note:</b>&nbsp;<img src=\"icons/question.png\" title=\"Enter note text below. To insert a link to a web page, enter it's info in the link fields below the Note box and click Insert Link. You must provide the URL, but the link text is optional. \"><br>
<textarea rows=\"10\" cols=\"60\" name=\"note\" id=\"notetextarea\" wrap=\"soft\">";
if ($edit || $templateid || $schedmaintcomplete) echo "$note";
if ($edit || $usertemplateid || $globaltemplateid || $schedmaintcomplete) echo "$note";
echo "</textarea><br>
<input type=\"text\" size=\"50\" id=\"linktextfield\" placeholder=\"Enter a URL to insert here\">&nbsp;<a href=\"#\" onclick=\"insertUrlAtCaret('notetextarea','linktextfield');return false;\">Insert Link</a><br>
<input type=\"text\" size=\"23\" id=\"linktextfield\" placeholder=\"Enter link text here\">&nbsp;
<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>
";
// get an array of flagids set for this noteid
// create an array called theseflags of flagids set for this noteid
$allflags=mysqli_query($db,"select flagid from flags");
unset($theseflags);
$theseflags=[];
while ($thisflag=mysqli_fetch_row($allflags)) {
$thisflagtbl="flag_".$thisflag[0];
if ($templateid) {
if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"notetemplates\" and id=\"$templateid\""))) {
if (mysqli_num_rows(mysqli_query($db,"select id from flagmap where flagid=\"$thisflag[0]\" and notetemplateid=\"$templateid\""))) {
$theseflags[]=$thisflag[0];
}
} else {
if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"lognotes\" and id=\"$noteid\""))) {
if (mysqli_num_rows(mysqli_query($db,"select id from flagmap where flagid=\"$thisflag[0]\" and lognoteid=\"$noteid\""))) {
$theseflags[]=$thisflag[0];
}
}
}
// if adding a note/template, only show active flags, otherwise, show all flags
if ($add) {
$flagslist=mysqli_query($db,"select * from flags where status=1");
} else {
@@ -671,6 +668,8 @@ if ($add) {
}
$flagsperline=8;
$flagcount=1;
// display checkboxes for all the flags, selecting the ones that are set for this note/template
while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) {
if (in_array($flagcheckbox["flagid"],$theseflags)) {
@@ -693,8 +692,12 @@ while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) {
}
echo "
<br><input type=\"checkbox\" name=\"syncflags\" value=\"1\"><font title=\"Set the selected flags on the other notes in the reference chain\">Set flags on reference chain</font>
";
if ($add && $refto) $refstring=$refto;
echo "
<br><br><b>References: </b>&nbsp;
<input type=\"text\" name=\"refs\" size=\"20\" value=\"$refto\" title=\"One or more Note ID numbers separated by commas\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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 ($add) {

View File

@@ -2,7 +2,7 @@
/*
login.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -2,7 +2,7 @@
/*
lognotes.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
@@ -29,7 +29,6 @@ if ($print) {
}
// use default date values if not supplied
$today=mysqli_fetch_row(mysqli_query($db,"select current_date"))[0];
if ($tgt_date=="") $tgt_date=$today;
// define shifttable_classic function
@@ -43,14 +42,14 @@ function shifttable_classic($shift, $tgt_date, $db) {
if ($dshdr) {
// print the shift header
printf("<b><font size=\"+1\">%s</font></b>\n",$shname);
$note=mysqli_query($db,"select lognoteid,tech,subject,lognote,refs,time from lognotes where date=\"$tgt_date\" and shift=\"$shift\" order by time asc");
$note=mysqli_query($db,"select lognoteid,tech,subject,lognote,time from lognotes where date=\"$tgt_date\" and shift=\"$shift\" order by time asc");
echo "<br><table border=\"1\" width=\"100%\">\n";
echo "<tr><th width=\"70\">Note ID</th><th width=\"70\">Tech</th><th width=\"100\">Subject</th><th>Note</th><th width=\"70\">References</th></tr>\n";
while ($tablerow = mysqli_fetch_assoc($note)) {
$reftonote=$tablerow["lognoteid"];
$refs="&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"logentry.php?add=1&refto=$reftonote\"><img src=\"icons/plus.png\" border=\"0\" title=\"Add referring note\" alt=\"Add referring note\"></a>";
if (islink($tablerow["lognoteid"])) {
$refs=$refs."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"refchain.php?chainnote=$reftonote\"><img src=\"icons/magnifier--arrow.png\" border=\"0\" title=\"View reference chain\" alt=\"View reference chain\"></a>";
$thisnote=$tablerow["lognoteid"];
$refs="&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"logentry.php?add=1&refto=$thisnote\"><img src=\"icons/plus.png\" border=\"0\" title=\"Add referring note\" alt=\"Add referring note\"></a>";
if (islink($thisnote)) {
$refs=$refs."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"refchain.php?chainnote=$thisnote\"><img src=\"icons/magnifier--arrow.png\" border=\"0\" title=\"View reference chain\" alt=\"View reference chain\"></a>";
}
// convert tech number to name
$tname=dblookup($db,"techs","techid","techname",$tablerow["tech"]);
@@ -60,27 +59,24 @@ function shifttable_classic($shift, $tgt_date, $db) {
$fmtnote=convertweblinks($tablerow["lognote"]);
// generate the flags string
$flagstring="";
$allflagqry=mysqli_query($db,"select flagid from flags");
while ($allflagids=mysqli_fetch_row($allflagqry)) {
$flagid=$allflagids[0];
$flag_tbl="flag_".$flagid;
if (mysqli_num_rows(mysqli_query($db,"select id from $flag_tbl where target=\"lognotes\" and id=\"$reftonote\""))) {
$flagparam=mysqli_fetch_assoc(mysqli_query($db,"select * from flags where flagid=\"$flagid\""));
$flagcolor=$flagparam["flagcolor"];
$flagsym=$flagparam["flagsym"];
$flagname=$flagparam["flagname"];
$flagqry=mysqli_query($db,"select flagid from flagmap where lognoteid=$thisnote");
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>";
}
if ($doparts) {
// turn on the parts indicator if parts were entered with the note
if (mysqli_num_rows(mysqli_query($db,"select logpartid from logparts where lognoteid=\"$reftonote\""))) {
$fmtnote=$fmtnote."<a href=\"logentry.php?partview=1&noteid=$reftonote\">PARTS</a>";
if (mysqli_num_rows(mysqli_query($db,"select logpartid from logparts where lognoteid=\"$thisnote\""))) {
$fmtnote=$fmtnote."<a href=\"logentry.php?partview=1&noteid=$thisnote\">PARTS</a>";
}
}
// now print the line in the table
@@ -135,14 +131,14 @@ function shifttable_clean($shift, $tgt_date, $db) {
if ($dshdr) {
// print the shift header
printf("<b><font size=\"+1\">%s</font></b>\n",$shname);
$note=mysqli_query($db,"select lognoteid,tech,subject,lognote,refs,time from lognotes where date=\"$tgt_date\" and shift=\"$shift\" order by time asc");
$note=mysqli_query($db,"select lognoteid,tech,subject,lognote,time from lognotes where date=\"$tgt_date\" and shift=\"$shift\" order by time asc");
echo "<br><br>";
echo "<table border=\"0\" width=\"100%\"><tr><td>\n";
while ($tablerow = mysqli_fetch_assoc($note)) {
$reftonote=$tablerow["lognoteid"];
$refs="&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"logentry.php?add=1&refto=$reftonote\"><img src=\"icons/plus.png\" border=\"0\" title=\"Add referring note\" alt=\"Add referring note\"></a>";
$thisnote=$tablerow["lognoteid"];
$refs="&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"logentry.php?add=1&refto=$thisnote\"><img src=\"icons/plus.png\" border=\"0\" title=\"Add referring note\" alt=\"Add referring note\"></a>";
if (islink($tablerow["lognoteid"])) {
$refs=$refs."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"refchain.php?chainnote=$reftonote\"><img src=\"icons/magnifier--arrow.png\" border=\"0\" title=\"View reference chain\" alt=\"View reference chain\"></a>";
$refs=$refs."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"refchain.php?chainnote=$thisnote\"><img src=\"icons/magnifier--arrow.png\" border=\"0\" title=\"View reference chain\" alt=\"View reference chain\"></a>";
}
// convert tech number to name
$tname=dblookup($db,"techs","techid","techname",$tablerow["tech"]);
@@ -152,18 +148,14 @@ function shifttable_clean($shift, $tgt_date, $db) {
$fmtnote=convertweblinks($tablerow["lognote"]);
// generate the flags string
$flagstring="";
$allflagqry=mysqli_query($db,"select flagid from flags");
while ($allflagids=mysqli_fetch_row($allflagqry)) {
$flagid=$allflagids[0];
$flag_tbl="flag_".$flagid;
if (mysqli_num_rows(mysqli_query($db,"select id from $flag_tbl where target=\"lognotes\" and id=\"$reftonote\""))) {
$flagparam=mysqli_fetch_assoc(mysqli_query($db,"select * from flags where flagid=\"$flagid\""));
$flagcolor=$flagparam["flagcolor"];
$flagsym=$flagparam["flagsym"];
$flagname=$flagparam["flagname"];
$flagqry=mysqli_query($db,"select flagid from flagmap where lognoteid=$thisnote");
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 {
@@ -171,8 +163,8 @@ function shifttable_clean($shift, $tgt_date, $db) {
}
if ($doparts) {
// turn on the parts indicator if parts were entered with the note
if (mysqli_num_rows(mysqli_query($db,"select logpartid from logparts where lognoteid=\"$reftonote\""))) {
$fmtnote=$fmtnote."<a href=\"logentry.php?edit=1&noteid=$reftonote\" title=\"Click here to see note and parts data.\">PARTS</a>";
if (mysqli_num_rows(mysqli_query($db,"select logpartid from logparts where lognoteid=\"$thisnote\""))) {
$fmtnote=$fmtnote."<a href=\"logentry.php?edit=1&noteid=$thisnote\" title=\"Click here to see note and parts data.\">PARTS</a>";
}
}
// now print the line in the table

View File

@@ -2,7 +2,7 @@
/*
maintform.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -2,7 +2,7 @@
/*
maintformentry.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
@@ -104,9 +104,6 @@ if ($printfmt) {
}
// ******** begin database manipulation ********
// determine today's date and make it the default
$today=mysqli_fetch_row(mysqli_query($db,"select current_date"))[0];
$now=mysqli_fetch_row(mysqli_query($db,"select current_time"))[0];
//var_dump($_REQUEST);
@@ -146,9 +143,7 @@ if ($mfadd) {
}
// remove cruft from malfunction text
$mfmalfunction=htmlentities($mfmalfunction);
if (!get_magic_quotes_gpc()) {
$mfmalfunction=addslashes($mfmalfunction);
}
if ($mfauthorized) {
$partdatainput=array();
@@ -170,6 +165,8 @@ if ($mfadd) {
if ($uid =="" || $partnum == "" || $sernum == "") {
// have the maintenance form stay pending due to incomplete part data
$pending=1;
} else {
$pending=0;
}
// add the record to maintforms
@@ -195,13 +192,14 @@ if ($mfedit) {
if ($mfmalfunction && ($uid || ($partnum && $sernum))) {
// remove cruft from malfunction text
$mfmalfunction=htmlentities($mfmalfunction);
if (!get_magic_quotes_gpc()) {
$mfmalfunction=addslashes($mfmalfunction);
}
// update parts table
if ($uid =="" || $partnum == "" || $sernum == "") {
// have the maintenance form stay pending due to incomplete part data
$pending=1;
} else {
$pending=0;
}
if (! $pdatamismatch) {
mysqli_query($db,"update parts set uid=\"$uid\", partnum=\"$partnum\", sernum=\"$sernum\", partname=\"$partname\" where partid=\"$mfpart\"");
@@ -215,6 +213,7 @@ if ($mfedit) {
$flagids=mysqli_query($db,"select flagid from flags");
while ($thisflagid=mysqli_fetch_row($flagids)) {
$thisflag_tbl="flag_".$thisflagid[0];
if ($flags[0]=="") $flags=[];
if (in_array($thisflagid[0],$flags)) {
if(!mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"maintforms\" and id=\"$maintformid\""))) {
mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"maintforms\",\"$maintformid\")");
@@ -256,9 +255,7 @@ if ($actionadd) {
}
// remove cruft from action text
$action=htmlentities($action);
if (!get_magic_quotes_gpc()) {
$action=addslashes($action);
}
// add to maintactions table
mysqli_query($db,"insert into maintactions (actiondate,actiontime,maintformnum,actiontech,action)
@@ -273,9 +270,8 @@ if ($actionedit) {
// update the action
// remove cruft from action text
$action=htmlentities($action);
if (!get_magic_quotes_gpc()) {
$action=addslashes($action);
}
// update maintactions table
mysqli_query($db,"update maintactions set actiondate=\"$actiondate\", actiontime=\"$actiontime\", action=\"$action\" where maintactionid=\"$maintactionid\"");
}
@@ -399,6 +395,7 @@ if ($printfmt) {
}
$flagslist=mysqli_query($db,"select * from flags");
while ($flagsymbol=mysqli_fetch_assoc($flagslist)) {
if ($theseflags[0]=="") $theseflags=[];
if (in_array($flagsymbol["flagid"],$theseflags)) {
echo $flagsymbol['flagsym']."&nbsp;&nbsp;";
}
@@ -491,6 +488,7 @@ if ($printfmt) {
$flagsperline=8;
$flagcount=1;
while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) {
if ($theseflags[0]=="") $theseflags=[];
if (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"]);

View File

@@ -2,7 +2,7 @@
/*
partentry.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -2,7 +2,7 @@
/*
parts.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -2,7 +2,7 @@
/*
profile.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/

View File

@@ -2,14 +2,14 @@
/*
refchain.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("functions.php");
$print=$_REQUEST['print'];
$print=$_REQUEST['print'] ?? "";
$chainnote=$_REQUEST['chainnote'];
$logname=LOG_NAME;
@@ -59,17 +59,29 @@ while($mptr<count($master)) {
$fmtnote=convertweblinks($tablerow["lognote"]);
// generate the flags string
$flagstring="";
$allflagqry=mysqli_query($db,"select flagid from flags");
while ($allflagids=mysqli_fetch_row($allflagqry)) {
$flagid=$allflagids[0];
$flag_tbl="flag_".$flagid;
if (mysqli_num_rows(mysqli_query($db,"select id from $flag_tbl where target=\"lognotes\" and id=\"$noteid\""))) {
$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;";
}
}
//$allflagqry=mysqli_query($db,"select flagid from flags");
//while ($allflagids=mysqli_fetch_row($allflagqry)) {
//$flagid=$allflagids[0];
//$flag_tbl="flag_".$flagid;
//if (mysqli_num_rows(mysqli_query($db,"select id from $flag_tbl where target=\"lognotes\" and id=\"$noteid\""))) {
//$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>

View File

@@ -2,7 +2,7 @@
/*
blankpage.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
@@ -14,50 +14,50 @@ if (isset($_SESSION['login'])) {
} else {
$loggedin=false;
}
$techid=$_SESSION['login'];
$techid=$_SESSION['login'] ?? NULL;
$isadmin=dblookup($db,"techs","techid","admin",$techid);
$upcoming=$_REQUEST['upcoming'];
$schedule=$_REQUEST['schedule'];
$tasks=$_REQUEST['tasks'];
$devices=$_REQUEST['devices'];
$action=$_REQUEST['action'];
$complete=$_REQUEST['complete'];
$defer=$_REQUEST['defer'];
$add=$_REQUEST['add'];
$edit=$_REQUEST['edit'];
$update=$_REQUEST['update'];
$delete=$_REQUEST['delete'];
$id=$_REQUEST['id'];
$active_flag=$_REQUEST['active_flag'];
$upcoming=$_REQUEST['upcoming'] ?? NULL;
$schedule=$_REQUEST['schedule'] ?? NULL;
$tasks=$_REQUEST['tasks'] ?? NULL;
$devices=$_REQUEST['devices'] ?? NULL;
$action=$_REQUEST['action'] ?? NULL;
$complete=$_REQUEST['complete'] ?? NULL;
$defer=$_REQUEST['defer'] ?? NULL;
$add=$_REQUEST['add'] ?? NULL;
$edit=$_REQUEST['edit'] ?? NULL;
$update=$_REQUEST['update'] ?? NULL;
$delete=$_REQUEST['delete'] ?? NULL;
$id=$_REQUEST['id'] ?? NULL;
$active_flag=$_REQUEST['active_flag'] ?? 0;
$devicename=$_REQUEST['devicename'];
$devicedesc=$_REQUEST['devicedesc'];
$group_flag=$_REQUEST['group_flag'];
$members=$_REQUEST['members'];
$devicename=$_REQUEST['devicename'] ?? NULL;
$devicedesc=$_REQUEST['devicedesc'] ?? NULL;
$group_flag=$_REQUEST['group_flag'] ?? 0;
$members=$_REQUEST['members'] ?? [];
$weekdays_only=$_REQUEST['weekdays_only'];
$nextdue_relative=$_REQUEST['nextdue_relative'];
$taskname=$_REQUEST['taskname'];
$taskdesc=$_REQUEST['taskdesc'];
$frequency=$_REQUEST['frequency'];
$period=$_REQUEST['period'];
$refdoc_name=$_REQUEST['refdoc_name'];
$refdoc_url=$_REQUEST['refdoc_url'];
$weekdays_only=$_REQUEST['weekdays_only'] ?? NULL;
$nextdue_relative=$_REQUEST['nextdue_relative'] ?? NULL;
$taskname=$_REQUEST['taskname'] ?? NULL;
$taskdesc=$_REQUEST['taskdesc'] ?? NULL;
$frequency=$_REQUEST['frequency'] ?? NULL;
$period=$_REQUEST['period'] ?? NULL;
$refdoc_name=$_REQUEST['refdoc_name'] ?? NULL;
$refdoc_url=$_REQUEST['refdoc_url'] ?? NULL;
$deferred_flag=$_REQUEST['deferred_flag'];
$deferred_date=$_REQUEST['deferred_date'];
$start_date=$_REQUEST['start_date'];
$last_date=$_REQUEST['last_date'];
$task=$_REQUEST['task'];
$device=$_REQUEST['device'];
$deferuntil=$_REQUEST['deferuntil'];
$completedate=$_REQUEST['completedate'];
$addlognote=$_REQUEST['addlognote'];
$deferred_flag=$_REQUEST['deferred_flag'] ?? 0;
$deferred_date=$_REQUEST['deferred_date'] ?? NULL;
$start_date=$_REQUEST['start_date'] ?? NULL;
$last_date=$_REQUEST['last_date'] ?? NULL;
$task=$_REQUEST['task'] ?? NULL;
$device=$_REQUEST['device'] ?? NULL;
$deferuntil=$_REQUEST['deferuntil'] ?? NULL;
$completedate=$_REQUEST['completedate'] ?? NULL;
$addlognote=$_REQUEST['addlognote'] ?? NULL;
$logname=LOG_NAME;
$print=$_REQUEST['print'];
$print=$_REQUEST['print'] ?? NULL;
if ($print) {
$sbcolor=P_SIDEBAR_COLOR;
@@ -67,7 +67,6 @@ if ($print) {
$mbgcolor=MENUBG_COLOR;
}
// **** BEGIN DATABASE OPERATIONS ****
$today=mysqli_fetch_row(mysqli_query($db,"select current_date"))[0];
$tomorrow=mysqli_fetch_row(mysqli_query($db,"select adddate((select current_date),1)"))[0];
$errorstack=array();
@@ -127,6 +126,9 @@ if ($add) {
}
// run through the memberlist and modify the table
foreach ($memberlist as $memberdev) {
if ($start_date==NULL) $start_date=$today;
if ($last_date==NULL) $last_date="0000-00-00";
if ($deferred_date==NULL) $deferred_date="0000-00-00";
$addqry=("insert into events(task,device,start_date,last_date,deferred_flag,deferred_date,active_flag)
values(\"$task\",\"$memberdev\",\"$start_date\",\"$last_date\",\"$deferred_flag\",\"$deferred_date\",\"$active_flag\")");
mysqli_query($db,$addqry);
@@ -201,6 +203,9 @@ if ($edit) {
$last_date=mysqli_real_escape_string($db,$last_date);
$deferred_date=mysqli_real_escape_string($db,$deferred_date);
// update the tasks table
if ($start_date==NULL) $start_date=$today;
if ($last_date==NULL) $last_date="0000-00-00";
if ($deferred_date==NULL) $deferred_date="0000-00-00";
mysqli_query($db,"update events
set task=\"$task\",device=\"$device\",start_date=\"$start_date\",last_date=\"$last_date\",deferred_flag=\"$deferred_flag\",
deferred_date=\"$deferred_date\",active_flag=\"$active_flag\"
@@ -401,7 +406,7 @@ if ($action) {
}
if ($start_date=="0000-00-00") $start_date=$today;
if ($last_date=="0000-00-00") $last_date="";
if ($deferred_date=="0000-00-00") $deferred_date="";
if ($deferred_date=="0000-00-00") $deferred_date=$tomorrow;
$deferuntiltag="<input type=\"text\" name=\"deferred_date\" id=\"deferdatepicker\" size=\"10\" maxlength=\"10\" value=\"$deferred_date\" title=\"Format: YYYY-MM-DD\">";
$startdatetag="<input type=\"text\" name=\"start_date\" id=\"startdatepicker\" size=\"10\" maxlength=\"10\" value=\"$start_date\" title=\"Format: YYYY-MM-DD\">";
$lastdatetag="<input type=\"text\" name=\"last_date\" id=\"completedatepicker\" size=\"10\" maxlength=\"10\" value=\"$last_date\" title=\"Format: YYYY-MM-DD\">";

View File

@@ -2,7 +2,7 @@
/*
search.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
@@ -58,20 +58,19 @@ framework("begin","$logname Search","Search",$print);
// ******** begin database manipulation ********
// get the date range of lognotes
$todaysdate = mysqli_fetch_row(mysqli_query($db,"select current_date"))[0];
$logdateqry=mysqli_query($db,"select min(date), max(date) from lognotes");
$logdateresults=mysqli_fetch_row($logdateqry);
$logmindate=$logdateresults[0];
if ($logmindate == "") $logmindate = $todaysdate;
if ($logmindate == "") $logmindate = $today;
$logmaxdate=$logdateresults[1];
if ($logmaxdate == "") $logmaxdate = $todaysdate;
if ($logmaxdate == "") $logmaxdate = $today;
// get the date range of maintenance forms
$mfdateqry=mysqli_query($db,"select min(mfdate), max(mfdate) from maintforms");
$mfdateresults=mysqli_fetch_row($mfdateqry);
$mfmindate=$mfdateresults[0];
if ($mfmindate == "") $mfmindate = $todaysdate;
if ($mfmindate == "") $mfmindate = $today;
$mfmaxdate=$mfdateresults[1];
if ($mfmaxdate == "") $mfmaxdate = $todaysdate;
if ($mfmaxdate == "") $mfmaxdate = $today;
// determine entire date range
$mindate=min($logmindate, $mfmindate);
$maxdate=max($logmaxdate, $mfmaxdate);
@@ -84,6 +83,7 @@ if ($search) {
$srchpname=trim($srchpname);
$srchploc=trim($srchploc);
$srchnha=trim($srchnha);
if ($target[0]=="") $target=[];
if (in_array("log",$target)) {
// define the query constraints
// log note id
@@ -188,6 +188,7 @@ if ($search) {
$logwhereclause=implode(" and ",$logconstraints);
$logrowqry=mysqli_query($db,"select lognotes.* from $logfromclause where $logwhereclause order by lognotes.date asc, lognotes.time asc");
}
if ($target[0]=="") $target=[];
if (in_array("maintform",$target)) {
// maintforms search
// define the query constraints
@@ -284,6 +285,7 @@ if ($search) {
$mfwhereclause=implode(" and ",$mfconstraints);
$mfrowqry=mysqli_query($db,"select maintforms.* from $mffromclause where $mfwhereclause order by maintforms.mfdate asc, maintforms.mftime asc");
}
if ($target[0]=="") $target=[];
if (in_array("part",$target)) {
// parts search
// define the query constraints
@@ -491,6 +493,7 @@ if (!$print) {
echo "
<b>Search in:</b>&nbsp;&nbsp;
";
if ($target[0]=="") $target=[];
if (in_array("log", $target)) {
echo "<input type=\"checkbox\" name=\"target[]\" value=\"log\" title=\"Search in Logbook\" checked>Logbook&nbsp;&nbsp;";
} else {
@@ -589,10 +592,13 @@ if (!$print) {
$flagsperline=8;
$flagcount=1;
while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) {
if ($srchflags) {
if ($srchflags[0]=="") $srchflags=[];
if (in_array($flagcheckbox["flagid"],$srchflags)) {
printf("<font color=\"%s\">%s</font>",
$flagcheckbox["flagcolor"],$flagcheckbox["flagsym"]);
}
}
if ($flagcount<$flagsperline) {
echo "&nbsp;&nbsp;&nbsp;";
$flagcount++;
@@ -605,6 +611,7 @@ if (!$print) {
<br><br>
";
if ($doparts) {
if ($target[0]=="") $target=[];
echo "
<b>Search in:</b>&nbsp;&nbsp;
";
@@ -627,6 +634,7 @@ if (!$print) {
}
if ($search) {
if ($target[0]=="") $target=[];
if (in_array("log",$target)) {
// run lognotes query and show results
if(mysqli_num_rows($logrowqry)) {
@@ -684,6 +692,7 @@ if ($search) {
echo "<font size=\"+1\">No Logbook notes match your search criteria.</font><br><hr>";
}
}
if ($target[0]=="") $target=[];
if (in_array("maintform",$target)) {
// run maintforms query and show results
if(mysqli_num_rows($mfrowqry)) {
@@ -746,6 +755,7 @@ if ($search) {
echo "<font size=\"+1\">No Maintenance Forms match your search criteria.</font><br><hr>";
}
}
if ($target[0]=="") $target=[];
if (in_array("part",$target)) {
// run parts query and show results
if(mysqli_num_rows($prowqry)) {

View File

@@ -2,11 +2,15 @@
/*
settings.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
// determine today's date and time and assign them to variables
$today = date("Y-m-d");
$now = date("H:i:s");
$sttl=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"session_ttl_days\""))[0];
$ostype=strtoupper(substr(php_uname('s'), 0, 3));
if ($ostype == 'WIN') {

605
distfiles/templates.php Normal file
View File

@@ -0,0 +1,605 @@
<?php
/*
templates.php
OpenLog Online Logbook
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("functions.php");
if (!$_SESSION['login'] && !$_REQUEST['partview']) {
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;
//$add=$_REQUEST['add'] ?? NULL;
//$edit=$_REQUEST['edit'] ?? NULL;
//$delete=$_REQUEST['delete'] ?? 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;
$defaultshift=dblookup($db,"techs","techid","shift",$techid);
if ($print=="Printer Friendly") {
$sbcolor=P_SIDEBAR_COLOR;
$mbgcolor=P_MENUBG_COLOR;
} else {
$sbcolor=SIDEBAR_COLOR;
$mbgcolor=MENUBG_COLOR;
}
framework("begin","$logname","Note Templates",$print);
// make basic determination about authorization
if ($isadmin) {
$authorized=TRUE;
} else if ($efftechid==$techid) {
$authorized=TRUE;
} else {
$authorized=FALSE;
}
var_dump($_REQUEST);
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);
if (mysqli_num_rows($templatequery)) {
$hastemplates=TRUE;
} else {
$hastemplates=FALSE;
}
echo "<b><font size=\"+1\">";
if ($hastemplates) {
// print the user header
if ($user=="0") {
echo "Global Templates</font></b>";
} else {
if ($user==$techid) {
echo "My templates</font></b>";
} else {
echo "Templates for $tblusername</font></b>";
}
}
// print the table
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"];
// 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."<font color=\"$flagcolor\" title=\"$flagname\">$flagsym</font>&nbsp;&nbsp;";
}
if ($flagstring) {
$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];
}
// now print the line in the table
if (!$isadmin && $user=="0") {
$nameblock="$templatename</a>";
} else {
$nameblock="<a href=\"templates.php?operation=edit&templateid=$templateid\">$templatename</a>";
}
printf(
"<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
);
};
echo "</table><br><hr><br>";
} else {
if ($user=="0") {
echo "There are no global templates</font></b>";
} else {
if ($user==$techid) {
echo "You have no templates</font></b>";
} else {
echo "$tblusername has no templates</font></b>";
}
}
echo "<br><hr>";
}
echo "<br>";
}
function templateselect($db,$techid,$operation) {
echo "
<form method=\"post\" action=\"templates.php\">
";
// generate template selection line
echo "
<table border=\"0\" cellpadding=\"10\"><tr>
";
// list user templates
echo "
<td>
<select name=\"usertemplateid\" title=\"Select the user template you'd like to load and click the Load Template button. User template selection takes precedence.\">
";
$templaterow=mysqli_query($db,"select * from notetemplates where tech=\"$techid\" order by templatename asc");
printf("<option value=\"%s\" selected>%s</option>","0","Select user template");
while ($templateitem=mysqli_fetch_assoc($templaterow)) {
printf("<option value=\"%s\">%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
}
echo "
</select>&nbsp;or&nbsp;
";
// list global templates
echo "
<select name=\"globaltemplateid\" title=\"Select the global template you'd like to load and click the Load Template button. User template selection takes precedence.\">
";
$templaterow=mysqli_query($db,"select * from notetemplates where tech=\"0\" order by templatename asc");
printf("<option value=\"%s\" selected>%s</option>","0","Select global template");
while ($templateitem=mysqli_fetch_assoc($templaterow)) {
printf("<option value=\"%s\">%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
}
echo "
</select>&nbsp;&nbsp;
";
// show load button
echo "
<input type=\"hidden\" name=\"operation\" value=\"$operation\">
<input type=\"submit\" name=\"loadtemplate\" value=\"Load Template\">
</td>
<td>
<a href=\"templates.php\">Manage templates</a>
</td>
</tr></table>
<hr>
</form>
";
}
// ******** begin database manipulation ********
if ($usertemplateid) {
$templateid=$usertemplateid;
} else if ($globaltemplateid) {
$templateid=$globaltemplateid;
} else {
$loadtemplate=NULL;
}
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 ($authorized) {
// check if name supplied
if ($templatename) {
$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\""))) {
// 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);
// update the flagmap table
foreach ($flags as $thisflag) {
// set flag for this note
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);
foreach ($refarray as $target) {
mysqli_query($db,"insert into reflinks(templateid,target) values($newtemplateid,$target)");
}
}
$templateid=$newtemplateid;
} else {
$nameexists=TRUE;
}
} else {
$namesupplied=FALSE;
}
}
}
}
}
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 ($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\"");
// update the flagmap table
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\")");
}
// update the reflinks table
mysqli_query($db,"delete from reflinks where templateid=\"$templateid\"");
if (strlen($refstring)) {
$refstring=trim($refstring);
$refarray=explode(" ",$refstring);
foreach ($refarray as $target) {
mysqli_query($db,"insert into reflinks(templateid,target) values($templateid,$target)");
}
}
}
}
}
}
if ($operation=="delete") {
if ($authorized) {
// update notetemplates
mysqli_query($db,"delete from notetemplates where templateid=\"$templateid\"");
// update the flagmap table
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;
}
}
}
// ******** end database manipulation ********
pagetable("begin");
if (!$print) {
pageblock("left","begin");
sidemenu();
pageblock("left","end");
}
pageblock("right","begin");
banner($print);
if ($submit || $operation=="delete") {
// show success/failure messages
$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;
}
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 (!$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 ($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") {
// 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 "
<br><b>$optext template</b><br><hr>
";
// show the template selection line
templateselect($db,$techid,$operation);
// start template entry section
echo "
<form method=\"post\" action=\"templates.php\">
<table border=\"0\" cellpadding=\"5\">
<tr><td colspan=\"2\"><b>Template Name: </b>&nbsp;
<input type=\"text\" name=\"templatename\" size=\"30\" value=\"$filltemplatename\" title=\"What you'd like to name the template.\"></td></tr>
";
if ($isadmin) {
echo "
<tr><td colspan=\"2\"><b>Tech: </b>&nbsp;
<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)) {
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 {
$authorized=TRUE;
echo "
<input type=\"hidden\" name=\"efftechid\" value=\"$techid\">
";
}
echo "
<tr>
<td><b>Shift: </b>&nbsp;
<select name=\"shift\">
";
$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"]);
} else {
printf("<option value=\"%s\">%s</option>",$shiftitem["shiftid"],$shiftitem["shiftname"]);
}
}
}
echo "
</select></td>
<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"]);
} else {
printf("<option value=\"%s\">%s</option>",$subjitem["subjectid"],$subjitem["subjectname"]);
}
}
}
echo "
</select></td>
</tr></table>
<b>Note:</b>&nbsp;<img src=\"icons/question.png\" title=\"Enter note text below. To insert a link to a web page, enter it's info in the link fields below the Note box and click Insert Link. You must provide the URL, but the link text is optional. \"><br>
<textarea rows=\"10\" cols=\"60\" name=\"note\" id=\"notetextarea\" wrap=\"soft\">$fillnote";
echo "</textarea><br>
<input type=\"text\" size=\"23\" id=\"linktextfield\" placeholder=\"Enter link text here\">&nbsp;
<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=[];
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];
}
}
}
$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"]);
} 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"]);
}
}
if ($flagcount<$flagsperline) {
echo "&nbsp;&nbsp;&nbsp;";
$flagcount++;
} else {
echo "<br>";
$flagcount=1;
}
}
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];
}
}
echo "
<br><br><b>References: </b>&nbsp;
<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) {
echo "
<input type=\"hidden\" name=\"operation\" value=\"add\">
<input type=\"submit\" name=\"submit\" value=\"Save Template\">
";
}
if ($operation=="edit" && $authorized) {
echo "
<input type=\"hidden\" name=\"operation\" value=\"edit\">
<input type=\"hidden\" name=\"templateid\" value=\"$templateid\">
<input type=\"submit\" name=\"submit\" value=\"Save Template\">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><br>
<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);
// 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);
?>

43
files-update.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
# files_update.sh
install_path=$1
# ---------- version 5.2.1 -------------
# No changes
# --------------------------------------
# ---------- version 5.2.2 -------------
# No changes
# --------------------------------------
# ---------- version 5.2.3 -------------
# No changes
# --------------------------------------
# ---------- version 5.2.4 -------------
# No changes
# --------------------------------------
# ---------- version 5.2.4.1 -----------
# No changes
# --------------------------------------
# ---------- version 5.2.4.2 -----------
# No changes
# --------------------------------------
# ---------- version 5.2.4.3 -----------
# Add AllowOverride Options to the apache conf-available file
install_loc=$(basename $install_path)
if ! grep -q "AllowOverride Options" /etc/apache2/conf-available/$install_loc.conf
then
sed -i '/^<Directory/a\ AllowOverride Options' /etc/apache2/conf-available/$install_loc.conf
systemctl reload apache2
fi
# --------------------------------------
# ---------- version 5.2.4.4 -----------
# No changes
# --------------------------------------

View File

@@ -8,21 +8,26 @@
APP_NAME="OpenLog"
DEFAULT_DB_NAME="openlog"
APP_VERSION="5.2.4"
APP_VERSION="5.3.0"
DOC_ROOT="/var/www"
INSTALL_LOC="openlog"
APACHE_USER="www-data"
APACHE_GROUP="www-data"
APACHE_CONF_DIR="/etc/apache2/conf-available"
BACKUP_DIR="openlog-previous-installation"
INDEX_FILE="lognotes.php"
LANDING_PAGE="lognotes.php"
CONFIG_TABLE="configs"
CONFIG_NAME_COLUMN="confname"
CONFIG_VALUE_COLUMN="confvalue"
CONFIG_DEFAULT_COLUMN=""
OFFER_OPTIONAL_PKGS=false
function privilege_check() {
# test for superuser rights
if [[ $EUID -ne 0 ]]; then
echo "This script must be run with superuser privileges. Try sudo $0"
exit 1
fi
}
function get_new_password() {
# Stores new password in the variable $newpassword
pwgood=false
@@ -105,11 +110,22 @@ function abort_exit() {
exit 1
}
function spinner() {
local pid="$1"
local delay="0.1"
local spinstr='|/-\\'
local i=0
while ps -p "$pid" > /dev/null; do
i=$(( (i+1) % 4 ))
printf "\r[%c]" "${spinstr:$i:1}"
sleep "$delay"
done
printf "\r \r" # Clear the spinner line
}
# test for superuser rights
if [[ $EUID -ne 0 ]]; then
echo "This script must be run with superuser privileges. Try sudo ./install.sh"
abort_exit
fi
privilege_check
echo ""
@@ -122,182 +138,28 @@ echo "Preparing for installation. Please wait..."
# Prevent unattended-upgrades from interfering
restart_uu=false
while systemctl status unattended-upgrades >/dev/null 2>&1
while dpkg -l|grep unattended-upgrades >/dev/null 2>&1
do
systemctl stop unattended-upgrades
sleep 5
restart_uu=true
done
apt-get update
apt-get update -qq
# Check for prerequisites and prompt to install
echo "Checking for required packages..."
echo ""
install_required_packages "apache2" "php" "mysql-server or mariadb-server" "uuid-runtime"
install_required_packages "apache2" "php" "mysql-server or mariadb-server" "php-mysql" "uuid-runtime"
echo ""
echo "Finished required package installation."
echo ""
if $OFFER_OPTIONAL_PKGS
then
# Check for optional packages and prompt to install
echo "Checking for optional packages..."
echo ""
echo "Checking for phpmyadmin installation..."
echo ""
if dpkg -l|grep phpmyadmin >/dev/null 2>&1
then
echo ""
echo "phpmyadmin is installed. Continuing."
echo ""
else
echo "phpmyadmin doesn't seem to be installed."
echo "It is an optional package that enables administration of the mysql/mariadb"
echo "database server using a friendly GUI. It is highly recommended."
echo "Note that this has the potential to be a security risk, especially"
echo "if your passwords aren't sufficiently strong."
echo -n "Install it now? [Y/n]: "
read reqinstall
if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ]
then
echo "Proceeding without installing phpmyadmin. Database administration"
echo "will require the use of the mysql/mariadb command line tools."
else
echo ""
echo "Proceeding with phpmyadmin installation"
echo ""
sleep 3
echo ""
echo "During the following installation of phpmyadmin:"
echo ""
echo "- Select apache2 as the web server to configure automatically."
echo ""
echo "- Choose Yes when prompted to install phpmyadmin database and allow it to"
echo " generate a random password(leave the field blank)."
echo ""
echo -n "Press enter to continue."
read continueok
echo ""
apt-get install -y phpmyadmin
echo ""
echo ""
echo "In order to log in to the database using phpmyadmin, there must be a"
echo "database user with a password set who has administrator privileges."
echo "After a fresh installation of the MySQL or MariaDB server, the root"
echo "user doesn't have a password, and is unable to log in to the phpmyadmin"
echo "web GUI. You should create a new user with administrative rights now."
echo ""
read -p "New MySQL/MariaDB administrator username: " -r newdbadminuser
echo ""
get_new_password
newdbadminpass=$newpassword
unset newpassword
mysql -e "CREATE USER '$newdbadminuser'@'localhost'
IDENTIFIED VIA mysql_native_password USING password('$newdbadminpass');
GRANT ALL PRIVILEGES ON *.* TO '$newdbadminuser'@'localhost'
REQUIRE NONE WITH GRANT OPTION
MAX_QUERIES_PER_HOUR 0
MAX_CONNECTIONS_PER_HOUR 0
MAX_UPDATES_PER_HOUR 0
MAX_USER_CONNECTIONS 0;
flush privileges"
echo ""
echo ""
echo "You can now access phpmyadmin using a web browser pointed to:"
echo ""
echo " http://$HOSTNAME/phpmyadmin"
echo ""
echo "*** WARNING!! this url is accessible via unencrypted (http) connections."
echo "This is a huge security risk since the username and password you enter"
echo "on the phpmyadmin login page can be sent in the clear for any potential"
echo "attacker to sniff! You should enable redirection to https for phpmyadmin"
echo "in your apache2 configuration if your site is reachable from the internet."
echo ""
echo -n "Press enter to continue."
read continueok
echo ""
echo "Finished with phpmyadmin installation"
echo ""
sleep 3
fi
fi
echo ""
echo "Checking for webmin installation..."
echo ""
if dpkg -l|grep webmin >/dev/null 2>&1
then
echo ""
echo "webmin is installed. Continuing."
echo ""
else
echo "webmin doesn't seem to be installed."
echo "It is an optional package that enables system administration"
echo "using a friendly GUI. It is highly recommended, especially for"
echo "headless servers without any way to log in directly on the machine."
echo "Note that this has the potential to be a security risk, especially"
echo "if your passwords aren't sufficiently strong."
echo -n "Install it now? [Y/n]: "
read reqinstall
if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ]
then
echo "Proceeding without installing webmin. System administration"
echo "will require login to the server either directly or via ssh."
else
echo ""
echo "Proceeding with webmin installation"
echo ""
sleep 3
echo "Installing webmin..."
skipwebmin="false"
if ! curl -o setup-repos.sh https://raw.githubusercontent.com/webmin/webmin/master/setup-repos.sh
then
echo "Warning: failed to download Webmin repo setup script."
echo -n "Ignore and [c]ontinue or [A]bort? [c/A]: "
read wmfailchoice
if [ "$wmfailchoice" = "C" -o "$wmfailchoice" = "c" ]
then
skipwebmin="true"
echo "Continuing without installing Webmin. You should investigate the failure"
echo "and install Webmin manually after the server is set up if you would like"
echo "to be able to manage the server from another computer with a GUI instead"
echo "of through ssh only."
echo -n "Press enter to continue."
read continueok
echo ""
fi
fi
if [ "$skipwebmin" = "false" ]
then
sh setup-repos.sh -f
apt-get install -y --install-recommends webmin
fi
echo "...done."
echo ""
echo "You can now access webmin using a web browser pointed to:"
echo "https://$HOSTNAME:10000"
echo "Unless you have obtained valid ssl certificates, your server is"
echo "using self-signed certs. This is not necessarily a problem, but"
echo "your browser will complain. You can tell the browser to accept the"
echo "self signed certificates and the traffic will still be encrypted,"
echo "however you may be vulnerable to man-in-the-middle attacks. You can"
echo "get free valid certificates through LetsEncrypt."
echo "See http://letsencrypt.org for more information."
echo ""
echo -n "Press enter to continue."
read continueok
echo ""
echo "Finished with webmin installation"
echo ""
sleep 3
# Determine the correct Apache2 user and group
APACHE_USER=$(grep APACHE_RUN_USER /etc/apache2/envvars | cut -d= -f2)
APACHE_GROUP=$(grep APACHE_RUN_GROUP /etc/apache2/envvars | cut -d= -f2)
httpd_user_group="$APACHE_USER:$APACHE_GROUP"
fi
fi
echo ""
echo "Finished optional package installation."
fi
echo ""
sleep 3
# prompt for install location
echo "Where would you like to install this version of $APP_NAME? This should"
@@ -322,6 +184,7 @@ fi
install_path="$doc_root_in/$install_loc_in"
if [ -d "$install_path" ]
then
echo "The installation path you chose already exists."
# Install path exists.
if [ -e "$install_path/db.php" ]
then
@@ -329,31 +192,59 @@ then
if grep -q -e "$APP_NAME" $install_path/db.php
then
# the db.php file is part of a previous installation
echo "The installation path you chose already exists."
echo "Would you like to upgrade an existing installation or cancel "
echo "and restart the install using a new installation location."
echo -n "[U]pgrade or [C]ancel? [C] :"
echo -n "[U]pgrade or [C]ancel? [U] :"
read upgrade_choice
if [ "$upgrade_choice" = "U" -o "$upgrade_choice" = "u" ] # Upgrade chosen
if [[ $upgrade_choice == "C" || $upgrade_choice == "c" ]] # Cancel chosen
then
echo "Cancelling installation"
abort_exit
else
# proceed with upgrade
mkdir -p backups
operation="upgraded"
curr_dbname=$(grep dbname $install_path/db.php | head -1 | cut -d\" -f2)
# create mysql option file with data for this installation
mysql_opt_file=$(mktemp --tmpdir=/run/shm/)
echo "[client]" > $mysql_opt_file
echo "user = $(grep username $install_path/db.php | head -1 | cut -d\" -f2)" >> $mysql_opt_file
echo "password = $(grep dbpass $install_path/db.php | head -1 | cut -d\" -f2)" >> $mysql_opt_file
echo "" >> $mysql_opt_file
echo "[mysql]" > $mysql_opt_file
echo "database = $curr_dbname" >> $mysql_opt_file
echo "batch" >> $mysql_opt_file
echo "disable-column-names" >> $mysql_opt_file
# back up existing database
echo "Backing up the current database to the package directory."
curr_dbname=`grep dbname $install_path/db.php | head -1 | cut -d "\"" -f2`
curr_username=`grep username $install_path/db.php | head -1 | cut -d "\"" -f2`
curr_dbpass=`grep dbpass $install_path/db.php | head -1 | cut -d "\"" -f2`
export MYSQL_PWD="$curr_dbpass"
mysqldump --no-tablespaces -u"$curr_username" $curr_dbname > $curr_dbname-`date +%Y-%m-%d_%H:%M:%S`-backup.sql
mysqldump --defaults-extra-file=$mysql_opt_file --no-tablespaces $curr_dbname > backups/$curr_dbname-$(date +%Y-%m-%d_%H:%M:%S)-backup.sql
# back up existing installation
echo "Backing up current installation to the package directory."
cp -R $install_path $install_loc_in-`date +%Y-%m-%d_%H:%M:%S`-backup
cp -R $install_path backups/$install_loc_in-`date +%Y-%m-%d_%H:%M:%S`-backup
# delete all existing installation files except db.php
find $install_path/ -mindepth 1 -not -name 'db.php' -delete
# apply database updates
mysql -u"$curr_username" -f -D $curr_dbname < database-update.sql >/dev/null 2>&1
# apply updates to existing db.php
bash ./db.php_update $install_path
echo "Performing database updates. This may take a while..."
# apply database updates from sql file
(mysql --defaults-extra-file=$mysql_opt_file --force < database-update.sql >/dev/null 2>&1) &
task_pid=$!
spinner $task_pid
# apply database updates via script
(bash ./database-update.sh $mysql_opt_file) &
task_pid=$!
spinner $task_pid
echo "... finished with database updates."
rm -f $mysql_opt_file
# apply updates to other files
bash ./files-update.sh $install_path
# copy distribution to install location
echo "Installing distribution . . ."
cp -R distfiles/* $install_path
@@ -365,27 +256,17 @@ then
# set symlink for index.php
if [ ! -L "$install_path/index.php" ]
then
ln -s $install_path/$INDEX_FILE $install_path/index.php
ln -s $install_path/$LANDING_PAGE $install_path/index.php
fi
# add the local timezone to .htaccess
local_tz=$(timedatectl show -p Timezone|cut -d= -f2)
echo "Your local timezone is $local_tz"
echo "php_value date.timezone \"$local_tz\"">$install_path/.htaccess
# set ownership
echo "In order to set the ownership correctly, we need to know the user and"
echo "group that the webserver expects its files to be owned by. This is"
echo "usually not the root account. Refer to the ownership of other files in"
echo "your webserver's document tree to see what this should be."
echo "Enter the user and group separated by a colon (username:groupname)."
echo "Enter the user:group of the $APP_NAME installation"
echo -n "directory [$APACHE_USER:$APACHE_GROUP] :"
read httpd_user_group
if [ "$httpd_user_group" = "" ]
then
httpd_user_group="$APACHE_USER:$APACHE_GROUP"
fi
echo ""
echo "Setting file ownership . . ."
chown -R $httpd_user_group $install_path
else
echo "Cancelling installation"
abort_exit
fi
else
# This was a mistake. Exit now to avoid clobbering another app.
@@ -396,9 +277,22 @@ then
else
# This was a mistake. Exit now to avoid clobbering another app.
echo "The installation directory you chose exists, but no previous installation"
echo "of $APP_NAME was found. Please investigate the situation. Aborting now."
echo "of $APP_NAME was found."
echo ""
echo " CAUTION: If there is anything else in this directory, it will be deleted!"
echo ""
echo "Would you like to use this location for a fresh installation or quit and"
echo "investigate further? It's probably safest to quit and investigate."
proceed=""
while [[ $proceed != "P" && $proceed != "p" && $proceed != "Q" && $proceed != "q" ]]
do
read proceed -p "[P]roceed with new install or [Q]uit? : "
done
if [[ $proceed == "Q" || $proceed == "q" ]]
then
abort_exit
fi
fi
else
# This is a fresh install
operation="installed"
@@ -486,21 +380,14 @@ else
fi
if [ ! -L "$install_path/index.php" ]
then
ln -s $install_path/lognotes.php $install_path/index.php
ln -s $install_path/$LANDING_PAGE $install_path/index.php
fi
# add the local timezone to .htaccess
local_tz=$(timedatectl show -p Timezone|cut -d= -f2)
echo "Your local timezone is $local_tz"
echo "php_value date.timezone \"$local_tz\"">$install_path/.htaccess
# set ownership
echo "In order to set the ownership correctly, we need to know the user and"
echo "group that the webserver expects its files to be owned by. This is"
echo "usually not the root account. Refer to the ownership of other files in"
echo "your webserver's document tree to see what this should be."
echo "Enter the user and group separated by a colon (username:groupname)."
echo "Enter the user:group of the $APP_NAME installation"
echo -n "directory [$APACHE_USER:$APACHE_GROUP] :"
read httpd_user_group
if [ "$httpd_user_group" = "" ]
then
httpd_user_group="$APACHE_USER:$APACHE_GROUP"
fi
echo ""
echo "Setting file ownership . . ."
chown -R $httpd_user_group $install_path
@@ -521,6 +408,7 @@ then
echo "Alias /$base_url $doc_root_in/$base_url" >> $APACHE_CONF_DIR/$base_url.conf
echo "" >> $APACHE_CONF_DIR/$base_url.conf
echo "<Directory $doc_root_in/$base_url>" >> $APACHE_CONF_DIR/$base_url.conf
echo " AllowOverride Options" >> $APACHE_CONF_DIR/$base_url.conf
echo " Options FollowSymLinks" >> $APACHE_CONF_DIR/$base_url.conf
echo " DirectoryIndex index.php" >> $APACHE_CONF_DIR/$base_url.conf
echo "</Directory>" >> $APACHE_CONF_DIR/$base_url.conf