Compare commits
8 Commits
v1.1.2-dev
...
1.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 89f7506fa7 | |||
| 4d95710f43 | |||
| eb8829af47 | |||
| 09155561f8 | |||
| 2bddfba99a | |||
| f7b91f4ef0 | |||
| 6e5c6e03e3 | |||
| 3667c4358f |
94
CHANGELOG
94
CHANGELOG
@@ -1,5 +1,5 @@
|
||||
OpenDRS - Online Discrepancy Reporting System
|
||||
Copyright (C) 2018 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -70,3 +70,95 @@ Changelog
|
||||
ownership of the installed server directory tree if the http
|
||||
user and group names were left at the default.
|
||||
- Updated and tested to support Raspberry Pi 4B hardware.
|
||||
|
||||
1.2.0 - 2021-05-05
|
||||
- Added ability to customize the terminology used for Device,
|
||||
Period, and Effective/Non-effective to make OpenDRS usable in
|
||||
a wider range of applications.
|
||||
|
||||
1.3.0 - 2022-03-05
|
||||
- Made several improvements to group functionality. The Writeup Groups
|
||||
page now displays all groups in a table instead of individually
|
||||
expandable sections. On the View Writeups and View Open Writeups
|
||||
pages, if a writeup is a member of only one group, clicking the
|
||||
icon will take you to the page for that group. If a writeup is
|
||||
a member of multiple groups, clicking the icon will take you to
|
||||
the detail page for that writeup where you can view or modify which
|
||||
groups the writeup is a member of. On the Search page, you can
|
||||
now choose which group(s) the results should include.
|
||||
- Made some improvements to the installation process for Raspberry Pi
|
||||
setup to accomodate the latest version of Raspberry Pi OS.
|
||||
- If setting up as a Raspberry Pi terminal/server, included the option
|
||||
to make the terminal a wireless access point if it connects to an
|
||||
ethernet network.
|
||||
|
||||
1.3.1 - 2022-05-11
|
||||
- Updated installation scripts and instructions to reflect changes in
|
||||
Raspberry Pi OS Release 2022-04-04.
|
||||
|
||||
1.3.2 - 2022-08-08
|
||||
- Fixed typo in dbadmin.php that prevented adding new When Discovered
|
||||
items.
|
||||
- Fixed bug in create.php that prevented the page from working.
|
||||
- Fixed bug in config.php that prevented banners from being modified.
|
||||
- Fixed bug where action_by and action_reason were not preselected for
|
||||
subsequent searches in search.php.
|
||||
- Fixed bug in about.php and gpl.php that still used old $mts_db
|
||||
database handle.
|
||||
- Removed the server session directory option in config.php
|
||||
Miscellaneous settings. For this to make sense, you'd have to have
|
||||
shell access to the server and if that's the case, you'd be able
|
||||
to make the necessary database changes as well.
|
||||
- Fixed opendrs-initial.sql to make the default banner colors match
|
||||
the ones in common.php.
|
||||
- Created changelog.php for use by the "changes" link on the About
|
||||
page so kiosk terminal users don't get dead-ended in the CHANGELOG
|
||||
text file with no way to get back to the app.
|
||||
- Extensive code cleanups/updates in all php files to make application
|
||||
compatible with php8 and eliminate php warnings in apache2 error
|
||||
log file.
|
||||
- For Raspberry Pi:
|
||||
- Updated server-setup.sh to attempt to install the php-mysqli package
|
||||
for compatibility with php8.
|
||||
- Chromium browser will use the printer designated as the local
|
||||
default if it is selected as such in the Cups printer
|
||||
configuration.
|
||||
|
||||
1.3.3 - 2023-10-03
|
||||
- Restricted the ability to change the report date and time when
|
||||
creating or editing a writeup to only logged in users. This is to
|
||||
prevent reporters from backdating writeups, causing them to possibly
|
||||
be missed.
|
||||
- For Raspberry Pi:
|
||||
- Updated the Webmin custom command scripts to use whatever user is
|
||||
logged into Webmin instead of the user "pi" which may not exist
|
||||
if rpi-imager options were used to set a different initial user
|
||||
when the SD card was created.
|
||||
|
||||
1.4.0 - 2024-05-09
|
||||
- Updated the installer script (install.sh) to check for and install the
|
||||
prerequisites (apache, php, mariadb/mysql) and optional packages
|
||||
(webmin, phpmyadmin).
|
||||
- Added an access mode setting. The access mode should be "untrusted" if
|
||||
OpenDRS is exposed to an untrusted environment such as the internet.
|
||||
Untrusted mode requires a login to access any part of the application.
|
||||
The access mode should be "trusted" when the application is used
|
||||
in a trusted environment where anybody on the network can
|
||||
create/edit writeups and search the database, with a login required
|
||||
for everything else.
|
||||
- On the View Open Writeups and View All Writeups pages, replaced the
|
||||
"Last 30 days" button with a dropdown with more options.
|
||||
- Changed the global font to a sans-serif font.
|
||||
- For Raspberry Pi:
|
||||
- Removed the Raspberry Pi terminal setup from OpenDRS. Setting up
|
||||
a Raspberry Pi as a terminal for OpenDRS can now be accomplished
|
||||
by installing the OpenKiosk application.
|
||||
- Removed the Raspberry Pi server setup from OpenDRS. Setting up
|
||||
a Raspberry Pi as an OpenDRS server is easily accomplished by
|
||||
the OpenDRS installer.
|
||||
|
||||
1.4.1 - 2024-06-18
|
||||
- Updated the installer script (install.sh) to check for and install the
|
||||
package supplying uuidgen. If uuidgen is not present, the mysql
|
||||
user would be created with a blank password.
|
||||
|
||||
|
||||
2
INSTALL
2
INSTALL
@@ -23,6 +23,6 @@ passwords are unchanged.
|
||||
The Admin Functions menu will be shown when logged in as an admin user.
|
||||
Click on Global Settings to set display options, page colors, banners, and
|
||||
miscellaneous options. Click on Manage Database to set users, devices,
|
||||
subsystems, action reasons and periods.
|
||||
subsystems, action reasons and when discovereds.
|
||||
|
||||
6. Start making writeups
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(brlaser CXX)
|
||||
set(BRLASER_VERSION "4")
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
message(STATUS "No build type selected, default to RelWithDebInfo")
|
||||
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type (default RelWithDebInfo)" FORCE)
|
||||
endif()
|
||||
|
||||
include(CMakePushCheckState)
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckIncludeFileCXX)
|
||||
|
||||
|
||||
## Enable assertions for all builds
|
||||
## (cmake by default sets NDEBUG for release builds)
|
||||
|
||||
foreach(var
|
||||
CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL)
|
||||
string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " "${var}" "${${var}}")
|
||||
endforeach()
|
||||
|
||||
|
||||
## Configure the compiler
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
macro(extra_cxx_compiler_flag FLAG)
|
||||
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SFLAG ${FLAG})
|
||||
check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
|
||||
if(COMPILER_SUPPORT_${SFLAG})
|
||||
set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} ${FLAG}")
|
||||
endif()
|
||||
endmacro(extra_cxx_compiler_flag)
|
||||
|
||||
# Compiler warnings
|
||||
extra_cxx_compiler_flag("-Wall")
|
||||
extra_cxx_compiler_flag("-Wno-missing-braces")
|
||||
# Some security flags
|
||||
extra_cxx_compiler_flag("-fstack-protector-strong")
|
||||
extra_cxx_compiler_flag("-Wformat")
|
||||
extra_cxx_compiler_flag("-Werror=format-security")
|
||||
extra_cxx_compiler_flag("-D_FORTIFY_SOURCE=2")
|
||||
# Enable the supported flags, but give priority to CXXFLAGS env var
|
||||
set(CMAKE_CXX_FLAGS "${EXTRA_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
|
||||
## Configure CUPS
|
||||
|
||||
find_program(CUPS_CONFIG NAMES cups-config)
|
||||
if(NOT CUPS_CONFIG)
|
||||
message(FATAL_ERROR "cups-config command not found. Are the CUPS development packages installed?")
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND "${CUPS_CONFIG}" --datadir
|
||||
OUTPUT_VARIABLE CUPS_DATA_DIR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(
|
||||
COMMAND "${CUPS_CONFIG}" --serverbin
|
||||
OUTPUT_VARIABLE CUPS_SERVER_BIN
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(
|
||||
COMMAND "${CUPS_CONFIG}" --cflags
|
||||
OUTPUT_VARIABLE CUPS_CFLAGS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(
|
||||
COMMAND "${CUPS_CONFIG}" --ldflags
|
||||
OUTPUT_VARIABLE CUPS_LDFLAGS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(
|
||||
COMMAND "${CUPS_CONFIG}" --image --libs
|
||||
OUTPUT_VARIABLE CUPS_LIBS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
cmake_push_check_state()
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${CUPS_CFLAGS}")
|
||||
check_include_file_cxx(cups/raster.h HAVE_CUPS_RASTER_H)
|
||||
cmake_pop_check_state()
|
||||
if(NOT HAVE_CUPS_RASTER_H)
|
||||
message(SEND_ERROR "<cups/raster.h> header not found. Are the CUPS development packages installed?")
|
||||
endif()
|
||||
|
||||
|
||||
## Build instructions
|
||||
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/brlaser.drv.in"
|
||||
"${PROJECT_BINARY_DIR}/brlaser.drv")
|
||||
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/config.h.in"
|
||||
"${PROJECT_BINARY_DIR}/config.h")
|
||||
|
||||
include_directories("${PROJECT_BINARY_DIR}")
|
||||
|
||||
add_executable(rastertobrlaser src/main.cc src/job.cc src/line.cc src/debug.cc)
|
||||
target_compile_options(rastertobrlaser PRIVATE ${CUPS_CFLAGS})
|
||||
target_link_libraries(rastertobrlaser ${CUPS_LIBS})
|
||||
target_link_libraries(rastertobrlaser ${CUPS_LDFLAGS})
|
||||
|
||||
add_executable(brdecode src/brdecode.cc)
|
||||
add_executable(test_lest test/test_lest.cc)
|
||||
add_executable(test_line test/test_line.cc src/line.cc)
|
||||
add_executable(test_block test/test_block.cc)
|
||||
|
||||
enable_testing()
|
||||
add_test(test_lest test_lest)
|
||||
add_test(test_line test_line)
|
||||
add_test(test_block test_block)
|
||||
|
||||
# Autotools-style "make check" command
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
|
||||
add_dependencies(check test_lest test_line test_block)
|
||||
|
||||
|
||||
# Installation
|
||||
|
||||
install(
|
||||
TARGETS rastertobrlaser
|
||||
DESTINATION "${CUPS_SERVER_BIN}/filter")
|
||||
install(
|
||||
FILES "${PROJECT_BINARY_DIR}/brlaser.drv"
|
||||
DESTINATION "${CUPS_DATA_DIR}/drv")
|
||||
@@ -1,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -1,9 +0,0 @@
|
||||
brlaser v3 (2014-07-07)
|
||||
Added DCP-7065DN description.
|
||||
|
||||
brlaser v2 (2014-06-29)
|
||||
Suppport compilation with GCC 4.6.
|
||||
Add a basic test suite.
|
||||
|
||||
brlaser v1 (2013-12-30)
|
||||
Initial release.
|
||||
@@ -1,85 +0,0 @@
|
||||
brlaser: Brother laser printer driver
|
||||
=====================================
|
||||
|
||||
brlaser is a CUPS driver for Brother laser printers.
|
||||
|
||||
Although most Brother printers support a standard printer language
|
||||
such as PCL or PostScript, not all do. If you have a monochrome
|
||||
Brother laser printer (or multi-function device) and the other open
|
||||
source drivers don't work, this one might help.
|
||||
|
||||
This driver is known to work with these printers:
|
||||
|
||||
* Brother DCP-1510
|
||||
* Brother DCP-7030
|
||||
* Brother DCP-7040
|
||||
* Brother DCP-7055
|
||||
* Brother DCP-7055W
|
||||
* Brother DCP-7065DN
|
||||
* Brother HL-L2300D
|
||||
* Brother MFC-7360N
|
||||
|
||||
|
||||
Other printers
|
||||
--------------
|
||||
|
||||
If your printer isn't included in the list above, just try selecting
|
||||
any entry marked 'brlaser' and see if it works.
|
||||
|
||||
If it does, please create a new issue here in Github and include the
|
||||
output of this command:
|
||||
|
||||
sudo lpinfo --include-schemes usb -l -v
|
||||
|
||||
Then I'll be able to add a proper entry for your printer.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Some operating systems already ship this driver. This is the case for
|
||||
at least Debian, Ubuntu, Raspbian, openSUSE and Arch Linux. Look for a
|
||||
package named `printer-driver-brlaser`.
|
||||
|
||||
You'll also need Ghostscript, in case that's not installed
|
||||
automatically.
|
||||
|
||||
Once brlaser is installed, you can add your printer using the usual
|
||||
CUPS interface.
|
||||
|
||||
|
||||
Building from source
|
||||
--------------------
|
||||
|
||||
To compile brlaser you'll need CMake and the CUPS development packages
|
||||
(libcups2-dev, libcupsimage2-dev or similar).
|
||||
|
||||
Get the code by cloning the git repo <!-- or downloading the [latest
|
||||
release] -->. Compile and install with these commands:
|
||||
|
||||
cmake .
|
||||
make
|
||||
sudo make install
|
||||
|
||||
It might be needed to restart CUPS after this.
|
||||
|
||||
[latest release]: https://github.com/pdewacht/brlaser/releases/latest
|
||||
|
||||
|
||||
Copyright
|
||||
---------
|
||||
|
||||
Copyright © 2013 Peter De Wachter
|
||||
|
||||
brlaser is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
brlaser is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
@@ -1,143 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#define USING "using @CMAKE_PROJECT_NAME@ v@BRLASER_VERSION@"
|
||||
|
||||
// Include standard font and media definitions
|
||||
#include <font.defs>
|
||||
#include <media.defs>
|
||||
|
||||
// List the fonts that are supported, in this case all standard fonts...
|
||||
Font *
|
||||
|
||||
// Manufacturer and driver version.
|
||||
Manufacturer "Brother"
|
||||
Version "@BRLASER_VERSION@"
|
||||
|
||||
// Each filter provided by the driver...
|
||||
Filter application/vnd.cups-raster 33 rastertobrlaser
|
||||
|
||||
// Supported resolutions.
|
||||
// The 1200dpi mode is weird: we need to send 1200x1200dpi raster
|
||||
// data, but Brother only advertises 1200x600dpi. I wonder what
|
||||
// is going on there.
|
||||
// The 300dpi mode is reportedly not supported on all printers, so
|
||||
// it's listed in individual printer blocks where we believe it works.
|
||||
// Resolution k 1 0 0 0 "300dpi/300 DPI"
|
||||
*Resolution k 1 0 0 0 "600dpi/600 DPI"
|
||||
Resolution k 1 0 0 0 "1200dpi/1200HQ"
|
||||
|
||||
// Supported page sizes.
|
||||
HWMargins 8 8 8 16
|
||||
*MediaSize A4
|
||||
MediaSize A5
|
||||
MediaSize A6
|
||||
MediaSize B5
|
||||
MediaSize B6
|
||||
MediaSize EnvC5
|
||||
MediaSize EnvMonarch
|
||||
MediaSize EnvDL
|
||||
MediaSize Executive
|
||||
MediaSize Legal
|
||||
MediaSize Letter
|
||||
|
||||
// Input trays. Numbers must match the filter source code.
|
||||
*InputSlot 0 "Auto/Auto-select"
|
||||
InputSlot 1 "Tray1/Tray 1"
|
||||
InputSlot 2 "Tray2/Tray 2"
|
||||
InputSlot 3 "Tray3/Tray 3"
|
||||
InputSlot 4 "MPTray/MP Tray"
|
||||
InputSlot 5 "Manual/Manual"
|
||||
|
||||
// Media types.
|
||||
*MediaType 0 "PLAIN/Plain paper"
|
||||
MediaType 1 "THIN/Thin paper"
|
||||
MediaType 2 "THICK/Thick paper"
|
||||
MediaType 3 "THICKER/Thicker paper"
|
||||
MediaType 4 "BOND/Bond paper"
|
||||
MediaType 5 "TRANS/Transparencies"
|
||||
MediaType 6 "ENV/Envelopes"
|
||||
MediaType 7 "ENV-THICK/Thick envelopes"
|
||||
MediaType 8 "ENV-THIN/Thin envelopes"
|
||||
|
||||
Option "brlaserEconomode/Toner save mode" Boolean AnySetup 10
|
||||
*Choice False/Off "<</cupsInteger10 0>>setpagedevice"
|
||||
Choice True/On "<</cupsInteger10 1>>setpagedevice"
|
||||
|
||||
|
||||
{
|
||||
ModelName "DCP-1510"
|
||||
Attribute "NickName" "" "Brother DCP-1510 series, $USING"
|
||||
Attribute "1284DeviceID" "" "MFG:Brother;CMD:PJL,XL2HB;MDL:DCP-1510 series;CLS:PRINTER;CID:Brother Laser Type1;"
|
||||
Resolution k 1 0 0 0 "300dpi/300 DPI"
|
||||
PCFileName "br1510.ppd"
|
||||
}
|
||||
|
||||
{
|
||||
ModelName "DCP-7030"
|
||||
Attribute "NickName" "" "Brother DCP-7030, $USING"
|
||||
Attribute "1284DeviceID" "" "MFG:Brother;CMD:PJL,HBP;MDL:DCP-7030;CLS:PRINTER;"
|
||||
Resolution k 1 0 0 0 "300dpi/300 DPI"
|
||||
PCFileName "br7030.ppd"
|
||||
}
|
||||
|
||||
{
|
||||
ModelName "DCP-7040"
|
||||
Attribute "NickName" "" "Brother DCP-7040, $USING"
|
||||
Attribute "1284DeviceID" "" "MFG:Brother;CMD:PJL,HBP;MDL:DCP-7040;CLS:PRINTER;"
|
||||
Resolution k 1 0 0 0 "300dpi/300 DPI"
|
||||
PCFileName "br7040.ppd"
|
||||
}
|
||||
|
||||
{
|
||||
ModelName "DCP-7055"
|
||||
Attribute "NickName" "" "Brother DCP-7055, $USING"
|
||||
Attribute "1284DeviceID" "" "MFG:Brother;CMD:PJL,HBP;MDL:DCP-7055;CLS:PRINTER;CID:Brother Laser Type1;"
|
||||
Resolution k 1 0 0 0 "300dpi/300 DPI"
|
||||
PCFileName "br7055.ppd"
|
||||
}
|
||||
|
||||
{
|
||||
ModelName "DCP-7055W"
|
||||
Attribute "NickName" "" "Brother DCP-7055W, $USING"
|
||||
Attribute "1284DeviceID" "" "MFG:Brother;CMD:PJL,HBP;MDL:DCP-7055W;CLS:PRINTER;CID:Brother Laser Type1;"
|
||||
Resolution k 1 0 0 0 "300dpi/300 DPI"
|
||||
PCFileName "br7055w.ppd"
|
||||
}
|
||||
|
||||
{
|
||||
ModelName "DCP-7065DN"
|
||||
Attribute "NickName" "" "Brother DCP-7065DN, $USING"
|
||||
Attribute "1284DeviceID" "" "MFG:Brother;CMD:PJL,HBP;MDL:DCP-7065DN;CLS:PRINTER;CID:Brother Laser Type1;"
|
||||
Duplex rotated
|
||||
PCFileName "br7065dn.ppd"
|
||||
}
|
||||
|
||||
{
|
||||
ModelName "HL-L2300D"
|
||||
Attribute "NickName" "" "Brother HL-L2300D, $USING"
|
||||
Attribute "1284DeviceID" "" " MFG:Brother;CMD:PJL,HBP;MDL:HL-L2300D series;CLS:PRINTER;CID:Brother Laser Type1;"
|
||||
Duplex rotated
|
||||
PCFileName "brl2300d.ppd"
|
||||
}
|
||||
|
||||
{
|
||||
ModelName "MFC-7360N"
|
||||
Attribute "NickName" "" "Brother MFC-7360N, $USING"
|
||||
Attribute "1284DeviceID" "" "MFG:Brother;CMD:PJL,HBP;MDL:MFC-7360N;CLS:PRINTER;CID:Brother Laser Type1;"
|
||||
PCFileName "br7360n.ppd"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
#define PACKAGE "@CMAKE_PROJECT_NAME@"
|
||||
#define VERSION "@BRLASER_VERSION@"
|
||||
@@ -1,68 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef BLOCK_H
|
||||
#define BLOCK_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
class block {
|
||||
public:
|
||||
block(): line_bytes_(0) {
|
||||
lines_.reserve(max_lines_per_block_);
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return line_bytes_ == 0;
|
||||
}
|
||||
|
||||
void add_line(std::vector<uint8_t> &&line) {
|
||||
assert(!line.empty());
|
||||
assert(line_fits(line.size()));
|
||||
line_bytes_ += line.size();
|
||||
lines_.emplace_back(line);
|
||||
}
|
||||
|
||||
bool line_fits(unsigned size) {
|
||||
return lines_.size() != max_lines_per_block_
|
||||
&& line_bytes_ + size < max_block_size_;
|
||||
}
|
||||
|
||||
void flush(FILE *f) {
|
||||
if (!empty()) {
|
||||
fprintf(f, "%dw%c%c",
|
||||
line_bytes_ + 2, 0,
|
||||
static_cast<int>(lines_.size()));
|
||||
for (auto &line : lines_) {
|
||||
fwrite(line.data(), 1, line.size(), f);
|
||||
}
|
||||
line_bytes_ = 0;
|
||||
lines_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static const unsigned max_block_size_ = 16350;
|
||||
static const unsigned max_lines_per_block_ = 128;
|
||||
|
||||
std::vector<std::vector<uint8_t>> lines_;
|
||||
int line_bytes_;
|
||||
};
|
||||
|
||||
#endif // BLOCK_H
|
||||
@@ -1,225 +0,0 @@
|
||||
// A quick-and-dirty tool to convert print files back to pbm images.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
const size_t MAX_LINE_SIZE = 2000;
|
||||
|
||||
FILE *in_file;
|
||||
std::vector<std::vector<uint8_t>> page;
|
||||
std::vector<uint8_t> line;
|
||||
size_t line_offset;
|
||||
|
||||
|
||||
class unexpected_eof: public std::exception {
|
||||
public:
|
||||
virtual const char *what() const noexcept {
|
||||
return "Unexpected EOF";
|
||||
}
|
||||
};
|
||||
|
||||
class line_overflow: public std::exception {
|
||||
public:
|
||||
virtual const char *what() const noexcept {
|
||||
return "Unreasonable long line, aborting";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
uint8_t get() {
|
||||
int ch = getc(in_file);
|
||||
if (ch < 0)
|
||||
throw unexpected_eof();
|
||||
return ch;
|
||||
}
|
||||
|
||||
unsigned read_overflow() {
|
||||
uint8_t ch;
|
||||
unsigned sum = 0;
|
||||
do {
|
||||
ch = get();
|
||||
sum += ch;
|
||||
} while (ch == 255);
|
||||
return sum;
|
||||
}
|
||||
|
||||
void read_repeat(uint8_t cmd) {
|
||||
uint16_t offset = (cmd >> 5) & 3;
|
||||
if (offset == 3)
|
||||
offset += read_overflow();
|
||||
uint16_t count = cmd & 31;
|
||||
if (count == 31)
|
||||
count += read_overflow();
|
||||
count += 2;
|
||||
uint8_t data = get();
|
||||
|
||||
size_t end = line_offset + offset + count;
|
||||
if (end > line.size()) {
|
||||
if (end > MAX_LINE_SIZE)
|
||||
throw line_overflow();
|
||||
line.resize(end);
|
||||
}
|
||||
line_offset += offset;
|
||||
std::fill_n(line.begin() + line_offset, count, data);
|
||||
line_offset += count;
|
||||
}
|
||||
|
||||
void read_substitute(uint8_t cmd) {
|
||||
uint16_t offset = (cmd >> 3) & 15;
|
||||
if (offset == 15)
|
||||
offset += read_overflow();
|
||||
uint16_t count = cmd & 7;
|
||||
if (count == 7)
|
||||
count += read_overflow();
|
||||
count += 1;
|
||||
|
||||
size_t end = line_offset + offset + count;
|
||||
if (end > line.size()) {
|
||||
if (end > MAX_LINE_SIZE)
|
||||
throw line_overflow();
|
||||
line.resize(end);
|
||||
}
|
||||
line_offset += offset;
|
||||
std::generate_n(line.begin() + line_offset, count, get);
|
||||
line_offset += count;
|
||||
}
|
||||
|
||||
void read_edit() {
|
||||
int8_t cmd = get();
|
||||
if (cmd < 0) {
|
||||
read_repeat(cmd);
|
||||
} else {
|
||||
read_substitute(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void read_line() {
|
||||
uint8_t num_edits = get();
|
||||
if (num_edits == 255) {
|
||||
line.clear();
|
||||
} else {
|
||||
line_offset = 0;
|
||||
for (int i = 0; i < num_edits; ++i) {
|
||||
read_edit();
|
||||
}
|
||||
}
|
||||
page.push_back(line);
|
||||
}
|
||||
|
||||
void read_block() {
|
||||
unsigned count = get();
|
||||
count = count * 256 + get();
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
read_line();
|
||||
}
|
||||
}
|
||||
|
||||
bool read_page() {
|
||||
bool in_esc = false;
|
||||
int ch;
|
||||
|
||||
page.clear();
|
||||
line.clear();
|
||||
while ((ch = getc(in_file)) >= 0) {
|
||||
if (ch == '\f') {
|
||||
break;
|
||||
} else if (ch == 033) {
|
||||
in_esc = true;
|
||||
} else if (in_esc && ch == 'w') {
|
||||
read_block();
|
||||
} else if (in_esc && (ch >= 'A' && ch <= 'Z')) {
|
||||
in_esc = false;
|
||||
}
|
||||
}
|
||||
return !page.empty();
|
||||
}
|
||||
|
||||
void write_pnm(FILE *f) {
|
||||
size_t height = page.size();
|
||||
size_t width = 0;
|
||||
for (auto &l : page) {
|
||||
width = std::max(width, l.size());
|
||||
}
|
||||
|
||||
fprintf(f, "P4 %zd %zd\n", width * 8, height);
|
||||
std::vector<uint8_t> empty(width);
|
||||
for (auto &l : page) {
|
||||
fwrite(l.data(), 1, l.size(), f);
|
||||
fwrite(empty.data(), 1, width - l.size(), f);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
const char *in_filename;
|
||||
std::string out_prefix;
|
||||
|
||||
if (argc > 2) {
|
||||
in_filename = argv[1];
|
||||
out_prefix = argv[2];
|
||||
} else if (argc > 1) {
|
||||
in_filename = argv[1];
|
||||
out_prefix = argv[1];
|
||||
} else {
|
||||
in_filename = nullptr;
|
||||
out_prefix = "page";
|
||||
}
|
||||
|
||||
if (in_filename) {
|
||||
in_file = fopen(in_filename, "rb");
|
||||
if (!in_file) {
|
||||
fprintf(stderr, "Can't open file \"%s\"\n", in_filename);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
in_file = stdin;
|
||||
if (isatty(0)) {
|
||||
fprintf(stderr, "No filename given and no input on stdin\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
int page_num = 1;
|
||||
while (read_page()) {
|
||||
std::string out_filename = out_prefix
|
||||
+ "-" + std::to_string(page_num) + ".pbm";
|
||||
FILE *out_file = fopen(out_filename.c_str(), "wb");
|
||||
if (!out_file) {
|
||||
fprintf(stderr, "Can't write file \"%s\"\n", out_filename.c_str());
|
||||
return 1;
|
||||
}
|
||||
write_pnm(out_file);
|
||||
fclose(out_file);
|
||||
fprintf(stderr, "%s\n", out_filename.c_str());
|
||||
++page_num;
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "%s\n", e.what());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
void dump(const char *name, const T &value) {
|
||||
std::cerr << "DEBUG: " PACKAGE ": page header: " << name << " = " << value << '\n';
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
void dump(const char *name, const T (&value)[N]) {
|
||||
std::cerr << "DEBUG: " PACKAGE ": page header: " << name << " =";
|
||||
for (int i = 0; i < N; ++i) {
|
||||
std::cerr << ' ' << value[i];
|
||||
}
|
||||
std::cerr << '\n';
|
||||
}
|
||||
|
||||
void dump(const char *name, const char *value) {
|
||||
std::cerr << "DEBUG: " PACKAGE ": page header: " << name << " = \"" << value << "\"\n";
|
||||
}
|
||||
|
||||
template <int N, int M>
|
||||
void dump(const char *name, const char (&value)[N][M]) {
|
||||
std::cerr << "DEBUG: " PACKAGE ": page header: " << name << " =";
|
||||
for (int i = 0; i < N; ++i) {
|
||||
std::cerr << " \"" << value[i] << '"';
|
||||
}
|
||||
std::cerr << '\n';
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
void dump_page_header(const cups_page_header2_t &h) {
|
||||
#define d(f) dump(#f, h.f)
|
||||
d(MediaClass);
|
||||
d(MediaColor);
|
||||
d(MediaType);
|
||||
d(OutputType);
|
||||
d(AdvanceDistance);
|
||||
d(AdvanceMedia);
|
||||
d(Collate);
|
||||
d(CutMedia);
|
||||
d(Duplex);
|
||||
d(HWResolution);
|
||||
d(ImagingBoundingBox);
|
||||
d(InsertSheet);
|
||||
d(Jog);
|
||||
d(LeadingEdge);
|
||||
d(Margins);
|
||||
d(ManualFeed);
|
||||
d(MediaPosition);
|
||||
d(MediaWeight);
|
||||
d(MirrorPrint);
|
||||
d(NegativePrint);
|
||||
d(NumCopies);
|
||||
d(Orientation);
|
||||
d(OutputFaceUp);
|
||||
d(PageSize);
|
||||
d(Separations);
|
||||
d(TraySwitch);
|
||||
d(Tumble);
|
||||
d(cupsWidth);
|
||||
d(cupsHeight);
|
||||
d(cupsMediaType);
|
||||
d(cupsBitsPerColor);
|
||||
d(cupsBitsPerPixel);
|
||||
d(cupsBytesPerLine);
|
||||
d(cupsColorOrder);
|
||||
d(cupsColorSpace);
|
||||
d(cupsCompression);
|
||||
d(cupsRowCount);
|
||||
d(cupsRowFeed);
|
||||
d(cupsRowStep);
|
||||
d(cupsNumColors);
|
||||
d(cupsBorderlessScalingFactor);
|
||||
d(cupsPageSize);
|
||||
d(cupsImagingBBox);
|
||||
d(cupsInteger);
|
||||
d(cupsReal);
|
||||
d(cupsString);
|
||||
d(cupsMarkerType);
|
||||
d(cupsRenderingIntent);
|
||||
d(cupsPageSizeName);
|
||||
#undef d
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H
|
||||
|
||||
#include <cups/raster.h>
|
||||
|
||||
void dump_page_header(const cups_page_header2_t &h);
|
||||
|
||||
#endif
|
||||
@@ -1,118 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "job.h"
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "line.h"
|
||||
#include "block.h"
|
||||
|
||||
|
||||
job::job(FILE *out, const std::string &job_name)
|
||||
: out_(out),
|
||||
job_name_(job_name),
|
||||
page_params_() {
|
||||
// Delete dubious characters from job name
|
||||
std::replace_if(job_name_.begin(), job_name_.end(), [](char c) {
|
||||
return c < 32 || c >= 127 || c == '"' || c == '\\';
|
||||
}, ' ');
|
||||
|
||||
begin_job();
|
||||
}
|
||||
|
||||
job::~job() {
|
||||
end_job();
|
||||
}
|
||||
|
||||
void job::begin_job() {
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
putc(0, out_);
|
||||
}
|
||||
fprintf(out_, "\033%%-12345X@PJL\n");
|
||||
fprintf(out_, "@PJL JOB NAME=\"%s\"\n", job_name_.c_str());
|
||||
}
|
||||
|
||||
void job::end_job() {
|
||||
fprintf(out_, "\033%%-12345X@PJL\n");
|
||||
fprintf(out_, "@PJL EOJ NAME=\"%s\"\n", job_name_.c_str());
|
||||
fprintf(out_, "\033%%-12345X\n");
|
||||
}
|
||||
|
||||
void job::write_page_header() {
|
||||
fprintf(out_, "\033%%-12345X@PJL\n");
|
||||
if (page_params_.resolution != 1200) {
|
||||
fprintf(out_, "@PJL SET RAS1200MODE = FALSE\n");
|
||||
fprintf(out_, "@PJL SET RESOLUTION = %d\n", page_params_.resolution);
|
||||
} else {
|
||||
fprintf(out_, "@PJL SET RAS1200MODE = TRUE\n");
|
||||
fprintf(out_, "@PJL SET RESOLUTION = 600\n");
|
||||
}
|
||||
fprintf(out_, "@PJL SET ECONOMODE = %s\n",
|
||||
page_params_.economode ? "ON" : "OFF");
|
||||
fprintf(out_, "@PJL SET SOURCETRAY = %s\n",
|
||||
page_params_.sourcetray.c_str());
|
||||
fprintf(out_, "@PJL SET MEDIATYPE = %s\n",
|
||||
page_params_.mediatype.c_str());
|
||||
fprintf(out_, "@PJL SET PAPER = %s\n",
|
||||
page_params_.papersize.c_str());
|
||||
fprintf(out_, "@PJL SET PAGEPROTECT = AUTO\n");
|
||||
fprintf(out_, "@PJL SET ORIENTATION = PORTRAIT\n");
|
||||
fprintf(out_, "@PJL ENTER LANGUAGE = PCL\n");
|
||||
|
||||
fputs("\033E", out_);
|
||||
fprintf(out_, "\033&l%dX", std::max(1, page_params_.num_copies));
|
||||
|
||||
if (page_params_.duplex) {
|
||||
fputs("\033&l2S", out_);
|
||||
}
|
||||
}
|
||||
|
||||
void job::encode_page(const page_params &page_params,
|
||||
int lines,
|
||||
int linesize,
|
||||
nextline_fn nextline) {
|
||||
if (!(page_params_ == page_params)) {
|
||||
page_params_ = page_params;
|
||||
write_page_header();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> line(linesize);
|
||||
std::vector<uint8_t> reference(linesize);
|
||||
block block;
|
||||
|
||||
if (!nextline(line)) {
|
||||
return;
|
||||
}
|
||||
block.add_line(encode_line(line));
|
||||
std::swap(line, reference);
|
||||
|
||||
fputs("\033*b1030m", out_);
|
||||
|
||||
for (int i = 1; i < lines && nextline(line); ++i) {
|
||||
std::vector<uint8_t> encoded = encode_line(line, reference);
|
||||
if (!block.line_fits(encoded.size())) {
|
||||
block.flush(out_);
|
||||
}
|
||||
block.add_line(std::move(encoded));
|
||||
std::swap(line, reference);
|
||||
}
|
||||
|
||||
block.flush(out_);
|
||||
fputs("1030M\f", out_);
|
||||
fflush(out_);
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef JOB_H
|
||||
#define JOB_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct page_params {
|
||||
int num_copies;
|
||||
int resolution;
|
||||
bool duplex;
|
||||
bool economode;
|
||||
std::string sourcetray;
|
||||
std::string mediatype;
|
||||
std::string papersize;
|
||||
|
||||
bool operator==(const page_params &o) const {
|
||||
return num_copies == o.num_copies
|
||||
&& resolution == o.resolution
|
||||
&& duplex == o.duplex
|
||||
&& economode == o.economode
|
||||
&& sourcetray == o.sourcetray
|
||||
&& mediatype == o.mediatype
|
||||
&& papersize == o.papersize;
|
||||
}
|
||||
};
|
||||
|
||||
class job {
|
||||
public:
|
||||
typedef bool (*nextline_fn)(std::vector<uint8_t> &buf);
|
||||
|
||||
explicit job(FILE *out, const std::string &job_name);
|
||||
~job();
|
||||
|
||||
void encode_page(const page_params ¶ms,
|
||||
int lines,
|
||||
int linesize,
|
||||
nextline_fn nextline);
|
||||
|
||||
private:
|
||||
void begin_job();
|
||||
void end_job();
|
||||
void write_page_header();
|
||||
|
||||
FILE *out_;
|
||||
std::string job_name_;
|
||||
page_params page_params_;
|
||||
};
|
||||
|
||||
#endif // JOB_H
|
||||
@@ -1,191 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "line.h"
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
using std::vector;
|
||||
|
||||
namespace {
|
||||
|
||||
void write_overflow(int value, vector<uint8_t> *out) {
|
||||
if (value >= 0) {
|
||||
if (value < 255) {
|
||||
out->push_back(value);
|
||||
} else {
|
||||
out->insert(out->end(), value / 255, 255);
|
||||
out->push_back(value % 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void write_substitute(int offset,
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
vector<uint8_t> *out) {
|
||||
assert(offset >= 0);
|
||||
assert(offset < 10000);
|
||||
assert(first != last);
|
||||
|
||||
const int offset_max = 15;
|
||||
const int count_max = 7;
|
||||
int count = std::distance(first, last) - 1;
|
||||
|
||||
int offset_low = std::min(offset, offset_max);
|
||||
int count_low = std::min(count, count_max);
|
||||
out->push_back((offset_low << 3) | count_low);
|
||||
write_overflow(offset - offset_max, out);
|
||||
write_overflow(count - count_max, out);
|
||||
out->insert(out->end(), first, last);
|
||||
}
|
||||
|
||||
void write_repeat(int offset, int count, int value, vector<uint8_t> *out) {
|
||||
assert(offset >= 0);
|
||||
assert(offset < 10000);
|
||||
assert(count >= 2);
|
||||
assert(count < 10000);
|
||||
|
||||
const int offset_max = 3;
|
||||
const int count_max = 31;
|
||||
count -= 2;
|
||||
|
||||
int offset_low = std::min(offset, offset_max);
|
||||
int count_low = std::min(count, count_max);
|
||||
out->push_back(128 | (offset_low << 5) | count_low);
|
||||
write_overflow(offset - offset_max, out);
|
||||
write_overflow(count - count_max, out);
|
||||
out->push_back(value);
|
||||
}
|
||||
|
||||
|
||||
bool all_zeros(const vector<uint8_t> &buf) {
|
||||
return std::none_of(buf.begin(), buf.end(), [](uint8_t b) { return b; });
|
||||
}
|
||||
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
int skip_to_next_mismatch(Iterator1 *first1,
|
||||
Iterator1 last1,
|
||||
Iterator2 *first2) {
|
||||
auto mismatch_it = std::mismatch(*first1, last1, *first2);
|
||||
int skipped = std::distance(*first1, mismatch_it.first);
|
||||
*first1 = mismatch_it.first;
|
||||
*first2 = mismatch_it.second;
|
||||
return skipped;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
int repeat_length(Iterator first, Iterator last) {
|
||||
if (first != last) {
|
||||
auto k = *first;
|
||||
auto mismatch = std::find_if(std::next(first), last,
|
||||
[=](decltype(k) x) { return x != k; });
|
||||
return std::distance(first, mismatch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
int substitute_length(Iterator1 first1, Iterator1 last1, Iterator2 first2) {
|
||||
if (first1 != last1) {
|
||||
Iterator1 it1 = first1;
|
||||
Iterator2 it2 = first2;
|
||||
Iterator1 next1 = std::next(first1);
|
||||
Iterator2 next2 = std::next(first2);
|
||||
Iterator1 prev1 = first1;
|
||||
while (next1 != last1) {
|
||||
if ((*it1 == *it2 && *next1 == *next2)) {
|
||||
return std::distance(first1, it1);
|
||||
}
|
||||
if (*it1 == *next1 && *it1 == *prev1) {
|
||||
return std::distance(first1, prev1);
|
||||
}
|
||||
prev1 = it1;
|
||||
it1 = next1; it2 = next2;
|
||||
++next1; ++next2;
|
||||
}
|
||||
}
|
||||
return std::distance(first1, last1);
|
||||
}
|
||||
|
||||
size_t reserve_size(const vector<uint8_t> &line) {
|
||||
// Big enough to store the line uncompressed together with an Substitute
|
||||
// command with many overflow bytes.
|
||||
return line.size() + 16;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
vector<uint8_t> encode_line(const vector<uint8_t> &line,
|
||||
const vector<uint8_t> &reference) {
|
||||
assert(line.size() == reference.size());
|
||||
if (all_zeros(line)) {
|
||||
return vector<uint8_t>(1, 0xFF);
|
||||
}
|
||||
|
||||
vector<uint8_t> output;
|
||||
output.reserve(reserve_size(line));
|
||||
output.push_back(0); // first byte is the edit count
|
||||
|
||||
const uint8_t max_edits = 254;
|
||||
int num_edits = 0;
|
||||
|
||||
auto line_it = line.begin();
|
||||
auto ref_it = reference.begin();
|
||||
while (1) {
|
||||
int offset = skip_to_next_mismatch(&line_it, line.end(), &ref_it);
|
||||
if (line_it == line.end()) {
|
||||
// No more differences, we're done.
|
||||
break;
|
||||
}
|
||||
|
||||
if (++num_edits == max_edits) {
|
||||
// We've run out of edits. Just output the rest of the line in a big
|
||||
// substitute command.
|
||||
write_substitute(offset, line_it, line.end(), &output);
|
||||
break;
|
||||
}
|
||||
|
||||
int s = substitute_length(line_it, line.end(), ref_it);
|
||||
if (s > 0) {
|
||||
write_substitute(offset, line_it, std::next(line_it, s), &output);
|
||||
line_it += s;
|
||||
ref_it += s;
|
||||
} else {
|
||||
int r = repeat_length(line_it, line.end());
|
||||
assert(r >= 2);
|
||||
write_repeat(offset, r, *line_it, &output);
|
||||
line_it += r;
|
||||
ref_it += r;
|
||||
}
|
||||
}
|
||||
|
||||
assert(num_edits <= max_edits);
|
||||
output[0] = num_edits;
|
||||
return output;
|
||||
}
|
||||
|
||||
vector<uint8_t> encode_line(const vector<uint8_t> &line) {
|
||||
if (all_zeros(line)) {
|
||||
return vector<uint8_t>(1, 0xFF);
|
||||
}
|
||||
vector<uint8_t> buf;
|
||||
buf.reserve(reserve_size(line));
|
||||
buf.push_back(1);
|
||||
write_substitute(0, line.begin(), line.end(), &buf);
|
||||
return buf;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef LINE_H
|
||||
#define LINE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
std::vector<uint8_t> encode_line(
|
||||
const std::vector<uint8_t> &line,
|
||||
const std::vector<uint8_t> &reference);
|
||||
|
||||
std::vector<uint8_t> encode_line(
|
||||
const std::vector<uint8_t> &line);
|
||||
|
||||
#endif // LINE_H
|
||||
@@ -1,205 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2013 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <cups/raster.h>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include "config.h"
|
||||
#include "job.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
cups_raster_t *ras;
|
||||
volatile sig_atomic_t interrupted = 0;
|
||||
|
||||
|
||||
void sigterm_handler(int sig) {
|
||||
interrupted = 1;
|
||||
}
|
||||
|
||||
|
||||
bool next_line(std::vector<uint8_t> &buf) {
|
||||
if (interrupted) {
|
||||
return false;
|
||||
}
|
||||
return cupsRasterReadPixels(ras, buf.data(), buf.size()) == buf.size();
|
||||
}
|
||||
|
||||
|
||||
bool plain_ascii_string(const char *str) {
|
||||
bool result = true;
|
||||
for (; result && *str; str++) {
|
||||
result = *str >= 32 && *str <= 126;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ascii_job_name(const char *job_id, const char *job_user, const char *job_name) {
|
||||
std::array<const char *, 3> parts = {{
|
||||
job_id,
|
||||
job_user,
|
||||
job_name
|
||||
}};
|
||||
std::string result;
|
||||
for (const char *part : parts) {
|
||||
if (*part && plain_ascii_string(part)) {
|
||||
if (!result.empty()) {
|
||||
result += '/';
|
||||
}
|
||||
result += part;
|
||||
}
|
||||
}
|
||||
if (result.empty()) {
|
||||
result = "brlaser";
|
||||
}
|
||||
const int max_size = 79;
|
||||
if (result.size() > max_size) {
|
||||
result.resize(max_size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
page_params build_page_params(const cups_page_header2_t &header) {
|
||||
static const std::array<std::string, 6> sources = {{
|
||||
"AUTO", "T1", "T2", "T3", "MP", "MANUAL"
|
||||
}};
|
||||
static const std::map<std::string, std::string> sizes = {
|
||||
{ "A4", "A4" },
|
||||
{ "A5", "A5" },
|
||||
{ "A6", "A6" },
|
||||
{ "B5", "B5" },
|
||||
{ "B6", "B6" },
|
||||
{ "EnvC5", "C5" },
|
||||
{ "EnvMonarch", "MONARCH" },
|
||||
{ "EnvPRC5", "DL" },
|
||||
{ "EnvDL", "DL" },
|
||||
{ "Executive", "EXECUTIVE" },
|
||||
{ "Legal", "LEGAL" },
|
||||
{ "Letter", "LETTER" }
|
||||
};
|
||||
|
||||
page_params p = { };
|
||||
p.num_copies = header.NumCopies;
|
||||
p.resolution = header.HWResolution[0];
|
||||
p.economode = header.cupsInteger[10];
|
||||
p.mediatype = header.MediaType;
|
||||
p.duplex = header.Duplex;
|
||||
|
||||
if (header.MediaPosition < sources.size())
|
||||
p.sourcetray = sources[header.MediaPosition];
|
||||
else
|
||||
p.sourcetray = sources[0];
|
||||
|
||||
auto size_it = sizes.find(header.cupsPageSizeName);
|
||||
if (size_it != sizes.end())
|
||||
p.papersize = size_it->second;
|
||||
else
|
||||
p.papersize = "A4";
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
fprintf(stderr, "INFO: %s version %s\n", PACKAGE, VERSION);
|
||||
|
||||
if (argc != 6 && argc != 7) {
|
||||
fprintf(stderr, "ERROR: rastertobrlaser job-id user title copies options [file]\n");
|
||||
fprintf(stderr, "INFO: This program is a CUPS filter. It is not intended to be run manually.\n");
|
||||
return 1;
|
||||
}
|
||||
const char *job_id = argv[1];
|
||||
const char *job_user = argv[2];
|
||||
const char *job_name = argv[3];
|
||||
// const int job_copies = atoi(argv[4]);
|
||||
// const char *job_options = argv[5];
|
||||
const char *job_filename = argv[6];
|
||||
// const char *job_charset = getenv("CHARSET");
|
||||
|
||||
signal(SIGTERM, sigterm_handler);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
int fd = STDIN_FILENO;
|
||||
if (job_filename) {
|
||||
fd = open(job_filename, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "ERROR: " PACKAGE ": Unable to open raster file\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio", nullptr) != 0) {
|
||||
fprintf(stderr, "ERROR: " PACKAGE ": pledge failed\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
ras = cupsRasterOpen(fd, CUPS_RASTER_READ);
|
||||
if (!ras) {
|
||||
fprintf(stderr, "DEBUG: " PACKAGE ": Cannot read raster data. Most likely an earlier filter in the pipeline failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pages = 0;
|
||||
{
|
||||
job job(stdout, ascii_job_name(job_id, job_user, job_name));
|
||||
cups_page_header2_t header;
|
||||
while (!interrupted && cupsRasterReadHeader2(ras, &header)) {
|
||||
if (header.cupsBitsPerPixel != 1
|
||||
|| header.cupsBitsPerColor != 1
|
||||
|| header.cupsNumColors != 1
|
||||
|| header.cupsBytesPerLine > 10000) {
|
||||
fprintf(stderr, "ERROR: " PACKAGE ": Page %d: Bogus raster data.\n", pages + 1);
|
||||
dump_page_header(header);
|
||||
return 1;
|
||||
}
|
||||
if (pages == 0) {
|
||||
fprintf(stderr, "DEBUG: " PACKAGE ": Page header of first page\n");
|
||||
dump_page_header(header);
|
||||
}
|
||||
job.encode_page(build_page_params(header),
|
||||
header.cupsHeight,
|
||||
header.cupsBytesPerLine,
|
||||
next_line);
|
||||
fprintf(stderr, "PAGE: %d %d\n", ++pages, header.NumCopies);
|
||||
}
|
||||
}
|
||||
|
||||
if (pages == 0) {
|
||||
fprintf(stderr, "ERROR: " PACKAGE ": No pages were found.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
if (ferror(stdout)) {
|
||||
fprintf(stderr, "DEBUG: " PACKAGE ": Could not write print data. Most likely the CUPS backend failed.\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
// Copyright 2013 by Martin Moene
|
||||
//
|
||||
// lest is based on ideas by Kevlin Henney, see video at
|
||||
// http://skillsmatter.com/podcast/agile-testing/kevlin-henney-rethinking-unit-testing-in-c-plus-plus
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0:
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#ifndef LEST_LEST_H_INCLUDED
|
||||
#define LEST_LEST_H_INCLUDED
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <cstddef>
|
||||
|
||||
#ifndef lest_NO_SHORT_ASSERTION_NAMES
|
||||
# define EXPECT lest_EXPECT
|
||||
# define EXPECT_THROWS lest_EXPECT_THROWS
|
||||
# define EXPECT_THROWS_AS lest_EXPECT_THROWS_AS
|
||||
#endif
|
||||
|
||||
#define lest_EXPECT( expr ) \
|
||||
try \
|
||||
{ \
|
||||
if ( ! (expr) ) \
|
||||
throw lest::failure{ lest_LOCATION, #expr }; \
|
||||
} \
|
||||
catch( lest::failure const & ) \
|
||||
{ \
|
||||
throw ; \
|
||||
} \
|
||||
catch( std::exception const & e ) \
|
||||
{ \
|
||||
throw lest::unexpected{ lest_LOCATION, #expr, lest::with_message( e.what() ) }; \
|
||||
} \
|
||||
catch(...) \
|
||||
{ \
|
||||
throw lest::unexpected{ lest_LOCATION, #expr, "of unknown type" }; \
|
||||
}
|
||||
|
||||
#define lest_EXPECT_THROWS( expr ) \
|
||||
for (;;) \
|
||||
{ \
|
||||
try { lest::serum( expr ); } catch (...) { break; } \
|
||||
throw lest::expected{ lest_LOCATION, #expr }; \
|
||||
}
|
||||
|
||||
#define lest_EXPECT_THROWS_AS( expr, excpt ) \
|
||||
for (;;) \
|
||||
{ \
|
||||
try { lest::serum( expr ); } catch ( excpt & ) { break; } catch (...) {} \
|
||||
throw lest::expected{ lest_LOCATION, #expr, lest::of_type( #excpt ) }; \
|
||||
}
|
||||
|
||||
#define lest_LOCATION lest::location{__FILE__, __LINE__}
|
||||
|
||||
namespace lest {
|
||||
|
||||
struct test
|
||||
{
|
||||
const std::string name;
|
||||
const std::function<void()> behaviour;
|
||||
};
|
||||
|
||||
struct location
|
||||
{
|
||||
const std::string file;
|
||||
const int line;
|
||||
|
||||
location( std::string file, int line )
|
||||
: file{ file }, line{ line } {}
|
||||
};
|
||||
|
||||
struct comment
|
||||
{
|
||||
const std::string text;
|
||||
|
||||
comment( std::string text ) : text{ text } {}
|
||||
explicit operator bool() { return ! text.empty(); }
|
||||
};
|
||||
|
||||
struct message : std::runtime_error
|
||||
{
|
||||
const std::string kind;
|
||||
const location where;
|
||||
const comment note;
|
||||
|
||||
~message() throw() {} // GCC 4.6
|
||||
|
||||
message( std::string kind, location where, std::string expr, std::string note = "" )
|
||||
: std::runtime_error{ expr }, kind{ kind }, where{ where }, note{ note } {}
|
||||
};
|
||||
|
||||
struct failure : message
|
||||
{
|
||||
failure( location where, std::string expr )
|
||||
: message{ "failed", where, expr } {}
|
||||
};
|
||||
|
||||
struct expected : message
|
||||
{
|
||||
expected( location where, std::string expr, std::string excpt = "" )
|
||||
: message{ "failed: didn't get exception", where, expr, excpt } {}
|
||||
};
|
||||
|
||||
struct unexpected : message
|
||||
{
|
||||
unexpected( location where, std::string expr, std::string note )
|
||||
: message{ "failed: got unexpected exception", where, expr, note } {}
|
||||
};
|
||||
|
||||
inline bool serum( bool verum ) { return verum; }
|
||||
|
||||
inline std::string with_message( std::string text )
|
||||
{
|
||||
return "with message \"" + text + "\"";
|
||||
}
|
||||
|
||||
inline std::string of_type( std::string text )
|
||||
{
|
||||
return "of type " + text;
|
||||
}
|
||||
|
||||
inline std::string pluralise( int n, std::string text )
|
||||
{
|
||||
return n == 1 ? text : text + "s";
|
||||
}
|
||||
|
||||
inline std::ostream & operator<<( std::ostream & os, comment note )
|
||||
{
|
||||
return os << (note ? " " + note.text : "" );
|
||||
}
|
||||
|
||||
inline std::ostream & operator<<( std::ostream & os, location where )
|
||||
{
|
||||
#ifdef __GNUG__
|
||||
return os << where.file << ":" << where.line;
|
||||
#else
|
||||
return os << where.file << "(" << where.line << ")";
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void report( std::ostream & os, message const & e, std::string test )
|
||||
{
|
||||
os << e.where << ": " << e.kind << e.note << ": " << test << ": " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
int run( test const (&specification)[N], std::ostream & os = std::cout )
|
||||
{
|
||||
int failures = 0;
|
||||
|
||||
for ( auto & testing : specification )
|
||||
{
|
||||
try
|
||||
{
|
||||
testing.behaviour();
|
||||
}
|
||||
catch( message const & e )
|
||||
{
|
||||
++failures;
|
||||
report( os, e, testing.name );
|
||||
}
|
||||
}
|
||||
|
||||
if ( failures > 0 )
|
||||
{
|
||||
os << failures << " out of " << N << " " << pluralise(N, "test") << " failed." << std::endl;
|
||||
}
|
||||
|
||||
return failures;
|
||||
}
|
||||
|
||||
} // namespace lest
|
||||
|
||||
#endif // LEST_LEST_H_INCLUDED
|
||||
@@ -1,54 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2014 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef TEMPFILE_H
|
||||
#define TEMPFILE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
|
||||
class tempfile {
|
||||
public:
|
||||
explicit tempfile()
|
||||
: ptr_(0),
|
||||
size_(0),
|
||||
file_(open_memstream(&ptr_, &size_)) {
|
||||
}
|
||||
|
||||
~tempfile() {
|
||||
fclose(file_);
|
||||
free(ptr_);
|
||||
}
|
||||
|
||||
FILE *file() {
|
||||
return file_;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> data() {
|
||||
if (fflush(file_))
|
||||
return std::vector<uint8_t>();
|
||||
return std::vector<uint8_t>(ptr_, ptr_ + size_);
|
||||
}
|
||||
|
||||
private:
|
||||
char *ptr_;
|
||||
size_t size_;
|
||||
FILE *file_;
|
||||
};
|
||||
|
||||
#endif // TEMPFILE_H
|
||||
@@ -1,91 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2014 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "lest.hpp"
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "tempfile.h"
|
||||
#include "../src/block.h"
|
||||
|
||||
typedef std::vector<uint8_t> vec;
|
||||
|
||||
const lest::test specification[] = {
|
||||
"A block is created empty",
|
||||
[] {
|
||||
block b;
|
||||
EXPECT(b.empty());
|
||||
},
|
||||
|
||||
"Adding a line makes a block no longer empty",
|
||||
[] {
|
||||
block b;
|
||||
b.add_line(vec{1});
|
||||
EXPECT(!b.empty());
|
||||
},
|
||||
|
||||
"A block can contain 128 lines",
|
||||
[] {
|
||||
block b;
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
EXPECT(b.line_fits(1));
|
||||
b.add_line(vec(1));
|
||||
}
|
||||
EXPECT(!b.line_fits(1));
|
||||
},
|
||||
|
||||
"A block has a size limit of about 16 kilobyte",
|
||||
[] {
|
||||
block b;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
EXPECT(b.line_fits(1000));
|
||||
b.add_line(vec(1000));
|
||||
}
|
||||
EXPECT(!b.line_fits(400));
|
||||
},
|
||||
|
||||
"Flushing an empty block does nothing",
|
||||
[] {
|
||||
block b;
|
||||
tempfile f;
|
||||
b.flush(f.file());
|
||||
EXPECT(f.data().empty());
|
||||
},
|
||||
|
||||
"Flush() writes the lines to a file with a proper header",
|
||||
[] {
|
||||
block b;
|
||||
for (uint8_t n = 1; n < 6; ++n) {
|
||||
b.add_line(vec{n, n});
|
||||
}
|
||||
tempfile f;
|
||||
b.flush(f.file());
|
||||
EXPECT(( f.data() == vec{'1','2','w',0,5,1,1,2,2,3,3,4,4,5,5} ));
|
||||
},
|
||||
|
||||
"After flush() a block is empty again",
|
||||
[] {
|
||||
block b;
|
||||
b.add_line(vec{1});
|
||||
tempfile f;
|
||||
b.flush(f.file());
|
||||
EXPECT(b.empty());
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
return lest::run(specification);
|
||||
}
|
||||
@@ -1,291 +0,0 @@
|
||||
// Copyright 2013 by Martin Moene
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0:
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include "lest.hpp"
|
||||
#include <sstream>
|
||||
|
||||
using namespace lest;
|
||||
|
||||
const lest::test specification[] =
|
||||
{
|
||||
"Function to suppress warning \"expression has no effect\" acts as identity function", []
|
||||
{
|
||||
EXPECT( false == serum( false ) );
|
||||
EXPECT( true == serum( true ) );
|
||||
},
|
||||
|
||||
"Function with_message() returns correct string", []
|
||||
{
|
||||
std::string msg = "Let writing tests become irresistibly easy and attractive.";
|
||||
EXPECT( "with message \"" + msg + "\"" == with_message( msg ) );
|
||||
},
|
||||
|
||||
"Function of_type() returns correct string", []
|
||||
{
|
||||
std::string msg = "this_type";
|
||||
EXPECT( "of type " + msg == of_type( msg ) );
|
||||
},
|
||||
|
||||
"Function pluralise() adds 's' except for 1 item", []
|
||||
{
|
||||
std::string word = "hammer";
|
||||
EXPECT( word == pluralise( 1, word ) );
|
||||
for ( auto i : {0,2,3,4,5,6,7,8,9,10,11,12} )
|
||||
EXPECT( word + "s" == pluralise( i, word ) );
|
||||
},
|
||||
|
||||
"Location constructs properly", []
|
||||
{
|
||||
char const * file = __FILE__; int line = __LINE__;
|
||||
location where{ file, line };
|
||||
EXPECT( file == where.file );
|
||||
EXPECT( line == where.line );
|
||||
},
|
||||
|
||||
"Comment constructs properly", []
|
||||
{
|
||||
std::string text = __FILE__;
|
||||
comment note = text;
|
||||
EXPECT( text == note.text );
|
||||
},
|
||||
|
||||
"Comment converted to bool indicates absence or presence of comment", []
|
||||
{
|
||||
EXPECT( false == bool( comment( "") ) );
|
||||
EXPECT( true == bool( comment("x") ) );
|
||||
},
|
||||
|
||||
"Failure exception type constructs and prints properly", []
|
||||
{
|
||||
std::string name = "test-name";
|
||||
failure msg( location{"filename.cpp", 765}, "expression" );
|
||||
|
||||
std::ostringstream os;
|
||||
report( os, msg, name );
|
||||
|
||||
#ifndef __GNUG__
|
||||
EXPECT( os.str() == "filename.cpp(765): failed: test-name: expression\n" );
|
||||
#else
|
||||
EXPECT( os.str() == "filename.cpp:765: failed: test-name: expression\n" );
|
||||
#endif
|
||||
},
|
||||
|
||||
"Expected exception type constructs and prints properly", []
|
||||
{
|
||||
std::string name = "test-name";
|
||||
expected msg( location{"filename.cpp", 765}, "expression" );
|
||||
|
||||
std::ostringstream os;
|
||||
report( os, msg, name );
|
||||
|
||||
#ifndef __GNUG__
|
||||
EXPECT( os.str() == "filename.cpp(765): failed: didn't get exception: test-name: expression\n" );
|
||||
#else
|
||||
EXPECT( os.str() == "filename.cpp:765: failed: didn't get exception: test-name: expression\n" );
|
||||
#endif
|
||||
},
|
||||
|
||||
"Unexpected exception type constructs and prints properly", []
|
||||
{
|
||||
std::string name = "test-name";
|
||||
unexpected msg( location{"filename.cpp", 765}, "expression", "exception-type" );
|
||||
|
||||
std::ostringstream os;
|
||||
report( os, msg, name );
|
||||
|
||||
#ifndef __GNUG__
|
||||
EXPECT( os.str() == "filename.cpp(765): failed: got unexpected exception exception-type: test-name: expression\n" );
|
||||
#else
|
||||
EXPECT( os.str() == "filename.cpp:765: failed: got unexpected exception exception-type: test-name: expression\n" );
|
||||
#endif
|
||||
},
|
||||
|
||||
"Expect generates no message exception for a succeeding test", []
|
||||
{
|
||||
test pass = { "P", [] { EXPECT( true ); } };
|
||||
|
||||
try { pass.behaviour(); }
|
||||
catch(...) { throw failure(location{__FILE__,__LINE__}, "unexpected error generated"); }
|
||||
},
|
||||
|
||||
"Expect generates a message exception for a failing test", []
|
||||
{
|
||||
test fail = { "F", [] { EXPECT( false ); } };
|
||||
|
||||
for (;;)
|
||||
{
|
||||
try { fail.behaviour(); } catch ( message & ) { break; }
|
||||
throw failure(location{__FILE__,__LINE__}, "no error generated");
|
||||
}
|
||||
},
|
||||
|
||||
"Expect succeeds for success (true) and failure (false)", []
|
||||
{
|
||||
test pass[] = {{ "P", [] { EXPECT( true ); } }};
|
||||
test fail[] = {{ "F", [] { EXPECT( false ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 0 == run( pass, os ) );
|
||||
EXPECT( 1 == run( fail, os ) );
|
||||
},
|
||||
|
||||
"Expect succeeds for integer comparation", []
|
||||
{
|
||||
test pass [] = {{ "P" , [] { EXPECT( 7 == 7 ); EXPECT( 7 != 8 );
|
||||
EXPECT( 7 >= 6 ); EXPECT( 7 <= 8 );
|
||||
EXPECT( 7 > 6 ); EXPECT( 7 < 8 ); } }};
|
||||
test fail_1[] = {{ "F1", [] { EXPECT( 7 == 8 ); } }};
|
||||
test fail_2[] = {{ "F2", [] { EXPECT( 7 != 7 ); } }};
|
||||
test fail_3[] = {{ "F3", [] { EXPECT( 7 <= 6 ); } }};
|
||||
test fail_4[] = {{ "F4", [] { EXPECT( 7 >= 8 ); } }};
|
||||
test fail_5[] = {{ "F5", [] { EXPECT( 7 < 6 ); } }};
|
||||
test fail_6[] = {{ "F6", [] { EXPECT( 7 > 8 ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 0 == run( pass , os ) );
|
||||
EXPECT( 1 == run( fail_1, os ) );
|
||||
EXPECT( 1 == run( fail_2, os ) );
|
||||
EXPECT( 1 == run( fail_3, os ) );
|
||||
EXPECT( 1 == run( fail_4, os ) );
|
||||
EXPECT( 1 == run( fail_5, os ) );
|
||||
EXPECT( 1 == run( fail_6, os ) );
|
||||
},
|
||||
|
||||
"Expect succeeds for string comparation", []
|
||||
{
|
||||
std::string a("a"); std::string b("b");
|
||||
test pass [] = {{ "P" , [=]() { EXPECT( a == a ); EXPECT( a != b );
|
||||
EXPECT( b >= a ); EXPECT( a <= b );
|
||||
EXPECT( b > a ); EXPECT( a < b ); } }};
|
||||
test fail_1[] = {{ "F1", [=]() { EXPECT( a == b ); } }};
|
||||
test fail_2[] = {{ "F2", [=]() { EXPECT( a != a ); } }};
|
||||
test fail_3[] = {{ "F3", [=]() { EXPECT( b <= a ); } }};
|
||||
test fail_4[] = {{ "F4", [=]() { EXPECT( a >= b ); } }};
|
||||
test fail_5[] = {{ "F5", [=]() { EXPECT( b < a ); } }};
|
||||
test fail_6[] = {{ "F6", [=]() { EXPECT( a > b ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 0 == run( pass , os ) );
|
||||
EXPECT( 1 == run( fail_1, os ) );
|
||||
EXPECT( 1 == run( fail_2, os ) );
|
||||
EXPECT( 1 == run( fail_3, os ) );
|
||||
EXPECT( 1 == run( fail_4, os ) );
|
||||
EXPECT( 1 == run( fail_5, os ) );
|
||||
EXPECT( 1 == run( fail_6, os ) );
|
||||
},
|
||||
|
||||
"Function run() returns the right failure count", []
|
||||
{
|
||||
test pass [] = {{ "P" , [] { EXPECT( 1==1 ); } }};
|
||||
test fail_1[] = {{ "F1", [] { EXPECT( 0==1 ); } }};
|
||||
test fail_3[] = {{ "F1", [] { EXPECT( 0==1 ); } },
|
||||
{ "F2", [] { EXPECT( 0==1 ); } },
|
||||
{ "F3", [] { EXPECT( 0==1 ); } },};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 0 == run( pass , os ) );
|
||||
EXPECT( 1 == run( fail_1, os ) );
|
||||
EXPECT( 3 == run( fail_3, os ) );
|
||||
},
|
||||
|
||||
"Expect succeeds with an unexpected standard exception", []
|
||||
{
|
||||
std::string text = "hello-world";
|
||||
test pass[] = {{ "P", [=]() { EXPECT( (throw std::runtime_error(text), true) ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 1 == run( pass, os ) );
|
||||
EXPECT( std::string::npos != os.str().find(text) );
|
||||
},
|
||||
|
||||
"Expect succeeds with an unexpected non-standard exception", []
|
||||
{
|
||||
test pass[] = {{ "P", [] { EXPECT( (throw 77, true) ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 1 == run( pass, os ) );
|
||||
},
|
||||
|
||||
"Expect_throws succeeds with an expected standard exception", []
|
||||
{
|
||||
std::string text = "hello-world";
|
||||
test pass[] = {{ "P", [=]() { EXPECT_THROWS( (throw std::runtime_error(text), true) ); } }};
|
||||
test fail[] = {{ "F", [ ]() { EXPECT_THROWS( true ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 0 == run( pass, os ) );
|
||||
EXPECT( 1 == run( fail, os ) );
|
||||
},
|
||||
|
||||
"Expect_throws succeeds with an expected non-standard exception", []
|
||||
{
|
||||
test pass[] = {{ "P", [] { EXPECT_THROWS( (throw 77, true) ); } }};
|
||||
test fail[] = {{ "F", [] { EXPECT_THROWS( true ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 0 == run( pass, os ) );
|
||||
EXPECT( 1 == run( fail, os ) );
|
||||
},
|
||||
|
||||
"Expect_throws_as succeeds with a specific expected standard exception", []
|
||||
{
|
||||
test pass[] = {{ "P", [] { EXPECT_THROWS_AS( (throw std::bad_alloc(), true), std::bad_alloc ); } }};
|
||||
test fail[] = {{ "F", [] { EXPECT_THROWS_AS( (throw std::bad_alloc(), true), std::runtime_error ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 0 == run( pass, os ) );
|
||||
EXPECT( 1 == run( fail, os ) );
|
||||
},
|
||||
|
||||
"Expect_throws_as succeeds with a specific expected non-standard exception", []
|
||||
{
|
||||
test pass[] = {{ "P", [] { EXPECT_THROWS_AS( (throw 77, true), int ); } }};
|
||||
test fail[] = {{ "F", [] { EXPECT_THROWS_AS( (throw 77, true), std::runtime_error ); } }};
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
EXPECT( 0 == run( pass, os ) );
|
||||
EXPECT( 1 == run( fail, os ) );
|
||||
},
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
return lest::run( specification );
|
||||
}
|
||||
|
||||
// cl -nologo -Wall -EHsc test_lest.cpp && test_lest
|
||||
// g++ -Wall -Wextra -Weffc++ -std=c++11 -o test_lest.exe test_lest.cpp && test_lest
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
// This file is part of the brlaser printer driver.
|
||||
//
|
||||
// Copyright 2014 Peter De Wachter
|
||||
//
|
||||
// brlaser is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// brlaser is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "lest.hpp"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "../src/line.h"
|
||||
|
||||
typedef std::vector<uint8_t> vec;
|
||||
|
||||
|
||||
uint8_t sub(uint8_t offset, uint8_t count) {
|
||||
assert(offset < 16);
|
||||
assert(count < 8);
|
||||
return (offset << 3) | count;
|
||||
}
|
||||
|
||||
uint8_t rep(uint8_t offset, uint8_t count) {
|
||||
assert(offset < 4);
|
||||
assert(count < 32);
|
||||
return 128 | (offset << 5) | count;
|
||||
}
|
||||
|
||||
|
||||
const lest::test specification[] = {
|
||||
"Don't crash on zero-length lines",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{}) == vec{0xFF} ));
|
||||
EXPECT(( encode_line(vec{}, vec{}) == vec{0xFF} ));
|
||||
},
|
||||
|
||||
"Encoding an initial blank line",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{0,0,0}) == vec{0xFF} ));
|
||||
},
|
||||
|
||||
"Encoding an initial non-blank line",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{1,2,3}) == (vec{1,sub(0,2),1,2,3}) ));
|
||||
},
|
||||
|
||||
"Encoding a (non-initial) blank line",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{0,0,0}, vec{1,2,3}) == vec{0xFF} ));
|
||||
},
|
||||
|
||||
"Encoding a repeated line",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{1,2,3}, vec{1,2,3}) == vec{0} ));
|
||||
},
|
||||
|
||||
"Using a subsitute command",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{0,0,1,2,3,0,0}, vec(7)) == vec{1,sub(2,2),1,2,3} ));
|
||||
},
|
||||
|
||||
"Using a repeat command",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{0,0,1,1,0,0}, vec(6)) == vec{1,rep(2,0),1} ));
|
||||
},
|
||||
|
||||
"Repeat command followed by substitute command",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{1,1,1,2,3}, vec(5)) == vec{2,rep(0,1),1,sub(0,1),2,3} ));
|
||||
},
|
||||
|
||||
"Substitute comand followed by repeat command",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{3,2,1,1,1}, vec(5)) == vec{2,sub(0,1),3,2,rep(0,1),1} ));
|
||||
},
|
||||
|
||||
"Substitute with an unmodified byte in the middle",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{1,2,3,0,1,2,3}, vec(7)) == vec{1,sub(0,6),1,2,3,0,1,2,3} ));
|
||||
},
|
||||
|
||||
"Substitue with two unmodified bytes in the middle",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{1,2,3,0,0,1,2,3}, vec(8)) == vec{2,sub(0,2),1,2,3,sub(2,2),1,2,3} ));
|
||||
},
|
||||
|
||||
"Repeat with an unmodified byte in the middle",
|
||||
[] {
|
||||
EXPECT(( encode_line(vec{1,1,1,0,1,1,1}, vec(7)) == vec{2,rep(0,1),1,rep(1,1),1} ));
|
||||
},
|
||||
|
||||
"254 edits needed for a single line",
|
||||
[] {
|
||||
vec line, result;
|
||||
for (int i = 0; i < 254; ++i)
|
||||
line.insert(line.end(), {0,0,1});
|
||||
result.push_back(254);
|
||||
for (int i = 0; i < 254; ++i)
|
||||
result.insert(result.end(), {sub(2,0),1});
|
||||
EXPECT(( encode_line(line, vec(line.size())) == result ));
|
||||
},
|
||||
|
||||
"Give up if more than 254 edits needed...",
|
||||
[] {
|
||||
vec line, result;
|
||||
for (int i = 0; i < 255; ++i)
|
||||
line.insert(line.end(), {0,0,1});
|
||||
result.push_back(254);
|
||||
for (int i = 0; i < 253; ++i)
|
||||
result.insert(result.end(), {sub(2,0),1});
|
||||
result.insert(result.end(), {sub(2,3),1,0,0,1});
|
||||
EXPECT(( encode_line(line, vec(line.size())) == result ));
|
||||
},
|
||||
|
||||
"Repeat command with overflow bytes",
|
||||
[] {
|
||||
vec line(3, 0);
|
||||
line.insert(line.end(), 512, 1);
|
||||
vec ref(line.size(), 0);
|
||||
vec expected{1,rep(3,31),0,255,224,1};
|
||||
EXPECT(encode_line(line, ref) == expected);
|
||||
},
|
||||
|
||||
"Substitute command with overflow bytes",
|
||||
[] {
|
||||
vec expected{1,sub(15,7),255,0,255,237};
|
||||
vec line(270, 0);
|
||||
for (int i = 0; i < 250; ++i) {
|
||||
expected.insert(expected.end(), {1,2});
|
||||
line.insert(line.end(), {1,2});
|
||||
}
|
||||
vec ref(line.size(), 0);
|
||||
EXPECT(encode_line(line, ref) == expected);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
return lest::run(specification);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
# OpenMDRS configuration
|
||||
|
||||
Alias /opendrs /var/www/opendrs
|
||||
|
||||
<Directory /var/www/opendrs>
|
||||
Options Indexes FollowSymLinks MultiViews
|
||||
AllowOverride None
|
||||
Order allow,deny
|
||||
allow from all
|
||||
</Directory>
|
||||
@@ -1,24 +0,0 @@
|
||||
<IfModule alias_module>
|
||||
# Aliases: Add here as many aliases as you need (with no limit). The format is
|
||||
# Alias fakename realname
|
||||
#
|
||||
# Note that if you include a trailing / on fakename then the server will
|
||||
# require it to be present in the URL. So "/icons" isn't aliased in this
|
||||
# example, only "/icons/". If the fakename is slash-terminated, then the
|
||||
# realname must also be slash terminated, and if the fakename omits the
|
||||
# trailing slash, the realname must also omit it.
|
||||
#
|
||||
# We include the /icons/ alias for FancyIndexed directory listings. If
|
||||
# you do not use FancyIndexing, you may comment this out.
|
||||
|
||||
#Alias /icons/ "/usr/share/apache2/icons/"
|
||||
|
||||
<Directory "/usr/share/apache2/icons">
|
||||
Options FollowSymlinks
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
</IfModule>
|
||||
|
||||
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
|
||||
@@ -1,31 +0,0 @@
|
||||
<VirtualHost *:80>
|
||||
# The ServerName directive sets the request scheme, hostname and port that
|
||||
# the server uses to identify itself. This is used when creating
|
||||
# redirection URLs. In the context of virtual hosts, the ServerName
|
||||
# specifies what hostname must appear in the request's Host: header to
|
||||
# match this virtual host. For the default virtual host (this file) this
|
||||
# value is not decisive as it is used as a last resort host regardless.
|
||||
# However, you must set it for any further virtual host explicitly.
|
||||
#ServerName www.example.com
|
||||
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /var/www/opendrs
|
||||
|
||||
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
|
||||
# error, crit, alert, emerg.
|
||||
# It is also possible to configure the loglevel for particular
|
||||
# modules, e.g.
|
||||
#LogLevel info ssl:warn
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
|
||||
# For most configuration files from conf-available/, which are
|
||||
# enabled or disabled at a global level, it is possible to
|
||||
# include a line for only one particular virtual host. For example the
|
||||
# following line enables the CGI configuration for this host only
|
||||
# after it has been globally disabled with "a2disconf".
|
||||
#Include conf-available/serve-cgi-bin.conf
|
||||
</VirtualHost>
|
||||
|
||||
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
|
||||
@@ -1 +0,0 @@
|
||||
deb http://download.webmin.com/download/repository sarge contrib
|
||||
@@ -1,146 +0,0 @@
|
||||
#
|
||||
# Configuration file for the CUPS scheduler. See "man cupsd.conf" for a
|
||||
# complete description of this file.
|
||||
#
|
||||
|
||||
# Log general information in error_log - change "warn" to "debug"
|
||||
# for troubleshooting...
|
||||
LogLevel warn
|
||||
PageLogFormat
|
||||
|
||||
# Deactivate CUPS' internal logrotating, as we provide a better one, especially
|
||||
# LogLevel debug2 gets usable now
|
||||
MaxLogSize 0
|
||||
|
||||
# Only listen for connections from the local machine.
|
||||
#Listen localhost:631
|
||||
Port 631
|
||||
Listen 0.0.0.0:631
|
||||
Listen /var/run/cups/cups.sock
|
||||
|
||||
# Show shared printers on the local network.
|
||||
Browsing On
|
||||
BrowseLocalProtocols dnssd
|
||||
|
||||
# Default authentication type, when authentication is required...
|
||||
DefaultAuthType Basic
|
||||
|
||||
# Web interface setting...
|
||||
WebInterface Yes
|
||||
|
||||
# Restrict access to the server...
|
||||
<Location />
|
||||
Order allow,deny
|
||||
Allow from 192.168.100.*
|
||||
</Location>
|
||||
|
||||
# Restrict access to the admin pages...
|
||||
<Location /admin>
|
||||
AuthType Basic
|
||||
Require valid-user
|
||||
Allow all
|
||||
Order allow,deny
|
||||
</Location>
|
||||
|
||||
# Restrict access to configuration files...
|
||||
<Location /admin/conf>
|
||||
AuthType Default
|
||||
Require user @SYSTEM
|
||||
Order allow,deny
|
||||
</Location>
|
||||
|
||||
# Restrict access to log files...
|
||||
<Location /admin/log>
|
||||
AuthType Default
|
||||
Require user @SYSTEM
|
||||
Order allow,deny
|
||||
</Location>
|
||||
|
||||
# Set the default printer/job policies...
|
||||
<Policy default>
|
||||
# Job/subscription privacy...
|
||||
JobPrivateAccess default
|
||||
JobPrivateValues default
|
||||
SubscriptionPrivateAccess default
|
||||
SubscriptionPrivateValues default
|
||||
|
||||
# Job-related operations must be done by the owner or an administrator...
|
||||
<Limit Create-Job Print-Job Print-URI Validate-Job>
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
<Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
|
||||
Require user @OWNER @SYSTEM
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
# All administration operations require an administrator to authenticate...
|
||||
<Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices>
|
||||
AuthType Default
|
||||
Require user @SYSTEM
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
# All printer operations require a printer operator to authenticate...
|
||||
<Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
|
||||
AuthType Default
|
||||
Require user @SYSTEM
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
# Only the owner or an administrator can cancel or authenticate a job...
|
||||
<Limit Cancel-Job CUPS-Authenticate-Job>
|
||||
Require user @OWNER @SYSTEM
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
<Limit All>
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
</Policy>
|
||||
|
||||
# Set the authenticated printer/job policies...
|
||||
<Policy authenticated>
|
||||
# Job/subscription privacy...
|
||||
JobPrivateAccess default
|
||||
JobPrivateValues default
|
||||
SubscriptionPrivateAccess default
|
||||
SubscriptionPrivateValues default
|
||||
|
||||
# Job-related operations must be done by the owner or an administrator...
|
||||
<Limit Create-Job Print-Job Print-URI Validate-Job>
|
||||
AuthType Default
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
<Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
|
||||
AuthType Default
|
||||
Require user @OWNER @SYSTEM
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
# All administration operations require an administrator to authenticate...
|
||||
<Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
|
||||
AuthType Default
|
||||
Require user @SYSTEM
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
# All printer operations require a printer operator to authenticate...
|
||||
<Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
|
||||
AuthType Default
|
||||
Require user @SYSTEM
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
# Only the owner or an administrator can cancel or authenticate a job...
|
||||
<Limit Cancel-Job CUPS-Authenticate-Job>
|
||||
AuthType Default
|
||||
Require user @OWNER @SYSTEM
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
|
||||
<Limit All>
|
||||
Order deny,allow
|
||||
</Limit>
|
||||
</Policy>
|
||||
@@ -1,2 +0,0 @@
|
||||
DRS_SERVER="http://localhost"
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
# This file is part of systemd.
|
||||
#
|
||||
# systemd is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
[Unit]
|
||||
Description=Getty on %I
|
||||
Documentation=man:agetty(8) man:systemd-getty-generator(8)
|
||||
Documentation=http://0pointer.de/blog/projects/serial-console.html
|
||||
After=systemd-user-sessions.service plymouth-quit-wait.service
|
||||
After=rc-local.service
|
||||
|
||||
# If additional gettys are spawned during boot then we should make
|
||||
# sure that this is synchronized before getty.target, even though
|
||||
# getty.target didn't actually pull it in.
|
||||
Before=getty.target
|
||||
IgnoreOnIsolate=yes
|
||||
|
||||
# IgnoreOnIsolate causes issues with sulogin, if someone isolates
|
||||
# rescue.target or starts rescue.service from multi-user.target or
|
||||
# graphical.target.
|
||||
Conflicts=rescue.service
|
||||
Before=rescue.service
|
||||
|
||||
# On systems without virtual consoles, don't start any getty. Note
|
||||
# that serial gettys are covered by serial-getty@.service, not this
|
||||
# unit.
|
||||
ConditionPathExists=/dev/tty0
|
||||
|
||||
[Service]
|
||||
# the VT is cleared by TTYVTDisallocate
|
||||
ExecStart=-/sbin/agetty -a customer --noclear %I $TERM
|
||||
Type=idle
|
||||
Restart=always
|
||||
RestartSec=0
|
||||
UtmpIdentifier=%I
|
||||
TTYPath=/dev/%I
|
||||
TTYReset=yes
|
||||
TTYVHangup=yes
|
||||
TTYVTDisallocate=yes
|
||||
KillMode=process
|
||||
IgnoreSIGPIPE=no
|
||||
SendSIGHUP=yes
|
||||
|
||||
# Unset locale for the console getty since the console has problems
|
||||
# displaying some internationalized messages.
|
||||
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
|
||||
|
||||
[Install]
|
||||
WantedBy=getty.target
|
||||
DefaultInstance=tty1
|
||||
@@ -1,268 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# server-setup.sh
|
||||
# OpenDRS Online Discrepancy Reporting System
|
||||
# Copyright (C) 2021 Rod Wright
|
||||
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
inst_name="OpenDRS"
|
||||
docroot_path="/var/www"
|
||||
apache_user="www-data"
|
||||
apache_group="www-data"
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "This script will configure a Raspberry Pi to be an OpenDRS server."
|
||||
echo ""
|
||||
echo ""
|
||||
echo "You should have already run the terminal-setup.sh script in this directory."
|
||||
echo ""
|
||||
if [ ! -e "/etc/drs.conf" ]
|
||||
then
|
||||
echo "It looks like the terminal-setup.sh script has not been run yet."
|
||||
echo "This is required before running the server-setup.sh script."
|
||||
echo "Aborting."
|
||||
exit 1
|
||||
fi
|
||||
echo "It looks like you have. Continuing."
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Updating Raspberry Pi OS..."
|
||||
sleep 10
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
apt update && apt dist-upgrade -y
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "...done."
|
||||
sleep 10
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "IMPORTANT!: Be sure to make note of usernames and passwords you provide below."
|
||||
echo "You will need them later."
|
||||
echo ""
|
||||
echo "Installing required server packages. Select apache2 as the web server to configure"
|
||||
echo "automatically. Choose Yes when prompted to install phpmyadmin database and allow it to"
|
||||
echo "generate a random password(leave the field blank)."
|
||||
echo -n "Press enter to continue."
|
||||
read continueok
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
apt install -y apache2 php php-mcrypt mariadb-server phpmyadmin uuid-runtime
|
||||
cp etc/apache2/mods-available/alias.conf /etc/apache2/mods-available
|
||||
service apache2 restart
|
||||
echo "...done."
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Configuring the mysql installation. Accept the defaults at the following prompts."
|
||||
echo "Remember the password you set here. You'll need it during the OpenDRS install."
|
||||
echo -n "Press enter to proceed."
|
||||
read continueok
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
mysql_secure_installation
|
||||
mysql mysql -e "update user set plugin='';flush privileges;"
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# This is a fresh install
|
||||
operation="installed"
|
||||
# prompt for mysql information
|
||||
bad_mysql_adm=1
|
||||
while [ $bad_mysql_adm -eq 1 ]
|
||||
do
|
||||
admintestdb="drsadm`date +%Y%m%d`"
|
||||
echo "We need to know the username and password of a MySQL administrator"
|
||||
echo "to be able to create the database and user for OpenDRS. Note that this"
|
||||
echo "is not necessarily the same as the login and password for the computer."
|
||||
echo -n "MySQL admin username: "
|
||||
read mysql_adm_user
|
||||
echo ""
|
||||
echo -n "MySQL admin password: "
|
||||
read -s mysql_adm_pass
|
||||
export MYSQL_PWD="$mysql_adm_pass"
|
||||
mysql -u"$mysql_adm_user" -e "create database $admintestdb;drop database $admintestdb"
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
bad_mysql_adm=0
|
||||
else
|
||||
echo "ERROR: Either the username/password you supplied were incorrect or the user"
|
||||
echo -n "is not a MySQL administrator. Try again? [Y/N]: "
|
||||
read admtry
|
||||
if [ "$admtry" != "Y" -o "$admtry" != "y" ]
|
||||
then
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
echo "What would you like to call this installation of OpenDRS? If you accept"
|
||||
echo "the default, it will be called $inst_name. If you will be running multiple"
|
||||
echo "instances of OpenDRS on this server, you should choose a distinctive name."
|
||||
echo -n "Installation name [$inst_name]: "
|
||||
read inst_name_in
|
||||
if [ "$inst_name_in" != "" ]
|
||||
then
|
||||
inst_name=$inst_name_in
|
||||
fi
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
# Create initial database
|
||||
db_create_fail=1
|
||||
while [ $db_create_fail -eq 1 ]
|
||||
do
|
||||
name_valid=0
|
||||
while [ $name_valid -eq 0 ]
|
||||
do
|
||||
echo "What would you like to call the database for this installation of OpenDRS?"
|
||||
echo "If you accept the default or make it blank, it will be $inst_name."
|
||||
echo "Spaces or special characters are not allowed in the name."
|
||||
echo -n "database name [$inst_name]: "
|
||||
read new_db_name
|
||||
if [ "$new_db_name" = "" ]
|
||||
then
|
||||
new_db_name=$inst_name
|
||||
fi
|
||||
echo $new_db_name|egrep -q "\W"
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "The name you entered seems to contain whitespace or special"
|
||||
echo "characters. Try again or just accept the default."
|
||||
else
|
||||
name_valid=1
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
export MYSQL_PWD="$mysql_adm_pass"
|
||||
mysql -u"$mysql_adm_user" -e "create database $new_db_name"
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
db_create_fail=0
|
||||
else
|
||||
echo "An error was encountered when trying to create the database."
|
||||
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" ]
|
||||
then
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Create user and give rights to database
|
||||
drs_user="$new_db_name-user"
|
||||
drs_pass=`uuidgen`
|
||||
export MYSQL_PWD="$mysql_adm_pass"
|
||||
mysql -u"$mysql_adm_user" -e "create user if not exists '$drs_user'@'localhost' identified by '$drs_pass'"
|
||||
mysql -u"$mysql_adm_user" -e "grant all on $new_db_name.* to '$drs_user'@'localhost'"
|
||||
mysql -u"$mysql_adm_user" -e "flush privileges"
|
||||
|
||||
# Populate initial database
|
||||
mysql -u"$mysql_adm_user" $new_db_name < ../opendrs-initial.sql
|
||||
|
||||
# Set the installation name
|
||||
export MYSQL_PWD="$drs_pass"
|
||||
mysql -u"$drs_user" $new_db_name -e "update config set value=\"$inst_name\",defaultvalue=\"$inst_name\" where name=\"app_name\""
|
||||
|
||||
# Create install path
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Creating installation directory . . ."
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Installing to $docroot_path/$inst_name"
|
||||
sleep 10
|
||||
install_path=$docroot_path/$inst_name
|
||||
mkdir $install_path
|
||||
|
||||
# Create db.php if it doesn't exist
|
||||
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/$drs_user/g" $install_path/db.php
|
||||
sed -i "s/DBPASS/$drs_pass/g" $install_path/db.php
|
||||
fi
|
||||
|
||||
# copy distribution to install location
|
||||
echo "Installing distribution . . ."
|
||||
cp -Rv ../distfiles/* $install_path
|
||||
ln -s $install_path/writeups.php $install_path/index.php
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# set ownership
|
||||
echo "In order to set the ownership correctly, we need to know the user and"
|
||||
echo "group that the webserver expects its files to be owned by. This is"
|
||||
echo "usually not the root account. Refer to the ownership of other files in"
|
||||
echo "your webserver's document tree to see what this should be."
|
||||
echo "Enter the user and group separated by a colon (username:groupname)."
|
||||
echo "Enter the user:group of the OpenDRS installation"
|
||||
echo -n "directory [$apache_user:$apache_group] :"
|
||||
read httpd_user_group_in
|
||||
if [ "$http_user_group_in" != "" ]
|
||||
then
|
||||
http_user_group=$http_user_group_in
|
||||
fi
|
||||
echo ""
|
||||
echo "Setting file ownership . . ."
|
||||
chown -R $httpd_user_group $install_path
|
||||
|
||||
echo ""
|
||||
|
||||
# tell user to launch web browser to continue
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "OpenDRS has been installed."
|
||||
|
||||
echo "# OpenDRS default Apache configuration" > /etc/apache2/conf-available/$inst_name.conf
|
||||
echo "" >> /etc/apache2/conf-available/$inst_name.conf
|
||||
echo "Alias /$inst_name $install_path" >> /etc/apache2/conf-available/$inst_name.conf
|
||||
echo "" >> /etc/apache2/conf-available/$inst_name.conf
|
||||
echo "<Directory $install_path>" >> /etc/apache2/conf-available/$inst_name.conf
|
||||
echo " Options FollowSymLinks" >> /etc/apache2/conf-available/$inst_name.conf
|
||||
echo " DirectoryIndex index.php" >> /etc/apache2/conf-available/$inst_name.conf
|
||||
echo "</Directory>" >> /etc/apache2/conf-available/$inst_name.conf
|
||||
|
||||
a2enconf $inst_name
|
||||
service apache2 reload
|
||||
echo "OpenDRS server setup is complete."
|
||||
echo ""
|
||||
echo "Once the reboot is complete you will need to do the final installation of $inst_name through"
|
||||
echo "the browser. You will need the mysql username and password you set during the mysql installation above."
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Once the final install is done, you will need to log in to $inst_name to configure it."
|
||||
echo "IMPORTANT: The default login credentials for the initial admin user are:"
|
||||
echo ""
|
||||
echo "login: drsadmin"
|
||||
echo "password: OpenDRS-1"
|
||||
echo ""
|
||||
echo "REMEMBER THESE CREDENTIALS. Otherwise, you will not be able to log in and"
|
||||
echo "configure your new installation."
|
||||
echo "It is highly recommended that you change the initial password to something"
|
||||
echo "secure after logging in for the first time."
|
||||
echo "DRS_SERVER=\"http://localhost/$inst_name\"" > /etc/drs.conf
|
||||
@@ -1,150 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# terminal-setup.sh
|
||||
# OpenDRS Online Maintenance Tracking System
|
||||
# Copyright (C) 2021 Rod Wright
|
||||
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "This script will configure a Raspberry Pi to be an OpenDRS terminal."
|
||||
echo ""
|
||||
echo ""
|
||||
echo "You should have already completed the following steps:"
|
||||
echo ""
|
||||
echo "1. Created a Raspberry Pi OS Lite SD card from the latest release."
|
||||
echo "2. Installed the card in a Raspberry Pi, booted it, and logged in as pi."
|
||||
echo "3. Ran sudo raspi-config and :"
|
||||
echo " a. Set a strong password for the pi user."
|
||||
echo " b. Set hostname and, if accessing a network through wifi, the SSID and"
|
||||
echo " passphrase under Network Options."
|
||||
echo " c. Set locale, timezone, keyboard layout, and wifi country under"
|
||||
echo " Localisation Options."
|
||||
echo " d. Enable SSH under Interfacing Options."
|
||||
echo " e. Set overscan as required to get rid of any black borders around the"
|
||||
echo " edge of the display."
|
||||
echo " f. Reboot when prompted and logged back in as pi."
|
||||
echo "4. Transferred the OpenDRS distribution package to /home/pi on the"
|
||||
echo " Raspberry Pi and extracted it."
|
||||
echo "5. Changed directory to RPiSetup in the the extracted distribution directory."
|
||||
echo ""
|
||||
echo "If you have completed these steps, press enter to continue. If not,"
|
||||
echo -n "press ctrl-c to quit."
|
||||
read continueok
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Updating Raspberry Pi OS..."
|
||||
sleep 10
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
apt update && apt dist-upgrade -y
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "...done."
|
||||
sleep 10
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Copying files..."
|
||||
chmod +x usr/local/bin/*
|
||||
cp usr/local/bin/* /usr/local/bin
|
||||
cp etc/apt/sources.list.d/* /etc/apt/sources.list.d
|
||||
cp lib/systemd/system/getty@tty1.service /lib/systemd/system
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "...done."
|
||||
sleep 10
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Installing required terminal packages..."
|
||||
sleep 10
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
wget http://www.webmin.com/jcameron-key.asc
|
||||
apt-key add jcameron-key.asc
|
||||
rm jcameron-key.asc
|
||||
apt update
|
||||
apt install -y --no-install-recommends xorg openbox chromium-browser
|
||||
apt install -y webmin cups libcups2-dev cmake
|
||||
addgroup lpadmin
|
||||
usermod -a -G lpadmin pi
|
||||
systemctl enable getty@tty1.service
|
||||
service cups-browsed stop
|
||||
systemctl disable cups-browsed.service
|
||||
cp etc/cups/cupsd.conf /etc/cups/
|
||||
service cups restart
|
||||
cd brlaser-master
|
||||
cmake . && make && make install
|
||||
cd ..
|
||||
myhn=`hostname`
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Drivers have been installed for the Brother HL-L2300D printer that may come"
|
||||
echo "with the terminal."
|
||||
echo "After the terminal is set up and working, you can use another network"
|
||||
echo "computer to point a web browser to $myhn:631 to add this or another printer"
|
||||
echo "of your choosing."
|
||||
echo -n "Press enter to continue."
|
||||
read continueok
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Creating customer user..."
|
||||
sleep 10
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
cloneuser `who am i | awk '{print $1}'` customer
|
||||
mkdir -p /home/customer/.config/openbox
|
||||
cp home/customer/.profile /home/customer
|
||||
cp home/customer/.config/openbox/rc.xml /home/customer/.config/openbox
|
||||
chown -R customer:customer /home/customer/.config /home/customer/.profile
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "...done."
|
||||
echo ""
|
||||
echo ""
|
||||
echo "This terminal will need to communicate with an OpenDRS server. If"
|
||||
echo "you intend to host the server directly on this terminal, leave this"
|
||||
echo -n "blank. Otherwise, enter the server URL :"
|
||||
read server_url
|
||||
if [[ $server_url == "" ]]
|
||||
then
|
||||
conftype="Server/Terminal"
|
||||
touch /etc/drs.conf
|
||||
./server-setup.sh
|
||||
else
|
||||
conftype="Terminal"
|
||||
echo "DRS_SERVER=\"$server_url\"" > /etc/drs.conf
|
||||
fi
|
||||
echo ""
|
||||
echo ""
|
||||
echo "$conftype configuration is now complete. "
|
||||
echo ""
|
||||
echo ""
|
||||
echo "It is highly recommended that after rebooting, you run ssh pi@$HOSTNAME"
|
||||
echo "from another computer on the network, then create new users for"
|
||||
echo "yourself and any other administrators using the cloneuser command"
|
||||
echo "(cloneuser pi <new username>)."
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Setup complete."
|
||||
echo -n "Press enter to reboot now."
|
||||
read rebootok
|
||||
reboot
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/bin/bash
|
||||
SRC=$1
|
||||
DEST=$2
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Usage: cloneuser source_user destination_user"
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -q $SRC /etc/passwd ;then echo "Source user doesn't exist!"; exit 1; fi
|
||||
if grep -q $DEST /etc/passwd ;then echo "Destination user already exists!"; exit 1; fi
|
||||
|
||||
SRC_GROUPS=`id -Gn ${SRC}`
|
||||
SRC_SHELL=$(awk -F : -v name=${SRC} '(name == $1) { print $7 }' /etc/passwd)
|
||||
RAND_PW=`date +%s | sha256sum | base64 | head -c 32 ; echo`
|
||||
|
||||
echo "Creating user $DEST with a random password"
|
||||
useradd --shell ${SRC_SHELL} --password ${RAND_PW} --create-home ${DEST}
|
||||
for grp in ${SRC_GROUPS};do
|
||||
if [ "$grp" != "$SRC" ]; then
|
||||
echo "Adding user $DEST to group $grp."
|
||||
usermod -a -G $grp ${DEST}
|
||||
fi
|
||||
done
|
||||
echo "Finished. Please set an actual password for $DEST if you want them to be able to log in."
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,144 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage: rpi-clone-setup {-t|--test} hostname
|
||||
# eg: sudo rpi-clone-setup bozo
|
||||
#
|
||||
# This script is automatically run by rpi-clone (when it is given -s options)
|
||||
# to setup an alternate hostname. A cloned file system mounted on /mnt/clone
|
||||
# is expected unless testing with the -t option.
|
||||
#
|
||||
# Or, this script can be run by hand at the end of a clone when rpi-clone
|
||||
# pauses with the cloned file systems still mounted on /mnt/clone.
|
||||
#
|
||||
# Or, run this script by hand with -t to process files in test directories
|
||||
# under /tmp/clone-test. Run -t and look at the files to see if the files
|
||||
# have been edited OK.
|
||||
# eg: sudo rpi-clone-setup -t bozo
|
||||
#
|
||||
# This is a starter script that handles only /etc/hosts and /etc/hostname.
|
||||
# Make sure the script works correctly for your /etc/hosts file.
|
||||
#
|
||||
# If adding a customization for another file:
|
||||
# Add the file to file_list.
|
||||
# If needed, add a mkdir -p line to the "if ((testing))" part.
|
||||
# Add the scripting necessary to customize the file.
|
||||
# Test new scripting by running: rpi-clone-setup -t newhostname
|
||||
#
|
||||
|
||||
file_list="etc/hostname etc/hosts"
|
||||
|
||||
clone=/mnt/clone
|
||||
clone_test=/tmp/clone-test
|
||||
|
||||
PGM=`basename $0`
|
||||
|
||||
if [ `id -u` != 0 ]
|
||||
then
|
||||
echo "You must be root to run $PGM"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
function usage
|
||||
{
|
||||
echo "Usage: $PGM hostname {-t|--test}"
|
||||
echo " Eg: $PGM rpi1"
|
||||
echo " Modify files appropriate to set up for a new host."
|
||||
echo " Files handled are:"
|
||||
for file in $file_list
|
||||
do
|
||||
echo " $file"
|
||||
done
|
||||
echo ""
|
||||
echo "If testing (-t flag) files are copied and processed to $clone_test"
|
||||
echo ""
|
||||
exit 0
|
||||
}
|
||||
|
||||
testing=0
|
||||
while [ "$1" ]
|
||||
do
|
||||
case "$1" in
|
||||
-t|--test)
|
||||
testing=1
|
||||
;;
|
||||
*)
|
||||
if [ "$newhost" != "" ]
|
||||
then
|
||||
echo "Bad args"
|
||||
usage
|
||||
fi
|
||||
newhost=$1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ "$newhost" = "" ]
|
||||
then
|
||||
echo -e "You must specify a target hostname\n"
|
||||
usage
|
||||
fi
|
||||
|
||||
echo -e "\t$newhost\t- target hostname"
|
||||
|
||||
if ((!testing)) && [ ! -d /mnt/clone/etc ]
|
||||
then
|
||||
echo "A destination clone file system is not mounted on /mnt/clone"
|
||||
echo "Aborting!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ((testing))
|
||||
then
|
||||
cd /tmp
|
||||
rm -rf $clone_test
|
||||
clone=$clone_test
|
||||
|
||||
mkdir -p $clone/etc
|
||||
|
||||
echo "**********************************************"
|
||||
echo "Testing setup: copying files to $clone"
|
||||
for file in $file_list
|
||||
do
|
||||
echo " cp /$file $clone/$file"
|
||||
cp /$file $clone/$file
|
||||
done
|
||||
echo "This test run will modify those files."
|
||||
echo "**********************************************"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
|
||||
##
|
||||
# Set /etc/hostname
|
||||
#
|
||||
cd $clone/etc
|
||||
echo $newhost > hostname
|
||||
#
|
||||
# Read it back to verify.
|
||||
#
|
||||
echo "$clone/etc/hostname - set new hostname: "
|
||||
LINE=`cat hostname`
|
||||
echo -e "$LINE\n"
|
||||
|
||||
|
||||
##
|
||||
# Edit /etc/hosts - edit the sed command if editing fails for your /etc/hosts.
|
||||
#
|
||||
cd $clone/etc
|
||||
sed -i s/"$HOSTNAME"/"$newhost"/ hosts
|
||||
#
|
||||
# Read it back to verify.
|
||||
#
|
||||
echo "$clone/etc/hosts - set new hostname \"$newhost\" in lines: "
|
||||
LINE=`grep $newhost hosts`
|
||||
echo -e "$LINE\n"
|
||||
|
||||
|
||||
##
|
||||
# Add more customizations if needed.
|
||||
#
|
||||
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
source /etc/drs.conf
|
||||
|
||||
openbox-session &
|
||||
|
||||
xset s off
|
||||
xset +dpms
|
||||
xset dpms 0 600 1800
|
||||
|
||||
while true
|
||||
do
|
||||
killall chromium-browser
|
||||
rm -rf ~/.{config,cache}/chromium/
|
||||
|
||||
# start browser to DRS Server
|
||||
# --test-type will ignore any warnings and
|
||||
# --ignore-certificate-errors will allow you to kiosk any https-page without displaying certificate errors
|
||||
chromium-browser --test-type --ignore-certificate-errors --kiosk --no-first-run --check-for-update-interval=1 --simulate-upgrade --incognito $DRS_SERVER &
|
||||
|
||||
sleep 10
|
||||
|
||||
while true
|
||||
do
|
||||
pgrep chromium-browse
|
||||
if [ "$?" -eq "1" ]
|
||||
then
|
||||
# relaunch browser if it terminates
|
||||
chromium-browser --test-type --ignore-certificate-errors --kiosk --no-first-run --check-for-update-interval=1 --simulate-upgrade --incognito $DRS_SERVER &
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
exit 0
|
||||
done
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
host=$1
|
||||
|
||||
rsync -rlptDvz rwright@$host:/home/rwright/ownCloud/Software_Projects/OpenDRS-1.1.0/distfiles/ /var/www/opendrs/ && chown -R www-data:www-data /var/www/opendrs/*
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
Raspberry Pi setup
|
||||
|
||||
1. Create Raspberry Pi OS Lite SD card from the most recent stable release.
|
||||
|
||||
2. Insert SD card in Raspberry Pi and boot.
|
||||
|
||||
3. Login as pi.
|
||||
|
||||
4. sudo raspi-config and:
|
||||
|
||||
a. Set a strong password for the default user (pi).
|
||||
|
||||
b. Set the desired hostname.
|
||||
|
||||
c. Set Wireless LAN SSID and passphrase if using WiFi for networking.
|
||||
|
||||
c. Use Localisation Options to:
|
||||
1. Set locale to en_US.UTF-8 UTF-8.
|
||||
2. Set timezone.
|
||||
3. Set keyboard layout (IMPORTANT! Raspberry Pi OS is made in
|
||||
England, so unless that's the kind of keyboard you have, the
|
||||
default layout will make your symbols come out wrong!).
|
||||
4. Set WLAN country.
|
||||
|
||||
d. Use Interfacing Options to enable SSH server.
|
||||
|
||||
e. If you have black borders on the sides of the screen, use Display
|
||||
Underscan option to change Overscan compensation.
|
||||
|
||||
f. When you've finished, tab down to highlight Finish and hit enter.
|
||||
|
||||
g. Reboot when prompted.
|
||||
|
||||
h. Log back in as pi using the password you set in a. above.
|
||||
|
||||
5. Copy OpenDRS distribution package to /home/pi on the Raspberry Pi and extract.
|
||||
|
||||
6. Change directory to the extracted distribution.
|
||||
|
||||
7. Change directory to RPiSetup.
|
||||
|
||||
8. run sudo ./terminal-setup.sh
|
||||
|
||||
9
TODO.txt
Normal file
9
TODO.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
TODO
|
||||
|
||||
- Add ability to save/restore configuration.
|
||||
|
||||
- Add ability to backup/restore writeups.
|
||||
|
||||
- Add a $border_visible debug variable to the end of settings.php and
|
||||
use it wherever there's a "border=\"0\"" to be able to see and fix
|
||||
table layout issues.
|
||||
@@ -2,12 +2,26 @@
|
||||
/*
|
||||
boilerplate.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// redirect to index.php on cancel button press
|
||||
if ($_REQUEST['cancel']) {
|
||||
@@ -18,41 +32,51 @@ if ($_REQUEST['cancel']) {
|
||||
}
|
||||
|
||||
// import session variables
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
if (isset($_SESSION['userid'])) {
|
||||
$userid=$_SESSION['userid'];
|
||||
} else {
|
||||
$userid=NULL;
|
||||
}
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming
|
||||
// form as "all_parameters" so we need to load those into $incoming[]
|
||||
$incoming=unserialize($_REQUEST['all_parameters']);
|
||||
|
||||
} else {
|
||||
// copy $_REQUEST to $incoming
|
||||
// copy $_REQUEST[] to $incoming[]
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
|
||||
|
||||
// define local functions
|
||||
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
*
|
||||
*/
|
||||
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print=="Printer Friendly") {
|
||||
$sbcolor=P_SIDEBAR_COLOR;
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$sbcolor=SIDEBAR_COLOR;
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
}
|
||||
|
||||
$role=dblookup($drs_db,"users","id","role",$userid);
|
||||
|
||||
// define local functions
|
||||
|
||||
|
||||
|
||||
|
||||
framework("begin","$appname","Boilerplate Page",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
db.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
OpenDRS - Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -70,3 +70,96 @@ Changelog
|
||||
ownership of the installed server directory tree if the http
|
||||
user and group names were left at the default.
|
||||
- Updated and tested to support Raspberry Pi 4B hardware.
|
||||
|
||||
1.2.0 - 2021-05-05
|
||||
- Added ability to customize the terminology used for Device,
|
||||
Period, and Effective/Non-effective to make OpenDRS usable in
|
||||
a wider range of applications.
|
||||
|
||||
1.3.0 - 2022-03-05
|
||||
- Made several improvements to group functionality. The Writeup Groups
|
||||
page now displays all groups in a table instead of individually
|
||||
expandable sections. On the View Writeups and View Open Writeups
|
||||
pages, if a writeup is a member of only one group, clicking the
|
||||
icon will take you to the page for that group. If a writeup is
|
||||
a member of multiple groups, clicking the icon will take you to
|
||||
the detail page for that writeup where you can view or modify which
|
||||
groups the writeup is a member of. On the Search page, you can
|
||||
now choose which group(s) the results should include.
|
||||
- Made some improvements to the installation process for Raspberry Pi
|
||||
setup to accomodate the latest version of Raspberry Pi OS.
|
||||
- If setting up as a Raspberry Pi terminal/server, included the option
|
||||
to make the terminal a wireless access point if it connects to an
|
||||
ethernet network.
|
||||
|
||||
1.3.1 - 2022-05-11
|
||||
- Updated installation scripts and instructions to reflect changes in
|
||||
Raspberry Pi OS Release 2022-04-04.
|
||||
|
||||
1.3.2 - 2022-08-08
|
||||
- Fixed typo in dbadmin.php that prevented adding new When Discovered
|
||||
items.
|
||||
- Fixed bug in create.php that prevented the page from working.
|
||||
- Fixed bug in config.php that prevented banners from being modified.
|
||||
- Fixed bug where action_by and action_reason were not preselected for
|
||||
subsequent searches in search.php.
|
||||
- Fixed bug in about.php and gpl.php that still used old $mts_db
|
||||
database handle.
|
||||
- Removed the server session directory option in config.php
|
||||
Miscellaneous settings. For this to make sense, you'd have to have
|
||||
shell access to the server and if that's the case, you'd be able
|
||||
to make the necessary database changes as well.
|
||||
- Fixed opendrs-initial.sql to make the default banner colors match
|
||||
the ones in common.php.
|
||||
- Created changelog.php for use by the "changes" link on the About
|
||||
page so kiosk terminal users don't get dead-ended in the CHANGELOG
|
||||
text file with no way to get back to the app.
|
||||
- Extensive code cleanups/updates in all php files to make application
|
||||
compatible with php8 and eliminate php warnings in apache2 error
|
||||
log file.
|
||||
- For Raspberry Pi:
|
||||
- Updated server-setup.sh to attempt to install the php-mysqli package
|
||||
for compatibility with php8.
|
||||
- Chromium browser will use the printer designated as the local
|
||||
default if it is selected as such in the Cups printer
|
||||
configuration.
|
||||
|
||||
1.3.3 - 2023-10-03
|
||||
- Restricted the ability to change the report date and time when
|
||||
creating or editing a writeup to only logged in users. This is to
|
||||
prevent reporters from backdating writeups, causing them to possibly
|
||||
be missed.
|
||||
- For Raspberry Pi:
|
||||
- Updated the Webmin custom command scripts to use whatever user is
|
||||
logged into Webmin instead of the user "pi" which may not exist
|
||||
if rpi-imager options were used to set a different initial user
|
||||
when the SD card was created.
|
||||
|
||||
1.4.0 - 2024-05-09
|
||||
- Updated the installer script (install.sh) to check for and install the
|
||||
prerequisites (apache, php, mariadb/mysql) and optional packages
|
||||
(webmin, phpmyadmin).
|
||||
- Added an access mode setting. The access mode should be "untrusted" if
|
||||
OpenDRS is exposed to an untrusted environment such as the internet.
|
||||
Untrusted mode requires a login to access any part of the application.
|
||||
The access mode should be "trusted" when the application is used
|
||||
in a trusted environment where anybody on the network can
|
||||
create/edit writeups and search the database, with a login required
|
||||
for everything else.
|
||||
- On the View All Writeups pages, replaced the "Last 7 days" and
|
||||
"Last 30 days" buttons with a dropdown with more options, including
|
||||
future dates so that OpenDRS can be more useful for things like
|
||||
preventive maintenance.
|
||||
- Changed the global font to a sans-serif font.
|
||||
- For Raspberry Pi:
|
||||
- Removed the Raspberry Pi terminal setup from OpenDRS. Setting up
|
||||
a Raspberry Pi as a terminal for OpenDRS can now be accomplished
|
||||
by installing the OpenKiosk application.
|
||||
- Removed the Raspberry Pi server setup from OpenDRS. Setting up
|
||||
a Raspberry Pi as an OpenDRS server is easily accomplished by
|
||||
the OpenDRS installer.
|
||||
|
||||
1.4.1 - 2024-06-18
|
||||
- Updated the installer script (install.sh) to check for and install the
|
||||
package supplying uuidgen. If uuidgen is not present, the mysql
|
||||
user would be created with a blank password.
|
||||
|
||||
@@ -23,6 +23,6 @@ passwords are unchanged.
|
||||
The Admin Functions menu will be shown when logged in as an admin user.
|
||||
Click on Global Settings to set display options, page colors, banners, and
|
||||
miscellaneous options. Click on Manage Database to set users, devices,
|
||||
subsystems, action reasons and periods.
|
||||
subsystems, action reasons and when discovereds.
|
||||
|
||||
6. Start making writeups
|
||||
|
||||
@@ -2,15 +2,20 @@
|
||||
/*
|
||||
about.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to index.php on cancel button press
|
||||
if ($_REQUEST['cancel']) {
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:index.php");
|
||||
@@ -21,7 +26,6 @@ if ($_REQUEST['cancel']) {
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming
|
||||
@@ -31,7 +35,7 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
// extract incoming array keys into variables
|
||||
|
||||
|
||||
// define local functions
|
||||
@@ -42,18 +46,17 @@ $appname=APP_NAME;
|
||||
$drs_version=DRS_VERSION;
|
||||
|
||||
if ($print=="Printer Friendly") {
|
||||
$sbcolor=P_SIDEBAR_COLOR;
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$sbcolor=SIDEBAR_COLOR;
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
}
|
||||
|
||||
$role=dblookup($mts_db,"users","id","role",$userid);
|
||||
|
||||
framework("begin","$appname","About OpenDRS",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
@@ -76,14 +79,14 @@ echo "
|
||||
OpenDRS $drs_version Discrepancy Reporting System
|
||||
</h3><br>
|
||||
<p>This program is licensed under the terms of the <a href=\"gpl.php\">GNU General Public License</a>. Click on the link
|
||||
or see the LICENSE file in the distribution to read it. OpenDRS is Copyright (C) 2018 by Rod Wright.
|
||||
or see the LICENSE file in the distribution to read it. OpenDRS is Copyright (C) 2024 by Rod Wright.
|
||||
</p>
|
||||
<p>
|
||||
OpenDRS is a simple online maintenance tracking/discrepancy reporting application. It allows anyone with a web browser to create ,
|
||||
OpenDRS is a simple online maintenance tracking/discrepancy reporting application. It allows anyone with a web browser to create,
|
||||
view, and search writeups. The look and feel of the OpenDRS pages are easily changed.
|
||||
Settings that affect all users can be changed in the Admin Functions menu. User specific settings can be changed in the
|
||||
My Profile menu. No browser specific HTML is used in OpenDRS, so it should be useable in any browser, and it has been
|
||||
tested using Google Chrome, Mozilla Firefox and Microsoft Internet Explorer.
|
||||
tested using Google Chrome, Mozilla Firefox, Microsoft Internet Explorer, and Microsoft Edge.
|
||||
</p>
|
||||
<p>
|
||||
OpenDRS is highly flexible. Instructions are included in the distribution for creating a user terminal with a Raspberry Pi. OpenDRS can be hosted on a
|
||||
@@ -91,7 +94,7 @@ centralized server, accessed by networked PCs and/or Raspberry Pi terminals. It
|
||||
terminal as a non-networked standalone system or in a small network of Raspberry Pi terminals.
|
||||
</p>
|
||||
<p>
|
||||
To read about the <a href=\"CHANGELOG\" >changes</a> in this latest version of OpenDRS, click on the link or see the CHANGELOG file in the distribution.
|
||||
To read about the <a href=\"changelog.php\" >changes</a> in this latest version of OpenDRS, click on the link or see the CHANGELOG file in the distribution.
|
||||
</p>
|
||||
|
||||
<p>Several pieces of Open Source software make OpenDRS possible.
|
||||
|
||||
92
distfiles/changelog.php
Normal file
92
distfiles/changelog.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/*
|
||||
changelog.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to index.php on cancel button press
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// import session variables
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
|
||||
// import incoming arrays
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming
|
||||
$incoming=unserialize($_REQUEST['all_parameters']);
|
||||
} else {
|
||||
// copy $_REQUEST to $incoming
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// extract incoming array keys into variables
|
||||
|
||||
|
||||
// define local functions
|
||||
|
||||
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
}
|
||||
|
||||
$role=dblookup($drs_db,"users","id","role",$userid);
|
||||
|
||||
framework("begin","$appname","OpenDRS Change Log",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
|
||||
|
||||
// ******** end database manipulation ********
|
||||
|
||||
pagetable("begin");
|
||||
if (!$print) {
|
||||
pageblock("left","begin");
|
||||
sidemenu();
|
||||
pageblock("left","end");
|
||||
}
|
||||
pageblock("right","begin");
|
||||
banner($print);
|
||||
echo "<br>";
|
||||
|
||||
echo "
|
||||
<pre>
|
||||
";
|
||||
echo file_get_contents("CHANGELOG");
|
||||
echo "
|
||||
</pre>
|
||||
";
|
||||
|
||||
echo "<br>";
|
||||
banner($print);
|
||||
pageblock("right","end");
|
||||
pagetable("end");
|
||||
|
||||
framework("end","","",$print);
|
||||
|
||||
?>
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
common.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
@@ -26,7 +26,20 @@ if (!file_exists("db.php")) {
|
||||
include("db.php");
|
||||
include("settings.php");
|
||||
|
||||
// define some constants
|
||||
// assign variables from constants
|
||||
$device_term=DEVICE_TERM;
|
||||
$discovered_term=DISCOVERED_TERM;
|
||||
$discovered_term_short=DISCOVERED_TERM_SHORT;
|
||||
$functional_term=FUNCTIONAL_TERM;
|
||||
$functional_term_short=FUNCTIONAL_TERM_SHORT;
|
||||
$disc_drop_data=DISC_DROP_DATA;
|
||||
$functional_yes=FUNCTIONAL_YES;
|
||||
$functional_no=FUNCTIONAL_NO;
|
||||
$functional_yes_short=FUNCTIONAL_YES_SHORT;
|
||||
$functional_no_short=FUNCTIONAL_NO_SHORT;
|
||||
$access_mode=ACCESS_MODE;
|
||||
|
||||
// define some other constants
|
||||
define("STAT_OPEN",1);
|
||||
define("STAT_CLOSED",2);
|
||||
define("STAT_DEFERRED",3);
|
||||
@@ -53,6 +66,17 @@ $basic_colors=array(
|
||||
"Fuchsia" => "#FF00FF",
|
||||
"Purple" => "#800080");
|
||||
|
||||
// Determine access mode, login status, and admin status
|
||||
if ($access_mode == "trusted") $trusted=true; else $trusted=false;
|
||||
$loggedin=$isadmin=false;
|
||||
if (isset($_SESSION['userid'])) {
|
||||
$uid=$_SESSION['userid'];
|
||||
$loggedin=true;
|
||||
if (mysqli_fetch_row(mysqli_query($drs_db,"select role from users where id=\"$uid\""))[0] == ADMIN) {
|
||||
$isadmin=true;
|
||||
}
|
||||
}
|
||||
|
||||
// Generic functions
|
||||
|
||||
function framework($option,$htmltitle,$pagetitle,$print) {
|
||||
@@ -82,6 +106,7 @@ function framework($option,$htmltitle,$pagetitle,$print) {
|
||||
<meta http-equiv=\"x-ua-compatible\" content=\"IE=edge\">
|
||||
<title>$htmltitle</title>
|
||||
<style type=\"text/css\">
|
||||
* {font-family: Arial, Helvetica, sans-serif;}
|
||||
table.writeup {table-layout:fixed;}
|
||||
td.forcewrap {word-wrap: break-word;}
|
||||
</style>
|
||||
@@ -260,9 +285,10 @@ function framework($option,$htmltitle,$pagetitle,$print) {
|
||||
$( \"#logoutall\" ).checkboxradio({
|
||||
icon: false
|
||||
});
|
||||
$( \"#device, #subsystem, #period, #period_effective, [id|='sel']\" ).selectmenu();
|
||||
$( \"#device, #subsystem, #discoveredselect, #functional, [id|='sel']\" ).selectmenu();
|
||||
$( \"#status, #user, #reason\" ).selectmenu();
|
||||
$( \"#subsystem, #period, #searchstatus, #pass, #passconf\").tooltip();
|
||||
$( \"#showdays\" ).selectmenu( { width : 130 } );
|
||||
$( \"#subsystem, #discovered, #searchstatus, #pass, #passconf\").tooltip();
|
||||
$( \"[id|='ms']\").multiselect();
|
||||
$( \"#configtabs, #dbadmintabs, #profiletabs\" ).tabs();
|
||||
</script>
|
||||
@@ -276,7 +302,6 @@ function framework($option,$htmltitle,$pagetitle,$print) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function pagetable($option) {
|
||||
if ($option=="begin") {
|
||||
echo "
|
||||
@@ -344,30 +369,31 @@ function pageblock($block,$option) {
|
||||
|
||||
function sidemenu($printable=true) {
|
||||
// Displays sidebar menu
|
||||
global $drs_db,$mbgcolor;
|
||||
echo "
|
||||
<div class=\"sidemenu\">
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><a href=\"create.php\" title=\"Create new writeup\"><font size=\"+1\"><b>Create New Writeup</b></font></a></td></tr>
|
||||
</table>
|
||||
<br>";
|
||||
global $drs_db,$mbgcolor,$trusted,$loggedin,$isadmin;
|
||||
|
||||
if ($trusted || $loggedin) {
|
||||
echo "
|
||||
<div class=\"sidemenu\">
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><a href=\"create.php\" title=\"Create new writeup\"><font size=\"+1\"><b>Create New Writeup</b></font></a></td></tr>
|
||||
</table>
|
||||
<br>";
|
||||
}
|
||||
echo "
|
||||
<center><button onclick=\"goBack()\">Go Back</button></center>
|
||||
";
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><a href=\"writeups.php\" title=\"View open writeups\">View Open Writeups</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"writeups.php?view=1\" title=\"View all writeups for a date range\">View All Writeups</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"groups.php\" title=\"View writeup groups\">Writeup Groups</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"search.php\">Search Writeups</a></td></tr>
|
||||
</table>
|
||||
<br>
|
||||
";
|
||||
|
||||
if (isset($_SESSION['userid'])) {
|
||||
$menuuser=$_SESSION['userid'];
|
||||
if (mysqli_fetch_row(mysqli_query($drs_db,"select role from users where id=\"$menuuser\""))[0] == ADMIN) {
|
||||
if ($trusted || $loggedin) {
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><a href=\"writeups.php\" title=\"View open writeups\">View Open Writeups</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"writeups.php?view=1\" title=\"View all writeups for a date range\">View All Writeups</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"groups.php\" title=\"View writeup groups\">Writeup Groups</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"search.php\">Search Writeups</a></td></tr>
|
||||
</table>
|
||||
<br>
|
||||
";
|
||||
if ($isadmin) {
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
@@ -381,7 +407,7 @@ function sidemenu($printable=true) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($_SESSION['userid'])) {
|
||||
if (! $loggedin) {
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
@@ -390,8 +416,8 @@ function sidemenu($printable=true) {
|
||||
</table>
|
||||
<br>";
|
||||
} else {
|
||||
$loginid=$_SESSION['userid'];
|
||||
$loggedinas=mysqli_fetch_row(mysqli_query($drs_db,"select firstname,lastname from users where id=\"$loginid\""));
|
||||
$menuuser=$_SESSION['userid'];
|
||||
$loggedinas=mysqli_fetch_row(mysqli_query($drs_db,"select firstname,lastname from users where id=\"$menuuser\""));
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
@@ -447,14 +473,19 @@ function banner($print) {
|
||||
}
|
||||
}
|
||||
|
||||
function dblookup($dbhandle,$table,$in_field,$out_field,$in_data) {
|
||||
function dblookup($drs_db,$table,$in_field,$out_field,$in_data) {
|
||||
// look up a single field in a database given a value for a single field
|
||||
$out_data=mysqli_fetch_row(mysqli_query($dbhandle,"select $out_field from $table where $in_field=\"$in_data\""));
|
||||
return($out_data[0]);
|
||||
$lookup_result=(mysqli_query($drs_db,"select $out_field from $table where $in_field=\"$in_data\""));
|
||||
if (mysqli_num_rows($lookup_result) > 0) {
|
||||
$out_data=mysqli_fetch_row($lookup_result);
|
||||
return($out_data[0]);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function arrayCopy( array $array ) {
|
||||
$result = array();
|
||||
$result=[];
|
||||
foreach( $array as $key => $val ) {
|
||||
if( is_array( $val ) ) {
|
||||
$result[$key] = arrayCopy( $val );
|
||||
@@ -483,7 +514,7 @@ function validate_password($pass,$passconf) {
|
||||
// first element is true if passwords match, false if not
|
||||
// second element is true if passwords meet complexity requirements, false if not
|
||||
|
||||
$results=array();
|
||||
$results=[];
|
||||
|
||||
// check for match
|
||||
if ($pass==$passconf) {
|
||||
@@ -532,17 +563,24 @@ function validate_password($pass,$passconf) {
|
||||
}
|
||||
|
||||
function displaywriteup($id) {
|
||||
// grab some important global variables
|
||||
global $device_term;
|
||||
global $discovered_term, $discovered_term_short, $disc_drop_data;
|
||||
global $functional_term, $functional_term_short;
|
||||
global $functional_yes, $functional_no;
|
||||
global $functional_yes_short, $functional_no_short;
|
||||
global $drs_db;
|
||||
|
||||
$writeupdata=mysqli_fetch_assoc(mysqli_query($drs_db,"select * from writeups where id=\"$id\""));
|
||||
// determine status indicator
|
||||
if ($writeupdata['status']==1) $statusind="<font color=\"#FF0000\"><div title=\"Open\">OPEN</div></font>";
|
||||
if ($writeupdata['status']==2) $statusind="<font color=\"#00FF00\"><div title=\"Closed\">CLSD</div></font>";
|
||||
if ($writeupdata['status']==3) $statusind="<font color=\"#FFFF00\"><div title=\"Deferred\">DFRD</div></font>";
|
||||
// determine effective icon
|
||||
if($writeupdata["period_effective"]==1) {
|
||||
$effind="<font color=\"#00FF00\" title=\"Period Effective\">EFF</font>";
|
||||
// determine functional indicator
|
||||
if($writeupdata["functional"]==1) {
|
||||
$funcind="<font color=\"#00FF00\" title=\"$functional_yes\">$functional_yes_short</font>";
|
||||
} else {
|
||||
$effind="<font color=\"#FF0000\" title=\"Period Non-effective\">NEF</font>";
|
||||
$funcind="<font color=\"#FF0000\" title=\"$functional_no\">$functional_no_short</font>";
|
||||
}
|
||||
// look up text data
|
||||
$devicename=dblookup($drs_db,"devices","id","name",$writeupdata["device"]);
|
||||
@@ -552,8 +590,8 @@ function displaywriteup($id) {
|
||||
$rdate=$writeupdata["report_date"];
|
||||
$rtime=$writeupdata["report_time"];
|
||||
$repby=$writeupdata["reported_by"];
|
||||
$period=$writeupdata["period"];
|
||||
$periodtimes=dblookup($drs_db,"periods","id","times",$period);
|
||||
$whendiscoveredname=dblookup($drs_db,"discovered","id","whendiscoveredname",$writeupdata["discovered"]);
|
||||
$whendiscovereddesc=dblookup($drs_db,"discovered","id","whendiscovereddesc",$writeupdata["discovered"]);
|
||||
$techfname=dblookup($drs_db,"users","id","firstname",$writeupdata["action_by"]);
|
||||
$techlname=dblookup($drs_db,"users","id","lastname",$writeupdata["action_by"]);
|
||||
$reasonname=dblookup($drs_db,"reasons","id","text",$writeupdata["action_reason"]);
|
||||
@@ -577,18 +615,20 @@ function displaywriteup($id) {
|
||||
if ($group_count == 1) {
|
||||
$group_ind="<a href=\"groups.php?group=$member_group\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"$imgtitle\"></a></div>";
|
||||
} else {
|
||||
$group_ind="<a href=\"groups.php\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"View writeup groups\"></a></div>";
|
||||
$group_ind="<a href=\"writeupdetail.php?id={$writeupdata['id']}\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"Member of $group_count groups. Click here to view.\"></a></div>";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$group_ind=NULL;
|
||||
}
|
||||
echo "
|
||||
<table border=\"2\" width=\"100%\"><tr><td>
|
||||
<table border=\"0\">
|
||||
<tr><td><b>ID:</b> <a href=\"writeupdetail.php?id=$id\" title=\"View or change details of this writeup\">$id</a></td><td> </td>
|
||||
<td><b>$statusind</b></td><td> </td>
|
||||
<td><b>Device:</b> $devicename</td><td> </td>
|
||||
<td><b>$device_term:</b> $devicename</td><td> </td>
|
||||
<td><b>Subsystem:</b> <font title=\"$subsystemdesc\">$subsystemname</font></td><td> </td>
|
||||
<td><b>Period:</b> <font title=\"$periodtimes\">$period</font></td><td> </td>
|
||||
<td><b>$effind</b></td>
|
||||
<td><b>$discovered_term:</b> <font title=\"$whendiscovereddesc\">$whendiscoveredname</font></td><td> </td>
|
||||
<td><b>$funcind</b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border=\"0\">
|
||||
@@ -649,47 +689,65 @@ function format_message($msgtype,$msgtxt) {
|
||||
function getsetting($setting_name,$user_id) {
|
||||
// get the value of a setting for a user
|
||||
global $drs_db;
|
||||
$confvalue=mysqli_fetch_assoc(mysqli_query($drs_db,"select id,value from config where name=\"$setting_name\""))['value'];
|
||||
$uservalue=mysqli_fetch_assoc(mysqli_query($drs_db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\""))['value'];
|
||||
if ($uservalue) {
|
||||
return $uservalue;
|
||||
} else {
|
||||
return $confvalue;
|
||||
}
|
||||
$confqry=mysqli_query($drs_db,"select id,value from config where name=\"$setting_name\"");
|
||||
$confvalue=mysqli_fetch_assoc($confqry)['value'];
|
||||
$userqry=mysqli_query($drs_db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\"");
|
||||
if (mysqli_num_rows($userqry) > 0) {
|
||||
$uservalue=mysqli_fetch_assoc($userqry)['value'];
|
||||
if ($uservalue) {
|
||||
return $uservalue;
|
||||
} else {
|
||||
return $confvalue;
|
||||
}
|
||||
} else {
|
||||
return $confvalue;
|
||||
}
|
||||
}
|
||||
|
||||
function putsetting($setting_name,$setting_value,$user_id) {
|
||||
// set the value of a setting for a tech
|
||||
global $drs_db;
|
||||
$confvalue=mysqli_fetch_assoc(mysqli_query($drs_db,"select value from config where name=\"$setting_name\""))['value'];
|
||||
$uservalue=mysqli_fetch_assoc(mysqli_query($drs_db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\""))['value'];
|
||||
if ($setting_value==$confvalue) {
|
||||
mysqli_query($drs_db,"delete from profile where user=\"$user_id\" and name=\"$setting_name\"");
|
||||
} else {
|
||||
if ($uservalue) {
|
||||
if ($uservalue != $setting_value) mysqli_query($drs_db,"update profile set value=\"$setting_value\" where name=\"$setting_name\" and user=\"$user_id\"");
|
||||
} else {
|
||||
mysqli_query($drs_db,"insert into profile(user,name,value) values(\"$user_id\",\"$setting_name\",\"$setting_value\")");
|
||||
}
|
||||
}
|
||||
$confqry=mysqli_query($drs_db,"select value from config where name=\"$setting_name\"");
|
||||
$confvalue=mysqli_fetch_assoc($confqry)['value'];
|
||||
$userqry=mysqli_query($drs_db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\"");
|
||||
if (mysqli_num_rows($userqry) > 0) {
|
||||
$uservalue=mysqli_fetch_assoc($userqry)['value'];
|
||||
if ($setting_value==$confvalue) {
|
||||
mysqli_query($drs_db,"delete from profile where user=\"$user_id\" and name=\"$setting_name\"");
|
||||
} else {
|
||||
if ($uservalue) {
|
||||
if ($uservalue != $setting_value) mysqli_query($drs_db,"update profile set value=\"$setting_value\" where name=\"$setting_name\" and user=\"$user_id\"");
|
||||
} else {
|
||||
mysqli_query($drs_db,"insert into profile(user,name,value) values(\"$user_id\",\"$setting_name\",\"$setting_value\")");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mysqli_query($drs_db,"insert into profile(user,name,value) values(\"$user_id\",\"$setting_name\",\"$setting_value\")");
|
||||
}
|
||||
}
|
||||
|
||||
function group_table($groupid,$role=false,$mode="view",$selection="none",$expanded=false) {
|
||||
function group_detail($groupid,$role=false,$mode="view",$selection="none") {
|
||||
// display a table for a single group
|
||||
|
||||
// groupid is the group for which detail is to be shown
|
||||
// role is true if user is logged in, false if not.
|
||||
// mode is "select" if selection boxes are to be displayed, "view" if not.
|
||||
// selection is "all" or "none"
|
||||
|
||||
// grab some important global variables
|
||||
global $device_term;
|
||||
global $discovered_term, $discovered_term_short, $disc_drop_data;
|
||||
global $functional_term, $functional_term_short;
|
||||
global $functional_yes, $functional_no;
|
||||
global $functional_yes_short, $functional_no_short;
|
||||
global $drs_db;
|
||||
|
||||
// print group id and name
|
||||
if ($selection == "all") {
|
||||
$sel_flag="checked";
|
||||
} elseif ($selection == "none") {
|
||||
$sel_flag="";
|
||||
}
|
||||
if ($expanded) {
|
||||
echo "
|
||||
<a href=\"groups.php\" style=\"text-decoration:none\">
|
||||
<img src=\"icons/minus-white.png\" alt=\"Unexpand group\">
|
||||
</a>
|
||||
";
|
||||
}
|
||||
$groupname=dblookup($drs_db,"groups","id","name",$groupid);
|
||||
if ($groupname == "") {
|
||||
echo "<b>Group ID: $groupid";
|
||||
@@ -706,12 +764,12 @@ function group_table($groupid,$role=false,$mode="view",$selection="none",$expand
|
||||
<th style=\"width:1%;\">ID</th>
|
||||
<th style=\"width:1%;\">Status</th>
|
||||
<th style=\"width:100px;\">Date</th>
|
||||
<th style=\"width:1%;\">Period</th>
|
||||
<th style=\"width:1%;\">Device</th>
|
||||
<th style=\"width:1%;\">$discovered_term_short</th>
|
||||
<th style=\"width:1%;\">$device_term</th>
|
||||
<th style=\"width:1%;\">Subsystem</th>
|
||||
<th style=\"width:1%;\">Reported by</th>
|
||||
<th>Discrepancy</th>
|
||||
<th style=\"width:1%;\">Msn Eff</th>
|
||||
<th style=\"width:1%;\">$functional_term_short</th>
|
||||
</tr>
|
||||
";
|
||||
} else {
|
||||
@@ -721,12 +779,12 @@ function group_table($groupid,$role=false,$mode="view",$selection="none",$expand
|
||||
<th style=\"width:1%;\">ID</th>
|
||||
<th style=\"width:1%;\">Status</th>
|
||||
<th style=\"width:100px;\">Date</th>
|
||||
<th style=\"width:1%;\">Period</th>
|
||||
<th style=\"width:1%;\">Device</th>
|
||||
<th style=\"width:1%;\">$discovered_term_short</th>
|
||||
<th style=\"width:1%;\">$device_term</th>
|
||||
<th style=\"width:1%;\">Subsystem</th>
|
||||
<th style=\"width:1%;\">Reported by</th>
|
||||
<th>Discrepancy</th>
|
||||
<th style=\"width:1%;\">Msn Eff</th>
|
||||
<th style=\"width:1%;\">$functional_term_short</th>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
@@ -744,13 +802,14 @@ function group_table($groupid,$role=false,$mode="view",$selection="none",$expand
|
||||
if ($writeupdata['status']==1) $statusind="<font color=\"#FF0000\"><div title=\"Open\">OPEN</div></font>";
|
||||
if ($writeupdata['status']==2) $statusind="<font color=\"#00FF00\"><div title=\"Closed\">CLSD</div></font>";
|
||||
if ($writeupdata['status']==3) $statusind="<font color=\"#FFFF00\"><div title=\"Deferred\">DFRD</div></font>";
|
||||
// determine times for period
|
||||
$ptimes=mysqli_fetch_row(mysqli_query($drs_db,"select times from periods where id=\"{$writeupdata['period']}\""))[0];
|
||||
// determine effective icon
|
||||
if($writeupdata["period_effective"]==1) {
|
||||
$eff_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"Period Effective\" alt=\"Period Effective\">";
|
||||
// determine whendiscovered text for discovered id
|
||||
$whendiscname=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscoveredname from discovered where id=\"{$writeupdata['discovered']}\""))[0];
|
||||
$whendiscdesc=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscovereddesc from discovered where id=\"{$writeupdata['discovered']}\""))[0];
|
||||
// determine functional icon
|
||||
if($writeupdata["functional"]==1) {
|
||||
$func_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes_short\">";
|
||||
} else {
|
||||
$eff_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"Period Non-effective\" alt=\"Period Non-effective\">";
|
||||
$func_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no_short\">";
|
||||
}
|
||||
// print table row
|
||||
if ($role && $mode=="select") {
|
||||
@@ -771,12 +830,12 @@ function group_table($groupid,$role=false,$mode="view",$selection="none",$expand
|
||||
$writeupdata["id"],$writeupdata["id"],
|
||||
$statusind,
|
||||
$writeupdata["report_date"],
|
||||
$ptimes, $writeupdata["period"],
|
||||
$whendiscdesc, $whendiscname,
|
||||
$tname,
|
||||
$ssname,
|
||||
$writeupdata["reported_by"],
|
||||
$writeupdata["discrepancy_text"],
|
||||
$eff_icon
|
||||
$func_icon
|
||||
);
|
||||
} else {
|
||||
printf(
|
||||
@@ -794,12 +853,12 @@ function group_table($groupid,$role=false,$mode="view",$selection="none",$expand
|
||||
$writeupdata["id"],$writeupdata["id"],
|
||||
$statusind,
|
||||
$writeupdata["report_date"],
|
||||
$ptimes, $writeupdata["period"],
|
||||
$whendiscdesc, $whendiscname,
|
||||
$tname,
|
||||
$ssname,
|
||||
$writeupdata["reported_by"],
|
||||
$writeupdata["discrepancy_text"],
|
||||
$eff_icon
|
||||
$func_icon
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -807,4 +866,5 @@ function group_table($groupid,$role=false,$mode="view",$selection="none",$expand
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -2,15 +2,29 @@
|
||||
/*
|
||||
config.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// redirect to index.php on cancel button press
|
||||
if ($_REQUEST['cancel']) {
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:index.php");
|
||||
@@ -18,11 +32,9 @@ if ($_REQUEST['cancel']) {
|
||||
}
|
||||
|
||||
// import session variables
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
$role=dblookup($drs_db,"users","id","role",$userid);
|
||||
// redirect to index.php if not an admin
|
||||
|
||||
if ($role != ADMIN) {
|
||||
// redirect to index.php if not an admin
|
||||
if (! $isadmin) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:index.php");
|
||||
@@ -30,7 +42,6 @@ if ($role != ADMIN) {
|
||||
}
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming[]
|
||||
@@ -40,35 +51,56 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
$update_display=$incoming['update_display'];
|
||||
$display_appname=$incoming['display_appname'];
|
||||
$display_banner=$incoming['display_banner'];
|
||||
$display_footer=$incoming['display_footer'];
|
||||
$display_pereffhlp=$incoming['display_pereffhlp'];
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
* update_display
|
||||
* display_appname
|
||||
* display_banner
|
||||
* display_footer
|
||||
* display_funchelp
|
||||
* display_device_term
|
||||
* display_discovered_term
|
||||
* display_discovered_term_short
|
||||
* display_disc_drop_data
|
||||
* display_functional_term
|
||||
* display_functional_term_short
|
||||
* display_functional_yes
|
||||
* display_functional_no
|
||||
* display_functional_yes_short
|
||||
* display_functional_no_short
|
||||
* update_colors
|
||||
* reset_colors
|
||||
* newbgc
|
||||
* newmbgc
|
||||
* newtc
|
||||
* newlc
|
||||
* newvlc
|
||||
* newhc
|
||||
* edit_banner
|
||||
* add_banner
|
||||
* update_banner
|
||||
* delete_banner
|
||||
* bnrid
|
||||
* bnrname
|
||||
* bnrcolor
|
||||
* bnrtxtcolor
|
||||
* update_misc
|
||||
* sessttl
|
||||
* logoutall
|
||||
* accessmode
|
||||
*/
|
||||
|
||||
$update_colors=$incoming['update_colors'];
|
||||
$reset_colors=$incoming['reset_colors'];
|
||||
$newbgc=$incoming['newbgc'];
|
||||
$newmbgc=$incoming['newmbgc'];
|
||||
$newtc=$incoming['newtc'];
|
||||
$newlc=$incoming['newlc'];
|
||||
$newvlc=$incoming['newvlc'];
|
||||
$newhc=$incoming['newhc'];
|
||||
|
||||
$edit_banner=$incoming['edit_banner'];
|
||||
$add_banner=$incoming['add_banner'];
|
||||
$update_banner=$incoming['update_banner'];
|
||||
$delete_banner=$incoming['delete_banner'];
|
||||
$bnrid=$incoming['bnrid'];
|
||||
$bnrname=$incoming['bnrname'];
|
||||
$bnrcolor=$incoming['bnrcolor'];
|
||||
$bnrtxtcolor=$incoming['bnrtxtcolor'];
|
||||
|
||||
$update_misc=$incoming['update_misc'];
|
||||
$sessttl=$incoming['sessttl'];
|
||||
$sessdir=$incoming['sessdir'];
|
||||
$logoutall=$incoming['logoutall'];
|
||||
if (!isset($update_display)) $update_display=false;
|
||||
if (!isset($update_colors)) $update_colors=false;
|
||||
if (!isset($reset_colors)) $reset_colors=false;
|
||||
if (!isset($add_banner)) $add_banner=false;
|
||||
if (!isset($edit_banner)) $edit_banner=false;
|
||||
if (!isset($update_banner)) $update_banner=false;
|
||||
if (!isset($delete_banner)) $delete_banner=false;
|
||||
if (!isset($update_misc)) $update_misc=false;
|
||||
if (!isset($logoutall)) $logoutall=false;
|
||||
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
@@ -81,10 +113,14 @@ if ($print=="Printer Friendly") {
|
||||
|
||||
framework("begin","$appname","Configuration",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
$nameunique_err=$namesuppld_err=$ttlsuppld_err=$dirsuppld_err=false;
|
||||
|
||||
if ($update_display) {
|
||||
// remove html tags from footer_message and sanitize
|
||||
$display_footer=strip_tags($display_footer);
|
||||
@@ -92,14 +128,52 @@ if ($update_display) {
|
||||
// remove html tags from app name and sanitize
|
||||
$display_appname=strip_tags($display_appname);
|
||||
$clean_display_appname=mysqli_real_escape_string($drs_db,$display_appname);
|
||||
// remove html tags from period effective help text and sanitize
|
||||
$display_pereffhlp=strip_tags($display_pereffhlp);
|
||||
$clean_display_pereffhlp=mysqli_real_escape_string($drs_db,$display_pereffhlp);
|
||||
// remove html tags from functional help text and sanitize
|
||||
$display_funchelp=strip_tags($display_funchelp);
|
||||
$clean_display_funchelp=mysqli_real_escape_string($drs_db,$display_funchelp);
|
||||
// remove html tags from device term and sanitize
|
||||
$display_device_term=strip_tags($display_device_term);
|
||||
$clean_display_device_term=mysqli_real_escape_string($drs_db,$display_device_term);
|
||||
// remove html tags from discovered term and sanitize
|
||||
$display_discovered_term=strip_tags($display_discovered_term);
|
||||
$clean_display_discovered_term=mysqli_real_escape_string($drs_db,$display_discovered_term);
|
||||
// remove html tags from short discovered term and sanitize
|
||||
$display_discovered_term_short=strip_tags($display_discovered_term_short);
|
||||
$clean_display_discovered_term_short=mysqli_real_escape_string($drs_db,$display_discovered_term_short);
|
||||
// remove html tags from functional term and sanitize
|
||||
$display_functional_term=strip_tags($display_functional_term);
|
||||
$clean_display_functional_term=mysqli_real_escape_string($drs_db,$display_functional_term);
|
||||
// remove html tags from short functional term and sanitize
|
||||
$display_functional_term_short=strip_tags($display_functional_term_short);
|
||||
$clean_display_functional_term_short=mysqli_real_escape_string($drs_db,$display_functional_term_short);
|
||||
// remove html tags from functional yes and sanitize
|
||||
$display_functional_yes=strip_tags($display_functional_yes);
|
||||
$clean_display_functional_yes=mysqli_real_escape_string($drs_db,$display_functional_yes);
|
||||
// remove html tags from functional no and sanitize
|
||||
$display_functional_no=strip_tags($display_functional_no);
|
||||
$clean_display_functional_no=mysqli_real_escape_string($drs_db,$display_functional_no);
|
||||
// remove html tags from short functional yes and sanitize
|
||||
$display_functional_yes_short=strip_tags($display_functional_yes_short);
|
||||
$clean_display_functional_yes_short=mysqli_real_escape_string($drs_db,$display_functional_yes_short);
|
||||
// remove html tags from short functional no and sanitize
|
||||
$display_functional_no_short=strip_tags($display_functional_no_short);
|
||||
$clean_display_functional_no_short=mysqli_real_escape_string($drs_db,$display_functional_no_short);
|
||||
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_appname\" where name=\"app_name\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$display_banner\" where name=\"banner\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_footer\" where name=\"footer_message\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_pereffhlp\" where name=\"period_eff_help_txt\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_funchelp\" where name=\"functional_help_txt\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_device_term\" where name=\"device_term\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_discovered_term\" where name=\"discovered_term\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_discovered_term_short\" where name=\"discovered_term_short\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$display_disc_drop_data\" where name=\"disc_drop_data\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_functional_term\" where name=\"functional_term\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_functional_term_short\" where name=\"functional_term_short\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_functional_yes\" where name=\"functional_yes\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_functional_no\" where name=\"functional_no\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_functional_yes_short\" where name=\"functional_yes_short\"");
|
||||
mysqli_query($drs_db,"update config set value=\"$clean_display_functional_no_short\" where name=\"functional_no_short\"");
|
||||
|
||||
echo "<meta http-equiv='refresh' content='0'>";
|
||||
}
|
||||
|
||||
@@ -124,6 +198,7 @@ if ($add_banner) {
|
||||
// test for name supplied
|
||||
if (strlen(trim($bnrname))) {
|
||||
$namesuppld=true;
|
||||
$namesuppld_err=false;
|
||||
} else {
|
||||
$namesuppld=false;
|
||||
$namesuppld_err=true;
|
||||
@@ -134,6 +209,7 @@ if ($add_banner) {
|
||||
$nameunique_err=true;
|
||||
} else {
|
||||
$nameunique=true;
|
||||
$nameunique_err=false;
|
||||
}
|
||||
if ($namesuppld && $nameunique) {
|
||||
// sanitize banner name
|
||||
@@ -154,17 +230,19 @@ if ($edit_banner) {
|
||||
// test for name supplied
|
||||
if (strlen(trim($bnrname))) {
|
||||
$namesuppld=true;
|
||||
$namesuppld_err=false;
|
||||
} else {
|
||||
$namesuppld=false;
|
||||
$namesuppld_err=true;
|
||||
}
|
||||
// test for name unique
|
||||
if (mysqli_num_rows(mysqli_query($db,"select bannerid from banners where bannername=\"$bnrname\" and bannerid!=\"$bnrid\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select bannerid from banners where bannername=\"$bnrname\" and bannerid!=\"$bnrid\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select bannerid from banners where bannername=\"$bnrname\""))) {
|
||||
$nameunique=false;
|
||||
$nameunique_err=true;
|
||||
} else {
|
||||
$nameunique=true;
|
||||
$nameunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$nameunique=true;
|
||||
@@ -179,6 +257,9 @@ if ($edit_banner) {
|
||||
}
|
||||
|
||||
if ($update_misc) {
|
||||
if ($accessmode) {
|
||||
mysqli_query($drs_db,"update config set value=\"$accessmode\" where name=\"access_mode\"");
|
||||
}
|
||||
if ($logoutall) {
|
||||
if ($ostype == 'WIN') {
|
||||
$sessfileloc=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"win_server_session_dir\""))[0];
|
||||
@@ -196,20 +277,8 @@ if ($update_misc) {
|
||||
$ttlsuppld=false;
|
||||
$ttlsuppld_err=true;
|
||||
}
|
||||
// test for sessdir supplied
|
||||
if (strlen(trim($sessdir))) {
|
||||
$dirsuppld=true;
|
||||
} else {
|
||||
$dirsuppld=false;
|
||||
$dirsuppld_err=true;
|
||||
}
|
||||
if ($ttlsuppld && $dirsuppld) {
|
||||
if ($ttlsuppld) {
|
||||
mysqli_query($drs_db,"update config set value=\"$sessttl\" where name=\"session_ttl_days\"");
|
||||
if ($ostype == 'WIN') {
|
||||
mysqli_query($drs_db,"update config set value=\"$sessdir\" where name=\"win_server_session_dir\"");
|
||||
} else {
|
||||
mysqli_query($drs_db,"update config set value=\"$sessdir\" where name=\"unix_server_session_dir\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +308,18 @@ echo "
|
||||
$curapn=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"app_name\""))[0];
|
||||
$curbnr=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"banner\""))[0];
|
||||
$curftr=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"footer_message\""))[0];
|
||||
$curpereffhlp=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"period_eff_help_txt\""))[0];
|
||||
$curfunchelp=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"functional_help_txt\""))[0];
|
||||
$curdscterm=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"discovered_term\""))[0];
|
||||
$curdscterms=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"discovered_term_short\""))[0];
|
||||
$curdiscdropdata=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"disc_drop_data\""))[0];
|
||||
$curfuncterm=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"functional_term\""))[0];
|
||||
$curfuncterms=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"functional_term_short\""))[0];
|
||||
$curfuncyes=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"functional_yes\""))[0];
|
||||
$curfuncno=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"functional_no\""))[0];
|
||||
$curfuncyess=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"functional_yes_short\""))[0];
|
||||
$curfuncnos=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"functional_no_short\""))[0];
|
||||
$curdevterm=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"device_term\""))[0];
|
||||
|
||||
echo "
|
||||
<font size=\"+1\"><b>Display Configuration Parameters</b></font><br><br><br><br>
|
||||
";
|
||||
@@ -259,12 +339,37 @@ while ($bannerrow=mysqli_fetch_assoc($bannerqry)) {
|
||||
printf("<option value=\"%s\">%s</option>",$bannerrow["bannerid"],$bannerrow["bannername"]);
|
||||
}
|
||||
}
|
||||
|
||||
$dropnamestate=$dropdescstate="";
|
||||
if($curdiscdropdata=="Name") $dropnamestate="checked";
|
||||
if($curdiscdropdata=="Desc") $dropdescstate="checked";
|
||||
|
||||
echo "
|
||||
</select><br><br><br>
|
||||
Footer Message (will appear at the bottom of pages):<br>
|
||||
<input type=\"text\" name=\"display_footer\" size=\"80\" value=\"$curftr\"><br><br><br>
|
||||
Period Effective Help Text :<br>
|
||||
<textarea rows=\"4\" cols=\"80\" name=\"display_pereffhlp\" wrap=\"soft\">$curpereffhlp</textarea><br><br><br><br>
|
||||
Device Terminology :
|
||||
<input type=\"text\" name=\"display_device_term\" size=\"10\" value=\"$curdevterm\"><br><br><br>
|
||||
When Discovered Terminology :
|
||||
<input type=\"text\" name=\"display_discovered_term\" size=\"20\" value=\"$curdscterm\"><br><br><br>
|
||||
Short When Discovered Terminology (shown where space is limited, like table headers) :<br>
|
||||
<input type=\"text\" name=\"display_discovered_term_short\" size=\"9\" value=\"$curdscterms\"><br><br><br>
|
||||
When Discovered data to show in dropdowns: <input type=\"radio\" name=\"display_disc_drop_data\" value=\"Name\" $dropnamestate> Name
|
||||
<input type=\"radio\" name=\"display_disc_drop_data\" value=\"Desc\" $dropdescstate> Description<br><br><br>
|
||||
Functional Terminology :
|
||||
<input type=\"text\" name=\"display_functional_term\" size=\"20\" value=\"$curfuncterm\"><br><br><br>
|
||||
Short Functional Terminology (shown where space is limited, like table headers) :<br>
|
||||
<input type=\"text\" name=\"display_functional_term_short\" size=\"4\" value=\"$curfuncterms\"><br><br><br>
|
||||
Functional Yes Terminology :
|
||||
<input type=\"text\" name=\"display_functional_yes\" size=\"20\" value=\"$curfuncyes\"><br><br><br>
|
||||
Functional No Terminology :
|
||||
<input type=\"text\" name=\"display_functional_no\" size=\"20\" value=\"$curfuncno\"><br><br><br>
|
||||
Short Functional Yes Terminology (shown where space is limited, like table headers) :<br>
|
||||
<input type=\"text\" name=\"display_functional_yes_short\" size=\"4\" value=\"$curfuncyess\"><br><br><br>
|
||||
Short Functional No Terminology (shown where space is limited, like table headers) :<br>
|
||||
<input type=\"text\" name=\"display_functional_no_short\" size=\"4\" value=\"$curfuncnos\"><br><br><br>
|
||||
Functional Help Text :<br>
|
||||
<textarea rows=\"4\" cols=\"80\" name=\"display_funchelp\" wrap=\"soft\">$curfunchelp</textarea><br><br><br><br>
|
||||
<input type=\"submit\" name=\"update_display\" value=\"Update Options\">
|
||||
<input type=\"submit\" name=\"reset\" value=\"Reset\"><br><br><br>
|
||||
</form>
|
||||
@@ -450,17 +555,18 @@ echo "
|
||||
<form method=\"post\" action=\"config.php#miscellaneous\">
|
||||
";
|
||||
if ($ttlsuppld_err) format_message(1,"Session expiration time cannot be blank.");
|
||||
if ($dirsuppld_err) format_message(1,"Server session file directory cannot be blank.");
|
||||
|
||||
$curaccessmode=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"access_mode\""))[0];
|
||||
$trustedstate=$untrustedstate="";
|
||||
if($curaccessmode=="trusted") $trustedstate="checked";
|
||||
if($curaccessmode=="untrusted") $untrustedstate="checked";
|
||||
|
||||
$curttl=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"session_ttl_days\""))[0];
|
||||
if ($ostype == 'WIN') {
|
||||
$curssdir=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"win_server_session_dir\""))[0];
|
||||
} else {
|
||||
$curssdir=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"unix_server_session_dir\""))[0];
|
||||
}
|
||||
echo "
|
||||
<font size=\"+1\"><b>Miscellaneous Configuration Parameters</b></font><br><br><br><br>
|
||||
Access mode: <input type=\"radio\" name=\"accessmode\" value=\"trusted\" $trustedstate> Trusted
|
||||
<input type=\"radio\" name=\"accessmode\" value=\"untrusted\" $untrustedstate> Untrusted<br><br><br>
|
||||
Session expiration time (users will have to log in again after this long) : <input type=\"text\" name=\"sessttl\" size=\"3\" value=\"$curttl\"> days<br><br>
|
||||
Server session file directory (must be writable by the web server process) : <br><input type=\"text\" name=\"sessdir\" size=\"40\" value=\"$curssdir\"><br><br>
|
||||
Force logout of all users <input type=\"checkbox\" name=\"logoutall\"><br><br><br><br>
|
||||
<input type=\"submit\" name=\"update_misc\" value=\"Update Options\">
|
||||
<input type=\"submit\" name=\"reset\" value=\"Reset\"><br>
|
||||
|
||||
@@ -2,15 +2,29 @@
|
||||
/*
|
||||
create.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// redirect to writeups.php on change cancel
|
||||
if ($_REQUEST['cancel']) {
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:writeups.php");
|
||||
@@ -18,10 +32,14 @@ if ($_REQUEST['cancel']) {
|
||||
}
|
||||
|
||||
// import session variables
|
||||
if (isset($_SESSION['personid'])) $personid=$_SESSION['personid'];
|
||||
if (isset($_SESSION['userid'])) {
|
||||
$userid=$_SESSION['userid'];
|
||||
} else {
|
||||
$userid=NULL;
|
||||
}
|
||||
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming[]
|
||||
@@ -31,32 +49,46 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
$create=$incoming['create'];
|
||||
$device=$incoming['device'];
|
||||
$period=$incoming['period'];
|
||||
$period_effective=$incoming['period_effective'];
|
||||
$reported_by=$incoming['reported_by'];
|
||||
$report_date=$incoming['report_date'];
|
||||
$report_time=$incoming['report_time'];
|
||||
$subsystem=$incoming['subsystem'];
|
||||
$discrepancy_text=$incoming['discrepancy_text'];
|
||||
$status=$incoming['status'];
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
* create
|
||||
* device
|
||||
* discovered
|
||||
* functional
|
||||
* reported_by
|
||||
* report_date
|
||||
* report_time
|
||||
* subsystem
|
||||
* discrepancy_text
|
||||
* status
|
||||
*/
|
||||
|
||||
if (!isset($device)) $device=NULL;
|
||||
if (!isset($discovered)) $discovered=NULL;
|
||||
if (!isset($reported_by)) $reported_by=NULL;
|
||||
if (!isset($discrepancy_text)) $discrepancy_text=NULL;
|
||||
if (!isset($functional)) $functional=NULL;
|
||||
if (!isset($subsystem)) $subsystem=NULL;
|
||||
|
||||
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print=="Printer Friendly") {
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
}
|
||||
|
||||
$role=dblookup($drs_db,"persons","id","role",$personid);
|
||||
$role=dblookup($drs_db,"users","id","role",$userid);
|
||||
|
||||
framework("begin","$appname","New Writeup",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
@@ -64,17 +96,17 @@ framework("begin","$appname","New Writeup",$print);
|
||||
// determine today's date and make it the default
|
||||
$today=date("Y-m-d");
|
||||
$now=date("H:i:s");
|
||||
if (!$report_date || $report_date=="automatic") $report_date=$today;
|
||||
if (!$report_time || $report_time=="automatic") $report_time=$now;
|
||||
if (!isset($report_date) || $report_date=="automatic") $report_date=$today;
|
||||
if (!isset($report_time) || $report_time=="automatic") $report_time=$now;
|
||||
|
||||
if ($create) {
|
||||
if (isset($create)) {
|
||||
// add the entry if create is pressed
|
||||
if ($discrepancy_text && $reported_by && $device && $subsystem && $period) {
|
||||
if ($discrepancy_text!=NULL && $reported_by!=NULL && $device!=NULL && $subsystem!=NULL && $discovered!=NULL) {
|
||||
// sanitize and fix blank date and time
|
||||
$report_date=mysqli_real_escape_string($drs_db,$report_date);
|
||||
$report_time=mysqli_real_escape_string($drs_db,$report_time);
|
||||
if (!$report_date) $report_date=$today;
|
||||
if (!$report_time) $report_time=$now;
|
||||
if (!isset($report_date)) $report_date=$today;
|
||||
if (!isset($report_time)) $report_time=$now;
|
||||
|
||||
// remove html tags from discrepancy text and sanitize
|
||||
$discrepancy_text=strip_tags($discrepancy_text);
|
||||
@@ -82,8 +114,8 @@ if ($create) {
|
||||
$clean_reported_by=mysqli_real_escape_string($drs_db,$reported_by);
|
||||
|
||||
// add the record to writeups
|
||||
mysqli_query($drs_db,"insert into writeups(device,period,period_effective,reported_by,report_date,report_time,subsystem,discrepancy_text,status)
|
||||
values (\"$device\",\"$period\",\"$period_effective\",\"$clean_reported_by\",\"$report_date\",\"$report_time\",\"$subsystem\",\"$clean_discrepancy_text\",\"$status\")");
|
||||
mysqli_query($drs_db,"insert into writeups(device,discovered,functional,reported_by,report_date,report_time,subsystem,discrepancy_text,status)
|
||||
values (\"$device\",\"$discovered\",\"$functional\",\"$clean_reported_by\",\"$report_date\",\"$report_time\",\"$subsystem\",\"$clean_discrepancy_text\",\"$status\")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,33 +131,33 @@ pageblock("right","begin");
|
||||
banner($print);
|
||||
echo "<br>";
|
||||
// display the form
|
||||
if ($create) {
|
||||
if ($discrepancy_text && $reported_by) {
|
||||
if (isset($create)) {
|
||||
if ($discrepancy_text!=NULL && $reported_by!=NULL) {
|
||||
format_message(0,"<strong>Writeup created.</strong> You may create another writeup or <a href=\"writeups.php\">return to Open Writeups page.</a>");
|
||||
$preserve=FALSE;
|
||||
$preserve=false;
|
||||
}
|
||||
if (!$device) {
|
||||
format_message(1,"You didn't select a device. Please try again.");
|
||||
$preserve=TRUE;
|
||||
if ($device==NULL) {
|
||||
format_message(1,"You didn't select a $device_term. Please try again.");
|
||||
$preserve=true;
|
||||
}
|
||||
if (!$subsystem) {
|
||||
if ($subsystem==NULL) {
|
||||
format_message(1,"You didn't select a subsystem. Please try again.");
|
||||
$preserve=TRUE;
|
||||
$preserve=true;
|
||||
}
|
||||
if (!$period) {
|
||||
format_message(1,"You didn't select a period. Please try again.");
|
||||
$preserve=TRUE;
|
||||
if ($discovered==NULL) {
|
||||
format_message(1,"You didn't select a $discovered_term. Please try again.");
|
||||
$preserve=true;
|
||||
}
|
||||
if (!$discrepancy_text) {
|
||||
if ($discrepancy_text==NULL) {
|
||||
format_message(1,"You didn't enter any discrepancy text. Please try again.");
|
||||
$preserve=TRUE;
|
||||
$preserve=true;
|
||||
}
|
||||
if (!$reported_by) {
|
||||
if ($reported_by==NULL) {
|
||||
format_message(1,"You didn't enter your name in the Reported by: block. Please try again.");
|
||||
$preserve=TRUE;
|
||||
$preserve=true;
|
||||
}
|
||||
} else {
|
||||
$preserve=FALSE;
|
||||
$preserve=false;
|
||||
}
|
||||
|
||||
echo "
|
||||
@@ -133,14 +165,11 @@ echo "
|
||||
";
|
||||
|
||||
// start writeup entry section
|
||||
if ($status==1) $statusind="<b><font color=\"#FF0000\">OPEN</font></b>";
|
||||
if ($status==2) $statusind="<b><font color=\"#008000\">CLSD</font></b>";
|
||||
if ($status==3) $statusind="<b><font color=\"#FFFF00\">DFRD</font></b>";
|
||||
|
||||
echo "
|
||||
<table border=\"0\" cellpadding=\"5\">
|
||||
<tr>
|
||||
<td align=\"left\">Device<br>
|
||||
<td align=\"left\">$device_term<br>
|
||||
<select name=\"device\" id=\"device\">
|
||||
<option value=\"\">Please select...</option>
|
||||
";
|
||||
@@ -170,16 +199,23 @@ echo "
|
||||
</select></td><td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align=\"left\">Period<br>
|
||||
<select name=\"period\" id=\"period\">
|
||||
<td align=\"left\">$discovered_term<br>
|
||||
<select name=\"discovered\" id=\"discoveredselect\">
|
||||
<option value=\"\">Please select...</option>
|
||||
";
|
||||
$prow=mysqli_query($drs_db,"select * from periods where active is true order by times asc");
|
||||
while ($pitem=mysqli_fetch_assoc($prow)) {
|
||||
if ($period==$pitem["id"] && $preserve) {
|
||||
printf("<option value=\"%s\" title=\"Period %s\" selected>%s</option>",$pitem["id"],$pitem["id"],$pitem["times"]);
|
||||
if ($disc_drop_data=="Name") {
|
||||
$discddtitle="whendiscovereddesc";
|
||||
$discddtext="whendiscoveredname";
|
||||
} else if ($disc_drop_data=="Desc") {
|
||||
$discddtitle="whendiscoveredname";
|
||||
$discddtext="whendiscovereddesc";
|
||||
}
|
||||
$drow=mysqli_query($drs_db,"select * from discovered where active is true order by whendiscoveredname asc");
|
||||
while ($ditem=mysqli_fetch_assoc($drow)) {
|
||||
if ($discovered==$ditem["id"] && $preserve) {
|
||||
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$ditem["id"],$ditem["$discddtitle"],$ditem["$discddtext"]);
|
||||
} else {
|
||||
printf("<option value=\"%s\" title=\"Period %s\">%s</option>",$pitem["id"],$pitem["id"],$pitem["times"]);
|
||||
printf("<option value=\"%s\" title=\"%s\">%s</option>",$ditem["id"],$ditem["$discddtitle"],$ditem["$discddtext"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,20 +226,28 @@ if (!$preserve) {
|
||||
$reported_by="";
|
||||
}
|
||||
|
||||
$effstate=$nefstate="";
|
||||
$funcyesstate=$funcnostate="";
|
||||
if ($preserve) {
|
||||
if($period_effective==1) $effstate="checked";
|
||||
if($period_effective==0) $nefstate="checked";
|
||||
if($functional==1) $funcyesstate="checked";
|
||||
if($functional==0) $funcnostate="checked";
|
||||
} else {
|
||||
$effstate="checked";
|
||||
$funcyesstate="checked";
|
||||
}
|
||||
|
||||
echo "</select></td>";
|
||||
if (!$role) {
|
||||
$timedatedisable="disabled";
|
||||
} else {
|
||||
$timedatedisable="";
|
||||
}
|
||||
echo "
|
||||
</select></td>
|
||||
<td align=\"left\" >Report Date<br>
|
||||
<input type=\"text\" name=\"report_date\" size=\"10\" maxlength=\"10\" value=\"$report_date\" id=\"singledatepicker\" title=\"Format: YYYY-MM-DD\"></td>
|
||||
<input type=\"text\" name=\"report_date\" size=\"10\" maxlength=\"10\" value=\"$report_date\" id=\"singledatepicker\" title=\"Format: YYYY-MM-DD\" $timedatedisable></td>
|
||||
<td align=\"left\">Report Time<br>
|
||||
<input type=\"text\" name=\"report_time\" size=\"8\" maxlength=\"8\" value=\"$report_time\" title=\"Format: HH:MM:SS\"></td>
|
||||
<input type=\"text\" name=\"report_time\" size=\"8\" maxlength=\"8\" value=\"$report_time\" title=\"Format: HH:MM:SS\" $timedatedisable></td>
|
||||
";
|
||||
|
||||
echo "
|
||||
</tr>
|
||||
<tr><td></td><td></td><td></td></tr>
|
||||
<tr><td colspan=\"3\">
|
||||
@@ -213,9 +257,9 @@ Discrepancy <font size=\"-2\">(required)</font><br>
|
||||
<tr>
|
||||
<td>Reported by <font size=\"-2\">(required)</font><br>
|
||||
<input type=\"text\" name=\"reported_by\" size=\"30\" value=\"$reported_by\" title=\"Who to contact with questions about this writeup\"></td>
|
||||
<td>Period effective? <img src=\"icons/question.png\" title=\"" . PERIOD_EFF_HELP_TXT . "\"><br>
|
||||
<input type=\"radio\" name=\"period_effective\" value=\"1\" $effstate> Yes
|
||||
<input type=\"radio\" name=\"period_effective\" value=\"0\" $nefstate> No
|
||||
<td>$functional_term? <img src=\"icons/question.png\" title=\"" . FUNCTIONAL_HELP_TXT . "\"><br>
|
||||
<input type=\"radio\" name=\"functional\" value=\"1\" $funcyesstate> Yes
|
||||
<input type=\"radio\" name=\"functional\" value=\"0\" $funcnostate> No
|
||||
</td>
|
||||
<td align=\"right\" valign=\"bottom\"><input type=\"submit\" name=\"create\" value=\"Submit Writeup\" id=\"createbutton\"></td>
|
||||
</tr>
|
||||
|
||||
@@ -2,15 +2,29 @@
|
||||
/*
|
||||
dbadmin.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// redirect to index.php on cancel button press
|
||||
if ($_REQUEST['cancel']) {
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:index.php");
|
||||
@@ -30,7 +44,6 @@ if ($role != ADMIN) {
|
||||
}
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming[]
|
||||
@@ -40,52 +53,85 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
$edit_user=$incoming['edit_user'];
|
||||
$add_user=$incoming['add_user'];
|
||||
$update_user=$incoming['update_user'];
|
||||
$delete_user=$incoming['delete_user'];
|
||||
$user_id=$incoming['user_id'];
|
||||
$user_fname=$incoming['user_fname'];
|
||||
$user_lname=$incoming['user_lname'];
|
||||
$user_login=$incoming['user_login'];
|
||||
$user_pass=$incoming['user_pass'];
|
||||
$user_passconf=$incoming['user_passconf'];
|
||||
$user_role=$incoming['user_role'];
|
||||
$user_active=$incoming['user_active'];
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
* edit_user
|
||||
* add_user
|
||||
* update_user
|
||||
* delete_user
|
||||
* user_id
|
||||
* user_fname
|
||||
* user_lname
|
||||
* user_login
|
||||
* user_pass
|
||||
* user_passconf
|
||||
* user_role
|
||||
* user_active
|
||||
* edit_device
|
||||
* add_device
|
||||
* update_device
|
||||
* delete_device
|
||||
* device_id
|
||||
* device_name
|
||||
* device_active
|
||||
* edit_subsystem
|
||||
* add_subsystem
|
||||
* update_subsystem
|
||||
* delete_subsystem
|
||||
* subsystem_id
|
||||
* subsystem_name
|
||||
* subsystem_desc
|
||||
* subsystem_active
|
||||
* edit_reason
|
||||
* add_reason
|
||||
* update_reason
|
||||
* delete_reason
|
||||
* reason_id
|
||||
* reason_text
|
||||
* reason_active
|
||||
* edit_discovered
|
||||
* add_discovered
|
||||
* update_discovered
|
||||
* delete_discovered
|
||||
* discovered_id
|
||||
* discovered_name
|
||||
* discovered_desc
|
||||
* discovered_active
|
||||
*/
|
||||
|
||||
$edit_device=$incoming['edit_device'];
|
||||
$add_device=$incoming['add_device'];
|
||||
$update_device=$incoming['update_device'];
|
||||
$delete_device=$incoming['delete_device'];
|
||||
$device_id=$incoming['device_id'];
|
||||
$device_name=$incoming['device_name'];
|
||||
$device_active=$incoming['device_active'];
|
||||
|
||||
$edit_subsystem=$incoming['edit_subsystem'];
|
||||
$add_subsystem=$incoming['add_subsystem'];
|
||||
$update_subsystem=$incoming['update_subsystem'];
|
||||
$delete_subsystem=$incoming['delete_subsystem'];
|
||||
$subsystem_id=$incoming['subsystem_id'];
|
||||
$subsystem_name=$incoming['subsystem_name'];
|
||||
$subsystem_desc=$incoming['subsystem_desc'];
|
||||
$subsystem_active=$incoming['subsystem_active'];
|
||||
|
||||
$edit_reason=$incoming['edit_reason'];
|
||||
$add_reason=$incoming['add_reason'];
|
||||
$update_reason=$incoming['update_reason'];
|
||||
$delete_reason=$incoming['delete_reason'];
|
||||
$reason_id=$incoming['reason_id'];
|
||||
$reason_text=$incoming['reason_text'];
|
||||
$reason_active=$incoming['reason_active'];
|
||||
|
||||
$edit_period=$incoming['edit_period'];
|
||||
$add_period=$incoming['add_period'];
|
||||
$update_period=$incoming['update_period'];
|
||||
$delete_period=$incoming['delete_period'];
|
||||
$period_id=$incoming['period_id'];
|
||||
$period_times=$incoming['period_times'];
|
||||
$period_active=$incoming['period_active'];
|
||||
if (!isset($edit_user)) $edit_user=false;
|
||||
if (!isset($add_user)) $add_user=false;
|
||||
if (!isset($update_user)) $update_user=false;
|
||||
if (!isset($delete_user)) $delete_user=false;
|
||||
if (!isset($edit_device)) $edit_device=false;
|
||||
if (!isset($add_device)) $add_device=false;
|
||||
if (!isset($update_device)) $update_device=false;
|
||||
if (!isset($delete_device)) $delete_device=false;
|
||||
if (!isset($edit_subsystem)) $edit_subsystem=false;
|
||||
if (!isset($add_subsystem)) $add_subsystem=false;
|
||||
if (!isset($update_subsystem)) $update_subsystem=false;
|
||||
if (!isset($delete_subsystem)) $delete_subsystem=false;
|
||||
if (!isset($edit_reason)) $edit_reason=false;
|
||||
if (!isset($add_reason)) $add_reason=false;
|
||||
if (!isset($update_reason)) $update_reason=false;
|
||||
if (!isset($delete_reason)) $delete_reason=false;
|
||||
if (!isset($edit_discovered)) $edit_discovered=false;
|
||||
if (!isset($add_discovered)) $add_discovered=false;
|
||||
if (!isset($update_discovered)) $update_discovered=false;
|
||||
if (!isset($delete_discovered)) $delete_discovered=false;
|
||||
if (!isset($user_fname)) $user_fname=NULL;
|
||||
if (!isset($user_lname)) $user_lname=NULL;
|
||||
if (!isset($user_login)) $user_login=NULL;
|
||||
if (!isset($user_pass)) $user_pass=NULL;
|
||||
if (!isset($user_passconf)) $user_passconf=NULL;
|
||||
if (!isset($device_name)) $device_name=NULL;
|
||||
if (!isset($subsystem_name)) $subsystem_name=NULL;
|
||||
if (!isset($subsystem_desc)) $subsystem_desc=NULL;
|
||||
if (!isset($reason_text)) $reason_text=NULL;
|
||||
if (!isset($discovered_name)) $discovered_name=NULL;
|
||||
if (!isset($discovered_desc)) $discovered_desc=NULL;
|
||||
|
||||
// define local functions
|
||||
|
||||
@@ -93,7 +139,7 @@ $period_active=$incoming['period_active'];
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print=="Printer Friendly") {
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
@@ -101,12 +147,19 @@ if ($print=="Printer Friendly") {
|
||||
|
||||
framework("begin","$appname","Database Administration",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
|
||||
// users-------------------------------------
|
||||
$usernameunique_err=$fnamesuppld_err=$lnamesuppld_err=false;
|
||||
$loginsuppld_err=$loginunique_err=$passcomplex_err=$passmatch_err=false;
|
||||
$userhaswriteups_err=false;
|
||||
$user_add_fail=false;
|
||||
|
||||
if ($add_user) {
|
||||
// do error checking
|
||||
// remove html tags from user name
|
||||
@@ -116,6 +169,7 @@ if ($add_user) {
|
||||
// test for first name supplied
|
||||
if (strlen(trim($user_fname))) {
|
||||
$fnamesuppld=true;
|
||||
$fnamesuppld_err=false;
|
||||
} else {
|
||||
$fnamesuppld=false;
|
||||
$fnamesuppld_err=true;
|
||||
@@ -123,6 +177,7 @@ if ($add_user) {
|
||||
// test for last name supplied
|
||||
if (strlen(trim($user_lname))) {
|
||||
$lnamesuppld=true;
|
||||
$lnamesuppld_err=false;
|
||||
} else {
|
||||
$lnamesuppld=false;
|
||||
$lnamesuppld_err=true;
|
||||
@@ -133,10 +188,12 @@ if ($add_user) {
|
||||
$usernameunique_err=true;
|
||||
} else {
|
||||
$usernameunique=true;
|
||||
$usernameunique_err=false;
|
||||
}
|
||||
// test for login supplied
|
||||
if (strlen(trim($user_login))) {
|
||||
$loginsuppld=true;
|
||||
$loginsuppld_err=false;
|
||||
} else {
|
||||
$loginsuppld=false;
|
||||
$loginsuppld_err=true;
|
||||
@@ -147,27 +204,30 @@ if ($add_user) {
|
||||
$loginunique_err=true;
|
||||
} else {
|
||||
$loginunique=true;
|
||||
$loginunique_err=false;
|
||||
}
|
||||
// test passwords
|
||||
$passresults=validate_password($user_pass,$user_passconf);
|
||||
if ($passresults['match']) {
|
||||
$passmatch=true;
|
||||
$passmatch_err=false;
|
||||
} else {
|
||||
$passmatch=false;
|
||||
$passmatch_err=true;
|
||||
}
|
||||
if ($passresults['complex']) {
|
||||
$passcomplex=true;
|
||||
$passcomplex_err=false;
|
||||
} else {
|
||||
$passcomplex=false;
|
||||
$passcomplex_err=true;
|
||||
}
|
||||
|
||||
// set role
|
||||
if (!$user_role) $user_role=USER;
|
||||
if (!isset($user_role)) $user_role=USER;
|
||||
|
||||
// set active status
|
||||
if (!$user_active) $user_active=0;
|
||||
if (!isset($user_active)) $user_active=0;
|
||||
|
||||
if ($fnamesuppld && $lnamesuppld && $usernameunique && $loginsuppld && $loginunique && $passcomplex && $passmatch) {
|
||||
// sanitize first name, last name, login
|
||||
@@ -178,6 +238,7 @@ if ($add_user) {
|
||||
$passhash=password_hash($user_pass,PASSWORD_DEFAULT);
|
||||
// modify the table
|
||||
mysqli_query($drs_db,"insert into users(firstname,lastname,login,password_hash,role,active) values(\"$clean_fname\",\"$clean_lname\",\"$clean_login\",\"$passhash\",\"$user_role\",\"$user_active\")");
|
||||
$user_add_fail=false;
|
||||
} else {
|
||||
$user_add_fail=true;
|
||||
}
|
||||
@@ -191,6 +252,7 @@ if ($edit_user) {
|
||||
$userhaswriteups_err=true;
|
||||
} else {
|
||||
$userhaswriteups=false;
|
||||
$userhaswriteups_err=false;
|
||||
}
|
||||
// if none, then remove from db
|
||||
if (!$userhaswriteups) mysqli_query($drs_db,"delete from users where id=\"$user_id\"");
|
||||
@@ -204,6 +266,7 @@ if ($edit_user) {
|
||||
// test for first name supplied
|
||||
if (strlen(trim($user_fname))) {
|
||||
$fnamesuppld=true;
|
||||
$fnamesuppld_err=false;
|
||||
} else {
|
||||
$fnamesuppld=false;
|
||||
$fnamesuppld_err=true;
|
||||
@@ -211,6 +274,7 @@ if ($edit_user) {
|
||||
// test for last name supplied
|
||||
if (strlen(trim($user_lname))) {
|
||||
$lnamesuppld=true;
|
||||
$lnamesuppld_err=false;
|
||||
} else {
|
||||
$lnamesuppld=false;
|
||||
$lnamesuppld_err=true;
|
||||
@@ -218,17 +282,20 @@ if ($edit_user) {
|
||||
// test for name unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from users where firstname=\"$user_fname\" and lastname=\"$user_lname\" and id!=\"$user_id\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from users where firstname=\"$user_fname\" and lastname=\"$user_lname\""))) {
|
||||
$nameunique=false;
|
||||
$nameunique_err=true;
|
||||
$nameunique=false;
|
||||
$nameunique_err=true;
|
||||
} else {
|
||||
$nameunique=true;
|
||||
$nameunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$nameunique=true;
|
||||
$nameunique_err=false;
|
||||
}
|
||||
// test for login supplied
|
||||
if (strlen(trim($user_login))) {
|
||||
$loginsuppld=true;
|
||||
$loginsuppld_err=false;
|
||||
} else {
|
||||
$loginsuppld=false;
|
||||
$loginsuppld_err=true;
|
||||
@@ -240,9 +307,11 @@ if ($edit_user) {
|
||||
$loginunique_err=true;
|
||||
} else {
|
||||
$loginunique=true;
|
||||
$loginunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$loginunique=true;
|
||||
$loginunique_err=false;
|
||||
}
|
||||
// sanitize first name, last name, login
|
||||
$clean_fname=mysqli_real_escape_string($drs_db,$user_fname);
|
||||
@@ -250,22 +319,24 @@ if ($edit_user) {
|
||||
$clean_login=mysqli_real_escape_string($drs_db,$user_login);
|
||||
|
||||
// set role
|
||||
if (!$user_role) $user_role=USER;
|
||||
if (!isset($user_role)) $user_role=USER;
|
||||
|
||||
// set active status
|
||||
if (!$user_active) $user_active=0;
|
||||
if (!isset($user_active)) $user_active=0;
|
||||
|
||||
if ($user_pass!="password_is_unchanged") {
|
||||
// test passwords
|
||||
$passresults=validate_password($user_pass,$user_passconf);
|
||||
if ($passresults['match']) {
|
||||
$passmatch=true;
|
||||
$passmatch_err=false;
|
||||
} else {
|
||||
$passmatch=false;
|
||||
$passmatch_err=true;
|
||||
}
|
||||
if ($passresults['complex']) {
|
||||
$passcomplex=true;
|
||||
$passcomplex_err=false;
|
||||
} else {
|
||||
$passcomplex=false;
|
||||
$passcomplex_err=true;
|
||||
@@ -287,6 +358,10 @@ if ($edit_user) {
|
||||
}
|
||||
|
||||
// devices-------------------------------
|
||||
$devicenameunique_err=$devicenamesuppld_err=false;
|
||||
$devicehaswriteups_err=false;
|
||||
$device_add_fail=false;
|
||||
|
||||
if ($add_device) {
|
||||
// do error checking
|
||||
// remove html tags from device name
|
||||
@@ -294,6 +369,7 @@ if ($add_device) {
|
||||
// test for device name supplied
|
||||
if (strlen(trim($device_name))) {
|
||||
$devicenamesuppld=true;
|
||||
$devicenamesuppld_err=false;
|
||||
} else {
|
||||
$devicenamesuppld=false;
|
||||
$devicenamesuppld_err=true;
|
||||
@@ -304,16 +380,18 @@ if ($add_device) {
|
||||
$devicenameunique_err=true;
|
||||
} else {
|
||||
$devicenameunique=true;
|
||||
$devicenameunique_err=false;
|
||||
}
|
||||
|
||||
// set active status
|
||||
if (!$device_active) $device_active=0;
|
||||
if (!isset($device_active)) $device_active=0;
|
||||
|
||||
if ($devicenamesuppld && $devicenameunique) {
|
||||
// sanitize device name
|
||||
$clean_devicename=mysqli_real_escape_string($drs_db,$device_name);
|
||||
// modify the table
|
||||
mysqli_query($drs_db,"insert into devices(name,active) values(\"$clean_devicename\",\"$device_active\")");
|
||||
$device_add_fail=false;
|
||||
} else {
|
||||
$device_add_fail=true;
|
||||
}
|
||||
@@ -326,6 +404,7 @@ if ($edit_device) {
|
||||
$devicehaswriteups_err=true;
|
||||
} else {
|
||||
$devicehaswriteups=false;
|
||||
$devicehaswriteups_err=false;
|
||||
}
|
||||
// if none, then remove from db
|
||||
if (!$devicehaswriteups) mysqli_query($drs_db,"delete from devices where id=\"$device_id\"");
|
||||
@@ -337,6 +416,7 @@ if ($edit_device) {
|
||||
// test for device name supplied
|
||||
if (strlen(trim($device_name))) {
|
||||
$devicenamesuppld=true;
|
||||
$devicenamesuppld_err=false;
|
||||
} else {
|
||||
$devicenamesuppld=false;
|
||||
$devicenamesuppld_err=true;
|
||||
@@ -344,17 +424,19 @@ if ($edit_device) {
|
||||
// test for device name unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from devices where name=\"$device_name\" and id!=\"$device_id\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from devices where name=\"$device_name\""))) {
|
||||
$devicenameunique=false;
|
||||
$devicenameunique_err=true;
|
||||
$devicenameunique=false;
|
||||
$devicenameunique_err=true;
|
||||
} else {
|
||||
$devicenameunique=true;
|
||||
$devicenameunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$devicenameunique=true;
|
||||
$devicenameunique_err=false;
|
||||
}
|
||||
|
||||
// set active status
|
||||
if (!$user_active) $user_active=0;
|
||||
if (!isset($device_active)) $device_active=0;
|
||||
|
||||
// sanitize device name
|
||||
$clean_devicename=mysqli_real_escape_string($drs_db,$device_name);
|
||||
@@ -367,6 +449,10 @@ if ($edit_device) {
|
||||
}
|
||||
|
||||
// subsystems--------------------------------
|
||||
$ssnameunique_err=$ssnamesuppld_err=false;
|
||||
$sshaswriteups_err=false;
|
||||
$subsystem_add_fail=false;
|
||||
|
||||
if ($add_subsystem) {
|
||||
// do error checking
|
||||
// remove html tags from subsystem name and description
|
||||
@@ -375,6 +461,7 @@ if ($add_subsystem) {
|
||||
// test for subsystem name supplied
|
||||
if (strlen(trim($subsystem_name))) {
|
||||
$ssnamesuppld=true;
|
||||
$ssnamesuppld_err=false;
|
||||
} else {
|
||||
$ssnamesuppld=false;
|
||||
$ssnamesuppld_err=true;
|
||||
@@ -385,10 +472,11 @@ if ($add_subsystem) {
|
||||
$ssnameunique_err=true;
|
||||
} else {
|
||||
$ssnameunique=true;
|
||||
$ssnameunique_err=false;
|
||||
}
|
||||
|
||||
// set active status
|
||||
if (!$subsystem_active) $subsystem_active=0;
|
||||
if (!isset($subsystem_active)) $subsystem_active=0;
|
||||
|
||||
if ($ssnamesuppld && $ssnameunique) {
|
||||
// sanitize subsystem name and description
|
||||
@@ -396,6 +484,7 @@ if ($add_subsystem) {
|
||||
$clean_subsystemdesc=mysqli_real_escape_string($drs_db,$subsystem_desc);
|
||||
// modify the table
|
||||
mysqli_query($drs_db,"insert into subsystems(name,description,active) values(\"$clean_subsystemname\",\"$clean_subsystemdesc\",\"$subsystem_active\")");
|
||||
$subsystem_add_fail=false;
|
||||
} else {
|
||||
$subsystem_add_fail=true;
|
||||
}
|
||||
@@ -408,6 +497,7 @@ if ($edit_subsystem) {
|
||||
$sshaswriteups_err=true;
|
||||
} else {
|
||||
$sshaswriteups=false;
|
||||
$sshaswriteups_err=false;
|
||||
}
|
||||
// if none, then remove from db
|
||||
if (!$sshaswriteups) mysqli_query($drs_db,"delete from subsystems where id=\"$subsystem_id\"");
|
||||
@@ -420,6 +510,7 @@ if ($edit_subsystem) {
|
||||
// test for subsystem name supplied
|
||||
if (strlen(trim($subsystem_name))) {
|
||||
$ssnamesuppld=true;
|
||||
$ssnamesuppld_err=false;
|
||||
} else {
|
||||
$ssnamesuppld=false;
|
||||
$ssnamesuppld_err=true;
|
||||
@@ -427,13 +518,15 @@ if ($edit_subsystem) {
|
||||
// test for subsystem name unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from subsystems where name=\"$subsystem_name\" and id!=\"$subsystem_id\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from subsystems where name=\"$subsystem_name\""))) {
|
||||
$ssnameunique=false;
|
||||
$ssnameunique_err=true;
|
||||
$ssnameunique=false;
|
||||
$ssnameunique_err=true;
|
||||
} else {
|
||||
$ssnameunique=true;
|
||||
$ssnameunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$ssnameunique=true;
|
||||
$ssnameunique_err=false;
|
||||
}
|
||||
// sanitize subsystem name and description
|
||||
$clean_ssname=mysqli_real_escape_string($drs_db,$subsystem_name);
|
||||
@@ -447,6 +540,10 @@ if ($edit_subsystem) {
|
||||
}
|
||||
|
||||
// reasons------------------------------------
|
||||
$reastextunique_err=$reastextsuppld_err=false;
|
||||
$reashaswriteups_err=false;
|
||||
$reason_add_fail=false;
|
||||
|
||||
if ($add_reason) {
|
||||
// do error checking
|
||||
// remove html tags from reason text
|
||||
@@ -454,6 +551,7 @@ if ($add_reason) {
|
||||
// test for reason text supplied
|
||||
if (strlen(trim($reason_text))) {
|
||||
$reastextsuppld=true;
|
||||
$reastextsuppld_err=false;
|
||||
} else {
|
||||
$reastextsuppld=false;
|
||||
$reastextsuppld_err=true;
|
||||
@@ -464,16 +562,18 @@ if ($add_reason) {
|
||||
$reastextunique_err=true;
|
||||
} else {
|
||||
$reastextunique=true;
|
||||
$reastextunique_err=false;
|
||||
}
|
||||
|
||||
// set active status
|
||||
if (!$reason_active) $reason_active=0;
|
||||
if (!isset($reason_active)) $reason_active=0;
|
||||
|
||||
if ($reastextsuppld && $reastextunique) {
|
||||
// sanitize reason text
|
||||
$clean_reastext=mysqli_real_escape_string($drs_db,$reason_text);
|
||||
// modify the table
|
||||
mysqli_query($drs_db,"insert into reasons(text,active) values(\"$clean_reastext\",\"$reason_active\")");
|
||||
$reason_add_fail=false;
|
||||
} else {
|
||||
$reason_add_fail=true;
|
||||
}
|
||||
@@ -486,6 +586,7 @@ if ($edit_reason) {
|
||||
$reashaswriteups_err=true;
|
||||
} else {
|
||||
$reashaswriteups=false;
|
||||
$reashaswriteups_err=false;
|
||||
}
|
||||
// if none, then remove from db
|
||||
if (!$reashaswriteups) mysqli_query($drs_db,"delete from reasons where id=\"$reason_id\"");
|
||||
@@ -497,6 +598,7 @@ if ($edit_reason) {
|
||||
// test for reason text supplied
|
||||
if (strlen(trim($reason_text))) {
|
||||
$reastextsuppld=true;
|
||||
$reastextsuppld_err=false;
|
||||
} else {
|
||||
$reastextsuppld=false;
|
||||
$reastextsuppld_err=true;
|
||||
@@ -508,13 +610,15 @@ if ($edit_reason) {
|
||||
$reastextunique_err=true;
|
||||
} else {
|
||||
$reastextunique=true;
|
||||
$reastextunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$reastextunique=true;
|
||||
$reastextunique_err=false;
|
||||
}
|
||||
|
||||
// set active status
|
||||
if (!$reason_active) $reason_active=0;
|
||||
if (!isset($reason_active)) $reason_active=0;
|
||||
|
||||
// sanitize reason text
|
||||
$clean_reastext=mysqli_real_escape_string($drs_db,$reason_text);
|
||||
@@ -526,102 +630,122 @@ if ($edit_reason) {
|
||||
}
|
||||
}
|
||||
|
||||
// periods-----------------------------------
|
||||
if ($add_period) {
|
||||
// when discovered-----------------------------------
|
||||
$discnamesuppld_err=$discnameunique_err=$discdescsuppld_err=false;
|
||||
$dischaswriteups_err=false;
|
||||
$discovered_add_fail=false;
|
||||
|
||||
if ($add_discovered) {
|
||||
// do error checking
|
||||
// remove html tags from id and times
|
||||
$period_id=strip_tags($period_id);
|
||||
$period_times=strip_tags($period_times);
|
||||
// test for id supplied
|
||||
if (strlen(trim($period_id))) {
|
||||
$peridsuppld=true;
|
||||
// remove html tags from name and description
|
||||
$discovered_name=strip_tags($discovered_name);
|
||||
$discovered_desc=strip_tags($discovered_desc);
|
||||
// test for name supplied
|
||||
if (strlen(trim($discovered_name))) {
|
||||
$discnamesuppld=true;
|
||||
$discnamesuppld_err=false;
|
||||
} else {
|
||||
$peridsuppld=false;
|
||||
$peridsuppld_err=true;
|
||||
$discnamesuppld=false;
|
||||
$discnamesuppld_err=true;
|
||||
}
|
||||
// test for id is integer
|
||||
if (preg_match('/^[0-9]+$/',$period_id)) {
|
||||
$peridisint=true;
|
||||
// test for name unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscoveredname=\"$discovered_name\""))) {
|
||||
$discnameunique=false;
|
||||
$discnameunique_err=true;
|
||||
} else {
|
||||
$peridisint=false;
|
||||
$peridisint_err=true;
|
||||
$discnameunique=true;
|
||||
$discnameunique_err=false;
|
||||
}
|
||||
// test for id unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from periods where id=\"$period_id\""))) {
|
||||
$peridunique=false;
|
||||
$peridunique_err=true;
|
||||
// test for description supplied
|
||||
if (strlen(trim($discovered_desc))) {
|
||||
$discdescsuppld=true;
|
||||
$discdescsuppld_err=false;
|
||||
} else {
|
||||
$peridunique=true;
|
||||
$discdescsuppld=false;
|
||||
$discdescsuppld_err=true;
|
||||
}
|
||||
// test for times supplied
|
||||
if (strlen(trim($period_times))) {
|
||||
$pertimessuppld=true;
|
||||
// test for description unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscovereddesc =\"$discovered_desc\""))) {
|
||||
$discdescunique=false;
|
||||
$discdescunique_err=true;
|
||||
} else {
|
||||
$pertimessuppld=false;
|
||||
$pertimessuppld_err=true;
|
||||
}
|
||||
// test for times unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from periods where times=\"$period_times\""))) {
|
||||
$pertimesunique=false;
|
||||
$pertimesunique_err=true;
|
||||
} else {
|
||||
$pertimesunique=true;
|
||||
$discdescunique=true;
|
||||
$discdescunique_err=false;
|
||||
}
|
||||
|
||||
// set active status
|
||||
if (!$period_active) $period_active=0;
|
||||
if (!isset($discovered_active)) $discovered_active=0;
|
||||
|
||||
if ($pertimessuppld && $pertimesunique && $peridsuppld && $peridunique && $peridisint) {
|
||||
// sanitize times
|
||||
$clean_pertimes=mysqli_real_escape_string($drs_db,$period_times);
|
||||
if ($discnamesuppld && $discnameunique && $discdescsuppld) {
|
||||
// sanitize name
|
||||
$clean_discovered_name=mysqli_real_escape_string($drs_db,$discovered_name);
|
||||
// sanitize description
|
||||
$clean_discovered_desc=mysqli_real_escape_string($drs_db,$discovered_desc);
|
||||
// modify the table
|
||||
mysqli_query($drs_db,"insert into periods(id,times,active) values(\"$period_id\",\"$clean_pertimes\",\"$period_active\")");
|
||||
mysqli_query($drs_db,"insert into discovered(whendiscoveredname,whendiscovereddesc,active) values(\"$clean_discovered_name\",\"$clean_discovered_desc\",\"$discovered_active\")");
|
||||
$discovered_add_fail=false;
|
||||
} else {
|
||||
$period_add_fail=true;
|
||||
$discovered_add_fail=true;
|
||||
}
|
||||
}
|
||||
if ($edit_period) {
|
||||
if ($delete_period) {
|
||||
// check for writeups with this period
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from writeups where period=\"$period_id\""))) {
|
||||
$perhaswriteups=true;
|
||||
$perhaswriteups_err=true;
|
||||
if ($edit_discovered) {
|
||||
if ($delete_discovered) {
|
||||
// check for writeups with this when discovered
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from writeups where discovered=\"$discovered_id\""))) {
|
||||
$dischaswriteups=true;
|
||||
$dischaswriteups_err=true;
|
||||
} else {
|
||||
$perhaswriteups=false;
|
||||
$dischaswriteups=false;
|
||||
$dischaswriteups_err=false;
|
||||
}
|
||||
// if none, then remove from db
|
||||
if (!$perhaswriteups) mysqli_query($drs_db,"delete from periods where id=\"$period_id\"");
|
||||
if (!$dischaswriteups) mysqli_query($drs_db,"delete from discovered where id=\"$discovered_id\"");
|
||||
}
|
||||
if ($update_period) {
|
||||
if ($update_discovered) {
|
||||
// do error checking
|
||||
// remove html tags from times
|
||||
$period_times=strip_tags($period_times);
|
||||
// test for times supplied
|
||||
if (strlen(trim($period_times))) {
|
||||
$pertimessuppld=true;
|
||||
} else {
|
||||
$pertimessuppld=false;
|
||||
$pertimessuppld_err=true;
|
||||
}
|
||||
// test for period times unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from periods where times=\"$period_times\" and id!=\"$period_id\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from periods where times=\"$period_times\""))) {
|
||||
$pertimesunique=false;
|
||||
$pertimesunique_err=true;
|
||||
} else {
|
||||
$pertimesunique=true;
|
||||
}
|
||||
} else {
|
||||
$pertimesunique=true;
|
||||
}
|
||||
// remove html tags from name and description
|
||||
$discovered_name=strip_tags($discovered_name);
|
||||
$discovered_desc=strip_tags($discovered_desc);
|
||||
// test for name supplied
|
||||
if (strlen(trim($discovered_name))) {
|
||||
$discnamesuppld=true;
|
||||
$discnamesuppld_err=false;
|
||||
} else {
|
||||
$discnamesuppld=false;
|
||||
$discnamesuppld_err=true;
|
||||
}
|
||||
// test for name unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscoveredname=\"$discovered_name\" and id!=\"$discovered_id\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscoveredname=\"$discovered_name\""))) {
|
||||
$discnameunique=false;
|
||||
$discnameunique_err=true;
|
||||
} else {
|
||||
$discnameunique=true;
|
||||
$discnameunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$discnameunique=true;
|
||||
$discnameunique_err=false;
|
||||
}
|
||||
// test for description supplied
|
||||
if (strlen(trim($discovered_desc))) {
|
||||
$discdescsuppld=true;
|
||||
$discdescsuppld_err=false;
|
||||
} else {
|
||||
$discdescsuppld=false;
|
||||
$discdescsuppld_err=true;
|
||||
}
|
||||
|
||||
// set active status
|
||||
if (!$period_active) $period_active=0;
|
||||
// set active status
|
||||
if (!isset($discovered_active)) $discovered_active=0;
|
||||
|
||||
// sanitize times
|
||||
$clean_pertimes=mysqli_real_escape_string($drs_db,$period_times);
|
||||
$updqry="update periods set times=\"$clean_pertimes\",active=\"$period_active\" where id=\"$period_id\"";
|
||||
if ($pertimessuppld && $pertimesunique) {
|
||||
// sanitize name
|
||||
$clean_discovered_name=mysqli_real_escape_string($drs_db,$discovered_name);
|
||||
// sanitize description
|
||||
$clean_discovered_desc=mysqli_real_escape_string($drs_db,$discovered_desc);
|
||||
|
||||
$updqry="update discovered set whendiscoveredname=\"$clean_discovered_name\",whendiscovereddesc=\"$clean_discovered_desc\",active=\"$discovered_active\" where id=\"$discovered_id\"";
|
||||
if ($discnamesuppld && $discnameunique && $discdescsuppld) {
|
||||
// modify the table
|
||||
mysqli_query($drs_db,$updqry);
|
||||
}
|
||||
@@ -646,7 +770,7 @@ echo "
|
||||
<li><a href=\"#devices\">Device Management</a></li>
|
||||
<li><a href=\"#subsystems\">Subsystem Management</a></li>
|
||||
<li><a href=\"#reasons\">Action Reasons Management</a></li>
|
||||
<li><a href=\"#periods\">Period Management</a></li>
|
||||
<li><a href=\"#discovered\">When Discovered Management</a></li>
|
||||
</ul>
|
||||
|
||||
<div id=\"users\">
|
||||
@@ -688,7 +812,7 @@ if ($edit_user && !$delete_user) {
|
||||
}
|
||||
} else {
|
||||
// set form options for add
|
||||
if (!$user_add_fail) unset($user_id,$user_fname,$user_lname,$user_login,$user_pass,$user_passconf,$user_role,$user_active);
|
||||
if (!$user_add_fail) $user_id=$user_fname=$user_lname=$user_login=$user_pass=$user_passconf=$user_role=$user_active=NULL;
|
||||
$sectiontitle="<b><font size=\"+1\">Add New User</font></b><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php#users\">";
|
||||
$buttontags="
|
||||
@@ -793,7 +917,7 @@ if ($edit_device && !$delete_device) {
|
||||
}
|
||||
} else {
|
||||
// set form options for add
|
||||
if (!$device_add_fail) unset($device_id,$device_name,$device_active);
|
||||
if (!$device_add_fail) $device_id=$device_name=$device_active=NULL;
|
||||
$sectiontitle="<b><font size=\"+1\">Add New Device</font></b><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php#devices\">";
|
||||
$buttontags="
|
||||
@@ -870,7 +994,7 @@ if ($edit_subsystem && !$delete_subsystem) {
|
||||
}
|
||||
} else {
|
||||
// set form options for add
|
||||
if (!$subsystem_add_fail) unset($subsystem_id,$subsystem_name,$subsystem_desc,$subsystem_active);
|
||||
if (!$subsystem_add_fail) $subsystem_id=$subsystem_name=$subsystem_desc=$subsystem_active=NULL;
|
||||
$sectiontitle="<b><font size=\"+1\">Add New Subsystem</font></b><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php#subsystems\">";
|
||||
$buttontags="
|
||||
@@ -950,7 +1074,7 @@ if ($edit_reason && !$delete_reason) {
|
||||
}
|
||||
} else {
|
||||
// set form options for add
|
||||
if (!$reason_add_fail) unset($reason_id,$reason_text,$reason_active);
|
||||
if (!$reason_add_fail) $reason_id=$reason_text=$reason_active=NULL;
|
||||
$sectiontitle="<b><font size=\"+1\">Add New Reason</font></b><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php#reasons\">";
|
||||
$buttontags="
|
||||
@@ -1001,53 +1125,50 @@ echo "</table>";
|
||||
echo "
|
||||
</div>
|
||||
|
||||
<div id=\"periods\">
|
||||
<div id=\"discovered\">
|
||||
";
|
||||
if ($peridisint_err) format_message(1,"Period number must be an integer.");
|
||||
if ($peridsuppld_err) format_message(1,"Period number cannot be blank.");
|
||||
if ($peridunique_err) format_message(1,"Period number already exists.");
|
||||
if ($pertimesunique_err) format_message(1,"Period already exists.");
|
||||
if ($pertimessuppld_err) format_message(1,"Period times cannot be blank.");
|
||||
if ($perhaswriteups_err) format_message(1,"Period has writeups in the database and cannot be deleted.");
|
||||
if ($discnamesuppld_err) format_message(1,"When Discovered name cannot be blank.");
|
||||
if ($discnameunique_err) format_message(1,"When Discovered name already exists.");
|
||||
if ($discdescsuppld_err) format_message(1,"When Discovered description cannot be blank.");
|
||||
if ($dischaswriteups_err) format_message(1,"When Discovered has writeups in the database and cannot be deleted.");
|
||||
|
||||
if ($edit_period && !$delete_period) {
|
||||
if ($edit_discovered && !$delete_discovered) {
|
||||
// set form options for editing
|
||||
$sectiontitle="<b><font size=\"+1\">Modify Period</font></b> <a href=\"dbadmin.php#periods\">Click here to add a new period</a><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php?edit_period=1#periods\">";
|
||||
$sectiontitle="<b><font size=\"+1\">Modify When Discovered</font></b> <a href=\"dbadmin.php#discovered\">Click here to add a new when discovered</a><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php?edit_discovered=1#discovered\">";
|
||||
$buttontags="
|
||||
<input type=\"hidden\" name=\"period_id\" value=\"$period_id\">
|
||||
<input type=\"submit\" name=\"update_period\" value=\"Update Period\">
|
||||
<input type=\"submit\" name=\"delete_period\" value=\"Delete Period\">
|
||||
<input type=\"hidden\" name=\"discovered_id\" value=\"$discovered_id\">
|
||||
<input type=\"submit\" name=\"update_discovered\" value=\"Update When Discovered\">
|
||||
<input type=\"submit\" name=\"delete_discovered\" value=\"Delete When Discovered\">
|
||||
<input type=\"submit\" name=\"reset\" value=\"Reset\"><br>
|
||||
";
|
||||
// pull current values from database
|
||||
$currentvalues=mysqli_fetch_assoc(mysqli_query($drs_db,"select * from periods where id=$period_id"));
|
||||
$period_times=$currentvalues["times"];
|
||||
$currentvalues=mysqli_fetch_assoc(mysqli_query($drs_db,"select * from discovered where id=$discovered_id"));
|
||||
$discovered_name=$currentvalues["whendiscoveredname"];
|
||||
$discovered_desc=$currentvalues["whendiscovereddesc"];
|
||||
if ($currentvalues["active"]==1) {
|
||||
$activetag="<input type=\"checkbox\" name=\"period_active\" value=\"1\" checked>";
|
||||
$activetag="<input type=\"checkbox\" name=\"discovered_active\" value=\"1\" checked>";
|
||||
} else {
|
||||
$activetag="<input type=\"checkbox\" name=\"period_active\" value=\"1\">";
|
||||
$activetag="<input type=\"checkbox\" name=\"discovered_active\" value=\"1\">";
|
||||
}
|
||||
$idtag="$period_id";
|
||||
} else {
|
||||
// set form options for add
|
||||
if (!$period_add_fail) unset($period_id,$period_times,$period_active);
|
||||
$sectiontitle="<b><font size=\"+1\">Add New Period</font></b><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php#periods\">";
|
||||
if (!$discovered_add_fail) $discovered_id=$discovered_name=$discovered_desc=$discovered_active=NULL;
|
||||
$sectiontitle="<b><font size=\"+1\">Add New When Discovered</font></b><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php#discovered\">";
|
||||
$buttontags="
|
||||
<input type=\"submit\" name=\"add_period\" value=\"Add Period\">
|
||||
<input type=\"submit\" name=\"add_discovered\" value=\"Add When Discovered\">
|
||||
";
|
||||
$idtag="<input type=\"text\" name=\"period_id\" size=\"3\" value=\"$period_id\">";
|
||||
// set default values
|
||||
$activetag="<input type=\"checkbox\" name=\"period_active\" value=\"1\" checked>";
|
||||
$activetag="<input type=\"checkbox\" name=\"discovered_active\" value=\"1\" checked>";
|
||||
}
|
||||
echo "
|
||||
$sectiontitle
|
||||
$formtag
|
||||
<table border=\"0\">
|
||||
<tr><td>
|
||||
Period Number: $idtag<br><br>
|
||||
Period Times: <input type=\"text\" name=\"period_times\" size=\"40\" value=\"$period_times\"><br><br>
|
||||
When Discovered Name: <input type=\"text\" name=\"discovered_name\" size=\"8\" value=\"$discovered_name\"><br><br>
|
||||
When Discovered Description: <input type=\"text\" name=\"discovered_desc\" size=\"60\" value=\"$discovered_desc\"><br><br>
|
||||
Active: $activetag <br><br>
|
||||
</td></tr>
|
||||
</table>
|
||||
@@ -1057,11 +1178,11 @@ $buttontags
|
||||
";
|
||||
|
||||
// show the table of entities
|
||||
$existingdata=mysqli_query($drs_db,"select * from periods order by id asc");
|
||||
$existingdata=mysqli_query($drs_db,"select * from discovered order by id asc");
|
||||
echo "
|
||||
<b>Existing Periods</b> <font size=\"-1\">Click on the Period ID to edit.</font><br><br>
|
||||
<b>Existing When Discovereds</b> <font size=\"-1\">Click on the When Disc ID to edit.</font><br><br>
|
||||
<table border=\"1\">
|
||||
<tr><th>Period ID</th><th>Period Times</th><th>Active</th></tr>
|
||||
<tr><th>When Disc ID</th><th>Name</th><th>Description</th><th>Active</th></tr>
|
||||
";
|
||||
while ($tablerow=mysqli_fetch_assoc($existingdata)) {
|
||||
if ($tablerow["active"]) {
|
||||
@@ -1071,12 +1192,14 @@ while ($tablerow=mysqli_fetch_assoc($existingdata)) {
|
||||
}
|
||||
printf("
|
||||
<tr>
|
||||
<td><a href=\"dbadmin.php?edit_period=1&period_id=%s#periods\">%s</a></td>
|
||||
<td><a href=\"dbadmin.php?edit_discovered=1&discovered_id=%s#discovered\">%s</a></td>
|
||||
<td>%s</td>
|
||||
<td>%s</td>
|
||||
<td align=\"center\">%s</td>
|
||||
</tr>",
|
||||
$tablerow["id"],$tablerow["id"],
|
||||
$tablerow["times"],
|
||||
$tablerow["whendiscoveredname"],
|
||||
$tablerow["whendiscovereddesc"],
|
||||
$activedef);
|
||||
}
|
||||
echo "</table>";
|
||||
|
||||
@@ -2,18 +2,23 @@
|
||||
/*
|
||||
gpl.php
|
||||
OpenMTS Online Maintenance Tracking System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to index.php on cancel button press
|
||||
if ($_REQUEST['cancel']) {
|
||||
// redirect to search.php on cancel button press
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:index.php");
|
||||
header("Location:search.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -21,7 +26,6 @@ if ($_REQUEST['cancel']) {
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming
|
||||
@@ -31,7 +35,7 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
// extract incoming array keys into variables
|
||||
|
||||
|
||||
// define local functions
|
||||
@@ -40,19 +44,19 @@ if ($print) {
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print=="Printer Friendly") {
|
||||
$sbcolor=P_SIDEBAR_COLOR;
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$sbcolor=SIDEBAR_COLOR;
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
}
|
||||
|
||||
$role=dblookup($mts_db,"users","id","role",$userid);
|
||||
$role=dblookup($drs_db,"users","id","role",$userid);
|
||||
|
||||
framework("begin","$appname","GNU General Public License",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
|
||||
@@ -2,15 +2,29 @@
|
||||
/*
|
||||
groups.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// redirect to groups.php on cancel button press
|
||||
if ($_REQUEST['cancel']) {
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:groups.php");
|
||||
@@ -18,10 +32,13 @@ if ($_REQUEST['cancel']) {
|
||||
}
|
||||
|
||||
// import session variables
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
if (isset($_SESSION['userid'])) {
|
||||
$userid=$_SESSION['userid'];
|
||||
} else {
|
||||
$userid=NULL;
|
||||
}
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming
|
||||
@@ -31,34 +48,47 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
* action
|
||||
* save
|
||||
* targets
|
||||
* group
|
||||
* name
|
||||
* search
|
||||
* s_status
|
||||
* s_device
|
||||
* s_subsystem
|
||||
* s_discovered
|
||||
* s_report_date_start
|
||||
* s_report_date_end
|
||||
* s_report_time_start
|
||||
* s_report_time_end
|
||||
* s_discrepancy_text
|
||||
* s_reported_by
|
||||
* s_functional
|
||||
* edit_status
|
||||
* edit_action_by
|
||||
* edit_action_reason
|
||||
* edit_action_date
|
||||
* edit_action_time
|
||||
* edit_action_text
|
||||
*/
|
||||
|
||||
$action=$incoming['action'];
|
||||
$save=$incoming['save'];
|
||||
$targets=$incoming['targets'];
|
||||
$group=$incoming['group'];
|
||||
$name=$incoming['name'];
|
||||
$expandgrp=$incoming['expandgrp'];
|
||||
if (!isset($action)) $action=NULL;
|
||||
if (!isset($s_discrepancy_text)) $s_discrepancy_text=NULL;
|
||||
if (!isset($s_reported_by)) $s_reported_by=NULL;
|
||||
if (!isset($edit_status)) $edit_status=NULL;
|
||||
if (!isset($edit_action_by)) $edit_action_by=NULL;
|
||||
if (!isset($edit_action_reason)) $edit_action_reason=NULL;
|
||||
if (!isset($edit_action_text)) $edit_action_text=NULL;
|
||||
if (!isset($save)) $save=false;
|
||||
if (!isset($search)) $search=false;
|
||||
if (!isset($group)) $group=NULL;
|
||||
if (!isset($name)) $name=NULL;
|
||||
|
||||
$search=$incoming['search'];
|
||||
$s_status=$incoming['s_status'];
|
||||
$s_device=$incoming['s_device'];
|
||||
$s_subsystem=$incoming['s_subsystem'];
|
||||
$s_period=$incoming['s_period'];
|
||||
$s_report_date_start=$incoming['s_report_date_start'];
|
||||
$s_report_date_end=$incoming['s_report_date_end'];
|
||||
$s_report_time_start=$incoming['s_report_time_start'];
|
||||
$s_report_time_end=$incoming['s_report_time_end'];
|
||||
$s_discrepancy_text=$incoming['s_discrepancy_text'];
|
||||
$s_reported_by=$incoming['s_reported_by'];
|
||||
$s_period_effective=$incoming['s_period_effective'];
|
||||
|
||||
$edit_status=$incoming['edit_status'];
|
||||
$edit_action_by=$incoming['edit_action_by'];
|
||||
$edit_action_reason=$incoming['edit_action_reason'];
|
||||
$edit_action_date=$incoming['edit_action_date'];
|
||||
$edit_action_time=$incoming['edit_action_time'];
|
||||
$edit_action_text=$incoming['edit_action_text'];
|
||||
|
||||
// define local functions
|
||||
|
||||
@@ -66,11 +96,9 @@ $edit_action_text=$incoming['edit_action_text'];
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print=="Printer Friendly") {
|
||||
$sbcolor=P_SIDEBAR_COLOR;
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$sbcolor=SIDEBAR_COLOR;
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
}
|
||||
|
||||
@@ -78,7 +106,9 @@ $role=dblookup($drs_db,"users","id","role",$userid);
|
||||
|
||||
framework("begin","$appname","Writeup Groups",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
@@ -90,17 +120,17 @@ $now=date("H:i:s");
|
||||
// get max report date from writeups table, validate input dates/times and set defaults
|
||||
$maxrepdate_qry=mysqli_query($drs_db,"select max(report_date) from writeups");
|
||||
$maxrepdate=mysqli_fetch_row($maxrepdate_qry)[0];
|
||||
if (!$s_report_date_start || !validateDate($s_report_date_start)) $s_report_date_start=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 30 day)"))[0];
|
||||
if (!$s_report_date_end || !validateDate($s_report_date_end)) $s_report_date_end=$maxrepdate;
|
||||
if (!$s_report_time_start || !validateTime($s_report_time_start)) $s_report_time_start="00:00:00";
|
||||
if (!$s_report_time_end || !validateTime($s_report_time_end)) $s_report_time_end="23:59:59";
|
||||
if (!$edit_action_date || !validateDate($edit_action_date)) $edit_action_date=$today;
|
||||
if (!$edit_action_time || !validateTime($edit_action_time)) $edit_action_time=$now;
|
||||
if (!isset($s_report_date_start) || !validateDate($s_report_date_start)) $s_report_date_start=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 30 day)"))[0];
|
||||
if (!isset($s_report_date_end) || !validateDate($s_report_date_end)) $s_report_date_end=$maxrepdate;
|
||||
if (!isset($s_report_time_start) || !validateTime($s_report_time_start)) $s_report_time_start="00:00:00";
|
||||
if (!isset($s_report_time_end) || !validateTime($s_report_time_end)) $s_report_time_end="23:59:59";
|
||||
if (!isset($edit_action_date) || !validateDate($edit_action_date)) $edit_action_date=$today;
|
||||
if (!isset($edit_action_time) || !validateTime($edit_action_time)) $edit_action_time=$now;
|
||||
|
||||
|
||||
if ($action=="add" && $role && $save) {
|
||||
$fail=false;
|
||||
if (!$group) {
|
||||
if ($group==NULL) {
|
||||
// group was not supplied, so create a new one
|
||||
mysqli_query($drs_db,"insert into groups(name) value(\"\")");
|
||||
$fail=mysqli_error($drs_db);
|
||||
@@ -116,18 +146,24 @@ if ($action=="add" && $role && $save) {
|
||||
}
|
||||
} elseif ($action=="remove" && $role && $save) {
|
||||
$fail=false;
|
||||
$writeups=array();
|
||||
$writeups=[];
|
||||
$writeups_qry=mysqli_query($drs_db,"select writeupid from links where linkgroup=\"$group\"");
|
||||
while ($writeuprow=mysqli_fetch_row($writeups_qry)) {
|
||||
$writeups[]=$writeuprow[0];
|
||||
}
|
||||
foreach ($writeups as $writeup) {
|
||||
if (!in_array($writeup,$targets)) {
|
||||
if (!isset($targets) || !in_array($writeup,$targets)) {
|
||||
// remove writeup from group
|
||||
mysqli_query($drs_db,"delete from links where writeupid=$writeup and linkgroup=$group");
|
||||
$fail=mysqli_error($drs_db);
|
||||
}
|
||||
}
|
||||
// if there are no longer any writeups in this group, dissolve it
|
||||
$memb_qty_query=mysqli_query($drs_db,"select id from links where linkgroup=\"$group\"");
|
||||
if (mysqli_num_rows($memb_qty_query) == 0) {
|
||||
mysqli_query($drs_db,"delete from groups where id=$group");
|
||||
$fail=mysqli_error($drs_db);
|
||||
}
|
||||
} elseif ($action=="dissolve" && $role && $save) {
|
||||
$fail=false;
|
||||
// unassign all writeups from a group and delete the group
|
||||
@@ -147,7 +183,7 @@ if ($action=="add" && $role && $save) {
|
||||
$fail=false;
|
||||
// set the status, action by, reason action date/time and append supplied text to action text
|
||||
// for all ids in group
|
||||
if ($edit_action_text) {
|
||||
if ($edit_action_reason!=NULL) {
|
||||
// sanitize date and time
|
||||
$edit_action_date=mysqli_real_escape_string($drs_db,$edit_action_date);
|
||||
$edit_action_time=mysqli_real_escape_string($drs_db,$edit_action_time);
|
||||
@@ -159,22 +195,23 @@ if ($action=="add" && $role && $save) {
|
||||
while ($edit_row=mysqli_fetch_row($groupmem_qry)) {
|
||||
$writeup_to_edit=$edit_row[0];
|
||||
$writeup_action_text=dblookup($drs_db,"writeups","id","action_text",$writeup_to_edit);
|
||||
$full_action_text=$writeup_action_text." STATUS CHANGED: ".$clean_edit_action_text;
|
||||
$full_action_text=$writeup_action_text." GROUP ACTION TAKEN: ".$clean_edit_action_text;
|
||||
mysqli_query($drs_db,"update writeups set status=\"$edit_status\",action_by=\"$edit_action_by\",action_date=\"$edit_action_date\",action_time=\"$edit_action_time\",action_reason=\"$edit_action_reason\",action_text=\"$full_action_text\" where id=\"$writeup_to_edit\"");
|
||||
$fail=mysqli_error($drs_db);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$fail="A status change reason was not selected.";
|
||||
}
|
||||
}
|
||||
if ($search) {
|
||||
// strip whitespace from beginning and end of text fields
|
||||
$s_reported_by=trim($s_reported_by);
|
||||
$s_action_text=trim($s_action_text);
|
||||
$s_discrepancy_text=trim($s_discrepancy_text);
|
||||
|
||||
// build the query string
|
||||
$query_string="";
|
||||
// device
|
||||
if ($s_device) {
|
||||
if (isset($s_device)) {
|
||||
$query_string="{$query_string}(";
|
||||
$device_param="Devices:";
|
||||
foreach ($s_device as $dev_val) {
|
||||
@@ -190,7 +227,7 @@ if ($search) {
|
||||
$query_string="{$query_string} and ";
|
||||
}
|
||||
// subsystem
|
||||
if ($s_subsystem) {
|
||||
if (isset($s_subsystem)) {
|
||||
$query_string="{$query_string}(";
|
||||
$subsystem_param="Subsystems:";
|
||||
foreach ($s_subsystem as $sub_val) {
|
||||
@@ -205,39 +242,39 @@ if ($search) {
|
||||
$query_string="{$query_string})";
|
||||
$query_string="{$query_string} and ";
|
||||
}
|
||||
// period
|
||||
if ($s_period) {
|
||||
// discovered
|
||||
if (isset($s_discovered)) {
|
||||
$query_string="{$query_string}(";
|
||||
$period_param="Periods:";
|
||||
foreach ($s_period as $per_val) {
|
||||
$query_string="{$query_string}period=\"{$per_val}\" or ";
|
||||
$period_dsp=$per_val;
|
||||
$period_param="{$period_param} {$period_dsp}, ";
|
||||
$discovered_param="{$discovered_term_short}s:";
|
||||
foreach ($s_discovered as $disc_val) {
|
||||
$query_string="{$query_string}discovered=\"{$disc_val}\" or ";
|
||||
$disc_dsp=$disc_val;
|
||||
$discovered_param="{$discovered_param} {$disc_dsp}, ";
|
||||
}
|
||||
$period_param=rtrim($period_param,", ");
|
||||
$num_periods=mysqli_num_rows(mysqli_query($drs_db,"select id from periods"));
|
||||
if (count($s_period)==$num_periods) $period_param="Periods: any";
|
||||
$discovered_param=rtrim($discovered_param,", ");
|
||||
$num_discovereds=mysqli_num_rows(mysqli_query($drs_db,"select id from discovered"));
|
||||
if (count($s_discovered)==$num_discovereds) $discovered_param="{$discovered_term_short}s: any";
|
||||
$query_string=rtrim($query_string," or ");
|
||||
$query_string="{$query_string})";
|
||||
$query_string="{$query_string} and ";
|
||||
}
|
||||
// period_effective
|
||||
if ($s_period_effective) {
|
||||
// functional
|
||||
if (isset($s_functional)) {
|
||||
$query_string="{$query_string}(";
|
||||
$eff_param="Period effective:";
|
||||
foreach ($s_period_effective as $eff_val) {
|
||||
$query_string="{$query_string}period_effective=\"{$eff_val}\" or ";
|
||||
if ($eff_val=="0") $eff_dsp="<font color=\"#FF0000\">NEF</font>";
|
||||
if ($eff_val=="1") $eff_dsp="<font color=\"#00FF00\">EFF</font>";
|
||||
$eff_param="{$eff_param} {$eff_dsp}, ";
|
||||
$func_param="$functional_term:";
|
||||
foreach ($s_functional as $func_val) {
|
||||
$query_string="{$query_string}functional=\"{$func_val}\" or ";
|
||||
if ($func_val=="0") $func_dsp="<font color=\"#FF0000\">$functional_no_short</font>";
|
||||
if ($func_val=="1") $func_dsp="<font color=\"#00FF00\">$functional_yes_short</font>";
|
||||
$func_param="{$func_param} {$func_dsp}, ";
|
||||
}
|
||||
$eff_param=rtrim($eff_param,", ");
|
||||
$func_param=rtrim($func_param,", ");
|
||||
$query_string=rtrim($query_string," or ");
|
||||
$query_string="{$query_string})";
|
||||
$query_string="{$query_string} and ";
|
||||
}
|
||||
// status
|
||||
if ($s_status) {
|
||||
if (isset($s_status)) {
|
||||
$query_string="{$query_string}(";
|
||||
$status_param="Status:";
|
||||
foreach ($s_status as $stat_val) {
|
||||
@@ -265,7 +302,7 @@ if ($search) {
|
||||
$query_string="{$query_string} and ";
|
||||
$reporttime_param="Report time between {$s_report_time_start} and {$s_report_time_end}";
|
||||
// discrepancy text
|
||||
if ($s_discrepancy_text) {
|
||||
if (isset($s_discrepancy_text)) {
|
||||
$query_string="{$query_string}(";
|
||||
$query_string="{$query_string}discrepancy_text like \"%{$s_discrepancy_text}%\"";
|
||||
$query_string="{$query_string})";
|
||||
@@ -275,7 +312,7 @@ if ($search) {
|
||||
$discrepancytext_param="Text in discrepancy: any";
|
||||
}
|
||||
// reported by
|
||||
if ($s_reported_by) {
|
||||
if (isset($s_reported_by)) {
|
||||
$query_string="{$query_string}(";
|
||||
$query_string="{$query_string}reported_by like \"%{$s_reported_by}%\"";
|
||||
$query_string="{$query_string})";
|
||||
@@ -302,6 +339,7 @@ banner($print);
|
||||
echo "<br>";
|
||||
|
||||
if ($action=="add") {
|
||||
if (!isset($targets)) $targets=[];
|
||||
if (count($targets) > 1) {
|
||||
$plural="s";
|
||||
} else {
|
||||
@@ -315,7 +353,7 @@ if ($action=="add") {
|
||||
if ($save) {
|
||||
// show the group
|
||||
$mode="view";
|
||||
group_table($group,$role,$mode);
|
||||
group_detail($group,$role,$mode);
|
||||
if ($role) {
|
||||
// show buttons
|
||||
echo "
|
||||
@@ -416,17 +454,17 @@ if ($action=="add") {
|
||||
<tr>
|
||||
<td align=\"left\">
|
||||
";
|
||||
// Period cell **********************
|
||||
// Discovered cell **********************
|
||||
echo "
|
||||
Period<br>
|
||||
<select name=\"s_period[]\" id=\"ms-period\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
$discovered_term<br>
|
||||
<select name=\"s_discovered[]\" id=\"ms-discovered\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
";
|
||||
$prow=mysqli_query($drs_db,"select * from periods order by times asc");
|
||||
while ($pitem=mysqli_fetch_assoc($prow)) {
|
||||
if (!$search || in_array($pitem["id"],$s_period,true)) {
|
||||
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$pitem["id"],$pitem["id"],$pitem["times"]);
|
||||
$discrow=mysqli_query($drs_db,"select * from discovered order by whendiscoveredname asc");
|
||||
while ($discitem=mysqli_fetch_assoc($discrow)) {
|
||||
if (!$search || in_array($discitem["id"],$s_discovered,true)) {
|
||||
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$discitem["id"],$discitem["whendiscovereddesc"],$discitem["whendiscoveredname"]);
|
||||
} else {
|
||||
printf("<option value=\"%s\" title=\"%s\">%s</option>",$pitem["id"],$pitem["id"],$pitem["times"]);
|
||||
printf("<option value=\"%s\" title=\"%s\">%s</option>",$discitem["id"],$discitem["whendiscovereddesc"],$discitem["whendiscoveredname"]);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
@@ -488,21 +526,21 @@ if ($action=="add") {
|
||||
</td>
|
||||
<td align=\"left\">
|
||||
";
|
||||
// Period effective cell ************
|
||||
// functional cell ************
|
||||
echo "
|
||||
Sim period effective? <img src=\"icons/question.png\" title=\"" . PERIOD_EFF_HELP_TXT . "\"><br>
|
||||
$functional_term? <img src=\"icons/question.png\" title=\"" . FUNCTIONAL_HELP_TXT . "\"><br>
|
||||
";
|
||||
if ($search) {
|
||||
$effstate=$nefstate="";
|
||||
if (in_array("1",$s_period_effective,true)) $effstate="selected";
|
||||
if (in_array("0",$s_period_effective,true)) $nefstate="selected";
|
||||
$funcyesstate=$funcnostate="";
|
||||
if (in_array("1",$s_functional,true)) $funcyesstate="selected";
|
||||
if (in_array("0",$s_functional,true)) $funcnostate="selected";
|
||||
} else {
|
||||
$effstate=$nefstate="selected";
|
||||
$funcyesstate=$funcnostate="selected";
|
||||
}
|
||||
echo "
|
||||
<select name=\"s_period_effective[]\" id=\"ms-period_effective\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
<option value=\"1\" $effstate title=\"Training objectives were achieved\">Effective</option>
|
||||
<option value=\"0\" $nefstate title=\"Training objectives were not achieved\">Non-effective</option>
|
||||
<select name=\"s_functional[]\" id=\"ms-functional\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
<option value=\"1\" $funcyesstate>$functional_yes</option>
|
||||
<option value=\"0\" $funcnostate>$functional_no</option>
|
||||
</select>
|
||||
</td>
|
||||
";
|
||||
@@ -530,15 +568,15 @@ if ($action=="add") {
|
||||
<th style=\"width:1%;\">Device</th>
|
||||
<th style=\"width:1%;\">Reported by</th>
|
||||
<th>Discrepancy</th>
|
||||
<th style=\"width:1%;\">Msn Eff</th>
|
||||
<th style=\"width:1%;\">$functional_term_short</th>
|
||||
</tr>
|
||||
";
|
||||
while ($tablerow = mysqli_fetch_assoc($writeup_qry)) {
|
||||
// determine effective icon
|
||||
if($tablerow["period_effective"]==1) {
|
||||
$eff_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"Period Effective\" alt=\"Period Effective\">";
|
||||
// determine functional icon
|
||||
if($tablerow["functional"]==1) {
|
||||
$func_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes\">";
|
||||
} else {
|
||||
$eff_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"Period Non-effective\" alt=\"Period Non-effective\">";
|
||||
$func_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no\">";
|
||||
}
|
||||
|
||||
// determine status indicator
|
||||
@@ -586,7 +624,7 @@ if ($action=="add") {
|
||||
$dname,
|
||||
$tablerow["reported_by"],
|
||||
$disc_txt,
|
||||
$eff_icon
|
||||
$func_icon
|
||||
);
|
||||
}
|
||||
echo "
|
||||
@@ -619,7 +657,7 @@ if ($action=="add") {
|
||||
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
||||
<input type=\"hidden\" name=\"action\" value=\"remove\">
|
||||
";
|
||||
group_table($group,$role,"select","all");
|
||||
group_detail($group,$role,"select","all");
|
||||
echo "
|
||||
Deselect the writeups you want to remove from this group. <br><br>
|
||||
<b>NOTE:</b> Deselecting them all will dissolve the group.
|
||||
@@ -651,7 +689,7 @@ if ($action=="add") {
|
||||
}
|
||||
// show the group
|
||||
$mode="view";
|
||||
group_table($group,$role,$mode);
|
||||
group_detail($group,$role,$mode);
|
||||
if ($role) {
|
||||
// show buttons
|
||||
echo "
|
||||
@@ -692,7 +730,7 @@ if ($action=="add") {
|
||||
}
|
||||
// show the group
|
||||
$mode="view";
|
||||
group_table($group,$role,$mode);
|
||||
group_detail($group,$role,$mode);
|
||||
if ($role) {
|
||||
// show buttons
|
||||
echo "
|
||||
@@ -718,7 +756,7 @@ if ($action=="add") {
|
||||
}
|
||||
// show the group
|
||||
$mode="view";
|
||||
group_table($group,$role,$mode);
|
||||
group_detail($group,$role,$mode);
|
||||
if ($role && ! $save) {
|
||||
// show action form
|
||||
echo "
|
||||
@@ -773,9 +811,9 @@ if ($action=="add") {
|
||||
<select name=\"edit_action_reason\" id=\"reason\">
|
||||
";
|
||||
$reasrow=mysqli_query($drs_db,"select id,text from reasons where active is true order by id asc");
|
||||
if (!$action_reason) echo "<option selected></option>";
|
||||
if ($edit_action_reason==NULL) echo "<option selected></option>";
|
||||
while ($reasitem=mysqli_fetch_assoc($reasrow)) {
|
||||
if ($action_reason==$reasitem["id"]) {
|
||||
if ($edit_action_reason==$reasitem["id"]) {
|
||||
printf("<option value=\"%s\" selected>%s</option>",$reasitem["id"],$reasitem["text"]);
|
||||
} else {
|
||||
printf("<option value=\"%s\">%s</option>",$reasitem["id"],$reasitem["text"]);
|
||||
@@ -816,10 +854,10 @@ if ($action=="add") {
|
||||
<hr>
|
||||
";
|
||||
}
|
||||
if ($group) {
|
||||
if ($group!=NULL) {
|
||||
// show only the requested group
|
||||
$mode="view";
|
||||
group_table($group,$role,$mode);
|
||||
group_detail($group,$role,$mode);
|
||||
if ($role) {
|
||||
// show buttons
|
||||
echo "
|
||||
@@ -839,48 +877,42 @@ if ($action=="add") {
|
||||
}
|
||||
echo "<hr><br>";
|
||||
} else {
|
||||
// show all groups
|
||||
$mode="view";
|
||||
$groups_qry=mysqli_query($drs_db,"select id from groups");
|
||||
// show group table
|
||||
$groups_qry=mysqli_query($drs_db,"select * from groups");
|
||||
if (mysqli_num_rows($groups_qry)) {
|
||||
echo "
|
||||
<br><br>
|
||||
<table border=\"1\" cellpadding=\"5\" style=\"width:100%;\">
|
||||
<tr>
|
||||
<th style=\"width:1%;\">ID</th>
|
||||
<th>Name</th>
|
||||
<th style=\"width:1%;\">Writeups assigned</th>
|
||||
</tr>
|
||||
";
|
||||
while ($grouprow=mysqli_fetch_assoc($groups_qry)) {
|
||||
if ($expandgrp == $grouprow['id']) {
|
||||
group_table($grouprow['id'],$role,$mode,"none",$expandgrp);
|
||||
if ($role) {
|
||||
// show buttons
|
||||
echo "
|
||||
<form method=post action=\"groups.php\">
|
||||
<input type=\"hidden\" name=\"group\" value=\"{$grouprow['id']}\">
|
||||
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
|
||||
|
||||
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
|
||||
|
||||
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
|
||||
|
||||
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
|
||||
|
||||
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
|
||||
</form>
|
||||
";
|
||||
}
|
||||
} else {
|
||||
echo "
|
||||
<a href=\"groups.php?expandgrp={$grouprow['id']}\" style=\"text-decoration:none\">
|
||||
<img src=\"icons/plus-white.png\" alt=\"Expand group\">
|
||||
</a>
|
||||
";
|
||||
$groupname=dblookup($drs_db,"groups","id","name",$grouprow['id']);
|
||||
if ($groupname == "") {
|
||||
echo "<b>Group ID:</b> {$grouprow['id']}";
|
||||
} else {
|
||||
echo "<b>Group Name:</b> $groupname";
|
||||
}
|
||||
}
|
||||
echo "<br><br>";
|
||||
}
|
||||
} else {
|
||||
echo "<br>No writeup groups were found.<br><br><br>";
|
||||
}
|
||||
$num_query=mysqli_query($drs_db,"select id from links where linkgroup={$grouprow['id']}");
|
||||
$num_writeups=mysqli_num_rows($num_query);
|
||||
if($grouprow['name']=="") {
|
||||
$name_text="Group {$grouprow['id']} has not been named";
|
||||
} else {
|
||||
$name_text="{$grouprow['name']}";
|
||||
}
|
||||
// print table row
|
||||
printf(
|
||||
"<tr>
|
||||
<td align=\"center\" valign=\"top\"><a href=\"groups.php?group=%s\" title=\"View or change details of this group\">%s</a></td>
|
||||
<td valign=\"top\">%s</td>
|
||||
<td align=\"center\" valign=\"top\">%s</td>
|
||||
</tr>\n",
|
||||
$grouprow["id"],$grouprow["id"],
|
||||
$name_text,
|
||||
$num_writeups
|
||||
);
|
||||
}
|
||||
echo "</table><br>";
|
||||
} else {
|
||||
echo "<br>No writeup groups were found.<br><br><br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,24 +2,49 @@
|
||||
/*
|
||||
login.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
|
||||
$print=$_REQUEST['print'];
|
||||
$userid=$_REQUEST['userid'];
|
||||
$userlogin=$_REQUEST['userlogin'];
|
||||
$pass=$_REQUEST['pass'];
|
||||
$login=$_REQUEST['login'];
|
||||
$cancel=$_REQUEST['cancel'];
|
||||
|
||||
if ($cancel) {
|
||||
session_destroy();
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// import incoming arrays
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming[]
|
||||
$incoming=unserialize($_REQUEST['all_parameters']);
|
||||
} else {
|
||||
// copy $_REQUEST[] to $incoming[]
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
* userid
|
||||
* userlogin
|
||||
* pass
|
||||
* login
|
||||
* cancel
|
||||
*/
|
||||
|
||||
if (!isset($userlogin)) $userlogin=NULL;
|
||||
if (!isset($pass)) $pass=NULL;
|
||||
|
||||
if (isset($cancel)) {
|
||||
session_destroy();
|
||||
} else {
|
||||
$cancel=false;
|
||||
}
|
||||
|
||||
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print) {
|
||||
@@ -31,7 +56,10 @@ if ($print) {
|
||||
|
||||
framework("begin","$appname","Login Page",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
pagetable("begin");
|
||||
if(!$print){
|
||||
@@ -41,7 +69,7 @@ if(!$print){
|
||||
pageblock("left","end");
|
||||
}
|
||||
pageblock("right","begin");
|
||||
if ($login) {
|
||||
if (isset($login)) {
|
||||
// get the id from the userlogin
|
||||
$userid=dblookup($drs_db,"users","login","id",$userlogin);
|
||||
$useractive=dblookup($drs_db,"users","id","active",$userid);
|
||||
|
||||
@@ -2,15 +2,29 @@
|
||||
/*
|
||||
profile.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// redirect to index.php on cancel button press
|
||||
if ($_REQUEST['cancel']) {
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:index.php");
|
||||
@@ -30,7 +44,6 @@ if (!$role) {
|
||||
}
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming[]
|
||||
@@ -40,24 +53,34 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
$update_colors=$incoming['update_colors'];
|
||||
$reset_colors=$incoming['reset_colors'];
|
||||
$newbgc=$incoming['newbgc'];
|
||||
$newmbgc=$incoming['newmbgc'];
|
||||
$newtc=$incoming['newtc'];
|
||||
$newlc=$incoming['newlc'];
|
||||
$newvlc=$incoming['newvlc'];
|
||||
$newhc=$incoming['newhc'];
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
* update_colors
|
||||
* reset_colors
|
||||
* newbgc
|
||||
* newmbgc
|
||||
* newtc
|
||||
* newlc
|
||||
* newvlc
|
||||
* newhc
|
||||
* edit_user
|
||||
* update_user
|
||||
* user_id
|
||||
* user_fname
|
||||
* user_lname
|
||||
* user_login
|
||||
* user_pass
|
||||
* user_passconf
|
||||
*/
|
||||
|
||||
$edit_user=$incoming['edit_user'];
|
||||
$update_user=$incoming['update_user'];
|
||||
$user_id=$userid; // ensures that I can only change my own profile
|
||||
$user_fname=$incoming['user_fname'];
|
||||
$user_lname=$incoming['user_lname'];
|
||||
$user_login=$incoming['user_login'];
|
||||
$user_pass=$incoming['user_pass'];
|
||||
$user_passconf=$incoming['user_passconf'];
|
||||
|
||||
if (!isset($update_colors)) $update_colors=false;
|
||||
if (!isset($reset_colors)) $reset_colors=false;
|
||||
if (!isset($edit_user)) $edit_user=false;
|
||||
if (!isset($update_user)) $update_user=false;
|
||||
|
||||
// define local functions
|
||||
|
||||
@@ -65,7 +88,7 @@ $user_passconf=$incoming['user_passconf'];
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print=="Printer Friendly") {
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
@@ -74,7 +97,9 @@ if ($print=="Printer Friendly") {
|
||||
|
||||
framework("begin","$appname","User Profile",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
@@ -92,6 +117,9 @@ if ($reset_colors) {
|
||||
echo "<meta http-equiv='refresh' content='0'>";
|
||||
}
|
||||
|
||||
$usernameunique_err=$fnamesuppld_err=$lnamesuppld_err=$loginsuppld_err=false;
|
||||
$loginunique_err=$passcomplex_err=$passmatch_err=false;
|
||||
|
||||
if ($edit_user) {
|
||||
if ($update_user) {
|
||||
// do error checking
|
||||
@@ -102,6 +130,7 @@ if ($edit_user) {
|
||||
// test for first name supplied
|
||||
if (strlen(trim($user_fname))) {
|
||||
$fnamesuppld=true;
|
||||
$fnamesuppld_err=false;
|
||||
} else {
|
||||
$fnamesuppld=false;
|
||||
$fnamesuppld_err=true;
|
||||
@@ -109,6 +138,7 @@ if ($edit_user) {
|
||||
// test for last name supplied
|
||||
if (strlen(trim($user_lname))) {
|
||||
$lnamesuppld=true;
|
||||
$lnamesuppld_err=false;
|
||||
} else {
|
||||
$lnamesuppld=false;
|
||||
$lnamesuppld_err=true;
|
||||
@@ -120,13 +150,16 @@ if ($edit_user) {
|
||||
$nameunique_err=true;
|
||||
} else {
|
||||
$nameunique=true;
|
||||
$nameunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$nameunique=true;
|
||||
$nameunique_err=false;
|
||||
}
|
||||
// test for login supplied
|
||||
if (strlen(trim($user_login))) {
|
||||
$loginsuppld=true;
|
||||
$loginsuppld_err=false;
|
||||
} else {
|
||||
$loginsuppld=false;
|
||||
$loginsuppld_err=true;
|
||||
@@ -138,9 +171,11 @@ if ($edit_user) {
|
||||
$loginunique_err=true;
|
||||
} else {
|
||||
$loginunique=true;
|
||||
$loginunique_err=false;
|
||||
}
|
||||
} else {
|
||||
$loginunique=true;
|
||||
$loginunique_err=false;
|
||||
}
|
||||
// sanitize first name, last name, login
|
||||
$clean_fname=mysqli_real_escape_string($drs_db,$user_fname);
|
||||
@@ -152,12 +187,14 @@ if ($edit_user) {
|
||||
$passresults=validate_password($user_pass,$user_passconf);
|
||||
if ($passresults['match']) {
|
||||
$passmatch=true;
|
||||
$passmatch_err=false;
|
||||
} else {
|
||||
$passmatch=false;
|
||||
$passmatch_err=true;
|
||||
}
|
||||
if ($passresults['complex']) {
|
||||
$passcomplex=true;
|
||||
$passcomplex_err=false;
|
||||
} else {
|
||||
$passcomplex=false;
|
||||
$passcomplex_err=true;
|
||||
|
||||
@@ -2,15 +2,41 @@
|
||||
/*
|
||||
search.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2021 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
if ($_REQUEST['exportcsv']) {
|
||||
$csv_filename="OpenDRS_Search_Results_" . date("Y-m-d_His") . ".csv";
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// redirect to search.php on cancel button press
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:search.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if (array_key_exists('exportcsv',$_REQUEST)) {
|
||||
$exportcsv=true;
|
||||
$csv_filename="{$appname}_Search_Results_" . date("Y-m-d_His") . ".csv";
|
||||
// disable caching
|
||||
$now = gmdate("D, d M Y H:i:s");
|
||||
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
|
||||
@@ -25,51 +51,69 @@ if ($_REQUEST['exportcsv']) {
|
||||
// disposition / encoding on response body
|
||||
header("Content-Disposition: attachment;filename={$csv_filename}");
|
||||
header("Content-Transfer-Encoding: binary");
|
||||
} else {
|
||||
$exportcsv=false;
|
||||
}
|
||||
|
||||
// import session variables
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
if (isset($_SESSION['userid'])) {
|
||||
$userid=$_SESSION['userid'];
|
||||
} else {
|
||||
$userid=NULL;
|
||||
}
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
$exportcsv=$_REQUEST['exportcsv'];
|
||||
if ($print || $exportcsv) {
|
||||
// if printer friendly or export csv was clicked, values will be
|
||||
// passed in serialized form as "all_parameters" so we need to load
|
||||
// those into $incoming[]
|
||||
$incoming=unserialize($_REQUEST['all_parameters']);
|
||||
} else {
|
||||
if (!$_REQUEST['cancel']) $incoming=arrayCopy($_REQUEST);
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
$search=$incoming['search'];
|
||||
$viewtype=$incoming['viewtype'];
|
||||
$s_device=$incoming['s_device'];
|
||||
$s_period=$incoming['s_period'];
|
||||
$s_period_effective=$incoming['s_period_effective'];
|
||||
$s_reported_by=$incoming['s_reported_by'];
|
||||
$s_report_date_start=$incoming['s_report_date_start'];
|
||||
$s_report_date_end=$incoming['s_report_date_end'];
|
||||
$s_report_time_start=$incoming['s_report_time_start'];
|
||||
$s_report_time_end=$incoming['s_report_time_end'];
|
||||
$s_action_date_start=$incoming['s_action_date_start'];
|
||||
$s_action_date_end=$incoming['s_action_date_end'];
|
||||
$s_action_time_start=$incoming['s_action_time_start'];
|
||||
$s_action_time_end=$incoming['s_action_time_end'];
|
||||
$s_action_by=$incoming['s_action_by'];
|
||||
$s_action_reason=$incoming['s_action_reason'];
|
||||
$s_action_text=$incoming['s_action_text'];
|
||||
$s_subsystem=$incoming['s_subsystem'];
|
||||
$s_id=$incoming['s_id'];
|
||||
$s_discrepancy_text=$incoming['s_discrepancy_text'];
|
||||
$s_status=$incoming['s_status'];
|
||||
$s_group=$incoming['s_group'];
|
||||
$sort=$incoming['sort'];
|
||||
$order=$incoming['order'];
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
* search
|
||||
* viewtype
|
||||
* s_device
|
||||
* s_discovered
|
||||
* s_functional
|
||||
* s_reported_by
|
||||
* s_report_date_start
|
||||
* s_report_date_end
|
||||
* s_report_time_start
|
||||
* s_report_time_end
|
||||
* s_action_date_start
|
||||
* s_action_date_end
|
||||
* s_action_time_start
|
||||
* s_action_time_end
|
||||
* s_action_by
|
||||
* s_action_reason
|
||||
* s_action_text
|
||||
* s_subsystem
|
||||
* s_id
|
||||
* s_discrepancy_text
|
||||
* s_status
|
||||
* s_group
|
||||
* sort
|
||||
* order
|
||||
*/
|
||||
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
if (!isset($search)) $search=false;
|
||||
if (!isset($viewtype)) $viewtype="summary";
|
||||
if (!isset($s_id)) $s_id=NULL;
|
||||
if (!isset($s_discrepancy_text)) $s_discrepancy_text=NULL;
|
||||
if (!isset($s_reported_by)) $s_reported_by=NULL;
|
||||
if (!isset($s_action_text)) $s_action_text=NULL;
|
||||
if (!isset($s_action_date_start)) $s_action_date_start=NULL;
|
||||
if (!isset($s_action_date_end)) $s_action_date_end=NULL;
|
||||
if (!isset($s_action_time_start)) $s_action_time_start=NULL;
|
||||
if (!isset($s_action_time_end)) $s_action_time_end=NULL;
|
||||
if (!isset($sort)) $sort=NULL;
|
||||
if (!isset($order)) $order=NULL;
|
||||
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
@@ -93,10 +137,10 @@ if (! $exportcsv) framework("begin","$appname",$pgtitle,$print);
|
||||
// get min, max report and action_dates from writeups table, validate input dates/times and set defaults
|
||||
$minmaxqry=mysqli_query($drs_db,"select min(report_date),max(report_date),min(action_date),max(action_date) from writeups");
|
||||
$minmaxdates=mysqli_fetch_row($minmaxqry);
|
||||
if (!$s_report_date_start || !validateDate($s_report_date_start)) $s_report_date_start=$minmaxdates[0];
|
||||
if (!$s_report_date_end || !validateDate($s_report_date_end)) $s_report_date_end=$minmaxdates[1];
|
||||
if (!$s_report_time_start || !validateTime($s_report_time_start)) $s_report_time_start="00:00:00";
|
||||
if (!$s_report_time_end || !validateTime($s_report_time_end)) $s_report_time_end="23:59:59";
|
||||
if (!isset($s_report_date_start) || !validateDate($s_report_date_start)) $s_report_date_start=$minmaxdates[0];
|
||||
if (!isset($s_report_date_end) || !validateDate($s_report_date_end)) $s_report_date_end=$minmaxdates[1];
|
||||
if (!isset($s_report_time_start) || !validateTime($s_report_time_start)) $s_report_time_start="00:00:00";
|
||||
if (!isset($s_report_time_end) || !validateTime($s_report_time_end)) $s_report_time_end="23:59:59";
|
||||
|
||||
if ($search) {
|
||||
// strip whitespace from beginning and end of text fields
|
||||
@@ -110,7 +154,7 @@ if ($search) {
|
||||
// device
|
||||
if ($s_device) {
|
||||
$query_string="{$query_string}(";
|
||||
$device_param="Devices:";
|
||||
$device_param="{$device_term}s:";
|
||||
foreach ($s_device as $dev_val) {
|
||||
$query_string="{$query_string}device=\"{$dev_val}\" or ";
|
||||
$device_dsp=dblookup($drs_db,"devices","id","name",$dev_val);
|
||||
@@ -118,7 +162,7 @@ if ($search) {
|
||||
}
|
||||
$device_param=rtrim($device_param,", ");
|
||||
$num_devices=mysqli_num_rows(mysqli_query($drs_db,"select id from devices"));
|
||||
if (count($s_device)==$num_devices) $device_param="Devices: any";
|
||||
if (count($s_device)==$num_devices) $device_param="{$device_term}s: any";
|
||||
$query_string=rtrim($query_string," or ");
|
||||
$query_string="{$query_string})";
|
||||
$query_string="{$query_string} and ";
|
||||
@@ -149,33 +193,33 @@ if ($search) {
|
||||
} else {
|
||||
$id_param="ID: any";
|
||||
}
|
||||
// period
|
||||
if ($s_period) {
|
||||
// discovered
|
||||
if ($s_discovered) {
|
||||
$query_string="{$query_string}(";
|
||||
$period_param="Periods:";
|
||||
foreach ($s_period as $per_val) {
|
||||
$query_string="{$query_string}period=\"{$per_val}\" or ";
|
||||
$period_dsp=$per_val;
|
||||
$period_param="{$period_param} {$period_dsp}, ";
|
||||
$discovered_param="{$discovered_term_short}:";
|
||||
foreach ($s_discovered as $disc_val) {
|
||||
$query_string="{$query_string}discovered=\"{$disc_val}\" or ";
|
||||
$disc_dsp=$disc_val;
|
||||
$discovered_param="{$discovered_param} {$disc_dsp}, ";
|
||||
}
|
||||
$period_param=rtrim($period_param,", ");
|
||||
$num_periods=mysqli_num_rows(mysqli_query($drs_db,"select id from periods"));
|
||||
if (count($s_period)==$num_periods) $period_param="Periods: any";
|
||||
$discovered_param=rtrim($discovered_param,", ");
|
||||
$num_discovereds=mysqli_num_rows(mysqli_query($drs_db,"select id from discovered"));
|
||||
if (count($s_discovered)==$num_discovereds) $discovered_param="{$discovered_term_short}s: any";
|
||||
$query_string=rtrim($query_string," or ");
|
||||
$query_string="{$query_string})";
|
||||
$query_string="{$query_string} and ";
|
||||
}
|
||||
// period_effective
|
||||
if ($s_period_effective) {
|
||||
// functional
|
||||
if ($s_functional) {
|
||||
$query_string="{$query_string}(";
|
||||
$eff_param="Period effective:";
|
||||
foreach ($s_period_effective as $eff_val) {
|
||||
$query_string="{$query_string}period_effective=\"{$eff_val}\" or ";
|
||||
if ($eff_val=="0") $eff_dsp="<font color=\"#FF0000\">NEF</font>";
|
||||
if ($eff_val=="1") $eff_dsp="<font color=\"#00FF00\">EFF</font>";
|
||||
$eff_param="{$eff_param} {$eff_dsp}, ";
|
||||
$func_param="$functional_term:";
|
||||
foreach ($s_functional as $func_val) {
|
||||
$query_string="{$query_string}functional=\"{$func_val}\" or ";
|
||||
if ($func_val=="0") $func_dsp="<font color=\"#FF0000\">$functional_no_short</font>";
|
||||
if ($func_val=="1") $func_dsp="<font color=\"#00FF00\">$functional_yes_short</font>";
|
||||
$func_param="{$func_param} {$func_dsp}, ";
|
||||
}
|
||||
$eff_param=rtrim($eff_param,", ");
|
||||
$func_param=rtrim($func_param,", ");
|
||||
$query_string=rtrim($query_string," or ");
|
||||
$query_string="{$query_string})";
|
||||
$query_string="{$query_string} and ";
|
||||
@@ -303,15 +347,22 @@ if ($search) {
|
||||
$query_string="select * from writeups where {$query_string} order by $sort $order";
|
||||
|
||||
// group membership
|
||||
if ($s_group) {
|
||||
$group_param="Group member:";
|
||||
if (isset($s_group)) {
|
||||
$group_param="Group member: ";
|
||||
// create an array of writeups that are members of the groups specified
|
||||
$group_writeups=[];
|
||||
foreach ($s_group as $group_val) {
|
||||
if ($group_val=="0") $group_dsp="No";
|
||||
if ($group_val=="1") $group_dsp="Yes";
|
||||
$group_param="{$group_param} {$group_dsp}, ";
|
||||
}
|
||||
$group_param=rtrim($group_param,", ");
|
||||
}
|
||||
$wulink_query=mysqli_query($drs_db,"select writeupid from links where linkgroup=$group_val");
|
||||
while($wulinkrow=mysqli_fetch_assoc($wulink_query)){
|
||||
$group_writeups[]=$wulinkrow['writeupid'];
|
||||
}
|
||||
$group_name=dblookup($drs_db,"groups","id","name",$group_val);
|
||||
$group_param="{$group_param} <font title=\"{$group_name}\">{$group_val}</font>, ";
|
||||
}
|
||||
$group_param=rtrim($group_param,", ");
|
||||
} else {
|
||||
$group_param="Group member: any";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +399,7 @@ if (! $exportcsv) {
|
||||
";
|
||||
// Device cell *********************
|
||||
echo "
|
||||
Device<br>
|
||||
$device_term<br>
|
||||
<select name=\"s_device[]\" id=\"ms-device\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
";
|
||||
$drow=mysqli_query($drs_db,"select * from devices order by id asc");
|
||||
@@ -392,17 +443,24 @@ if (! $exportcsv) {
|
||||
<tr>
|
||||
<td align=\"left\">
|
||||
";
|
||||
// Period cell **********************
|
||||
// Discovered cell **********************
|
||||
echo "
|
||||
Period<br>
|
||||
<select name=\"s_period[]\" id=\"ms-period\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
$discovered_term<br>
|
||||
<select name=\"s_discovered[]\" id=\"ms-discovered\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
";
|
||||
$prow=mysqli_query($drs_db,"select * from periods order by times asc");
|
||||
while ($pitem=mysqli_fetch_assoc($prow)) {
|
||||
if (!$search || in_array($pitem["id"],$s_period,true)) {
|
||||
printf("<option value=\"%s\" title=\"Period %s\" selected>%s</option>",$pitem["id"],$pitem["id"],$pitem["times"]);
|
||||
if ($disc_drop_data=="Name") {
|
||||
$discddtitle="whendiscovereddesc";
|
||||
$discddtext="whendiscoveredname";
|
||||
} else if ($disc_drop_data=="Desc") {
|
||||
$discddtitle="whendiscoveredname";
|
||||
$discddtext="whendiscovereddesc";
|
||||
}
|
||||
$discrow=mysqli_query($drs_db,"select * from discovered order by whendiscoveredname asc");
|
||||
while ($discitem=mysqli_fetch_assoc($discrow)) {
|
||||
if (!$search || in_array($discitem["id"],$s_discovered,true)) {
|
||||
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$discitem["id"],$discitem["$discddtitle"],$discitem["$discddtext"]);
|
||||
} else {
|
||||
printf("<option value=\"%s\" title=\"Period %s\">%s</option>",$pitem["id"],$pitem["id"],$pitem["times"]);
|
||||
printf("<option value=\"%s\" title=\"%s\">%s</option>",$discitem["id"],$discitem["$discddtitle"],$discitem["$discddtext"]);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
@@ -464,21 +522,21 @@ if (! $exportcsv) {
|
||||
</td>
|
||||
<td align=\"left\">
|
||||
";
|
||||
// Period effective cell ************
|
||||
// functional cell ************
|
||||
echo "
|
||||
Sim period effective? <img src=\"icons/question.png\" title=\"" . PERIOD_EFF_HELP_TXT . "\"><br>
|
||||
$functional_term? <img src=\"icons/question.png\" title=\"" . FUNCTIONAL_HELP_TXT . "\"><br>
|
||||
";
|
||||
if ($search) {
|
||||
$effstate=$nefstate="";
|
||||
if (in_array("1",$s_period_effective,true)) $effstate="selected";
|
||||
if (in_array("0",$s_period_effective,true)) $nefstate="selected";
|
||||
$funcyesstate=$funcnostate="";
|
||||
if (in_array("1",$s_functional,true)) $funcyesstate="selected";
|
||||
if (in_array("0",$s_functional,true)) $funcnostate="selected";
|
||||
} else {
|
||||
$effstate=$nefstate="selected";
|
||||
$funcyesstate=$funcnostate="selected";
|
||||
}
|
||||
echo "
|
||||
<select name=\"s_period_effective[]\" id=\"ms-period_effective\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
<option value=\"1\" $effstate>Effective</option>
|
||||
<option value=\"0\" $nefstate>Non-effective</option>
|
||||
<select name=\"s_functional[]\" id=\"ms-functional\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
<option value=\"1\" $funcyesstate>$functional_yes</option>
|
||||
<option value=\"0\" $funcnostate>$functional_no</option>
|
||||
</select>
|
||||
";
|
||||
// **********************************
|
||||
@@ -488,20 +546,31 @@ if (! $exportcsv) {
|
||||
";
|
||||
// Group status cell **************
|
||||
echo "
|
||||
Group Member?<br>
|
||||
Group Assignments:<br>
|
||||
<select style=\"max-width:40%;\" name=\"s_group[]\" id=\"ms-group\" multiple title=\"Select the groups the results should be a member of. If you uncheck them all, this field will not be included in the search.\">
|
||||
";
|
||||
if ($search) {
|
||||
$yesgroupstate=$nogroupstate="";
|
||||
if (in_array("1",$s_group,true)) $yesgroupstate="selected";
|
||||
if (in_array("0",$s_group,true)) $nogroupstate="selected";
|
||||
} else {
|
||||
$yesgroupstate=$nogroupstate="selected";
|
||||
}echo "
|
||||
<select name=\"s_group[]\" id=\"ms-group\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
||||
<option value=\"1\" $yesgroupstate title=\"Writeup is a member of a group\">Show group members</option>
|
||||
<option value=\"0\" $nogroupstate title=\"Writeup is not a member of a group\">Show non group members</option>
|
||||
if (!isset($s_group)) $s_group=[];
|
||||
$grow=mysqli_query($drs_db,"select * from groups order by id asc");
|
||||
while ($gitem=mysqli_fetch_assoc($grow)) {
|
||||
if ($gitem["name"]=="") {
|
||||
$gname="Group ".$gitem["id"];
|
||||
} else {
|
||||
$gname=$gitem["name"];
|
||||
}
|
||||
if($search) {
|
||||
if (in_array($gitem["id"],$s_group,true)) {
|
||||
printf("<option value=\"%s\" selected>%s</option>",$gitem["id"],$gname);
|
||||
} else {
|
||||
printf("<option value=\"%s\">%s</option>",$gitem["id"],$gname);
|
||||
}
|
||||
} else {
|
||||
printf("<option value=\"%s\">%s</option>",$gitem["id"],$gname);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
</select>
|
||||
";
|
||||
|
||||
// ************************************
|
||||
echo "
|
||||
</td></tr>
|
||||
@@ -542,7 +611,11 @@ if (! $exportcsv) {
|
||||
";
|
||||
$persrow=mysqli_query($drs_db,"select id,firstname,lastname from users order by lastname asc");
|
||||
while ($persitem=mysqli_fetch_assoc($persrow)) {
|
||||
printf("<option value=\"%s\" selected>%s %s</option>",$persitem["id"],$persitem["firstname"],$persitem["lastname"]);
|
||||
if (!$search || in_array($persitem["id"],$s_action_by,true)) {
|
||||
printf("<option value=\"%s\" selected>%s %s</option>",$persitem["id"],$persitem["firstname"],$persitem["lastname"]);
|
||||
} else {
|
||||
printf("<option value=\"%s\">%s %s</option>",$persitem["id"],$persitem["firstname"],$persitem["lastname"]);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
</select>
|
||||
@@ -560,7 +633,11 @@ if (! $exportcsv) {
|
||||
";
|
||||
$reasrow=mysqli_query($drs_db,"select id,text from reasons order by id asc");
|
||||
while ($reasitem=mysqli_fetch_assoc($reasrow)) {
|
||||
printf("<option value=\"%s\" selected>%s</option>",$reasitem["id"],$reasitem["text"]);
|
||||
if (!$search || in_array($reasitem["id"],$s_action_reason,true)) {
|
||||
printf("<option value=\"%s\" selected>%s</option>",$reasitem["id"],$reasitem["text"]);
|
||||
} else {
|
||||
printf("<option value=\"%s\">%s</option>",$reasitem["id"],$reasitem["text"]);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
</select>
|
||||
@@ -611,7 +688,7 @@ if (! $exportcsv) {
|
||||
} else {
|
||||
$summarystat="checked";
|
||||
}
|
||||
$idsort=$statussort=$datesort=$periodsort=$devicesort=$subsyssort=$repbysort=$discrepsort=$effsort="";
|
||||
$idsort=$statussort=$datesort=$discsort=$devicesort=$subsyssort=$repbysort=$discrepsort=$funcsort="";
|
||||
switch ($sort) {
|
||||
case "id":
|
||||
$idsort="checked";
|
||||
@@ -622,8 +699,8 @@ if (! $exportcsv) {
|
||||
case "report_date":
|
||||
$datesort="checked";
|
||||
break;
|
||||
case "period":
|
||||
$periodsort="checked";
|
||||
case "discovered":
|
||||
$discsort="checked";
|
||||
break;
|
||||
case "device":
|
||||
$devicesort="checked";
|
||||
@@ -637,8 +714,8 @@ if (! $exportcsv) {
|
||||
case "discrepancy_text":
|
||||
$discrepsort="checked";
|
||||
break;
|
||||
case "period_effective":
|
||||
$effsort="checked";
|
||||
case "functional":
|
||||
$funcsort="checked";
|
||||
break;
|
||||
default:
|
||||
$datesort="checked";
|
||||
@@ -660,12 +737,12 @@ if (! $exportcsv) {
|
||||
<input type=\"radio\" $idsort name=\"sort\" value=\"id\" id=\"idview\" ><label for=\"idview\" title=\"Sort by ID.\">ID</label>
|
||||
<input type=\"radio\" $statussort name=\"sort\" value=\"status\" id=\"statusview\" ><label for=\"statusview\" title=\"Sort by Status.\">Status</label>
|
||||
<input type=\"radio\" $datesort name=\"sort\" value=\"report_date\" id=\"dateview\" ><label for=\"dateview\" title=\"Sort by Report Date.\">Date</label>
|
||||
<input type=\"radio\" $periodsort name=\"sort\" value=\"period\" id=\"periodview\" ><label for=\"periodview\" title=\"Sort by Period.\">Period</label>
|
||||
<input type=\"radio\" $devicesort name=\"sort\" value=\"device\" id=\"deviceview\" ><label for=\"deviceview\" title=\"Sort by Device.\">Device</label>
|
||||
<input type=\"radio\" $discsort name=\"sort\" value=\"discovered\" id=\"discoveredview\" ><label for=\"discoveredview\" title=\"Sort by $discovered_term.\">$discovered_term_short</label>
|
||||
<input type=\"radio\" $devicesort name=\"sort\" value=\"device\" id=\"deviceview\" ><label for=\"deviceview\" title=\"Sort by $device_term.\">$device_term</label>
|
||||
<input type=\"radio\" $subsyssort name=\"sort\" value=\"subsystem\" id=\"subsysview\" ><label for=\"subsysview\" title=\"Sort by Subsystem.\">Subsystem</label>
|
||||
<input type=\"radio\" $repbysort name=\"sort\" value=\"reported_by\" id=\"repbyview\" ><label for=\"repbyview\" title=\"Sort by Reported by.\">Reported by</label>
|
||||
<input type=\"radio\" $discrepsort name=\"sort\" value=\"discrepancy_text\" id=\"discrepview\" ><label for=\"discrepview\" title=\"Sort by Discrepancy.\">Discrepancy</label>
|
||||
<input type=\"radio\" $effsort name=\"sort\" value=\"period_effective\" id=\"effview\" ><label for=\"effview\" title=\"Sort by Mission Effective.\">Msn Eff</label>
|
||||
<input type=\"radio\" $funcsort name=\"sort\" value=\"functional\" id=\"funcview\" ><label for=\"funcview\" title=\"Sort by $functional_term.\">$functional_term_short</label>
|
||||
<br>Sort Order:<br>
|
||||
<input type=\"radio\" $ascsort name=\"order\" value=\"asc\" id=\"ascview\" ><label for=\"ascview\" title=\"Sort results in ascending order.\">Ascending</label>
|
||||
<input type=\"radio\" $descsort name=\"order\" value=\"desc\" id=\"descview\" ><label for=\"descview\" title=\"Sort results in descending order.\">Descending</label>
|
||||
@@ -704,7 +781,7 @@ if ($search) {
|
||||
</table>
|
||||
<table border=\"0\">
|
||||
<tr>
|
||||
<td>$period_param</td><td> </td>
|
||||
<td>$discovered_param</td><td> </td>
|
||||
<td>$reportdate_param</td><td> </td>
|
||||
<td>$reporttime_param</td><td> </td>
|
||||
</tr>
|
||||
@@ -717,7 +794,7 @@ if ($search) {
|
||||
<table border=\"0\">
|
||||
<tr>
|
||||
<td>$repby_param</td><td> </td>
|
||||
<td>$eff_param</td><td> </td>
|
||||
<td>$func_param</td><td> </td>
|
||||
<td>$group_param</td><td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -752,35 +829,21 @@ if ($search) {
|
||||
}
|
||||
$writeup=mysqli_query($drs_db,$query_string);
|
||||
// create an array of ids returned by the query string
|
||||
$result_ids=array();
|
||||
$result_ids=[];
|
||||
while ($eachid=mysqli_fetch_assoc($writeup)) {
|
||||
$result_ids[]=$eachid['id'];
|
||||
}
|
||||
mysqli_data_seek($writeup,0);
|
||||
// create an array of all ids in groups
|
||||
$groupmems=array();
|
||||
$groupmem_qry=mysqli_query($drs_db,"select writeupid from links");
|
||||
while ($groupmemrow=mysqli_fetch_row($groupmem_qry)) {
|
||||
$groupmems[]=$groupmemrow[0];
|
||||
}
|
||||
$groupmems=array_unique($groupmems);
|
||||
// determine how many group members are in results
|
||||
$member_count=0;
|
||||
foreach($result_ids as $result_id) {
|
||||
if (in_array($result_id,$groupmems)) $member_count += 1;
|
||||
}
|
||||
if (in_array("1",$s_group)) $show_groupmems=true;
|
||||
if (in_array("0",$s_group)) $show_nongroupmems=true;
|
||||
|
||||
if ($show_groupmems == $show_nongroupmems) $num_results=mysqli_num_rows($writeup); //show members and nonmembers
|
||||
if ($show_groupmems && !$show_nongroupmems) $num_results=$member_count; //only show members
|
||||
if (!$show_groupmems && $show_nongroupmems) $num_results=mysqli_num_rows($writeup)-$member_count; //only show nonmembers
|
||||
mysqli_data_seek($writeup,0);
|
||||
if (!isset($group_writeups)) $group_writeups=[];
|
||||
reset($group_writeups);
|
||||
$num_results=mysqli_num_rows($writeup);
|
||||
if ($num_results > 0) {
|
||||
if ($exportcsv) {
|
||||
// generate csv file
|
||||
// create an array of lines of the csv data
|
||||
$csv_data=array();
|
||||
$csv_data[]=['WriteupID','Status','Device','Subsystem','Period','Effective','Discrepancy','Group','Report date','Report time','Reported by','Action taken by','Status Change Reason','Action taken','Action date','Action time'];
|
||||
$csv_data=[];
|
||||
$csv_data[]=['WriteupID','Status',$device_term,'Subsystem',$discovered_term_short,$functional_term,'Discrepancy','Group','Report date','Report time','Reported by','Action taken by','Status Change Reason','Action taken','Action date','Action time'];
|
||||
|
||||
$csv_fp=fopen('php://temp', 'w+');
|
||||
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
||||
@@ -799,14 +862,14 @@ if ($search) {
|
||||
// convert subsystem number to name for csv
|
||||
$csv_ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]);
|
||||
|
||||
// period number for csv
|
||||
$csv_period="{$tablerow["period"]}";
|
||||
// discovered name for csv
|
||||
$csv_discovered=dblookup($drs_db,"discovered","id","whendiscoveredname",$tablerow["discovered"]);
|
||||
|
||||
// determine effective text for csv
|
||||
if($tablerow["period_effective"]==1) {
|
||||
$csv_eff_text="EFF";
|
||||
// determine functional text for csv
|
||||
if($tablerow["functional"]==1) {
|
||||
$csv_func_text="$functional_yes_short";
|
||||
} else {
|
||||
$csv_eff_text="NEF";
|
||||
$csv_func_text="$functional_no_short";
|
||||
}
|
||||
|
||||
// discrepancy text for csv
|
||||
@@ -862,14 +925,10 @@ if ($search) {
|
||||
// action time for csv
|
||||
$csv_action_time="{$tablerow["action_time"]}";
|
||||
|
||||
|
||||
|
||||
if (($show_groupmems == $show_nongroupmems) || ($is_member && $show_groupmems) || (!$is_member && $show_nongroupmems)) {
|
||||
// add line of results to csv array
|
||||
$csv_data[]=[$csv_id, $csv_status_text, $csv_dname, $csv_ssname, $csv_period, $csv_eff_text, $csv_disc_txt, $csv_member_group_name, $csv_report_date, $csv_report_time, $csv_reported_by_text, $csv_action_by, $csv_reasonname, $csv_action_text, $csv_action_date, $csv_action_time];
|
||||
|
||||
}
|
||||
// add line of results to csv array
|
||||
$csv_data[]=[$csv_id, $csv_status_text, $csv_dname, $csv_ssname, $csv_discovered, $csv_func_text, $csv_disc_txt, $csv_member_group_name, $csv_report_date, $csv_report_time, $csv_reported_by_text, $csv_action_by, $csv_reasonname, $csv_action_text, $csv_action_date, $csv_action_time];
|
||||
}
|
||||
|
||||
foreach ($csv_data as $csv_fields) {
|
||||
// add row to csv buffer
|
||||
fputcsv($csv_fp, $csv_fields);
|
||||
@@ -879,7 +938,6 @@ if ($search) {
|
||||
rewind($csv_fp);
|
||||
// send file contents
|
||||
$csv_contents=stream_get_contents($csv_fp);
|
||||
//fpassthru($csv_fp);
|
||||
// Close our pointer and free up memory and /tmp space
|
||||
fclose($csv_fp);
|
||||
echo $csv_contents;
|
||||
@@ -891,12 +949,12 @@ if ($search) {
|
||||
<th style=\"width:1%;\">ID</th>
|
||||
<th style=\"width:1%;\">Status</th>
|
||||
<th style=\"width:100px;\">Date</th>
|
||||
<th style=\"width:1%;\">Period</th>
|
||||
<th style=\"width:1%;\">Device</th>
|
||||
<th style=\"width:1%;\">$discovered_term_short</th>
|
||||
<th style=\"width:1%;\">$device_term</th>
|
||||
<th style=\"width:1%;\">Subsystem</th>
|
||||
<th style=\"width:1%;\">Reported by</th>
|
||||
<th>Discrepancy</th>
|
||||
<th style=\"width:1%;\">Msn Eff</th>
|
||||
<th style=\"width:1%;\">$functional_term_short</th>
|
||||
</tr>
|
||||
";
|
||||
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
||||
@@ -904,11 +962,11 @@ if ($search) {
|
||||
$member_qry=mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\"");
|
||||
$is_member=mysqli_num_rows($member_qry);
|
||||
|
||||
// determine effective icon
|
||||
if($tablerow["period_effective"]==1) {
|
||||
$eff_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"Period Effective\" alt=\"Period Effective\">";
|
||||
// determine functional icon
|
||||
if($tablerow["functional"]==1) {
|
||||
$func_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes_short\">";
|
||||
} else {
|
||||
$eff_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"Period Non-effective\" alt=\"Period Non-effective\">";
|
||||
$func_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no_short\">";
|
||||
}
|
||||
|
||||
// determine status indicator
|
||||
@@ -918,8 +976,10 @@ if ($search) {
|
||||
|
||||
// convert device number to name
|
||||
$dname=dblookup($drs_db,"devices","id","name",$tablerow["device"]);
|
||||
// convert period number to times
|
||||
$ptimes=dblookup($drs_db,"periods","id","times",$tablerow["period"]);
|
||||
// convert discovered number to description
|
||||
$discname=dblookup($drs_db,"discovered","id","whendiscoveredname",$tablerow["discovered"]);
|
||||
// convert discovered number to description
|
||||
$discdesc=dblookup($drs_db,"discovered","id","whendiscovereddesc",$tablerow["discovered"]);
|
||||
// convert subsystem number to name
|
||||
$ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]);
|
||||
$disc_txt="{$tablerow["discrepancy_text"]}";
|
||||
@@ -937,11 +997,11 @@ if ($search) {
|
||||
}
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php?group=$group_num\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"$imgtitle\"></a></div>";
|
||||
} else {
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"View writeup groups\"></a></div>";
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"writeupdetail.php?id={$tablerow['id']}\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"Member of $group_count groups. Click here to view.\"></a></div>";
|
||||
}
|
||||
}
|
||||
|
||||
if (($show_groupmems == $show_nongroupmems) || ($is_member && $show_groupmems) || (!$is_member && $show_nongroupmems)) {
|
||||
if(in_array($tablerow['id'],$group_writeups) || count($s_group)==0) {
|
||||
// print table row
|
||||
printf(
|
||||
"<tr>
|
||||
@@ -958,12 +1018,12 @@ if ($search) {
|
||||
$tablerow["id"],$tablerow["id"],
|
||||
$statusind,
|
||||
$tablerow["report_date"],
|
||||
$ptimes,$tablerow["period"],
|
||||
$discdesc,$discname,
|
||||
$dname,
|
||||
$ssname,
|
||||
$tablerow["reported_by"],
|
||||
$disc_txt,
|
||||
$eff_icon
|
||||
$func_icon
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -976,7 +1036,7 @@ if ($search) {
|
||||
// determine if this is a member of a group
|
||||
$member_qry=mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\"");
|
||||
$is_member=mysqli_num_rows($member_qry);
|
||||
if (($show_groupmems == $show_nongroupmems) || ($is_member && $show_groupmems) || (!$is_member && $show_nongroupmems)) {
|
||||
if(in_array($tablerow['id'],$group_writeups) || count($s_group)==0) {
|
||||
displaywriteup($tablerow['id']);
|
||||
echo "<br>";
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
settings.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
@@ -35,17 +35,23 @@ $configqry=mysqli_query($drs_db,"select name,value from config");
|
||||
while ($configrow = mysqli_fetch_assoc($configqry)) {
|
||||
$constname=strtoupper($configrow['name']);
|
||||
if (isset($userid)) {
|
||||
$usrval=mysqli_fetch_row(mysqli_query($drs_db,"select value from profile where name=\"{$configrow['name']}\" and user=\"$userid\""))[0];
|
||||
$usrvalqry=mysqli_query($drs_db,"select value from profile where name=\"{$configrow['name']}\" and user=\"$userid\"");
|
||||
if (mysqli_num_rows($usrvalqry) > 0) {
|
||||
$usrrow=mysqli_fetch_row($usrvalqry);
|
||||
$usrval=$usrrow[0];
|
||||
}
|
||||
}
|
||||
if ($usrval) {
|
||||
if (isset($usrval)) {
|
||||
$constvalue=$usrval;
|
||||
unset($usrval);
|
||||
} else {
|
||||
$constvalue=$configrow['value'];
|
||||
}
|
||||
define("$constname","$constvalue");
|
||||
if (!defined("$constname")) define("$constname","$constvalue");
|
||||
}
|
||||
|
||||
//report no errors
|
||||
error_reporting(0);
|
||||
// level of error reporting. Set to 0 for production or E_ALL for development/troubleshooting
|
||||
//error_reporting(0);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
?>
|
||||
|
||||
@@ -2,15 +2,29 @@
|
||||
/*
|
||||
writeupdetail.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// redirect to writeups.php on change cancel
|
||||
if ($_REQUEST['cancel']) {
|
||||
if (array_key_exists('cancel',$_REQUEST)) {
|
||||
$id=$_REQUEST['id'];
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
@@ -22,7 +36,6 @@ if ($_REQUEST['cancel']) {
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming[]
|
||||
@@ -32,31 +45,42 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
$usersave=$incoming['usersave'];
|
||||
$techsave=$incoming['techsave'];
|
||||
$useredit=$incoming['useredit'];
|
||||
$techedit=$incoming['techedit'];
|
||||
$id=$incoming['id'];
|
||||
$device=$incoming['device'];
|
||||
$period=$incoming['period'];
|
||||
$period_effective=$incoming['period_effective'];
|
||||
$reported_by=$incoming['reported_by'];
|
||||
$report_date=$incoming['report_date'];
|
||||
$report_time=$incoming['report_time'];
|
||||
$subsystem=$incoming['subsystem'];
|
||||
$discrepancy_text=$incoming['discrepancy_text'];
|
||||
$status=$incoming['status'];
|
||||
$action_by=$incoming['action_by'];
|
||||
$action_date=$incoming['action_date'];
|
||||
$action_time=$incoming['action_time'];
|
||||
$action_reason=$incoming['action_reason'];
|
||||
$action_text=$incoming['action_text'];
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
* usersave
|
||||
* techsave
|
||||
* useredit
|
||||
* techedit
|
||||
* id
|
||||
* device
|
||||
* discovered
|
||||
* functional
|
||||
* reported_by
|
||||
* report_date
|
||||
* report_time
|
||||
* subsystem
|
||||
* discrepancy_text
|
||||
* status
|
||||
* action_by
|
||||
* action_date
|
||||
* action_time
|
||||
* action_reason
|
||||
* action_text
|
||||
* group
|
||||
*/
|
||||
|
||||
if (!isset($usersave)) $usersave=false;
|
||||
if (!isset($techsave)) $techsave=false;
|
||||
if (!isset($useredit)) $useredit=false;
|
||||
if (!isset($techedit)) $techedit=false;
|
||||
if (!isset($group)) $group=[];
|
||||
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
|
||||
if ($print=="Printer Friendly") {
|
||||
if ($print) {
|
||||
$mbgcolor=P_MENUBG_COLOR;
|
||||
} else {
|
||||
$mbgcolor=MENUBG_COLOR;
|
||||
@@ -66,6 +90,9 @@ $role=dblookup($drs_db,"users","id","role",$userid);
|
||||
|
||||
framework("begin","$appname","Writeup Detail",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
@@ -89,7 +116,19 @@ if ($usersave) {
|
||||
$clean_reported_by=mysqli_real_escape_string($drs_db,$reported_by);
|
||||
|
||||
// update the record in writeups
|
||||
mysqli_query($drs_db,"update writeups set device=\"$device\",period=\"$period\",period_effective=\"$period_effective\",reported_by=\"$clean_reported_by\",report_date=\"$report_date\",report_time=\"$report_time\",subsystem=\"$subsystem\",discrepancy_text=\"$clean_discrepancy_text\" where id=\"$id\"");
|
||||
mysqli_query($drs_db,"update writeups set device=\"$device\",discovered=\"$discovered\",functional=\"$functional\",reported_by=\"$clean_reported_by\",report_date=\"$report_date\",report_time=\"$report_time\",subsystem=\"$subsystem\",discrepancy_text=\"$clean_discrepancy_text\" where id=\"$id\"");
|
||||
|
||||
// remove writeup from all groups and add to only selected groups
|
||||
mysqli_query($drs_db,"delete from links where writeupid=\"$id\"");
|
||||
foreach($group as &$link) {
|
||||
if($link==0) {
|
||||
// new group was requested
|
||||
mysqli_query($drs_db,"insert into groups(name) value(\"\")");
|
||||
$newgroup=mysqli_insert_id($drs_db);
|
||||
$link=$newgroup;
|
||||
}
|
||||
mysqli_query($drs_db,"insert into links(linkgroup, writeupid) values(\"$link\", \"$id\")");
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($techsave) {
|
||||
@@ -115,8 +154,8 @@ elseif ($techsave) {
|
||||
// get current writeup data from database to populate fields
|
||||
$writeupdata=mysqli_fetch_assoc(mysqli_query($drs_db,"select * from writeups where id=\"$id\""));
|
||||
$device=$writeupdata['device'];
|
||||
$period=$writeupdata['period'];
|
||||
$period_effective=$writeupdata['period_effective'];
|
||||
$discovered=$writeupdata['discovered'];
|
||||
$functional=$writeupdata['functional'];
|
||||
$reported_by=$writeupdata['reported_by'];
|
||||
$report_date=$writeupdata['report_date'];
|
||||
$report_time=$writeupdata['report_time'];
|
||||
@@ -195,7 +234,7 @@ echo "
|
||||
<td align=\"left\">Writeup ID<br>
|
||||
<table border=\"1\" width=\"100%\"><tr><td><center>$id</center></td></tr></table>
|
||||
</td>
|
||||
<td align=\"left\">Device<br>
|
||||
<td align=\"left\">$device_term<br>
|
||||
";
|
||||
if ($useredit) {
|
||||
echo "
|
||||
@@ -248,41 +287,49 @@ echo "
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align=\"left\">Period<br>
|
||||
<td align=\"left\">$discovered_term<br>
|
||||
";
|
||||
if ($useredit) {
|
||||
echo "
|
||||
<select name=\"period\" id=\"period\">
|
||||
<select name=\"discovered\" id=\"discoveredselect\">
|
||||
";
|
||||
$prow=mysqli_query($drs_db,"select * from periods where active is true order by times asc");
|
||||
while ($pitem=mysqli_fetch_assoc($prow)) {
|
||||
if ($period==$pitem["id"]) {
|
||||
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$pitem["id"],$pitem["times"],$pitem["id"]);
|
||||
if ($disc_drop_data=="Name") {
|
||||
$discddtitle="whendiscovereddesc";
|
||||
$discddtext="whendiscoveredname";
|
||||
} else if ($disc_drop_data=="Desc") {
|
||||
$discddtitle="whendiscoveredname";
|
||||
$discddtext="whendiscovereddesc";
|
||||
}
|
||||
$discrow=mysqli_query($drs_db,"select * from discovered where active is true order by whendiscoveredname asc");
|
||||
while ($discitem=mysqli_fetch_assoc($discrow)) {
|
||||
if ($discovered==$discitem["id"]) {
|
||||
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$discitem["id"],$discitem["$discddtitle"],$discitem["$discddtext"]);
|
||||
} else {
|
||||
printf("<option value=\"%s\" title=\"%s\">%s</option>",$pitem["id"],$pitem["times"],$pitem["id"]);
|
||||
printf("<option value=\"%s\" title=\"%s\">%s</option>",$discitem["id"],$discitem["$discddtitle"],$discitem["$discddtext"]);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
</select>
|
||||
";
|
||||
} else {
|
||||
$pertimes=dblookup($drs_db,"periods","id","times",$period);
|
||||
$discname=dblookup($drs_db,"discovered","id","whendiscoveredname",$discovered);
|
||||
$discdesc=dblookup($drs_db,"discovered","id","whendiscovereddesc",$discovered);
|
||||
echo "
|
||||
<table border=\"1\" width=\"100%\"><tr><td><font title=\"$pertimes\">$period</font></td></tr></table>
|
||||
<table border=\"1\" width=\"100%\"><tr><td><font title=\"$discdesc\">$discname</font></td></tr></table>
|
||||
";
|
||||
}
|
||||
echo "
|
||||
</td>
|
||||
";
|
||||
|
||||
$effstate=$nefstate="";
|
||||
if($period_effective==1) {
|
||||
$effstate="checked";
|
||||
$eff_ind="Effective";
|
||||
$funcyesstate=$funcnostate="";
|
||||
if($functional==1) {
|
||||
$funcyesstate="checked";
|
||||
$func_ind="$functional_yes";
|
||||
}
|
||||
if($period_effective==0) {
|
||||
$nefstate="checked";
|
||||
$eff_ind="Non-Effective";
|
||||
if($functional==0) {
|
||||
$funcnostate="checked";
|
||||
$func_ind="$functional_no";
|
||||
}
|
||||
|
||||
$openstate=$closedstate=$deferredstate="";
|
||||
@@ -293,7 +340,7 @@ if($status==3) $deferredstate="selected";
|
||||
echo "
|
||||
<td align=\"left\" >Report Date<br>
|
||||
";
|
||||
if ($useredit) {
|
||||
if ($useredit && $role) {
|
||||
echo "
|
||||
<input type=\"text\" name=\"report_date\" size=\"10\" maxlength=\"10\" value=\"$report_date\" id=\"reportdatepicker\" title=\"Format: YYYY-MM-DD\"></td>
|
||||
";
|
||||
@@ -305,7 +352,7 @@ if ($useredit) {
|
||||
echo "
|
||||
<td align=\"left\">Report Time<br>
|
||||
";
|
||||
if ($useredit) {
|
||||
if ($useredit && $role) {
|
||||
echo "
|
||||
<input type=\"text\" name=\"report_time\" size=\"8\" maxlength=\"8\" value=\"$report_time\" title=\"Format: HH:MM:SS\"></td>
|
||||
";
|
||||
@@ -340,16 +387,16 @@ if ($useredit) {
|
||||
";
|
||||
}
|
||||
echo "
|
||||
<td align=\"left\">Sim period effective? <img src=\"icons/question.png\" title=\"" . PERIOD_EFF_HELP_TXT . "\"><br>
|
||||
<td align=\"left\">$functional_term? <img src=\"icons/question.png\" title=\"" . FUNCTIONAL_HELP_TXT . "\"><br>
|
||||
";
|
||||
if ($useredit) {
|
||||
echo "
|
||||
<input type=\"radio\" name=\"period_effective\" value=\"1\" $effstate> Yes
|
||||
<input type=\"radio\" name=\"period_effective\" value=\"0\" $nefstate> No
|
||||
<input type=\"radio\" name=\"functional\" value=\"1\" $funcyesstate> Yes
|
||||
<input type=\"radio\" name=\"functional\" value=\"0\" $funcnostate> No
|
||||
";
|
||||
} else {
|
||||
echo "
|
||||
<table border=\"1\" width=\"100%\"><tr><td><font title=\"$eff_title\">$eff_ind</font></td></tr></table>
|
||||
<table border=\"1\" width=\"100%\"><tr><td><font title=\"" . FUNCTIONAL_HELP_TXT . "\">$func_ind</font></td></tr></table>
|
||||
";
|
||||
}
|
||||
echo "
|
||||
@@ -360,13 +407,76 @@ if ($useredit) {
|
||||
<td align=\"right\" valign=\"bottom\"><input type=\"submit\" name=\"usersave\" value=\"Save Changes\"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td></td><td align=\"right\" valign=\"bottom\">
|
||||
<td colspan=\"2\">Group Assignments:  
|
||||
";
|
||||
// Group multi-select ********************
|
||||
echo "
|
||||
<select style=\"max-width:60%;\" name=\"group[]\" id=\"ms-group\" multiple title=\"Select the groups this writeup should be a member of.\">
|
||||
";
|
||||
$linkquery=mysqli_query($drs_db,"select * from links where writeupid=\"$id\"");
|
||||
// create an array of ids returned by group query
|
||||
$wugroups=[];
|
||||
while ($eachlink=mysqli_fetch_assoc($linkquery)) {
|
||||
$wugroups[]=$eachlink['linkgroup'];
|
||||
}
|
||||
reset($wugroups);
|
||||
$grow=mysqli_query($drs_db,"select * from groups order by id asc");
|
||||
printf("<option value=\"%s\">%s</option>",0,"New group");
|
||||
while ($gitem=mysqli_fetch_assoc($grow)) {
|
||||
if ($gitem["name"]=="") {
|
||||
$gname="Group ".$gitem["id"];
|
||||
} else {
|
||||
$gname=$gitem["name"];
|
||||
}
|
||||
if (in_array($gitem["id"],$wugroups,true)) {
|
||||
printf("<option value=\"%s\" selected>%s</option>",$gitem["id"],$gname);
|
||||
} else {
|
||||
printf("<option value=\"%s\">%s</option>",$gitem["id"],$gname);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
</select>
|
||||
";
|
||||
echo "
|
||||
</td>
|
||||
<td align=\"right\" valign=\"bottom\">
|
||||
<input type=\"submit\" name=\"cancel\" value=\"Cancel Changes\"></td>
|
||||
</tr>
|
||||
";
|
||||
} else {
|
||||
echo "<tr></tr><td colspan=\"2\">Group Assignments:  ";
|
||||
$wustat=dblookup($drs_db,"writeups","id","status",$id);
|
||||
if ($wustat==2 && !$role) $allowuseredit="disabled";
|
||||
if ($wustat==2 && !$role) {
|
||||
$allowuseredit="disabled";
|
||||
} else {
|
||||
$allowuseredit=NULL;
|
||||
}
|
||||
// Group multi-select ********************
|
||||
echo "
|
||||
<select style=\"max-width:60%;\" name=\"groupshow\" id=\"ms-group\" multiple title=\"The groups this writeup is a member of.\">
|
||||
";
|
||||
$linkquery=mysqli_query($drs_db,"select * from links where writeupid=\"$id\"");
|
||||
// create an array of ids returned by group query
|
||||
$wugroups=[];
|
||||
while ($eachlink=mysqli_fetch_assoc($linkquery)) {
|
||||
$wugroups[]=$eachlink['linkgroup'];
|
||||
}
|
||||
reset($wugroups);
|
||||
$grow=mysqli_query($drs_db,"select * from groups order by id asc");
|
||||
while ($gitem=mysqli_fetch_assoc($grow)) {
|
||||
if ($gitem["name"]=="") {
|
||||
$gname="Group ".$gitem["id"];
|
||||
} else {
|
||||
$gname=$gitem["name"];
|
||||
}
|
||||
if (in_array($gitem["id"],$wugroups,true)) {
|
||||
printf("<option value=\"%s\" selected disabled>%s</option>",$gitem["id"],$gname);
|
||||
}
|
||||
}
|
||||
echo "
|
||||
</select>
|
||||
</td>
|
||||
";
|
||||
echo "
|
||||
<td align=\"right\" valign=\"bottom\"><input $allowuseredit type=\"submit\" name=\"useredit\" value=\"Edit this Discrepancy\"></td>
|
||||
</tr>
|
||||
@@ -515,7 +625,11 @@ if ($techedit) {
|
||||
</tr>
|
||||
";
|
||||
} else {
|
||||
if (!$role) $live="disabled";
|
||||
if (!$role) {
|
||||
$live="disabled";
|
||||
} else {
|
||||
$live=NULL;
|
||||
}
|
||||
echo "
|
||||
<td align=\"right\" valign=\"bottom\"><input $live type=\"submit\" name=\"techedit\" value=\"Edit this Action\"></td>
|
||||
</tr>
|
||||
|
||||
@@ -2,18 +2,35 @@
|
||||
/*
|
||||
writeups.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2024 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
if (array_key_exists('print',$_REQUEST)) {
|
||||
$print=true;
|
||||
} else {
|
||||
$print=false;
|
||||
}
|
||||
|
||||
// redirect to login page if access_mode is untrusted and user is
|
||||
// not logged in
|
||||
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
||||
header("Cache-Control:no-cache, must-revalidate");
|
||||
header("Pragma:no-cache");
|
||||
header("Location:login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// import session variables
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
if (isset($_SESSION['userid'])) {
|
||||
$userid=$_SESSION['userid'];
|
||||
} else {
|
||||
$userid=NULL;
|
||||
}
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
if ($print) {
|
||||
// if printer friendly was clicked, values will be passed in serialized
|
||||
// form as "all_parameters" so we need to load those into $incoming[]
|
||||
@@ -24,20 +41,25 @@ if ($print) {
|
||||
$incoming=arrayCopy($_REQUEST);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
// extract incoming array keys into variables
|
||||
extract($incoming, EXTR_SKIP);
|
||||
/*
|
||||
* possible keys are:
|
||||
*
|
||||
* view
|
||||
* start_date
|
||||
* end_date
|
||||
* showtoday
|
||||
* showyesterday
|
||||
* show7day
|
||||
* show30day
|
||||
* showdays
|
||||
* viewtype
|
||||
* togroup
|
||||
* addtogroup
|
||||
* selectedids
|
||||
*/
|
||||
|
||||
$view=$incoming['view'];
|
||||
$start_date=$incoming['start_date'];
|
||||
$end_date=$incoming['end_date'];
|
||||
$showtoday=$incoming['showtoday'];
|
||||
$showyesterday=$incoming['showyesterday'];
|
||||
$show7day=$incoming['show7day'];
|
||||
$show30day=$incoming['show30day'];
|
||||
$viewtype=$incoming['viewtype'];
|
||||
|
||||
$togroup=$incoming['togroup'];
|
||||
$addtogroup=$incoming['addtogroup'];
|
||||
$selectedids=$incoming['selectedids'];
|
||||
|
||||
// assign variables from constants
|
||||
$appname=APP_NAME;
|
||||
@@ -51,7 +73,14 @@ if ($print) {
|
||||
$role=dblookup($drs_db,"users","id","role",$userid);
|
||||
|
||||
// define local functions
|
||||
function opentable($start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
function opentable($incoming,$start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
// grab some important global variables
|
||||
global $device_term;
|
||||
global $discovered_term, $discovered_term_short, $disc_drop_data;
|
||||
global $functional_term, $functional_term_short;
|
||||
global $functional_yes, $functional_no;
|
||||
global $functional_yes_short, $functional_no_short;
|
||||
|
||||
// show date range selector
|
||||
echo "
|
||||
<form method=post action=\"writeups.php\">
|
||||
@@ -71,7 +100,7 @@ function opentable($start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
echo "
|
||||
</form>
|
||||
";
|
||||
$writeup=mysqli_query($drs_db,"select * from writeups where status=".STAT_OPEN." and report_date between \"$start_date\" and \"$end_date\" order by report_date desc,period desc,report_time desc");
|
||||
$writeup=mysqli_query($drs_db,"select * from writeups where status=".STAT_OPEN." and report_date between \"$start_date\" and \"$end_date\" order by report_date desc,report_time desc");
|
||||
if (mysqli_num_rows($writeup)) {
|
||||
$now=date("H:i l");
|
||||
echo "
|
||||
@@ -80,20 +109,20 @@ function opentable($start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
<tr>
|
||||
<th style=\"width:1%;\">ID</th>
|
||||
<th style=\"width:100px;\">Date</th>
|
||||
<th style=\"width:1%;\">Period</th>
|
||||
<th style=\"width:1%;\">Device</th>
|
||||
<th style=\"width:1%;\">$discovered_term_short</th>
|
||||
<th style=\"width:1%;\">$device_term</th>
|
||||
<th style=\"width:1%;\">Subsystem</th>
|
||||
<th style=\"width:1%;\">Reported by</th>
|
||||
<th>Discrepancy</th>
|
||||
<th style=\"width:1%;\">Msn Eff</th>
|
||||
<th style=\"width:1%;\">$functional_term_short</th>
|
||||
</tr>
|
||||
";
|
||||
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
||||
// determine effective icon
|
||||
if($tablerow["period_effective"]==1) {
|
||||
$eff_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"Period Effective\" alt=\"Period Effective\">";
|
||||
if($tablerow["functional"]==1) {
|
||||
$funcind="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes_short\">";
|
||||
} else {
|
||||
$eff_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"Period Non-effective\" alt=\"Period Non-effective\">";
|
||||
$funcind="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no_short\">";
|
||||
}
|
||||
|
||||
// convert device number to name
|
||||
@@ -102,8 +131,12 @@ function opentable($start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
// convert subsystem number to name
|
||||
$ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]);
|
||||
|
||||
// determine times for period
|
||||
$ptimes=mysqli_fetch_row(mysqli_query($drs_db,"select times from periods where id=\"{$tablerow['period']}\""))[0];
|
||||
// convert subsystem number to description
|
||||
$ssdesc=dblookup($drs_db,"subsystems","id","description",$tablerow["subsystem"]);
|
||||
|
||||
// determine values for when discovered
|
||||
$whendiscdesc=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscovereddesc from discovered where id=\"{$tablerow['discovered']}\""))[0];
|
||||
$whendiscname=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscoveredname from discovered where id=\"{$tablerow['discovered']}\""))[0];
|
||||
|
||||
$disc_txt="{$tablerow['discrepancy_text']}";
|
||||
|
||||
@@ -122,7 +155,7 @@ function opentable($start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
if ($group_count == 1) {
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php?group=$member_group\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"$imgtitle\"></a></div>";
|
||||
} else {
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"View writeup groups\"></a></div>";
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"writeupdetail.php?id={$tablerow['id']}\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"Member of $group_count groups. Click here to view.\"></a></div>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,28 +166,28 @@ function opentable($start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
<td valign=\"top\">%s</td>
|
||||
<td valign=\"top\"><font title=\"%s\">%s</font></td>
|
||||
<td valign=\"top\">%s</td>
|
||||
<td valign=\"top\">%s</td>
|
||||
<td valign=\"top\"><font title=\"%s\">%s</td>
|
||||
<td valign=\"top\">%s</td>
|
||||
<td valign=\"top\">%s</td>
|
||||
<td align=\"center\" valign=\"top\">%s</td>
|
||||
</tr>\n",
|
||||
$tablerow["id"],$tablerow["id"],
|
||||
$tablerow["report_date"],
|
||||
$ptimes, $tablerow["period"],
|
||||
$whendiscdesc, $whendiscname,
|
||||
$dname,
|
||||
$ssname,
|
||||
$ssdesc, $ssname,
|
||||
$tablerow["reported_by"],
|
||||
$disc_txt,
|
||||
$eff_icon
|
||||
$funcind
|
||||
);
|
||||
}
|
||||
echo "</table>\n";
|
||||
} else {
|
||||
if ($_REQUEST['showyesterday']) {
|
||||
if (array_key_exists('showyesterday',$incoming)) {
|
||||
$datespec="yesterday";
|
||||
} elseif ($_REQUEST['show7day']) {
|
||||
} elseif (array_key_exists('show7day',$incoming)) {
|
||||
$datespec="the last 7 days";
|
||||
} elseif ($_REQUEST['show30day']) {
|
||||
} elseif (array_key_exists('show30day',$incoming)) {
|
||||
$datespec="the last 30 days";
|
||||
} else {
|
||||
$datespec="today";
|
||||
@@ -164,6 +197,13 @@ function opentable($start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
}
|
||||
|
||||
function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$role) {
|
||||
// grab some important global variables
|
||||
global $device_term;
|
||||
global $discovered_term, $discovered_term_short, $disc_drop_data;
|
||||
global $functional_term, $functional_term_short;
|
||||
global $functional_yes, $functional_no;
|
||||
global $functional_yes_short, $functional_no_short;
|
||||
|
||||
// show date range selector
|
||||
$summarystat=$detailstat="";
|
||||
if ($viewtype=="detail") {
|
||||
@@ -179,8 +219,24 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol
|
||||
echo "
|
||||
<input type=\"submit\" name=\"showtoday\" value=\"Today\">
|
||||
<input type=\"submit\" name=\"showyesterday\" value=\"Yesterday\">
|
||||
<input type=\"submit\" name=\"show7day\" value=\"Last 7 Days\">
|
||||
<input type=\"submit\" name=\"show30day\" value=\"Last 30 Days\">
|
||||
<select name=\"showdays\" id=\"showdays\">
|
||||
<option value=\"\">Date range...</option>
|
||||
<option value=\"-3\">Last 3 days</option>
|
||||
<option value=\"-7\">Last 7 days</option>
|
||||
<option value=\"-30\">Last 30 days</option>
|
||||
<option value=\"-90\">Last 90 days</option>
|
||||
<option value=\"-180\">Last 180 days</option></option>
|
||||
<option value=\"-365\">Last 365 days</option>
|
||||
<option value=\"-\">All past</option>
|
||||
<option value=\"+3\">Next 3 days</option>
|
||||
<option value=\"+7\">Next 7 days</option>
|
||||
<option value=\"+30\">Next 30 days</option>
|
||||
<option value=\"+90\">Next 90 days</option>
|
||||
<option value=\"+180\">Next 180 days</option></option>
|
||||
<option value=\"+365\">Next 365 days</option>
|
||||
<option value=\"+\">All future</option>
|
||||
</select>
|
||||
|
||||
";
|
||||
}
|
||||
echo "
|
||||
@@ -196,7 +252,7 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol
|
||||
<br><br>
|
||||
";
|
||||
}
|
||||
$writeup=mysqli_query($drs_db,"select * from writeups where report_date between \"$start_date\" and \"$end_date\" order by report_date desc,period desc,report_time desc");
|
||||
$writeup=mysqli_query($drs_db,"select * from writeups where report_date between \"$start_date\" and \"$end_date\" order by report_date desc,report_time desc");
|
||||
if (mysqli_num_rows($writeup)) {
|
||||
$now=date("H:i l");
|
||||
if ($viewtype == "summary") {
|
||||
@@ -213,20 +269,20 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol
|
||||
<th style=\"width:1%;\">ID</th>
|
||||
<th style=\"width:1%;\">Status</th>
|
||||
<th style=\"width:100px;\">Date</th>
|
||||
<th style=\"width:1%;\">Period</th>
|
||||
<th style=\"width:1%;\">Device</th>
|
||||
<th style=\"width:1%;\">$discovered_term_short</th>
|
||||
<th style=\"width:1%;\">$device_term</th>
|
||||
<th style=\"width:1%;\">Subsystem</th>
|
||||
<th style=\"width:1%;\">Reported by</th>
|
||||
<th>Discrepancy</th>
|
||||
<th style=\"width:1%;\">Msn Eff</th>
|
||||
<th style=\"width:1%;\">$functional_term_short</th>
|
||||
</tr>
|
||||
";
|
||||
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
||||
// determine effective icon
|
||||
if($tablerow["period_effective"]==1) {
|
||||
$eff_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"Period Effective\" alt=\"Period Effective\">";
|
||||
if($tablerow["functional"]==1) {
|
||||
$funcind="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes_short\">";
|
||||
} else {
|
||||
$eff_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"Period Non-effective\" alt=\"Period Non-effective\">";
|
||||
$funcind="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no_short\">";
|
||||
}
|
||||
|
||||
// determine status indicator
|
||||
@@ -240,9 +296,11 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol
|
||||
// convert subsystem number to name
|
||||
$ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]);
|
||||
|
||||
// determine times for period
|
||||
$ptimes=mysqli_fetch_row(mysqli_query($drs_db,"select times from periods where id=\"{$tablerow['period']}\""))[0];
|
||||
$disc_txt="{$tablerow['discrepancy_text']}";
|
||||
// determine values for when discovered
|
||||
$whendiscdesc=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscovereddesc from discovered where id=\"{$tablerow['discovered']}\""))[0];
|
||||
$whendiscname=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscoveredname from discovered where id=\"{$tablerow['discovered']}\""))[0];
|
||||
|
||||
$disc_txt="{$tablerow['discrepancy_text']}";
|
||||
|
||||
// determine if this is a member of a group
|
||||
$member_qry=mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\"");
|
||||
@@ -259,7 +317,7 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol
|
||||
if ($group_count == 1) {
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php?group=$member_group\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"$imgtitle\"></a></div>";
|
||||
} else {
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"View writeup groups\"></a></div>";
|
||||
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"writeupdetail.php?id={$tablerow['id']}\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"Member of $group_count groups. Click here to view.\"></a></div>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,12 +344,12 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol
|
||||
$tablerow["id"],$tablerow["id"],
|
||||
$statusind,
|
||||
$tablerow["report_date"],
|
||||
$ptimes, $tablerow["period"],
|
||||
$whendiscdesc, $whendiscname,
|
||||
$dname,
|
||||
$ssname,
|
||||
$tablerow["reported_by"],
|
||||
$disc_txt,
|
||||
$eff_icon
|
||||
$funcind
|
||||
);
|
||||
}
|
||||
echo "</table>\n";
|
||||
@@ -317,7 +375,12 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol
|
||||
";
|
||||
$tgrow=mysqli_query($drs_db,"select id,name from groups order by id asc");
|
||||
while ($tgitem=mysqli_fetch_assoc($tgrow)) {
|
||||
printf("<option value=\"%s\">%s</option>",$tgitem["id"],$tgitem["name"]);
|
||||
if($tgitem["name"]=="") {
|
||||
$tgname="Group ".$tgitem["id"];
|
||||
} else {
|
||||
$tgname=$tgitem["name"];
|
||||
}
|
||||
printf("<option value=\"%s\">%s</option>",$tgitem["id"],$tgname);
|
||||
}
|
||||
echo "
|
||||
</select>
|
||||
@@ -334,39 +397,57 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol
|
||||
|
||||
// use default date values if not supplied
|
||||
$today = date("Y-m-d");
|
||||
if ($start_date=="") $start_date=$today;
|
||||
if ($end_date=="") $end_date=$today;
|
||||
if ($showtoday) {
|
||||
if (!isset($start_date)) $start_date=$today;
|
||||
if (!isset($end_date)) $end_date=$today;
|
||||
if (isset($showtoday)) {
|
||||
$start_date=$today;
|
||||
$end_date=$today;
|
||||
}
|
||||
if ($showyesterday) {
|
||||
if (isset($showyesterday)) {
|
||||
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 1 day)"))[0];
|
||||
$end_date=$start_date;
|
||||
}
|
||||
if ($show7day) {
|
||||
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 7 day)"))[0];
|
||||
$end_date=$today;
|
||||
}
|
||||
if ($show30day) {
|
||||
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 30 day)"))[0];
|
||||
$end_date=$today;
|
||||
|
||||
if (isset($showdays) && $showdays != "") {
|
||||
$minmaxqry=mysqli_query($drs_db,"select min(report_date),max(report_date) from writeups");
|
||||
$minmaxdates=mysqli_fetch_row($minmaxqry);
|
||||
$direction=$showdays[0];
|
||||
$numdays=substr($showdays,1);
|
||||
if ($direction=="-") {
|
||||
if ($numdays=="") {
|
||||
$start_date=$minmaxdates[0];
|
||||
} else {
|
||||
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval $numdays day)"))[0];
|
||||
}
|
||||
$end_date=$today;
|
||||
}
|
||||
if ($direction=="+") {
|
||||
$start_date=$today;
|
||||
if ($numdays=="") {
|
||||
$end_date=$minmaxdates[1];
|
||||
} else {
|
||||
$end_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_add(curdate(),interval $numdays day)"))[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($view) {
|
||||
if (isset($view)) {
|
||||
$pgtitle="Recent Writeups";
|
||||
} else {
|
||||
$pgtitle="Open Writeups";
|
||||
}
|
||||
|
||||
framework("begin","$appname",$pgtitle,$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
|
||||
if ($addtogroup && $togroup && $selectedids && $role) {
|
||||
if (isset($addtogroup) && isset($togroup) && isset($selectedids) && $role!=NULL) {
|
||||
$fail=false;
|
||||
if ($togroup=="newgroup") {
|
||||
// Create a new group
|
||||
@@ -397,7 +478,7 @@ pageblock("right","begin");
|
||||
banner($print);
|
||||
echo "<br>";
|
||||
|
||||
if ($addtogroup) {
|
||||
if (isset($addtogroup)) {
|
||||
if (count($selectedids) > 1) {
|
||||
$plural="s";
|
||||
} else {
|
||||
@@ -409,14 +490,14 @@ if ($addtogroup) {
|
||||
format_message(2,"<strong>An error was encountered when adding writeup$plural.</strong> The error was \" $fail \"");
|
||||
}
|
||||
}
|
||||
if (!$viewtype) $viewtype="summary";
|
||||
if (!isset($viewtype)) $viewtype="summary";
|
||||
|
||||
if ($view==1) {
|
||||
if (isset($view)) {
|
||||
// show writeup table
|
||||
viewtable($start_date,$end_date,$print,$drs_db,$viewtype,$role);
|
||||
} else {
|
||||
// show open table
|
||||
opentable($start_date,$end_date,$print,$drs_db,$viewtype);
|
||||
opentable($incoming,$start_date,$end_date,$print,$drs_db,$viewtype);
|
||||
}
|
||||
|
||||
echo "<br>";
|
||||
|
||||
405
install.sh
405
install.sh
@@ -2,12 +2,12 @@
|
||||
|
||||
# install.sh
|
||||
# OpenDRS Online Discrepancy Reporting System
|
||||
# Copyright (C) 2021 Rod Wright
|
||||
# Copyright (C) 2024 Rod Wright
|
||||
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
|
||||
DRS_VERSION="1.1.2"
|
||||
DRS_VERSION="1.4.0"
|
||||
DOC_ROOT="/var/www"
|
||||
INSTALL_LOC="opendrs"
|
||||
APACHE_USER="www-data"
|
||||
@@ -21,7 +21,15 @@ if [[ $EUID -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# initial stuff
|
||||
|
||||
# Prevent unattended-upgrades from interfering
|
||||
restart_uu=false
|
||||
while systemctl status unattended-upgrades >/dev/null 2>&1
|
||||
do
|
||||
systemctl stop unattended-upgrades
|
||||
sleep 5
|
||||
restart_uu=true
|
||||
done
|
||||
echo ""
|
||||
echo ""
|
||||
echo "* * * * * Welcome to OpenDRS $DRS_VERSION Installation * * * * *"
|
||||
@@ -29,7 +37,341 @@ echo ""
|
||||
echo ""
|
||||
echo "Just press enter at the prompts to accept the defaults shown."
|
||||
echo ""
|
||||
# Check for prerequisites and prompt to install
|
||||
echo "Checking for prerequisites..."
|
||||
echo ""
|
||||
echo ""
|
||||
echo " Checking for apache2 installation..."
|
||||
echo ""
|
||||
if dpkg -l|grep apache2 >/dev/null 2>&1
|
||||
then
|
||||
echo ""
|
||||
echo "apache2 is installed. Continuing."
|
||||
echo ""
|
||||
else
|
||||
echo "OpenDRS requires the apache2 http server, but it doesn't seem"
|
||||
echo -n "to be installed. Install it now? [Y/n]: "
|
||||
read reqinstall
|
||||
if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ]
|
||||
then
|
||||
echo "OpenDRS requires apache2, but you have elected not to install it."
|
||||
echo "Installation cannot continue."
|
||||
exit 1
|
||||
else
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Proceeding with apache2 installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
apt-get install -y apache2
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Finished with apache2 installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo " Checking for php installation..."
|
||||
echo ""
|
||||
if dpkg -l|grep php >/dev/null 2>&1
|
||||
then
|
||||
echo ""
|
||||
echo "php is installed. Continuing."
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo ""
|
||||
echo "OpenDRS requires php, but it doesn't seem to be installed."
|
||||
echo -n "Install it now? [Y/n]: "
|
||||
read reqinstall
|
||||
if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ]
|
||||
then
|
||||
echo "OpenDRS requires php, but you have elected not to install it."
|
||||
echo "Installation cannot continue."
|
||||
exit 1
|
||||
else
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Proceeding with php installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
apt-get install -y php
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Finished with php installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo " Checking for mariadb or mysql installation..."
|
||||
echo ""
|
||||
|
||||
if dpkg -l|grep mariadb-server >/dev/null 2>&1
|
||||
then
|
||||
echo ""
|
||||
echo "mariadb-server is installed. Continuing."
|
||||
echo ""
|
||||
elif dpkg -l|grep mysql-server >/dev/null 2>&1
|
||||
then
|
||||
echo ""
|
||||
echo "mysql-server is installed. Continuing."
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo ""
|
||||
echo "OpenDRS requires either mariadb or mysql server, but neither seem"
|
||||
echo -n "to be installed. Install mariadb-server now? [Y/n]: "
|
||||
read reqinstall
|
||||
if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ]
|
||||
then
|
||||
echo "OpenDRS requires either mariadb or mysql server, but you have elected not to install it."
|
||||
echo "Installation cannot continue."
|
||||
exit 1
|
||||
else
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Proceeding with mariadb-server installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
apt-get install -y mariadb-server
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Finished with mariadb-server installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Proceeding with mariadb configuration"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
echo ""
|
||||
echo "Configuring the MariaDB installation. There will be some more prompts:"
|
||||
echo ""
|
||||
echo "- You'll be prompted for the current password for the root user. You've"
|
||||
echo " just installed MariaDB and you haven't set one yet, so just press enter."
|
||||
echo ""
|
||||
echo "- You'll be prompted to switch to unix_socket authentication. Answer Y."
|
||||
echo ""
|
||||
echo "- You'll be prompted to change the root password. Answer Y and enter a password."
|
||||
echo " Note that this is just the password for the MariaDB root user, not the root login."
|
||||
echo " DO NOT FORGET THIS PASSWORD. You'll need it later during OpenDRS install."
|
||||
echo ""
|
||||
echo "- Answer Y to remove anonymous users, disallow root login remotely, remove"
|
||||
echo " test database and access, and reload privilege tables."
|
||||
echo ""
|
||||
echo -n "Press enter to proceed."
|
||||
read continueok
|
||||
echo ""
|
||||
mysql_secure_installation
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Finished with mariadb configuration."
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
echo " Checking for phpmyadmin installation..."
|
||||
echo ""
|
||||
if dpkg -l|grep phpmyadmin >/dev/null 2>&1
|
||||
then
|
||||
echo ""
|
||||
echo "phpmyadmin is installed. Continuing."
|
||||
echo ""
|
||||
else
|
||||
echo "phpmyadmin is optional, but doesn't seem to be installed."
|
||||
echo "It is an optional package that enables administration of the mysql/mariadb"
|
||||
echo "database server using a friendly GUI. It is highly recommended."
|
||||
echo "Note that this has the potential to be a security risk, especially"
|
||||
echo "if your passwords aren't sufficiently strong."
|
||||
echo -n "Install it now? [Y/n]: "
|
||||
read reqinstall
|
||||
if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ]
|
||||
then
|
||||
echo "Proceeding without installing phpmyadmin. Database administration"
|
||||
echo "will require the use of the mysql/mariadb command line tools."
|
||||
else
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Proceeding with phpmyadmin installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
echo ""
|
||||
echo "During the following installation of phpmyadmin:"
|
||||
echo ""
|
||||
echo "- Select apache2 as the web server to configure automatically."
|
||||
echo ""
|
||||
echo "- Choose Yes when prompted to install phpmyadmin database and allow it to"
|
||||
echo " generate a random password(leave the field blank)."
|
||||
echo ""
|
||||
echo -n "Press enter to continue."
|
||||
read continueok
|
||||
echo ""
|
||||
apt-get install -y phpmyadmin
|
||||
echo ""
|
||||
echo ""
|
||||
echo "You can now access phpmyadmin using a web browser pointed to:"
|
||||
echo "http://$HOSTNAME/phpmyadmin"
|
||||
echo "*** WARNING!! this url is accessible via unencrypted (http), not"
|
||||
echo "encrypted SSL (https) connections. This is a huge security risk"
|
||||
echo "since the username and password you enter will be sent in the"
|
||||
echo "clear for any potential attacker to sniff! You should enable"
|
||||
echo "redirection to https for phpmyadmin in your apache2 configuration."
|
||||
echo ""
|
||||
echo -n "Press enter to continue."
|
||||
read continueok
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Finished with phpmyadmin installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
echo " Checking for webmin installation..."
|
||||
echo ""
|
||||
if dpkg -l|grep webmin >/dev/null 2>&1
|
||||
then
|
||||
echo ""
|
||||
echo "webmin is installed. Continuing."
|
||||
echo ""
|
||||
else
|
||||
echo "webmin is optional, but doesn't seem to be installed."
|
||||
echo "It is an optional package that enables system administration"
|
||||
echo "using a friendly GUI. It is highly recommended, especially for"
|
||||
echo "headless servers without any way to log in directly on the machine."
|
||||
echo "Note that this has the potential to be a security risk, especially"
|
||||
echo "if your passwords aren't sufficiently strong."
|
||||
echo -n "Install it now? [Y/n]: "
|
||||
read reqinstall
|
||||
if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ]
|
||||
then
|
||||
echo "Proceeding without installing webmin. System administration"
|
||||
echo "will require login to the server either directly or via ssh."
|
||||
else
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Proceeding with webmin installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
echo "Installing webmin..."
|
||||
skipwebmin="false"
|
||||
if ! curl -o setup-repos.sh https://raw.githubusercontent.com/webmin/webmin/master/setup-repos.sh
|
||||
then
|
||||
echo "Warning: failed to download Webmin repo setup script."
|
||||
echo -n "Ignore and [c]ontinue or [A]bort? [c/A]: "
|
||||
read wmfailchoice
|
||||
if [ "$wmfailchoice" = "C" -o "$wmfailchoice" = "c" ]
|
||||
then
|
||||
skipwebmin="true"
|
||||
echo "Continuing without installing Webmin. You should investigate the failure"
|
||||
echo "and install Webmin manually after the server is set up if you would like"
|
||||
echo "to be able to manage the server from another computer with a GUI instead"
|
||||
echo "of through ssh only."
|
||||
echo -n "Press enter to continue."
|
||||
read continueok
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
if [ "$skipwebmin" = "false" ]
|
||||
then
|
||||
sh setup-repos.sh -f
|
||||
apt-get install -y --install-recommends webmin
|
||||
fi
|
||||
echo "...done."
|
||||
echo ""
|
||||
echo "You can now access webmin using a web browser pointed to:"
|
||||
echo "https://$HOSTNAME:10000"
|
||||
echo "Unless you have obtained valid ssl certificates, your server is"
|
||||
echo "using self-signed certs. This is not necessarily a problem, but"
|
||||
echo "your browser will complain. You can tell the browser to accept the"
|
||||
echo "self signed certificates and the traffic will still be encrypted,"
|
||||
echo "however you may be vulnerable to man-in-the-middle attacks. You can"
|
||||
echo "get free valid certificates through LetsEncrypt."
|
||||
echo "See http://letsencrypt.org for more information."
|
||||
echo ""
|
||||
echo -n "Press enter to continue."
|
||||
read continueok
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Finished with webmin installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
echo " Checking for uuidgen installation..."
|
||||
echo ""
|
||||
if uuidgen 2>&1
|
||||
then
|
||||
echo ""
|
||||
echo "uuidgen is installed. Continuing."
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo ""
|
||||
echo "OpenDRS requires uuidgen, but it doesn't seem to be installed."
|
||||
echo -n "Install it now? [Y/n]: "
|
||||
read reqinstall
|
||||
if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ]
|
||||
then
|
||||
echo "OpenDRS requires uuidgen, but you have elected not to install it."
|
||||
echo "Installation cannot continue."
|
||||
exit 1
|
||||
else
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Proceeding with uuidgen installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
apt-get install -y uuid-runtime
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
echo ""
|
||||
echo "Finished with uuidgen installation"
|
||||
echo ""
|
||||
echo "###################################################################"
|
||||
sleep 3
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Finished checking for and installing prerequisites..."
|
||||
echo ""
|
||||
echo ""
|
||||
sleep 3
|
||||
# prompt for install location
|
||||
echo "Where would you like to install this version of OpenDRS? This should"
|
||||
echo "be somewhere the webserver can find it. If you don't know, refer to the"
|
||||
@@ -57,10 +399,7 @@ then
|
||||
if [ -e "$install_path/db.php" ]
|
||||
then
|
||||
# A db.php file was found in the install path
|
||||
prev_inst_present=1
|
||||
grep -q -e "OpenDRS" -e "OpenMTS" $install_path/db.php
|
||||
prev_inst_present=$?
|
||||
if [ "$prev_inst_present" -eq 0 ]
|
||||
if grep -q -e "OpenDRS" -e "OpenMTS" $install_path/db.php
|
||||
then
|
||||
# the db.php file is part of an OpenDRS/OpenMTS installation
|
||||
echo "The installation path you chose already exists."
|
||||
@@ -78,19 +417,27 @@ then
|
||||
curr_username=`grep username $install_path/db.php | head -1 | cut -d "\"" -f2`
|
||||
curr_dbpass=`grep dbpass $install_path/db.php | head -1 | cut -d "\"" -f2`
|
||||
export MYSQL_PWD="$curr_dbpass"
|
||||
mysqldump -u"$curr_username" $curr_dbname > $curr_dbname-`date +%Y-%m-%d_%H:%M:%S`-backup.sql
|
||||
mysqldump --no-tablespaces -u"$curr_username" $curr_dbname > $curr_dbname-`date +%Y-%m-%d_%H:%M:%S`-backup.sql
|
||||
# back up existing installation
|
||||
echo "Backing up current installation to the package directory."
|
||||
cp -R $install_path $install_loc_in-`date +%Y-%m-%d_%H:%M:%S`-backup
|
||||
# delete all existing installation files except db.php
|
||||
find $install_path/ -mindepth 1 -not -name 'db.php' -delete
|
||||
# apply database updates
|
||||
mysql -u"$curr_username" $curr_dbname < opendrs-update.sql >/dev/null 2>&1
|
||||
mysql -u"$curr_username" -f -D $curr_dbname < opendrs-update.sql >/dev/null 2>&1
|
||||
# apply updates to existing db.php
|
||||
./opendrs-update.sh $install_path
|
||||
# copy distribution to install location
|
||||
echo "Installing distribution . . ."
|
||||
cp -R distfiles/* $install_path
|
||||
if [ ! -L "$install_path/jquery-ui" ]
|
||||
then
|
||||
ln -s $install_path/jquery-ui* $install_path/jquery-ui
|
||||
fi
|
||||
if [ ! -L "$install_path/index.php" ]
|
||||
then
|
||||
ln -s $install_path/writeups.php $install_path/index.php
|
||||
fi
|
||||
# set ownership
|
||||
echo "In order to set the ownership correctly, we need to know the user and"
|
||||
echo "group that the webserver expects its files to be owned by. This is"
|
||||
@@ -127,8 +474,8 @@ else
|
||||
# This is a fresh install
|
||||
operation="installed"
|
||||
# prompt for mysql information
|
||||
bad_mysql_adm=1
|
||||
while [ $bad_mysql_adm -eq 1 ]
|
||||
bad_mysql_adm=true
|
||||
while $bad_mysql_adm
|
||||
do
|
||||
admintestdb="drsadm`date +%Y%m%d`"
|
||||
echo "We need to know the username and password of a MySQL administrator"
|
||||
@@ -140,10 +487,9 @@ else
|
||||
echo -n "MySQL admin password: "
|
||||
read -s mysql_adm_pass
|
||||
export MYSQL_PWD="$mysql_adm_pass"
|
||||
mysql -u"$mysql_adm_user" -e "create database $admintestdb;drop database $admintestdb"
|
||||
if [ $? -eq 0 ]
|
||||
if mysql -u"$mysql_adm_user" -e "create database $admintestdb;drop database $admintestdb"
|
||||
then
|
||||
bad_mysql_adm=0
|
||||
bad_mysql_adm=false
|
||||
else
|
||||
echo "ERROR: Either the username/password you supplied were incorrect or the user"
|
||||
echo -n "is not a MySQL administrator. Try again? [Y/N]: "
|
||||
@@ -158,13 +504,18 @@ else
|
||||
echo "What would you like to call this installation of OpenDRS? If you accept"
|
||||
echo "the default, it will be called OpenDRS. If you will be running multiple"
|
||||
echo "instances of OpenDRS on this server, you should choose a distinctive name."
|
||||
echo "This can be changed later in the application itself."
|
||||
echo -n "Installation name [OpenDRS]: "
|
||||
read new_inst_name
|
||||
echo ""
|
||||
if [ "$new_inst_name" = "" ]
|
||||
then
|
||||
new_inst_name="OpenDRS"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Create initial database
|
||||
db_create_fail=1
|
||||
while [ $db_create_fail -eq 1 ]
|
||||
db_create_fail=true
|
||||
while $db_create_fail
|
||||
do
|
||||
echo "What would you like to call the database for this installation of OpenDRS?"
|
||||
echo "If you accept the default, it will be called opendrs. Again, this is fine"
|
||||
@@ -179,10 +530,9 @@ else
|
||||
fi
|
||||
echo ""
|
||||
export MYSQL_PWD="$mysql_adm_pass"
|
||||
mysql -u"$mysql_adm_user" -e "create database $new_db_name"
|
||||
if [ $? -eq 0 ]
|
||||
if mysql -u"$mysql_adm_user" -e "create database $new_db_name"
|
||||
then
|
||||
db_create_fail=0
|
||||
db_create_fail=false
|
||||
else
|
||||
echo "An error was encountered when trying to create the database."
|
||||
echo "This probably means the database already exists."
|
||||
@@ -225,8 +575,15 @@ else
|
||||
|
||||
# copy distribution to install location
|
||||
echo "Installing distribution . . ."
|
||||
cp -Rv distfiles/* $install_path
|
||||
|
||||
cp -R distfiles/* $install_path
|
||||
if [ ! -L "$install_path/jquery-ui" ]
|
||||
then
|
||||
ln -s $install_path/jquery-ui* $install_path/jquery-ui
|
||||
fi
|
||||
if [ ! -L "$install_path/index.php" ]
|
||||
then
|
||||
ln -s $install_path/writeups.php $install_path/index.php
|
||||
fi
|
||||
# set ownership
|
||||
echo "In order to set the ownership correctly, we need to know the user and"
|
||||
echo "group that the webserver expects its files to be owned by. This is"
|
||||
@@ -267,7 +624,7 @@ then
|
||||
read enconf
|
||||
if [ "$enconf" = "" -o "$enconf" = "Y" -o "$enconf" = "y" ]
|
||||
then
|
||||
a2enconf $base_url.conf
|
||||
a2enconf $base_url.conf >/dev/null
|
||||
service apache2 reload
|
||||
echo "You can now point a web browser to $base_url on your web server "
|
||||
echo "to set up and configure OpenDRS."
|
||||
@@ -292,3 +649,5 @@ else
|
||||
echo "to use your upgraded OpenDRS."
|
||||
fi
|
||||
|
||||
# Re-enable unattended-upgrades
|
||||
if $restart_uu; then systemctl start unattended-upgrades; fi
|
||||
|
||||
@@ -37,7 +37,12 @@ CREATE 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');
|
||||
INSERT INTO `banners` VALUES
|
||||
(1,'no banner','#000000','#FFFFFF'),
|
||||
(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;
|
||||
|
||||
@@ -63,7 +68,39 @@ CREATE TABLE `config` (
|
||||
|
||||
LOCK TABLES `config` WRITE;
|
||||
/*!40000 ALTER TABLE `config` DISABLE KEYS */;
|
||||
INSERT INTO `config` VALUES (1,'drs_version','1.1.2','1.1.2'),(5,'app_name','OpenDRS - Discrepancy Reporting System','OpenDRS Discrepancy Reporting System'),(6,'banner','1','1'),(7,'background_color','0B3144','0B3144'),(8,'p_background_color','FFFFFF','FFFFFF'),(11,'menubg_color','000000','000000'),(12,'p_menubg_color','FFFFFF','FFFFFF'),(13,'text_color','FFFFFF','FFFFFF'),(14,'p_text_color','000000','000000'),(15,'link_color','79EFEA','79EFEA'),(16,'p_link_color','000000','000000'),(17,'vlink_color','79EFEA','79EFEA'),(18,'p_vlink_color','000000','000000'),(19,'heading_color','5AE2B3','5AE2B3'),(20,'p_heading_color','000000','000000'),(21,'footer_message','Please report bugs to Rod Wright (software@rodsplace.net)','Please report bugs to Rod Wright (software@rodsplace.net)'),(26,'unix_server_session_dir','/tmp/opendrs/opendrs/sessions','/tmp/opendrs/opendrs/sessions'),(27,'win_server_session_dir','c:\\Windows\\Temp\\opendrs\\opendrs\\sessions','c:\\Windows\\Temp\\opendrs\\opendrs\\sessions'),(28,'session_ttl_days','30','30'),(29,'period_eff_help_txt','If maintenance issues prevented the training objectives from being achieved and you will have to come back and redo the same training, answer Non-effective. Otherwise, answer Effective.','If maintenance issues prevented the training objectives from being achieved and you will have to come back and redo the same training, answer Non-effective. Otherwise, answer Effective.');
|
||||
INSERT INTO `config` VALUES
|
||||
(1,'drs_version','1.4.0','1.4.0'),
|
||||
(5,'app_name','OpenDRS - Discrepancy Reporting System','OpenDRS Discrepancy Reporting System'),
|
||||
(6,'banner','1','1'),
|
||||
(7,'background_color','0B3144','0B3144'),
|
||||
(8,'p_background_color','FFFFFF','FFFFFF'),
|
||||
(11,'menubg_color','000000','000000'),
|
||||
(12,'p_menubg_color','FFFFFF','FFFFFF'),
|
||||
(13,'text_color','FFFFFF','FFFFFF'),
|
||||
(14,'p_text_color','000000','000000'),
|
||||
(15,'link_color','79EFEA','79EFEA'),
|
||||
(16,'p_link_color','000000','000000'),
|
||||
(17,'vlink_color','79EFEA','79EFEA'),
|
||||
(18,'p_vlink_color','000000','000000'),
|
||||
(19,'heading_color','5AE2B3','5AE2B3'),
|
||||
(20,'p_heading_color','000000','000000'),
|
||||
(21,'footer_message','Please report bugs to Rod Wright (software@rodsplace.net)','Please report bugs to Rod Wright (software@rodsplace.net)'),
|
||||
(26,'unix_server_session_dir','/tmp/opendrs/opendrs/sessions','/tmp/opendrs/opendrs/sessions'),
|
||||
(27,'win_server_session_dir','c:\\Windows\\Temp\\opendrs\\opendrs\\sessions','c:\\Windows\\Temp\\opendrs\\opendrs\\sessions'),
|
||||
(28,'session_ttl_days','30','30'),
|
||||
(29,'functional_help_txt','If this discrepancy renders the device unusable, answer No. Otherwise, answer Yes.',
|
||||
'If this discrepancy renders the device unusable, answer No. Otherwise, answer Yes.'),
|
||||
(30,'device_term','Device','Device'),
|
||||
(31,'discovered_term','When Discovered','When Discovered'),
|
||||
(32,'discovered_term_short','When Disc','When Disc'),
|
||||
(33,'functional_term','Functional','Functional'),
|
||||
(34,'functional_term_short','Func','Func'),
|
||||
(35,'functional_yes','Functional','Functional'),
|
||||
(36,'functional_no','Non-functional','Non-functional'),
|
||||
(37,'functional_yes_short','OK','OK'),
|
||||
(38,'functional_no_short','INOP','INOP'),
|
||||
(39,'disc_drop_data','Name','Name'),
|
||||
(40,'access_mode','trusted','trusted');
|
||||
/*!40000 ALTER TABLE `config` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
@@ -115,28 +152,29 @@ LOCK TABLES `links` WRITE;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `periods`
|
||||
-- Table structure for table `discovered`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `periods`;
|
||||
DROP TABLE IF EXISTS `discovered`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `periods` (
|
||||
`id` int(11) NOT NULL,
|
||||
`times` text NOT NULL,
|
||||
CREATE TABLE `discovered` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`whendiscoveredname` text NOT NULL,
|
||||
`whendiscovereddesc` text NOT NULL,
|
||||
`active` tinyint(1) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `periods`
|
||||
-- Dumping data for table `discovered`
|
||||
--
|
||||
|
||||
LOCK TABLES `periods` WRITE;
|
||||
/*!40000 ALTER TABLE `periods` DISABLE KEYS */;
|
||||
INSERT INTO `periods` VALUES (1,'0600 brief, 0645 box, 0830 debrief, 0930 end',1),(2,'0745 brief, 0830 box, 1015 debrief, 1115 end',1),(3,'0930 brief, 1015 box, 1200 debrief, 1300 end',1),(4,'1115 brief, 1200 box, 1345 debrief, 1445 end',1),(5,'1300 brief, 1345 box, 1530 debrief, 1630 end',1),(6,'1445 brief, 1530 box, 1715 debrief, 1815 end',1),(7,'1630 brief, 1715 box, 1900 debrief, 2000 end',1),(8,'1815 brief, 1900 box, 2045 debrief, 2145 end',1);
|
||||
/*!40000 ALTER TABLE `periods` ENABLE KEYS */;
|
||||
LOCK TABLES `discovered` WRITE;
|
||||
/*!40000 ALTER TABLE `discovered` DISABLE KEYS */;
|
||||
INSERT INTO `discovered` VALUES (1,'Install','Initial installation',1);
|
||||
/*!40000 ALTER TABLE `discovered` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
@@ -236,6 +274,7 @@ CREATE TABLE `devices` (
|
||||
|
||||
LOCK TABLES `devices` WRITE;
|
||||
/*!40000 ALTER TABLE `devices` DISABLE KEYS */;
|
||||
INSERT INTO `devices` VALUES (1,'OpenDRS Server',1);
|
||||
/*!40000 ALTER TABLE `devices` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
@@ -278,8 +317,8 @@ DROP TABLE IF EXISTS `writeups`;
|
||||
CREATE TABLE `writeups` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`device` int(11) NOT NULL,
|
||||
`period` int(11) NOT NULL,
|
||||
`period_effective` tinyint(1) NOT NULL,
|
||||
`discovered` int(11) NOT NULL,
|
||||
`functional` tinyint(1) NOT NULL,
|
||||
`reported_by` tinytext NOT NULL,
|
||||
`report_date` date NOT NULL,
|
||||
`report_time` time NOT NULL,
|
||||
@@ -301,6 +340,7 @@ CREATE TABLE `writeups` (
|
||||
|
||||
LOCK TABLES `writeups` WRITE;
|
||||
/*!40000 ALTER TABLE `writeups` DISABLE KEYS */;
|
||||
INSERT INTO `writeups` VALUES (1,1,1,1,'R. Wright',CURRENT_DATE(),CURRENT_TIME(),1,'This is a new installation of OpenDRS. There is one admin user (username: drsadmin password: OpenDRS-1). You should immediately log in and click on Manage Database under Admin Functions, go to the User Management tab, and add yourself as a new user, making sure to click the Admin checkbox to give yourself admin rights. You should then edit the DRS Admin user by clicking the User ID number in the table of existing users, and uncheck the Active checkbox. After you have done that, you can close this writeup.',1,0,NULL,NULL,0,NULL);
|
||||
/*!40000 ALTER TABLE `writeups` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
@@ -39,3 +39,215 @@ UPDATE config SET defaultvalue="c:\Windows\Temp\opendrs\opendrs\sessions" WHERE
|
||||
-- Update version number
|
||||
UPDATE config SET value="1.1.2",defaultvalue="1.1.2" WHERE name="drs_version";
|
||||
-- --------------------------------------
|
||||
|
||||
-- ---------- version 1.2.0 -------------
|
||||
-- Update version number
|
||||
UPDATE config SET value="1.2.0",defaultvalue="1.2.0" WHERE name="drs_version";
|
||||
|
||||
-- Add device_term to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'device_term',
|
||||
'Device' AS wval,
|
||||
'Device' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT name FROM config WHERE name = 'device_term'
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add discovered_term to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'discovered_term',
|
||||
'When Discovered' AS wval,
|
||||
'When Discovered' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT name FROM config WHERE name = 'discovered_term'
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add discovered_term_short to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'discovered_term_short',
|
||||
'When Disc' AS wval,
|
||||
'When Disc' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT name FROM config WHERE name = 'discovered_term_short'
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add disc_drop_data to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'disc_drop_data',
|
||||
'Name' AS wval,
|
||||
'Name' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT name FROM config WHERE name = 'disc_drop_data'
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add functional_term to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'functional_term',
|
||||
'Functional' AS wval,
|
||||
'Functional' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT `name` FROM `config` WHERE `name` = "functional_term"
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add functional_term_short to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'functional_term_short',
|
||||
'Func' AS wval,
|
||||
'Func' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT `name` FROM `config` WHERE `name` = "functional_term_short"
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add functional_yes to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'functional_yes',
|
||||
'Functional' AS wval,
|
||||
'Functional' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT `name` FROM `config` WHERE `name` = "functional_yes"
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add functional_no to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'functional_no',
|
||||
'Non-functional' AS wval,
|
||||
'Non-functional' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT `name` FROM `config` WHERE `name` = "functional_no"
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add functional_yes_short to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'functional_yes_short',
|
||||
'OK' AS wval,
|
||||
'OK' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT `name` FROM `config` WHERE `name` = "functional_yes_short"
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Add functional_no_short to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'functional_no_short',
|
||||
'INOP' AS wval,
|
||||
'INOP' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT `name` FROM `config` WHERE `name` = "functional_no_short"
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- Rename period_eff_help_txt config to functional_help_txt
|
||||
UPDATE `config` SET name="functional_help_txt" WHERE name="period_eff_help_txt";
|
||||
|
||||
-- Change the default value of functional_help_text
|
||||
UPDATE `config` SET defaultvalue="If this discrepancy renders the device unusable, answer No. Otherwise, answer Yes." WHERE name="function_help_txt";
|
||||
|
||||
-- Rename periods table to discovered
|
||||
RENAME TABLE `periods` TO `discovered`;
|
||||
|
||||
-- Add whendiscoveredname column to discovered table
|
||||
ALTER TABLE `discovered` ADD COLUMN `whendiscoveredname` text NOT NULL AFTER id;
|
||||
|
||||
-- Copy the contents of the id column to the whendiscoveredname column where whendiscoveredname is empty
|
||||
UPDATE `discovered` SET `whendiscoveredname`=`id` WHERE `whendiscoveredname`="";
|
||||
|
||||
-- Rename times column of discovered table to whendiscovereddesc
|
||||
ALTER TABLE `discovered` CHANGE COLUMN `times` `whendiscovereddesc` text not null;
|
||||
|
||||
-- Add auto_increment flag to id column
|
||||
ALTER TABLE `discovered` CHANGE COLUMN `id` `id` text not null auto_increment;
|
||||
|
||||
-- Rename period column of writeups table to discovered
|
||||
ALTER TABLE `writeups` CHANGE COLUMN `period` `discovered` int not null;
|
||||
|
||||
-- Rename period_effective column of writeups table to functional
|
||||
ALTER TABLE `writeups` CHANGE COLUMN `period_effective` `functional` tinyint(1) not null;
|
||||
-- --------------------------------------
|
||||
|
||||
-- ---------- version 1.3.0 -------------
|
||||
-- Update version number
|
||||
UPDATE config SET value="1.3.0",defaultvalue="1.3.0" WHERE name="drs_version";
|
||||
-- --------------------------------------
|
||||
|
||||
-- ---------- version 1.3.1 -------------
|
||||
-- Update version number
|
||||
UPDATE config SET value="1.3.1",defaultvalue="1.3.1" WHERE name="drs_version";
|
||||
-- --------------------------------------
|
||||
|
||||
-- ---------- version 1.3.2 -------------
|
||||
-- Update version number
|
||||
UPDATE config SET value="1.3.2",defaultvalue="1.3.2" WHERE name="drs_version";
|
||||
-- --------------------------------------
|
||||
|
||||
-- ---------- version 1.3.3 -------------
|
||||
-- Update version number
|
||||
UPDATE config SET value="1.3.3",defaultvalue="1.3.3" WHERE name="drs_version";
|
||||
-- --------------------------------------
|
||||
|
||||
-- ---------- version 1.4.0 -------------
|
||||
-- Update version number
|
||||
UPDATE config SET value="1.4.0",defaultvalue="1.4.0" WHERE name="drs_version";
|
||||
|
||||
-- Add access_mode to config table
|
||||
INSERT INTO config(name,value,defaultvalue)
|
||||
SELECT * FROM
|
||||
(SELECT 'access_mode',
|
||||
'trusted' AS wval,
|
||||
'trusted' AS dval
|
||||
)
|
||||
AS tmp
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT `name` FROM `config` WHERE `name` = "access_mode"
|
||||
) LIMIT 1
|
||||
;
|
||||
|
||||
-- --------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user