function invoice_settings_form_submit in Invoice 6
Same name and namespace in other branches
- 7 invoice.module \invoice_settings_form_submit()
Submit function for the settings form
File
- ./
invoice.module, line 417 - Invoice module
Code
function invoice_settings_form_submit(&$form_state, $form) {
$fv =& $form['values'];
// Invoice specific settings
variable_set('invoice_locale', $fv['locale']);
variable_set('invoice_date_format', $fv['date_format']);
variable_set('invoice_vat', $fv['vat']);
variable_set('invoice_pay_limit', $fv['pay_limit']);
variable_set('invoice_invoice_number_zerofill', $fv['invoice_number_zerofill']);
variable_set('invoice_invoice_number_prefix', $fv['invoice_number_prefix']);
variable_set('invoice_default_template', $fv['default_template']);
// Display columns specific settings
variable_set('invoice_display_column_vat', $fv['display_column_vat']);
variable_set('invoice_display_column_exunitcost', $fv['display_column_exunitcost']);
variable_set('invoice_display_column_incunitcost', $fv['display_column_incunitcost']);
variable_set('invoice_display_column_extotal', $fv['display_column_extotal']);
variable_set('invoice_display_column_inctotal', $fv['display_column_inctotal']);
// Supplier specific settings
variable_set('invoice_supplier_company_name', $fv['supplier_company_name']);
variable_set('invoice_supplier_street', $fv['supplier_street']);
variable_set('invoice_supplier_building_number', $fv['supplier_building_number']);
variable_set('invoice_supplier_zipcode', $fv['supplier_zipcode']);
variable_set('invoice_supplier_city', $fv['supplier_city']);
variable_set('invoice_supplier_country', $fv['supplier_country']);
variable_set('invoice_supplier_phone', $fv['supplier_phone']);
variable_set('invoice_supplier_fax', $fv['supplier_fax']);
variable_set('invoice_supplier_email', $fv['supplier_email']);
variable_set('invoice_supplier_web', $fv['supplier_web']);
variable_set('invoice_supplier_coc_number', $fv['supplier_coc_number']);
variable_set('invoice_supplier_vat_number', $fv['supplier_vat_number']);
$a_templates = _invoice_get_templates();
foreach ($a_templates as $s_template) {
$count = db_result(db_query("SELECT COUNT(*) FROM {invoice_templates} WHERE name='%s'", $s_template));
if ($count == 0) {
db_query("INSERT INTO {invoice_templates} (name) VALUES ('%s')", $s_template);
}
// Numeric fields in this query will become a zero if nothing is filled in, instead of the overloading system.
// So numeric fields that are empty will take over the general setting and update that in the database for this template.
db_query("UPDATE {invoice_templates} SET locale='%s', date_format='%s', vat=%d, pay_limit=%d,\n supplier_company_name='%s', supplier_street='%s', supplier_building_number='%s', supplier_zipcode='%s', supplier_city='%s',\n supplier_country='%s', supplier_phone='%s', supplier_fax='%s', supplier_email='%s', supplier_web='%s', supplier_coc_number='%s',\n supplier_vat_number='%s', display_column_vat=%d, display_column_exunitcost=%d, display_column_incunitcost=%d,\n display_column_extotal=%d, display_column_inctotal=%d\n WHERE name='%s'", $fv[$s_template . '_locale'], $fv[$s_template . '_date_format'], $fv[$s_template . '_vat'] != '' ? $fv[$s_template . '_vat'] : $fv['vat'], $fv[$s_template . '_pay_limit'] != '' ? $fv[$s_template . '_pay_limit'] : $fv['pay_limit'], $fv[$s_template . '_supplier_company_name'], $fv[$s_template . '_supplier_street'], $fv[$s_template . '_supplier_building_number'], $fv[$s_template . '_supplier_zipcode'], $fv[$s_template . '_supplier_city'], $fv[$s_template . '_supplier_country'], $fv[$s_template . '_supplier_phone'], $fv[$s_template . '_supplier_fax'], $fv[$s_template . '_supplier_email'], $fv[$s_template . '_supplier_web'], $fv[$s_template . '_supplier_coc_number'], $fv[$s_template . '_supplier_vat_number'], $count > 0 ? $fv[$s_template . '_display_column_vat'] : 0, $count > 0 ? $fv[$s_template . '_display_column_exunitcost'] : 1, $count > 0 ? $fv[$s_template . '_display_column_incunitcost'] : 1, $count > 0 ? $fv[$s_template . '_display_column_extotal'] : 1, $count > 0 ? $fv[$s_template . '_display_column_inctotal'] : 1, $s_template);
}
drupal_set_message(t('Succesfully saved'));
}