diff --git a/BUGS b/BUGS index 39f47d2..26132e5 100644 --- a/BUGS +++ b/BUGS @@ -1,4 +1,5 @@ BUGS 1. Adding a reference to a note using the magnifying glass icon is possible even if not logged in. This results in a blank tech and shift. -SOMEWHAT FIXED. If not logged in and the partview argument is not 1, redirects to login page. (This is not the optimal solution. There needs to be a specific view only state.) +SOMEWHAT FIXED. If not logged in and the partview argument is not 1, redirects to login page. (This is not the optimal solution. There +needs to be a specific view only state.) diff --git a/CHANGELOG b/CHANGELOG index 28ba9c0..b1224f3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ CHANGELOG OpenLog Online Logbook - Copyright (C) 2025 Rod Wright + Copyright (C) 2026 Rod Wright SPDX-License-Identifier: GPL-2.0 @@ -244,3 +244,41 @@ 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. + +5.3.0 - 2026-02-20 + - Moved the template Create/Copy/Edit/Delete/Rename functionality to + its own page to make it less confusing and to fix some strange + behavior. + - Added global templates which can be used by anyone but can only be + created, modified, or deleted by administrators. This makes it + easier to employ standardized templates. + - Changed the character encoding of the database to utf8mb4 to enable + using emojis in text fields. + - Changed the insert link functionality. There are now two fields, link + text, and URL. The full URL string will now not be displayed in the + note, since it frequently was too long and deformed the table, + causing the user to have to scroll right to see the entire note. If + a URL is entered in the URL field and no link text is entered in the + link text field, the link will show up as just the last part of the + URL. For example, "http://somewhere.com/myfile.pdf" will show as + "myfile.pdf" in the note text. If text is entered in the link text + field, that is what will show as the clickable link in the note text. + NOTE: URLs in previously entered notes will not automatically be + converted. + - Changed the flag handling code to no longer dynamically create flag_ + tables in the database to track assignments. This is now done using + a flagmap table. + NOTE: The database will be modified to support this and the + importation of the previous data will take some time during + installation. + - References will no longer be stored in the lognotes table with the note. + There is now a reflinks table that stores the link information. + NOTE: The database will be modified to support this and the + importation of the previous data will take some time during + installation. + - Various code cleanups to prevent php warnings in the logs if logging + is enabled. + - Validate all date and time fields to prevent user entered invalid date + formats from crashing php. + - Fixed profile page to automatically refresh page to show the results + when a user changes their color preferences. diff --git a/INSTALL b/INSTALL index c7ced63..6ba22bf 100644 --- a/INSTALL +++ b/INSTALL @@ -1,35 +1,33 @@ INSTALL OpenLog Online Logbook - Copyright (C) 2025 Rod Wright + Copyright (C) 2026 Rod Wright SPDX-License-Identifier: GPL-2.0 - Installation of OpenLog is straightforward. 1. Gather the required information. -You'll need to know how to configure your web server. This means where -you want to put the files to be served and any configuration required to -allow clients to reach them. You'll also need to know the username and -password of the MySQL administrator. + You'll need to know how to configure your web server. This means where + you want to put the files to be served and any configuration required to + allow clients to reach them. You'll also need to know the username and + password of the MySQL administrator. 2. Unpack -Unpack the distribution in a convenient place (such as /tmp or My Documents). -A directory will be created called OpenLog-x.x.x. + Unpack the distribution in a convenient place (such as /tmp or My Documents). + A directory will be created called OpenLog-x.x.x. 3. Review License -Change to the openlog-x.x.x directory and review the LICENSE file. + Change to the openlog-x.x.x directory and review the LICENSE file. 4. Run the install script -If installing on a Linux or Unix based system, type ./install.sh at a -command prompt. If installing on a Windows based system, double click -install.bat. Follow the prompts. + If installing on a Linux or Unix based system, type ./install.sh at a + command prompt. If installing on a Windows based system, double click + install.bat. Follow the prompts. 5. Check and set Configuration -Click on the Administration menu option on the main page to adjust the initial -settings. You will need to log in as OpenLogAdmin. The initial default password -is "OpenLog-1". From the Administration page, you can click on the links at the -top to add techs, subjects, shifts, etc. - -7. Start using OpenLog. + Click on the Administration menu option on the main page to adjust the initial + settings. You will need to log in as OpenLogAdmin. The initial default password + is "OpenLog-1". From the Administration page, you can click on the links at the + top to add techs, subjects, shifts, etc. +6. Start using OpenLog. diff --git a/README.md b/README.md index e69de29..cec85a9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/TODO.txt b/TODO.txt index 3d54569..f5e5795 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,15 +1,15 @@ TODO.txt 1. Create a weblink hot button on the add logbook entry page to insert a weblink. DONE -2. Allow admins to create global templates. +2. Allow admins to create global templates. DONE 3. Create a way to restore the global page colors. (db change reqd) 4. Pick a logbook subject to associate with a scheduled task to populate for the logbook entry. (db change reqd) 5. Add info messages to scheduled task page edits. 6. Allow scheduled tasks to be completed as a group instead of having to complete each member. 7. Implement popup calendars for date entry fields. DONE -8. Improve template management interface. It can be confusing. It needs its own page. -9. Remove refs from templates. (db change reqd) -10. Replace dynamic flag_ table creation with a flagassignment table. (db change reqd) +8. Improve template management interface. It can be confusing. It needs its own page. DONE +9. Remove refs from templates. (db change reqd) DONE +10. Replace dynamic flag_ table creation with a flagassignment table. (db change reqd) DONE 11. allow partids to be autogenerated if user doesn't supply one (db change reqd) 12. If there are no flags, don't offer to set them on reference chain 13. make some flags immutable so they won't be synced on reference chain. diff --git a/VERSION.txt b/VERSION.txt index 462faf7..03f488b 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.2.5 +5.3.0 diff --git a/database-initial.sql b/database-initial.sql index 951c5cf..0ca4ab8 100644 --- a/database-initial.sql +++ b/database-initial.sql @@ -1,607 +1,942 @@ --- MariaDB dump 10.19 Distrib 10.6.18-MariaDB, for debian-linux-gnu (x86_64) +/*M!999999\- enable the sandbox mode */ +-- MariaDB dump 10.19-11.8.3-MariaDB, for debian-linux-gnu (x86_64) -- --- Host: localhost Database: ol521 +-- Host: localhost Database: openlog -- ------------------------------------------------------ --- Server version 10.6.18-MariaDB-0ubuntu0.22.04.1 +-- Server version 11.8.3-MariaDB-0+deb13u1 from Debian -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8mb4 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */ +; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */ +; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */ +; +/*!40101 SET NAMES utf8mb4 */ +; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */ +; +/*!40103 SET TIME_ZONE='+00:00' */ +; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */ +; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */ +; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ +; +/*M!100616 SET @OLD_NOTE_VERBOSITY=@@NOTE_VERBOSITY, NOTE_VERBOSITY=0 */ +; -- -- Table structure for table `banners` -- DROP TABLE IF EXISTS `banners`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `banners` ( - `bannerid` int(11) NOT NULL AUTO_INCREMENT, - `bannername` tinytext DEFAULT NULL, - `bannercolor` tinytext DEFAULT NULL, - `textcolor` tinytext DEFAULT NULL, - PRIMARY KEY (`bannerid`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `bannerid` int(11) NOT NULL AUTO_INCREMENT, + `bannername` tinytext DEFAULT NULL, + `bannercolor` tinytext DEFAULT NULL, + `textcolor` tinytext DEFAULT NULL, + PRIMARY KEY (`bannerid`) +) ENGINE = InnoDB AUTO_INCREMENT = 6 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `banners` -- LOCK TABLES `banners` WRITE; -/*!40000 ALTER TABLE `banners` DISABLE KEYS */; -INSERT INTO `banners` VALUES -(1,'no banner','#000000','#000000'), -(2,'UNCLASSIFIED','#009900','#FFFFFF'), -(3,'CONFIDENTIAL','#000099','#FFFFFF'), -(4,'SECRET','#990000','#FFFFFF'), -(5,'TOP SECRET','#FF6600','#FFFFFF'); -/*!40000 ALTER TABLE `banners` ENABLE KEYS */; +/*!40000 ALTER TABLE `banners` DISABLE KEYS */ +; +set autocommit = 0; + +INSERT INTO + `banners` +VALUES ( + 1, + 'no banner', + '#000000', + '#000000' + ), + ( + 2, + 'UNCLASSIFIED', + '#009900', + '#FFFFFF' + ), + ( + 3, + 'CONFIDENTIAL', + '#000099', + '#FFFFFF' + ), + ( + 4, + 'SECRET', + '#990000', + '#FFFFFF' + ), + ( + 5, + 'TOP SECRET', + '#FF6600', + '#FFFFFF' + ); +/*!40000 ALTER TABLE `banners` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `configs` -- DROP TABLE IF EXISTS `configs`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `configs` ( - `confid` int(11) NOT NULL AUTO_INCREMENT, - `confname` text DEFAULT NULL, - `confvalue` text DEFAULT NULL, - PRIMARY KEY (`confid`), - UNIQUE (`confname`) -) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `confid` int(11) NOT NULL AUTO_INCREMENT, + `confname` text DEFAULT NULL, + `confvalue` text DEFAULT NULL, + PRIMARY KEY (`confid`), + UNIQUE KEY `confname` (`confname`) USING HASH +) ENGINE = InnoDB AUTO_INCREMENT = 33 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `configs` -- LOCK TABLES `configs` WRITE; -/*!40000 ALTER TABLE `configs` DISABLE KEYS */; -INSERT INTO `configs` VALUES -(1,'ol_version','5.2.5'), -(2,'log_name','OpenLog'), -(3,'banner','1'), -(4,'background_color','#003333'), -(5,'p_background_color','#FFFFFF'), -(6,'sidebar_color','#336666'), -(7,'p_sidebar_color','#FFFFFF'), -(8,'menubg_color','#000000'), -(9,'p_menubg_color','#FFFFFF'), -(10,'text_color','#FFFFFF'), -(11,'p_text_color','#000000'), -(12,'link_color','#00FF00'), -(13,'p_link_color','#000000'), -(14,'vlink_color','#00FF00'), -(15,'p_vlink_color','#000000'), -(16,'heading_color','#00FFFF'), -(17,'p_heading_color','#000000'), -(18,'footer_message','Please report bugs to software@thermionic.net.'), -(19,'show_ts','1'), -(20,'url_chunk_size','70'), -(21,'tech_alpha','1'), -(22,'subj_alpha','1'), -(23,'unix_server_session_dir','/tmp/openlog/openlog/sessions'), -(24,'win_server_session_dir','c:\\Windows\\Temp\\openlog\\\\openlog\\sessions'), -(25,'session_ttl_days','30'), -(26,'log_style','1'), -(27,'uid_text','Part ID Number'), -(28,'parts_functions','1'), -(29,'schedmaint_functions','1'), -(30,'log_errors','0'); -/*!40000 ALTER TABLE `configs` ENABLE KEYS */; +/*!40000 ALTER TABLE `configs` DISABLE KEYS */ +; +set autocommit = 0; + +INSERT INTO + `configs` +VALUES (1, 'ol_version', '5.3.0'), + (2, 'log_name', 'OpenLog'), + (3, 'banner', '1'), + ( + 4, + 'background_color', + '#003333' + ), + ( + 5, + 'p_background_color', + '#FFFFFF' + ), + (6, 'sidebar_color', '#336666'), + ( + 7, + 'p_sidebar_color', + '#FFFFFF' + ), + (8, 'menubg_color', '#000000'), + ( + 9, + 'p_menubg_color', + '#FFFFFF' + ), + (10, 'text_color', '#FFFFFF'), + (11, 'p_text_color', '#000000'), + (12, 'link_color', '#00FF00'), + (13, 'p_link_color', '#000000'), + (14, 'vlink_color', '#00FF00'), + ( + 15, + 'p_vlink_color', + '#000000' + ), + ( + 16, + 'heading_color', + '#00FFFF' + ), + ( + 17, + 'p_heading_color', + '#000000' + ), + ( + 18, + 'footer_message', + 'Please report bugs to software@thermionic.net.' + ), + (19, 'show_ts', '1'), + (20, 'url_chunk_size', '70'), + (21, 'tech_alpha', '1'), + (22, 'subj_alpha', '1'), + ( + 23, + 'unix_server_session_dir', + '/tmp/openlog/openlog/sessions' + ), + ( + 24, + 'win_server_session_dir', + 'c:\\Windows\\Temp\\openlog\\\\openlog\\sessions' + ), + (25, 'session_ttl_days', '30'), + (26, 'log_style', '1'), + ( + 27, + 'uid_text', + 'Part ID Number' + ), + (28, 'parts_functions', '1'), + ( + 29, + 'schedmaint_functions', + '1' + ), + (30, 'log_errors', '0'); +/*!40000 ALTER TABLE `configs` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `customs` -- DROP TABLE IF EXISTS `customs`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `customs` ( - `customid` int(11) NOT NULL AUTO_INCREMENT, - `customtech` int(11) DEFAULT NULL, - `customconfnum` int(11) DEFAULT NULL, - `customconfvalue` text DEFAULT NULL, - PRIMARY KEY (`customid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `customid` int(11) NOT NULL AUTO_INCREMENT, + `customtech` int(11) DEFAULT NULL, + `customconfnum` int(11) DEFAULT NULL, + `customconfvalue` text DEFAULT NULL, + PRIMARY KEY (`customid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `customs` -- LOCK TABLES `customs` WRITE; -/*!40000 ALTER TABLE `customs` DISABLE KEYS */; -/*!40000 ALTER TABLE `customs` ENABLE KEYS */; +/*!40000 ALTER TABLE `customs` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `customs` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `devicegroups` -- DROP TABLE IF EXISTS `devicegroups`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `devicegroups` ( - `groupid` int(11) NOT NULL AUTO_INCREMENT, - `groupdevice` int(11) DEFAULT NULL, - `memberdevice` int(11) DEFAULT NULL, - PRIMARY KEY (`groupid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `groupid` int(11) NOT NULL AUTO_INCREMENT, + `groupdevice` int(11) DEFAULT NULL, + `memberdevice` int(11) DEFAULT NULL, + PRIMARY KEY (`groupid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `devicegroups` -- LOCK TABLES `devicegroups` WRITE; -/*!40000 ALTER TABLE `devicegroups` DISABLE KEYS */; -/*!40000 ALTER TABLE `devicegroups` ENABLE KEYS */; +/*!40000 ALTER TABLE `devicegroups` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `devicegroups` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `devices` -- DROP TABLE IF EXISTS `devices`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `devices` ( - `deviceid` int(11) NOT NULL AUTO_INCREMENT, - `devicename` tinytext DEFAULT NULL, - `devicedesc` text DEFAULT NULL, - `group_flag` int(11) DEFAULT NULL, - `active_flag` int(11) DEFAULT NULL, - PRIMARY KEY (`deviceid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `deviceid` int(11) NOT NULL AUTO_INCREMENT, + `devicename` tinytext DEFAULT NULL, + `devicedesc` text DEFAULT NULL, + `group_flag` int(11) DEFAULT NULL, + `active_flag` int(11) DEFAULT NULL, + PRIMARY KEY (`deviceid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `devices` -- LOCK TABLES `devices` WRITE; -/*!40000 ALTER TABLE `devices` DISABLE KEYS */; -/*!40000 ALTER TABLE `devices` ENABLE KEYS */; +/*!40000 ALTER TABLE `devices` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `devices` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `events` -- DROP TABLE IF EXISTS `events`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `events` ( - `eventid` int(11) NOT NULL AUTO_INCREMENT, - `task` int(11) DEFAULT NULL, - `device` int(11) DEFAULT NULL, - `start_date` date DEFAULT NULL, - `last_date` date DEFAULT NULL, - `deferred_flag` int(11) DEFAULT NULL, - `deferred_date` date DEFAULT NULL, - `active_flag` int(11) DEFAULT NULL, - PRIMARY KEY (`eventid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `eventid` int(11) NOT NULL AUTO_INCREMENT, + `task` int(11) DEFAULT NULL, + `device` int(11) DEFAULT NULL, + `start_date` date DEFAULT NULL, + `last_date` date DEFAULT NULL, + `deferred_flag` int(11) DEFAULT NULL, + `deferred_date` date DEFAULT NULL, + `active_flag` int(11) DEFAULT NULL, + PRIMARY KEY (`eventid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `events` -- LOCK TABLES `events` WRITE; -/*!40000 ALTER TABLE `events` DISABLE KEYS */; -/*!40000 ALTER TABLE `events` ENABLE KEYS */; +/*!40000 ALTER TABLE `events` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `events` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + +-- +-- Table structure for table `flagmap` +-- + +DROP TABLE IF EXISTS `flagmap`; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; +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 */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `flagmap` ENABLE KEYS */ +; +UNLOCK TABLES; + +commit; + -- -- Table structure for table `flags` -- DROP TABLE IF EXISTS `flags`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `flags` ( - `flagid` int(11) NOT NULL AUTO_INCREMENT, - `flagname` tinytext DEFAULT NULL, - `flagsym` tinytext DEFAULT NULL, - `flagcolor` tinytext DEFAULT NULL, - `status` int(11) NOT NULL, - PRIMARY KEY (`flagid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `flagid` int(11) NOT NULL AUTO_INCREMENT, + `flagname` tinytext DEFAULT NULL, + `flagsym` tinytext DEFAULT NULL, + `flagcolor` tinytext DEFAULT NULL, + `status` int(11) NOT NULL, + PRIMARY KEY (`flagid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `flags` -- LOCK TABLES `flags` WRITE; -/*!40000 ALTER TABLE `flags` DISABLE KEYS */; -/*!40000 ALTER TABLE `flags` ENABLE KEYS */; +/*!40000 ALTER TABLE `flags` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `flags` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `links` -- DROP TABLE IF EXISTS `links`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `links` ( - `linkid` int(11) NOT NULL AUTO_INCREMENT, - `linkpriority` int(11) NOT NULL, - `displaytxt` text DEFAULT NULL, - `urltxt` text DEFAULT NULL, - `status` int(11) NOT NULL, - PRIMARY KEY (`linkid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `linkid` int(11) NOT NULL AUTO_INCREMENT, + `linkpriority` int(11) NOT NULL, + `displaytxt` text DEFAULT NULL, + `urltxt` text DEFAULT NULL, + `status` int(11) NOT NULL, + PRIMARY KEY (`linkid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `links` -- LOCK TABLES `links` WRITE; -/*!40000 ALTER TABLE `links` DISABLE KEYS */; -/*!40000 ALTER TABLE `links` ENABLE KEYS */; +/*!40000 ALTER TABLE `links` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `links` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `lognotes` -- DROP TABLE IF EXISTS `lognotes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `lognotes` ( - `lognoteid` int(11) NOT NULL AUTO_INCREMENT, - `date` date DEFAULT NULL, - `time` time DEFAULT NULL, - `shift` int(11) NOT NULL, - `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 */; + `lognoteid` int(11) NOT NULL AUTO_INCREMENT, + `date` date DEFAULT NULL, + `time` time DEFAULT NULL, + `shift` int(11) NOT NULL, + `tech` int(11) NOT NULL, + `subject` int(11) NOT NULL, + `lognote` text DEFAULT NULL, + PRIMARY KEY (`lognoteid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `lognotes` -- LOCK TABLES `lognotes` WRITE; -/*!40000 ALTER TABLE `lognotes` DISABLE KEYS */; -/*!40000 ALTER TABLE `lognotes` ENABLE KEYS */; +/*!40000 ALTER TABLE `lognotes` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `lognotes` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `logpartactions` -- DROP TABLE IF EXISTS `logpartactions`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `logpartactions` ( - `lpactionid` int(11) NOT NULL AUTO_INCREMENT, - `lpactionname` tinytext DEFAULT NULL, - `status` int(11) DEFAULT NULL, - PRIMARY KEY (`lpactionid`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `lpactionid` int(11) NOT NULL AUTO_INCREMENT, + `lpactionname` tinytext DEFAULT NULL, + `status` int(11) DEFAULT NULL, + PRIMARY KEY (`lpactionid`) +) ENGINE = InnoDB AUTO_INCREMENT = 7 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `logpartactions` -- LOCK TABLES `logpartactions` WRITE; -/*!40000 ALTER TABLE `logpartactions` DISABLE KEYS */; -INSERT INTO `logpartactions` VALUES -(1,'removed',1), -(2,'installed',1), -(3,'repaired',1), -(4,'replaced',1), -(5,'incoming',1), -(6,'outgoing',1); -/*!40000 ALTER TABLE `logpartactions` ENABLE KEYS */; +/*!40000 ALTER TABLE `logpartactions` DISABLE KEYS */ +; +set autocommit = 0; + +INSERT INTO + `logpartactions` +VALUES (1, 'removed', 1), + (2, 'installed', 1), + (3, 'repaired', 1), + (4, 'replaced', 1), + (5, 'incoming', 1), + (6, 'outgoing', 1); +/*!40000 ALTER TABLE `logpartactions` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `logparts` -- DROP TABLE IF EXISTS `logparts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `logparts` ( - `logpartid` int(11) NOT NULL AUTO_INCREMENT, - `lognoteid` int(11) DEFAULT NULL, - `partid` int(11) DEFAULT NULL, - `action` int(11) DEFAULT NULL, - PRIMARY KEY (`logpartid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `logpartid` int(11) NOT NULL AUTO_INCREMENT, + `lognoteid` int(11) DEFAULT NULL, + `partid` int(11) DEFAULT NULL, + `action` int(11) DEFAULT NULL, + PRIMARY KEY (`logpartid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `logparts` -- LOCK TABLES `logparts` WRITE; -/*!40000 ALTER TABLE `logparts` DISABLE KEYS */; -/*!40000 ALTER TABLE `logparts` ENABLE KEYS */; +/*!40000 ALTER TABLE `logparts` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `logparts` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `maintactions` -- DROP TABLE IF EXISTS `maintactions`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `maintactions` ( - `maintactionid` int(11) NOT NULL AUTO_INCREMENT, - `actiondate` date DEFAULT NULL, - `actiontime` time DEFAULT NULL, - `maintformnum` int(11) NOT NULL, - `actiontech` int(11) NOT NULL, - `action` text DEFAULT NULL, - PRIMARY KEY (`maintactionid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `maintactionid` int(11) NOT NULL AUTO_INCREMENT, + `actiondate` date DEFAULT NULL, + `actiontime` time DEFAULT NULL, + `maintformnum` int(11) NOT NULL, + `actiontech` int(11) NOT NULL, + `action` text DEFAULT NULL, + PRIMARY KEY (`maintactionid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `maintactions` -- LOCK TABLES `maintactions` WRITE; -/*!40000 ALTER TABLE `maintactions` DISABLE KEYS */; -/*!40000 ALTER TABLE `maintactions` ENABLE KEYS */; +/*!40000 ALTER TABLE `maintactions` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `maintactions` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `maintforms` -- DROP TABLE IF EXISTS `maintforms`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `maintforms` ( - `maintformid` int(11) NOT NULL AUTO_INCREMENT, - `mfdate` date DEFAULT NULL, - `mftime` time DEFAULT NULL, - `mftech` int(11) DEFAULT NULL, - `mfpart` int(11) NOT NULL, - `mfpartloc` text DEFAULT NULL, - `mfmalfunction` text DEFAULT NULL, - `nha` tinytext DEFAULT NULL, - `repord` tinytext DEFAULT NULL, - `lognoteid` int(11) DEFAULT NULL, - `pending` int(11) DEFAULT NULL, - PRIMARY KEY (`maintformid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `maintformid` int(11) NOT NULL AUTO_INCREMENT, + `mfdate` date DEFAULT NULL, + `mftime` time DEFAULT NULL, + `mftech` int(11) DEFAULT NULL, + `mfpart` int(11) NOT NULL, + `mfpartloc` text DEFAULT NULL, + `mfmalfunction` text DEFAULT NULL, + `nha` tinytext DEFAULT NULL, + `repord` tinytext DEFAULT NULL, + `lognoteid` int(11) DEFAULT NULL, + `pending` int(11) DEFAULT NULL, + PRIMARY KEY (`maintformid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `maintforms` -- LOCK TABLES `maintforms` WRITE; -/*!40000 ALTER TABLE `maintforms` DISABLE KEYS */; -/*!40000 ALTER TABLE `maintforms` ENABLE KEYS */; +/*!40000 ALTER TABLE `maintforms` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `maintforms` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `notetemplates` -- DROP TABLE IF EXISTS `notetemplates`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `notetemplates` ( - `templateid` int(11) NOT NULL AUTO_INCREMENT, - `templatename` tinytext DEFAULT NULL, - `shift` int(11) NOT NULL, - `tech` int(11) NOT NULL, - `subject` int(11) NOT NULL, - `lognote` text DEFAULT NULL, - `refs` tinytext DEFAULT NULL, - PRIMARY KEY (`templateid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `templateid` int(11) NOT NULL AUTO_INCREMENT, + `templatename` tinytext DEFAULT NULL, + `shift` int(11) NOT NULL, + `tech` int(11) NOT NULL, + `subject` int(11) NOT NULL, + `lognote` text DEFAULT NULL, + `refs` tinytext DEFAULT NULL, + PRIMARY KEY (`templateid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `notetemplates` -- LOCK TABLES `notetemplates` WRITE; -/*!40000 ALTER TABLE `notetemplates` DISABLE KEYS */; -/*!40000 ALTER TABLE `notetemplates` ENABLE KEYS */; +/*!40000 ALTER TABLE `notetemplates` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `notetemplates` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `parts` -- DROP TABLE IF EXISTS `parts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `parts` ( - `partid` int(11) NOT NULL AUTO_INCREMENT, - `uid` tinytext DEFAULT NULL, - `partnum` tinytext DEFAULT NULL, - `sernum` tinytext DEFAULT NULL, - `partname` tinytext DEFAULT NULL, - PRIMARY KEY (`partid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `partid` int(11) NOT NULL AUTO_INCREMENT, + `uid` tinytext DEFAULT NULL, + `partnum` tinytext DEFAULT NULL, + `sernum` tinytext DEFAULT NULL, + `partname` tinytext DEFAULT NULL, + PRIMARY KEY (`partid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `parts` -- LOCK TABLES `parts` WRITE; -/*!40000 ALTER TABLE `parts` DISABLE KEYS */; -/*!40000 ALTER TABLE `parts` ENABLE KEYS */; +/*!40000 ALTER TABLE `parts` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `parts` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + +-- +-- Table structure for table `reflinks` +-- + +DROP TABLE IF EXISTS `reflinks`; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; +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 */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `reflinks` ENABLE KEYS */ +; +UNLOCK TABLES; + +commit; + -- -- Table structure for table `shifts` -- DROP TABLE IF EXISTS `shifts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `shifts` ( - `shiftid` int(11) NOT NULL AUTO_INCREMENT, - `shiftname` tinytext DEFAULT NULL, - `status` int(11) NOT NULL, - PRIMARY KEY (`shiftid`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `shiftid` int(11) NOT NULL AUTO_INCREMENT, + `shiftname` tinytext DEFAULT NULL, + `status` int(11) NOT NULL, + PRIMARY KEY (`shiftid`) +) ENGINE = InnoDB AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `shifts` -- LOCK TABLES `shifts` WRITE; -/*!40000 ALTER TABLE `shifts` DISABLE KEYS */; -INSERT INTO `shifts` VALUES -(1,'First Shift',1); -/*!40000 ALTER TABLE `shifts` ENABLE KEYS */; +/*!40000 ALTER TABLE `shifts` DISABLE KEYS */ +; +set autocommit = 0; + +INSERT INTO `shifts` VALUES (1, 'First Shift', 1); +/*!40000 ALTER TABLE `shifts` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `styles` -- DROP TABLE IF EXISTS `styles`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `styles` ( - `styleid` int(11) NOT NULL AUTO_INCREMENT, - `styletype` tinytext DEFAULT NULL, - `stylename` tinytext DEFAULT NULL, - PRIMARY KEY (`styleid`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `styleid` int(11) NOT NULL AUTO_INCREMENT, + `styletype` tinytext DEFAULT NULL, + `stylename` tinytext DEFAULT NULL, + PRIMARY KEY (`styleid`) +) ENGINE = InnoDB AUTO_INCREMENT = 3 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `styles` -- LOCK TABLES `styles` WRITE; -/*!40000 ALTER TABLE `styles` DISABLE KEYS */; -INSERT INTO `styles` VALUES -(1,'logdisplay','classic'), -(2,'logdisplay','clean'); -/*!40000 ALTER TABLE `styles` ENABLE KEYS */; +/*!40000 ALTER TABLE `styles` DISABLE KEYS */ +; +set autocommit = 0; + +INSERT INTO + `styles` +VALUES (1, 'logdisplay', 'classic'), + (2, 'logdisplay', 'clean'); +/*!40000 ALTER TABLE `styles` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `subjects` -- DROP TABLE IF EXISTS `subjects`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `subjects` ( - `subjectid` int(11) NOT NULL AUTO_INCREMENT, - `subjectname` tinytext DEFAULT NULL, - `status` int(11) NOT NULL, - PRIMARY KEY (`subjectid`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `subjectid` int(11) NOT NULL AUTO_INCREMENT, + `subjectname` tinytext DEFAULT NULL, + `status` int(11) NOT NULL, + PRIMARY KEY (`subjectid`) +) ENGINE = InnoDB AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `subjects` -- LOCK TABLES `subjects` WRITE; -/*!40000 ALTER TABLE `subjects` DISABLE KEYS */; -INSERT INTO `subjects` VALUES -(1,'Miscellaneous',1); -/*!40000 ALTER TABLE `subjects` ENABLE KEYS */; +/*!40000 ALTER TABLE `subjects` DISABLE KEYS */ +; +set autocommit = 0; + +INSERT INTO `subjects` VALUES (1, 'Miscellaneous', 1); +/*!40000 ALTER TABLE `subjects` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `tasks` -- DROP TABLE IF EXISTS `tasks`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `tasks` ( - `taskid` int(11) NOT NULL AUTO_INCREMENT, - `taskname` tinytext DEFAULT NULL, - `taskdesc` text DEFAULT NULL, - `frequency` int(11) DEFAULT NULL, - `period` tinytext DEFAULT NULL, - `weekdays_only` int(11) DEFAULT NULL, - `nextdue_relative` int(11) DEFAULT NULL, - `refdoc_name` tinytext DEFAULT NULL, - `refdoc_url` tinytext DEFAULT NULL, - `active_flag` int(11) DEFAULT NULL, - PRIMARY KEY (`taskid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `taskid` int(11) NOT NULL AUTO_INCREMENT, + `taskname` tinytext DEFAULT NULL, + `taskdesc` text DEFAULT NULL, + `frequency` int(11) DEFAULT NULL, + `period` tinytext DEFAULT NULL, + `weekdays_only` int(11) DEFAULT NULL, + `nextdue_relative` int(11) DEFAULT NULL, + `refdoc_name` tinytext DEFAULT NULL, + `refdoc_url` tinytext DEFAULT NULL, + `active_flag` int(11) DEFAULT NULL, + PRIMARY KEY (`taskid`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `tasks` -- LOCK TABLES `tasks` WRITE; -/*!40000 ALTER TABLE `tasks` DISABLE KEYS */; -/*!40000 ALTER TABLE `tasks` ENABLE KEYS */; +/*!40000 ALTER TABLE `tasks` DISABLE KEYS */ +; +set autocommit = 0; +/*!40000 ALTER TABLE `tasks` ENABLE KEYS */ +; UNLOCK TABLES; +commit; + -- -- Table structure for table `techs` -- DROP TABLE IF EXISTS `techs`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET @saved_cs_client = @@character_set_client */ +; +/*!40101 SET character_set_client = utf8mb4 */ +; CREATE TABLE `techs` ( - `techid` int(11) NOT NULL AUTO_INCREMENT, - `techname` tinytext DEFAULT NULL, - `admin` int(11) DEFAULT NULL, - `shift` int(11) DEFAULT NULL, - `techpass` text DEFAULT NULL, - `status` int(11) NOT NULL, - PRIMARY KEY (`techid`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; + `techid` int(11) NOT NULL AUTO_INCREMENT, + `techname` tinytext DEFAULT NULL, + `admin` int(11) DEFAULT NULL, + `shift` int(11) DEFAULT NULL, + `techpass` text DEFAULT NULL, + `status` int(11) NOT NULL, + PRIMARY KEY (`techid`) +) ENGINE = InnoDB AUTO_INCREMENT = 3 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */ +; -- -- Dumping data for table `techs` -- LOCK TABLES `techs` WRITE; -/*!40000 ALTER TABLE `techs` DISABLE KEYS */; -INSERT INTO `techs` VALUES -(1,'OpenLogAdmin',1,1,'$2y$10$6eCxUFNzoAkycMJpZ.zvaOfoByYhqi0YicQbut3XGc/TRxyxiUwcm',1); -/*!40000 ALTER TABLE `techs` ENABLE KEYS */; +/*!40000 ALTER TABLE `techs` DISABLE KEYS */ +; +set autocommit = 0; + +INSERT INTO + `techs` +VALUES ( + 1, + 'OpenLogAdmin', + 1, + 1, + '$2y$10$6eCxUFNzoAkycMJpZ.zvaOfoByYhqi0YicQbut3XGc/TRxyxiUwcm', + 1 + ); +/*!40000 ALTER TABLE `techs` ENABLE KEYS */ +; UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +commit; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */ +; --- Dump completed on 2024-07-09 14:36:00 +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */ +; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */ +; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */ +; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */ +; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */ +; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */ +; +/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */ +; + +-- Dump completed on 2026-02-19 14:18:01 \ No newline at end of file diff --git a/database-update.sh b/database-update.sh index cc37f86..45e45c2 100755 --- a/database-update.sh +++ b/database-update.sh @@ -6,6 +6,19 @@ # SPDX-License-Identifier: GPL-2.0 +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 +} if [[ $1 == "" ]] then @@ -37,3 +50,97 @@ 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." + echo "This may take some time..." + ( + 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 + ) & + task_pid=$! + spinner $task_pid + 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." + echo "This may take some time..." + ( + 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 + ) & + task_pid=$! + spinner $task_pid + echo "...done." + echo "Importing template reference chain data into new reflinks table." + echo "This may take some time..." + ( + 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 + ) & + task_pid=$! + spinner $task_pid + 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." +# ------------------------------------- diff --git a/database-update.sql b/database-update.sql index 20326fb..a5d096e 100644 --- a/database-update.sql +++ b/database-update.sql @@ -2,56 +2,85 @@ -- ---------- version 5.2.1 ------------- -- Make confname a unique column -ALTER TABLE configs ADD UNIQUE(confname); +ALTER TABLE configs ADD UNIQUE (confname); -- Delete db name, user, and password configs -DELETE FROM configs where confname="ol_dbname"; -DELETE FROM configs where confname="ol_dbuser"; -DELETE FROM configs where confname="ol_dbpass"; +DELETE FROM configs where confname = "ol_dbname"; + +DELETE FROM configs where confname = "ol_dbuser"; + +DELETE FROM configs where confname = "ol_dbpass"; -- Add config option for server side error logging -INSERT IGNORE INTO configs(confname,confvalue) values('log_errors','0') +INSERT IGNORE INTO + configs (confname, confvalue) +values ('log_errors', '0') -- Update version number -UPDATE configs SET confvalue="5.2.1" WHERE confname="ol_version"; +UPDATE configs SET confvalue = "5.2.1" WHERE confname = "ol_version"; -- -------------------------------------- -- ---------- version 5.2.2 ------------- -- Update version number -UPDATE configs SET confvalue="5.2.2" WHERE confname="ol_version"; +UPDATE configs SET confvalue = "5.2.2" WHERE confname = "ol_version"; -- -------------------------------------- -- ---------- version 5.2.3 ------------- -- Update version number -UPDATE configs SET confvalue="5.2.3" WHERE confname="ol_version"; +UPDATE configs SET confvalue = "5.2.3" WHERE confname = "ol_version"; -- -------------------------------------- -- ---------- version 5.2.4 ------------- -- Update version number -UPDATE configs SET confvalue="5.2.4" WHERE confname="ol_version"; +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"; +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"; +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"; +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"; +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"; +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; + +-- -------------------------------------- \ No newline at end of file diff --git a/db.php.template b/db.php.template index 084f062..147da5c 100644 --- a/db.php.template +++ b/db.php.template @@ -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 */ @@ -14,10 +14,10 @@ ** DO NOT EDIT ** ************************************************************************ */ -$appname="APPNAME"; -$dbname="DBNAME"; -$username="DBUSER"; -$dbpass="DBPASS"; +$appname = "APPNAME"; +$dbname = "DBNAME"; +$username = "DBUSER"; +$dbpass = "DBPASS"; function dberrmsg($dbname) { echo " @@ -34,7 +34,7 @@ function dberrmsg($dbname) { exit(); } -$db=@mysqli_connect("localhost",$username,$dbpass,$dbname); +$db = @mysqli_connect("localhost",$username,$dbpass,$dbname); if (mysqli_errno($db)) { dberrmsg($dbname); } diff --git a/default-apache.conf b/default-apache.conf new file mode 100644 index 0000000..d6cb9d2 --- /dev/null +++ b/default-apache.conf @@ -0,0 +1,13 @@ +# _APPNAME_ default Apache configuration + +Alias /_BASEURL_ _DOCROOTIN_/_BASEURL_ + + + AllowOverride Options + Options FollowSymLinks + DirectoryIndex index.php + + #RewriteEngine On + #RewriteBase /_BASEURL_/ + #RewriteRule . maintenancemode.php [L] + diff --git a/distfiles/CHANGELOG b/distfiles/CHANGELOG index dbadc6b..e78488e 100644 --- a/distfiles/CHANGELOG +++ b/distfiles/CHANGELOG @@ -1,6 +1,6 @@ CHANGELOG OpenLog Online Logbook - Copyright (C) 2025 Rod Wright + Copyright (C) 2026 Rod Wright SPDX-License-Identifier: GPL-2.0 @@ -233,7 +233,7 @@ installers. 5.2.4.4 - 2025-12-19 - -Fixed bugs that caused crashes on the Scheduled Maintenance page + - 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 @@ -244,4 +244,43 @@ 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. + +5.3.0 - 2026-02-20 + - Moved the template Create/Copy/Edit/Delete/Rename functionality to + its own page to make it less confusing and to fix some strange + behavior. + - Added global templates which can be used by anyone but can only be + created, modified, or deleted by administrators. This makes it + easier to employ standardized templates. + - Changed the character encoding of the database to utf8mb4 to enable + using emojis in text fields. + - Changed the insert link functionality. There are now two fields, link + text, and URL. The full URL string will now not be displayed in the + note, since it frequently was too long and deformed the table, + causing the user to have to scroll right to see the entire note. If + a URL is entered in the URL field and no link text is entered in the + link text field, the link will show up as just the last part of the + URL. For example, "http://somewhere.com/myfile.pdf" will show as + "myfile.pdf" in the note text. If text is entered in the link text + field, that is what will show as the clickable link in the note text. + NOTE: URLs in previously entered notes will not automatically be + converted. + - Changed the flag handling code to no longer dynamically create flag_ + tables in the database to track assignments. This is now done using + a flagmap table. + NOTE: The database will be modified to support this and the + importation of the previous data will take some time during + installation. + - References will no longer be stored in the lognotes table with the note. + There is now a reflinks table that stores the link information. + NOTE: The database will be modified to support this and the + importation of the previous data will take some time during + installation. + - Various code cleanups to prevent php warnings in the logs if logging + is enabled. + - Validate all date and time fields to prevent user entered invalid date + formats from crashing php. + - Fixed profile page to automatically refresh page to show the results + when a user changes their color preferences. + diff --git a/distfiles/INSTALL b/distfiles/INSTALL index c7ced63..d808a4f 100644 --- a/distfiles/INSTALL +++ b/distfiles/INSTALL @@ -1,6 +1,6 @@ INSTALL OpenLog Online Logbook - Copyright (C) 2025 Rod Wright + Copyright (C) 2026 Rod Wright SPDX-License-Identifier: GPL-2.0 @@ -14,16 +14,14 @@ allow clients to reach them. You'll also need to know the username and password of the MySQL administrator. 2. Unpack -Unpack the distribution in a convenient place (such as /tmp or My Documents). +Unpack the distribution in a convenient place. A directory will be created called OpenLog-x.x.x. 3. Review License -Change to the openlog-x.x.x directory and review the LICENSE file. +Change to the OpenLog-x.x.x directory and review the LICENSE file. 4. Run the install script -If installing on a Linux or Unix based system, type ./install.sh at a -command prompt. If installing on a Windows based system, double click -install.bat. Follow the prompts. +Type ./install.sh at a command prompt. Follow the prompts. 5. Check and set Configuration Click on the Administration menu option on the main page to adjust the initial diff --git a/distfiles/about.php b/distfiles/about.php index af3b950..9ebfa31 100644 --- a/distfiles/about.php +++ b/distfiles/about.php @@ -2,33 +2,33 @@ /* about.php OpenLog Online Logbook - Copyright (C) 2025 Rod Wright + Copyright (C) 2026 Rod Wright SPDX-License-Identifier: GPL-2.0 */ include("functions.php"); -$version=OL_VERSION; +$version = OL_VERSION; -$print=$_REQUEST['print'] ?? NULL; +$print = $_REQUEST['print'] ?? NULL; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } -framework("begin","About OpenLog","About OpenLog",$print); +framework("begin", "About OpenLog", "About OpenLog", $print); pagetable("begin"); -if(!$print){ - pageblock("left","begin"); +if (!$print) { + pageblock("left", "begin"); sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); echo "

