<?php ################################################################ # @(#) $Id: generic_item.inc,v 1.13 2001/08/15 22:33:52 andr Exp $ # # A.Gaponenko, June 2001 # require("edit_utils.inc"); $scriptid .= '@(#) $Id: generic_item.inc,v 1.13 2001/08/15 22:33:52 andr Exp $'; ################################################################ if($send) { ## strip spaces where they should be ignored mytrim( array( 'status_date' ), $HTTP_POST_VARS ); ## HTML-escape all posted data and reset vars in current scope esc_r($HTTP_POST_VARS); extract($HTTP_POST_VARS, EXTR_OVERWRITE); $comment=chop($comment); $errflag = 0; $modstr = ""; $modstr .= change4_str( "Status", 'status', $errflag, $HTTP_POST_VARS); ################################################################ if($modstr || $comment) { send_html_header("$self_name $item_id"); echo "<H1>$self_name $item_id</H1>\n"; echo "<FORM action=view_item.php method=POST>\n" ."<input type=hidden name=item_type value=\"$item_type\">\n" ."<input type=hidden name=item_id value=\"$item_id\">\n" ."<input type=hidden name=comment value=\"$comment\">\n" ."<input type=hidden name=status value=\"$status\">\n" ."<input type=hidden name=old_status value=\"$old_status\">\n" ."<input type=hidden name=status_date value=\"$status_date\">\n" ."<input type=hidden name=old_status_date value=\"$old_status_date\">\n" ##---------------- ."\n<table>\n" ##---------------- . ($modstr ? "<tr><td>\n" ."<TABLE border width=100% cellpadding=4>\n" ."<TR>\n" ."<TD><b>You want to change</b></TD>\n" ."<TD><b>from</b></TD>\n" ."<TD><b>to</b></TD>\n" ."<TD><b>work date</b></TD>\n" ."</TR>\n" . $modstr ."</TABLE>\n" ."</td></tr>\n" : "" ) ##---------------- . ($comment ? "<tr><td>". "<p><b>Your comment is:</b><br><tt><pre>\n" ."$comment</pre></tt></p>\n" ."</td></tr>\n" : "" ) ##---------------- ."\n</table>\n" ##---------------- . ($errflag ? "" : "<input type=submit name=confirm " ."value=\"Confirm\">\n" ) ."<input type=submit name=reset value=\"Cancel everything\">\n" .' <b>OR Press the <i>Back</i> button of your browser' .' to edit your input</b><br>'; ; } else { send_html_header("$self_name $item_id"); echo "<H1>$self_name $item_id</H1>\n"; echo "<FORM action=view_item.php method=POST>\n" ."<input type=hidden name=item_type value=\"$item_type\">\n" ."<input type=hidden name=item_id value=\"$item_id\">\n" ."You didn't modify anything. " ."<input type=submit name=reset value=\"OK\">\n" ; } send_common_trailer(); exit; } ################################################################ if($confirm) { ## HTML-escape all posted data and reset vars in current scope esc_r($HTTP_POST_VARS); extract($HTTP_POST_VARS, EXTR_OVERWRITE); $err = ''; $op = 'edit_generic_item'; if(!start_transaction($conn,$op,$scriptid,$comment)) { $err .= "Can't start transaction."; } else { ## ---------------------------------------------------------------- $sernum = make_sernum($conn, $item_id, $item_type); ## ---------------------------------------------------------------- if($comment) { $q = pg_exec( $conn, "INSERT INTO item_comment" ." (tn,sernum,workdate)" ." values" ." (currval('tn'),$sernum,'now');" ); if(!$q) { $err .= "Error setting comment.<br>\n"; } } ## ---------------------------------------------------------------- $res = check_change4('status', $HTTP_POST_VARS); if($res['error']) { $err .= "Error verifying 'status' vars: $res[error].<br>\n"; } elseif($res['diff']) { $err .= edit_set_selected( $sernum, $status, $status_date, 'status', 'statuses', 'status'); } ## ================================================================ if(!$err) { if(!pg_exec($conn, "COMMIT;")) { $err .= "Error commiting changes."; } } } ################################################################ ## Exit on a error. But, if DB is successfully modified ## just continue to display an updated page. if($err) { pg_exec($conn, "ROLLBACK;"); echo "<FORM method=POST>\n" ."<font color=red>$err</font><br>\n" ."<b>Database has not been modified.</b>\n" ."<input type=hidden name=item_type value=\"$item_type\">\n" ."<input type=hidden name=item_id value=\"$item_id\">\n" ."<input type=submit name=reset value=\"Ok\">\n" ."</FORM>\n" ; send_common_trailer(); exit; } } ################################################################ # Query DB about current item parameters ## ================================================================ ## Prepare status info $res = edit_get_status($item_id, $item_type); if($statusarr['error']) { echo "<font color=red>$res[error]</font><br>"; } $status = $res['status']; $status_date = $res['date']; $status_set = $res['isset']; $status_options = $res['options']; ## ================================================================ ## Where is the item installed? $res = edit_get_base($sernum); if($res['error']) { echo "<font color=red>$res[error]</font><br>"; } $base_sernum = $res['base_sernum']; $base_date = $res['date']; $base_desc = $res['description']; ## ---------------------------------------------------------------- $comments = get_comments($sernum); ################################################################ # Display a form with current parameters as default values send_html_header("$self_name $item_id"); echo "<FORM action=view_item.php method=POST>\n" ."<H1>$self_name $item_id</H1>\n" ."<input type=hidden name=item_type value=\"$item_type\">\n" ."<input type=hidden name=item_id value=\"$item_id\">\n" # -------------------------------- ."<div>\n" ."<p>Status:" ."<input type=hidden name=old_status" ." value=\"$status\">\n" ."<select name=status>\n" . $status_options ."</select>\n" . ($status_set? "" : "(default) " ) ." Status change date: " ."</TD><TD align=left>\n" ."<input type=text name=status_date size=23" ." value=\"$status_date\">\n" ."<input type=hidden name=old_status_date" ." value=\"$status_date\">\n" ."</div>\n" # -------------------------------- ."<div><p>\n" . ($base_sernum ? "Installed in " ."<a href=view_item.php?sernum=$base_sernum>\n" ."$base_desc " . format_default_id($base_sernum) ."</a>" ." on $base_date" : "Not installed. " ) ."</div>\n" # -------------------------------- ."<div>\n" ."<p>Comment to add<br>\n" .' <textarea name="comment" rows="3" cols="80">' .'</textarea>' ."</div>\n" # ---------------- ."<div>\n" ."<input type=submit name=send value=\"Submit changes\">\n" ."<input type=submit name=reset value=\"Reload page\">\n" ."</div>\n" # ---------------------------------------------------------------- .( $comments ? "<div><hr>\n" ."<i>Existing comments about " ."<b>$self_name</b> $item_id</i>:\n" . $comments ."</div>\n" : "" ) # ---------------------------------------------------------------- ."</FORM>\n" ; ################################################################ ?>