8 Commits

29 changed files with 1177 additions and 340 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
@@ -240,7 +240,3 @@
treating the $today variable as global.
- In install.php, if a previous installation was found, make upgrade
the default choice.
5.2.5 - 2026-02-10
This is just a version number bump to get on a major-minor-patch
scheme. There are no code changes for this release.

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

@@ -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.

View File

@@ -1 +1 @@
5.2.5
5.3.0

View File

@@ -69,7 +69,7 @@ CREATE TABLE `configs` (
LOCK TABLES `configs` WRITE;
/*!40000 ALTER TABLE `configs` DISABLE KEYS */;
INSERT INTO `configs` VALUES
(1,'ol_version','5.2.5'),
(1,'ol_version','5.2.4'),
(2,'log_name','OpenLog'),
(3,'banner','1'),
(4,'background_color','#003333'),
@@ -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`
--

View File

@@ -37,3 +37,82 @@ margs="--defaults-extra-file=$mysql_opt_file"
# ---------- version 5.2.5 ------------
# Nothing to do
# -------------------------------------
# ---------- version 5.3.0 ------------
#
echo "Started database updates for OpenLog version 5.3.0..."
# Import old flag data from old scheme to new flagmap table
if [[ $(mysql $margs -e "select count(*) from flagmap") == 0 ]]
then
echo "Importing flag data from old scheme to new flagmap table..."
for flagnumber in $(mysql $margs -e "select flagid from flags")
do
flag_x=$(mysql $margs -s -e "show tables like 'flag_$flagnumber'")
if [[ -n "$flag_x" ]]
then
for tgtid in $(mysql $margs -e "select id from flag_$flagnumber")
do
target=$(mysql $margs -e "select target from flag_$flagnumber where id=$tgtid")
if [[ $target == "lognotes" ]]
then
mysql $margs -e "insert into flagmap(flagid,lognoteid) values($flagnumber,$tgtid)"
elif [[ $target == "maintforms" ]]
then
mysql $margs -e "insert into flagmap(flagid,maintformid) values($flagnumber,$tgtid)"
elif [[ $target == "notetemplates" ]]
then
mysql $margs -e "insert into flagmap(flagid,notetemplateid) values($flagnumber,$tgtid)"
fi
done
mysql $margs -e "drop table flag_$flagnumber"
fi
done
echo "...done."
fi
# Import reference chain data into new reflinks table
if [[ $(mysql $margs -e "select count(*) from reflinks") == 0 ]]
then
echo "Importing lognote reference chain data into new reflinks table..."
for note in $(mysql $margs -e "select lognoteid from lognotes where refs!=''")
do
refstring=$(mysql $margs -e "select refs from lognotes where lognoteid=$note")
oldifs=$IFS
IFS=', '
for target in $refstring
do
target=$(echo "$target" | xargs)
mysql $margs -e "insert into reflinks(noteid,target) values($note,$target)"
done
IFS=$oldifs
done
echo "...done."
echo "Importing template reference chain data into new reflinks table..."
for template in $(mysql $margs -e "select templateid from notetemplates where refs!=''")
do
refstring=$(mysql $margs -e "select refs from notetemplates where templateid=$template")
oldifs=$IFS
IFS=', '
for target in $refstring
do
target=$(echo "$target" | xargs)
mysql $margs -e "insert into reflinks(templateid,target) values($template,$target)"
done
IFS=$oldifs
done
echo "...done."
mysql $margs -e "alter table lognotes drop column refs" >/dev/null 2>&1
mysql $margs -e "alter table notetemplates drop column refs" >/dev/null 2>&1
fi
# Convert database to utf8mb4/utf8mb4_unicode_ci
echo "Converting database to utf8mb4 encoding..."
mysql $margs -e "ALTER DATABASE CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci"
for table in $(mysql $margs -e "show tables")
do
mysql $margs -e "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
done
echo "...done."
# -------------------------------------

View File

@@ -55,3 +55,28 @@ UPDATE configs SET confvalue="5.2.4.4" WHERE confname="ol_version";
-- 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";
-- Create the flagmap table
CREATE TABLE IF NOT EXISTS `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_unicode_ci;
-- Create the reflinks table
CREATE TABLE IF NOT EXISTS `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_unicode_ci;
-- --------------------------------------

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,6 +1,6 @@
CHANGELOG
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
@@ -240,8 +240,3 @@
treating the $today variable as global.
- In install.php, if a previous installation was found, make upgrade
the default choice.
5.2.5 - 2026-02-10
This is just a version number bump to get on a major-minor-patch
scheme. There are no code changes for this release.

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);
}
@@ -924,4 +931,54 @@ function format_message($msgtype,$msgtxt) {
";
}
function templateselect($techid,$operation) {
// Displays a line enabling selection of a user or global template
// $techid is the id number of the current tech
// $operation is one of "add" "edit" "delete"
global $db;
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>
";
}
?>

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,20 +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);
// var_dump($_REQUEST);
// ******** begin database manipulation ********
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
@@ -100,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
@@ -137,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\")");
}
}
}
}
@@ -220,99 +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 ($flags[0]=="") $flags=[];
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\"");
@@ -323,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
@@ -359,31 +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 ($flags[0]=="") $flags=[];
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\")");
foreach ($chainmembers as $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\"");
}
}
}
@@ -449,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\"");
}
@@ -488,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) {
@@ -514,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>
";
@@ -641,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 {
@@ -670,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)) {
@@ -692,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
*/
@@ -42,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"]);
@@ -59,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
@@ -134,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"]);
@@ -151,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 {
@@ -170,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
*/

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
*/

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
*/
@@ -34,7 +34,7 @@ $srchpname=$_REQUEST['srchpname'] ?? NULL;
$srchploc=$_REQUEST['srchploc'] ?? NULL;
$srchnha=$_REQUEST['srchnha'] ?? NULL;
$srchrepord=$_REQUEST['srchrepord'] ?? NULL;
$srchflags=$_REQUEST['srchflags'] ?? NULL;
$srchflags=$_POST['srchflags'] ?? [];
$target=$_REQUEST['target'] ?? NULL;
$doparts=PARTS_FUNCTIONS;
@@ -57,6 +57,15 @@ framework("begin","$logname Search","Search",$print);
//var_dump($_REQUEST);
// ******** begin database manipulation ********
// define the arrays
$logfromtables=[];
$mffromtables=[];
$pfromtables=[];
$logconstraints=[];
$mfconstraints=[];
$pconstraints=[];
// get the date range of lognotes
$logdateqry=mysqli_query($db,"select min(date), max(date) from lognotes");
$logdateresults=mysqli_fetch_row($logdateqry);
@@ -75,8 +84,6 @@ if ($mfmaxdate == "") $mfmaxdate = $today;
$mindate=min($logmindate, $mfmindate);
$maxdate=max($logmaxdate, $mfmaxdate);
if ($search) {
// strip whitespace from beginning and end of text fields
$srchtext=trim($srchtext);
@@ -122,8 +129,9 @@ if ($search) {
$logfromtables[]="lognotes";
$logconstraints[]="lognotes.lognote like \"%$srchtext%\"";
}
// fixme
// flags
if ($srchflags != NULL) {
if (!empty($srchflags)) {
foreach ($srchflags as $flagtblnum) {
$flagtblname="flag_{$flagtblnum}";
$logfromtables[]="lognotes";
@@ -231,6 +239,7 @@ if ($search) {
$mffromtables[]="maintactions";
$mfconstraints[]="maintforms.mfmalfunction like \"%$srchtext%\" or (maintactions.action like \"%$srchtext%\" and maintforms.maintformid=maintactions.maintformnum)";
}
// fixme
// flags
foreach ($srchflags as $flagtblnum) {
$flagtblname="flag_{$flagtblnum}";
@@ -463,27 +472,37 @@ if (!$print) {
<br><br>
<b>Flags:</b>
";
$flagslist=mysqli_query($db,"select * from flags");
$flagsperline=8;
$flagcount=1;
while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) {
if ($srchflags[0]=="") $srchflags=[];
if (in_array($flagcheckbox["flagid"],$srchflags)) {
printf("<input type=\"checkbox\" name=\"srchflags[]\" value=\"%s\" checked title=\"When checked, only results with this flag set will be shown\"><font color=\"%s\" title=\"%s\">%s</font>",
$flagcheckbox["flagid"],$flagcheckbox["flagcolor"],$flagcheckbox["flagname"],$flagcheckbox["flagsym"]);
$flagslist = mysqli_query($db, "select * from flags");
$flagsperline = 8;
$flagcount = 1;
while ($flagcheckbox = mysqli_fetch_assoc($flagslist)) {
if ($srchflags[0] == "") $srchflags = [];
if (in_array($flagcheckbox["flagid"], $srchflags)) {
printf(
"<input type=\"checkbox\" name=\"srchflags[]\" value=\"%s\" checked title=\"When checked, only results with this flag set will be shown\"><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=\"srchflags[]\" value=\"%s\" title=\"When checked, only results with this flag set will be shown\"><font color=\"%s\" title=\"%s\">%s</font>",
$flagcheckbox["flagid"],$flagcheckbox["flagcolor"],$flagcheckbox["flagname"],$flagcheckbox["flagsym"]);
$flagid = $flagcheckbox["flagid"];
if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagid=\"$flagid\" and status=1"))) {
printf(
"<input type=\"checkbox\" name=\"srchflags[]\" value=\"%s\" title=\"When checked, only results with this flag set will be shown\"><font color=\"%s\" title=\"%s\">%s</font>",
$flagcheckbox["flagid"],
$flagcheckbox["flagcolor"],
$flagcheckbox["flagname"],
$flagcheckbox["flagsym"]
);
}
}
if ($flagcount<$flagsperline) {
if ($flagcount < $flagsperline) {
echo "&nbsp;&nbsp;&nbsp;";
$flagcount++;
} else {
echo "<br>";
$flagcount=1;
$flagcount = 1;
}
}
echo "
@@ -656,20 +675,23 @@ if ($search) {
$logsubjname=dblookup($db,"subjects","subjectid","subjectname",$logtablerow['subject']);
// create links of urls in note
$logfmtnote=convertweblinks($logtablerow['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=\"$logtablerow[lognoteid]\""))) {
$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;";
$flagqry=mysqli_query($db,"select flagid from flagmap where lognoteid=$logtablerow[lognoteid]");
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) {
$logfmtnote=$logfmtnote."<br>".$flagstring."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
} else {
$logfmtnote=$logfmtnote."<br>";
}
if ($flagstring) $logfmtnote=$logfmtnote."<br>".$flagstring;
printf("<tr>
<td valign=\"top\"><a href=logentry.php?edit=1&noteid=%s>%s</a></td>
<td valign=\"top\">%s&nbsp;&#047;&nbsp;%s</td>

View File

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

554
distfiles/templates.php Normal file
View File

@@ -0,0 +1,554 @@
<?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;
$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>";
}
// ******** 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($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);
?>

View File

@@ -41,8 +41,3 @@ fi
# ---------- version 5.2.4.4 -----------
# No changes
# --------------------------------------
# ---------- version 5.2.5 -------------
# No changes
# --------------------------------------

View File

@@ -8,11 +8,10 @@
APP_NAME="OpenLog"
DEFAULT_DB_NAME="openlog"
APP_VERSION="5.2.5"
APP_VERSION="5.3.0"
DOC_ROOT="/var/www"
INSTALL_LOC="openlog"
APACHE_CONF_DIR="/etc/apache2/conf-available"
BACKUP_DIR="openlog-previous-installation"
LANDING_PAGE="lognotes.php"
CONFIG_TABLE="configs"
CONFIG_NAME_COLUMN="confname"
@@ -202,7 +201,9 @@ then
abort_exit
else
# proceed with upgrade
mkdir -p backups
datestamp=$(date +%Y-%m-%d_%H:%M:%S)
backupdir=backups/$datestamp
mkdir -p $backupdir
operation="upgraded"
curr_dbname=$(grep dbname $install_path/db.php | head -1 | cut -d\" -f2)
@@ -219,11 +220,11 @@ then
# back up existing database
echo "Backing up the current database to the package directory."
mysqldump --defaults-extra-file=$mysql_opt_file --no-tablespaces $curr_dbname > backups/$curr_dbname-$(date +%Y-%m-%d_%H:%M:%S)-backup.sql
mysqldump --defaults-extra-file=$mysql_opt_file --no-tablespaces $curr_dbname > $backupdir/$curr_dbname-$datestamp-backup.sql
# back up existing installation
echo "Backing up current installation to the package directory."
cp -R $install_path backups/$install_loc_in-`date +%Y-%m-%d_%H:%M:%S`-backup
cp -R $install_path $backupdir/$install_loc_in-$datestamp-backup
# delete all existing installation files except db.php
find $install_path/ -mindepth 1 -not -name 'db.php' -delete
@@ -267,6 +268,8 @@ then
echo ""
echo "Setting file ownership . . ."
chown -R $httpd_user_group $install_path
echo "Backups of the previous openlog files and the previous database were made"
echo "and are located in the $backupdir directory."
fi
else
# This was a mistake. Exit now to avoid clobbering another app.