OpenLog $version @@ -87,10 +87,8 @@ border=0>Fugue
Icons
The icons used in OpenLog ar

-"; -pageblock("right","end"); +"; +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/admin.php b/distfiles/admin.php index daa09a2..a2373a4 100644 --- a/distfiles/admin.php +++ b/distfiles/admin.php @@ -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 */ @@ -10,710 +10,723 @@ include("functions.php"); if (!isset($_SESSION['login'])) { - header ("Location: login.php"); + header("Location: login.php"); } // get user's admin status -$loginid=$_SESSION['login'] ?? NULL; -$isadmin=dblookup($db,"techs","techid","admin",$loginid); -$print=$_REQUEST['print'] ?? NULL; -$table=$_REQUEST['table'] ?? NULL; -$edit=$_REQUEST['edit'] ?? NULL; -$add=$_REQUEST['add'] ?? NULL; -$update=$_REQUEST['update'] ?? NULL; -$delete=$_REQUEST['delete'] ?? NULL; -$id=$_REQUEST['id'] ?? NULL; -$name=$_REQUEST['name'] ?? NULL; -$admin=$_REQUEST['admin'] ?? NULL; -$shift=$_REQUEST['shift'] ?? NULL; -$pass=$_REQUEST['pass'] ?? NULL; -$passconf=$_REQUEST['passconf'] ?? NULL; -$belowlink=$_REQUEST['belowlink'] ?? NULL; -$url=$_REQUEST['url'] ?? NULL; -$flagsym=$_REQUEST['flagsym'] ?? NULL; -$flagcolor=$_REQUEST['flagcolor'] ?? NULL; -$bnrcolor=$_REQUEST['bnrcolor'] ?? NULL; -$bnrtxtcolor=$_REQUEST['bnrtxtcolor'] ?? NULL; -$active=$_REQUEST['active'] ?? NULL; -$type=$_REQUEST['type'] ?? NULL; -$display_logname=$_REQUEST['display_logname'] ?? NULL; -$display_urlchunk=$_REQUEST['display_urlchunk'] ?? NULL; -$display_banner=$_REQUEST['display_banner'] ?? NULL; -$display_footer=$_REQUEST['display_footer'] ?? NULL; -$display_showts=$_REQUEST['display_showts'] ?? NULL; -$display_techalpha=$_REQUEST['display_techalpha'] ?? NULL; -$display_subjalpha=$_REQUEST['display_subjalpha'] ?? NULL; -$display_logstyle=$_REQUEST['display_logstyle'] ?? NULL; -$display_uidtext=$_REQUEST['display_uidtext'] ?? NULL; -$modcolor=$_REQUEST['modcolor'] ?? NULL; -$hexcolor=$_REQUEST['hexcolor'] ?? NULL; -$db_dbname=$_REQUEST['db_dbname'] ?? NULL; -$misc_sessttl=$_REQUEST['misc_sessttl'] ?? NULL; -$misc_sessdir=$_REQUEST['misc_sessdir'] ?? NULL; -$misc_logoutall=$_REQUEST['misc_logoutall'] ?? NULL; -$misc_partfuncs=$_REQUEST['misc_partfuncs'] ?? NULL; -$misc_schedmaintfuncs=$_REQUEST['misc_schedmaintfuncs'] ?? NULL; +$loginid = $_SESSION['login'] ?? NULL; +$isadmin = dblookup($db, "techs", "techid", "admin", $loginid); +$print = $_REQUEST['print'] ?? NULL; +$table = $_REQUEST['table'] ?? NULL; +$edit = $_REQUEST['edit'] ?? NULL; +$add = $_REQUEST['add'] ?? NULL; +$update = $_REQUEST['update'] ?? NULL; +$delete = $_REQUEST['delete'] ?? NULL; +$id = $_REQUEST['id'] ?? NULL; +$name = $_REQUEST['name'] ?? NULL; +$admin = $_REQUEST['admin'] ?? NULL; +$shift = $_REQUEST['shift'] ?? NULL; +$pass = $_REQUEST['pass'] ?? NULL; +$passconf = $_REQUEST['passconf'] ?? NULL; +$belowlink = $_REQUEST['belowlink'] ?? NULL; +$url = $_REQUEST['url'] ?? NULL; +$flagsym = $_REQUEST['flagsym'] ?? NULL; +$flagcolor = $_REQUEST['flagcolor'] ?? NULL; +$bnrcolor = $_REQUEST['bnrcolor'] ?? NULL; +$bnrtxtcolor = $_REQUEST['bnrtxtcolor'] ?? NULL; +$active = $_REQUEST['active'] ?? NULL; +$type = $_REQUEST['type'] ?? NULL; +$display_logname = $_REQUEST['display_logname'] ?? NULL; +$display_urlchunk = $_REQUEST['display_urlchunk'] ?? NULL; +$display_banner = $_REQUEST['display_banner'] ?? NULL; +$display_footer = $_REQUEST['display_footer'] ?? NULL; +$display_showts = $_REQUEST['display_showts'] ?? NULL; +$display_techalpha = $_REQUEST['display_techalpha'] ?? NULL; +$display_subjalpha = $_REQUEST['display_subjalpha'] ?? NULL; +$display_logstyle = $_REQUEST['display_logstyle'] ?? NULL; +$display_uidtext = $_REQUEST['display_uidtext'] ?? NULL; +$modcolor = $_REQUEST['modcolor'] ?? NULL; +$hexcolor = $_REQUEST['hexcolor'] ?? NULL; +$db_dbname = $_REQUEST['db_dbname'] ?? NULL; +$misc_sessttl = $_REQUEST['misc_sessttl'] ?? NULL; +$misc_sessdir = $_REQUEST['misc_sessdir'] ?? NULL; +$misc_logoutall = $_REQUEST['misc_logoutall'] ?? NULL; +$misc_partfuncs = $_REQUEST['misc_partfuncs'] ?? NULL; +$misc_schedmaintfuncs = $_REQUEST['misc_schedmaintfuncs'] ?? NULL; -$logname=LOG_NAME; +$logname = LOG_NAME; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } -framework("begin","$logname","Administration",$print); +framework("begin", "$logname", "Administration", $print); //var_dump($_REQUEST); pagetable("begin"); -if(!$print){ - pageblock("left","begin"); +if (!$print) { + pageblock("left", "begin"); if ($isadmin) { // ******** begin database manipulation ******** if ($add) { - switch($table) { + switch ($table) { case "techs": - if ($admin) $admin=1; else $admin=0; - if ($active) $active=1; else $active=0; + if ($admin) $admin = 1; + else $admin = 0; + if ($active) $active = 1; + else $active = 0; // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Tech name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select techid from techs where techname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select techid from techs where techname=\"$name\""))) { + $nameunique = FALSE; echo " Tech name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } // test for matching passwords - if ($pass==$passconf) { - $passmatch=1; - $passhash=password_hash($pass,PASSWORD_DEFAULT); + if ($pass == $passconf) { + $passmatch = TRUE; + $passhash = password_hash($pass, PASSWORD_DEFAULT); } else { - $passmatch=0; + $passmatch = FALSE; echo " The passwords you supplied don't match.
"; } if ($namesuppld && $nameunique && $passmatch) { // modify the table - $addqry=("insert into techs(techname,admin,shift,techpass,status) values(\"$name\",\"$admin\",\"$shift\",\"$passhash\",\"$active\")"); - mysqli_query($db,$addqry); + $addqry = ("insert into techs(techname,admin,shift,techpass,status) values(\"$name\",\"$admin\",\"$shift\",\"$passhash\",\"$active\")"); + mysqli_query($db, $addqry); } break; case "shifts": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Shift name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select shiftid from shifts where shiftname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select shiftid from shifts where shiftname=\"$name\""))) { + $nameunique = FALSE; echo " Shift name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } if ($namesuppld && $nameunique) { // modify the table - $addqry=("insert into shifts(shiftname,status) values(\"$name\",\"$active\")"); - mysqli_query($db,$addqry); + $addqry = ("insert into shifts(shiftname,status) values(\"$name\",\"$active\")"); + mysqli_query($db, $addqry); } break; case "subjects": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Subject name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select subjectid from subjects where subjectname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select subjectid from subjects where subjectname=\"$name\""))) { + $nameunique = FALSE; echo " Subject name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } if ($namesuppld && $nameunique) { // modify the table - $addqry=("insert into subjects(subjectname,status) values(\"$name\",\"$active\")"); - mysqli_query($db,$addqry); + $addqry = ("insert into subjects(subjectname,status) values(\"$name\",\"$active\")"); + mysqli_query($db, $addqry); } break; case "links": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Display text cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select linkid from links where displaytxt=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select linkid from links where displaytxt=\"$name\""))) { + $nameunique = FALSE; echo " Display text already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } // test for urltxt supplied if (strlen(trim($url))) { - $urlsuppld=1; + $urlsuppld = TRUE; } else { - $urlsuppld=0; + $urlsuppld = FALSE; echo " URL text cannot be blank.
"; } if ($namesuppld && $nameunique && $urlsuppld) { // bump entries with linkpriority higher than belowlink up by one if necessary - $mypriority=$belowlink+1; - if (mysqli_num_rows(mysqli_query($db,"select linkpriority from links where linkpriority=\"$mypriority\""))) { - mysqli_query($db,"update links set linkpriority=linkpriority+1 where linkpriority>\"$belowlink\""); + $mypriority = $belowlink + 1; + if (mysqli_num_rows(mysqli_query($db, "select linkpriority from links where linkpriority=\"$mypriority\""))) { + mysqli_query($db, "update links set linkpriority=linkpriority+1 where linkpriority>\"$belowlink\""); } // insert the link - mysqli_query($db,"insert into links(linkpriority,displaytxt,urltxt,status) values(\"$mypriority\",\"$name\",\"$url\",\"$active\")"); + mysqli_query($db, "insert into links(linkpriority,displaytxt,urltxt,status) values(\"$mypriority\",\"$name\",\"$url\",\"$active\")"); } break; case "flags": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Flag name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select flagid from flags where flagname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagname=\"$name\""))) { + $nameunique = FALSE; echo " Flag name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } // test for symbol supplied if (strlen(trim($flagsym))) { - $symsuppld=1; + $symsuppld = TRUE; } else { - $symsuppld=0; + $symsuppld = FALSE; echo " Flag symbol cannot be blank.
"; } // test for symbol unique - if (mysqli_num_rows(mysqli_query($db,"select flagid from flags where flagsym=\"$flagsym\""))) { - $symunique=0; + if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagsym=\"$flagsym\""))) { + $symunique = FALSE; echo " Flag symbol already exists.
"; } else { - $symunique=1; + $symunique = TRUE; } if ($namesuppld && $nameunique && $symsuppld && $symunique) { - // insert record in links table - mysqli_query($db,"insert into flags(flagname,flagsym,flagcolor,status) values(\"$name\",\"$flagsym\",\"$flagcolor\",\"$active\")"); - // create sub tables for this link - $lastflagid=mysqli_insert_id($db); - mysqli_query($db,"create table flag_$lastflagid(target tinytext,id int not null)"); + // insert record in flags table + mysqli_query($db, "insert into flags(flagname,flagsym,flagcolor,status) values(\"$name\",\"$flagsym\",\"$flagcolor\",\"$active\")"); } break; case "logpartactions": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Part Action name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select lpactionid from logpartactions where lpactionname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select lpactionid from logpartactions where lpactionname=\"$name\""))) { + $nameunique = FALSE; echo " Part Action name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } if ($namesuppld && $nameunique) { // modify the table - $addqry=("insert into logpartactions(lpactionname,status) values(\"$name\",\"$active\")"); - mysqli_query($db,$addqry); + $addqry = ("insert into logpartactions(lpactionname,status) values(\"$name\",\"$active\")"); + mysqli_query($db, $addqry); } break; case "banners": // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Banner name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select bannerid from banners where bannername=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select bannerid from banners where bannername=\"$name\""))) { + $nameunique = FALSE; echo " Banner name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } if ($namesuppld && $nameunique) { // modify the table - $addqry=("insert into banners(bannername,bannercolor,textcolor) values(\"$name\",\"$bnrcolor\",\"$bnrtxtcolor\")"); - mysqli_query($db,$addqry); + $addqry = ("insert into banners(bannername,bannercolor,textcolor) values(\"$name\",\"$bnrcolor\",\"$bnrtxtcolor\")"); + mysqli_query($db, $addqry); } break; - default : - framework("begin","$logname Administration","Error",$print); - echo "unknown table"; - framework("end","","",$print); - exit(); + default: + framework("begin", "$logname Administration", "Error", $print); + echo "unknown table"; + framework("end", "", "", $print); + exit(); } } if ($edit) { - switch($table) { + switch ($table) { case "techs": - if ($admin) $admin=1; else $admin=0; - if ($active) $active=1; else $active=0; + if ($admin) $admin = 1; + else $admin = 0; + if ($active) $active = 1; + else $active = 0; if ($delete) { // check for log notes by this tech - if (mysqli_num_rows(mysqli_query($db,"select lognoteid from lognotes where tech=\"$id\""))) { - $hasnotes=1; + if (mysqli_num_rows(mysqli_query($db, "select lognoteid from lognotes where tech=\"$id\""))) { + $hasnotes = TRUE; echo " Tech has notes in logbook and cannot be deleted.
"; } else { - $hasnotes=0; + $hasnotes = FALSE; } // check for maintenance forms by this tech - if (mysqli_num_rows(mysqli_query($db,"select maintformid from maintforms where mftech=\"$id\""))) { - $hasmfs=1; + if (mysqli_num_rows(mysqli_query($db, "select maintformid from maintforms where mftech=\"$id\""))) { + $hasmfs = TRUE; echo " Tech has maintenance forms and cannot be deleted.
"; } else { - $hasmfs=0; + $hasmfs = FALSE; } // check for maintenance actions by this tech - if (mysqli_num_rows(mysqli_query($db,"select maintactionid from maintactions where actiontech=\"$id\""))) { - $hasmas=1; + if (mysqli_num_rows(mysqli_query($db, "select maintactionid from maintactions where actiontech=\"$id\""))) { + $hasmas = TRUE; echo " Tech has maintenance actions and cannot be deleted.
"; } else { - $hasmas=0; + $hasmas = FALSE; } if (!$hasnotes && !$hasmfs && !$hasmas) { // delete entity - mysqli_query($db,"delete from techs where techid=\"$id\""); + mysqli_query($db, "delete from techs where techid=\"$id\""); } } if ($update) { // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Tech name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select techid from techs where techname=\"$name\" and techid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select techid from techs where techname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select techid from techs where techname=\"$name\" and techid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select techid from techs where techname=\"$name\""))) { + $nameunique = FALSE; echo " Tech name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } } else { - $nameunique=1; + $nameunique = TRUE; } // test for matching passwords - if ($pass!="password_is_unchanged") { - if ($pass==$passconf) { - $passmatch=1; - $passhash=password_hash($pass,PASSWORD_DEFAULT); - $updqry=("update techs set techname=\"$name\",admin=\"$admin\",shift=\"$shift\",techpass=\"$passhash\",status=\"$active\" where techid=\"$id\""); + if ($pass != "password_is_unchanged") { + if ($pass == $passconf) { + $passmatch = TRUE; + $passhash = password_hash($pass, PASSWORD_DEFAULT); + $updqry = ("update techs set techname=\"$name\",admin=\"$admin\",shift=\"$shift\",techpass=\"$passhash\",status=\"$active\" where techid=\"$id\""); } else { - $passmatch=0; + $passmatch = FALSE; echo " The passwords you supplied don't match.
"; } } else { - $passmatch=1; - $updqry="update techs set techname=\"$name\",admin=\"$admin\",shift=\"$shift\",status=\"$active\" where techid=\"$id\""; + $passmatch = TRUE; + $updqry = "update techs set techname=\"$name\",admin=\"$admin\",shift=\"$shift\",status=\"$active\" where techid=\"$id\""; } if ($namesuppld && $nameunique && $passmatch) { // modify the table - mysqli_query($db,$updqry); + mysqli_query($db, $updqry); } } break; case "shifts": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; if ($delete) { // check for log notes with this shift - if (mysqli_num_rows(mysqli_query($db,"select lognoteid from lognotes where shift=\"$id\""))) { - $hasnotes=1; + if (mysqli_num_rows(mysqli_query($db, "select lognoteid from lognotes where shift=\"$id\""))) { + $hasnotes = TRUE; echo " Shift has notes in logbook and cannot be deleted.
"; } else { - $hasnotes=0; + $hasnotes = FALSE; } if (!$hasnotes) { // delete entity - mysqli_query($db,"delete from shifts where shiftid=\"$id\""); + mysqli_query($db, "delete from shifts where shiftid=\"$id\""); } } if ($update) { // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Shift name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select shiftid from shifts where shiftname=\"$name\" and shiftid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select shiftid from shifts where shiftname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select shiftid from shifts where shiftname=\"$name\" and shiftid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select shiftid from shifts where shiftname=\"$name\""))) { + $nameunique = FALSE; echo " Shift name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } } else { - $nameunique=1; + $nameunique = TRUE; } if ($namesuppld && $nameunique) { // modify the table - mysqli_query($db,"update shifts set shiftname=\"$name\",status=\"$active\" where shiftid=\"$id\""); + mysqli_query($db, "update shifts set shiftname=\"$name\",status=\"$active\" where shiftid=\"$id\""); } } break; case "subjects": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; if ($delete) { // check for log notes with this subject - if (mysqli_num_rows(mysqli_query($db,"select lognoteid from lognotes where subject=\"$id\""))) { - $hasnotes=1; + if (mysqli_num_rows(mysqli_query($db, "select lognoteid from lognotes where subject=\"$id\""))) { + $hasnotes = TRUE; echo " Subject has notes in logbook and cannot be deleted.
"; } else { - $hasnotes=0; + $hasnotes = FALSE; } if (!$hasnotes) { // delete entity - mysqli_query($db,"delete from subjects where subjectid=\"$id\""); + mysqli_query($db, "delete from subjects where subjectid=\"$id\""); } } if ($update) { // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Subject name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select subjectid from subjects where subjectname=\"$name\" and subjectid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select subjectid from subjects where subjectname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select subjectid from subjects where subjectname=\"$name\" and subjectid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select subjectid from subjects where subjectname=\"$name\""))) { + $nameunique = FALSE; echo " Subject name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } } else { - $nameunique=1; + $nameunique = TRUE; } if ($namesuppld && $nameunique) { // modify the table - mysqli_query($db,"update subjects set subjectname=\"$name\",status=\"$active\" where subjectid=\"$id\""); + mysqli_query($db, "update subjects set subjectname=\"$name\",status=\"$active\" where subjectid=\"$id\""); } } break; case "links": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; if ($delete) { - mysqli_query($db,"delete from links where linkid=\"$id\""); + mysqli_query($db, "delete from links where linkid=\"$id\""); } if ($update) { // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Display text cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select linkid from links where displaytxt=\"$name\" and linkid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select linkid from links where displaytxt=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select linkid from links where displaytxt=\"$name\" and linkid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select linkid from links where displaytxt=\"$name\""))) { + $nameunique = FALSE; echo " Display text already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } } else { - $nameunique=1; + $nameunique = TRUE; } // test for urltxt supplied if (strlen(trim($url))) { - $urlsuppld=1; + $urlsuppld = TRUE; } else { - $urlsuppld=0; + $urlsuppld = FALSE; echo " URL text cannot be blank.
"; } if ($namesuppld && $nameunique && $urlsuppld) { // bump entries with linkpriority higher than belowlink up by one if necessary - $mypriority=$belowlink+1; - if (mysqli_num_rows(mysqli_query($db,"select linkpriority from links where linkpriority=\"$mypriority\""))) { - mysqli_query($db,"update links set linkpriority=linkpriority+1 where linkpriority>\"$belowlink\""); + $mypriority = $belowlink + 1; + if (mysqli_num_rows(mysqli_query($db, "select linkpriority from links where linkpriority=\"$mypriority\""))) { + mysqli_query($db, "update links set linkpriority=linkpriority+1 where linkpriority>\"$belowlink\""); } // update the link - mysqli_query($db,"update links set linkpriority=\"$mypriority\",displaytxt=\"$name\",urltxt=\"$url\",status=\"$active\" where linkid=\"$id\""); + mysqli_query($db, "update links set linkpriority=\"$mypriority\",displaytxt=\"$name\",urltxt=\"$url\",status=\"$active\" where linkid=\"$id\""); } } break; case "flags": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; if ($delete) { // check for things using this flag - if (mysqli_num_rows(mysqli_query($db,"select * from flag_$id"))) { - $used=1; + if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$id\""))) { + $used = TRUE; echo " Flag is used by other tables and cannot be deleted.
"; } else { - $used=0; + $used = FALSE; } if (!$used) { // delete entity - mysqli_query($db,"delete from flags where flagid=\"$id\""); - mysqli_query($db,"drop table flag_$id"); + mysqli_query($db, "delete from flags where flagid=\"$id\""); } } if ($update) { // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Flag name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select flagid from flags where flagname=\"$name\" and flagid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select flagid from flags where flagname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagname=\"$name\" and flagid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagname=\"$name\""))) { + $nameunique = FALSE; echo " Flag name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } } else { - $nameunique=1; + $nameunique = TRUE; } // test for symbol supplied if (strlen(trim($flagsym))) { - $symsuppld=1; + $symsuppld = TRUE; } else { - $symsuppld=0; + $symsuppld = FALSE; echo " Flag symbol cannot be blank.
"; } // test for symbol unique - if (mysqli_num_rows(mysqli_query($db,"select flagid from flags where flagsym=\"$flagsym\" and flagid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select flagid from flags where flagsym=\"$flagsym\""))) { - $symunique=0; + if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagsym=\"$flagsym\" and flagid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagsym=\"$flagsym\""))) { + $symunique = FALSE; echo " Flag symbol already exists.
"; } else { - $symunique=1; + $symunique = TRUE; } } else { - $symunique=1; + $symunique = TRUE; } if ($namesuppld && $nameunique && $symsuppld && $symunique) { // modify the table - mysqli_query($db,"update flags set flagname=\"$name\",flagsym=\"$flagsym\",flagcolor=\"$flagcolor\",status=\"$active\" where flagid=\"$id\""); + mysqli_query($db, "update flags set flagname=\"$name\",flagsym=\"$flagsym\",flagcolor=\"$flagcolor\",status=\"$active\" where flagid=\"$id\""); } } break; case "logpartactions": - if ($active) $active=1; else $active=0; + if ($active) $active = 1; + else $active = 0; if ($delete) { // check for logparts with this part action - if (mysqli_num_rows(mysqli_query($db,"select logpartid from logparts where action=\"$id\""))) { - $hasparts=1; + if (mysqli_num_rows(mysqli_query($db, "select logpartid from logparts where action=\"$id\""))) { + $hasparts = TRUE; echo " Action is assigned to parts in logbook notes and cannot be deleted.
"; } else { - $hasparts=0; + $hasparts = FALSE; } if (!$hasparts) { // delete entity - mysqli_query($db,"delete from logpartactions where lpactionid=\"$id\""); + mysqli_query($db, "delete from logpartactions where lpactionid=\"$id\""); } } if ($update) { // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Part Action name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select lpactionid from logpartactions where lpactionname=\"$name\" and lpactionid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select lpactionid from logpartactions where lpactionname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select lpactionid from logpartactions where lpactionname=\"$name\" and lpactionid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select lpactionid from logpartactions where lpactionname=\"$name\""))) { + $nameunique = FALSE; echo " Part Action name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } } else { - $nameunique=1; + $nameunique = TRUE; } if ($namesuppld && $nameunique) { // modify the table - mysqli_query($db,"update logpartactions set lpactionname=\"$name\",status=\"$active\" where lpactionid=\"$id\""); + mysqli_query($db, "update logpartactions set lpactionname=\"$name\",status=\"$active\" where lpactionid=\"$id\""); } } break; case "banners": if ($delete) { // delete entity - mysqli_query($db,"delete from banners where bannerid=\"$id\""); + mysqli_query($db, "delete from banners where bannerid=\"$id\""); } if ($update) { // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Banner name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select bannerid from banners where bannername=\"$name\" and bannerid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select bannerid from banners where bannername=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select bannerid from banners where bannername=\"$name\" and bannerid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select bannerid from banners where bannername=\"$name\""))) { + $nameunique = FALSE; echo " Banner name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } } else { - $nameunique=1; + $nameunique = TRUE; } if ($namesuppld && $nameunique) { // modify the table - mysqli_query($db,"update banners set bannername=\"$name\",bannercolor=\"$bnrcolor\",textcolor=\"$bnrtxtcolor\" where bannerid=\"$id\""); + mysqli_query($db, "update banners set bannername=\"$name\",bannercolor=\"$bnrcolor\",textcolor=\"$bnrtxtcolor\" where bannerid=\"$id\""); } } break; - case "configs" : - switch($type) { - case "display" : - if ($display_showts) $display_showts=1; else $display_showts=0; - if ($display_techalpha=="a") $display_techalpha=1; else $display_techalpha=0; - if ($display_subjalpha=="a") $display_subjalpha=1; else $display_subjalpha=0; + case "configs": + switch ($type) { + case "display": + if ($display_showts) $display_showts = 1; + else $display_showts = 0; + if ($display_techalpha == "a") $display_techalpha = 1; + else $display_techalpha = 0; + if ($display_subjalpha == "a") $display_subjalpha = 1; + else $display_subjalpha = 0; // test for logname supplied if (strlen(trim($display_logname))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Log name cannot be blank.
"; } // test for urlchunk supplied if (strlen(trim($display_urlchunk))) { - $chunksuppld=1; + $chunksuppld = TRUE; } else { - $chunksuppld=0; + $chunksuppld = FALSE; echo " URL chunk size cannot be blank.
"; } if ($namesuppld && $chunksuppld) { - mysqli_query($db,"update configs set confvalue=\"$display_logname\" where confname=\"log_name\""); - mysqli_query($db,"update configs set confvalue=\"$display_urlchunk\" where confname=\"url_chunk_size\""); - mysqli_query($db,"update configs set confvalue=\"$display_banner\" where confname=\"banner\""); - mysqli_query($db,"update configs set confvalue=\"$display_footer\" where confname=\"footer_message\""); - mysqli_query($db,"update configs set confvalue=\"$display_showts\" where confname=\"show_ts\""); - mysqli_query($db,"update configs set confvalue=\"$display_techalpha\" where confname=\"tech_alpha\""); - mysqli_query($db,"update configs set confvalue=\"$display_subjalpha\" where confname=\"subj_alpha\""); - mysqli_query($db,"update configs set confvalue=\"$display_logstyle\" where confname=\"log_style\""); - mysqli_query($db,"update configs set confvalue=\"$display_uidtext\" where confname=\"uid_text\""); - } + mysqli_query($db, "update configs set confvalue=\"$display_logname\" where confname=\"log_name\""); + mysqli_query($db, "update configs set confvalue=\"$display_urlchunk\" where confname=\"url_chunk_size\""); + mysqli_query($db, "update configs set confvalue=\"$display_banner\" where confname=\"banner\""); + mysqli_query($db, "update configs set confvalue=\"$display_footer\" where confname=\"footer_message\""); + mysqli_query($db, "update configs set confvalue=\"$display_showts\" where confname=\"show_ts\""); + mysqli_query($db, "update configs set confvalue=\"$display_techalpha\" where confname=\"tech_alpha\""); + mysqli_query($db, "update configs set confvalue=\"$display_subjalpha\" where confname=\"subj_alpha\""); + mysqli_query($db, "update configs set confvalue=\"$display_logstyle\" where confname=\"log_style\""); + mysqli_query($db, "update configs set confvalue=\"$display_uidtext\" where confname=\"uid_text\""); + } break; - case "color" : - $hexcolor="#".ltrim($hexcolor); - mysqli_query($db,"update configs set confvalue=\"$hexcolor\" where confname=\"$modcolor\""); + case "color": + $hexcolor = "#" . ltrim($hexcolor); + mysqli_query($db, "update configs set confvalue=\"$hexcolor\" where confname=\"$modcolor\""); break; case "misc": if ($misc_partfuncs) { - mysqli_query($db,"update configs set confvalue=\"1\" where confname=\"parts_functions\""); + mysqli_query($db, "update configs set confvalue=\"1\" where confname=\"parts_functions\""); } else { - mysqli_query($db,"update configs set confvalue=\"0\" where confname=\"parts_functions\""); + mysqli_query($db, "update configs set confvalue=\"0\" where confname=\"parts_functions\""); } if ($misc_logoutall) { if ($ostype == 'WIN') { - $sessfileloc=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"win_server_session_dir\""))[0]; + $sessfileloc = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"win_server_session_dir\""))[0]; } else { - $sessfileloc=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"unix_server_session_dir\""))[0]; + $sessfileloc = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"unix_server_session_dir\""))[0]; } - foreach (glob($sessfileloc."/*") as $sessfile) { + foreach (glob($sessfileloc . "/*") as $sessfile) { unlink($sessfile); } } if ($misc_schedmaintfuncs) { - mysqli_query($db,"update configs set confvalue=\"1\" where confname=\"schedmaint_functions\""); + mysqli_query($db, "update configs set confvalue=\"1\" where confname=\"schedmaint_functions\""); } else { - mysqli_query($db,"update configs set confvalue=\"0\" where confname=\"schedmaint_functions\""); + mysqli_query($db, "update configs set confvalue=\"0\" where confname=\"schedmaint_functions\""); } // test for sessttl supplied if (strlen(trim($misc_sessttl))) { - $ttlsuppld=1; + $ttlsuppld = TRUE; } else { - $ttlsuppld=0; + $ttlsuppld = FALSE; echo " Session expiration time cannot be blank.
"; } // test for sessdir supplied if (strlen(trim($misc_sessdir))) { - $dirsuppld=1; + $dirsuppld = TRUE; } else { - $dirsuppld=0; + $dirsuppld = FALSE; echo " Server session file directory cannot be blank.
"; } if ($ttlsuppld && $dirsuppld) { - mysqli_query($db,"update configs set confvalue=\"$misc_sessttl\" where confname=\"session_ttl_days\""); + mysqli_query($db, "update configs set confvalue=\"$misc_sessttl\" where confname=\"session_ttl_days\""); if ($ostype == 'WIN') { - mysqli_query($db,"update configs set confvalue=\"$misc_sessdir\" where confname=\"win_server_session_dir\""); + mysqli_query($db, "update configs set confvalue=\"$misc_sessdir\" where confname=\"win_server_session_dir\""); } else { - mysqli_query($db,"update configs set confvalue=\"$misc_sessdir\" where confname=\"unix_server_session_dir\""); + mysqli_query($db, "update configs set confvalue=\"$misc_sessdir\" where confname=\"unix_server_session_dir\""); } } break; - default : + default: echo "Unknown config type!"; break; } break; - default : - framework("begin","$logname Administration","Error",$print); + default: + framework("begin", "$logname Administration", "Error", $print); echo "unknown table"; - framework("end","","",$print); + framework("end", "", "", $print); exit(); } } // ******** end database manipulation ******** } - + // show help echo "
Changes made here are global and affect all users. You must have admin privileges to make changes to these settings. To set your personal preferences, you should use the My Profile page. "; - + sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); -banner($print); +pageblock("right", "begin"); +banner($print); // show the menu of tables echo " @@ -735,47 +748,55 @@ echo "

