function system_school_data_form_validate

7.x system.module system_school_data_form_validate($form, &$form_state)
6.x system.module system_school_data_form_validate($form, &$form_state)
4.x system.module system_school_data_form_validate($form, &$form_state)
5.x system.module system_school_data_form_validate($form, &$form_state)

Validate handler for the school_data_form.

Most of our data can be saved as simple system_settings, but for the others, we want to save them to special tables, then remove them from the form_state so they don't get saved to the variables table, taking up a lot of space.

_state

Parameters

unknown_type $form:

File

modules/system/system.module, line 1953

Code

function system_school_data_form_validate($form, &$form_state) {

  $school_id = intval($form_state ['values']['school_id']);
  $fs = "";
  if ($school_id !== 0) {
    $fs = "~~school_" . $school_id;
  }
  // Subjects...
  db_query("DELETE FROM subjects WHERE school_id = ?", $school_id);


  $subjects = trim($form_state ["values"]["subjects" . $fs]);
  $lines = explode("\n", $subjects);
  foreach ($lines as $line) {
    $temp = explode("~", $line);

    db_query("INSERT INTO subjects (subject_id, college, title, school_id)
              VALUES (?, ?, ?, ?) ", strtoupper(trim($temp [0])), strtoupper(trim($temp [1])), trim($temp [2]), $school_id);

  }
  // Remove the data from our form_state, so it isn't saved twice
  unset($form_state ["values"]["subjects" . $fs]);



  // Colleges...
  db_query("DELETE FROM colleges WHERE school_id = ?", $school_id);

  $contents = trim($form_state ["values"]["colleges" . $fs]);
  $lines = explode("\n", $contents);
  foreach ($lines as $line) {
    $temp = explode("~", $line);

    db_query("INSERT INTO colleges (college_code, title, school_id)
              VALUES (?, ?, ?) ", strtoupper(trim($temp [0])), trim($temp [1]), $school_id);

  }
  // Remove the data from our form_state, so it isn't saved twice
  unset($form_state ["values"]["colleges" . $fs]);



  // Degree College...
  db_query("DELETE FROM degree_college WHERE school_id = ?", $school_id);

  $contents = trim($form_state ["values"]["degree_college" . $fs]);
  $lines = explode("\n", $contents);
  foreach ($lines as $line) {
    $temp = explode("~", $line);

    db_query("INSERT INTO degree_college (major_code, college_code, school_id)
              VALUES (?, ?, ?) ", strtoupper(trim($temp [0])), strtoupper(trim($temp [1])), $school_id);

  }
  // Remove the data from our form_state, so it isn't saved twice
  unset($form_state ["values"]["degree_college" . $fs]);

  watchdog("system", "Updated school settings (school_id: $school_id)");


}