diff --git a/CHANGELOG b/CHANGELOG index 8efbde7..338d69a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -62,3 +62,11 @@ Changelog - Changed systemd ctrl-alt-del.target symlink to point to reboot.target. +1.1.2 - 2021-04-28 + - Added ability to export search results as a CSV file. + - Fixed bug in server-setup.sh that resulted in an incorrect install + location if the installation name was left at the default. + - Fixed bug in server-setup.sh that resulted in failure to set the + 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. diff --git a/RPiSetup/server-setup.sh b/RPiSetup/server-setup.sh index 5a08c9f..0822f75 100644 --- a/RPiSetup/server-setup.sh +++ b/RPiSetup/server-setup.sh @@ -2,7 +2,7 @@ # server-setup.sh # OpenDRS Online Discrepancy Reporting System -# Copyright (C) 2020 Rod Wright +# Copyright (C) 2021 Rod Wright # SPDX-License-Identifier: GPL-2.0 @@ -30,10 +30,22 @@ fi echo "It looks like you have. Continuing." echo "" echo "" -echo "Updating Raspbian..." +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." @@ -43,7 +55,10 @@ echo "automatically. Choose Yes when prompted to install phpmyadmin database and echo "generate a random password(leave the field blank)." echo -n "Press enter to continue." read continueok -sleep 10 +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 @@ -54,6 +69,10 @@ echo "Configuring the mysql installation. Accept the defaults at the following p 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 "" @@ -94,9 +113,15 @@ 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 +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 ] @@ -156,7 +181,17 @@ 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 @@ -173,6 +208,10 @@ fi 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" @@ -182,7 +221,11 @@ 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 +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 diff --git a/RPiSetup/terminal-setup.sh b/RPiSetup/terminal-setup.sh index 335524b..2038a9a 100644 --- a/RPiSetup/terminal-setup.sh +++ b/RPiSetup/terminal-setup.sh @@ -2,7 +2,7 @@ # terminal-setup.sh # OpenDRS Online Maintenance Tracking System -# Copyright (C) 2020 Rod Wright +# Copyright (C) 2021 Rod Wright # SPDX-License-Identifier: GPL-2.0 @@ -15,7 +15,7 @@ echo "" echo "" echo "You should have already completed the following steps:" echo "" -echo "1. Created a Raspbian Lite SD card from the latest release." +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." @@ -30,27 +30,48 @@ 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 "6. Ran sudo ./terminal-setup.sh (this file)." 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 "Updating Raspbian..." +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 @@ -68,6 +89,10 @@ 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" @@ -78,11 +103,20 @@ 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 "" diff --git a/RaspberryPiSetup.txt b/RaspberryPiSetup.txt index 9a78dcd..4ada47d 100644 --- a/RaspberryPiSetup.txt +++ b/RaspberryPiSetup.txt @@ -1,6 +1,6 @@ Raspberry Pi setup -1. Create Raspbian Lite SD card from the most recent stable release. +1. Create Raspberry Pi OS Lite SD card from the most recent stable release. 2. Insert SD card in Raspberry Pi and boot. @@ -8,24 +8,24 @@ Raspberry Pi setup 4. sudo raspi-config and: - a. Use option 1 to set a strong password for the default user (pi). + a. Set a strong password for the default user (pi). - b. Use option 2 Network Options to: - 1. Set the desired hostname. - 2. Set WiFi SSID and passphrase if using WiFi for networking. + b. Set the desired hostname. - c. Use option 4 Localisation Options to: - 1. Set locale. + 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! Raspbian 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 WiFi country. + 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 option 5 Interfacing Options to enable SSH server. + d. Use Interfacing Options to enable SSH server. - e. If you have black borders on the sides of the screen, use option 7 - Advanced Options to select No for Overscan compensation. + 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. diff --git a/boilerplate.php b/boilerplate.php index 15b2083..d8ee2ac 100644 --- a/boilerplate.php +++ b/boilerplate.php @@ -48,7 +48,7 @@ if ($print=="Printer Friendly") { $mbgcolor=MENUBG_COLOR; } -$role=dblookup($mts_db,"users","id","role",$userid); +$role=dblookup($drs_db,"users","id","role",$userid); framework("begin","$appname","Boilerplate Page",$print); diff --git a/distfiles/CHANGELOG b/distfiles/CHANGELOG index fe12b96..31900a1 100644 --- a/distfiles/CHANGELOG +++ b/distfiles/CHANGELOG @@ -61,3 +61,12 @@ Changelog chromium hotkey combinations and enable ctrl-alt-del reboot. - Changed systemd ctrl-alt-del.target symlink to point to reboot.target. + +1.1.2 - 2021-04-28 + - Added ability to export search results as a CSV file. + - Fixed bug in server-setup.sh that resulted in an incorrect install + location if the installation name was left at the default. + - Fixed bug in server-setup.sh that resulted in failure to set the + 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. diff --git a/distfiles/common.php b/distfiles/common.php index 0f0e0ca..9a42650 100644 --- a/distfiles/common.php +++ b/distfiles/common.php @@ -807,5 +807,4 @@ function group_table($groupid,$role=false,$mode="view",$selection="none",$expand } - ?> diff --git a/distfiles/search.php b/distfiles/search.php index ab88b9d..103f6c0 100644 --- a/distfiles/search.php +++ b/distfiles/search.php @@ -2,23 +2,42 @@ /* search.php OpenDRS Online Discrepancy Reporting System - Copyright (C) 2020 Rod Wright + Copyright (C) 2021 Rod Wright SPDX-License-Identifier: GPL-2.0 */ include("common.php"); +if ($_REQUEST['exportcsv']) { + $csv_filename="OpenDRS_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"); + header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate"); + header("Last-Modified: {$now} GMT"); + + // force download + header("Content-Type: application/force-download"); + header("Content-Type: application/octet-stream"); + header("Content-Type: application/download"); + + // disposition / encoding on response body + header("Content-Disposition: attachment;filename={$csv_filename}"); + header("Content-Transfer-Encoding: binary"); +} + // import session variables 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[] +$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); } @@ -61,9 +80,11 @@ if ($print) { $role=dblookup($drs_db,"users","id","role",$userid); $pgtitle="Search Writeups"; -framework("begin","$appname",$pgtitle,$print); +if (! $exportcsv) framework("begin","$appname",$pgtitle,$print); +//echo "_REQUEST array
"; //var_dump($_REQUEST); +//echo "