"; -switch($table) { - case "techs" : - if ($isadmin) { +switch ($table) { + case "techs": + if ($isadmin) { // show the form if ($edit) { // set form options for editing - $sectiontitle="Modify Tech

"; - $formtag="
"; - $buttontags=" + $sectiontitle = "Modify Tech

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from techs where techid=$id")); - $name=$currentvalues["techname"]; - $pass=$passconf="password_is_unchanged"; - $shift=$currentvalues["shift"]; - if ($currentvalues["admin"]==1) { - $admintag=""; + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from techs where techid=$id")); + if (!empty($currentvalues)) { + $name = $currentvalues["techname"]; + $pass = $passconf = "password_is_unchanged"; + $shift = $currentvalues["shift"]; + if ($currentvalues["admin"] == 1) { + $admintag = ""; + } else { + $admintag = ""; + } + if ($currentvalues["status"] == 1) { + $activetag = ""; + } else { + $activetag = ""; + } } else { - $admintag=""; - } - if ($currentvalues["status"]==1) { - $activetag=""; - } else { - $activetag=""; + $name = NULL; + $pass = NULL; + $shift = NULL; + $admintag = ""; + $activetag = ""; } } else { // set form options for add - $sectiontitle="Add New Tech

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Add New Tech

"; + $formtag = ""; + $buttontags = " "; // set default values - $admintag=""; - $activetag=""; + $admintag = ""; + $activetag = ""; } - + echo " $sectiontitle $formtag @@ -786,18 +807,18 @@ switch($table) { Repeat Password:  

Need a random password?   "; - $rpw=substr(str_shuffle(password_hash(microtime(),PASSWORD_DEFAULT)), 10, 12); + $rpw = substr(str_shuffle(password_hash(microtime(), PASSWORD_DEFAULT)), 10, 12); echo "  $rpw

Shift:            
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from shifts where shiftid=$id")); - $name=$currentvalues["shiftname"]; - if ($currentvalues["status"]==1) { - $activetag=""; + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from shifts where shiftid=$id")); + if (!empty($currentvalues)) { + $name = $currentvalues["shiftname"]; + if ($currentvalues["status"] == 1) { + $activetag = ""; + } else { + $activetag = ""; + } } else { - $activetag=""; + $name = NULL; + $activetag = ""; } } else { // set form options for add - $sectiontitle="Add New Shift

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Add New Shift

"; + $formtag = ""; + $buttontags = " "; // set default values - $activetag=""; + $activetag = ""; } - + echo " $sectiontitle $formtag @@ -894,62 +923,70 @@ switch($table) { "; } // show the table of entities - $existingdata=mysqli_query($db,"select shiftid,shiftname,status from shifts order by shiftid asc"); + $existingdata = mysqli_query($db, "select shiftid,shiftname,status from shifts order by shiftid asc"); echo " Existing Shifts   Click on the Shift ID to edit.

"; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { + while ($tablerow = mysqli_fetch_assoc($existingdata)) { if ($tablerow["status"]) { - $statdef="\"active\""; + $statdef = "\"active\""; } else { - $statdef="\"inactive\""; + $statdef = "\"inactive\""; } - printf(" + printf( + " ", - $tablerow["shiftid"],$tablerow["shiftid"], - $tablerow["shiftname"], - $statdef); + $tablerow["shiftid"], + $tablerow["shiftid"], + $tablerow["shiftname"], + $statdef + ); } echo "
Shift IDShift NameActive
%s %s %s
"; break; - case "subjects" : + case "subjects": if ($isadmin) { // show the form if ($edit) { // set form options for editing - $sectiontitle="Modify Subject

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Modify Subject

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from subjects where subjectid=$id")); - $name=$currentvalues["subjectname"]; - if ($currentvalues["status"]==1) { - $activetag=""; + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from subjects where subjectid=$id")); + if (!empty($currentvalues)) { + $name = $currentvalues["subjectname"]; + if ($currentvalues["status"] == 1) { + $activetag = ""; + } else { + $activetag = ""; + } } else { - $activetag=""; + $name = ""; + $activetag = ""; } } else { // set form options for add - $sectiontitle="Add New Subject

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Add New Subject

"; + $formtag = ""; + $buttontags = " "; // set default values - $activetag=""; + $activetag = ""; } - + echo " $sectiontitle $formtag @@ -965,100 +1002,110 @@ switch($table) { "; } // show the table of entities - $existingdata=mysqli_query($db,"select subjectid,subjectname,status from subjects order by subjectid asc"); + $existingdata = mysqli_query($db, "select subjectid,subjectname,status from subjects order by subjectid asc"); echo " Existing Subjects   Click on the Subject ID to edit.

"; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { + while ($tablerow = mysqli_fetch_assoc($existingdata)) { if ($tablerow["status"]) { - $statdef="\"active\""; + $statdef = "\"active\""; } else { - $statdef="\"inactive\""; + $statdef = "\"inactive\""; } - printf(" + printf( + " ", - $tablerow["subjectid"],$tablerow["subjectid"], - $tablerow["subjectname"], - $statdef); + $tablerow["subjectid"], + $tablerow["subjectid"], + $tablerow["subjectname"], + $statdef + ); } echo "
Subject IDSubject NameActive
%s %s %s
"; break; - case "links" : + case "links": if ($isadmin) { // show the form if ($edit) { // set form options for editing - $sectiontitle="Modify Link

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Modify Link

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from links where linkid=$id")); - $name=$currentvalues["displaytxt"]; - $priority=$currentvalues["linkpriority"]; - $url=$currentvalues["urltxt"]; - if ($currentvalues["status"]==1) { - $activetag=""; + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from links where linkid=$id")); + if (!empty($currentvalues)) { + $name = $currentvalues["displaytxt"]; + $priority = $currentvalues["linkpriority"]; + $url = $currentvalues["urltxt"]; + if ($currentvalues["status"] == 1) { + $activetag = ""; + } else { + $activetag = ""; + } } else { - $activetag=""; + $name = NULL; + $priority = NULL; + $url = NULL; + $activetag = ""; } // determine where we are in the priority stack - $prow=mysqli_fetch_assoc(mysqli_query($db,"select min(linkpriority) as highest from links")); - if ($prow["highest"]==$priority) { - $belowselection=0; + $prow = mysqli_fetch_assoc(mysqli_query($db, "select min(linkpriority) as highest from links")); + if ($prow["highest"] == $priority) { + $belowselection = 0; } else { - $abovelink=mysqli_fetch_row(mysqli_query($db,"select max(linkpriority) from links where linkpriority<\"$priority\"")); - $belowselection=$abovelink[0]; + $abovelink = mysqli_fetch_row(mysqli_query($db, "select max(linkpriority) from links where linkpriority<\"$priority\"")); + $belowselection = $abovelink[0]; } - $priorselect=""; + if ($belowselection == 0) { + $priorselect = $priorselect . ""; } else { - $priorselect=$priorselect . ""; + $priorselect = $priorselect . ""; } - $linkrow=mysqli_query($db,"select linkpriority,displaytxt from links order by linkpriority asc"); - while ($linkitem=mysqli_fetch_assoc($linkrow)) { - if ($belowselection==$linkitem["linkpriority"]) { - $priorselect=$priorselect . "\n"; + $linkrow = mysqli_query($db, "select linkpriority,displaytxt from links order by linkpriority asc"); + while ($linkitem = mysqli_fetch_assoc($linkrow)) { + if ($belowselection == $linkitem["linkpriority"]) { + $priorselect = $priorselect . "\n"; } else { - $priorselect=$priorselect . "\n"; + $priorselect = $priorselect . "\n"; } } - $priorselect=$priorselect . ""; + $priorselect = $priorselect . ""; } else { // set form options for add - $sectiontitle="Add New Link

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Add New Link

"; + $formtag = ""; + $buttontags = " "; // set default values - $abovelink=mysqli_fetch_row(mysqli_query($db,"select max(linkpriority) from links")); - $belowselection=$abovelink[0]; - $priorselect=""; + $priorselect = $priorselect . ""; + $linkrow = mysqli_query($db, "select linkpriority,displaytxt from links order by linkpriority asc"); + while ($linkitem = mysqli_fetch_assoc($linkrow)) { + if ($belowselection == $linkitem["linkpriority"]) { + $priorselect = $priorselect . "\n"; } else { - $priorselect=$priorselect . "\n"; + $priorselect = $priorselect . "\n"; } } - $priorselect=$priorselect . ""; - $activetag=""; + $priorselect = $priorselect . ""; + $activetag = ""; } - + echo " $sectiontitle $formtag @@ -1078,83 +1125,94 @@ switch($table) { "; } // show the table of entities - $existingdata=mysqli_query($db,"select linkid,displaytxt,urltxt,status from links order by linkpriority asc"); + $existingdata = mysqli_query($db, "select linkid,displaytxt,urltxt,status from links order by linkpriority asc"); echo " Existing Links   Click on the Link ID to edit.

"; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { + while ($tablerow = mysqli_fetch_assoc($existingdata)) { if ($tablerow["status"]) { - $statdef="\"active\""; + $statdef = "\"active\""; } else { - $statdef="\"inactive\""; + $statdef = "\"inactive\""; } - printf(" + printf( + " ", - $tablerow["linkid"],$tablerow["linkid"], - $tablerow["displaytxt"], - $tablerow["urltxt"],$tablerow["urltxt"], - $statdef); + $tablerow["linkid"], + $tablerow["linkid"], + $tablerow["displaytxt"], + $tablerow["urltxt"], + $tablerow["urltxt"], + $statdef + ); } echo "
Link IDDisplay TextURLActive
%s %s %s %s
"; break; - case "flags" : + case "flags": if ($isadmin) { // show the form if ($edit) { // set form options for editing - $sectiontitle="Modify Flag

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Modify Flag

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from flags where flagid=$id")); - $name=$currentvalues["flagname"]; - $flagsym=$currentvalues["flagsym"]; - $flagcolor=$currentvalues["flagcolor"]; - $flagcoloropts=""; - foreach($basic_colors as $cname => $chex) { - if ($chex==$flagcolor) { - $flagcoloropts=$flagcoloropts . ""; + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from flags where flagid=$id")); + if (!empty($currentvalues)) { + $name = $currentvalues["flagname"]; + $flagsym = $currentvalues["flagsym"]; + $flagcolor = $currentvalues["flagcolor"]; + $flagcoloropts = ""; + if ($currentvalues["status"] == 1) { + $activetag = ""; } else { - $flagcoloropts=$flagcoloropts . ""; + $activetag = ""; } - } - if ($currentvalues["status"]==1) { - $activetag=""; } else { - $activetag=""; + $name = NULL; + $flagsym = NULL; + $flagcolor = NULL; + $activetag = ""; + } + foreach ($basic_colors as $cname => $chex) { + if ($chex == $flagcolor) { + $flagcoloropts = $flagcoloropts . ""; + } else { + $flagcoloropts = $flagcoloropts . ""; + } } } else { // set form options for add - $sectiontitle="Add New Flag

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Add New Flag

"; + $formtag = ""; + $buttontags = " "; // set default values - $flagcolor="#FFFFFF"; - $flagcoloropts=""; - foreach($basic_colors as $cname => $chex) { - if ($chex==$flagcolor) { - $flagcoloropts=$flagcoloropts . ""; + $flagcolor = "#FFFFFF"; + $flagcoloropts = ""; + foreach ($basic_colors as $cname => $chex) { + if ($chex == $flagcolor) { + $flagcoloropts = $flagcoloropts . ""; } else { - $flagcoloropts=$flagcoloropts . ""; + $flagcoloropts = $flagcoloropts . ""; } } - $activetag=""; + $activetag = ""; } - + echo " $sectiontitle $formtag @@ -1175,64 +1233,73 @@ switch($table) { "; } // show the table of entities - $existingdata=mysqli_query($db,"select * from flags order by flagid asc"); + $existingdata = mysqli_query($db, "select * from flags order by flagid asc"); echo " Existing Flags   Click on the Flag ID to edit.

"; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { + while ($tablerow = mysqli_fetch_assoc($existingdata)) { if ($tablerow["status"]) { - $statdef="\"active\""; + $statdef = "\"active\""; } else { - $statdef="\"inactive\""; + $statdef = "\"inactive\""; } - printf(" + printf( + " ", - $tablerow["flagid"],$tablerow["flagid"], - $tablerow["flagname"], - $tablerow["flagcolor"],$tablerow["flagsym"], - $statdef); + $tablerow["flagid"], + $tablerow["flagid"], + $tablerow["flagname"], + $tablerow["flagcolor"], + $tablerow["flagsym"], + $statdef + ); } echo "
Flag IDFlag NameFlag SymbolActive
%s %s %s %s
"; break; - case "logpartactions" : + case "logpartactions": if ($isadmin) { // show the form if ($edit) { // set form options for editing - $sectiontitle="Modify Part Action

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Modify Part Action

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from logpartactions where lpactionid=$id")); - $name=$currentvalues["lpactionname"]; - if ($currentvalues["status"]==1) { - $activetag=""; + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from logpartactions where lpactionid=$id")); + if (!empty($currentvalues)) { + $name = $currentvalues["lpactionname"]; + if ($currentvalues["status"] == 1) { + $activetag = ""; + } else { + $activetag = ""; + } } else { - $activetag=""; + $name = NULL; + $activetag = ""; } } else { // set form options for add - $sectiontitle="Add New Part Action

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Add New Part Action

"; + $formtag = ""; + $buttontags = " "; // set default values - $activetag=""; + $activetag = ""; } - + echo " $sectiontitle $formtag @@ -1248,92 +1315,101 @@ switch($table) { "; } // show the table of entities - $existingdata=mysqli_query($db,"select * from logpartactions order by lpactionid asc"); + $existingdata = mysqli_query($db, "select * from logpartactions order by lpactionid asc"); echo " Existing Part Actions   Click on the Action ID to edit.

"; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { + while ($tablerow = mysqli_fetch_assoc($existingdata)) { if ($tablerow["status"]) { - $statdef="\"active\""; + $statdef = "\"active\""; } else { - $statdef="\"inactive\""; + $statdef = "\"inactive\""; } - printf(" + printf( + " ", - $tablerow["lpactionid"],$tablerow["lpactionid"], - $tablerow["lpactionname"], - $statdef); + $tablerow["lpactionid"], + $tablerow["lpactionid"], + $tablerow["lpactionname"], + $statdef + ); } echo "
Part Action IDPart Action NameActive
%s %s %s
"; break; - case "banners" : + case "banners": if ($isadmin) { // show the form if ($edit) { // set form options for editing - $sectiontitle="Modify Banner

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Modify Banner

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from banners where bannerid=$id")); - $name=$currentvalues["bannername"]; - $bnrcolor=$currentvalues["bannercolor"]; - $bnrtextcolor=$currentvalues["textcolor"]; - $bnrcoloropts=""; - foreach($basic_colors as $cname => $chex) { - if ($chex==$bnrcolor) { - $bnrcoloropts=$bnrcoloropts . ""; + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from banners where bannerid=$id")); + if (!empty($currentvalues)) { + $name = $currentvalues["bannername"]; + $bnrcolor = $currentvalues["bannercolor"]; + $bnrtextcolor = $currentvalues["textcolor"]; + } else { + $name = NULL; + $bnrcolor = NULL; + $bnrtextcolor = NULL; + } + $bnrcoloropts = ""; + foreach ($basic_colors as $cname => $chex) { + if ($chex == $bnrcolor) { + $bnrcoloropts = $bnrcoloropts . ""; } else { - $bnrcoloropts=$bnrcoloropts . ""; + $bnrcoloropts = $bnrcoloropts . ""; } } - $bnrtextcoloropts=""; - foreach($basic_colors as $cname => $chex) { - if ($chex==$bnrtextcolor) { - $bnrtextcoloropts=$bnrtextcoloropts . ""; + $bnrtextcoloropts = ""; + foreach ($basic_colors as $cname => $chex) { + if ($chex == $bnrtextcolor) { + $bnrtextcoloropts = $bnrtextcoloropts . ""; } else { - $bnrtextcoloropts=$bnrtextcoloropts . ""; + $bnrtextcoloropts = $bnrtextcoloropts . ""; } } } else { // set form options for add - $sectiontitle="Add New Banner

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Add New Banner

"; + $formtag = ""; + $buttontags = " "; // set default values - $bnrcolor="#000000"; - $bnrtextcolor="#FFFFFF"; - $bnrcoloropts=""; - foreach($basic_colors as $cname => $chex) { - if ($chex==$bnrcolor) { - $bnrcoloropts=$bnrcoloropts . ""; + $bnrcolor = "#000000"; + $bnrtextcolor = "#FFFFFF"; + $bnrcoloropts = ""; + foreach ($basic_colors as $cname => $chex) { + if ($chex == $bnrcolor) { + $bnrcoloropts = $bnrcoloropts . ""; } else { - $bnrcoloropts=$bnrcoloropts . ""; + $bnrcoloropts = $bnrcoloropts . ""; } } - $bnrtextcoloropts=""; - foreach($basic_colors as $cname => $chex) { - if ($chex==$bnrtextcolor) { - $bnrtextcoloropts=$bnrtextcoloropts . ""; + $bnrtextcoloropts = ""; + foreach ($basic_colors as $cname => $chex) { + if ($chex == $bnrtextcolor) { + $bnrtextcoloropts = $bnrtextcoloropts . ""; } else { - $bnrtextcoloropts=$bnrtextcoloropts . ""; + $bnrtextcoloropts = $bnrtextcoloropts . ""; } } } - + echo " $sectiontitle $formtag @@ -1356,47 +1432,52 @@ switch($table) { "; } // show the table of entities - $existingdata=mysqli_query($db,"select * from banners where bannerid!=1 order by bannerid asc"); + $existingdata = mysqli_query($db, "select * from banners where bannerid!=1 order by bannerid asc"); echo " Existing Banners   Click on the Banner ID to edit.

"; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { - printf(" + while ($tablerow = mysqli_fetch_assoc($existingdata)) { + printf( + " ", - $tablerow["bannerid"],$tablerow["bannerid"], - $tablerow["bannercolor"],$tablerow["textcolor"],$tablerow["bannername"]); + $tablerow["bannerid"], + $tablerow["bannerid"], + $tablerow["bannercolor"], + $tablerow["textcolor"], + $tablerow["bannername"] + ); } echo "
Banner IDBanner
%s %s
"; break; - case "configs" : - switch($type) { - case "display" : - $curlname=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"log_name\""))[0]; - $curlchunk=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"url_chunk_size\""))[0]; - $curbnr=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"banner\""))[0]; - $curftr=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"footer_message\""))[0]; - $curts=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"show_ts\""))[0]; - $curtdo=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"tech_alpha\""))[0]; - $cursdo=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"subj_alpha\""))[0]; - $curlogstyle=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"log_style\""))[0]; - $curuidtxt=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"uid_text\""))[0]; + case "configs": + switch ($type) { + case "display": + $curlname = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"log_name\""))[0]; + $curlchunk = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"url_chunk_size\""))[0]; + $curbnr = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"banner\""))[0]; + $curftr = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"footer_message\""))[0]; + $curts = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"show_ts\""))[0]; + $curtdo = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"tech_alpha\""))[0]; + $cursdo = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"subj_alpha\""))[0]; + $curlogstyle = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"log_style\""))[0]; + $curuidtxt = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"uid_text\""))[0]; echo "
Display Configuration Parameters


Log Name (will appear at the top of pages and in the titlebar):  

Banner (will appear at the top and bottom of pages):  

Log style (the look of the log notes display):    + "; + if ($isadmin && $operation != NULL) { + $templaterow = mysqli_query($db, "select * from notetemplates where tech!=\"0\" order by tech asc, templatename asc"); + } else { + $templaterow = mysqli_query($db, "select * from notetemplates where tech=\"$techid\" order by templatename asc"); + } + printf("", "0", "Select user template"); + while ($templateitem = mysqli_fetch_assoc($templaterow)) { + if ($isadmin && $operation != NULL) { + $techname = dblookup($db, "techs", "techid", "techname", $templateitem["tech"]); + printf("", $templateitem["templateid"], $templateitem["templatename"], $techname); + } else { + printf("", $templateitem["templateid"], $templateitem["templatename"]); + } + } + echo " +  or  + "; + // list global templates + echo " +    + "; + // show load button + echo " + + + + + Manage templates + + +
+
+ "; +} + +function fix_date($datestring) +{ + // accepts a string as an argument + // returns a valid date string in the format YYYY-MM-DD + // if input string is not a valid date, return the current date + global $db, $today; + + if (!$datestring) $datestring = $today; + $datepatt = '/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/'; + if (!preg_match($datepatt, $datestring)) $datestring = $today; + $datestring = mysqli_real_escape_string($db, $datestring); + return $datestring; +} + +function fix_time($timestring) +{ + // accepts a string as an argument + // returns a valid time string in the format HH:MM:SS + // if input string is not a valid time, return the current time + global $db, $now; + + if (!$timestring) $timestring = $now; + $timepatt = '/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/'; + if (!preg_match($timepatt, $timestring)) $timestring = $now; + $timestring = mysqli_real_escape_string($db, $timestring); + return $timestring; +} diff --git a/distfiles/gpl.php b/distfiles/gpl.php index 30db540..aa66594 100644 --- a/distfiles/gpl.php +++ b/distfiles/gpl.php @@ -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 */ @@ -10,25 +10,25 @@ include("functions.php"); -$print=$_REQUEST['print']; +$print = $_REQUEST['print'] ?? NULL; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } -framework("begin","OpenLog License","OpenLog License",$print); +framework("begin", "OpenLog License", "OpenLog License", $print); pagetable("begin"); -if(!$print){ - pageblock("left","begin"); - sidemenu(); - pageblock("left","end"); +if (!$print) { + pageblock("left", "begin"); + sidemenu(); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); echo "
             GNU GENERAL PUBLIC LICENSE
