$query = "UPDATE asset_tbl SET status='Decomissioned' WHERE assetid = {$current_asset}"; $result = pg_query($query); query_error_check($result, $query, "Failed to set status to Decomissioned"); // Assign to user "None" $query = "INSERT INTO assignment_tbl (datetime,assetid_fkey,userid_fkey) VALUES ('" . date('m/d/Y h:i:s A') . "',{$current_asset},'199')"; $result = pg_query($query); query_error_check($result, $query, "Failed to assign to user None"); } // After a successful update, redirect to detail page if ($current_tbl == "user_tbl") { header("Location: user_details.php?user={$current_asset}&field=note"); } else { header("Location: tag_details.php?asset={$current_asset}&field=note"); } } else { // If there is a duplicate found html_header('HI Asset DB - Duplicate', ''); include "top_menu.php"; echo "<h2>Duplicate found</h2>\n"; echo "<p>Problem updating. " . display_format($current_field) . " {$_POST['new_value']} already exists.</p>\n"; if ($current_tbl == "user_tbl") { echo "<p><a href=user_details.php?user={$current_asset}&field=note>Click here to return</a></p>"; } else { echo "<p><a href=tag_details.php?asset={$current_asset}&field=note>Click here to return</a></p>"; } echo "</pre></body></html>\n"; } } ?>
function detail_row($current_tbl, $asset, $current_val, $field, $edit_field) { // Used in user_datails.php and tag_details.php // If those pages are ever combined, consider moving this function to that page if ($edit_field == $field) { echo "\t\t\t\t\t\t<tr>\n"; echo "\t\t\t\t\t\t\t<td>" . display_format($field) . "</td>\n"; echo "\t\t\t\t\t\t\t<td>\n"; echo "\t\t\t\t\t\t\t\t<FORM name=\"update_form\" method=\"post\" action=\"updating.php\">\n"; echo "\t\t\t\t\t\t\t\t<INPUT TYPE=hidden NAME=pass_table VALUE={$current_tbl}>\n"; echo "\t\t\t\t\t\t\t\t<INPUT TYPE=hidden NAME=pass_assetid VALUE={$asset}>\n"; echo "\t\t\t\t\t\t\t\t<INPUT TYPE=hidden NAME=pass_field VALUE={$field}>\n"; if ($field == "type" || $field == "description" || $field == "department" || $field == "videocard" || $field == "videobus" || $field == "harddrive" || $field == "cpu" || $field == "memory") { echo "<SELECT NAME=\"new_value\">\n"; // Create OPTION list from current values in the database! $query = "SELECT {$field} FROM {$current_tbl} GROUP BY {$field} ORDER BY {$field}"; $result = pg_query($query); while ($option_row = pg_fetch_assoc($result)) { echo "<OPTION VALUE=\"" . htmlentities($option_row[$field]) . "\""; if ($option_row[$field] == $current_val) { echo " selected=\"selected\""; } echo ">" . htmlentities($option_row[$field]) . "</OPTION>\n"; } echo "\t</SELECT>\n"; echo "\t</td>\n"; } elseif ($field == "active") { echo "<input type=radio NAME=\"new_value\" value=\"t\" "; if ($current_val == "t") { echo "checked"; } echo ">Yes "; echo "<input type=radio NAME=\"new_value\" value=\"f\" "; if ($current_val == "f") { echo "checked"; } echo ">No"; } elseif ($field == "status") { $choice_array = array('Active', 'Available', 'Benched', 'Unstable', 'Proxy', 'Build', 'Remote', 'Parts', 'Reserved', 'Decomissioned', 'Unknown'); echo "<SELECT NAME=\"new_value\">\n"; foreach ($choice_array as $choice) { echo "<OPTION VALUE=\"" . $choice . "\""; if ($choice == $current_val) { echo "selected=\"selected\""; } echo ">" . $choice . "</OPTION>\n"; } echo "</SELECT>\n"; echo "</td>\n"; } else { $value = htmlentities($current_val); echo "\t\t\t\t\t\t\t\t<INPUT TYPE=text NAME=\"new_value\" VALUE=\"" . $value . "\">\n"; echo "\t\t\t\t\t\t\t</td>\n"; } echo "\t\t\t\t\t\t\t<td>\n"; echo "\t\t\t\t\t\t\t\t<INPUT TYPE=submit VALUE=\"Update\"></td>\n"; echo "\t\t\t\t\t\t\t\t</FORM>\n"; echo "\t\t\t\t\t\t\t</td>\n"; echo "\t\t\t\t\t\t</tr>\n"; return; } else { // Display data that is not currently being edited echo "\t\t\t\t\t\t<tr>\n"; echo "\t\t\t\t\t\t\t<td> " . display_format($field) . "</td>\n"; if ($field == "active" && $current_val == 't') { echo "\t\t\t\t\t\t\t<td style=\"color:green;\">Yes</td>\n"; } elseif ($field == "active" && $current_val == 'f') { echo "\t\t\t\t\t\t\t<td style=\"color:red;\">No</td>\n"; } elseif ($field == "active" && !$current_val) { echo "\t\t\t\t\t\t\t<td style=\"color:red;\">NULL!</td>\n"; } elseif ($field == "batch" || $field == "harddrive" || $field == "memory" || $field == "videocard" || $field == "videobus" || $field == "cpu" || $field == "warranty" || $field == "status") { // Some fields get a reference to a list of other assets with the same value echo "\t\t\t\t\t\t\t<td><a href=\"pc_list.php?search={$field}&key=" . htmlentities($current_val) . "\">{$current_val}</a></td>\n"; } elseif ($field == "description") { echo "\t\t\t\t\t\t\t<td><a href=\"asset_list.php?search={$field}&key=" . htmlentities($current_val) . "\">{$current_val}</a></td>\n"; } else { echo "\t\t\t\t\t\t\t<td> " . htmlentities($current_val) . "</td>\n"; } if ($current_tbl == "asset_tbl" || $current_tbl == "pc_detail_tbl") { echo "\t\t\t\t\t\t\t<td><a href=\"tag_details.php?asset=" . $asset . "&field=" . $field . "\">edit</a></td>\n"; } elseif ($current_tbl == "user_tbl") { echo "\t\t\t\t\t\t\t<td><a href=\"user_details.php?user="******"&field=" . $field . "\">edit</a></td>\n"; } echo "\t\t\t\t\t\t</tr>\n"; return; } }