incoming array
"; //var_dump($incoming); @@ -295,431 +316,440 @@ if ($search) { // ******** end database manipulation ******** - -pagetable("begin"); -if(!$print) { - pageblock("left","begin"); - sidemenu(); - echo "

"; - pageblock("left","end"); +if (! $exportcsv) { + pagetable("begin"); + if(!$print) { + pageblock("left","begin"); + sidemenu(); + echo "

"; + pageblock("left","end"); + } + pageblock("right","begin"); + banner($print); + echo "
"; + + // show search form + if (!$print) { + echo " +
+ + + + + + "; + echo " + + + + + "; + echo " + + + + + + + + + + + + + + + + + + + + + + + + + +
+ "; + // ID cell ***************** + echo " + ID
+ + "; + // ********************************** + echo " +
+ "; + // Device cell ********************* + echo " + Device
+ + "; + // ********************************** + echo " +
+ "; + // Subsystem cell ******************* + echo " + Subsystem
+ + "; + // ********************************** + echo " +
+ "; + // Period cell ********************** + echo " + Period
+ + "; + // ********************************** + echo " +
+ "; + // Report Date cell ***************** + echo " + Report Date Between
+ +  and  + + "; + // ********************************** + echo " +
+ "; + // Report Time cell ***************** + echo " + Report Time Between
+ +  and  + + "; + // ********************************** + echo " +
+ "; + // Discrepancy text cell ************ + echo " + Words in Discrepancy
+
+ "; + // ********************************** + echo " +
+ "; + // Reported by cell ***************** + echo " + Reported by
+ + "; + // ********************************** + echo " +
+ "; + // Period effective cell ************ + echo " + Sim period effective?  
+ "; + if ($search) { + $effstate=$nefstate=""; + if (in_array("1",$s_period_effective,true)) $effstate="selected"; + if (in_array("0",$s_period_effective,true)) $nefstate="selected"; + } else { + $effstate=$nefstate="selected"; + } + echo " + + "; + // ********************************** + echo " +
+ "; + // Group status cell ************** + echo " + Group Member?
+ "; + 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 " + + "; + // ************************************ + echo " +
+ "; + // Status cell ********************** + echo " + Status
+ "; + if ($search) { + $openstate=$clsdstate=$dfrdstate=""; + if (in_array("1",$s_status,true)) $openstate="selected"; + if (in_array("2",$s_status,true)) $clsdstate="selected"; + if (in_array("3",$s_status,true)) $dfrdstate="selected"; + } else { + $openstate=$clsdstate=$dfrdstate="selected"; + } + echo " + + "; + // ********************************** + echo " +
+ "; + // action by cell ************ + echo " + Status changed by
+ + "; + // *********************************** + echo " +
+ "; + // action reason cell ********* + echo " + Status change reason
+ + "; + // *********************************** + echo " +
+ "; + // Action taken text cell ************ + echo " + Words in Action Taken
+
+ "; + // *********************************** + echo " +
+ "; + // Action date cell ****************** + echo " + Action Taken Date Between
+ +  and  + + "; + // *********************************** + echo " +
+ "; + // Action time cell ****************** + echo " + Action Taken Time Between
+ +  and  + + "; + // *********************************** + $summarystat=$detailstat=""; + if ($viewtype=="detail") { + $detailstat="checked"; + } else { + $summarystat="checked"; + } + $idsort=$statussort=$datesort=$periodsort=$devicesort=$subsyssort=$repbysort=$discrepsort=$effsort=""; + switch ($sort) { + case "id": + $idsort="checked"; + break; + case "status": + $statussort="checked"; + break; + case "report_date": + $datesort="checked"; + break; + case "period": + $periodsort="checked"; + break; + case "device": + $devicesort="checked"; + break; + case "subsystem": + $subsyssort="checked"; + break; + case "reported_by": + $repbysort="checked"; + break; + case "discrepancy_text": + $discrepsort="checked"; + break; + case "period_effective": + $effsort="checked"; + break; + default: + $datesort="checked"; + } + $ascsort=$descsort=""; + if ($order=="desc") { + $descsort="checked"; + } else { + $ascsort="checked"; + } + echo "
+
+     + +