@@ -375,10 +375,8 @@ Public License instead of this License.
 
 
"; - -pageblock("right","end"); + +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/logentry.php b/distfiles/logentry.php index 256d1a8..6f4f2bf 100644 --- a/distfiles/logentry.php +++ b/distfiles/logentry.php @@ -2,217 +2,242 @@ /* logentry.php OpenLog Online Logbook - Copyright (C) 2025 Rod Wright + Copyright (C) 2026 Rod Wright SPDX-License-Identifier: GPL-2.0 */ include("functions.php"); -if (!$_SESSION['login'] && !$_REQUEST['partview']) { - header ("Location: login.php"); +if (!array_key_exists("login", $_SESSION) && !array_key_exists("partview", $_REQUEST)) { + header("Location: login.php"); } -$techid=$_SESSION['login'] ?? NULL; -$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; -$submit=$_REQUEST['submit'] ?? NULL; -$add=$_REQUEST['add'] ?? NULL; -$edit=$_REQUEST['edit'] ?? NULL; -$delete=$_REQUEST['delete'] ?? NULL; -$templateid=$_REQUEST['templateid'] ?? 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; -$flags=$_POST['flags'] ?? []; -$uids=$_POST['uids'] ?? []; -$partnums=$_POST['partnums'] ?? []; -$sernums=$_POST['sernums'] ?? []; -$actions=$_POST['actions'] ?? []; -$mfreqs=$_POST['mfreqs'] ?? []; -$schedmaintcomplete=$_REQUEST['schedmaintcomplete'] ?? NULL; -$partview=$_REQUEST['partview'] ?? NULL; +$techid = $_SESSION['login'] ?? NULL; +$isadmin = dblookup($db, "techs", "techid", "admin", $techid); +$efftechid = $_REQUEST['efftechid'] ?? NULL; +$noteid = $_REQUEST['noteid'] ?? NULL; +$print = $_REQUEST['print'] ?? NULL; +$date = $_REQUEST['date'] ?? NULL; +$time = $_REQUEST['time'] ?? NULL; +$note = $_REQUEST['note'] ?? NULL; +$shift = $_REQUEST['shift'] ?? NULL; +$subject = $_REQUEST['subject'] ?? 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; +$usertemplateid = $_REQUEST['usertemplateid'] ?? NULL; +$globaltemplateid = $_REQUEST['globaltemplateid'] ?? NULL; +$loadtemplate = $_REQUEST['loadtemplate'] ?? NULL; +$templatename = $_REQUEST['templatename'] ?? NULL; +$removepart = $_REQUEST['removepart'] ?? NULL; +$syncflags = $_REQUEST['syncflags'] ?? NULL; +$flags = $_POST['flags'] ?? []; +$uids = $_POST['uids'] ?? []; +$partnums = $_POST['partnums'] ?? []; +$sernums = $_POST['sernums'] ?? []; +$actions = $_POST['actions'] ?? []; +$mfreqs = $_POST['mfreqs'] ?? []; +$schedmaintcomplete = $_REQUEST['schedmaintcomplete'] ?? NULL; +$partview = $_REQUEST['partview'] ?? NULL; -$doparts=PARTS_FUNCTIONS; -$logname=LOG_NAME; -$techalpha=TECH_ALPHA; -$subjalpha=SUBJ_ALPHA; -$uidtext=UID_TEXT; +$doparts = PARTS_FUNCTIONS; +$logname = LOG_NAME; +$techalpha = TECH_ALPHA; +$subjalpha = SUBJ_ALPHA; +$uidtext = UID_TEXT; -$defaultshift=dblookup($db,"techs","techid","shift",$techid); +$defaultshift = dblookup($db, "techs", "techid", "shift", $techid); -if ($print=="Printer Friendly") { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; +if ($print == "Printer Friendly") { + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } -if ($partview) $edit=1; -if (!$add && !$edit && !$delete && !$submit) $add=1; +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; + framework("begin", "$logname", "Note Entry", $print); + $authorized = TRUE; } if ($edit || $delete) { - framework("begin","$logname","Note Edit",$print); - $owner=dblookup($db,"lognotes","lognoteid","tech",$noteid); - if (($techid==$owner) || $isadmin) $authorized=1; + framework("begin", "$logname", "Note Edit", $print); + $owner = dblookup($db, "lognotes", "lognoteid", "tech", $noteid); + if ($techid == $owner) $authorized = TRUE; } -//var_dump($_REQUEST); +// var_dump($_REQUEST); // ******** begin database manipulation ******** -if ($add) { - if ($submit) { +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 if ($note) { // sanitize and fix blank date and time - $date=mysqli_real_escape_string($db,$date); - $time=mysqli_real_escape_string($db,$time); - if (!$date) $date=$today; - if (!$time) $time=$now; + $date = fix_date($date); + $time = fix_time($time); + // determine whether supplied date is future or past - $datediff=mysqli_fetch_row(mysqli_query($db,"select datediff(\"$date\",CURRENT_DATE)")); + $datediff = mysqli_fetch_row(mysqli_query($db, "select datediff(\"$date\",CURRENT_DATE)")); // if future, set time to 00:00:01, if past, set to 23:59:59 - if ($datediff[0]<0) { - $time="23:59:59"; + if ($datediff[0] < 0) { + $time = "23:59:59"; } - if ($datediff[0]>0) { - $time="00:00:01"; + if ($datediff[0] > 0) { + $time = "00:00:01"; } - + // remove html tags from note text and sanitize - $note=strip_tags($note,""); - $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 ($doparts==1) { + $note = strip_tags($note, ""); + $note = mysqli_real_escape_string($db, $note); + + 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 - $maxplidx=max( - max(array_keys($uids)), - max(array_keys($partnums)), - max(array_keys($sernums)) + $maxplidx = max( + max(array_keys($uids)), + max(array_keys($partnums)), + max(array_keys($sernums)) ); - for ($plidx=0;$plidx<=$maxplidx;$plidx++) { + for ($plidx = 0; $plidx <= $maxplidx; $plidx++) { // for each part line, see what info is available // if uid or pn/sn supplied, pull other info from parts if ($uids[$plidx] != "") { // see if this uid is in parts table. - $uidqry=mysqli_query($db,"select * from parts where uid=\"$uids[$plidx]\""); + $uidqry = mysqli_query($db, "select * from parts where uid=\"$uids[$plidx]\""); if (mysqli_num_rows($uidqry)) { // if so, populate pn/sn - $uiddata=mysqli_fetch_assoc($uidqry); - $partnums[$plidx]=$uiddata['partnum']; - $sernums[$plidx]=$uiddata['sernum']; + $uiddata = mysqli_fetch_assoc($uidqry); + $partnums[$plidx] = $uiddata['partnum']; + $sernums[$plidx] = $uiddata['sernum']; } } if ($partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if this pn/sn is in parts table. - $pnsnqry=mysqli_query($db,"select * from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""); + $pnsnqry = mysqli_query($db, "select * from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""); if (mysqli_num_rows($pnsnqry)) { // if so, populate uid - $pnsndata=mysqli_fetch_assoc($pnsnqry); - $uids[$plidx]=$pnsndata['uid']; + $pnsndata = mysqli_fetch_assoc($pnsnqry); + $uids[$plidx] = $pnsndata['uid']; } } } } 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\")"); - $newnoteid=mysqli_insert_id($db); - - // add this noteid to the appropriate flag_tables - $chainmembers=generate_chain($newnoteid); - foreach ($flags as $flagtblnum) { - $flagtblname="flag_".$flagtblnum; + 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 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); + + // 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\")"); + } } } } - - if ($doparts==1) { + + if ($doparts == 1) { // now run through the part lines - for ($plidx=0;$plidx<=$maxplidx;$plidx++) { + for ($plidx = 0; $plidx <= $maxplidx; $plidx++) { // update the parts table - + // if this line includes a uid and a pn/sn if ($uids[$plidx] != "" && $partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if it's in the parts table - if (! mysqli_num_rows(mysqli_query($db,"select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { + if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { // if not, add it to parts - mysqli_query($db,"insert into parts(uid,partnum,sernum) values(\"$uids[$plidx]\",\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); - $lpid=mysqli_insert_id($db); + mysqli_query($db, "insert into parts(uid,partnum,sernum) values(\"$uids[$plidx]\",\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); + $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table - $lpid=mysqli_fetch_row(mysqli_query($db,"select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; + $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; } // add it to logparts table - mysqli_query($db,"insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); + mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required - if ($mfreqs[$plidx]=="on") { - mysqli_query($db,"insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); + if ($mfreqs[$plidx] == "on") { + mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); } - - // if this line includes a uid only + + // if this line includes a uid only } else if ($uids[$plidx] != "" && $partnums[$plidx] == "" && $sernums[$plidx] == "") { // see if this uid is in parts table - if (! mysqli_num_rows(mysqli_query($db,"select partid from parts where uid=\"$uids[$plidx]\" and partnum is NULL and sernum is NULL"))) { + if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum is NULL and sernum is NULL"))) { // if not, add it to parts - mysqli_query($db,"insert into parts(uid) values(\"$uids[$plidx]\")"); - $lpid=mysqli_insert_id($db); + mysqli_query($db, "insert into parts(uid) values(\"$uids[$plidx]\")"); + $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table - $lpid=mysqli_fetch_row(mysqli_query($db,"select partid from parts where uid=\"$uids[$plidx]\""))[0]; + $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\""))[0]; } // add it to logparts table - mysqli_query($db,"insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); + mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required - if ($mfreqs[$plidx]=="on") { - mysqli_query($db,"insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); + if ($mfreqs[$plidx] == "on") { + mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); } - - // if this line includes a pn/sn only + + // if this line includes a pn/sn only } else if ($uids[$plidx] == "" && $partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if this pn/sn is in the parts table - if (! mysqli_num_rows(mysqli_query($db,"select partid from parts where uid is NULL and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { + if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid is NULL and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { // if not, add it to parts - mysqli_query($db,"insert into parts(partnum,sernum) values(\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); - $lpid=mysqli_insert_id($db); + mysqli_query($db, "insert into parts(partnum,sernum) values(\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); + $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table - $lpid=mysqli_fetch_row(mysqli_query($db,"select partid from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; + $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; } // add it to logparts table - mysqli_query($db,"insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); + mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required - if ($mfreqs[$plidx]=="on") { - mysqli_query($db,"insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); + if ($mfreqs[$plidx] == "on") { + mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); } - } else { // no part info was entered } @@ -220,138 +245,64 @@ if ($add) { } } } - } elseif ($loadtemplate) { - if ($templateid) { - $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,""); - $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\""); - } - } - } - } 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; - } - } + } 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"]; + $refstringqry = mysqli_query($db, "select target from reflinks where templateid=\"$templateid\""); + while ($thistgt = mysqli_fetch_row($refstringqry)) { + $refstring = $refstring . " " . $thistgt[0]; } } - } elseif ($copytemplate) { - if ($note) { - // remove cruft from note text - $note=strip_tags($note,""); - $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\""); + if ($removepart && $authorized) mysqli_query($db, "delete from logparts where lognoteid=\"$noteid\" and logpartid=\"$removepart\""); if ($submit) { if ($note) { + // sanitize and fix blank date and time + $date = fix_date($date); + $time = fix_time($time); + // remove cruft from note text - $note=strip_tags($note,""); - $note=mysqli_real_escape_string($db,$note); - + $note = strip_tags($note, ""); + $note = mysqli_real_escape_string($db, $note); + // remove cruft from references - $refs=preg_replace("#[a-zA-Z]{1,}#","",$refs); - - if ($doparts==1) { + if (strlen($refstring)) { + $refstring = trim($refstring); + $refstring = preg_replace("#[a-zA-Z]{1,}#", "", $refstring); + } + + if ($doparts == 1) { // inspect part data - $maxplidx=max( - max(array_keys($uids)), - max(array_keys($partnums)), - max(array_keys($sernums)) + $maxplidx = max( + max(array_keys($uids)), + max(array_keys($partnums)), + max(array_keys($sernums)) ); - for ($plidx=0;$plidx<=$maxplidx;$plidx++) { + for ($plidx = 0; $plidx <= $maxplidx; $plidx++) { // for each part line, see what info is available // if uid or pn/sn supplied, pull other info from parts if ($uids[$plidx] != "") { // see if this uid is in parts table. - $uidqry=mysqli_query($db,"select * from parts where uid=\"$uids[$plidx]\""); + $uidqry = mysqli_query($db, "select * from parts where uid=\"$uids[$plidx]\""); if (mysqli_num_rows($uidqry)) { // if so, populate pn/sn - $uiddata=mysqli_fetch_assoc($uidqry); - $partnums[$plidx]=$uiddata['partnum']; - $sernums[$plidx]=$uiddata['sernum']; + $uiddata = mysqli_fetch_assoc($uidqry); + $partnums[$plidx] = $uiddata['partnum']; + $sernums[$plidx] = $uiddata['sernum']; } } if ($partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if this pn/sn is in parts table. - $pnsnqry=mysqli_query($db,"select * from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""); + $pnsnqry = mysqli_query($db, "select * from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""); if (mysqli_num_rows($pnsnqry)) { // if so, populate uid - $pnsndata=mysqli_fetch_assoc($pnsnqry); - $uids[$plidx]=$pnsndata['uid']; + $pnsndata = mysqli_fetch_assoc($pnsnqry); + $uids[$plidx] = $pnsndata['uid']; } } } @@ -359,215 +310,204 @@ 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\""); - - // update the flag_tables - $flagids=mysqli_query($db,"select flagid from flags"); - $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 - 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\")"); - } - } - } - } - } 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\""); + mysqli_query($db, "update lognotes set date=\"$date\", time=\"$time\", shift=\"$shift\", tech=\"$efftechid\", subject=\"$subject\", lognote=\"$note\" where lognoteid=\"$noteid\""); + + // 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); + + // update the flagmap table + mysqli_query($db, "delete from flagmap where lognoteid=\"$noteid\""); + if ($syncflags) { + foreach ($chainmembers as $refdnote) { + if ($refdnote != $noteid) { + mysqli_query($db, "delete from flagmap where lognoteid=\"$refdnote\""); } } } - - if ($doparts==1) { + 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\")"); + } + } + } + } + + if ($doparts == 1) { // run through the new part lines - for ($plidx=0;$plidx<=$maxplidx;$plidx++) { + for ($plidx = 0; $plidx <= $maxplidx; $plidx++) { // update the parts table - + // if this line includes a uid and a pn/sn if ($uids[$plidx] != "" && $partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if it's in the parts table - if (! mysqli_num_rows(mysqli_query($db,"select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { + if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { // if not, add it to parts - mysqli_query($db,"insert into parts(uid,partnum,sernum) values(\"$uids[$plidx]\",\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); - $lpid=mysqli_insert_id($db); + mysqli_query($db, "insert into parts(uid,partnum,sernum) values(\"$uids[$plidx]\",\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); + $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table - $lpid=mysqli_fetch_row(mysqli_query($db,"select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; + $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; } // add it to logparts table - mysqli_query($db,"insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); + mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required - if ($mfreqs[$plidx]=="on") { - mysqli_query($db,"insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); + if ($mfreqs[$plidx] == "on") { + mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); } - - // if this line includes a uid only + + // if this line includes a uid only } else if ($uids[$plidx] != "" && $partnums[$plidx] == "" && $sernums[$plidx] == "") { // see if this uid is in parts table - if (! mysqli_num_rows(mysqli_query($db,"select partid from parts where uid=\"$uids[$plidx]\" and partnum is NULL and sernum is NULL"))) { + if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum is NULL and sernum is NULL"))) { // if not, add it to parts - mysqli_query($db,"insert into parts(uid) values(\"$uids[$plidx]\")"); - $lpid=mysqli_insert_id($db); + mysqli_query($db, "insert into parts(uid) values(\"$uids[$plidx]\")"); + $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table - $lpid=mysqli_fetch_row(mysqli_query($db,"select partid from parts where uid=\"$uids[$plidx]\""))[0]; + $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\""))[0]; } // add it to logparts table - mysqli_query($db,"insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); + mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required - if ($mfreqs[$plidx]=="on") { - mysqli_query($db,"insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); + if ($mfreqs[$plidx] == "on") { + mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); } - - // if this line includes a pn/sn only + + // if this line includes a pn/sn only } else if ($uids[$plidx] == "" && $partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if this pn/sn is in the parts table - if (! mysqli_num_rows(mysqli_query($db,"select partid from parts where uid is NULL and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { + if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid is NULL and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { // if not, add it to parts - mysqli_query($db,"insert into parts(partnum,sernum) values(\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); - $lpid=mysqli_insert_id($db); + mysqli_query($db, "insert into parts(partnum,sernum) values(\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); + $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table - $lpid=mysqli_fetch_row(mysqli_query($db,"select partid from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; + $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; } // add it to logparts table - mysqli_query($db,"insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); + mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required - if ($mfreqs[$plidx]=="on") { - mysqli_query($db,"insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); + if ($mfreqs[$plidx] == "on") { + mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); } - } else { - // no part info was entered + // no part info was entered + ; } } } } } } - // refresh the note in question from the database - $getnote=mysqli_query($db,"select * from lognotes where lognoteid=\"$noteid\""); - $notetoedit=mysqli_fetch_assoc($getnote); + 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) { - // 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\""); + // 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 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\""); + mysqli_query($db, "delete from logparts where lognoteid=\"$noteid\""); } // ******** end database manipulation ******** pagetable("begin"); if (!$print) { - pageblock("left","begin"); + pageblock("left", "begin"); sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); banner($print); // display the form if ($add) { - $notedate=$today; - $notetime=$now; + $notedate = $today; + $notetime = $now; } if ($edit || $delete) { - $notedate=$notetoedit["date"]; - $notetime=$notetoedit["time"]; - $defaultshift=$notetoedit["shift"]; - $defaultsubject=$notetoedit["subject"]; - $note=$notetoedit["lognote"]; - $refto=$notetoedit["refs"]; - $techid=$notetoedit["tech"]; + $notedate = $notetoedit["date"] ?? $today; + $notetime = $notetoedit["time"] ?? $now; + $defaultshift = $notetoedit["shift"]; + $defaultsubject = $notetoedit["subject"]; + + $note = $notetoedit["lognote"]; + // 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; +$techname = dblookup($db, "techs", "techid", "techname", $techid); if ($submit) { if ($note) { if ($add) { - format_message(0,"Note added. You may enter another note or return to main page."); + format_message(0, "Note added. You may enter another note or return to main page."); } if ($edit) { - format_message(0,"Note changed. Return to main page."); + format_message(0, "Note changed. Return to main page."); } } else { - format_message(1,"You didn't enter any note text. Please try again."); + format_message(1, "You didn't enter any note text. Please try again."); } } if ($delete) { - format_message(0,"Note deleted. Return to main page."); + format_message(0, "Note deleted. Return to main page."); } -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 " -
-"; -if ($_SESSION['login']) { - // generate template line - echo " - - "; - - if ($loadtemplate) { - echo " - - - "; - } - - echo " -
-    - -   - - - - -
-
- "; + +if (array_key_exists('login', $_SESSION)) { + // show the template selection line + templateselect($techid, NULL); } + // start note entry section echo " +
Date:   @@ -581,14 +521,15 @@ if ($isadmin) { Tech:   Shift:   Subject:  
-Note: 
+Note: 

- Insert Link
+  +  +Insert Link
"; -// get an array of flagids set for this noteid -$allflags=mysqli_query($db,"select flagid from flags"); + +// 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]; +$theseflags = []; +while ($thisflag = mysqli_fetch_row($allflags)) { if ($templateid) { - if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"notetemplates\" and id=\"$templateid\""))) { - $theseflags[]=$thisflag[0]; + 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\""))) { - $theseflags[]=$thisflag[0]; + 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"); + $flagslist = mysqli_query($db, "select * from flags where status=1"); } else { - $flagslist=mysqli_query($db,"select * from flags"); + $flagslist = mysqli_query($db, "select * from flags"); } -$flagsperline=8; -$flagcount=1; -while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) { - - if (in_array($flagcheckbox["flagid"],$theseflags)) { - printf("%s", - $flagcheckbox["flagid"],$flagcheckbox["flagcolor"],$flagcheckbox["flagname"],$flagcheckbox["flagsym"]); +$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)) { + printf( + "%s", + $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("%s", - $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( + "%s", + $flagcheckbox["flagid"], + $flagcheckbox["flagcolor"], + $flagcheckbox["flagname"], + $flagcheckbox["flagsym"] + ); } } - if ($flagcount<$flagsperline) { + if ($flagcount < $flagsperline) { echo "   "; $flagcount++; } else { echo "
"; - $flagcount=1; + $flagcount = 1; } } echo "
Set flags on reference chain +"; + +if ($add && $refto) $refstring = $refto; +echo "

References:   -         +                               "; if ($add) { @@ -703,13 +665,13 @@ if ($add) { "; } if ($doparts) { - $defaultaction=0; + $defaultaction = 0; echo "

"; - for ($partline=0;$partline <=5;$partline++) { + for ($partline = 0; $partline <= 5; $partline++) { echo " @@ -718,13 +680,13 @@ if ($add) { "; // populate the existing part lines - $linekey=0; - $elineqry=mysqli_query($db,"select logpartid, partid, action from logparts where lognoteid=\"$noteid\""); - while ($eline=mysqli_fetch_assoc($elineqry)) { - $iconpartid=$eline['logpartid']; - $lpidvar=$eline['partid']; - $eparts=mysqli_fetch_assoc(mysqli_query($db,"select uid,partnum,sernum from parts where partid=\"$lpidvar\"")); - $epuid=$eparts['uid']; - $eppn=$eparts['partnum']; - $epsn=$eparts['sernum']; - $defaultaction=$eline['action']; - + $linekey = 0; + $elineqry = mysqli_query($db, "select logpartid, partid, action from logparts where lognoteid=\"$noteid\""); + while ($eline = mysqli_fetch_assoc($elineqry)) { + $iconpartid = $eline['logpartid']; + $lpidvar = $eline['partid']; + $eparts = mysqli_fetch_assoc(mysqli_query($db, "select uid,partnum,sernum from parts where partid=\"$lpidvar\"")); + $epuid = $eparts['uid']; + $eppn = $eparts['partnum']; + $epsn = $eparts['sernum']; + $defaultaction = $eline['action']; + echo " "; // find maint form for this line and show link - $mflinknum=mysqli_fetch_assoc(mysqli_query($db,"select maintformid from maintforms where lognoteid=\"$noteid\" and mfpart=\"$lpidvar\""))["maintformid"]; + $mflinknum = mysqli_fetch_assoc(mysqli_query($db, "select maintformid from maintforms where lognoteid=\"$noteid\" and mfpart=\"$lpidvar\""))["maintformid"]; echo " "; } // add six empty part lines - $defaultaction=0; - for ($partline=$linekey;$partline <=$linekey+5;$partline++) { + $defaultaction = 0; + for ($partline = $linekey; $partline <= $linekey + 5; $partline++) { echo " @@ -804,13 +766,13 @@ if ($edit) {
$uidtextPart NumberSerial NumberActionMaint Form
$uidtextPart NumberSerial NumberActionMaint Form
@@ -777,9 +739,9 @@ if ($edit) { $epsn "; - $actrow=mysqli_query($db,"select * from logpartactions"); - while ($actitem=mysqli_fetch_assoc($actrow)) { - if ($actitem["lpactionid"]==$defaultaction) { + $actrow = mysqli_query($db, "select * from logpartactions"); + while ($actitem = mysqli_fetch_assoc($actrow)) { + if ($actitem["lpactionid"] == $defaultaction) { echo "$actitem[lpactionname]"; } } @@ -787,15 +749,15 @@ if ($edit) { $mflinknum
"; - 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["status"]==1) { - printf("",$techitem["techid"],$techitem["techname"]); + 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["status"] == 1) { + printf("", $techitem["techid"], $techitem["techname"]); } } echo "

@@ -87,16 +87,14 @@ if ($login) {

"; } else { - $loginid=$_SESSION['login']; - $loggedinas=mysqli_fetch_row(mysqli_query($db,"select techname from techs where techid=\"$loginid\""))[0]; + $loginid = $_SESSION['login']; + $loggedinas = mysqli_fetch_row(mysqli_query($db, "select techname from techs where techid=\"$loginid\""))[0]; echo " You are already logged in as $loggedinas. Please select a menu option at the left to continue.

"; } } -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/lognotes.php b/distfiles/lognotes.php index 1854e05..d1d80d6 100644 --- a/distfiles/lognotes.php +++ b/distfiles/lognotes.php @@ -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 */ @@ -12,106 +12,107 @@ include("functions.php"); //$tgt_year=$_REQUEST['y']; //$tgt_month=$_REQUEST['m']; //$tgt_day=$_REQUEST['d']; -$tgt_date=$_REQUEST['tgt_date'] ?? ""; -$print=$_REQUEST['print'] ?? ""; -if (isset($_SESSION['login'])) $techid=$_SESSION['login']; +$tgt_date = $_REQUEST['tgt_date'] ?? ""; +$print = $_REQUEST['print'] ?? ""; +if (isset($_SESSION['login'])) $techid = $_SESSION['login']; -$logname=LOG_NAME; -$tablestyle=LOG_STYLE; +$logname = LOG_NAME; +$tablestyle = LOG_STYLE; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } // use default date values if not supplied -if ($tgt_date=="") $tgt_date=$today; +if ($tgt_date == "") $tgt_date = $today; // define shifttable_classic function -function shifttable_classic($shift, $tgt_date, $db) { +function shifttable_classic($shift, $tgt_date, $db) +{ // convert the shift number to a name for display - $doparts=PARTS_FUNCTIONS; - $showtime=SHOW_TS; - $shname=dblookup($db,"shifts","shiftid","shiftname",$shift); - $dshdrdata=mysqli_query($db,"select date,shift from lognotes where date=\"$tgt_date\" and shift=\"$shift\""); - $dshdr=mysqli_fetch_row($dshdrdata); + $doparts = PARTS_FUNCTIONS; + $showtime = SHOW_TS; + $shname = dblookup($db, "shifts", "shiftid", "shiftname", $shift); + $dshdrdata = mysqli_query($db, "select date,shift from lognotes where date=\"$tgt_date\" and shift=\"$shift\""); + $dshdr = mysqli_fetch_row($dshdrdata); if ($dshdr) { // print the shift header - printf("%s\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"); + printf("%s\n", $shname); + $note = mysqli_query($db, "select lognoteid,tech,subject,lognote,time from lognotes where date=\"$tgt_date\" and shift=\"$shift\" order by time asc"); echo "
\n"; echo "\n"; while ($tablerow = mysqli_fetch_assoc($note)) { - $reftonote=$tablerow["lognoteid"]; - $refs="    \"Add"; - if (islink($tablerow["lognoteid"])) { - $refs=$refs."      \"View"; + $thisnote = $tablerow["lognoteid"]; + $refs = "    \"Add"; + if (islink($thisnote)) { + $refs = $refs . "      \"View"; } // convert tech number to name - $tname=dblookup($db,"techs","techid","techname",$tablerow["tech"]); + $tname = dblookup($db, "techs", "techid", "techname", $tablerow["tech"]); //convert subject number to name - $subjname=dblookup($db,"subjects","subjectid","subjectname",$tablerow["subject"]); + $subjname = dblookup($db, "subjects", "subjectid", "subjectname", $tablerow["subject"]); // create links of urls in note - $fmtnote=convertweblinks($tablerow["lognote"]); + $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"]; - $flagstring=$flagstring."$flagsym  "; - } + $flagstring = ""; + $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 . "$flagsym  "; } if ($flagstring) { - $fmtnote=$fmtnote."
".$flagstring."     "; - } else { - $fmtnote=$fmtnote."
"; + $fmtnote = $fmtnote . "
" . $flagstring . "     "; + } else { + $fmtnote = $fmtnote . "
"; } + 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."PARTS"; + if (mysqli_num_rows(mysqli_query($db, "select logpartid from logparts where lognoteid=\"$thisnote\""))) { + $fmtnote = $fmtnote . "PARTS"; } } // now print the line in the table if ($showtime) { printf( - " + "\n", - $tablerow["lognoteid"],$tablerow["lognoteid"],$tablerow["time"], - $tname, - $subjname, - $fmtnote, - $refs + $tablerow["lognoteid"], + $tablerow["lognoteid"], + $tablerow["time"], + $tname, + $subjname, + $fmtnote, + $refs ); } else { printf( - " + "\n", - $tablerow["lognoteid"],$tablerow["lognoteid"], - $tname, - $subjname, - $fmtnote, - $refs + $tablerow["lognoteid"], + $tablerow["lognoteid"], + $tname, + $subjname, + $fmtnote, + $refs ); } } @@ -124,86 +125,85 @@ function shifttable_classic($shift, $tgt_date, $db) { } // define the shifttable_clean function -function shifttable_clean($shift, $tgt_date, $db) { +function shifttable_clean($shift, $tgt_date, $db) +{ // convert the shift number to a name for display - $doparts=PARTS_FUNCTIONS; - $showtime=SHOW_TS; - $shname=dblookup($db,"shifts","shiftid","shiftname",$shift); - $dshdrdata=mysqli_query($db,"select date,shift from lognotes where date=\"$tgt_date\" and shift=\"$shift\""); - $dshdr=mysqli_fetch_row($dshdrdata); + $doparts = PARTS_FUNCTIONS; + $showtime = SHOW_TS; + $shname = dblookup($db, "shifts", "shiftid", "shiftname", $shift); + $dshdrdata = mysqli_query($db, "select date,shift from lognotes where date=\"$tgt_date\" and shift=\"$shift\""); + $dshdr = mysqli_fetch_row($dshdrdata); if ($dshdr) { // print the shift header - printf("%s\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"); + printf("%s\n", $shname); + $note = mysqli_query($db, "select lognoteid,tech,subject,lognote,time from lognotes where date=\"$tgt_date\" and shift=\"$shift\" order by time asc"); echo "

