check_group_auth( array("root", "ceo", "cfo") ) ) { show_error("You do not have permission to view this page"); } if( $Input->post("process_form") ) { // clean user input $clean['notes'] = htmlentities( $Input->post("notes"), ENT_QUOTES, "UTF-8" ); switch( $Input->post("skip") ) { case "yes": case "no": $clean['skip'] = $Input->post("skip"); break; default: $clean['skip'] = "no"; break; } // check for errors $errors = ''; if( ! $Input->post("notes") ) { $errors[] = "You must include a note."; } if( is_array($errors) ) { #print_r($errors); _show_message( $errors, 'error' ); } else { // determine form status. the skip switch is only available if the user has already signed, // or no one has signed, and they wish to send the form along regardless // if skip = yes, set status to approve // if skip = no, set status to pending... if( $clean['skip'] == "yes" ) { $skip = TRUE; $clean['status'] = 3; } else { $skip = FALSE; $clean['status'] = 1; } if( $Input->post("approve") == 1 ) { $clean['status'] = 3; } $updateSPR = new SPR( $DBH ); $updateSPR->set(array("id"=>$id)); // determine what user group we are. ceo or cfo and run proper update query if( $Userauth->check_group_auth( array("root", "ceo") ) ) { $clean['ceo_date_signed'] = time(); $clean['ceo_id'] = $Userauth->get("id"); $clean['ceo_sig'] = encrypt_user_sig( $Userauth->get("username"),$Userauth->get("id") ); $updateSPR->set( $clean ); $updateSPR->ceo_approve_spr(); } elseif( $Userauth->check_group_auth( array("root", "cfo") ) ) { $clean['cfo_date_signed'] = time(); $clean['cfo_id'] = $Userauth->get("id"); $clean['cfo_sig'] = encrypt_user_sig( $Userauth->get("username"),$Userauth->get("id") ); $updateSPR->set( $clean ); $updateSPR->cfo_approve_spr(); } // get the spr objects updated attributes $updateSPR->set( $updateSPR->get_form_details() ); // if status is 3, then the status is approved and the PO needs to be notified. if( $clean['status'] == 3 ) { // mail po here since the status is now APPROVED. $group = $Userauth->get_group_id("cfo"); $location = $updateSPR->get('location_id'); $po_emails = $updateSPR->get_spr_emails( $location, $group ); #spr_send_approved_notice( $emails ); } _show_message( array("SPR Updated"), "msg" ); } } else { // get details of spr $SPR = new SPR( $DBH ); $SPR->set( array( "id"=>$id ) ); $spr_details = $SPR->get_form_details(); $approve_switch = 0; // check to see if ceo and cfo have signed the form if( $spr_details['ceo_id'] == "" && $spr_details['cfo_id'] == "" || empty($spr_details['ceo_id']) && empty($spr_details['cfo_id']) ) { // ceo and cfo havent signed the form $TPL->assign_block_vars("SWITCH_SKIP_SIG",array());// enables the switch to bypass the second sig in the form $TPL->assign_var("NOTICE", "

Two Signatures are recommended to apoprove an SPR. If you want to skip the second signature, check the appropriate radio button and explain the reasons why in the notes field.

"); } // someone has signed, determine who // if current user has signed, then show message and skip sig switch elseif( $spr_details['ceo_id'] == $Userauth->get("id") || $spr_details['cfo_id'] == $Userauth->get("id") ) { $TPL->assign_block_vars("SWITCH_SKIP_SIG",array()); $TPL->assign_var("NOTICE", "

You have already signed this SPR, but you can push it ahead by skipping the second signature. If you want to skip the second signature, check the appropriate radio button and explain the reasons why in the notes field.

"); } else { $TPL->assign_var("NOTICE", "

This form has been signed once. After you approve this form it will be sent to the PO and taken out of the pending queue

"); } // determine the status to set the form at if( !empty($spr_details['ceo_id']) && empty($spr_details['cfo_id']) || !empty($spr_details['cfo_id']) && empty($spr_details['ceo_id']) ) { // someone has signed, so the next signature should move the form to the PO $approve_switch = 1; // however, if the sig is from the current user, then set switch to 0... if( $spr_details['ceo_id'] != "" && $spr_details['ceo_id'] == $Userauth->get("id") || $spr_details['cfo_id'] != "" && $spr_details['cfo_id'] == $Userauth->get("id") ) { $approve_switch = 0; } } $TPL->assign_vars(array( "APPROVE_SWITCH" => $approve_switch, "FORM_ID" => $id, "NOTES" => $SPR->get_spr_notes() )); $template = "spr/spr_approve.html"; } ?>