function biblio_admin_types_edit_form_submit in Bibliography Module 7.2
Same name and namespace in other branches
- 6.2 includes/biblio.admin.inc \biblio_admin_types_edit_form_submit()
- 6 biblio.admin.inc \biblio_admin_types_edit_form_submit()
- 7 includes/biblio.admin.inc \biblio_admin_types_edit_form_submit()
File
- includes/
biblio.admin.inc, line 924
Code
function biblio_admin_types_edit_form_submit($form, &$form_state) {
if ($form_state['triggering_element']['#value'] == t('Change Publication Type')) {
$form_state['rebuild'] = TRUE;
$form_state['pub_type'] = $form_state['values']['pub_type'];
$form_state['input'] = array();
return;
}
$tid = isset($form_state['values']['type_id']) ? $form_state['values']['type_id'] : 0;
if ($tid) {
// save publication type name
$type_name_record = array(
'tid' => $tid,
'name' => $form_state['values']['type_name'],
);
// drupal_write_record('biblio_types', $type_name_record, 'tid');
db_update('biblio_types')
->fields($type_name_record)
->condition('tid', $tid)
->execute();
biblio_locale_refresh_types($tid);
}
// save author types
/* $link['biblio_type'] = $tid;
db_delete('biblio_contributor_type')
->condition('biblio_type', $link['biblio_type'])
->execute();
for ($i=1; $i<=5; $i++) {
$link['auth_category'] = $i;
$auth_types = (array)$form_state['values']['configured_flds'][$i]['auth_type'];
// if default values have not changed, do not store to the database explicitly
if ($link['biblio_type'] &&
(array_values($auth_types) == array_values((array)$form['configured_flds'][$i]['auth_type']['#default_value']))) continue;
foreach ($auth_types as $type) {
$link['auth_type'] = $type;
db_insert('biblio_contributor_type')
->fields($link)
->execute();
}
}
*/
$hide_other_fields = isset($form_state['values']['hide_other_fields']) ? $form_state['values']['hide_other_fields'] : 0;
variable_set('biblio_hide_other_fields', $hide_other_fields);
// save other field data
foreach ($form_state['values']['biblio_tabs'] as $fid => $values) {
$update = FALSE;
$val = array();
$link = array();
if (is_int($fid)) {
$link['fid'] = $fid;
$link['tid'] = $tid;
foreach ($values as $name => $value) {
$disabled = !empty($form_state['tab_defaults'][$fid][$name]['disabled']) ? TRUE : FALSE;
if (!$disabled) {
$default_value = isset($form_state['tab_defaults'][$fid][$name]['default']) ? $form_state['tab_defaults'][$fid][$name]['default'] : '';
if ($name == 'checkboxes') {
$link['visible'] = !empty($value['visible']) ? 1 : 0;
$link['required'] = !empty($value['required']) ? 1 : 0;
if ($tid == 0) {
$link['common'] = !empty($value['common']) ? 1 : 0;
$link['autocomplete'] = !empty($value['autocomplete']) ? 1 : 0;
}
}
elseif ($name == 'weight') {
$link['weight'] = $value;
}
else {
$val[$name] = $value;
if (!$update) {
$update = $default_value != $val[$name] ? $form_state['values']['biblio_tabs'][$fid]['ftdid'] : FALSE;
}
}
}
}
if ($update == $fid && $link['tid']) {
// we just changed a default value, so create a new entry in biblio_field_type_data
$new_ftdid = variable_get('biblio_last_ftdid', 100);
variable_set('biblio_last_ftdid', $new_ftdid + 1);
$val['ftdid'] = $new_ftdid;
$link['ftdid'] = $new_ftdid;
$link['cust_tdid'] = $new_ftdid;
drupal_write_record('biblio_field_type_data', $val);
}
elseif ($update >= 100 && $link['tid']) {
// we are updating an existing entry
$val['ftdid'] = $form_state['values']['biblio_tabs'][$fid]['ftdid'];
drupal_write_record('biblio_field_type_data', $val, 'ftdid');
}
elseif ($update == $fid) {
// changing the defaults
$val['ftdid'] = $fid;
drupal_write_record('biblio_field_type_data', $val, 'ftdid');
}
drupal_write_record('biblio_field_type', $link, array(
'fid',
'tid',
));
if ($tid == 0) {
if ($link['common']) {
// $query = "UPDATE {biblio_field_type} SET ftdid = %d, common = %d, visible = %d WHERE fid = %d";
// db_query($query, array($fid, 1, 1, $fid));
db_update('biblio_field_type')
->fields(array(
'ftdid' => $fid,
'common' => 1,
'visible' => 1,
))
->condition('fid', $fid)
->execute();
}
else {
// not common, so change pointer back to customizations if available
$query = "UPDATE {biblio_field_type} SET ftdid = cust_tdid, common = :comm WHERE fid = :fid";
db_query($query, array(
':comm' => 0,
':fid' => $fid,
));
// db_update('biblio_field_type')
// ->fields(array('ftdid' => $fid, 'common' => 0, 'visible' => 1))
// ->condition('fid', $fid)
// ->execute();
}
// set the autocomplete bit on this field for all the types
// $query = "UPDATE {biblio_field_type} SET autocomplete = %d WHERE fid = %d";
// db_query($query, array($link['autocomplete'], $fid));
db_update('biblio_field_type')
->fields(array(
'autocomplete' => $link['autocomplete'],
))
->condition('fid', $fid)
->execute();
}
}
}
drupal_set_message(t("The changes have been saved."));
// Clear the cached pages and menus:
//menu_rebuild();
// Refresh translatable field strings.
biblio_locale_refresh_fields($tid);
}