"; echo "
Note IDTechSubjectNoteReferences
%s  %s %s %s %s %s
%s %s %s %s %s
", - $def_eventid,$def_deferred_date, - $devicedata_devicedesc,$devicedata_devicename, - $taskdata_taskdesc,$taskdata_taskname, - $lastdatestrg + $def_eventid, + $def_deferred_date, + $devicedata_devicedesc, + $devicedata_devicename, + $taskdata_taskdesc, + $taskdata_taskname, + $lastdatestrg ); } echo " @@ -886,9 +909,7 @@ if ($action) { banner($print); -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/search.php b/distfiles/search.php index 04d774b..3e89453 100644 --- a/distfiles/search.php +++ b/distfiles/search.php @@ -2,382 +2,421 @@ /* search.php OpenLog Online Logbook - Copyright (C) 2025 Rod Wright + Copyright (C) 2026 Rod Wright SPDX-License-Identifier: GPL-2.0 */ include("functions.php"); -$noprint=1; +$noprint = TRUE; if (isset($_SESSION['login'])) { - $loggedin=1; + $loggedin = TRUE; } else { - unset($loggedin); + $loggedin = FALSE; } -$print=$_REQUEST['print'] ?? NULL; -$search=$_REQUEST['search'] ?? NULL; -$srchnoteid=$_REQUEST['srchnoteid'] ?? NULL; -$srchmfid=$_REQUEST['srchmfid'] ?? NULL; -$srchbdate=$_REQUEST['srchbdate'] ?? NULL; -$srchedate=$_REQUEST['srchedate'] ?? NULL; -$srchshift=$_REQUEST['srchshift'] ?? NULL; -$srchtech=$_REQUEST['srchtech'] ?? NULL; -$srchsubj=$_REQUEST['srchsubj'] ?? NULL; -$srchtext=$_REQUEST['srchtext'] ?? NULL; -$srchuid=$_REQUEST['srchuid'] ?? NULL; -$srchpn=$_REQUEST['srchpn'] ?? NULL; -$srchsn=$_REQUEST['srchsn'] ?? NULL; -$srchpname=$_REQUEST['srchpname'] ?? NULL; -$srchploc=$_REQUEST['srchploc'] ?? NULL; -$srchnha=$_REQUEST['srchnha'] ?? NULL; -$srchrepord=$_REQUEST['srchrepord'] ?? NULL; -$srchflags=$_REQUEST['srchflags'] ?? NULL; -$target=$_REQUEST['target'] ?? NULL; +$print = $_REQUEST['print'] ?? NULL; +$search = $_REQUEST['search'] ?? NULL; +$srchnoteid = $_REQUEST['srchnoteid'] ?? NULL; +$srchmfid = $_REQUEST['srchmfid'] ?? NULL; +$srchbdate = $_REQUEST['srchbdate'] ?? NULL; +$srchedate = $_REQUEST['srchedate'] ?? NULL; +$srchshift = $_REQUEST['srchshift'] ?? NULL; +$srchtech = $_REQUEST['srchtech'] ?? NULL; +$srchsubj = $_REQUEST['srchsubj'] ?? NULL; +$srchtext = $_REQUEST['srchtext'] ?? NULL; +$srchuid = $_REQUEST['srchuid'] ?? NULL; +$srchpn = $_REQUEST['srchpn'] ?? NULL; +$srchsn = $_REQUEST['srchsn'] ?? NULL; +$srchpname = $_REQUEST['srchpname'] ?? NULL; +$srchploc = $_REQUEST['srchploc'] ?? NULL; +$srchnha = $_REQUEST['srchnha'] ?? NULL; +$srchrepord = $_REQUEST['srchrepord'] ?? NULL; +$srchflags = $_POST['srchflags'] ?? []; +$target = $_REQUEST['target'] ?? ["log", "maintform", "part"]; -$doparts=PARTS_FUNCTIONS; -$logname=LOG_NAME; -$techalpha=TECH_ALPHA; -$subjalpha=SUBJ_ALPHA; -$uidtext=UID_TEXT; +$doparts = PARTS_FUNCTIONS; +$logname = LOG_NAME; +$techalpha = TECH_ALPHA; +$subjalpha = SUBJ_ALPHA; +$uidtext = UID_TEXT; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } -framework("begin","$logname Search","Search",$print); +framework("begin", "$logname Search", "Search", $print); -//var_dump($_REQUEST); +// echo "REQUEST variables:
"; +// var_dump($_REQUEST); +// echo "
"; // ******** 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); -$logmindate=$logdateresults[0]; +$logdateqry = mysqli_query($db, "select min(date), max(date) from lognotes"); +$logdateresults = mysqli_fetch_row($logdateqry); +$logmindate = $logdateresults[0]; if ($logmindate == "") $logmindate = $today; -$logmaxdate=$logdateresults[1]; +$logmaxdate = $logdateresults[1]; 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]; +$mfdateqry = mysqli_query($db, "select min(mfdate), max(mfdate) from maintforms"); +$mfdateresults = mysqli_fetch_row($mfdateqry); +$mfmindate = $mfdateresults[0]; if ($mfmindate == "") $mfmindate = $today; -$mfmaxdate=$mfdateresults[1]; +$mfmaxdate = $mfdateresults[1]; if ($mfmaxdate == "") $mfmaxdate = $today; // determine entire date range -$mindate=min($logmindate, $mfmindate); -$maxdate=max($logmaxdate, $mfmaxdate); - - +$mindate = min($logmindate, $mfmindate); +$maxdate = max($logmaxdate, $mfmaxdate); if ($search) { // strip whitespace from beginning and end of text fields - $srchtext=trim($srchtext); - $srchpname=trim($srchpname); - $srchploc=trim($srchploc); - $srchnha=trim($srchnha); - if ($target[0]=="") $target=[]; - if (in_array("log",$target)) { + $srchtext = trim($srchtext); + $srchpname = trim($srchpname); + $srchploc = trim($srchploc); + $srchnha = trim($srchnha); + if (in_array("log", $target)) { // define the query constraints // log note id if ($srchnoteid != "any" && $srchnoteid != "") { - $logfromtables[]="lognotes"; - $logconstraints[]="lognotes.lognoteid=\"$srchnoteid\""; + $logfromtables[] = "lognotes"; + $logconstraints[] = "lognotes.lognoteid=\"$srchnoteid\""; } // maint form id if ($srchmfid != "any" && $srchmfid != "") { - $logfromtables[]="lognotes"; - $logfromtables[]="maintforms"; - $logconstraints[]="lognotes.lognoteid=maintforms.lognoteid and maintforms.maintformid=\"$srchmfid\""; + $logfromtables[] = "lognotes"; + $logfromtables[] = "maintforms"; + $logconstraints[] = "lognotes.lognoteid=maintforms.lognoteid and maintforms.maintformid=\"$srchmfid\""; } // date range if ($srchbdate != "" && $srchedate != "") { - $logfromtables[]="lognotes"; - $logconstraints[]="lognotes.date between \"$srchbdate\" and \"$srchedate\""; + $logfromtables[] = "lognotes"; + $logconstraints[] = "lognotes.date between \"$srchbdate\" and \"$srchedate\""; } // shift - if ($srchshift !="0") { - $logfromtables[]="lognotes"; - $logconstraints[]="lognotes.shift=\"$srchshift\""; + if ($srchshift != "0") { + $logfromtables[] = "lognotes"; + $logconstraints[] = "lognotes.shift=\"$srchshift\""; } // tech - if ($srchtech !="0") { - $logfromtables[]="lognotes"; - $logconstraints[]="lognotes.tech=\"$srchtech\""; + if ($srchtech != "0") { + $logfromtables[] = "lognotes"; + $logconstraints[] = "lognotes.tech=\"$srchtech\""; } // subject - if ($srchsubj !="0") { - $logfromtables[]="lognotes"; - $logconstraints[]="lognotes.subject=\"$srchsubj\""; + if ($srchsubj != "0") { + $logfromtables[] = "lognotes"; + $logconstraints[] = "lognotes.subject=\"$srchsubj\""; } // search text - if ($srchtext !="") { - $logfromtables[]="lognotes"; - $logconstraints[]="lognotes.lognote like \"%$srchtext%\""; - } - // flags - if ($srchflags != NULL) { - foreach ($srchflags as $flagtblnum) { - $flagtblname="flag_{$flagtblnum}"; - $logfromtables[]="lognotes"; - $logfromtables[]=$flagtblname; - $logconstraints[]="lognotes.lognoteid={$flagtblname}.id and {$flagtblname}.target=\"lognotes\""; - } + if ($srchtext != "") { + $logfromtables[] = "lognotes"; + $logconstraints[] = "lognotes.lognote like \"%$srchtext%\""; } // uid if ($srchuid != "any" && $srchuid != "") { - $logfromtables[]="lognotes"; - $logfromtables[]="logparts"; - $logfromtables[]="parts"; - $logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.uid=\"{$srchuid}\""; + $logfromtables[] = "lognotes"; + $logfromtables[] = "logparts"; + $logfromtables[] = "parts"; + $logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.uid=\"{$srchuid}\""; } // part number if ($srchpn != "any" && $srchpn != "") { - $logfromtables[]="lognotes"; - $logfromtables[]="logparts"; - $logfromtables[]="parts"; - $logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.partnum=\"{$srchpn}\""; + $logfromtables[] = "lognotes"; + $logfromtables[] = "logparts"; + $logfromtables[] = "parts"; + $logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.partnum=\"{$srchpn}\""; } // serial number if ($srchsn != "any" && $srchsn != "") { - $logfromtables[]="lognotes"; - $logfromtables[]="logparts"; - $logfromtables[]="parts"; - $logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.sernum=\"{$srchsn}\""; + $logfromtables[] = "lognotes"; + $logfromtables[] = "logparts"; + $logfromtables[] = "parts"; + $logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.sernum=\"{$srchsn}\""; } // part name if ($srchpname != "any" && $srchpname != "") { - $logfromtables[]="lognotes"; - $logfromtables[]="logparts"; - $logfromtables[]="parts"; - $logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.partname like \"%{$srchpname}%\""; + $logfromtables[] = "lognotes"; + $logfromtables[] = "logparts"; + $logfromtables[] = "parts"; + $logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.partname like \"%{$srchpname}%\""; } // part location if ($srchploc != "any" && $srchploc != "") { - $logfromtables[]="lognotes"; - $logfromtables[]="logparts"; - $logfromtables[]="parts"; - $logfromtables[]="maintforms"; - $logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\""; + $logfromtables[] = "lognotes"; + $logfromtables[] = "logparts"; + $logfromtables[] = "parts"; + $logfromtables[] = "maintforms"; + $logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\""; } // next higher assembly if ($srchnha != "any" && $srchnha != "") { - $logfromtables[]="lognotes"; - $logfromtables[]="logparts"; - $logfromtables[]="parts"; - $logfromtables[]="maintforms"; - $logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\""; + $logfromtables[] = "lognotes"; + $logfromtables[] = "logparts"; + $logfromtables[] = "parts"; + $logfromtables[] = "maintforms"; + $logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\""; } // repair order if ($srchrepord != "any" && $srchrepord != "") { - $logfromtables[]="lognotes"; - $logfromtables[]="logparts"; - $logfromtables[]="parts"; - $logfromtables[]="maintforms"; - $logconstraints[]="lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; + $logfromtables[] = "lognotes"; + $logfromtables[] = "logparts"; + $logfromtables[] = "parts"; + $logfromtables[] = "maintforms"; + $logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; + } + // flags + if (!empty($srchflags)) { + unset($flagconstraints); + $flagcount = count($srchflags); + $logfromtables[] = "lognotes"; + $logfromtables[] = "flagmap"; + $flagconstraints[] = "flagmap.lognoteid=lognotes.lognoteid and flagmap.flagid in ("; + foreach ($srchflags as $flagid) { + $flagconstraints[] = "\"$flagid\""; + $flagconstraints[] = ","; + } + // remove final comma + array_splice($flagconstraints, -1, 1); + $flagconstraints[] = ") group by flagmap.lognoteid having count(distinct flagmap.flagid)=$flagcount"; + // make flagconstraints a single string so that the final implode doesn't split it + $logconstraints[] = join('', $flagconstraints); } // build the clauses and run the query - $logfromclause=implode(",",array_unique($logfromtables)); - $logwhereclause=implode(" and ",$logconstraints); - $logrowqry=mysqli_query($db,"select lognotes.* from $logfromclause where $logwhereclause order by lognotes.date asc, lognotes.time asc"); + $logfromclause = implode(",", array_unique($logfromtables)); + $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)) { + if (in_array("maintform", $target)) { // maintforms search // define the query constraints // log note id if ($srchnoteid != "any" && $srchnoteid != "") { - $mffromtables[]="maintforms"; - $mffromtables[]="lognotes"; - $mfconstraints[]="maintforms.lognoteid=lognotes.lognoteid and lognotes.lognoteid=\"$srchnoteid\""; + $mffromtables[] = "maintforms"; + $mffromtables[] = "lognotes"; + $mfconstraints[] = "maintforms.lognoteid=lognotes.lognoteid and lognotes.lognoteid=\"$srchnoteid\""; } // maint form id if ($srchmfid != "any" && $srchmfid != "") { - $mffromtables[]="maintforms"; - $mfconstraints[]="maintforms.maintformid=\"$srchmfid\""; + $mffromtables[] = "maintforms"; + $mfconstraints[] = "maintforms.maintformid=\"$srchmfid\""; } // date range if ($srchbdate != "" && $srchedate != "") { - $mffromtables[]="maintforms"; - $mfconstraints[]="maintforms.mfdate between \"$srchbdate\" and \"$srchedate\""; + $mffromtables[] = "maintforms"; + $mfconstraints[] = "maintforms.mfdate between \"$srchbdate\" and \"$srchedate\""; } // shift - if ($srchshift !="0") { - $mffromtables[]="maintforms"; - $mffromtables[]="lognotes"; - $mfconstraints[]="maintforms.lognoteid=lognotes.lognoteid and lognotes.shift=\"$srchshift\""; + if ($srchshift != "0") { + $mffromtables[] = "maintforms"; + $mffromtables[] = "lognotes"; + $mfconstraints[] = "maintforms.lognoteid=lognotes.lognoteid and lognotes.shift=\"$srchshift\""; } // tech - if ($srchtech !="0") { - $mffromtables[]="maintforms"; - $mfconstraints[]="maintforms.mftech=\"$srchtech\""; + if ($srchtech != "0") { + $mffromtables[] = "maintforms"; + $mfconstraints[] = "maintforms.mftech=\"$srchtech\""; } // subject - if ($srchsubj !="0") { - $mffromtables[]="maintforms"; - $mffromtables[]="lognotes"; - $mfconstraints[]="maintforms.lognoteid=lognotes.lognoteid and lognotes.subject=\"$srchsubj\""; + if ($srchsubj != "0") { + $mffromtables[] = "maintforms"; + $mffromtables[] = "lognotes"; + $mfconstraints[] = "maintforms.lognoteid=lognotes.lognoteid and lognotes.subject=\"$srchsubj\""; } // search text - if ($srchtext !="") { - $mffromtables[]="maintforms"; - $mffromtables[]="maintactions"; - $mfconstraints[]="maintforms.mfmalfunction like \"%$srchtext%\" or (maintactions.action like \"%$srchtext%\" and maintforms.maintformid=maintactions.maintformnum)"; - } - // flags - foreach ($srchflags as $flagtblnum) { - $flagtblname="flag_{$flagtblnum}"; - $mffromtables[]="maintforms"; - $mffromtables[]=$flagtblname; - $mfconstraints[]="maintforms.maintformid={$flagtblname}.id and {$flagtblname}.target=\"maintforms\""; + if ($srchtext != "") { + $mffromtables[] = "maintforms"; + $mffromtables[] = "maintactions"; + $mfconstraints[] = "maintforms.mfmalfunction like \"%$srchtext%\" or (maintactions.action like \"%$srchtext%\" and maintforms.maintformid=maintactions.maintformnum)"; } // uid if ($srchuid != "any" && $srchuid != "") { - $mffromtables[]="maintforms"; - $mffromtables[]="parts"; - $mfconstraints[]="maintforms.mfpart=parts.partid and parts.uid=\"{$srchuid}\""; + $mffromtables[] = "maintforms"; + $mffromtables[] = "parts"; + $mfconstraints[] = "maintforms.mfpart=parts.partid and parts.uid=\"{$srchuid}\""; } // part number if ($srchpn != "any" && $srchpn != "") { - $mffromtables[]="maintforms"; - $mffromtables[]="parts"; - $mfconstraints[]="maintforms.mfpart=parts.partid and parts.partnum=\"{$srchpn}\""; + $mffromtables[] = "maintforms"; + $mffromtables[] = "parts"; + $mfconstraints[] = "maintforms.mfpart=parts.partid and parts.partnum=\"{$srchpn}\""; } // serial number if ($srchsn != "any" && $srchsn != "") { - $mffromtables[]="maintforms"; - $mffromtables[]="parts"; - $mfconstraints[]="maintforms.mfpart=parts.partid and parts.sernum=\"{$srchsn}\""; + $mffromtables[] = "maintforms"; + $mffromtables[] = "parts"; + $mfconstraints[] = "maintforms.mfpart=parts.partid and parts.sernum=\"{$srchsn}\""; } // part name if ($srchpname != "any" && $srchpname != "") { - $mffromtables[]="maintforms"; - $mffromtables[]="parts"; - $mfconstraints[]="maintforms.mfpart=parts.partid and parts.partname like \"%{$srchpname}%\""; + $mffromtables[] = "maintforms"; + $mffromtables[] = "parts"; + $mfconstraints[] = "maintforms.mfpart=parts.partid and parts.partname like \"%{$srchpname}%\""; } // part location if ($srchploc != "any" && $srchploc != "") { - $mffromtables[]="parts"; - $mffromtables[]="maintforms"; - $mfconstraints[]="maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\""; + $mffromtables[] = "parts"; + $mffromtables[] = "maintforms"; + $mfconstraints[] = "maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\""; } // next higher assembly if ($srchnha != "any" && $srchnha != "") { - $mffromtables[]="parts"; - $mffromtables[]="maintforms"; - $mfconstraints[]="maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\""; + $mffromtables[] = "parts"; + $mffromtables[] = "maintforms"; + $mfconstraints[] = "maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\""; } // repair order if ($srchrepord != "any" && $srchrepord != "") { - $mffromtables[]="parts"; - $mffromtables[]="maintforms"; - $mfconstraints[]="maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; + $mffromtables[] = "parts"; + $mffromtables[] = "maintforms"; + $mfconstraints[] = "maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; + } + // flags + if (!empty($srchflags)) { + unset($flagconstraints); + $flagcount = count($srchflags); + $mffromtables[] = "maintforms"; + $mffromtables[] = "flagmap"; + $flagconstraints[] = "flagmap.maintformid=maintforms.maintformid and flagmap.flagid in ("; + foreach ($srchflags as $thisflagid) { + $flagconstraints[] = "\"$thisflagid\""; + $flagconstraints[] = ","; + } + // remove final comma + array_splice($flagconstraints, -1, 1); + $flagconstraints[] = ") group by flagmap.maintformid having count(distinct flagmap.flagid)=$flagcount"; + // make flagconstraints a single string so that the final implode doesn't split it + $mfconstraints[] = join('', $flagconstraints); } // build the clauses and run the query - $mffromclause=implode(",",array_unique($mffromtables)); - $mfwhereclause=implode(" and ",$mfconstraints); - $mfrowqry=mysqli_query($db,"select maintforms.* from $mffromclause where $mfwhereclause order by maintforms.mfdate asc, maintforms.mftime asc"); + $mffromclause = implode(",", array_unique($mffromtables)); + $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)) { + if (in_array("part", $target)) { // parts search // define the query constraints // log note id if ($srchnoteid != "any" && $srchnoteid != "") { - $pfromtables[]="parts"; - $pfromtables[]="logparts"; - $pfromtables[]="lognotes"; - $pconstraints[]="parts.partid=logparts.partid and logparts.lognoteid=lognotes.lognoteid and lognotes.lognoteid=\"$srchnoteid\""; + $pfromtables[] = "parts"; + $pfromtables[] = "logparts"; + $pfromtables[] = "lognotes"; + $pconstraints[] = "parts.partid=logparts.partid and logparts.lognoteid=lognotes.lognoteid and lognotes.lognoteid=\"$srchnoteid\""; } // maint form id if ($srchmfid != "any" && $srchmfid != "") { - $pfromtables[]="parts"; - $pfromtables[]="maintforms"; - $pconstraints[]="parts.partid=maintforms.mfpart and maintforms.maintformid=\"$srchmfid\""; + $pfromtables[] = "parts"; + $pfromtables[] = "maintforms"; + $pconstraints[] = "parts.partid=maintforms.mfpart and maintforms.maintformid=\"$srchmfid\""; } // date range doesn't apply to parts // shift doesn't apply to parts // tech doesn't apply to parts // subject doesn't apply to parts // search text doesn't apply to parts - // flags doesn't apply to parts // uid if ($srchuid != "any" && $srchuid != "") { - $pfromtables[]="parts"; - $pconstraints[]="parts.uid=\"{$srchuid}\""; + $pfromtables[] = "parts"; + $pconstraints[] = "parts.uid=\"{$srchuid}\""; } // part number if ($srchpn != "any" && $srchpn != "") { - $pfromtables[]="parts"; - $pconstraints[]="parts.partnum=\"{$srchpn}\""; + $pfromtables[] = "parts"; + $pconstraints[] = "parts.partnum=\"{$srchpn}\""; } // serial number if ($srchsn != "any" && $srchsn != "") { - $pfromtables[]="parts"; - $pconstraints[]="parts.sernum=\"{$srchsn}\""; + $pfromtables[] = "parts"; + $pconstraints[] = "parts.sernum=\"{$srchsn}\""; } // part name if ($srchpname != "any" && $srchpname != "") { - $pfromtables[]="parts"; - $pconstraints[]="parts.partname like \"%{$srchpname}%\""; + $pfromtables[] = "parts"; + $pconstraints[] = "parts.partname like \"%{$srchpname}%\""; } // part location if ($srchploc != "any" && $srchploc != "") { - $pfromtables[]="parts"; - $pfromtables[]="maintforms"; - $pconstraints[]="maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\""; + $pfromtables[] = "parts"; + $pfromtables[] = "maintforms"; + $pconstraints[] = "maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\""; } // next higher assembly if ($srchnha != "any" && $srchnha != "") { - $pfromtables[]="parts"; - $pfromtables[]="maintforms"; - $pconstraints[]="maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\""; + $pfromtables[] = "parts"; + $pfromtables[] = "maintforms"; + $pconstraints[] = "maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\""; } // repair order if ($srchrepord != "any" && $srchrepord != "") { - $pfromtables[]="parts"; - $pfromtables[]="maintforms"; - $pconstraints[]="maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; + $pfromtables[] = "parts"; + $pfromtables[] = "maintforms"; + $pconstraints[] = "maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; } + // flags doesn't apply to parts // build the clauses and run the query - $pfromclause=implode(",",array_unique($pfromtables)); - $pwhereclause=implode(" and ",$pconstraints); - $prowqry=mysqli_query($db,"select parts.* from $pfromclause where $pwhereclause order by parts.uid asc"); + $pfromclause = implode(",", array_unique($pfromtables)); + $pwhereclause = implode(" and ", $pconstraints); + $prowqry = mysqli_query($db, "select parts.* from $pfromclause where $pwhereclause order by parts.uid asc"); } } // ******** end database manipulation ******** pagetable("begin"); -if(!$print){ - pageblock("left","begin"); +if (!$print) { + pageblock("left", "begin"); sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); banner($print); // display the form -if ($srchnoteid) $noteidval=$srchnoteid; else $noteidval="any"; -if ($srchmfid) $mfidval=$srchmfid; else $mfidval="any"; -if ($srchbdate) $bdateval=$srchbdate; else $bdateval=$mindate; -if ($srchedate) $edateval=$srchedate; else $edateval=$maxdate; -if ($srchshift) $shiftval=$srchshift; else $shiftval=0; -if ($srchtech) $techval=$srchtech; else $techval=0; -if ($srchsubj) $subjval=$srchsubj; else $subjval=0; -if ($srchtext) $textval=$srchtext; else $textval=""; -if ($srchuid) $uidval=$srchuid; else $uidval="any"; -if ($srchpn) $pnval=$srchpn; else $pnval="any"; -if ($srchsn) $snval=$srchsn; else $snval="any"; -if ($srchpname) $pnameval=$srchpname; else $pnameval="any"; -if ($srchploc) $plocval=$srchploc; else $plocval="any"; -if ($srchnha) $nhaval=$srchnha; else $nhaval="any"; -if ($srchrepord) $repordval=$srchrepord; else $repordval="any"; +if ($srchnoteid) $noteidval = $srchnoteid; +else $noteidval = "any"; +if ($srchmfid) $mfidval = $srchmfid; +else $mfidval = "any"; +if ($srchbdate) $bdateval = $srchbdate; +else $bdateval = $mindate; +if ($srchedate) $edateval = $srchedate; +else $edateval = $maxdate; +if ($srchshift) $shiftval = $srchshift; +else $shiftval = 0; +if ($srchtech) $techval = $srchtech; +else $techval = 0; +if ($srchsubj) $subjval = $srchsubj; +else $subjval = 0; +if ($srchtext) $textval = $srchtext; +else $textval = ""; +if ($srchuid) $uidval = $srchuid; +else $uidval = "any"; +if ($srchpn) $pnval = $srchpn; +else $pnval = "any"; +if ($srchsn) $snval = $srchsn; +else $snval = "any"; +if ($srchpname) $pnameval = $srchpname; +else $pnameval = "any"; +if ($srchploc) $plocval = $srchploc; +else $plocval = "any"; +if ($srchnha) $nhaval = $srchnha; +else $nhaval = "any"; +if ($srchrepord) $repordval = $srchrepord; +else $repordval = "any"; if (!$print) { echo " @@ -390,53 +429,55 @@ if (!$print) {

Shift:         Tech:         Subject:  %s", - $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( + "%s", + $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("%s", - $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( + "%s", + $flagcheckbox["flagid"], + $flagcheckbox["flagcolor"], + $flagcheckbox["flagname"], + $flagcheckbox["flagsym"] + ); } } - if ($flagcount<$flagsperline) { + if ($flagcount < $flagsperline) { echo "   "; $flagcount++; } else { echo "
"; - $flagcount=1; + $flagcount = 1; } } echo " @@ -493,7 +544,7 @@ if (!$print) { echo " Search in:   "; - if ($target[0]=="") $target=[]; + if ($target[0] == "") $target = []; if (in_array("log", $target)) { echo "Logbook  "; } else { @@ -519,7 +570,7 @@ if (!$print) { "; if ($search) { - $allvars=http_build_query($_REQUEST); + $allvars = http_build_query($_REQUEST); echo "       Print Search Results "; @@ -538,30 +589,30 @@ if (!$print) {

Shift:   "; - if ($shiftval==0) { + if ($shiftval == 0) { echo "any"; } else { - $shiftname=dblookup($db,"shifts","shiftid","shiftname",$shiftval); + $shiftname = dblookup($db, "shifts", "shiftid", "shiftname", $shiftval); echo "$shiftname"; } echo "        Tech:   "; - if ($techval==0) { + if ($techval == 0) { echo "any"; } else { - $techname=dblookup($db,"techs","techid","techname",$techval); + $techname = dblookup($db, "techs", "techid", "techname", $techval); echo "$techname"; } echo "        Subject:   "; - if ($subjval==0) { + if ($subjval == 0) { echo "any"; } else { - $subjname=dblookup($db,"subjects","subjectid","subjectname",$subjval); + $subjname = dblookup($db, "subjects", "subjectid", "subjectname", $subjval); echo "$subjname"; } echo " @@ -588,30 +639,33 @@ if (!$print) {

Flags: "; - $flagslist=mysqli_query($db,"select * from flags"); - $flagsperline=8; - $flagcount=1; - while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) { + $flagslist = mysqli_query($db, "select * from flags"); + $flagsperline = 8; + $flagcount = 1; + while ($flagcheckbox = mysqli_fetch_assoc($flagslist)) { if ($srchflags) { - if ($srchflags[0]=="") $srchflags=[]; - if (in_array($flagcheckbox["flagid"],$srchflags)) { - printf("%s", - $flagcheckbox["flagcolor"],$flagcheckbox["flagsym"]); + if ($srchflags[0] == "") $srchflags = []; + if (in_array($flagcheckbox["flagid"], $srchflags)) { + printf( + "%s", + $flagcheckbox["flagcolor"], + $flagcheckbox["flagsym"] + ); } } - if ($flagcount<$flagsperline) { + if ($flagcount < $flagsperline) { echo "   "; $flagcount++; } else { echo "
"; - $flagcount=1; + $flagcount = 1; } } echo "

"; if ($doparts) { - if ($target[0]=="") $target=[]; + if ($target[0] == "") $target = []; echo " Search in:   "; @@ -634,43 +688,48 @@ if (!$print) { } if ($search) { - if ($target[0]=="") $target=[]; - if (in_array("log",$target)) { + if ($target[0] == "") $target = []; + if (in_array("log", $target)) { // run lognotes query and show results - if(mysqli_num_rows($logrowqry)) { + $log_num_results = mysqli_num_rows($logrowqry); + if ($log_num_results) { echo " - Results from Logbook

+ Results from Logbook: $log_num_results

\n"; while ($tablerow = mysqli_fetch_assoc($note)) { - $reftonote=$tablerow["lognoteid"]; - $refs="    \"Add"; + $thisnote = $tablerow["lognoteid"]; + $refs = "    \"Add"; if (islink($tablerow["lognoteid"])) { - $refs=$refs."      \"View"; + $refs = $refs . "      \"View"; } // convert tech number to name - $tname=dblookup($db,"techs","techid","techname",$tablerow["tech"]); + $tname = dblookup($db, "techs", "techid", "techname", $tablerow["tech"]); //convert subject number to name - $subjname=dblookup($db,"subjects","subjectid","subjectname",$tablerow["subject"]); + $subjname = dblookup($db, "subjects", "subjectid", "subjectname", $tablerow["subject"]); // create links of urls in note - $fmtnote=convertweblinks($tablerow["lognote"]); + $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"]; - $flagstring=$flagstring."$flagsym  "; - } + $flagstring = ""; + $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 . "$flagsym  "; } if ($flagstring) { - $fmtnote=$fmtnote."
".$flagstring."     "; - } else { - $fmtnote=$fmtnote."
"; + $fmtnote = $fmtnote . "
" . $flagstring . "     "; + } else { + $fmtnote = $fmtnote . "
"; } 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."PARTS"; + if (mysqli_num_rows(mysqli_query($db, "select logpartid from logparts where lognoteid=\"$thisnote\""))) { + $fmtnote = $fmtnote . "PARTS"; } } // now print the line in the table if ($showtime) { printf( - "%s   + "%s   %s      %s      %s      %s
%s

\n", - $tablerow["lognoteid"],$tablerow["lognoteid"], - $tablerow["time"], - $tname, - $subjname, - $refs, - $fmtnote + $tablerow["lognoteid"], + $tablerow["lognoteid"], + $tablerow["time"], + $tname, + $subjname, + $refs, + $fmtnote ); } else { printf( - "%s   + "%s   %s      %s      %s
%s

\n", - $tablerow["lognoteid"],$tablerow["lognoteid"], - $tname, - $subjname, - $refs, - $fmtnote + $tablerow["lognoteid"], + $tablerow["lognoteid"], + $tname, + $subjname, + $refs, + $fmtnote ); } } @@ -215,11 +215,11 @@ function shifttable_clean($shift, $tgt_date, $db) { echo "

\n"; } -framework("begin","$logname","Online Logbook",$print); +framework("begin", "$logname", "Online Logbook", $print); pagetable("begin"); -if(!$print) { - pageblock("left","begin"); +if (!$print) { + pageblock("left", "begin"); //calendar($tgt_year,$tgt_month,$tgt_day,"lognotes.php"); echo "
"; echo htmlspecialchars($tgt_date); @@ -232,29 +232,27 @@ if(!$print) { sidemenu(); echo "

"; showlinklist($print); - pageblock("left","end"); + pageblock("left", "end"); } else { echo "
$tgt_year-$tgt_month-$tgt_day

