Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2009
    Location
    Chicago, IL
    Posts
    45
    Plugin Contributions
    0

    Default New custom field in Admin Settings resets to default on edit save

    Hi all,
    I added a new field, products_id to the admin table so that I could feed different admins product specific sales reports while using Admin Profiles to hide everything else from them.

    I added my new field to the admin.php file in my admin folder, and it's working perfectly when I insert a new admin, but when I go to edit an admin that's already been created, it restores the product id to the default of 0.

    I'm running 1.3.8a with the Admin Profiles mod (which is awesome btw)

    I think the problem has to do with something I'm missing around ($action == 'save') but I don't know enough to figure out what it is

    here's the code where I added the new field to the array:
    Code:
    //-------------------------------------------------------------------------------------------------------------------------
        case 'insert':
        case 'save':
        case 'reset':
        $error = false;
        if ( ($action == 'insert') || ($action == 'reset') ){
        	$password_new = zen_db_prepare_input($_POST['password_new']);
        	$password_confirmation = zen_db_prepare_input($_POST['password_confirmation']);
        
        	if (strlen($password_new) < ENTRY_PASSWORD_MIN_LENGTH) {
        		$error = true;
        		$messageStack->add(ENTRY_PASSWORD_NEW_ERROR, 'error');
        	}
        	if ($password_new != $password_confirmation) {
        		$error = true;
        		$messageStack->add(ENTRY_PASSWORD_NEW_ERROR_NOT_MATCHING, 'error');
        	}
        }
        
        if ($error == false) {
        	if (isset($_GET['adminID'])) $admins_id = zen_db_prepare_input($_GET['adminID']);
        	$admin_name = zen_db_prepare_input($_POST['admin_name']);
        	$admin_email = zen_db_prepare_input($_POST['admin_email']);
        	$products_id = zen_db_prepare_input($_POST['products_id']);
        	$password_new = zen_db_prepare_input($password_new);
        	$admin_level = zen_db_prepare_input($_POST['admin_level']);
        	$password_new = zen_db_prepare_input($password_new);
        
        	$sql_data_array = array(
                                  'admin_name' => $admin_name,
                                  'admin_email' => $admin_email,
                                  'products_id' => $products_id,
                                  'admin_level' => (int)$admin_level
                                  );
        
        	if ($action == 'insert') {
        
        		$insert_sql_data = array('admin_pass' => zen_encrypt_password($password_new));
        		$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
        		zen_db_perform(TABLE_ADMIN, $sql_data_array);
        		$new_admin_id = zen_db_insert_id();
            $admins_id = $new_admin_id;
        
        	} elseif ($action == 'save') {
        
        		zen_db_perform(TABLE_ADMIN, $sql_data_array, 'update', "admin_id = '" . (int)$admins_id . "'");
            $db->Execute("UPDATE " . TABLE_CONFIGURATION . " set configuration_value='" . (int)$_POST['demo_status'] . "' where configuration_key='ADMIN_DEMO'");
        
        	} elseif ($action == 'reset') {
        
        		$update_sql_data = array('admin_pass' => zen_encrypt_password($password_new));
        		$sql_data_array = array_merge($sql_data_array, $update_sql_data);
        		zen_db_perform(TABLE_ADMIN, $sql_data_array, 'update', "admin_id = '" . (int)$admins_id . "'");
        
        	} // end action check
        
        
        	zen_redirect(zen_href_link(FILENAME_ADMIN, (isset($_GET['page']) ? 'page=' . $_GET['page'] . '&' : '') . 'adminID=' . $admins_id));
        
        } // end error check
        
        
        //echo $action;
        //	zen_redirect(zen_href_link(FILENAME_ADMIN, (isset($_GET['page']) ? 'page=' . '&' : '') . 'adminID=' . $admins_id));
        break;
        
    //-------------------------------------------------------------------------------------------------------------------------
    and here's the code for the edit box:
    Code:
    //-------------------------------------------------------------------------------------------------------------------------
      case 'edit':
        $heading[] = array('text' => '<b>' . TEXT_HEADING_EDIT_ADMIN . '</b>');
        $contents = array('form' => zen_draw_form('edit_admin', FILENAME_ADMIN, 'page=' . $_GET['page'] . '&adminID=' . $adminInfo->admin_id . '&action=save', 'post', 'enctype="multipart/form-data"'));
        $contents[] = array('text' => TEXT_EDIT_INTRO);
        $contents[] = array('text' => '<br><b>' . $adminInfo->admin_id . '</b>&nbsp;-&nbsp;' . $adminInfo->admin_name . '</b>');
        $contents[] = array('text' => '<br>' . TEXT_ADMINS_NAME . '<br>' . zen_draw_input_field('admin_name', $adminInfo->admin_name, zen_set_field_length(TABLE_ADMIN, 'admin_name', $max=30)) );
        $contents[] = array('text' => '<br>' . TEXT_ADMINS_EMAIL . '<br>' . zen_draw_input_field('admin_email', $adminInfo->admin_email, zen_set_field_length(TABLE_ADMIN, 'admin_email', $max=30)) );
        $contents[] = array('text' => '<br>' . TEXT_ADMINS_PRODUCT . '<br>' . zen_draw_input_field('products_info', $adminInfo->products_info, zen_set_field_length(TABLE_ADMIN, 'products_info', $max=20)) );
        
        $admin_current = $db->Execute("select admin_level from " . TABLE_ADMIN . " where admin_id='" . $_SESSION['admin_id'] . "'");
        /*
        if ($admin_current->fields['admin_level'] == '1') {
          $contents[] = array('text' => '<br>' . TEXT_ADMIN_LEVEL_INSTRUCTIONS);
          $contents[] = array(
        	  'text' => '<strong>' . TEXT_ADMINS_LEVEL . '</strong><br>' . zen_draw_input_field('admin_level', $adminInfo->admin_level, zen_set_field_length(TABLE_ADMIN, 'admin_level'))
          );
        */
          $demo_status= zen_get_configuration_key_value('ADMIN_DEMO');
          switch ($demo_status) {
            case '0': $on_status = false; $off_status = true; break;
            case '1': $on_status = true; $off_status = false; break;
            default:  $on_status = false; $off_status = true; break;
          }
          if ($on_status == true) {
            $contents[] = array('text' => '<br>' . TEXT_ADMIN_DEMO);
            $contents[] = array('text' => '<strong>' . TEXT_DEMO_STATUS . '</strong><br>' . zen_draw_radio_field('demo_status', '1', $on_status) . '&nbsp;' . TEXT_DEMO_ON . '&nbsp;' . zen_draw_radio_field('demo_status', '0', $off_status) . '&nbsp;' . TEXT_DEMO_OFF);
          } else {
            $contents[] = array('text' => zen_draw_hidden_field('demo_status', 0) );
          }
        
        $contents[] = array('align' => 'center',
                            'text' => '<br>' . zen_image_submit('button_save.gif', IMAGE_SAVE) . '<a href="' . zen_href_link(FILENAME_ADMIN, 'page=' . $_GET['page'] . '&adminID=' . $adminInfo->admin_id) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      
    //-------------------------------------------------------------------------------------------------------------------------
    Thanks!!

  2. #2
    Join Date
    Dec 2008
    Posts
    23
    Plugin Contributions
    0

    Default Re: New field in Admin Settings resets to default on edit save

    Hi,

    I am struggling with the same problem. I am trying to integrate new database fields in the ADMIN part of my site (database fields from products table and products_description_table).

    I thought I had succeeded in my effort because at my local site (localhost) everything works fine. I can edit all of the new database fields in the admin part of my local site.

    I uploaded all the files to my server. When I try to edit the new database fields now it clears all the fields in the preview screen.

    Has anybody got an idea why this works on my local site and not on my live site??

    Greetings,
    Paul
    MEINES TRADE

    PS: Please feel free to use the files for your own site (replace the database fields in all the files with your field names).
    Attached Files Attached Files

  3. #3
    Join Date
    Dec 2008
    Posts
    23
    Plugin Contributions
    0

    Default Re: New field in Admin Settings resets to default on edit save

    I worked it out.

    The corrected files are attached

    Greetings,
    Paul
    MEINES TRADE
    Attached Files Attached Files

  4. #4
    Join Date
    Apr 2009
    Location
    Chicago, IL
    Posts
    45
    Plugin Contributions
    0

    Default Re: New field in Admin Settings resets to default on edit save

    Good work Paul! I had just wiped out the code that allowed the admin to update my new fields, but I'll check out your solution and see if I can actually solve my problem the right way :)

 

 

Similar Threads

  1. v151 Save / Restore - Admin Settings
    By Kevin205 in forum General Questions
    Replies: 8
    Last Post: 8 Mar 2013, 08:33 AM
  2. My admin won't save settings changes or let me add/delete products
    By westcoastflipp in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 27 Feb 2010, 07:25 PM
  3. New Product Default Settings
    By beth99 in forum Setting Up Categories, Products, Attributes
    Replies: 8
    Last Post: 10 Aug 2008, 03:49 AM
  4. Save admin settings
    By theshmoo in forum General Questions
    Replies: 1
    Last Post: 17 Dec 2007, 04:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg