function admin_apply_draft_changes_form_submit

6.x admin.module admin_apply_draft_changes_form_submit($form, $form_submit)
4.x admin.module admin_apply_draft_changes_form_submit($form, $form_submit)
5.x admin.module admin_apply_draft_changes_form_submit($form, $form_submit)

Handles the actual moving of draft courses into production.

File

modules/admin/admin.module, line 929
The administrative configurations for FlightPath.

Code

function admin_apply_draft_changes_form_submit($form, $form_submit) {
  $values = $form_submit ["values"];

  $db = get_global_database_handler();
  $de_catalog_year = admin_get_de_catalog_year();

  // Check to make sure they entered the transfer passcode correctly.

  if ($values ["passcode"] != variable_get("admin_transfer_passcode", "h24897Ewujflnb7 wy2896432hke w490ukj")) {

    form_error("passcode", t("Error!  The password you entered is not correct.  Check with the FlightPath administrator
                              (or check the admin settings pages) to learn the password."));
    return;

  }


  // First, set maintenance mode...
  variable_set("maintenance_mode", TRUE);

  // Okay, so what we gotta do is truncate the production tables,
  // then copy the draft tables in.
  $table_array = array(
    "courses",
    "degree_requirements",
    "degree_tracks",
    "degrees",
    "group_requirements",
    "groups",
  );

  foreach ($table_array as $table_name) {
    $draft_table_name = "draft_$table_name";
    // First, truncate existing...
    $query = "truncate table $table_name";
    $res = db_query($query);
    // Now, copy in draft changes...
    $query = "INSERT INTO $table_name
            SELECT * FROM $draft_table_name ";
    $res = db_query($query);
  }

  $db2 = new DatabaseHandler();
  // Now, we need to go through the draft_instructions table,
  // and perform each instruction one at a time.
  $res = db_query("SELECT * FROM draft_instructions
            ORDER BY `id` ");
  while ($cur = db_fetch_array($res)) 
   {
    $instruction = trim($cur ["instruction"]);

    $temp = explode(",", $instruction);

    if (trim($temp [0]) == "update_course_id") {
      $db2->update_course_id(trim($temp [1]), trim($temp [2]));
    }

    if (trim($temp [0]) == "update_course_requirement_from_name") {
      $db2->update_course_requirement_from_name(trim($temp [1]), trim($temp [2]), trim($temp [3]));
    }
  }

  // Once this is done, truncate the draft_instructions table.
  $res = db_query("TRUNCATE TABLE draft_instructions");


  // And we are done!  Set maintenance mode back to none
  variable_set("maintenance_mode", FALSE);

  // Send emails to notify programmers...
  $notify = variable_get("notify_apply_draft_changes_email_address", "");
  if ($notify != "") {
    mail($notify, "FlightPath Apply Draft Changes", "Someone has applied draft changes to FlightPath, which updated degree plans, groups, and courses.");
  }

  fp_add_message(t("Successfully updated the production database with draft changes.  Your changes are now live and visible on production for all users."));

  watchdog("admin", "Draft changes applied.");


}