"; } -pageblock("right","begin"); -banner($print); +pageblock("right", "begin"); +banner($print); if (isset($techid)) nag($techid); //$date=date("Y-m-d",mktime(0,0,0,$tgt_month,$tgt_day,$tgt_year)); -$qry=mysqli_query($db,"select shiftid from shifts where status=1 order by shiftid asc"); -while ($shnum=mysqli_fetch_row($qry)) { - if ($tablestyle==1) { - shifttable_classic($shnum[0],$tgt_date,$db); - } else if ($tablestyle==2) { - shifttable_clean($shnum[0],$tgt_date,$db); +$qry = mysqli_query($db, "select shiftid from shifts where status=1 order by shiftid asc"); +while ($shnum = mysqli_fetch_row($qry)) { + if ($tablestyle == 1) { + shifttable_classic($shnum[0], $tgt_date, $db); + } else if ($tablestyle == 2) { + shifttable_clean($shnum[0], $tgt_date, $db); } } banner($print); -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/maintform.php b/distfiles/maintform.php index 933db51..44dcde0 100644 --- a/distfiles/maintform.php +++ b/distfiles/maintform.php @@ -2,45 +2,47 @@ /* maintform.php OpenLog Online Logbook - Copyright (C) 2025 Rod Wright + Copyright (C) 2026 Rod Wright SPDX-License-Identifier: GPL-2.0 */ include("functions.php"); -if (isset($_SESSION['login'])) $techid=$_SESSION['login']; +if (isset($_SESSION['login'])) $techid = $_SESSION['login']; -$histdays=$_REQUEST['histdays']; -$submit=$_REQUEST['submit']; +$print = $_REQUEST['print'] ?? NULL; +$histdays = $_REQUEST['histdays'] ?? NULL; +$submit = $_REQUEST['submit'] ?? NULL; -$logname=LOG_NAME; -$uidtext=UID_TEXT; +$logname = LOG_NAME; +$uidtext = UID_TEXT; -if ($histdays=="") $histdays=30; +if ($histdays == "") $histdays = 30; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } // define pendtable function -function pendtable($tech_id, $db) { - $uidtext=UID_TEXT; +function pendtable($tech_id, $db) +{ + $uidtext = UID_TEXT; // print section header if ($tech_id) { echo " Your Pending Maintenance Forms
"; - $pmf=mysqli_query($db,"select * from maintforms where mftech=\"$tech_id\" and pending=\"1\" order by mfdate desc, mftime desc"); + $pmf = mysqli_query($db, "select * from maintforms where mftech=\"$tech_id\" and pending=\"1\" order by mfdate desc, mftime desc"); } else { echo " All Pending Maintenance Forms
"; - $pmf=mysqli_query($db,"select * from maintforms where pending=\"1\" order by mfdate desc, mftime desc"); + $pmf = mysqli_query($db, "select * from maintforms where pending=\"1\" order by mfdate desc, mftime desc"); } echo "
@@ -59,26 +61,26 @@ function pendtable($tech_id, $db) { "; while ($pendrow = mysqli_fetch_assoc($pmf)) { // look up part data - $uid=dblookup($db,"parts","partid","uid",$pendrow["mfpart"]); - if ($uid=="") $uid=" "; - $partno=dblookup($db,"parts","partid","partnum",$pendrow["mfpart"]); - if ($partno=="") $partno=" "; - $serno=dblookup($db,"parts","partid","sernum",$pendrow["mfpart"]); - if ($serno=="") $serno=" "; - $partname=dblookup($db,"parts","partid","partname",$pendrow["mfpart"]); - if ($partname=="") $partname=" "; + $uid = dblookup($db, "parts", "partid", "uid", $pendrow["mfpart"]); + if ($uid == "") $uid = " "; + $partno = dblookup($db, "parts", "partid", "partnum", $pendrow["mfpart"]); + if ($partno == "") $partno = " "; + $serno = dblookup($db, "parts", "partid", "sernum", $pendrow["mfpart"]); + if ($serno == "") $serno = " "; + $partname = dblookup($db, "parts", "partid", "partname", $pendrow["mfpart"]); + if ($partname == "") $partname = " "; // look up tech name - $tname=dblookup($db,"techs","techid","techname",$pendrow["mftech"]); - if ($pendrow["lognoteid"]==0) { - $noteidval=" "; - $notetag="%s%s"; + $tname = dblookup($db, "techs", "techid", "techname", $pendrow["mftech"]); + if ($pendrow["lognoteid"] == 0) { + $noteidval = " "; + $notetag = "%s%s"; } else { - $noteidval=$pendrow["lognoteid"]; - $notetag="%s"; + $noteidval = $pendrow["lognoteid"]; + $notetag = "%s"; } if (!$tech_id) { printf( - " + " @@ -88,18 +90,20 @@ function pendtable($tech_id, $db) { ", - $pendrow["maintformid"],$pendrow["maintformid"], - $pendrow["mfdate"], - $tname, - $uid, - $partno, - $serno, - $partname, - $noteidval,$noteidval + $pendrow["maintformid"], + $pendrow["maintformid"], + $pendrow["mfdate"], + $tname, + $uid, + $partno, + $serno, + $partname, + $noteidval, + $noteidval ); } else { printf( - " + " @@ -108,13 +112,15 @@ function pendtable($tech_id, $db) { ", - $pendrow["maintformid"],$pendrow["maintformid"], - $pendrow["mfdate"], - $uid, - $partno, - $serno, - $partname, - $noteidval,$noteidval + $pendrow["maintformid"], + $pendrow["maintformid"], + $pendrow["mfdate"], + $uid, + $partno, + $serno, + $partname, + $noteidval, + $noteidval ); } } @@ -124,9 +130,10 @@ function pendtable($tech_id, $db) { } // define histtable function -function histtable($hist_days,$db) { - $uidtext=UID_TEXT; - $dayopts=array(30,90,180,365); +function histtable($hist_days, $db) +{ + $uidtext = UID_TEXT; + $dayopts = array(30, 90, 180, 365); // print section header echo " @@ -134,13 +141,13 @@ function histtable($hist_days,$db) { Days      @@ -159,24 +166,24 @@ function histtable($hist_days,$db) { "; while ($histrow = mysqli_fetch_assoc($histqry)) { // look up part data - $uid=dblookup($db,"parts","partid","uid",$histrow["mfpart"]); - $partno=dblookup($db,"parts","partid","partnum",$histrow["mfpart"]); - if ($partno=="") $partno=" "; - $serno=dblookup($db,"parts","partid","sernum",$histrow["mfpart"]); - if ($serno=="") $serno=" "; - $partname=dblookup($db,"parts","partid","partname",$histrow["mfpart"]); - if ($partname=="") $partname=" "; + $uid = dblookup($db, "parts", "partid", "uid", $histrow["mfpart"]); + $partno = dblookup($db, "parts", "partid", "partnum", $histrow["mfpart"]); + if ($partno == "") $partno = " "; + $serno = dblookup($db, "parts", "partid", "sernum", $histrow["mfpart"]); + if ($serno == "") $serno = " "; + $partname = dblookup($db, "parts", "partid", "partname", $histrow["mfpart"]); + if ($partname == "") $partname = " "; // look up tech name - $tname=dblookup($db,"techs","techid","techname",$histrow["mftech"]); - if ($histrow["lognoteid"]==0) { - $noteidval=" "; - $notetag="%s%s"; + $tname = dblookup($db, "techs", "techid", "techname", $histrow["mftech"]); + if ($histrow["lognoteid"] == 0) { + $noteidval = " "; + $notetag = "%s%s"; } else { - $noteidval=$histrow["lognoteid"]; - $notetag="%s"; + $noteidval = $histrow["lognoteid"]; + $notetag = "%s"; } printf( - " + " @@ -186,14 +193,16 @@ function histtable($hist_days,$db) { ", - $histrow["maintformid"],$histrow["maintformid"], - $histrow["mfdate"], - $tname, - $uid, - $partno, - $serno, - $partname, - $noteidval,$noteidval + $histrow["maintformid"], + $histrow["maintformid"], + $histrow["mfdate"], + $tname, + $uid, + $partno, + $serno, + $partname, + $noteidval, + $noteidval ); } echo " @@ -201,30 +210,28 @@ function histtable($hist_days,$db) { "; } -framework("begin","$logname","Maintenance Forms",$print); +framework("begin", "$logname", "Maintenance Forms", $print); pagetable("begin"); -if(!$print) { - pageblock("left","begin"); +if (!$print) { + pageblock("left", "begin"); sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); -banner($print); +pageblock("right", "begin"); +banner($print); echo "
"; -$haspending=mysqli_num_rows(mysqli_query($db,"select maintformid from maintforms where mftech=\"$techid\" and pending=\"1\"")); +$haspending = mysqli_num_rows(mysqli_query($db, "select maintformid from maintforms where mftech=\"$techid\" and pending=\"1\"")); if ($haspending) { - pendtable($techid,$db); + pendtable($techid, $db); echo "


"; } -pendtable(0,$db); +pendtable(0, $db); echo "


"; -histtable($histdays,$db); +histtable($histdays, $db); echo "

"; banner($print); -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/maintformentry.php b/distfiles/maintformentry.php index 46a4e26..35b88f5 100644 --- a/distfiles/maintformentry.php +++ b/distfiles/maintformentry.php @@ -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 */ @@ -11,120 +11,123 @@ include("functions.php"); if (!$_SESSION['login'] && ($_REQUEST['mfadd'] || $_REQUEST['actionadd'])) { - header ("Location: login.php"); + header("Location: login.php"); } -$loggedinas=$_SESSION['login']; -$isadmin=dblookup($db,"techs","techid","admin",$loggedinas); +$loggedinas = $_SESSION['login']; +$isadmin = dblookup($db, "techs", "techid", "admin", $loggedinas); -function getmfdata($maintformid) { +function getmfdata($maintformid) +{ // pull maintenance form data from maintforms table global $db; - $mfdata=mysqli_fetch_assoc(mysqli_query($db,"select * from maintforms where maintformid=\"$maintformid\"")); + $mfdata = mysqli_fetch_assoc(mysqli_query($db, "select * from maintforms where maintformid=\"$maintformid\"")); return $mfdata; } -function getactiondata($maintactionid) { +function getactiondata($maintactionid) +{ // pull maintenance action data from maintactions table global $db; - $actiondata=mysqli_fetch_assoc(mysqli_query($db,"select * from maintactions where maintactionid=\"$maintactionid\"")); + $actiondata = mysqli_fetch_assoc(mysqli_query($db, "select * from maintactions where maintactionid=\"$maintactionid\"")); return $actiondata; } -$print=$_REQUEST['print']; +$print = $_REQUEST['print'] ?? NULL; -$maintformid=$_REQUEST['maintformid']; -$lognoteid=$_REQUEST['lognoteid']; -$mfdate=$_REQUEST['date']; -$mftime=$_REQUEST['time']; -$mfsubmit=$_REQUEST['mfsubmit']; -$mfadd=$_REQUEST['mfadd']; -$mfedit=$_REQUEST['mfedit']; -$mfdelete=$_REQUEST['mfdelete']; -$mfpartloc=$_REQUEST['mfpartloc']; -$mfmalfunction=$_REQUEST['mfmalfunction']; -$nha=$_REQUEST['nha']; -$repord=$_REQUEST['repord']; -$mfpart=$_REQUEST['mfpart']; -$uid=$_REQUEST['uid']; -$partnum=$_REQUEST['partnum']; -$sernum=$_REQUEST['sernum']; -$partname=$_REQUEST['partname']; -$actionadd=$_REQUEST['actionadd']; -$actionedit=$_REQUEST['actionedit']; -$actiondelete=$_REQUEST['actiondelete']; -$maintactionid=$_REQUEST['maintactionid']; -$actiondate=$_REQUEST['actiondate']; -$actiontime=$_REQUEST['actiontime']; -$actiontech=$_REQUEST['actiontech']; -$action=$_REQUEST['action']; -$actionaddsubmit=$_REQUEST['actionaddsubmit']; -$actioneditsubmit=$_REQUEST['actioneditsubmit']; -$printfmt=$_REQUEST['printfmt']; -if ($printfmt) $print=1; -$flags=$_POST['flags']; +$maintformid = $_REQUEST['maintformid'] ?? NULL; +$lognoteid = $_REQUEST['lognoteid'] ?? NULL; +$mfdate = $_REQUEST['date'] ?? NULL; +$mftime = $_REQUEST['time'] ?? NULL; +$mfsubmit = $_REQUEST['mfsubmit'] ?? NULL; +$mfadd = $_REQUEST['mfadd'] ?? NULL; +$mfedit = $_REQUEST['mfedit'] ?? NULL; +$mfdelete = $_REQUEST['mfdelete'] ?? NULL; +$mfpartloc = $_REQUEST['mfpartloc'] ?? NULL; +$mfmalfunction = $_REQUEST['mfmalfunction'] ?? NULL; +$nha = $_REQUEST['nha'] ?? NULL; +$repord = $_REQUEST['repord'] ?? NULL; +$mfpart = $_REQUEST['mfpart'] ?? NULL; +$uid = $_REQUEST['uid'] ?? NULL; +$partnum = $_REQUEST['partnum'] ?? NULL; +$sernum = $_REQUEST['sernum'] ?? NULL; +$partname = $_REQUEST['partname'] ?? NULL; +$actionadd = $_REQUEST['actionadd'] ?? NULL; +$actionedit = $_REQUEST['actionedit'] ?? NULL; +$actiondelete = $_REQUEST['actiondelete'] ?? NULL; +$maintactionid = $_REQUEST['maintactionid'] ?? NULL; +$actiondate = $_REQUEST['actiondate'] ?? NULL; +$actiontime = $_REQUEST['actiontime'] ?? NULL; +$actiontech = $_REQUEST['actiontech'] ?? NULL; +$action = $_REQUEST['action'] ?? NULL; +$actionaddsubmit = $_REQUEST['actionaddsubmit'] ?? NULL; +$actioneditsubmit = $_REQUEST['actioneditsubmit'] ?? NULL; +$printfmt = $_REQUEST['printfmt'] ?? NULL; +if ($printfmt) $print = TRUE; +$flags = $_POST['flags'] ?? []; -$logname=LOG_NAME; -$uidtext=UID_TEXT; +$logname = LOG_NAME; +$uidtext = UID_TEXT; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } if ($printfmt) { - framework("begin","","",$print); + framework("begin", "", "", $print); } else if ($mfedit) { - framework("begin","$logname","Maintenance Form Edit",$print); - if ($loggedinas) $mfauthorized=1; + framework("begin", "$logname", "Maintenance Form Edit", $print); + if ($loggedinas) $mfauthorized = TRUE; } else if ($mfdelete) { - framework("begin","$logname","Maintenance Form Edit",$print); - $mfowner=dblookup($db,"maintforms","maintformid","mftech",$maintformid); - if (($loggedinas==$mfowner) || $isadmin) $mfauthorized=1; + framework("begin", "$logname", "Maintenance Form Edit", $print); + $mfowner = dblookup($db, "maintforms", "maintformid", "mftech", $maintformid); + if (($loggedinas == $mfowner) || $isadmin) $mfauthorized = TRUE; } else if ($actionadd) { - framework("begin","$logname","Maintenance Action Entry",$print); - $mfowner=dblookup($db,"maintforms","maintformid","mftech",$maintformid); + framework("begin", "$logname", "Maintenance Action Entry", $print); + $mfowner = dblookup($db, "maintforms", "maintformid", "mftech", $maintformid); if ($loggedinas) { - $mfauthorized=1; - $actionauthorized=1; + $mfauthorized = TRUE; + $actionauthorized = TRUE; } } else if ($actionedit || $actiondelete) { - framework("begin","$logname","Maintenance Action Edit",$print); - $mfowner=dblookup($db,"maintforms","maintformid","mftech",$maintformid); - if ($loggedinas) $mfauthorized=1; - $actionowner=dblookup($db,"maintactions","maintactionid","actiontech",$maintactionid); - if (($loggedinas==$actionowner) || $isadmin) $actionauthorized=1; + framework("begin", "$logname", "Maintenance Action Edit", $print); + $mfowner = dblookup($db, "maintforms", "maintformid", "mftech", $maintformid); + if ($loggedinas) $mfauthorized = TRUE; + $actionowner = dblookup($db, "maintactions", "maintactionid", "actiontech", $maintactionid); + if (($loggedinas == $actionowner) || $isadmin) $actionauthorized = TRUE; } else { - $mfadd=1; - framework("begin","$logname","Maintenance Form Entry",$print); - $mftech=$loggedinas; - $mfauthorized=1; + $mfadd = TRUE; + framework("begin", "$logname", "Maintenance Form Entry", $print); + $mftech = $loggedinas; + $mfauthorized = TRUE; } // ******** begin database manipulation ******** //var_dump($_REQUEST); +$pdatamismatch = NULL; if ((($mfedit || $actionadd || $actionedit) && ! $mfsubmit) || $printfmt) { // pull mf data from database - $mftoedit=getmfdata($maintformid); - $partdatainput=array(); - if ($mftoedit['mfpart']) $partdatainput['partid']=$mftoedit['mfpart']; - if ($uid) $partdatainput['uid']=$uid; - if ($partnum) $partdatainput['partnum']=$partnum; - if ($sernum) $partdatainput['sernum']=$sernum; - $partinfo=get_part_data($partdatainput); - if ($partinfo['result']==2) { - $pdatamismatch=1; + $mftoedit = getmfdata($maintformid); + $partdatainput = []; + if ($mftoedit['mfpart']) $partdatainput['partid'] = $mftoedit['mfpart']; + if ($uid) $partdatainput['uid'] = $uid; + if ($partnum) $partdatainput['partnum'] = $partnum; + if ($sernum) $partdatainput['sernum'] = $sernum; + $partinfo = get_part_data($partdatainput); + if ($partinfo['result'] == 2) { + $pdatamismatch = TRUE; } else { - unset($pdatamismatch); - if ($partinfo['partid']) $mfpart=$partinfo['partid']; - if ($partinfo['uid']) $uid=$partinfo['uid']; - if ($partinfo['partnum']) $partnum=$partinfo['partnum']; - if ($partinfo['sernum']) $sernum=$partinfo['sernum']; - if ($partinfo['partname']) $partname=$partinfo['partname']; + $pdatamismatch = FALSE; + if ($partinfo['partid']) $mfpart = $partinfo['partid']; + if ($partinfo['uid']) $uid = $partinfo['uid']; + if ($partinfo['partnum']) $partnum = $partinfo['partnum']; + if ($partinfo['sernum']) $sernum = $partinfo['sernum']; + if ($partinfo['partname']) $partname = $partinfo['partname']; } } @@ -132,54 +135,59 @@ if ($mfadd) { if ($mfsubmit) { // add the entry if submit is pressed if ($mfmalfunction && ($uid || ($partnum && $sernum))) { + // sanitize and fix blank date and time + $mfdate = fix_date($mfdate); + $mftime = fix_time($mftime); // determine whether supplied date is future or past - $datediff=mysqli_fetch_row(mysqli_query($db,"select datediff(\"$mfdate\",CURRENT_DATE)")); + $datediff = mysqli_fetch_row(mysqli_query($db, "select datediff(\"$mfdate\",CURRENT_DATE)")); // if future, set time to 00:00:01, if past, set to 23:59:59 - if ($datediff[0]<0) { - $mftime="23:59:59:"; + if ($datediff[0] < 0) { + $mftime = "23:59:59:"; } - if ($datediff[0]>0) { - $mftime="00:00:01:"; + if ($datediff[0] > 0) { + $mftime = "00:00:01:"; } // remove cruft from malfunction text - $mfmalfunction=htmlentities($mfmalfunction); - $mfmalfunction=addslashes($mfmalfunction); - + $mfmalfunction = htmlentities($mfmalfunction); + $mfmalfunction = addslashes($mfmalfunction); + if ($mfauthorized) { - $partdatainput=array(); - if ($uid) $partdatainput['uid']=$uid; - if ($partnum) $partdatainput['partnum']=$partnum; - if ($sernum) $partdatainput['sernum']=$sernum; - $partinfo=get_part_data($partdatainput); + $partdatainput = array(); + if ($uid) $partdatainput['uid'] = $uid; + if ($partnum) $partdatainput['partnum'] = $partnum; + if ($sernum) $partdatainput['sernum'] = $sernum; + $partinfo = get_part_data($partdatainput); // add to parts table - if ($partinfo['result']==1) { + if ($partinfo['result'] == 1) { // if this part has not been seen before, add it to the parts table and get partid - mysqli_query($db,"insert into parts(uid,partnum,sernum,partname) values(\"$uid\",\"$partnum\",\"$sernum\",\"$partname\")"); - $mfpart=mysqli_insert_id($db); - } else if ($partinfo['result']==2) { - $pdatamismatch=1; + mysqli_query($db, "insert into parts(uid,partnum,sernum,partname) values(\"$uid\",\"$partnum\",\"$sernum\",\"$partname\")"); + $mfpart = mysqli_insert_id($db); + } else if ($partinfo['result'] == 2) { + $pdatamismatch = TRUE; } else { // if it is in parts table, get partid for this record - $mfpart=$partinfo['partid']; + $pdatamismatch = FALSE; + $mfpart = $partinfo['partid']; } - if ($uid =="" || $partnum == "" || $sernum == "") { + if ($uid == "" || $partnum == "" || $sernum == "") { // have the maintenance form stay pending due to incomplete part data - $pending=1; + $pending = 1; } else { - $pending=0; + $pending = 0; } - + // add the record to maintforms if (! $pdatamismatch) { - mysqli_query($db,"insert into maintforms(mfdate,mftime,mftech,mfpart,mfpartloc,mfmalfunction,nha,repord,lognoteid,pending) + $lognoteid = ($lognoteid == NULL) ? 0 : $lognoteid; + mysqli_query($db, "insert into maintforms(mfdate,mftime,mftech,mfpart,mfpartloc,mfmalfunction,nha,repord,lognoteid,pending) values (\"$mfdate\", \"$mftime\",\"$loggedinas\",\"$mfpart\",\"$mfpartloc\",\"$mfmalfunction\",\"$nha\",\"$repord\",\"$lognoteid\",\"$pending\")"); - $newmaintformid=mysqli_insert_id($db); - $mfidtoprint=$newmaintformid; + $newmaintformid = mysqli_insert_id($db); + $mfidtoprint = $newmaintformid; - // add this maintformid to the appropriate flag_tables - foreach ($flags as $flagtblnum) { - $flagtblname="flag_".$flagtblnum; - mysqli_query($db,"insert into $flagtblname(target,id) values(\"maintforms\",\"$newmaintformid\")"); + // update the flagmap table + foreach ($flags as $thisflag) { + // set flag for this maintenance form + mysqli_query($db, "insert into flagmap(flagid,maintformid) values(\"$thisflag\",\"$newmaintformid\")"); } } } @@ -187,78 +195,69 @@ if ($mfadd) { } } if ($mfedit) { - $mfidtoprint=$maintformid; + $mfidtoprint = $maintformid; if ($mfsubmit && $mfauthorized) { if ($mfmalfunction && ($uid || ($partnum && $sernum))) { // remove cruft from malfunction text - $mfmalfunction=htmlentities($mfmalfunction); - $mfmalfunction=addslashes($mfmalfunction); - + $mfmalfunction = htmlentities($mfmalfunction); + $mfmalfunction = addslashes($mfmalfunction); + // update parts table - if ($uid =="" || $partnum == "" || $sernum == "") { + if ($uid == "" || $partnum == "" || $sernum == "") { // have the maintenance form stay pending due to incomplete part data - $pending=1; + $pending = 1; } else { - $pending=0; + $pending = 0; } if (! $pdatamismatch) { - mysqli_query($db,"update parts set uid=\"$uid\", partnum=\"$partnum\", sernum=\"$sernum\", partname=\"$partname\" where partid=\"$mfpart\""); + mysqli_query($db, "update parts set uid=\"$uid\", partnum=\"$partnum\", sernum=\"$sernum\", partname=\"$partname\" where partid=\"$mfpart\""); } - + // update the record in maintforms if (! $pdatamismatch) { - mysqli_query($db,"update maintforms set mfdate=\"$mfdate\", mftime=\"$mftime\", mfpart=\"$mfpart\", mfpartloc=\"$mfpartloc\", + mysqli_query($db, "update maintforms set mfdate=\"$mfdate\", mftime=\"$mftime\", mfpart=\"$mfpart\", mfpartloc=\"$mfpartloc\", mfmalfunction=\"$mfmalfunction\", nha=\"$nha\", repord=\"$repord\", lognoteid=\"$lognoteid\", pending=\"$pending\" where maintformid=\"$maintformid\""); - // update the appropriate 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=\"maintforms\" and id=\"$maintformid\""))) { - mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"maintforms\",\"$maintformid\")"); - } - } else { - if(mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"maintforms\" and id=\"$maintformid\""))) { - mysqli_query($db,"delete from $thisflag_tbl where target=\"maintforms\" and id=\"$maintformid\""); - } - } + + // update the flagmap table + mysqli_query($db, "delete from flagmap where maintformid=\"$maintformid\""); + foreach ($flags as $thisflag) { + // set flag for this maintenance form + mysqli_query($db, "insert into flagmap(flagid,maintformid) values(\"$thisflag\",\"$maintformid\")"); } } } } // refresh the maintenance form in question from the database - $mftoedit=getmfdata($maintformid); + $mftoedit = getmfdata($maintformid); } if ($mfdelete && $mfauthorized) { // delete from maintforms table - mysqli_query($db,"delete from maintforms where maintformid=\"$maintformid\""); - // 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=\"maintforms\" and id=\"$maintformid\""); - } + mysqli_query($db, "delete from maintforms where maintformid=\"$maintformid\""); + // delete occurances from the flagmap table + mysqli_query($db, "delete from flagmap where maintformid=\"$maintformid\""); } if ($actionadd) { if ($actionaddsubmit) { if ($action) { + // sanitize and fix blank date and time + $actiondate = fix_date($actiondate); + $actiontime = fix_time($actiontime); // determine whether supplied date is future or past - $datediff=mysqli_fetch_row(mysqli_query($db,"select datediff(\"$actiondate\",CURRENT_DATE)")); + $datediff = mysqli_fetch_row(mysqli_query($db, "select datediff(\"$actiondate\",CURRENT_DATE)")); // if future, set time to 00:00:01, if past, set to 23:59:59 - if ($datediff[0]<0) { - $actiontime="23:59:59:"; + if ($datediff[0] < 0) { + $actiontime = "23:59:59:"; } - if ($datediff[0]>0) { - $actiontime="00:00:01:"; + if ($datediff[0] > 0) { + $actiontime = "00:00:01:"; } // remove cruft from action text - $action=htmlentities($action); - $action=addslashes($action); - + $action = htmlentities($action); + $action = addslashes($action); + // add to maintactions table - mysqli_query($db,"insert into maintactions (actiondate,actiontime,maintformnum,actiontech,action) + mysqli_query($db, "insert into maintactions (actiondate,actiontime,maintformnum,actiontech,action) values (\"$actiondate\",\"$actiontime\",\"$maintformid\",\"$loggedinas\",\"$action\")"); echo mysqli_error($db); } @@ -268,20 +267,23 @@ if ($actionadd) { if ($actionedit) { if ($actioneditsubmit && $actionauthorized) { // update the action + // sanitize and fix blank date and time + $actiondate = fix_date($actiondate); + $actiontime = fix_time($actiontime); // remove cruft from action text - $action=htmlentities($action); - $action=addslashes($action); - + $action = htmlentities($action); + $action = addslashes($action); + // update maintactions table - mysqli_query($db,"update maintactions set actiondate=\"$actiondate\", actiontime=\"$actiontime\", action=\"$action\" where maintactionid=\"$maintactionid\""); + mysqli_query($db, "update maintactions set actiondate=\"$actiondate\", actiontime=\"$actiontime\", action=\"$action\" where maintactionid=\"$maintactionid\""); } // refresh the action in question from the database - $actiontoedit=getactiondata($maintactionid); + $actiontoedit = getactiondata($maintactionid); } if ($actiondelete && $actionauthorized) { // delete the action - mysqli_query($db,"delete from maintactions where maintactionid=\"$maintactionid\""); + mysqli_query($db, "delete from maintactions where maintactionid=\"$maintactionid\""); } @@ -289,66 +291,67 @@ if ($actiondelete && $actionauthorized) { pagetable("begin"); if (!$print) { - pageblock("left","begin"); + pageblock("left", "begin"); sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); banner($print); // display the form if ($mfadd || $actionadd) { - $mfdate=$today; - $mftime=$now; - $actiondate=$today; - $actiontime=$now; + $mfdate = $today; + $mftime = $now; + $actiondate = $today; + $actiontime = $now; } if ($mfedit || $mfdelete || $actionadd || $actionedit || $actiondelete || $printfmt) { - $mfdate=$mftoedit["mfdate"]; - $mftime=$mftoedit["mftime"]; - $mfpart=$mftoedit["mfpart"]; - $mfpartloc=$mftoedit["mfpartloc"]; - $mfmalfunction=$mftoedit["mfmalfunction"]; - $nha=$mftoedit["nha"]; - $repord=$mftoedit["repord"]; - $lognoteid=$mftoedit["lognoteid"]; - if ($mfedit || $mfdelete || $actionadd || $actionedit || $actiondelete || $printfmt) $mftech=$mftoedit["mftech"]; - if (! $mftime) $mftime=$now; + $mfdate = $mftoedit["mfdate"]; + $mftime = $mftoedit["mftime"]; + $mfpart = $mftoedit["mfpart"]; + $mfpartloc = $mftoedit["mfpartloc"]; + $mfmalfunction = $mftoedit["mfmalfunction"]; + $nha = $mftoedit["nha"]; + $repord = $mftoedit["repord"]; + $lognoteid = $mftoedit["lognoteid"]; + if ($mfedit || $mfdelete || $actionadd || $actionedit || $actiondelete || $printfmt) $mftech = $mftoedit["mftech"]; + if (! $mftime) $mftime = $now; } if (($mfedit || $actionadd || $actionedit) && ! ($mfsubmit || $actionaddsubmit || $actioneditsubmit)) { - $partinfo=array(); - $partinfoinput['partid']=$mfpart; - $partinfo=get_part_data($partinfoinput); - $mfpart=$partinfo['partid']; - $uid=$partinfo['uid']; - $partnum=$partinfo['partnum']; - $sernum=$partinfo['sernum']; - $partname=$partinfo['partname']; - $pluresult=$partinfo['result']; - if ($pluresult==2) $pdatamismatch=1; else unset($pdatamismatch); + $partinfo = array(); + $partinfoinput['partid'] = $mfpart; + $partinfo = get_part_data($partinfoinput); + $mfpart = $partinfo['partid']; + $uid = $partinfo['uid']; + $partnum = $partinfo['partnum']; + $sernum = $partinfo['sernum']; + $partname = $partinfo['partname']; + $pluresult = $partinfo['result']; + if ($pluresult == 2) $pdatamismatch = TRUE; + else $pdatamismatch = FALSE; } -$techname=dblookup($db,"techs","techid","techname",$mftech); +$techname = dblookup($db, "techs", "techid", "techname", $mftech); if ($mfsubmit) { if ($mfmalfunction) { if (($uid || ($partnum && $sernum)) || $mfpart) { if ($mfadd) { - format_message(0,"Maintenance Form added. You may enter another one or return to Maintenance Forms page."); + format_message(0, "Maintenance Form added. You may enter another one or return to Maintenance Forms page."); } if ($mfedit) { - format_message(0,"Maintenance Form changed. Return to Maintenance Forms page."); + format_message(0, "Maintenance Form changed. Return to Maintenance Forms page."); } } else { - format_message(1,"You didn't enter any part information. Please try again."); + format_message(1, "You didn't enter any part information. Please try again."); } } else { - format_message(1,"You didn't enter any malfunction description. Please try again."); + format_message(1, "You didn't enter any malfunction description. Please try again."); } } if ($mfdelete) { - format_message(0,"Maintenance Form Deleted. Return to Maintenance Forms page."); + format_message(0, "Maintenance Form Deleted. Return to Maintenance Forms page."); } if ($pdatamismatch) { - $advtxt=" + $advtxt = "   Warning: The $uidtext doesn't match the Part Number/Serial Number associated with it in our database. Please ensure the part information @@ -356,7 +359,7 @@ if ($pdatamismatch) { the Parts page to correct the database. "; } else { - $advtxt=" + $advtxt = " You can enter a $uidtext or Part Number/Serial Number or both. "; } @@ -384,32 +387,34 @@ if ($printfmt) { Flags
%s %s %s%s $notetag
%s %s %s%s $notetag
%s %s %s%s $notetag
"; - // get an array of flagids set for this maintformid - $allflags=mysqli_query($db,"select flagid from flags"); + + // create an array called theseflags of flagids set for this maintformid + $allflags = mysqli_query($db, "select flagid from flags"); unset($theseflags); - while ($thisflag=mysqli_fetch_row($allflags)) { - $thisflagtbl="flag_".$thisflag[0]; - if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"maintforms\" and id=\"$maintformid\""))) { - $theseflags[]=$thisflag[0]; + $theseflags = []; + while ($thisflag = mysqli_fetch_row($allflags)) { + if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and maintformid=\"$maintformid\""))) { + $theseflags[] = $thisflag[0]; } } - $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']."  "; + // display flag symbols for set flags + $flagslist = mysqli_query($db, "select * from flags"); + while ($flagsymbol = mysqli_fetch_assoc($flagslist)) { + if ($theseflags[0] == "") $theseflags = []; + if (!empty($theseflags) && in_array($flagsymbol["flagid"], $theseflags)) { + echo $flagsymbol['flagsym'] . "  "; } } echo "