+ Sort Field:
+     +     +     +     +     +     +     +     +     +
Sort Order:
+     +     +

+ +         + +
+
+ "; + } } -pageblock("right","begin"); -banner($print); -echo "
"; - -// show search form -if (!$print) { - echo " -
- - - - - - "; - echo " - - - - - "; - echo " - - - - - - - - - - - - - - - - - - - - - - - - - -
- "; - // ID cell ***************** - echo " - ID
- - "; - // ********************************** - echo " -
- "; - // Device cell ********************* - echo " - Device
- - "; - // ********************************** - echo " -
- "; - // Subsystem cell ******************* - echo " - Subsystem
- - "; - // ********************************** - echo " -
- "; - // Period cell ********************** - echo " - Period
- - "; - // ********************************** - echo " -
- "; - // Report Date cell ***************** - echo " - Report Date Between
- -  and  - - "; - // ********************************** - echo " -
- "; - // Report Time cell ***************** - echo " - Report Time Between
- -  and  - - "; - // ********************************** - echo " -
- "; - // Discrepancy text cell ************ - echo " - Words in Discrepancy
-
- "; - // ********************************** - echo " -
- "; - // Reported by cell ***************** - echo " - Reported by
- - "; - // ********************************** - echo " -
- "; - // Period effective cell ************ - echo " - Sim period effective?  
- "; - if ($search) { - $effstate=$nefstate=""; - if (in_array("1",$s_period_effective,true)) $effstate="selected"; - if (in_array("0",$s_period_effective,true)) $nefstate="selected"; - } else { - $effstate=$nefstate="selected"; - } - echo " - - "; - // ********************************** - echo " -
- "; - // Group status cell ************** - echo " - Group Member?
- "; - 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 " - - "; - // ************************************ - echo " -
- "; - // Status cell ********************** - echo " - Status
- "; - if ($search) { - $openstate=$clsdstate=$dfrdstate=""; - if (in_array("1",$s_status,true)) $openstate="selected"; - if (in_array("2",$s_status,true)) $clsdstate="selected"; - if (in_array("3",$s_status,true)) $dfrdstate="selected"; - } else { - $openstate=$clsdstate=$dfrdstate="selected"; - } - echo " - - "; - // ********************************** - echo " -
- "; - // action by cell ************ - echo " - Status changed by
- - "; - // *********************************** - echo " -
- "; - // action reason cell ********* - echo " - Status change reason
- - "; - // *********************************** - echo " -
- "; - // Action taken text cell ************ - echo " - Words in Action Taken
-
- "; - // *********************************** - echo " -
- "; - // Action date cell ****************** - echo " - Action Taken Date Between
- -  and  - - "; - // *********************************** - echo " -
- "; - // Action time cell ****************** - echo " - Action Taken Time Between
- -  and  - - "; - // *********************************** - $summarystat=$detailstat=""; - if ($viewtype=="detail") { - $detailstat="checked"; - } else { - $summarystat="checked"; - } - $idsort=$statussort=$datesort=$periodsort=$devicesort=$subsyssort=$repbysort=$discrepsort=$effsort=""; - switch ($sort) { - case "id": - $idsort="checked"; - break; - case "status": - $statussort="checked"; - break; - case "report_date": - $datesort="checked"; - break; - case "period": - $periodsort="checked"; - break; - case "device": - $devicesort="checked"; - break; - case "subsystem": - $subsyssort="checked"; - break; - case "reported_by": - $repbysort="checked"; - break; - case "discrepancy_text": - $discrepsort="checked"; - break; - case "period_effective": - $effsort="checked"; - break; - default: - $datesort="checked"; - } - $ascsort=$descsort=""; - if ($order=="desc") { - $descsort="checked"; - } else { - $ascsort="checked"; - } - echo "
-
-     - -

