function audit_hidden_approval_form_submit

6.x audit.module audit_hidden_approval_form_submit($form, $form_state)

File

modules/audit/audit.module, line 654
This is the Audit module, which provides functionality relating to degree audits.

Code

function audit_hidden_approval_form_submit($form, $form_state) {
  global $user;
  $values = $form_state ["values"];

  $faculty_id = $user->cwid;
  $student_id = $values ["approval_student_id"];
  $approval_type = $values ["approval_type"];
  $approval_value = $values ["approval_value"];
  $comment = trim($values ["approval_comment"]);

  $school_id = db_get_school_id_for_student_id($student_id);

  //  Check that we have permission to edit the approval for this person?
  if (!user_has_permission("edit_audit_approvals") || !audit_can_access_audit($student_id)) {
    fp_add_message(t("You do not have permission to edit audit approvals for this student"), "error");
    return FALSE;
  }





  $types = audit_get_approval_types($school_id);
  $details = $types [$approval_type];
  $approval_type_title = $details ["title"];
  if ($approval_type_title == "") {
    $approval_type_title = $approval_type;
  }



  // Okay, let's save the approval status to our table.
  // Begin by deleting what's there for this approval type and student.
  db_query("DELETE FROM audit_approvals 
            WHERE student_id = '?'
            AND approval_type = '?' ", $student_id, $approval_type);
  // Now, add our values
  $now = time();
  db_query("INSERT INTO audit_approvals
            (student_id, uid, faculty_id, approval_type, approval_value, posted)
            VALUES ('?', '?', '?', '?', '?', '?')
            ", $student_id, $user->id, $faculty_id, $approval_type, $approval_value, $now);

  fp_add_message(t("Approval value has been successfully updated for type %title.", array("%type" => $approval_type, "%title" => $approval_type_title)));

  // Also write to our comments table, and include the comment. 
  //$approval_desc = ($approval_value == "no_approve") ? t("Not approved") : t("Approved");
  $options = audit_get_approval_options();
  $approval_desc = $options [$approval_value];
  if ($approval_desc == "") {
    $approval_desc = $approval_value;
  }



  $new_comment = " -- " . t("Automated Audit Comment") . " --<br><br>
                  " . t("Approval status updated for:") . " <b>$approval_type_title</b>.  " . t("New value:") . " <b>$approval_desc</b>.";
  if ($comment != "") {
    $new_comment .= "<br><br>" . t("Additional comment:") . " <br>-----------<br><em>" . nl2br($comment) . "</em>";
  }
  $new_values = array(
    "student_id" => $student_id,
    "faculty_id" => $faculty_id,
    "comment" => $new_comment,
  );

  audit_comment_form_submit(array(), array("values" => $new_values));



}