Maintenance Actions
"; - $maintactionqry=mysqli_query($db,"select * from maintactions where maintformnum=\"$maintformid\" order by actiondate asc, actiontime asc"); - while ($actiontable=mysqli_fetch_assoc($maintactionqry)) { - $actiondate=$actiontable["actiondate"]; - $actiontime=$actiontable["actiontime"]; - $tname=dblookup($db,"techs","techid","techname",$actiontable["actiontech"]); - $actiontext=convertweblinks($actiontable["action"]); + $maintactionqry = mysqli_query($db, "select * from maintactions where maintformnum=\"$maintformid\" order by actiondate asc, actiontime asc"); + while ($actiontable = mysqli_fetch_assoc($maintactionqry)) { + $actiondate = $actiontable["actiondate"]; + $actiontime = $actiontable["actiontime"]; + $tname = dblookup($db, "techs", "techid", "techname", $actiontable["actiontech"]); + $actiontext = convertweblinks($actiontable["action"]); // print the actions echo " @@ -470,41 +475,50 @@ if ($printfmt) {
"; - // get an array of flagids set for this maintformid - $allflags=mysqli_query($db,"select flagid from flags"); + // create an array called theseflags of flagids set for this maintformid + $allflags = mysqli_query($db, "select flagid from flags"); unset($theseflags); - $theseflags=[]; - while ($thisflag=mysqli_fetch_row($allflags)) { - $thisflagtbl="flag_".$thisflag[0]; - if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"maintforms\" and id=\"$maintformid\""))) { - $theseflags[]=$thisflag[0]; + $theseflags = []; + while ($thisflag = mysqli_fetch_row($allflags)) { + if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and maintformid=\"$maintformid\""))) { + $theseflags[] = $thisflag[0]; } } if ($mfadd) { - $flagslist=mysqli_query($db,"select * from flags where status=1"); + $flagslist = mysqli_query($db, "select * from flags where status=1"); } else { - $flagslist=mysqli_query($db,"select * from flags"); + $flagslist = mysqli_query($db, "select * from flags"); } - $flagsperline=8; - $flagcount=1; - while ($flagcheckbox=mysqli_fetch_assoc($flagslist)) { - if ($theseflags[0]=="") $theseflags=[]; - if (in_array($flagcheckbox["flagid"],$theseflags)) { - printf("%s", - $flagcheckbox["flagid"],$flagcheckbox["flagcolor"],$flagcheckbox["flagname"],$flagcheckbox["flagsym"]); + $flagsperline = 8; + $flagcount = 1; + while ($flagcheckbox = mysqli_fetch_assoc($flagslist)) { + //if ($theseflags[0]=="") $theseflags=[]; + if (in_array($flagcheckbox["flagid"], $theseflags)) { + printf( + "%s", + $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("%s", - $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( + "%s", + $flagcheckbox["flagid"], + $flagcheckbox["flagcolor"], + $flagcheckbox["flagname"], + $flagcheckbox["flagsym"] + ); } } - if ($flagcount<$flagsperline) { + if ($flagcount < $flagsperline) { echo "   "; $flagcount++; } else { echo "
"; - $flagcount=1; + $flagcount = 1; } } echo " @@ -551,7 +565,7 @@ if ($printfmt) {
"; } - + echo "
@@ -559,16 +573,16 @@ if ($printfmt) { if ($actionadd || $actionedit) { // show the action form if ($actionadd) { - $matime=$now; - $actiontext=""; - $actiontech=$loggedinas; + $matime = $now; + $actiontext = ""; + $actiontech = $loggedinas; } else if ($actionedit) { - $actiontext=$actiontoedit['action']; - $actiontech=$actiontoedit['actiontech']; - $actiondate=$actiontoedit['actiondate']; - $actiontime=$actiontoedit['actiontime']; + $actiontext = $actiontoedit['action']; + $actiontech = $actiontoedit['actiontech']; + $actiondate = $actiontoedit['actiondate']; + $actiontime = $actiontoedit['actiontime']; } - $tname=dblookup($db,"techs","techid","techname",$actiontech); + $tname = dblookup($db, "techs", "techid", "techname", $actiontech); echo " "; -$partqry=mysqli_query($db,"select * from parts order by $sort $order"); -while ($partline=mysqli_fetch_assoc($partqry)) { +$partqry = mysqli_query($db, "select * from parts order by $sort $order"); +while ($partline = mysqli_fetch_assoc($partqry)) { if (!$partline['uid']) { - $pluidtxt="none"; + $pluidtxt = "none"; } else { - $pluidtxt=$partline['uid']; + $pluidtxt = $partline['uid']; } if ($loggedin) { - printf(" + printf( + " ", - $partline['partid'],$pluidtxt, - $partline['partnum'], - $partline['sernum'], - $partline['partname'] + $partline['partid'], + $pluidtxt, + $partline['partnum'], + $partline['sernum'], + $partline['partname'] ); } else { - printf(" + printf( + " ", - $pluidtxt, - $partline['partnum'], - $partline['sernum'], - $partline['partname'] + $pluidtxt, + $partline['partnum'], + $partline['sernum'], + $partline['partname'] ); } echo " @@ -115,9 +118,7 @@ echo " echo "

"; banner($print); -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/profile.php b/distfiles/profile.php index c299f66..9954d63 100644 --- a/distfiles/profile.php +++ b/distfiles/profile.php @@ -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 */ @@ -10,133 +10,138 @@ include("functions.php"); if (!isset($_SESSION['login'])) { - header ("Location: login.php"); + header("Location: login.php"); } -$techid=$_SESSION['login'] ?? NULL; -$print=$_REQUEST['print'] ?? NULL; -$table=$_REQUEST['table'] ?? NULL; -$updateinfo=$_REQUEST['updateinfo'] ?? NULL; -$updatedisplay=$_REQUEST['updatedisplay'] ?? NULL; -$setcolor=$_REQUEST['setcolor'] ?? NULL; -$name=$_REQUEST['name'] ?? NULL; -$pass=$_REQUEST['pass'] ?? NULL; -$passconf=$_REQUEST['passconf'] ?? NULL; -$shift=$_REQUEST['shift'] ?? NULL; -$display_urlchunk=$_REQUEST['display_urlchunk'] ?? NULL; -$display_showts=$_REQUEST['display_showts'] ?? NULL; -$display_techalpha=$_REQUEST['display_techalpha'] ?? NULL; -$display_subjalpha=$_REQUEST['display_subjalpha'] ?? NULL; -$display_logstyle=$_REQUEST['display_logstyle'] ?? NULL; -$modcolor=$_REQUEST['modcolor'] ?? NULL; -$hexcolor=$_REQUEST['hexcolor'] ?? NULL; -$resetcustom=$_REQUEST["resetcustom"] ?? NULL; +$techid = $_SESSION['login'] ?? NULL; +$print = $_REQUEST['print'] ?? NULL; +$table = $_REQUEST['table'] ?? NULL; +$updateinfo = $_REQUEST['updateinfo'] ?? NULL; +$updatedisplay = $_REQUEST['updatedisplay'] ?? NULL; +$setcolor = $_REQUEST['setcolor'] ?? NULL; +$name = $_REQUEST['name'] ?? NULL; +$pass = $_REQUEST['pass'] ?? NULL; +$passconf = $_REQUEST['passconf'] ?? NULL; +$shift = $_REQUEST['shift'] ?? NULL; +$display_urlchunk = $_REQUEST['display_urlchunk'] ?? NULL; +$display_showts = $_REQUEST['display_showts'] ?? NULL; +$display_techalpha = $_REQUEST['display_techalpha'] ?? NULL; +$display_subjalpha = $_REQUEST['display_subjalpha'] ?? NULL; +$display_logstyle = $_REQUEST['display_logstyle'] ?? NULL; +$modcolor = $_REQUEST['modcolor'] ?? NULL; +$hexcolor = $_REQUEST['hexcolor'] ?? NULL; +$resetcustom = $_REQUEST["resetcustom"] ?? NULL; -$logname=LOG_NAME; +$logname = LOG_NAME; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } -framework("begin","$logname","My Profile",$print); +framework("begin", "$logname", "My Profile", $print); pagetable("begin"); -if(!$print){ - pageblock("left","begin"); - +if (!$print) { + pageblock("left", "begin"); + // ******** begin database manipulation ******** if ($updateinfo) { // name shift password settings // do error checking // test for name supplied if (strlen(trim($name))) { - $namesuppld=1; + $namesuppld = TRUE; } else { - $namesuppld=0; + $namesuppld = FALSE; echo " Tech name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select techid from techs where techname=\"$name\" and techid!=\"$techid\""))) { - if (mysqli_num_rows(mysqli_query($db,"select techid from techs where techname=\"$name\""))) { - $nameunique=0; + if (mysqli_num_rows(mysqli_query($db, "select techid from techs where techname=\"$name\" and techid!=\"$techid\""))) { + if (mysqli_num_rows(mysqli_query($db, "select techid from techs where techname=\"$name\""))) { + $nameunique = FALSE; echo " Tech name already exists.
"; } else { - $nameunique=1; + $nameunique = TRUE; } } else { - $nameunique=1; + $nameunique = TRUE; } // test for matching passwords - if ($pass!="password_is_unchanged") { - if ($pass==$passconf) { - $passmatch=1; - $passhash=password_hash($pass,PASSWORD_DEFAULT); - $namepassupdqry=("update techs set techname=\"$name\",techpass=\"$passhash\" where techid=\"$techid\""); + if ($pass != "password_is_unchanged") { + if ($pass == $passconf) { + $passmatch = TRUE; + $passhash = password_hash($pass, PASSWORD_DEFAULT); + $namepassupdqry = ("update techs set techname=\"$name\",techpass=\"$passhash\" where techid=\"$techid\""); } else { - $passmatch=0; + $passmatch = FALSE; echo " The passwords you supplied don't match.
"; } } else { - $passmatch=1; - $namepassupdqry="update techs set techname=\"$name\" where techid=\"$techid\""; + $passmatch = TRUE; + $namepassupdqry = "update techs set techname=\"$name\" where techid=\"$techid\""; } if ($namesuppld && $nameunique && $passmatch) { - mysqli_query($db,$namepassupdqry); - mysqli_query($db,"update techs set shift=\"$shift\" where techid=\"$techid\""); + mysqli_query($db, $namepassupdqry); + mysqli_query($db, "update techs set shift=\"$shift\" where techid=\"$techid\""); } } if ($updatedisplay) { // display settings - if ($display_showts) $display_showts=1; else $display_showts=0; - if ($display_techalpha=="a") $display_techalpha=1; else $display_techalpha=0; - if ($display_subjalpha=="a") $display_subjalpha=1; else $display_subjalpha=0; + if ($display_showts) $display_showts = 1; + else $display_showts = 0; + if ($display_techalpha == "a") $display_techalpha = 1; + else $display_techalpha = 0; + if ($display_subjalpha == "a") $display_subjalpha = 1; + else $display_subjalpha = 0; // test for urlchunk supplied if (strlen(trim($display_urlchunk))) { - $chunksuppld=1; + $chunksuppld = TRUE; } else { - $chunksuppld=0; + $chunksuppld = FALSE; echo " URL chunk size cannot be blank.
"; } if ($chunksuppld) { - putsetting('url_chunk_size',$display_urlchunk,$techid); - putsetting('show_ts',$display_showts,$techid); - putsetting('tech_alpha',$display_techalpha,$techid); - putsetting('subj_alpha',$display_subjalpha,$techid); - putsetting('log_style',$display_logstyle,$techid); + putsetting('url_chunk_size', $display_urlchunk, $techid); + putsetting('show_ts', $display_showts, $techid); + putsetting('tech_alpha', $display_techalpha, $techid); + putsetting('subj_alpha', $display_subjalpha, $techid); + putsetting('log_style', $display_logstyle, $techid); } } if ($setcolor) { // color settings - $hexcolor="#".ltrim($hexcolor); - putsetting($modcolor,$hexcolor,$techid); + $hexcolor = "#" . ltrim($hexcolor); + putsetting($modcolor, $hexcolor, $techid); + $currentpage = $_SERVER['PHP_SELF']; + header("Refresh: .1; url=$currentpage"); } - if ($resetcustom) mysqli_query($db,"delete from customs where customtech=\"$techid\""); - + if ($resetcustom) mysqli_query($db, "delete from customs where customtech=\"$techid\""); + sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); // pull my current data from tables -$curname=dblookup($db,"techs","techid","techname",$techid); -$curshift=dblookup($db,"techs","techid","shift",$techid); -$pass=$passconf="password_is_unchanged"; +$curname = dblookup($db, "techs", "techid", "techname", $techid); +$curshift = dblookup($db, "techs", "techid", "shift", $techid); +$pass = $passconf = "password_is_unchanged"; // other values from customs -$curlchunk=getsetting('url_chunk_size',$techid)["value"]; -$curts=getsetting('show_ts',$techid)["value"]; -$curtdo=getsetting('tech_alpha',$techid)["value"]; -$cursdo=getsetting('subj_alpha',$techid)["value"]; -$curbgc=getsetting('background_color',$techid)["value"]; -$cursbc=getsetting('sidebar_color',$techid)["value"]; -$curmbgc=getsetting('menubg_color',$techid)["value"]; -$curtc=getsetting('text_color',$techid)["value"]; -$curlc=getsetting('link_color',$techid)["value"]; -$curvlc=getsetting('vlink_color',$techid)["value"]; -$curhc=getsetting('heading_color',$techid)["value"]; -$curlogstyle=getsetting('log_style',$techid)["value"]; +$curlchunk = getsetting('url_chunk_size', $techid)["value"]; +$curts = getsetting('show_ts', $techid)["value"]; +$curtdo = getsetting('tech_alpha', $techid)["value"]; +$cursdo = getsetting('subj_alpha', $techid)["value"]; +$curbgc = getsetting('background_color', $techid)["value"]; +$cursbc = getsetting('sidebar_color', $techid)["value"]; +$curmbgc = getsetting('menubg_color', $techid)["value"]; +$curtc = getsetting('text_color', $techid)["value"]; +$curlc = getsetting('link_color', $techid)["value"]; +$curvlc = getsetting('vlink_color', $techid)["value"]; +$curhc = getsetting('heading_color', $techid)["value"]; +$curlogstyle = getsetting('log_style', $techid)["value"]; // show the form echo " @@ -149,19 +154,19 @@ Password:  

Need a random password?   "; -$rpw=substr(str_shuffle(password_hash(microtime(),PASSWORD_DEFAULT)), 10, 12); +$rpw = substr(str_shuffle(password_hash(microtime(), PASSWORD_DEFAULT)), 10, 12); echo "   $rpw

Shift:   "; -$logstyleqry=mysqli_query($db,"select styleid,stylename from styles where styletype=\"logdisplay\""); -while ($logstylerow=mysqli_fetch_assoc($logstyleqry)) { - if ($logstylerow["styleid"]==$curlogstyle) { - printf("",$logstylerow["styleid"],$logstylerow["stylename"]); +$logstyleqry = mysqli_query($db, "select styleid,stylename from styles where styletype=\"logdisplay\""); +while ($logstylerow = mysqli_fetch_assoc($logstyleqry)) { + if ($logstylerow["styleid"] == $curlogstyle) { + printf("", $logstylerow["styleid"], $logstylerow["stylename"]); } else { - printf("",$logstylerow["styleid"],$logstylerow["stylename"]); + printf("", $logstylerow["styleid"], $logstylerow["stylename"]); } } echo " @@ -236,7 +241,7 @@ echo "
My Color Preferences

"; -switch($modcolor) { +switch ($modcolor) { case "background_color": echo "
Tech:  $tname @@ -606,25 +620,25 @@ if ($printfmt) {

"; } - + echo "Maintenance Actions    "; if ($_SESSION['login'] && $maintformid) echo ""; echo "

"; - - - $maintactionqry=mysqli_query($db,"select * from maintactions where maintformnum=\"$maintformid\" order by actiondate asc, actiontime asc"); - while ($actiontable=mysqli_fetch_assoc($maintactionqry)) { - $maintactionid=$actiontable["maintactionid"]; - $actiondate=$actiontable["actiondate"]; - $actiontime=$actiontable["actiontime"]; - $maintformnum=$actiontable["maintformnum"]; - $tname=dblookup($db,"techs","techid","techname",$actiontable["actiontech"]); - $actiontext=convertweblinks($actiontable["action"]); + + + $maintactionqry = mysqli_query($db, "select * from maintactions where maintformnum=\"$maintformid\" order by actiondate asc, actiontime asc"); + while ($actiontable = mysqli_fetch_assoc($maintactionqry)) { + $maintactionid = $actiontable["maintactionid"]; + $actiondate = $actiontable["actiondate"]; + $actiontime = $actiontable["actiontime"]; + $maintformnum = $actiontable["maintformnum"]; + $tname = dblookup($db, "techs", "techid", "techname", $actiontable["actiontech"]); + $actiontext = convertweblinks($actiontable["action"]); // print the table echo "
"; - if (($loggedinas==$actiontable["actiontech"]) || $isadmin) { + if (($loggedinas == $actiontable["actiontech"]) || $isadmin) { echo " \"Edit   \"Delete @@ -647,16 +661,14 @@ if ($printfmt) {

"; } - + echo " "; } banner($print); -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/partentry.php b/distfiles/partentry.php index fdd1b94..5775dfd 100644 --- a/distfiles/partentry.php +++ b/distfiles/partentry.php @@ -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 */ @@ -11,39 +11,39 @@ include("functions.php"); if (!isset($_SESSION['login'])) { - header ("Location: login.php"); + header("Location: login.php"); } -$loggedinas=$_SESSION['login']; -$isadmin=dblookup($db,"techs","techid","admin",$loggedinas); +$loggedinas = $_SESSION['login']; +$isadmin = dblookup($db, "techs", "techid", "admin", $loggedinas); -$print=$_REQUEST['print']; -$add=$_REQUEST['add']; -$edit=$_REQUEST['edit']; -$delete=$_REQUEST['delete']; +$print = $_REQUEST['print'] ?? NULL; +$add = $_REQUEST['add'] ?? NULL; +$edit = $_REQUEST['edit'] ?? NULL; +$delete = $_REQUEST['delete'] ?? NULL; -$partid=$_REQUEST['partid']; -$uid=$_REQUEST['uid']; -$partnum=$_REQUEST['partnum']; -$sernum=$_REQUEST['sernum']; -$partname=$_REQUEST['partname']; -$submit=$_REQUEST['submit']; +$partid = $_REQUEST['partid'] ?? NULL; +$uid = $_REQUEST['uid'] ?? NULL; +$partnum = $_REQUEST['partnum'] ?? NULL; +$sernum = $_REQUEST['sernum'] ?? NULL; +$partname = $_REQUEST['partname'] ?? NULL; +$submit = $_REQUEST['submit'] ?? NULL; -$logname=LOG_NAME; -$uidtext=UID_TEXT; +$logname = LOG_NAME; +$uidtext = UID_TEXT; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } if ($edit || $delete) { - framework("begin","$logname","Part Edit",$print); + framework("begin", "$logname", "Part Edit", $print); } else { - $add=1; - framework("begin","$logname","Part Entry",$print); + $add = 1; + framework("begin", "$logname", "Part Entry", $print); } // ******** begin database manipulation ******** @@ -53,11 +53,11 @@ if ($add) { if ($submit) { // add the entry if submit is pressed if ($uid || ($partnum && $sernum)) { - $partexists=mysqli_num_rows(mysqli_query($db,"select partid from parts where uid=\"$uid\" or (partnum=\"$partnum\" and sernum=\"$sernum\")")); + $partexists = mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uid\" or (partnum=\"$partnum\" and sernum=\"$sernum\")")); if (! $partexists) { // add to parts table - mysqli_query($db,"insert into parts(uid,partnum,sernum,partname) values(\"$uid\",\"$partnum\",\"$sernum\",\"$partname\")"); - $partid=mysqli_insert_id($db); + mysqli_query($db, "insert into parts(uid,partnum,sernum,partname) values(\"$uid\",\"$partnum\",\"$sernum\",\"$partname\")"); + $partid = mysqli_insert_id($db); } } } @@ -66,18 +66,18 @@ if ($edit) { if ($submit) { if ($uid || ($partnum && $sernum)) { // update parts table - mysqli_query($db,"update parts set uid=\"$uid\", partnum=\"$partnum\", sernum=\"$sernum\", partname=\"$partname\" where partid=\"$partid\""); + mysqli_query($db, "update parts set uid=\"$uid\", partnum=\"$partnum\", sernum=\"$sernum\", partname=\"$partname\" where partid=\"$partid\""); } } } if ($delete) { // check for occurrence in logparts table - $inlogparts=mysqli_num_rows(mysqli_query($db,"select logpartid from logparts where partid=\"$partid\"")); + $inlogparts = mysqli_num_rows(mysqli_query($db, "select logpartid from logparts where partid=\"$partid\"")); // check for occurrence in maintforms table - $inmaintforms=mysqli_num_rows(mysqli_query($db,"select maintformid from maintforms where mfpart=\"$partid\"")); + $inmaintforms = mysqli_num_rows(mysqli_query($db, "select maintformid from maintforms where mfpart=\"$partid\"")); // delete from parts table - if(!$inlogparts && !$inmaintforms) { - mysqli_query($db,"delete from parts where partid=\"$partid\""); + if (!$inlogparts && !$inmaintforms) { + mysqli_query($db, "delete from parts where partid=\"$partid\""); } } @@ -85,24 +85,24 @@ if ($delete) { pagetable("begin"); if (!$print) { - pageblock("left","begin"); + pageblock("left", "begin"); sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); banner($print); // display the form -$partdatainput=array(); -$partdatainput['partid']=$partid; -$partinfo=get_part_data($partdatainput); -if ($partinfo['result']==2) { - $pdatamismatch=1; +$partdatainput = array(); +$partdatainput['partid'] = $partid; +$partinfo = get_part_data($partdatainput); +if ($partinfo['result'] == 2) { + $pdatamismatch = TRUE; } else { - unset($pdatamismatch); - if ($partinfo['uid']) $uid=$partinfo['uid']; - if ($partinfo['partnum']) $partnum=$partinfo['partnum']; - if ($partinfo['sernum']) $sernum=$partinfo['sernum']; - if ($partinfo['partname']) $partname=$partinfo['partname']; + $pdatamismatch = FALSE; + $uid = (array_key_exists('uid', $partinfo)) ? $partinfo['uid'] : NULL; + $partnum = (array_key_exists('partnum', $partinfo)) ? $partinfo['partnum'] : NULL; + $sernum = (array_key_exists('sernum', $partinfo)) ? $partinfo['sernum'] : NULL; + $partname = (array_key_exists('partname', $partinfo)) ? $partinfo['partname'] : NULL; } if ($delete) { if ($inmaintforms) { @@ -168,9 +168,7 @@ echo " "; banner($print); -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/parts.php b/distfiles/parts.php index 5dbcc08..606eac2 100644 --- a/distfiles/parts.php +++ b/distfiles/parts.php @@ -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 */ @@ -10,50 +10,50 @@ include("functions.php"); if (isset($_SESSION['login'])) { - $loggedin=1; + $loggedin = TRUE; } else { - unset($loggedin); + $loggedin = FALSE; } -$print=$_REQUEST['print']; -$add=$_REQUEST['add']; -$sort=$_REQUEST['sort']; -$order=$_REQUEST['order']; +$print = $_REQUEST['print'] ?? NULL; +$add = $_REQUEST['add'] ?? NULL; +$sort = $_REQUEST['sort'] ?? NULL; +$order = $_REQUEST['order'] ?? NULL; -$logname=LOG_NAME; -$uidtext=UID_TEXT; +$logname = LOG_NAME; +$uidtext = UID_TEXT; if ($add) { - header ("Location: partentry.php?add=1"); + header("Location: partentry.php?add=1"); } -if (! $sort) $sort="uid"; +if (! $sort) $sort = "uid"; if ($order == "asc") { - $order="desc"; + $order = "desc"; } else if ($order == "desc") { - $order="asc"; + $order = "asc"; } else { - $order="asc"; + $order = "asc"; } if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } -framework("begin","$logname","Parts",$print); +framework("begin", "$logname", "Parts", $print); pagetable("begin"); -if(!$print) { - pageblock("left","begin"); +if (!$print) { + pageblock("left", "begin"); sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); banner($print); if ($loggedin) { echo " @@ -71,15 +71,16 @@ echo "
Part Name
%s @@ -87,22 +88,24 @@ while ($partline=mysqli_fetch_assoc($partqry)) { %s %s %s
%s %s %s %s
", - $eventdata_eventid,$duedatestrg, - $devicedata_devicedesc,$devicedata_devicename, - $taskdata_taskdesc,$taskdata_taskname, - $lastdatestrg + $eventdata_eventid, + $duedatestrg, + $devicedata_devicedesc, + $devicedata_devicename, + $taskdata_taskdesc, + $taskdata_taskname, + $lastdatestrg ); } echo "
Page background color"; colorpicker("profile.php?setcolor=1&modcolor=background_color&hexcolor="); @@ -290,9 +295,7 @@ echo " "; -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/refchain.php b/distfiles/refchain.php index db77d8c..2826055 100644 --- a/distfiles/refchain.php +++ b/distfiles/refchain.php @@ -2,76 +2,77 @@ /* 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']; -$chainnote=$_REQUEST['chainnote']; +$print = $_REQUEST['print'] ?? ""; +$chainnote = $_REQUEST['chainnote'] ?? NULL; -$logname=LOG_NAME; +$logname = LOG_NAME; if ($print) { - $sbcolor=P_SIDEBAR_COLOR; - $mbgcolor=P_MENUBG_COLOR; + $sbcolor = P_SIDEBAR_COLOR; + $mbgcolor = P_MENUBG_COLOR; } else { - $sbcolor=SIDEBAR_COLOR; - $mbgcolor=MENUBG_COLOR; + $sbcolor = SIDEBAR_COLOR; + $mbgcolor = MENUBG_COLOR; } -framework("begin","$logname","Reference Chain Display",$print); +framework("begin", "$logname", "Reference Chain Display", $print); // ******** begin database manipulation ******** -$master=generate_chain($chainnote); +$master = generate_chain($chainnote); // ******** end database manipulation ******** pagetable("begin"); -if(!$print){ - pageblock("left","begin"); +if (!$print) { + pageblock("left", "begin"); sidemenu(); - pageblock("left","end"); + pageblock("left", "end"); } -pageblock("right","begin"); +pageblock("right", "begin"); banner($print); // display the chain -$mptr=0; +$mptr = 0; echo "

"; echo ""; -while($mptr\"Add    "; +while ($mptr < count($master)) { + if (mysqli_num_rows(mysqli_query($db, "select * from lognotes where lognoteid=$master[$mptr]"))) { + $tablerow = mysqli_fetch_assoc(mysqli_query($db, "select * from lognotes where lognoteid=$master[$mptr]")); + $noteid = $tablerow["lognoteid"]; + $urldatestr = "y=" . date("Y", strtotime($tablerow["date"])) . "&m=" . date("m", strtotime($tablerow["date"])) . "&d=" . date("d", strtotime($tablerow["date"])); + $refs = "  \"Add    "; // convert the shift number to a name - $shname=dblookup($db,"shifts","shiftid","shiftname",$tablerow["shift"]); + $shname = dblookup($db, "shifts", "shiftid", "shiftname", $tablerow["shift"]); // convert tech number to name - $tname=dblookup($db,"techs","techid","techname",$tablerow["tech"]); + $tname = dblookup($db, "techs", "techid", "techname", $tablerow["tech"]); //convert subject number to name - $subjname=dblookup($db,"subjects","subjectid","subjectname",$tablerow["subject"]); + $subjname = dblookup($db, "subjects", "subjectid", "subjectname", $tablerow["subject"]); // create links of urls in note - $fmtnote=convertweblinks($tablerow["lognote"]); + $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\""))) { - $flagparam=mysqli_fetch_assoc(mysqli_query($db,"select * from flags where flagid=\"$flagid\"")); - $flagcolor=$flagparam["flagcolor"]; - $flagsym=$flagparam["flagsym"]; - $flagstring=$flagstring."$flagsym  "; + $flagstring = ""; + $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 . "$flagsym  "; } } - if ($flagstring) $fmtnote=$fmtnote."
".$flagstring; - printf(" + + if ($flagstring) $fmtnote = $fmtnote . "
" . $flagstring; + printf( + "
@@ -81,23 +82,24 @@ while($mptr%s ", - $tablerow["lognoteid"],$tablerow["lognoteid"], - $tablerow["date"],$tablerow["time"], - $shname, - $tname, - $subjname, - $fmtnote, - $refs); + $tablerow["lognoteid"], + $tablerow["lognoteid"], + $tablerow["date"], + $tablerow["time"], + $shname, + $tname, + $subjname, + $fmtnote, + $refs + ); } else { - printf("\n",$master[$mptr]); + printf("\n", $master[$mptr]); } - $mptr=$mptr+1; + $mptr = $mptr + 1; } echo "
Note IDDate / TimeShiftTechSubjectNoteReferences
%s %s / %s%s
Note Id %s has been deleted and cannot be displayed.
Note Id %s has been deleted and cannot be displayed.


"; banner($print); -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/schedmaint.php b/distfiles/schedmaint.php index 62a983a..c5424d1 100644 --- a/distfiles/schedmaint.php +++ b/distfiles/schedmaint.php @@ -1,8 +1,8 @@  You didn't select a task.
"; + $taskselected = false; + $errorstack[] = " You didn't select a task.
"; } // check for device selected if ($device) { - $deviceselected=true; + $deviceselected = true; } else { - $deviceselected=false; - $errorstack[]=" You didn't select a device.
"; + $deviceselected = false; + $errorstack[] = " You didn't select a device.
"; } // sanitize text data - $start_date=mysqli_real_escape_string($db,$start_date); - $last_date=mysqli_real_escape_string($db,$last_date); - $deferred_date=mysqli_real_escape_string($db,$deferred_date); + if ($start_date == NULL) $start_date = $today; + if ($last_date == NULL) $last_date = "0001-01-01"; + if ($deferred_date == NULL) $deferred_date = "0001-01-01"; + $start_date = fix_date($start_date); + $last_date = fix_date($last_date); + $deferred_date = fix_date($deferred_date); if ($taskselected && $deviceselected) { // determine if device represents a group and break out individual devices - if (dblookup($db,"devices","deviceid","group_flag",$device)) { - $memberqry=mysqli_query($db,"select memberdevice from devicegroups where groupdevice=\"$device\""); - $memberlist=array(); - while ($memberrow=mysqli_fetch_row($memberqry)) { - $memberlist[]=$memberrow[0]; + if (dblookup($db, "devices", "deviceid", "group_flag", $device)) { + $memberqry = mysqli_query($db, "select memberdevice from devicegroups where groupdevice=\"$device\""); + $memberlist = array(); + while ($memberrow = mysqli_fetch_row($memberqry)) { + $memberlist[] = $memberrow[0]; } } else { - $memberlist=array($device); + $memberlist = array($device); } // 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) + $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); + mysqli_query($db, $addqry); } } } @@ -139,54 +140,54 @@ if ($add) { // do error checking // test for name supplied if (strlen(trim($taskname))) { - $namesuppld=true; + $namesuppld = true; } else { - $namesuppld=false; - $errorstack[]=" Task name cannot be blank.
"; + $namesuppld = false; + $errorstack[] = " Task name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select taskid from tasks where taskname=\"$taskname\""))) { - $nameunique=false; - $errorstack[]=" Task name already exists.
"; + if (mysqli_num_rows(mysqli_query($db, "select taskid from tasks where taskname=\"$taskname\""))) { + $nameunique = false; + $errorstack[] = " Task name already exists.
"; } else { - $nameunique=true; + $nameunique = true; } // sanitize text data - $taskname=mysqli_real_escape_string($db,$taskname); - $taskdesc=mysqli_real_escape_string($db,$taskdesc); - $refdoc_name=mysqli_real_escape_string($db,$refdoc_name); - $refdoc_url=mysqli_real_escape_string($db,$refdoc_url); - + $taskname = mysqli_real_escape_string($db, $taskname); + $taskdesc = mysqli_real_escape_string($db, $taskdesc); + $refdoc_name = mysqli_real_escape_string($db, $refdoc_name); + $refdoc_url = mysqli_real_escape_string($db, $refdoc_url); + if ($namesuppld && $nameunique) { // modify the table - $addqry=("insert into tasks(taskname,taskdesc,frequency,period,weekdays_only,nextdue_relative,refdoc_name,refdoc_url,active_flag) + $addqry = ("insert into tasks(taskname,taskdesc,frequency,period,weekdays_only,nextdue_relative,refdoc_name,refdoc_url,active_flag) values(\"$taskname\",\"$taskdesc\",\"$frequency\",\"$period\",\"$weekdays_only\",\"$nextdue_relative\",\"$refdoc_name\",\"$refdoc_url\",\"$active_flag\")"); - mysqli_query($db,$addqry); + mysqli_query($db, $addqry); } } if ($devices) { // do error checking // test for name supplied if (strlen(trim($devicename))) { - $namesuppld=true; + $namesuppld = true; } else { - $namesuppld=false; - $errorstack[]=" Device name cannot be blank.
"; + $namesuppld = false; + $errorstack[] = " Device name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select deviceid from devices where devicename=\"$devicename\""))) { - $nameunique=false; - $errorstack[]=" Device name already exists.
"; + if (mysqli_num_rows(mysqli_query($db, "select deviceid from devices where devicename=\"$devicename\""))) { + $nameunique = false; + $errorstack[] = " Device name already exists.
"; } else { - $nameunique=true; + $nameunique = true; } // sanitize name and description - $devicename=mysqli_real_escape_string($db,$devicename); - $devicedesc=mysqli_real_escape_string($db,$devicedesc); + $devicename = mysqli_real_escape_string($db, $devicename); + $devicedesc = mysqli_real_escape_string($db, $devicedesc); if ($namesuppld && $nameunique) { // modify the table - $addqry=("insert into devices(devicename,devicedesc,group_flag,active_flag) values(\"$devicename\",\"$devicedesc\",\"$group_flag\",\"$active_flag\")"); - mysqli_query($db,$addqry); + $addqry = ("insert into devices(devicename,devicedesc,group_flag,active_flag) values(\"$devicename\",\"$devicedesc\",\"$group_flag\",\"$active_flag\")"); + mysqli_query($db, $addqry); } } } @@ -194,19 +195,19 @@ if ($edit) { if ($schedule) { if ($delete) { // delete entity - mysqli_query($db,"delete from events where eventid=\"$id\""); + mysqli_query($db, "delete from events where eventid=\"$id\""); } if ($update) { // do error checking // sanitize text data - $start_date=mysqli_real_escape_string($db,$start_date); - $last_date=mysqli_real_escape_string($db,$last_date); - $deferred_date=mysqli_real_escape_string($db,$deferred_date); + if ($start_date == NULL) $start_date = $today; + if ($last_date == NULL) $last_date = "0001-01-01"; + if ($deferred_date == NULL) $deferred_date = "0001-01-01"; + $start_date = fix_date($start_date); + $last_date = fix_date($last_date); + $deferred_date = fix_date($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 + 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\" where eventid=\"$id\""); @@ -215,45 +216,45 @@ if ($edit) { if ($tasks) { if ($delete) { // check for scheduled maintenance for this entity - if (mysqli_num_rows(mysqli_query($db,"select eventid from events where task=\"$id\""))) { - $hasevents=true; - $errorstack[]=" Task has been scheduled maintenance and cannot be deleted.
"; + if (mysqli_num_rows(mysqli_query($db, "select eventid from events where task=\"$id\""))) { + $hasevents = true; + $errorstack[] = " Task has been scheduled maintenance and cannot be deleted.
"; } else { - $hasevents=false; + $hasevents = false; } if (!$hasevents) { // delete entity - mysqli_query($db,"delete from tasks where taskid=\"$id\""); + mysqli_query($db, "delete from tasks where taskid=\"$id\""); } } if ($update) { // do error checking // test for name supplied if (strlen(trim($taskname))) { - $namesuppld=true; + $namesuppld = true; } else { - $namesuppld=false; - $errorstack[]=" Task name cannot be blank.
"; + $namesuppld = false; + $errorstack[] = " Task name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select taskid from tasks where taskname=\"$taskname\" and taskid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select taskid from tasks where taskname=\"$taskname\""))) { - $nameunique=false; - $errorstack[]=" Task name already exists.
"; + if (mysqli_num_rows(mysqli_query($db, "select taskid from tasks where taskname=\"$taskname\" and taskid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select taskid from tasks where taskname=\"$taskname\""))) { + $nameunique = false; + $errorstack[] = " Task name already exists.
"; } else { - $nameunique=true; + $nameunique = true; } } else { - $nameunique=true; + $nameunique = true; } // sanitize text data - $taskname=mysqli_real_escape_string($db,$taskname); - $taskdesc=mysqli_real_escape_string($db,$taskdesc); - $refdoc_name=mysqli_real_escape_string($db,$refdoc_name); - $refdoc_url=mysqli_real_escape_string($db,$refdoc_url); + $taskname = mysqli_real_escape_string($db, $taskname); + $taskdesc = mysqli_real_escape_string($db, $taskdesc); + $refdoc_name = mysqli_real_escape_string($db, $refdoc_name); + $refdoc_url = mysqli_real_escape_string($db, $refdoc_url); if ($namesuppld && $nameunique) { // update the tasks table - mysqli_query($db,"update tasks + mysqli_query($db, "update tasks set taskname=\"$taskname\",taskdesc=\"$taskdesc\",frequency=\"$frequency\",period=\"$period\",weekdays_only=\"$weekdays_only\", nextdue_relative=\"$nextdue_relative\",refdoc_name=\"$refdoc_name\",refdoc_url=\"$refdoc_url\",active_flag=\"$active_flag\" where taskid=\"$id\""); @@ -263,48 +264,48 @@ if ($edit) { if ($devices) { if ($delete) { // check for scheduled maintenance for this device - if (mysqli_num_rows(mysqli_query($db,"select eventid from events where device=\"$id\""))) { - $hasevents=true; - $errorstack[]=" Device has scheduled maintenance and cannot be deleted.
"; + if (mysqli_num_rows(mysqli_query($db, "select eventid from events where device=\"$id\""))) { + $hasevents = true; + $errorstack[] = " Device has scheduled maintenance and cannot be deleted.
"; } else { - $hasevents=false; + $hasevents = false; } if (!$hasevents) { // delete entity - mysqli_query($db,"delete from devices where deviceid=\"$id\""); + mysqli_query($db, "delete from devices where deviceid=\"$id\""); } } if ($update) { // do error checking // test for name supplied if (strlen(trim($devicename))) { - $namesuppld=true; + $namesuppld = true; } else { - $namesuppld=false; - $errorstack[]=" Device name cannot be blank.
"; + $namesuppld = false; + $errorstack[] = " Device name cannot be blank.
"; } // test for name unique - if (mysqli_num_rows(mysqli_query($db,"select deviceid from devices where devicename=\"$devicename\" and deviceid!=\"$id\""))) { - if (mysqli_num_rows(mysqli_query($db,"select deviceid from devices where devicename=\"$devicename\""))) { - $nameunique=false; - $errorstack[]=" Device name already exists.
"; + if (mysqli_num_rows(mysqli_query($db, "select deviceid from devices where devicename=\"$devicename\" and deviceid!=\"$id\""))) { + if (mysqli_num_rows(mysqli_query($db, "select deviceid from devices where devicename=\"$devicename\""))) { + $nameunique = false; + $errorstack[] = " Device name already exists.
"; } else { - $nameunique=true; + $nameunique = true; } } else { - $nameunique=true; + $nameunique = true; } // sanitize name and description - $devicename=mysqli_real_escape_string($db,$devicename); - $devicedesc=mysqli_real_escape_string($db,$devicedesc); + $devicename = mysqli_real_escape_string($db, $devicename); + $devicedesc = mysqli_real_escape_string($db, $devicedesc); if ($namesuppld && $nameunique) { // update the devices table - mysqli_query($db,"update devices set devicename=\"$devicename\",devicedesc=\"$devicedesc\",group_flag=\"$group_flag\",active_flag=\"$active_flag\" where deviceid=\"$id\""); + mysqli_query($db, "update devices set devicename=\"$devicename\",devicedesc=\"$devicedesc\",group_flag=\"$group_flag\",active_flag=\"$active_flag\" where deviceid=\"$id\""); // update the devicegroups table - mysqli_query($db,"delete from devicegroups where groupdevice=\"$id\""); + mysqli_query($db, "delete from devicegroups where groupdevice=\"$id\""); if ($group_flag) { foreach ($members as $member) { - mysqli_query($db,"insert into devicegroups(groupdevice,memberdevice) values(\"$id\",\"$member\")"); + mysqli_query($db, "insert into devicegroups(groupdevice,memberdevice) values(\"$id\",\"$member\")"); } } } @@ -314,17 +315,17 @@ if ($edit) { // **** END DATABASE OPERATIONS **** -framework("begin","$logname","Scheduled Maintenance",$print); +framework("begin", "$logname", "Scheduled Maintenance", $print); //var_dump($_REQUEST); pagetable("begin"); -pageblock("left","begin"); +pageblock("left", "begin"); sidemenu(); -pageblock("left","end"); +pageblock("left", "end"); -pageblock("right","begin"); +pageblock("right", "begin"); banner($print); if ($loggedin) { echo " @@ -340,17 +341,17 @@ if ($loggedin) { } // display any errors from database operations if (count($errorstack)) { - foreach($errorstack as $errorline) { + foreach ($errorstack as $errorline) { echo "$errorline
"; } } if ($action) { // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from events where eventid=$id")); + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from events where eventid=$id")); extract($currentvalues); - $taskname=dblookup($db,"tasks","taskid","taskname",$task); - $devicename=dblookup($db,"devices","deviceid","devicename",$device); + $taskname = dblookup($db, "tasks", "taskid", "taskname", $task); + $devicename = dblookup($db, "devices", "deviceid", "devicename", $device); // display form to complete or defer echo "
Task :   $taskname Device :   $devicename
@@ -383,46 +384,46 @@ if ($action) { // manage maintenance schedule if ($edit) { // set form options for editing - $sectiontitle="Modify Event

"; - $formtag="
"; - $buttontags=" + $sectiontitle = "Modify Event

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from events where eventid=$id")); + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from events where eventid=$id")); extract($currentvalues); if ($active_flag) { - $activetag=""; + $activetag = ""; } else { - $activetag=""; + $activetag = ""; } if ($deferred_flag) { - $deferredtag=""; + $deferredtag = ""; } else { - $deferredtag=""; + $deferredtag = ""; } - 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=$tomorrow; - $deferuntiltag=""; - $startdatetag=""; - $lastdatetag=""; + if ($start_date == "0001-01-01") $start_date = $today; + //if ($last_date == "0001-01-01") $last_date = ""; + if ($deferred_date == "0001-01-01") $deferred_date = $tomorrow; + $deferuntiltag = ""; + $startdatetag = ""; + $lastdatetag = ""; } else { // set form options for add - $sectiontitle="Add Scheduled Maintenance

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Add Scheduled Maintenance

