"; //var_dump($_REQUEST); //echo "

incoming array
"; //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 "; } // discovered if ($s_discovered) { $query_string="{$query_string}("; $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}, "; } $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 "; } // functional if ($s_functional) { $query_string="{$query_string}("; $func_param="$functional_term:"; foreach ($s_functional as $func_val) { $query_string="{$query_string}functional=\"{$func_val}\" or "; if ($func_val=="0") $func_dsp="$functional_no_short"; if ($func_val=="1") $func_dsp="$functional_yes_short"; $func_param="{$func_param} {$func_dsp}, "; } $func_param=rtrim($func_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="OPEN"; if ($stat_val=="2") $stat_dsp="CLSD"; if ($stat_val=="3") $stat_dsp="DFRD"; $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 "
"; if ($action=="add") { if (count($targets) > 1) { $plural="s"; } else { $plural=""; } if ($save && !$fail) { format_message(0,"Writeup$plural successfully added. Return to Writeup Groups page."); } elseif ($save && $fail) { format_message(2,"An error was encountered when adding writeup$plural. The error was \" $fail \""); } if ($save) { // show the group $mode="view"; group_table($group,$role,$mode); if ($role) { // show buttons echo "
                       
"; } } else { if ($role){ // show mini search with discrepancy data only echo "
Search Parameters     Enter search terms to find writeups to add to the group.
"; echo " "; 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 "
"; // Device cell ********************* echo " Device
"; // ********************************** echo "
"; // Subsystem cell ******************* echo " Subsystem
"; // ********************************** echo "
"; // Discovered cell ********************** echo " $discovered_term
"; // ********************************** 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 "
"; // functional cell ************ echo " $functional_term?  
"; if ($search) { $funcyesstate=$funcnostate=""; if (in_array("1",$s_functional,true)) $funcyesstate="selected"; if (in_array("0",$s_functional,true)) $funcnostate="selected"; } else { $funcyesstate=$funcnostate="selected"; } echo "
"; // display the results if ($search) { $writeup_qry=mysqli_query($drs_db,$query_string); if (mysqli_num_rows($writeup_qry)) { echo "
"; while ($tablerow = mysqli_fetch_assoc($writeup_qry)) { // determine functional icon if($tablerow["functional"]==1) { $func_icon="\"$functional_yes\""; } else { $func_icon="\"$functional_no\""; } // 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"]); $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."
\"GRP\"
"; } else { $disc_txt=$disc_txt."
\"GRP\"
"; } } // print table row printf( "\n", $tablerow["id"], $tablerow["id"],$tablerow["id"], $statusind, $tablerow["report_date"], $dname, $tablerow["reported_by"], $disc_txt, $func_icon ); } echo "
Select ID Status Date Device Reported by Discrepancy $functional_term_short
%s %s %s %s %s %s %s
\n
Select the writeups above you'd like to add to the group and   

If nothing looks appropriate, you can modify the search parameters above and search again or select another menu option.
"; } else { echo " No writeups match your search parameters.

You can modify the search parameters above and search again or select another menu option. "; } } } } } elseif ($action=="remove") { if ($save && !$fail) { format_message(0,"Group successfully modified. Return to Writeup Groups page."); } elseif ($save && $fail) { format_message(2,"An error was encountered when modifying group. 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 "
"; group_table($group,$role,"select","all"); echo " Deselect the writeups you want to remove from this group.

NOTE: Deselecting them all will dissolve the group.

     
"; } } elseif ($action=="dissolve") { if ($save && !$fail) { format_message(0,"Group dissolved. Return to Writeup Groups page."); } elseif ($save && $fail) { format_message(2,"An error was encountered when dissolving the group. The error was \" $fail \""); } else { if ($role) { echo "
NOTE: Dissolving this group will unassign its member writeups and remove the group.

It will not delete any writeups or affect their assignment to other groups.

     
"; } // show the group $mode="view"; group_table($group,$role,$mode); if ($role) { // show buttons echo "
                       
"; } } } elseif ($action=="setname") { if ($save && !$fail) { format_message(0,"Group name updated. Return to Writeup Groups page."); } elseif ($save && $fail) { format_message(2,"An error was encountered when updating the group name. 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 "
     
"; } // show the group $mode="view"; group_table($group,$role,$mode); if ($role) { // show buttons echo "
                       
"; } } elseif ($action=="takeaction") { if ($save && !$fail) { format_message(0,"Group action completed. Return to Writeup Groups page."); } elseif ($save && $fail) { format_message(2,"An error was encountered when taking group action. The error was \" $fail \""); } // show the group $mode="view"; group_table($group,$role,$mode); if ($role && ! $save) { // show action form echo "
Status
Action taken by
"; if ($role==ADMIN) { // allow selection of tech name echo " "; } else { // limit the choice to the tech in question echo " "; } echo "
Status change reason
Action Taken (required)

Action Taken Date
Action Taken Time
"; } } else { if ($role) { echo "

"; } if ($group) { // show only the requested group $mode="view"; group_table($group,$role,$mode); if ($role) { // show buttons echo "
                       
"; } echo "

"; } 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 "
                       
"; } } else { echo " \"Expand "; $groupname=dblookup($drs_db,"groups","id","name",$grouprow['id']); if ($groupname == "") { echo "Group ID:  {$grouprow['id']}"; } else { echo "Group Name:  $groupname"; } } echo "

"; } } else { echo "
No writeup groups were found.


"; } } } echo "
"; banner($print); pageblock("right","end"); pagetable("end"); framework("end","","",$print); ?>