| 1 | <?php
 | 
  
    | 2 | 
 | 
  
    | 3 | // $Id: save_field.php 53 2005-09-09 11:48:13Z stefan $
 | 
  
    | 4 | 
 | 
  
    | 5 | /*
 | 
  
    | 6 | 
 | 
  
    | 7 |  Website Baker Project <http://www.websitebaker.org/>
 | 
  
    | 8 |  Copyright (C) 2004-2005, Ryan Djurovich
 | 
  
    | 9 | 
 | 
  
    | 10 |  Website Baker is free software; you can redistribute it and/or modify
 | 
  
    | 11 |  it under the terms of the GNU General Public License as published by
 | 
  
    | 12 |  the Free Software Foundation; either version 2 of the License, or
 | 
  
    | 13 |  (at your option) any later version.
 | 
  
    | 14 | 
 | 
  
    | 15 |  Website Baker is distributed in the hope that it will be useful,
 | 
  
    | 16 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
  
    | 17 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
  
    | 18 |  GNU General Public License for more details.
 | 
  
    | 19 | 
 | 
  
    | 20 |  You should have received a copy of the GNU General Public License
 | 
  
    | 21 |  along with Website Baker; if not, write to the Free Software
 | 
  
    | 22 |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
  
    | 23 | 
 | 
  
    | 24 | */
 | 
  
    | 25 | 
 | 
  
    | 26 | /*
 | 
  
    | 27 | The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
 | 
  
    | 28 | for his contributions to this module - adding extra field types
 | 
  
    | 29 | */
 | 
  
    | 30 | 
 | 
  
    | 31 | require('../../config.php');
 | 
  
    | 32 | 
 | 
  
    | 33 | // Get id
 | 
  
    | 34 | if(!isset($_POST['field_id']) OR !is_numeric($_POST['field_id'])) {
 | 
  
    | 35 | 	header("Location: ".ADMIN_URL."/pages/index.php");
 | 
  
    | 36 | } else {
 | 
  
    | 37 | 	$field_id = $_POST['field_id'];
 | 
  
    | 38 | 	$field_id = $field_id;
 | 
  
    | 39 | }
 | 
  
    | 40 | 
 | 
  
    | 41 | // Include WB admin wrapper script
 | 
  
    | 42 | $update_when_modified = true; // Tells script to update when this page was last updated
 | 
  
    | 43 | require(WB_PATH.'/modules/admin.php');
 | 
  
    | 44 | 
 | 
  
    | 45 | // Validate all fields
 | 
  
    | 46 | if($admin->get_post('title') == '' OR $admin->get_post('type') == '') {
 | 
  
    | 47 | 	$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'§ion_id='.$section_id.'&field_id='.$field_id);
 | 
  
    | 48 | } else {
 | 
  
    | 49 | 	$title = $admin->add_slashes($admin->get_post('title'));
 | 
  
    | 50 | 	$type = $admin->get_post('type');
 | 
  
    | 51 | 	$required = $admin->get_post('required');
 | 
  
    | 52 | }
 | 
  
    | 53 | 
 | 
  
    | 54 | // Update row
 | 
  
    | 55 | $database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET title = '$title', type = '$type', required = '$required' WHERE field_id = '$field_id'");
 | 
  
    | 56 | 
 | 
  
    | 57 | // If field type has multiple options, get all values and implode them
 | 
  
    | 58 | $list_count = $admin->get_post('list_count');
 | 
  
    | 59 | if(is_numeric($list_count)) {
 | 
  
    | 60 | 	$values = array();
 | 
  
    | 61 | 	for($i = 1; $i <= $list_count; $i++) {
 | 
  
    | 62 | 		if($admin->get_post('value'.$i) != '') {
 | 
  
    | 63 | 			$values[] = $admin->get_post('value'.$i);
 | 
  
    | 64 | 		}
 | 
  
    | 65 | 	}
 | 
  
    | 66 | 	$value = implode(',', $values);
 | 
  
    | 67 | }
 | 
  
    | 68 | 
 | 
  
    | 69 | // Get extra fields for field-type-specific settings
 | 
  
    | 70 | if($admin->get_post('type') == 'textfield') {
 | 
  
    | 71 | 	$length = $admin->get_post('length');
 | 
  
    | 72 | 	$value = $admin->get_post('value');
 | 
  
    | 73 | 	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$length' WHERE field_id = '$field_id'");
 | 
  
    | 74 | } elseif($admin->get_post('type') == 'textarea') {
 | 
  
    | 75 | 	$value = $admin->get_post('value');
 | 
  
    | 76 | 	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '' WHERE field_id = '$field_id'");
 | 
  
    | 77 | } elseif($admin->get_post('type') == 'heading') {
 | 
  
    | 78 | 	$extra = $admin->get_post('template');
 | 
  
    | 79 | 	if(trim($extra) == '') $extra = '<tr><td class="field_heading" colspan="2">{TITLE}{FIELD}</td></tr>';
 | 
  
    | 80 | 	$extra = $admin->add_slashes($extra);
 | 
  
    | 81 | 	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '', extra = '$extra' WHERE field_id = '$field_id'");
 | 
  
    | 82 | } elseif($admin->get_post('type') == 'select') {
 | 
  
    | 83 | 	$extra = $admin->get_post('size').','.$admin->get_post('multiselect');
 | 
  
    | 84 | 	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
 | 
  
    | 85 | } elseif($admin->get_post('type') == 'checkbox') {
 | 
  
    | 86 | 	$extra = $admin->get_post('seperator');
 | 
  
    | 87 | 	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
 | 
  
    | 88 | } elseif($admin->get_post('type') == 'radio') {
 | 
  
    | 89 | 	$extra = $admin->get_post('seperator');
 | 
  
    | 90 | 	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
 | 
  
    | 91 | }
 | 
  
    | 92 | 
 | 
  
    | 93 | // Check if there is a db error, otherwise say successful
 | 
  
    | 94 | if($database->is_error()) {
 | 
  
    | 95 | 	$admin->print_error($database->get_error(), WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'§ion_id='.$section_id.'&field_id='.$field_id);
 | 
  
    | 96 | } else {
 | 
  
    | 97 | 	$admin->print_success($TEXT['SUCCESS'], WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'§ion_id='.$section_id.'&field_id='.$field_id);
 | 
  
    | 98 | }
 | 
  
    | 99 | 
 | 
  
    | 100 | // Print admin footer
 | 
  
    | 101 | $admin->print_footer();
 | 
  
    | 102 | 
 | 
  
    | 103 | ?>
 |