- Sort Field:
-     -     -     -     -     -     -     -     -     -
Sort Order:
-     -     -

- -         - - -
-
- "; -} - // display the results if ($search) { - //display the search parameters used - if (!$print) echo ""; - echo " - - "; - } else { - echo ""; - } - echo " - -
Parameters used in this search - "; - if (!$print) { - echo "        Scroll up to modify parameters
- - - - - - -
$status_param   $device_param   $subsystem_param   $id_param   
- - - - - - -
$period_param   $reportdate_param   $reporttime_param   
- - - - -
$discrepancytext_param
- - - - - - -
$repby_param   $eff_param   $group_param   
- - - - - -
$actionby_param   $reason_param   
- - - - -
$actiontext_param
- - - - - -
$actiondate_param   $actiontime_param   
-
-
- "; + if (! $exportcsv) { + //display the search parameters used + if (!$print) echo ""; + echo " + + "; + } else { + echo ""; + } + echo " + +
Parameters used in this search + "; + if (!$print) { + echo "        Scroll up to modify parameters
+ + + + + + +
$status_param   $device_param   $subsystem_param   $id_param   
+ + + + + + +
$period_param   $reportdate_param   $reporttime_param   
+ + + + +
$discrepancytext_param
+ + + + + + +
$repby_param   $eff_param   $group_param   
+ + + + + +
$actionby_param   $reason_param   
+ + + + +
$actiontext_param
+ + + + + +
$actiondate_param   $actiontime_param   
+
+
+ "; + } + $currentparams=arrayCopy($_REQUEST); + if (! $exportcsv) { + echo " +
+ +
+ "; + } $writeup=mysqli_query($drs_db,$query_string); // create an array of ids returned by the query string $result_ids=array(); @@ -746,117 +776,226 @@ if ($search) { 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 if ($num_results > 0) { - if ($viewtype=="summary") { - echo " - - - - - - - - - - - - - "; - while ($tablerow = mysqli_fetch_assoc($writeup)) { - // 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 ($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_fp=fopen('php://temp', 'w+'); + while ($tablerow = mysqli_fetch_assoc($writeup)) { - // determine effective icon + // writeup id for csv + $csv_id=$tablerow['id']; + + // determine status text + if ($tablerow['status']==1) $csv_status_text="Open"; + if ($tablerow['status']==2) $csv_status_text="Closed"; + if ($tablerow['status']==3) $csv_status_text="Deferred"; + + // convert device number to name for csv + $csv_dname=dblookup($drs_db,"devices","id","name",$tablerow["device"]); + + // 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"]}"; + + // determine effective text for csv if($tablerow["period_effective"]==1) { - $eff_icon="\"Period"; + $csv_eff_text="EFF"; } else { - $eff_icon="\"Period"; + $csv_eff_text="NEF"; } - // determine status indicator - if ($tablerow['status']==1) $statusind="
OPEN
"; - if ($tablerow['status']==2) $statusind="
CLSD
"; - if ($tablerow['status']==3) $statusind="
DFRD
"; + // discrepancy text for csv + $csv_disc_txt="{$tablerow["discrepancy_text"]}"; + $csv_disc_txt=str_replace("\n","\r\n",$csv_disc_txt); - // 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 subsystem number to name - $ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]); - $disc_txt="{$tablerow["discrepancy_text"]}"; - - // set group indicator + // group name or number for csv + $member_qry=mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\""); + $is_member=mysqli_num_rows($member_qry); + // look up group name if ($is_member) { $group_count=$is_member; if ($group_count == 1) { $group_num=mysqli_fetch_row(mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\""))[0]; $member_group_name=dblookup($drs_db,"groups","id","name",$group_num); if ($member_group_name) { - $imgtitle="Member of group: $member_group_name"; + $csv_member_group_name=$member_group_name; } else { - $imgtitle="Member of group ID: $group_num"; + $csv_member_group_name=$group_num; } - $disc_txt=$disc_txt."
\"GRP\"
"; } else { - $disc_txt=$disc_txt."
\"GRP\"
"; + $csv_member_group_name="multiple"; } + } else { + $csv_member_group_name="none"; } + // report date for csv + $csv_report_date="{$tablerow["report_date"]}"; + + // report time for csv + $csv_report_time="{$tablerow["report_time"]}"; + + // reported by text for csv + $csv_reported_by_text="{$tablerow["reported_by"]}"; + $csv_reported_by_text=str_replace("\n","\r\n",$csv_reported_by_text); + + // action taken by text for csv + $techfname=dblookup($drs_db,"users","id","firstname","{$tablerow["action_by"]}"); + $techlname=dblookup($drs_db,"users","id","lastname","{$tablerow["action_by"]}"); + $csv_action_by="$techfname $techlname"; + + // status change reason for csv + $csv_reasonname=dblookup($drs_db,"reasons","id","text","{$tablerow["action_reason"]}"); + + // action taken text for csv + $csv_action_text="{$tablerow["action_text"]}"; + $csv_action_text=str_replace("\n","\r\n",$csv_action_text); + + // action date for csv + $csv_action_date="{$tablerow["action_date"]}"; + + // action time for csv + $csv_action_time="{$tablerow["action_time"]}"; + + + if (($show_groupmems == $show_nongroupmems) || ($is_member && $show_groupmems) || (!$is_member && $show_nongroupmems)) { - // print table row - printf( - " - - - - - - - - - - \n", - $tablerow["id"],$tablerow["id"], - $statusind, - $tablerow["report_date"], - $ptimes,$tablerow["period"], - $dname, - $ssname, - $tablerow["reported_by"], - $disc_txt, - $eff_icon - ); + // 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]; + } } - echo "
IDStatusDatePeriodDeviceSubsystemReported byDiscrepancyMsn Eff
%s%s%s%s%s%s%s%s%s
\n"; - } elseif ($viewtype=="detail") { - echo " -
- "; - while ($tablerow = mysqli_fetch_assoc($writeup)) { - // 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)) { - displaywriteup($tablerow['id']); - echo "
"; - } - } - echo " -
- "; - } + foreach ($csv_data as $csv_fields) { + // add row to csv buffer + fputcsv($csv_fp, $csv_fields); + } + $csv_filename="data_export_" . date("Y-m-d") . ".csv"; + // reset pointer back to start + 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; + } else { + if ($viewtype=="summary") { + echo " + + + + + + + + + + + + + "; + while ($tablerow = mysqli_fetch_assoc($writeup)) { + // 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); + + // determine effective icon + if($tablerow["period_effective"]==1) { + $eff_icon="\"Period"; + } else { + $eff_icon="\"Period"; + } + + // determine status indicator + if ($tablerow['status']==1) $statusind="
OPEN
"; + if ($tablerow['status']==2) $statusind="
CLSD
"; + if ($tablerow['status']==3) $statusind="
DFRD
"; + + // 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 subsystem number to name + $ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]); + $disc_txt="{$tablerow["discrepancy_text"]}"; + + // set group indicator + if ($is_member) { + $group_count=$is_member; + if ($group_count == 1) { + $group_num=mysqli_fetch_row(mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\""))[0]; + $member_group_name=dblookup($drs_db,"groups","id","name",$group_num); + if ($member_group_name) { + $imgtitle="Member of group: $member_group_name"; + } else { + $imgtitle="Member of group ID: $group_num"; + } + $disc_txt=$disc_txt."
\"GRP\"
"; + } else { + $disc_txt=$disc_txt."
\"GRP\"
"; + } + } + + if (($show_groupmems == $show_nongroupmems) || ($is_member && $show_groupmems) || (!$is_member && $show_nongroupmems)) { + // print table row + printf( + " + + + + + + + + + + \n", + $tablerow["id"],$tablerow["id"], + $statusind, + $tablerow["report_date"], + $ptimes,$tablerow["period"], + $dname, + $ssname, + $tablerow["reported_by"], + $disc_txt, + $eff_icon + ); + } + } + echo "
IDStatusDatePeriodDeviceSubsystemReported byDiscrepancyMsn Eff
%s%s%s%s%s%s%s%s%s
\n"; + } elseif ($viewtype=="detail") { + echo " +
+ "; + while ($tablerow = mysqli_fetch_assoc($writeup)) { + // 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)) { + displaywriteup($tablerow['id']); + echo "
"; + } + } + echo " +
+ "; + } + } } else { echo "No writeups match your search parameters.
"; } } - -echo "
"; -banner($print); -pageblock("right","end"); -pagetable("end"); - -framework("end","","",$print); - +if (! $exportcsv) { + echo "
"; + banner($print); + pageblock("right","end"); + pagetable("end"); + + framework("end","","",$print); +} ?> diff --git a/install.sh b/install.sh index 5dcd23d..ef70a73 100644 --- a/install.sh +++ b/install.sh @@ -2,12 +2,12 @@ # install.sh # OpenDRS Online Discrepancy Reporting System -# Copyright (C) 2020 Rod Wright +# Copyright (C) 2021 Rod Wright # SPDX-License-Identifier: GPL-2.0 -DRS_VERSION="1.1.1" +DRS_VERSION="1.1.2" DOC_ROOT="/var/www" INSTALL_LOC="opendrs" APACHE_USER="www-data" diff --git a/opendrs-initial.sql b/opendrs-initial.sql index 9a6143b..4a00919 100644 --- a/opendrs-initial.sql +++ b/opendrs-initial.sql @@ -63,7 +63,7 @@ CREATE TABLE `config` ( LOCK TABLES `config` WRITE; /*!40000 ALTER TABLE `config` DISABLE KEYS */; -INSERT INTO `config` VALUES (1,'drs_version','1.1.1','1.1.1'),(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.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.'); /*!40000 ALTER TABLE `config` ENABLE KEYS */; UNLOCK TABLES; diff --git a/opendrs-update.sql b/opendrs-update.sql index 9462352..668f71c 100644 --- a/opendrs-update.sql +++ b/opendrs-update.sql @@ -34,3 +34,8 @@ UPDATE config SET defaultvalue="OpenDRS Discrepancy Reporting System" WHERE name UPDATE config SET defaultvalue="/tmp/opendrs/opendrs/sessions" WHERE name="unix_server_session_dir"; UPDATE config SET defaultvalue="c:\Windows\Temp\opendrs\opendrs\sessions" WHERE name="win_server_session_dir"; -- -------------------------------------- + +-- ---------- version 1.1.2 ------------- +-- Update version number +UPDATE config SET value="1.1.2",defaultvalue="1.1.2" WHERE name="drs_version"; +-- --------------------------------------