Files
OpenDRS/distfiles/groups.php

896 lines
39 KiB
PHP

<?php
/*
groups.php
OpenDRS Online Discrepancy Reporting System
Copyright (C) 2020 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("common.php");
// redirect to groups.php on cancel button press
if ($_REQUEST['cancel']) {
header("Cache-Control:no-cache, must-revalidate");
header("Pragma:no-cache");
header("Location:groups.php");
exit();
}
// 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
$incoming=unserialize($_REQUEST['all_parameters']);
} else {
// copy $_REQUEST to $incoming
$incoming=arrayCopy($_REQUEST);
}
// load variables from incoming array
$action=$incoming['action'];
$save=$incoming['save'];
$targets=$incoming['targets'];
$group=$incoming['group'];
$name=$incoming['name'];
$expandgrp=$incoming['expandgrp'];
$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
// assign variables from constants
$appname=APP_NAME;
if ($print=="Printer Friendly") {
$sbcolor=P_SIDEBAR_COLOR;
$mbgcolor=P_MENUBG_COLOR;
} else {
$sbcolor=SIDEBAR_COLOR;
$mbgcolor=MENUBG_COLOR;
}
$role=dblookup($drs_db,"users","id","role",$userid);
framework("begin","$appname","Writeup Groups",$print);
//var_dump($_REQUEST);
//var_dump($incoming);
// ******** begin database manipulation ********
// determine today's date and make it the default
$today=date("Y-m-d");
$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 ($action=="add" && $role && $save) {
$fail=false;
if (!$group) {
// group was not supplied, so create a new one
mysqli_query($drs_db,"insert into groups(name) value(\"\")");
$fail=mysqli_error($drs_db);
$group=mysqli_insert_id($drs_db);
}
foreach ($targets as $target) {
// add writeup to the group
if (!mysqli_num_rows(mysqli_query($drs_db,"select id from links where writeupid=\"$target\" and linkgroup=\"$group\""))) {
// target is not already a member of this group
mysqli_query($drs_db,"insert into links (linkgroup,writeupid) values($group,$target)");
$fail=mysqli_error($drs_db);
}
}
} elseif ($action=="remove" && $role && $save) {
$fail=false;
$writeups=array();
$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)) {
// remove writeup from group
mysqli_query($drs_db,"delete from links where writeupid=$writeup and linkgroup=$group");
$fail=mysqli_error($drs_db);
}
}
} elseif ($action=="dissolve" && $role && $save) {
$fail=false;
// unassign all writeups from a group and delete the group
mysqli_query($drs_db,"delete from links where linkgroup=$group");
$fail=mysqli_error($drs_db);
mysqli_query($drs_db,"delete from groups where id=$group");
$fail=mysqli_error($drs_db);
} elseif ($action=="setname" && $role && $save) {
$fail=false;
// change the name of a group
// remove html tags from group name and sanitize
$name=strip_tags($name);
$clean_name=mysqli_real_escape_string($drs_db,$name);
mysqli_query($drs_db,"update groups set name=\"$clean_name\" where id=\"$group\"");
$fail=mysqli_error($drs_db);
} elseif ($action=="takeaction" && $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) {
// 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);
// remove html tags from action text and sanitize
$edit_action_text=strip_tags($edit_action_text);
$clean_edit_action_text=mysqli_real_escape_string($drs_db,$edit_action_text);
// update the group members
$groupmem_qry=mysqli_query($drs_db,"select writeupid from links where linkgroup=\"$group\"");
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;
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);
}
}
}
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) {
$query_string="{$query_string}(";
$device_param="Devices:";
foreach ($s_device as $dev_val) {
$query_string="{$query_string}device=\"{$dev_val}\" or ";
$device_dsp=dblookup($drs_db,"devices","id","name",$dev_val);
$device_param="{$device_param} {$device_dsp}, ";
}
$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";
$query_string=rtrim($query_string," or ");
$query_string="{$query_string})";
$query_string="{$query_string} and ";
}
// subsystem
if ($s_subsystem) {
$query_string="{$query_string}(";
$subsystem_param="Subsystems:";
foreach ($s_subsystem as $sub_val) {
$query_string="{$query_string}subsystem=\"{$sub_val}\" or ";
$subsystem_dsp=dblookup($drs_db,"subsystems","id","name",$sub_val);
$subsystem_param="{$subsystem_param} {$subsystem_dsp}, ";
}
$subsystem_param=rtrim($subsystem_param,", ");
$num_subsystems=mysqli_num_rows(mysqli_query($drs_db,"select id from subsystems"));
if (count($s_subsystem)==$num_subsystems) $subsystem_param="Subsystems: any";
$query_string=rtrim($query_string," or ");
$query_string="{$query_string})";
$query_string="{$query_string} and ";
}
// period
if ($s_period) {
$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}, ";
}
$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";
$query_string=rtrim($query_string," or ");
$query_string="{$query_string})";
$query_string="{$query_string} and ";
}
// period_effective
if ($s_period_effective) {
$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}, ";
}
$eff_param=rtrim($eff_param,", ");
$query_string=rtrim($query_string," or ");
$query_string="{$query_string})";
$query_string="{$query_string} and ";
}
// status
if ($s_status) {
$query_string="{$query_string}(";
$status_param="Status:";
foreach ($s_status as $stat_val) {
$query_string="{$query_string}status=\"{$stat_val}\" or ";
if ($stat_val=="1") $stat_dsp="<font color=\"#FF0000\">OPEN</font>";
if ($stat_val=="2") $stat_dsp="<font color=\"#00FF00\">CLSD</font>";
if ($stat_val=="3") $stat_dsp="<font color=\"#FFFF00\">DFRD</font>";
$status_param="{$status_param} {$stat_dsp}, ";
}
$status_param=rtrim($status_param,", ");
$query_string=rtrim($query_string," or ");
$query_string="{$query_string})";
$query_string="{$query_string} and ";
}
// report date
$query_string="{$query_string}(";
$query_string="{$query_string}report_date between \"{$s_report_date_start}\" and \"{$s_report_date_end}\"";
$query_string="{$query_string})";
$query_string="{$query_string} and ";
$reportdate_param="Report date between {$s_report_date_start} and {$s_report_date_end}";
// report time
$query_string="{$query_string}(";
$query_string="{$query_string}report_time between \"{$s_report_time_start}\" and \"{$s_report_time_end}\"";
$query_string="{$query_string})";
$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) {
$query_string="{$query_string}(";
$query_string="{$query_string}discrepancy_text like \"%{$s_discrepancy_text}%\"";
$query_string="{$query_string})";
$query_string="{$query_string} and ";
$discrepancytext_param="Text in discrepancy: {$s_discrepancy_text}";
} else {
$discrepancytext_param="Text in discrepancy: any";
}
// reported by
if ($s_reported_by) {
$query_string="{$query_string}(";
$query_string="{$query_string}reported_by like \"%{$s_reported_by}%\"";
$query_string="{$query_string})";
$query_string="{$query_string} and ";
$repby_param="Text in Reported by: {$s_reported_by}";
} else {
$repby_param="Text in Reported by: any";
}
$query_string=rtrim($query_string," and ");
$query_string="select * from writeups where {$query_string} order by report_date asc";
}
// ******** end database manipulation ********
pagetable("begin");
if (!$print) {
pageblock("left","begin");
sidemenu();
pageblock("left","end");
}
pageblock("right","begin");
banner($print);
echo "<br>";
if ($action=="add") {
if (count($targets) > 1) {
$plural="s";
} else {
$plural="";
}
if ($save && !$fail) {
format_message(0,"<strong>Writeup$plural successfully added.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
} elseif ($save && $fail) {
format_message(2,"<strong>An error was encountered when adding writeup$plural.</strong> The error was \" $fail \"");
}
if ($save) {
// show the group
$mode="view";
group_table($group,$role,$mode);
if ($role) {
// show buttons
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<input type=\"hidden\" name=\"action\" value=\"add\">
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
</form>
";
}
} else {
if ($role){
// show mini search with discrepancy data only
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<input type=\"hidden\" name=\"action\" value=\"add\">
<b>Search Parameters</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enter search terms to find writeups to add to the group.<br>
<table border=\"0\" cellpadding=\"5\">
<tr>
<td align=\"left\">
";
// Status cell **********************
echo "
Status<br>
";
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 "
<select name=\"s_status[]\" id=\"ms-status\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
<option title=\"Open\" value=\"1\" $openstate>OPEN</option>
<option title=\"Closed\" value=\"2\" $clsdstate>CLSD</option>
<option title=\"Deferred\" value=\"3\" $dfrdstate>DFRD</option>
</select>
";
// **********************************
echo "
</td>
<td align=\"left\">
";
// Device cell *********************
echo "
Device<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");
while ($ditem=mysqli_fetch_assoc($drow)) {
if (!$search || in_array($ditem["id"],$s_device,true)) {
printf("<option value=\"%s\" selected>%s</option>",$ditem["id"],$ditem["name"]);
} else {
printf("<option value=\"%s\">%s</option>",$ditem["id"],$ditem["name"]);
}
}
echo "
</select>
";
// **********************************
echo "
</td>
<td align=\"left\">
";
// Subsystem cell *******************
echo "
Subsystem<br>
<select name=\"s_subsystem[]\" id=\"ms-subsystem\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
";
$ssrow=mysqli_query($drs_db,"select * from subsystems order by id asc");
while ($ssitem=mysqli_fetch_assoc($ssrow)) {
if (!$search || in_array($ssitem["id"],$s_subsystem,true)) {
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$ssitem["id"],$ssitem["description"],$ssitem["name"]);
} else {
printf("<option value=\"%s\" title=\"%s\">%s</option>",$ssitem["id"],$ssitem["description"],$ssitem["name"]);
}
}
echo "
</select>
";
// **********************************
echo "
</td>
";
echo "
</tr>
<tr>
<td align=\"left\">
";
// Period 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.\">
";
$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"]);
} else {
printf("<option value=\"%s\" title=\"%s\">%s</option>",$pitem["id"],$pitem["id"],$pitem["times"]);
}
}
echo "
</select>
";
// **********************************
echo "
</td>
<td align=\"left\">
";
// Report Date cell *****************
echo "
Report Date Between<br>
<input type=\"text\" name=\"s_report_date_start\" size=\"10\" maxlength=\"10\" value=\"$s_report_date_start\" id=\"sdp-report_date\" title=\"Format: YYYY-MM-DD\">
&nbsp;and&nbsp;
<input type=\"text\" name=\"s_report_date_end\" size=\"10\" maxlength=\"10\" value=\"$s_report_date_end\" id=\"edp-report_date\" title=\"Format: YYYY-MM-DD\">
";
// **********************************
echo "
</td>
";
echo "
<td align=\"left\">
";
// Report Time cell *****************
echo "
Report Time Between<br>
<input type=\"text\" name=\"s_report_time_start\" size=\"8\" maxlength=\"8\" value=\"$s_report_time_start\" title=\"Format: HH:MM:SS\">
&nbsp;and&nbsp;
<input type=\"text\" name=\"s_report_time_end\" size=\"8\" maxlength=\"8\" value=\"$s_report_time_end\" title=\"Format: HH:MM:SS\">
";
// **********************************
echo "
</td>
</tr>
<tr><td></td><td></td><td></td></tr>
<tr>
<td colspan=\"3\">
";
// Discrepancy text cell ************
echo "
Words in Discrepancy<br>
<textarea rows=\"5\" cols=\"80\" name=\"s_discrepancy_text\" wrap=\"soft\">$s_discrepancy_text</textarea><br>
";
// **********************************
echo "
</td>
</tr>
<tr>
<td align=\"left\">
";
// Reported by cell *****************
echo "
Reported by<br>
<input type=\"text\" name=\"s_reported_by\" size=\"30\" value=\"$s_reported_by\">
";
// **********************************
echo "
</td>
<td align=\"left\">
";
// Period effective cell ************
echo "
Sim period effective? &nbsp; <img src=\"icons/question.png\" title=\"" . PERIOD_EFF_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";
} else {
$effstate=$nefstate="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>
</td>
";
// **********************************"
echo "
<td align=\"right\">
<input type=\"submit\" name=\"search\" value=\"Find Writeups\">
</td></tr>
</table>
</form>";
// display the results
if ($search) {
$writeup_qry=mysqli_query($drs_db,$query_string);
if (mysqli_num_rows($writeup_qry)) {
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<input type=\"hidden\" name=\"action\" value=\"add\">
<table border=\"1\" cellpadding=\"5\" style=\"width:100%;\">
<tr>
<th style=\"width:1%;\">Select</th>
<th style=\"width:1%;\">ID</th>
<th style=\"width:1%;\">Status</th>
<th style=\"width:100px;\">Date</th>
<th style=\"width:1%;\">Device</th>
<th style=\"width:1%;\">Reported by</th>
<th>Discrepancy</th>
<th style=\"width:1%;\">Msn Eff</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\">";
} else {
$eff_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"Period Non-effective\" alt=\"Period Non-effective\">";
}
// determine status indicator
if ($tablerow['status']==1) $statusind="<font color=\"#FF0000\"><div title=\"Open\">OPEN</div></font>";
if ($tablerow['status']==2) $statusind="<font color=\"#00FF00\"><div title=\"Closed\">CLSD</div></font>";
if ($tablerow['status']==3) $statusind="<font color=\"#FFFF00\"><div title=\"Deferred\">DFRD</div></font>";
// convert device number to name
$dname=dblookup($drs_db,"devices","id","name",$tablerow["device"]);
$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']}\"");
$is_member=mysqli_num_rows($member_qry);
if ($is_member) {
$group_count=$is_member;
$member_group=mysqli_fetch_row($member_qry)[0];
$member_group_name=dblookup($drs_db,"groups","id","name",$member_group);
if ($member_group_name) {
$imgtitle="Member of group: $member_group_name";
} else {
$imgtitle="Member of group ID: $member_group";
}
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>";
}
}
// print table row
printf(
"<tr>
<td align=\"center\" valign=\"top\"><input type=\"checkbox\" name=\"targets[]\" value=\"%s\"></td>
<td align=\"center\" valign=\"top\"><a href=\"writeupdetail.php?id=%s\" title=\"View or change details of this writeup\">%s</a></td>
<td valign=\"top\">%s</td>
<td valign=\"top\">%s</td>
<td valign=\"top\">%s</td>
<td valign=\"top\">%s</td>
<td valign=\"top\">%s</td>
<td align=\"center\" valign=\"top\">%s</td>
</tr>\n",
$tablerow["id"],
$tablerow["id"],$tablerow["id"],
$statusind,
$tablerow["report_date"],
$dname,
$tablerow["reported_by"],
$disc_txt,
$eff_icon
);
}
echo "
</table>\n
<br>
Select the writeups above you'd like to add to the group and &nbsp;&nbsp;
<button name=\"save\" value=\"save\" type=\"submit\">Save group</button>
<br><br>
If nothing looks appropriate, you can modify the search parameters above and search again or select another menu option.
</form>";
} else {
echo "
<b>No writeups match your search parameters.</b><br><br>
You can modify the search parameters above and search again or select another menu option.
";
}
}
}
}
} elseif ($action=="remove") {
if ($save && !$fail) {
format_message(0,"<strong>Group successfully modified.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
} elseif ($save && $fail) {
format_message(2,"<strong>An error was encountered when modifying group.</strong> The error was \" $fail \"");
}
if ($role && mysqli_num_rows(mysqli_query($drs_db,"select id from links where linkgroup=$group"))) {
// show group table with everything selected
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<input type=\"hidden\" name=\"action\" value=\"remove\">
";
group_table($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.
<br><br>
<button name=\"save\" value=\"save\" type=\"submit\">Modify this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"cancel\" value=\"cancel\" type=\"submit\">Cancel</button>
</form>
";
}
} elseif ($action=="dissolve") {
if ($save && !$fail) {
format_message(0,"<strong>Group dissolved.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
} elseif ($save && $fail) {
format_message(2,"<strong>An error was encountered when dissolving the group.</strong> The error was \" $fail \"");
} else {
if ($role) {
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<input type=\"hidden\" name=\"action\" value=\"dissolve\">
<b>NOTE:</b> Dissolving this group will unassign its member writeups and remove the group.<br><br>
It will not delete any writeups or affect their assignment to other groups.<br><br>
<button name=\"save\" value=\"save\" type=\"submit\">Dissolve this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"cancel\" value=\"cancel\" type=\"submit\">Cancel</button>
</form>
";
}
// show the group
$mode="view";
group_table($group,$role,$mode);
if ($role) {
// show buttons
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
</form>
";
}
}
} elseif ($action=="setname") {
if ($save && !$fail) {
format_message(0,"<strong>Group name updated.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
} elseif ($save && $fail) {
format_message(2,"<strong>An error was encountered when updating the group name.</strong> The error was \" $fail \"");
}
if ($role) {
// get current group name if there is one and show the form
$curr_name=dblookup($drs_db,"groups","id","name",$group);
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<input type=\"hidden\" name=\"action\" value=\"setname\">
<input type=\"text\" name=\"name\" size=\"60\" value=\"$curr_name\">
<button name=\"save\" value=\"save\" type=\"submit\">Update group name</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"cancel\" value=\"cancel\" type=\"submit\">Cancel</button>
</form>
";
}
// show the group
$mode="view";
group_table($group,$role,$mode);
if ($role) {
// show buttons
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
</form>
";
}
} elseif ($action=="takeaction") {
if ($save && !$fail) {
format_message(0,"<strong>Group action completed.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
} elseif ($save && $fail) {
format_message(2,"<strong>An error was encountered when taking group action.</strong> The error was \" $fail \"");
}
// show the group
$mode="view";
group_table($group,$role,$mode);
if ($role && ! $save) {
// show action form
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<input type=\"hidden\" name=\"action\" value=\"takeaction\">
<table border=\"0\" cellpadding=\"5\" width=\"600\">
<tr>
<td>Status<br>
<select name=\"edit_status\" id=\"status\">
<option value=\"1\">OPEN</option>
<option value=\"2\"selected>CLOSED</option>
<option value=\"3\">DEFERRED</option>
</select>
</td>
<td>Action taken by<br>
";
if ($role==ADMIN) {
// allow selection of tech name
echo "
<select name=\"edit_action_by\" id=\"user\">
";
$persrow=mysqli_query($drs_db,"select id,firstname,lastname from users where active is true order by lastname asc");
while ($persitem=mysqli_fetch_assoc($persrow)) {
if ($userid==$persitem["id"]) {
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>
";
} else {
// limit the choice to the tech in question
echo "
<select name=\"edit_action_by\" id=\"user\">
";
$persrow=mysqli_query($drs_db,"select id,firstname,lastname from users where active is true order by lastname asc");
while ($persitem=mysqli_fetch_assoc($persrow)) {
if ($userid==$persitem["id"]) {
printf("<option value=\"%s\" selected>%s %s</option>",$persitem["id"],$persitem["firstname"],$persitem["lastname"]);
}
}
echo "
</select>
";
}
echo "
</td>
<td>Status change reason<br>
<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>";
while ($reasitem=mysqli_fetch_assoc($reasrow)) {
if ($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"]);
}
}
echo "
</select>
</td>
</tr>
<tr><td></td><td></td><td></td></tr>
<tr><td colspan=\"3\">
Action Taken <font size=\"-2\">(required)</font><br>
<textarea rows=\"10\" cols=\"80\" name=\"edit_action_text\" wrap=\"soft\"></textarea><br>
</td>
</tr>
<tr>
<td align=\"left\" >Action Taken Date<br>
<input type=\"text\" name=\"edit_action_date\" size=\"10\" maxlength=\"10\" value=\"$today\" id=\"actiondatepicker\" title=\"Format: YYYY-MM-DD\"></td>
<td align=\"left\">Action Taken Time<br>
<input type=\"text\" name=\"edit_action_time\" size=\"8\" maxlength=\"8\" value=\"$now\" title=\"Format: HH:MM:SS\"></td>
<td align=\"right\" valign=\"bottom\"><button type=\"submit\" name=\"save\" value=\"save\">Save action</button></td>
</tr>
<tr>
<td align=\"left\" valign=\"bottom\">
<td></td><td align=\"right\" valign=\"bottom\">
<input type=\"submit\" name=\"cancel\" value=\"Cancel Changes\"></td>
</tr>
</table>
</form>
";
}
} else {
if ($role) {
echo "
<form method=post action=\"groups.php\">
<button name=\"action\" value=\"add\" type=\"submit\">Create a new group</button>
</form>
<hr>
";
}
if ($group) {
// show only the requested group
$mode="view";
group_table($group,$role,$mode);
if ($role) {
// show buttons
echo "
<form method=post action=\"groups.php\">
<input type=\"hidden\" name=\"group\" value=\"$group\">
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
</form>
";
}
echo "<hr><br>";
} else {
// show all groups
$mode="view";
$groups_qry=mysqli_query($drs_db,"select id from groups");
if (mysqli_num_rows($groups_qry)) {
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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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> &nbsp;{$grouprow['id']}";
} else {
echo "<b>Group Name:</b> &nbsp;$groupname";
}
}
echo "<br><br>";
}
} else {
echo "<br>No writeup groups were found.<br><br><br>";
}
}
}
echo "<br>";
banner($print);
pageblock("right","end");
pagetable("end");
framework("end","","",$print);
?>