"; + $formtag = ""; + $buttontags = " "; // set default values - $deferredtag=""; - $deferuntiltag=""; - $activetag=""; - $startdatetag=""; - $lastdatetag=""; + $deferredtag = ""; + $deferuntiltag = ""; + $activetag = ""; + $startdatetag = ""; + $lastdatetag = ""; } // display form echo " @@ -434,13 +435,13 @@ if ($action) {
Task:  Device:   "; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { + while ($tablerow = mysqli_fetch_assoc($existingdata)) { extract($tablerow); - 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 ($start_date == "0001-01-01") $start_date = $today; + if ($last_date == "0001-01-01") $last_date = ""; + if ($deferred_date == "0001-01-01") $deferred_date = ""; if ($active_flag) { - $statdef="\"active\""; + $statdef = "\"active\""; } else { - $statdef="\"inactive\""; + $statdef = "\"inactive\""; } if ($deferred_flag) { - $deferredflag="\"deferred\""; + $deferredflag = "\"deferred\""; } else { - $deferredflag="\"not"; + $deferredflag = "\"not"; } - $taskdata=mysqli_fetch_assoc(mysqli_query($db,"select * from tasks where taskid=\"$task\"")); - extract($taskdata,EXTR_PREFIX_ALL,"taskdata"); - $devicedata=mysqli_fetch_assoc(mysqli_query($db,"select * from devices where deviceid=\"$device\"")); - extract($devicedata,EXTR_PREFIX_ALL,"devicedata"); - if ($taskdata_period=="once") { - $tasktitle="One-time event"; + $taskdata = mysqli_fetch_assoc(mysqli_query($db, "select * from tasks where taskid=\"$task\"")); + extract($taskdata, EXTR_PREFIX_ALL, "taskdata"); + $devicedata = mysqli_fetch_assoc(mysqli_query($db, "select * from devices where deviceid=\"$device\"")); + extract($devicedata, EXTR_PREFIX_ALL, "devicedata"); + if ($taskdata_period == "once") { + $tasktitle = "One-time event"; } else { - $tasktitle="Repeat every $taskdata_frequency $taskdata_period"; + $tasktitle = "Repeat every $taskdata_frequency $taskdata_period"; } - printf(" + printf( + " @@ -520,60 +522,63 @@ if ($action) { ", - $eventid,$eventid, - $tasktitle,$taskdata_taskname, - $devicedata_devicename, - $start_date, - $last_date, - $deferredflag, - $deferred_date, - $statdef); + $eventid, + $eventid, + $tasktitle, + $taskdata_taskname, + $devicedata_devicename, + $start_date, + $last_date, + $deferredflag, + $deferred_date, + $statdef + ); } echo "
Event IDTaskDeviceStart DateLast
Completed
DeferredDeferred
Until
Active
%s %s%s %s
"; } else if ($tasks) { // manage tasks if ($edit) { // set form options for editing - $sectiontitle="Modify Task

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Modify Task

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from tasks where taskid=$id")); + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from tasks where taskid=$id")); extract($currentvalues); - $perioddef=$period; + $perioddef = $period; if ($active_flag) { - $activetag=""; + $activetag = ""; } else { - $activetag=""; + $activetag = ""; } if ($weekdays_only) { - $wdotag=""; + $wdotag = ""; } else { - $wdotag=""; + $wdotag = ""; } if ($nextdue_relative) { - $nextduetag="Absolute   Relative"; + $nextduetag = "Absolute   Relative"; } else { - $nextduetag="Absolute   Relative"; + $nextduetag = "Absolute   Relative"; } } else { // set form options for add - $sectiontitle="Add New Task

"; - $formtag=""; - $perioddef="once"; - $frequency=1; - $buttontags=" + $sectiontitle = "Add New Task

"; + $formtag = ""; + $perioddef = "once"; + $frequency = 1; + $buttontags = " "; // set default values - $wdotag=""; - $nextduetag="Absolute   Relative"; - $activetag=""; + $wdotag = ""; + $nextduetag = "Absolute   Relative"; + $activetag = ""; } // display form echo " @@ -590,10 +595,10 @@ if ($action) { Repeat every:     "; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { + while ($tablerow = mysqli_fetch_assoc($existingdata)) { extract($tablerow); if ($active_flag) { - $statdef="\"active\""; + $statdef = "\"active\""; } else { - $statdef="\"inactive\""; + $statdef = "\"inactive\""; } - if ($period=="once") { - $rptstrg="one time only"; + if ($period == "once") { + $rptstrg = "one time only"; } else { - $rptstrg="$frequency $period"; + $rptstrg = "$frequency $period"; } - + if ($nextdue_relative) { - $duecalc="Relative"; + $duecalc = "Relative"; } else { - $duecalc="Absolute"; + $duecalc = "Absolute"; } if ($refdoc_name) { - $refstrg="$refdoc_name"; + $refstrg = "$refdoc_name"; if ($refdoc_url) { - $refstrg="$refdoc_name"; + $refstrg = "$refdoc_name"; } } else { - $refstrg=""; + $refstrg = ""; } if ($weekdays_only) { - $wdoflag="\"active\""; + $wdoflag = "\"active\""; } else { - $wdoflag="\"inactive\""; + $wdoflag = "\"inactive\""; } - printf(" + printf( + " @@ -660,54 +666,55 @@ if ($action) { ", - $taskid,$taskname, - $taskdesc, - $rptstrg, - $duecalc, - $wdoflag, - $refstrg, - $statdef); + $taskid, + $taskname, + $taskdesc, + $rptstrg, + $duecalc, + $wdoflag, + $refstrg, + $statdef + ); } echo "
Task NameTask DescriptionRepeat EveryDue Date
Calculation
Weekdays
Only
ReferenceActive
%s %s%s %s
"; - } else if ($devices) { // manage devices if ($edit) { // set form options for editing - $sectiontitle="Modify Device

"; - $formtag=""; - $buttontags=" + $sectiontitle = "Modify Device

"; + $formtag = ""; + $buttontags = "          
"; // pull current values from database - $currentvalues=mysqli_fetch_assoc(mysqli_query($db,"select * from devices where deviceid=$id")); + $currentvalues = mysqli_fetch_assoc(mysqli_query($db, "select * from devices where deviceid=$id")); extract($currentvalues); if ($group_flag) { - $showgrouptable=true; - $grouptag=""; + $showgrouptable = true; + $grouptag = ""; } else { - $showgrouptable=false; - $grouptag=""; + $showgrouptable = false; + $grouptag = ""; } if ($active_flag) { - $activetag=""; + $activetag = ""; } else { - $activetag=""; + $activetag = ""; } } else { // set form options for add - $sectiontitle="Add New Device

"; - $formtag=""; - $showgrouptable=false; - $buttontags=" + $sectiontitle = "Add New Device

"; + $formtag = ""; + $showgrouptable = false; + $buttontags = " "; // set default values - $activetag=""; - $grouptag=""; + $activetag = ""; + $grouptag = ""; } // display form echo " @@ -722,28 +729,30 @@ if ($action) { Device represents a group of devices:  $grouptag

"; if ($showgrouptable) { - $existingdevs=mysqli_query($db,"select * from devices where deviceid!=$id and active_flag=\"1\""); + $existingdevs = mysqli_query($db, "select * from devices where deviceid!=$id and active_flag=\"1\""); echo " Existing members of this group

"; - while ($grouprow=mysqli_fetch_assoc($existingdevs)) { - extract($grouprow,EXTR_PREFIX_ALL,"gtbl"); - if (mysqli_num_rows(mysqli_query($db,"select groupid from devicegroups where memberdevice=$gtbl_deviceid and groupdevice=$id"))) { - $memberdef=""; + while ($grouprow = mysqli_fetch_assoc($existingdevs)) { + extract($grouprow, EXTR_PREFIX_ALL, "gtbl"); + if (mysqli_num_rows(mysqli_query($db, "select groupid from devicegroups where memberdevice=$gtbl_deviceid and groupdevice=$id"))) { + $memberdef = ""; } else { - $memberdef=""; + $memberdef = ""; } - printf(" + printf( + " ", - $gtbl_devicename, - $gtbl_devicedesc, - $memberdef); + $gtbl_devicename, + $gtbl_devicedesc, + $memberdef + ); } echo "
Device NameDevice DescriptionMember
%s %s %s

"; } @@ -756,25 +765,26 @@ if ($action) {

"; // show table of current devices - $existingdata=mysqli_query($db,"select * from devices"); + $existingdata = mysqli_query($db, "select * from devices"); echo " Existing Devices   Click on the Device ID to edit.

"; - while ($tablerow=mysqli_fetch_assoc($existingdata)) { + while ($tablerow = mysqli_fetch_assoc($existingdata)) { extract($tablerow); if ($group_flag) { - $groupdef="\"This"; + $groupdef = "\"This"; } else { - $groupdef="\"This"; + $groupdef = "\"This"; } if ($active_flag) { - $statdef="\"active\""; + $statdef = "\"active\""; } else { - $statdef="\"inactive\""; + $statdef = "\"inactive\""; } - printf(" + printf( + " @@ -782,20 +792,25 @@ if ($action) { ", - $deviceid,$deviceid, - $devicename, - $devicedesc, - $groupdef, - $statdef); + $deviceid, + $deviceid, + $devicename, + $devicedesc, + $groupdef, + $statdef + ); } echo "
Device IDDevice NameDevice DescriptionGroupActive
%s %s%s %s
"; } else { - $ucevents=get_upcoming_events(); - + $ucevents = get_upcoming_events(); + // sort the upcoming events - function uc_cmp($a,$b) { return strcmp($a["duedate"], $b["duedate"]); } - uasort($ucevents,'uc_cmp'); - + function uc_cmp($a, $b) + { + return strcmp($a["duedate"], $b["duedate"]); + } + uasort($ucevents, 'uc_cmp'); + // show upcoming events table echo " Upcoming Scheduled Maintenance

@@ -806,55 +821,59 @@ if ($action) { "; foreach ($ucevents as $ucline) { extract($ucline); - printf(" + printf( + "
%s %s %s %s



"; - + // build array of deferred events - $defeventsqry=mysqli_query($db,"select * from events where active_flag=\"1\" and deferred_flag=\"1\" and deferred_date > \"$today\" order by deferred_date asc"); - $defevents=array(); - while ($defeventrow=mysqli_fetch_assoc($defeventsqry)) { + $defeventsqry = mysqli_query($db, "select * from events where active_flag=\"1\" and deferred_flag=\"1\" and deferred_date > \"$today\" order by deferred_date asc"); + $defevents = array(); + while ($defeventrow = mysqli_fetch_assoc($defeventsqry)) { // provide eventid,task,device,start_date,last_date,deferred_flag,deferred_date,active_flag - extract($defeventrow,EXTR_PREFIX_ALL,"def"); + extract($defeventrow, EXTR_PREFIX_ALL, "def"); // provide deviceid,devicename,devicedesc,group_flag,active_flag - $devicedata=mysqli_fetch_assoc(mysqli_query($db,"select * from devices where deviceid=\"$def_device\"")); - extract($devicedata,EXTR_PREFIX_ALL,"devicedata"); + $devicedata = mysqli_fetch_assoc(mysqli_query($db, "select * from devices where deviceid=\"$def_device\"")); + extract($devicedata, EXTR_PREFIX_ALL, "devicedata"); // provide taskid,taskname,taskdesc,frequency,period,weekdays_only,nextdue_relative,refdoc_name,refdoc_url,active_flag - $taskdata=mysqli_fetch_assoc(mysqli_query($db,"select * from tasks where taskid=\"$def_task\"")); - extract($taskdata,EXTR_PREFIX_ALL,"taskdata"); - if ( ! ($taskdata_period == "once" && $def_last_date > $def_start_date)) { - if ($def_last_date=="0000-00-00") { - $lastdatestrg="never"; + $taskdata = mysqli_fetch_assoc(mysqli_query($db, "select * from tasks where taskid=\"$def_task\"")); + extract($taskdata, EXTR_PREFIX_ALL, "taskdata"); + if (! ($taskdata_period == "once" && $def_last_date > $def_start_date)) { + if ($def_last_date == "0001-01-01") { + $lastdatestrg = "never"; } else { - $lastdatestrg="$def_last_date"; + $lastdatestrg = "$def_last_date"; } - $defeventline=array( - 'def_eventid'=>$def_eventid, - 'def_deferred_date'=>$def_deferred_date, - 'devicedata_devicedesc'=>$devicedata_devicedesc, - 'devicedata_devicename'=>$devicedata_devicename, - 'taskdata_taskdesc'=>$taskdata_taskdesc, - 'taskdata_taskname'=>$taskdata_taskname, - 'lastdatestrg'=>$lastdatestrg + $defeventline = array( + 'def_eventid' => $def_eventid, + 'def_deferred_date' => $def_deferred_date, + 'devicedata_devicedesc' => $devicedata_devicedesc, + 'devicedata_devicename' => $devicedata_devicename, + 'taskdata_taskdesc' => $taskdata_taskdesc, + 'taskdata_taskname' => $taskdata_taskname, + 'lastdatestrg' => $lastdatestrg ); - $defevents[]=$defeventline; + $defevents[] = $defeventline; } } - + // show deferred events table echo " Deferred Scheduled Maintenance

@@ -865,17 +884,21 @@ if ($action) { "; foreach ($defevents as $defline) { extract($defline); - printf(" + printf( + "
%s %s %s %s
"; while ($logtablerow = mysqli_fetch_assoc($logrowqry)) { - $logrefs="    \"Add"; + $logrefs = "    \"Add"; if (islink($logtablerow['lognoteid'])) { - $logrefs=$logrefs."      \"View"; + $logrefs = $logrefs . "      \"View"; } // convert the shift number to a name - $logshname=dblookup($db,"shifts","shiftid","shiftname",$logtablerow['shift']); + $logshname = dblookup($db, "shifts", "shiftid", "shiftname", $logtablerow['shift']); // convert tech number to name - $logtname=dblookup($db,"techs","techid","techname",$logtablerow['tech']); + $logtname = dblookup($db, "techs", "techid", "techname", $logtablerow['tech']); //convert subject number to name - $logsubjname=dblookup($db,"subjects","subjectid","subjectname",$logtablerow['subject']); + $logsubjname = dblookup($db, "subjects", "subjectid", "subjectname", $logtablerow['subject']); // create links of urls in note - $logfmtnote=convertweblinks($logtablerow['lognote']); + $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."$flagsym  "; - } + $flagstring = ""; + $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 . "$flagsym  "; } - if ($flagstring) $logfmtnote=$logfmtnote."
".$flagstring; - printf(" + if ($flagstring) { + $logfmtnote = $logfmtnote . "
" . $flagstring . "     "; + } else { + $logfmtnote = $logfmtnote . "
"; + } + + printf( + " @@ -679,25 +738,29 @@ if ($search) { ", - $logtablerow['lognoteid'],$logtablerow['lognoteid'], - $logtablerow['date'],$logtablerow['time'], - $logshname, - $logtname, - $logsubjname, - $logfmtnote, - $logrefs); + $logtablerow['lognoteid'], + $logtablerow['lognoteid'], + $logtablerow['date'], + $logtablerow['time'], + $logshname, + $logtname, + $logsubjname, + $logfmtnote, + $logrefs + ); } echo "
Note IDDate/TimeShiftTechSubjectNoteReferences
%s %s / %s %s%s %s


"; } else { echo "No Logbook notes match your search criteria.

"; } } - if ($target[0]=="") $target=[]; - if (in_array("maintform",$target)) { + if ($target[0] == "") $target = []; + if (in_array("maintform", $target)) { // run maintforms query and show results - if(mysqli_num_rows($mfrowqry)) { + $mf_num_results = mysqli_num_rows($mfrowqry); + if ($mf_num_results) { echo " - Results from Maintenance Forms

+ Results from Maintenance Forms: $mf_num_results


@@ -712,25 +775,25 @@ if ($search) { "; while ($mfrow = mysqli_fetch_assoc($mfrowqry)) { // look up part data - $mfuid=dblookup($db,"parts","partid","uid",$mfrow["mfpart"]); - if ($mfuid=="") $mfuid=" "; - $mfpartno=dblookup($db,"parts","partid","partnum",$mfrow["mfpart"]); - if ($mfpartno=="") $mfpartno=" "; - $mfserno=dblookup($db,"parts","partid","sernum",$mfrow["mfpart"]); - if ($mfserno=="") $mfserno=" "; - $mfpartname=dblookup($db,"parts","partid","partname",$mfrow["mfpart"]); - if ($mfpartname=="") $mfpartname=" "; + $mfuid = dblookup($db, "parts", "partid", "uid", $mfrow["mfpart"]); + if ($mfuid == "") $mfuid = " "; + $mfpartno = dblookup($db, "parts", "partid", "partnum", $mfrow["mfpart"]); + if ($mfpartno == "") $mfpartno = " "; + $mfserno = dblookup($db, "parts", "partid", "sernum", $mfrow["mfpart"]); + if ($mfserno == "") $mfserno = " "; + $mfpartname = dblookup($db, "parts", "partid", "partname", $mfrow["mfpart"]); + if ($mfpartname == "") $mfpartname = " "; // look up tech name - $mftname=dblookup($db,"techs","techid","techname",$mfrow["mftech"]); - if ($mfrow["lognoteid"]==0) { - $mfnoteidval=" "; - $mfnotetag="%s%s"; + $mftname = dblookup($db, "techs", "techid", "techname", $mfrow["mftech"]); + if ($mfrow["lognoteid"] == 0) { + $mfnoteidval = " "; + $mfnotetag = "%s%s"; } else { - $mfnoteidval=$mfrow["lognoteid"]; - $mfnotetag="%s"; + $mfnoteidval = $mfrow["lognoteid"]; + $mfnotetag = "%s"; } printf( - " + " @@ -740,14 +803,16 @@ if ($search) { ", - $mfrow["maintformid"],$mfrow["maintformid"], - $mfrow["mfdate"], - $mftname, - $mfuid, - $mfpartno, - $mfserno, - $mfpartname, - $mfnoteidval,$mfnoteidval + $mfrow["maintformid"], + $mfrow["maintformid"], + $mfrow["mfdate"], + $mftname, + $mfuid, + $mfpartno, + $mfserno, + $mfpartname, + $mfnoteidval, + $mfnoteidval ); } echo "
ID
%s %s %s%s $mfnotetag


"; @@ -755,24 +820,26 @@ if ($search) { echo "No Maintenance Forms match your search criteria.

"; } } - if ($target[0]=="") $target=[]; - if (in_array("part",$target)) { + if ($target[0] == "") $target = []; + if (in_array("part", $target)) { // run parts query and show results - if(mysqli_num_rows($prowqry)) { + $p_num_results = mysqli_num_rows($prowqry); + if ($p_num_results) { echo " - Results from Parts

+ Results from Parts: $p_num_results

- - - - + + + + "; - while ($partrow=mysqli_fetch_assoc($prowqry)) { + while ($partrow = mysqli_fetch_assoc($prowqry)) { if ($loggedin) { - printf(" + printf( + " ", - $partrow['partid'], - $partrow['uid'], - $partrow['partnum'], - $partrow['sernum'], - $partrow['partname'] + $partrow['partid'], + $partrow['uid'], + $partrow['partnum'], + $partrow['sernum'], + $partrow['partname'] ); } else { - printf(" + printf( + " ", - $partrow['uid'], - $partrow['partnum'], - $partrow['sernum'], - $partrow['partname'] + $partrow['uid'], + $partrow['partnum'], + $partrow['sernum'], + $partrow['partname'] ); } echo " @@ -817,9 +885,7 @@ if ($search) { } banner($print); -pageblock("right","end"); +pageblock("right", "end"); pagetable("end"); -framework("end","","",$print); - -?> +framework("end", "", "", $print); diff --git a/distfiles/settings.php b/distfiles/settings.php index a538c53..7a3b616 100644 --- a/distfiles/settings.php +++ b/distfiles/settings.php @@ -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 */ @@ -11,55 +11,53 @@ $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)); +$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') { - $sdir=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"win_server_session_dir\""))[0]; + $sdir = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"win_server_session_dir\""))[0]; } else { - $sdir=mysqli_fetch_row(mysqli_query($db,"select confvalue from configs where confname=\"unix_server_session_dir\""))[0]; + $sdir = mysqli_fetch_row(mysqli_query($db, "select confvalue from configs where confname=\"unix_server_session_dir\""))[0]; } -$lifetime=60 * 60 * 24 * $sttl; +$lifetime = 60 * 60 * 24 * $sttl; if (!is_dir($sdir)) mkdir($sdir, 0700, true); ini_set('session.cookie_lifetime', $lifetime); ini_set('session.gc_maxlifetime', $lifetime); ini_set('session.save_path', $sdir); -$ss=session_status(); -if ($ss==PHP_SESSION_NONE) session_start(); +$ss = session_status(); +if ($ss == PHP_SESSION_NONE) session_start(); // get config options from database and assign them to constants unset($techid); if (isset($_SESSION['login']) && $_SESSION['login'] != '') { - $techid=$_SESSION['login']; + $techid = $_SESSION['login']; } -$configqry=mysqli_query($db,"select confname,confvalue,confid from configs"); +$configqry = mysqli_query($db, "select confname,confvalue,confid from configs"); while ($configrow = mysqli_fetch_assoc($configqry)) { - $constname=strtoupper($configrow["confname"]); + $constname = strtoupper($configrow["confname"]); if (isset($techid)) { - $confid=$configrow["confid"]; - $custqry=mysqli_query($db,"select customconfvalue from customs where customconfnum=\"$confid\" and customtech=\"$techid\""); + $confid = $configrow["confid"]; + $custqry = mysqli_query($db, "select customconfvalue from customs where customconfnum=\"$confid\" and customtech=\"$techid\""); if (mysqli_num_rows($custqry)) { - $custrow=mysqli_fetch_row($custqry); - $custval=$custrow[0]; + $custrow = mysqli_fetch_row($custqry); + $custval = $custrow[0]; } else { unset($custval); } } if (isset($custval)) { - $constvalue=$custval; + $constvalue = $custval; } else { - $constvalue=$configrow["confvalue"]; + $constvalue = $configrow["confvalue"]; } - define("$constname","$constvalue"); + define("$constname", "$constvalue"); } // error reporting -$logerrors=LOG_ERRORS; -if ($logerrors==1) { +$logerrors = LOG_ERRORS; +if ($logerrors == 1) { error_reporting(E_ALL); } else { error_reporting(0); } - -?> diff --git a/distfiles/templates.php b/distfiles/templates.php new file mode 100644 index 0000000..4b56ca0 --- /dev/null +++ b/distfiles/templates.php @@ -0,0 +1,571 @@ +"; + if ($hastemplates) { + // print the user header + if ($user == "0") { + echo "Global Templates"; + } else { + if ($user == $techid) { + echo "My templates"; + } else { + echo "Templates for $tblusername"; + } + } + // print the table + echo "
Action$uidtextPart NumberSerial NumberPart Name$uidtextPart NumberSerial NumberPart Name
\"Edit @@ -781,14 +848,15 @@ if ($search) { %s %s %s
\"You @@ -797,10 +865,10 @@ if ($search) { %s %s %s
"; + echo ""; + while ($tablerow = mysqli_fetch_assoc($templatequery)) { + $templateid = $tablerow["templateid"]; + $templatename = $tablerow["templatename"]; + // convert shift number to name + $shiftname = dblookup($db, "shifts", "shiftid", "shiftname", $tablerow["shift"]); + // convert subject number to name + $subjname = dblookup($db, "subjects", "subjectid", "subjectname", $tablerow["subject"]); + // create links of urls in note + $fmtnote = convertweblinks($tablerow["lognote"]); + // generate the flags string + $flagstring = ""; + $flagqry = mysqli_query($db, "select flagid from flagmap where notetemplateid=$templateid"); + while ($flagid = mysqli_fetch_row($flagqry)) { + $flagparams = mysqli_fetch_assoc(mysqli_query($db, "select * from flags where flagid=\"$flagid[0]\"")); + $flagcolor = $flagparams["flagcolor"]; + $flagsym = $flagparams["flagsym"]; + $flagname = $flagparams["flagname"]; + $flagstring = $flagstring . "$flagsym  "; + } + if ($flagstring) { + $fmtnote = $fmtnote . "
" . $flagstring . "     "; + } else { + $fmtnote = $fmtnote . "
"; + } + // generate a reference string + $refstring = NULL; + $refstringqry = mysqli_query($db, "select target from reflinks where templateid=\"$templateid\""); + while ($tgt = mysqli_fetch_row($refstringqry)) { + $refstring = $refstring . " " . $tgt[0]; + } + // now print the line in the table + if (!$isadmin && $user == "0") { + $nameblock = "$templatename"; + } else { + $nameblock = "$templatename"; + } + printf( + " + + + + + + \n", + $nameblock, + $shiftname, + $subjname, + $fmtnote, + $refstring + ); + }; + echo "
Template NameShiftSubjectNoteReferences
%s %s%s%s%s



"; + } else { + if ($user == "0") { + echo "There are no global templates"; + } else { + if ($user == $techid) { + echo "You have no templates"; + } else { + echo "$tblusername has no templates"; + } + } + echo "

"; + } + echo "
"; +} + +// ******** begin database manipulation ******** + +if ($usertemplateid) { + $templateid = $usertemplateid; +} else if ($globaltemplateid) { + $templateid = $globaltemplateid; +} else { + $loadtemplate = NULL; +} + +// determine original owner of template +$orig_owner = dblookup($db, "notetemplates", "templateid", "tech", $templateid); +if ($efftechid != NULL && $efftechid != $orig_owner) { + $operation = "add"; +} + +if ($operation == "add") { + if ($submit) { + if ($note) { + // remove cruft from note text + $note = strip_tags($note, ""); + $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, ""); + $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, "Template created."); + } + 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, "Template modified."); + } + 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, "Template deleted."); + } +} + +if ($operation == "delete") { + // just show the link back to the templates page + echo " +
Manage templates



+ "; +} else if ($operation == "add" || $operation == "edit") { + // Display the input form + if ($loadtemplate) { + // make templateid the selected template + if ($usertemplateid) { + $templateid = $usertemplateid; + } else if ($globaltemplateid) { + $templateid = $globaltemplateid; + } else { + $templateid = NULL; + } + } + if ($operation == "edit" || $loadtemplate) { + // use values from the templateid supplied with a defined tech id + $loadeddata = mysqli_fetch_assoc(mysqli_query($db, "select * from notetemplates where templateid=\"$templateid\"")); + $filltemplatename = $loadeddata["templatename"]; + if ($efftechid) { + $filltech = $efftechid; + } else if ($isadmin && $loadeddata["tech"] == "0") { + $filltech = "0"; + } else { + $filltech = $techid; + } + $fillshift = $loadeddata["shift"]; + $fillsubject = $loadeddata["subject"]; + $fillnote = $loadeddata["lognote"]; + } else { + // use empty values with a defined tech id + $filltemplatename = NULL; + if ($efftechid) { + $filltech = $efftechid; + } else { + $filltech = $techid; + } + $fillshift = $defaultshift; + $fillsubject = NULL; + $fillnote = NULL; + } + + if ($operation == "add") $optext = "Creating new"; + if ($operation == "edit") $optext = "Editing"; + echo " +
$optext template

+ "; + + // show the template selection line + templateselect($techid, $operation); + + // start template entry section + echo " + + + + "; + if ($isadmin) { + echo " + + "; + } else { + $authorized = TRUE; + echo " + + "; + } + echo " + + + +
Template Name:   +
Tech:   +
Shift:   + Subject:   +
+ + Note: 
+
+   +   + Insert Link
+ "; + + // 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( + "%s", + $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( + "%s", + $flagcheckbox["flagid"], + $flagcheckbox["flagcolor"], + $flagcheckbox["flagname"], + $flagcheckbox["flagsym"] + ); + } + } + if ($flagcount < $flagsperline) { + echo "   "; + $flagcount++; + } else { + echo "
"; + $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 " +

References:   +          +                       + "; + + if ($operation == "add" && $authorized) { + echo " + + + "; + } + if ($operation == "edit" && $authorized) { + echo " + + + +      

+ Deleted templates are irretrievable! + "; + } + + echo " + +
+ "; +} else { + echo "
Create or copy a template

"; + + // Show my user template table + templatetable($db, $techid, $techid); + + // Show global template table + templatetable($db, $techid, "0"); + + if ($isadmin) { + // Show template tables for other users + $techqry = mysqli_query($db, "select techid from techs where techid != $techid and techid != 0"); + while ($techtblrow = (mysqli_fetch_row($techqry))) { + templatetable($db, $techid, $techtblrow[0]); + } + } +} + + +banner($print); +pageblock("right", "end"); +pagetable("end"); + +framework("end", "", "", $print); diff --git a/files-update.sh b/files-update.sh index de5086f..962ad47 100755 --- a/files-update.sh +++ b/files-update.sh @@ -41,8 +41,3 @@ fi # ---------- version 5.2.4.4 ----------- # No changes # -------------------------------------- - -# ---------- version 5.2.5 ------------- -# No changes -# -------------------------------------- - diff --git a/install.sh b/install.sh index 46fe055..8020cf3 100755 --- a/install.sh +++ b/install.sh @@ -2,17 +2,16 @@ # install.sh # OpenLog Online Logbook -# Copyright (C) 2025 Rod Wright +# Copyright (C) 2026 Rod Wright # SPDX-License-Identifier: GPL-2.0 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" @@ -22,7 +21,7 @@ CONFIG_DEFAULT_COLUMN="" function privilege_check() { # test for superuser rights - if [[ $EUID -ne 0 ]]; then + if [[ "$EUID" != 0 ]]; then echo "This script must be run with superuser privileges. Try sudo $0" exit 1 fi @@ -37,11 +36,11 @@ function get_new_password() { echo "" read -p "Re-type new password: " -s -r rnewpw echo "" - if [ "$newpassword" = "" -o "$rnewpw" = "" ] + if [[ "$newpassword" == "" || "$rnewpw" == "" ]] then echo "Password cannot be blank. Please try again." echo "" - elif [ "$newpassword" != "$rnewpw" ] + elif [[ "$newpassword" != "$rnewpw" ]] then echo "Passwords do not match. Please try again." echo "" @@ -64,7 +63,7 @@ function install_required_packages() { gpattern="" for pkg_option in $(echo $prereq) do - if [ "$pkg_option" != "or" ] + if [[ "$pkg_option" != "or" ]] then gpattern+=" -e $pkg_option" preferred_pkg=$pkg_option @@ -77,7 +76,7 @@ function install_required_packages() { echo "$APP_NAME requires $prereq, but it doesn't seem to be installed. " echo -n "Install $preferred_pkg now? [Y/n]: " read reqinstall - if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ] + if [[ "$reqinstall" == "N" || "$reqinstall" == "n" ]] then echo "$APP_NAME requires $prereq, but you have elected not to install it." echo "Installation cannot continue." @@ -173,20 +172,20 @@ echo "" echo -n "Enter name of $APP_NAME installation directory [$INSTALL_LOC] :" read install_loc_in echo "" -if [ "$doc_root_in" = "" ] +if [[ "$doc_root_in" == "" ]] then doc_root_in=$DOC_ROOT fi -if [ "$install_loc_in" = "" ] +if [[ "$install_loc_in" == "" ]] then install_loc_in=$INSTALL_LOC fi install_path="$doc_root_in/$install_loc_in" -if [ -d "$install_path" ] +if [[ -d "$install_path" ]] then echo "The installation path you chose already exists." # Install path exists. - if [ -e "$install_path/db.php" ] + if [[ -e "$install_path/db.php" ]] then # A db.php file was found in the install path if grep -q -e "$APP_NAME" $install_path/db.php @@ -196,13 +195,47 @@ then echo "and restart the install using a new installation location." echo -n "[U]pgrade or [C]ancel? [U] :" read upgrade_choice - if [[ $upgrade_choice == "C" || $upgrade_choice == "c" ]] # Cancel chosen + if [[ "$upgrade_choice" == "C" || "$upgrade_choice" == "c" ]] # Cancel chosen then echo "Cancelling installation" abort_exit else # proceed with upgrade - mkdir -p backups + # put app in maintenance mode + echo "Putting the application in maintenance mode..." + # make sure mod_rewrite is enabled + if [[ ! -e "$APACHE_CONF_DIR/../mods-enabled/rewrite.load" ]] + then + a2enmod -q rewrite + systemctl restart apache2 + fi + # disable the app + a2disconf -q $install_loc_in + systemctl reload apache2 + # modify the apache conf file + if ! grep -q "RewriteEngine" "$APACHE_CONF_DIR/$install_loc_in.conf" + then + # this is an old version of the conf file. Replace with new version + cp -f default-apache.conf $APACHE_CONF_DIR/$install_loc_in.conf + sed -i "s|_APPNAME_|$APP_NAME|g" $APACHE_CONF_DIR/$install_loc_in.conf + sed -i "s|_BASEURL_|$install_loc_in|g" $APACHE_CONF_DIR/$install_loc_in.conf + sed -i "s|_DOCROOTIN_|$doc_root_in|g" $APACHE_CONF_DIR/$install_loc_in.conf + fi + sed -i "s|#Rewrite|Rewrite|g" $APACHE_CONF_DIR/$install_loc_in.conf + # copy in the default maintenancemode.php if it's not already there + if [[ ! -e "$install_path/maintenancemode.php" ]] + then + cp maintenancemode.php $install_path/ + # modify the maintenancemode.php file + sed -i "s|_APPNAME_|$APP_NAME|g" $install_path/maintenancemode.php + fi + # re-enable the app in maintenance mode + a2enconf -q $install_loc_in + systemctl reload apache2 + + 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) @@ -216,28 +249,24 @@ then 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." - 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 + # delete all existing installation files except db.php and maintenancemode.php + find $install_path/ -mindepth 1 ! \( -name 'db.php' -o -name 'maintenancemode.php' \) -delete - echo "Performing database updates. This may take a while..." + echo "Performing database updates..." # 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 + mysql --defaults-extra-file=$mysql_opt_file --force < database-update.sql >/dev/null 2>&1 # apply database updates via script - (bash ./database-update.sh $mysql_opt_file) & - task_pid=$! - spinner $task_pid + bash ./database-update.sh $mysql_opt_file echo "... finished with database updates." rm -f $mysql_opt_file @@ -249,12 +278,12 @@ then echo "Installing distribution . . ." cp -R distfiles/* $install_path # set symlink for jquery-ui - if [ ! -L "$install_path/jquery-ui" ] + if [[ ! -L "$install_path/jquery-ui" ]] then ln -s $install_path/jquery-ui* $install_path/jquery-ui fi # set symlink for index.php - if [ ! -L "$install_path/index.php" ] + if [[ ! -L "$install_path/index.php" ]] then ln -s $install_path/$LANDING_PAGE $install_path/index.php fi @@ -267,6 +296,19 @@ 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." + + # take app out of maintenance mode + echo "Taking the app out of maintenance mode..." + # disable the app + a2disconf -q $install_loc_in + systemctl reload apache2 + # modify the apache conf file + sed -i "s|Rewrite|#Rewrite|g" $APACHE_CONF_DIR/$install_loc_in.conf + # re-enable the app in production mode + a2enconf -q $install_loc_in + systemctl reload apache2 fi else # This was a mistake. Exit now to avoid clobbering another app. @@ -284,11 +326,11 @@ then 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" ]] + 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" ]] + if [[ "$proceed" == "Q" || "$proceed" == "q" ]] then abort_exit fi @@ -303,7 +345,7 @@ else echo "This can be changed later in the application itself." echo -n "Installation name [$APP_NAME]: " read new_inst_name - if [ "$new_inst_name" = "" ] + if [[ "$new_inst_name" == "" ]] then new_inst_name="$APP_NAME" fi @@ -320,7 +362,7 @@ else echo "distinctive name." echo -n "database name [$DEFAULT_DB_NAME]: " read new_db_name - if [ "$new_db_name" = "" ] + if [[ "$new_db_name" == "" ]] then new_db_name=$DEFAULT_DB_NAME fi @@ -333,7 +375,7 @@ else echo "This probably means the database already exists." echo -n "Try again with a different database name? [Y/N]: " read dbcreatetry - if [ "$dbcreatetry" != "Y" -o "$dbcreatetry" != "y" ] + if [[ "$dbcreatetry" != "Y" || "$dbcreatetry" != "y" ]] then abort_exit fi @@ -353,7 +395,7 @@ else # Set the installation name export MYSQL_PWD="$db_pass" mysql -u"$db_user" $new_db_name -e "update $CONFIG_TABLE set $CONFIG_VALUE_COLUMN=\"$new_inst_name\" where $CONFIG_NAME_COLUMN=\"log_name\"" - if [ "$CONFIG_DEFAULT_COLUMN" != "" ] + if [[ "$CONFIG_DEFAULT_COLUMN" != "" ]] then mysql -u"$db_user" $new_db_name -e "update $CONFIG_TABLE set $CONFIG_DEFAULT_COLUMN=\"$new_inst_name\" where $CONFIG_NAME_COLUMN=\"log_name\"" fi @@ -362,23 +404,29 @@ else mkdir $install_path # Create db.php if it doesn't exist - if [ ! -f "$install_path/db.php" ] + if [[ ! -f "$install_path/db.php" ]] then cp db.php.template $install_path/db.php - sed -i "s/DBNAME/$new_db_name/g" $install_path/db.php - sed -i "s/DBUSER/$db_user/g" $install_path/db.php - sed -i "s/DBPASS/$db_pass/g" $install_path/db.php - sed -i "s/APPNAME/$APP_NAME/g" $install_path/db.php + sed -i "s|DBNAME|$new_db_name|g" $install_path/db.php + sed -i "s|DBUSER|$db_user|g" $install_path/db.php + sed -i "s|DBPASS|$db_pass|g" $install_path/db.php + sed -i "s|APPNAME|$APP_NAME|g" $install_path/db.php + fi + # Create maintenancemode.php if it doesn't exist + if [[ ! -f "$install_path/maintenancemode.php" ]] + then + cp maintenancemode.php $install_path/maintenancemode.php + sed -i "s|_APPNAME_|$APP_NAME|g" $install_path/maintenancemode.php fi # copy distribution to install location echo "Installing distribution . . ." cp -R distfiles/* $install_path - if [ ! -L "$install_path/jquery-ui" ] + if [[ ! -L "$install_path/jquery-ui" ]] then ln -s $install_path/jquery-ui* $install_path/jquery-ui fi - if [ ! -L "$install_path/index.php" ] + if [[ ! -L "$install_path/index.php" ]] then ln -s $install_path/$LANDING_PAGE $install_path/index.php fi @@ -401,23 +449,24 @@ echo "" echo "" echo "$APP_NAME has been $operation." base_url=$install_loc_in -if [ "$operation" = "installed" ] +if [[ "$operation" == "upgraded" ]] then - echo "# $APP_NAME default Apache configuration" > $APACHE_CONF_DIR/$base_url.conf - echo "" >> $APACHE_CONF_DIR/$base_url.conf - echo "Alias /$base_url $doc_root_in/$base_url" >> $APACHE_CONF_DIR/$base_url.conf - echo "" >> $APACHE_CONF_DIR/$base_url.conf - echo "" >> $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 "" >> $APACHE_CONF_DIR/$base_url.conf + a2enconf -q $base_url + systemctl reload apache2 +fi +if [[ "$operation" == "installed" ]] +then + cp -f default-apache.conf $APACHE_CONF_DIR/$base_url.conf + sed -i "s|_APPNAME_|$APP_NAME|g" $APACHE_CONF_DIR/$base_url.conf + sed -i "s|_BASEURL_|$base_url|g" $APACHE_CONF_DIR/$base_url.conf + sed -i "s|_DOCROOTIN_|$doc_root_in|g" $APACHE_CONF_DIR/$base_url.conf + echo -n "The apache2 $base_url configuration must be enabled. Would you like to do that now? [Y/n] :" read enconf - if [ "$enconf" = "" -o "$enconf" = "Y" -o "$enconf" = "y" ] + if [[ "$enconf" == "" || "$enconf" == "Y" || "$enconf" == "y" ]] then - a2enconf $base_url.conf >/dev/null - service apache2 reload + a2enconf -q $base_url.conf >/dev/null + systemctl reload apache2 echo "You can now point a web browser to $base_url on your web server " echo "to set up and configure $APP_NAME." echo "" diff --git a/maintenancemode.php b/maintenancemode.php new file mode 100644 index 0000000..f5db8ce --- /dev/null +++ b/maintenancemode.php @@ -0,0 +1,26 @@ + + +_APPNAME_ + + + +



+_APPNAME_ is currently down for maintenance. Please try again later. +

+ + +"; + +?> \ No newline at end of file